Shaders: lower SV_RenderTargetArrayIndex and SV_ViewportArrayIndex exports #1416

Closed
fuzeofficlal wants to merge 1 commit from upstream-pr/1417 into main
fuzeofficlal commented 2026-11-24 17:54:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T17:54:16Z.


Fixes #914.

Summary

  • Unpack SV_RenderTargetArrayIndex (bits 0..15, kind == 4) and SV_ViewportArrayIndex (bits 16..31, kind == 5) from RDNA2's exp pos1.z misc vector when declared in the output signature.
  • Shift SV_ClipDistance and SV_CullDistance exports to pos2..=pos3 whenever the misc vector is present (first_clip = 2).
  • Mark both semantics Constant (interp = 1) in signatures and set DXIL VIEWPORT_RT_INDEX (ShaderFlags bit 9, SFI0 0x2000) for non-mesh rasterizer stages.

Verification

  • Added end-to-end VS -> PS multi-slice Texture2DArray RTV + dual-viewport draw readback tests covering standalone RTAI, standalone VPAI, packed RTAI + VPAI + shifted SV_ClipDistance0 (+1.0 pass / -1.0 clipped):
    • dxil.dll validation: passed
    • NVIDIA GeForce RTX 5090: passed
    • AMD Radeon(TM) Graphics: passed
    • Microsoft D3D12 WARP: passed
  • cargo clippy --workspace --all-features and cargo xtask policy: passed.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6588062789 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1417). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-24T17:54:16Z. --- Fixes #914. ### Summary - Unpack `SV_RenderTargetArrayIndex` (`bits 0..15`, `kind == 4`) and `SV_ViewportArrayIndex` (`bits 16..31`, `kind == 5`) from RDNA2's `exp pos1.z` misc vector when declared in the output signature. - Shift `SV_ClipDistance` and `SV_CullDistance` exports to `pos2..=pos3` whenever the misc vector is present (`first_clip = 2`). - Mark both semantics `Constant` (`interp = 1`) in signatures and set DXIL `VIEWPORT_RT_INDEX` (`ShaderFlags` bit 9, `SFI0` `0x2000`) for non-mesh rasterizer stages. ### Verification - Added end-to-end VS -> PS multi-slice `Texture2DArray` RTV + dual-viewport draw readback tests covering standalone `RTAI`, standalone `VPAI`, packed `RTAI + VPAI + shifted SV_ClipDistance0` (`+1.0` pass / `-1.0` clipped): - `dxil.dll` validation: passed - **NVIDIA GeForce RTX 5090**: passed - **AMD Radeon(TM) Graphics**: passed - **Microsoft D3D12 WARP**: passed - `cargo clippy --workspace --all-features` and `cargo xtask policy`: passed.
geiyiliyabumo commented 2026-11-24 18:06:04 +00:00 (Migrated from github.com)

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


Independent verification of \3296002\ on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200) / Rust 1.98.1 MSVC:

  • Merge check vs \main\ (\ fe310e): clean
  • \cargo test -p victory-shader --lib valu_tests\ (real RX 9060 XT GPU execution): 14 passed, 0 failed
  • \cargo clippy -p victory-shader --all-targets -- -D warnings\ (default and --all-features): clean
  • \cargo xtask policy: 154 files ok

AI-assisted; synthetic tests only, no game files.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139998835 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1417#issuecomment-7139998835). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T17:59:32Z. --- Independent verification of \3296002\ on **Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200\) / Rust 1.98.1 MSVC**: - Merge check vs \main\ (\ fe310e\): clean - \cargo test -p victory-shader --lib valu_tests\ (real RX 9060 XT GPU execution): **14 passed, 0 failed** - \cargo clippy -p victory-shader --all-targets -- -D warnings\ (default and \--all-features\): clean - \cargo xtask policy\: 154 files ok *AI-assisted; synthetic tests only, no game files.*
catminou4 commented 2026-11-24 20:02:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T19:25:08Z.

Review: COMMENTED


Static review only — this is a large change (host.rs test infrastructure enumerating all SM 6.6 adapters, MRT draw support, SV_RenderTargetArrayIndex/SV_ViewportArrayIndex exports packed into bits 0..15/16..31 of a system value) and none of it can run on macOS: cargo test -p victory-shader --locked stays at 96 passed with no new coverage here. The packing matches the D3D12 semantic (two independent 16-bit fields) and the feature check gates on D3D12_OPTIONS support, which is the right call. Before merge I'd want: (1) the Windows CI leg green on the new adapter-enumeration tests, (2) at least one hardware run of the MRT/array-index cases (WARP may not exercise the SV path the same way), and (3) a note on how this interacts with the mesh pipeline linking work in #1563 (both touch export/system-value plumbing).

<!-- greyfinch-sync:Marvisak/VIctory:review:6045878116 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1417#pullrequestreview-6045878116). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T19:25:08Z. **Review:** COMMENTED --- Static review only — this is a large change (host.rs test infrastructure enumerating all SM 6.6 adapters, MRT draw support, `SV_RenderTargetArrayIndex`/`SV_ViewportArrayIndex` exports packed into bits 0..15/16..31 of a system value) and none of it can run on macOS: `cargo test -p victory-shader --locked` stays at 96 passed with no new coverage here. The packing matches the D3D12 semantic (two independent 16-bit fields) and the feature check gates on `D3D12_OPTIONS` support, which is the right call. Before merge I'd want: (1) the Windows CI leg green on the new adapter-enumeration tests, (2) at least one hardware run of the MRT/array-index cases (WARP may not exercise the SV path the same way), and (3) a note on how this interacts with the mesh pipeline linking work in #1563 (both touch export/system-value plumbing).
sinan-cmyk commented 2026-11-24 21:03:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T20:44:02Z.


Offline measurement on a retail dump, and the shader tests on Ada

Result: no count change against main.

Offline. I merged head 3296002 onto main ffe310e (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 on main, 21,724 with this PR.

No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on main. The count shows that the change rejects nothing. It does not show whether the output is right.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 121, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143984086 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1417#issuecomment-7143984086). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T20:44:02Z. --- ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head 3296002 onto `main` ffe310e (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 21,724 on `main`, 21,724 with this PR. No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on `main`. The count shows that the change rejects nothing. It does not show whether the output is right. **Tests:** with the same merge, `cargo test --locked -p victory-shader --lib` passed 121, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Marvisak commented 2026-11-25 02:06:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:26:43Z.


Automated triage for the maintainers.

Merge candidate. It now merges cleanly with main. Main refused vertex-stage exports of SV_RenderTargetArrayIndex/SV_ViewportArrayIndex ("render-target or viewport index exports"). emit/lower.rs now takes them from the misc vector exp pos1.z (layer in the low 16 bits, viewport index in the high 16) and shifts clip/cull distances to pos2..pos3 when that vector is present. emit/mod.rs and shader.rs mark both semantics constant-interpolated and set the VIEWPORT_RT_INDEX shader flag. The misc-vector packing and the position-export shift match what Mesa's public RDNA export code does, and other channels of pos1 (point size) are still refused rather than guessed. The tests draw into a Texture2DArray with two viewports and read back each slice. The new HostDevice::adapters enumeration is test-only.

CI: passing (check).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149553123 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1417#issuecomment-7149553123). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:26:43Z. --- <!-- victory-triage v1 head=07567747c5d458ef18c5f35ca30153e858d2b590 verdict=merge-candidate at=2026-11-25T06:35:00Z --> Automated triage for the maintainers. **Merge candidate.** It now merges cleanly with `main`. Main refused vertex-stage exports of `SV_RenderTargetArrayIndex`/`SV_ViewportArrayIndex` ("render-target or viewport index exports"). `emit/lower.rs` now takes them from the misc vector `exp pos1.z` (layer in the low 16 bits, viewport index in the high 16) and shifts clip/cull distances to `pos2..pos3` when that vector is present. `emit/mod.rs` and `shader.rs` mark both semantics constant-interpolated and set the `VIEWPORT_RT_INDEX` shader flag. The misc-vector packing and the position-export shift match what Mesa's public RDNA export code does, and other channels of `pos1` (point size) are still refused rather than guessed. The tests draw into a `Texture2DArray` with two viewports and read back each slice. The new `HostDevice::adapters` enumeration is test-only. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-25 23:02:48 +00:00
Marvisak commented 2026-11-25 23:06:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:12:52Z.


Automated triage for the maintainers, second look (a review against current main, with builds and tests where they could change the verdict).

Closing because it does not translate what the console compiler emits. Two vertex shaders writing SV_RenderTargetArrayIndex (one also SV_ViewportArrayIndex and a clip distance), compiled with the console compiler, pack (viewport << 16) | layer into pos1.z as assumed here, but export pos1 with all four channels enabled (zeros in x, y and w). The Target::Position(1) if has_misc arm refuses any channel but z, so both containers still fail with this PR; only the refusal reason changes. The GPU test passes because it hand-writes an export with only z enabled. No title program reaches this path on main.

If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7176080190 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1417#issuecomment-7176080190). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T22:12:52Z. --- Automated triage for the maintainers, second look (a review against current `main`, with builds and tests where they could change the verdict). Closing because it does not translate what the console compiler emits. Two vertex shaders writing `SV_RenderTargetArrayIndex` (one also `SV_ViewportArrayIndex` and a clip distance), compiled with the console compiler, pack `(viewport << 16) | layer` into pos1.z as assumed here, but export pos1 with all four channels enabled (zeros in x, y and w). The `Target::Position(1) if has_misc` arm refuses any channel but z, so both containers still fail with this PR; only the refusal reason changes. The GPU test passes because it hand-writes an export with only z enabled. No title program reaches this path on `main`. If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.
andrewpozdnakov7-jpg commented 2026-11-26 03:05:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T03:01:05Z.


I reproduced the full-mask case from the closing review with a synthetic vertex shader. The fixture enables all four pos1 channels and writes (0, 0, packed, 0). On 2a60d82, translation stops at that export with the clip, cull or point-size error.

f7c2aac extends that exact head and keeps its Git author. It accepts the other enabled channels only when proven zero. The same test still rejects a nonzero constant and an unknown vertex input in those channels.

Six paired Windows/WARP runs agreed. The patched shader draws into slice 2/viewport 0 for layer only, slice 0/viewport 1 for viewport only, and slice 1/viewport 1 for both. A negative clip distance still leaves all slices clear. The same test passes with the branch merged onto 63bcca4. The VALU, semantics and lowerer suites and strict shader Clippy passed.

Could you revisit #1417 with this case? Please retain the follow-up's Git author if you cherry-pick it. If you combine the fix or fixture with another commit, please include:

Co-authored-by: andrewpozdnakov7-jpg [email protected]

AI-assisted with Codex. Synthetic inputs only.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7181320996 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1417#issuecomment-7181320996). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T03:01:05Z. --- I reproduced the full-mask case from the [closing review](https://github.com/Marvisak/VIctory/pull/1417#issuecomment-7176080190) with a synthetic vertex shader. The fixture enables all four `pos1` channels and writes `(0, 0, packed, 0)`. On `2a60d82`, translation stops at that export with the clip, cull or point-size error. [f7c2aac](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/f7c2aac62a949aff0d02ac29d00e25635aa8b8d7) extends that exact head and keeps its Git author. It accepts the other enabled channels only when proven zero. The same test still rejects a nonzero constant and an unknown vertex input in those channels. Six paired Windows/WARP runs agreed. The patched shader draws into slice 2/viewport 0 for layer only, slice 0/viewport 1 for viewport only, and slice 1/viewport 1 for both. A negative clip distance still leaves all slices clear. The same test passes with the branch merged onto `63bcca4`. The VALU, semantics and lowerer suites and strict shader Clippy passed. Could you revisit #1417 with this case? Please retain the follow-up's Git author if you cherry-pick it. If you combine the fix or fixture with another commit, please include: Co-authored-by: andrewpozdnakov7-jpg <[email protected]> AI-assisted with Codex. Synthetic inputs only.

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!1416
No description provided.