Skip to content

Runtime: predicate byte-granular buffer copies (BUILD-180) - #1277

Merged
ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
73N1X:feat/predicated-buffer-copy-current
Nov 22, 2026
Merged

ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
73N1X:feat/predicated-buffer-copy-current

Conversation

@73N1X

@73N1X 73N1X commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: BUILD-180 — renewed reservation, original claim.

Depends on: #856 (merged). Rebased onto main e7584c52.

What and why

vkCmdCopyBuffer ignores conditional rendering, so a CopyBufferRegion under a false predicate currently overwrites its destination. Replay predicated buffer copies as byte-granular compute dispatches using #856's captured 64-bit condition instead.

  • Support both predicate operators, unaligned byte offsets/lengths, arena offsets and zero-byte no-ops. Validate ranges, overflow and physically overlapping regions.
  • Enable optional storageBuffer8BitAccess; reject unsupported predicated copies instead of executing them unconditionally. Ordinary copies retain the transfer path.
  • Split descriptor windows and dispatches at device limits. Retain descriptor batches in command-buffer slots through timeline completion, preserving the tracker lock order and copy-then-commit behavior.
  • Preserve QueueKind and accumulate compute/copy readback producer stages before the queue's host-stage filtering.

Tested

Windows, RX 5700 XT, driver 32.0.21045.5002, RelWithDebInfo, Khronos validation and synchronization validation enabled. Synthetic inputs only.

  • Full runtime build: passed.
  • d3d12_predicated_copy_test: 180 exact Vulkan/WARP/literal-oracle comparisons plus 16 query-to-copy cases. Four paired same-address recapture controls change exactly one 13-byte region. Predicate-buffer guards and untouched destination bytes match.
  • vk_predicated_copy_test: 32 gated + 32 reused submissions, forced small descriptor/dispatch windows, dependent copies, failed-submit cleanup and direct/compute/copy host-stage controls: passed.
  • Binary and overlapping occlusion CTests: passed, including independent destinations preserved under a false predicate and copied after reset while query results remain correct.
  • vk_predicate_capture_test: 192 snapshots and tracker/queue integration controls passed. Replay A-G and all 1,663 existing typeless WARP readbacks passed.
  • Full CTest: 61 passed, 1 failed; GameInput remains disabled because SDL3 is unavailable. The sole failure is the stencil CopyResource comparison in d3d12_vulkan_device: a separate build of unmodified main e7584c52 reproduces the same six mismatch reports exactly.
  • Embedded SPIR-V matches freshly compiled GLSL; glslang 16.6.0 Vulkan 1.2 validation and git diff --check passed. Zero validation errors in the new GPU tests.

Scope and limitations

Texture copies, CopyResource, resolves and other predicated transfer operations remain outside this change. Predicated buffer copies require the enabled storage8 feature and a supported direct/compute queue; logical copy queues remain unsupported for predicate capture. Active pipeline-statistics queries are rejected to avoid counting internal compute work. Application compute bindings must be restored by future dispatch integration, as documented for #856.

The query-to-copy fixtures use real empty ordinary/binary occlusion queries; they do not claim nonzero visible-draw coverage. Executing GPU overwrite copies supply the high-word-only replacement used by snapshot/recapture controls.

Checklist

  • No game data, keys or decryption, including fixtures and quoted results.
  • Translator contract changes: not applicable; this adds a synthetic runtime helper shader, not a shader-translator rule.

Build on the full 64-bit predicate snapshots from ItsNotRexed#856. Replay predicated buffer copies through a storage8 compute helper, retain descriptor batches through timeline completion, and reject missing capabilities or active statistics queries before submitting work.

Validate byte offsets, high predicate words, bounds, skipped destinations and pending descriptor lifetimes with CPU checks, 180 native WARP comparisons and 64 gated/reused GPU submissions. The existing OPTIONS19 host-capability mismatch also reproduces on base 4a36bb1; no tests are disabled.
Verify compute and transfer readback-stage collection, descriptor cleanup after failed submits and gated/reused batches. Extend binary and overlapping occlusion fixtures with independent destinations to check skipped-copy preservation and copying after predicate reset. Document the command-slot lifetime and queue integration.

Local RX 5700 XT validation: 180 exact WARP comparisons, 64 gated/reused copy submissions, both occlusion controls, 192 predicate captures, replay A-G and 1663 existing WARP readbacks passed. CTest: 59/60 active tests passed; the six stencil CopyResource mismatch reports exactly match the tested ItsNotRexed#856 baseline. Shader source and embedded SPIR-V match after Vulkan 1.2 validation.
Resolve real empty ordinary/binary occlusion queries into default-heap predicates at two offsets and check both operators. Add GPU high-word-only overwrites, captured-value preservation, same-address recapture and reset controls. Compare all destination bytes and predicate guards with literal expectations and native WARP; four paired recapture controls change exactly one 13-byte region.

RX 5700 XT with Vulkan validation and synchronization validation: all 16 query-to-copy cases plus 180 existing cases passed, zero validation errors. Native WARP-only controls also passed. Coverage intentionally excludes nonzero visible-draw occlusion counts.
@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): pass. ctest: 62/62 on the RTX 4080 SUPER. On the Intel UHD 770, 58/62. The Intel failures are known Intel issues, not from this PR: d3d12_vulkan_device (#962), d3d12_descriptor (min-LOD), d3d12_copy_xfmt, and vk_binary_occlusion (also on main; reported separately).

@ItsNotRexed
ItsNotRexed merged commit b583c89 into ItsNotRexed:main Nov 22, 2026
12 checks passed
ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
#1277 builds d3d12_predicated_copy_test but no add_test ran it, which #1258's test_ctest_registration now catches.
It is registered like its neighbours (exit 77 is a skip); it passes on an RTX 4060 Ti.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ItsNotRexed pushed a commit that referenced this pull request Nov 22, 2026
On top of the merge candidate 70178d3 (Ryx69#6, which merged main at
426023a): the 219 commits main gained since. Three hunks conflicted, in two
files; both follow the notes on #291 (ItsNotRexed 08:27 UTC, Vonsek 09:58 UTC
on 2026-11-22).

runtime/shims/d3d12_vulkan_device.cpp, device setup after the VulkanContext:
- the branch's GPU address arena is created first, as before;
- main's block that configures predication and the predicated byte copy
  (#1277) follows it;
- one load_host_image_copy call and main's lazy D24 converter (enabled only
  where D24_UNORM_S8_UINT is not usable) replace the branch's unconditional
  enable_depth24, which was the same code before main changed it.

runtime/src/vulkan_replay.h:
- CopyBuffer: main's version. It already adds ResourceBinding::buffer_offset
  to both offsets, as the branch did, and adds the overflow and overlap
  checks and the predicated copy. With the arena, source and destination are
  often the same VkBuffer; the overlap check compares the adjusted ranges.
- Predication: main's version. prepare() passes buffer_offset + the command's
  offset to prepare_predicate, so a default-heap buffer inside the arena is
  read at its own range; emit() captures the word and tests the capture's
  scratch slot, not the application's buffer.

Everything else merged without conflicts. Nothing in main's 219 commits adds
a caller that takes a buffer's Vulkan device address for its GPU VA.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.

3 participants