startup: lower cube image sampling in gfx2hlsl #2960
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2960"
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 legacy-code-archaeologist on 2026-11-26T23:37:08Z.
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 #2938, which is still a draft. On main,d3d12_draw.inlreads an unknownsrvkind as a buffer, so this must land after #2938. That is why this PR is a draft too. Once both land, the sentence in #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
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-27T00:08:59Z.
Cross-check against the native path: on
cpp-migration(f934df52),cube_axesinsrc/gfx1013_direct_compute.inlalready rebuilds a cube direction for the direct C++ frontend. It uses the same per-face table asx2w_cube_dirhere: u = 2s - 3, v = 2t - 3, +X (1, -v, -u), -X (-1, -v, u), +Y (u, 1, v), -Y (u, -1, -v), +Z (u, -v, 1), -Z (-u, -v, -1). So both translators agree on the face convention.There are two differences, both outside what the fixture draws:
face >> 3as a cube-array layer for aTextureCubeArray. This lowering samples layer 0 of aTextureCube.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T04:32:12Z.
Review: COMMENTED
PR #2960 implements cube image sampling in gfx2hlsl. Complex translation that needs careful review.
What works
cubesc/cubetc/cubema registers. The s-1, t-1 face positioning is exactly right.
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.
(cube derivatives not converted), image_get_lod, a16, d16, compute stages, DISABLE_CUBE_WRAP constant sampler.
and known limitations (cube-array). The 254-line gfx2hlsl.py change is well-organized.
Issues
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.
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.
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.
Thegfx2hlsl-only translations can be checked but the draw-time binding cannot. Consider adding a unit test
that checks the emitted HLSL directly.
Recommendations
Overall: solid implementation. The experiment doc is thorough and the refusal cases are well-reasoned.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T05:36:27Z.
Review: COMMENTED
What works
_lz, _l, _b) to HLSL TypeCube Sample/SampleLevel/SampleBias.
LLVM's ConstantFoldAMDGCNCubeIntrinsic, with clear enumeration of
refused forms and limits (cube-array ambiguity, face-wrap, bias).
with per-face component ordering matching the standard cube layout.
Issues
correct but the error message format should be consistent with other
unbound-type refusals in the manifest binding code.
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.
(matches 2D handling). Verify the same check exists in the code.
Recommendations
(Sample, SampleLevel, SampleBias) and not just implicit LOD.
gfx2hlsl and update the experiment doc.
for a subsequent PR.
Overall
Strong implementation with excellent documentation. Clear enum of
limitations and correct refusal of derivatives. Approvable.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T09:36:49Z.
This PR now conflicts with
main. Conflicting files:tools/startup/gfx2hlsl.pyCould you merge
maininto your branch (a merge commit, no force push needed) and resolve these? Thank you.AI-assisted; commands listed were executed locally. (
git merge-tree origin/main <head>)Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-27T09:46:04Z.
Thanks for review @tedin7
On it as soon as I get home in like 2 hours, if it is urgent someone else can take over.
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-27T12:34:32Z.
@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.
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-28T00:39:55Z.
Merged
upstream/main(38129ba3, which includes#29387fcde81fruntimetexcubeview binding) intostartup/gfx2hlsl-image-cube, updateddocs/experiments/startup-image-cube.mdto reflect that#2938has landed, and marked this PR ready for review.Local verification (
devpreset, Windows 10.0.26100, WARP10.0.26100.9711&Intel(R) HD Graphics 53031.0.101.2111):cmake --build --preset dev --target offscreen_check d3d12_xs_shim startup_stream_consumer: passedctest --preset dev --no-tests=error -R '^(startup_image_cube|startup_image_3d|startup_image_2d_array|startup_image_sample_l|startup_image_sample_b|startup_address_console_cube_order)' -V: 24/24 passed (156.92s, 0 skips — includingstartup_image_cube_{controls,warp,hardware}andstartup_address_console_cube_order_{warp,hardware})python -B tests/docs_links_check.py: passed (128Markdown files,629links)AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-28T01:57:32Z.
Review: CHANGES_REQUESTED
Independently reviewed
f7da3f69integrated overmain86beae95(treecb3475be). The merge is clean andgit diff --cached --check origin/mainis 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:(1, -v, -u);(-1, -v, u);(u, 1, v);(u, -1, -v);(u, -v, 1);(-u, -v, -1).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.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.image_sample_d,image_get_lod, a16, d16 and compute stages are refused by name;DISABLE_CUBE_WRAP) is refused;srv ... texcubeto a TextureCube view (d3d12_draw.inl, kind 5).What I ran. I built
offscreen_check d3d12_xs_shim startup_stream_consumerindevandrelease, then ran:_hardwaretests pass in Debug and in Release/O2, with no skips. These includestartup_image_cube_{controls,warp,hardware}.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, thenstartup_image_cube_{controls,warp}was run, and the source restored afterwards (git diff --quietclean).float3(s, t, face)instead ofx2w_cube_dir(...)DISABLE_CUBE_WRAPread from bit 27 instead of 28image_sample_drefusal removedSQ_RSRC_IMG_CUBEremoved fromthreeu = clamp(s - 1.5, -1, 1)(scale 1 instead of 2)v = 2(t - 1.5)without the clampFinding: the face scale is not pinned. Every draw samples a 2×2 face at a texel centre (
s, t∈ {1.25, 1.75}), and thev_cubechain directions land on texel centres too. On a 2×2 face with point sampling, only the sign ofuandvpicks the texel, so any positive factor inu = 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.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.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_dirclampsuandvto the face. Without the clamp, an out-of-rangeswould instead select a neighbouring face on the desktop. No case hassortoutside [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 indocs/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 fixturesandRun platform-independent Python checks on Linuxpass onf7da3f69.This reply was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-28T02:08:25Z.
@pigalot Thank you for catching that! Fixed in
dda0ca83:4×4 cube faces & scale-2 verification (
tests/startup_image_3d.cpp,tests/offscreen_check.cpp,tests/startup_image_cube_check.py):--startup-image-cubeto six 4×4 faces (96distinct texels((1 + x + 4y + 16f) / 128, x, y, f)).CASESto outer-ring texel centers (1.125,1.875) andDIRECTIONSto exact binary32 directions landing on 4×4 texel centers ({1.125, 1.375, 1.625, 1.875}) withx != y.clamp(2.0 * (s - 1.5), -1.0, 1.0)/clamp(2.0 * (t - 1.5), -1.0, 1.0)assertions incontrols()and two new translator scale mutants (u scale 2 dropped,v scale 2 dropped) inmutants()(15mutants /19controls+mutants total).2.0 * (s - 1.5)with(s - 1.5)intools/startup/gfx2hlsl.pyfails bothstartup_image_cube_controlsandstartup_image_cube_warp(rc=8).Clamping outside
[1, 2]documented as an untested assumption (tools/startup/gfx2hlsl.py,docs/experiments/startup-image-cube.md):x2w_cube_dircomment and indocs/experiments/startup-image-cube.mdthat clampinguandvto[-1, 1]whensortlies outside[1, 2]is an untested assumption.Verified (
devandrelease/O2, Windows 11 24H210.0.26100.9711,debug_layer=unavailableon both adapters):ctest --preset dev --no-tests=error -R '^startup_image_(cube|3d|2d_array)' -V: 9/9 passed (cube controls/warp/hardware plus existingstartup_image_3dandstartup_image_2d_arraytests).ctest --preset release --no-tests=error -R '^startup_image_cube_' -V: 3/3 passed (22cube draws matched their references;19controls and mutants read the texel they predict on bothMicrosoft Basic Render Driver10.0.26100.9711andNVIDIA Quadro M1000M32.0.15.7371).python -B tests/docs_links_check.py: self-test passed (128Markdown files,629links). (llvm-mcis not present locally, sobinaryreassembly runs on CI.)AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-28T02:15:15Z.
Note on the
dda0ca83Linux CI failure:tests/startup_image_cube_check.py,Assemble and translate gfx1013 fixtures, andBuild and test on Windowsall passed;Run platform-independent Python checks on Linuxfailed on an unrelated ~1.5 ms mtime flake intests/startup_gfx2hlsl_watch_check.py(FAIL failure left unchanged by later passes, which passes locally). I don't have permissions to rerun the failed workflow job (gh run rerun --failed), so please rerun the failed Linux check on your side when convenient.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-28T02:29:49Z.
Review: APPROVED
Re-reviewed
dda0ca8314on main24eb18b9(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.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?
Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-28T03:52:56Z.
Review: APPROVED
I retested
dda0ca83merged overmaina166a753. The merge is clean (tree86d88383) andgit diff --cached --checkis 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 editedx2w_cube_dirintools/startup/gfx2hlsl.pyand ranstartup_image_cube_controls,_warpand_hardware:u = clamp(s - 1.5, -1.0, 1.0)v = clamp(t - 1.5, -1.0, 1.0)u = clamp(2.0 * (s - 1.0), -1.0, 1.0)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 droppedandv scale 2 droppedmutants cover the same thing on both adapters.What I ran. I built
offscreen_checkindevandrelease, then ran:/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.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 onf7da3f69.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 Windowspasses ondda0ca83.This reply was AI-assisted.