Skip to content

fix(shader): preserve channels across partial color exports (SHADER-422) - #2362

Merged
ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
Vonsek:codex/partial-mrt-exports
Nov 23, 2026
Merged

ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
Vonsek:codex/partial-mrt-exports

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as SHADER-422.

What and why

A later partial color export to an MRT zeroed the channels it left off. A shader that exported red/blue and then green/alpha lost red and blue. RDNA2 accumulates pixel exports, with individual component enables for ordinary exports and RG/BA pair enables for compressed ones. Preserve disabled components from that render target. Initialize partial outputs to zero to retain the previous result for channels never written. AMD RDNA 2 ISA, sections 11.1 and 11.2.1

Tested

  • LLVM 21.1.8 assembled the hand-written gfx1030 shader. It interleaves sparse uncompressed writes to MRT0 and compressed half-pair writes to MRT1. The intended RGBA values are (1, 2, 3, 4) and (5, 6, 7, 8).
  • CPU execution of the emitted SPIR-V on main at 49475796 returned (0, 2, 0, 4) and (0, 0, 7, 8), matching 4/8 expected words. The patched shader matched all 8/8. The shader translated, assembled and passed spirv-val --target-env vulkan1.2 on both revisions (1/1 before and after).
  • All 19 semantic export/valid-mask tests passed, including an inactive-lane export, overwriting an enabled channel, and a first partial color export. Fourteen focused tests for depth and position exports also passed. CPU verification on Windows. No GPU rendering or corpus run.

AI-assisted with Codex.

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.

An EXP component mask can write different channels of the same MRT across multiple instructions. Retain disabled components from that target so a later export does not erase color that an earlier instruction wrote.
@tylerstraub

Copy link
Copy Markdown
Contributor

Tested cfdc3bab0d33d7b9f6931cf4b005e4294e505e36 on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

Independent Vulkan check of cfdc3bab0d33d7b9f6931cf4b005e4294e505e36 on NVIDIA GeForce RTX 5090 (595.99.02, Linux 7.0.0-43-generic, LLVM 21.1.8, SPIRV-Tools v2026.1). AI-assisted. Synthetic input only.

I split the PR's assembly fixture into two single-attachment draws for the stock vk_harness, preserving the order of each target's two exports. Every pixel in each 64×64 readback had the following RGBA values:

Export form Translator diff reverted PR head
Uncompressed component masks (0, 2, 0, 4) (1, 2, 3, 4)
Compressed half-pair masks (0, 0, 7, 8) (5, 6, 7, 8)

Each PR-head draw matched all 4,096 pixels, and the reverted translator cleared the previously written channels at every pixel. Both sets of modules passed SPIR-V validation. The 19 CPU tests in test_export_valid_mask.py also passed, including the original interleaved MRT case. The GPU comparison exercised the two export forms in separate draws.

AI-assisted verification.

@duudiis

duudiis commented Nov 22, 2026

Copy link
Copy Markdown

Tested cfdc3bab0d33d7b9f6931cf4b005e4294e505e36 on NVIDIA GeForce RTX 5070, driver 621.24, Windows 11 Pro build 26300: pass.

I used the original interleaved two-MRT fixture unmodified. A local vk_harness variant mapped the RGBA32F readback attachment to fragment output location 0 or 1, leaving the other slot unused, so each replay executed the same unchanged two-output SPIR-V shader. SPIRV-Tools 2026.4 assembled and validated both revisions against Vulkan 1.2.

Readback Parent 49475796 PR head
MRT0, sparse uncompressed exports (0, 2, 0, 4) (1, 2, 3, 4)
MRT1, compressed half pairs (0, 0, 7, 8) (5, 6, 7, 8)

Each value held for all 256 pixels in that draw. Synthetic inputs only. AI-assisted verification.

@whattheflop

Copy link
Copy Markdown
Contributor

Independent Windows Vulkan verification for SHADER-422. AI-assisted with Codex.

I assembled the stock synthetic partial_color_exports.asm with WSL LLVM 21.1.8 (gfx1030), then ran the exact translators at base 49475796c226c8511b9470bf97a4daf57b8af323 and head cfdc3bab0d33d7b9f6931cf4b005e4294e505e36. This exercises the original interleaved exports in one draw with two simultaneous RGBA32F attachments, complementing the author's CPU check and the RTX 5090 split-draw report. The disposable offscreen harness adapted the render-pass and readback path from vk_harness.

Windows GPU Base exact RGBA words Head exact RGBA words
NVIDIA GeForce RTX 3080, 616.64 (Vulkan 1.4.351) 4/8 per pixel, 64/128 total 8/8 per pixel, 128/128 total
Ryzen 7 9800X3D Radeon Graphics, 25.10.30.02 (Vulkan 1.4.315) 4/8 per pixel, 64/128 total 8/8 per pixel, 128/128 total

On both GPUs all 16 pixels read MRT0 (0, 2, 0, 4) and MRT1 (0, 0, 7, 8) on base, then MRT0 (1, 2, 3, 4) and MRT1 (5, 6, 7, 8) on head. The comparator encoded the expected RGBA values as IEEE-754 32-bit words and checked every word. A separate head control that removed the first export to each target matched 128/128 words on each GPU, including zero in every unwritten channel.

Both unmodified fragment outputs, the control, and the fullscreen vertex shader passed spirv-val --target-env vulkan1.2 (SPIRV-Tools 2026.4). Native x64 MSVC 19.38.33145, Vulkan SDK 1.4.363, and uv CPython 3.12.13. Runs were serial with one ICD, an empty implicit layer path, Khronos core and synchronization validation, a 5-second fence timeout, and a 20-second process timeout. The harness checked device limits and format support, used a standard graphics pipeline and coherent transfer readback, and produced zero validation warnings or errors across all six measured runs. An initial pipeline setup attempt flagged a 128-byte push-constant range before any draw. I corrected the harness to cover the full declared 144-byte block for every measured run.

@Yourrespawn

Copy link
Copy Markdown
Contributor

Tested cfdc3bab on NVIDIA GeForce RTX 4080 (Ada, subgroup 32..32), driver 617.14, Vulkan API 1.4.351, Windows 11 Pro 10.0.26200: pass.

  • The new test_export_valid_mask: 19/19 via unittest discover -s tests/semantic (Python 3.12.10)
  • Semantic suite: 2570 OK
  • run_gpu_tests.py: 139/185 passed, 46 skipped (native wave64, expected on this 32-lane GPU) — the partial-export fixtures (cs_w32_partial_scmp etc.) behave as before, no regression from the export-path change

AI-assisted (ZCode agent): builds and runs executed by a coding agent on this machine.

Keep the targeted regression and the intervening upstream changes together for review.
@TreXito

TreXito commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Tested cfda9fd4 on NVIDIA GeForce RTX 3060 Ti (subgroup 32..32), driver 580.173.02, Linux (kernel 6.18), Python 3.14: the change passes, one GPU failure comes from the old base.

  • pytest tests/semantic/test_export_valid_mask.py: 19 passed. With the base's tools/ (f847748): 3 failed, 16 passed, so the new tests catch the bug.
  • ctest: 41/41 passed.
  • scripts/run_gpu_tests.py: 152/199 passed, 46 skipped, 1 failed: ps_sdwa_f16_const, 4096/4096 mismatches, got 0xaaaa3800 0xaaaa0000 0xaaaa3e00 0xaaaa73f0, want 0xaaaa3800 0xaaaa1c00 0xaaaa3e00 0xaaaa73f0.

That's not this PR. The wrong word is y, the f16 denormal 2^-18 times 1024, flushed to 0. This branch's last main merge is f847748. main fixed f16 denormals after that, in 9d71037 (widen f16 denormal operands without UnpackHalf2x16) and a094bd2 (DenormPreserve 16, SHADER-526). The diff here doesn't touch SDWA or f16 operands. On the same GPU, ps_sdwa_f16_const passes on every PR based on aa2988c that I ran tonight (#2220, #2254, #2291, #2305, #2311, #2323). The branch merges cleanly with current main (git merge-tree), so merging main in should clear it.

Update: confirmed. cfda9fd4 merged with main d0835dd (4a6547d1, clean merge) on the same GPU: run_gpu_tests.py 164/210 passed, 46 skipped, 0 failed, with ps_sdwa_f16_const 4096/4096 pixels exact. pytest tests/semantic/test_export_valid_mask.py: 19 passed. So the only thing this branch needs is a main merge.

No game files. AI-assisted (Claude Code).

@amarovndres

Copy link
Copy Markdown

Tested cfda9fd4 on AMD Radeon RX 9060 XT (RDNA4, discrete, subgroup 32..64), AMD 26.10.1 (32.0.32015.7029, LLPC, Vulkan 1.4.359), Windows 11 Pro (build 26200): pass.

  • scripts/run_gpu_tests.py (full suite; test programs built from this head with llvm-mingw, llvm-mc 23.1.6): 185/199 passed, 14 skipped, 0 failed. main d0835dd9 on the same machine: 196/210 passed, 14 skipped. (This head's base f847748c is 1313 commits behind main, so its suite has fewer tests.)
  • tests/semantic/test_export_valid_mask.py: 19 tests, OK
  • This PR adds no GPU fixture, so the GPU run is a regression check of the translator change on RDNA4 (native wave64), not a test of the new rule itself; the new rule is covered by the semantic test above.

AI-assisted (Claude Code). Synthetic shaders only, no game files.

@ItsNotRexed
ItsNotRexed merged commit 20498a7 into ItsNotRexed:main Nov 23, 2026
3 of 10 checks passed
@tunczzz

tunczzz commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested cfda9fd4 (merge base f847748c) on an NVIDIA GeForce RTX 5070 Ti (Blackwell, subgroup 32..32), driver 616.56, Windows 11 10.0.26300. Translator and fixtures came from this head; runtime test programs were built from main aa2988cc (MSVC 19.44); spirv-as/spirv-val and llvm-mc 21 came from WSL Ubuntu. Result: pass.

  • scripts/run_gpu_tests.py: 153/199 passed, 46 skipped, 0 failed.
  • Compared with main aa2988cc (164/210), 11 tests are missing. All of them come from the old base, not this PR. Ten have no fixture at f847748c (cs_fmt_d16_xyz, cs_heap_init, cs_w32_andn2_exec, cs_w32_lds_subdword, cs_w32_lds_wide, ps_f64_round, ps_mul_legacy_denorm, ps_mul_legacy_denorm_mods, ps_vcmp_64, ps_vcmp_f32_nan). cs_fma_fused has a fixture there, but no runner row yet. This PR changes only tools/rdna2spirv.py, its semantic test and fixture, and docs/design.md. A merge of current main would bring those tests in.
  • cs_tbuffer_store PASS (128/128) shows up here but not on main, because main's runner currently drops that row (claimed on Coordinating who works on what (24) (moved to #4683) #4571).

Not run: the PR merged with current main, LEONIDA_W64_EMULATE=1, other vendors. No game files.

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.

9 participants