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

Open
opened 2026-11-26 04:14:09 +00:00 by github-bot · 4 comments
Owner

@⁠davi713albano-coder on GitHub · 2026-11-24 14:02 UTC · original

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.

**@⁠davi713albano-coder** on GitHub · 2026-11-24 14:02 UTC · [original](https://github.com/Marvisak/VIctory/issues/914) ### 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:09 +00:00
Author
Owner

@⁠DaniiL35 on GitHub · 2026-11-24 14:07 UTC · original

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.

**@⁠DaniiL35** on GitHub · 2026-11-24 14:07 UTC · [original](https://github.com/Marvisak/VIctory/issues/914#issuecomment-7133875901) ### 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`.
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 14:08 UTC · original · edited 2026-11-24 14:30 UTC

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

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 14:08 UTC · [original](https://github.com/Marvisak/VIctory/issues/914#issuecomment-7133913520) · edited 2026-11-24 14:30 UTC 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)
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 06:53 UTC · original · edited 2026-11-26 03:45 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-25 06:53 UTC · [original](https://github.com/Marvisak/VIctory/issues/914#issuecomment-7155273993) · edited 2026-11-26 03:45 UTC <!-- 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)_
Author
Owner

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

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.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 03:01 UTC · [original](https://github.com/Marvisak/VIctory/issues/914#issuecomment-7181321281) 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://git.gtahub.st/github/Marvisak--VIctory/pulls/1417). 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.
This discussion has been locked. Commenting is limited to contributors.
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#914
No description provided.