From kevincommits' finding (item 2) in #1608.
- plan_overlapping_statistics_segments: a clamped indirect draw opens a
segment of its own (the clamp is a helper dispatch), but the planner then
set the segment's kind to vertex and skipped the draw-kind rule. A clamped
indirect mesh draw under overlapping statistics queries therefore ran in
the full 11-counter pool (VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076)
and had no mesh-primitives query. The clamped call now falls through to
the same rule as every draw; a dispatch leaves the kind unset. The
one-query-at-a-time planner already marked it mesh.
- VulkanQueue::execute keeps the PreparedLists of its largest batch, but
gathered the segment kinds from all of them, so a smaller batch could pick
up a stale mesh segment and create the mesh pools (or fail as unsupported
where the device has none). It now gathers from this batch's lists only,
through batch_statistics_mesh in vulkan_replay.h.
replay_query_predication_test gains case 16b: the clamped mesh draw's segment
is mesh, a mesh draw after it stays in it, a vertex draw splits; the
non-overlapping planner agrees; and batch_statistics_mesh over the first n
lists leaves the stale tail out. 2 checks fail with the old planner.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gen_random() looked the handle up under g_lock (shared), released the
lock, and then called the host BCryptGenRandom with the host handle. A
concurrent close_algorithm_provider() could unlink the wrapper, close the
host handle and free the wrapper while the host call was still using it
(kevincommits' finding in #1608, item 3).
gen_random() now keeps g_lock shared across the lookup and the host call,
and close_algorithm_provider() closes the host handle under the exclusive
lock, so a close waits for calls in flight on any handle and no later
call can find the closed one. Calls still run side by side. The
system-preferred path takes no handle and no lock, and the seeded path
fills after the shared hold ends, since fill_seeded() takes the lock
exclusive.
A test hook, swap_host_functions_for_test(), lets bcrypt_rng_test install
fake host functions: the fake generate call blocks until released, and
the fake close records whether a call was still running. The new case
fails twice with main's bcrypt_rng.cpp (hook only) and passes with the
fix.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
create_address_guard() made the page table that shaders translated with
--address-guard read through its device address with
VK_SHARING_MODE_EXCLUSIVE, though those shaders run on the direct and
the async-compute queue. The other buffers every queue reads are shared
by the device's queue families (DeviceState::share).
The create info now comes from address_guard::table_buffer_info(), which
shares it the same way (concurrent on two or more families, exclusive on
one), with a CPU test.
Found by kevincommits (#1608).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two bugs from kevincommits' finding in #1608 (item 2):
- module_name() and module_name_w() stripped the directory and then
added ".dll" when no '.' was left, so "" and a path ending in a slash
came out as ".dll". That passed every `dll.empty()` guard and went to
the bundled loader's lookups as a module name. Both now return an
empty name there.
- host_module_name() caches HMODULE -> module name for GetProcAddress on
host modules, and free_library() never removed the entry. A DLL loaded
later at the same base was then served the freed module's shims.
free_library() now erases the entry when FreeLibrary succeeds; a module
that is still loaded is looked up again on the next call.
New test library_loader_names: a fake bundled loader records the names
it is asked for, and a fixture DLL with no relocations at a fixed base is
loaded as wsock32.dll (a shimmed host module), freed, and loaded again
under a plain name at the same base. Both checks fail on main.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From kevincommits' finding (item 3) in #1608.
prepare() set up the clamp pass (vulkan_indirect_clamp.h) of an
ExecuteIndirect(DISPATCH) before it resolved the dispatch's compute pipeline.
When that pipeline was dropped (skipped on request, or async_build and still
building), the command was left out after its clamp was prepared and linked
into the list's shared work budget, and emit() then recorded the clamp pass
before skipping the dispatch. The pass claimed scratch and counter slots and
counted the dropped call's records against the list budget that every later
clamped draw and dispatch of the list shares.
The pipeline is now resolved first, so a dropped dispatch leaves prepare()
before any clamp exists. A pipeline left to PipelineCompiles is not dropped
later: a failed deferred build fails the list.
New CPU test replay_dropped_indirect_clamp follows the repro: a dropped
dispatch alone, before and between built ones, for skipped and async_build
pipelines. 10 checks fail on main; all pass with the change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From kevincommits' finding (item 4) in #1608.
- d3d12_com.cpp:
- ResourceBarrier: a count with no array fails the list (check(false)) instead
of reading through null, as WriteBufferImmediate does.
- Barrier: the same for a null group array, and for a group with barriers but
no barrier array (the three array pointers are one union).
- CopyTiles: a bundle is refused for reserved buffers too, not only for sparse
images; no copy is allowed in a bundle.
- submitted_calibration: vkGetQueryPoolResults asks VK_QUERY_RESULT_WAIT_BIT,
so the read cannot answer VK_NOT_READY.
- process.cpp:
- run_entry passes the entry point itself to the game thread instead of a
pointer to its own stack: another thread can end the run before the game
thread first runs, and run_entry's frame is then gone.
- __getmainargs/__wgetmainargs expand wildcards when `expand` is nonzero
(mode 2, as _configure_*_argv does) and fail on a null argc or argv.
Tests: d3d12_com_test (null arrays fail Close; counts of 0 and valid calls
do not), d3d12_buffer_tiles_test (CopyTiles of a reserved buffer in a bundle
fails Close), process_cmdline_test (expand 0 and 1, null argc/argv).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From kevincommits' finding on #1608 (item 4):
- SimpleVolume::SetMasterVolume, StreamVolume::SetChannelVolume and
StreamVolume::SetAllVolumes refuse NaN. They tested
`level < 0.0f || level > 1.0f`, which is false for NaN, and stored it.
One helper checks `level >= 0.0f && level <= 1.0f`, as
SpatialObject::SetVolume does.
- ISimpleAudioVolume's master volume and mute are kept under the client's
lock, like the channel volumes, instead of read and written bare.
- SpatialStream::Reset revokes every active object, as Microsoft's
reference for ISpatialAudioObjectRenderStreamBase::Reset says: each is
inactive, its type can be activated again, and queued ends are dropped.
The stream keeps a list of its live objects (not owned); an object
leaves it first thing in its destructor.
Not changed: ActivateSpatialAudioObject during an update pass. The
reference lists no SPTLAUDCLNT_E_OUT_OF_ORDER for it, and activating
objects inside a pass is the documented pattern (this file's own test
does it).
6 new checks in silent_audio_test fail on main and pass with the fix.
AI-assisted (Claude Code).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Four offline GDK shim gaps from kevincommits' finding on #1608:
- XStoreShowGiftingUIAsync (store slot 82) is offline_failure_async<82, 5>
like the other offline *Async slots, so a caller waiting on its block gets
an answer. The block is the 5th argument (storeContextHandle, storeId,
name, extendedJsonData, async), as in microsoft/XBOX-GDK-dotnet.
- XSpeechSynthesizerGetStreamData forwards a host stream
(LEONIDA_LOCAL_SPEECH=1) also when `used` is null; it is _Out_opt_. The
host provider is made once into a namespace-scope atomic instead of a
block-scope static on a title thread (the Wine guard issue this file
already avoids elsewhere). A test hook sets a fake host.
- XPackageMountWithUiAsync completes with E_ACCESSDENIED for the game's
own package, as XPackageMount refuses it, instead of
E_GAMEPACKAGE_NO_PACKAGE_IDENTIFIER. A block used again before its result
was read closes the earlier mount's handle; if the new run does not
start, the earlier mount keeps its place.
- XGameGetXboxTitleId skips a <TitleId> inside an XML comment, as
package_locales already does (the comment stripping is now shared).
New checks in xgameruntime_test, xgameruntime_store_test and
xgameruntime_offline_test: 5 fail with main's logic, all pass with the fix.
AI-assisted (Claude Code).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Slots 25 and 108 size a list from the PC form of its descriptions
(pc_resource_desc), which drops the title's layout word (0x100 | swizzle
mode). console_texture_layout read the layout from that PC form, so a
texture only the CPU fills was sized in XG's default mode instead of the
one the title named: a 64x64 BC7 texture in SW_64KB_S came out 4 KiB
instead of 64 KiB, a 32x32 RGBA8 linear texture 4 KiB instead of 8 KiB.
Pass the title's layout word to console_texture_layout in
console_placement and apply_console_placement, as the unordered-access
rule already does.
Found by kevincommits (#1608).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Gate 4-byte 0xC5 cross-instruction fusion in isa_jit_patch::patch_image behind
opt-in LEONIDA_ISA_FUSE_4B=1 (off by default) and document LEONIDA_ISA_FUSE_4B
in runtime/README.md.
- When LEONIDA_ISA_FUSE_4B=1 is enabled and mark_block_targets resolves a
RIP-relative target inside a non-executable data section, also scan
consecutive signed 32-bit Clang/LLVM table-relative jump-table entries
( arget_rva = tbl_rva + entry) within [beg_rva, end_rva) so fusion never
crosses a relative switch case boundary.
- Update isa_jit_patch_test to verify default non-fusion of 4-byte 0xC5 sites,
opt-in fusion under LEONIDA_ISA_FUSE_4B=1, and fusion refusal across both
image-base RVA tables and negative table-relative int32_t .rdata switch tables.
Add runtime/src/bmi_emulation.h and wire it into gta6rt and Loader::protect_sections
so pre-Haswell AVX1 + SSE4.2 CPUs (Intel Sandy Bridge and Ivy Bridge) can execute
the game's integer Haswell/ABM instruction delta:
- Decode and emulate VEX-encoded BMI1 (andn, bextr, blsi, blsmsk, blsr), BMI2
(bzhi, mulx, pdep, pext, rorx, sarx, shlx, shrx), and legacy 16/32/64-bit MOVBE
on STATUS_ILLEGAL_INSTRUCTION (#UD), using SEH-guarded non-inlined __movsb copies
so valid pages take zero syscalls while xmem first-touch, write-watched shadow
pages, read-only faults and unmapped faults behave like native accesses.
- Patch non-faulting legacy TZCNT (F3 0F BC) and LZCNT (F3 0F BD) before executable
sections are protected by walking .pdata functions and 0xCC-delimited leaf
routines: >=5-byte 32/64-bit register sites jump to branchless BSF/BSR + CMOV +
BT stubs within 2 GiB, and 4-byte, 16-bit or memory sites become UD2 (0F 0B)
backed by a side-table for the #UD handler (configurable via LEONIDA_LZCNT_PATCH).
- Add runtime/test/bmi_emulation_test.cpp covering decoding, synthetic CONTEXT
application, immediate byte-trap rejection, stub/UD2 flag consumers, and live
execution on hardware.
Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7181466437
AI-assisted: yes (Antigravity, Gemini 4 Carbon)
test_a_checkpoint_sees_a_demand_that_started_during_it checked its first
look (!has_compile_waiter()) inside the checkpoint job, after log.start.
The test thread woke on that log.start and submitted the demanded build,
so on a loaded machine the build could be queued or running before the
checkpoint's thread reached its first look, and the check failed (seen
1 in 64 runs with 16 copies running at once).
The job now records the first look and opens a gate; the test waits for
that gate (10 s limit, no fixed sleep) before it submits the build, and
checks the recorded look.
AI-assisted (Claude Code).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With LEONIDA_COMPILE_THREADS=1, a PSO's job that is not graphics waits while a graphics build of that PSO runs on
the graphics-only worker. The general worker has gone back to sleep by then, so only the graphics-only worker's
wake on return lets it go. Follow-up to #2233 (a test for the case its review named).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
display_white_worker() waited out its second with the predicate
"worker_stop_" only, so the notify effective_sdr_white_nits() sends on
the first HDR10 present ended no wait, and the first Windows SDR white
level was read up to a second late (found by djrolfes, #1608). A request
sent before the worker reached its wait was lost the same way.
The worker moves to leonida::DisplayWhiteCache (src/display_white_cache.h)
with a read_now_ flag, set under the lock with the notify and checked
by the wait, so the first get() is read at once. XboxPresentation holds
one, made last in its constructor and dropped first in its destructor,
as the thread was before. display_white_cache_test checks the first
read with a one-hour period, the periodic reads, a failed read keeping
the last value, and a prompt shutdown.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Loader::load_runtime_module_w (LoadLibraryW / LoadLibraryExW of a
bundled DLL) did not open a RuntimeLoadScope, unlike the narrow path and
resolve_module_export. The module was mapped as a static load, so its
DllMain(DLL_PROCESS_ATTACH) got a non-NULL lpvReserved. It now opens the
scope too.
Loader::initialize_tls patched an executable's /GA TLS reads and wrote
m.tls_ga_slot after it had published the slot owner and released
ExclusiveTlsLock, while a thread starting then reads m.tls_ga_slot in
install_thread_block under SharedTlsLock. The patch and the write now
happen before the owner is published.
loader_test checks the wide path's lpvReserved (fails on main);
loader_tls_index0_test checks that the noreserve executable gets its
/GA slot.
Found by kevincommits on #1608.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two gaps in mirroring title-backed descriptor heaps on the Xbox console path:
- Xbox device slot 61 (CreateSamplerX) created the sampler in the real heap only. Every other
descriptor creator and copier also stores the result at the title's address (local_write_through),
so a title that copies samplers out of its own heap memory read zeros. Slot 61 now writes through
as slot 22 does.
- local_mirror_table, run when a descriptor table is bound (list slots 35/36), checked the real range
with VirtualQuery even when it is a mapped range. Wine can report a live vkMapMemory span as
MEM_FREE, so on Wine the table was never mirrored. It now skips the check for a mapped range, as
local_write_through does.
From kevincommits' finding in #1608 (item 2). xs_proxy_mock_test gains check_descriptor_mirror, with
the mock's real heap pointed at memory.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From a review of the shim by kevincommits (#1608):
- ForceFeedbackEffect::SetParams accepted any kind, also one the motor
does not report, which CreateForceFeedbackEffect refuses. It now
refuses it the same way.
- A kind change through SetParams was sent to SDL as an update of the
existing effect, which SDL_UpdateHapticEffect refuses ("Updating
effect type is illegal"), so the effect stopped. The poll thread now
destroys the old SDL effect and creates one of the new type. The
test's fake haptics refuses a type change in an update, as SDL does.
- CreateForceFeedbackEffect and IsForceFeedbackMotorPoweredOn read the
motor count, features and haptic handle that open_pad and close_pad
write on the poll thread under g().mu, without the lock. They take
it now.
- GetControllerAxisState and GetControllerButtonState called memcpy
with a null buffer for 0 bytes. They copy only when there is
something to copy.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Four VulkanSwapchain bugs from a mock-driver review (kevincommits, #1608):
- A failed vkCreateSwapchainKHR still retires its oldSwapchain
(VUID-VkSwapchainCreateInfoKHR-oldSwapchain-01933). The retired
swapchain was kept, acquired from, and passed as oldSwapchain again.
It is now destroyed with its buffers, as the host's swap chain has no
buffers after a failed ResizeBuffers.
- When the off-screen back buffers could not be made, exposed_count_
kept the old BufferCount while there was no ring, so image() and
resource_binding() indexed the native images out of bounds. Nothing
is exposed until the new buffers exist. ResizeBuffers with count 0
still keeps the last built BufferCount.
- A surface the queue family cannot present to was kept, and the next
create() skipped the support check. It is destroyed.
- The present blit always used VK_FILTER_LINEAR. It is NEAREST for a
1:1 blit, and LINEAR only when the format allows linear filtering
(VUID-vkCmdBlitImage-filter-02001). The composite alpha is the first
one the surface offers, opaque first.
dxgi_swapchain_count_test gains one case per finding, following the
repros.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GraphicsCommandList::record_indirect for IndirectKind::dispatch_mesh
differed from DispatchMesh and the indirect DRAW/DRAW_INDEXED path in
three ways:
- it tested viewport 0 only, so a call with viewport 0 empty and
another viewport set recorded nothing; it now uses
any_nonempty_viewport();
- it did not set draw.viewports, so the replay drew with viewport 0
and scissor 0 alone; it now sets draw_viewports();
- it had no mesh_ok check, so a root signature larger than a mesh
shader's 16-dword window recorded; it is now a recording error, as
for DispatchMesh.
The root-window check and its direct-heap notes move into one helper
that both paths call. d3d12_mesh_test records each case; each check
fails with its part of the fix reverted.
Found by kevincommits on #1608.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review follow-up for #1564:
- Registration and the cleanup of exit, quick_exit and _cexit hold one recursive lock of the run's own, from before the thread-local callback through the table's drain (and _cexit's stream flush), as the UCRT holds its exit lock: two threads never clean up at once, and a registration from another thread waits for the cleanup. The exiting thread may still register from a handler, _cexit still returns, and the lock is released before the run ends (end_run), also when a handler ends the run from inside a drain.
- Each guest cleanup callback (atexit, at_quick_exit, the thread-local destructor callback) runs inside a C++ exception boundary: one that throws ends the run through game_abort, as the UCRT's terminate() would (exit code 3), instead of leaving the process with 0xE06D7363.
tiny_atexit gains four modes, held to the native sequence: concurrent_cexit (a second thread's _cexit, with a thread_local of its own, waits for the cleanup), quick_exit_register (an at_quick_exit from a second thread during a quick_exit drain waits, so its handler never runs), quick_exit_throw and exit_throw (exit code 3). In the concurrent modes the slow handler waits until the second thread is about to call, so the sequence is fixed under any scheduling with the lock. All four fail on c5b51e9 through --run.
The game's at_quick_exit() (_crt_at_quick_exit) and _register_thread_local_exe_atexit_callback still
reached the host CRT, which the game shares with gta6rt. Under `gta6rt --run`:
- quick_exit() ran none of the game's at_quick_exit handlers;
- exit() and _cexit() never ran the exiting thread's thread_local destructors, and a second
registration in the host's one-slot callback would terminate gta6rt.
Now _crt_at_quick_exit goes to a second table of the run's own, which quick_exit() runs newest first
under the exit lock; _exit() and _Exit() run none (they no longer share game_quick_exit). The thread-local
callback is the run's own: exit() and _cexit() call it with DLL_PROCESS_DETACH before the atexit handlers,
as the UCRT does, and a second registration aborts, as the UCRT's terminate() does. Both reset per run.
tiny_atexit gains five modes (at_quick_exit, at_quick_exit_exit, at_quick_exit__exit, thread_local_exit,
thread_local_cexit). Their expected sequences in check_atexit.cmake were measured by running the fixture
natively on Windows 11; before this change --run differed on at_quick_exit, thread_local_exit and
thread_local_cexit. run_tiny_atexit now holds 13 paths to the Windows sequence.