GPU: typed null descriptors for empty table slots, depth-UAV scratch stand-in, and packed 16-bit fallback #581

Closed
FibbS6 wants to merge 2 commits from upstream-pr/581 into main
FibbS6 commented 2026-11-24 05:13:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by FibbS6 on 2026-11-24T05:13:03Z.


Problem

On NVIDIA D3D12 hardware (tested on RTX 4070), several descriptor-table edge cases cause D3D12 validation errors and GPU page faults / hangs (related to #392):

  1. Empty descriptor table slots always defaulted to a 2D Texture SRV null descriptor. When a shader indexes an unwritten slot expecting a UAV, CBV, or Buffer (dwords == 4), NVIDIA drivers fault or hang on the mismatched descriptor type.
  2. Depth-stencil textures bound as UAVs (e.g. R16_TYPELESS / R32G8X24_TYPELESS with PlaneSlice=1) cannot have UAVs created directly on D3D12, leaving null/invalid descriptors and triggering validation errors on PlaneSlice.
  3. Packed 16-bit texture formats (console format codes 86 / 115) lacked a host typeless fallback when creating views.

Fix

  • Populate empty descriptor table slots with typed null descriptors (SRV, UAV, CBV, buffer vs. texture) matching the shader's declared UsedResource metadata.
  • Add a depth-UAV scratch stand-in resource (with PlaneSlice = 0 for Texture2D/Texture2DArray) when a depth-stencil surface is bound as a UAV.
  • Add an R16_TYPELESS view fallback for packed 16-bit formats.

Verification

  • cargo xtask policy — passed (151 files ok)
  • cargo test -p victory-gpu -- --test-threads=1 — 43 passed, 0 failed
  • Verified on RTX 4070: eliminates D3D12 view/null-descriptor errors and GPU hangs on empty table slots.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6575141767 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/581). Originally posted by [FibbS6](https://github.com/FibbS6) on 2026-11-24T05:13:03Z. --- ### Problem On NVIDIA D3D12 hardware (tested on RTX 4070), several descriptor-table edge cases cause D3D12 validation errors and GPU page faults / hangs (related to #392): 1. **Empty descriptor table slots** always defaulted to a 2D Texture SRV null descriptor. When a shader indexes an unwritten slot expecting a `UAV`, `CBV`, or `Buffer` (`dwords == 4`), NVIDIA drivers fault or hang on the mismatched descriptor type. 2. **Depth-stencil textures bound as UAVs** (e.g. `R16_TYPELESS` / `R32G8X24_TYPELESS` with `PlaneSlice=1`) cannot have UAVs created directly on D3D12, leaving null/invalid descriptors and triggering validation errors on `PlaneSlice`. 3. **Packed 16-bit texture formats** (console format codes `86` / `115`) lacked a host typeless fallback when creating views. ### Fix - Populate empty descriptor table slots with typed null descriptors (`SRV`, `UAV`, `CBV`, buffer vs. texture) matching the shader's declared `UsedResource` metadata. - Add a depth-UAV scratch stand-in resource (with `PlaneSlice = 0` for `Texture2D`/`Texture2DArray`) when a depth-stencil surface is bound as a UAV. - Add an `R16_TYPELESS` view fallback for packed 16-bit formats. ### Verification - `cargo xtask policy` — passed (`151 files ok`) - `cargo test -p victory-gpu -- --test-threads=1` — `43 passed, 0 failed` - Verified on RTX 4070: eliminates D3D12 view/null-descriptor errors and GPU hangs on empty table slots.
Nixitov commented 2026-11-24 06:56:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Nixitov on 2026-11-24T06:04:54Z.


Test report on the hardware the two no host texture warnings come from (RTX 5070, native Windows D3D12).

Setup: Windows 11 Pro 26200.9974, NVIDIA RTX 5070, driver 617.14, in-box D3D12 10.0.26100.9818, Rust 1.98.1, cargo build --release -p victory, base d2a4bae + this PR merged, no other local changes except the rpcrt4 policy line from #636 (unrelated file).

Warnings at the first screens, main vs this PR:

log line main d2a4bae this PR
no host texture ... format: 86, flags: 5 (2560x1440, UAV) 1 0
no host texture ... format: 115, flags: 1 (2560x1440, RT) 1 0
view the host does not allow unordered=true format=53 flags=2 1 1, immediately followed by depth UAV: scratch stand-in format=53 width=768 height=768

So both packed 16-bit targets now exist on this GPU, and the depth-stencil UAV takes the scratch stand-in. The one remaining view the host does not allow is the depth surface's own UAV view, one line before the stand-in: expected, and it does not stop the frame.

Where the run goes: past the first screens and into the world. The frame log reaches frame = 1024 (4976 draws / 514 dispatches in the preceding 512 frames) after about 35 s, and pipeline creation continues to frame ~1669. Menus are at 30 fps.

Then the known NVIDIA hang, unchanged by this PR: a submission of 11 lists takes 10.97 s and the device is removed with 0x887A0006 (DXGI_ERROR_DEVICE_HUNG, reported after 0x887A0004). It holds 16 compute pipelines, 24 mesh+pixel pipelines and one vertex+pixel pipeline; the compute hashes in that submission were 19e215b47ff9112a, 1d449fb6a212a044, 362753554f3ad60b, 5fae02b711504eee, 6a62009bc6a4146e, 6b48bef1005f4f2f, 81e79f687ae84943, 9146291b38ea9ce1, 98888f39b68dbfde, 9938c251a313fe28, e3d5f313df8f0bd0, ec4528c014a996ca, eccf008b413ba7b1, f7f9f22551967b84, fb9c7f430da14c4c. Not breadcrumbed (release build, no DRED).

Not covered by this test: the menus' pixels were not compared beyond the frame count; AMD/Intel and WARP were not run. No game files are included; only log lines and shader hashes.

AI-assisted (DeepSeek V4.1 Flash coding agent).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123562005 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/581#issuecomment-7123562005). Originally posted by [Nixitov](https://github.com/Nixitov) on 2026-11-24T06:04:54Z. --- Test report on the hardware the two `no host texture` warnings come from (RTX 5070, native Windows D3D12). **Setup:** Windows 11 Pro 26200.9974, NVIDIA RTX 5070, driver 617.14, in-box D3D12 10.0.26100.9818, Rust 1.98.1, `cargo build --release -p victory`, base `d2a4bae` + this PR merged, no other local changes except the `rpcrt4` policy line from #636 (unrelated file). **Warnings at the first screens, main vs this PR:** | log line | main `d2a4bae` | this PR | |---|---|---| | `no host texture ... format: 86, flags: 5` (2560x1440, UAV) | 1 | 0 | | `no host texture ... format: 115, flags: 1` (2560x1440, RT) | 1 | 0 | | `view the host does not allow unordered=true format=53 flags=2` | 1 | 1, immediately followed by `depth UAV: scratch stand-in format=53 width=768 height=768` | So both packed 16-bit targets now exist on this GPU, and the depth-stencil UAV takes the scratch stand-in. The one remaining `view the host does not allow` is the depth surface's own UAV view, one line before the stand-in: expected, and it does not stop the frame. **Where the run goes:** past the first screens and into the world. The frame log reaches `frame = 1024` (4976 draws / 514 dispatches in the preceding 512 frames) after about 35 s, and pipeline creation continues to frame ~1669. Menus are at 30 fps. **Then the known NVIDIA hang, unchanged by this PR:** a submission of 11 lists takes 10.97 s and the device is removed with `0x887A0006` (`DXGI_ERROR_DEVICE_HUNG`, reported after `0x887A0004`). It holds 16 compute pipelines, 24 mesh+pixel pipelines and one vertex+pixel pipeline; the compute hashes in that submission were `19e215b47ff9112a`, `1d449fb6a212a044`, `362753554f3ad60b`, `5fae02b711504eee`, `6a62009bc6a4146e`, `6b48bef1005f4f2f`, `81e79f687ae84943`, `9146291b38ea9ce1`, `98888f39b68dbfde`, `9938c251a313fe28`, `e3d5f313df8f0bd0`, `ec4528c014a996ca`, `eccf008b413ba7b1`, `f7f9f22551967b84`, `fb9c7f430da14c4c`. Not breadcrumbed (release build, no DRED). **Not covered by this test:** the menus' pixels were not compared beyond the frame count; AMD/Intel and WARP were not run. No game files are included; only log lines and shader hashes. AI-assisted (DeepSeek V4.1 Flash coding agent).
Nixitov commented 2026-11-24 06:56:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Nixitov on 2026-11-24T06:24:54Z.


Follow-up: this stacks cleanly on #493 + #483 (the pair that stops the RTX 5070 world hang for me), and in a full world run the texture warnings stay gone.

  • d2a4bae + #493 + #483 + this PR, merged in that order: cargo build --release -p victory clean, no conflicts after the one described on #493 (guard slot on the variable dynamic range).
  • Run on the RTX 5070 (Windows 11 26200.9974, driver 617.14): no device removal in 4+ minutes in the world, 0 no host texture lines, 1 depth UAV: scratch stand-in format=53 width=768 height=768, 1.8-1.9 fps at 500-1207 draws per frame.
  • Without this PR the same #493 + #483 build is also stable, so this PR is not required for the hang; it is the one that makes the two 2560x1440 packed targets exist on this GPU.

No game files; only log lines and timings.

AI-assisted (DeepSeek V4.1 Flash coding agent).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123908124 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/581#issuecomment-7123908124). Originally posted by [Nixitov](https://github.com/Nixitov) on 2026-11-24T06:24:54Z. --- Follow-up: this stacks cleanly on #493 + #483 (the pair that stops the RTX 5070 world hang for me), and in a full world run the texture warnings stay gone. - `d2a4bae` + #493 + #483 + this PR, merged in that order: `cargo build --release -p victory` clean, no conflicts after the one described on #493 (guard slot on the variable dynamic range). - Run on the RTX 5070 (Windows 11 26200.9974, driver 617.14): **no device removal in 4+ minutes in the world**, 0 `no host texture` lines, 1 `depth UAV: scratch stand-in format=53 width=768 height=768`, 1.8-1.9 fps at 500-1207 draws per frame. - Without this PR the same #493 + #483 build is also stable, so this PR is not required for the hang; it is the one that makes the two 2560x1440 packed targets exist on this GPU. No game files; only log lines and timings. AI-assisted (DeepSeek V4.1 Flash coding agent).
iurysf commented 2026-11-24 09:06:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by iurysf on 2026-11-24T08:06:27Z.


Tested on an RTX 4070 (driver 32.0.16.2101) on top of #493 + #483. Run with VICTORY_D3D12_DEBUG=1 + VICTORY_D3D12_GBV=1 + DRED=1, one run each.

D3D12 message base (#493 + #483) base + this PR
id 940, SRV dimension: TEXTURE2D expected, TEXTURE1D in descriptor (heap index 0) 5 15 (7 draw, 8 dispatch)
id 941, UAV dimension: TEXTURE3D expected, TEXTURE2D in descriptor 0 2 (heap index 860148, 393204)
  • The view-kind mismatch at heap index 0 is still there, and it now also shows up from compute dispatches. Both validated runs ended on the title's own exception before the world (base 135 s, this PR 146 s), so these are counts up to that point.
  • Without the validation layers, a 300 s run didn't hit a device removal, the same as the base.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7125733192 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/581#issuecomment-7125733192). Originally posted by [iurysf](https://github.com/iurysf) on 2026-11-24T08:06:27Z. --- Tested on an RTX 4070 (driver 32.0.16.2101) on top of #493 + #483. Run with `VICTORY_D3D12_DEBUG=1` + `VICTORY_D3D12_GBV=1` + `DRED=1`, one run each. | D3D12 message | base (#493 + #483) | base + this PR | |---|---:|---:| | id 940, SRV dimension: TEXTURE2D expected, TEXTURE1D in descriptor (heap index 0) | 5 | **15** (7 draw, 8 dispatch) | | id 941, UAV dimension: TEXTURE3D expected, TEXTURE2D in descriptor | 0 | 2 (heap index 860148, 393204) | - The view-kind mismatch at heap index 0 is still there, and it now also shows up from compute dispatches. Both validated runs ended on the title's own exception before the world (base 135 s, this PR 146 s), so these are counts up to that point. - Without the validation layers, a 300 s run didn't hit a device removal, the same as the base. AI-assisted.
mercuryVM commented 2026-11-24 12:03:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T11:40:34Z.

Review: COMMENTED


Tested 0a936b6 on Windows 11, RTX 5070, MSVC: cargo test -p victory-gpu -- --test-threads=1 43 passed. Clippy's 1 warning is the existing one in host.rs. I didn't run a title here, and the PR adds no tests.

Typed null descriptors for empty table slots (make_null_for_used) are the right fix: a CBV, buffer SRV, or buffer or texture UAV slot now gets a null descriptor of its declared kind instead of a 2D-texture SRV. Two parts trade a fault for silently wrong results and should say so, or be gated:

  • descriptor/host.rs (fits, own == 53): a packed 16-bit colour view (B5G5R5A1, B4G4R4A4, or unknown) on an R16_TYPELESS texture becomes R16_UNORM/R16_UINT. The shader then reads one 16-bit channel where it expects four packed channels, so colours come out wrong without any error. If the host texture really lost its packed format, fix that at texture creation, or at least log once per texture so it's visible.
  • depth_scratch: a UAV on a depth texture is redirected to a scratch texture. Writes are discarded and reads return scratch contents. That's acceptable as a stop-gap against device removal, but it needs a shortcut: note and a one-time warn, so a missing effect isn't mistaken for a translator bug.
  • A unit test for make_null_for_used's kind mapping (the sentinel table) would be cheap and would catch a swapped arm.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6038538208 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/581#pullrequestreview-6038538208). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T11:40:34Z. **Review:** COMMENTED --- Tested 0a936b6 on Windows 11, RTX 5070, MSVC: `cargo test -p victory-gpu -- --test-threads=1` 43 passed. Clippy's 1 warning is the existing one in host.rs. I didn't run a title here, and the PR adds no tests. Typed null descriptors for empty table slots (`make_null_for_used`) are the right fix: a CBV, buffer SRV, or buffer or texture UAV slot now gets a null descriptor of its declared kind instead of a 2D-texture SRV. Two parts trade a fault for silently wrong results and should say so, or be gated: - `descriptor/host.rs` (`fits`, `own == 53`): a packed 16-bit colour view (`B5G5R5A1`, `B4G4R4A4`, or unknown) on an `R16_TYPELESS` texture becomes `R16_UNORM`/`R16_UINT`. The shader then reads one 16-bit channel where it expects four packed channels, so colours come out wrong without any error. If the host texture really lost its packed format, fix that at texture creation, or at least log once per texture so it's visible. - `depth_scratch`: a UAV on a depth texture is redirected to a scratch texture. Writes are discarded and reads return scratch contents. That's acceptable as a stop-gap against device removal, but it needs a `shortcut:` note and a one-time `warn`, so a missing effect isn't mistaken for a translator bug. - A unit test for `make_null_for_used`'s kind mapping (the sentinel table) would be cheap and would catch a swapped arm. AI-assisted (Claude Code).
SamuelReeder commented 2026-11-24 18:05:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by SamuelReeder on 2026-11-24T17:32:46Z.


From reading the diff; not run.

  1. tables() (draw.rs): an empty slot in a fresh table now depends on the UsedResource, but the fresh_tables key still hashes only the table address and record words. Within a list, two pipelines binding the same table with different kinds for an empty slot share the first one's null. Hashing the null kind of empty slots would fix it.
  2. make_null_for_used on a mirrored slot: a slot that already holds one null kind is rewritten as another, which an earlier recorded draw may still read. mirror also sees the nonzero sentinel on an empty slot, resets it and writes the 2D null again, so each draw rewrites the slot twice. Treating generation-0 keys as "no view" in mirror, and giving a conflicting table its own dynamic slots, would avoid both.
  3. depth_scratch: SCRATCH is keyed by the raw resource pointer and never cleared. Entries leak, and a texture later allocated at the same address gets the old scratch, possibly of another size or format.
  4. In a fresh table, slots no used-resource entry names (later array elements) pass None and stay a 2D SRV null.

Point 2 came up in review of a similar local patch of mine. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139355293 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/581#issuecomment-7139355293). Originally posted by [SamuelReeder](https://github.com/SamuelReeder) on 2026-11-24T17:32:46Z. --- From reading the diff; not run. 1. `tables()` (draw.rs): an empty slot in a fresh table now depends on the `UsedResource`, but the `fresh_tables` key still hashes only the table address and record words. Within a list, two pipelines binding the same table with different kinds for an empty slot share the first one's null. Hashing the null kind of empty slots would fix it. 2. `make_null_for_used` on a mirrored slot: a slot that already holds one null kind is rewritten as another, which an earlier recorded draw may still read. `mirror` also sees the nonzero sentinel on an empty slot, resets it and writes the 2D null again, so each draw rewrites the slot twice. Treating generation-0 keys as "no view" in `mirror`, and giving a conflicting table its own dynamic slots, would avoid both. 3. `depth_scratch`: `SCRATCH` is keyed by the raw resource pointer and never cleared. Entries leak, and a texture later allocated at the same address gets the old scratch, possibly of another size or format. 4. In a fresh table, slots no used-resource entry names (later array elements) pass `None` and stay a 2D SRV null. Point 2 came up in review of a similar local patch of mine. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 01:04:20 +00:00
Marvisak commented 2026-11-25 01:07:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:25:32Z.


Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

Three hacks against old code: depth UAVs written into a throwaway scratch texture (main has depth twins, twin.rs), null CBVs via CreateConstantBufferView (main reads constant buffers as raw views), and an unexplained format-53 to R16 view fallback.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148496050 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/581#issuecomment-7148496050). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:25:32Z. --- Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has since replaced the code it patches. Three hacks against old code: depth UAVs written into a throwaway scratch texture (main has depth twins, twin.rs), null CBVs via CreateConstantBufferView (main reads constant buffers as raw views), and an unexplained format-53 to R16 view fallback. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

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
Marvisak/VIctory!581
No description provided.