Shaders: support image_sample_b with a16 and _cl LOD-clamp variants #73
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/73"
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 Yaekai on 2026-11-24T00:13:12Z.
In GFX10/RDNA2 MIMG instructions with
a16=1,offset(_o),bias(_b), andz-compare(_c) remain full 32-bit VGPRs at the start ofvaddr, while gradients, coordinates, LOD, and clamp are packed in 16-bit pairs starting after them (matchinggfx10::fields::image_addr_dwords).Changes
crates/victory-shader/src/emit/lower.rsinto full 32-bit prefix VGPRs (addr_u32) anda16-packed trailing components (addr_packed), removing thea16+image_sample_bbailout._clLOD-clamp variants (image_sample_cl,image_sample_b_cl,image_sample_d_cl,image_sample_c_cl) by passing the trailing clamp component to DXIL'sclampargument.unorm/ gradients /get_lod) ahead of coordinate reads so cube gradient samples report the right reason instead of an out-of-bounds address.Verification
cargo test -p victory-shader: 57/57 passed.victory translate --validateon GTA VIshaders.rpf(26,084 programs):a biased image sample with 16-bit coordinates:108→0image_sample_d_cl:27→012,272→12,316(+44 complete shaders, all passingdxil.dllvalidation with 0 new validator errors).Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T00:59:52Z.
Tested
6c8af09on Arch Linux x86_64, rustc 1.98.1: pass, no regression only.cargo test -p victory-shader: 51 passed, 0 failed (2 test binaries). The diff adds no test for theimage_sample_ba16 /_clLOD-clamp variants, so the new paths are unexercised; a fixture per variant would cover them.victory-gpuE0425.No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
Imported from Marvisak/VIctory. Originally posted by Sunkiller-qc on 2026-11-24T01:29:28Z.
With
a16set, the LOD bias is an f16 in the low half of its own dword, and the upper 16 bits are undefined. See LLVM'sSITargetLowering::lowerImage: "Bias is of type half but occupies full 32-bit" (D111754/D116038). Here the whole dword is read as an f32 (crates/victory-shader/src/emit/lower.rs:5555-5556), so an a16image_sample_b*gets a garbage bias. Converting the low half withlegacyF16ToF32would fix it. #160 does it that way and points out the disagreement. #136 has the same code (lower.rs:5660-5661).Static review, not built or run.
Imported from Marvisak/VIctory. Originally posted by r4tedx on 2026-11-24T01:43:23Z.
A note from comparing this with #160, which covers the same a16 bias and
_clforms: the two read the a16 bias differently. Here the bias dword is taken as a full f32 (addr_u32), in #160 as an f16 in the low half of that dword. LLVM'sSITargetLowering::lowerImagehas:so with a16 the bias keeps its own dword but holds a half in the low 16 bits (the upper half is undefined); the offset and the comparison reference stay 32-bit. Read as an f32, an f16 bias comes out as a denormal near zero, so the sample would lose its bias without failing.
One related point I got wrong myself and fixed in #160: on GFX10.3 a16 does not make the derivatives 16-bit (only the
_g16opcodes do); LLVM'sgfx10_asm_mimg.shasimage_sample_d ... 2D a16with five address dwords. Worth checking here if_dforms with a16 pass through this code.From the sources only, not run on hardware. No game data used.
Imported from Marvisak/VIctory. Originally posted by Yaekai on 2026-11-24T02:31:33Z.
Thanks @Sunkiller-qc and @r4tedx for the great catches! Updated and rebased onto
d2a4baein3eab56a:a16, LOD bias is now masked to its low 16 bits and converted vialegacyF16ToF32instead of being bitcast asf32._g16image_sample_d*derivatives now stay 32-bit (addr_u32+as_float, andimage_addr_dwordsingfx10/fields.rsonly halves derivative dwords for_g16opcodes).cargo test -p victory-shader(71/71 passed) andvictory translate --validateonshaders.rpf(0 new validator errors).Imported from Marvisak/VIctory. Originally posted by slint6614-dev on 2026-11-24T07:23:38Z.
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.Pull request closed