Shader: fix biased 16-bit image samples and DXIL validator failures #306

Closed
wbkepler wants to merge 3 commits from upstream-pr/306 into main
wbkepler commented 2026-11-24 02:12:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T02:12:21Z.


Summary

Fixes 5 shader emission and DXIL container/validator issues in victory-shader (+176 newly validated shaders, 100% of emitted VS/PS/CS validating cleanly):

  • Biased 16-bit image samples (emit/lower.rs):
    • Enables a16 biased image samples (image_sample_b) by separating full 32-bit prefix VGPRs (offsets, bias, comparison reference) from a16-packed tail operands (gradients, coordinates, explicit LOD) matching GFX10 MIMG hardware layout.
  • Conservative depth SV_Position (emit/mod.rs):
    • Sets SV_Position interpolation to linear_noperspective_centroid (5) in pixel shaders outputting conservative depth (SV_DepthLessEqual/SV_DepthGreaterEqual).
  • Row interpolation consistency (emit/mod.rs, emit/lower.rs):
    • Adds harmonize_row_interp() so packed elements in the same signature row share one interpolation mode (propagating Constant for integer/SV_IsFrontFace rows and inheriting read modes for unread PS siblings).
  • Signature ordering (emit/container.rs):
    • Stably sorts ISG1/OSG1 signature rows by register only (preserving element-ID order within a row to match DXIL validator expectations).
  • Compute implicit-derivative sampling (emit/shader.rs):
    • Tracks SM 6.6 compute-shader implicit-derivative sampling to emit dx.valver = 1.8 and PSVRuntimeInfo3 (52 bytes with EntryFunctionName).

Verification

  • cargo clippy --workspace --all-targets — passed (zero new warnings)
  • cargo clippy -p victory --features diagnostics --all-targets — passed
  • cargo test --workspace — passed (victory-shader: 74/74 including 5 new dxil.dll validation and D3D12 compute PSO tests)
  • cargo xtask policy — passed (151 files ok)
<!-- greyfinch-sync:Marvisak/VIctory:issue:6573037931 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/306). Originally posted by [wbkepler](https://github.com/wbkepler) on 2026-11-24T02:12:21Z. --- ## Summary Fixes 5 shader emission and DXIL container/validator issues in `victory-shader` (+176 newly validated shaders, 100% of emitted VS/PS/CS validating cleanly): - **Biased 16-bit image samples (`emit/lower.rs`)**: - Enables `a16` biased image samples (`image_sample_b`) by separating full 32-bit prefix VGPRs (offsets, bias, comparison reference) from `a16`-packed tail operands (gradients, coordinates, explicit LOD) matching GFX10 MIMG hardware layout. - **Conservative depth `SV_Position` (`emit/mod.rs`)**: - Sets `SV_Position` interpolation to `linear_noperspective_centroid` (`5`) in pixel shaders outputting conservative depth (`SV_DepthLessEqual`/`SV_DepthGreaterEqual`). - **Row interpolation consistency (`emit/mod.rs`, `emit/lower.rs`)**: - Adds `harmonize_row_interp()` so packed elements in the same signature row share one interpolation mode (propagating `Constant` for integer/`SV_IsFrontFace` rows and inheriting read modes for unread PS siblings). - **Signature ordering (`emit/container.rs`)**: - Stably sorts `ISG1`/`OSG1` signature rows by register only (preserving element-ID order within a row to match DXIL validator expectations). - **Compute implicit-derivative sampling (`emit/shader.rs`)**: - Tracks SM 6.6 compute-shader implicit-derivative sampling to emit `dx.valver = 1.8` and `PSVRuntimeInfo3` (52 bytes with `EntryFunctionName`). ## Verification - `cargo clippy --workspace --all-targets` — passed (zero new warnings) - `cargo clippy -p victory --features diagnostics --all-targets` — passed - `cargo test --workspace` — passed (`victory-shader`: 74/74 including 5 new `dxil.dll` validation and D3D12 compute PSO tests) - `cargo xtask policy` — passed (151 files ok)
r4tedx commented 2026-11-24 06:55:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by r4tedx on 2026-11-24T03:14:19Z.


Review note on the a16 address layout, two points where this differs from LLVM's AMDGPU backend:

  1. The bias. The test here builds image_sample_b ... a16 with "a 32-bit f32 bias", and the lowering reads the bias dword whole. SITargetLowering::lowerImage has:
// Special handling of bias when A16 is on. Bias is of type half but
// occupies full 32-bit.
SDValue Bias = DAG.getBuildVector(MVT::v2f16, DL, {Op.getOperand(ArgOffset + I), DAG.getPOISON(MVT::f16)});

and asserts "Bias needs to be converted to 16 bit in A16 mode". So with a16 the bias is an f16 in the low half of its own dword; read as an f32 it is a denormal near zero, and the sample silently loses its bias. The test passes because it encodes the same assumption.

  1. Derivatives. With a16 the derivatives are taken as packed 16-bit values. On GFX10.3 they are 16-bit only in the _g16 opcodes; LLVM's gfx10_asm_mimg.s has image_sample_d ... dim:SQ_RSRC_IMG_2D a16 with five address dwords (four 32-bit derivatives plus the packed coordinates).

#160 and #318 read the bias as f16; #73 and #136 as f32, like this one. I got point 2 wrong myself in #160 and fixed it there.

From the documents and synthetic tests only; I have no copy of the title and have not run this on console hardware.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7120901272 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/306#issuecomment-7120901272). Originally posted by [r4tedx](https://github.com/r4tedx) on 2026-11-24T03:14:19Z. --- Review note on the a16 address layout, two points where this differs from LLVM's AMDGPU backend: 1. **The bias.** The test here builds `image_sample_b ... a16` with "a 32-bit f32 bias", and the lowering reads the bias dword whole. `SITargetLowering::lowerImage` has: ```cpp // Special handling of bias when A16 is on. Bias is of type half but // occupies full 32-bit. SDValue Bias = DAG.getBuildVector(MVT::v2f16, DL, {Op.getOperand(ArgOffset + I), DAG.getPOISON(MVT::f16)}); ``` and asserts "Bias needs to be converted to 16 bit in A16 mode". So with a16 the bias is an f16 in the low half of its own dword; read as an f32 it is a denormal near zero, and the sample silently loses its bias. The test passes because it encodes the same assumption. 2. **Derivatives.** With a16 the derivatives are taken as packed 16-bit values. On GFX10.3 they are 16-bit only in the `_g16` opcodes; LLVM's `gfx10_asm_mimg.s` has `image_sample_d ... dim:SQ_RSRC_IMG_2D a16` with five address dwords (four 32-bit derivatives plus the packed coordinates). #160 and #318 read the bias as f16; #73 and #136 as f32, like this one. I got point 2 wrong myself in #160 and fixed it there. From the documents and synthetic tests only; I have no copy of the title and have not run this on console hardware.
wbkepler commented 2026-11-24 06:55:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T03:40:39Z.


Thanks @r4tedx, you're right on both points. Fixed in a8430f2:

  1. Bias with a16: the bias keeps its own address dword, but it is now read as an f16 from the low half (masked, then legacyF16ToF32) instead of as an f32. The synthetic image_sample_b ... a16 test now puts f16 -1.0 in the low half and junk in the high half, so the test no longer bakes in the f32 assumption.
  2. Derivatives: outside the _g16 opcodes, a16 leaves each derivative as a full 32-bit dword. Only the coordinates and LOD are packed. The decoder's address dword count now follows this (2D image_sample_d ... a16 = 5 dwords, _g16 packs one dword per direction), and the lowering reads the gradients as full f32 dwords, with the packed coordinates starting after them. There is a new decoder unit test for these counts.

The workspace clippy, tests and cargo xtask policy pass.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121317875 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/306#issuecomment-7121317875). Originally posted by [wbkepler](https://github.com/wbkepler) on 2026-11-24T03:40:39Z. --- Thanks @r4tedx, you're right on both points. Fixed in a8430f2: 1. **Bias with a16:** the bias keeps its own address dword, but it is now read as an f16 from the low half (masked, then `legacyF16ToF32`) instead of as an f32. The synthetic `image_sample_b ... a16` test now puts f16 -1.0 in the low half and junk in the high half, so the test no longer bakes in the f32 assumption. 2. **Derivatives:** outside the `_g16` opcodes, a16 leaves each derivative as a full 32-bit dword. Only the coordinates and LOD are packed. The decoder's address dword count now follows this (2D `image_sample_d ... a16` = 5 dwords, `_g16` packs one dword per direction), and the lowering reads the gradients as full f32 dwords, with the packed coordinates starting after them. There is a new decoder unit test for these counts. The workspace clippy, tests and `cargo xtask policy` pass.
iurysf commented 2026-11-24 06:56:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by iurysf on 2026-11-24T06:02:20Z.


Measured offline against main d2a4bae: victory translate --list --validate over the title's shaders.rpf + executable (26,096 programs), dxil.dll 1.9.2602.17 (DXC v1.9.2602).

validated rejected by the validator "incompatible with the shader stage" (cs)
main 21,983 185 23
main + this PR 22,159 53 0
main + this PR + #309 + #385 (clean merge) 22,320 53 0
  • No program that validated on main is rejected with this PR, alone or stacked.
  • The 53 left are all mesh vertex plus primitive output size is greater than 32768.
  • The incompatible with the shader stage rejections grow to 34 with #309 and 45 with #385 alone (newly emitted compute programs with implicit-derivative sample). This PR clears them all, so it's worth landing before or with those two.
  • I hit the same root cause independently. A minimal HLSL compute shader with Texture2D.Sample compiled by dxc with -T cs_6_6 -validator-version 1.6 or 1.7 fails with exactly this error, and it passes with 1.8. So dx.valver 1.8 for compute derivatives is the right fix.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7123513862 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/306#issuecomment-7123513862). Originally posted by [iurysf](https://github.com/iurysf) on 2026-11-24T06:02:20Z. --- Measured offline against main `d2a4bae`: `victory translate --list --validate` over the title's `shaders.rpf` + executable (26,096 programs), dxil.dll 1.9.2602.17 (DXC v1.9.2602). | | validated | rejected by the validator | "incompatible with the shader stage" (cs) | |---|---:|---:|---:| | main | 21,983 | 185 | 23 | | main + this PR | 22,159 | **53** | **0** | | main + this PR + #309 + #385 (clean merge) | 22,320 | 53 | 0 | - No program that validated on main is rejected with this PR, alone or stacked. - The 53 left are all mesh `vertex plus primitive output size is greater than 32768`. - The `incompatible with the shader stage` rejections grow to 34 with #309 and 45 with #385 alone (newly emitted compute programs with implicit-derivative `sample`). This PR clears them all, so it's worth landing before or with those two. - I hit the same root cause independently. A minimal HLSL compute shader with `Texture2D.Sample` compiled by dxc with `-T cs_6_6 -validator-version 1.6` or `1.7` fails with exactly this error, and it passes with `1.8`. So `dx.valver` 1.8 for compute derivatives is the right fix.
slint6614-dev commented 2026-11-24 08:02:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by slint6614-dev on 2026-11-24T07:23:42Z.


Measured on the full retail shader pack (26,503 containers) with victory translate --validate, against main d2a4bae:

VS/PS validated CS validated MS validated cargo test -p victory-shader
main 12172 1670 8129 ok
#569 12208 1670 8129 ok
#73 12208 1670 8129 ok
#318 12208 1670 8129 ok
#306 12316 1693 8138 ok

All four clear the 108 "biased image sample with 16-bit coordinates" programs identically. #73 and #318 also clear the 27 image_sample_d_cl refusals, but those programs then stop on another reason (emitted count unchanged). #306 additionally clears 15 of the 16 validator error kinds (only the mesh 32 KiB output size remains, see #459); it overlaps #554/#565/#381. Windows 11, dxil.dll from SDK 10.0.26100.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7124942792 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/306#issuecomment-7124942792). Originally posted by [slint6614-dev](https://github.com/slint6614-dev) on 2026-11-24T07:23:42Z. --- Measured on the full retail shader pack (26,503 containers) with `victory translate --validate`, against main d2a4bae: | | VS/PS validated | CS validated | MS validated | `cargo test -p victory-shader` | |---|---|---|---|---| | main | 12172 | 1670 | 8129 | ok | | #569 | 12208 | 1670 | 8129 | ok | | #73 | 12208 | 1670 | 8129 | ok | | #318 | 12208 | 1670 | 8129 | ok | | #306 | 12316 | 1693 | 8138 | ok | All four clear the 108 "biased image sample with 16-bit coordinates" programs identically. #73 and #318 also clear the 27 `image_sample_d_cl` refusals, but those programs then stop on another reason (emitted count unchanged). #306 additionally clears 15 of the 16 validator error kinds (only the mesh 32 KiB output size remains, see #459); it overlaps #554/#565/#381. Windows 11, dxil.dll from SDK 10.0.26100.
Halfect commented 2026-11-24 13:00:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Halfect on 2026-11-24T13:00:28Z.

Review: COMMENTED


Static review of a8430f2, focused on the container/validator items. I did not run the suite here; this is code reading plus comparison against an independent implementation.

Compute implicit-derivative sampling (dx.valver 1.8 + PSVRuntimeInfo3). The approach is correct and the emitted bytes are right: RuntimeInfoSize 52, with the EntryFunctionName string-table offset 1 (main\0 appended after the leading empty string) as the last four bytes of the info. I had implemented this same item independently on a fork branch before noticing this PR; the PSV0 output is byte-identical, so I am dropping mine as a duplicate of this item. The tracked opcode set (60 Sample, 61 SampleBias, 64 SampleCmp, 81 CalculateLOD) is exactly the implicit-derivative set — SampleLevel (62), SampleGrad (63) and SampleCmpLevelZero (65) take an explicit level or gradients and correctly stay at validator 1.6/1.7.

On the interaction with #180: even if #180 lands and converts plain compute image_sample / image_sample_b to SampleGrad, comparison samples with implicit derivatives (image_sample_c* in compute) still require validator 1.8, so this item stays necessary either way. The two are complementary, not conflicting.

Row-interpolation harmonization. It runs from both lower (pixel inputs, after fill_phis) and emit. The function only rewrites elements with usage == 0 and never changes the mode it computes from, so the second pass is a no-op — redundant but harmless. Forcing Constant on rows that hold SV_IsFrontFace or integer elements matches the validator's one-interpolation-mode-per-row rule.

Conservative depth. Switching the pixel SV_Position input to linear_noperspective_centroid (5) when the shader outputs SV_DepthLessEqual/SV_DepthGreaterEqual matches the validator's conservative-depth requirement; leaving it at 4 otherwise is right.

a16 layout. The a8430f2 fix matches LLVM's lowerImage: the bias is an f16 in the low half of its own dword, and derivatives stay 32-bit outside the _g16 opcodes. The two points @r4tedx raised are addressed.

One process note: the PR is currently dirty against main (ffe310e) and needs a rebase before it can land.

No blockers from what I can check statically. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:review:6039626718 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/306#pullrequestreview-6039626718). Originally posted by [Halfect](https://github.com/Halfect) on 2026-11-24T13:00:28Z. **Review:** COMMENTED --- Static review of `a8430f2`, focused on the container/validator items. I did not run the suite here; this is code reading plus comparison against an independent implementation. **Compute implicit-derivative sampling (`dx.valver` 1.8 + PSVRuntimeInfo3).** The approach is correct and the emitted bytes are right: `RuntimeInfoSize` 52, with the `EntryFunctionName` string-table offset 1 (`main\0` appended after the leading empty string) as the last four bytes of the info. I had implemented this same item independently on a fork branch before noticing this PR; the PSV0 output is byte-identical, so I am dropping mine as a duplicate of this item. The tracked opcode set (60 `Sample`, 61 `SampleBias`, 64 `SampleCmp`, 81 `CalculateLOD`) is exactly the implicit-derivative set — `SampleLevel` (62), `SampleGrad` (63) and `SampleCmpLevelZero` (65) take an explicit level or gradients and correctly stay at validator 1.6/1.7. On the interaction with #180: even if #180 lands and converts plain compute `image_sample` / `image_sample_b` to `SampleGrad`, comparison samples with implicit derivatives (`image_sample_c*` in compute) still require validator 1.8, so this item stays necessary either way. The two are complementary, not conflicting. **Row-interpolation harmonization.** It runs from both `lower` (pixel inputs, after `fill_phis`) and `emit`. The function only rewrites elements with `usage == 0` and never changes the mode it computes from, so the second pass is a no-op — redundant but harmless. Forcing `Constant` on rows that hold `SV_IsFrontFace` or integer elements matches the validator's one-interpolation-mode-per-row rule. **Conservative depth.** Switching the pixel `SV_Position` input to `linear_noperspective_centroid` (5) when the shader outputs `SV_DepthLessEqual`/`SV_DepthGreaterEqual` matches the validator's conservative-depth requirement; leaving it at 4 otherwise is right. **a16 layout.** The `a8430f2` fix matches LLVM's `lowerImage`: the bias is an f16 in the low half of its own dword, and derivatives stay 32-bit outside the `_g16` opcodes. The two points @r4tedx raised are addressed. One process note: the PR is currently `dirty` against `main` (`ffe310e`) and needs a rebase before it can land. No blockers from what I can check statically. AI-assisted.
ordis-labs commented 2026-11-24 15:04:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ordis-labs on 2026-11-24T15:00:47Z.


Rebased this onto current main (ffe310e) locally to measure it there, since it no longer merges cleanly. Three things needed:

  1. emit/mod.rs: main now has #565's conservative-depth rule as a separate block after the interpolation loop, and this PR has the same rule inside the loop. I kept this PR's version plus harmonize_row_interp(interpolated) and dropped main's block. Same result for SV_Position.
  2. emit/lower.rs: #634 (image_sample_o) added addr_val(self, 0) in the old two-argument form. With this PR's addr_val(l, start, k) that becomes addr_val(self, 0, 0), which is identical to main's addr_val(l, k).
  3. The test helper in emit/mod.rs (~line 806): resource::track takes Some(&st) since ffe310e, so structure goes first.

Results on ffe310e (translate --list --validate over the 1.0.2.1 shaders.rpf, SDK 10.0.26100 dxil.dll, outcomes matched program by program against main):

  • +153 programs validate, 0 lost. 44 are "a biased image sample with 16-bit coordinates". The rest were validator signature errors that harmonize_row_interp fixes (TEXCOORD/NORMAL/COLOR/SV_IsFrontFace locations, input/output signature mismatches) plus 24 "incompatible operation".
  • Every emitted vertex/pixel program validates: 12,275/12,275 (main: 12,155 of 12,231).
  • cargo test -p victory-shader: 111 passed. The 15 failures also fail on main on this machine (Windows 10, no SM 6.6 device for the GPU tests).

Windows 10 19045, RX 6700 XT. Tested and written up with Claude's help.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7135314515 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/306#issuecomment-7135314515). Originally posted by [ordis-labs](https://github.com/ordis-labs) on 2026-11-24T15:00:47Z. --- Rebased this onto current main (`ffe310e`) locally to measure it there, since it no longer merges cleanly. Three things needed: 1. `emit/mod.rs`: main now has #565's conservative-depth rule as a separate block after the interpolation loop, and this PR has the same rule inside the loop. I kept this PR's version plus `harmonize_row_interp(interpolated)` and dropped main's block. Same result for `SV_Position`. 2. `emit/lower.rs`: #634 (`image_sample_o`) added `addr_val(self, 0)` in the old two-argument form. With this PR's `addr_val(l, start, k)` that becomes `addr_val(self, 0, 0)`, which is identical to main's `addr_val(l, k)`. 3. The test helper in `emit/mod.rs` (~line 806): `resource::track` takes `Some(&st)` since `ffe310e`, so `structure` goes first. Results on `ffe310e` (`translate --list --validate` over the 1.0.2.1 `shaders.rpf`, SDK 10.0.26100 `dxil.dll`, outcomes matched program by program against main): - **+153 programs validate, 0 lost.** 44 are "a biased image sample with 16-bit coordinates". The rest were validator signature errors that `harmonize_row_interp` fixes (`TEXCOORD`/`NORMAL`/`COLOR`/`SV_IsFrontFace` locations, input/output signature mismatches) plus 24 "incompatible operation". - Every emitted vertex/pixel program validates: 12,275/12,275 (main: 12,155 of 12,231). - `cargo test -p victory-shader`: 111 passed. The 15 failures also fail on main on this machine (Windows 10, no SM 6.6 device for the GPU tests). Windows 10 19045, RX 6700 XT. Tested and written up with Claude's help.
marquezinii commented 2026-11-24 18:05:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by marquezinii on 2026-11-24T17:19:42Z.


I ran the a16 samples on a GPU and read back the mip level each lane got. The checks above are DXIL validation and offline counts, so this is the runtime side. Setup: RTX 5070 (desktop, driver 621.40, the only adapter in the machine), Windows 11 26300, Rust 1.98.1, this PR's head 9342153.

Test commit on top of this branch: bc7fe21. It adds emit/image_a16_tests.rs and a mipmapped texture view to the test harness (View::Mips). Three wave32 compute programs run image_sample_l, _d and _b with a16 on a 16x4 RGBA32F texture. Every texel of mip m holds m, the filter is point, and each lane stores the level it sampled. Lanes load their address dwords from a raw buffer, so the packed halves and the junk (0x5A5A) in the high halves the hardware ignores are set bit for bit. The texture is not square, so a gradient read on the wrong axis lands two levels off.

case ffe310e this PR
image_sample_l a16: f16 LOD in the low half, junk above it pass pass
image_sample_d a16: four f32 gradients, then packed (u, v). Lane l asks for level l % 5 in gradient component (l / 5) % 4 fail: got [2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, ...], want [0, 1, 2, 3, 4, 0, 1, ...] pass
image_sample_b a16: f16 bias in the low half, junk above it. Implicit derivatives come from 2x2 quads spaced one texel of level 0-2 apart, with biases -2 to +4 refused in lower pass
  • Hardware adapter and WARP give the same results.
  • The three tests passed in 11 runs out of 11.
  • dxil.dll from the SDK validates all three shaders.
  • cargo test -p victory-shader with the commit: 129 passed, 0 failed, 1 ignored.

This checks the translation end to end against the layout this PR implements (the f16 bias in its own dword; 32-bit derivatives outside _g16, as in r4tedx's review). It is not a comparison with console hardware. Not covered: _g16, _cl and _o forms, sample_b in a pixel shader, and the signature and container changes in this PR.

The commit only adds tests, so cherry-pick it if it's useful.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139028597 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/306#issuecomment-7139028597). Originally posted by [marquezinii](https://github.com/marquezinii) on 2026-11-24T17:19:42Z. --- I ran the a16 samples on a GPU and read back the mip level each lane got. The checks above are DXIL validation and offline counts, so this is the runtime side. Setup: RTX 5070 (desktop, driver 621.40, the only adapter in the machine), Windows 11 26300, Rust 1.98.1, this PR's head `9342153`. Test commit on top of this branch: [`bc7fe21`](https://github.com/marquezinii/VIctory/commit/bc7fe217c116a5829d0cc1137fb49844108761b4). It adds `emit/image_a16_tests.rs` and a mipmapped texture view to the test harness (`View::Mips`). Three wave32 compute programs run `image_sample_l`, `_d` and `_b` with `a16` on a 16x4 RGBA32F texture. Every texel of mip `m` holds `m`, the filter is point, and each lane stores the level it sampled. Lanes load their address dwords from a raw buffer, so the packed halves and the junk (`0x5A5A`) in the high halves the hardware ignores are set bit for bit. The texture is not square, so a gradient read on the wrong axis lands two levels off. | case | `ffe310e` | this PR | |---|---|---| | `image_sample_l` a16: f16 LOD in the low half, junk above it | pass | pass | | `image_sample_d` a16: four f32 gradients, then packed (u, v). Lane `l` asks for level `l % 5` in gradient component `(l / 5) % 4` | **fail**: got `[2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, ...]`, want `[0, 1, 2, 3, 4, 0, 1, ...]` | pass | | `image_sample_b` a16: f16 bias in the low half, junk above it. Implicit derivatives come from 2x2 quads spaced one texel of level 0-2 apart, with biases -2 to +4 | refused in `lower` | pass | - Hardware adapter and WARP give the same results. - The three tests passed in 11 runs out of 11. - `dxil.dll` from the SDK validates all three shaders. - `cargo test -p victory-shader` with the commit: 129 passed, 0 failed, 1 ignored. This checks the translation end to end against the layout this PR implements (the f16 bias in its own dword; 32-bit derivatives outside `_g16`, as in r4tedx's review). It is not a comparison with console hardware. Not covered: `_g16`, `_cl` and `_o` forms, `sample_b` in a pixel shader, and the signature and container changes in this PR. The commit only adds tests, so cherry-pick it if it's useful.
alexdeliu commented 2026-11-24 18:05:42 +00:00 (Migrated from github.com)

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


Merged onto main @ ffe310eb (PR head 93421530), two of the new tests fail in dxil.dll validation on this host. Both fail the same way on a retry:

  • compute_shader_implicit_sample_uses_valver_1_8_and_validates: Validator version in metadata (1.8) is not supported; maximum: (1.7). The test needs a newer dxil.dll than the one here, so it may want to skip when the validator is older.
  • row_interp_harmonizes_packed_elements_and_validates: Container part 'Pipeline State Validation' does not match expected for module.

main itself validates fine with the same dxil.dll.

Checked with CI's steps (both clippy runs with -D warnings, cargo test --workspace) on Windows 11, AMD RX 9070. Every open PR: https://gist.github.com/alexdeliu/ef9ef0ebc1776ff104b5aa8eaea18e87

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139123672 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/306#issuecomment-7139123672). Originally posted by [alexdeliu](https://github.com/alexdeliu) on 2026-11-24T17:23:32Z. --- Merged onto `main` @ `ffe310eb` (PR head `93421530`), two of the new tests fail in `dxil.dll` validation on this host. Both fail the same way on a retry: - `compute_shader_implicit_sample_uses_valver_1_8_and_validates`: `Validator version in metadata (1.8) is not supported; maximum: (1.7).` The test needs a newer `dxil.dll` than the one here, so it may want to skip when the validator is older. - `row_interp_harmonizes_packed_elements_and_validates`: `Container part 'Pipeline State Validation' does not match expected for module.` `main` itself validates fine with the same `dxil.dll`. <sub>Checked with CI's steps (both clippy runs with `-D warnings`, `cargo test --workspace`) on Windows 11, AMD RX 9070. Every open PR: https://gist.github.com/alexdeliu/ef9ef0ebc1776ff104b5aa8eaea18e87</sub>
justlovett0 commented 2026-11-24 19:04:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by justlovett0 on 2026-11-24T18:48:29Z.


Verified + integrated. Stack: main ffe310e + #175/#994/#747/#302/#193/#704/#309/#953/#1067/#986/#1260/#1267/#1254/#1276/#189 (wave64 emulation), RTX 3080 10 GB / Win10 21H2 (19044.7846) / driver 621.24 (32.0.16.2124). Re-census of captured runtime containers; world stable ~9 min, 0 device removals.

Biased 16-bit image samples + conservative depth merged (runtime emit kept; a mod.rs test-module conflict resolved to our tests). Compute emission 493/560. Note: image_gather4_l (9 of our runtime refusals) is not cleared by this PR — that needs the gather lowering (#160/#694).

AI use: Qwen Code; local measurements. No game data posted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7141179706 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/306#issuecomment-7141179706). Originally posted by [justlovett0](https://github.com/justlovett0) on 2026-11-24T18:48:29Z. --- **Verified + integrated.** Stack: main `ffe310e` + #175/#994/#747/#302/#193/#704/#309/#953/#1067/#986/#1260/#1267/#1254/#1276/#189 (wave64 emulation), RTX 3080 10 GB / Win10 21H2 (19044.7846) / driver 621.24 (32.0.16.2124). Re-census of captured runtime containers; world stable ~9 min, 0 device removals. Biased 16-bit image samples + conservative depth merged (runtime emit kept; a mod.rs test-module conflict resolved to our tests). Compute emission 493/560. Note: `image_gather4_l` (9 of our runtime refusals) is **not** cleared by this PR — that needs the gather lowering (#160/#694). AI use: Qwen Code; local measurements. No game data posted.
wbkepler commented 2026-11-24 21:03:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T20:36:41Z.


Thanks @alexdeliu, I reproduced both failures with a 1.7 dxil.dll (via VICTORY_DXIL). They are fixed in e3067ae.

  • PSV0 mismatch: this was a real emitter bug. It already existed on main, but none of main's tests hit it. When a semantic name repeats (for example TEXCOORD0 and TEXCOORD1), PSV0 kept a single copy of the name in its string table. DXC's PSV writer writes one copy per element. Validators before 1.8 compare PSV0 byte for byte, so they rejected any signature that repeats a name. 1.8 compares the strings themselves, which is why it passed here. PSV0 now writes one copy per element.
  • valver 1.8: a 1.7 validator rejects dx.valver 1.8 modules outright. I added Validator::version(), which reads IDxcVersionInfo. The compute-derivative test now skips only the dxil.dll step when the validator is older than 1.8, and the pipeline-creation check still runs. At runtime nothing changes: translated shaders never go through dxil.dll because they carry our own container hash. An old dxil.dll only affects the offline translate --validate.

Verified: the full victory-shader suite, clippy and the policy check pass with the SDK 1.8 validator. The row_interp, signature, sample-frequency and repeated-name PSV cases also validate with 1.7, 1.8 and 1.9 validators.

AI-assisted (Claude Code); checked on Windows 11 / RTX 5090.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143812697 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/306#issuecomment-7143812697). Originally posted by [wbkepler](https://github.com/wbkepler) on 2026-11-24T20:36:41Z. --- Thanks @alexdeliu, I reproduced both failures with a 1.7 `dxil.dll` (via `VICTORY_DXIL`). They are fixed in e3067ae. - **PSV0 mismatch:** this was a real emitter bug. It already existed on main, but none of main's tests hit it. When a semantic name repeats (for example `TEXCOORD0` and `TEXCOORD1`), PSV0 kept a single copy of the name in its string table. DXC's PSV writer writes one copy per element. Validators before 1.8 compare PSV0 byte for byte, so they rejected any signature that repeats a name. 1.8 compares the strings themselves, which is why it passed here. PSV0 now writes one copy per element. - **valver 1.8:** a 1.7 validator rejects `dx.valver` 1.8 modules outright. I added `Validator::version()`, which reads `IDxcVersionInfo`. The compute-derivative test now skips only the dxil.dll step when the validator is older than 1.8, and the pipeline-creation check still runs. At runtime nothing changes: translated shaders never go through dxil.dll because they carry our own container hash. An old dxil.dll only affects the offline `translate --validate`. Verified: the full `victory-shader` suite, clippy and the policy check pass with the SDK 1.8 validator. The `row_interp`, signature, sample-frequency and repeated-name PSV cases also validate with 1.7, 1.8 and 1.9 validators. _AI-assisted (Claude Code); checked on Windows 11 / RTX 5090._
SAitken91 commented 2026-11-24 21:03:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by SAitken91 on 2026-11-24T20:37:11Z.


Measured this against my #569 (same biased-a16 fix) on the retail shaders.rpf, each merged alone onto main ffe310e, victory translate --validate, Windows SDK dxil.dll:

VS/PS emitted / validated CS validated MS validated
main 12231 / 12155 1417 8152
+ #569 12275 / 12191 1417 8152
+ #306 9342153 12275 / 12275 1441 8161

Both unblock the same 44 programs (a biased image sample with 16-bit coordinates 108 → 0), but #306 also clears every remaining validator failure on this pack except the 53 mesh vertex plus primitive output size > 32768 — including the interpolation-row ones, while keeping rows in place (the reason I closed #554 in its favour). So #306 covers #569; if this lands, #569 isn't needed.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143825694 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/306#issuecomment-7143825694). Originally posted by [SAitken91](https://github.com/SAitken91) on 2026-11-24T20:37:11Z. --- Measured this against my #569 (same biased-a16 fix) on the retail `shaders.rpf`, each merged alone onto `main` `ffe310e`, `victory translate --validate`, Windows SDK `dxil.dll`: | | VS/PS emitted / validated | CS validated | MS validated | |---|---|---|---| | `main` | 12231 / 12155 | 1417 | 8152 | | + #569 | 12275 / 12191 | 1417 | 8152 | | + #306 `9342153` | 12275 / **12275** | **1441** | **8161** | Both unblock the same 44 programs (`a biased image sample with 16-bit coordinates` 108 → 0), but #306 also clears every remaining validator failure on this pack except the 53 mesh `vertex plus primitive output size > 32768` — including the interpolation-row ones, while keeping rows in place (the reason I closed #554 in its favour). So #306 covers #569; if this lands, #569 isn't needed.
upstream-sync closed this pull request 2026-11-24 23:04:03 +00:00
alexdeliu commented 2026-11-24 23:05:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by alexdeliu on 2026-11-24T22:22:09Z.


Rechecked e3067ae on the RX 9070 (RDNA4) with the stock Windows SDK 10.0.26100 dxil.dll (1.7.2308): cargo test --workspace --locked gives 348 passed, 0 failed, 6 ignored. Both PSV0 failures I reported are gone, and compute_shader_implicit_sample_uses_valver_1_8_and_validates and signature_part_preserves_element_order_within_row_and_validates pass. Thanks!

Note: the branch is still on ffe310e. Merging current main (70564ae) conflicts in emit/lower.rs and emit/shader.rs.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7146143724 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/306#issuecomment-7146143724). Originally posted by [alexdeliu](https://github.com/alexdeliu) on 2026-11-24T22:22:09Z. --- Rechecked `e3067ae` on the RX 9070 (RDNA4) with the stock Windows SDK 10.0.26100 `dxil.dll` (1.7.2308): `cargo test --workspace --locked` gives 348 passed, 0 failed, 6 ignored. Both PSV0 failures I reported are gone, and `compute_shader_implicit_sample_uses_valver_1_8_and_validates` and `signature_part_preserves_element_order_within_row_and_validates` pass. Thanks! Note: the branch is still on `ffe310e`. Merging current main (`70564ae`) conflicts in `emit/lower.rs` and `emit/shader.rs`.

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