Commit Graph

138 Commits

Author SHA1 Message Date
7734b05623 Merge remote-tracking branch 'origin/pr/9002' 2026-11-23 17:40:53 -05:00
0e707f9383 Merge remote-tracking branch 'origin/pr/9715' 2026-11-23 17:24:40 -05:00
3afcab2a8b d3d12: enforce cross-device ownership checks on queue, fence, and bundle paths 2026-11-23 23:00:06 +01:00
d59013b815 d3d12: harden Set*Root* closed-list, zero-count null, and foreign root sig handling 2026-11-23 22:32:17 +01:00
e1ec785b2d d3d12: ExecuteIndirect bounds the span max_count * stride, and checks the offset at max_count 0
d3d12_execute_indirect_validation reports five host-parity mismatches on the RTX 5060 and on
WARP: the layer accepts an argument buffer range the host refuses. Both live hosts bound the
bytes the signature can walk, max_count * stride, so a record that fits at the end of the
buffer while its stride runs past it is refused (offset 240 with stride 20 in a 256-byte
buffer), and both check the offset itself when max_count is 0, which the layer skipped
entirely.

The layer validated with (max_count - 1) * stride + record_size and only when max_count was
non-zero. It now uses the same span as the host and validates every call, in d3d12_com.cpp
(recording, so Close fails as the host's does) and in vulkan_replay.h (replay, which had its
own copy of the old arithmetic).

The test's positive GPU path recorded the same out-of-range calls the parity table marks as
refused, so it moves to an exact-fit range (244 + 12 == 256) and a max_count 0 no-op at the
buffer's end (offset 256), and the five parity rows take the verdict both hosts give here.
2026-11-24 03:55:56 +08:00
1599683caf d3d12: reset predication in ClearState and align SetPredication / AtomicCopyBuffer validation (#6815)
Squash-merged after diff review of PR #6815
2026-11-23 12:32:05 -06:00
4da716493f d3d12: reject null arrays and invalid lists in ExecuteCommandLists (#6610)
Squash-merged after diff review of PR #6610
2026-11-23 11:16:29 -06:00
6adeaf0b25 Runtime: guard closed-list IA/OM/PSO state setters and expand D3D12 Close parity tests (#6644)
Squash-merged after diff review of PR #6644
2026-11-23 11:07:42 -06:00
17cc9a7a92 d3d12: validate and track SetDescriptorHeaps and directly-indexed root flags (#6674)
Squash-merged after diff review of PR #6674
2026-11-23 11:00:10 -06:00
9a9ca1ec14 d3d12: match Windows recording-time ExecuteIndirect validation (#6830)
Squash-merged after diff review of PR #6830 - d3d12: match Windows recording-time ExecuteIndirect validation
2026-11-23 09:53:12 -06:00
2c72b0d281 d3d12: validate DXR acceleration-structure prebuild and recording inputs (#6825)
Squash-merged after diff review of PR #6825 - d3d12: validate DXR acceleration-structure prebuild and recording inputs
2026-11-23 09:49:28 -06:00
56e607ac85 Runtime: pipeline-statistics queries around mesh draws (D3D-291) (#2359)
Squash-merged after diff review of PR #2359
2026-11-23 09:34:02 -06:00
78bdbf6ed9 Merge pull request #4445 from pmilewsskiedu-gif
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:14:47 -05:00
b7e7d4a3fd Merge pull request #4411 from pmilewsskiedu-gif
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:14:29 -05:00
f54c6395ed Merge pull request #4312 from Victor Garcia
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	docs/d3d12_vulkan.md
2026-11-22 23:13:27 -05:00
dc473d8c17 Merge pull request #4282 from cixotdev
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:13:05 -05:00
5f5dd44102 Merge pull request #4061 from Exopus
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:10:55 -05:00
cd5267b47a Merge pull request #4060 from sds-228
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	docs/d3d12_vulkan.md
2026-11-22 23:10:55 -05:00
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