Skip to content

Use supported backing storage for D24 render targets - #1874

Open
bkaradzic-microsoft wants to merge 3 commits into
BabylonJS:masterfrom
bkaradzic-microsoft:pr/d24-render-target-fallback
Open

bkaradzic-microsoft wants to merge 3 commits into
BabylonJS:masterfrom
bkaradzic-microsoft:pr/d24-render-target-fallback

Conversation

@bkaradzic-microsoft

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

Copy link
Copy Markdown
Member

Summary

initializeTexture passes D24 directly to bgfx even on backends that only support 24-bit depth using D24S8 storage. Unlike the generated-depth path in createFrameBuffer, it does not check format support first. An explicit D24 render-target request consequently fails during allocation on D3D11.

  • Keep supported D24 requests unchanged. For an unsupported D24 render target, select D24S8 only when it supports the same creation flags.
  • Reject non-finite, fractional, negative, and out-of-range numeric formats before converting to a bgfx enum, and validate the effective texture flags, including the BLIT_DST flag added by Texture::Create2D.
  • Throw a JavaScript error for invalid or unsupported requests before replacing any existing allocation. Non-render-target D24 requests are not substituted.

The fallback preserves 24-bit depth precision; this changes storage selection, not framebuffer depth/stencil state. Independently based on upstream 2caf5447, with its existing dependency pins. No visual references, tolerances, exclusions, or dependency versions change.

Validation

Built Release UnitTests using the stock dependency revisions on Windows:

Backend New native regressions Existing JavaScript.All
D3D11 / Chakra 4 passed 46 passed, 27 pending
D3D11 / JSI 4 passed 46 passed, 27 pending
GLES/ANGLE / Chakra (Windows development backend) 4 passed 46 passed, 27 pending

The native regressions inspect the allocated handle and actual backing format, attach the single-sampled depth texture to a framebuffer, verify 1x/4x allocation flags, preserve ordinary RGBA8 allocation behavior, and check that invalid/unsupported requests leave an existing texture intact.

Negative control: the single-sampled D24 allocation regression fails against the unmodified upstream implementation on D3D11, while the ordinary RGBA8 control passes. It passes after the fix.

Review follow-up: reproduced ToUint32 coercion accepting a wrapped/fractional format and replacing an existing texture, then added non-coercing validation and regressions for those inputs, NaN, and infinities.

Initial CI also exposed two test-harness portability issues: Env::RunScript is unavailable with JSI, and JavaScriptCore stack strings omit the error message. The harness now uses the shared Napi::Eval API and asserts Error::Message() directly. The JSI build and runtime coverage pass locally; cross-platform CI is rerunning.

The 4x case verifies allocation and flags only: multisampled sampled-depth framebuffer support requires additional bgfx flags and is unchanged here. This PR does not claim complete FrameGraph visual recovery on stock dependencies; the original shotgun scenes include other independently tracked fixes.

Validate InitializeTexture's format and effective creation flags before
allocating. Keep supported D24 requests unchanged; use D24S8 backing only
when a D24 render target is unsupported and the packed format is supported.
Reject invalid or unsupported requests without replacing an existing texture.

Add native regressions for backing formats, single-sampled framebuffer
attachment, multisample allocation flags, ordinary color textures, and
JavaScript errors. No dependency pins or visual fixtures change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 60c2ec68-6de1-445d-9fc9-b699db737eae
Copilot AI lite review requested due to automatic review settings September 11, 2026 20:29

Copilot AI 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.

🟡 Changes recommended

Reject non-integral and non-finite format values before converting them to enum values.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR adds texture validation and D24-to-D24S8 fallback for supported render targets. One moderate issue remains: Uint32Value() can coerce invalid numeric inputs into valid enum values.

Changes:

  • Validate formats and effective texture flags.
  • Add D24S8 fallback for render targets.
  • Add native regression tests and CMake registration.
File summaries
File Description
Plugins/NativeEngine/Source/NativeEngine.cpp Implements validation and backing-format fallback.
Apps/UnitTests/Source/Tests.NativeEngine.TextureFormats.cpp Adds texture allocation and rejection tests.
Apps/UnitTests/CMakeLists.txt Registers the new test source.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Plugins/NativeEngine/Source/NativeEngine.cpp Outdated
Reject fractional, non-finite, negative, and out-of-range numbers before
converting a texture format to an enum. Cover values that previously
wrapped or truncated to valid formats and replaced an existing texture.

Use Napi::Eval instead of the non-JSI Env::RunScript extension. Compare
Error::Message rather than a stack string, since JavaScriptCore stacks
do not include the error message. Preserve both in unexpected-error output.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 60c2ec68-6de1-445d-9fc9-b699db737eae

Copilot AI 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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread Apps/UnitTests/Source/Tests.NativeEngine.TextureFormats.cpp
Comment thread Plugins/NativeEngine/Source/NativeEngine.cpp Outdated
Comment thread Plugins/NativeEngine/Source/NativeEngine.cpp
Report the original numeric value and the finite-integer enum range while
preserving the existing Invalid texture format prefix. Add a regression
for the NaN diagnostic alongside allocation-preservation coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 60c2ec68-6de1-445d-9fc9-b699db737eae
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.

2 participants