shader: lower fixed-mip 2D texture gathers at startup #1920
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1927"
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 R0Y00/Xbox2Windows. Originally posted by avt0m4t48 on 2026-11-24T21:31:03Z.
Refs #1802. Lower the reported
image_gather4_lz2D pixel instruction for a validated constant sampler. The one-hot mask selects the texture channel, and the four taps fill four contiguous registers. The fixed guest level and Direct3D Gather both select mip zero of the bound texture view, including an SRV starting at a later resource mip. Implicit, explicit-LOD, comparison and offset gathers remain refused.The Linux encoded test fails on the upstream translator and passes with the patch. LLVM 15 reassembles all four channel cases. Linux DXC and dxv validated the generated DXIL. Windows WARP with debug enabled matched every channel in nine 64-pixel cases, and changing the first tap made the check fail at (0,0). Windows FXC also compiled all four exact startup requests to ps_5_1. Windows verification
ctest --preset release --no-tests=error -R '^startup_image_gather_lz(_warp|_hardware)?$' -Vafter buildingoffscreen_check. Physical GPU and application sampling results remain open. Source-built inputs only.Imported from R0Y00/Xbox2Windows. Originally posted by akimfomin on 2026-11-24T21:41:04Z.
Independent physical-GPU validation of exact head
682dd4f9993e33c61ddc693671ce6975981a281f, following the outstanding hardware check in this PR.ctest --preset release --no-tests=error -R '^startup_image_gather_lz_hardware$' -V: passed. Nine synthetic draws on hardware, 64 pixels and 256 channel values each, maximum absolute error 0. The wrong-tap control was rejected at pixel (0,0), channel 0 (expected 548, got 532).ctest --preset release --no-tests=error -R '^startup_image_gather_lz(_warp)?$' -V: both passed. WARP matched the same nine outputs and rejected the identical negative control. The software adapter was Microsoft Basic Render Driver 10.0.28000.3365.I built the
offscreen_checktarget in a local release build with LLVM-MinGW Clang and LLVM MASM 23.1.6, and used the checked-in fixture and CTest. Source files were unchanged. PortBridge checked the receiving discussion for the remaining physical-GPU coverage. Codex (GPT-6 family) prepared and ran the validation.Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T22:00:58Z.
Post-merge check: two acceptances the fixture does not pin
Verifying the merged state on
main(82f0db65):Four mutations to
op_image_gather4_lzintools/startup/gfx2hlsl.py, each reverted:'dmask:0x1': 'Red'↔'dmask:0x2': 'Green'self.emit('… .Gather%s …')→GatherRedhard-codedcheck_gather_sampler(words, 1, comparison=False)→(words, 0, …)dst[2] - dst[1] != 3 or dst[2] > 255dropped from the destination checkWhat the second survivor disables, exactly
check_gather_samplerline 252:With
mips = 1the bound is0, soMAX_LODmust be at or above the last visible mip — the reason the call passes1rather than the guest level. Withmips = 0the bound becomes(0 - 1) << 8 = -256, and sincew1 >> 12is non-negative the comparison is always false: theMAX_LODsanity check disappears entirely. A sampler that clamps sampling to an earlier mip than the_lzinstruction implies would then translate as if it agreed with the guest.The fixture has no case with
MAX_LODbelow the bound, so nothing notices.The other survivor
Dropping
dst[2] - dst[1] != 3 or dst[2] > 255accepts a destination that is not four contiguous registers, e.g.v[5:6]. The fourset_vwrites then run past the declared range (for i, component in enumerate('xyzw', dst[1])), silently clobbering neighbouring VGPRs instead of refusing.Suggested cases, both refusals only
Both are cheap and neither needs a device.
What is good about the merged change
The channel map, the one-hot
dmaskrequirement, the constant-sampler requirement and thedim:/modifier whitelist are all pinned by the mutations above — the first two are what I could break and they failed loudly. The comment at lines 1241–1242 ("both the guest_lzand D3D Gather select mip zero of the bound view") is exactly the kind of note a later reader needs, and it is why the1argument is worth defending with a case.Verdict
Merged and working for the accepted forms; two refusal paths are unguarded. Reporting rather than opening a change on top of a fresh merge — say the word and I will send the two cases.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T22:01:53Z.
Correction to my previous comment: the
mipsmutation is equivalent, not a gapI claimed that
check_gather_sampler(words, 1, …)→(words, 0, …)disables theMAX_LODcheck. Working the arithmeticthrough properly, that is wrong and I should not have published it:
mips = 1→ bound0, andw1 >> 12is non-negative, so the term is never true either way.mips = 0→ bound-256, sow1 >> 12 < -256is also never true.Both calls leave the
MAX_LODterm vacuous, so the mutation changes nothing observable. The real content ofcheck_gather_samplerfor this call site isw0 == 0x12(normalized clamp, no truncation),w1 & ~0x00fff000(only theMAX_LOD/MIN_LODfields may be set),w2 == 0x04500000(bilinear XY, point mip) andw3 == 0— and those are pinned:bad_wrapandbad_min_lodin the fixture both fail on thew0field, and the manifest assertion pins all four words.Given the
_lzform always reads mip 0, an unconstrainedMAX_LODis a defensible choice rather than a hole; if that is theintent, the parenthesised bound is dead for every reachable value and a reader will try to work out what it excludes.
The second mutation still stands
Dropping
dst[2] - dst[1] != 3 or dst[2] > 255from the destination check is a real acceptance change:v[5:6](two countedregisters) then reaches
and writes
v5..v8, three of which are outside the declared range — silently clobbering neighbouring VGPRs instead of refusing.The fixture has no case for a non-quad destination, so it survives.
That one is worth a case; it is the same class as the
nsaaddress check already incontrols().