Skip to content

rdna2spirv: typed pixel render-target outputs (OSG1 uint/sint) and compressed exports decoded by producer (pknorm u16/i16) - #3544

Open
Vonsek wants to merge 9 commits into
ItsNotRexed:mainfrom
Vonsek:claude/hw4-mrt-types
Open

Vonsek wants to merge 9 commits into
ItsNotRexed:mainfrom
Vonsek:claude/hw4-mrt-types

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-MRT-TYPES, #3381 (comment)

Depends on: #3499 and #3061 (VKH_COLOR_FORMAT for the GPU tests' render targets; this branch is on top of them, only the last commit is new).

What and why

The translator declared every pixel-shader render-target output as a float vec4 and decoded every compressed (compr) export as two f16 pairs. On RDNA2 the export format follows the render target. I measured this with tools/ps_oracle.py --format on gfx1036 (#3499):

  • a compr export's 16-bit halves are f16 for an FP16_ABGR target (RGBA16F, RG16F, RGBA8, RGB10A2);
  • they reach a 16-bit UNORM, SNORM, UINT or SINT target bit for bit.

So a pixel shader writing an integer target, or a 16-bit normalized target through v_cvt_pknorm_* + compr, came out wrong (finding: #3381 (comment)).

The shader does not name its render target, so the translator now uses what it has:

  1. Output signature. An SV_Target (system value 64) that the PS OSG1 declares uint / sint is now a uvec4 / ivec4 output. An uncompressed export's dwords go to it unchanged; a compressed export's halves are zero- / sign-extended.
  2. Producer of the exported registers. On a float SV_Target, a compr export whose two registers are only ever written by v_cvt_pknorm_u16_f32 / v_cvt_pknorm_i16_f32 (plain v_mov_b32 copies are followed) is decoded as unorm16 (u / 65535) / snorm16 (max(s / 32767, -1)). A UNORM16 / SNORM16 target converts that back to the same bits; the test checks all 65,536 unorm and every snorm value v_cvt_pknorm_i16_f32 can write.
    • Registers written by any other op keep the f16 decode. This is the common FP16 case, and the same output as before.
    • Halves from v_cvt_pk_u16_u32 / v_cvt_pk_i16_i32 on a float target, and registers with producers of two kinds, are Unsupported rather than guessed.
    • An untraced register keeps the old f16 decode instead of being refused, so shaders translated today are unaffected.

Changes:

  • tools/rdna2spirv.py: output_target_types (OSG1 SV_Target component types), compr_kinds (producer analysis), the typed path and the unorm16/snorm16 decode in Gen.export, and per-output pointer types.
  • GPU fixtures ps_mrt_uint, ps_mrt_sint (RGBA32_UINT / RGBA32_SINT targets) and ps_compr_unorm16, ps_compr_snorm16 (RGBA16_UNORM / RGBA16_SNORM targets, compared texel by texel). Each word is derived in the header.
  • build.py gets TARGET_CASES (each test's OSG1 component type and color target) and its DXBC container. check.py and scripts/run_gpu_tests.py set VKH_COLOR_FORMAT for these tests and compare 8-byte texels.
  • The same shaders as semantic fixtures. tests/semantic/test_mrt_types.py has hand constants, a Python reference, the round-trip check, the uncompressed-integer, copy-following and f16-kept cases, and the refusals.
  • docs/design.md: a contract row.

Tested

  • python -I scripts/run_gpu_tests.py --filter ps_mrt and --filter ps_compr: all four PASS 4096/4096 pixels exact on NVIDIA GeForce RTX 5080 (driver 616.92) and on the AMD Radeon iGPU (gfx1036, driver 26.10.1), selected with LEONIDA_VK_DEVICE.
  • The four bodies, run as the real pixel shader through tools/ps_oracle.py on gfx1036 into 16-bit targets, give the fixtures' words: 0x8000ffff 0x40000000, 0x40008001 0xc0002000, and 0x80017fff 0xc0003c01 for the uint and sint ones.
  • Red without the change, on both GPUs: all four fail 4096/4096 (e.g. unorm16 got 0x0, 0xffff0000 for 0x8000ffff, 0x40000000).
  • Negative control: decoding every compr export as f16 again, and sign-extending with OpBitFieldUExtract, fail ps_compr_* and ps_mrt_sint on both GPUs and fail 7 semantic tests. Reverted.
  • python -m unittest discover -s tests/semantic (4,151 tests): OK. python tests/semantic/regen_fixtures.py --check: clean. python -I tests/test_shader_checks.py: OK.
  • All pixel tests, python -I scripts/run_gpu_tests.py --filter ps_: 84/92 passed and 8 skipped (device or harness skips such as ps_m15), 0 failures on both GPUs, the existing compressed-export fixtures included.

AI-assisted.

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.

vk_harness takes VKH_COLOR_FORMAT=<VkFormat>:<bytes> for its color target
and writes the target's texels as stored. ps_oracle.py --format picks it
(the driver then picks the export format, as for a game pipeline), with
an integer-output const template for integer targets. docs gets the
export behaviour measured on gfx1036: 32_GR / 32_R take the last enabled
channels, a compr export reaches 16-bit UNORM/SNORM/UINT/SINT targets bit
for bit, FP16 targets get the halves as f16 (a NaN half becomes 0xfe00).

AI-assisted.
…producer

An SV_Target the PS output signature declares uint / sint becomes a
uvec4 / ivec4 output: an uncompressed export's dwords go to it as they
are, a compressed export's 16-bit halves zero- / sign-extended. On a
float target, a compressed export whose registers come only from
v_cvt_pknorm_u16_f32 / v_cvt_pknorm_i16_f32 is decoded as unorm16 /
snorm16, so a UNORM16 / SNORM16 target stores the same bits; other
producers keep the f16 decode, integer or mixed producers are refused.

Measured with tools/ps_oracle.py --format on gfx1036: a compressed
export reaches 16-bit UNORM/SNORM/UINT/SINT targets bit for bit. GPU
tests ps_mrt_uint/sint and ps_compr_unorm16/snorm16 (targets set through
VKH_COLOR_FORMAT), semantic tests, docs/design.md row (EGEN-PS-MRT-TYPES).

AI-assisted.
docs/shader_validation.md

AI-assisted.
docs/shader_validation.md

AI-assisted.
docs/shader_validation.md
tools/rdna2spirv.py

AI-assisted.
@Vonsek
Vonsek marked this pull request as ready for review November 22, 2026 21:04

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

Tested 4f0c41fb3241870230483c02918f99e901c3a5fe. The four supplied typed-target fixtures pass on the RTX 5070. I found one additional straight-line case where the producer analysis rejects a valid shader.

Register reuse after an export. With a synthetic OSG1 declaring two float render targets, both versions of this five-instruction test assemble for gfx1013:

v_cvt_pkrtz_f16_f32 v2, 1.0, -2.0
exp mrt0 v2, v2, v2, v2 compr
v_cvt_pknorm_u16_f32 v2, 1.0, 0
exp mrt1 v2, v2, v2, v2 done compr vm
s_endpgm

The translator reports compressed export of mixed halves to a float target. Changing only the second producer and export to use v3 translates successfully and the interpreter returns MRT0 = (1, −2, 1, −2) and MRT1 = (1, 0, 1, 0). In the original, the later write cannot reach the first export, and it fully defines the value used by the second. Could you add this regression and have compr_kinds consider which writes can reach each export? The case reproduces on both PR revisions.

GPU checks. Rebuilt the Windows harness and retranslated the fixtures on this revision. Each 64 × 64 frame matched all 4,096 expected pixels with exact bits, and each complete readback matched the corresponding result at 2705d5b8. This covered R32G32B32A32_UINT, R32G32B32A32_SINT, R16G16B16A16_UNORM and R16G16B16A16_SNORM, 16,384 pixels total.

CPU checks. All nine focused semantic tests passed. A separate synthetic FP16 pack into a uint target preserved the four half-word bit patterns. I also translated one local package pixel shader with its own DXBC and FSSM on main and on this PR. Both modules passed Vulkan 1.2 validation. For its declared uint target, three controlled interpreter runs on the PR returned the expected integer half words when I changed one synthetic buffer word or scalar. The package shader was tested in the CPU interpreter.

Intel Core Ultra 7 265K, NVIDIA GeForce RTX 5070 (621.01, subgroup 32), Windows 11 Home 25H2 build 26200.9974. Integrated Intel Graphics (32.0.101.9150) was idle. LLVM 21.1.8 and SPIRV-Tools 2026.1 under WSL. The reproduction above is synthetic. Game-derived inputs stayed local. AI-assisted.

@crastinator

Copy link
Copy Markdown
Contributor

Tested 4f0c41f merged into main f847748c (clean merge) on AMD Radeon RX 6700 XT (Navi 22, gfx1031, subgroup 32..64), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5, GCC 16.2.1, llvm-mc 23.1.5: pass.

  • New tests pass natively: ps_compr_snorm16 (4096/4096 pixels exact); ps_compr_unorm16 (4096/4096 pixels exact); ps_mrt_sint (4096/4096 pixels exact); ps_mrt_uint (4096/4096 pixels exact).
  • Whole run_gpu_tests.py: 189/203 native, 189/203 with LEONIDA_W64_EMULATE=1 (the skips are the D3D12-only fixtures and ps_w64x_readlane, as on main). ctest 41/41.
  • tests/semantic/test_mrt_types.py, tests/test_ps_oracle.py: 19 passed, 2 skipped, 30 subtests passed.

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

@jeremygold02

Copy link
Copy Markdown
Contributor

One more GPU result at 4f0c41fb for the full-word case. This is separate from the earlier register-reuse review. In a package-local pixel shader, two independently varied indices are combined into a 32-bit word before the shader's half conversion. Six compute shaders use a matching four-component image layout and index separate records with the two halves of the second component.

I ran the unmodified translated pixel module with a synthetic vertex stage, test descriptor contents, and an R32G32B32A32_UINT target. A direct 32-bit control used the same input memory, scalar and target.

Before conversion Selected shader, Y Direct UINT control, Y
0x3f800007 0x00003c00 0x3f800007
0x3f800008 0x00003c00 0x3f800008
0x3f802000 0x00003c01 0x3f802000
0x40000007 0x00004000 0x40000007

All four pixels in each of eight 2×2 draws matched. On this translation the first two indices have already become indistinguishable when the target is read back. The frame's original Xbox export configuration, attachment identity and producer-to-dispatch scheduling are still open. This gives a concrete case for testing those inputs before relying on a uint signature alone. Material-pass write-up

Intel Core Ultra 7 265K, NVIDIA GeForce RTX 5070 (driver 621.01 / 32.0.16.2101, subgroup 32), Windows 11 Home 25H2 build 26200.9974. The GPU ran the producer and direct control. The six readers were checked on CPU. AI-assisted.

docs/shader_validation.md

AI-assisted.
docs/shader_validation.md
tools/ps_oracle.py

AI-assisted.
tests/test_ps_oracle.py

The RADV test's fake run_harness takes the new fmt argument.

AI-assisted.
@nschlaepfer

Copy link
Copy Markdown
Contributor

Independent Apple M3 Max verification of @Vonsek’s typed pixel-output change at c567aaeb. The synthetic unsigned and signed fixtures both failed integer pipeline creation on the parent. On this PR, each drew all 4,096 expected pixels. Changing just the declared output signature back to float caused pipeline creation to fail again on those integer attachments. A conventional float-target control passed on both revisions. SPIR-V validation alone had passed for the original modules as well.

I also tested one package visibility-buffer pixel shader selected through an unambiguous material-to-effect lookup. With controlled vertex outputs, supplied uniforms and an integer render target, all 12,288 pixels across three draws matched the independent reference. For this shader the expected unsigned values are the zero-extended bit patterns of its explicit half conversion. This exercises the selected pixel shader in isolation. The retail runtime’s selected pass, target width and original vertex producer remain separate checks.

AI-assisted verification. Only public fixture descriptions and aggregate outcomes are included.

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.

4 participants