A pixel shader with an ordered section (POPS) reads the hardware's collision word, which sits in the SGPR after the
user SGPRs and the primitive mask: collision wave id in bits 0-9, this wave's id in bits 16-25, overlap in bit 31.
The program waits until wave_id + ~collision_id is below src_pops_exiting_wave_id + ~collision_id (unsigned). The
translator orders the section with fragment-shader interlock and reads the exiting id as 0, and the word was
whatever the push constants held at that dword, usually 0. With wave id == collision id the test is
0xffffffff < 0xffffffff, never true, so a wave that reached the loop ran it until the loop guard (65,536 rounds).
The overlap test before the loop skips it whenever a lane is on in EXEC, so it is a wave (a host subgroup) with EXEC
all off there; on 32-wide subgroups that is either half of a wave64 program whose lanes are all off.
The SGPR is now the source of the program's wave-id extract (s_bfe_u32 with field 0x000a0010) when the program reads
that SGPR's entry value (shader_meta's user_sgpr_reads), and it is set at entry to 0x00010000 (no overlap, wave id 1,
collision id 0): the loop leaves after one round. A program without that extract keeps the old behaviour.
- tools/rdna2spirv.py: pops_collision_sgpr and the entry store.
- tests/semantic/test_pops_collision_seed.py: subgroups of 64 and 32 lanes, with and without the seed, and the SGPR
search; the GPU fixture runtime/test/shaders/ps_pops_wait_loop.asm (check.py, run_gpu_tests.py) and its llvm-mc
listing.
- tests/semantic/spirv_wave_interp.py: the interlock instructions run as no-ops (a run has no other primitive).
- runtime/test/vk_harness.cpp: a fragment shader that needs pixel interlock on a device without it is unsupported
(77), as for barycentrics.
- docs/design.md, docs/d3d12_vulkan.md: the POPS rows.
GPU: on an RTX 4070 SUPER the fixture gives 4096 of 4096 pixels as expected; with the seed taken out every pixel's
round count is 0x00010000.
Idea from Marvisak/VIctory 7ac1f54, written anew.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf
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).
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).
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.
Since #2098 a scripted press lasts its 300 ms and then until the title has made
six GetCurrentReading calls since it began. gameinput_test --input-script still
expected the press to be over after 350 ms and three reads, so ctest
gameinput_script failed on main in every build with SDL3 (it is disabled
without SDL3, so CI did not show it).
The test now checks that the press is still held at that point, reads the pad
six more times and then expects the release. Test only.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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>
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
#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>
Conflict in runtime/test/large_module_gate.h: kept main's forwarding header to runtime/src/large_module_gate.h (unchanged) and put LargeModuleQueue after the include; it admits with the gate's admits() and a blocking Ticket under its own mutex, so try_enter and the try_to_lock Ticket are no longer needed.
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
#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>
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>
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.
#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>
#2098 added a check that XGCreateTextureComputer refuses a render target with no layout mode (E_NOTIMPL). On main the
second (general) layout model lays out the render targets xg_xs_layout.h does not, and xg_xs_test already expects
S_OK for those ("the other render targets still use the general layout model"). The check now says the same for this
one: the explicit-mode model refuses it and the general model makes the computer.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main's warm-up test has the warm-up thread build every compute module after a submission. Its 132 KiB modules are over
#2098's LEONIDA_COMPUTE_WARMUP_LIVE_MAX_BYTES (128 KiB by default), which leaves big warm-ups to their first use while
the title submits, so four of them were never started and the test's "each once" check failed. The limit is a
separate feature from the gate order the test checks; it is set to 0 for this test only.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
#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>
- 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>
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>
In write_direct_heaps(), the bound resource and sampler heaps were passed using raw cbv_srv_uav_base_ and sampler_base_. For console descriptor heaps shadowed in the GPU address arena, this supplied the title's host console VA rather than the shader VA where GPU descriptor reads land, triggering GPU device loss (READ_INVALID) in compute/graphics passes during world transition.
Remap the bound bases through console_descriptor_table_va() before writing them to user SGPRs and tracking in remember_table() and graphics_user_data(). Update d3d12_set_descriptor_heaps_test to assert that recorded dispatch user data receives the remapped console_descriptor_table_va addresses.
AI-assisted (Claude Code, Claude Opus 5.5).
#634 rewrote the same runtime/README.md paragraph on the loader. Its text
stays, and its relocation sentence takes this PR's wording: DIR64 and
HIGHLOW relocations, the other types rejected.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
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>
pipeline_order.h: a passive recorder of the first request of each pipeline and
variant, with its text file format (checksummed lines, truncated or damaged
lines skipped on read) and a lock-free, allocation-free hot path with a writer
thread of its own. ComputePipeline and GraphicsPipeline get a `requested`
callback, called where a submission is prepared, also for handles that exist
already. Nothing uses either yet; the device wiring is the next commit.
Tests (CPU only): pipeline_order_test (first request only, variants, order,
round trip, truncation at every byte, damaged lines, sessions, full record,
bounded file, unwritable file, 8 threads, no allocation, counts line) and
replay_pipeline_order_hook_test (ready, lazy, skipped, unbound variant).
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Extend #957's DPP VOPC compare to v_cmpx: the same lane selection, with the
result written to EXEC. v_cmpx prints no destination, so src0 is its first
operand. Only the forms where every lane writes its bit are taken, as for
v_cmp. 78 pipeline-library pixel shaders of 1.0.2.1 were refused for it; all
78 now translate and pass spirv-val.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>