fix(gpu): bind bounded single-descriptor tables for root SRVs and UAVs #3337

Open
github-bot wants to merge 1 commit from github-bot/gh-3337 into main AGit
Owner

@⁠legayclightning22 on GitHub · 2026-11-26 18:58 UTC · original
legayclightning22:fix/bounded-root-srv-uav-tables → main · +339 −59 · 2 files · 1 commits · open

Summary

Binds bounded single-descriptor tables for root SRVs and UAVs in victory-gpu (crates/victory-gpu/src/draw.rs and crates/victory-gpu/src/pipeline/host.rs), with a VICTORY_ROOT_SRV_DIRECT opt-out for direct root binding.

Changes

  • Update root SRV and UAV binding paths in crates/victory-gpu/src/draw.rs and crates/victory-gpu/src/pipeline/host.rs to use bounded single-descriptor tables[cite: 18].
  • Add VICTORY_ROOT_SRV_DIRECT opt-out support and unit tests covering bounded root views and environment override behavior[cite: 18].

Verification

  • cargo test -p victory-gpu --lib[cite: 18]
  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings[cite: 18]
  • cargo xtask policy[cite: 18]
**@⁠legayclightning22** on GitHub · 2026-11-26 18:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/3337) `legayclightning22:fix/bounded-root-srv-uav-tables` → `main` · +339 −59 · 2 files · 1 commits · open ## Summary Binds bounded single-descriptor tables for root SRVs and UAVs in `victory-gpu` (`crates/victory-gpu/src/draw.rs` and `crates/victory-gpu/src/pipeline/host.rs`), with a `VICTORY_ROOT_SRV_DIRECT` opt-out for direct root binding. ## Changes - Update root SRV and UAV binding paths in `crates/victory-gpu/src/draw.rs` and `crates/victory-gpu/src/pipeline/host.rs` to use bounded single-descriptor tables[cite: 18]. - Add `VICTORY_ROOT_SRV_DIRECT` opt-out support and unit tests covering bounded root views and environment override behavior[cite: 18]. ## Verification - `cargo test -p victory-gpu --lib`[cite: 18] - `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings`[cite: 18] - `cargo xtask policy`[cite: 18]
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 19:06:52 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 19:09 UTC · original · approved these changes

LGTM — verified on RTX 5090 (Windows / D3D12) against origin/main (63bcca4).

  • Binding bounded single-descriptor tables for root SRVs/UAVs (with opt-out preserving raw addresses) is cleanly scoped and verified on hardware.
  • cargo test -p victory-gpu --lib pipeline::host:: -- --test-threads=1: 7 passed, 0 failed (root_srv_direct_only_for_one, root_srv_direct_opt_out_keeps_raw_addresses, root_srvs_and_uavs_are_bounded_one_descriptor_tables).
  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20 passed, 0 failed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 19:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/3337#pullrequestreview-6079338820) · **approved these changes** LGTM — verified on RTX 5090 (Windows / D3D12) against `origin/main` (`63bcca4`). - Binding bounded single-descriptor tables for root SRVs/UAVs (with opt-out preserving raw addresses) is cleanly scoped and verified on hardware. - `cargo test -p victory-gpu --lib pipeline::host:: -- --test-threads=1`: 7 passed, 0 failed (`root_srv_direct_only_for_one`, `root_srv_direct_opt_out_keeps_raw_addresses`, `root_srvs_and_uavs_are_bounded_one_descriptor_tables`). - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1`: 20 passed, 0 failed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 19:16 UTC · original

WARP/CPU verification of head 8dd2ca97 (claim: #1633)

Environment: Windows 11, WARP only (VICTORY_WARP=1, VICTORY_D3D12_WARP=1), dxil.dll from Windows SDK 10.0.26100.0 (VICTORY_DXIL), no physical GPU, no game files. -j 4, --locked, separate target dir. Control: origin/main @ 63bcca43. Merge: git merge-tree against current origin/main is clean (head is 1 commit ahead, 0 behind).

Check main 63bcca43 PR 8dd2ca97
cargo test -p victory-gpu 231 passed, 0 failed, 1 ignored 234 passed, 0 failed, 1 ignored (+3)
cargo clippy -p victory-gpu --all-targets -- -D warnings clean clean
xtask policy 191 files ok 191 files ok

New tests all pass on WARP: root_srvs_and_uavs_are_bounded_one_descriptor_tables, root_srv_direct_opt_out_keeps_raw_addresses, root_srv_direct_only_for_one. They are absent on control (added by this PR); I did not separately demonstrate them failing without the fix. Synthetic/unit tests only; no real-title rendering was checked.

AI disclosure: run by Claude Code (Claude Sonnet 5.5), coordinated by Antigravity.

**@⁠oni-swr** on GitHub · 2026-11-26 19:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/3337#issuecomment-7201399169) **WARP/CPU verification of head `8dd2ca97`** (claim: #1633) Environment: Windows 11, **WARP only** (`VICTORY_WARP=1`, `VICTORY_D3D12_WARP=1`), `dxil.dll` from Windows SDK 10.0.26100.0 (`VICTORY_DXIL`), no physical GPU, no game files. `-j 4`, `--locked`, separate target dir. Control: `origin/main` @ `63bcca43`. Merge: `git merge-tree` against current `origin/main` is clean (head is 1 commit ahead, 0 behind). | Check | main `63bcca43` | PR `8dd2ca97` | |---|---|---| | `cargo test -p victory-gpu` | 231 passed, 0 failed, 1 ignored | 234 passed, 0 failed, 1 ignored (+3) | | `cargo clippy -p victory-gpu --all-targets -- -D warnings` | clean | clean | | `xtask policy` | 191 files ok | 191 files ok | New tests all pass on WARP: `root_srvs_and_uavs_are_bounded_one_descriptor_tables`, `root_srv_direct_opt_out_keeps_raw_addresses`, `root_srv_direct_only_for_one`. They are absent on control (added by this PR); I did not separately demonstrate them failing without the fix. Synthetic/unit tests only; no real-title rendering was checked. AI disclosure: run by Claude Code (Claude Sonnet 5.5), coordinated by Antigravity.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 20:58 UTC · original · requested changes

Converting raw root SRVs/UAVs to bounded single-descriptor tables is a solid goal, and pipeline/host.rs cleanly switches root_srvs/root_uavs to D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE with the VICTORY_ROOT_SRV_DIRECT=1 opt-out. However, there is a silent data-corruption bug in State::root_table whenever a title binds a root SRV or root UAV at a non-zero offset inside a buffer.

Blocking issue: State::root_table discards the byte offset (crates/victory-gpu/src/draw.rs:1064, 1080-1092)

In crates/victory-gpu/src/draw.rs:

  • root_view_slot creates the raw view at first = 0 (shadow.start) and caches it per (key, copy, uav):
    host.raw_view_at(index, Some(&shadow.buffer), 0, shadow.range().1 & !3, uav);
    
  • root_table then calls root_view_slot and discards the returned offset (address - shadow.start):
    let (key, index, _) = self.root_view_slot(list, compute, slot, uav)?;
    

Reusing a first = 0 view only works for the is_root_view user-data path (victory-shader/src/emit/lower.rs:1695-1733, !self.root_memory), where the shader receives offset in a ROOT_VIEW_OFFSET user-data dword and adds it to every byte address. For shaders that populate stage.root_srvs / stage.root_uavs (victory-shader/src/emit/lower.rs:5447-5459, root_memory == true), root_view_offset() returns None (lower.rs:1724): the shader indexes directly from byte 0 of the bound resource, relying on the binding itself to start at address (as Set*RootShaderResourceView / Set*RootUnorderedAccessView(param, shadow.gpu(address)) did on main).

As a result, any root SRV/UAV bound at address > shadow.start:

  1. Reads from shadow.start + 0 instead of address — which is either unrefreshed zeros (because root_view_slot at line 1046 only refreshes [address..shadow.end]) or stale/unrelated data at offset 0.
  2. For root UAVs, writes to shadow.start + 0 instead of address, silently corrupting the start of the buffer (outside the declared gpu_writes(list, address, ...) range) while leaving address untouched.
  3. Also cannot reach past the 512 MiB (1 << 27 dwords) raw-view cap in HostHeap::raw_view_at if address is more than 512 MiB into a large buffer.

Live GPU reproduction (RTX 5090 & WARP, VICTORY_D3D12_DEBUG=1)

Dispatching a compute shader (ByteAddressBuffer : register(t0, space1) -> RWByteAddressBuffer : register(u1, space1), copying dword 0) with src[0x0] = 0xDEADBEEF, src[0x100] = 0xCAFEBABE, binding root SRV at src + 0x100 and root UAV at dst + 0x200:

  • Direct baseline (main / VICTORY_ROOT_SRV_DIRECT=1): dst[0x0] = 0x00000000, dst[0x200] = 0xcafebabe (RTX 5090 & WARP).
  • PR root_table (cold src[0]): dst[0x0] = 0x00000000, dst[0x200] = 0x00000000 (reads unrefreshed zeros at src[0]; RTX 5090 & WARP).
  • PR root_table (warm src[0]): dst[0x0] = 0xdeadbeef, dst[0x200] = 0x00000000 (reads wrong data from src[0] and writes it to dst[0] instead of dst[0x200]; RTX 5090 & WARP).

Note that the new test assertion in draw.rs:2784 only checks state.root_table(...) == heap_host.gpu(index) without actually dispatching a shader through the table at a non-zero offset.

Suggested fix

  • Have root_table create (and cache separately, keyed by (key, copy, offset, uav) or (key, address, uav)) a bounded raw view starting at first = offset with bytes = shadow.left(address) & !3 (requiring offset to be 4-byte aligned, and passing shadow.mark_entry(address) to host.set_mark for UAVs), rather than reusing root_view_slot's first = 0 descriptor.
  • Add an end-to-end GPU compute dispatch test exercising root_table on both a root SRV and a root UAV at non-zero offsets within their buffers, plus an out-of-bounds read past shadow.left(address) returning 0.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 20:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/3337#pullrequestreview-6080415053) · **requested changes** Converting raw root SRVs/UAVs to bounded single-descriptor tables is a solid goal, and `pipeline/host.rs` cleanly switches `root_srvs`/`root_uavs` to `D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE` with the `VICTORY_ROOT_SRV_DIRECT=1` opt-out. However, there is a silent data-corruption bug in `State::root_table` whenever a title binds a root SRV or root UAV at a non-zero offset inside a buffer. ### Blocking issue: `State::root_table` discards the byte offset (`crates/victory-gpu/src/draw.rs:1064, 1080-1092`) In `crates/victory-gpu/src/draw.rs`: - `root_view_slot` creates the raw view at `first = 0` (`shadow.start`) and caches it per `(key, copy, uav)`: ```rust host.raw_view_at(index, Some(&shadow.buffer), 0, shadow.range().1 & !3, uav); ``` - `root_table` then calls `root_view_slot` and discards the returned `offset` (`address - shadow.start`): ```rust let (key, index, _) = self.root_view_slot(list, compute, slot, uav)?; ``` Reusing a `first = 0` view only works for the `is_root_view` user-data path (`victory-shader/src/emit/lower.rs:1695-1733`, `!self.root_memory`), where the shader receives `offset` in a `ROOT_VIEW_OFFSET` user-data dword and adds it to every byte address. For shaders that populate `stage.root_srvs` / `stage.root_uavs` (`victory-shader/src/emit/lower.rs:5447-5459`, `root_memory == true`), `root_view_offset()` returns `None` (`lower.rs:1724`): the shader indexes directly from byte `0` of the bound resource, relying on the binding itself to start at `address` (as `Set*RootShaderResourceView` / `Set*RootUnorderedAccessView(param, shadow.gpu(address))` did on `main`). As a result, any root SRV/UAV bound at `address > shadow.start`: 1. Reads from `shadow.start + 0` instead of `address` — which is either unrefreshed zeros (because `root_view_slot` at line 1046 only refreshes `[address..shadow.end]`) or stale/unrelated data at offset `0`. 2. For root UAVs, writes to `shadow.start + 0` instead of `address`, silently corrupting the start of the buffer (outside the declared `gpu_writes(list, address, ...)` range) while leaving `address` untouched. 3. Also cannot reach past the 512 MiB (`1 << 27` dwords) raw-view cap in `HostHeap::raw_view_at` if `address` is more than 512 MiB into a large buffer. ### Live GPU reproduction (RTX 5090 & WARP, `VICTORY_D3D12_DEBUG=1`) Dispatching a compute shader (`ByteAddressBuffer : register(t0, space1)` -> `RWByteAddressBuffer : register(u1, space1)`, copying dword 0) with `src[0x0] = 0xDEADBEEF`, `src[0x100] = 0xCAFEBABE`, binding root SRV at `src + 0x100` and root UAV at `dst + 0x200`: - Direct baseline (`main` / `VICTORY_ROOT_SRV_DIRECT=1`): `dst[0x0] = 0x00000000`, `dst[0x200] = 0xcafebabe` (RTX 5090 & WARP). - PR `root_table` (cold `src[0]`): `dst[0x0] = 0x00000000`, `dst[0x200] = 0x00000000` (reads unrefreshed zeros at `src[0]`; RTX 5090 & WARP). - PR `root_table` (warm `src[0]`): `dst[0x0] = 0xdeadbeef`, `dst[0x200] = 0x00000000` (reads wrong data from `src[0]` and writes it to `dst[0]` instead of `dst[0x200]`; RTX 5090 & WARP). Note that the new test assertion in `draw.rs:2784` only checks `state.root_table(...) == heap_host.gpu(index)` without actually dispatching a shader through the table at a non-zero offset. ### Suggested fix - Have `root_table` create (and cache separately, keyed by `(key, copy, offset, uav)` or `(key, address, uav)`) a bounded raw view starting at `first = offset` with `bytes = shadow.left(address) & !3` (requiring `offset` to be 4-byte aligned, and passing `shadow.mark_entry(address)` to `host.set_mark` for UAVs), rather than reusing `root_view_slot`'s `first = 0` descriptor. - Add an end-to-end GPU compute dispatch test exercising `root_table` on both a root SRV and a root UAV at non-zero offsets within their buffers, plus an out-of-bounds read past `shadow.left(address)` returning `0`.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3337/head:github-bot/gh-3337'
git switch 'github-bot/gh-3337'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3337'
git switch 'github-bot/gh-3337'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3337'
git switch 'github-bot/gh-3337'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3337'
git switch 'main'
git merge --squash 'github-bot/gh-3337'
git switch 'main'
git merge --ff-only 'github-bot/gh-3337'
git switch 'main'
git merge 'github-bot/gh-3337'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3337
No description provided.