gfx2hlsl: lower 2D depth-comparison image sampling (image_sample_c, image_sample_c_lz) #1464
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1471"
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-24T12:17:28Z.
Change
tools/startup/gfx2hlsl.pylowers the gfx1013image_sample_c_lzandimage_sample_cforms of a 2D texture (dmask:0x1) toSampleCmpLevelZero(andSampleCmpforimage_sample_cin a pixel stage with a known execution mask and no branches). The first address register is the reference, then u and v. The sampler words must pass the existingpixel_aot.comparison_sampler_stateprofile; the sampler is declared as aSamplerComparisonStateand listed as ansmpc N w0 w1 w2 w3manifest line.src/startup_stubs/translated_sampler_bindings.hbuilds the matching comparison static sampler (filter 0x80 or 0x94, function = hardware function + 1) and keeps manifest order as register order.image_sample_c_lis refused (HLSL has noSampleCmpLevelbefore shader model 6.7; the stages compile as 5.1 and 6.0). Array, 3D, cube and 1D images, otherdmaskvalues, offset/bias/clamp/gather forms,a16/d16/tfe/lwe/r128/unorm, reserved MIMG bits, run-time heap samplers and samplers outside the checked profile are refused with their own message.Draft: a D3D12 readback of a
gfx2hlsl.pycomparison draw is not part of this PR (see Evidence and follow-up).Verification
AI-assisted; commands listed were executed locally (Linux, Python 3, LLVM 15.0.6 extracted from the Debian package into a temporary folder, and LLVM 19).
python3 -B tests/startup_image_sample_c_check.py: all controls and 7 mutants pass/fail as expected.python3 -B tests/startup_image_sample_c_check.py binary llvm-mc-15and... binary llvm-mc-19:fixture words match llvm-mc(every recorded fixture, both LLVM versions).origin/main(detached copy of main): fails withgfx2hlsl.Unsupported: image_sample_c_lz.x86_64-w64-mingw32-g++ -std=c++17 -Wall -Wextraoftests/startup_sampler_comparison_check.cpp, run under Wine:startup_sampler_comparison ok. Mutating the header (function offset, filter reduction,smpcparsing) makes it printFAILfor each.tests/startup_image_sample_l_check.py,startup_image_3d_check.py,startup_image_load_mip_check.py,startup_image_2d_array_check.py,startup_flat_param_check.py,startup_gfx2hlsl_bit_alu_check.py,startup_gfx2hlsl_sdwa_check.py,startup_inline_sampler_check.py,startup_sampler_heap_check.py,startup_translator_check.py,docs_links_check.py,bidi_controls_check.py: pass.rdna2_tools_check.pywith LLVM 15:OK (skipped=1).py_compileandgit diff --check: clean.ctest --preset dev --no-tests=error -R '^(startup_image_sample_c|startup_sampler_comparison)$' -V(outside--preset pr; Debug and /O2).Evidence and follow-up
v[0:2]reads the reference fromv0, the NSA form[v3, v0, v1]reads it fromv3. The sameimage_sample_c_lzorder and the same HLSL call are already read back on WARP for the pixel AOT path bytests/pixel_compare_check.py.gfx2hlsl.pyoutput with ansmpcsampler on an R32_FLOAT texture and checks exact 1.0/0.0 per comparison function. Also open: 2D array comparisons andimage_sample_c_l(needs a proven constant level 0 or shader model 6.7).CMakeLists.txt,docs/experiments.mdandwindows.ymlonly with appended entries;tools/startup/gfx2hlsl.pyhunks are separate from #1430 (a merge of both is clean).Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T12:31:39Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
5b91c08744ℹ️ 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-24T12:43:23Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T12:26:30Z.
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
5b91c08744114cde5789189dc0fa152461dde4f9:--preset dev):ctest --preset dev -R '^(startup_sampler_comparison|startup_image_sample_c)$' --no-tests=error --output-on-failure: 2/2 passed/O2(--preset release): same selection: 2/2 passedLinux:
git diff --check,docs_links_check.py,bidi_controls_check.pyandx2w_pipe.py preflightpass.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T12:26:41Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
5b91c08ℹ️ 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-24T12:31:39Z.
Code review location:
tools/startup/gfx2hlsl.py; line 795When
image_sample_csamples a minified, mipmapped texture withMAX_LOD == 0(for example, the accepted samplerw1 = 0, w2 = 1 << 26), this emits a derivative-basedSampleCmpwithout preserving that limit.pixel_aot.comparison_sampler_state()deliberately ignoresMAX_LODbecause its profile validates LOD-zero sampling, whiletranslated_sampler_bindings.h::decode_sampler()always setsMaxLODtoD3D12_FLOAT32_MAX. The source therefore samples mip 0 while the translation can compare against a higher mip, producing different comparison results when the mip contents differ. Decode and enforce the limit for implicit comparisons, or refuse that form until an appropriate sampler profile is supported.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T12:43:23Z.
Code review location:
tools/startup/gfx2hlsl.py; line 795Fixed in
8ae3c180: an implicit comparison now reads MAX_LOD (word 1 bits 23:12). A limit of 0 lowers to SampleCmpLevelZero, which is exact. The unlimited value keeps SampleCmp. Any other limit is refused, because the static sampler cannot carry it. New fixtures c_max0 and c_max_partial in tests/startup_image_sample_c_check.py cover both cases.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T13:09:37Z.
Review: CHANGES_REQUESTED
Release passes the three translator/sampler checks. In image_compare, an implicit comparison with unrestricted MAX_LOD falls through to SampleCmpLevelZero when EXEC is uncertain or the sample is inside a block. This silently changes the selected mip. Please refuse that implicit form when its derivatives cannot be represented, while retaining explicit-zero and proven MAX_LOD=0. For the unrestricted branch, please establish the mip filter and chosen mip with two distinguishable mips in a source-built startup draw, or keep the first slice at proven LOD zero.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T13:25:41Z.
Review: COMMENTED
The new derivative refusal and three Release checks pass. The unrestricted mip branch still needs its own evidence: the comparison-state helper deliberately ignores the mip filter when mapping to the level-zero desktop profiles, and the shown runtime static sampler filters use point mip selection. Please keep unrestricted implicit sampling out of this slice or add the matched mip-filter mapping and a two-mip startup draw that fails on an incorrect mip or blend.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T13:48:02Z.
Review: APPROVED
Re-reviewed
d21e3d6e. The startup translator now limits the first slice to level zero and rejects unrestricted implicit mip selection. The three Release translation and sampler-binding checks passed. This verifies the translator and binding fixture scope.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T13:13:48Z.
Fixed in
d9e27f68:image_comparenow refuses an implicitimage_sample_cwith unrestricted MAX_LOD when its derivatives cannot be represented (exec not proven, or inside a block), instead of falling through toSampleCmpLevelZero. Proven MAX_LOD=0 still lowers toSampleCmpLevelZero, and the proven pixel-stage unrestricted form still lowers toSampleCmp. I did not add a two-mip draw test; the unrestrictedSampleCmpform stays limited to the cases where the derivatives are proven.Regression test in
tests/startup_image_sample_c_check.py: both implicit fixtures (c,c_nsa) are refused in the exec-uncertain and in-block cases, andc_max0staysSampleCmpLevelZeroin both.Win2025
startup_sampler_comparisonandstartup_image_sample_cond9e27f68:--preset dev): 2/2 passed./O2(--preset release): 2/2 passed.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T13:36:28Z.
Fixed in
d21e3d6e: unrestricted implicit image_sample_c is kept out of this slice. image_sample_c is lowered to SampleCmpLevelZero only when the sampler MAX_LOD is 0 (exact level zero); any other MAX_LOD is refused as implicit mip selection, so the SampleCmp branch and its mip-filter-ignoring mapping are gone. tests/startup_image_sample_c_check.py now requires c, c_nsa and the partial-MAX_LOD form to be refused and keeps the MAX_LOD 0 lowering; docs/experiments.md is updated.Win2025 at
d21e3d6e: Debug (dev) startup_sampler_comparison + startup_image_sample_c 2/2 passed; Release /O2 2/2 passed.Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T15:11:52Z.
The reference ordering and the comparison call are both covered
Independent reviewer, not the author. Reviewed the current head; nothing pushed to the branch. Mutations were made
locally in
tools/startup/gfx2hlsl.py, reverted between each; working tree is clean.Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100, DXC 1.8.2502.11, LLVM gfx1013 tooling
available, RTX 5080 Laptop (32.0.15.8142) for
_hardware.Mutation A — the address dwords are unpacked in the wrong order
The lowering builds
SampleCmpLevelZero(smp, float2(u, v), reference)fromcs[1],cs[2]andcs[0]. Taking thedwords in file order instead:
So the fixture notices that the reference is the first address dword rather than the first argument slot — which is the
easy mistake to make here, since the HLSL call order is the reverse of the word order.
Mutation B — the comparison call degrades to a plain sample
The comparison itself is asserted, not just "a sample happened".
What this does not say
startup_sampler_comparisonstays green under mutation A because it checks the static-sampler mapping, not the callsite; that is consistent with its name, and I mention it so the two fixtures' division of labour is explicit.
The refusal paths (
image_sample_c_lneeding SM 6.7,cwith a non-zero MAX_LOD) I did not drive; they areUnsupportedraises and would need crafted sampler words.
Verdict
Reviewed the current head. Builds clean, all four cases pass across WARP and a physical adapter, and two independent
mutations in the emitted call are caught. No objection from me.