Shaders: lower root UAV accesses as ROVs in POPS pixel shaders #2488

Open
reeledMarek wants to merge 1 commit from upstream-pr/2490 into main
reeledMarek commented 2026-11-25 14:48:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T14:48:15Z.


Problem

In crates/victory-shader/src/emit/lower.rs:

  1. When a pixel shader uses POPS (self.pops == true, DB_SHADER_CONTROL bit 16), Lower::handle() ORs the ROV flag (0x2000) into props.0 for UAV handles (0x100B -> 0x300B). However, the Source::Built match arms only matched 0x100B and 11, causing any root UAV store/atomic/UAV-annotated load in a POPS pixel shader to fail translation with "a root UAV or typed root view".
  2. Lower::root_view() hardcoded (11 | 0x1000, 0) without checking self.pops, so root UAV heap handles in POPS shaders lost the 0x2000 ROV annotation (and global_load_* on a root UAV, which passes props.0 == 11 into handle(), also skipped setting flags::ROVS).

Fix

  • Match props.0 & !0x2000 in Lower::handle() for Source::Built root descriptors so ROV-annotated raw UAV handles (0x300B) route to root_view(..., true) (or root_uav_handle when root_memory is active).
  • In Lower::root_view(), when uav && self.pops, set self.s.flags |= flags::ROVS and annotate the heap handle with (11 | 0x1000 | 0x2000, 0). (Shader::heap_handle still records view_index because 0x300B & 0x1000 != 0 and 0x300B & 0xFF == 11, so write marks keep working.)
  • Added synthetic unit tests in emit::lower::tests::pops_pixel_shader_lowers_root_uav_accesses_as_rovs covering buffer_store_dword, global_store_dword, and global_load_dword on root UAVs in POPS and non-POPS pixel shaders (with and without view_marks).

Verification

  • cargo test -p victory-shader --locked (145 passed, 0 failed)
  • cargo test -p xtask --locked (repository_passes_policy passed)
  • cargo clippy -p victory-shader --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings (0 warnings)
<!-- greyfinch-sync:Marvisak/VIctory:issue:5493617637 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2490). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-25T14:48:15Z. --- ### Problem In `crates/victory-shader/src/emit/lower.rs`: 1. When a pixel shader uses POPS (`self.pops == true`, `DB_SHADER_CONTROL` bit 16), `Lower::handle()` ORs the ROV flag (`0x2000`) into `props.0` for UAV handles (`0x100B` -> `0x300B`). However, the `Source::Built` match arms only matched `0x100B` and `11`, causing any root UAV store/atomic/UAV-annotated load in a POPS pixel shader to fail translation with `"a root UAV or typed root view"`. 2. `Lower::root_view()` hardcoded `(11 | 0x1000, 0)` without checking `self.pops`, so root UAV heap handles in POPS shaders lost the `0x2000` ROV annotation (and `global_load_*` on a root UAV, which passes `props.0 == 11` into `handle()`, also skipped setting `flags::ROVS`). ### Fix - Match `props.0 & !0x2000` in `Lower::handle()` for `Source::Built` root descriptors so ROV-annotated raw UAV handles (`0x300B`) route to `root_view(..., true)` (or `root_uav_handle` when `root_memory` is active). - In `Lower::root_view()`, when `uav && self.pops`, set `self.s.flags |= flags::ROVS` and annotate the heap handle with `(11 | 0x1000 | 0x2000, 0)`. (`Shader::heap_handle` still records `view_index` because `0x300B & 0x1000 != 0` and `0x300B & 0xFF == 11`, so write marks keep working.) - Added synthetic unit tests in `emit::lower::tests::pops_pixel_shader_lowers_root_uav_accesses_as_rovs` covering `buffer_store_dword`, `global_store_dword`, and `global_load_dword` on root UAVs in POPS and non-POPS pixel shaders (with and without `view_marks`). ### Verification - `cargo test -p victory-shader --locked` (145 passed, 0 failed) - `cargo test -p xtask --locked` (`repository_passes_policy` passed) - `cargo clippy -p victory-shader --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings` (0 warnings)
oni-swr commented 2026-11-25 15:08:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T15:08:46Z.

Review: COMMENTED


Independent verification on Windows, VICTORY_D3D12_WARP=1 (WARP only, no hardware GPU touched). Tested commit d8e54fd834998271d3e6e315b8fe2a312519e32e (clean detached checkout).

  • cargo test -p victory-shader --locked --lib pops_pixel_shader_lowers_root_uav — 1 passed, 0 failed, 0 ignored.
  • Mutation check: with the if self.pops branch in root_view forced off, the same test fails (panic at the first l.rovs assert), so it guards the change.
  • cargo test -p victory-shader --locked --lib — 248 passed, 0 failed, 3 ignored (the ignored ones are pre-existing).

Code read: root_view(.., uav=true) now sets flags::ROVS and 0x2000 under POPS. This covers the global_load route, where handle() sees props.0 == 11 without 0x1000 and so never adds the ROV bit itself. The props.0 & !0x2000 mask in the root-descriptor match keeps the 0x100B and (Uav, 11) arms matching. The non-POPS path is unchanged, and the test asserts rovs == false for it. No problems found.

AI-assisted (Claude Code / Claude Sonnet 5.5)

<!-- greyfinch-sync:Marvisak/VIctory:review:6060181085 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2490#pullrequestreview-6060181085). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T15:08:46Z. **Review:** COMMENTED --- Independent verification on Windows, `VICTORY_D3D12_WARP=1` (WARP only, no hardware GPU touched). Tested commit `d8e54fd834998271d3e6e315b8fe2a312519e32e` (clean detached checkout). - `cargo test -p victory-shader --locked --lib pops_pixel_shader_lowers_root_uav` — 1 passed, 0 failed, 0 ignored. - Mutation check: with the `if self.pops` branch in `root_view` forced off, the same test fails (panic at the first `l.rovs` assert), so it guards the change. - `cargo test -p victory-shader --locked --lib` — 248 passed, 0 failed, 3 ignored (the ignored ones are pre-existing). Code read: `root_view(.., uav=true)` now sets `flags::ROVS` and `0x2000` under POPS. This covers the `global_load` route, where `handle()` sees `props.0 == 11` without `0x1000` and so never adds the ROV bit itself. The `props.0 & !0x2000` mask in the root-descriptor match keeps the `0x100B` and `(Uav, 11)` arms matching. The non-POPS path is unchanged, and the test asserts `rovs == false` for it. No problems found. AI-assisted (Claude Code / Claude Sonnet 5.5)
Marvisak commented 2026-11-25 16:09:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:58:17Z.


Automated triage for the maintainers.

Needs work: CI fails. Thanks for the rebase and the root_memory change. The logic reads right. classify_root_descriptor in crates/victory-shader/src/emit/lower.rs accepts the ROV bit (0x2000) only on the !root_memory view arms. With root_memory, POPS root UAVs stay refused instead of becoming unordered root_uav_handles. root_view sets flags::ROVS and 0x300B for POPS.

However, the check run on f11c1b4 fails xtask policy::tests::repository_passes_policy: crates/victory-shader/src/emit/lower.rs: 526918 bytes exceeds the 524288-byte limit. The ~160-line test pushes the file over the policy's size cap. Please move pops_pixel_shader_lowers_root_uav_accesses_as_rovs (and, if needed, RootBinding/classify_root_descriptor) into a separate file, for example a #[cfg(test)] module next to lower.rs. Do not change xtask/src/policy.rs. With CI green this would be back to a merge candidate.

CI: failing (asset policy size limit).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167475928 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2490#issuecomment-7167475928). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:58:17Z. --- <!-- victory-triage v1 head=f11c1b43ea4604d921bebee2fbe474a99b924d32 verdict=needs-work at=2026-11-26T07:22:21Z --> Automated triage for the maintainers. **Needs work: CI fails.** Thanks for the rebase and the `root_memory` change. The logic reads right. `classify_root_descriptor` in `crates/victory-shader/src/emit/lower.rs` accepts the ROV bit (`0x2000`) only on the `!root_memory` view arms. With `root_memory`, POPS root UAVs stay refused instead of becoming unordered `root_uav_handle`s. `root_view` sets `flags::ROVS` and `0x300B` for POPS. However, the `check` run on `f11c1b4` fails `xtask` `policy::tests::repository_passes_policy`: `crates/victory-shader/src/emit/lower.rs: 526918 bytes exceeds the 524288-byte limit`. The ~160-line test pushes the file over the policy's size cap. Please move `pops_pixel_shader_lowers_root_uav_accesses_as_rovs` (and, if needed, `RootBinding`/`classify_root_descriptor`) into a separate file, for example a `#[cfg(test)]` module next to `lower.rs`. Do not change `xtask/src/policy.rs`. With CI green this would be back to a merge candidate. CI: failing (asset policy size limit). --- _Generated by [Claude Code](https://claude.ai/code)_
reeledMarek commented 2026-11-25 20:06:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T20:05:17Z.


Updated to address the triage feedback:

  • Restricted the 0x2000 ROV bit mask to the !self.root_memory arms via classify_root_descriptor, keeping self.root_memory + POPS root UAV refused (Err("a root UAV or typed root view")) instead of silently lowering to an unordered Shader::root_uav_handle.
  • Added unit test assertions covering root_memory = true (both POPS refused and non-POPS allowed) alongside root_memory = false.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7173172919 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2490#issuecomment-7173172919). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-25T20:05:17Z. --- Updated to address the triage feedback: - Restricted the `0x2000` ROV bit mask to the `!self.root_memory` arms via `classify_root_descriptor`, keeping `self.root_memory` + POPS root UAV refused (`Err("a root UAV or typed root view")`) instead of silently lowering to an unordered `Shader::root_uav_handle`. - Added unit test assertions covering `root_memory = true` (both POPS refused and non-POPS allowed) alongside `root_memory = false`.
reeledMarek commented 2026-11-26 06:03:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-26T05:55:59Z.


Rebased cleanly onto current main (63bcca4) and verified cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings passes.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7183936057 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2490#issuecomment-7183936057). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-26T05:55:59Z. --- Rebased cleanly onto current `main` (`63bcca4`) and verified `cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings` passes.
reeledMarek commented 2026-11-26 11:04:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-26T10:21:14Z.


Moved pops_pixel_shader_lowers_root_uav_accesses_as_rovs into crates/victory-shader/src/emit/lower/pops_tests.rs (#[cfg(test)] mod pops_tests;) so lower.rs stays well below the 512 KiB asset-policy file size cap. Verified cargo test -p xtask --locked (6/6 passed) and Windows cross-clippy (-D warnings).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7189252319 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2490#issuecomment-7189252319). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-26T10:21:14Z. --- Moved `pops_pixel_shader_lowers_root_uav_accesses_as_rovs` into `crates/victory-shader/src/emit/lower/pops_tests.rs` (`#[cfg(test)] mod pops_tests;`) so `lower.rs` stays well below the 512 KiB asset-policy file size cap. Verified `cargo test -p xtask --locked` (6/6 passed) and Windows cross-clippy (`-D warnings`).
cloph-dsp commented 2026-11-27 02:32:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-27T02:32:25Z.


Independent CPU-only verification on Windows (Rust 1.100.0/MSVC, worktree-local CARGO_TARGET_DIR, CARGO_BUILD_JOBS=2, no game data).

  • PR head a4f4c72, merge base 63bcca4.
  • cargo test --locked -p victory-shader --lib -- emit::lower::pops_tests::pops_pixel_shader_lowers_root_uav_accesses_as_rovs --exact --test-threads=1 --quiet -> test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 305 filtered out.
  • Note: the bare test name matches 0 tests; the module-qualified name is required.
  • git diff --check 63bcca4 HEAD -> exit 0.
  • Negative control: new test name absent from 63bcca4 (git grep -c ... crates/victory-shader/src/emit/lower/pops_tests.rs -> exit 1).

Only the named synthetic IR-lowering test was replayed; the full crate suite was not run. GPU/driver: N/A (CPU-only lowering test). AI-assisted (Hy4 flash). No game data, assets, extracted shaders or DRM involved.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7208217340 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2490#issuecomment-7208217340). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-27T02:32:25Z. --- Independent CPU-only verification on Windows (Rust 1.100.0/MSVC, worktree-local `CARGO_TARGET_DIR`, `CARGO_BUILD_JOBS=2`, no game data). - PR head `a4f4c72`, merge base `63bcca4`. - `cargo test --locked -p victory-shader --lib -- emit::lower::pops_tests::pops_pixel_shader_lowers_root_uav_accesses_as_rovs --exact --test-threads=1 --quiet` -> `test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 305 filtered out`. - Note: the bare test name matches 0 tests; the module-qualified name is required. - `git diff --check 63bcca4 HEAD` -> exit 0. - Negative control: new test name absent from `63bcca4` (`git grep -c ... crates/victory-shader/src/emit/lower/pops_tests.rs` -> exit 1). Only the named synthetic IR-lowering test was replayed; the full crate suite was not run. GPU/driver: N/A (CPU-only lowering test). AI-assisted (Hy4 flash). No game data, assets, extracted shaders or DRM involved.
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/2490:upstream-pr/2490'
git switch 'upstream-pr/2490'

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/2490'
git switch 'upstream-pr/2490'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2490'
git switch 'upstream-pr/2490'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2490'
git switch 'main'
git merge --squash 'upstream-pr/2490'
git switch 'main'
git merge --ff-only 'upstream-pr/2490'
git switch 'main'
git merge 'upstream-pr/2490'
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
Marvisak/VIctory!2488
No description provided.