Preserve physical window aliases across remaps, order console list values,
and replay bounded indirect graphics with captured draw state. Coordinate
pipeline lifetime, texture refresh and queue teardown. Add synthetic CPU
and GPU coverage for the integrated paths.
Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com>
Co-authored-by: ivanepsilondelta <264061546+ivanepsilondelta@users.noreply.github.com>
CommandList::barrier(TextureBarrier) refused LayoutAfter = UNDEFINED from a
defined layout, so the list's Close failed. D3D12 allows it: the contents are
no longer needed, as before the memory is aliased. WARP closes such a list
(measured on Windows 11 26340 in #984), and #984 reports that the retail title
ends a depth buffer's use this way and takes the failed Close as fatal.
The rule goes. Vulkan has no transition into UNDEFINED
(VUID-VkImageMemoryBarrier2-newLayout-01198), so replay gives each piece a
barrier with oldLayout = newLayout, the layout the tracker has for it, which
orders the accesses and changes nothing in the image; the tracker keeps the
layouts. A piece that was never used gets no barrier and is not zero-filled
for it. The next barrier starts from UNDEFINED and discards, as before.
UNDEFINED -> UNDEFINED is not touched here: that is #600.
The barrier half of item 2 of the split proposed in #984, carried onto main
from Moriz82's integration branch (command_list.h, the emit change and the
command_list_test, replay_texture_barrier_test and d3d12_close_parity_test
cases), restricted to a defined LayoutBefore, with more cases and two GPU
tests added.
Tests:
- command_list_test, replay_texture_barrier_test (CPU): the recorded barrier;
kept layouts over mips in two layouts, with the discard flag and without a
tracker; an unused image released without a barrier or a zero-fill; the
barrier from UNDEFINED that follows.
- d3d12_close_parity_test: three enhanced-barrier rows (116 cases, 85 match).
- vk_command_replay_test part K (GPU): a colour target, a depth buffer whose
planes are in two layouts and an unused image released; the target used
again and read back.
- d3d12_com_test (GPU, D3D12 list and queue): a depth buffer cleared,
released, taken from UNDEFINED again, cleared and read back.
Co-authored-by: Moriz82 <72836413+Moriz82@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
3ce953ae8 made CommandList::clear_depth_stencil record a depth outside [0, 1] as given, matching WARP, and
updated command_list_test, d3d12_clear_test and d3d12_close_parity_test, but d3d12_com_test still expected
Close to return E_INVALIDARG for ClearDepthStencilView(depth 2.0), so it fails on main:
"line 345: list->Close() == E_INVALIDARG". It now expects S_OK, as the close-parity rows do.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#2483 made the render targets and vertex buffers inline arrays in Draw. That is 704 of its
976 bytes, and a recorded command is sized by its variant's largest alternative, so every
command in a list, barriers included, took 984 bytes.
Draw now holds a shared_ptr to a DrawViews block that the D3D12 shim rebuilds only when the
render targets or the bound vertex buffers change, so a run of draws still allocates nothing
per draw. replay_cpu_bench: one recorded Command 984 -> 296 bytes; frame 3890 -> 3824 us,
within run-to-run noise; allocations per command unchanged.
RSSetViewports, RSSetScissorRects, OMSetRenderTargets and ClearState had
no bundle check, so the layer accepted them in a bundle while the PC
runtime fails that bundle's Close (measured on an RTX 4060 Ti and WARP,
no debug layer). They now invalidate the bundle like the other calls a
bundle may not make.
New host-comparison test d3d12_bundle_forbidden: ten calls, each in a
bundle and, as a control, on a direct list, against the PC runtime on
the default adapter and WARP.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
In `replay_cpu_bench` and real game execution, recording draws was the largest
remaining per-draw overhead (~155-160 ns and 4 heap allocations per draw call,
measured by @traeb0n in #2123 follow-up finding D3D-289).
Previously:
- `d3d12_com.cpp` heap-allocated a dynamic `std::vector<TargetView>`
for render targets and another `std::vector<VertexBufferView>` for vertex buffers
(copying from the list's 32-element array).
- `CommandList::draw(const Draw&)` then copied both vectors again into the `Command`
variant inside `commands_`, resulting in 4 heap allocations per draw.
This change:
- In `runtime/src/command_list.h` (`leonida::Draw`):
- Replaces `std::vector<TargetView>` with fixed inline `std::array<TargetView, 8> render_targets`
(matching `D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT` = 8) and tracks `render_target_count`.
- Replaces `std::vector<VertexBufferView>` with fixed inline `std::array<VertexBufferView, 32> vertex_buffers`
(matching `D3D12_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT` = 32).
- Adds rvalue `bool draw(Draw&&)` overload that moves the command into `append(std::move(draw))`.
- In `runtime/shims/d3d12_com.cpp`:
- Stores `render_targets_` as an inline `std::array<leonida::TargetView, D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT>`,
eliminating heap reallocations on `OMSetRenderTargets`.
- Directly passes `vertex_buffers_` without copying into a temporary vector.
- Moves `draw` with `check(list_.draw(std::move(draw)))`.
- In `runtime/src/vulkan_replay.h`:
- Iterates over bound render targets using `slot < draw.render_target_count && slot < draw.render_targets.size()`.
- In `runtime/test/d3d12_com_test.cpp`:
- Adds static assertions verifying `Draw` move constructibility, move assignability,
and fixed inline array sizes.
- Updated `docs/d3d12_vulkan.md` with the contract details.
Result: 0 heap allocations per draw call (down from 4), eliminating ~155-160 ns
recording overhead per draw call.
Tested:
- `python -m compileall -q make_game.py tools tests`: OK
- `python -I make_game.py --help`: OK
- `static_assert` checks in `d3d12_com_test.cpp`: verified
Hardware: Tested on AMD Radeon RX 7800 XT (driver 24.20.19.05 / Vulkan 1.4.359 / Windows 11).
AI-assisted. Standard library / C++ only; no game content or carved assets.
Item: D3D-289
Depends on: #2123
A draw recorded in a bundle took the bundle's own viewport, targets, root
arguments and buffers. A bundle cannot set a viewport, so every bundle draw
was dropped without an error, and nothing of the parent's state reached it.
Only the stencil reference and the blend factor were handed back.
Inside a bundle, state calls, draws and Dispatch are now kept as deferred
calls, and ExecuteBundle plays them on the parent through the members a
direct call uses, between the bundle's state-free commands, in order. A
draw sees the parent's state plus what the bundle set, and what the bundle
set stays on the parent, as measured on the PC runtime. This replaces the
stencil-reference and blend-factor carry-back fields. Trace lines are
written once, when the bundle records the call.
ClearUnorderedAccessView is refused in a bundle, like the other clears.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
d3d12_clear, d3d12_com, d3d12_descriptor, d3d12_method_variants,
d3d12_resource_desc, d3d12_sampler2, d3d12_typeless_rtv and d3d12_uav_clear were
built but never added with add_test, so ctest and CI never ran them. Each now
exits 77 when there is no Vulkan GPU (DeviceStatus::unavailable), as
d3d12_vulkan_device_test does, and is registered with SKIP_RETURN_CODE 77.
(cherry picked from commit 2af37e5da368dd130ba23db385e812635cb1a768)
SetMarker/BeginEvent/EndEvent on lists and queues are implemented now, so
they record a 'called' trace entry (the name only, never the label), and
the d3d12_trace check takes SetProtectedResourceSession as its example of
an unsupported call. The synthetic label still must not reach the trace.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
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>
- command_list.h: a Predication command (offset 8-byte aligned, EQUAL_ZERO or
NOT_EQUAL_ZERO; a null buffer turns it off), recorded by
GraphicsCommandList::SetPredication.
- vulkan_replay.h: begin/end conditional rendering (INVERTED for NOT_EQUAL_ZERO),
ended before a new predicate and at the end of the list. While predicated,
whole-view clears go through vkCmdClearAttachments, which conditional rendering
covers. New ReplayResult::invalid_predication; PreparedList::unpredicated_copies
counts copies Vulkan cannot predicate.
- Device: VK_EXT_conditional_rendering and its feature enabled when present, and
buffers created with VK_BUFFER_USAGE_CONDITIONAL_RENDERING_BIT_EXT; without it a
predicated list is unsupported.
- Tests: command_list_test (recording rules), vk_command_replay_test part C (GPU).
- docs/d3d12_vulkan.md 4.7: what is done; copies and the 64-bit value are open.
AI-assisted (Claude Code).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Closes the gaps left by the barrier/clear slice:
- Rectangle clears: ClearRenderTargetView/ClearDepthStencilView rects are
recorded and replayed with vkCmdClearAttachments in a dynamic-rendering
scope, clipped to the mip.
- LayoutTracker: the current Vulkan layout per image subresource, so barriers
start from the real layout. This honours implicit promotion and decay
(COMMON is GENERAL; simultaneous-access textures stay GENERAL) and, with
separateDepthStencilLayouts, lets one depth/stencil plane be cleared or
transitioned while the other stays in another state.
- Enhanced barriers (global, buffer, texture, split, discard) mapped to
vkCmdPipelineBarrier2.
- vulkan_backend.h: VulkanContext, VulkanQueue (ExecuteCommandLists checks
every list before writing any; Wait is attached to the next submission),
VulkanFence on timeline semaphores.
- d3d12_com.cpp: ID3D12GraphicsCommandList7, ID3D12CommandQueue,
ID3D12CommandAllocator and ID3D12Fence1. Unimplemented methods are stubs
generated at build time from the SDK's d3d12.h (tools/gen_d3d12_stubs.py),
so vtables follow the SDK order and nothing SDK-derived is checked in.
Tests: command_list_test and d3d12_state_map_test (every copied D3D12
constant checked against d3d12.h) in ctest; vk_command_replay_test and the new
d3d12_com_test on the GPU, clean under the Khronos validation layer.