Repository navigation
shader: lower image_sample_c_lz to SampleCmpLevelZero in pixel_aot - #718
Conversation
|
The 48 readbacks and mismatch controls cover the intended compare/filter path. One profile boundary remains: the docs exclude exact filter boundaries with TRUNC_COORD=0, but the decoder currently accepts either bit value and the lowerer does not apply it. Please define the accepted coordinate/precision premise at the caller binding and add a boundary case that would distinguish the modes, or refuse the unsupported setting. Check that depth references outside the tested interval are either covered or explicitly outside the contract. Also add a rejection for |
ceb2329 to
dafb61e
Compare
|
Independent Windows 10 run on In the focused Windows 10 22H2 AI-assisted. All reported tests ran locally. |
|
Thanks. All three points are in 1.
The decoder now accepts only the pairs RADV programs on gfx10 by default ( New draws, each with all 8 compare functions:
The coordinate offsets are exact in binary32, and the CPU controls check every sum. The negative control for the 2. Depth references. The contract is now references and texels in [0, 1], ends included. Two new programs use constant references 0 and 1 on a texture with texels equal to 0 and 1, with both filters and all 8 functions. Controls check 3. Results at
The PR description is updated to match. AI-assisted: yes |
|
Your |
Depth-comparison sampling at LOD zero on a 2D texture, the form used by shadow-map lookups, now translates. The reference is the first address operand (RDNA 2 order), in a VGPR range or the NSA form. The sampler words must still match the caller binding; the compare function and the point or bilinear filter are decoded from them, and any field that would change the result outside this profile is refused. offscreen_check --check-pixel-compare draws with a descriptor-heap comparison sampler built from the decoded state. pixel_compare_check.py covers all eight compare functions with both filters for a constant, an interpolated and an ALU reference, against an independent CPU model, with negative controls for the compare function, filter, ignored reference and swapped coordinates. Refs R0Y00#710 AI-assisted: yes
TRUNC_COORD applies to X and Y for every filter on gfx10. With 0, point sampling rounds to nearest even at six fraction bits before dropping the fraction, so it can select the next texel just below an edge; D3D takes the floor. The decoder now accepts only the pairs RADV programs on gfx10 by default, point with 1 and bilinear with 0, and refuses the other two. New draws, all eight compare functions each: point sampling 1/256 texel below an edge and exactly on an edge, bilinear on texel centres, and constant references 0 and 1 against texels equal to them. Negative controls: the TRUNC_COORD 0 image below an edge, the texel below an exact edge, the image without the coordinate offset and the inclusive function at both ends. References or texels outside [0, 1] are outside the contract, because the image format is not decoded. A destination, range or NSA operand past v255 is refused. Refs R0Y00#710 AI-assisted: yes
Use the same constant operand check as the other paths (R0Y00#727), so values from params1, params2 and later buffers are recognised, and add a CPU control whose comparison reference is read from b1.
dafb61e to
617374a
Compare
|
Thanks, done in
Local mutations of the new control: removing Results at
The PR description is updated to match. AI-assisted: yes |
Step 2 of R0Y00#730, on top of the lit fixture (R0Y00#749). A light pass writes light-space depth from the translated mesh program into a depth texture. The camera pass draws a receiver plane whose translated pixel program compares against that map with image_sample_c_lz (the R0Y00#718 path), then the caster lit with the R0Y00#749 N.L program. An exact CPU reference checks every byte, the shadow map and the mesh traces. Negative controls: GREATER for LESS, stale map, ignored map, coverage instead of depth. Refs R0Y00#730
Change
pixel_aotloweredimage_sampleandimage_sample_lz, but no depth-comparison form. Everyimage_sample_c*stopped translation, so a pixel shader that reads a shadow map could not reach DXIL through the internal path. This PR adds the LOD-zero 2D form. Refs #710.It follows the scope agreed in #710 ("Please go ahead with a focused 2D
_c_lzPR…"):the ordinary-sampler path is unchanged, and the comparison-only path carries explicit desktop sampler state, which the test host binds from the decoded words;
mixed comparison and ordinary sampling is rejected;
LLVM 15 assembles and disassembles both address forms, showing the reference before the coordinates (Verification); the descriptor fields and the compare order cite Mesa, Linux and RADV (below);
the draws separate
LESSfromGREATER, use a reference equal to some texels so the strict and inclusive functions disagree, and use depth neighbourhoods where compare-then-filter disagrees with comparing a filtered depth (a negative control for the latter);one fixture holds the texture view, the host sampler and the generated HLSL, checked against an independent CPU reference.
image_sample_c_lz vD, v[a:a+2], s[T:T+7], s[S:S+3] dmask:0x1 dim:SQ_RSRC_IMG_2Dand the NSA spelling[vR, vU, vV]. In the RDNA 2 address order the reference comes before the coordinates. The result lowers totex.SampleCmpLevelZero(samp, float2(u, v), reference)withTexture2D<float> tex : register(t0)andSamplerComparisonState samp : register(s0). The reference may be a constant, an ALU result or an interpolated attribute. Operands use the same constant check as the other paths since shader: bind further constant buffers by table register and offset in pixel_aot #727 (params, soparams1[,params2[and later buffers are recognised).The four sampler words must still match the caller binding (
--sampler-words), as for ordinary sampling. In addition,comparison_sampler_state()decodes the fields that change a comparison result, and the generated HLSL names the desktop sampler it needs in a comment:D3D12_COMPARISON_FUNCorder minus one, asreference OP texel;D3D12_FILTER_COMPARISON_MIN_MAG_MIP_POINTor..._MIN_MAG_LINEAR_MIP_POINT;CLAMP_LAST_TEXEL, anisotropy, unnormalized coordinates,MC_COORD_TRUNC,FORCE_DEGAMMA, a min/max filter mode,MIN_LOD, LOD bias, different min and mag filters, mip filter 3, word 2 bits 28–31 (MIP_POINT_PRECLAMP,ANISO_OVERRIDE,BLEND_ZERO_PRT) and word 3 bits 12–29, which gfx10 leaves unnamed (bit 29 isUPGRADED_DEPTHon GFX8);TRUNC_COORD(word 0 bit 27) is part of the contract. On gfx10 it applies to X and Y for every filter (Mesaac_gpu_info.h). With 0, point sampling rounds to nearest even at six fraction bits before dropping the fraction (Mesa d573d1d8), so it can take the next texel when the coordinate is up to 1/128 texel below an edge; D3D takes the floor (D3D11.3 §7.18.7). Only the pairs RADV programs on gfx10 by default are accepted (radv_sampler.c), point with 1 and bilinear with 0; the other two are refused. RADV clears the bit for DXVK and vkd3d-proton (00-radv-defaults.conf), so point with 0 is a setting drivers use. Bilinear results are in the contract where the texel-space position is a multiple of 1/64;sample_c), and the image format is not decoded, so values outside [0, 1] and NaN are outside the contract. The generated HLSL states both premises in its comment;v255is refused;docs/experiments.md.Field positions follow
SQ_IMG_SAMP_WORD0…3(registers 0x8F30…0x8F3C) in Mesasrc/amd/registers/gfx10-rsrc.json:DEPTH_COMPARE_FUNCis word 0 bits 14:12,XY_MAG_FILTER/XY_MIN_FILTERword 2 bits 21:20 and 23:22. The enum values follow Linuxnavi10_enum.h(SQ_TEX_DEPTH_COMPARE_NEVER= 0 …ALWAYS= 7,SQ_TEX_CLAMP_LAST_TEXEL= 2,SQ_TEX_XY_FILTER_POINT/BILINEAR= 0/1).A program that mixes comparison and ordinary sampling, or uses the second texture, is refused, because both would need
s0. The ordinary sampling paths emit the same HLSL as before.tests/pixel_aot_vs.hlslhas one ordinary static sampler, and a static sampler cannot carry a per-case compare function. So I did not change it. The newoffscreen_check --check-pixel-compare(tests/pixel_compare_render.cpp) builds its own root signature with t0, b0 and a descriptor-heap sampler that comes from the case file. If you would rather bind this another way, I will change it: a second static sampler ats1, or a root signature emitted by the translator.New test
tests/pixel_compare_check.py: CPU controls with no arguments,binaryfor LLVM 15 anddrawfor D3D12. It is registered aspixel_aot_compare_{hardware,warp}and added to the Ubuntu LLVM 15 step. Docs: a new paragraph after theimage_sample_lzone indocs/experiments.md.Overlap with open PRs (checked with
git merge-treeagainst every open PR that touches these files): shader: lower flat_load_dword through TitleLookup in pixel_aot #694 renames thevmcntcounter inlower()(samples→vector_loads), so whichever of the two lands second needs a small rebase of the new branch; shader: preserve raw bits in integer pixel constant loads #680 adds a CI line at the same place inwindows.yml. No other open PR conflicts beyond its existing conflicts withmain. The branch merges cleanly withmainat67edabe.Verification
Commit
617374a, rebased onmainatfd2486f(after #727; #685 moved theoffscreen_checkoperations into a table, and--check-pixel-compareis a row there). Windows 11 build 26200.9974, D3D12 debug layer enabled, NVIDIA GeForce RTX 3070 (driver 621.01) and WARP.pixel_aot_compare_hardwareandpixel_aot_compare_warpeach reportdraws=104 negative_controls_detected=18. Every draw printedmismatches=0anddebug_errors=0 debug_warnings=0.The fixture draws an 8×8
R32_FLOATtexture into a 16×16R32G32B32A32_FLOATtarget and compares every result bitwise. Each row covers all 8 compare functions, 104 draws per adapter:EQUALand theLESS/LESS_EQUALsplit are visiblev[7:9]attr0.x; it varies per pixel and is never equal to a texelv_fma_f32of constant words[v20, v8, v9]LESS)The offsets are exact in binary32, and the CPU controls check every sum against the rational value.
The expected images come from an independent CPU model, using
Fractionarithmetic: compare each texel, clamp to the edge, then weight bilinearly. It does not call the translator. The test writes the sampler words from the field layout itself, not through the decoder. The host sampler state comes from the decoder, so a wrong decoded bit changes the draw.Negative controls, on each adapter, all failing with
pixel_mismatch(18 per adapter):GREATERandGREATER_EQUALagainst aLESSdescriptor; for the constant reference alsoLESS_EQUAL;0.5f);TRUNC_COORD0 (x=8 y=0 expected=1 actual=0on both adapters); on an edge, the texel below (x=8 y=0 expected=0 actual=1);LESS_EQUALagainstLESSandGREATER_EQUALagainstGREATER.The draws show the desktop side: the accepted point rule is the floor, and D3D does not round at six fraction bits. They cannot show the console rule; that comes from the Mesa sources above.
CPU controls, run in every mode:
TRUNC_COORD0 with point and 1 with bilinear;dmask:0x3, two or four address VGPRs,dim:SQ_RSRC_IMG_2D_ARRAYand implicit-LODimage_sample_care rejected;v256as the destination,v[254:256]and[v20, v8, v256]are rejected withVGPR out of range, andv255is accepted;b1(--extra-constant 20 0x60, word 1) lowers toSampleCmpLevelZerowith a reference equal toparams1[0].yundercbuffer Constants1 : register(b1); without that contract entry the same program is rejected;NEVERandALWAYS, the truncating and rounding models differ below an edge, and the floor and the texel below differ on an edge; at 0 and 1 the strict and inclusive functions differ;s_waitcnt vmcnt(0), a reference taken from an outstanding comparison, a mixed program, a second texture and no sampler binding are rejected;image_sample_lzstill emitsSamplerState.Mutation checks (local, not added, each reverted):
u, v, reference = values): caught by the CPU controls before any draw;D3D12_TEXTURE_ADDRESS_MODE_WRAPinstead ofCLAMPin the test host: caught on WARP atconstant bilinear LESS(x=5 y=0 expected=0 actual=0.0625);D3D12_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINTin place of the bilinear filter: caught on WARP (x=7 y=0 expected=0.25 actual=0). The opposite split (MIN_LINEAR_MAG_POINT) passed all 48 draws of the first commit: at LOD zero WARP uses the min filter. The decoder accepts only equal min and mag filters, so this split cannot reach the host;x=8 y=0 expected=0 actual=1). Moved down by 1/1024 texel: caught by the on-edge draw (x=8 y=0 expected=1 actual=0);TRUNC_COORDread from bit 26, the check removed, or point with 0 accepted: caught by the CPU controls;v255limit raised tov256, or applied to the destination or the address only: caught by the CPU controls;b1control:aluremoved from the operand prefixes, the extra contract ignored, orb1declared asregister(b0): each caught. Putting backparams[is not caught, and neither is droppingparamsfrom the prefixes: the operands are always VGPRs, and no instruction writes a constant-buffer value into a VGPR as is (a move makes it analuvalue). So the prefix change keeps the check identical to the other paths, like the VGPR-only checks shader: bind further constant buffers by table register and offset in pixel_aot #727 updated, rather than changing a result.Pure-Python checks from
AGENTS.md, pluspixel_aot_check.pywith no arguments: all exit 0.pixel_compare_check.py binaryneeds LLVM 15 with AMDGPU, which I don't have locally. It ran in this PR's CI at617374a, and passed: https://github.com/R0Y00/Xbox2Windows/actions/runs/45088811425. It assembles the four distinct programs (including the whole-quad edge program) with two descriptors usingllvm-mc-15and decodes them throughlibLLVM-15.so.1. LLVM printsimage_sample_c_lz v12, v[7:9], s[28:35], s[40:43] dmask:0x1 dim:SQ_RSRC_IMG_2Dandimage_sample_c_lz v12, [v20, v8, v9], .... Each decoded program translates to the same HLSL as its line fixture. The other jobs in that run also passed: the Windows build and tests, the Windows /O2 build and the Linux Python checks.GPU load (
nvidia-smi, RTX 3070): 4 % before and 2 % after the ctest run, with other processes using the GPU. About 5.6 GB of the 8 GB of VRAM was already in use by them, and the reading changed by 6 MiB. The draws are 16×16.pixel_aot_compare_hardwaretook 41 s and_warp10 s. In an earlier run of the same selection atdafb61e,pixel_aot_blend_scalar_hardwarehit its 60 s timeout while the GPU was shared; it passed alone and in later runs.Evidence and follow-up
tools/scan_unsupported_shaders.pyalready classifiesimage_sample_cas MIMG, so a rescan could count how many PS records stop at a comparison sample, and how many of those use_c_lzon 2D.image_sample_c(needs whole-quad coordinates),_c_l,_c_b,_c_o,_c_d,image_gather4_c*;TRUNC_COORDpairs, which would need a six-bit rounding emulation in HLSL. Point with 0 is the pair RADV programs for DXVK and vkd3d-proton.reference OP texel, the same as D3DSampleCmp. Mesa RADV maps Vulkan'sDref OP texelone to one ontoSQ_TEX_DEPTH_COMPARE. The draws confirm the D3D side only, not the console.tools/scan_unsupported_shaders.pydoes not listimage_sample_lzamong its supported regexes either. I left it unchanged to keep this PR to one behavior.Checklist
docs/experiments.md; the README row's-R '^pixel_aot_'already selects the new tests.)AI-assisted: yes