Skip to content

[Native] Combined native-engine GL fixes (depth, cube load, cube RTT, updateTextureData)#18567

Closed
bkaradzic-microsoft wants to merge 3 commits into
masterfrom
native-combined-gl-fixes
Closed

[Native] Combined native-engine GL fixes (depth, cube load, cube RTT, updateTextureData)#18567
bkaradzic-microsoft wants to merge 3 commits into
masterfrom
native-combined-gl-fixes

Conversation

@bkaradzic-microsoft

@bkaradzic-microsoft bkaradzic-microsoft commented Jun 11, 2026

Copy link
Copy Markdown
Member

Paired native PR: BabylonJS/BabylonNative#1748 (rolled up in the combined BN integration branch BabylonJS/BabylonNative#1752)

What

Loads self-contained single-file .dds / .ktx / .ktx2 cubemaps on the native engine — the
format produced by CubeTexture.CreateFromPrefilteredData(...), i.e. all six faces plus the
prefiltered mip chain in one container — and wires the spherical-harmonics coefficients returned by
the native loader into _sphericalPolynomial for diffuse IBL.

History — this started as a combined integration branch. It originally bundled four
native-engine fixes so combined CI could validate them together. Three have since merged into
master
#18558 (honor depthCullingState.depthTest), #18561 (cube render targets), and
#18566 (updateTextureData + engine.name = "Native") — and #18560 was closed in favor of
this branch. After rebasing onto master the net delta here is now just the single-file cubemap
loading
fix (the former #18560 content).

Changes (2 files, +103 / −26 vs master)

  • packages/dev/core/src/Engines/Native/Extensions/nativeEngine.cubeTexture.pure.ts — dispatches
    single-URL .dds/.ktx/.ktx2 cube containers to the native createCubeTexture path and sets
    _sphericalPolynomial from the coefficients the native loader returns.
  • packages/dev/core/src/Engines/Native/nativeInterfaces.tsloadCubeTexture's onSuccess
    callback gains an optional sphericalPolynomial?: Float32Array so the native loader can hand back
    the parsed SH.

No WebGL behavior change.

Validation tests re-enabled

The paired native PR BabylonJS/BabylonNative#1748 re-enables six prefiltered-.dds PBR
environment Playground validation tests (Win32 / D3D11). They pass pixel comparison once this TS
change is present in the bundled babylonjs:

  • NMEGLTF
  • Anisotropic
  • Clear Coat
  • PBRMetallicRoughnessMaterial
  • PBRSpecularGlossinessMaterial
  • PBR

Landing order

This PR → babylonjs npm release → BabylonNative#1748. The native validation tests only go
green once this TS change ships in the bundled engine, so the JS side lands first. Verified locally
against a from-source babylon.max.js built with this change (the six tests pass; SH integration is
correct — total solid angle = 4π).

@bjsplat

bjsplat commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat

bjsplat commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Snapshot stored with reference name:
refs/pull/18567/merge

Test environment:
https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/18567/merge/index.html

To test a playground add it to the URL, for example:

https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/18567/merge/index.html#WGZLGJ#4600

Links to test your changes to core in the published versions of the Babylon tools (does not contain changes you made to the tools themselves):

https://playground.babylonjs.com/?snapshot=refs/pull/18567/merge
https://sandbox.babylonjs.com/?snapshot=refs/pull/18567/merge
https://gui.babylonjs.com/?snapshot=refs/pull/18567/merge
https://nme.babylonjs.com/?snapshot=refs/pull/18567/merge

To test the snapshot in the playground with a playground ID add it after the snapshot query string:

https://playground.babylonjs.com/?snapshot=refs/pull/18567/merge#BCU1XR#0

If you made changes to the sandbox or playground in this PR, additional comments will be generated soon containing links to the dev versions of those tools.

@bjsplat

bjsplat commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

🟢 Memory Leak Test Results

13 passed, 0 leaked out of 13 scenarios

🟢 All memory leak tests passed — no leaks detected.

Passed Scenarios (13)
Scenario Package
Core Feature Stack @babylonjs/core
Core Rendering Materials Shadows Stack @babylonjs/core
Core Textures Render Targets PostProcess Stack @babylonjs/core
GUI Fullscreen UI Controls @babylonjs/gui
GUI Mesh ADT Controls @babylonjs/gui
Loaders Boombox Import @babylonjs/loaders
Loaders OBJ Direct Load @babylonjs/loaders
Loaders STL Direct Load @babylonjs/loaders
Materials Library Stack @babylonjs/materials
Serializers glTF Export @babylonjs/serializers
Serializers GLB Export @babylonjs/serializers
PostProcesses Digital Rain Stack @babylonjs/post-processes
Procedural Textures Stack @babylonjs/procedural-textures

@bjsplat

bjsplat commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

⚡ Performance Test Results

🟢 All performance tests passed — no regressions detected.

@sebavan

sebavan commented Jul 3, 2026

Copy link
Copy Markdown
Member

@bkaradzic, any update on this one ?

bkaradzic and others added 3 commits July 6, 2026 07:59
The native createCubeTexture override only handled a single .env file or six
face files; a single self-contained cubemap container (.dds/.ktx/.ktx2, as
produced by CubeTexture.CreateFromPrefilteredData) threw "Cannot load cubemap
because 6 files were not defined". The generic WebGL loader route is unusable on
native (its texture-upload and cube-readback entry points are unimplemented).

Route a single-URL container cubemap to engine.loadCubeTexture with the raw
buffer; the native engine decodes it (bimg) and, when polynomials are requested,
returns spherical-harmonics coefficients computed from the top mip, which are set
as the texture's spherical polynomial. loadCubeTexture's onSuccess now optionally
carries those coefficients. The .env and six-file paths are unchanged.

Pairs with a Babylon Native NativeEngine change implementing the single-buffer
cube decode and spherical-harmonics computation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…d onSuccess

The six-file path passed the Promise resolve directly, which is not assignable to
the widened onSuccess signature (sphericalPolynomial?: Float32Array). Wrap with
() => resolve() / () => reject(new Error(...)).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bkaradzic-microsoft
bkaradzic-microsoft force-pushed the native-combined-gl-fixes branch from bbac444 to c746fdb Compare July 6, 2026 15:00
@bjsplat

bjsplat commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

🟢 Memory Leak Test Results

4 passed, 0 leaked out of 4 scenarios

🟢 All memory leak tests passed — no leaks detected.

Passed Scenarios (4)
Scenario Package
Core Playground #2FDQT5#1508 @babylonjs/core
Core Playground #T90MQ4#14 @babylonjs/core
Core Playground #8EDB5N#2 @babylonjs/core
Core Playground #LL5BIQ#636 @babylonjs/core

@bjsplat

bjsplat commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

⚡ Performance Test Results

🟢 All performance tests passed — no regressions detected.

@bjsplat

bjsplat commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

@bghgary

bghgary commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

[Commented by Copilot on behalf of @bghgary]

This is the JS side of the native-SH approach in BabylonJS/BabylonNative#1748 — it wires the spherical harmonics that the native engine computes in C++ into _sphericalPolynomial.

That approach is being replaced. Per the discussion on #1748, the plan is to implement the _uploadDataToTextureDirectly / _uploadCompressedDataToTextureDirectly stubs (#218) so the native engine reuses the shared JS _DDSTextureLoader, which already loads single-file .dds/.ktx/.ktx2 cubemaps and computes the SH in JS. Under that route the native side never returns SH, so both changes here — the loadCubeTexture(sphericalPolynomial?) param and the bespoke native single-file cube dispatch — are no longer needed.

Suggest closing this, since it'll be made redundant by the #218 work — easy to reopen if that plan changes.

@bghgary bghgary left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Reviewed by Copilot on behalf of @bghgary]

Requesting changes to hold this from merging: it depends on the native-SH approach in BabylonJS/BabylonNative#1748, which is being replaced by the #218 route (native reuses the shared JS _DDSTextureLoader, SH computed in JS) — making these changes redundant. See the comment above. Shouldn't merge until the #218 direction is settled.

bkaradzic-microsoft added a commit to BabylonJS/BabylonNative that referenced this pull request Jul 7, 2026
## What

Re-enables the `blur-cube-with-the-effect-renderer` Playground
validation test (`#4C900K#2`) by
dropping its `excludeFromAutomaticTesting` entry in `config.json`, and
bumps the bundled `babylonjs`
to **9.15.0** (which contains the paired engine fix) so the test
actually passes in CI.

Two commits:
1. Re-enable `blur-cube-with-the-effect-renderer` in
`Apps/Playground/Scripts/config.json`.
2. Bump `babylonjs` to 9.15.0 in `Apps/package.json` +
`Apps/package-lock.json`.

Broken out of #1748 so it
can merge independently:
#1748 re-enables this same test alongside six single-file-`.dds` cube
tests, but those six are still
gated on an unmerged cube-loading TS change
(BabylonJS/Babylon.js#18567), whereas this test only
needs the already-merged depth-test fix. (#1748 currently still carries
a duplicate `blur-cube`
re-enable; that entry should be dropped there once this lands.)

## Why it passes now

The test previously failed pixel comparison because the native engine
ignored
`depthCullingState.depthTest`, so an `EffectRenderer` fullscreen pass
produced an all-black frame.
That is fixed by BabylonJS/Babylon.js#18558
("[Native] Honor
depthCullingState.depthTest on the native engine"), **merged 2026-06-16
and shipped in `babylonjs`
9.15.0** — the version this PR now pins. With that fix present in the
bundled engine the pass renders
correctly and the test matches its reference image.

## Status

- **Pin bump included; the earlier gate is resolved.** The bump to
9.15.0 (which contains #18558) is
part of this PR, so the re-enable no longer depends on a separate future
`babylonjs` bump.
- **CI is fully green**, including every Win32 D3D11 and Ubuntu desktop
job that runs the validation
suite — `blur-cube-with-the-effect-renderer` validates. Ready to merge
(pending review).

---------

Co-authored-by: Branimir Karadzic <branimirkaradzic@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Branimir Karadzic <bkaradzic@users.noreply.github.com>
@bkaradzic-microsoft

Copy link
Copy Markdown
Member Author

Closing per @bghgary's suggestion. This is the JS half of the native-computed-SH cubemap approach (paired with BabylonJS/BabylonNative#1748), and that approach is being replaced.

Per the discussion on #1748, the plan (BabylonJS/BabylonNative#218) is to implement the native engine's _uploadDataToTextureDirectly / _uploadCompressedDataToTextureDirectly stubs so it reuses the shared JS _DDSTextureLoader, which already loads single-file .dds/.ktx/.ktx2 cubemaps and computes the spherical harmonics in JS (no GPU readback). Under that route the native side never returns SH, so both changes here — the loadCubeTexture(sphericalPolynomial?) param and the bespoke native single-file cube dispatch — are no longer needed.

Closing as it'll be made redundant by the #218 work; easy to reopen if that plan changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants