Skip to content

Shader: honor BGRA views for normalized formatted buffer stores - #1341

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Vonsek:codex/mubuf-bgra-stores
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Vonsek:codex/mubuf-bgra-stores

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as BGRA formatted buffer stores.

What and why

The runtime represents B8G8R8A8_UNORM and A2R10G10B10_UNORM with the same format codes as their RGBA counterparts and the V# selectors Z,Y,X,W. Formatted stores previously placed the red value in the low memory field for either selector order. The encoder now fills absent source components with zero and exchanges the red and blue fields for the BGRA view on these two formats. This includes one-component instructions.

This change covers the two existing UNORM encodings. A separate native sample with format 54 (2_10_10_10_UINT) confirmed that BGRA swaps those fields too. The translator's format table currently omits 54. Across all 24 permutations of the four RGBA selectors on gfx1036, some stores followed neither a direct nor an inverse permutation. This patch implements only the measured BGRA case.

Tested

  • Native RDNA2 gfx1036 (Windows Radeon 32.0.21045.16010), ordinary and D16 stores with x, xy, xyz and xyzw operands, identity and BGRA, wave32 and wave64. All 64 results for these two formats matched an independently packed CPU word. Guard dwords remained intact. For example, storing (0.25, 0.5, 0.75, 1) into the 8-bit view wrote 0xffbf8040 for RGBA and 0xff4080bf for BGRA.
  • On f85582e, all 32 hand-assembled compute fixtures translated and passed spirv-val. On RTX 5080 (Windows 616.92) and Radeon gfx1036, BGRA disagreed with the hardware-verified expectation at all 1,024 output words per GPU, while RGBA matched all 1,024 per GPU. On dac5489 all 32 translated and passed spirv-val again, and both views matched all 2,048 words on each GPU. Both buffer guards survived each dispatch. No Vulkan validation VUIDs.
  • The new fragment semantic regression had eight failures and eight passes on the base. All sixteen passed with the change. The full translator suite passed 396 tests with two skips.

Checklist

  • All shader assembly, descriptors, values and expected words were source-built.
  • The measured formats and selectors are documented in the translator contract in docs/design.md.

AI-assisted.

The runtime describes two encodable packed UNORM formats in BGRA order through V# selectors. A store must place red in the third memory field even when only the red input is present.
@kapitche

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51, llvm-mc 23.1.6): pass. --filter cs_fmt passes on both the RTX 4080 SUPER and the Intel UHD 770. ctest: 65/65.

@tylerstraub

Copy link
Copy Markdown
Contributor

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

I assembled eight synthetic wave32 compute shaders covering the two supported BGRA/RGBA UNORM encodings (8:8:8:8 and 10:10:10:2), both selector orders and ordinary and D16 stores. Each shader exercised x, xy, xyz and xyzw. vk_compute_test read the four packed words and one adjacent guard dword per store.

All 32 packed words and 32 guards matched the CPU reference. The 8-bit BGRA x store wrote 00400000, and its xyzw store wrote ff4080bf. The 10-bit BGRA equivalents were 10000000 and d00802ff, for both ordinary and D16 inputs.

A temporary control translator forced identity channel order for these two encodings. All 16 BGRA words then differed from the reference, while the 16 RGBA words and 32 guards still matched. All 16 modules passed SPIR-V validation. Linux 7.0.0-43-generic, llvm-mc 21.1.8, SPIRV-Tools 2026.1. The GPU run covered wave32 for these two encodings.

AI-assisted verification.

@Rainmaker33

Copy link
Copy Markdown

Tested dac5489 on NVIDIA GeForce RTX 3090 (Ampere, subgroup 32..32), driver 610.88 (Vulkan 1.4.341), Windows 11 Pro 26300: pass, no regression.

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

  • tests/semantic: 1178 run, OK.
  • scripts/run_gpu_tests.py: 105/133 pass, 28 skipped (wave64), identical per test to main's translator.
  • No GPU fixture runs a BGRA-view formatted buffer store yet, so the new rule was only checked through the CPU tests. I didn't run tests/test_translate.py (it needs pytest, which isn't installed here).

@bvtterbroot

Copy link
Copy Markdown

Tested dac5489 on AMD Radeon RX 7900 XTX (RDNA3, Navi 31), AMD driver 26.11.2, Vulkan 1.4.359, Windows 11: no regression.

  • run_gpu_tests.py: 133/133 in two full runs. This PR adds no GPU test, so this only shows that nothing else changed.
  • In a first full run cs_user_sgprs failed once without a message. It passed in two more full runs and in four runs of it alone, on this branch and on main. It uses buffer_store_dwordx4, not the formatted stores changed here, so I take it as unrelated.
  • The pytest-based tests/test_translate.py was not run here (no pytest); CI covers it.

Tools: llvm-mc 21.1.8 (WSL), Vulkan SDK 1.4.363.0, MSVC 14.44. Base main f85582e: run_gpu_tests.py 133/133.

@ItsNotRexed
ItsNotRexed merged commit bfe7580 into ItsNotRexed:main Nov 22, 2026
11 checks passed
@Vonsek

Vonsek commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

@Rainmaker33 I added ordinary 8/8/8/8 and packed single-component 10/10/10/2 BGRA stores to the existing cs_store fixture in #1394 at 554b1d1. This PR merged dac5489 before the additional test commit arrived. You can run them without pytest:

python -I scripts/run_gpu_tests.py --filter cs_store --build <your-runtime-build>

The last two words were 0x400080ff and 0x000003ff on the base translator, so the new checker failed. On RTX 5080 and Radeon the same shader now gives 0x40ff8000 and 0x3ff00000, respectively, with all six preceding words still matching. If you rerun on Ampere, those last two words directly check the change. AI-assisted.

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.

6 participants