NVIDIA D3D12 fixes & shader translation improvements (dynamic descriptors, Wave32 compute, untracked masks) #1845

Open
github-bot wants to merge 5 commits from github-bot/gh-1845 into main AGit
Owner

@⁠mrsqarvc-byte on GitHub · 2026-11-24 23:18 UTC · original
mrsqarvc-byte:fix/shader-untracked-mask-select → main · +1523 −218 · 9 files · 5 commits · open

This PR bundles 5 clean-room fixes targeting NVIDIA D3D12 compatibility and GFX10-to-DXIL shader translation:

  1. victory-shader: SMEM buffer descriptors & multi-slice loads
    • Handle SMEM buffer descriptors and multi-slice loads in descriptor_data.
  2. victory-shader: descriptor format & stride reconstruction
    • Rebuild missing buffer stride (d1) and BASE_ARRAY (d5) metadata for descriptor loads (+5 shaders translated).
  3. victory-gpu: NVIDIA dynamic descriptor budget & FreshTables
    • Preserve the full dynamic descriptor budget (262k) on capped heaps on NVIDIA GPUs and reuse FreshTables, eliminating dropped draws (8,192+ dropped draws → 0).
  4. victory-shader, victory-gpu: Wave64 → Wave32 compute lowering
    • Lower Wave64 compute shaders for 32-lane host GPUs with proper LDS barrier handling (113 refused host pipelines → 0).
  5. victory-shader: uniform and constant lane masks in selects and phis
    • Track non-EXEC-derived lane masks (s_cselect, constants, scalar logic, split 32-bit Wave64 halves) in Structured::other_masks, resolve back-edge Atom::Phi mask arguments, and handle NULL/inline constants in v_cndmask_b32 and v_*_co_ci_u32 (75 previously failing shaders now translate).

Validation

  • Full test suite passing (cargo test), including new Wave32/Wave64 unit tests validated with IDxcValidator.
  • Verified clean-room compliance (asset policy hook passed).
  • Tested on RTX 5080 with VICTORY_D3D12_DRED=1 and VICTORY_GPU_TIMING=1 (0 host pipeline refusals, 0 untracked mask errors).

Fully done by AI ( Gemini Neon)

**@⁠mrsqarvc-byte** on GitHub · 2026-11-24 23:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/1845) `mrsqarvc-byte:fix/shader-untracked-mask-select` → `main` · +1523 −218 · 9 files · 5 commits · open This PR bundles 5 clean-room fixes targeting NVIDIA D3D12 compatibility and GFX10-to-DXIL shader translation: 1. **`victory-shader`: SMEM buffer descriptors & multi-slice loads** - Handle SMEM buffer descriptors and multi-slice loads in `descriptor_data`. 2. **`victory-shader`: descriptor format & stride reconstruction** - Rebuild missing buffer `stride` (`d1`) and `BASE_ARRAY` (`d5`) metadata for descriptor loads (+5 shaders translated). 3. **`victory-gpu`: NVIDIA dynamic descriptor budget & `FreshTables`** - Preserve the full dynamic descriptor budget (262k) on capped heaps on NVIDIA GPUs and reuse `FreshTables`, eliminating dropped draws (8,192+ dropped draws → 0). 4. **`victory-shader`, `victory-gpu`: Wave64 → Wave32 compute lowering** - Lower Wave64 compute shaders for 32-lane host GPUs with proper LDS barrier handling (113 refused host pipelines → 0). 5. **`victory-shader`: uniform and constant lane masks in selects and phis** - Track non-EXEC-derived lane masks (`s_cselect`, constants, scalar logic, split 32-bit Wave64 halves) in `Structured::other_masks`, resolve back-edge `Atom::Phi` mask arguments, and handle `NULL`/inline constants in `v_cndmask_b32` and `v_*_co_ci_u32` (75 previously failing shaders now translate). ### Validation - Full test suite passing (`cargo test`), including new Wave32/Wave64 unit tests validated with `IDxcValidator`. - Verified clean-room compliance (asset policy hook passed). - Tested on RTX 5080 with `VICTORY_D3D12_DRED=1` and `VICTORY_GPU_TIMING=1` (0 host pipeline refusals, 0 untracked mask errors). Fully done by AI ( Gemini Neon)
When a wide `s_load_dword*` loads multiple adjacent descriptors or a
descriptor used by `s_buffer_load_dword*`, `descriptor_data()` previously
inspected only the first `Role::Resource` match and rejected `Fields::Smem`
uses with "a scalar memory read as data".

Group descriptor uses per `first` dword offset, prefer Image/Buffer over
Smem when a slice is shared, reconstruct buffer record counts via
`dx.op.getDimensions` for `Fields::Smem` SRV/UAV slices (using RawBuffer or
StructuredBuffer properties matching `stride`), and isolate unsupported or
CBV slice errors so sibling slices remain usable.

Add unit tests covering `s_buffer_load_dword` SRV size reads and wide
`s_load_dwordx8` loads mixing CBV and SRV descriptors, validated with
`IDxcValidator`.
In `descriptor_data()`, buffer descriptors previously only populated dword 2
(`num_records`), and array image descriptors omitted dword 5 (`BASE_ARRAY`),
leaving both to fail with a generic "a descriptor's address or format read
as data" error.

- Add `only_high_bits_read()` to verify that every non-descriptor read of a
  buffer's dword 1 discards bits `[15:0]` (`base_address_hi`). When true for
  raw or structured buffers, emit `(stride & 0x3FFF) << 16` using the
  compile-time buffer stride (`props.1` for structured buffers, `0` for raw)
  so no GPU virtual address bit is ever fabricated.
- Populate image dword 5 (`BASE_ARRAY = 0`) for 1DArray and 2DArray views,
  matching the existing `base_level = 0` host-view invariant.
- Split remaining unmodeled descriptor dword errors into base address,
  format/metadata, and unused wide-load slot diagnostics.

Add unit tests covering stride extraction via `s_bfe_u32`/`s_lshr_b32`,
rejection of low-bit address reads, format/metadata reporting, and 2DArray
`BASE_ARRAY` queries, validated with `IDxcValidator`.
On NVIDIA GPUs, D3D12 caps shader-visible view heaps at `PORTABLE_VIEWS`
(1,000,000), which previously fell back to `MIN_DYNAMIC` (65,536) dynamic
slots — running dry seconds into the world and dropping thousands of draws.
In addition, `draw::State::tables()` keyed `fresh_tables` by `(table, hash)`
of the exact entry count `n`, causing stages or draws binding a shorter
prefix of the same unchanged table to allocate duplicate dynamic copies.

- Add `capped_split()` in `descriptor/host.rs` so capped view heaps keep
  full `DYNAMIC` (262,144) headroom (`737,856` static + `262,144` dynamic
  for a 1,245,184-view title heap) while preserving all title slots when
  `MIN_DYNAMIC` still fits, and log `static_slots`/`dynamic_slots`.
- Replace `fresh_tables` hashing in `draw.rs` with `FreshTables`, matching
  copied `[u32; 3]` descriptor records by exact prefix so stages and draws
  reusing an unchanged prefix share the same dynamic slots.
- Add unit tests for `capped_split` and `FreshTables`.
On NVIDIA GPUs (`WaveLaneCountMax = 32`), D3D12 rejected every compute
pipeline declaring `WaveSize(64)` with `E_INVALIDARG` even when the shader
only used wave-size-agnostic HLSL wave operations or single-wave LDS
without `s_barrier`.

- Query `D3D12_FEATURE_D3D12_OPTIONS1` (`WaveLaneCountMin`/`Max`) in
  `victory-gpu::host` and expose `max_wave_size()`.
- Include `max_wave` in `shader_cache`'s BLAKE3 build fingerprint so 32-lane
  and 64-lane GPUs never share disk cache entries, and pass it through
  `translate_for_wave()` / `emit_for_wave()`.
- In `victory-shader::emit::lower`, when a compute shader's console wave
  size exceeds `max_wave`, omit `WaveSize(64)`, switch `mask_data` to
  `MaskData::Host` (supporting whole-wave reductions/prefixes and
  wave-size-agnostic ballot ops), return a clean error in `cross_lane()`
  for genuinely wave64-dependent instructions, and insert deadlock-free group
  barriers (`sync_lds`) between conflicting LDS accesses in uniformly
  reached blocks when a single 64-thread console wave splits across two
  32-lane host warps.
- Add unit tests for `sync_lds`, `MaskData::Host` compute ballots, wave64
  cross-lane refusal (all validated with `IDxcValidator`), and cache key
  isolation.
- Track non-EXEC-derived lane masks (s_cselect, constants, scalar logic,
  and split 32-bit Wave64 halves) in `Structured::other_masks` via
  `Structured::select_mask()`, keeping `masks` untouched for scalar ops
- Resolve back-edge `Atom::Phi` mask arguments during `Lanes::finish()`
- Handle `NULL` and inline `0`/`-1` constants in `v_cndmask_b32` and
  `v_*_co_ci_u32`, and use `select_mask()` in `pending_masks`
- Add Wave32 and Wave64 unit tests validated with `IDxcValidator`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:46:25 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 23:21 UTC · original

For the reviewers, where this stack (5 commits on ffe310e, no description yet) meets other open PRs, from the commit titles and the lower.rs hunks; nothing built:

  • c624d98 (uniform and constant lane masks in selects and phis) is the same area as #1788, which lowers selects and carry-ins on a lane mask held as data. The constant-mask case was raised there too.
  • e716e31 (full dynamic descriptor budget on capped heaps) is the same as #1751, #1777 and #1779 (NVIDIA's 1,000,000 cap, #1744).
  • 351e728 (wave64 compute on 32-lane host GPUs) touches what #233 does for wave64 programs on 32-lane hosts.
  • 3014591 and 4db3b01 (descriptor_data stride, array base and SMEM descriptors): I did not find an open PR on these.

Splitting it along those lines would let each part be compared with the PR it overlaps.

AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-24 23:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/1845#issuecomment-7147305688) For the reviewers, where this stack (5 commits on `ffe310e`, no description yet) meets other open PRs, from the commit titles and the `lower.rs` hunks; nothing built: - `c624d98` (uniform and constant lane masks in selects and phis) is the same area as #1788, which lowers selects and carry-ins on a lane mask held as data. The constant-mask case was raised there too. - `e716e31` (full dynamic descriptor budget on capped heaps) is the same as #1751, #1777 and #1779 (NVIDIA's 1,000,000 cap, #1744). - `351e728` (wave64 compute on 32-lane host GPUs) touches what #233 does for wave64 programs on 32-lane hosts. - `3014591` and `4db3b01` (`descriptor_data` stride, array base and SMEM descriptors): I did not find an open PR on these. Splitting it along those lines would let each part be compared with the PR it overlaps. AI-assisted (Claude Code).
Author
Owner

@⁠Mericas77 on GitHub · 2026-11-25 00:04 UTC · original

Tested c624d98 on an NVIDIA host with the 1,000,000 view heap cap: RTX 4070 12 GB, driver 621.01, Windows 11 (build 26300), i5-13500, debug build.

This branch is based on ffe310e, 28 commits behind main (70564ae). It doesn't merge cleanly into main: git merge-tree reports conflicts in descriptor/host.rs, draw.rs, host.rs, shader_cache.rs, emit/lower.rs and emit/mod.rs. So I compared it with its own base:

base ffe310e this PR c624d98
cargo test --workspace --locked --no-fail-fast 342 passed, 0 failed, 6 ignored 356 passed, 0 failed, 6 ignored
-p victory-gpu 50 passed, 0 failed, 1 ignored 53 passed, 0 failed, 1 ignored
-p victory-shader 120 passed, 0 failed, 1 ignored 131 passed, 0 failed, 1 ignored

All 14 tests this PR adds pass on this card. Among them are capped_split_preserves_dynamic_budget_on_nvidia_cap, fresh_tables_reuses_matching_prefixes_and_detects_changes, the wave64_* lowering tests on a wave32 host, and the v_cndmask_*/mask phi tests. -p victory-gpu -- --test-threads=1: 53 passed, 0 failed. 10 parallel runs of -p victory-gpu --lib: no failures. No hangs, device removals or driver resets.

What this can't show: 4 of #1744's 5 NVIDIA failures on main are in tests added after ffe310e: memory::tests::lists_share_a_table_and_copies_keep_their_views, emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, a_heap_buffer_read_where_no_buffer_view_is_reads_zeros and emit::synthetic_tests::gathers_at_a_level_match_the_hardware. They don't exist on this branch. The fifth, dynamic_slots_are_held_until_released, passes here, but its NumDescriptors >= HEAP_VIEWS assertion isn't in this version either. Rebased onto main, this PR would also overlap with #1779's capped-heap changes in descriptor/host.rs.

**@⁠Mericas77** on GitHub · 2026-11-25 00:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/1845#issuecomment-7148115173) Tested `c624d98` on an NVIDIA host with the 1,000,000 view heap cap: RTX 4070 12 GB, driver 621.01, Windows 11 (build 26300), i5-13500, debug build. This branch is based on `ffe310e`, 28 commits behind `main` (`70564ae`). It doesn't merge cleanly into `main`: `git merge-tree` reports conflicts in `descriptor/host.rs`, `draw.rs`, `host.rs`, `shader_cache.rs`, `emit/lower.rs` and `emit/mod.rs`. So I compared it with its own base: | | base `ffe310e` | this PR `c624d98` | |---|---|---| | `cargo test --workspace --locked --no-fail-fast` | 342 passed, 0 failed, 6 ignored | 356 passed, 0 failed, 6 ignored | | `-p victory-gpu` | 50 passed, 0 failed, 1 ignored | 53 passed, 0 failed, 1 ignored | | `-p victory-shader` | 120 passed, 0 failed, 1 ignored | 131 passed, 0 failed, 1 ignored | All 14 tests this PR adds pass on this card. Among them are `capped_split_preserves_dynamic_budget_on_nvidia_cap`, `fresh_tables_reuses_matching_prefixes_and_detects_changes`, the `wave64_*` lowering tests on a wave32 host, and the `v_cndmask_*`/mask phi tests. `-p victory-gpu -- --test-threads=1`: 53 passed, 0 failed. 10 parallel runs of `-p victory-gpu --lib`: no failures. No hangs, device removals or driver resets. What this can't show: 4 of #1744's 5 NVIDIA failures on `main` are in tests added after `ffe310e`: `memory::tests::lists_share_a_table_and_copies_keep_their_views`, `emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride`, `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros` and `emit::synthetic_tests::gathers_at_a_level_match_the_hardware`. They don't exist on this branch. The fifth, `dynamic_slots_are_held_until_released`, passes here, but its `NumDescriptors >= HEAP_VIEWS` assertion isn't in this version either. Rebased onto `main`, this PR would also overlap with #1779's capped-heap changes in `descriptor/host.rs`.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:37 UTC · original

Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-gpu/src/descriptor/host.rs, crates/victory-gpu/src/draw.rs, crates/victory-gpu/src/host.rs, crates/victory-gpu/src/shader_cache.rs, crates/victory-shader/src/emit/lower.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/1845#issuecomment-7149756593) <!-- victory-triage v1 head=c624d98f7774d257a1e52d33346e3c2ed0ba127c verdict=needs-rebase at=2026-11-25T01:37:05Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-gpu/src/descriptor/host.rs`, `crates/victory-gpu/src/draw.rs`, `crates/victory-gpu/src/host.rs`, `crates/victory-gpu/src/shader_cache.rs`, `crates/victory-shader/src/emit/lower.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/descriptor/host.rs
  • crates/victory-gpu/src/host.rs
  • crates/victory-gpu/src/shader_cache.rs
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/emit/mod.rs
  • crates/victory-shader/src/emit/valu_tests.rs
  • crates/victory-shader/src/emit/waterfall_tests.rs
  • crates/victory-shader/src/structure.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 origin '+refs/pull/1845/head:github-bot/gh-1845'
git switch 'github-bot/gh-1845'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1845'
git switch 'github-bot/gh-1845'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1845'
git switch 'github-bot/gh-1845'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1845'
git switch 'main'
git merge --squash 'github-bot/gh-1845'
git switch 'main'
git merge --ff-only 'github-bot/gh-1845'
git switch 'main'
git merge 'github-bot/gh-1845'
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!1845
No description provided.