Skip to content

NativeEngine: accept R8 and RG32F in raw texture upload path.#1694

Merged
bkaradzic-microsoft merged 1 commit into
BabylonJS:masterfrom
bkaradzic-microsoft:fix-rawtexture-format-whitelist
May 11, 2026
Merged

NativeEngine: accept R8 and RG32F in raw texture upload path.#1694
bkaradzic-microsoft merged 1 commit into
BabylonJS:masterfrom
bkaradzic-microsoft:fix-rawtexture-format-whitelist

Conversation

@bkaradzic-microsoft
Copy link
Copy Markdown
Contributor

What

Adds R8 and RG32F to the small format whitelist asserted by PrepareImage in Plugins/NativeEngine/Source/NativeEngine.cpp. Both formats are already supported by bimg and bgfx; the gap was only in BN's adapter assert.

             assert(
+                image->m_format == bimg::TextureFormat::R8 ||
                 image->m_format == bimg::TextureFormat::R16 ||
                 image->m_format == bimg::TextureFormat::RGB8 ||
                 image->m_format == bimg::TextureFormat::RGBA8 ||
                 image->m_format == bimg::TextureFormat::RGBA16 ||
                 image->m_format == bimg::TextureFormat::RGBA16F ||
                 image->m_format == bimg::TextureFormat::RG16F ||
+                image->m_format == bimg::TextureFormat::RG32F ||
                 image->m_format == bimg::TextureFormat::RGBA32F ||
                 image->m_format == bimg::TextureFormat::RGBA32U);

Why

NativeEngine::LoadRawTexture (the binding for Babylon.js engine.createRawTexture(...)) forwards the JS-supplied texture format to PrepareImage, which had a hard-coded whitelist of 8 formats. Two formats that Babylon.js requests in normal usage fall outside that list and cause SIGABRT on the assert:

Format Where it shows up
R8 createRawTexture for single-channel byte data (texture updates)
RG32F GPU particle internal state textures (262 elements * 8 bytes)

RG16F was already on the list - the 32-bit twin had simply been overlooked.

How verified

Local Win32 V8 D3D11 Debug build, headless Playground runner, 8 currently-excluded tests known to hit this assert:

idx title before after
336 Test updateTextureData SIGABRT (R8) runs (hits separate JS issue, not in scope)
652 Particles - Billboard Y SIGABRT (RG32F) runs (pixel-diff fail)
682 GPU Particles - Change - Size SIGABRT (RG32F) runs (pixel-diff fail)
684 GPU Particles - Change - Speed SIGABRT (RG32F) runs (pixel-diff fail)
685 GPU Particles - Change - Speed Limit SIGABRT (RG32F) runs (pixel-diff fail)
686 GPU Particles - Change - Angular Speed SIGABRT (RG32F) runs (pixel-diff fail)
687 GPU Particles - Change - Drag SIGABRT (RG32F) runs (pixel-diff fail)
688 GPU Particles - Change - Size Range SIGABRT (RG32F) runs (pixel-diff fail)

Each failing call was confirmed by a temporary fprintf placed in LoadRawTexture (build, capture, revert).

Scope

  • This PR only fixes the assert. The 8 tests still fail and remain excluded - whether they should be re-enabled is a separate question, since they fail pixel-diff (and idx 336 surfaces an unrelated JS issue) after the assert is removed.
  • For these tests mips=false and srgb=false, so the mipmap-generation and SRGB-conversion branches in PrepareImage don't need format-aware extensions for this fix. If a future caller requests mips on R8 / RG32F, the existing mip branch will need analogous handling.
  • FlipImage is format-agnostic (it computes rowPitch from total-size / height), so invertY is safe for the new formats.

Risk

Very low. Two enum values added to a disjunction. No code path that previously rejected these formats now accepts data that bgfx would refuse to ingest - the underlying renderer already advertises both formats.

`NativeEngine::LoadRawTexture` (called from `engine.createRawTexture` on the
Babylon.js side) passes the JS-supplied format to `PrepareImage`, which
asserts a small whitelist. Babylon emits `R8` for a few raw-data textures
and `RG32F` for GPU particle state textures - neither was on the list,
causing SIGABRT in the assert at startup of those tests.

Add `R8` and `RG32F` to the whitelist. `RG16F` was already accepted; the
32-bit twin had been overlooked.

For these specific JS callers, `mips=false` and `srgb=false`, so the
mipmap-generation and sRGB-conversion branches of `PrepareImage` are not
exercised and need no further changes. `FlipImage` (the only other
in-place operation in the function) is format-agnostic. The `bimg`
container and bgfx both already support both formats; this was purely an
adapter-side gap.

Verified locally on Win32 V8 D3D11 Debug for the 8 currently-excluded
Playground tests that hit this assert (idx 336, 652, 682, 684, 685, 686,
687, 688): all 8 no longer SIGABRT. They remain pixel-diff failures (or
hit unrelated downstream issues), tracked separately.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the NativeEngine raw texture upload preparation path to accept two additional bimg texture formats (R8 and RG32F) that are already supported downstream (bimg/bgfx), preventing debug-time aborts when Babylon.js requests these formats via engine.createRawTexture(...).

Changes:

  • Extend PrepareImage’s debug-format whitelist to include bimg::TextureFormat::R8.
  • Extend PrepareImage’s debug-format whitelist to include bimg::TextureFormat::RG32F.

@bkaradzic-microsoft bkaradzic-microsoft enabled auto-merge (squash) May 11, 2026 21:17
@bkaradzic-microsoft bkaradzic-microsoft merged commit bbf0a5e into BabylonJS:master May 11, 2026
32 checks passed
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.

4 participants