startup: keep the implicit LOD of a plain image_sample past a uniform join in gfx2hlsl #2691
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2699"
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 tedin7 on 2026-11-26T02:32:33Z.
Part of #1723
What this unblocks: a plain
image_samplepast a uniform branch or join in a pixel shader samples the mip the guest's derivatives pick, instead of always mip 0.What changed
tools/startup/gfx2hlsl.py: after a block boundary a plainimage_samplewas lowered toSampleLevel(.., 0). It now lowers to the implicit-LODSamplewhere the ruleimage_sample_bandimage_get_lodalready use holds: pixel stage, entry EXEC mask, wave-uniform control flow so far (uniform_cf), and no divergent back edge over the call (checked after the pass, likederivative_sites).SampleLevel(.., 0)exactly as before. Nothing new is refused: a plain sample that translated before still translates.tests/startup_image_sample_implicit_lod_check.py(registered asstartup_image_sample_implicit_lod_controls): on the recordedc_lzfixture with the MIMG opcode set toimage_sample: straight line,s_cbranch_scc0and a uniform join giveSample; divergent EXEC,s_cbranch_vccz/vccnz/execz/execnzbefore the call, and a divergent back edge over it stay level 0.Why it is correct
A plain
image_sampletakes its LOD from the coordinate derivatives of the pixel quad (RDNA 2 ISA, MIMG sample). HLSLSampledoes the same. The quad runs the call together exactly whenimage_sample_b/image_get_lodare accepted today, so the same condition decides it here.What stays level 0
Shaders whose EXEC is no longer the entry mask (for example the
s_wqmbracket an LLVM-built pixel shader puts around a sample) and divergent control flow. Those need their own proof and are not changed here.Verification:
python3 tests/startup_image_sample_implicit_lod_check.py: passes on this branch; onorigin/main(fa189d2ef) it fails at thebranchcase (SampleLevel(.., 0)).startup_image_sample_b_check.py,startup_gfx2hlsl_image_get_lod_check.py,startup_image_sample_lod_check.py,startup_inline_sampler_check.py,startup_image_sample_c_check.py.tests/startup_gfx2hlsl*check*.pyandtests/startup_*pixel*check*.pyrun on this branch and onorigin/main: identical pass/fail (the same 2 draw checks,startup_gfx2hlsl_export_null_draw_check.pyandstartup_gfx2hlsl_mul24_align_draw_check.py, fail on both without the Windows draw runner).tests/startup_image_sample_b_check.py(draw, registered asstartup_image_sample_b_warp/_hardware) now draws the recorded array fixture with a uniform join before a plainimage_sample. It must read mip 1 (the implicit LOD from the derivatives); the mip-0 expectation, whatSampleLevel(.., 0)reads, must fail on the readback (negative control).904f21e6plus the commit that adds that readback, default 5-slot pool),python3 x2w_pipe.py win2025 2699 --patch <diff> --no-skip-build --regex 'startup_image_sample_b|startup_image_sample_implicit_lod|startup_gfx2hlsl_image_get_lod|startup_image_sample_lod|startup_inline_sampler': dev 10/10 and release 10/10 passed (startup_image_sample_b_warp/_hardware,startup_image_sample_lod_warp/_hardware,startup_inline_sampler_warp/_hardwareand the controls). An earlier run without a fresh build failed at the existing sample_b and sample_lod draws with "Expected one inline sampler in the image 3D draw" (a stale draw executable on the node, also in the untouched sample_lod draw);startup_image_sample_implicit_lod_controlspassed in that run (11/11 controls and inline-sampler tests), and the rerun's slot did not list it.cmake --build --preset dev --target offscreen_checkthenctest --preset dev --no-tests=error -R '^(startup_image_sample_b|startup_image_sample_implicit_lod|startup_image_sample_lod)' -V.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T03:02:40Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
9cc7c38305ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:48:33Z.
Ready for review, @MasterDomino.
Added after the independent check: a WARP/hardware readback of the new path in
startup_image_sample_b_check.pydraw (plainimage_sampleafter a uniform join reads mip 1; the mip-0 expectation must fail). Win2025 on head904f21e6plus that commit (9cc7c3830): dev 10/10 and release 10/10 passed withx2w_pipe.py win2025 2699 --patch <diff> --no-skip-build --regex <image sample tests>. Details are in the PR body.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T02:48:43Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
9cc7c38ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T03:02:41Z.
Code review location:
tools/startup/gfx2hlsl.py; line 2128For a pixel loop shaped
L: image_sample ...; ...; s_cbranch_vccnz exit; s_branch L,uniform_cfis still true when the sample is visited, anddivergent_back_edgesremains empty because the conditional edge is forward and the backward edge is unconditional. I reproduced this with a synthetic gfx1013 fixture containing a varying loop limit and UV updates: it now emitsSamplewhere the parent emittedSampleLevel(..., 0). Sincebody()lowers the exit to a per-pixelpcbranch, subsequent iterations can run on incomplete quads, making implicit derivatives undefined and mip selection unreliable. Check divergent CFG regions, including forward loop exits, before choosing the implicit call.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:47:49Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:48:48Z.
Independent re-check of the fix pushed after Ready (
7ac50ab77,divergent_exit_loop), head10c5bb0a4.s_branchor by a uniforms_cbranch_scc*reads level 0; a loop whose exit and back edge are both uniform (scc proven by a compare) keeps the implicit-LODSample, so no precision is lost versus before the fix.tests/startup_image_sample_implicit_lod_check.pyfails on the parent of the fix (exit_7readsSample() and passes with it.x2w_pipe.py win2025 2699 --py-checks tests/startup_image_sample_implicit_lod_check.py --targets offscreen_check --regex 'startup_image_sample|implicit_lod|plain_sample': 19/19 passed.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:47:49Z.
Code review location:
tools/startup/gfx2hlsl.py; line 2128Confirmed and fixed in
10c5bb0a4. A plainimage_samplefollowed by a divergent forward exit (s_cbranch_vccnz/s_cbranch_execnz) in a loop closed by an unconditionals_branchback to it was lowered toSample; it staysSampleLevel(.., 0)now. The loop-safety check (divergent_exit_loop) also looks at backward branches of any kind, unconditional ones included, that hold a wave-divergent branch.Test:
exit_7andexit_9cases intests/startup_image_sample_implicit_lod_check.py(fail on the previous head withSample, pass now). The existing straight/branch/join cases still lower toSample.Commands run:
python3 tests/startup_image_sample_implicit_lod_check.py,python3 tests/startup_image_sample_b_check.pytests/startup_gfx2hlsl_*scripts (same exit codes as before; the two*_draw_checkscripts need a renderer argument)10c5bb0a4:ctest --preset dev|release -R 'startup_image_sample|startup_gfx2hlsl_image'24/24 on both presetsAI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T05:54:34Z.
I resolved the main conflict in
05e3fdcdby sharing the DPP proof’s divergent-branch map. The control suites and FXC/DXC compilation pass for both a uniform join and a divergent loop exit. Before merging a change from explicit level zero to implicit LOD, please add one draw with distinct mip colors and derivatives that reliably choose a nonzero mip after the uniform join. The same shader with its generated Sample call forced to SampleLevel(..., 0) should read the mip-zero color. This will verify the behavior beyond the emitted call spelling.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T06:08:33Z.
Review: APPROVED
The added CTest runs the generated gfx1013 pixel shader after a uniform join. A complete three-mip SRV and a nonzero-base SRV both selected physical mip 2 (RGBA words 3f020000). Forcing the otherwise identical Sample call to view-relative level zero selected physical mip 0 and physical mip 1 respectively (3c000000 and 3e840000). DXC and FXC both passed on Windows 11 build 26200, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656. Debug warnings/errors were zero, and the Windows release configure registered the host and two draw checks.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-26T06:25:12Z.
Post-merge note on #2699 (merged as
59218765), from a review that finished after the merge.SampleLevel(.., 0)toSample(..), and thebranchandjoincases of the new check translate on the previousmain. It landed atx2w-startup-shader-19, which #2708 had set four minutes earlier. Entries cached under19before this merge keep level 0 until the next graphics bump. #2723 and #2006 both need a bump to20anyway, so the first of them to land re-keys these entries too..Sample(with.SampleLevel(..., 0)in the plain-join draw ofstartup_image_sample_b_check.py. WARP and the RX 9070 XT then read3d800000,40400000,3f800000,00000000(texel_cell(0, 0), the mip-0 colour), while the translated shader reads mip 1 (3e880000,3f800000,00000000,40000000). So the draw does tell the two apart, but the check's own negative control only flips the expectation. Adding that forced-level-0 shader to the check would pin it.s_wqmbracket stays level 0. After a uniform join,s_mov_b64 s[0:1], exec; s_wqm_b64 exec, exec; image_sample ...; s_and_b64 exec, exec, s[0:1]now emitsSample. That's fine, since WQM makes the derivatives valid, but the wording should match.Checked and still level 0: divergent EXEC, a discard-style
s_andn2_b64 exec, exec, vccafter the join, vcc/exec branches, divergent back edges, and divergent exits closed bys_branchor a uniforms_cbranch_scc0.Pre-existing: the
derivative_sitescheck forimage_sample_b/image_get_lodstill uses onlydivergent_back_edges, so the forward-exit loop shape Codex found likely applies to them as well.Runs (Windows 11 build 26300; RX 9070 XT, driver 32.0.32029.2010; WARP 10.0.26100.9818):
ctest --preset dev -R "startup_image_sample|startup_gfx2hlsl_image|startup_inline_sampler" -V27/27 at05e3fdcd.AI-assisted; commands listed were executed locally.