Shaders: lower SV_RenderTargetArrayIndex and SV_ViewportArrayIndex exports (exp pos1) #914

Open
opened 2026-11-24 14:02:49 +00:00 by davi713albano-coder · 5 comments
davi713albano-coder commented 2026-11-24 14:02:49 +00:00 (Migrated from github.com)
Contributor

Imported from Marvisak/VIctory. Originally posted by davi713albano-coder on 2026-11-24T14:02:49Z.


Summary

Implements lowering for vertex shader SV_RenderTargetArrayIndex (kind == 4) and SV_ViewportArrayIndex (kind == 5) exports from RDNA2's exp pos1 misc vector, and shifts clip/cull distance exports to pos2..=pos3 when the misc vector is present.

Because external PR creation is restricted (collaborators_only), the CI-green branch is ready on my fork:

Changes

  • crates/victory-shader/src/emit/mod.rs: sets Constant (1) interpolation mode on kind == 4 (SV_RenderTargetArrayIndex) and kind == 5 (SV_ViewportArrayIndex) signature elements, matching DXC.
  • crates/victory-shader/src/emit/shader.rs: adds flags::VIEWPORT_RT_INDEX (1 << 9 in DXIL ShaderFlags metadata, mapped to 0x2000 in SFI0 for SHADER_FEATURE_VIEWPORT_AND_RT_ARRAY_INDEX_FROM_ANY_SHADER_FEEDING_RASTERIZER).
  • crates/victory-shader/src/emit/lower.rs:
    • When outputs declares SV_RenderTargetArrayIndex and/or SV_ViewportArrayIndex, treats exp pos1 as the GFX9+/RDNA2 misc vector and extracts SV_RenderTargetArrayIndex from pos1.z & 0xFFFF and SV_ViewportArrayIndex from pos1.z >> 16, setting flags::VIEWPORT_RT_INDEX for non-mesh outputs.
    • Shifts clip/cull distance exports from pos1..=pos2 to pos2..=pos3 when the misc vector is present.
  • crates/victory-shader/src/emit/valu_tests.rs: adds vs_rt_and_viewport_index_exports_validate_and_create_pso.

Tests & Verification

vs_rt_and_viewport_index_exports_validate_and_create_pso lowers three synthetic GFX10 vertex shaders (RT array index only, viewport array index only, and both packed in pos1.z together with SV_ClipDistance in pos2.x) plus a minimal pixel shader:

  • All emitted DXIL containers pass dxil.dll validation with matching container hashes and SFI0 & 0x2000 != 0.
  • All three graphics PSOs are created cleanly on D3D12 (Host::pipeline).

Verified on GitHub Actions (windows-latest) using upstream ci.yml (cargo clippy --workspace --all-targets --locked -- -D warnings, --all-features, and cargo test --workspace --locked including xtask asset-policy check):

Not tested: live title execution or multi-slice draw readback.
No game data used. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6583535653 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/914). Originally posted by [davi713albano-coder](https://github.com/davi713albano-coder) on 2026-11-24T14:02:49Z. --- ### Summary Implements lowering for vertex shader `SV_RenderTargetArrayIndex` (`kind == 4`) and `SV_ViewportArrayIndex` (`kind == 5`) exports from RDNA2's `exp pos1` misc vector, and shifts clip/cull distance exports to `pos2..=pos3` when the misc vector is present. Because external PR creation is restricted (`collaborators_only`), the CI-green branch is ready on my fork: - **Branch:** https://github.com/davi713albano-coder/VIctory/commits/shader/rt-viewport-index-exports - **Commit:** `1060727` (based on `main` `ffe310e`, 4 files, +307/-30) - **Compare:** https://github.com/Marvisak/VIctory/compare/main...davi713albano-coder:shader/rt-viewport-index-exports ### Changes - **`crates/victory-shader/src/emit/mod.rs`**: sets `Constant` (`1`) interpolation mode on `kind == 4` (`SV_RenderTargetArrayIndex`) and `kind == 5` (`SV_ViewportArrayIndex`) signature elements, matching DXC. - **`crates/victory-shader/src/emit/shader.rs`**: adds `flags::VIEWPORT_RT_INDEX` (`1 << 9` in DXIL `ShaderFlags` metadata, mapped to `0x2000` in `SFI0` for `SHADER_FEATURE_VIEWPORT_AND_RT_ARRAY_INDEX_FROM_ANY_SHADER_FEEDING_RASTERIZER`). - **`crates/victory-shader/src/emit/lower.rs`**: - When `outputs` declares `SV_RenderTargetArrayIndex` and/or `SV_ViewportArrayIndex`, treats `exp pos1` as the GFX9+/RDNA2 misc vector and extracts `SV_RenderTargetArrayIndex` from `pos1.z & 0xFFFF` and `SV_ViewportArrayIndex` from `pos1.z >> 16`, setting `flags::VIEWPORT_RT_INDEX` for non-mesh outputs. - Shifts clip/cull distance exports from `pos1..=pos2` to `pos2..=pos3` when the misc vector is present. - **`crates/victory-shader/src/emit/valu_tests.rs`**: adds `vs_rt_and_viewport_index_exports_validate_and_create_pso`. ### Tests & Verification `vs_rt_and_viewport_index_exports_validate_and_create_pso` lowers three synthetic GFX10 vertex shaders (RT array index only, viewport array index only, and both packed in `pos1.z` together with `SV_ClipDistance` in `pos2.x`) plus a minimal pixel shader: - All emitted DXIL containers pass `dxil.dll` validation with matching container hashes and `SFI0 & 0x2000 != 0`. - All three graphics PSOs are created cleanly on D3D12 (`Host::pipeline`). Verified on GitHub Actions (`windows-latest`) using upstream `ci.yml` (`cargo clippy --workspace --all-targets --locked -- -D warnings`, `--all-features`, and `cargo test --workspace --locked` including `xtask` asset-policy check): - `victory-shader`: 121 passed, 0 failed (full workspace: 343 passed, 0 failed, 6 ignored) - CI run: https://github.com/davi713albano-coder/VIctory/actions/runs/45408634865 **Not tested:** live title execution or multi-slice draw readback. No game data used. AI-assisted.
DaniiL35 commented 2026-11-24 15:03:52 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by DaniiL35 on 2026-11-24T14:07:26Z.


Independent Verification Review: davi713albano-coder:shader/rt-viewport-index-exports (1060727)

Audited RDNA2 misc position vector export lowering and DXIL feature flag emission:


1. RDNA2 Misc Vector & Clip Distance Shift Semantics

  • In AMD GFX10/RDNA2 ISA, when vertex/primitive shaders export misc attributes (specifically SV_RenderTargetArrayIndex and SV_ViewportArrayIndex), they target the exp pos1 position slot.
  • Bit packing in pos1.z conforms to RDNA2 hardware specification:
    • Low 16 bits (Extract::Low16, pos1.z & 0xFFFF): SV_RenderTargetArrayIndex (kind == 4).
    • High 16 bits (Extract::High16, pos1.z >> 16 via logical shift Bin::LShr): SV_ViewportArrayIndex (kind == 5).
  • When the misc vector is present (has_misc == true), clip/cull distance exports correctly shift from pos1..=pos2 to pos2..=pos3 (first_clip = 2). Channel index computation k = usize::from(n - first_clip) * 4 + usize::from(ch) guarantees correct indexing into PA_CL_VS_OUT_CNTL distance allocations.

2. DXIL Feature Flag & Container Metadata

  • crates/victory-shader/src/emit/shader.rs: flags::VIEWPORT_RT_INDEX correctly sets bit 9 in DXIL shader flags and maps to 0x2000 (SHADER_FEATURE_VIEWPORT_AND_RT_ARRAY_INDEX_FROM_ANY_SHADER_FEEDING_RASTERIZER) in SFI0 part.
  • crates/victory-shader/src/emit/mod.rs: Sets interp = 1 (Constant) on kind 4 and 5 signature elements, matching DXC signature layouts.

3. Test Suite & Policy Invariants

  • vs_rt_and_viewport_index_exports_validate_and_create_pso covers:
    1. Render-target array index only
    2. Viewport array index only
    3. Both packed in pos1.z alongside SV_ClipDistance in pos2.x
  • Synthetic instructions are constructed via vop1 and exp_inst helper byte streams without binary blobs or external files (Rule #1 compliant). DXIL containers validate against dxil.dll and D3D12 PSO creation succeeds.

Ready to merge cleanly onto main.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7133875901 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/914#issuecomment-7133875901). Originally posted by [DaniiL35](https://github.com/DaniiL35) on 2026-11-24T14:07:26Z. --- ### Independent Verification Review: davi713albano-coder:shader/rt-viewport-index-exports (`1060727`) Audited RDNA2 misc position vector export lowering and DXIL feature flag emission: --- ### 1. RDNA2 Misc Vector & Clip Distance Shift Semantics - In AMD GFX10/RDNA2 ISA, when vertex/primitive shaders export misc attributes (specifically `SV_RenderTargetArrayIndex` and `SV_ViewportArrayIndex`), they target the `exp pos1` position slot. - Bit packing in `pos1.z` conforms to RDNA2 hardware specification: - Low 16 bits (`Extract::Low16`, `pos1.z & 0xFFFF`): `SV_RenderTargetArrayIndex` (`kind == 4`). - High 16 bits (`Extract::High16`, `pos1.z >> 16` via logical shift `Bin::LShr`): `SV_ViewportArrayIndex` (`kind == 5`). - When the misc vector is present (`has_misc == true`), clip/cull distance exports correctly shift from `pos1..=pos2` to `pos2..=pos3` (`first_clip = 2`). Channel index computation `k = usize::from(n - first_clip) * 4 + usize::from(ch)` guarantees correct indexing into `PA_CL_VS_OUT_CNTL` distance allocations. --- ### 2. DXIL Feature Flag & Container Metadata - `crates/victory-shader/src/emit/shader.rs`: `flags::VIEWPORT_RT_INDEX` correctly sets bit 9 in DXIL shader flags and maps to `0x2000` (`SHADER_FEATURE_VIEWPORT_AND_RT_ARRAY_INDEX_FROM_ANY_SHADER_FEEDING_RASTERIZER`) in `SFI0` part. - `crates/victory-shader/src/emit/mod.rs`: Sets `interp = 1` (`Constant`) on kind 4 and 5 signature elements, matching DXC signature layouts. --- ### 3. Test Suite & Policy Invariants - `vs_rt_and_viewport_index_exports_validate_and_create_pso` covers: 1. Render-target array index only 2. Viewport array index only 3. Both packed in `pos1.z` alongside `SV_ClipDistance` in `pos2.x` - Synthetic instructions are constructed via `vop1` and `exp_inst` helper byte streams without binary blobs or external files (Rule #1 compliant). DXIL containers validate against `dxil.dll` and D3D12 PSO creation succeeds. Ready to merge cleanly onto `main`.
MichaelSmithAI commented 2026-11-24 15:04:05 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by MichaelSmithAI on 2026-11-24T14:08:52Z.


Multi-slice readback now passes on RTX 4090 under Wine/GE 3.2. On an 8×4 target with two slices, the layer-only shader drew red in the left viewport of slice 1, the viewport-only shader in the right viewport of slice 0, and the combined shader in the right viewport of slice 1. All other pixels matched the clear value. With negative clip distance the selected slice stayed clear. Microsoft DXIL validation passed. Wine mapped the WARP request to the same GPU, so this is one hardware result. The readback regression is on the author branch for review.

On native Windows 10, andrewpozdnakov7-jpg reported that all pixel assertions passed on 4e9847d for the layer-only, viewport-only and combined exports, including negative clip distance. All 14 tests in the VALU group passed. The test executable included Agility 1.620.2 loader exports and used Microsoft’s DXIL validator. Both adapter labels ran on the same forced WARP 1.0.22 software adapter. Reviewer’s native WARP result

<!-- greyfinch-sync:Marvisak/VIctory:comment:7133913520 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/914#issuecomment-7133913520). Originally posted by [MichaelSmithAI](https://github.com/MichaelSmithAI) on 2026-11-24T14:08:52Z. --- Multi-slice readback now passes on RTX 4090 under Wine/GE 3.2. On an 8×4 target with two slices, the layer-only shader drew red in the left viewport of slice 1, the viewport-only shader in the right viewport of slice 0, and the combined shader in the right viewport of slice 1. All other pixels matched the clear value. With negative clip distance the selected slice stayed clear. Microsoft DXIL validation passed. Wine mapped the WARP request to the same GPU, so this is one hardware result. The [readback regression](https://github.com/davi713albano-coder/VIctory/pull/8) is on the author branch for review. On native Windows 10, andrewpozdnakov7-jpg reported that all pixel assertions passed on 4e9847d for the layer-only, viewport-only and combined exports, including negative clip distance. All 14 tests in the VALU group passed. The test executable included Agility 1.620.2 loader exports and used Microsoft’s DXIL validator. Both adapter labels ran on the same forced WARP 1.0.22 software adapter. [Reviewer’s native WARP result](https://github.com/davi713albano-coder/VIctory/pull/8#issuecomment-7134261928)
Marvisak commented 2026-11-25 07:03:26 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T06:53:57Z.


Automated triage for the maintainers.

This lowers vertex-shader SV_RenderTargetArrayIndex and SV_ViewportArrayIndex exports from exp pos1. On main (63bcca4) the Target::Position(1..=2) arm of export lowering in crates/victory-shader/src/emit/lower.rs still refuses them ("render-target or viewport index exports").

PR #1417, which carried this change, was closed without merging on 2026-11-25: the console compiler exports pos1 with all four channels enabled (zeros in x, y and w), and #1417 refused any channel but z, so real programs still failed. The maintainer review also notes that no title program reaches this path on main.

The 2026-11-26 comment offers a follow-up on a fork (f7c2aac, on #1417's head) that accepts the other pos1 channels only when they are provably zero, with WARP readback tests passing and a clean merge onto 63bcca4. No open pull request carries it. Pull requests are open to everyone, so please open one against main with that commit (keeping the original author) rather than asking for #1417 to be reopened; the decision is left to the maintainers.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7155273993 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/914#issuecomment-7155273993). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T06:53:57Z. --- <!-- victory-issue-triage v1 verdict=tracked seen=2026-11-26T03:01:06Z at=2026-11-26T03:46:00Z --> Automated triage for the maintainers. This lowers vertex-shader `SV_RenderTargetArrayIndex` and `SV_ViewportArrayIndex` exports from `exp pos1`. On `main` (63bcca4) the `Target::Position(1..=2)` arm of export lowering in `crates/victory-shader/src/emit/lower.rs` still refuses them ("render-target or viewport index exports"). PR #1417, which carried this change, was closed without merging on 2026-11-25: the console compiler exports `pos1` with all four channels enabled (zeros in x, y and w), and #1417 refused any channel but z, so real programs still failed. The maintainer review also notes that no title program reaches this path on `main`. The 2026-11-26 comment offers a follow-up on a fork (`f7c2aac`, on #1417's head) that accepts the other `pos1` channels only when they are provably zero, with WARP readback tests passing and a clean merge onto `63bcca4`. No open pull request carries it. Pull requests are open to everyone, so please open one against `main` with that commit (keeping the original author) rather than asking for #1417 to be reopened; the decision is left to the maintainers. --- _Generated by [Claude Code](https://claude.ai/code)_
andrewpozdnakov7-jpg commented 2026-11-26 03:05:18 +00:00 (Migrated from github.com)
Author
Contributor

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


The full-mask case from #1417 now has a synthetic before-and-after check. On 2a60d82, all four enabled pos1 channels cause translation to stop even when X/Y/W are zero. f7c2aac passes six WARP readback runs for the layer, viewport and clip-distance cases and also passes on a clean merge with upstream 63bcca4. The tested commit is offered in the existing PR discussion.

Please retain the follow-up's Git author if you cherry-pick it, or include this trailer if you fold in the fix or tests.

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

AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7181321281 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/914#issuecomment-7181321281). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T03:01:06Z. --- The full-mask case from #1417 now has a synthetic before-and-after check. On [`2a60d82`](https://github.com/Marvisak/VIctory/commit/2a60d8264d5e4480b797fd059d3d45173f3c5309), all four enabled `pos1` channels cause translation to stop even when X/Y/W are zero. [`f7c2aac`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/f7c2aac62a949aff0d02ac29d00e25635aa8b8d7) passes six WARP readback runs for the layer, viewport and clip-distance cases and also passes on a clean merge with upstream `63bcca4`. The tested commit is offered in the [existing PR discussion](https://github.com/Marvisak/VIctory/pull/1417#issuecomment-7181320996). Please retain the follow-up's Git author if you cherry-pick it, or include this trailer if you fold in the fix or tests. Co-authored-by: andrewpozdnakov7-jpg <[email protected]> AI-assisted with Codex.
andrewpozdnakov7-jpg commented 2026-11-27 08:35:43 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T08:35:43Z.


Opened #3489 with the full-mask fix and the original authorship preserved. The same synthetic shader fails on 2a60d82 and renders into the expected slices and viewports on 7987ba8 (main 63bcca4). The new PR has the results and the current CI.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7213705736 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/914#issuecomment-7213705736). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T08:35:43Z. --- Opened [#3489](https://github.com/Marvisak/VIctory/pull/3489) with the full-mask fix and the original authorship preserved. The same synthetic shader fails on `2a60d82` and renders into the expected slices and viewports on `7987ba8` (main `63bcca4`). The new PR has the results and the current CI.
Sign in to join this conversation.
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#914
No description provided.