Commit Graph

220 Commits

Author SHA1 Message Date
0539527a1f Merge pull request #4038 from pmilewsskiedu-gif
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:10:40 -05:00
6df9cc0d18 Merge pull request #3315 from zneel
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	README.md
2026-11-22 23:07:14 -05:00
95b2e2c8bd Merge pull request #2951 from AlxcBTW
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:06:28 -05:00
04d020822d Merge main for reserved texture tile mapping 2026-11-23 00:47:18 -03:00
a5412e0d73 Runtime: report device loss from blocking multi-fence waits 2026-11-22 21:32:39 -05:00
9ec296cc40 Runtime: unbind scissor rectangles on zero-count D3D12 call 2026-11-22 20:16:54 -05:00
003baa94c1 Merge origin/main into queue-wait-before-signal 2026-11-23 02:15:15 +01:00
7c2252609d D3D-448: console root-argument layout, measured for compute and used there
rt::rootsig::pack_stage() lays a root signature out for one stage the
way the console compiler does: root order from the stage base, a table
one dword (its 32-bit VA), a root view two, constants one per value,
and the first parameter that does not fit refused (the spill array
behind s[0:1] is not modelled).

Compute (base s4) is measured: on the package's FidelityFX DLL, whose 29
compute containers carry their RTS0 next to the console-compiled program,
base plus span equals RSRC2 USER_SGPR in 29 of 29, and
root_sig_contract.py --model console finds all 20 translated programs
compatible (the s0 model contradicts 7). VS/PS/GS s8 and MS s16 stay a
census hypothesis.

The compute bind point now uses this layout; graphics keeps pack(),
since every stage reads one push-constant block and a mesh shader (s16)
and a pixel shader (s8) would collide. A signature carries both
layouts; binding it where its layout refused it invalidates the list.

Test fixtures follow: the compute GLSL shaders read the new places, and
the asm fixtures a D3D12 compute PSO runs are built with
LEONIDA_USER_DATA_SHIFT=4 (compute_fixture.py shifts every SGPR and the
RSRC2 user count), so the standalone harness keeps using them at s0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 01:44:40 +01:00
8dfe9bce1a runtime: notify QueueHolds when a held CPU Fence::Signal fires
When ID3D12Fence::Signal is deferred behind a pending GPU queue signal,
Fence::Signal enqueues a FenceWaitDispatcher callback that calls
vkSignalSemaphore directly instead of going through VulkanFence::signal.
That callback previously never notified QueueHolds via
holds().signaled(semaphore, value) and holds().pump_ready(), leaving any
cross-queue Wait-before-Signal batch stalled on that fence value
forever even after GetCompletedValue() reached it.

Record whether vkSignalSemaphore succeeded, decrement held_ first, and
then call holds().signaled(semaphore, value) and holds().pump_ready()
with no dispatcher or queue lock held. Add cross-queue regression cases
to check_held_cpu_signal in d3d12_fence_timing_test.cpp covering both a
Wait queued before the held CPU Signal and a Wait queued while the CPU
Signal is already held.

Claim: https://github.com/ItsNotRexed/Leonida/issues/4084#issuecomment-7088187469
AI-assisted: yes (Antigravity)
2026-11-22 21:17:10 -03:00
cc4b374499 d3d12: translate ARRAY_OF_POINTERS instances on the KHR path
KHR TLAS builds hardcoded arrayOfPointers = VK_FALSE and passed the guest's console-VA pointer list straight to Vulkan. Carry DescsLayout into the recorded build, validate each pointer, stage a copy with heap_base added into a device-addressable buffer, and use it as the build input. The guest input is not modified and GPU-written pointer lists are refused. Adds ARRAY and ARRAY_OF_POINTERS RayQuery coverage plus a null-entry refusal check.
2026-11-23 02:12:09 +03:00
b70fdadc8b d3d12: ExecuteCommandLists refuses a list whose type isn't the queue's
ID3D12CommandQueue::ExecuteCommandLists only refused bundles: a DIRECT
list ran on a COPY or COMPUTE queue (its draws recorded for a
transfer-only or compute-only Vulkan family) and a COMPUTE or COPY list
on any queue. D3D12 requires the list's type to be the queue's (the
debug layer's EXECUTECOMMANDLISTS_COMMANDLISTMISMATCH, message 836).
A mismatched list now refuses the whole batch with nothing submitted,
like the layer's other ExecuteCommandLists checks.

d3d12_queue_list_type_test: every list type on every queue type, and a
batch whose matching DIRECT list copies a marker while its second list
doesn't match; the marker must not land. On the old code 8 of its 16
checks fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 00:12:06 +01:00
40cf85c2e3 d3d12: retain invalid upload self-copy Close rejection 2026-11-22 18:05:46 -05:00
00c63805c2 XDXR builder: BOX16 inner nodes for MINIMIZE_MEMORY bottom-level builds
A bottom-level BuildRaytracingAccelerationStructure with MINIMIZE_MEMORY now
writes BOX16 inner nodes (64 bytes, half boxes) instead of BOX32 (128 bytes):
the same tree, about a fifth smaller. Prebuild info, the build and its refits
take the choice from the same flags (xdxr_box16), so the sizes stay exact.
Top-level builds keep BOX32 (world space: a half's step is 2 m at 2 km).

Each child box is rounded outward from the exact box kept in scratch, in
integer code (packHalf2x16's rounding is implementation-defined; AMD rounds
toward zero). Past the half range a bound goes to +-inf outward and +-65504
inward, so empty slots stay empty; below the smallest normal half it goes to
0 or +-2^-14, never a denormal a flushing decoder would shrink.
tools/xdxr_bvh.py half_round gets the same denormal rule, and check-build now
compares every BOX16 word bit for bit with encode_box16 of the exact box of
the triangles under it.

Tests: five blas_box16_* cases in vk_xdxr_build_test (radix and small sort,
an inactive triangle, values past 65504 and below 2^-14, a refit), and a
MINIMIZE_MEMORY BLAS plus its in-place update through the D3D12 API in
d3d12_xdxr_rt_test (prebuild and postbuild sizes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:29:47 +01:00
2ce8378268 Merge pull request #3693 from Ayinaki 2026-11-22 17:03:26 -05:00
b69e3a4898 Merge pull request #2297 from Ewann 2026-11-22 16:59:09 -05:00
63cb07c069 Merge upstream main and preserve Vulkan runtime behavior 2026-11-22 18:58:22 -03:00
f506039c95 perf(runtime): move a draw's views out of the command variant (D3D-391)
#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.
2026-11-22 21:23:04 +00:00
6de779367b Runtime: command allocators and lists answer invalid arguments as the host does
Measured against the host D3D12 runtime (RTX 5070, driver 621.14) with
d3d12_vulkan_device_test's compare_invalid_arguments:

- CreateCommandAllocator and CreateCommandList1 took any type (7, 99,
  -1); the host refuses types past VIDEO_ENCODE with E_INVALIDARG.
- CreateCommandList and CreateCommandList1 took a node mask with bits
  past node 0; the host answers E_INVALIDARG.
- A null output was E_POINTER in all three; the host answers
  E_UNEXPECTED, after the argument checks.

compare_invalid_arguments gets 35 "command allocator:", "command list:"
and "command list1:" cases. Video list types are not compared: the host
hands out a video list (E_NOINTERFACE for ID3D12GraphicsCommandList),
while this layer creates a graphics list for them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 21:21:25 +01:00
7cedefbe33 Merge pull request #3255 from KanameS 2026-11-22 15:16:15 -05:00
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
5efe4afddd Merge origin/main into queue-wait-before-signal 2026-11-22 21:03:29 +01:00
90f10662ac Merge upstream main into reserved texture tile mappings 2026-11-22 17:03:14 -03:00
f8007dda67 Queue holds: review fixes (Present ordering, pins, timeline monotonicity, fence lifetime, teardown, docs)
- Present is queued behind held work (QueueHolds::after_held) and submitted in order by the releasing thread.
- Held batches keep the pipeline states and root signatures of their lists; fences a queue waits on or signals are
  kept until the submission has completed on the GPU (a D3D12 queue holds them).
- A held Signal released below an unheld one on the same fence leaves the Vulkan signal out (claimed under the submit lock).
- A queue destroyed with held Signals completes the CPU waits on their fences and reports it.
- A failed held batch is reported (take_held_failure, last_execute_result), its waits stay for the next submission,
  and the Signal behind it still signals.
- d3d12_queue_handover_test: pairs, two-thread signalling stress, held Signal of a released fence, shared fence,
  teardown with a CPU waiter; --two-queues and --shared-queue modes on a caller-owned device.
- Tests for each fix in vk_presenter_sync_test, vk_queue_query_sync_test and d3d12_m4_compute_test; docs section 4.4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 21:02:33 +01:00
70e3acf459 Runtime: a bundle that sets viewports, scissors or render targets, or calls ClearState, fails its Close, as on D3D12
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>
2026-11-23 02:53:47 +07: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
f8e89767f6 Runtime: map sparse reserved RGBA8 texture tiles (D3D-285) 2026-11-22 13:39:08 -03: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