pixel_aot: lower depth-comparison sampling (image_sample_c_lz) to SampleCmpLevelZero #710
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows#710
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@roansystemlabs on GitHub · 2026-11-22 21:41 UTC · original
Problem
tools/pixel_aot.pylowersimage_sampleandimage_sample_lz, but no depth-comparison form. Everyimage_sample_c*stops translation. Shadow-map lookups (percentage-closer filtering) use these instructions, so a pixel shader that reads a shadow map cannot reach DXIL through the internal path today. The SPIR-V bridge has comparison sampling (#670, #676);pixel_aotdoes not.I could not measure how many archive PS records stop here, because I do not have the archive.
tools/scan_unsupported_shaders.pyalready classifiesimage_sample_cas MIMG, so a maintainer rescan could count it.Proposal
One reviewable change in
pixel_aot.py, with its own test:image_sample_c_lz vD, v[a:a+2], s[T:T+7], s[S:S+3] dmask:0x1 dim:SQ_RSRC_IMG_2D. In the RDNA2 address layout, the depth reference comes before the coordinates, sov[a]is the reference andv[a+1:a+2]is (u, v). The result is one float invD. I will also accept the NSA spelling if LLVM 15 prints it for gfx1013.--sampler-wordsmust match the SGPRs exactly, as today. In addition, decode the fields that change the result of a comparison sample:DEPTH_COMPARE_FUNC(bits 14:12), the X/Y clamp modes,MAX_ANISO_RATIO,FORCE_UNNORMALIZEDandFILTER_MODE;MIN_LOD;XY_MAG_FILTER,XY_MIN_FILTER,MIP_FILTERand the LOD biases.The first version supports point and bilinear filtering (one filter for both min and mag), clamp-to-edge addressing, no anisotropy, normalized coordinates and the default blend filter mode. Any other value is rejected with a named error.
SamplerComparisonStateats0andtex.SampleCmpLevelZero(samp, uv, ref). Also expose the decoded desktop state (D3D12_FILTER_COMPARISON_*,D3D12_COMPARISON_FUNC_*, address mode) through a helper and a comment in the HLSL, so a host can create the matching sampler. The hardware compare function maps one to one ontoD3D12_COMPARISON_FUNC(NEVER … ALWAYS; D3D value = hardware value + 1), with the reference on the left:ref OP texel.s0.The existing fixed root signature in
tests/pixel_aot_vs.hlslhas one non-comparison static sampler, and a static sampler cannot carry a per-case compare function. So I would not change it. Instead, the test uses a small separate host path with a sampler descriptor heap, built from the decoded state, liketests/spirv_window/sampler_readback.cppdoes for the bridge. If you prefer a different binding (a second static sampler ats1, or the translator emitting a root signature), I will follow that.Alternatives
LoadorGather, compare, weight by hand). This needs no new sampler, but hardware PCF is cheaper and closer to what the console does. Rejected for the first version.image_sample_c(implicit LOD),_c_l,_c_b,_c_oandimage_gather4_ctogether. That is a larger review. I would rather land_c_lzfirst; the others follow the same decoding and would be separate PRs.Verification
Source-built synthetic programs only (written with LLVM 15 syntax, assembled in the Ubuntu job). An 8×8
R32_FLOATdepth texture with distinct values, references from a constant, from an interpolated attribute and from ALU, and all eight compare functions. The expected images come from an independent CPU model ofref OP texel(and bilinear weights for the PCF case). They do not reuse translator output. Runs on_warpand_hardware(RTX 3070, Windows 11, debug layer on), plus the pure-Python checks fromAGENTS.md.Negative controls on both adapters: LESS and GREATER swapped in the descriptor, the reference replaced by a coordinate, the reference ignored (constant), point and bilinear swapped,
uandvswapped. CPU controls reject unsupported descriptor fields,dmaskother than 0x1, a mixed program and an overlapping write.Limits stated up front:
_c_lzon 2D textures. Cube shadow maps, array slices and offsets (_o) are out of scope.This work is AI-assisted.
Checklist
image_sample_c,sample_corSampleCmpforpixel_aot. The open PRs that touchtools/pixel_aot.py, including #510 and #506, do not change comparison sampling. #670, #676 and #681 cover the SPIR-V bridge only.)@R0Y00 on GitHub · 2026-11-22 21:55 UTC · original
Please go ahead with a focused 2D
_c_lzPR. Keep the existing ordinary-sampler path and give the comparison-only path explicit desktop sampler state so the test host can bind the decoded settings. Reject mixed sampling until the profile can declare both bindings. For the native instruction side, include the LLVM 15 assembly/disassembly for the reference/coordinate order and cite the descriptor-field and compare-order evidence. For the draw, distinguish LESS from GREATER, include equality where the strict and inclusive functions disagree, and use a depth neighbourhood where bilinear compare-then-filter disagrees with comparing a filtered depth. Keep the texture view, host sampler and generated HLSL under the same fixture, with an independent pixel reference.@R0Y00 on GitHub · 2026-11-23 00:47 UTC · original
The focused 2D
image_sample_c_lzimplementation merged in #718. It keeps comparison sampler state explicit and rejects mixed ordinary/comparison sampling. The WARP and RTX 3070 readbacks cover all eight comparison functions, equality, point and bilinear neighborhoods, and the coordinate-boundary and compare/filter mismatch controls. The accepted sampler and reference domain is documented.