Commit Graph

96 Commits

Author SHA1 Message Date
5abbc6031a Merge pull request #2042 from Vonsek 2026-11-22 15:10:04 -05:00
45ffc82680 Merge pull request #1161 from woreksami 2026-11-22 15:09:38 -05:00
00e53365b7 Merge pull request #2483 from Shadman PC 2026-11-22 13:15:38 -05:00
7762899b33 Runtime: hold a CPU fence signal until the queue signals before it have completed
ID3D12Fence::Signal from the CPU called vkSignalSemaphore at once, also while a queue Signal of a lower value
was still pending on the GPU. Vulkan requires a host signal to stay below every pending signal
(VUID-VkSemaphoreSignalInfo-value-03259), and D3D12 allows the order. The fence now records the highest value a
queue will signal, under the same lock as the claim, and a CPU signal above a value the GPU has not reached yet
(or made while an earlier one is held) is handed to the fence dispatcher, which applies it once the GPU passes
that value, in the order the signals were made. The callback holds no pointer to the fence; when the fence is
released (cancel) or the device is lost before the queue value is reached, the held signal is dropped, since
signalling then would break the same rule. Until a held signal is applied, GetCompletedValue reads the GPU's
progress.

d3d12_fence_timing_test: a queue Signal kept pending by a Wait on a gate fence, a CPU Signal above it (held, then
applied), and two CPU signals held behind one queue signal (applied in order). Fails on main's Fence at the first
check: the event for the CPU value fired while the queue signal was still pending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 13:09:56 -05:00
8d43271bcd Merge upstream main into codex/d3d12-compute-trace
Trace at the Dispatch entry point while preserving the newly merged bundle replay path.
2026-11-22 19:09:24 +01:00
90a046eaa4 perf(runtime): inline draw views and move into CommandList to eliminate allocations (D3D-289)
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
2026-11-22 23:11:32 +06:00
e3c972d0d5 Merge pull request #2145 from KanameS 2026-11-22 11:42:13 -05:00
6f77e39793 Merge pull request #2112 from SirKingg 2026-11-22 11:41:54 -05:00
538a9fd77d Merge upstream main into codex/d3d12-compute-trace
Keep the newly merged graphics descriptor trace coverage ahead of the compute calls in the shared fixture.
2026-11-22 17:40:54 +01:00
b76c78acdb Runtime: a bundle's draws run with the parent's state, and what the bundle set stays on the parent
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>
2026-11-22 23:06:44 +07:00
849f4b7a9c d3d12: reject integer formats in plain resolves (D3D-274)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
2026-11-22 16:59:20 +01:00
ea9dcd1797 fix(runtime): trace D3D12 compute command calls
Startup traces need to show whether compute setup reaches Dispatch before a graphics draw.
2026-11-22 16:42:01 +01:00
756bc62610 Merge pull request #1907 from Vonsek 2026-11-22 10:39:19 -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
6531d9c696 fix(runtime): trace graphics descriptor setup
Show whether callers attempted to set graphics descriptor tables or shader-visible heaps before the first draw.
2026-11-22 15:59:03 +01:00
b566a8652f Merge pull request #1844 from romainveurrier 2026-11-22 09:48:41 -05:00
3b7cd5e4bf Merge pull request #1791 from AlxcBTW 2026-11-22 09:48:16 -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
9bc4674296 Merge pull request #1796 from Vonsek 2026-11-22 09:15:24 -05:00
f61946cfe1 Merge pull request #1795 from AimLogin 2026-11-22 09:15:24 -05:00
c2f39447b6 Merge origin/main into m4-synthetic-gate 2026-11-22 15:13:40 +01:00
34d3225e26 fix(runtime): trace graphics pipeline setup
Record pipeline and root-signature bindings so the boot trace shows whether both setup calls reached the command list.
2026-11-22 15:12:57 +01:00
2123a02506 Runtime: Xbox-ABI proxy for the command allocator (device slot 9)
Device slot 9 (CreateCommandAllocator) now returns an allocator proxy,
the fourth command object after the queue and fence (BUILD-231) and the
list (D3D-136): the public chain (9 slots, Reset at 8) is forwarded, a
slot past it up to the end of a 64-slot table is logged and refused with
E_NOTIMPL, and a read past the table faults in its own guard region. The
console allocator's extra methods are not measured and not guessed.

A list takes the title's allocator in CreateCommandList and Reset, so a
proxy is only safe where the list side resolves it. Slot 9 therefore
wraps an allocator only when it answers kLeonidaCommandAllocatorTag (the
Vulkan layer's CommandAllocator, whose from() resolves the proxy for both
calls); a PC runtime allocator is handed out unchanged, logged once,
until a command-list proxy unwraps it at Reset. Allocator proxies are
unwrapped in the residency calls like heap, queue and fence proxies.
Device slot 12 is not touched.

Tests: allocator_proxy_test (WARP, a hardware adapter, the Vulkan device:
forwarding, refused tail, guard region, identity, D3D12's allocator rules,
a list created and Reset on the proxy with GPU copies through the queue
and fence proxies read back), mock cases for allocators with and without
the tag and their failure paths, and device_proxy_test's slot-9
expectations. No game files.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 15:11:53 +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
8c0738cf44 fix(runtime): include graphics draws in the D3D12 trace
The first draw can currently be invisible in a boot trace. Record both public draw entry points even before the command list has a graphics pipeline.
2026-11-22 14:36:11 +01:00
1b1d090e3c Merge pull request #1667 from romainveurrier 2026-11-22 08:08:38 -05:00
f5d31f02ae Merge pull request #1660 from Vonsek 2026-11-22 08:08:34 -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
5f7caad4d5 fix(runtime): carry bundle blend factors back to parent draws 2026-11-22 14:00:44 +01:00
af665729d2 Merge pull request #1553 from quackottu 2026-11-22 07:38:09 -05:00
1556d9c4db Merge main (99f99890) into d3d-51-command-list-rules
Conflicts in d3d12_com.cpp and d3d12_vulkan_device_test.cpp: both sides kept.

d3d12_debug_markers_test recorded two lists into one allocator at once, which
this branch rejects as the PC runtime does; its second list now has its own
allocator. The device-removed wording in the docs and the test matches main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 13:36:11 +01:00
217249c8a3 Runtime: ExecuteIndirect with MaxCommandCount 0 is a no-op, not a failed list 2026-11-22 17:34:40 +05:30
ba4687404d Merge origin/main (bb2e1842) into d3d90-castable-placed
Third merge round (118 commits): D3D-97's per-queue priorities keep the
GPU address arena's bufferDeviceAddress enable; main's VK_KHR_shader_fma
probing chains after the PR's PSO feature enables; the backing-offset and
hardened whole-buffer-copy refactors replace the PR's older lines.
2026-11-22 03:30:40 -08:00
69b21a9427 Merge origin/main (c2967a5e) into d3d90-castable-placed
Second merge round: main added rgb96 views, the device filter, the
present source-rect path and its own ctest registration of
d3d12_present_test. bind_image keeps both defaulted parameters and the
rgb96 view fallback; image_descriptor runs main's 96-bit family check
before the castable-list check; Resource keeps main's rgb96_ member;
register_samplers and the presentation plumbing follow main's positions,
and the duplicated d3d12_present_test block and stale 'surfaces' local
are dropped in favour of main's.
2026-11-22 03:15:32 -08:00
35804cf199 Merge pull request #1404 from kovaaper 2026-11-22 06:08:14 -05:00
bed399b7b6 D3D-97: preserve LF line endings in queue shim
Keep the published diff limited to queue leasing. AI-assisted (Codex).
2026-11-22 14:02:42 +03: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
9fbe517bd9 D3D-97: lease separate Vulkan queues for D3D12 waits
Give each live standalone D3D12 queue its own graphics-family VkQueue so cross-queue Wait-before-Signal can progress. Preserve legacy caller-owned devices. AI-assisted (Codex).
2026-11-22 13:53:09 +03:00
41dccfb3e4 Merge pull request #1339 from mrb-eel 2026-11-22 05:37:48 -05:00
3b7cbf46c7 Resolve indirect arguments relative to Vulkan backing buffers 2026-11-22 11:22:14 +01:00
62593f47ca Runtime: Xbox-ABI proxies for the command queue and the fence (BUILD-231)
Device slots 8 (CreateCommandQueue), 75 (CreateCommandQueue1), 36
(CreateFence) and 32 (OpenSharedHandle of a fence) now return queue and
fence proxies. They forward the public chain in PC order (19 queue slots,
11 or 12 fence slots), refuse and log a slot past it up to the end of the
proxy's table, and name a read past the table through a guard region and
a vectored handler.

Heap, queue and fence proxies are unwrapped wherever a device or queue
method hands them to the real runtime: queue Signal/Wait, device slots
31/34/35/45/46/50. Arrays are copied without exceptions. QueryInterface
answers only the modelled interfaces, and logs one the real object has
but the proxy does not model. Outputs are cleared on failure as for
slots 14/62/76. --trace-d3d12 records proxy calls in the README grammar.
Every function a thunk hands its words to keeps them in the same
positions, because a title passes only as many as the method takes.

Tests: queue_proxy_test (host WARP, host hardware, Vulkan device;
differential per-process error cases, guard faults, identity, threads,
raw-slot client, child-runner self-test), xs_proxy_mock_test (older
devices, fences without Fence1, OpenSharedHandle branches, allocation
failures; three guard-setup fault modes), and device_proxy_test through
the D3D12XboxCreateDevice shim. No game files.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 11:08:53 +01:00
158e3e9455 Validate Vulkan clock calibration against Win32 QPC 2026-11-22 17:30:42 +08:00
8163c74be5 Merge origin/main into d3d90-castable-placed (resolve #1083 conflicts) 2026-11-22 00:52:00 -08: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
432520f71c Merge pull request #1225 from quackottu 2026-11-22 03:37:56 -05:00
a3ac0c8ea8 Merge pull request #1212 from quackottu 2026-11-22 03:37:51 -05:00
eb21bee162 Runtime: a released fence sets the events still waiting on it, and SetEventOnMultipleFenceCompletion with no fences is E_INVALIDARG 2026-11-22 14:06:06 +05:30
be0e227dbd D3D12: refuse query calls the list type can't hold, and CreateQueryHeap node masks above 1 2026-11-22 13:54:34 +05:30
2a333b5c69 Merge pull request #1155 from quackottu 2026-11-22 03:14:16 -05:00
bb36812235 perf(vulkan): conditional Sync2 readback flush, O(1) deferred deletion, lock split, TDR safety, and centralized FenceWaitDispatcher 2026-11-22 05:05:36 -03:00