Skip to content

rdna2spirv: define the format-table constants before use - #3921

Closed
Kam471 wants to merge 1 commit into
ItsNotRexed:mainfrom
Kam471:fix-fmt-size-const
Closed

Kam471 wants to merge 1 commit into
ItsNotRexed:mainfrom
Kam471:fix-fmt-size-const

Conversation

@Kam471

@Kam471 Kam471 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

What

main aa2988cc added the fmt_size_arr table for typed buffer loads. The table's declaration and members call gen.cu(), but that block runs after the constant instructions are emitted (for v, name in sorted(gen.consts.items())). The first such call, gen.cu(128) for the array length, therefore adds %c80 after its use.

Red on main:

python -m pytest tests/test_u16_high_half.py -q
FAILED tests/test_u16_high_half.py::test_d16_buffer_store_no_redundant_extract_after_shr16
spirv-as: error: line 153: Operand '135[%135]' requires a previous definition
  %_arr_uint_135 = OpTypeArray %uint %135

The same applies to the mask table length (16), its member constants and the 128 format sizes if they are not already in the constant set.

Fix

Before emitting the constants, register the constants the format tables need:

  • gen.cu(128) and every FORMATS[c][0] size when uses_fmt_size;
  • gen.cu(16) and every int_format_masks() word when uses_store_views or uses_int_fetch.

The declaration block still calls gen.cu(); it now returns the already-emitted ids.

Green

python -m pytest tests/test_u16_high_half.py -q          -> 33 passed
python -m pytest tests/test_d16_format_probe.py -q       -> 21 passed, 2 skipped
compileall                                              -> clean
git diff --check                                        -> clean

No translator behavior change beyond defining the constants it already referenced. No game data. Head c0130045. AI-assisted.

uses_fmt_size names %c80 as the 128-entry array length after the constant block was emitted, so the SPIR-V referenced an undefined id and spirv-as rejected it. Register the table length, member sizes and mask constants before emitting the constant instructions.
@CaravelaLabs

Copy link
Copy Markdown
Contributor

Automated test: c0130045 merged onto main aa2988cc on AMD Radeon 8060S (RADV GFX1151, RDNA 3.5), Mesa 25.2.8, Ubuntu 24.04, runtime rebuilt from this branch in a clean sandbox. Result: pass.

Same machine and setup as my earlier manual reports. AI-assisted (Claude Code).

@ray3242

ray3242 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

This fixes the same main aa2988cc regression as #3902 by @fearkov: the %c80 array length of %fmt_size_arr is used before it is defined. @fearkov claimed it in #3796 at 22:20 UTC and opened #3902 at 22:22. I found no claim for this PR.

The two fixes take different approaches. #3902 inserts late gen.cu constants after the constant block (insert_late_constants), while this PR registers the format-table constants before that block. On Linux with CPython 3.12.16, pytest -q tests/test_u16_high_half.py gives:

Only one of the two is needed.

AI-assisted (Devin).

@throny

throny commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested c013004 on real corpus shaders (CPU only, Windows 11): pass. The 4 shaders of my own 1.0.2.1 copy that were newly invalid at aa2988cc (requires a previous definition, 0/4 valid) are 4/4 valid with this head; #3902 c225f859 gives the same 4/4 (table in #3902). The two overlap, as @ray3242 noted; #3902 was claimed first, is the more general fix and has a test. Counts only, no shader data. AI-assisted.

@Kam471

Kam471 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of #3902, which fearkov claimed first (22:20Z) and which fixes this generically by inserting every late gen.cu() constant after the last written one, rather than pre-registering just the format-table constants. I verified #3902 at c225f859: tests/test_u16_high_half.py 33 passed, tests/test_d16_format_probe.py 21 passed / 2 skipped, compileall clean. No content is lost; #3902 is the fix to review.

@Kam471 Kam471 closed this Nov 22, 2026
@javdc

javdc commented Nov 22, 2026

Copy link
Copy Markdown

Tested c013004 on Steam Deck LCD (Jupiter), AMD Custom GPU 0405 "Van Gogh", RADV Mesa 26.2.0-devel (git-5c65d4fc31), Vulkan 1.4.350, SteamOS 3.9.5 (holo), kernel 7.2.7-valve2-2-neptune-72-g31504582a073: pass.

Commands:

  • python3 -m pytest tests/test_u16_high_half.py -q -> 33 passed
  • python3 -m pytest tests/test_d16_format_probe.py -q -> 21 passed, 2 skipped, 2 subtests passed
  • python3 -I scripts/run_gpu_tests.py --build /home/deck/opencode/Leonida/runtime/build -> 194/210 passed, 14 skipped, 0 failed

The 14 skips were the expected suite skips; no failures.

AI-assisted (OpenCode).

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.

5 participants