Commit Graph

4696 Commits

Author SHA1 Message Date
bd8be62577 Merge own/main into own/mangrove
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 21:54:28 +00:00
140bc377db Merge own/slot67: #8448, #8526, #3976 (+ always-barrier fix) for the slot 67 library programs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 21:54:28 +00:00
4154ab0a62 d3d12_xs: a struct-return argument on the caller's stack is the return buffer, not the device
Device slots 25, 26, 56 and 108 tell the C form (buffer, device) from the
PC form (device, buffer) by which argument starts with the proxy vtable
pointer. A title's return buffer is uninitialised stack memory and can still
hold that pointer from an earlier call; both arguments then look like the
proxy and the struct is written over it (xcl found this on a retail title).
A device proxy is a heap object, so an argument inside the calling thread's
stack is taken for the buffer.

xs_proxy_mock_test: check_struct_return_stale_vtable puts a stale copy of
the vtable pointer in a stack buffer and calls slots 25 and 108 in the C
form and slot 26 in both forms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 21:54:19 +00:00
cb29a2b88f d3d12_xs: slot 133 commits the buffer's xmem pages before the host-pointer import
xmem commits physical pages on first touch (#7556), so a range the title has
mapped but not written yet is still MEM_RESERVE when it places a buffer on it
through device slot 133, and the Vulkan layer's import (#7218) refuses reserved
pages and answers with its fallback buffer, which the title's writes never reach.

Slot 133 now calls a registered pages hook (set_placed_at_va_pages_hook, next to
set_placed_at_va_handler) with the buffer's range before the handler; gta6rt
registers rt::xmem::commit_physical_range. A failed commit is logged once and the
handler still runs. Textures don't call it. The Vulkan layer doesn't link xmem.

Tests: xs_proxy_mock_test checks the hook order, arguments, failure and texture
cases; the new d3d12_xmem_placed_test places a buffer on untouched xmem physical
pages and checks the fallback without the hook, and with it the import and a GPU
copy reading the CPU's writes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 18:51:49 -03:00
664aff24f1 Merge #7556 (xmem: commit physical pages on first touch) for the stack 2026-11-23 18:51:48 -03:00
72ab1220d3 shader_library_test: make section 4 dynamic code-length tree complete for standard zlib 2026-11-23 22:50:24 +01:00
bef7488733 Merge #3976 into own/slot67
regen_fixtures finds its sources by marker on main, so the two ds_append
sources carry the marker instead of a SHADERS entry. ds_append and
ds_consume join wave64_emulate_opt's always-barrier ops (autogenes-sudo's
fix on #3976): under --wave64-emulate they exchange through a barrier
round, and a guarded one in a multi-wave group hit the translator's assert.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 21:49:07 +00:00
88797f3ebd d3d12: LEONIDA_CAPTURE writes the presented frames to disk
A question that keeps coming back on the boot path is "what is actually on screen", and the window is not a reliable
answer: under Wine it is not mapped at all, and even on Windows a compositor or a capture-blocked surface can hide
the content. The presenter already copies every presented frame into a staging buffer when capture is enabled, so
this adds the disk side: `LEONIDA_CAPTURE=<dir>` writes each captured frame as a binary PPM and appends the extent
and the mean RGB to `<dir>/index.txt`, with `LEONIDA_CAPTURE_EVERY` and `LEONIDA_CAPTURE_LIMIT` bounding the run.

Off unless set, and created with the folder if it is missing. The write happens on the fence that already covers the
copy, so the present path is untouched.

d3d12_present_test turns it on and checks the files against the colour the test clears to: at least half the captured
frames (it resizes and injects failures on purpose, so a frame caught mid-transition is a near miss), and no frame
black. A capture that reads the wrong or a stale buffer fails there instead of in a report months later.
2026-11-24 00:48:42 +03:00
dbadb08b15 dxgi: the adapter answers IDXGIAdapter4; GetRestrictToOutput, ResizeBuffers flags and null out-pointers answer as the host does
Measured against the host runtime's DXGI on an RTX 5070 Ti and on WARP (Windows 11), both agreeing:

- The adapter answers IDXGIAdapter4. GetDesc3 gives what GetDesc1 gives, plus the
  preemption granularities; a null description is E_INVALIDARG.
- GetRestrictToOutput on a swap chain created without an output is S_OK with a null
  output, not DXGI_ERROR_NOT_FOUND.
- ResizeBuffers refuses NONPREROTATED, FULLSCREEN_VIDEO and every bit from 0x4000 up
  with DXGI_ERROR_INVALID_CALL, and FOREGROUND_LAYER, YUV_VIDEO and 0x2000 on a chain
  created without them with E_INVALIDARG (a sweep of all 32 bits on the host).
- A null out-pointer on GetBuffer, GetHwnd, GetLastPresentCount and GetRestrictToOutput
  is DXGI_ERROR_INVALID_CALL, not E_POINTER or E_INVALIDARG.

dxgi_host_parity_test compares the layer with the host for each of these (PROBE_WARP=1
for WARP): 18 of 26 rows differ before, 0 after, on both. dxgi_device_test and
dxgi_swapchain_test now expect the host's answers.

AI-assisted: yes
2026-11-23 15:47:27 -06:00
f1d006bdbd Merge #4025 (test/877b-shader-programs-validation) 2026-11-23 21:45:01 +00:00
5d801afc11 bcrypt_rng: fail closed on missing host CSPRNG and log seeded mode once 2026-11-24 04:44:30 +07:00
464bb23d9f com_shim: retain host apartment reference when absorbing RPC_E_CHANGED_MODE 2026-11-24 04:43:36 +07:00
d030b99128 xs_proxy_mock_test: the slot 70 placed-buffer check reads the mock's held private data
Own's mock keeps the SetPrivateDataInterface object in Mock::held (ladder's
port of #7052); #7235's mock calls it private_data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 21:43:14 +00:00
0438ee44fd xbox_present_test: open the trace capture with _wfopen_s, and check the trace-off case
Review notes on #9549: fopen warns C4996 on MSVC and narrows the temp path to
the ANSI code page, so a TEMP outside it left stderr unredirected and the test
failed with counts of 0. The capture now opens the wide path and reports
whether it redirected, which the test expects.

The comment said nothing is written with the trace off; a refused PresentX
under a capture with the trace off now checks it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HxBQf4pXH8PWpC5oZsM4bt
2026-11-23 15:42:08 -06:00
bc14ec5dd9 d3d12_xs: the placed-buffer registry is keyed by entry id, so a tag removes its entry in O(log n)
Releasing N placed buffers scanned N(N+1)/2 entries under the lock slot 70 takes (shdann's review on #8304).
The entries now live in a std::map keyed by their id. Ids only grow, so map order is placement order and
slot 70 still walks it backwards for the newest placement; a tag whose entry already went with its device
erases nothing. Teardown of 32,768 buffers released newest first: 151.63 ms before (shdann), 3.47 ms after
(same loop, MSVC /O2, Windows 11).

(cherry picked from commit 335d0a1870a2fd49106289ecb0980b71cd2410c8)
2026-11-23 21:41:03 +00:00
da62707101 d3d12_xs: a buffer placed at an address through device slot 133 is the resource of a slot 70 view of that address
Device slot 70 makes a shader-resource view from a description and a console
address, with no resource object. It asked only the device behind the proxy
for a buffer at that address, and that device knows the buffer by the title's
address only when it could put the buffer on the title's own pages. When it
could not (the import is refused, or the device is a PC one), the slot 133
buffer has an address of its own, nothing was found, and the title's
descriptor got the null view.

The proxy now remembers every buffer a slot 133 call made by the range the
title placed it at, whichever way it was made (the placed-at-VA handler, PC
CreateCommittedResource3 or CreateCommittedResource), and slot 70 asks there
first, then the device's provider. An entry holds no reference. An object
attached to the resource as private data removes the entry when the resource
dies, and a device proxy's entries go with it. The newest buffer over an
address answers, so a range the title places again is the new buffer's.

xs_proxy_mock_test: check_slot70_placed_buffer covers both creation paths
and the handler path, the element range, the cut at the buffer's end, the
addresses around two buffers, a texture, the provider fallback and its
order, a range placed twice, a released buffer and a released device. The
check of the placed-at-VA handler in check_levels hands out a mock resource
instead of a made-up pointer, since the proxy now asks the object for
ID3D12Resource.

Depends on: #7066 (slot 70), #7218 or #7075 (slot 133), #6953 (the table
reaches slot 133), and #7235 for the mock's SetPrivateDataInterface.

(cherry picked from commit 7387445983daa6d52367cd7a78ef0a6069b7035e)
2026-11-23 21:40:52 +00:00
33d76521d4 Merge #7218 (slot 133 buffer on the title's pages) at 3644c72a5
Resolved as #8304's integration merge b7a68aa39 does: a buffer goes to the registered placed-at-VA handler
first; a texture, a device with no handler and a handler refusal keep #7075's committed stand-in. #7218's own
proxy_create_placed_resource_x is folded into #7075's; slot_name keeps one case 133.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 21:39:56 +00:00
6cbcf3c6e0 fix(docs,tools): fix markdown links and pin newline='\n' in text writers 2026-11-23 23:38:26 +02:00
c57dc3669e dxgi: GetDesc/GetDesc1 report the SwapEffect and BufferUsage the chain was created with
Both were hardcoded (FLIP_DISCARD, RENDER_TARGET_OUTPUT). The host and WARP report the creation values:
FLIP_SEQUENTIAL, RENDER_TARGET_OUTPUT | SHADER_INPUT, or 0. dxgi_host_answers: 6 of 7 rows differ on main against
the NVIDIA host and against WARP, 0 with both commits.

AI-assisted: yes
2026-11-23 15:37:33 -06:00
f40692d6f4 dxgi: flip-model back buffers go round-robin, as the host hands them out
When the native swapchain matched the request (count, size and format), the app's back buffers were the Vulkan
images themselves, so GetCurrentBackBufferIndex followed vkAcquireNextImageKHR: 0 1 0 2 1 0 2 on an RTX 5070 Ti
with three FIFO images, where DXGI (NVIDIA and WARP) hands a flip-model chain's buffers out 0, 1, 2, 0, ... An app
that keeps its own (i+1)%N counter rendered into a buffer that wasn't presented next. The offscreen ring the
mismatched cases already use (one blit per present) is now always used.

dxgi_host_answers_test creates the same chains on the Vulkan-backed factory and on the host's (PROBE_WARP=1: WARP)
and compares the index sequence over 12 presents and a resize, and GetDesc/GetDesc1.

AI-assisted: yes
2026-11-23 15:37:32 -06:00
88045c7ae8 Keep buffer registrations atomic on host allocation failure 2026-11-23 16:37:09 -05:00
ca9e34bd08 xbox_present_test: compare all three channels of the HDR10 swapchain, not only red
The HDR10 swapchain check compared only red, so errors confined to green or blue could pass. Compare all three
channels within one 10-bit code for either packed format and report the first mismatching sampled pixel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 14:36:47 -07:00
9538218ee3 vk_descriptor_bench, vk_sandbox: LEONIDA_VK_DEVICE names the GPU (TEST-1141)
Both tools ranked the devices themselves and ignored LEONIDA_VK_DEVICE,
so on a PC with two GPUs they ran on the best-ranked one whatever the
filter said. vk_sandbox now uses vk_device_pick.h's pick_device, and
vk_descriptor_bench skips devices the filter leaves out. When the filter
matches no usable device, both report it and fail the run, as the other
harnesses do.

check_device_filter_tools.py (ctest vk_device_filter_tools) runs both
tools with a filter that matches nothing and skips on a machine with no
Vulkan device.
2026-11-23 16:36:07 -05:00
3e648aa10f vk_harness: build without VK_KHR_pipeline_binary headers, exit 77 with the flag
The VKH_BINARY_OUT/VKH_BINARY_IN path needs VK_KHR_pipeline_binary, which is newer than
some Vulkan header sets: Ubuntu 24.04 ships 1.3.275 and CMake's find_package(Vulkan)
picks those up when VULKAN_SDK is not set, so the whole target failed to compile with
"VkPhysicalDevicePipelineBinaryFeaturesKHR was not declared in this scope" and seven
follow-on errors.

Guard the feature on the two extension macros the code already needs. With old headers a
VKH_BINARY_OUT/VKH_BINARY_IN run now prints "unsupported: these Vulkan headers have no
VK_KHR_pipeline_binary" and exits 77, the skip code the harness uses elsewhere, and
everything else in the harness is unchanged.
2026-11-24 00:35:10 +03:00
2879a3a045 d3d12_sparse_queue_family: exit 77 when no Vulkan device, like its siblings
The test registered SKIP_RETURN_CODE 77 and check_sparse_queue_family.py already reads 77 as
"Vulkan device / sparse features unavailable", but main() pushed the standalone device creation
through ok(), so on a host without a Vulkan device it printed "FAIL Leonida
create_vulkan_device_standalone hr=0x80004005" and exited 2. The Windows CI runner has no GPU
driver, so the windows ctest job fails on this one test out of 166 while every sibling d3d12 test
skips through vktest::Device.

Return 77 on a failed creation instead, matching d3d12_dxr_validation_test, and keep the hard
failures for everything after it.
2026-11-24 00:35:10 +03:00
52b4f03b78 GameInput: honor the delay between trigger haptic pulses 2026-11-24 08:34:25 +11:00
b170687d25 xgameruntime_offline: keep XUser device association and audio endpoint registrations until unregistered (RT-391)
XUserDeviceImpl slots 4/5 (XUserRegisterForDeviceAssociationChanged and its
unregister) and 7/8 (XUserRegisterForDefaultAudioEndpointUtf16Changed and its
unregister) handed out a token and dropped the registration; unregister
returned true for anything.

Each registration is now kept (kind, a duplicate of its queue, context,
callback) under a token unique across both kinds and never 0, and the
matching unregister removes it at once, with or without wait. Unregister
returns true for every token, as XUserUnregisterForChangeEvent does; a token
already removed, never issued or of the other kind changes nothing. Offline
the association and the default audio endpoint never change, so no event is
raised and no callback is queued or called. The state is namespace-scope
with a constinit SRW lock, no function-local statics.

xgameruntime_offline_test checks null arguments, token uniqueness, that
registrations are kept and removed per kind, harmless repeat and foreign
unregisters, and that no callback runs. docs/runtime_imports.md says so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 16:33:58 -05:00
8dfa9cc5e7 root_sig_test: match host d3d12.dll behavior when verifying bad-hash forwarding 2026-11-23 22:33:42 +01:00
e597d90c12 GPU test cs_w32_partial_permute: ds_permute_b32 in a partial wave32
A 20-thread group is one wave32 with lanes 20-31 never launched. A launched
lane whose source lane is missing gets 0, and a send to a missing lane is
lost. cs_w32_permute and cs_w64x_permute run full waves only. The expected
words are measured with a raw 20-thread hw_oracle kernel on gfx1036.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 22:32:20 +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
3630610ca8 feat(d3d12): report console descriptor heap address on Xbox slot 14
Handle the console-extended CreateDescriptorHeap layout observed in #313 by reading address/size only on the Xbox slot 14 proxy path after a readable-range check, and report that console VA as the heap CPU/GPU start via an explicit Leonida helper. Normal 16-byte PC CreateDescriptorHeap calls remain unchanged. Title-memory aliasing / section 3.3 backing is still unresolved.
2026-11-23 23:32:12 +02:00
e063e5ead6 code_hooks: unwind data for the thunks, so exceptions and stack walks pass through them 2026-11-23 22:32:01 +01:00
3ce953ae80 d3d12: a depth clear outside [0, 1], NaN, or with no clear flag no longer fails the list
`CommandList::clear_depth_stencil` (`runtime/src/command_list.h`) refused a `ClearDepthStencilView` whose depth was
outside [0, 1] or NaN, and one whose `D3D12_CLEAR_FLAGS` were 0, so `Close` answered `E_INVALIDARG` and the whole
`ExecuteCommandLists` submission was dropped. Windows' D3D12 closes those lists: on WARP a `D32_FLOAT` target keeps
1.5, -0.5 and NaN exactly as given, and a clear that names no plane clears nothing. `d3d12_clear_test` now reads those
back on WARP and on the layer, and `d3d12_close_parity_test` measures the four `Close` verdicts.

A title that clears depth with a computed value (or wraps the clear in a flag mask that can be 0) lost that frame's
depth clear and, with it, the whole submission's work. The call is now recorded with the depth as given (a D16 target
still quantizes at replay) or, with no plane named, recorded as nothing.

d3d12_clear_test adds three read-back comparisons (1.5/-0.5, NaN, flags 0), command_list_test asserts the accepted
calls and the stored values, and the four close-parity rows move from the known-difference table to `match`.
2026-11-23 22:31:56 +01:00
bcb1f888aa shader_library: 9-bit canonical Huffman LUT and 64-bit BitReader refill (PERF-ZLIB-HUFFMAN-LUT) 2026-11-23 22:31:03 +01:00
3644c72a57 d3d12: slot-133 texture layouts are validated; an import reaching the arena's VA window takes the fallback
From review (@FRaccie):
- The texture fallback called create_committed, which takes the state without checking it (textures start
  undefined and take their first command's layout), so the barrier-layout state and its COMMON retry did
  nothing. It now goes through create_committed_validated, as CreateCommittedResource does: RENDER_TARGET on a
  texture without ALLOW_RENDER_TARGET is refused and the COMMON retry answers; a description the checks refuse
  outright is refused.
- An imported buffer's VA is its host address, in the same BufferVaIndex as default-heap buffers, whose VAs are
  offsets in [0, arena size). A host address inside that window (low addresses, as under Wine) would shadow arena
  buffers in the nearest-start lookup, so such a range is not imported and the fallback answers.

d3d12_existing_heap_test checks the two texture cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 22:29:53 +01:00
11323362c4 xs_proxy_mock_test: the committed-resource-3 mock refuses only a render-target or depth-stencil buffer
own/main shares this mock between the slot 127 and slot 133 tests. The ported refusal also turned away
a buffer with unordered access, which the PC runtime accepts, and failed slot 133's UAV buffer case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 21:29:41 +00:00
5c3487a944 d3d12_xs_rootsig: fail closed on any malformed DXBC chunk-table entry 2026-11-23 22:29:35 +01:00
08d91830ef Make BufferVaIndex insertion atomic on allocation failure 2026-11-23 16:29:23 -05:00
6de6f5b2bb file_system: roll back directory when marker deletion fails 2026-11-23 22:27:43 +01:00
85441c34fb xbox_present: one [d3d12-trace] line per PresentX, with its outcome
The queue proxy's PresentX slot is past the PC chain, so nothing recorded
a present: a --trace-d3d12 run of a frame loop could not say how many
frames were presented, or whether one was refused. XboxPresentation::PresentX
now writes one line per call through d3d12_trace::result (ok or failed).

xbox_present_test captures the trace around a blank present and a refused
three-plane call and checks for exactly those two lines.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HxBQf4pXH8PWpC5oZsM4bt
2026-11-23 15:27:18 -06:00
bcfabd83d7 Enable subgroup size control on Vulkan 1.2 devices 2026-11-24 02:56:34 +05:30
42374fb2bc Recognize the documented wave64 exchange mode 2026-11-24 02:56:33 +05:30
aecb0809c7 Reject conflicting FSPX metadata for bare programs 2026-11-24 02:56:33 +05:30
28716daea5 file_system: check CopyFile2 cancellation before preparing destination 2026-11-23 22:25:45 +01:00
57d08d2fd6 d3d12: 8-bit sRGB UAV textures are mutable UNORM images where the sRGB format has no storage
The host runtime sizes and creates R8G8B8A8_UNORM_SRGB and B8G8R8A8_UNORM_SRGB textures with
ALLOW_UNORDERED_ACCESS (RTX 4090 617.42 and WARP). The layer created their image in the sRGB format with
STORAGE usage, which most GPUs lack, so it refused them: a retail title sizes a 2048x2048, 12-mip
R8G8B8A8_UNORM_SRGB render target with unordered access through device slot 25, got UINT64_MAX and
stopped on its 32-bit size check.

Such a texture is now a mutable image of the UNORM format of the same order (Format::uint_backed, from
#7604), where the GPU can make that image with both formats listed. Its storage view is UNORM, as every
D3D12 typed UAV of these textures is; RTVs and SRVs are sRGB, so clears and draws encode and sampling
decodes. Multisampled ones are still refused.

d3d12_srgb_uav_test compares with WARP: the retail shape's size alignment and creation, a clear
through the sRGB RTV and one through a UNORM UAV, byte for byte, for RGBA8 and BGRA8. Without the
change it fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 22:25:05 +01:00
68e20ecff8 file_system: clear marker when recreating directory 2026-11-23 22:24:36 +01:00
66e46ec9d4 runtime: pe_loader_fuzz, a deterministic mutation fuzzer for Loader::load under ASan (RT-388)
Synthetic PE32+ images built in the test (relocations, imports and delay
imports, exports with forwarders, TLS directory, .pdata/UNWIND_INFO),
field- and byte-level mutations, seeded and reproducible per case, with
--minimize in child processes. LEONIDA_LOADER_FUZZ_ASAN builds it with
/fsanitize=address under MSVC or clang-cl.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 22:24:27 +01:00
9f89213b01 xgameruntime: terminate empty package user locale 2026-11-23 22:24:24 +01:00
f967225be8 runtime/shims: shim bcrypt.dll provider lifecycle and RNG with deterministic seed support
Refs: https://github.com/ItsNotRexed/Leonida/issues/9065#issuecomment-7114352737
2026-11-24 04:23:26 +07:00
aa2dc43f70 Test fragment color modulation through a constant buffer descriptor table 2026-11-24 05:22:56 +08:00