Repository navigation
startup: lower cube image sampling in gfx2hlsl - #2960
legacy-code-archaeologist wants to merge 3 commits into
Conversation
image_sample, image_sample_lz, image_sample_l and image_sample_b on dim:SQ_RSRC_IMG_CUBE now lower to TextureCube<float4>, with the manifest kind texcube. The gfx10 address (s, t, face), where s = sc/|ma| + 1.5 (Mesa prepare_cube_coords) and ma is twice the major coordinate (LLVM ConstantFoldAMDGCNCubeIntrinsic), is rebuilt into a direction by an emitted helper x2w_cube_dir. Cube loads, image_sample_d, image_get_lod, a16, d16, compute stages and constant samplers with DISABLE_CUBE_WRAP stay refused by name. offscreen_check --startup-image-cube binds six 2x2 faces as a TextureCube. tests/startup_image_cube_check.py draws literal face addresses against the address meaning, 13 helper mutants, guest-input controls and the v_cube chain per face against a desktop TextureCube draw. The cube cases of the sample_l and sample_b checks change from refusal to acceptance; the 3D check's unverified-dimension case moves to MSAA, since the same words now form a valid cube sample. The runtime binding of texcube views is R0Y00#2938; this must land after it. AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Cross-check against the native path: on There are two differences, both outside what the fixture draws:
AI-assisted. |
KelboLive
left a comment
There was a problem hiding this comment.
PR #2960 implements cube image sampling in gfx2hlsl. Complex translation that needs careful review.
What works
- Address reconstruction: correct derivation from Mesa prepare_cube_coords. s,t in [1,2], face ID from
cubesc/cubetc/cubema registers. The s-1, t-1 face positioning is exactly right. - x2w_cube_dir: reconstructs a direction vector whose major component is +/-1 for the face. Other components
carry u=2(s-1.5), v=2(t-1.5) with per-face signs from the existing v_cube* lowering. Projecting again
returns the same face coordinates. Correct for all 6 faces. - Refusal list is thorough: image_load/image_load_mip (cube loads not defined on TextureCube), image_sample_d
(cube derivatives not converted), image_get_lod, a16, d16, compute stages, DISABLE_CUBE_WRAP constant sampler. - Clear dependency note: "this must land after #2938" for texcube runtime binding. Good practice.
- Experiment doc startup-image-cube.md is excellent: documents the Mesa source, LLVM intrinsics, refused forms,
and known limitations (cube-array). The 254-line gfx2hlsl.py change is well-organized. - Test harness adds cube support to check_startup_image_3d with a six-face TextureCube fixture.
Issues
- Cube-array limitation: The doc correctly notes gfx10 MIMG has no array bit so cube-array views cannot
be distinguished from cube views from the instruction. The helper keeps face bits (id & 7) and samples
layer 0 of a TextureCube which is wrong for cube-array. This should at least be a refuse-with-reason or
a dev-build assertion when a cube-array descriptor is bound. - DISABLE_CUBE_WRAP constant sampler: The guest filters without crossing face edges when the bit is set, but
D3D12 TextureCube always filters across edges. The refusal is correct, but the note says "With the bit
clear both cross" — are they guaranteed to match even without the bit? Border texel values may differ
between the GPU-computed and the HLSL-projected direction. - x2w_cube_dir projection math: u = 2(s-1.5) = 2s-3. For s in [1,2]: u in [-1, 1]. When projecting
the direction back, does this handle the case where the major component is not unique (corner of a cube
face)? The math assumes one component is strictly largest, which is true for face coordinates but could
be ambiguous at face corners. - Test dependency on #2938 runtime: The PR is a draft and cannot be tested end-to-end without the runtime.
Thegfx2hlsl-only translations can be checked but the draw-time binding cannot. Consider adding a unit test
that checks the emitted HLSL directly.
Recommendations
- Add a refuse-with-reason for cube-array (if possible to detect from the descriptor).
- Verify DISABLE_CUBE_WRAP equality at face corners with a test harness edge case.
- Add inline comments near x2w_cube_dir explaining why u,v are computed as 2(s-1.5).
Overall: solid implementation. The experiment doc is thorough and the refusal cases are well-reasoned.
KelboLive
left a comment
There was a problem hiding this comment.
What works
- Comprehensive lowering of all four sample forms (image_sample,
_lz, _l, _b) to HLSL TypeCube Sample/SampleLevel/SampleBias. - Excellent experiment doc tracing Mesa's prepare_cube_coords and
LLVM's ConstantFoldAMDGCNCubeIntrinsic, with clear enumeration of
refused forms and limits (cube-array ambiguity, face-wrap, bias). - The x2w_cube_dir helper correctly reconstructs the direction vector
with per-face component ordering matching the standard cube layout.
Issues
- Compute dispatch has no texcube view binding; the refusal is
correct but the error message format should be consistent with other
unbound-type refusals in the manifest binding code. - Cube-array is silently sampled as layer 0 (helper keeps id & 7).
The doc notes this, but if cube-array textures appear in the title
the silent fallback will produce wrong results. Consider adding an
explicit refusal if the descriptor can be checked. - The experiment doc mentions bias is refused outside pixel stage
(matches 2D handling). Verify the same check exists in the code.
Recommendations
- Verify tests/startup_image_cube_check.py covers all four lowered forms
(Sample, SampleLevel, SampleBias) and not just implicit LOD. - If cube-array is expected in the title, add an explicit refusal in
gfx2hlsl and update the experiment doc. - Consider adding srv binding for texcube in the startup draw dispatcher
for a subsequent PR.
Overall
Strong implementation with excellent documentation. Clear enum of
limitations and correct refusal of derivatives. Approvable.
Resolve tools/startup/gfx2hlsl.py: keep the cube DISABLE_CUBE_WRAP refusal and the cube direction next to main's sampler joins and its three-coordinate get_lod guard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This PR now conflicts with
Could you merge AI-assisted; commands listed were executed locally. ( |
|
Thanks for review @tedin7 |
Resolve tools/startup/gfx2hlsl.py: keep both uses_bvh/bvh and uses_cube_dir/texcube in Pipeline.
|
@tedin7 Merged \upstream/main\ (\35f7197e) into \startup/gfx2hlsl-image-cube\ in commit \982cdfe9\ (keeping both \uses_bvh/\�vh\ and \uses_cube_dir/\ excube\ in \ ools/startup/gfx2hlsl.py). Re-verified locally on \982cdfe9\ (\dev\ preset):
Keeping #2960 as a draft until #2938 lands. AI-assisted. |
Change
tools/startup/gfx2hlsl.pylowersimage_sample,image_sample_lz,image_sample_landimage_sample_bondim:SQ_RSRC_IMG_CUBEtoTextureCube<float4>Sample,SampleLevelandSampleBias, and writes the manifest kindtexcube. Fixes #2943.prepare_cube_coords(src/amd/common/nir/ac_nir_lower_tex.c) builds s = sc/|ma| + 1.5 and t = tc/|ma| + 1.5. LLVM 15.0.7ConstantFoldAMDGCNCubeIntrinsicdefinesv_cubemaas twice the major coordinate. So s and t lie in [1, 2].x2w_cube_dirrebuilds a direction whose major component is ±1. Its other components carry the per-face signs of the existingv_cubesc/v_cubetclowering, so projecting it again returns the same face coordinates.image_sample_d,image_get_lod, a16, d16, compute stages, and constant samplers withDISABLE_CUBE_WRAP(word 0 bit 28, Mesagfx10-rsrc.json).texcubeviews is startup: bind cube views of console-layout textures in slot 70 #2938, which is still a draft. On main,d3d12_draw.inlreads an unknownsrvkind as a buffer, so this must land after startup: bind cube views of console-layout textures in slot 70 #2938. That is why this PR is a draft too. Once both land, the sentence in startup: bind cube views of console-layout textures in slot 70 #2938's docs that gfx2hlsl "does not emit that kind yet" is out of date.Verification
Commit
44a7d7d3onmain6ee878d8, Windows 10.0.26100.9711 (24H2),devpreset. Debug layer unavailable on both adapters.ctest --preset dev --no-tests=error -R '^startup_image_cube_' -V: 3/3 passed.ctest --preset dev --no-tests=error -R '^startup_image_|^startup_gfx2hlsl_cube' -j 2: 53/53 passed, no skips. The baseline before the change was 50/50.python -B tests/startup_image_cube_check.py binary <llvm-mc 15>: all 16 fixture programs reassemble to the recorded words. Run locally throughclang -cc1as -show-encodingof LLVM 15.0.7.python-linuxlist from the workflow, throughtools/run_checks_parallel.py: all ok.startup_run_shandstartup_build_revexit 77 on Windows.python -B tests/docs_links_check.py: ok.image dimension SQ_RSRC_IMG_CUBE.Evidence and follow-up
Fixture.
offscreen_check --startup-image-cubebinds six 2x2 R32G32B32A32_FLOAT faces as aTextureCube. Texel (x, y) of face f holds ((1 + x + 2y + 4f) / 32, x, y, f). All sources are source-built.v_cube*. The reference is only the address meaning, so a wrong face, sign or axis in the helper reads another texel, chosen by the desktop driver's own face selection.usign flipped andu/vexchanged, plus faces 2 and 3 exchanged. Each must read the texel a D3D lookup of the mutated direction gives.v_cubechains, one per face, must match both the reference and a desktop pixel shader that samples the same direction.Changed expectations, intended.
cuberefusals instartup_image_sample_l_check.pyandstartup_image_sample_b_check.pybecome acceptance checks.startup_image_3d_check.py, the 1D words with the dim field set to cube now form a valid three-register cube sample: the disassembler sizes the address from the dimension. Its unverified-dimension case therefore uses MSAA, which is still refused.Limits (all documented in
docs/experiments/startup-image-cube.md):_land_bdraws only show that the extra dword is not read as a coordinate.DISABLE_CUBE_WRAP.Checklist
AI-assisted.
🤖 Generated with Claude Code