CreateQueryHeap makes one VkQueryPool per heap: occlusion (OCCLUSION and
BINARY_OCCLUSION queries), timestamp and copy-queue timestamp, and pipeline
statistics (all eleven Vulkan counters, whose order is the field order of
D3D12_QUERY_DATA_PIPELINE_STATISTICS). Other heap types are logged and
refused with E_NOTIMPL.
BeginQuery, EndQuery and ResolveQueryData are recorded in the command-list
IR with D3D12's rules for the calls, and replayed as vkCmdResetQueryPool +
vkCmdBeginQuery/vkCmdEndQuery, vkCmdWriteTimestamp at BOTTOM_OF_PIPE and
vkCmdCopyQueryPoolResults (64-bit, WAIT). Heap types, index ranges and the
destination buffer are checked before anything is written. A query that was
never ended resolves to zeros instead of stalling the GPU on WAIT_BIT.
GetTimestampFrequency is 1e9 / timestampPeriod. The devices enable
occlusionQueryPrecise and pipelineStatisticsQuery where the GPU has them.
Overlapping queries of one kind (valid D3D12, one active query per type in
Vulkan) are refused as unsupported, and binary occlusion is not clamped to
0/1 yet; both are written down in docs/d3d12_vulkan.md section 4.6.
Tested on an RTX 5070 (driver 621.01) under VK_LAYER_KHRONOS_validation.
AI-assisted (Claude Code).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Upload-heap buffers asked for HOST_VISIBLE | HOST_COHERENT memory only, so the GPU read every vertex, index and
constant buffer a game uploads over PCIe from system memory. They now prefer DEVICE_LOCAL | HOST_VISIBLE |
HOST_COHERENT when the device has Resizable BAR: such a type in a device-local heap larger than the 256 MiB BAR
window (leonida::resizable_bar, runtime/src/vulkan_memory.h). Without Resizable BAR that type is a window of
256 MiB or less that every upload buffer would share, so they stay in system memory there. A full VRAM heap falls
back to system memory through DeviceState::allocate's existing order.
The device logs where upload heaps live, LEONIDA_UPLOAD_SYSMEM=1 keeps them in system memory for comparison, and
vulkan_memory_flags / device_upload_in_vram report the choice to tests. d3d12_state_map_test checks the detection
on the heap layouts of an RTX 5060 Ti with Resizable BAR, an RTX 3090 without it, a 256 MiB window and an
integrated GPU; d3d12_vulkan_device_test checks that its upload buffer is placed accordingly, and its GPU copies
then read that buffer in both placements.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A volume mip has a single tracked layout, but its color attachment may cover only part of its depth. Use the view to select W slices and keep barriers on the whole mip so clears preserve neighboring slices.
Windows SDK 10.0.28000.0 omits the legacy video queue layout
enumerator. Compare against the enum when the SDK exposes it and
check the established numeric value on newer SDKs.
D3D12 lets an access be named with a sync scope whose Vulkan stages cannot perform it:
SYNC_ALL_SHADING with ACCESS_VERTEX_BUFFER is valid D3D12, but VERTEX_ATTRIBUTE_READ needs
VERTEX_ATTRIBUTE_INPUT. Vulkan rejects such barriers (docs/d3d12_vulkan.md listed it as a known gap).
vulkan_barrier_scope maps each side of a global, buffer or texture barrier and adds the narrowest
stage that supports any access left without one (the synchronization2 "supported access types"
table). The access is never dropped, so the dependency still covers everything the application
named. CLEAR only writes, and ALL_GRAPHICS holds no transfer stage, so transfer reads get ALL_TRANSFER.
vk_command_replay_test part D records all 360 D3D12 sync/access pairs as global, buffer and texture
barriers: 462 validation errors before, 0 after, on Intel(R) Graphics. d3d12_state_map_test checks
that stages only grow, accesses never change, and pairs Vulkan already accepts are left alone.
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.
The IR (command_list.h, was clear_commands.h) now records transition, UAV and
aliasing barriers (split barriers record their end half) and full-view
ClearDepthStencilView next to ClearRenderTargetView.
vulkan_replay.h (was vulkan_clear.h) maps D3D12 resource states to Vulkan
layout/access/stage (section 4.3 table), decodes subresource indices including
depth/stencil planes, validates the whole list before emitting anything, and
wraps clears in a layout round trip so images stay in their D3D12 state. The
caller no longer manages layouts by hand.
Tests: command_list_test (recording rules), d3d12_state_map_test (state table,
subresource decoding, constants checked against d3d12.h; needs Vulkan headers
only) and vk_command_replay_test (GPU readback of colour, depth and stencil;
LEONIDA_VK_VALIDATION=1 runs it under the Khronos validation layer).