GPU: reuse indexed buffer spans and retain bound heaps on recorded lists #149

Open
syrrath-creator wants to merge 1 commit from upstream-pr/149 into main
syrrath-creator commented 2026-11-25 15:08:43 +00:00 (Migrated from github.com)
First-time contributor

Imported from Zettrox/ztrx. Originally posted by syrrath-creator on 2026-11-25T14:54:28Z.


When a shader picks a buffer from the descriptor heap by index, the renderer refreshes the byte ranges covered by the possible views. Today it rebuilds those ranges from every known slot on every indexed pass. The map of resolved slots is process-global and indexed by the host heap's address.

This change stores the slot map on the heap and reuses the grouped ranges while the resolved resources and byte bounds match. A changed or removed resource invalidates the ranges. The existing full rescan every 16 passes and the actual buffer refresh calls still run. A recorded command list now owns each shader-visible host heap it actually bound until reset. This also keeps the current native descriptor targets and stride table alive through delayed submission.

Synthetic workload, 83,000 slots CPU time per pass, before → after
Stable heap 1.422 → 0.189 ms
1% of slots reported again with identical resolutions 1.612 → 0.207 ms
1% of slots actually changed 1.961 → 1.987 ms

These are three-process release measurements on a Ryzen 7 7800X3D, pinned to one logical processor and including the usual full rescans. They cover CPU range bookkeeping. The number of changed slots affects the result. Three seeds checked 6,336 complete range sets against the baseline implementation.

On a physical RTX 4090, three fresh processes ran 69 compute dispatches and checked all 552 output DWORDs. Cases include slot replacement, removal, periodic rescans, a second command list submitted after the first one was reset, and updating a volatile descriptor after recording. The CPU unit test separately covers a new backing allocation with identical byte bounds.

Reproduce the NVIDIA check with synthetic resources. Developed and tested with Codex.

<!-- greyfinch-sync:Zettrox/ztrx:issue:6607288553 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/149). Originally posted by [syrrath-creator](https://github.com/syrrath-creator) on 2026-11-25T14:54:28Z. --- When a shader picks a buffer from the descriptor heap by index, the renderer refreshes the byte ranges covered by the possible views. Today it rebuilds those ranges from every known slot on every indexed pass. The map of resolved slots is process-global and indexed by the host heap's address. This change stores the slot map on the heap and reuses the grouped ranges while the resolved resources and byte bounds match. A changed or removed resource invalidates the ranges. The existing full rescan every 16 passes and the actual buffer refresh calls still run. A recorded command list now owns each shader-visible host heap it actually bound until reset. This also keeps the current native descriptor targets and stride table alive through delayed submission. | Synthetic workload, 83,000 slots | CPU time per pass, before → after | | --- | ---: | | Stable heap | 1.422 → 0.189 ms | | 1% of slots reported again with identical resolutions | 1.612 → 0.207 ms | | 1% of slots actually changed | 1.961 → 1.987 ms | These are three-process release measurements on a Ryzen 7 7800X3D, pinned to one logical processor and including the usual full rescans. They cover CPU range bookkeeping. The number of changed slots affects the result. Three seeds checked 6,336 complete range sets against the baseline implementation. On a physical RTX 4090, three fresh processes ran 69 compute dispatches and checked all 552 output DWORDs. Cases include slot replacement, removal, periodic rescans, a second command list submitted after the first one was reset, and updating a volatile descriptor after recording. The CPU unit test separately covers a new backing allocation with identical byte bounds. [Reproduce the NVIDIA check with synthetic resources](https://github.com/syrrath-creator/ztrx/blob/298dfd2d39bc43155ceb844ea638aa929afc9a44/docs/indexed-buffer-hardware.md). Developed and tested with Codex.
Artking175 commented 2026-11-25 16:13:08 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by Artking175 on 2026-11-25T15:16:41Z.


Independent retest on Windows 10 22H2, RTX 2060, driver 531.41, Rust 1.98.1 MSVC, DXC 1.8.2505.32, and app-local Agility SDK 1.608.2. I used the synthetic fixture from 298dfd2 on 90b529f and e8f64e5.

The fixture's Weak<Shadow> check was true on both revisions at the point where the title heap was released. I added a native descriptor-heap reference check after the first list was reset and before the second list was submitted.

let native_heap = descriptor::heap(heap.0).host().unwrap().heap.clone();
let before = host::references(&native_heap);
drop(c);
drop(heap);
assert_eq!(host::references(&native_heap), before);
drop(native_heap);
  • 90b529f: native heap references 3 → 2 on title heap release. The assertion stopped the control before deferred submission.
  • e8f64e5: native heap references 2 → 2. After the observer was dropped, the fixture completed all 23 dispatches, matching 184 dwords, including the volatile replacement after recording.

The victory-gpu library suite had 113 passed, 0 failed, and 2 ignored. The hardware fixture was run separately. All inputs were synthetic.

<!-- greyfinch-sync:Zettrox/ztrx:comment:7166585405 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/149#issuecomment-7166585405). Originally posted by [Artking175](https://github.com/Artking175) on 2026-11-25T15:16:41Z. --- Independent retest on Windows 10 22H2, RTX 2060, driver 531.41, Rust 1.98.1 MSVC, DXC 1.8.2505.32, and app-local Agility SDK 1.608.2. I used the synthetic fixture from `298dfd2` on `90b529f` and `e8f64e5`. The fixture's `Weak<Shadow>` check was true on both revisions at the point where the title heap was released. I added a native descriptor-heap reference check after the first list was reset and before the second list was submitted. ```rust let native_heap = descriptor::heap(heap.0).host().unwrap().heap.clone(); let before = host::references(&native_heap); drop(c); drop(heap); assert_eq!(host::references(&native_heap), before); drop(native_heap); ``` - `90b529f`: native heap references **3 → 2** on title heap release. The assertion stopped the control before deferred submission. - `e8f64e5`: native heap references **2 → 2**. After the observer was dropped, the fixture completed all **23 dispatches**, matching **184 dwords**, including the volatile replacement after recording. The `victory-gpu` library suite had 113 passed, 0 failed, and 2 ignored. The hardware fixture was run separately. All inputs were synthetic.
syrrath-creator commented 2026-11-25 16:13:08 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by syrrath-creator on 2026-11-25T15:32:39Z.


Thank you for checking the deferred list on the RTX 2060 and for isolating the native descriptor heap. I added your COM reference check to the shared hardware fixture, with attribution. On the RTX 4090, upstream now stops before submitting the deferred list at 3 → 2 references. The PR keeps 2 → 2 in three fresh runs. After the observer is dropped, all 23 dispatches in each run return the expected eight dwords. Updated fixture

<!-- greyfinch-sync:Zettrox/ztrx:comment:7167006427 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/149#issuecomment-7167006427). Originally posted by [syrrath-creator](https://github.com/syrrath-creator) on 2026-11-25T15:32:39Z. --- Thank you for checking the deferred list on the RTX 2060 and for isolating the native descriptor heap. I added your COM reference check to the shared hardware fixture, with attribution. On the RTX 4090, upstream now stops before submitting the deferred list at 3 → 2 references. The PR keeps 2 → 2 in three fresh runs. After the observer is dropped, all 23 dispatches in each run return the expected eight dwords. [Updated fixture](https://github.com/syrrath-creator/ztrx/commit/d7e806be7b3abd0a257fc3b14da9a187bca06e02)
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/149:upstream-pr/149'
git switch 'upstream-pr/149'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/149'
git switch 'upstream-pr/149'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/149'
git switch 'upstream-pr/149'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/149'
git switch 'main'
git merge --squash 'upstream-pr/149'
git switch 'main'
git merge --ff-only 'upstream-pr/149'
git switch 'main'
git merge 'upstream-pr/149'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Zettrox/ztrx!149
No description provided.