Commit Graph

48 Commits

Author SHA1 Message Date
ae2a4a1705 Merge pull request #987 from gabrielsteglich 2026-11-22 10:38:46 -05:00
729bee7bb2 Merge pull request #901 from traeb0n 2026-11-22 10:38:45 -05:00
b17531d021 Support sparse tile mappings for reserved D3D12 buffers
Depends on D3D-16 (PR #286).
2026-11-22 12:24:19 -03:00
9d47be3dec Runtime: no heap allocation per barrier, clear or copy in replay
Three allocations replay_cpu_bench (#878) found on the hot path:

- detail::current returned a std::vector<LayoutPiece> for every
  transition, clear and copy in emit, though the answer is nearly always
  one piece (two with separate depth/stencil). LayoutPieces keeps two
  inline and spills to the heap beyond that, with the same interface
  (begin/end, size, push_back, clear), so `auto pieces = current(...)`
  callers compile as is. LayoutTracker::pieces takes either container.
- detail::clip built a new vector with push_back (two allocations for two
  rectangles); it now writes into the kept entry's p.rects.
- CommandList::append took const Command& and copied the temporary the
  recording calls build, so a rectangle clear's vector was allocated
  twice; an rvalue overload moves it.

replay_cpu_bench, i7-14700K, on top of #893: the frame goes from 194 to
173 ns per command, emit from 48 to 33 ns; emit makes no allocation per
command in the frame (0.43 before) and prepare 0.07 (0.26), and
recording makes one only for a rectangle clear's own rectangles.
d3d12_state_map_test checks LayoutPieces against the vector path,
including the spill at four pieces.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 09:19:29 -06:00
b566a8652f Merge pull request #1844 from romainveurrier 2026-11-22 09:48:41 -05:00
9fd1aaed66 XDXR: CopyRaytracingAccelerationStructure (clone, compact) and postbuild sizes
CopyRaytracingAccelerationStructure and EmitRaytracingAccelerationStructure-
PostbuildInfo were not implemented, and the postbuild descs of
BuildRaytracingAccelerationStructure were ignored.

- CLONE and COMPACT copy the structure's bytes (MODE_COPY_AS). XDXR records
  are position-independent: node pointers count from the structure's start
  and a TLAS names its BLASes by address. The size comes from the source
  header, so a copy can follow a build in the same list; the destination
  resource bounds it.
- COMPACTED_SIZE and CURRENT_SIZE (MODE_POSTBUILD) are totalSizeIn64BNodes *
  64: a build is already exactly its layout's size. Written for
  EmitRaytracingAccelerationStructurePostbuildInfo and for each postbuild
  desc of a build, after it.
- New IR commands CopyAccelerationStructure and AccelerationStructurePostbuild.
  Serialization, deserialization and tools visualization are refused at
  replay. With LEONIDA_RT_AS=khr the postbuild descs stay ignored, as before.
- vk_xdxr_build_test: a clone of blas_random, its COMPACTED_SIZE (== layout
  size), a compaction into exactly that size with a guard word after it, and
  a clone of the refitted TLAS.
- d3d12_xdxr_rt_test: EmitRaytracingAccelerationStructurePostbuildInfo for
  both structures and a TLAS rebuild with a CURRENT_SIZE desc (all equal to
  the prebuild sizes), then COMPACT into a buffer of that size, checked as
  d3d12_blas_compacted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 15:29:57 +01:00
967564a20c M4 (synthetic): d3d12_m4_compute_test, UAV table, indirect dispatch, copy queues; buffer UAV views and indirect dispatch state
d3d12_m4_compute_test, through the proxy with D3D12 API only and two
translator-output compute shaders (cs_m4_fill.asm, cs_m4_indirect.asm):
a COPY queue streams an input buffer in, a COMPUTE queue waits on it and runs a
compute PSO over a UAV table (structured buffer, raw buffers, an R32_UINT
RWTexture2D), then ExecuteIndirect of a second PSO from arguments the first
wrote (with a transition to INDIRECT_ARGUMENT and UAV barriers), and a COPY
queue behind a cross-queue fence reads the results back. 1,924 words match the
CPU reference with error 0.

Layer gaps the test found, fixed:
- CreateUnorderedAccessView of a buffer was a stub: structured and raw views are
  now a V# in the slot.
- ExecuteIndirect of a dispatch ran whatever pipeline and root arguments the
  command buffer had bound; the command now carries the list's, as Dispatch does.
- An image created in UNORDERED_ACCESS and first used by a shader was
  zero-filled by the first barrier or copy that named it, losing the shader's
  writes; images with a UAV view are now moved to GENERAL (zeroed) at the next
  submission.
- COMPUTE and COPY command lists no longer log "unimplemented".

Test infrastructure: vk_test_device.h can create more than one VkQueue;
build.py gives a compute shader's FSSM program extra words (fssm-at/fssm-data
from 0x148) so two compute shaders with the same group size get distinct hashes,
and honours LEONIDA_SPIRV_TOOLS (as #1679) so the target builds under the Visual
Studio generator. docs/d3d12_vulkan.md section 6: M4 synthetic part met; M3 row
credits @whattheflop's #1584 measurement of fences in flight.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 15:09:58 +01:00
1b1d090e3c Merge pull request #1667 from romainveurrier 2026-11-22 08:08:38 -05:00
1c58d6cfbc D3D12: BuildRaytracingAccelerationStructure writes XDXR BVH4 records
The game's translated RT shaders read the console's XDXR records, which a
VkAccelerationStructureKHR is not (docs/d3d12_vulkan.md 4.8). The standalone
Vulkan device now builds them with src/xdxr_build.h, unless LEONIDA_RT_AS=khr
keeps #743's KHR builds (the proposal in the maintainer decisions of #1548).

- VulkanDeviceInfo::xdxr_acceleration_structures; the standalone device sets
  it with bufferDeviceAddress and then leaves the KHR extensions off, so
  acceleration-structure buffers keep their console VAs.
- VulkanContext owns an XdxrBuilder; replay checks the inputs while the list
  is prepared (R32G32B32/R32G32 vertices, none/R16/R32 indices, addresses,
  counts) and records the build with heap_base added to every VA and as the
  bias for instance BLAS addresses.
- GetRaytracingAccelerationStructurePrebuildInfo answers from XdxrLayout,
  exactly; an update rebuilds, so it needs the same scratch.
- The geometry's vertex format is mapped per DXGI format (an unknown one is
  refused instead of read as R32G32B32), and its D3D12 flags reach the build.
- test/d3d12_xdxr_rt_test.cpp: a two-geometry BLAS (a soup; an R16-indexed
  grid with stride 16 and a transform) and a TLAS of three instances through
  the D3D12 API; ctest d3d12_xdxr_rt + d3d12_xdxr_rt_check.
- tools/xdxr_bvh.py: check-build compares TLAS hits by (geometry, primitive),
  and skips (77) when the build step wrote no cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 14:04:34 +01:00
af665729d2 Merge pull request #1553 from quackottu 2026-11-22 07:38:09 -05:00
217249c8a3 Runtime: ExecuteIndirect with MaxCommandCount 0 is a no-op, not a failed list 2026-11-22 17:34:40 +05:30
db83d7a707 Merge pull request #1424 from Ryderadzeee 2026-11-22 06:38:00 -05:00
09b08df5d1 Support SINT and SNORM RTVs for typeless RGBA8 textures 2026-11-22 15:17:12 +04:00
d7e1857c5d Merge origin/main into d3d90-castable-placed (resolve #1083 conflicts)
Both sides extended the same spots: the PR's castable-format flag and main's
R9G9B9E5-as-R32_UINT view emulation meet in bind_image (two extra defaulted
parameters), image_descriptor's view format (resource_format + castable list),
create_texture (TextureCreateInfo carries the VkImageFormatListCreateInfo the
castable list fills) and the device init (arena creation plus main's predication
configuration). Main's hardened CopyBuffer preparation and predicate capture
keep the PR's arena-buffer offsets; the PR's old emit-side offset math is
superseded by main's prepare-side buffer_offset handling.
2026-11-22 03:00:14 -08:00
9360ec9ec0 Runtime: predicate byte-granular CopyBufferRegion on the GPU
Build on the full 64-bit predicate snapshots from #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.
2026-11-22 05:28:28 -04:00
759087b51b Merge origin/main into d3d90-castable-placed (resolve #1083 conflicts)
- register_samplers (main) and create_window_presenter (stack) both kept.
- Resource dtor: stack arena release + main deferred destroys.
- AS binding: main size/host_readable + stack console va.
- VulkanContext: main's lock split kept; stack arena/pipeline accessors
  moved to resource_mutex_ (execute copies replay_ under its shared lock),
  presenter lookups take it shared.
- README takes main wholesale; D3D-90 code and tests untouched.
2026-11-22 00:51:55 -08:00
73dd6d7dce Runtime: depth and stencil resolves in ResolveSubresourceRegion
MIN and MAX of either plane, and AVERAGE of the depth plane when Format is
the plane's own format, as the PC runtime accepts them (RTX 5070 and WARP).
Each resolve is a vkCmdBeginRendering scope with no draws: the MSAA plane
is the depth or stencil attachment and the destination plane its resolve
target, checked at record time against D3D12's rules and the device's
supported resolve modes. Colour resolves are unchanged.
2026-11-22 13:14:43 +05:30
2933767eac Merge origin/main into d3d90-castable-placed (resolve #1083 conflicts)
Keep-both resolutions per #313's conflict analysis: main's ExecuteIndirect /
acceleration-structure / debug-marker / depth24 / node-mask features alongside
the stack's arena, compute and draw paths. Main's indirect and AS offsets gain
the arena's buffer_offset / heap_base compensation; AS resources on default
heaps get their GENERIC structure over the arena range. Reset clears
stencil_ref_set_ next to reset_state, and OMSetStencilRef sets it. README takes
main's (the crypto-token lines stay deleted).
2026-11-21 23:23:18 -08:00
998924fea8 feat(d3d12): add ExecuteIndirect CountBuffer and optional BLAS/TLAS/RayQueryKHR support 2026-11-22 03:04:35 -03:00
69fe9d3752 Merge remote-tracking branch 'origin/main' into claude/d3d-24-debug-markers-457bab
# Conflicts:
#	runtime/CMakeLists.txt
#	runtime/shims/d3d12_com.cpp
#	runtime/shims/d3d12_com.h
2026-11-22 05:01:46 +00:00
4fc1301a11 Merge remote-tracking branch 'origin/main' into claude/d3d-24-debug-markers-457bab
# Conflicts:
#	runtime/shims/d3d12_com.h
#	runtime/shims/d3d12_vulkan_device.cpp
#	runtime/src/command_list.h
#	runtime/src/vulkan_replay.h
#	runtime/test/vk_test_device.h
2026-11-22 04:05:35 +00:00
Ryx
1e7f5152ae Runtime: graphics pipelines and draws on Vulkan (milestone M1, D3D-4)
- CreateGraphicsPipelineState (PC slot 10): VS and PS found by the SHA-256
  of their FSSM programs in the translator's index. Input-layout elements are
  matched to the VS input signature by semantic name and index; location =
  the element's register (the translator's vertex-fetch rule); a layout that
  leaves an input unfed is refused, as D3D12 does. Rasterizer, blend and
  depth-stencil state map one to one; viewport, scissor, topology, vertex
  strides, stencil references and blend factor are dynamic; dynamic
  rendering takes the RTV/DSV formats. Hull/domain/geometry, stream output,
  MSAA, set-0 bindings and two code-base stages (question 14) are refused
  with a log.
- Command list: IASetPrimitiveTopology / VertexBuffers / IndexBuffer,
  RSSetViewports / ScissorRects (first of each), OMSetRenderTargets (views
  read at the call, single-range handles too), OMSetBlendFactor,
  OMSetStencilRef and CommandList8's front/back references (now applied),
  DrawInstanced / DrawIndexedInstanced recording a copy of that state.
  CreateCommandList's initial pipeline state is applied. Reset and
  ClearState share one state reset.
- Replay: vertex/index views resolve to buffers by VA (arena or upload),
  attachments move to attachment layouts through the tracker (first use
  zero-fills), the draw runs in a dynamic-rendering scope with a flipped
  viewport (translated VS write D3D clip coordinates), stencil references
  per face, then vkCmdDraw / vkCmdDrawIndexed. Render-target views take the
  pipeline's formats (the view cache keys on format).
- shader_library.h reads the index's input_signature and PS outputs.

Test: d3d12_draw_test (through the proxy) builds a VS+PS PSO whose input
layout order differs from the VS registers, uploads a vertex buffer into the
arena, reads indices from an upload heap, and draws two indexed quads with
different root constants and root CBVs plus a back-facing triangle: all 4096
read-back pixels match (which also checks the viewport flip and winding).
Shaders are GLSL written to the translator's contract. d3d12_com_test now
uses SetMarker as its unimplemented-method example, since DrawInstanced is
implemented. 13/13 ctest; all six GPU tests clean under the Khronos
validation layer.
2026-11-22 05:01:36 +01:00
Ryx
998368adbf Runtime: compute groundwork (FSSM shader lookup, Dispatch in the IR)
First pieces of D3D-3 (compute path), no pipelines wired up yet:
- shader_library.h: FSSM extraction from the DXBC container (DXIL, XDAT
  0x0D, XBCH, zlib), SHA-256, a minimal JSON reader and the
  spirv/index.json lookup by fssm_sha256. Self-contained inflate, no
  dependencies.
- IR Dispatch with user data captured at record time; replay binds the
  pipeline, pushes the 144-byte block (s0..s31, heap base, code base) and
  dispatches. Arena buffers get a buffer_offset that copies honour.
- Root signatures use main's model (runtime/src/root_signature.h); the docs
  say so.

Tests: shader_library_test (FIPS 180-4 vectors; stored, fixed and dynamic
deflate blocks; corrupt and truncated streams; FSSM from a synthetic
container) joins ctest; command_list_test covers dispatch recording.
2026-11-22 04:58:00 +01:00
d868cba00f Runtime: barriers into PREDICATION cover conditional rendering's read
D3D12_RESOURCE_STATE_PREDICATION is the same bit as INDIRECT_ARGUMENT
(and SYNC/ACCESS_PREDICATION the same as EXECUTE_INDIRECT /
INDIRECT_ARGUMENT), and the layer mapped that bit only to
INDIRECT_COMMAND_READ at DRAW_INDIRECT. vkCmdBeginConditionalRenderingEXT
reads the predicate with CONDITIONAL_RENDERING_READ at the
CONDITIONAL_RENDERING stage, so ResolveQueryData -> COPY_DEST to
PREDICATION barrier -> SetPredication had no dependency from the copy's
write to the predicate read (and none the other way before the next
resolve).

With the extension enabled (the only case those flags are valid),
vulkan_access and vulkan_barrier_scope now add the conditional-rendering
access and stage for that bit; GENERIC_READ, which contains it, gets
them too. The replay passes the flag from its conditional-rendering
entry points.

d3d12_vulkan_device_test now enables conditional rendering on its device
and runs an occlusion query resolved into a predicate: EQUAL_ZERO skips a
clear, NOT_EQUAL_ZERO runs one, and the predicate is resolved into again
after the read, once through legacy barriers and once through enhanced
buffer barriers. d3d12_state_map_test checks both mappings with and
without the extension.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 21:55:19 -06:00
7079108182 Runtime: query heaps on Vulkan (D3D-15)
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>
2026-11-21 21:30:47 -06:00
96404ac97a Merge main into D3D-26: unordered-access clears on main
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>
2026-11-22 02:58:23 +00:00
deae7cc736 Merge remote-tracking branch 'origin/main' into claude/d3d-24-debug-markers-457bab
# Conflicts:
#	runtime/shims/d3d12_com.cpp
#	runtime/src/command_list.h
2026-11-22 02:56:52 +00:00
c7e450fc69 D3D-26: keep a null discard region apart from an explicit UINT_MAX count
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>
2026-11-22 02:55:44 +00:00
e40bd6563e Merge main into D3D-26: predication and reserved resources on main
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>
2026-11-22 01:29:19 +00:00
f230b0dac2 Merge main (c432cdc) into d3d-25-uav-clears
Conflicts, both sides kept: predication (D3D-18) next to the UAV clear in
command_list.h, vulkan_backend.h and vulkan_replay.h; the D3D-28 tests next to
the UAV clear test; texture_create_info's attachment argument with main's
mutable host-transfer usage.

UAV clears under a predicate: a whole-view texture clear takes the attachment
path, as render-target clears do, so conditional rendering applies; buffer
clears and non-attachment texture clears are transfers and are counted in
unpredicated_copies with the copies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 01:28:38 +00:00
6d40ad39cc Merge remote-tracking branch 'origin/main' into claude/d3d-24-debug-markers-457bab
# Conflicts:
#	runtime/CMakeLists.txt
#	runtime/shims/d3d12_com.h
#	runtime/src/command_list.h
#	runtime/src/vulkan_replay.h
#	runtime/test/vk_test_device.h
2026-11-22 01:26:57 +00:00
58019e85ec Merge main and preserve predicated typeless clear handling 2026-11-21 20:26:41 -04:00
1eaca53672 Merge main into D3D-26: bundles and samplers on main; D3D-26 calls follow 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>
2026-11-22 00:13:23 +00:00
707b194707 Merge main (4abd545) into d3d-25-uav-clears
Conflicts, both sides kept: command_list.h (clear_unordered_access next to
ExecuteBundle's execute_bundle), vulkan_backend.h (fill/update buffer next to
the sampler functions), CMakeLists.txt (the UAV clear test next to the new
descriptor test) and the known-gaps paragraph in docs/d3d12_vulkan.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 00:11:50 +00:00
d7a08ad45c Runtime: debug markers on VK_EXT_debug_utils and private data on every object (D3D-24)
SetMarker/BeginEvent/EndEvent on command lists are recorded in the IR
(DebugMarker) and replayed as vkCmd*DebugUtilsLabelEXT; on queues they
call vkQueue*DebugUtilsLabelEXT under the submit lock. Labels are used
only when the instance enabled VK_EXT_debug_utils
(VulkanDeviceInfo::debug_utils; the standalone device enables it when
the loader lists it); otherwise the calls are no-ops. Events may span
the lists of one ExecuteCommandLists; an unmatched end is dropped and
labels left open are ended before the command buffer ends, so Vulkan's
begin/end rule always holds. Metadata 0/1 strings become UTF-8 labels;
a PIX3 blob (2) gets a fixed label (open question 21).

SetPrivateDataInterface holds a reference until replaced, removed or
the object dies, and GetPrivateData hands it back AddRef'd. SetName
stores WKPDID_D3DDebugObjectNameW. Both live in the shared Object base,
so every object of the Vulkan device has them.

d3d12_debug_markers_test checks the exact label calls through a
recording vkGetInstanceProcAddr, the no-extension path, and private
data on the device, queue, allocator, list, heap, resource and fence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 00:10:17 +00:00
be91840c07 Runtime: SetPredication on VK_EXT_conditional_rendering (D3D-18)
- 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>
2026-11-22 10:59:11 +11:00
500255da2a Merge main and retain typed view cache with bindless preparation 2026-11-21 19:55:10 -04:00
399b8ff839 Merge main into D3D-26: the replay test's new part D, the resolve-region 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>
2026-11-21 23:49:29 +00:00
6ae02af006 Merge main into d3d-25-uav-clears
Conflicts: main moved texture create info into texture_create_info (the UAV
attachment usage now goes there, so placed-resource sizing agrees) and edited
the same docs paragraphs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 23:33:19 +00:00
fe12da7edd D3D-35: implement ExecuteBundle IR inlining and validation 2026-11-22 00:32:28 +01:00
467b1d1ff9 runtime: ClearUnorderedAccessViewUint/Float on the Vulkan device (D3D-25)
The CPU handle's slot is read while recording as the GFX10 T#/V# a shader
would load (docs section 3.4), so the clear works with whichever view
creation lands (#157, #328, #334) and with game-built descriptors.

- Buffers: vkCmdFillBuffer for elements up to 4 bytes, with the unaligned
  ends copied from the filled middle; 8/16-byte elements are written with
  vkCmdUpdateBuffer and doubled with copies. Rects are element ranges.
- Textures: vkCmdClearColorImage for whole views, vkCmdClearAttachments
  for rects (UAV textures also get COLOR_ATTACHMENT usage when the format
  supports it), in place in GENERAL; mip and layer range from the T#.
- Values follow D3D's Uint (raw low bits) and Float (converting) rules,
  encoded in the view's format and cleared into the image as the value
  that decodes those bytes in the image's own format (typeless resources).
- d3d12_uav_clear_test: hand-computed conversion checks, then raw,
  structured and typed buffers and 2D, array and volume textures cleared
  and read back through D3D12; refusals at record and replay.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 23:29:32 +00:00
fbffbce383 Runtime: preserve explicit RGBA8 typeless RTV formats for clears 2026-11-21 19:26:08 -04:00
19742b531a Runtime: DiscardResource, WriteBufferImmediate and atomic copies on Vulkan (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 #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>
2026-11-21 23:16:54 +00:00
489258fda5 Resolve colour MSAA regions into destination offsets 2026-11-22 00:05:17 +01:00
d27e4c5765 Runtime: ResolveSubresource and multisampled textures on Vulkan
There was no resolve, and a multisampled committed texture was refused.

- IR: ResolveSubresource (two different resources).
- Replay: ResolveSubresource is vkCmdResolveImage in the layouts copies
  use: a multisampled colour subresource into a single-sampled 2D one of
  the same size and format. Depth-stencil resolves and resolves between
  two formats of a typeless family stay unsupported. ResourceBinding gains
  samples: a multisampled texture copies only to its own sample count and
  has no footprint.
- Device: committed multisampled 2D textures (single-mip render targets or
  depth-stencils, when the GPU has the sample count for the format; the
  other shapes are E_INVALIDARG as in D3D12), and TEXTURE2DMS
  render-target and depth-stencil views.
- COM: ID3D12GraphicsCommandList::ResolveSubresource.

Tests: command_list_test (recording rules, and a copy with a z range);
vk_command_replay_test part C (a 4x resolve and the refused resolves and
multisampled copies; it also runs the volume copies that are already on
main at the Vulkan level, on Linux too: a 4x4x4 volume uploaded, copied as
a block and whole, read back, and the z ranges that must be refused);
d3d12_vulkan_device_test (a resolve through the Xbox-ABI proxy and the
refused shapes).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 16:34:22 -05:00
Ryx
99336386d1 Runtime: D3D12 copies on Vulkan (buffers, textures, uploads, BC) and GetCopyableFootprints
- IR: CopyBufferRegion, CopyTextureRegion (subresource or placed footprint,
  optional box) and CopyResource, with D3D12's call rules (512-byte footprint
  offsets, 256-byte pitches, non-empty boxes).
- Replay: vkCmdCopyBuffer / CopyBufferToImage / CopyImageToBuffer / CopyImage.
  Footprint pitch becomes bufferRowLength; BC extents stop at the mip edge;
  every range and buffer bound is checked before anything is written. Copies
  run in TRANSFER_SRC/DST, or in place in GENERAL for a COMMON texture
  (implicit promotion). 2D only.
- Device: buffers expose their VkBuffer; BC1-7 formats; textureCompressionBC
  enabled when present; GetCopyableFootprints for buffers and 2D textures.
  Compared with the PC runtime over 13 descriptions, which showed planar
  depth-stencil rows are padded to 512 bytes.
- Each submission ends with a barrier to the host so readback buffers hold the
  GPU's writes after the fence wait. BC textures are not zero-filled on first
  use (Vulkan cannot clear them; the validation layer caught the first try).

Tests: d3d12_vulkan_device_test now reads results back through D3D12
(CopyTextureRegion into a readback heap, Map) and adds an upload list: a
pattern into a texture, CopyResource into a COMMON texture, a boxed copy, a BC1
round trip and CopyBufferRegion. command_list_test covers the copy rules. All
GPU tests are clean under the Khronos validation layer; 6/6 ctest.
2026-11-21 20:33:34 +01:00
Ryx
6052bf0bd5 Runtime: rectangle clears, layout tracking, enhanced barriers, COM list/queue/fence
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.
2026-11-21 19:19:31 +01:00
Ryx
7f6e8f059d Runtime: D3D12 barriers and depth-stencil clears in the command-list IR
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).
2026-11-21 18:58:48 +01:00