Shader: fix biased 16-bit image samples and DXIL validator failures #306
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!306
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/306/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@wbkepler on GitHub · 2026-11-24 02:12 UTC · original
wbkepler:shader/validator-and-16bit-sample-fixes→main· +566 −59 · 6 files · 3 commits · closed without mergingSummary
Fixes 5 shader emission and DXIL container/validator issues in
victory-shader(+176 newly validated shaders, 100% of emitted VS/PS/CS validating cleanly):emit/lower.rs):a16biased image samples (image_sample_b) by separating full 32-bit prefix VGPRs (offsets, bias, comparison reference) froma16-packed tail operands (gradients, coordinates, explicit LOD) matching GFX10 MIMG hardware layout.SV_Position(emit/mod.rs):SV_Positioninterpolation tolinear_noperspective_centroid(5) in pixel shaders outputting conservative depth (SV_DepthLessEqual/SV_DepthGreaterEqual).emit/mod.rs,emit/lower.rs):harmonize_row_interp()so packed elements in the same signature row share one interpolation mode (propagatingConstantfor integer/SV_IsFrontFacerows and inheriting read modes for unread PS siblings).emit/container.rs):ISG1/OSG1signature rows by register only (preserving element-ID order within a row to match DXIL validator expectations).emit/shader.rs):dx.valver = 1.8andPSVRuntimeInfo3(52 bytes withEntryFunctionName).Verification
cargo clippy --workspace --all-targets— passed (zero new warnings)cargo clippy -p victory --features diagnostics --all-targets— passedcargo test --workspace— passed (victory-shader: 74/74 including 5 newdxil.dllvalidation and D3D12 compute PSO tests)cargo xtask policy— passed (151 files ok)Fixes 5 shader emission and DXIL container/validator issues in `victory-shader`, raising validated shaders across the test corpus from 21,983 to 22,159 (+176; 100% of emitted VS/PS/CS shaders now validate cleanly): 1. Biased 16-bit image samples (`emit/lower.rs`): - Remove the `a16` rejection on `image_sample_b` and separate 32-bit prefix operands (offsets, bias, comparison reference) from `a16`-packed tail operands (gradients, coordinates, explicit LOD) starting at `regs[first]`, matching GFX10 MIMG hardware operand layout. 2. Conservative depth `SV_Position` interpolation (`emit/mod.rs`): - Declare `SV_Position` with `linear_noperspective_centroid` (5) instead of `linear_noperspective` (4) in pixel shaders outputting `SV_DepthLessEqual` or `SV_DepthGreaterEqual` (kinds 18/19). 3. Per-row interpolation mode consistency (`emit/mod.rs`, `emit/lower.rs`): - Add `harmonize_row_interp()` so elements sharing a signature row always declare the same interpolation mode: rows containing integer attributes or `SV_IsFrontFace` propagate `nointerpolation` (1) to sibling elements, and after pixel-shader lowering unread siblings inherit the actual read mode of sibling elements in the same row. 4. Container signature row ordering (`emit/container.rs`): - Sort `ISG1`/`OSG1` rows stably by register only (`row`) rather than `(row, col)`, preserving DXIL element-ID order within a row so the container signature matches DXIL validator expectations byte for byte. 5. SM 6.6 compute-shader implicit derivatives (`emit/shader.rs`, `emit/container.rs`, `emit/lower.rs`): - Track compute shaders emitting implicit-derivative sampling ops and emit `dx.valver = 1.8` with `PSVRuntimeInfo3` (52 bytes, carrying `EntryFunctionName`), enabling validation and D3D12 compute PSO creation. Adds 5 unit + `dxil.dll` validation (+ D3D12 compute PSO) tests in `emit::tests`.PSV0 shared one string-table copy of a repeated semantic name (TEXCOORD0 and TEXCOORD1 pointing at the same "TEXCOORD"). DXC's PSV writer writes one copy per element, and validators before 1.8 compare PSV0 byte for byte, so any signature repeating a name was rejected there ("Pipeline State Validation does not match"); 1.8 compares the strings and accepted both. Checked against dxil.dll 1.7, 1.8 and 1.9. Validator::version() reads IDxcVersionInfo; the compute-derivative test skips dxil.dll validation when the validator predates 1.8, which rejects dx.valver 1.8 outright. Translated shaders never go through dxil.dll. Reported by @alexdeliu. Co-Authored-By: Claude Opus 5.5 <[email protected]>@r4tedx on GitHub · 2026-11-24 03:14 UTC · original
Review note on the a16 address layout, two points where this differs from LLVM's AMDGPU backend:
image_sample_b ... a16with "a 32-bit f32 bias", and the lowering reads the bias dword whole.SITargetLowering::lowerImagehas: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.
_g16opcodes; LLVM'sgfx10_asm_mimg.shasimage_sample_d ... dim:SQ_RSRC_IMG_2D a16with 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 on GitHub · 2026-11-24 03:40 UTC · original
Thanks @r4tedx, you're right on both points. Fixed in a8430f2:
legacyF16ToF32) instead of as an f32. The syntheticimage_sample_b ... a16test 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._g16opcodes, 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 (2Dimage_sample_d ... a16= 5 dwords,_g16packs 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 policypass.@iurysf on GitHub · 2026-11-24 06:02 UTC · original
Measured offline against main
d2a4bae:victory translate --list --validateover the title'sshaders.rpf+ executable (26,096 programs), dxil.dll 1.9.2602.17 (DXC v1.9.2602).vertex plus primitive output size is greater than 32768.incompatible with the shader stagerejections grow to 34 with #309 and 45 with #385 alone (newly emitted compute programs with implicit-derivativesample). This PR clears them all, so it's worth landing before or with those two.Texture2D.Samplecompiled by dxc with-T cs_6_6 -validator-version 1.6or1.7fails with exactly this error, and it passes with1.8. Sodx.valver1.8 for compute derivatives is the right fix.@slint6614-dev on GitHub · 2026-11-24 07:23 UTC · original
Measured on the full retail shader pack (26,503 containers) with
victory translate --validate, against maind2a4bae:cargo test -p victory-shaderAll four clear the 108 "biased image sample with 16-bit coordinates" programs identically. #73 and #318 also clear the 27
image_sample_d_clrefusals, 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.@ordis-labs on GitHub · 2026-11-24 15:00 UTC · original
Rebased this onto current main (
ffe310e) locally to measure it there, since it no longer merges cleanly. Three things needed: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 plusharmonize_row_interp(interpolated)and dropped main's block. Same result forSV_Position.emit/lower.rs: #634 (image_sample_o) addedaddr_val(self, 0)in the old two-argument form. With this PR'saddr_val(l, start, k)that becomesaddr_val(self, 0, 0), which is identical to main'saddr_val(l, k).emit/mod.rs(~line 806):resource::tracktakesSome(&st)sinceffe310e, sostructuregoes first.Results on
ffe310e(translate --list --validateover the 1.0.2.1shaders.rpf, SDK 10.0.26100dxil.dll, outcomes matched program by program against main):harmonize_row_interpfixes (TEXCOORD/NORMAL/COLOR/SV_IsFrontFacelocations, input/output signature mismatches) plus 24 "incompatible operation".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 on GitHub · 2026-11-24 17:19 UTC · original
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 addsemit/image_a16_tests.rsand a mipmapped texture view to the test harness (View::Mips). Three wave32 compute programs runimage_sample_l,_dand_bwitha16on a 16x4 RGBA32F texture. Every texel of mipmholdsm, 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.ffe310eimage_sample_la16: f16 LOD in the low half, junk above itimage_sample_da16: four f32 gradients, then packed (u, v). Lanelasks for levell % 5in gradient component(l / 5) % 4[2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, ...], want[0, 1, 2, 3, 4, 0, 1, ...]image_sample_ba16: 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 +4lowerdxil.dllfrom the SDK validates all three shaders.cargo test -p victory-shaderwith 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,_cland_oforms,sample_bin 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 on GitHub · 2026-11-24 17:23 UTC · original
Merged onto
main@ffe310eb(PR head93421530), two of the new tests fail indxil.dllvalidation 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 newerdxil.dllthan 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.mainitself validates fine with the samedxil.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@justlovett0 on GitHub · 2026-11-24 18:48 UTC · original
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 on GitHub · 2026-11-24 20:36 UTC · original
Thanks @alexdeliu, I reproduced both failures with a 1.7
dxil.dll(viaVICTORY_DXIL). They are fixed ine3067ae.TEXCOORD0andTEXCOORD1), 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.dx.valver1.8 modules outright. I addedValidator::version(), which readsIDxcVersionInfo. 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 offlinetranslate --validate.Verified: the full
victory-shadersuite, clippy and the policy check pass with the SDK 1.8 validator. Therow_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 on GitHub · 2026-11-24 20:37 UTC · original
Measured this against my #569 (same biased-a16 fix) on the retail
shaders.rpf, each merged alone ontomainffe310e,victory translate --validate, Windows SDKdxil.dll:main9342153Both unblock the same 44 programs (
a biased image sample with 16-bit coordinates108 → 0), but #306 also clears every remaining validator failure on this pack except the 53 meshvertex 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.@alexdeliu on GitHub · 2026-11-24 22:22 UTC · original
Rechecked
e3067aeon the RX 9070 (RDNA4) with the stock Windows SDK 10.0.26100dxil.dll(1.7.2308):cargo test --workspace --lockedgives 348 passed, 0 failed, 6 ignored. Both PSV0 failures I reported are gone, andcompute_shader_implicit_sample_uses_valver_1_8_and_validatesandsignature_part_preserves_element_order_within_row_and_validatespass. Thanks!Note: the branch is still on
ffe310e. Merging current main (70564ae) conflicts inemit/lower.rsandemit/shader.rs.Pull request closed