Shaders: lower SV_RenderTargetArrayIndex and SV_ViewportArrayIndex exports #1417

Closed
github-bot wants to merge 1 commit from gh-pr/1417/head into gh-pr/1417/base
Owner

@⁠fuzeofficlal on GitHub · 2026-11-24 17:54 UTC · original
fuzeofficlal:feat/shader-rtai-vpai-exports-914 → main · +518 −72 · 5 files · 1 commits · closed without merging

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.
**@⁠fuzeofficlal** on GitHub · 2026-11-24 17:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/1417) `fuzeofficlal:feat/shader-rtai-vpai-exports-914` → `main` · +518 −72 · 5 files · 1 commits · closed without merging 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.
Extract SV_RenderTargetArrayIndex (bits 0..15) and SV_ViewportArrayIndex (bits 16..31) from RDNA2's exp pos1.z misc vector when declared in the output signature, shift clip and cull distance exports to pos2..=pos3, mark both semantics Constant in signatures, and declare the DXIL VIEWPORT_RT_INDEX feature flag (ShaderFlags bit 9, SFI0 0x2000) for non-mesh rasterizer stages.

Add multi-slice Texture2DArray RTV and multi-viewport draw readback tests across SM 6.6 hardware adapters and WARP.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:30:57 +00:00
github-bot closed this pull request 2026-11-26 04:30:57 +00:00
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 17:59 UTC · original

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.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 17:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/1417#issuecomment-7139998835) 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.*
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-24 20:44 UTC · original

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).

**@⁠sinan-cmyk** on GitHub · 2026-11-24 20:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/1417#issuecomment-7143984086) ### 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).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:26 UTC · original · edited 2026-11-25 06:28 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-25 01:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/1417#issuecomment-7149553123) · edited 2026-11-25 06:28 UTC <!-- 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)_
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:12 UTC · original

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.

**@⁠Marvisak** on GitHub · 2026-11-25 22:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/1417#issuecomment-7176080190) 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.
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 03:01 UTC · original

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.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 03:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/1417#issuecomment-7181320996) I reproduced the full-mask case from the [closing review](https://git.gtahub.st/github/Marvisak--VIctory/pulls/1417) 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

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