When released_backings or title_va_aliases().invalidations() advances,
refresh_console_heap() previously scanned all 32-byte slots of heap.copy
linearly to find live buffer V#s (!(w[3] >> 30) && (w[2] || w[6])). When
heap.copy sits in arena.mapped (uncached write-combined GPU memory), each
buffer release triggered ~180k uncached PCIe reads across a 5.5 MiB heap.
Add a portable host-RAM bitset (leonida::ConsoleHeapVsharpSlots in
runtime/src/console_heap_vsharp_slots.h) updated at every resource-heap
write to heap.copy (fix_console_slot, deferred fix_over zeroing,
for_each_zeroed, and add_console_heap reset), and iterate only live V#
slots during invalidation passes (0 reads from heap.copy; 64 slots skipped
per word via std::countr_zero).
Item: RT-CONSOLE-HEAP-VSHARP-BITSET
A boot ended with eight title threads faulting within a second. Each
entered the filter; the ones after the first returned at once and went on
to the title's filter, which can end the process during the write. The
write now runs under std::call_once, so they wait for it.
AI-assisted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The retail title calls SetUnhandledExceptionFilter (from
api-ms-win-core-errorhandling-l1-1-0), which replaced the runtime's filter:
a title fault at 354 s ended the process without the cache write. The
title's call is now served by the runtime, which keeps its filter
installed and passes the exception on to the title's.
AI-assisted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pipeline_cache.session.bin was written only in ~Device. A title never
releases its device, so a real boot kept none of what it compiled: not
after a normal exit, a console close or a crash, and every boot built the
world start again.
save_pipeline_caches_at_exit writes the session cache of every live device
(a registry the Device constructor and destructor keep), once per process,
after stop_pipeline_compiles. A build still running on another thread is
given wait_ms, then the previous file is kept, as at teardown. gta6rt calls
it at the run's exit, at a console close, and from an unhandled-exception
filter (a fault in the title or its DLLs, the int3 after a device loss),
which then passes the exception on, so the exit code is unchanged.
d3d12_compile_teardown_test's exit case checks that the file is written
with the device alive, and only once.
AI-assisted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A CopyTextureRegion of the depth plane from a D32_SFLOAT_S8_UINT image into a
D32_SFLOAT one was replayed as vkCmdCopyImage. Vulkan requires depth/stencil
formats to match exactly (VUID-vkCmdCopyImage-srcImage-01548), and the NVIDIA
driver (RTX 4070 Laptop, 621.40) wrote past the end of the D32 image: the
world-start WRITE_INVALID device loss, with the fault at the first byte after a
2560x1440 D32_SFLOAT image (VK_EXT_device_address_binding_report) and this VUID
reported by the validation layer just before the loss.
depth_format_pair: two depth formats with the same depth encoding but not the
same VkFormat (D32 / D32S8, D16 / D16S8, X8_D24 / D24S8) take the image ->
scratch -> image path depth <-> colour and A8 copies already use; the depth
aspect has the same texel layout in a buffer on both sides.
replay_copy_offset_test: the D32S8 -> D32 and D32 -> D32S8 depth-plane copies
are staged (no vkCmdCopyImage, depth aspect, 4 bytes a texel), and D32 -> D32
keeps vkCmdCopyImage. Fails without the change (6 checks).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fix edge-case arithmetic and boundary bugs in the title-memory window
planner and GPU address arena allocator:
1. runtime/src/title_window_plan.h:
- title_window_range(): reject va < lo (previously returned a range
starting at lo > va that excluded va, causing va - range.start to
underflow in resolve_title_memory), reject most == 0 (avoiding
std::clamp(want, 1, 0) UB), require power-of-two align, and avoid
UINT64_MAX - want - align unsigned underflow when computing end.
- title_pool_extent(): reject non-power-of-two align and unreadable
requests (readable_end <= va) before rounding end up to align, and
enforce the most cap after alignment rounding so out.size <= most
always holds and out contains va.
2. runtime/src/arena_blocks.h:
- Make align_up() overflow-checked so high alignments or keep_out_end
near UINT64_MAX cannot wrap to 0 and trigger an infinite loop in
ArenaBlocks::allocate().
- Guard against non-advancing keep_out_end <= start in allocate().
- Make consistent() safe against reserved_ > size_ underflow and
free_bytes_ + live_bytes overflow.
Extend runtime/test/arena_blocks_test.cpp and add portable
runtime/test/title_window_plan_bounds_test.cpp.
Item: RT-TITLE-WINDOW-AND-ARENA-BOUNDS
#1723's list values own list slots 71 to 74 of the lists they track and
hand 71/72 to the GPU-label path only for lists they do not track. This
keeps that, and keeps what #622 adds that #1723 lacks: landing a value
in the GPU address arena and on an xmem page the title's view refuses.
- LEONIDA_GPU_LABELS stays opt-in (`1`), as on main and in #1723.
- src/value_write_sink.h: one place for the two targets a host store
cannot reach, used by both writers. The device answers for the arena
(an address below its size that is not the title's memory, the rule
resolve_title_memory uses); xmem registers write_title_bytes for its
pages. Replaces #622's label-only sink and xmem's title_write_fn.
- The pump's land(): the arena is asked before any host store, so an
arena offset is never stored to as a host address; then
kernel_writes::store as before; then xmem's mapping when that store
faults. Counted as writes_arena and writes_title_pages.
- The arena refuses its reserved start (null region, zero page, quad
indices) and a write past its end, stores an aligned value in one
access, and is unregistered when its device goes.
- xmem's write_title_bytes stores an aligned value in one access.
- The label path keeps the same order for untracked lists.
Test, no game data: xbox_list_value_fallback. A tracked list's writes to
title memory land through the host store; to a default-heap buffer's
arena offset land in the arena (read back by a GPU copy); to the arena's
reserved start are dropped; to an xmem page the title made PAGE_NOACCESS
land through xmem's mapping. LEONIDA_GPU_LABELS=1 throughout, and no
write is handed to the label path. Without the arena step it fails at
line 168, without the xmem step at line 208 (llvmpipe and the iGPU).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflicts:
- runtime/README.md: #1723's LEONIDA_GPU_LABELS row (opt-in, only for
lists the list values do not track). The rows #622 changed are
brought in line with #1723 in the commits after this merge.
- runtime/shims/d3d12_vulkan_device.cpp: both sides. #622 tracks the
arena for the label path; #1723 resets the arena's block tree under
its lock and starts the arena after the null region.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Found by the comparison agent, not by a failing test. #1723's console
list slot path still handed slots 71 and 72 to main's GPU-label hook
(record_gpu_label, LEONIDA_GPU_LABELS) when its own list values track
the list (track_values, on by default with LEONIDA_LIST_VALUES). The
--first-run-ui profile sets LEONIDA_GPU_LABELS=1 (runtime/src/main.cpp).
With both on, two threads stored to one title address, one from a
Vulkan command buffer's completion and query, the other from the part's
fence and a D3D12 timestamp query. A late label could rewind a rising
counter or split a begin/end pair. The suite did not catch it:
xbox_gpu_label_completion submits its real list straight to the queue,
so only the label path landed there.
The list values are the right owner. They land slots 71 to 74 in
queue order behind the gates, and they also do the waits the labels
cannot do. Now:
- The label hook runs only for a list the list values do not track
(LEONIDA_LIST_VALUES=0, bundles). Each handoff is counted in
ListValueStats::labels_handed.
- The --first-run-ui profile no longer sets LEONIDA_GPU_LABELS.
runtime/README.md and docs/first_run_ui.md say so.
- xbox_gpu_label_completion runs its label section with the list values
off, as it always measured the label path alone, and checks that all
five writes went there. A new section turns both on and records one
write32 and one write64 on a tracked list, submitted through the queue
proxy. Each lands exactly once: writes_landed == 2, labels_handed == 0,
and the values are in memory. With the old condition this section
fails at line 136 (labels_handed was 2), on llvmpipe and the iGPU.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
d3d12_xmem_placed failed at line 113 (to_cpu(dst) == dst) and line 244
(independently_mapped(gpu, size)). #1723 added View::independent_pages,
the to_cpu branch and independently_mapped for a GPU-only range that
queue slot 31 maps by itself, but nothing ever sets the flag: xmem
calls note_reservation without it, so every pair it makes is the legacy
kind, read at its CPU view. Nothing in the runtime read
independently_mapped either, although its comment says a slot-133
buffer there must be a shadow, not an import.
Neither side is simply right. The tests express #1723's design, but no
rule exists for which of the title's pairs are independent, and none
can be inferred: marking every GPU-only pair independent (tried) breaks
main's xmem test, whose pair (attributes 0x23/0x3, protect 0x2004 then
0x801, two constant sets docs/xmem_exe_calls.md lists among the
title's sites) must read at the CPU view, and
would move where DirectStorage, slot-70 views and slot 31's CPU mirror
read and write in the game. That rule is left to #1723's author.
So:
- title_gpu_views::set_independent_pages(gpu) marks a pair. Nothing in
the runtime calls it yet, so the game's behaviour does not change.
- create_host_buffer declines an import over an independently mapped
range before making anything, as independently_mapped's comment asks,
and the shadow answers. On llvmpipe the import otherwise succeeded and
the twin was never guarded (line 264, seen with every pair marked).
- d3d12_xmem_placed marks its two windows. It now also checks that xmem
made them the legacy kind and that marking changes to_cpu and
independently_mapped. Everything after that (slot 31 remapping only
the GPU range, the CPU view untouched, the guarded twin, pins, host
and kernel writes) is checked as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both headers now include <windows.h>, and the test targets that reach them
through vulkan_replay.h (replay_uav_clear_offset_test first) do not define
NOMINMAX, so windows.h's max/min macros broke the std::max/std::min calls in
vulkan_replay.h ("expected unqualified-id") and the runtime's test build
failed. Guard the include the way vulkan_gpu_labels.h already does.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On an RTX 5070 Ti (NVIDIA 617.42) a 4,090 MiB arena-shaped buffer may use
the DEVICE_LOCAL | HOST_VISIBLE type and a 4,092 MiB one may not, so
LEONIDA_ARENA_MB=4096 (4,095 MiB, the workaround from #1537) placed the
whole arena in system memory: 4 GiB more host commit, and every
default-heap buffer read over PCIe.
With Resizable BAR, create_arena now tries 16 MiB smaller sizes, by at
most an eighth, and keeps the largest whose buffer may still use that type
(device_local_arena_bytes in arena_size.h). The cap is logged like the
other device caps. Without Resizable BAR nothing changes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Preserve physical window aliases across remaps, order console list values,
and replay bounded indirect graphics with captured draw state. Coordinate
pipeline lifetime, texture refresh and queue teardown. Add synthetic CPU
and GPU coverage for the integrated paths.
Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com>
Co-authored-by: ivanepsilondelta <264061546+ivanepsilondelta@users.noreply.github.com>
A PSO whose blend state uses a SRC1 factor gets its fragment module's Location 1
colour output moved to Location 0 with Index 1, as Vulkan takes the second
source. Slot 57 native PSOs now map the SRC1 factors of state blob A.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A library pipeline enables MAX on an R8_UINT target; the colour block bypasses
blending there, and D3D12 refuses the PSO.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main records the console's value writes (list slots 71 and 72) as GPU completion labels since #939. This widens where a completed label may land: the GPU address arena, and the pages the title maps, which main does not track and whose title view may be PAGE_NOACCESS for the CPU. The recording stays main's; the landing and the default are ours.
prepare() leaves the pipelines that are not built yet to PipelineCompiles, once per pipeline and variant. VulkanQueue::execute_now compiles them together on the device's workers with the resource lock held, places them in the prepared commands and then writes the command buffer, so every draw and dispatch has its own pipeline. A refused compile gives the result prepare() alone would have given. LEONIDA_PIPELINE_THREADS=0 keeps the path of before. Graphics pipelines of 1 MiB of SPIR-V or more and compute pipelines over 128 KiB compile one after another, and LEONIDA_ASYNC_PIPELINES keeps its own worker.
PipelineWorkers::run is a blocking parallel loop: the calling thread works on its own batch beside the workers, so a batch completes with no worker left and nothing outlives the call. CPU test: every job once and before run returns, no workers, exceptions, several callers, stop with jobs queued, and the LEONIDA_PIPELINE_THREADS text.
RADV checks the pages of a VK_EXT_external_memory_host import again at
every submission, and once one of them is read-only the kernel rejects
that submission and every later one. The slot-133 shadow trackers and the
geometry watch make copied title pages read-only to see the next write,
and a page can be both under a shadow and under a live import.
A new leonida::kernel_writes::hold pins a range until release() and opens
it. Unlike begin_write it records the pin when no opener is set yet (no
tracker exists), so a tracker made later passes over the pages too;
ShadowPages and the geometry watch already pass over pinned pages. The
slot-133 import (create_host_buffer) and the console descriptor heap
import take the pin before vkAllocateMemory, so no guard lands between
the writability check and the import, and end it on every path that
frees the memory: a declined or failed import and the release.
The finding and the design are NateWeav's (coordination issue #14,
comments 7141859164 and 7142359977); this implements their description.
As in their tree the pin is unconditional; a driver gate is not done.
Tests: kernel_writes_test checks hold and release on the pin set (no
opener, with an opener, alongside a file read's pin). d3d12_title_va_test
in its imports-on mode makes a shadow over pages, checks that its tracker
guards them, then imports the same pages and checks that two submissions
leave them writable, that the pin ends with the import and that the
tracker guards them again afterwards.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main now has its own device-fault report (LEONIDA_DEVICE_FAULT=1, from #984)
and #980's device-lost line, so this branch's vulkan_device_fault.h, its
report code and vk_device_fault_test are dropped in favour of main's.
What stays is the case main does not cover: a loss the driver shows only as
a timeline counter of UINT64_MAX. VulkanFence::completed() then asks
vkDeviceWaitIdle through observe_result, so main's report runs, and marks
the device lost when that returns VK_ERROR_DEVICE_LOST.
vk_fence_lost_by_counter_test is adapted to main's reporter.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
main already lays graphics root arguments out in the console layout (from s8, one dword per table: #939's
graphics-root-layout patch in #984's form, pack_stage(Stage::Pixel), RootArgumentLayout::graphics_console,
graphics_arguments_end, LEONIDA_GRAPHICS_STAGE_LAYOUT=0 for pack()). That form stays. What this pull request adds
beyond it is carried onto it: the mesh-shader root window (translator, index "root_window", mesh_ok, the two
refusals) and its tests. Its own graphics spill handling (Spill::block) and LEONIDA_GRAPHICS_ROOT_LAYOUT=pc are not
carried: main keeps pack()'s s0 layout for a graphics signature past s31, and its switch does what =pc did.
Conflicts:
- runtime/src/root_signature.h, root_signature.cpp: main's pack_stage (compute spill array, spill_dword); the
Spill enum, first_spilled and spilled_dwords dropped. The header keeps the PR's evidence note, with Stage::Pixel.
- runtime/shims/d3d12_com.h: main's comment and members, with the mesh window described; mesh_ok added (false by
default, set only for a console-layout signature that Stage::Mesh also places); the PR's second graphics_console
dropped.
- runtime/shims/d3d12_vulkan_device.cpp (CreateRootSignature): main's pixel/packed form; the PR's Stage::Mesh pack
and its log line added, mesh_ok = pixel.ok && mesh.ok. The mesh-shader refusal without "root_window" (no
conflict) stays.
- runtime/shims/d3d12_com.cpp: DispatchMesh keeps main's any_nonempty_viewport() and graphics_user_data() after the
PR's mesh_ok check; address() keeps main's comment. The PR's kNoSgpr guard in constants()/address() stays,
reworded: in main a spilled compute parameter has first_sgpr kNoSgpr, and kNoSgpr + offset wrapped round to s0.
- runtime/src/shader_library.h: both (main's wave64_graphics, the PR's root_window).
- runtime/test/d3d12_mesh_test.cpp: main's mesh shader-kind byte on both containers (also the PR's ms_old); the
PR's two-parameter signature replaces main's 25-dword padding onto the s0 layout; both test blocks kept (the
PR's window refusals, main's DISPATCH_MESH command signature), each in its own scope. The =pc case is dropped
(main's switch is read once per process).
- runtime/CMakeLists.txt (no conflict): the mesh test uses ps_draw.spv again; the ps_draw_s0.spv rule is gone.
- runtime/test/glsl/ps_draw.frag, vs_depth.vert, vs_draw.vert, vs_draw_int.vert, ps_depth_write.frag and
runtime/test/shaders/ps_m15, ps_m2, ps_m2_array, ps_m2_literal, ps_m2_uoff, ps_m3, ps_m3_post, ps_m3_query,
vs_m15, vs_m3 (.asm): main's (the same s8 rewrite done twice); ps_draw.frag's mesh-test note updated.
- runtime/test/root_signature_test.cpp (no conflict): the Spill::block cases dropped, the window cases kept.
- docs/design.md: main's rows (loop guard, direct resource heap) and the PR's user-data row.
- docs/d3d12_vulkan.md (no conflict): section 3.5 and the CreateRootSignature bullet rewritten for main's form.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The slot 57 native pipeline description is adapted from enx/leonida at 5c175db90 on the original author's git mirror. The header now says so with the commit, GPL-3.0-or-later as a fork of this project, what was changed as #939 describes it, and that the server could not be reached on 2026-11-25, so the source and its licence were not read there. Comment only.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
runtime/src/console_texture_layout.h, the second computer in runtime/shims/xg_xs.cpp and its test said GPL-3.0 for Marvisak/VIctory. The project is GPL-3.0-or-later, and the notices now also say that the code was translated from Rust to C++ and changed for Leonida. docs/runtime_imports.md follows. Comments only.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
graphics-root-layout, descriptor-table-refresh, descriptor-write-through and sampler-table-refresh of Sigtryggur-Mani-Gudmundsson/graphics-runtime-patches are in #939 almost as published, about 390 lines, and only one sentence of docs/first_run_ui.md said so. That sentence now names the four, their licence and author and the files they are in, and each code region carries a comment naming its patch. Comments and one doc paragraph only.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A completed label was stored only into a page that was read-write at that moment and dropped otherwise. The
base makes title pages read-only while a shadow or the geometry watch waits for the title's next write, so a
label for such a page was lost, and a title that waits for a completion label then waits for ever. The store
now announces the write the way a kernel write is announced (kernel_writes::begin_write): the layer opens the
pages it guards and copies them again at its next refresh. A page that is still read-only after that is the
title's own doing and the label is dropped as before; so are guard, no-access and decommitted pages and a
released allocation. The store moves out of the class as label::store_value so that it can be tested.
gpu_label_store_test (CPU only, registered as gpu_label_store) covers each of those cases with a stand-in for
the layer's opener.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
run_tiny_first_run_ui clears two variables by passing them empty. Windows cannot hold an empty variable, so there they are unset; under Wine they exist, and the profile's size-only query reported them as set and kept them. The test failed that way on #939's head too. The profile now reads the first character, so an empty value gets the profile's default on both.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The merge had taken the base's process-wide scan hook (title_va_aliases), which belongs to the first device that registered. A second device over the same GPU then had its tables scanned by the first: d3d12_rebound_second_device, a test of #939, failed on it. #939 scans through the context of the device (VulkanContext::set_table_scanner), which the merged device still registers. That one is asked first now and the process-wide hook serves a context without a scanner.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The base's early return for such a target came before #939's lines, so Format::rgba4_render_fallback was never set: #939's pixel-shader quantisation ran (it keys on the pipeline), its clear quantisation and its refusal of footprint copies did not. The flag is set now, so a clear stores what a draw would. The refusal of footprint copies is not taken as the default: the story-load boots of #984 ran with those copies made; LEONIDA_RGBA4_COPY_REFUSE=1 gives #939's refusal. Neither test device here lacks a 4444 colour attachment, so this path is exercised only on a GPU that does (NVIDIA).
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Fourteen commits the #984 merge gained after 8a242efeb: its own failing tests (xmem_test under Wine, check_tls_index0, vk_bindless_grow, xs_present_lazy_test), the console-heap probe and the poke experiment behind their switches, Python tool fixes, and the title watchdog default. No conflicts.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The retail title runs its own hang watchdog: when the game's main loop has
not reported for 30 seconds, it ends itself. #984 kept that watchdog from
firing by default, because under the runtime the game thread can wait
longer than that, for example while the driver compiles pipelines on the
first boot after a driver update.
By the maintainer's decision the watchdog now stays armed by default, as on
the console, so a real hang still ends the run. LEONIDA_TITLE_WATCHDOG=0
turns on the runtime thread that keeps it from firing; as before, it only
acts in the build the watchdog was measured in. The README's environment
table and the log line say the same.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>