Recompiler: a static sampler whose S# word is written with s_brev_b32 falls back to sampler-heap entry 0 #2274

Closed
opened 2026-11-25 12:24:29 +00:00 by Prime1997 · 0 comments
Prime1997 commented 2026-11-25 12:24:29 +00:00 (Migrated from github.com)
Contributor

Imported from ivall/xcl. Originally posted by Prime1997 on 2026-11-25T12:24:29Z.


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. github.com/Prime1997/xcl-compat-fixes@253bc79d0b

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.

<!-- greyfinch-sync:ivall/xcl:issue:6604410441 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2284). Originally posted by [Prime1997](https://github.com/Prime1997) on 2026-11-25T12:24:29Z. --- **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`) ```rust 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.
Sign in to join this conversation.
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
xcl-dev/xcl#2274
No description provided.