GPU: variable-rate shading (RSSetShadingRate) reaches the host #3511

Open
alexandruiulian201-bot wants to merge 1 commit from upstream-pr/3511 into main
alexandruiulian201-bot commented 2026-11-27 11:56:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by alexandruiulian201-bot on 2026-11-27T11:56:25Z.


## Summary

Forwards the title's RSSetShadingRate command (console command-list slot 124: 0x3e0 in the older layout, 0x3f0 in the newer layout via newer_slot) to host D3D12 (ID3D12GraphicsCommandList5::RSSetShadingRate), following the same capability-query and state-replay structure as depth bounds (#158).

Changes

  • crates/victory-gpu/src/host.rs:
    • Queries D3D12_FEATURE_D3D12_OPTIONS6 (VariableShadingRateTier and AdditionalShadingRatesSupported) during host device creation.
    • Queries Option<ID3D12GraphicsCommandList5> onto HostList when VariableShadingRateTier != NOT_SUPPORTED.
    • Adds one-time warnings for unsupported adapters, invalid shading rates, and invalid combiners.
  • crates/victory-gpu/src/list.rs:
    • Adds cross-platform sanitize_shading_rate:
      • Tier 0: returns None (no host call).
      • Standard rates (1x1, 1x2, 2x1, 2x2): forwarded directly.
      • Additional 4x rates (2x4, 4x2, 4x4): forwarded when AdditionalShadingRatesSupported is true, clamped conservatively to 2x2 otherwise.
      • Unknown base rates: fall back to 1x1 (0x0) and flag a one-time warning.
      • Tier 1: drops combiners to None (D3D12 Tier 1 forbids non-passthrough combiners).
      • Tier 2: validates each combiner in 0..=4 (PASSTHROUGH..=SUM), falling back to PASSTHROUGH (0) on out-of-range values with a one-time warning.
    • Implements extern "system" fn shading_rate and wires slot 124 in both layouts (0x3e0 / 0x3f0).
    • Adds unit tests for tier/input sanitization and both vtable slots.
  • crates/victory-gpu/src/draw.rs:
    • Tracks shading_rate: Option<(u32, Option<[u32; 2]>)> on draw::State (reset to None on State::reset).
    • Applies it immediately on set_shading_rate, replays it across segment splits in State::cut(), and reapplies it after graphics SetPipelineState in State::bind() (covering indirect-clamp pipeline invalidation and host_state_lost).
  • crates/victory-gpu/src/pipeline/shading_rate_test.rs & crates/victory-gpu/src/pipeline.rs:
    • Adds a synthetic D3D12 render + readback test (HLSL compiled via D3DCompile, no game assets) exercising title command-list entry points (0x3e0/0x3f0, 0xb0, 0x60, 0x50) across fresh 1x1, 2x2, 2x1, 1x2 ([PASSTHROUGH, PASSTHROUGH]), non-passthrough combiner [PASSTHROUGH, MAX], invalid base rate 0x7 -> 1x1, 4x4 (0xA) when AdditionalShadingRatesSupported is true, Tier 0 fallback, and Reset restoring 1x1.

Out of scope

  • RSSetShadingRateImage is intentionally left unmapped until its console vtable slot is confirmed.

Verification

All tests use synthetic shaders and targets only (no game files).

  • cargo test --locked -p victory-gpu --lib -- shading_rate --nocapture --test-threads=1 on NVIDIA GeForce GTX 1070 (tier=0, additional=false): 3 passed, 0 failed (verifies clean Tier 0 fallback).
  • VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test --locked -p victory-gpu --features diagnostics --lib -- shading_rate --nocapture --test-threads=1 on Microsoft Basic Render Driver (WARP) (tier=1, additional=true): 3 passed, 0 failed with zero D3D12 debug layer errors (verifies real 2x2, 2x1, 1x2, 4x4 coarse rasterization, Tier 1 combiner stripping, invalid-rate fallback, and Reset restoring 1x1).
  • cargo clippy --workspace --all-targets --locked -- -D warnings: pass
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: pass
  • cargo run -p xtask --locked -- policy: asset policy: 192 files ok
  • Tier 2 hardware was not available locally; Tier 2 combiner validation is covered by unit tests in list::tests::sanitize_shading_rate_enforces_tier_and_validates_inputs.

Disclosure

This PR was developed with AI assistance and manually reviewed and verified against live D3D12 (GTX 1070 + WARP with the D3D12 Debug Layer) using synthetic tests only.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5526204839 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3511). Originally posted by [alexandruiulian201-bot](https://github.com/alexandruiulian201-bot) on 2026-11-27T11:56:25Z. --- ## Summary Forwards the title's `RSSetShadingRate` command (console command-list slot `124`: `0x3e0` in the older layout, `0x3f0` in the newer layout via `newer_slot`) to host D3D12 (`ID3D12GraphicsCommandList5::RSSetShadingRate`), following the same capability-query and state-replay structure as depth bounds (#158). ## Changes - **`crates/victory-gpu/src/host.rs`**: - Queries `D3D12_FEATURE_D3D12_OPTIONS6` (`VariableShadingRateTier` and `AdditionalShadingRatesSupported`) during host device creation. - Queries `Option<ID3D12GraphicsCommandList5>` onto `HostList` when `VariableShadingRateTier != NOT_SUPPORTED`. - Adds one-time warnings for unsupported adapters, invalid shading rates, and invalid combiners. - **`crates/victory-gpu/src/list.rs`**: - Adds cross-platform `sanitize_shading_rate`: - Tier 0: returns `None` (no host call). - Standard rates (`1x1`, `1x2`, `2x1`, `2x2`): forwarded directly. - Additional 4x rates (`2x4`, `4x2`, `4x4`): forwarded when `AdditionalShadingRatesSupported` is true, clamped conservatively to `2x2` otherwise. - Unknown base rates: fall back to `1x1` (`0x0`) and flag a one-time warning. - Tier 1: drops combiners to `None` (D3D12 Tier 1 forbids non-passthrough combiners). - Tier 2: validates each combiner in `0..=4` (`PASSTHROUGH..=SUM`), falling back to `PASSTHROUGH` (`0`) on out-of-range values with a one-time warning. - Implements `extern "system" fn shading_rate` and wires slot `124` in both layouts (`0x3e0` / `0x3f0`). - Adds unit tests for tier/input sanitization and both vtable slots. - **`crates/victory-gpu/src/draw.rs`**: - Tracks `shading_rate: Option<(u32, Option<[u32; 2]>)>` on `draw::State` (reset to `None` on `State::reset`). - Applies it immediately on `set_shading_rate`, replays it across segment splits in `State::cut()`, and reapplies it after graphics `SetPipelineState` in `State::bind()` (covering indirect-clamp pipeline invalidation and `host_state_lost`). - **`crates/victory-gpu/src/pipeline/shading_rate_test.rs` & `crates/victory-gpu/src/pipeline.rs`**: - Adds a synthetic D3D12 render + readback test (HLSL compiled via `D3DCompile`, no game assets) exercising title command-list entry points (`0x3e0`/`0x3f0`, `0xb0`, `0x60`, `0x50`) across fresh `1x1`, `2x2`, `2x1`, `1x2` (`[PASSTHROUGH, PASSTHROUGH]`), non-passthrough combiner `[PASSTHROUGH, MAX]`, invalid base rate `0x7 -> 1x1`, `4x4` (`0xA`) when `AdditionalShadingRatesSupported` is true, Tier 0 fallback, and `Reset` restoring `1x1`. ## Out of scope - `RSSetShadingRateImage` is intentionally left unmapped until its console vtable slot is confirmed. ## Verification All tests use synthetic shaders and targets only (no game files). - `cargo test --locked -p victory-gpu --lib -- shading_rate --nocapture --test-threads=1` on **NVIDIA GeForce GTX 1070** (`tier=0, additional=false`): **3 passed, 0 failed** (verifies clean Tier 0 fallback). - `VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test --locked -p victory-gpu --features diagnostics --lib -- shading_rate --nocapture --test-threads=1` on **Microsoft Basic Render Driver (WARP)** (`tier=1, additional=true`): **3 passed, 0 failed** with zero D3D12 debug layer errors (verifies real `2x2`, `2x1`, `1x2`, `4x4` coarse rasterization, Tier 1 combiner stripping, invalid-rate fallback, and `Reset` restoring `1x1`). - `cargo clippy --workspace --all-targets --locked -- -D warnings`: pass - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: pass - `cargo run -p xtask --locked -- policy`: `asset policy: 192 files ok` - Tier 2 hardware was not available locally; Tier 2 combiner validation is covered by unit tests in `list::tests::sanitize_shading_rate_enforces_tier_and_validates_inputs`. ## Disclosure This PR was developed with AI assistance and manually reviewed and verified against live D3D12 (GTX 1070 + WARP with the D3D12 Debug Layer) using synthetic tests only.
andrewpozdnakov7-jpg commented 2026-11-27 12:44:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T12:44:30Z.


Tier 2 and the additional-rate flag still leave SUM conditional on D3D12_OPTIONS10.VariableRateShadingSumCombinerSupported. The sanitizer on 5ad4a02 accepts [MAX, SUM] for any Tier 2 host. D3D12 capability definition

Follow-up 3a9b480 reads OPTIONS10 once at host creation and passes the capability to the draw-state sanitizer. If the query fails or the capability is false, each SUM uses the existing PASSTHROUGH fallback. The CPU regression covers both combiner positions, both capability values, and independent additional-rate support.

All four shading-rate tests pass on the final commit. App-local WARP 1.0.22 with Agility 1.620.2 reports Tier 2, additional rates and SUM support. The GPU readback includes [PASSTHROUGH, SUM] and shows the four pixels sharing the requested 2x2 rate. Strict Clippy passes both configurations and the asset policy check passes.

One other result from this WARP build is worth checking on hardware. I cleared the same target and tested both the guest entry point and a direct native RSSetShadingRate call. Both paths wrote 4/4 pixels with [PASSTHROUGH, SUM], [PASSTHROUGH, MAX] and [PASSTHROUGH, PASSTHROUGH]. Both left the clear value in all four positions when SUM occupied the first combiner. A physical Tier 2 run with the capability reported by OPTIONS10 would clarify that result.

Please retain the Git author if taking the commit. If folding it into another commit, please add Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.

AI-assisted with OpenAI Codex. Synthetic targets and shaders.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7218617551 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3511#issuecomment-7218617551). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T12:44:30Z. --- Tier 2 and the additional-rate flag still leave `SUM` conditional on `D3D12_OPTIONS10.VariableRateShadingSumCombinerSupported`. The sanitizer on `5ad4a02` accepts `[MAX, SUM]` for any Tier 2 host. [D3D12 capability definition](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_feature_data_d3d12_options10) [Follow-up `3a9b480`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/3a9b48069a2c7fd043ad136bc289fabe7531860b) reads OPTIONS10 once at host creation and passes the capability to the draw-state sanitizer. If the query fails or the capability is false, each `SUM` uses the existing `PASSTHROUGH` fallback. The CPU regression covers both combiner positions, both capability values, and independent additional-rate support. All four shading-rate tests pass on the final commit. App-local WARP 1.0.22 with Agility 1.620.2 reports Tier 2, additional rates and SUM support. The GPU readback includes `[PASSTHROUGH, SUM]` and shows the four pixels sharing the requested 2x2 rate. Strict Clippy passes both configurations and the asset policy check passes. One other result from this WARP build is worth checking on hardware. I cleared the same target and tested both the guest entry point and a direct native `RSSetShadingRate` call. Both paths wrote 4/4 pixels with `[PASSTHROUGH, SUM]`, `[PASSTHROUGH, MAX]` and `[PASSTHROUGH, PASSTHROUGH]`. Both left the clear value in all four positions when `SUM` occupied the first combiner. A physical Tier 2 run with the capability reported by OPTIONS10 would clarify that result. Please retain the Git author if taking the commit. If folding it into another commit, please add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`. AI-assisted with OpenAI Codex. Synthetic targets and shaders.
UncommonDLL commented 2026-11-27 13:39:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by UncommonDLL on 2026-11-27T13:39:36Z.


We tested your 3a9b480 follow-up on a physical RTX 5070 Ti with driver 621.40. The device reported VRS Tier 2 and OPTIONS10 SUM support. With SUM in either combiner position, both the guest setter and native RSSetShadingRate wrote [1, 1, 0, 1] to all four pixels. The pixel outside the draw kept its clear value. The MAX and passthrough controls matched. A second process reproduced the result, with no skips.

First-position SUM drew on this setup. The other rate inputs were at their defaults, so the result leaves SUM arithmetic open. OpenAI Codex helped extend and run the synthetic fixture. Claude Sonnet 5.5 reviewed the interpretation.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7219772500 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3511#issuecomment-7219772500). Originally posted by [UncommonDLL](https://github.com/UncommonDLL) on 2026-11-27T13:39:36Z. --- We tested your `3a9b480` follow-up on a physical RTX 5070 Ti with driver 621.40. The device reported VRS Tier 2 and OPTIONS10 SUM support. With SUM in either combiner position, both the guest setter and native `RSSetShadingRate` wrote `[1, 1, 0, 1]` to all four pixels. The pixel outside the draw kept its clear value. The MAX and passthrough controls matched. A second process reproduced the result, with no skips. First-position SUM drew on this setup. The other rate inputs were at their defaults, so the result leaves SUM arithmetic open. OpenAI Codex helped extend and run the synthetic fixture. Claude Sonnet 5.5 reviewed the interpretation.
ColorMeBoom commented 2026-11-27 15:03:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-27T15:03:54Z.


Tier 0 host: RX 5700 XT (RDNA1, no variable-rate shading), driver 32.0.21045.29003, Windows 11 26200, Rust 1.98.1. Head 5ad4a02 merged onto main 63bcca4, native adapter, no game files. The run above is a Tier 2 card, so this covers the other branch of shading_rate_controls_coarse_pixel_rasterization.

  • The render test reports shading rate on AMD Radeon RX 5700 XT: tier=0, additional=false and passes on the Tier 0 path. With a 2x2 rate set, the quadrants still rasterize at 1x1 (distinct X and Y per pixel), and the reset and invalid-rate passes match. HostList gets no ID3D12GraphicsCommandList5 there, and the guest's RSSetShadingRate is dropped without error.
  • sanitize_shading_rate_enforces_tier_and_validates_inputs and shading_rate_slot_is_wired_in_both_layouts pass.
  • Full victory-gpu lib suite: 234 passed, 0 failed, 1 ignored.

I didn't run @andrewpozdnakov7-jpg's 3a9b480 follow-up. It only changes the Tier 2 SUM-combiner check, which this card never reaches.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7221578193 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3511#issuecomment-7221578193). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-27T15:03:54Z. --- **Tier 0 host: RX 5700 XT** (RDNA1, no variable-rate shading), driver 32.0.21045.29003, Windows 11 26200, Rust 1.98.1. Head `5ad4a02` merged onto `main` `63bcca4`, native adapter, no game files. The run above is a Tier 2 card, so this covers the other branch of `shading_rate_controls_coarse_pixel_rasterization`. - The render test reports `shading rate on AMD Radeon RX 5700 XT: tier=0, additional=false` and **passes on the Tier 0 path**. With a 2x2 rate set, the quadrants still rasterize at 1x1 (distinct X and Y per pixel), and the reset and invalid-rate passes match. `HostList` gets no `ID3D12GraphicsCommandList5` there, and the guest's `RSSetShadingRate` is dropped without error. - `sanitize_shading_rate_enforces_tier_and_validates_inputs` and `shading_rate_slot_is_wired_in_both_layouts` pass. - Full `victory-gpu` lib suite: **234 passed, 0 failed, 1 ignored**. I didn't run @andrewpozdnakov7-jpg's `3a9b480` follow-up. It only changes the Tier 2 SUM-combiner check, which this card never reaches. AI use: Claude Code (Claude Opus 5.5).
passerbyyhx commented 2026-11-27 18:56:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by passerbyyhx on 2026-11-27T18:56:54Z.


Windows synthetic verification at 5ad4a021e58ff28539aa76713ca1f22c04af7d62.

I checked the command-list boundaries with a 4×4 position-color render target on RTX 4090 Laptop (621.14, Tier 2, 16-pixel tiles, additional rates and OPTIONS10 SUM supported), with a WARP comparison. On the 4090 the cut retained horizontal 2×1 shading. Forcing native 1×1 after the cut gave 16 distinct pixels without rebinding; replaying the production bind restored the 2×2 pattern. A guest Reset returned to 16 distinct 1×1 pixels. The parent 63bcca43c6a00a758510398fa43096ce7e4f7df0 returned distinct pixels.

With default 1×1 secondary inputs the two MIN positions gave 1×1, and MAX produced 2×2. The SUM cases cover this SUM-capable adapter only. Head render cases 3/3 on both adapters. A separate known descriptor-heap size probe emitted diagnostic 645 during 4090 setup and fell back successfully. The subsequent measured VRS operations had zero debug errors.

Reproducible fixture. GTA-VI-3/EIGHT-20261127. AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7226033853 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3511#issuecomment-7226033853). Originally posted by [passerbyyhx](https://github.com/passerbyyhx) on 2026-11-27T18:56:54Z. --- Windows synthetic verification at `5ad4a021e58ff28539aa76713ca1f22c04af7d62`. I checked the command-list boundaries with a 4×4 position-color render target on RTX 4090 Laptop (621.14, Tier 2, 16-pixel tiles, additional rates and OPTIONS10 SUM supported), with a WARP comparison. On the 4090 the cut retained horizontal 2×1 shading. Forcing native 1×1 after the cut gave 16 distinct pixels without rebinding; replaying the production bind restored the 2×2 pattern. A guest Reset returned to 16 distinct 1×1 pixels. The parent `63bcca43c6a00a758510398fa43096ce7e4f7df0` returned distinct pixels. With default 1×1 secondary inputs the two MIN positions gave 1×1, and MAX produced 2×2. The SUM cases cover this SUM-capable adapter only. Head render cases 3/3 on both adapters. A separate known descriptor-heap size probe emitted diagnostic 645 during 4090 setup and fell back successfully. The subsequent measured VRS operations had zero debug errors. [Reproducible fixture](https://github.com/passerbyyhx/VIctory/commit/40bcd0fbffbf19a7e0f3342c4e5f6638d83d6e31). GTA-VI-3/EIGHT-20261127. AI-assisted with Codex.
passerbyyhx commented 2026-11-27 19:10:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by passerbyyhx on 2026-11-27T19:10:56Z.


Follow-up to the command-list tests on 5ad4a021e58ff28539aa76713ca1f22c04af7d62. The earlier fixture used default 1×1 secondary inputs. This run supplies 2×1 per primitive from the vertex shader and 1×2 from a single R8_UINT shading-rate tile, with a 1×1 base rate. The guest sets the combiners. The tile is bound through the native D3D12 list; the guest shading-rate image entry point is outside this test.

Primitive combiner Image combiner Measured pixel group
PASSTHROUGH PASSTHROUGH 1×1
OVERRIDE PASSTHROUGH 2×1
PASSTHROUGH OVERRIDE 1×2
MAX MAX 2×2
Guest Reset after MAX/MAX, same VS and host image supplied again, no rate setter 1×1

All five draws matched the expected grouping for all 16 pixels of the 4×4 position-color target. RTX 4090 Laptop, driver 621.14, Tier 2, tile size 16, LUID 00000000:0001c903. The debug layer reported zero draw errors; the previously recorded descriptor-heap setup probe 645 was counted separately.

Fixture and reproduction command. AU-20261127-08X. AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7226270972 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3511#issuecomment-7226270972). Originally posted by [passerbyyhx](https://github.com/passerbyyhx) on 2026-11-27T19:10:56Z. --- Follow-up to [the command-list tests](https://github.com/Marvisak/VIctory/pull/3511#issuecomment-7226033853) on `5ad4a021e58ff28539aa76713ca1f22c04af7d62`. The earlier fixture used default 1×1 secondary inputs. This run supplies **2×1 per primitive** from the vertex shader and **1×2 from a single R8_UINT shading-rate tile**, with a 1×1 base rate. The guest sets the combiners. The tile is bound through the native D3D12 list; the guest shading-rate image entry point is outside this test. | Primitive combiner | Image combiner | Measured pixel group | | --- | --- | --- | | PASSTHROUGH | PASSTHROUGH | 1×1 | | OVERRIDE | PASSTHROUGH | 2×1 | | PASSTHROUGH | OVERRIDE | 1×2 | | MAX | MAX | 2×2 | | Guest Reset after MAX/MAX, same VS and host image supplied again, no rate setter | | 1×1 | All five draws matched the expected grouping for all 16 pixels of the 4×4 position-color target. RTX 4090 Laptop, driver 621.14, Tier 2, tile size 16, LUID `00000000:0001c903`. The debug layer reported zero draw errors; the previously recorded descriptor-heap setup probe 645 was counted separately. [Fixture and reproduction command](https://github.com/passerbyyhx/VIctory/tree/b7b5dda6fb6f04c9557908bc84ffb862d32ddf0d/tests/fixtures/vrs-independent-inputs). AU-20261127-08X. AI-assisted with Codex.
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/3511:upstream-pr/3511'
git switch 'upstream-pr/3511'

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