Commit Graph

1118 Commits

Author SHA1 Message Date
861bb0546e d3d12: reap a retired geometry view only after the replays that may name it
drain_geometry_releases retired released views at submitted_retire_ticket(),
read in before_execute_. The submission about to run records its own ticket
only after that, so it was not covered, and with an idle GPU
(completed == submitted) drain_released reaped the view in the same call,
before the lists recorded against it ran. A sparse bind in the same replay or
another queue's replay can take tickets in between, so submitted + 1 is not
enough either.

- VulkanContext::set_after_execute: called at the end of every replay that
  called before_execute_, however it returns, once its submissions are recorded.
- GeometryViews::execute_begin/execute_end track the replays in progress. A view
  retired at kAfterExecutes takes the serial of the last replay begun once it
  is unreachable, and gets its ticket (submitted_retire_ticket(), read under
  the views' lock) only when every replay up to that serial has ended.
- before_execute_ drains before refresh_shadows(), so this submission's console
  heap slots are never translated to a view retired in the same call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 21:28:04 -05:00
7d38eee116 Merge main into RT-GEOMETRY-VIEW-EVICTION
Conflict in runtime/shims/d3d12_title_buffer_windows.h: main (#2098) added the
lock-free published_ block list (for_each_block, find_mapped); this branch
destroys empty blocks. Both are kept; a destroyed block's published_ entry is
cleared here, and the follow-up commits make that safe for the lock-free readers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 21:22:30 -05:00
ef34931860 Merge pull request #2123 from qhukz13/cont/d16s8-d24-uav
d3d12: depth-stencil UAVs for console D16S8 (format 118) made as D24S8
2026-11-26 02:52:29 +01:00
66e96ccea6 d3d12: the session cache limit counts what a session adds to an offline seed; exit wait sized from measurements
Review of #1886: the seed the driver hands back with the session's builds no longer counts against
LEONIDA_PIPELINE_CACHE_BYTES (pipeline_cache_store::over_save_limit, with a unit test), the stale 512 MiB
checkpoint sentence is gone from docs/d3d12_vulkan.md, and kExitCacheWriteMs is 6 s with the measured
write times (1.87 GB in 1.4 s, 2.9 GB in 1.3-1.6 s; about 2.2 s at the 4 GiB default).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwRYcpySx4P4ncQ3wD5
2026-11-26 02:36:38 +01:00
10b01d207e Merge remote-tracking branch 'origin/main' into session-cache-limit 2026-11-26 02:28:52 +01:00
2769c5a739 d3d12: never defer buffer V#s past console-fix budget (RT-CONSOLE-FIX-NEVER-DEFER-BUFFER-VSHARP)
In fix_console_slots, when the LEONIDA_CONSOLE_FIX_US budget expires, do not null or defer buffer descriptors (!(w3 >> 30)). Only defer image T# descriptors to retry_console_slots.

Buffer V# descriptors only rebase address offsets and are fast to fix, whereas image T#s perform costly texture lookups and view creation. Compute shaders during world transition (e.g. lib_cs_01144) read loop bounds and record counts from buffer descriptors; nulling them causes infinite loops and device loss.

Tested with console_heap_vsharp_slots_test and vk_console_heap_gpu_test.

AI-assisted (Claude Code).
2026-11-26 03:39:08 +03:00
bbc7506559 d3d12: stub draws only for this device's mesh stubs; =color stubs override the state that hides them
Review follow-up for #1549:
- record_draw no longer skips a draw with an unregistered PSO: graphics stubs are registered now, so a draw with a PSO from another implementation fails the list again (Close: E_INVALIDARG), as on main. A stub records its kind (none, compute, mesh) when stub_or creates it; stub_pipeline_kind(pso, device) gives it only for the list's own device, and DispatchMesh skips only that mesh stub's draws. A mesh draw with another device's stub fails the list. record_dispatch keeps main's bypass.
- LEONIDA_STUB_PIPELINES=color turns off the title's culling, wireframe fill, sample mask, alpha to coverage, depth and stencil tests, blending and logic op for the stub, keeping the write mask. The B4G4R4A4 fallback's refusal of blending and logic ops now waits until it is known whether the pipeline is such a stub.
- docs/boot.md: the cover needs a triangle topology and stays inside the scissor; what is turned off; which draws stay recording errors.

d3d12_stub_draw_test: =color with CULL_MODE_BACK, FILL_MODE_WIREFRAME, SampleMask 0 and a reverse-Z GREATER test against a depth target cleared to 0; a draw with another implementation's PSO (switch off); DispatchMesh with a mesh stub on its own device's list (closes) and on another device's (fails). Each fails on fa223d8 or on the first version of this fix; every case is reported. The B4G4R4A4 path has no test (the GPUs here render A4R4G4B4).
2026-11-25 21:35:42 -03:00
78159b8865 d3d12: LEONIDA_STUB_PIPELINES builds a real graphics pipeline from built-in stages (MVP-GPU-04)
A graphics PSO whose translated shader is missing used to be created with no Vulkan pipeline and never
registered. Its draws did not become no-ops as the comment said: record_draw refused them, so the whole
list failed to close.

Now a vertex pipeline with a missing translation (no shader library, or no entry for its FSSM/FSPX
program) takes a vertex and a pixel stage from src/stub_pipeline.h and goes through the normal
create_graphics path: registered, built eagerly, drawn through replay and the validation layer.

- LEONIDA_STUB_PIPELINES=1: the vertex stage puts every vertex outside the clip volume, so a draw
  changes no pixel (the old intent), but the render pass, attachments and push constants are real.
- LEONIDA_STUB_PIPELINES=color: every three vertices cover the viewport and the pixel stage writes
  magenta (1 to UINT/SINT targets) to each render target, so stubbed passes show on screen.
- Point-list PSOs get a PointSize write; the vertex stage's Position is a bare output, so
  rect_list_geometry takes it.
- Compute and mesh stubs stay unregistered; record_draw and DispatchMesh now skip a draw on an
  unregistered pipeline as record_dispatch already did, instead of failing the list.

d3d12_stub_draw_test draws with both modes into an RGBA8 and an R32_UINT target and reads them back;
d3d12_stub_pipelines_test now expects a registered pipeline. docs/boot.md describes the switch.
2026-11-25 21:35:10 -03:00
a42bffdc3e Merge origin/main into heavy-pipeline-cache
main's per-pipeline compute journal (pipeline_cache_journal.h) now persists every compute build and survives a
crash, so the compute build takes main's build_compute_pipeline and the heavy cache keeps graphics pipelines only.
CMake keeps both test sets; docs and the create_pipeline comment say so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 05:27:39 +05:00
f36d89ebcc Merge remote-tracking branch 'origin/main' into title-texture-partial-mips
# Conflicts:
#	runtime/shims/d3d12_vulkan_device.cpp
2026-11-26 01:26:03 +01:00
4d811fcee9 Merge remote-tracking branch 'origin/main' into shadow-keep-gpu-writes
# Conflicts:
#	runtime/shims/d3d12_vulkan_device.cpp
2026-11-26 01:23:09 +01:00
0ebd4286ea d3d12: a slot-133 shadow keeps the GPU's writes where the title's bytes did not change (LEONIDA_SHADOW_KEEP)
ShadowPages copies pages that carry no sign of a title write (aliased,
unguarded, reopened with their 64 KiB block, write-watched or pinned) at
every refresh, and that copy overwrote what a shader had stored in the
shadow with the title's unchanged bytes. A value a compute program writes
for the next frame then read back as the title's old bytes every other
frame.

Each tracker now keeps a 64-bit sum per 256-byte piece of the bytes it
copied last (runtime/src/shadow_keep.h) and copies a piece only when the
title's bytes differ. Zeroed pages forget their sums. LEONIDA_SHADOW_KEEP=0
copies every job whole, as before. New CPU-only test shadow_keep.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwRYcpySx4P4ncQ3wD5
2026-11-26 01:22:14 +01:00
8d832fd109 Merge main into rt-title-every-budget (#2122)
#2098 split the every-pass loop of refresh_title_textures by mode: with
LEONIDA_TEXTURE_REFRESH_ASYNC every persistent mapping is polled each
pass and only stale unmapped textures are visited, without it all mapped
or stale ones are. The async branch is kept as main has it.
LEONIDA_TITLE_EVERY_BUDGET_US applies to the synchronous pass, the one
before a submission on the submitting thread; under async the pass runs
on the refresh worker and the limit does not apply (README says so).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 19:04:24 -05:00
a1df1713d4 d3d12: LEONIDA_TITLE_PARTIAL_MIPS fills the readable smaller mips of a title texture whose larger ones are not there
The XG layout of a 2D texture of one slice stores its mips from the smallest to the largest, so the mips from m on
are a prefix of its footprint (mip_chain_bytes). With LEONIDA_TITLE_PARTIAL_MIPS=1 the readability probe returns the
readable prefix (texture_memory_readable_bytes), first_mip_within the first mip it holds; when the last slot-70 view
starts there or later, those mips are filled and only the T#s of views that start there or later are published. The
others stay on the fallback until a later fill has their mips. A texture not filled, or filled in part, whose pages
came through a map change is marked stale so the next pass fills it.

Off by default: the image still has memory for every mip. LEONIDA_TITLE_PARTIAL_MIPS_MB (2048) bounds the image
memory of the textures filled in part. Unset, the behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwRYcpySx4P4ncQ3wD5
2026-11-26 00:44:13 +01:00
fc71534883 Make the live compute warm-up limit opt-in; main's warm-up stays the default
#2098's LEONIDA_COMPUTE_WARMUP_LIVE_MAX_BYTES defaulted to 128 KiB, so while the title submits it skipped exactly the
large modules main's warm-up (#1889) exists to build, with LargeModuleGate already ordering them behind a submission's
compiles. At the maintainers' decision ("main wins") it is opt-in now: unset or 0 is no limit, as on main; <n> leaves
warm-ups of modules over n bytes to their first use while the title submits, as #2098 measured with 131072.

This reverts the test-side override of fb60a1cf4: d3d12_big_compute_warmup runs with main's environment again. The
switch is documented in runtime/README.md beside the other #2098 switches, and in docs/d3d12_vulkan.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 18:37:48 -05:00
3a2820b3bf Merge main c1e1ef0b8 into RT-POST-LOAD-GPU-MEMORY (#2098)
Two conflicts:

- d3d12_com.cpp, note_direct_heap_indexing: main's console_descriptor_table_va(cbv_srv_uav_base_) for the tracked
  table, with this branch's per-site once() flag instead of note_once on every draw.
- d3d12_vulkan_device.cpp, PipelineState::build_compute: this branch's body (build_compute_pipeline, journal, compile
  helper). main's dev_status::Build around the compute create moves into build_compute_pipeline, next to the
  pipeline_profile::DriverCall, so the status line still names the compute pipeline in the driver.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 18:36:19 -05:00
c5359a4644 d3d12: the window write-back waits for the submission that wrote (RT-TITLE-WINDOW-WRITE-BACK)
The first cut copied the reached ranges back at the next refresh whether or not
the submission that wrote them had finished, so a range the GPU was still
filling could be read half done.

A batch is now kept with the retire ticket of the submission that will use it,
and the ranges are copied back only once the context reports that ticket done.
Anything not yet retired stays queued and is copied on a later refresh, still
before that refresh's forward copy, so the ordering that keeps the title's own
newer bytes is unchanged.

The test is unchanged and still passes: it asserts the pages are untouched
until the next submission and then hold exactly what the shader wrote.
2026-11-25 23:30:33 +00:00
75f6890bb9 Keep the storage view's pNext chain alive for the 2D-array mirror view
#2098's 2D mirror of a 2D-array image (BindlessSet::MirrorViews) copies storage_info, pNext chain and all, after the
block that made the storage view. That chain (VkImageViewUsageCreateInfo, VkImageViewSlicedCreateInfoEXT) was declared
inside the block, so the mirror's vkCreateImageView followed a dangling pointer into stale stack; winevulkan walked it
without end. That was the 120 s hang of d3d12_existing_heap (and its two variants), d3d12_r9g9b9e5_uav,
d3d12_depth_stencil_uav, xbox_depth_storage and xbox_d16s8_storage on lavapipe and the iGPU alike: each makes a UAV
of a 2D-array (or cube) texture. The two structs are declared before the block now.

Found with a winedbg backtrace of the hung test (bind_image_views_locked's make_mirror lambda, line 6604), then
confirmed by disabling the mirror in a scratch tree: all six tests pass then too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 18:30:31 -05:00
c1e1ef0b81 Merge pull request #1953 from abnalstlll-byte/feat/rt-lazy-pipeline-f16-top-location
d3d12, test: pass device_.f16_half_top_location in lazy graphics pipeline stage_words (RT-LAZY-PIPELINE-F16-TOP-LOCATION)
2026-11-26 00:27:57 +01:00
38385762bd dev overlay: the title HUD's VRAM and private memory figures
LEONIDA_DEV_OVERLAY (#2137) showed the working set and free RAM, with
no GPU memory and no private memory. It now shows both, from the same
code as the title HUD:

- src/memory_figures.h holds VramBudget, the private-bytes choice (the
  larger of PrivateUsage and PagefileUsage, since Wine fills only the
  latter), the "RAM ..." and "VRAM ..." text with "n/a" where there is
  no figure, and a publisher for the device's GPU memory figure. No
  Vulkan, and Win32 only under _WIN32, so the overlay's test still
  builds on every host.
- A device with VK_EXT_memory_budget publishes a reader when it is
  created and withdraws it first thing when it is destroyed (the lock
  is held during a read, so a reader never outlives its device).
  latest_vram() calls the reader at most once per 500 ms for both
  views. The HUD reads it instead of its own per-device lambda.
- The overlay's last line is now "RAM 2.5 GB (ws 1.0)   VRAM
  3.5/16.0 GB +0.5 shared"; cores and free RAM keep their own line.

Tests: dev_overlay_test checks the text with and without figures, the
private-bytes fallback, and the publisher (one read per refresh, only
the publishing device withdraws). title_hud_test checks that a HUD
without its own source shows the published figure.
d3d12_vram_budget_test checks that the device publishes its figure
while it lives and withdraws it on release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 18:18:57 -05:00
d4fb292344 Merge main into rt-title-hud-vram-budget
Brings in #2137 (LEONIDA_DEV_OVERLAY), which the next commit extends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 18:18:55 -05:00
7b1d71e218 Leave the layer's below-arena V#s alone in the table scan
#2098's scan_title_table nulls a table V# whose base nothing backs (rebase_title_vsharp's `unbacked`). A V# the
layer wrote itself for one of its own buffers that the driver put below the arena holds the low 48 bits of a negative
offset, which the shaders read sign-extended (vsharp_address accepts it). On the RDNA2 iGPU, upload buffers live in
ReBAR memory below the arena, so the scan took such a V# for an unbacked title address and nulled it before the
dispatch read it: d3d12_compute, d3d12_fspx_compute, d3d12_unmapped_vsharp, d3d12_graphics_indirect_heap_resources
and d3d12_compile_teardown failed there and passed on lavapipe, where the buffers sit above the arena.

rebase_title_vsharp now leaves a base with bit 47 set alone when its sign-extended offset is one of the layer's
backings (gpu_backings), as vsharp_address reads it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 18:15:45 -05:00
dcdcade326 runtime: address review of the pipeline order recorder
- open(): when the existing log does not end with a newline (a process killed
  mid-line), write one first so the next session line is not glued to the cut
  line and its records are not filed under the previous run.
- Fix the hook comments (vulkan_replay.h, d3d12_vulkan_device.cpp, docs,
  README): the hook never blocks and allocates nothing, but the readiness
  callbacks take a non-blocking try_lock on the first request of a pipeline
  and of a variant.
- Close the order log after the exit pipeline cache write, not before.
- Remove the unused Slot::written and Slot::build_written.
- Tests: cut file then new session, flush stops at an unpublished slot,
  unknown session version rejected. Trailing whitespace fixed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-26 00:07:37 +01:00
b83ae01f5c Build pipelines through main's PipelineCompiles path again, not #2098's pre-pass
At the maintainers' decision, main's compile path wins over #2098's second one. #2098 made every lazy PSO
asynchronous (async_build = true) and built what a submission needs in a pre-pass of VulkanQueue::execute, one
pipeline after another on the submitting thread, with a per-variant state machine (replay_get / replay_await) and a
wait budget (LEONIDA_PIPELINE_WAIT_MS, LEONIDA_PIPELINE_WAIT_FRAME_MS). That bypassed PipelineCompiles and
PipelineWorkers (parallel compiles with resource_mutex_ released, #1742) and the LargeModuleGate budget (#1889), which
d3d12_pipeline_workers(_eager) and d3d12_big_compute_* check.

Removed: the pre-pass (collect_pipeline_awaits, await_pipelines, PipelineAwait, ComputePipeline/GraphicsPipeline::
await), PipelineState's Build states, replay_get/replay_await, set_pipeline_build_hook, the wait budget and its 10 s
line, and d3d12_pipeline_wait_test, which tested only that. PipelineState is wired as on main again: async_build =
LEONIDA_ASYNC_PIPELINES, queue_build for asynchronous builds, build_compute / variant through PipelineCompiles
otherwise.

Kept from #2098, adapted to main's path:
- the record-time build request (request_pipeline_build): queue_build without counting a skip;
- compile-helper deferral: a compute build the helper is still making publishes nothing, so its next use asks again;
- big warm-ups left to their first use while the title submits (LEONIDA_COMPUTE_WARMUP_LIVE_MAX_BYTES):
  src/pipeline_wait.h keeps only the last-submission time this reads, noted by VulkanQueue::execute.
docs/d3d12_vulkan.md, "Pipelines still being built", says what is left.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 18:05:25 -05:00
ffcfe68f12 Merge pull request #2137 from Snooozs/dev-overlay
runtime: LEONIDA_DEV_OVERLAY shows what the runtime is doing over the title's window (RT-DEV-OVERLAY)
2026-11-26 00:02:32 +01:00
cdbbb39554 Merge remote-tracking branch 'origin/main' into feat/pipeline-order-recorder 2026-11-26 00:02:32 +01:00
d4681041ec Merge pull request #710 from aslan2142/gpuav-as-type
OLD-8414: restore old upstream PR 8414 - d3d12: arena AS resources take their address from vkGetAccelerationStructureDeviceAddressKHR
2026-11-25 23:59:57 +01:00
d86ac98133 Fill a never-filled mapped texture before its first submission (async refresh)
OreoFR's point on #2098 holds: with LEONIDA_TEXTURE_REFRESH_ASYNC=1 the before-execute hook only wakes the refresh
worker (request_title_refresh), so a slot-133 texture the title maps, writes and uses in its next submission (a video
plane) can be read empty by that submission while the worker has not come to it.

The hook now first fills, on the submitting thread, the mapped textures that were never filled (mapped && !fills),
with try_to_lock on the registry: the worker may hold it for a fill that needs this queue, so it does not wait. A
fill that needs generic staging is left to the worker, as the pass does. Everything else stays on the worker.

Test: d3d12_mapped_plane_async (d3d12_existing_heap_test --mapped-plane-async, which sets the switch itself) maps a
written R8 plane and copies it to a readback buffer in the first submission, with host image copies and with the
staged upload; every byte must be the written one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 17:50:07 -05:00
7a4d1f7721 runtime: record the order of first pipeline requests behind LEONIDA_PIPELINE_ORDER_LOG=1
RT-PIPELINE-PREWARM-ORDER phase 1. With the variable set to 1 the D3D12 device
appends, per compute, graphics and mesh pipeline and variant that the title
uses for the first time, one line to pipeline_order.log beside
pipeline_cache.session.bin: the description key, the variant, creation and
first-use times since the process started, the build time and whether the
handle was ready. One line of counts at exit. Off by default: nothing reads the
file yet, and a run without the variable carries no hook. It touches no cache
file, the memory gate or the compile queue.

The mesh pipeline's key folds in the MS hash (the graphics key does not cover
it). Documented in runtime/README.md and docs/d3d12_vulkan.md, and the doc test
checks the variable is read and named in both.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-25 23:47:38 +01:00
f6cb4aedfc runtime: LEONIDA_DEV_OVERLAY shows what the runtime is doing over the title's window (RT-DEV-OVERLAY)
A click-through window of its own with its own thread: frame and submission rate, a submission's CPU time by phase, the
phase running now, pipeline builds in flight, indirect draws, cores and memory. Off by default. submit_phases keeps
per-phase counts of the threads inside a phase, so overlapping submissions of several queues leave none behind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 23:28:38 +01:00
8dc07b3a4b d3d12, test: unify f16 halves linking helper and pass top_location in lazy stage_words (RT-LAZY-PIPELINE-F16-TOP-LOCATION)
Move per-pipeline f16 halves linking into a shared helper PipelineState::link_f16_halves
called by both eager create_graphics() and lazy stage_words() paths, always passing
device_.f16_half_top_location. Previously, stage_words() omitted top_location, causing
it to default to 29 and relocate outputs beyond the device limit on hardware where
maxVertexOutputComponents < 124 (e.g. top_location = 14 on 64-component limits).

Add f16_half_top_location to VulkanDeviceInfo (0 = read from device limits; non-zero =
override for testing low-limit devices).
Expose rt::d3d12::pipeline_stage_words() to allow inspecting linked lazy pipeline SPIR-V.
In runtime/test/d3d12_f16_halves_test.cpp, add low top_location = 14 tests verifying that
out-of-budget pipelines are rejected at CreateGraphicsPipelineState, in-budget pipelines
relocate within location 14 and execute correctly through the lazy path on first draw, and
explicitly verify that the linked SPIR-V stage modules' highest Location does not exceed 14.
Keep unit check #11 in runtime/test/spirv_f16_halves_test.cpp.

Tested:
- spirv_f16_halves_test (passed)
- python -I scripts/check_no_game_data.py runtime/shims/d3d12_com.h runtime/shims/d3d12_vulkan_device.cpp runtime/test/d3d12_f16_halves_test.cpp (clean)
No retail game data or keys.

AI-assisted (Claude Code, Claude Opus 5.5).
2026-11-26 01:25:22 +03:00
bffc6395b1 Merge main into RT-POST-LOAD-GPU-MEMORY (#2098)
main d3b8251bc brings #1889 (large compiles within a memory budget), #1987 (unbound T# reasons), #1759, #1860
and others under this branch. Conflicts:

- d3d12_vulkan_device.cpp, includes: both (pipeline_cache_journal.h and large_module_gate.h).
- d3d12_vulkan_device.cpp, fix_console_slot's T# branch: main's form (counts refused_reasons, #1987), with this
  branch's comment on why a slot that is no T# is nulled. The same reason count is added to console_tsharp_check,
  the GPU console-heap path's T# registration, so its log line has the reasons too.
- d3d12_vulkan_device.cpp, the heap log: both blocks (the release filter / GPU heap lines and main's "unbound T#s by
  reason" line).
- d3d12_vulkan_device.cpp, PipelineState::build_compute: this branch's body (build_compute_pipeline, journal, compile
  helper) behind main's entry: the `Work` argument and enter_build, so a large module takes its place at
  big_compile_gate() before variants_mutex_, as #1889 requires (a thread that waits for memory holds no PSO lock).
  build_compute_pipeline's own big_compile mutex now follows main's BigCompiles: taken only with
  LEONIDA_SERIAL_BIG_COMPILES=1 (it was on by default here), so the default is main's budget, not one at a time.
- d3d12_vulkan_device.cpp, queue_locked: this branch's Build-state jobs (claim, defer, finish). main's
  `requested_`/`publication` mechanism they replace is not kept. build_variant passes Work::speculative for a
  "warmup" build and Work::demand otherwise, as main's queue_build did.
- vulkan_replay.h, ComputePipeline: main's comment on `large`, and this branch's `await`.
- vulkan_backend.h: this branch's LEONIDA_SUBMIT_ASYNC block, with main's lock order in the state_mutex_ comment
  (state_mutex_ -> pipeline_mutex_ -> resource_mutex_ -> tracker_mutex_ -> submit_mutex_).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 17:21:25 -05:00
8ff0a161ff address_binding: review fixes for RT-FAULT-ADDRESS-OWNER
- A second Vulkan instance in the process no longer overwrites the messenger
  handle (the first one was left alive past its instance): it is refused, and
  enable_device only enables the extension for the instance that owns the
  messenger. install/uninstall are under a lock.
- `on` is set only when a messenger records the device, and is atomic. With
  LEONIDA_ADDRESS_BINDINGS=1 and nothing recording, the fault report says the
  bindings were not recorded instead of reading as "no object there".
- An object that only shares the reported page with the fault address is
  labelled "on the page" (unbound: "held the page"), not "containing".
- Tests: exact end and start of an object, page vs byte precision, unbind
  matching by handle and size, the kept_unbound cap, recording from several
  threads while a report reads, and the two-instance messenger cases. The test
  builds on Linux too (setenv in place of _putenv_s).

Changes made by Claude Code (AI-assisted).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JPqXc6svM4pbBagTsVEYA3
2026-11-25 22:12:33 +00:00
aab7653566 d3d12: retry a failed heavy cache write and never publish a VK_INCOMPLETE snapshot
Review of RT-HEAVY-PIPELINE-CACHE:
- The writer thread marked a generation written even when the save failed, so the
  cache stayed unsaved until teardown. A failed save now keeps the cache dirty and
  is retried after a bounded backoff (5 s, doubling, capped at 2 min), so a write
  that keeps failing does not spin. WriteSchedule::failed() holds that decision and
  heavy_pipeline_cache_test checks it.
- save_heavy_pipeline_cache accepted VK_INCOMPLETE and published the truncated blob
  over a complete file. It now requires VK_SUCCESS, like the session cache, and
  keeps the previous file; the next try queries a fresh size.

Changes made by Claude Code (AI-assisted).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JPqXc6svM4pbBagTsVEYA3
2026-11-25 22:10:37 +00:00
dd6d3fd8a5 Merge main into stream-output (#1630)
Brings #1630 up to date with main; no conflicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 17:04:49 -05:00
d3b8251bc3 Merge pull request #1860 from lixonik/fix/title-3d-view-array-range
D3D-3D-VIEW-ARRAY-RANGE: use the single array layer for Vulkan 3D views
2026-11-25 23:02:37 +01:00
04290dd2d1 d3d12: a window's GPU writes go back to the title's pages (RT-TITLE-WINDOW-WRITE-BACK)
A window of the title's memory is a read-side mirror refreshed before every
submission, so a UAV or raw write into one landed in the copy and the title
never saw it. At the world start that is the WRITE_INVALID device loss of
#1537 (QemmHD, 160 s into the load, past the cap): the culling compute writes
through addresses that name title memory, and nothing ever reads the result
back into the pages.

The layer now keeps every title range a submission's bindings reach (the
resolve path, so root views, table V#s and created views alike) and copies
those ranges from the copy to the title's pages at the start of the next
refresh, before the forward copy. A page the title wrote in between takes the
title's newer bytes and its GPU result is dropped; the tracker already knows
those pages (guarded, hot and clean). Caps: 8,192 ranges and 64 MiB a
submission, logged once; LEONIDA_TITLE_WRITEBACK=0 turns it off.

Test: d3d12_title_window_write_back, a dispatch through a root UAV at the
title's pages: the written words reach the pages, hold across two
submissions, and a title write survives the next forward copy. No game files.

Item: RT-TITLE-WINDOW-WRITE-BACK (claimed in #1608)

Wine against llvmpipe.
2026-11-25 21:59:18 +00:00
c626cb2dc2 Merge upstream main into fault-address-owner 2026-11-25 21:56:36 +00:00
c3b8520683 Merge upstream main into heavy-pipeline-cache 2026-11-25 21:56:36 +00:00
f17c365b61 Merge upstream main into d3d-sample-positions 2026-11-25 21:56:34 +00:00
244387529b title HUD: VRAM from VK_EXT_memory_budget, private bytes under Wine
The title HUD (#1922, LEONIDA_TITLE_HUD=1) read VRAM from DXGI's
QueryVideoMemoryInfo on the host dxgi.dll and private memory from
PROCESS_MEMORY_COUNTERS_EX::PrivateUsage. Under Wine both read 0.

- VRAM: the runtime's device enables VK_EXT_memory_budget when the GPU
  has it (VulkanDeviceInfo::memory_budget), and
  rt::d3d12::vulkan_vram_budget sums heapUsage and heapBudget over the
  DEVICE_LOCAL heaps (other heaps' usage shown as shared), from
  src/vulkan_memory_budget.h. The HUD calls it once per refresh on its
  own thread. Without the extension it falls back to DXGI, and where
  that has no figure either it shows "VRAM n/a" rather than 0.
- Private memory: Wine's GetProcessMemoryInfo fills only the
  PROCESS_MEMORY_COUNTERS part and leaves PrivateUsage 0; PagefileUsage
  is the same commit-charge figure on Windows 8 and later, so the HUD
  takes the larger of the two.

Tests: title_hud_test checks the sums, the DXGI fallback, the "n/a"
text and the private-bytes choice with made-up values, and that a VRAM
source reaches the title at most once per refresh. The new
d3d12_vram_budget_test checks that the device enables the extension
exactly when the GPU has it and reads a non-zero budget, and skips
(77) without it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 16:56:01 -05:00
712714bef2 Merge main into perf/big-compute-budget (#1889)
Brings #1889 up to date with main after #1742 (the pipeline compile unlock),
resolving the five conflicts as described in the guide on the PR:
https://github.com/ubiquitarianism/leonida/pull/1889#issuecomment-7175252290

- vulkan_replay.h: PipelineCompiles::build takes both the large-compile
  budget and main's `prior` compiles; build_pipelines passes the budget,
  and main's check_compiled_pipelines / finish_compiled_pipelines stay.
- vulkan_backend.h: execute_now takes the large-compile demand and passes
  the budget to the pass-0 compile, and pass 1 passes the budget too.
  set_large_compiles locks pipeline_mutex_, since #1742 moved the
  pipeline state under that lock.
- replay_pipeline_compiles_test.cpp: both test blocks kept, and the
  prior_compiles_reuse call passes an empty budget.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 16:41:36 -05:00
6fd430ebc7 d3d12: deliver a released title range to every device's geometry views
leonida::geometry_writes previously kept one process-wide release queue, so when two devices held GeometryViews over the same title range, the first device to call drain_released() emptied the queue and the second kept its view and charged bytes forever.

Give each GeometryViews its own ReleaseQueue subscribed to leonida::geometry_writes on construction and unsubscribed on destruction. note_released() delivers each released range to every subscriber's queue under subscribers_mutex -> queue.mutex (keeping the 65536-entry collapse per queue), and take_released() drains only the caller's queue under queue.mutex.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 23:24:42 +02:00
5da3b6be3c d3d12: the title texture pass can time-box its mapped and stale visits (RT-TITLE-EVERY-BUDGET)
LEONIDA_TITLE_EVERY_BUDGET_US (0, the default: unchanged) limits how long one pass of refresh_title_textures
spends on the textures it visits every pass (mapped by the title, or known stale). The visits resume from a cursor
of their own, so every marked texture gets its turn; the texture that crosses the limit is finished. A mapped
texture never filled yet is visited first whatever the limit, so a video plane is not left empty until its turn.
The pass stays synchronous, before the submission, as today.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 22:23:36 +01:00
2d258c8cd4 d3d12: log the title staging fallback once per Vulkan format
Record which title image formats have no bindable host-transfer memory type. Document the three formats observed on the GTX 1050 Ti by qhukz13.

Suggested-by: qhukz13 (PR #1894)

AI-assisted-by: OpenAI Codex (gpt-6.2-astra)
2026-11-26 07:16:59 +10:00
a05c178708 d3d12, test: fix unbound_tsharp_tracker scope and verify binding rules (RT-UNBOUND-TSHARP-REASONS)
- Move UnboundTsharpTracker and unbound_tsharp_tracker() to namespace scope
  so the free functions in rt::d3d12 that call it compile correctly.
- Add non-const Device::state() overload for test_bind_title_image().
- Remove nonexistent rt::d3d12_xs::resource_proxy_real_resource() call;
  resource_image_address() now casts the ID3D12Resource pointer directly.
- Fix cube layer check in bind_title_image to verify texture layer count.
- Add D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET to test MSAA texture desc.
- All 35 checks in d3d12_unbound_tsharp_rules_test pass cleanly.

AI-assisted (Claude Code)
2026-11-26 00:01:32 +03:00
5e188a02f9 d3d12, test: track unbound T# refusal counts by reason and verify binding rules (RT-UNBOUND-TSHARP-REASONS)
In runtime/shims/d3d12_vulkan_device.cpp, extend note_refused_tsharp to record
both overall distinct slots and per-reason distinct slots and total refusal
counts across console descriptor heaps, matching the title texture diagnostic
breakdown in refresh_console_heaps.

Expose inspection helpers in runtime/shims/d3d12_com.h and add synthetic tests
in runtime/test/d3d12_unbound_tsharp_rules_test.cpp covering:
- 1D rule: dimension and layer count compatibility ("T# type or samples do not fit the texture")
- Array rule: layer bounds ("T# names layers the texture lacks")
- Cube rule: minimum layer requirements ("cube T# on fewer than six layers")
- MSAA rule: sample count matching ("T# type or samples do not fit the texture")
- Tracking: distinct slot and total refusal counts by reason

AI-assisted (Claude Code)
2026-11-26 00:01:32 +03:00
40a69e0084 d3d12: CreatePlacedResource takes a format-118 clear value
create_placed turns a console D16S8 (format 118) description into its PC
format before committed_resource_refusal, but left the clear value as
118, so the clear format's family no longer matched the resource's and
every placed format-118 depth texture with a clear value was refused
("clear value"), with D24S8 backing. The clear value now goes through
pc_format() too, as the description does. Found by
xbox_d16s8_d24_storage's CreatePlacedResource case on a GTX 1050 Ti.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 22:56:51 +02:00
9f98dcc617 Improve post-load GPU memory and pipeline handling (RT-POST-LOAD-GPU-MEMORY)
Fall back to a dedicated buffer allocation when the shared arena fills.
Update console descriptors and resource backing, preserve pipeline cache
entries, and replay mesh records using bounded indirect arguments. Keep
scripted input available until read and cover the runtime and translator
paths with synthetic tests.

Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com>
Co-authored-by: ivanepsilondelta <264061546+ivanepsilondelta@users.noreply.github.com>
2026-11-25 14:30:51 -06:00
06ba2eb2de d3d12: stage title images when host transfer has no memory type
Check the host-transfer memory requirements before selecting the backing for a CPU-fillable title texture. Exercise the mapped linear R8 plane with a driver shim that returns no compatible memory types for the host-transfer image.

Reported-by: qhukz13 (PR #1894)

AI-assisted-by: OpenAI Codex (gpt-6.2-astra)
2026-11-26 06:21:47 +10:00