Repository navigation
startup: keep the implicit LOD of a plain image_sample past a uniform join in gfx2hlsl - #2699
Conversation
… join in gfx2hlsl A plain image_sample takes its LOD from the pixel quad's derivatives. After a block boundary it was lowered to SampleLevel(.., 0), so the guest's mip was lost. Where the rule image_sample_b and image_get_lod already use holds (pixel stage, entry EXEC mask, wave-uniform control flow, no divergent back edge over the call) it is now the implicit-LOD Sample; everywhere else it stays level 0, and nothing new is refused.
The implicit-LOD lowering of a plain image_sample after a join was only checked as HLSL text. Draw the recorded array fixture with a uniform join in front of the image_sample: it must read mip 1 (implicit LOD from the derivatives), and the mip-0 expectation, what SampleLevel(.., 0) would read, must fail. with_join_before_sample now finds any image_sample form.
|
Ready for review, @MasterDomino. Added after the independent check: a WARP/hardware readback of the new path in AI-assisted; commands listed were executed locally. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour 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. |
There was a problem hiding this comment.
💡 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
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
…oop closed by an unconditional branch A plain image_sample in such a loop ran on uneven quads on later passes. The loop-safety check now also covers backward branches of any kind that hold a wave-divergent branch.
|
Independent re-check of the fix pushed after Ready (7ac50ab,
AI-assisted; commands listed were executed locally. |
|
I resolved the main conflict in 05e3fdc by 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. |
R0Y00
left a comment
There was a problem hiding this comment.
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.
|
Post-merge note on #2699 (merged as
Checked and still level 0: divergent EXEC, a discard-style Pre-existing: the Runs (Windows 11 build 26300; RX 9070 XT, driver 32.0.32029.2010; WARP 10.0.26100.9818): AI-assisted; commands listed were executed locally. |
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(fa189d2) 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).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.