Repository navigation
Description
What happens
The console compiler places a root signature's static samplers as S# words built from constants in the code, and constant_samplers (crates/xcl/src/gpu/recomp/mod.rs) turns an S# whose four words were all set that way into a static sampler of the pipeline. It follows s_mov_b32, s_movk_i32 and s_mov_b64. A word with only high bits set is written bit-reversed instead, for example
s_movk_i32 s64, 0x92
s_mov_b32 s65, 0xc00000
s_brev_b32 s66, 40 ; 0x14000000
s_mov_b32 s67, 0
image_gather4_lz v[12:15], [v13, v20], s[40:47], s[64:67]
s_brev_b32 is not followed, so this S# is not recognised and the image instruction is emitted with the fallback for an S# from memory:
SamplerState t68_S = SamplerDescriptorHeap[NonUniformResourceIndex(s67 & 0x7FFu)];
Word 3 of a constant S# is 0 here, so the instruction samples with sampler-heap entry 0, a sampler the title created for something else. Both translators are affected: the direct one calls the same function (dxil/kernel.rs).
How often
In a seeded sample of 1244 programs of a retail title (xcl shaders … --direct --sample 1500 --seed 7 --dump, then counted with constant_samplers over the decoded programs):
- 534 programs use a sampler, in 4951 sample / gather instructions;
- 1253 of those instructions get a static sampler today;
- 482 more, in 203 programs, have an S# that is constant but for one word written with
s_brev_b32.
The rest load their S# from memory (s_load_dwordx4) or set it in an earlier block. The example above is the gather at guest 0x270 of a542b07e605c8fd7.
Minimal program (fails on main 568e7db: static_samplers is empty and the HLSL contains SamplerDescriptorHeap)
let clamp = 2 | 2 << 3 | 2 << 6;
let point = [clamp, 0x00FF_F000u32, 40u32.reverse_bits(), 0];
let code = prog(&[
("S_MOV_B32", "ENC_SOP1", &[("SDST", 24), ("SSRC0", 255)], Some(point[0])),
("S_MOV_B32", "ENC_SOP1", &[("SDST", 25), ("SSRC0", 255)], Some(point[1])),
("S_BREV_B32", "ENC_SOP1", &[("SDST", 26), ("SSRC0", 128 + 40)], None),
("S_MOV_B32", "ENC_SOP1", &[("SDST", 27), ("SSRC0", 128)], None),
("IMAGE_SAMPLE_LZ", "ENC_MIMG", &[("VDATA", 10), ("VADDR", 0), ("SRSRC", 4), ("SSAMP", 6), ("DMASK", 0xF), ("DIM", 1)], None),
]);
let t = translate(&code, &Options::default()).unwrap();
assert_eq!(t.static_samplers, vec![(point, false)]);Fix (branch, PR to follow once its GPU test and the regression runs are done): one more arm in constant_samplers that takes s_brev_b32 of a constant as the constant it is. https://github.com/Prime1997/xcl-compat-fixes/commit/253bc79d0b46f7a58945c9aa0b3e03cb132ba13b
Checked for duplicates: main at 1a0bbe3 has no S_BREV_B32 in constant_samplers; no open PR or issue I could find covers it (the open PRs that mention s_brev, #620, #1597, #1672 and #2091, are about the instruction itself or about mask trees, going by their titles).
Not tested: what the wrong sampler does to the picture in the title (which sampler sits in entry 0 depends on the run); the GPU test of the fix has not been run yet.
Setup: main 568e7db, RTX 3060 Ti 8 GB (driver 617.14), Windows 11 26200, DXC 1.9.2609.5.
AI use: Claude Code (Claude Fable 5.2) found this, wrote the fix, the test and this report, and posted it at Prime's request; the runs were on Prime's machine.
Activity