Skip to content

Streamer: compute the dynamic buffer offset after "Grow" - #326

Merged
dzhdanNV merged 1 commit into
NVIDIA-RTX:mainfrom
0z5a:fix/streamer-offset-after-grow
Nov 16, 2026
Merged

dzhdanNV merged 1 commit into
NVIDIA-RTX:mainfrom
0z5a:fix/streamer-offset-after-grow

Conversation

@0z5a

@0z5a 0z5a commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

StreamBufferData and StreamTextureData compute the returned offset as m_FrameIndex * m_DynamicBufferSizePerFrame + m_DynamicBufferOffset before calling Grow(). If Grow() raises the per-frame size and replaces the buffer while m_FrameIndex >= 1, the offset still uses the old per-frame size. The data is then written and returned outside the current frame's slot of the new buffer, partly or fully inside another frame's slot. The next frames stream into that slot while the GPU may still read the previous frame's data, for example dynamic vertices or indices, ImGui geometry, or a texture copy source.

This change keeps the in-frame offset and adds the frame base after Grow(). The same fix is applied to both functions.

Repro

The repo has no test directory, so I used a small standalone program. It links the static library (NONE backend) and constructs StreamerImpl the way the backends do. The NONE core interface is passed in with buffer create/map/destroy redirected to host memory, so the streamed bytes can be checked. Setup: queuedFrameNum = 2, dynamicBufferDesc.size = 64 KB.

case before after
grow in frame slot 0 (control) inside slot inside slot
frame slot 1, no grow (control) inside slot inside slot
grow in frame slot 1, StreamBufferData 100 KB data at [64, 164) KB, slot 1 is [128, 256) KB [128, 228) KB
next frame streams 120 KB, previous frame's bytes overwritten 57344 0
grow in frame slot 1, StreamTextureData BC7 1024x1024 mip 1 (256 KB) data at [64, 320) KB, slot 1 is [256, 512) KB [256, 512) KB

I checked this in Debug and Release builds, and both gave the same output. I also timed a loop of 10^6 StreamBufferData calls (256 B each) in Release, alternating before/after runs, on a busy machine. The two sets of runs didn't agree on a direction:

  • 31 runs each: median 23.77 ns/call before, 23.27 after.
  • 15 runs each: median 21.27 before, 22.80 after.

The change only moves the frame-base add to after Grow(); it doesn't add any work.

Testing

  • NONE + Validation static build (Debug and Release); the repro above passes with the change and fails without it.
  • Not run on GPU hardware. The change is in backend-independent shared code; the GPU-side overlap follows from the offsets above.

This change was drafted with Claude Code (claude-opus-5-5); the test results above are from the runs described.

StreamBufferData and StreamTextureData computed the frame base with the per-frame size from before Grow(). After a grow in frame slot >= 1 the data landed outside the current frame slot of the new buffer, where the next frames overwrote it while it could still be in flight. Add the frame base after Grow().
@dzhdanNV

Copy link
Copy Markdown
Collaborator

It's a bomb. Thanks. Merged!

@dzhdanNV
dzhdanNV merged commit 2ae3a25 into NVIDIA-RTX:main Nov 16, 2026
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