Repository navigation
startup: lower cube image sampling in gfx2hlsl - #2960
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. |
…age-cube # Conflicts: # tests/desktop_gpu.h # tests/startup_image_3d.cpp
AI-assisted.
|
Merged Local verification (
AI-assisted. |
pigalot
left a comment
There was a problem hiding this comment.
Independently reviewed f7da3f69 integrated over main 86beae95 (tree cb3475be). The merge is clean and git diff --cached --check origin/main is clean.
What I traced.
x2w_cube_diragainst LLVM'sConstantFoldAMDGCNCubeIntrinsictable: for each face I took (sc, tc, major), solvedu = sc/|major|,v = tc/|major|with the major component ±1, and got the six returned rows exactly:- +X
(1, -v, -u); - -X
(-1, -v, u); - +Y
(u, 1, v); - -Y
(u, -1, -v); - +Z
(u, -v, 1); - -Z
(-u, -v, -1).
- +X
u = 2(s - 1.5)follows froms = sc/|ma| + 1.5with|ma| = 2|major|. Over a face,sspans 1 anduspans 2, so the implicit LOD from the derivatives is the same on both sides within a face.- Address order:
image_sample_btakes the bias first andimage_sample_lthe level last, as for the other dimensions. Theimage_compareand gather paths still refuse a cube dimension, because they checkdimthemselves. - Refusals:
- load and load_mip,
image_sample_d,image_get_lod, a16, d16 and compute stages are refused by name; - a constant sampler with SQ_IMG_SAMP_WORD0 bit 28 (
DISABLE_CUBE_WRAP) is refused; - the runtime already maps
srv ... texcubeto a TextureCube view (d3d12_draw.inl, kind 5).
- load and load_mip,
What I ran. I built offscreen_check d3d12_xs_shim startup_stream_consumer in dev and release, then ran:
ctest --test-dir out/build/<preset> --no-tests=error -j 6 -R '^startup_image_(cube|3d|2d_array|sample_b|sample_l|sample_lod|sample_a16|sample_c|gather_lz|load_mip|load_d16)[a-z0-9_]*$' -E '_hardware$'
python .agentic/scripts/with_gpu_lock.py ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^startup_image_(...)[a-z0-9_]*_hardware$'- 26 non-hardware tests and 12
_hardwaretests pass in Debug and in Release/O2, with no skips. These includestartup_image_cube_{controls,warp,hardware}. - On
main86beae95the new tests are not registered (tests/cmake/startup_image_cube.cmakeis new), andmain's translator refuses the cube dimension.
Mutants in tools/startup/gfx2hlsl.py. Each was applied alone, then startup_image_cube_{controls,warp} was run, and the source restored afterwards (git diff --quiet clean).
| Mutant | Result |
|---|---|
raw float3(s, t, face) instead of x2w_cube_dir(...) |
killed: translation control |
DISABLE_CUBE_WRAP read from bit 27 instead of 28 |
killed: the bit-28 sampler is accepted |
| cube Load refusal removed | killed |
| cube compute refusal removed | killed |
cube image_sample_d refusal removed |
killed |
SQ_RSRC_IMG_CUBE removed from three |
killed |
u = clamp(s - 1.5, -1, 1) (scale 1 instead of 2) |
survives |
v = 2(t - 1.5) without the clamp |
survives (see below) |
Finding: the face scale is not pinned. Every draw samples a 2×2 face at a texel centre (s, t ∈ {1.25, 1.75}), and the v_cube chain directions land on texel centres too. On a 2×2 face with point sampling, only the sign of u and v picks the texel, so any positive factor in u = k(s - 1.5) reads the same texel. The helper-row mutants in the check catch the sign, axis and face errors, but not this one.
- To reproduce: change
2.0 * (s - 1.5)to(s - 1.5)in the emitted helper, then runctest --test-dir out/build/dev -R '^startup_image_cube_(controls|warp)$'. Both pass. - Suggested direction (unconfirmed): add one case that a wrong scale changes, for example a 4×4 face. At
s = 1.125, factor 2 gives texel 0 and factor 1 gives texel 1. A linear-filter case at a non-centre coordinate, with the expected blend, would also do.
Non-blocking: the edge clamp is an assumption. x2w_cube_dir clamps u and v to the face. Without the clamp, an out-of-range s would instead select a neighbouring face on the desktop. No case has s or t outside [1, 2], so neither behaviour is tested, and I don't know which one gfx10 hardware has. The comment states the clamp as fact. Calling it an assumption there, or in docs/experiments/startup-image-cube.md, would help.
Verdict: changes requested for the face-scale gap. The lowering itself matches my derivation; the fixture just cannot tell the right scale from a wrong one.
Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088 and WARP 10.0.26100.9818, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Python 3.12.10; debug layer enabled.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on f7da3f69.
This reply was AI-assisted.
Switch --startup-image-cube to six 4x4 faces (96 distinct texels) with outer-ring texel centers so dropping the 2.0 * scale on u or v shifts texels on both WARP and hardware, add scale-2 translator mutants and controls, and clarify that clamping outside [1, 2] is an untested assumption. AI-assisted.
|
@pigalot Thank you for catching that! Fixed in
AI-assisted. |
|
Note on the AI-assisted. |
There was a problem hiding this comment.
Re-reviewed dda0ca8 on main 24eb18b (trial tree 48bfb76ab462f962c47d520ee39e2264d48e5c12). The 4x4 faces distinguish the earlier scale issue: at (1.125, 1.875, +X), dropping the U factor reads (1,3,+X), and dropping the V factor reads (0,2,+X), instead of the expected (0,3,+X). Both mutants failed as expected on WARP and RTX. The edge clamp is documented as an assumption.
cmake --build <build> --target offscreen_check
ctest --test-dir <build> --no-tests=error --output-on-failure -j 1 -R "^startup_image_cube_(controls|warp|hardware)$"
Debug and Release /O2 each passed 3/3, no skips. Each adapter matched 22 reference draws and 19 controls/mutants. Windows 11 26200.9974, RTX 4060 Laptop 32.0.16.1656, inbox WARP 10.0.26100.9818, D3D12 debug layer enabled on both adapters. The local watcher check passed, and the rerun of the Linux workflow is green on the same head.
@pigalot, the earlier face-scale finding is now exercised on the updated head. Could you recheck your change request?
pigalot
left a comment
There was a problem hiding this comment.
I retested dda0ca83 merged over main a166a753. The merge is clean (tree 86d88383) and git diff --cached --check is clean.
My earlier finding (face scale 2.0 * (s - 1.5) not pinned): addressed. The faces are now 4x4 and the literal cases use outer-ring texel centres (1.125 and 1.875), so a scale of 1 moves every literal case to another texel. I edited x2w_cube_dir in tools/startup/gfx2hlsl.py and ran startup_image_cube_controls, _warp and _hardware:
| Mutant | Result |
|---|---|
u = clamp(s - 1.5, -1.0, 1.0) |
killed in all three |
v = clamp(t - 1.5, -1.0, 1.0) |
killed in all three |
u = clamp(2.0 * (s - 1.0), -1.0, 1.0) |
killed in all three |
All three are caught first by the helper-text asserts. So I ran the draw mode again from a copy of the test with those two asserts removed. Unmutated, it reports "22 cube draws matched their references; 19 controls and mutants read the texel they predict". With either scale dropped, it fails with "image 3D readback differs" on WARP. So the draws pin the scale on their own. The new in-test u scale 2 dropped and v scale 2 dropped mutants cover the same thing on both adapters.
What I ran. I built offscreen_check in dev and release, then ran:
ctest --test-dir out/build/<preset> --no-tests=error -j 4 -R 'startup_image_|startup_gfx2hlsl_image' -E '_hardware'
python .agentic\scripts\with_gpu_lock.py ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '(startup_image_|startup_gfx2hlsl_image).*_hardware'- Results: 41/41 non-hardware and 18/18 hardware tests pass in both Debug and Release
/O2, with no skips. These include the neighbours whose checks changed with the 4x4 texel formula:startup_image_3d,_2d_array,_sample_band_sample_l. - Negative control:
tests/cmake/startup_image_cube.cmakeandstartup_image_cube_check.pydon't exist onmaina166a753, somainregisters no cube test.
Verdict: approve on dda0ca83. This supersedes my changes-requested review on f7da3f69.
Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088 and WARP, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Windows SDK 10.0.28000.0 DXC, Python 3.12.10; I did not check the debug-layer status.
CI: Build and test on Windows passes on dda0ca83.
This reply was 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