Skip to content

rdna2spirv: a pixel lane off at the last color export is not written; without vm, EXEC at the color export decides (measured on RDNA2) - #3988

Open
Vonsek wants to merge 1 commit into
ItsNotRexed:mainfrom
Vonsek:claude/ps-export-mask
Open

Vonsek wants to merge 1 commit into
ItsNotRexed:mainfrom
Vonsek:claude/ps-export-mask

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Lucas · project thread

Claimed in the coordination issue as: EGEN-PS-EXPORT-MASK, #3918 (comment) (finding with the full table: #3918 (comment))

What and why

#1640 made a pixel shader discard by EXEC at its last vm export, from the ISA guide, and said it was not measured. I measured it on RDNA2 with the pixel-shader oracle of #3061 (hand-written ISA as the pixel shader of a real draw, gfx1036, wave64 stage, 8x8 target, EXEC cut to half of the target with v_cmpx on an interpolated coordinate, s_waitcnt expcnt(0) after every export). 18 programs; one rule fits all of them:

a pixel is written when its lane was on in EXEC at the last vm export the path executed (if any) and at the last export to the color target.

The vm half is what #1640 implemented, and it holds. The color half is new: an export sends data only for the lanes that are on, a later export to the same target replaces the earlier one for the whole wave, and a lane with no data from the last one is not written, even when a later exp null done vm marks it valid. Six of the 18 programs differed from the translator:

program (R = right half off in EXEC) right half, hardware translator before
exp mrt0 done (no vm); EXEC R afterwards written discarded (EXEC at the end)
EXEC R; exp mrt0 done (no vm); EXEC restored not written written, initial value
EXEC R; exp mrt0; restored; exp null done vm not written written, initial value
exp mrt0 A; EXEC R; exp mrt0 B; restored; exp null done vm not written written with A
exp mrt0 A vm; EXEC R; exp mrt0 B done (no vm); restored not written written with A
EXEC R; exp mrt0 vm; restored; top half only; exp null done vm top-right not written top-right written, initial value

The change: export also keeps EXEC at each color export (%col_mask_mrtN), and the PS epilogue keeps the pixel when (no vm export ran or EXEC was on at the last one) and (EXEC was on at the last color export); a path with no export at all still goes by EXEC at the end. As before, the latches are only emitted when some path can write EXEC after a vm export, now also after a color export; in every other shader EXEC at the end is the same mask and the SPIR-V is unchanged (the 81 other semantic fixtures translate to byte-identical text).

Limits, also in the design row: with several color targets a pixel stays when any target got an export from its lane (Vulkan cannot skip one attachment per pixel, and the oracle's pipeline has one target, so this is not measured); mrtz is not part of the color mask (not measured). Whether any corpus shader writes EXEC between a color export and the end was not counted (no corpus here); compiled code normally exports last.

A trap for anyone measuring exports, now in docs/design.md: they are asynchronous. Without s_waitcnt expcnt(0) the hardware takes the data and the EXEC of a later moment, which looks exactly like "EXEC at the end decides".

Tested

  • tests/semantic/test_export_valid_mask.py: 21 tests. Two of Translator: a pixel shader discards by EXEC at its last vm export, not at the end #1640's expectations for paths without vm are turned around to what the hardware does, a class ColorExportMask has the table's rows, and the new GPU fixture runs there too. Against main's translator 7 fail; with the change all pass.
  • New GPU test runtime/test/shaders/ps_exp_color_mask.asm (the first row: exp mrt0 done from every lane, wait, EXEC off): run_gpu_tests.py --filter ps_exp_color_mask 4096/4096 pixels exact on the AMD Radeon RDNA2 iGPU (driver 26.10.1) and on the RTX 5080 (driver 616.92). The same body run natively through the oracle gives the same words on every pixel. With main's translator the test fails on both GPUs (every pixel still the clear value).
  • The rows whose hardware result is "not written" are asserted in the semantic test only: the pixel tests compare one tuple for every pixel.
  • python -m unittest discover -s tests/semantic: 7461 tests, 7 failures and 3 errors, the same ten as on main aa2988c without this change on this machine (test_loop_ballot_barrier 3 + 2 errors, test_cmp_class_f64 2, test_mutations 2, test_vcmp16_opsel 1 error; checked by running those four modules on a clean export of main). None is in the export tests. regen_fixtures.py --check clean; tests/test_shader_checks.py and tests/test_docs_*.py OK.
  • run_gpu_tests.py --filter ps_ on the Radeon with the change: 86/94 passed, 8 skipped, none failed.

Depends on nothing; #3061 is only the tool the measurement used.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

AI-assisted.

… without vm, EXEC at the color export decides

Measured on RDNA2 (gfx1036) with the pixel-shader oracle of ItsNotRexed#3061: a pixel is
written when its lane was on in EXEC at the last vm export (if the path has one)
and at the last export to the color target. The translator discarded by EXEC at
the end on a path without vm, and kept an older export's value for a lane off at
the last color export. The latches are only emitted where EXEC can change after
an export.

GPU fixture ps_exp_color_mask, semantic tests, design.md EXEC row.

AI-assisted.

@jeremygold02 jeremygold02 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.

Verified partial writes on the translated Vulkan path at b3d34afc6c047cc31bbe3b46f1592866ebecf47a. With independent color-export and validity masks, the 64 pixels in their intersection received B and all other 192 retained the framebuffer clear value. At parent aa2988cc555bad7ecd508b48a702adbb32fe7c95, the 64 top-right pixels showed the earlier color A. I compared all four RGBA32F words at every position.

Revision EXEC at last MRT0 export EXEC at final vm export B = 2 Earlier A = 1 Clear = −1
Head left half top half 64 0 192
Head left half all 128 0 128
Head all top half 128 0 128
Head all all 256 0 0
Parent left half top half 64 64 128

To reproduce, draw the synthetic vs_ids fullscreen triangle into a 16×16 target with vk_harness's −1 clear. The handwritten PS saves incoming EXEC, exports A = (1,1,1,1) to MRT0 from every lane, then exports B = (2,2,2,2) to the same target with EXEC restricted to u < 0.5. Restore incoming EXEC, restrict it to v < 0.5, issue exp null off, off, off, off done vm, then restore EXEC again. Use s_waitcnt expcnt(0) after each export. Omitting the first or second restriction independently gives the control rows above. The final restore ensures the result distinguishes the sampled export masks from end-of-shader EXEC.

Five draws ran on NVIDIA GeForce RTX 5070, driver 621.01 (32.0.16.2101), subgroup 32, with Intel Core Ultra 7 265K on Windows 11 Home 25H2 build 26200.9974. Built the harness from the PR head and translated the same synthetic assembly on each revision. All modules passed Vulkan 1.2 SPIR-V validation. This covers one MRT on the translated path. The PR author's separate native RDNA2 measurements provide the hardware reference.

AI-assisted by GPT-6.2 Astra.

@Vonsek
Vonsek marked this pull request as ready for review November 22, 2026 23:05
@FIocker

FIocker commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Independent mixed-mask pixel run at b3d34afc against aa2988cc, AI-assisted. Windows 11 26200, RTX 5080 (621.01), Vulkan 1.4.357. I drew three synthetic 64×64 fixtures with the fullscreen triangle's interpolated X/Y and compared all four channels with explicit pixel expectations. (1) Full A, left-half-only B, then full NULL vm: head 4096/4096; base 2048/4096, retaining A across the right half. (2) Left-half early color vm, then full B with no vm: both 4096/4096. (3) Left-half color and top-half final NULL vm: head 4096/4096 (1,024 colored pixels), base 3072/4096 (2,048 colored pixels). All six modules passed SPIR-V validation. The 21 semantic tests also passed.

@CaravelaLabs

Copy link
Copy Markdown
Contributor

Automated test: b3d34afc 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.

  • scripts/run_gpu_tests.py: 193/210 passed, 15 skipped (plain main: 192/209 passed, 15 skipped).
    • new test ps_exp_color_mask: pass
  • Python tests this PR touches: 21 passed.

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

@theswiss24

Copy link
Copy Markdown

Tested b3d34afc (contains main aa2988cc) on NVIDIA GeForce RTX 4070 (Ada), driver 621.24, Windows 11 (26300), MSVC from Visual Studio 2026 (Ninja, RelWithDebInfo), Vulkan SDK 1.4.363.1, llvm-mc 21.1.8: pass.

  • LEONIDA_W64_EMULATE=1 python -I scripts/run_gpu_tests.py --build runtime\build: 196/211 passed, 15 skipped, 0 failed. The only difference from main aa2988cc built and run the same way (195/210, same 15 skips) is the new PASS ps_exp_color_mask 4096/4096 pixels exact.
  • Corpus slice from my own copy (outcomes only): tools/rdna2spirv.py <disasm> --shard 0/64 --wave64-emulate, 415 shaders across all stages. main gives 415 translated, 414 pass spirv-val; this branch gives the same 415 / 414. All 402 .spv outputs are byte-identical between the two, so no shader in this slice changes. The one failure is the same on both, a compute shader whose text fails to assemble ("requires a previous definition"). That comes from aa2988cc's format-size table and is what Translator: constants assemble asks for late are defined too #3902 addresses, not from this PR.

AI-assisted (Claude Code).

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