shader: lower v_cubema/sc/tc/id_f32 and SQ_RSRC_IMG_CUBE in gfx2hlsl (Part of #1723) #2035
No reviewers
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!2035
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2035/head"
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?
@tedin7 on GitHub · 2026-11-24 23:31 UTC · original
tedin7:x2w-r20-cube→main· +391 −30 · 15 files · 11 commits · closed without mergingPart of #1723
What this unblocks: Run 20 census #6 (71/69 pairs): cube-map shaders no longer stop translation.
Lowers
v_cubeid_f32,v_cubesc_f32,v_cubetc_f32andv_cubema_f32intools/startup/gfx2hlsl.pythrough four helpers in the common preamble (major axis is z when |z| >= max(|x|,|y|), else y when |y| >= |x|, else x; face ids +x -x +y -y +z -z;mais twice the major axis). Image ops withdim:SQ_RSRC_IMG_CUBEtake (s, t, face) and declare aTexture2DArray<float4>(kindtex2da), the same path asSQ_RSRC_IMG_2D_ARRAY. Seamless filtering across face edges is not modelled.Verification:
python3 -B tests/startup_gfx2hlsl_cube_check.pyon the branch:gfx2hlsl cube: ok.origin/mainsources: fails withUnsupportedon the first cube op.startup_gfx2hlsl_swap_check.py,_sdwa_check.py,_operand_count_check.py,_op_refusals_check.py,_cmp_class_check.py,_mad_check.py.startup_gfx2hlsl_cube.AI-assisted; commands listed were executed locally.
@ -2902,2 +2902,3 @@dmask = int([m for m in mods if m.startswith('dmask:')][0][6:], 0)kinds = {'SQ_RSRC_IMG_1D': 'tex1d', 'SQ_RSRC_IMG_2D': 'tex2d', 'SQ_RSRC_IMG_3D': 'tex3d', 'SQ_RSRC_IMG_2D_ARRAY': 'tex2da'}kinds = {'SQ_RSRC_IMG_1D': 'tex1d', 'SQ_RSRC_IMG_2D': 'tex2d', 'SQ_RSRC_IMG_3D': 'tex3d', 'SQ_RSRC_IMG_2D_ARRAY': 'tex2da','SQ_RSRC_IMG_CUBE': 'tex2da'}@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:39 UTC · original
Accepting this dimension breaks three existing pure-Python checks:
tests/startup_image_sample_l_check.py:246raisescube was accepted,tests/startup_image_3d_check.py:114raisesunverified image dimension accepted, andtests/startup_image_2d_array_check.py:249raisesimage_load_mip on a cube accepted. All three pass against the parent translator and are still selected by.github/workflows/windows.yml:193-199; array draw mode also runs the failing controls before GPU work. Update these fixtures to verify the newly supported cube behavior alongside this mapping so the feature does not leave the existing test suite failing.Useful? React with 👍 / 👎.
@ -2908,2 +2912,3 @@one = dim == 'SQ_RSRC_IMG_1D'three = dim in ('SQ_RSRC_IMG_3D', 'SQ_RSRC_IMG_2D_ARRAY')# A cube is addressed as six 2D slices: the cube instructions already produce s, t and the face id.three = dim in ('SQ_RSRC_IMG_3D', 'SQ_RSRC_IMG_2D_ARRAY', 'SQ_RSRC_IMG_CUBE')@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:39 UTC · original
For a cube shader using a clamped sampler, RDNA cube normalization produces s/t coordinates in [1,2] (
SC / abs(MA) + 1.5), but this path feeds them unchanged intoTexture2DArray, which expects normalized coordinates in [0,1]. A +X-face-center sample consequently becomes(1.5, 1.5, 0)and clamps to the face corner instead of sampling(0.5, 0.5, 0). This corrupts even interior samples, independently of the acknowledged seamless-filtering limitation. Subtract the cube-specific bias from s/t beforeSampleorSampleLevel, leaving the face and LOD unchanged.Useful? React with 👍 / 👎.
@ -2902,2 +2902,3 @@dmask = int([m for m in mods if m.startswith('dmask:')][0][6:], 0)kinds = {'SQ_RSRC_IMG_1D': 'tex1d', 'SQ_RSRC_IMG_2D': 'tex2d', 'SQ_RSRC_IMG_3D': 'tex3d', 'SQ_RSRC_IMG_2D_ARRAY': 'tex2da'}kinds = {'SQ_RSRC_IMG_1D': 'tex1d', 'SQ_RSRC_IMG_2D': 'tex2d', 'SQ_RSRC_IMG_3D': 'tex3d', 'SQ_RSRC_IMG_2D_ARRAY': 'tex2da','SQ_RSRC_IMG_CUBE': 'tex2da'}@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:39 UTC · original
When the bound view is a normal
D3D12_SRV_DIMENSION_TEXTURECUBEorTEXTURECUBEARRAYSRV, emittingtex2damakes the runtime bind a null resource. Insrc/startup_stubs/d3d12_draw.inl, lines 956-958 requireTEXTURE2DARRAYfor this kind, lines 976-978 copy the recorded cube descriptor unchanged, and lines 1009-1018 reject its differing dimension and clear the texture. Thus these newly accepted shaders cannot sample their actual cube resources. Add a cube-aware binding kind or convert the recorded cube view into an equivalent array view with the correct face and mip ranges.Useful? React with 👍 / 👎.
@ -4251,2 +4262,4 @@'v_trunc_f32': (1, 'trunc({0})'), 'v_fract_f32': (1, 'frac({0})'), 'v_rndne_f32': (1, 'round({0})'),'v_sin_f32': (1, 'sin({0} * 6.283185307)'), 'v_cos_f32': (1, 'cos({0} * 6.283185307)'),'v_cubeid_f32': (3, 'cubeid({0}, {1}, {2})'), 'v_cubesc_f32': (3, 'cubesc({0}, {1}, {2})'),'v_cubetc_f32': (3, 'cubetc({0}, {1}, {2})'), 'v_cubema_f32': (3, 'cubema({0}, {1}, {2})'),@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:39 UTC · original
This adds public startup-translator capabilities without the documentation update required by
AGENTS.md.docs/experiments.md:11412still explicitly lists cubeimage_sample_lamong forms refused withUnsupported, anddocs/startup-runtime.md:875-876still says cube images are refused. Update the relevant README or experiments documentation with the accepted forms, reproduction command, and non-seamless filtering limitation so contributors can determine the actual supported scope.AGENTS.md reference: AGENTS.md:L210-L211
Useful? React with 👍 / 👎.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:39 UTC · original
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
8dfaaeeℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
@denn0x on GitHub · 2026-11-25 00:55 UTC · original
I checked the four helpers against the RDNA ISA pseudo-code for
V_CUBEID/SC/TC/MA_F32. The major-axis order (z, then y, then x, with>=), the face ids, the sign rules for sc/tc andma = 2 * majorall match.One small difference: the ISA compares
|z| >= |x| && |z| >= |y|separately, whileabs(z) >= max(abs(x), abs(y))lets HLSL'smaxdrop a NaN. A NaN in x can therefore pick a different face. Spelling out the two comparisons would match exactly.The sample is the part I think is wrong. The compiler does not pass sc/tc straight to a CUBE sample. In a private executable's pixel programs (aggregate, decode only):
dim:SQ_RSRC_IMG_CUBE;v_rcp_f32 |ma|, thenv_fmaak_f32 s, sc, rcp, 0x3fc00000and the same for t, i.e.sc / |ma| + 1.5.Since
mais twice the major axis,sandtlie in [1, 2], not [0, 1]. As aTexture2DArraysample:I have not run this on WARP. The failure follows from the coordinate range, and the test does not cover it because it only checks text.
Possible fixes, in order of effort:
dim:SQ_RSRC_IMG_CUBE, and refuse a non-clamp, non-wrap sampler. This is still not seamless.TextureCube. This keeps seamless filtering and also needs the SRV to be created as a cube.Either way, a value test that samples a small cube with distinct texels per face, through the exact
1.5sequence, would pin it down. Comparing the helpers' values with the ISA pseudo-code on a set of directions (including ties and signed zeros) would also strengthen the test.@ -2902,2 +2902,3 @@dmask = int([m for m in mods if m.startswith('dmask:')][0][6:], 0)kinds = {'SQ_RSRC_IMG_1D': 'tex1d', 'SQ_RSRC_IMG_2D': 'tex2d', 'SQ_RSRC_IMG_3D': 'tex3d', 'SQ_RSRC_IMG_2D_ARRAY': 'tex2da'}kinds = {'SQ_RSRC_IMG_1D': 'tex1d', 'SQ_RSRC_IMG_2D': 'tex2d', 'SQ_RSRC_IMG_3D': 'tex3d', 'SQ_RSRC_IMG_2D_ARRAY': 'tex2da','SQ_RSRC_IMG_CUBE': 'tex2da'}@tedin7 on GitHub · 2026-11-25 00:56 UTC · original
The three older refusal checks were already updated in 79c8ac9c (rebased); they pass locally.
@ -2908,2 +2912,3 @@one = dim == 'SQ_RSRC_IMG_1D'three = dim in ('SQ_RSRC_IMG_3D', 'SQ_RSRC_IMG_2D_ARRAY')# A cube is addressed as six 2D slices: the cube instructions already produce s, t and the face id.three = dim in ('SQ_RSRC_IMG_3D', 'SQ_RSRC_IMG_2D_ARRAY', 'SQ_RSRC_IMG_CUBE')@tedin7 on GitHub · 2026-11-25 00:56 UTC · original
Fixed in a678bc3c: cube s/t now lower as float3(s - 1.0, t - 1.0, face); check updated.
@ -2902,2 +2902,3 @@dmask = int([m for m in mods if m.startswith('dmask:')][0][6:], 0)kinds = {'SQ_RSRC_IMG_1D': 'tex1d', 'SQ_RSRC_IMG_2D': 'tex2d', 'SQ_RSRC_IMG_3D': 'tex3d', 'SQ_RSRC_IMG_2D_ARRAY': 'tex2da'}kinds = {'SQ_RSRC_IMG_1D': 'tex1d', 'SQ_RSRC_IMG_2D': 'tex2d', 'SQ_RSRC_IMG_3D': 'tex3d', 'SQ_RSRC_IMG_2D_ARRAY': 'tex2da','SQ_RSRC_IMG_CUBE': 'tex2da'}@tedin7 on GitHub · 2026-11-25 00:56 UTC · original
Fixed in a678bc3c: d3d12_draw.inl rebinds TEXTURECUBE and TEXTURECUBEARRAY views as TEXTURE2DARRAY (6 slices per cube). Needs a Windows build to run.
@ -4251,2 +4262,4 @@'v_trunc_f32': (1, 'trunc({0})'), 'v_fract_f32': (1, 'frac({0})'), 'v_rndne_f32': (1, 'round({0})'),'v_sin_f32': (1, 'sin({0} * 6.283185307)'), 'v_cos_f32': (1, 'cos({0} * 6.283185307)'),'v_cubeid_f32': (3, 'cubeid({0}, {1}, {2})'), 'v_cubesc_f32': (3, 'cubesc({0}, {1}, {2})'),'v_cubetc_f32': (3, 'cubetc({0}, {1}, {2})'), 'v_cubema_f32': (3, 'cubema({0}, {1}, {2})'),@tedin7 on GitHub · 2026-11-25 00:56 UTC · original
Fixed in a678bc3c: docs/startup-runtime.md and docs/experiments.md now list the accepted cube forms, the repro commands and the non-seamless limitation.
@denn0x on GitHub · 2026-11-25 01:37 UTC · original
Thanks, a678bc3c fixes the [1, 2] range and the binding. One case is still off: cube arrays.
In the same private executable's pixel programs (decode only, aggregate counts), a few of the CUBE samples are arrays. The third address component is built as
v_fmamk_f32 vZ, vLayer, 0x41000000, vFace, i.e.layer * 8 + face.As I understand it, that is how ACO addresses a cube array: each layer takes 8 face slots, of which 6 are used. The image descriptor is set up to match.
With TEXTURECUBEARRAY rebound as a 2D array of 6 slices per cube, the sampled slice
8 * layer + faceis wrong for every layer >= 1. For example, layer 1, face 0 reads slice 8 (layer 1, face 2) instead of slice 6.Options:
slice = floor(z / 8) * 6 + (z mod 8)on the rounded component, when the bound view is a cube array; ordim:SQ_RSRC_IMG_CUBEover a cube-array view until that remap has a test. A 2-layer cube array with a distinct colour per (layer, face), sampled at layer 1, would catch it.@tedin7 on GitHub · 2026-11-25 01:49 UTC · original
Thanks, both points were right. Pushed 9b540eb6.
cubeslice(),slice = floor(r / 8) * 6 + (r mod 8)onr = max(round(z), 0). Layer 0 (plain cube) is unchanged. The SRV rebind already maps a cube array to a 2D array of 6 slices per cube.cubeaxisnow spells out|z| >= |x| && |z| >= |y|.Verification (Linux, executed locally):
python3 -B tests/startup_gfx2hlsl_cube_check.py-> ok (checks thecubeslice(F(v2))sample text, the helper in the preamble and the separate comparisons)startup_gfx2hlsl_cube_alu_check.py(translation controls),startup_image_2d_array_check.py,startup_image_3d_check.py,startup_image_sample_l_check.py,startup_gfx2hlsl_refusals_check.py,startup_gfx2hlsl_f32_nan_check.py-> passNot done yet: the Win2025 WARP run, and a value test that draws a 2-layer cube array with a distinct colour per (layer, face) sampled at layer 1. The remap is only text-checked for now, so the PR stays open for that fixture before it is trusted.
AI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-25 02:36 UTC · original
Follow-up on the cube-array slice fix (9b540eb6): f5e61316 adds a real D3D12 draw check for the
layer * 8 + facetolayer * 6 + facemapping.tests/startup_image_cube_array_check.pydrawsimage_sample dim:SQ_RSRC_IMG_CUBEfor addresses 0, 5, 8, 9, 13 and reads back slices 0, 5, 6, 7, 11. A mutant that leaves the address aslayer * 8 + facemust read slice 9 for address 9 and fail.startup_image_cube_array_{controls,warp,hardware}.Verification:
python3 -B tests/startup_image_cube_array_check.py,tests/startup_gfx2hlsl_cube_check.py,tests/startup_image_2d_array_check.py,tests/startup_image_3d_check.pyall pass.python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py win2025 2035 --force --targets offscreen_check --regex 'startup_(image_cube_array|image_2d_array|image_3d|gfx2hlsl_cube)' --py-checks tests/startup_gfx2hlsl_cube_check.py,tests/startup_image_cube_array_check.pyat f5e61316.startup_image_cube_array_warpandstartup_image_cube_array_controls, 0 failed, 0 skipped). Both Python checks ok on Windows._hardwarevariants ran on that same adapter. A first attempt on the other slot failed with a missing file in that slot's checkout; the rerun above is the passing one.TEXTURECUBEARRAYtoTEXTURE2DARRAYview rewrite ind3d12_draw.inl(the draw binds the array view directly).AI-assisted; commands listed were executed locally.
@ -2902,2 +2902,3 @@dmask = int([m for m in mods if m.startswith('dmask:')][0][6:], 0)kinds = {'SQ_RSRC_IMG_1D': 'tex1d', 'SQ_RSRC_IMG_2D': 'tex2d', 'SQ_RSRC_IMG_3D': 'tex3d', 'SQ_RSRC_IMG_2D_ARRAY': 'tex2da'}kinds = {'SQ_RSRC_IMG_1D': 'tex1d', 'SQ_RSRC_IMG_2D': 'tex2d', 'SQ_RSRC_IMG_3D': 'tex3d', 'SQ_RSRC_IMG_2D_ARRAY': 'tex2da','SQ_RSRC_IMG_CUBE': 'tex2da'}@tedin7 on GitHub · 2026-11-25 11:01 UTC · original
Re-checked on current head
2e7a81e3: the cube refusal controls are updated in this head (tests/startup_gfx2hlsl_cube_check.py). Resolving. AI-assisted; commands listed were executed locally.@thepatrickworld on GitHub · 2026-11-25 11:54 UTC · original
Three fixtures, three runs, all on the AMD adapter (
adapter=AMD Radeon RX 9070 XT vendor=1002 device=7550,driver=32.0.32029.2010), backendhardware, both compilers.Cube ALU —
startup_gfx2hlsl_cube_alu_check.py draw <dxc> <check> hardware <fxc>:Cube image addressing —
startup_image_cube_array_check.py draw ..., five addresses per compiler:Addresses 0, 5, 8, 9 and 13 give slices 0, 5, 6, 7 and 11 under
dxc, the same underfxc, and the mutation that leaves thelayer * 8 + faceindexing in place is caught. Why 8 has to become 6 is stated by the fixture itself (tests/startup_image_cube_array_check.py:9-11) and by the helper ingfx2hlsl.py:3181— the ISA indexes with eight face slots per layer, the bound array view has six — that is their explanation, not something the log prints; the log only shows the pairs.2D array —
startup_image_2d_array_check.py draw ...: 24 readbacks and 20 mutation runs per compiler, all matching, all mutations failing.Limits of my run. The cube-array fixture reads
s = 1.75andt = 1.25(per its docstring), so in my run the bias removal is exercised on those two coordinates and I did not try others. The cube-ALU fixture carries no such coordinates. And out of the five addresses above, the only one that leaves the six-slice mapping is the mutation, which is expected to fail.AI-assisted.
@tedin7 on GitHub · 2026-11-25 11:54 UTC · original
Stage-2 verification at head
2e7a81e3a333a88a686c7cdaf13613a3c8588867(Windows Server 2025 build 26100, MSVC 14.44, D3D12 WARP, 3-slot pool):x2w_pipe.py win2025 2035 --force --targets offscreen_check --regex 'cube|startup_image_(2d_array|3d|sample_l)|gfx2hlsl'plus the three cube Python checks: dev 105/105 and release 105/105 passed.startup_gfx2hlsl_cube,startup_gfx2hlsl_cube_alu_{controls,warp},startup_image_cube_array_{controls,warp}.startup_gfx2hlsl_cube_check.py,startup_gfx2hlsl_cube_alu_check.py,startup_image_cube_array_check.py: ok.Co-Authored-By, no local-probe mentions.Note for the author: the PR body is stale. It still says "Win2025 run: not executed" and does not mention
cubeslice()(layer8+face to layer6+face), the two WARP draw checks, or the D3D12 SRV rebind. Please refresh it before Ready.AI-assisted; commands listed were executed locally.
@legacy-code-archaeologist on GitHub · 2026-11-25 11:59 UTC · original
Ran head
2e7a81e3on three adapters. All pass. Windows 11 build 26100, debug layer unavailable, FXC and DXC from SDK 10.0.26100.0. The adapter for each hardware run came fromXBOX2WINDOWS_ADAPTERand was confirmed by theadapter=line.startup_gfx2hlsl_cube,startup_gfx2hlsl_cube_alu_controls,startup_image_cube_array_controlsstartup_gfx2hlsl_cube_alu_{warp,hardware}startup_image_cube_array_{warp,hardware}For context: in a local census of start-up shader requests (aggregate counts only, one input, not checked in CI),
v_cubema/sc/tc_f32each appear in 221 pixel code pairs,v_cubeid_f32in 220 andimage dimension SQ_RSRC_IMG_CUBEin 220, so this PR covers a large block of pixel refusals there. The head currently conflicts withmain.AI-assisted.
@tedin7 on GitHub · 2026-11-25 12:58 UTC · original
Thank you for running this on three adapters (WARP, Quadro M1000M, HD Graphics 530) and for the census numbers. Both are useful.
Your pass is on
2e7a81e3. The head has since moved todb59df52, which is a merge ofmaininto the branch. That merge also clears the conflict you noted.After the merge, the Linux Python check
tests/startup_image_sample_b_check.pyfailed. It still expectedimage_sample_bon a cube to be refused, and this PR now accepts cube addressing. The lowering intools/startup/gfx2hlsl.pyis unchanged. Only the test control changed: the refusal case now usesSQ_RSRC_IMG_1D_ARRAY, the same swapstartup_image_sample_l_check.pyalready got in this PR.Fix is commit
52020e6c(test file only,tests/startup_image_sample_b_check.py). Your hardware results should still hold, since no shader code or WARP/hardware test changed after2e7a81e3.Commands run locally:
python3 -I tests/startup_image_sample_b_check.py: ok (failed with "cube was accepted" before the change)python3 -I tests/startup_image_*_check.pyandtests/startup_gfx2hlsl*_check.py: all okOne open point:
image_sample_bon a cube is now accepted through the shared path, but no WARP readback covers the bias case yet.AI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-25 13:50 UTC · original
Closing this PR for now to keep the Windows test queue short. Nothing is wrong with it and the branch stays as it is.
We will reopen it once the queue is clear, re-run the Win2025 WARP checks at its head, and post the result here.
AI-assisted; commands listed were executed locally.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:39 UTC · original · reviewed
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
8dfaaeef7fℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Pull request closed