Skip to content

Fix instance data stride.#1691

Merged
bkaradzic-microsoft merged 3 commits intoBabylonJS:masterfrom
bkaradzic-microsoft:fix-instance-data-stride
May 9, 2026
Merged

Fix instance data stride.#1691
bkaradzic-microsoft merged 3 commits intoBabylonJS:masterfrom
bkaradzic-microsoft:fix-instance-data-stride

Conversation

@bkaradzic-microsoft
Copy link
Copy Markdown
Contributor

No description provided.

bkaradzic and others added 2 commits May 8, 2026 09:23
bgfx exposes instance data as a sequence of float4 registers (TEXCOORD7..0),
and the D3D11 input layout binds each one at a hard-coded offset of slotIdx*16,
so stride must be a multiple of 16 and each attribute must be 16-byte-padded.
The previous code summed ElementSize directly, which both tripped bgfx's
'Stride must be multiple of 16' assert and placed sub-vec4 attributes at the
wrong offsets within their slots. Now each instance attribute occupies one
16-byte slot, the buffer is zeroed first, and we early-return on empty/zero
instance counts. Lifts 36 of the 58 affected particle/instance tests from
crash to pass; the remaining 22 still render but fail pixel-diff for unrelated
reasons.

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

After the bgfx instance-data stride fix in this branch, 36 of the 58
previously-affected particle/instance tests now pass and are re-enabled so
CI can verify the fix. The remaining 22 tests no longer crash but still
fail pixel-diff for reasons unrelated to stride alignment (likely
shader-side packing of vec3+float into shared vec4 instance slots); their
exclusion reason is updated to reflect the post-fix state and to flag the
follow-up work.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 8, 2026 16:24
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 BabylonNative’s bgfx instance-data packing to use 16-byte slots per instance attribute (matching bgfx’s expected i_dataN layout), addressing stride/alignment assertions and stabilizing instanced rendering across backends. It also adjusts Playground validation configuration to re-enable tests that were previously excluded due to the stride issue and to update exclusion reasons for remaining problematic scenes.

Changes:

  • Align instance data stride/padding to fixed 16-byte slots per instance attribute and zero-fill unused bytes.
  • Make instance-data buffer construction robust to empty inputs and inferred instance counts.
  • Re-enable several Playground validation tests previously disabled due to bgfx stride assertions; update exclusion reasons for others.

Reviewed changes

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

File Description
Plugins/NativeEngine/Source/VertexBuffer.cpp Packs instance attributes into fixed 16-byte slots, zero-fills padding, and adjusts stride computation to satisfy bgfx alignment expectations.
Apps/Playground/Scripts/config.json Re-enables previously excluded tests tied to the stride issue and updates remaining exclusion reasons.

Comment thread Plugins/NativeEngine/Source/VertexBuffer.cpp
Comment thread Plugins/NativeEngine/Source/VertexBuffer.cpp
Copy link
Copy Markdown
Contributor

@bghgary bghgary left a comment

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]

LGTM except for one minor comment.

Comment thread Apps/Playground/Scripts/config.json Outdated
@bkaradzic-microsoft bkaradzic-microsoft merged commit 06a5a0e into BabylonJS:master May 9, 2026
28 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