startup: lower image_sample_b in gfx2hlsl #2044
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2051"
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 JB2WIN on 2026-11-24T23:39:17Z.
Refs #1996 (item D)
Change
tools/startup/gfx2hlsl.pynow lowersimage_sample_bin the pixel stage asSampleBias.Address layout: the AMD RDNA 2 ISA (30 November 2020, section 8.2.4, table 43) defines
_Bas "LOD BIAS … Add this BIAS to the LOD computed". Section 8.2.5 orders the address{offset} {bias} {z-compare} {derivative} {body}, with the bias as one float dword. So the bias is the first address VGPR, before the coordinates. LLVM 15 agrees:IntrinsicsAMDGPU.tdAMDGPUSample_bhas abiasextra argument, andMIMGInstructions.tdhasIMAGE_SAMPLE_Bwith opcode 0x25.Forms: the same dimensions as the existing
image_sample_lpath (2D, 2D-array, 3D), including the NSA spelling. 1D, cube and MSAA stay refused.Refused:
image_sample_b_cl,image_sample_c_b*,_b_oandimage_gather4_b;exec, or code after a branch, where the neighbouring path would fall back to level 0 and lose the bias;unorm,r128,tfe,lwe,a16,d16, an emptydmaskand reserved bits;glc/slc/dlcare accepted, as forimage_sample_l.Test
New check
tests/startup_image_sample_b_check.py, registered asstartup_image_sample_b_controls,_warpand_hardware. It also has an LLVM 15binarymode (30 fixture words) and is listed in the pure-Python job andAGENTS.md. Short notes are added todocs/experiments.mdanddocs/startup-runtime.md.uinitialiser of the translated HLSL with a screen-dependent value, giving an implicit LOD of 1, and leaves theSampleBiascall untouched. The check and the docs say so.image_samplereads mip 1 in every case, so the expectations for bias -1 and +1 fail. Replacing the bias with 0, negating it, swapping it withu, or callingSampleinstead each read a different cell.gfx2hlsl.py, ignoring the bias and swapping it with the first coordinate both make the controls fail. Againstmain'sgfx2hlsl.pythe check fails withUnsupported: image_sample_b.On commit
79a74816(rebased on06cdc47d), with an NVIDIA GeForce RTX 3080 (driver 32.0.16.2124), WARP 10.0.26100.9818 and Windows 11 build 26200:Not covered: heap samplers' own LOD bias and LOD limits (accepted, as for
image_sample), bias values outside -16..15.99, fractional bias with a linear mip filter, and a plain-2D or 3D draw (the renderer only has mips for the 2D-array texture; those forms are checked at the text level).AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T00:54:51Z.
Review: CHANGES_REQUESTED
The translated fixture passes on WARP and RTX 4060 Laptop with both FXC and DXC, including the unbiased controls. It sets guest MAX_LOD to 2 and uses a texture whose last mip is already 2, so it cannot detect dropped sampler limits. The translated sampler currently leaves MinLOD at zero and MaxLOD unbounded, and the heap path bypasses even the constant-bias check. Please preserve the relevant guest clamp/bias or refuse descriptors for which it cannot be proven irrelevant, including dynamic samplers in this slice. Use a texture with a visible next mip and a guest MAX_LOD below it as the discriminator.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T23:52:35Z.
Ran it, broke it five ways — all caught, including each clause of the three-part guard
cs[-1], the_Lconvention)exec_known) clause is dropped_Land_Baddress splits are swappedThe part I would defend hardest, and it is covered
sample_bneeds the coordinate derivatives, which only exist in a pixel stage that still runs under its entry mask with no control flow:Three separate reasons, and each one is independently mutation-caught. That matters more than usual here, because the fallback the code
deliberately refuses is worse than a refusal: lowering a biased sample to
SampleLevel(…, 0)would return a valid-looking colour at the wrong mip,and no downstream check would see it as anything but pixels.
The address layout is the other half —
{ offset } { bias } { z-compare } { derivative } { body }puts the bias before the coordinates, opposite to_L's trailing LOD — and taking it from the wrong end is mutation one.What the fixture pins beyond the lowering
The refusal list is long and specific (
b_cl,c_b, offset, gather4_b, cube, MSAA, 1D, a16, d16, tfe, lwe, unorm, r128, dmask 0, reserved bits,sampler LOD bias), which is the right shape for this translator: each of those would change how many dwords the address block consumes or how the
result is filtered, and silently reading the wrong dword is indistinguishable from a working shader until the image looks wrong.
draw model: 6 distinct (mip, slice) cellsis the line I trust most in that output — it means the check does not stop at the emitted text butpropagates into what cell each thread samples.
One thing worth stating in the description
The PR says the bias is "the first address VGPR, before the coordinates" and cites section 8.2.5. That is the whole risk of this patch in one
sentence, and it is currently only in a source comment. If a reviewer has the PDF, quoting the ordering table in the description would let the next
contributor check
image_sample_b_cland the other combinations without re-deriving it.What I did not check
No shader compiled or run:
SampleBiassemantics (bias added to the derivative-derived LOD, clamped by the sampler's min/max) are asserted by thedraw model, not by me. And the "static sampler carries neither the descriptor's LOD bias nor…" reasoning is about the stand-in's model, which I read
but cannot measure without a build.
Notes
Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-25T00:26:42Z.
I checked the operand order against the RDNA 2 ISA address order (section 8.2.5, bias before the body). The bias is the first address register in every form: plain, NSA, array, 3D.
Run on the head (
79a74816), pure Python:python -B tests/startup_image_sample_b_check.py: all controls print, including the refusals of_b_cl,_c_b, offsets, cube, MSAA, 1D, a16, d16, tfe, lwe, unorm, r128, an empty dmask, reserved bits and a sampler with an LOD bias.startup_image_sample_l_check.py,startup_image_3d_check.pyandstartup_translator_check.py.A second, independent lowering (not public) agrees on the operand order and on refusing a16. One difference: it does not refuse a constant sampler whose word 2 carries an LOD bias, and yours does. I think yours is right.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:55:47Z.
Review: COMMENTED
Review of head
79a74816aea1d5a9693eb07531c6846739445e72(comment only, no approval).Summary: The
image_sample_blowering toSampleBiasis correct. The bias is the first address dword, which matches the RDNA 2 ISA address order. The refusal list is conservative and the guards look right. No P1 or P2 findings.State
Commands run locally in a worktree of this head
git diff --stat origin/main...HEAD: 7 files, +579/-8.python3 tests/startup_image_sample_b_check.py: ended withSelf-test passed.It covers the address layouts (plain, NSA, array, NSA array, 3D), the no-bias Sample case, the refusals (b_cl, c_b, offset, gather4_b, cube, MSAA, 1D, a16, d16, tfe, lwe, unorm, r128, dmask 0, reserved bits, sampler LOD bias) and the accepted glc/slc/dlc/partial dmask.python3 tests/docs_links_check.py: 391 links OK, self-test passed.python3 tests/bidi_controls_check.py: 1404 files, no bidi controls.git diff --check origin/main...HEAD: clean.Mutations (both reverted with
git checkout -- .)tools/startup/gfx2hlsl.py, I changedbias, cs = cs[0], cs[1:]tocs[-1], cs[:-1]. The check failed with an AssertionError on the array case, so the mutation is killed.if False:. The check failed, though by a crash (AttributeError: 'Stage' object has no attribute 'pipe') rather than a clean assertion. It is still killed.Nits (not blocking)
gfx2hlsl.py(sampler LOD-bias refusal):wordsisNonefor a heap sampler, so thewords[2] & 0xfffffcheck is skipped. That looks intended, since a heap sampler carries its own state. One test line pinning "heap sampler with bias is accepted (or refused)" would document the choice.len(self.blocks) > 0refuses all bias samples after any branch. It is conservative and correct. It may cost coverage on real shaders later, so a follow-up note in the docs would help.Unsupportedfor a non-pixel stage would give a clearer failure message.I did not run a Win2025 WARP job. The CI Windows build/test passed, and the PR's own
_warpand_hardwareregistrations cover that path. The Windows readback result should be confirmed from the author's Verification block before Ready.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:15:43Z.
Review: COMMENTED
Review of head
3222f965ff6786215abc427d7cce08bbe9fb6c26(comment only, no approval). This is a re-review: my earlier review covered79a74816; the new commit3222f965adds the sampler LOD-limit handling.Summary: The new
smplmanifest line and the refusals insample_b_samplerlook correct. MIN_LOD (word 1 bits 11:0) and MAX_LOD (bits 23:12) are u4.8, so/256is right. LOD_BIAS in word 2 bits 19:0 and MIP_FILTER in word 2 bits 27:26 match the gfx10 SQ_IMG_SAMP layout. Refusing a heap or register sampler, a nonzero descriptor bias, mip filter 0 and MIN_LOD above MAX_LOD is conservative and sound.smpandsmpclines are unchanged for every other sample form. No P1 or P2 findings in the code.State
startup_sampler_comparisonand the WARP/hardware sample_b fixtures). The /O2 job and the chart job are skipped.Commands run locally in a worktree of this head
git diff --stat origin/main...HEAD: 9 files, +788/-18.python3 tests/startup_image_sample_b_check.py: "Self-test passed." (limits, refusals and the 6-cell draw model all listed).python3 tests/docs_links_check.py: 18 files, 399 links, passed.python3 tests/bidi_controls_check.py: 1445 files, no bidi controls.git diff --check origin/main...HEAD: clean.if False:. The check failed with "mip filter none was accepted". Restored.if False:. The check failed with "array min3 max2 was accepted". Restored.Findings
git log --format=%B origin/main..HEAD | grep -i ai-assisted.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-25T02:10:08Z.
Pushed
3222f965(rebased on currentmain) for the review:MIN_LOD / MAX_LOD are carried over.
image_sample_bnow emits its constant sampler as a new manifest linesmpl, and the runtime'sdecode_samplersetsMinLOD = MIN_LOD/256andMaxLOD = MAX_LOD/256. Both fields are u4.8, per the RDNA 2 ISA section 8.2.7. The bit positions come from Mesa 24.0.0src/amd/registers/gfx10-rsrc.json(MIN_LOD 0–11, MAX_LOD 12–23) and the encoding fromsi_state.c, which usesS_FIXED(x, 8). Thesmp/smpclines of the other sample forms are unchanged.Still refused: a guest LOD bias, because the ISA scales it by
T#.perf_modulationand the desktop sampler has no matching field. Also a mip filter of 0 (mipmapping off),MIN_LOD > MAX_LOD, and every heap or register sampler forimage_sample_b, including the default-sampler shortcut for a heap load with a register offset.Discriminator on the existing 3-mip texture, drawn on WARP and hardware with DXC and FXC:
Each case is also drawn through a plain
smpline without the limits and must give the unclamped mip.Mutations: both fail the tests. Dropping the MaxLOD assignment fails
startup_sampler_comparisonandstartup_image_sample_b_warp. Accepting a heap sampler fails the controls.Results:
ctest --preset dev --no-tests=error -R '^startup_(image_|gfx2hlsl|sampler)'passed 82/82 before the rebase, and all pure checks pass after it.image_sample,image_sample_landimage_sample_lzstill drop MIN_LOD/MAX_LOD, and they accept heap samplers unchecked. I left them alone here and can take them as a follow-up.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-25T02:54:14Z.
@tedin7, thanks for the re-review. About the trailer nit: I can't find a rule against naming the AI tool or model in this repository.
.github/PULL_REQUEST_TEMPLATE.mdasks for AI assistance to be stated, and several merged commits onmaincarry the sameCo-Authored-Byline. If the rule lives elsewhere, please point me to it and I'll reword the commits.On the Windows readback:
startup_image_sample_b_{warp,hardware}passed locally on WARP 10.0.26100.9818 and on an RTX 3080 (32.0.16.2124), Windows 11 build 26200; see the verification above.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-25T03:56:32Z.
Hardware run, RX 9070 XT (driver 32.0.32029.2010), dxc
ps_6_0and fxcps_5_1:The biased sample lands on the mip the bias selects, and the plain-sample mutation still fails, so the readback really distinguishes the two.
Limits: AMD only, no NVIDIA here.
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T06:58:38Z.
Review: APPROVED
The previous LOD finding is resolved. The updated branch carries the constant sampler limits and refuses dynamic samplers for this slice. On Windows Release I reran ten selected checks on the merge resolution. WARP and RTX 4060 Laptop both reproduced the dropped-limit controls in DXC and FXC with a visible mip above MAX_LOD. The A16 sampler and D16 image-load regressions also passed. The latest pushed commit still needs its applicable CI.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T07:00:33Z.
Review: COMMENTED
Review of head
434aa2fee6adce4865e5d6804b996749367be0d6(comment only, no approval). Re-review: my earlier review covered3222f965. The new commit434aa2feis a merge of main that keeps the sampler-bias and image-load support.Summary: The
image_sample_blowering is unchanged in substance since the last review. Thesmplmanifest line, the/256decode of MIN_LOD and MAX_LOD, and the refusals insample_b_sampler(heap, register sampler, nonzero LOD bias, mip filter 0, MIN_LOD above MAX_LOD) still read correctly after the merge. The bias dword is taken before the coordinates andSampleBiasis only emitted in a pixel stage with a known entry mask and no branches (tools/startup/gfx2hlsl.py:1946-1970,:2021-2046,:2150-2175). No P1 or P2 findings in the code.State
startup_sampler_comparisonand the WARP/hardware sample_b fixtures at this head, and the merge did not touch the sample_b lowering.Commands run locally in a worktree of this head
git diff --stat origin/main...HEAD: 9 files, +788/-18.python3 tests/startup_image_sample_b_check.py: exit 0, last line "draw model: 6 distinct (mip, slice) cells".python3 tests/docs_links_check.py: "Checked 18 Markdown files and 417 links."python3 tests/bidi_controls_check.py: "Checked 1519 tracked source, script and build/CI files: no bidirectional controls."git diff --check origin/main...HEAD: clean.if False:. The check failed with "AssertionError: mip filter none was accepted". Restored withgit checkout -- ..Findings
git log --format=%B origin/main..HEAD | grep -i -E 'co-authored|ai-assisted'returns 4 lines). The repo rule is no AI model names or codenames on GitHub. Please reword those commit messages before merge, or make sure the squash message drops those lines.AI-assisted; commands listed were executed locally.