Shader: fix biased 16-bit image samples and DXIL validator failures #306
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/306"
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?
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):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)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:
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.
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: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.Imported from Marvisak/VIctory. Originally posted by iurysf on 2026-11-24T06:02:20Z.
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.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 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.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.valver1.8 + PSVRuntimeInfo3). The approach is correct and the emitted bytes are right:RuntimeInfoSize52, with theEntryFunctionNamestring-table offset 1 (main\0appended 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 (60Sample, 61SampleBias, 64SampleCmp, 81CalculateLOD) is exactly the implicit-derivative set —SampleLevel(62),SampleGrad(63) andSampleCmpLevelZero(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_btoSampleGrad, 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, afterfill_phis) andemit. The function only rewrites elements withusage == 0and never changes the mode it computes from, so the second pass is a no-op — redundant but harmless. ForcingConstanton rows that holdSV_IsFrontFaceor integer elements matches the validator's one-interpolation-mode-per-row rule.Conservative depth. Switching the pixel
SV_Positioninput tolinear_noperspective_centroid(5) when the shader outputsSV_DepthLessEqual/SV_DepthGreaterEqualmatches the validator's conservative-depth requirement; leaving it at 4 otherwise is right.a16 layout. The
a8430f2fix matches LLVM'slowerImage: the bias is an f16 in the low half of its own dword, and derivatives stay 32-bit outside the_g16opcodes. The two points @r4tedx raised are addressed.One process note: the PR is currently
dirtyagainstmain(ffe310e) and needs a rebase before it can land.No blockers from what I can check statically. AI-assisted.
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: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.
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 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.
Imported from Marvisak/VIctory. Originally posted by alexdeliu on 2026-11-24T17:23:32Z.
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/ef9ef0ebc1776ff104b5aa8eaea18e87Imported 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.
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(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.
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 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.Imported from Marvisak/VIctory. Originally posted by alexdeliu on 2026-11-24T22:22:09Z.
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.upstream-sync referenced this pull request2026-11-25 02:06:26 +00:00
Pull request closed