Commit Graph

4696 Commits

Author SHA1 Message Date
690dea5193 Merge pull request #2220 from MoonEyes/feat/pipeline-order-recorder
runtime: record the order of first pipeline requests (LEONIDA_PIPELINE_ORDER_LOG=1, RT-PIPELINE-PREWARM-ORDER phase 1)
2026-11-27 13:43:04 +01:00
1d7c662b4b compile gate: auto default, calibrated at device creation
With LEONIDA_COMPILE_GATE unset or `auto`, the device measures the driver once
before the VulkanContext exists: a worker creates a synthetic compute pipeline
(SPIR-V written in code, new specialization seed each run, no pipeline cache)
while the queue gets empty submissions waited on a fence. Quick submissions with
the create still in the driver give the adaptive gate; a held one, a create too
fast to tell, an unexplained slow submission or any failure give classic. The
verdict is cached per vendor/device/driver/pipelineCacheUUID in
compile_gate_calibration.txt beside the pipeline cache;
LEONIDA_COMPILE_GATE_RECALIBRATE=1 measures again. Only the title process
calibrates; build hosts and tests keep classic. `classic`, `adaptive`, `1`, `0`
still force a mode.

Tests: compile_gate_policy_test (no GPU: settings, NVIDIA version decode,
verdicts, cache file, SPIR-V shape) and vk_compile_gate_calibration_test (GPU:
a verdict within 20 s, adaptive on NVIDIA 621.40).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 13:24:49 +01:00
ad1789d7e9 Merge main into mesh-serial-waves
docs/design.md: keep the new row and take main's text of the row below it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-27 20:11:21 +08:00
78a5eab40a d3d12: single-worker owner check written as in #2361
qhukz13 claimed and fixed the same race for main in #2361
(RT-COMPILE-OWNER-RACE). The single-worker branch of next_locked now uses
their code line for line, so whichever of the two lands second merges
trivially. The pool branch is as before 9b8760d32. No behaviour change;
d3d12_compile_pool_test passes 5 of 5 repeats.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 05:56:51 -06:00
e578518c8f check_module_names: mock _is_windows instead of global os.name for Linux CI 2026-11-27 19:56:25 +08:00
4ca6d97a8c check_argv_modes: mock _is_windows instead of global os.name for Linux CI 2026-11-27 19:56:00 +08:00
ebdc991627 compile gate: the held check on every pass of the wait, and presents never use the probe budget
Second review on #2412:
- enter_submit no longer switches to the held limit for good once it sees a create of a kind that holds
  submissions: each pass checks held_blocking(). With one in the driver the held limit applies on its own (also when
  it is under the plain limit) and the budget is off; without, the plain limit and budget apply, so a submission
  goes ahead at the plain limit once the holding create left while a create of a kind with no verdict stays. The
  "reached the limit, but ..." notice comes once per wait, and the wait wakes when a holding create leaves.
- SubmitTurn passes `probe` into enter_submit: a present or wait never goes ahead at the probe budget, only at the
  limit.
- VulkanPresenter::submit's turn does not probe (it covers the startup frame's fence wait and the present); the
  nested queue_submit turn still probes the vkQueueSubmit alone.
- submit_mutex_test: gate_second_review covers the four cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 12:46:36 +01:00
8f59df0fb0 Merge remote-tracking branch 'upstream/main' into claude/rt-async-compile-pool
# Conflicts:
#	docs/d3d12_vulkan.md
2026-11-27 05:46:06 -06:00
b0712ff2ce Merge test/round2 into heaps-in-place: per-piece sums and the T# index word for heaps read in place
title_mirror.h: a filtered page's sums per 256-byte piece are of the title's bytes (title compared with title); the
filter runs after that compare, only when a piece changed or the home is fresh, and writes the home. write_back skips
a filtered home, so page_mirror_write_back takes TitleMirror::write_back as is. A home leaving its filter is copied
whole once.

The T# index word (tsharp_index_word) is written by finish_in_place into the home's dword 6 once the T# is bound; the
filter leaves 0 (the fallback) there meanwhile, so the title's own dword 6 is never read as an index. Copy-path heaps
keep fix_console_slot's write. d3d12_heap_in_place_test checks a T# slot reads the tag and index while the title's
bytes keep their dword 6; title_mirror_hooks_test checks write-back skips filtered homes and the filter is not called
again for unchanged title bytes. set_tsharp_index_words_for_test for the test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 06:39:35 -05:00
3c9820f8da Local test merge: bindless index in dword 6 of heap T#s, read directly by placed operands (be3e9c142)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-27 06:27:01 -05:00
23c3341196 Merge branch 'test/round2' into heaps-in-place: heaps read in place under the mirror's B and C steps
With the mirror's steps B and C (title memory resolved to heap_base + its address, ordinary memory mirrored when a
reader names it, the write-back of GPU stores from the homes, a separate bind flush), the in-place filter changes:

- Lock order console_heap_mutex, then page_mirror.mutex, then slot_change_mutex. vsharp_address's mirror path takes
  the mirror's lock under console_heap_mutex now, so the filter, which runs inside the mirror's fills, takes no other
  lock of ours: the in-place heaps' filter state is under the mirror's lock (page_mirror.in_place), and the mirror's
  refresh no longer takes console_heap_mutex. Under the lock the filter does only reachability (arena, a buffer of
  ours, or the mirror through page_mirror_resolve_locked, which names ordinary memory as any reader does), nulls and
  the list of what is left: a V# the mirror does not hold and a T# to bind are finished in the heap's refresh
  (finish_in_place), outside the mirror's lock, and written into the home unless the title rewrote the slot since.
  The change list is taken under the mirror's lock when a heap is read in place, so the entries it has not read stay.
- No write-back from a heap read in place: page_mirror_write_back skips filtered pages (TitleMirror::filtered_at), as
  their homes hold the filtered slots, not the title's bytes.
- The heap's pages are named to the mirror when the heap is made (ordinary memory is mirrored then), after its
  filter range and its second binding are set. The binds go in flush_page_mirror's batch.

d3d12_heap_in_place_test also checks that a GPU store into the heap's pages is not copied back over the title's
bytes; title_mirror_hooks_test checks filtered_at.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 06:21:29 -05:00
be3e9c1424 descriptors: the T# index word in the contract table, README and translator source lists
docs/design.md states what the pack and the runtime agree on (the tag 0xA << 28, index 0, how an older pack is
recognised) with the counts; runtime/README.md says what LEONIDA_CONSOLE_HEAP_GPU does with an index-word pack;
make_game.py and runtime/cmake/translator_deps.cmake list the translator's new imports (descriptor_sources.py,
heap_index_census.py), so a pack and the test shaders are made again when they change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 06:20:53 -05:00
16245b98b2 Merge remote-tracking branch 'upstream/main' into claude/pipeline-prewarm-order
# Conflicts:
#	docs/d3d12_vulkan.md
2026-11-27 05:20:16 -06:00
ee81c0e4a0 compile gate: builds outside MSVC, and the classic gate stays the default
- CreateKind, CreateInfo and GateAhead move out of SubmitMutex to namespace scope (CompileGateKind,
  CompileGateCreate, CompileGateAhead), with using aliases so SubmitMutex::CreateInfo and the rest still work:
  clang and GCC reject a `= {}` default argument of a nested class with default member initializers inside the
  enclosing class (review on #2412).
- LEONIDA_COMPILE_GATE unset is the classic gate again, as on main: compute creates only, no limit, no probes;
  graphics creates do not pass it. The adaptive gate is LEONIDA_COMPILE_GATE=adaptive: on a driver that holds
  submissions (630.20) its first probe of a kind enters the driver after the 2.5 s probe budget and loses the
  device if that create stays 10 s more, which the classic gate waits out. `1` and `0` are unchanged.
- submit_mutex_test: a classic-gate case (a graphics create holds nothing back, a 3 s compute create is waited out
  with no verdict), the adaptive cases opt into graphics gating; passes unset, with `adaptive` and with `1`.
- README rows and docs/d3d12_vulkan.md say so; the "held verdict 2 s into the probe" wording is corrected (it comes
  when the probe returns, and the probe holds the submit lock until then).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 12:20:11 +01:00
5cf7f89886 page mirror: the XMemAlloc heap in the mirror's range; pages written on both sides merged at the 256-byte piece (RT-PAGE-MIRROR)
The XMemAlloc heap (src/title_heap.h) is the runtime's own over a 32 GiB reservation that xmem places in the
mirror's range. It does not use RtlCreateHeap over a given base, which faults under Wine. Size classes of 64 bytes up
to 1 KiB, then powers of two up to 32 KiB, in 1 MiB spans. Larger blocks are runs of 64 KiB pages, committed when
handed out and decommitted when freed. Freed blocks are kept on lists outside the title's memory, and one lock covers
every call. Committed pages are fed to the mirror as they are committed, so a pointer the title writes into a block
reads the block's bytes without anything naming the range first. The title sees the same as before: 64-byte
alignment, size 0 as 1 byte, and XMemFree of a block from either entry point. When the range is full, blocks come
from the host's heap as before. With LEONIDA_TITLE_HEAP=0 they come from the CRT.

Pages written on both sides: each home keeps a 64-bit sum per 256-byte piece of what both sides last agreed on.
- An upload copies only the pieces the title changed, so a piece only the GPU wrote keeps the GPU's bytes.
- Write-back copies only the pieces the GPU changed while the title's piece still matches the sum.
- A piece both sides changed keeps the title's bytes and is counted.
The mirror's 10 s line gives uploaded and written-back KiB per submission and per frame, and the count of pieces
written on both sides.

Tests:
- title_heap: classes, large blocks, and 20000 random allocations and frees checked against a reference.
- d3d12_page_mirror part 7: one page, the GPU writes piece A and the title piece B in one window, and both survive.
- d3d12_page_mirror part 8: the GPU reads XMemAlloc blocks through pointers nothing named, and a freed large block
  reads zero.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 06:18:52 -05:00
74bfb7d070 Merge branch 'test/round2' into tsharp-index 2026-11-27 06:17:53 -05:00
26e0830184 descriptors: T# index word follows SGPR spills and VCC, deferred views and replaced entries; unknown-source T#s probe only without the word
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 06:17:16 -05:00
916868ebe0 Merge remote-tracking branch 'origin/main' into window-retire-on-1920
# Conflicts:
#	runtime/CMakeLists.txt
#	runtime/test/d3d12_title_va_test.cpp
2026-11-27 12:11:50 +01:00
c4261506b3 Merge remote-tracking branch 'upstream/pr2220' into claude/pipeline-prewarm-order
# Conflicts:
#	runtime/CMakeLists.txt
2026-11-27 05:11:17 -06:00
ba32cd6acf d3d12: a console resource heap the page mirror holds is read in place: no copy, its pages filtered as they are filled
When every page of a console CBV/SRV/UAV heap lies in the page mirror (a reservation xmem placed in its range),
add_heap_in_place gives it no copy and no page tracker of its own. 25,865 of the corpus's 26,503 shaders keep 32 bits
of a descriptor-table pointer, so the heap's pages are bound a second time into the arena below 4 GiB
(TitleMirror::alias, same bind batches and wait as the mirror's), at a range of whole arena blocks with no arena
memory behind it (arena_reserve_unbacked); the null slots after the heap are that range's rest, unbound, reading
zero. Table pointers go there as before (console_heap_ranges).

The mirror fills the pages' home through filter_heap_page (TitleMirror::filter_range): the title's page is only
read; a slot whose bytes changed since it was last filtered, or that a change touched (the records' change list,
applied at the mirror's refresh before the written pages are filled, filtered straight into the home), is fixed as a
copied slot was, into the home: a V# whose base lies in the arena, the mirror or a buffer of ours stays as the title
wrote it (reachable_as_written, no record); another V# is resolved as before (an interim until every title allocation
is in the mirror) or written with no base and no records and waits; a T# is bound as before [TSHARP-INDEX: its
bindless index in the entry]; other words are null. A GPU write-back is never taken from these pages: the mirror has
none, and no window is made for them.

A heap the mirror does not hold (a device without the mirror, memory outside its range) is copied as before. New
log line per in-place heap: pages filtered and slots changed per submission and per frame, the ms, and the V#
halves read as the title wrote them. arena_gpu_read reads the arena with the GPU after the mirror's last bind
(tests).

Test: d3d12_heap_in_place_test (Wine, iGPU): a heap in physical pages of an XMemVirtualAlloc reservation; the GPU
reads, below 4 GiB, a V# into nobody's memory and a data word null and V#s into the arena and the mirror as written,
while the title's bytes stay as written byte for byte; a rewrite through the title's own view reaches the GPU at the
next refresh, filtered, and the title keeps what it wrote; the null slots read zero. It fails on the copy path. Linux
ctest 123/123.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 06:05:33 -05:00
4aca5032f8 Merge branch 'claude/rt-async-compile-pool' into claude/pipeline-prewarm-order
# Conflicts:
#	runtime/CMakeLists.txt
#	runtime/README.md
2026-11-27 05:05:06 -06:00
054cbe0f3d Local test merge: geometry, slot-133 buffers, title windows and pool extents on the page mirror; hot/cold tracking; homes by memory budget (edb0f8502, 0cdc80d20)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-27 06:04:05 -05:00
2a191041ff d3d12: a console heap's V# words are fixed once a pass, not once a slot (RT-CONSOLE-VSHARP-MEMO)
The title writes the same words into thousands of slots of its console
descriptor heap, many of them data that reads as a V# into title memory
with no copy, and each fix_vsharp of those costs VirtualQuery calls: a
third of the submitting thread's time after the story load under Wine.
refresh_console_heap now keeps fix_vsharp's answers for the pass over the
copied slots and, separately, for the pass over the slots the changes
since the last submission touch, and drops them after each.

Retail boot, Proton, RTX 3090, 900 s: heap refresh after the story load
107.8 -> 18.8 ms a submission (max 5,332 -> 1,109), submissions after it
1,977 -> 2,527.

AI-assisted; tested under WineHQ 11.22 and GE-Proton11-14 on an RTX 3090
(NVIDIA 590.48.01).
2026-11-27 13:01:19 +02:00
897026d2b9 Local test merge: submit frame and submit floor lines (adc74d5d6, c1f573212)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-27 05:59:34 -05:00
c1f573212b submit_frame_test: the contended lock is taken and released on its holder's thread
Unlocking a mutex on another thread is undefined; MSVC's runtime throws, and under
Wine the test stopped on msvcp140's missing _Throw_Cpp_error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 05:59:18 -05:00
0cdc80d207 d3d12: slot-133 buffers, title windows and pool extents onto the page mirror; GPU writes into mirrored pages go back; hot/cold tracking; homes by budget (RT-PAGE-MIRROR)
Step C, with the previous WIP commit.
- Resource::create_mirror_buffer: a slot-133 buffer over title memory the mirror holds in one chunk is bound to that
  chunk at heap_base + its title address: no import, no shadow, no per-submission walk or guard of its own. Its GPU VA
  is the title address; V#s and root views naming it keep that address. Title windows and stream-pool extents are not
  made for mirrored memory (resolve_title_memory answers the mirror first, since step B).
- Write-back (DeviceState::page_mirror_write_back, from write_back_titles after the reaching submission retired): the
  256-byte pieces whose home differs from the title's page are written back through kernel_writes, on pages nothing
  wrote since they were last armed (TitleMirrorTracking::unwritten); a page written on both sides keeps the title's
  bytes, which are uploaded over the home before the next submission. Ranges are noted (note_title_write, with its
  caps) where a V#, a writable geometry range, a title-memory resolution or a BVH range is answered by the mirror.
- The mirror's tracking is HotColdTracking (src/title_mirror_hot_cold.h); it now answers unwritten() for cold pages
  from the version its guard was armed at (an additive change to that file and to the interface, default false).
- Homes go to device-local memory while VK_EXT_memory_budget keeps 1.5 GiB (or an eighth of the budget) for the
  title's textures and render targets after a unit, to host memory otherwise, decided per 32 MiB unit and logged when
  it switches; the mirror's line and the mem-probe item count units of each kind.
- The mirror's line adds hot and cold pages, write faults, hot and cold copies, and KiB uploaded a submission and a
  frame.

Not moved: the XMemAlloc heap (HeapCreate places it). RtlCreateHeap over a reservation in the mirror's range faults
under Wine (it writes the reserved base), so it stays outside the mirror; slot-133 buffers there keep their shadows.

Tests: d3d12_page_mirror_test (Wine, iGPU): a slot-133 buffer over mirrored memory has the title's address as its GPU
VA and is no shadow; a GPU write into its home goes back to the title's page (one 256-byte piece), a page written on
both sides keeps the title's write. Linux ctest (llvmpipe) 122/122; xmem_test OK.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 05:56:53 -05:00
08647217ea Merge origin/main into fix/compile-gate-bounded
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 11:55:03 +01:00
03ec559ac1 d3d12_compile_pool_test: wait for an idle pool before the checkpoint test's last check
The demanded job leaves the running list only after its function returns,
so has_compile_waiter() could still see it right after the log said it had
finished (1 failure in 10 runs). Found while merging this into #2275.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 04:54:43 -06:00
721e56f423 Local test merge: v_dot4 as packed integer dot products; one bounds check and wide loads for s_buffer_load (0513e00b0, 2e5498014)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-27 05:50:10 -05:00
c741bd6dab Merge remote-tracking branch 'upstream/main' into console-heap-gpu-overflow-and-rollback 2026-11-27 04:50:08 -06:00
f950eaae8f Merge branch 'test/round2' into page-mirror 2026-11-27 05:49:06 -05:00
4f00daef50 WIP: step C (slot-133 buffers on the mirror, write-back of mirrored pages, XMemAlloc heap placed)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 05:49:06 -05:00
0513e00b07 rdna2spirv: the 4x8-bit dot products as SPV_KHR_integer_dot_product
v_dot4_i32_i8, v_dot4c_i32_i8, v_dot4_u32_u8 and v_dot4c_u32_u8 become one
OpSDot / OpUDot on the packed bytes plus OpIAdd for the addend, and
OpSDotAccSat / OpUDotAccSat under clamp (both saturate the addend plus the
exact sum, as the hardware does). op_sel halves are put together into one
dword first. RADV did not re-form v_dot4 from the old expansion (four
extracts, multiplies and adds each), which made the FidelityFX upscaler
passes ALU bound.

--integer-dot-fallback keeps the expansion for a device without
shaderIntegerDotProduct (required by Vulkan 1.3): vk_subgroup_info.py
reports integer_dot_product and make_game.py turns the flag on where it is
false. The runtime and vk_pipeline_check enable the feature where the
device has it; the interpreters of the semantic tests run the new ops.

Tested: tests/semantic/test_packed_dot4.py (new fixtures), the translator
suite, tools/dot_diff.py on the four ops, a wave32 GPU program on the
Radeon iGPU (gfx1036) and the RX 7900 XTX against the gfx1036-measured
words, RADV statistics of the upscaler passes (docs/design.md row).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 05:48:33 -05:00
63185f4a35 Merge pull request #2432 from OreoFR/rt-xgamesave-trace
xgameruntime: LEONIDA_TRACE_XGAMESAVE logs every XGameSave call
2026-11-27 11:48:10 +01:00
d071531bc8 Merge pull request #2440 from OreoFR/rt-async-large-only
d3d12: LEONIDA_ASYNC_MIN_BYTES, only large pipelines asynchronous (RT-ASYNC-LARGE-ONLY)
2026-11-27 11:47:57 +01:00
e2377070d3 GPU tests: give cs_pk_mul_lo_const its 128 words, keep the exit message of a dump row
cs_pk_mul_lo_const runs 32 lanes that each store 16 bytes, 128 words, but
run_gpu_tests.py and check.py ran it without VKC_OUT_WORDS, so
vk_compute_test gave it the default 64 and lanes 16-31 wrote past the
buffer through its device address (GPU-AV:
VUID-RuntimeSpirv-PhysicalStorageBuffer64-11819). Both runners now pass
VKC_OUT_WORDS=128 (check.PK_MUL_LO_ENV), and the fixture's Run line
says so.

run_gpu_tests.py's dump rows (the bounds group, cs_heap_init,
cs_user_sgprs) showed the printed words whenever there were any. A run
that printed the right words and then exited non-zero (validation
errors) was a FAIL that showed only the expected words. dump_result now
reports "exit N: <output>" for a non-zero exit.

Found by kevincommits in the coordination issue (#1608).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 04:36:05 -06:00
edb0f8502f d3d12: geometry onto the page mirror: V#s, root views, stream-pool ranges, BVH ranges and draw bindings of mirrored title memory name heap_base + the title address, no copy (RT-PAGE-MIRROR)
Step B. Where the page mirror holds a title range, every reader takes the title's address as its shader VA (heap_base +
address is the mirror's chunk), so no geometry copy, pool extent or title buffer is made for it:
- vsharp_address (title memory, after the alias table: slot-133 buffers keep their shadows until step C),
  geometry_va, resolve_title_memory (before pool extents and windows), copy_title_range, make_title_buffer (vertex and
  index views), device_reachable;
- VulkanContext::buffer_at falls back to the mirror (set_mirror_buffer): a vertex, index, copy or indirect binding of a
  mirrored title address is its chunk and offset, cut at the chunk's end (counted).
Ordinary memory is mirrored when a reader first names it (page_mirror_resolve: each page its own home, watched, then
filled; at most 256 MiB not yet mirrored at once, else the old backing), and leaves on release or decommit
(geometry_writes::note_released). xmem also places the title's own VirtualAlloc reservations in the mirror's range, and
records which reservations are ordinary memory. The binds go in one batch at the end of the before-execute hook
(flush_page_mirror), after every reader of the submission has named what it reads.

The geometry copies remain only for title memory outside the mirror (the XMemAlloc heap) and on devices without the
mirror (llvmpipe). The mem-probe breakdown line has a "page mirror" item: units allocated, homes bound, pages
mirrored, chunks; the mirror's line counts ranges resolved, refused, ordinary pages mirrored and released, and
bindings cut; the console heap line counts V#s resolved into the mirror.

Not here: write-back of GPU writes into mirrored pages to the title's pages. The geometry copies these readers used
had none either (only slot-133 shadows do, and they stay until step C), so nothing is lost; the per-page rule for
pages dirty on both sides comes with step C.

Tests: d3d12_page_mirror_test (Wine, iGPU): committed XMemVirtualAlloc memory named by a constant-buffer view keeps the
title address as its V# base, the GPU reads it and a later title write there; a binding of it, and of a GPU-only pool
page, is served by the mirror's chunk; a page named on its own is mirrored. memory_breakdown_test: the new item.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 05:25:43 -05:00
872a8cf417 descriptors: a heap T# carries its bindless index in dword 6; shaders read it there instead of probing the hash table
On the console a texture access loads the T# and samples. Translated shaders hashed the eight T# words and probed up
to eight slots of the descriptor table for every access: 62 lookups and 19,714 RADV instructions in the tiled-lighting
pixel shader (3,080 in the native program).

The layer now writes the index into dword 6 of every T# in the heaps shaders read, as TAG 0xA [31:28] | storage kind
[27:23] | sampled kind [22:16] | index [15:0] (gfx10_descriptors.h, tsharp_index_word): the console resource heap
copies (fix_console_slot, again whenever the texture at the T#'s address comes, goes or is replaced) and its own
shader-visible heaps (write_image_descriptor, refreshed for bound tables by scan_title_table). The title's bytes and
the T#'s table key keep the title's dword 6.

The translator (tools/descriptor_sources.py, Gen.tsharp_index_sgpr) follows the SGPR dataflow and takes the index from
dword 6, with no lookup, for every T# whose dword 6 it traces to a heap slot (an s_load from a 32-bit descriptor-table
or heap pointer in user data); index 0 unless the word has the tag and dword 3 names an image. Other T#s are looked up
and prefer a tagged word. S#s keep the lookup (sampler heaps are read in place; 40% are literals).

Over the 1.0.2.1 corpus (tools/descriptor_source_census.py) 438,353 of 439,415 T# operands (99.76%) take the word and
17,432 of 17,540 modules keep no T# lookup; no scalar instruction reads dword 5-7 of a heap T#. RADV on an RX 7900 XTX,
lighting shader: instructions 19,714 -> 17,568, latency 73,690 -> 32,458, inverse throughput 16,453 -> 7,468.

Modules record "tsharp_index": "dword6"; the runtime writes the word when the library's modules read it, so packs
translated before keep working as they did. LEONIDA_CONSOLE_HEAP_GPU's pass copies T#s as written, so such a library's
console heaps are fixed on the CPU.

Tests: tests/semantic/test_tsharp_index_word.py (interpreter and dataflow), gfx10_descriptors_test, shader_library_test;
ps_texture_sample and ps_table_fetch now load their T# through a table pointer and vk_texture_test writes the word
(integrated GPU, RADV).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 05:20:52 -05:00
e5401bd62d Merge remote-tracking branch 'upstream/main' into claude/rt-async-compile-pool 2026-11-27 04:20:00 -06:00
9b8760d328 d3d12: one build of a PSO at a time with one worker plus the graphics worker
With LEONIDA_COMPILE_THREADS=1 (the layout of main: one general worker and
the graphics-only one) next_locked did not look at the owner, so two variants
of one graphics PSO could build at once, one on each worker. A last Release
meanwhile hands the PSO's deletion to the running build it finds first
(after_running), and that worker deleted the PSO while the other was still
in build() on it. The single-worker selection now skips a job whose PSO has
a build running, as the pool already did.

New test in d3d12_compile_pool_test: two graphics variants of one PSO with
one worker plus the graphics worker; the second must not start while the
first runs, another PSO's build still uses the free worker, and a last
Release runs after the first build with the second dropped. It fails
without the fix.

Docs: the heavy count also bounds LEONIDA_SERIAL_BIG_COMPILES=0 on the
workers; only compute creates pass the compile gate.

Found by qhukz13 in review of #2233.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 04:19:53 -06:00
adc74d5d65 runtime: per-frame CPU line and the floor of an unchanged submission, beside the submit phases line
Two always-on lines every LEONIDA_SUBMIT_FRAME_SECONDS (10 by default, 0
off), from the counters the phase line already keeps and a few more:

[rt] submit frame: frames presented and, per frame, the submissions by
queue kind and the milliseconds the title's threads spent in the layer:
the existing phases counted per frame instead of per submission, plus
what the phase line leaves out - ExecuteCommandLists outside the phases
(list unwrapping, the console's list-value waits and writes, the queue
lock), the queues' Signal and Wait, and the present. Inside those, the
vkQueueSubmit calls and waits for contended submission-path locks are
given apart. Then the window's worst frame and the time of our own
threads per frame: the submit worker (LEONIDA_SUBMIT_ASYNC), the texture
read threads and filler, the console heap resolver, the geometry
refresher, the list values' pump and releaser, the fence callbacks.

[rt] submit floor: how many submissions changed nothing (no heap slot or
page, shadow page, geometry, texture fill or pipeline build), their
average and least cost and their phases, against all submissions.

Title calls are timed once, at their outermost entry, less the phases
inside them; a WorkerScope marks our own threads so their phases are not
counted as the title's. A frame ends at each present the presenter takes.

submit_frame_test checks a scripted run on the CPU (frame sums, title and
own threads, worst frame, floor) and, with a Vulkan device, that the floor
of 20 empty submissions through VulkanQueue sums to exactly what the
phase totals grew by.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 05:19:48 -05:00
b4a6c3673a page mirror: a range's pages bound at a second address, and a filter on the fill path (for heaps read in place)
Two additive hooks in src/title_mirror.h for console descriptor heaps read in place; nothing changes for a mirror
that uses neither.

- alias(lo, hi, buffer, offset) / unalias(lo): the pages of [lo, hi) are also bound into `buffer` at offset +
  (va - lo), follow their remaps and unmaps, and go in the same bind batches as the chunk binds, so the one wait
  (VulkanContext::note_mirror_bind) orders a reader of either address. A heap uses it to be read below 4 GiB of the
  arena, where 32-bit descriptor-table pointers reach. Pages not mapped stay unbound there and read zero.
- filter_range(lo, hi) / unfilter_range(lo) and TitleMirrorHooks::filter: the home of a page in a filtered range is
  filled through the filter (the title's bytes in, what the GPU reads into the home), fresh when the home is made or
  its filter changes, not fresh on a refill after a write (the home then holds the filter's last output). The
  title's bytes are never written: the filter writes the home only, which is the mirror's own GPU memory. A home
  shown at a filtered and an unfiltered address holds the filtered bytes; when the filtered address goes it is filled
  as a copy again. home_bytes(va) gives a mapped page's home for writing one changed slot between fills. The
  counters count filtered fills.

Test: title_mirror_hooks_test (no GPU, fake handles): binds into the second buffer with the chunk binds, after a
map, a remap and an unmap, and none after unalias; filtered fills fresh and not, a copy outside the range, a home
shown twice, refiltering a mapped page, unfiltering, and the title's bytes unchanged. vk_title_mirror_test passes
as before (Ryzen 9 7950X3D iGPU, RADV, Mesa 26.3.1, under validation).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 05:16:43 -05:00
63bb5d1488 test: vk_heap_alias_test binds one home into a mirror chunk and into the arena, as a console heap read in place needs
25,865 of the corpus's 26,503 shaders keep only the low 32 bits of a descriptor-table pointer (docs/d3d12_vulkan.md,
"Descriptor-table high-dword truncation"), so a console heap whose pages live in the page mirror at heap_base + the
title's address (tens of TiB up) must also be readable at heap_base + an offset below 4 GiB: in the sparse arena.
The mechanism is a second sparse bind of the same home. On a real device, with no shader: one VkDeviceMemory bound
into two sparse aliased buffers shows the same bytes through both, for CPU writes into the home and GPU writes through
either buffer; the arena pages after the heap, with nothing bound, read zero (the null-slot guard needs no memory);
unbinding the mirror's view leaves the arena's. Skips (77) without sparse aliased buffers with strict residency.

Ryzen 9 7950X3D iGPU, RADV, Mesa 26.3.1: passes, 0 validation errors; llvmpipe skips (no strict residency).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 05:07:02 -05:00
77ecad8b58 tracking: the hot/cold policy as the page mirror's tracking (HotColdTracking), and a probe observed after its arming (RT-TRACKING-POLICY)
HotColdTracking (src/title_mirror_hot_cold.h) implements TitleMirrorTracking (watch, unwatch, collect) over the
geometry watch's cells with TitleWritePolicy, so it can replace GuardTracking with no change in the mirror:
collect() returns the pages written since the last collect, each armed again first, and every time the pages
written so often that they are left writable. One collect is one interval of the policy's history.

A hot page's probe is now armed at the collect after it is asked for and judged on the interval after that;
judged on the interval of the arming itself, a page written every interval looked quiet and was turned cold
(seven promotions and six demotions of one page in 200 intervals). Test title_mirror_hot_cold (Windows, real
guards and a handler that does what the layer's does first): the page written every interval stops faulting
(12 faults in 200 intervals, the warm-up and the probes), the page written every 10th faults 19 times, and the
copy the collects name equals the memory after every collect.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 05:06:38 -05:00
2773ab8be1 d3d12: the write-back's list of copies over a run is a host_heap vector (RT-TITLE-WINDOW-RETIRE)
ShadowPages::write_back builds the list of targets with bytes in a run while it holds the tracker's lock_. Nothing
under that lock may touch the process heap: a title thread inside HeapAlloc can fault on a guarded heap-header page
and wait for lock_, while this thread would wait for the heap lock in push_back. Use the class's Vector alias
(leonida::host_heap), as the tracker's other containers do. Found in review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
2026-11-27 11:06:06 +01:00
fb1c8815a4 Merge branch 'test/round2' into tracking-policy 2026-11-27 05:03:32 -05:00
61e9ed4c16 tracking: what a guard costs under Wine, a hot/cold write policy, and cells reopened in one call (RT-TRACKING-POLICY)
guard_fault_bench (Windows, prints a table): VirtualProtect per call and per page from 4 KiB to 4 MiB, one write
fault through a minimal handler and through the geometry watch's cells on one thread and on eight, re-arming a
tile, GetWriteWatch on private memory and on a section view, and Linux's soft-dirty bits through Z:\proc\self.
Under Wine on this machine: a fault 2-2.5 us, a tile re-armed 3 us, VirtualProtect 1.3 us for 4 KiB and 8 us for
4 MiB in one call against about 1 us a page one call at a time; GetWriteWatch works on private memory (37 of 37
pages) and not on a section view (error 87, as on Windows); soft-dirty bits read back clear (not usable here).

The geometry watch's cells reopened a faulted tile page by page, a VirtualQuery and a VirtualProtect each (16 us
a fault): reopen() now does one query and one protect per region of equal protection (5.3 us; 5.8 us of wall
time a fault with eight threads faulting, from 24).

TitleWritePolicy (src/title_write_policy.h, portable): pages written in most intervals are left writable and
copied at every collect, the others guarded and copied once a write faults; a page is armed before it is named,
so a write during the copy is in the next collect; hot pages are probed (guarded for one interval) every 32. Test
title_write_policy: scripted (hot stops faulting, cold faults once an interval, a quiet hot page turns cold) and
randomised against a byte-exact reference, writes during the copy and refused guards included.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 05:03:32 -05:00
b699078893 d3d12, xmem: the page mirror: the title's GPU-readable pages at heap_base + their title address (RT-PAGE-MIRROR)
A V# or 64-bit pointer the title writes into its own memory names a title address, and the translated shaders read
heap_base + sext48(address). Nothing was there: run 63 lost the device on such a V# into the stream pool's GPU-only
window, which read zeros before step 2. The mirror puts the title's bytes there.

- src/title_mirror_space.h: xmem places every XMemVirtualAlloc reservation the title lets it place (address null) in
  [16 TiB, 48 TiB), handed out in order at reservation time, so no title pointer ever holds an old address. RADV makes
  sparse buffers at a chosen address only in its top 64 TiB, where heap_base (the sparse arena) is; heap_base + an
  address there stays inside it. A reservation the range cannot take is placed by the host, as before.
- src/title_mirror.h (TitleMirror, Vulkan through hooks): 2 GiB sparse chunks at heap_base + title address
  (bufferDeviceAddressCaptureReplay), one home per physical page (64 KiB of a 32 MiB host-visible unit), every page
  that shows a physical page bound to its one home (aliases share bytes and GPU writes; a remap is a rebind), the binds
  of a submission in one batch (the last bind of a page wins), homes freed after the retire ticket.
- src/title_frames.h Feed/Attach, xmem: every change of what a page of the range shows (host views in note_mapping,
  table pages in note_table_page), in order, with the physical page's scratch bytes; attaching feeds the pages mapped
  now under g_phys_mutex.
- src/title_mirror_tracking.h: the dirty set behind a small interface (watch, unwatch, collect: re-armed before the
  caller copies), with GuardTracking (a geometry-watch cell guard per page) until a measured policy replaces it.
- DeviceState::create_page_mirror / refresh_page_mirror (first in the before-execute hook): chunks for new
  reservations, the feed bound, written pages filled again once, the batch on the arena's bind queue signalling a
  timeline value; VulkanContext::note_mirror_bind makes every queue's next submission wait for it (the ordering rule).
  Off, with one line saying why, without capture-replay addresses, aliased strict sparse buffers, the bind queue, a
  sparse arena, signed V# offsets, xmem or the write-fault handler (llvmpipe), or with LEONIDA_PAGE_MIRROR=0.
  page_mirror_covers / page_mirror_address for the readers that move onto it. A log line every 10 s.

Tests: vk_title_mirror_test (native and under Wine, Raphael iGPU and RX 7900 XTX): a title-written V# read from a buffer
and dereferenced as the translated shaders do reaches its page, an alias the same, an unbound page reads zero; a remap,
a write (one upload for two aliases) and an unmap reach the next dispatch that waits for the batch; a home is freed only
after its ticket. d3d12_page_mirror_test (Wine, the game's device over xmem's pages): after slot-31 copies the GPU-only
page, its twin and the title's view hold the bytes at heap_base + address; a title write through its view reaches them
with one upload; a remap is a rebind with no host remap; an unmapped page reads zero. xmem_test: reservations land in
the range, the pair still pairs, the feed reports attach, host maps, table copies and unmaps in order, nothing after
detaching. Linux ctest (llvmpipe) 121/121.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 04:55:14 -05:00
11c6647c6e Merge branch 'test/round2' into page-mirror 2026-11-27 04:34:08 -05:00
3d0294e1b5 test: vk_sparse_bind_bench tries sparse buffers at chosen device addresses (bufferDeviceAddressCaptureReplay)
Raphael iGPU, RADV, natively: a 3 GiB sparse buffer asked for at 0xffffffb4a0000000, 0xffffffb8a0000000 or
0xffffffff00000000 is made exactly there; one asked for below 0xffffc00000000000 is made 0x400000000000 higher
(RADV's sparse range is the top 64 TiB), and 0xffff800100000000 is refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 04:32:30 -05:00