Skip to content

Shader: translate fixed-format D16 buffer loads - #1302

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
evilclanker9000:codex/mtbuf-packed-loads
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
evilclanker9000:codex/mtbuf-packed-loads

Conversation

@evilclanker9000

@evilclanker9000 evilclanker9000 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as packed MTBUF loads.

Depends on: #1275 (merged).

What and why

A vertex shader can encode its fetch format in tbuffer_load_format_d16_{x,xy,xyz,xyzw}. All four instructions previously produced Unsupported. Route them through the existing fixed-format decoder and packed register writer. This keeps the instruction's format authoritative even when the V# declares a different format. The default when LLVM omits the modifier is 8_UNORM.

Tested

  • On c0ac5fd, 16 LLVM-assembled synthetic compute shaders produced 0 translations and 0 validated modules. On this change all 16 translated and passed spirv-val. The cases cross all four widths, RGBA8_UINT/UNORM and valid/out-of-bounds descriptor addresses, with a conflicting 32_UINT V#. All 2,048 readback words per GPU matched on an RTX 5080 (Windows 616.92) and AMD Radeon Graphics (32.0.21045.16010).
  • On native RDNA2 gfx1036, 64 raw MTBUF kernels crossed the same cases with wave32/wave64 and two seeds for the destination registers. All stored words matched the independent half-word expectations.
  • The hand-written semantic cases for the four widths plus the omitted format produced five Unsupported errors before this change. The selector regression additionally failed six fixed-format subcases on 761c532. All 25 buffer-format tests passed on 7adce0d, including ordinary MUBUF as a descriptor-controlled comparison. The full semantic suite ran 1,174 tests with one skip, and the translator suite passed 365 with two skips.
  • For an actual draw, I used the separate #291 integration candidate at 70178d3 and a source-built D3D12 guest. Its translated VS fetched four vertex colors using the instruction's 32_32_32_32_FLOAT format from a V# declaring 32_UINT. A PSO selected the source-built shader pair, three draws ran through gta6rt --run, and the guest copied a 64×64 target back after a fence. The CPU image matched all 4,096 pixels on both GPUs. On native gfx1036, fixed-format MTBUF returned X000, XY00, XYZ0 or XYZW according to the format. This held for packed and regular FLOAT loads with identity and WXYZ descriptors at both wave sizes. In the guest, changing only the instruction to 32_FLOAT now writes X000: exactly 2,544 geometric pixels changed and 1,552 clear pixels stayed identical. Rotating the V# selectors to WXYZ left both predicted images unchanged. On 761c532 the rotated descriptor disagreed with the CPU image at 2,544 pixels for either format on each GPU. On 7adce0d all four combinations matched all 4,096 pixels on each GPU. Vulkan validation reported no VUID.

Checklist

  • No game data, keys or decryption. Every shader, descriptor and vertex buffer used here was source-built.
  • The fixed-format load contract and how it was verified are documented in docs/design.md.

AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 761c532 on Linux (WSL2 Ubuntu), Python 3.12, CPU only: pass. python -m unittest discover -s tests/semantic: 1173 OK. With main's tools/rdna2spirv.py, test_buffer_load_format.py gives 5 errors. The tbuffer_load_format_d16_* forms join the existing branch, which reads the instruction's own format: (default BUF_FMT_8_UNORM), so the instruction stays authoritative over the V#. It merges cleanly with #1291. Not GPU-checked.

@Pixel-Katana

Copy link
Copy Markdown

Code review of 761c532: looks correct, no changes requested.

The change only adds the four names to the MTBUF dispatch, which already forwards to buffer_load_format(op[1:], ..., fixed_fmt=code), so the d16 forms reuse #1275's odd-component path and the fixed-format decoder unchanged. I followed up on the edge cases from my #1275 review through the repo's harness (test_buffer_load_format.load_format + spirv_mini_interp, V# declaring FMT_U32, destination seeded 0x12345678 / 0xa9bcdef0):

tbuffer_load_format_d16_* v2 v3
_xyz, 8_8_8_8_UNORM, in bounds 0x32663444 0xa9bc3044: high half kept, z = f16(0x22/255)
_xyz, 8_8_8_8_UNORM, offset 0x100 (OOB) 0x00000000 0xa9bc0000
_xyz, 8_8_8_8_UINT 0x00330044 0xa9bc0022
_x, 8_UNORM 0x12343444: high half kept
_xyzw, 8_UNORM and with the modifier omitted 0x34443444 0x34443444

The last row repeats x into y/z/w. That matches SHADER-86 (MissingComponentsRepeat: missing channels are c mod n on RDNA2), and the non-d16 tbuffer and both buffer_load_format forms give the same repeat, so the new forms follow the measured rule. The omitted modifier decodes as 8_UNORM, as the dispatch comment says.

On 761c532 (Windows, Python 3.12): tests/semantic 1173 OK, test_buffer_load_format.py 24 OK, test_translate.py + test_d16_pack.py 368 passed / 2 skipped (llvm-mc 21.1.8), compileall clean.

AI-assisted review (Claude Code).

@evilclanker9000

Copy link
Copy Markdown
Contributor Author

The Windows Runtime job on 761c532 and the same job on the base commit both failed only d3d12_predicated_copy. That target runs the newly registered predicated-copy test. I reproduced its silent exit 1 with an unavailable Vulkan ICD, then ran it successfully with an RTX 5080 and separately in WARP-only mode. Reproduction and owner notification. On the integrated shader branch, the full semantic suite ran 1,173 tests, one skipped. AI-assisted.

@evilclanker9000

Copy link
Copy Markdown
Contributor Author

Correction to my 32_FLOAT draw control in the description. The recorded GPU image was real, but its expected repeat-X result modeled the old translator, not native MTBUF. I have now run the instructions on gfx1036 in wave32 and wave64 with distinct channel selectors, plus ordinary MUBUF as a control. MTBUF ignores the descriptor selectors and returns X000 for a one-component instruction format and XY00 for two. The four-component path should likewise ignore non-identity V# selectors. I'm correcting this shared path and will rerun the draw and regressions on this PR. AI-assisted.

@tylerstraub

Copy link
Copy Markdown
Contributor

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

Independent Linux measurement at 761c532c7cfedcb371c2a229888d668f0544157e on RTX 5090, NVIDIA 595.99.02, Linux 7.0.0-43-generic, llvm-mc 21.1.8, SPIRV-Tools 2026.1.

A synthetic wave fixture read the word 11223344 with all four packed MTBUF load widths. The instruction specified RGBA8_UINT, while the V# declared format 44 or 50. Both identity-selector descriptors produced the same expected words, including the seeded high half on odd widths and the adjacent untouched register on x and xy.

Instruction width Identity selectors V# X/Y selectors swapped
x a9bc0044 a9bcbeef a9bc0033 a9bcbeef
xy 00330044 a9bcbeef 00440033 a9bcbeef
xyz 00330044 a9bc0022 00440033 a9bc0022
xyzw 00330044 00110022 00440033 00110022

This confirms the descriptor-selector problem in your correction for the packed RGBA8 path too. Changing only the selector bits still swaps the bytes on this head. The native behavior you reported predicts the identity columns for both descriptors. The three synthetic shaders passed spirv-val, and the 24 buffer-format semantic tests passed. AI-assisted.

AI-assisted verification.

Native RDNA2 ignores descriptor selectors for MTBUF and supplies zero for absent components. Preserve runtime descriptor swizzles for MUBUF and cover both paths with the same conflicting selectors.
@evilclanker9000

Copy link
Copy Markdown
Contributor Author

@tylerstraub, I pushed 7adce0d with the selector correction. Could you rerun your four-width X/Y-swap fixture on the RTX 5090? Both descriptors should now produce the four words/pairs in your identity column.

On RTX 5080 and Radeon gfx1036 I reran the source-built guest with an identity and a WXYZ descriptor. With a four-component format the rotated descriptor previously gave 2,544 incorrect pixels on each GPU. With a one-component format, both descriptors previously disagreed with native X000 at those same 2,544 pixels. All eight 64×64 images now match their CPU expectations, with zero Vulkan validation messages carrying a VUID. The 16 assembled RGBA8 packed compute fixtures also matched all 2,048 words per GPU. I corrected the draw description in the PR. AI-assisted.

@Rainmaker33

Copy link
Copy Markdown

Tested 761c532 on NVIDIA GeForce RTX 3090 (Ampere, subgroup 32..32), driver 610.88 (Vulkan 1.4.341), Windows 11 Pro 26300: pass, no change on the GPU.

The PR's diff applied cleanly to main c0ac5fd. VS 2022, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8; harness programs from a CMake build of that main.

  • tests/semantic: 1173 run, OK (1 skipped).
  • scripts/run_gpu_tests.py: 98/126 pass, 28 skipped (wave64), identical per test to main's translator.
  • valu_fuzz --family mem --seed 1 --programs 200: 200/200 that ran match native, 400/400 with --emulate. The mem generator doesn't emit tbuffer_load_format_d16_*, so this checks for regressions only, not the new path.

No game files.

@danosovsky

Copy link
Copy Markdown

Tested 761c532 on NVIDIA RTX 4070 SUPER, 621.24, Windows 11 (26300), MSVC BuildTools 2022, Vulkan SDK 1.4.363.0: pass

  • python -m unittest discover -s tests/semantic: 1173 tests OK.
  • run_gpu_tests.py: 129 shaders, 129 translated, 129 pass spirv-val; 98/126 passed, 28 skipped (wave64, 32-wide subgroups), exit 0.
  • With LEONIDA_W64_EMULATE=1: 126/126 passed, exit 0.
    No regression in the existing GPU suite. I did not re-run the PR's own LLVM-assembled MTBUF cases.

AI-assisted run.

ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
@tylerstraub

Copy link
Copy Markdown
Contributor

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

I reran the four-width X/Y-swap fixture on the corrected head at your request. All 24 checked words matched on Linux 7.0.0-43-generic with RTX 5090, NVIDIA 595.99.02, llvm-mc 21.1.8 and SPIRV-Tools 2026.1.

The format-44 identity, format-50 identity and format-44 swapped X/Y descriptors each produced the same pairs for the RGBA8_UINT instruction:

Packed load width Readback
x a9bc0044 a9bcbeef
xy 00330044 a9bcbeef
xyz 00330044 a9bc0022
xyzw 00330044 00110022

This confirms the corrected translator ignores the swapped descriptor selectors for these MTBUF instructions and preserves the seeded high halves and adjacent register where applicable. All three modules passed SPIR-V validation, and the 25 formatted-load semantic tests passed. The GPU check covered the synthetic wave32 RGBA8_UINT fixture.

AI-assisted verification.

@ItsNotRexed
ItsNotRexed merged commit 3d4bd43 into ItsNotRexed:main Nov 22, 2026
11 checks passed
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.

7 participants