Skip to content

Replay: a buffer UAV clear writes its resource's range of a shared VkBuffer (buffer_offset) - #990

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
quackottu:uav-clear-buffer-offset
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
quackottu:uav-clear-buffer-offset

Conversation

@quackottu

Copy link
Copy Markdown
Contributor

prepare_buffer_uav_clear (runtime/src/vulkan_replay.h) handed vkCmdFillBuffer / vkCmdUpdateBuffer / vkCmdCopyBuffer the view's offset, which is relative to the resource, without the binding's buffer_offset. ResourceBinding documents that a buffer may be a range of a larger VkBuffer ("the GPU address arena holds many"), and copies, atomic copies (AtomicCopyBuffer) and buffer_at already add it. A buffer UAV clear of such a resource wrote from the start of the VkBuffer, over whatever lives there.

On main the device binds every buffer at buffer_offset 0, so this is latent. With #291's arena (and the PRs built on it), every default-heap buffer gets a nonzero buffer_offset, so every ClearUnorderedAccessView* on one would clear a neighbouring resource. #291 adds buffer_offset to the copy and predication paths but not to this one.

  • One line: offset += p.binding.buffer_offset, after the D3D12 alignment check (relative to the view, as D3D12 states it) and before the transfer alignment (vkCmdFillBuffer needs the absolute offset to be a multiple of 4).
  • New CPU-only replay_uav_clear_offset_test (registered next to d3d12_state_map, built when the Vulkan headers are found; no loader or GPU): a resource at 64 KiB in a shared buffer, with fake transfer functions recording every range. Raw whole-view, raw at 16, R8 from byte 1 (unaligned ends copied from the middle), RGBA32 (update + doubling copies) and a rectangle clear must all write, and copy from, only the view's bytes.

Tested (Windows 11, RTX 5070 (driver 621.24), MSVC 14.44, Vulkan SDK 1.4.363.0, LEONIDA_VK_VALIDATION=1, overlay layers off): the new test passes; with vulkan_replay.h from main all five checks fail (fill at 0 instead of 65536). Full runtime build OK.

Found by a CPU check of the header's own contract; no game files. A separate PR rather than folded into #291 so it can land on its own.

AI-assisted.

🤖 Generated with Claude Code

…Buffer

prepare_buffer_uav_clear gave vkCmdFillBuffer/UpdateBuffer/CopyBuffer the
view's offset, which is relative to the resource, without the binding's
buffer_offset. ResourceBinding documents that a buffer may be a range of a
larger VkBuffer (the GPU address arena holds many), and copies, atomic
copies and buffer_at already add it; a clear of such a resource wrote from
the start of the VkBuffer, over whatever lives there. Latent on main (the
device binds buffer_offset 0), live once buffers sit in the arena.

The offset is added after the D3D12 alignment check (relative to the view)
and before the transfer alignment, which needs the absolute offset.
replay_uav_clear_offset_test checks raw, R8, RGBA32 and rectangle clears
with fake transfer functions; no GPU.
@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

I verified 2c17fac1d893e0d0ab85fa0762ba989893bd1d37 on Windows with an RTX 5080 and Radeon Graphics. The synthetic fixture records a float UAV rectangle clear through CommandList and replay, then copies the intended buffer range into a 65 × 64 RGBA32F image and reads the pixels back. Each expected pixel contains exactly (0.25, -0.5, 1.5, -2.0).

The 256 KiB shared buffer has a resource at byte 131072. Its view starts another 32 bytes in, and the rectangle starts at element 3, so the intended byte range begins at 131152. Clearing 66560 bytes exercises the 65536-byte update and the following copy. I checked every target and guard byte as well as the image.

Per GPU Parent 067d3e8 PR 2c17fac1
Incorrect image pixels 4160 / 4160 0 / 4160
Incorrect target bytes 66560 / 66560 0 / 66560
Modified guard bytes 66560 / 195584 0 / 195584

On the parent, the complete expected color pattern appeared at byte 80 in the neighboring area. Moving the resource base to zero made both revisions pass every check. Both GPUs gave identical readbacks and zero Vulkan synchronization-validation errors on both revisions. This exercises an explicitly supplied shared-buffer binding at replay level. Integration with #291's allocator remains a separate check.

AI-assisted with Codex. All inputs were built from source.

@UlteriorMotive00

Copy link
Copy Markdown
Contributor

Tested 2c17fac (on main) on AMD RDNA2 iGPU and RTX 5070: pass.

Windows 11 Home 10.0.26300, MSVC 14.44.35207, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, Ninja RelWithDebInfo (scripts\build_runtime.ps1), LEONIDA_VK_VALIDATION=1, VK_LOADER_LAYERS_DISABLE=~implicit~. One PC, two GPUs, picked with VK_LOADER_DRIVERS_SELECT: AMD Radeon iGPU of a Ryzen 7 9800X3D (RDNA2, 1002:13C0, AMD 2026.04.17) and NVIDIA GeForce RTX 5070 (Blackwell, 617.42).

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

@kapitche

Copy link
Copy Markdown
Contributor

Tested 2c17fac on Windows 11, MSVC 14.51, with the full shader toolchain: ctest 34/34 on an RTX 4080 SUPER (32.0.16.1714), including this PR's tests. On an Intel UHD 770 (32.0.101.6129) the one failure is d3d12_vulkan_device comparing OPTIONS1 with the other GPU's host device. That fails on main too, #962 fixes it, and it isn't from this PR.

@BACONMANXDGOD

Copy link
Copy Markdown
Contributor

Tested 2c17fac: pass on both GPUs. Windows 11 26200, MSVC 19.44, Vulkan SDK 1.4.363, LEONIDA_VK_VALIDATION=1, applied to main 43d4703 (merges cleanly). GPUs: Intel Arrow Lake Xe-LPG iGPU (Windows 32.0.101.8132) and RTX 5070 Ti Laptop (617.42), selected with VK_LOADER_DRIVERS_SELECT.

  • replay_uav_clear_offset_test exits 0 on the Intel iGPU and the RTX: buffer UAV clears write their resource's range of a shared buffer.
  • Control: with 43d4703's vulkan_replay.h it fails on both GPUs, at the five checks (raw whole-view clear fills the resource's range of the buffer, raw view at 16, R8 view at 1, RGBA32 view at 32, elements 2..5 of a view at 8).

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

@ItsNotRexed
ItsNotRexed merged commit beef465 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.

6 participants