Repository navigation
Runtime: DiscardResource, WriteBufferImmediate and atomic copies on Vulkan (D3D-26) - #417
Conversation
…ulkan (D3D-26) Three command-list IR commands, recorded through COM and replayed by vulkan_replay.h: - DiscardResource: an oldLayout = UNDEFINED barrier to the layout the tracker already has for each subresource. Buffers, rectangle discards, parts never used yet, untracked replays and one plane of a combined depth-stencil without separate layouts are no-ops. - WriteBufferImmediate: a 4-byte vkCmdUpdateBuffer at the address, resolved at execution through ResourceBinding::va / buffer_offset and ReplayFunctions::buffer_at (the same fields and lookup as ProjectLeonida#291). MARKER_OUT waits for and sees every earlier write; MARKER_IN gets an execution-only ALL_COMMANDS dependency (Vulkan cannot say "started"); DEFAULT is ordered by the application's barriers. - AtomicCopyBufferUINT/UINT64: one vkCmdCopyBuffer region after a barrier that covers every earlier write, the dependent resources' included. Recording follows the debug layer's ATOMICCOPYBUFFER_* and WRITEBUFFERIMMEDIATE_* rules. Tests: command_list_test (recording rules), vk_command_replay_test part D (GPU readback of writes in all three modes, ordered atomic copies, discards, and the lists that must be refused), and the COM path in d3d12_vulkan_device_test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ion section main's vk_command_replay_test now has a part D (sync/access pairs), so the D3D-26 test becomes part E. The device test's D3D-26 section signals fence value 7, after main's resolve-region section took 5 and 6. The docs keep both sides. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…llow the bundle rules main added ExecuteBundle (command_list.h, d3d12_com.cpp) and samplers (vulkan_backend.h); both sides are kept. DiscardResource and the atomic copies are now refused in a bundle, as D3D12 documents, and WriteBufferImmediate is allowed there (d3d12_com_test covers all four). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merged current main (4abd545) into the branch, now at 1eaca53: ctest 19/19, vk_command_replay_test A–E plus d3d12_vulkan_device/com/descriptor tests pass with LEONIDA_VK_VALIDATION=1 and no validation errors (RTX 4090, driver 621.14). Also: DiscardResource and the atomic copies are now refused in bundles, WriteBufferImmediate is allowed, per the D3D12 bundle rules. |
|
Tested 1eaca53 on an NVIDIA RTX 4090 (621.24) and an AMD Radeon iGPU (2.0.353), Windows 11 (build 26300), MSVC 14.44, Vulkan SDK 1.4.363.0, clean Ninja build of
(AI-assisted test run.) |
main added SetPredication (D3D-18) and reserved resources; both sides are kept. The predication replay test took part E, so the D3D-26 test is now part F. An atomic copy recorded under a predicate is counted with the other copies that Vulkan's conditional rendering cannot skip, and SetPredication, DiscardResource and the atomic copies are all refused in a bundle. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merged current main (c432cdc, with D3D-18 predication and reserved resources) into the branch, now at e40bd65: ctest 27/27; vk_command_replay_test A–F (D3D-26 is now part F) and d3d12_vulkan_device/com/descriptor/uint_clear tests pass with LEONIDA_VK_VALIDATION=1 and no validation errors (RTX 4090, driver 621.14). Thanks @NRXM for the AMD run on 1eaca53. |
|
Code review at |
A region with NumSubresources = UINT_MAX was recorded like a null region and skipped the FirstSubresource check. DiscardResource now has a whole flag; explicit ranges are checked in 64-bit at recording and replay. Tests at the UINT_MAX boundary in command_list_test, part F and the COM device test. Found by matheuskshn in review. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keeps both sides; the discard emit now passes the binding to image_barrier as main's version takes it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @matheuskshn, you're right: a non-null region with |
Item: D3D-26 (#313, claimed in #156)
Three command-list methods, recorded into the command-list IR and replayed on Vulkan by
vulkan_replay.h:DiscardResourceoldLayout = UNDEFINEDto the layout the tracker already has for each subresourceseparateDepthStencilLayoutsWriteBufferImmediate(GCL2)vkCmdUpdateBufferResourceBinding::va/buffer_offsetandReplayFunctions::buffer_at.MARKER_OUT:ALL_COMMANDS/MEMORY_WRITE→TRANSFERfirst.MARKER_IN: an execution-onlyALL_COMMANDS→TRANSFERdependency, because Vulkan cannot express "started" (TOP_OF_PIPEin a first scope is no stage), so it is stricter than D3D12 requires, never weaker.DEFAULT: ordered by the application's barriers, like any copyAtomicCopyBufferUINT/UINT64(GCL1)vkCmdCopyBufferregion after anALL_COMMANDS/MEMORY_WRITE→TRANSFERbarrierRecording refuses what the D3D12 debug layer flags (
WRITEBUFFERIMMEDIATE_*andATOMICCOPYBUFFER_*ind3d12sdklayers.h): a null or unaligned address, an unknown mode, offsets not aligned to the copy size, and zero dependencies. A refused call makesClosereturnE_INVALIDARG, as the other recorded calls do.How it fits #291 / #157:
mainhas noGetGPUVirtualAddressyet. This PR adds the sameResourceBinding::va/buffer_offsetfields and the samebuffer_atlookup as #291, with identical lines, so the two should merge without a real conflict. Nothing inGetGPUVirtualAddressis touched. Until a buffer gets a VA onmain, a list with an immediate write is refused at execution asunresolved_resourceand nothing is submitted. Once #291 or #157 fillsbinding.va, it works with no further change.Assumption (documented in
docs/d3d12_vulkan.md§4.2): Vulkan promises no atomicity for a transfer. The layer relies on a naturally aligned 4- or 8-byte copy being a single write on the GPU, which matters only to a reader that races the copy from another queue or the host.Tests
command_list_test(CPU, in ctest): the recording rules for all three calls.vk_command_replay_testpart E (GPU readback;main's part D is the sync/access test):WriteBufferImmediatein all three modes at console VAs, one of them inside a binding that is a range of another buffer, as arena resources are.vkCmdUpdateBuffer, a copy or dependent range past its buffer, an unknown dependent resource, and a subresource the resource doesn't have.d3d12_vulkan_device_test: both atomic copies and the discards through COM, with readback; refused misaligned and empty calls;WriteBufferImmediaterefused at execution while no buffer has a VA.Results:
ctest --test-dir runtime/build --output-on-failure: 18/18 passed (after mergingmain)vk_command_replay_test(parts A–E),d3d12_vulkan_device_test,d3d12_com_testandd3d12_descriptor_testpass withLEONIDA_VK_VALIDATION=1, with no validation errorsruntimebuild (RelWithDebInfo, Ninja) has no warnings at/W4Tested on an NVIDIA RTX 4090, driver 621.14, Windows 11 build 26200, MSVC 19.44, Vulkan SDK 1.4.363.0. No game files used.
AI-assisted (Claude Code).
🤖 Generated with Claude Code