Skip to content

rdna2spirv: support 1D, 3D, CUBE, 2D_MSAA, 2D_MSAA_ARRAY and a16 in image_get_resinfo - #5247

Open
DenRakEiw wants to merge 1 commit into
ItsNotRexed:mainfrom
DenRakEiw:feat/rdna2-image-get-resinfo-dims
Open

DenRakEiw wants to merge 1 commit into
ItsNotRexed:mainfrom
DenRakEiw:feat/rdna2-image-get-resinfo-dims

Conversation

@DenRakEiw

Copy link
Copy Markdown
Contributor

Claim: #5156 (comment)

Summary

Extends image_get_resinfo in tools/rdna2spirv.py to support all remaining standard bindless image dimensions (plus a16 16-bit mip level masking):

  • dim:SQ_RSRC_IMG_3D (set 0 binding 6, %images_3d): OpImageQuerySizeLod %v3int + OpImageQueryLevels %int with OOB mip zeroing (mip >= levels -> (0, 0, 0, levels)).
  • dim:SQ_RSRC_IMG_CUBE (set 0 binding 3, %images_arr, matching the bindless 2D-array-of-6*N-faces layout): OpImageQuerySizeLod %v3int + OpImageQueryLevels %int -> (w, h, 6*N, levels) with OOB mip zeroing.
  • dim:SQ_RSRC_IMG_1D (set 0 binding 5, %images_1d, OpCapability Sampled1D): scalar OpImageQuerySizeLod %int + OpImageQueryLevels %int -> (w, 0, 0, levels) with OOB mip zeroing.
  • dim:SQ_RSRC_IMG_2D_MSAA & dim:SQ_RSRC_IMG_2D_MSAA_ARRAY (set 0 bindings 20 & 21, %images_2dms / %images_2dmsa matching runtime/src/vulkan_bindless.h): OpImageQuerySize %v2int / %v3int + OpImageQuerySamples %int (no mipmaps, so OpImageQuerySizeLod / OpImageQueryLevels are not emitted; mip != 0 zeroes spatial extents while keeping sample count in .w).
  • a16: masks the low 16 bits (& 0xFFFF) of the address VGPR as the unsigned mip level.
  • Preserves existing 2D and 2D_ARRAY (SHADER-388) behavior and Gen.resinfo_words bool backwards compatibility; SQ_RSRC_IMG_1D_ARRAY (no bindless binding) and d16 remain Unsupported.

Verification

  • python -m unittest discover -s tests/semantic -p test_image_get_resinfo_dims.py -v: 10/10 PASS (all 7 dims in PS & CS, 8 dmask subsets per dim, a16, semantic evaluation of resinfo_words including OOB mips, and llvm-mc-assembled round-trips — every generated SPIR-V module validated with spirv-as + spirv-val --target-env vulkan1.2).
  • python -I tests/test_image_query_translate.py -v: 10/10 PASS.
  • pytest tests/test_translate.py -k resinfo -v: 6/6 PASS (with LLVM_MC + spirv-val).
  • python -I tests/test_text_write_line_endings.py: 3/3 PASS.
  • scripts/run_gpu_tests.py --filter resinfo:
    • NVIDIA GeForce RTX 5090 (LEONIDA_W64_EMULATE=1): 2/2 PASS (cs_resinfo 64/64 words exact, ps_array_resinfo 4096/4096 pixels exact).
    • AMD Radeon iGPU (LEONIDA_VK_DEVICE=AMD): 1/2 PASS, 1 SKIP (cs_resinfo 64/64 words exact; ps_array_resinfo skipped due to 128 B push-constant limit).
  • git diff --check: clean.

AI-assisted (Gemini 4 Neon).

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 20f02e6 on Intel UHD Graphics 630 (CFL GT2, subgroup 8..32): tests/semantic test_image_get_resinfo_dims passes (10 tests), tests/test_image_query_translate.py passes (10), and test_translate.py -k resinfo gives 6 passed. run_gpu_tests.py --filter resinfo with LEONIDA_VK_DEVICE=Intel passes 2/2, "PASS cs_resinfo all 64 words of the uint image, the sint image and the volume exact" and "PASS ps_array_resinfo 4096/4096 pixels exact", and a nonexistent device name fails both rows with "no Vulkan physical device matches". Those two GPU fixtures are not changed by this PR, so the new 1D, 3D, CUBE, MSAA and a16 paths are covered here only by the semantic and translator tests. The AMD and NVIDIA results in the description were not reproduced.

AI-assisted.

@CryingLaughing

Copy link
Copy Markdown
Contributor

Independent RTX 4080 coverage of the new query paths at 20f02e62 (Windows 11 build 26200, NVIDIA 621.01, Khronos validation 1.4.357).

  • Cube and a16: Five synthetic cube pixel shaders ran through stock vk_texture_test against its 8×8, 12-face array view. Each matched all 4,096 RGBA32F pixels. Mip 0 and a16 with 0xabcd0000 returned (8, 8, 12, 1). Mip 1, a16 with 0xabcd0001, and unmasked 0xabcd0000 returned (0, 0, 0, 1). Parent 3faac557 rejected all five cube variants during translation. The existing 2D-array control was byte-identical on both revisions.
  • 3D: A local vk_store_test variant added two sampled views at binding 6 over the same 19×11×5 volume. The translated compute fixture matched 64/64 readback words, covering mip 0 and 1, the first out-of-range mip, a view starting at mip 1, packed a16, and a selective dmask with a preserved VGPR.

SPIR-V validation passed and there were no Vulkan validation warnings or errors. Synthetic inputs only. AI-assisted with Codex.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Head 20f02e6 · Windows 11, Python 3.13.15

  • python tests/semantic/test_image_get_resinfo_dims.py -v -> 9 passed, 1 skipped ("requires llvm-mc with amdgcn target")
  • python -I -m pytest tests/test_image_query_translate.py -q -> 10 passed (10 subtests)
  • python -I -m pytest tests/test_translate.py -k resinfo -q -> 6 skipped (LLVM_MC absent), 590 deselected
  • Main repro: PR test with origin/main:tools/rdna2spirv.py -> FAILED (failures=16, errors=57, skipped=1)
  • git diff --check clean

Two problems:

  1. No docs/design.md change, and that contract row still ends "image_get_resinfo on other dimensions is Unsupported". CONTRIBUTING.md and AGENTS.md require a new translator rule in the table with how it was confirmed.
  2. The MSAA path loads binding 20/21 unconditionally. The runtime puts an MS view only at sampled_binding(dim, sampled_class), with sampled_class = numeric_class(view_format) (runtime/src/vulkan_bindless.h, write_image), so UINT/SINT MSAA live at bindings 22–25. A uint MSAA T# therefore queries the 1x1 fallback rather than the texture. The GPU runs in the body only cover 2D and 2D-array resinfo, so this is unverified.

Verdict: needs changes — docs row plus class-aware MSAA binding (or an explicit, tested restriction).

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 20f02e6 on Windows Server 2022, CPython 3.13.12: pass

  • python -I tests/test_image_query_translate.py -> Ran 10 tests, OK
  • Negative control (tools/rdna2spirv.py swapped to upstream/main): also OK, control does not differentiate on this suite

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

@sovljanskii

Copy link
Copy Markdown
Contributor

Tested 904608c merged onto main 561b65a (the branch already contains it) on Apple M4, macOS 27.2.1, MoltenVK 1.4.2, Python 3.15.2 and 3.12.16: needs changes

  • Both earlier review points are still open at 904608c.

    • No docs/design.md change: the "Image atomics, size and LOD queries" row (design.md:401) still ends "image_get_resinfo on other dimensions is Unsupported". The new rules need contract rows that say how each was confirmed.
    • MSAA always reads bindings 20/21. In runtime/src/vulkan_bindless.h, write_image puts an MS view only at sampled_binding(dim, sampled_class) (20/21 + 2·class) and the fallback image everywhere else. So a UINT or SINT MSAA T# gets the size and sample count of the fallback image, not of the texture.
  • The hardware result is unmeasured for every new dimension. The only native measurement (gfx1036, tools/image_query_probe.py, SHADER-388) covers 2D and 2D array. Two choices run against that measured rule:

    • CUBE returns the unminified face count at every level. On hardware, the 2D array's layer count is minified like a 3D depth, max(1, layers >> (BASE_LEVEL + level)) (design.md:401). A cube T# keeps its faces in the same DEPTH field, so mip > 0 of a multi-level cube may come out minified on hardware.
    • MSAA .w is OpImageQuerySamples. runtime/src/gfx10_descriptors.h:121 writes an MSAA T# with BASE_LEVEL 0 and log2(samples) in LAST_LEVEL. design.md:401 measures the level word as LAST_LEVEL − BASE_LEVEL + 1. Unless the hardware special-cases MSAA, that gives log2(samples) + 1 (3 for 4x), not 4.
    • The 1D height word (0 here) is unmeasured as well.

    Please measure these with an extended image_query_probe.py on your AMD GPU, or record them in the new contract rows as hypotheses. The semantic test's evaluator encodes the same assumptions, so it can't tell either way.

  • Corpus: none of the new paths has a user in this corpus. Over all 25,734 shaders, every one of the 1,148 image_get_resinfo instructions (in 407 shaders) is dim:SQ_RSRC_IMG_2D. None uses 1D, 2D array, 3D, cube, MSAA, a16 or d16, and no image instruction of any kind uses an MSAA dimension. Shard 0/64 (--no-asm): main and PR both translate 415/415, all 415 pass spirv-val, and no shader is unsupported. 0 of 415 .spv hashes differ, and 0 index entries differ.

  • Semantic suite in the PR tree: 6,160 tests (main has 6,150, plus these 10). The result is OK (skipped=1, expected failures=1), the same as main, with no failing ids on either side.

  • PR tests, both Pythons: test_image_get_resinfo_dims 10/10, including the llvm-mc round trip (LLVM 23.1.6). test_image_query_translate passes 10/10, and test_translate.py -k resinfo passes 6/6 (pytest, Python 3.15 only). compileall and git diff --check are clean.

  • Mutations, 10 of 10 caught by test_image_get_resinfo_dims:

    • a16 mask dropped;
    • mask widened to 0xFFFFFFFF;
    • MSAA mip ≠ 0 no longer zeroing the extents;
    • CUBE minified like 2D array;
    • 1D height 1;
    • MSAA binding 20 → 22;
    • MSAA .w = 1;
    • z not zeroed past the last level;
    • a16 rejected again;
    • CUBE reading the 3D binding.

    test_image_query_translate catches none of them: it only checks that 1D_ARRAY and d16 still raise.

  • GPU, M4: run_gpu_tests.py --filter resinfo gives 2/2 PASS on main and on the PR (cs_resinfo 64 words, ps_array_resinfo 4096/4096), and both SPIR-V files are byte-identical to main's. I also made local variants of ps_array_resinfo.asm with dim:SQ_RSRC_IMG_CUBE against its 8×8, 12-layer view:

    • mip 0, and a16 with 0xabcd0000: (8, 8, 12, 1) on all 4096 pixels;
    • mip 1, a16 with 0xabcd0001, and an unmasked 0xabcd0000: (0, 0, 0, 1);
    • these match what the PR intends.

AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 904608c merged with main 561b65a (PR already based on it) on Linux WSL2, Python 3.12.16, and native Windows, Python 3.13.1 (llvm-mc 23.1.6 on PATH): pass

tests/semantic/test_image_get_resinfo_dims.py: Linux 10 run, 9 passed, 1 skipped (the llvm-mc/spirv-val round trip, no spirv-as on Linux), 0 failed; Windows 10 run, 10 passed, 0 skipped. tests/test_image_query_translate.py: 10 run, 10 passed on both.

Full semantic suite with the #4357 runner (scripts/run_semantic_tests.py --jobs 3, Linux): 434 files, 6160 tests, 0 files not ok. Baseline main (561b65a): 433 files, 6150 tests, 0 not ok; the difference is exactly this PR's new file (1 file, 10 tests), so no other file changed status.

Negative control: with tools/rdna2spirv.py restored to upstream/main the new semantic file runs 10 tests with 16 failures, 57 errors and 1 skip. tests/test_image_query_translate.py still passes on main's translator, because the PR only removes 1D/3D/CUBE and a16 from that file's list of dims that must be refused, so that edit is not a regression check by itself. I checked the bindings: the new set-0 bindings 20 and 21 for MSAA images match first_ms_binding = 20 and the comment in runtime/src/vulkan_bindless.h. No issue found.

@thiefyzheng thiefyzheng left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code read at 904608c4 against base 561b65a8 (AI-assisted review, automated pass per AGENTS.md; driver + worker, see lrev).

Mechanical checks (run by the driver, not the model):

  • compileall on the changed Python: ok
  • tests/semantic/test_image_get_resinfo_dims.py: ok — OK (skipped=1)
  • patch mentions game-data/protection terms; needs a human read

Review
VERDICT: CONCERNS
WHY: The translation is wired correctly (bindings, types and capabilities match runtime/src/vulkan_bindless.h and gfx10_descriptors.h, and the 2D/2D_ARRAY paths are preserved), but the CUBE path issues the same OpImageQuerySizeLod %v3int on the same %images_arr/%img2da as 2D_ARRAY yet skips the layer minification applied there, and none of the new dimension rules is recorded in the docs/design.md contract table or confirmed against hardware — the only resinfo GPU tests still cover just 2D and 2D array.
FINDINGS:

  • tools/rdna2spirv.py:12556 — CUBE is queried through exactly the same path as 2D_ARRAY (has_z at 12548 routes it to OpImageQuerySizeLod %v3int on the %images_arr/%img2da load), but only dim:SQ_RSRC_IMG_2D_ARRAY applies the max(1, layers >> (BASE_LEVEL + level)) minification; the cube face count is returned raw. One of the two must be wrong for the same hardware query, and docs/design.md:401 states the measured RDNA2 rule is that a 2D array's depth word is minified — a cube is bound as a 6N-layer 2D array (runtime/src/gfx10_descriptors.h:199), so a minification is to be expected there too. Nothing measures the cube case (runtime/test/shaders/cs_resinfo.asm:41 and ps_array_resinfo.asm:6 only exercise 2D and 2D_ARRAY), and tests/semantic/test_image_get_resinfo_dims.py:315 bakes the unminified assumption in, so the suite cannot catch it.
  • docs/design.md:401 — the contract row for this instruction still ends with "image_get_resinfo on other dimensions is Unsupported" and records only the 2D/2D-array behaviour measured on gfx1036; five new rules (3D, CUBE, 1D, 2D_MSAA, 2D_MSAA_ARRAY) plus a16 masking were added with no row and no statement of how each was confirmed. AGENTS.md requires a new translator rule to go into that table with its confirmation, and the PR's own GPU evidence covers none of the new dimensions (only cs_resinfo 2D and ps_array_resinfo 2D_ARRAY), so the MSAA sample-count-in-W, mip != 0 zeroing, 1D depth = 0 and cube face count are assumptions.
  • tools/rdna2spirv.py:14218 — declaring %images_2dms/%images_2dmsa (bindings 20/21) makes the shader statically use those bindings unconditionally, while runtime/src/vulkan_bindless.h:125 (binding_enabled) omits the MS bindings from set 0's layout whenever that sample class is off — the default is one sample, and limit_ms_bindings turns classes off on devices whose descriptor limits are tight. On such a device a shader containing an MSAA image_get_resinfo fails pipeline creation instead of falling back via the descriptor table.
    CHECKED: .lrev.diff; tools/rdna2spirv.py (lines 12500-12574 resinfo_words, 12675-12869 image_misc, 13945-13960 iface, 13996 capabilities, 14171-14230 types/decorations, 14485-14510 globals, 11360-11399 desc_lookup/uses_tex); tests/semantic/test_image_get_resinfo_dims.py; tests/semantic/support.py (translate_lines/translate_listing); tests/semantic/README.md; tests/test_image_query_translate.py (160-204); tests/test_translate.py:1558-1572; docs/design.md:262-277, 399-401; runtime/src/vulkan_bindless.h:4-160; runtime/src/gfx10_descriptors.h:180-200; runtime/shims/d3d12_vulkan_device.cpp:4684; runtime/test/shaders/cs_resinfo.asm, ps_array_resinfo.asm; scripts/run_gpu_tests.py:890. No game data or protection material appears in the diff (the mechanical flag is a false positive: the matches are the words cube/dim:). I could not run spirv-val or the GPU tests here, and validate_spirv in the new test returns silently when spirv-as/spirv-val are absent, so the driver's "OK (skipped=1)" does not by itself prove the modules validated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants