Guest bindless indices clamp to a null before the host's dynamic descriptors; unsafe view bindings drop the draw #632

Open
deama wants to merge 2 commits from deama/Darner:c14/descriptor-isolation into Main
First-time contributor

Run in the game only inside a combined test build (official main c8258f9 + #594–#601 + this PR + the two other fix PRs from the same source), not on its own. Ported from uncommitted "Patch C14" work in a local VIctory-NVIDIA tree (before the rename), written to stop GPU timeouts.

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: read from the code. Shaders clamp every ResourceDescriptorHeap index at the view heap's last slot (999,999 on NVIDIA's 1,000,000-view heap), but the host's dynamic tables sit below it (606,783–999,998 by default). A stale or wild index the title computes can therefore select a descriptor the host made for another draw, often of another type. On the VIctory branch this was the top suspect in three driver timeouts (bugcheck 0x116) on an RTX 4080. The initiating GPU command was never identified, and other suspects were fixed at the same time.

Two commits:

  • descriptors: guest bindless indices clamp to a null before the host's dynamic tables

  • draw: drop draws whose view bindings cannot be made safely

  • Every view heap keeps a guest null just before its dynamic tables (606,782 on NVIDIA); the title's slots end before it. A translation clamps an index whose every leaf is a ResourceDescriptorHeap load to that null. Table indices (which the host may rewrite into its dynamic tables) still clamp at the last slot. In a phi/select/per-lane choice between a guest and a table descriptor, the guest operand is clamped on its own edge first, and a raw twin's index is clamped before the twin bit. Main's view-start size query keeps the access handle's range.

  • The partition is the same in every heap, so a short title heap leaves a null-filled gap. On 2^21-slot heaps the dynamic tables default to 2^18 slots (DARNER_DYNAMIC_SLOTS still raises them to 2^20), leaving 1,835,006 title slots. Sampler heaps hold at least 2,048 initialized descriptors, because shaders clamp sampler indices to 2,047. A heap whose null fill fails is not used.

  • Both shader cache keys include the guest null, so every shader is translated again once.

  • A draw or dispatch is dropped (counted in the F3 line, now "binds dropped for unavailable view heaps or descriptor table slots", and warned once) when: an indexed table's runtime-selected entry would cross into the guest null or dynamic tables and it can't be snapshotted; its shader reads view slots but only the one-slot fallback view heap is bound; or a direct root CBV/SRV is unset or has no backing (an explicit zero included), which used to leave the previous root descriptor bound.

  • Main's HostHeap::release subtracted the title count instead of the start of the dynamic range; fixed with the partition.

How it was tested

  • Tested revision: a091731660 (branch head; gates below). Game runs used a combined test build that contains it.
  • Commands and results: on a091731660, Windows 10 22H2 with its built-in Direct3D 12 (no Shader Model 6.6), Rust 1.98.1:
    • cargo clippy --workspace --all-targets --locked -- -D warnings: passed
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed
    • cargo --config 'profile.test.package.darner-shader.opt-level=3' test --workspace --locked --no-fail-fast (the opt-level only speeds up darner-shader's exhaustive float tests): 66 failed, all of which fail on unmodified main (c8258f9556) on this PC too (darner-shader tests that need Shader Model 6.6).
    • darner-gpu's test process aborts at the first test that needs Shader Model 6.6, on main too, so its tests were run in batches that survive the abort and compared one by one with main (main: 1658 pass, 8 fail, 139 need Shader Model 6.6, 81 ignored): no test that passes on main fails here, none removed; 6 new tests: 2 need Shader Model 6.6 (abort here), 4 pass.
    • cargo xtask policy: ok (576 files).
  • Game, combined test build, RTX 4080 16 GB (PCIe 4.0 x4), Windows 10 22H2, driver 581.80, Agility SDK 1.621.0 beside darner.exe, 4K output, DLSS Balanced, Series X profile, no frame generation. The outdoor checkpoint pose and harness come from #596.
    • Strict run (DARNER_D3D12_DEBUG=1, DARNER_D3D12_ERROR_ABORT=1, from #594), 180 s: loads, restores the outdoor pose at about 102 s, and draws there at about 17 fps (debug layer on). dropped 0 draws or dispatches and binds dropped … 0.00/frame in every report line, so the new drops removed nothing in this scene. A captured frame looks complete. The only debug-layer message was 1047 (a pooled texture still written by another queue), about 26 s after the pose, which stopped the strict run. The same message appears in a build of main + #594 + #596 alone (without this PR or any of #595 and #597–#601), so it predates this change.
    • The first start after this change translated every shader again (the cache key changed), as expected.
  • Changes a default: yes, for everyone: descriptor heap partition and shader clamps (above), and new draw drops in unsafe cases.
  • A/B result: none. These fixes were not timed on their own. The combined build's frame rate was in line with the build without them at the same spot (17.1–17.4 fps in the strict run, against 17.3–18.1 fps without these fixes), but strict debug-layer runs are not a speed comparison.
  • Gates run on that revision: see above.
  • Shader wave sizes tested: unit tests; game on NVIDIA (32-lane) only.
  • Hardware dependence: affects every vendor. AMD's uncapped heaps get fewer default dynamic slots (2^18), which the repo's notes say once ran out on NVIDIA. Untested on AMD and Intel.
  • Coverage gaps: the C14 audit's blocker 3 is not addressed (the null sentinels are Texture2D views, so a clamped buffer, cube, CBV or UAV access can still meet a null of the wrong type). The fallback sampler heap is still one slot. Two new GPU tests need Shader Model 6.6 and did not run here. No GPU-timeout reproduction exists on Darner, so "fixes the black screens" is not shown.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only). Only inside the combined build described above.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #598 (root-buffer indices). Whichever merges second needs a one-line change: #598's two heap_handle_at calls for root-buffer indices pass HeapRange::Host instead of true. Also #292 and #394 (constant reads through root SRVs; different problem in the same area).
  • Replaces or overlaps: none found
**Run in the game only inside a combined test build** (official `main` c8258f9 + #594–#601 + this PR + the two other fix PRs from the same source), not on its own. Ported from uncommitted "Patch C14" work in a local VIctory-NVIDIA tree (before the rename), written to stop GPU timeouts. ## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: read from the code. Shaders clamp every `ResourceDescriptorHeap` index at the view heap's last slot (999,999 on NVIDIA's 1,000,000-view heap), but the host's dynamic tables sit below it (606,783–999,998 by default). A stale or wild index the title computes can therefore select a descriptor the host made for another draw, often of another type. On the VIctory branch this was the top suspect in three driver timeouts (bugcheck 0x116) on an RTX 4080. The initiating GPU command was never identified, and other suspects were fixed at the same time. Two commits: - descriptors: guest bindless indices clamp to a null before the host's dynamic tables - draw: drop draws whose view bindings cannot be made safely - Every view heap keeps a guest null just before its dynamic tables (606,782 on NVIDIA); the title's slots end before it. A translation clamps an index whose every leaf is a `ResourceDescriptorHeap` load to that null. Table indices (which the host may rewrite into its dynamic tables) still clamp at the last slot. In a phi/select/per-lane choice between a guest and a table descriptor, the guest operand is clamped on its own edge first, and a raw twin's index is clamped before the twin bit. Main's view-start size query keeps the access handle's range. - The partition is the same in every heap, so a short title heap leaves a null-filled gap. On 2^21-slot heaps the dynamic tables default to 2^18 slots (`DARNER_DYNAMIC_SLOTS` still raises them to 2^20), leaving 1,835,006 title slots. Sampler heaps hold at least 2,048 initialized descriptors, because shaders clamp sampler indices to 2,047. A heap whose null fill fails is not used. - Both shader cache keys include the guest null, so every shader is translated again once. - A draw or dispatch is dropped (counted in the F3 line, now "binds dropped for unavailable view heaps or descriptor table slots", and warned once) when: an indexed table's runtime-selected entry would cross into the guest null or dynamic tables and it can't be snapshotted; its shader reads view slots but only the one-slot fallback view heap is bound; or a direct root CBV/SRV is unset or has no backing (an explicit zero included), which used to leave the previous root descriptor bound. - Main's `HostHeap::release` subtracted the title count instead of the start of the dynamic range; fixed with the partition. ## How it was tested - Tested revision: `a091731660` (branch head; gates below). Game runs used a combined test build that contains it. - Commands and results: on `a091731660`, Windows 10 22H2 with its built-in Direct3D 12 (no Shader Model 6.6), Rust 1.98.1: - `cargo clippy --workspace --all-targets --locked -- -D warnings`: passed - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passed - `cargo --config 'profile.test.package.darner-shader.opt-level=3' test --workspace --locked --no-fail-fast` (the opt-level only speeds up darner-shader's exhaustive float tests): 66 failed, all of which fail on unmodified `main` (c8258f9556) on this PC too (darner-shader tests that need Shader Model 6.6). - darner-gpu's test process aborts at the first test that needs Shader Model 6.6, on `main` too, so its tests were run in batches that survive the abort and compared one by one with `main` (`main`: 1658 pass, 8 fail, 139 need Shader Model 6.6, 81 ignored): no test that passes on `main` fails here, none removed; 6 new tests: 2 need Shader Model 6.6 (abort here), 4 pass. - `cargo xtask policy`: ok (576 files). - Game, combined test build, RTX 4080 16 GB (PCIe 4.0 x4), Windows 10 22H2, driver 581.80, Agility SDK 1.621.0 beside darner.exe, 4K output, DLSS Balanced, Series X profile, no frame generation. The outdoor checkpoint pose and harness come from #596. - Strict run (`DARNER_D3D12_DEBUG=1`, `DARNER_D3D12_ERROR_ABORT=1`, from #594), 180 s: loads, restores the outdoor pose at about 102 s, and draws there at about 17 fps (debug layer on). `dropped 0 draws or dispatches` and `binds dropped … 0.00/frame` in every report line, so the new drops removed nothing in this scene. A captured frame looks complete. The only debug-layer message was 1047 (a pooled texture still written by another queue), about 26 s after the pose, which stopped the strict run. The same message appears in a build of main + #594 + #596 alone (without this PR or any of #595 and #597–#601), so it predates this change. - The first start after this change translated every shader again (the cache key changed), as expected. - Changes a default: yes, for everyone: descriptor heap partition and shader clamps (above), and new draw drops in unsafe cases. - A/B result: none. These fixes were not timed on their own. The combined build's frame rate was in line with the build without them at the same spot (17.1–17.4 fps in the strict run, against 17.3–18.1 fps without these fixes), but strict debug-layer runs are not a speed comparison. - Gates run on that revision: see above. - Shader wave sizes tested: unit tests; game on NVIDIA (32-lane) only. - Hardware dependence: affects every vendor. AMD's uncapped heaps get fewer default dynamic slots (2^18), which the repo's notes say once ran out on NVIDIA. Untested on AMD and Intel. - Coverage gaps: the C14 audit's blocker 3 is not addressed (the null sentinels are `Texture2D` views, so a clamped buffer, cube, CBV or UAV access can still meet a null of the wrong type). The fallback sampler heap is still one slot. Two new GPU tests need Shader Model 6.6 and did not run here. No GPU-timeout reproduction exists on Darner, so "fixes the black screens" is not shown. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). Only inside the combined build described above. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #598 (root-buffer indices). Whichever merges second needs a one-line change: #598's two `heap_handle_at` calls for root-buffer indices pass `HeapRange::Host` instead of `true`. Also #292 and #394 (constant reads through root SRVs; different problem in the same area). - Replaces or overlaps: none found
Shaders clamped every view index at the view heap's last slot (999,999 on
NVIDIA's 1,000,000-view heap), but the host's dynamic tables lie below it,
at 606,783 to 999,998 by default. A stale or wild index the title computes
for `ResourceDescriptorHeap` could therefore pick a descriptor the host made
for another draw, often of another type. Every view heap now keeps a guest
null just before its dynamic tables (606,782 there; the title's slots end
before it), and a translation clamps an index whose every leaf is a
`ResourceDescriptorHeap` load to it. A table's index, which the host may
have rewritten into its dynamic tables, still clamps at the last slot. In a
choice between a guest and a table descriptor (phi, select, per-lane pick,
nested) the guest operand is clamped on its own edge before the choice, and
a raw twin's index is clamped before the twin bit is set. Main's view-start
size query keeps the access handle's range.

The partition is the same in every heap whatever its title count, so a
short title heap leaves a null-filled gap, and the CPU-side ownership and
twin flags stay packed (title slots, then dynamic ones). On a 2^21-slot heap
the dynamic tables now default to 2^18 slots (`DARNER_DYNAMIC_SLOTS` still
takes them to 2^20), leaving 1,835,006 title slots instead of a count that
depended on the title's heap. A sampler heap holds at least 2,048
descriptors, all made null, as shaders clamp sampler indices to 2,047
whatever the title's heap holds; its title count is unchanged. A heap whose
null fill fails is no longer used. Both shader cache keys include the guest
null, so earlier translations are made again once.

Ported from VIctory-NVIDIA's uncommitted Patch C14 work (descriptor track
and the shader and heap fixes from its audit), adapted to main's
`source_heap_handle`, view-start handles and allocator.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Three ways a draw or dispatch could still read descriptors it must not:

- An indexed table was checked only up to its last declared descriptor, so
  a root constant could select an entry past the slots the host heap mirrors
  in place, into the guest null and the dynamic tables. The check now counts
  the entries the root constants select and each declaration's whole
  descriptor. A view table that needs a snapshot and cannot have one (unset,
  in no shader-visible view heap, off a descriptor boundary, past the title
  heap, or longer than the dynamic slots) drops the draw instead of leaving
  the title's offsets bound.
- Without a title view heap a list binds a one-slot fallback heap. A draw
  whose shader reads any view slot (a view table, its own heap index, the
  host's metadata tables) is dropped there; root-only and sampler-only
  shaders still run.
- An unset direct root CBV or SRV, or one without backing (an explicit zero
  included), left the previous root descriptor bound. The draw is dropped.

Each drop is counted with the dropped table binds (the F3 line now reads
"unavailable view heaps or descriptor table slots") and warned of once.

Ported from VIctory-NVIDIA's uncommitted Patch C14 work (its draw-side
fixes for audit blockers 2, 4 and 7), adapted to main's heap binding and
table snapshots.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
TrustNo1 changed title from [pr-fix][rendering][shaders] Guest bindless indices clamp to a null before the host's dynamic descriptors; unsafe view bindings drop the draw to Guest bindless indices clamp to a null before the host's dynamic descriptors; unsafe view bindings drop the draw 2026-12-06 03:25:52 +00:00
Owner

Test needed — commit a0917316; what to check:

  • The problem on main: read from the code. Shaders clamp every ResourceDescriptorHeap index at the view heap's last slot (999,999 on NVIDIA's 1,000,000-view heap), but the host's dynamic tables sit below it (606,783–999,998 by default). A stale or wild index the title computes can therefore select a descriptor the host made for another draw, often of another type. On the an earlier fork branch this was the top suspect in three driver timeouts (bugcheck 0x116) on an RTX 4080. The initiating GPU command was never identified, and other suspects were fixed at the same time.

Two commits:

  • descriptors: guest bindless indices clamp to a null before the host's dynamic tables

  • draw: drop draws whose view bindings cannot be made safely

  • Every view heap keeps a guest null just before its dynamic tables (606,782 on NVIDIA); the title's slots end before it. A translation clamps an index whose every leaf is a ResourceDescriptorHeap load to that null. Table indices (which the host may rewrite into its dynamic tables) still clamp at the last slot. In a phi/select/per-lane choice between a guest and a table descriptor, the guest operand is clamped on its own edge first, and a raw twin's index is c

Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture.

Reply testing to take this run; it's free again after 24 h with no results.

**Test needed** — commit `a0917316`; what to check: - The problem on main: read from the code. Shaders clamp every `ResourceDescriptorHeap` index at the view heap's last slot (999,999 on NVIDIA's 1,000,000-view heap), but the host's dynamic tables sit below it (606,783–999,998 by default). A stale or wild index the title computes can therefore select a descriptor the host made for another draw, often of another type. On the an earlier fork branch this was the top suspect in three driver timeouts (bugcheck 0x116) on an RTX 4080. The initiating GPU command was never identified, and other suspects were fixed at the same time. Two commits: - descriptors: guest bindless indices clamp to a null before the host's dynamic tables - draw: drop draws whose view bindings cannot be made safely - Every view heap keeps a guest null just before its dynamic tables (606,782 on NVIDIA); the title's slots end before it. A translation clamps an index whose every leaf is a `ResourceDescriptorHeap` load to that null. Table indices (which the host may rewrite into its dynamic tables) still clamp at the last slot. In a phi/select/per-lane choice between a guest and a table descriptor, the guest operand is clamped on its own edge first, and a raw twin's index is c Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture. Reply `testing` to take this run; it's free again after 24 h with no results.
This pull request has changes conflicting with the target branch.
  • crates/darner-gpu/src/descriptor/host.rs
  • crates/darner-shader/src/emit/mod.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'c14/descriptor-isolation:deama-c14/descriptor-isolation'
git switch 'deama-c14/descriptor-isolation'

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 'deama-c14/descriptor-isolation'
git switch 'deama-c14/descriptor-isolation'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'deama-c14/descriptor-isolation'
git switch 'deama-c14/descriptor-isolation'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'deama-c14/descriptor-isolation'
git switch 'Main'
git merge --squash 'deama-c14/descriptor-isolation'
git switch 'Main'
git merge --ff-only 'deama-c14/descriptor-isolation'
git switch 'Main'
git merge 'deama-c14/descriptor-isolation'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!632
No description provided.