dxil-spirv: read and write 2 to 4 dwords of a byte-address buffer through one untyped pointer (VKD3D_UNTYPED_VEC_SSBO, off by default) #411

Open
github-bot wants to merge 1 commit from github-bot/gh-411 into main AGit
Owner

@⁠CorvetteCole on GitHub · 2026-12-04 01:37 UTC · original
CorvetteCole:vkd3d-untyped-vec-ssbo → main · +224 −0 · 2 files · 1 commits · open

What

Adds VKD3D_UNTYPED_VEC_SSBO to patches/vkd3d.dxil-spirv.patch (the dxil-spirv submodule of vkd3d-proton). Off by default; nothing changes unless it is set.

With it set, a DXIL rawBufferLoad of 2 to 4 dwords (up to 16 bytes) from a storage buffer is emitted as one OpUntypedAccessChainKHR plus one vector OpLoad ... Aligned <elem size> (SPV_KHR_untyped_pointers), instead of one OpAccessChain + OpLoad per live component on a uint[] runtime array. Stores of 2 to 4 dwords are handled the same way (VKD3D_UNTYPED_VEC_SSBO=loads leaves stores alone).

Why: RADV compiles the per-component uint[] loads as separate dword loads when it cannot prove they are adjacent and in range (data-dependent offsets, non-uniform descriptors, robust buffer access), so a Load4 becomes up to four buffer_load_b32. A single vector load is one memory instruction. Components that are not read are not loaded; a live range with a gap (for example .x and .w of a Load4) is loaded as the whole span.

Files: patches/vkd3d.dxil-spirv.patch (the diff git diff HEAD of the dxil-spirv submodule gives, as tools/patch.sh vkd3d writes it; the existing RADV.bvh64 hunks are unchanged and the new hunks are in opcodes/dxil/dxil_buffer.cpp) and one row in docs/SETTINGS.md.

Measured

RX 7900 XTX (RDNA3 / GFX11), Linux, pinned Mesa 26.3.1 RADV, native 1440p (VICTORY_RENDER_SCALE=1.0), 45591b0, VICTORY_SHADER_OPT=63, VICTORY_WARM=0. A/B/B/A, 85 s per run, frame time is the median of the last 8 per-second samples, drops=0 on every run, separate shader and vkd3d caches per arm, same scene.

Run VKD3D_UNTYPED_VEC_SSBO Frame time
A1 unset 36.28 ms
B1 1 35.83 ms
B2 1 35.52 ms
A2 unset 36.59 ms
  • Mean 36.44 ms → 35.67 ms: −0.77 ms (−2.1%).
  • Cleanest pair (A2 → B2, adjacent in time): −1.07 ms. The other pair (A1 → B1) is −0.45 ms.
  • Four short runs, so treat the size as roughly −0.5 to −1 ms rather than a precise figure; the direction held in both pairs. B1's last-8 mean was 37.9 ms because of one hitch; its median is the number used.
  • On top of #342's hardware-RT path (VICTORY_HW_RT=1 VICTORY_HW_RT_LEAN_BUILDER=1), an ABBA with isolated caches measured 33.27 ms (unset) vs 33.43 ms (=1, +0.16 ms), confirming the gain above comes primarily from the software BVH builder and ray-walk shaders that hardware RT replaces — another reason to keep this opt-in (off by default).
  • Visual parity: same-scene captures with the flag on and off look the same (only the animated TV differs).

ISA

I checked the effect offline on a gfx1100 (navi31) target: dxil-spirv built from this patch at b540c8a2, then RADV 26.3.1 with robustBufferAccess and robustBufferAccess2 enabled, compiled through VK_KHR_pipeline_executable_properties. Probe (HLSL, SM 6.6, bindless heap, a non-uniform descriptor index and a data-dependent 4-byte-aligned offset, so nothing is provably merged):

uint4 a = src.Load4(off);        // .x and .w used
uint3 b = src.Load3(off + 64);   // .y and .z used
uint r = a.x + a.w + b.y + b.z;
unset VKD3D_UNTYPED_VEC_SSBO=1
buffer_load_* 4 × buffer_load_b32 (offsets 0, 12, 68, 72) buffer_load_b128 + buffer_load_b64 offset:68
VMEM / instructions / code size 6 / 38 / 208 B 4 / 34 / 176 B
VGPRs 12 12

A simpler probe with constant offsets and no robustness gave identical ISA both ways (RADV already merges those), so the change only matters where the merge is blocked. I have not diffed the ISA of the game's own shaders for this PR.

Applies to the pinned source

patches/vkd3d.dxil-spirv.patch applies with git apply --index to dxil-spirv b540c8a2 (the submodule commit of the vkd3d-proton 71cae091 that setup.sh pins), and the build links; this PR's diff applies to current main. I did not rebuild a full setup.sh vkd3d from scratch.

Notes

  • Changes the SPIR-V vkd3d-proton gets, so use an empty vkd3d-cache when you turn it on or off (the docs row says so).
  • Needs a driver that accepts SPV_KHR_untyped_pointers (Mesa 26.3.1 RADV does). The extension and capability are only declared in shaders that actually use an untyped load or store.
  • Not measured: stores on their own (loads vs 1), and other GPUs. I'd expect a smaller effect on cards where RADV already merges, and I have no number for RDNA2 or RDNA4.
  • 16 bytes is the cap (span * element size <= 16), so 64-bit elements go up to 2 components.
**@⁠CorvetteCole** on GitHub · 2026-12-04 01:37 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/411) `CorvetteCole:vkd3d-untyped-vec-ssbo` → `main` · +224 −0 · 2 files · 1 commits · open ## What Adds `VKD3D_UNTYPED_VEC_SSBO` to `patches/vkd3d.dxil-spirv.patch` (the dxil-spirv submodule of vkd3d-proton). Off by default; nothing changes unless it is set. With it set, a DXIL `rawBufferLoad` of 2 to 4 dwords (up to 16 bytes) from a storage buffer is emitted as one `OpUntypedAccessChainKHR` plus one vector `OpLoad ... Aligned <elem size>` (`SPV_KHR_untyped_pointers`), instead of one `OpAccessChain` + `OpLoad` per live component on a `uint[]` runtime array. Stores of 2 to 4 dwords are handled the same way (`VKD3D_UNTYPED_VEC_SSBO=loads` leaves stores alone). Why: RADV compiles the per-component `uint[]` loads as separate dword loads when it cannot prove they are adjacent and in range (data-dependent offsets, non-uniform descriptors, robust buffer access), so a `Load4` becomes up to four `buffer_load_b32`. A single vector load is one memory instruction. Components that are not read are not loaded; a live range with a gap (for example `.x` and `.w` of a `Load4`) is loaded as the whole span. Files: `patches/vkd3d.dxil-spirv.patch` (the diff `git diff HEAD` of the dxil-spirv submodule gives, as `tools/patch.sh vkd3d` writes it; the existing `RADV.bvh64` hunks are unchanged and the new hunks are in `opcodes/dxil/dxil_buffer.cpp`) and one row in `docs/SETTINGS.md`. ## Measured RX 7900 XTX (RDNA3 / GFX11), Linux, pinned Mesa 26.3.1 RADV, native 1440p (`VICTORY_RENDER_SCALE=1.0`), `45591b0`, `VICTORY_SHADER_OPT=63`, `VICTORY_WARM=0`. A/B/B/A, 85 s per run, frame time is the median of the last 8 per-second samples, `drops=0` on every run, separate shader and vkd3d caches per arm, same scene. | Run | `VKD3D_UNTYPED_VEC_SSBO` | Frame time | |---|---|---:| | A1 | unset | 36.28 ms | | B1 | `1` | 35.83 ms | | B2 | `1` | 35.52 ms | | A2 | unset | 36.59 ms | - Mean 36.44 ms → 35.67 ms: **−0.77 ms (−2.1%)**. - Cleanest pair (A2 → B2, adjacent in time): **−1.07 ms**. The other pair (A1 → B1) is −0.45 ms. - Four short runs, so treat the size as roughly −0.5 to −1 ms rather than a precise figure; the direction held in both pairs. B1's last-8 mean was 37.9 ms because of one hitch; its median is the number used. - On top of #342's hardware-RT path (`VICTORY_HW_RT=1 VICTORY_HW_RT_LEAN_BUILDER=1`), an ABBA with isolated caches measured `33.27 ms` (unset) vs `33.43 ms` (`=1`, +0.16 ms), confirming the gain above comes primarily from the software BVH builder and ray-walk shaders that hardware RT replaces — another reason to keep this opt-in (off by default). - Visual parity: same-scene captures with the flag on and off look the same (only the animated TV differs). ## ISA I checked the effect offline on a gfx1100 (navi31) target: dxil-spirv built from this patch at `b540c8a2`, then RADV 26.3.1 with `robustBufferAccess` and `robustBufferAccess2` enabled, compiled through `VK_KHR_pipeline_executable_properties`. Probe (HLSL, SM 6.6, bindless heap, a non-uniform descriptor index and a data-dependent 4-byte-aligned offset, so nothing is provably merged): ```hlsl uint4 a = src.Load4(off); // .x and .w used uint3 b = src.Load3(off + 64); // .y and .z used uint r = a.x + a.w + b.y + b.z; ``` | | unset | `VKD3D_UNTYPED_VEC_SSBO=1` | |---|---|---| | `buffer_load_*` | 4 × `buffer_load_b32` (offsets 0, 12, 68, 72) | `buffer_load_b128` + `buffer_load_b64 offset:68` | | VMEM / instructions / code size | 6 / 38 / 208 B | 4 / 34 / 176 B | | VGPRs | 12 | 12 | A simpler probe with constant offsets and no robustness gave identical ISA both ways (RADV already merges those), so the change only matters where the merge is blocked. I have not diffed the ISA of the game's own shaders for this PR. ## Applies to the pinned source `patches/vkd3d.dxil-spirv.patch` applies with `git apply --index` to dxil-spirv `b540c8a2` (the submodule commit of the vkd3d-proton `71cae091` that `setup.sh` pins), and the build links; this PR's diff applies to current `main`. I did not rebuild a full `setup.sh vkd3d` from scratch. ## Notes - Changes the SPIR-V vkd3d-proton gets, so use an empty `vkd3d-cache` when you turn it on or off (the docs row says so). - Needs a driver that accepts `SPV_KHR_untyped_pointers` (Mesa 26.3.1 RADV does). The extension and capability are only declared in shaders that actually use an untyped load or store. - Not measured: stores on their own (`loads` vs `1`), and other GPUs. I'd expect a smaller effect on cards where RADV already merges, and I have no number for RDNA2 or RDNA4. - 16 bytes is the cap (`span * element size <= 16`), so 64-bit elements go up to 2 components.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 01:38:34 +00:00
Author
Owner

@⁠Luxuride on GitHub · 2026-12-04 11:28 UTC · original

The translator change reads right and applies cleanly to dxil-spirv b540c8a (git apply --check against a pristine archive), and the store path being an else if on raw_vec_size == 1 keeps index_id in scalar units — that part needs nothing.

Two fixes:

  • patches/vkd3d.dxil-spirv.patch:38-42 parses "anything not unset/empty/0/loads" as loads and stores, so VKD3D_UNTYPED_VEC_SSBO=false, =off, =no and =Loads all enable the widest mode while docs/SETTINGS.md:141 advertises only 1 and loads. =false is exactly what someone writes to compare runs, and it silently does the opposite. Accept 0/off/false/no as off, loads as loads-only, 1/on/true/all as both, warn on anything else.
  • docs/SETTINGS.md:141 is inside the "Listed in the menu under Performance" table, but the menu is parsed from run.conf.default (crates/victory-core/src/menu.rs:604, :630) and this PR adds no row there — a VKD3D_* variable belongs in "Runtime-only settings" (:144). While there: the switch only exists after ./setup.sh vkd3d re-applies the patch and rebuilds, which the "start from an empty cache" note does not say.

One risk worth a sentence in the "Effect" cell: the widened load spans lowest-to-highest live component (patch:97-113), so a straddle across the buffer end now makes the in-range dwords of that span robust-zero too. Narrow, but it is the one behaviour change the row does not mention.

**@⁠Luxuride** on GitHub · 2026-12-04 11:28 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/411#issuecomment-7410145477) The translator change reads right and applies cleanly to dxil-spirv `b540c8a` (`git apply --check` against a pristine archive), and the store path being an `else if` on `raw_vec_size == 1` keeps `index_id` in scalar units — that part needs nothing. Two fixes: - `patches/vkd3d.dxil-spirv.patch:38-42` parses "anything not unset/empty/`0`/`loads`" as loads *and* stores, so `VKD3D_UNTYPED_VEC_SSBO=false`, `=off`, `=no` and `=Loads` all enable the widest mode while `docs/SETTINGS.md:141` advertises only `1` and `loads`. `=false` is exactly what someone writes to compare runs, and it silently does the opposite. Accept `0/off/false/no` as off, `loads` as loads-only, `1/on/true/all` as both, warn on anything else. - `docs/SETTINGS.md:141` is inside the "Listed in the menu under Performance" table, but the menu is parsed from `run.conf.default` (`crates/victory-core/src/menu.rs:604`, `:630`) and this PR adds no row there — a `VKD3D_*` variable belongs in "Runtime-only settings" (`:144`). While there: the switch only exists after `./setup.sh vkd3d` re-applies the patch and rebuilds, which the "start from an empty cache" note does not say. One risk worth a sentence in the "Effect" cell: the widened load spans lowest-to-highest live component (`patch:97-113`), so a straddle across the buffer end now makes the *in-range* dwords of that span robust-zero too. Narrow, but it is the one behaviour change the row does not mention.
This pull request has changes conflicting with the target branch.
  • docs/SETTINGS.md
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/411/head:github-bot/gh-411'
git switch 'github-bot/gh-411'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-411'
git switch 'github-bot/gh-411'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-411'
git switch 'github-bot/gh-411'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-411'
git switch 'main'
git merge --squash 'github-bot/gh-411'
git switch 'main'
git merge --ff-only 'github-bot/gh-411'
git switch 'main'
git merge 'github-bot/gh-411'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.