Repository navigation
Improve post-load GPU memory and pipeline handling (RT-POST-LOAD-GPU-MEMORY) - #2098
Conversation
…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>
|
Native Windows boot of this draft ( Machine: Windows 10 19045, RTX 5060 Ti 16 GB, NVIDIA 621.01, 32 GB RAM, own 1.0.2.1, MSVC RelWithDebInfo (builds clean). Shaders from my work folder (47,772 loaded, 0 refused), cold pipeline cache, Reached: the loading screens and the world start. Then it stops the same way as my runs without it: the last submission is number 2,216 at t=217 s, What it does save, against my earlier runs:
Not a clean comparison: the runs differ in much (geometry copies, a 1.1 to 1.6 GB heavy pipeline cache in most of mine, host copies). One thing stands out either way: The loading was slow here: 1 to 4 frames/s from 20 to 60 s, because the cache was cold. Is there anything you want measured with a warm journal or a switch ( A question on the stall, since your title frame counter advanced to 2,830 at 600 s under Proton: did AI-assisted (Claude Code, Claude Opus 5.5). |
|
Overlap with #1889 (RT-BIG-COMPUTE-BUDGET), so that neither of us finds out at the merge. Read from the code of 9f98dcc and from trial merges; I have not built or run this pull request. I do not have the game, so I cannot test on it directly: what I check is the project's own tests and synthetic modules.
AI-assisted (Claude Code). |
|
A note on the async texture refresh ( |
main d3b8251 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>
Found building #2098 with clang-cl (Make generator); each also fails on the pull request's own head: - dxgi_swapchain_count_test: VulkanSwapchain takes a SubmitMutex& now; the test passed a std::mutex. - vk_store_test: kind_sampled_bit/kind_storage_bit come from descriptor_table.h, which it did not include. - d3d12_compute_journal_test listed gta6rt_indirect_count_shader's output among its sources, so Make had two rules for cs_indirect_dispatch_count.spv and the two glslangValidator runs raced ("Failed to open file"). It depends on that target now, and the second shader has a target of its own. - tests/semantic/test_tsharp_dimension.py began with a UTF-8 BOM, which test_ci_registration's ast.parse refuses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tests/test_docs_env_vars.py failed: LEONIDA_TEXTURE_REFRESH_ASYNC, LEONIDA_SUBMIT_ASYNC, the LEONIDA_CONSOLE_HEAP_GPU family, the shadow GPU copies and the diagnostics this branch reads were in no document. One row each in "Switches of the D3D12 layer for a retail boot", from the comments at the code that reads them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… 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>
…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>
#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>
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>
…t model #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>
#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>
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>
…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 fb60a1c: 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>
|
Merged, thanks, @Moriz82, for the post-load memory and pipeline work, and to Snooozs, TheGeogeo and OreoFR for the boot run, the #1889 overlap map and the async-refresh catch.
AI-assisted (Claude Code, Claude Opus 5.5). |
ProjectLeonida#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>
…jectLeonida#1561 review) - test_tool_stdout_encoding: three scripts merged since this PR opened (check_compute_journal_overlay.py and compute_workers_win.py with ProjectLeonida#2098, corpus_watch.py with ProjectLeonida#817) get the same stdout guard as the tools here. - test_runtime_paths: the runtime workflow's two path filters now include tools/conformance/**, which runtime/CMakeLists.txt names. The change is ProjectLeonida#1673's (xel1uz), carried here since ProjectLeonida#1673 duplicates this PR. With it, test_tool_stdout_encoding, test_runner_calls_all_tests and test_runtime_paths all pass on main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ProjectLeonida#2098 gave the SDL path its own loop (held 300 ms, then until the title has read the pads six times, at most 5 s), which ignored button@seconds:hold. A press now lasts its own hold, then the read latch, and never past 5 s or its hold if longer. The long-script test checks both: X kept past 300 ms until six reads, Y kept for its 0.6 s after them. It fails on the old loop. Found by AndreiKocherzhinskiiA on ProjectLeonida#1608. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
16 upstream commits after 33bd07c, mostly ProjectLeonida#2098 (post-load GPU memory and pipeline handling) and ProjectLeonida#2122 (the title-texture pass time box). The rules of the earlier merges stand; what this one decided: ProjectLeonida#2098 - GPU console-heap fix (console_heap_gpu.h, console_heap_fix.comp/.inc): taken, opt-in (LEONIDA_CONSOLE_HEAP_GPU, with LEONIDA_CONSOLE_HEAP_VA for the console-addressed heap). Our CPU title-heap sync with the dirty-page watch stays the default: the pass fixes descriptors of a heap at console VAs, and ours reaches title VAs through the page table, so in our default layout it has nothing to do. - Pipeline cache journal and compile helper (pipeline_cache_journal.h, d3d12_compile_helper.h): built, and main.cpp has their precompile/compile-server commands beside ours; our pipeline states do not feed them (as upstream itself went back to PipelineCompiles over the pre-pass, b83ae01). Our per-GPU cache with checkpoints stays. - Post-load memory: the opt-in switches and the stream-queue GPU-only reservation (with our gpu_only_protect) are taken. Not taken: the dedicated-buffer fallback when the arena is full (a VA past the arena is a page-table title VA here; ours answers E_OUTOFMEMORY, d3d12_compute's no_slice case adapted) and LEONIDA_TITLE_HEAP on by default (it conflicts with our 40-bit 64 KiB blocks; it stays opt-in). - Taken: the compile gate (SubmitMutex/SubmitTurn around vkQueueSubmit, vkQueueWaitIdle and the present submit; our compute creates through DriverTurn), async submit with synchronous staging queues and held failures picked up in execute_lists, the prelude pass (wired into our execute_lists and teardown), depth bounds (dynamic state in our PSO recipe, draw capture and replay; DepthBoundsTestSupported from the device feature), the descriptor-table kind word (our insert_key keeps its try/catch), the fsdraw backing hook. request_pipeline_build is a no-op for our PSOs. Others - ProjectLeonida#2122 title-texture refresh, async and time-boxed: taken (on TitleViewTexture). - Indirect mesh draws: taken; our raster-indirect clamp passes the mesh record kind, and a mesh indirect draw is let through when the device asks for the clamp (vk.require_indirect_clamp). Upstream's second clamp call before a stateful indirect draw is dropped: ours runs with the other helper passes, outside rendering. - rdna2spirv: upstream's `fits` check and our `small_index` check, both. - Restored: five lines of our IndirectRasterDraw clamp branch git had dropped outside the hunk (every heavily changed file was checked for such losses). Fixes for new failures - vulkan_present.h: read_back returns the frame whose copy was submitted again (9f98dcc made it wait for a shown present, so a resize with an out-of-date swapchain read nothing); only the disk sample needs a shown frame. - d3d12_indirect_rt(+_upload_sysmem): the new replay part takes vulkan_buffer_range() (upload and readback buffers are arena ranges here) and sets require_indirect_clamp. gameinput_script: reads the pad 6 times before the sleep, as 9f98dcc's held-press rule needs. Tests (runtime\build, 502): 491 pass. Not passing: the known ones (d3d12_clear, run_startup_cmdline, run_tiny_game_eh; d3d12_xdxr_rt(+_check), d3d12_existing_heap (x3), xbox_linear_texture_map; d3d12_set_descriptor_heaps), and d3d12_mapped_plane_async, ProjectLeonida#2122's async twin of the persistent slot-133 plane case that d3d12_existing_heap already fails (the texture does not take its mapped pages' bytes), to fix together with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#2098 made the tagged descriptor probe return (index, kind) as %desc_hit. The branch evaluator still modelled every %desc_lookup_fn call as the bare integer index, so extracting the kind component indexed an int and seven tests errored.\n\nModel a sampled-only hit as the composite the translator now emits: every sampled-dimension bit set, no storage-array bit. A miss remains index zero.\n\nVerification under the machine lock:\n- python -m compileall -q tests/test_image_load_typed.py tools/rdna2spirv.py\n- origin/main copy of tests/test_image_load_typed.py: 28 run, 7 errors (TypeError: 'int' object is not subscriptable)\n- patched tests/test_image_load_typed.py: 28 run, OK\n\nAI-assisted (Devin).
…xture sits in Since ProjectLeonida#2098 (merged in from main) a tagged module reads its instruction's array only when the entry's kind names it; with the 2D bit alone, ps_ssharp_cube and ps_ssharp_3d read the magenta fallback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… (TEST-GAMEINPUT-SCRIPT-READS) 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>
… (2D and 2D array) Since #2098 a tagged module reads its instruction's array only when the table entry's kind names it. The harness binds index 1 in images[1] (binding 0) and in the 2D-array images[1] (binding 3), but tagged it 2D only (2D array in cube mode), so ps_array_resinfo and ps_get_lod_array read the 1x1 fallback on every driver. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflict in runtime/shims/d3d12_title_buffer_windows.h: main (ProjectLeonida#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>
ProjectLeonida#2098's TitleBufferWindows::published_ and update_gpu_backed assumed blocks are never destroyed: for_each_block fed every block made so far into the console heap pass's backed table, and the table was rebuilt only when the published count grew. With empty blocks now destroyed, a freed block stayed in the table, and its "never of memory that is not there" contract broke. - A destroyed block's published_ slot keeps its other fields; only its address (now atomic) goes to 0, and for_each_block and find_mapped skip it. A slot is never reused before release(), so a lock-free reader never sees one half rewritten. - layout_generation() changes whenever a block is made or destroyed; update_gpu_backed uses it instead of the block count to see a change. - destroy_block tells the device (DeviceState::title_block_gone): the block's span goes into released_ranges, as a released backing's does, so the backed table cuts it at once and the key entries and heap slots answering into it go at the next refresh. A block is destroyed only once its last range was freed, after the GPU work that used it completed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since ProjectLeonida#2098 every TitleBufferWindows carries a 128 KiB published_ array, so the eight GeometryViews this test puts on the stack pass the 1 MiB Windows default and the test died at startup with a stack overflow. They are heap-allocated now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ProjectLeonida#2098 gave the SDL path its own loop (held 300 ms, then until the title has read the pads six times, at most 5 s), which ignored button@seconds:hold. A press now lasts its own hold, then the read latch, and never past 5 s or its hold if longer. The long-script test checks both: X kept past 300 ms until six reads, Y kept for its 0.6 s after them. It fails on the old loop. Found by AndreiKocherzhinskiiA on ProjectLeonida#1608. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
RTX 3090 / 621.40: xbox_present fails the resize present_planes check (xbox_present_test.cpp:1226 on main). First bad is 9f98dcc; reverting only its captured_ gating in vulkan_present.h passes. After a resize recreate captured_ stays false, so read_back fails. LEONIDA_COMPILE_GATE=0 and the dxgi_swapchain.h hunk don't change the result. |
…COMPILE-POOL) With LEONIDA_ASYNC_PIPELINES=1 every demanded build, the compute warm-up and the cache checkpoint ran on one general worker (plus a graphics-only one), so one long driver compile held every pipeline a submission asked for behind it, and their draws and dispatches were skipped meanwhile. PipelineCompiler now runs LEONIDA_COMPILE_THREADS workers (half the logical processors, 2 to 8). A worker takes the most urgent job it may: - demanded builds first, in the order they came, then warm-ups by size, then the checkpoint, which waits until no worker compiles; - large builds (compute over 128 KiB, graphics of 1 MiB or more) and warm-ups together take at most threads-1 workers, so one stays free for a small demanded build; at most LEONIDA_COMPILE_HEAVY_MAX large builds at once (default threads-1, 1 with LEONIDA_SERIAL_BIG_COMPILES=1), compute and graphics alike, each still within the memory gate; - warm-ups run one at a time, and none starts while a demanded build runs: each holds the compile gate for its whole create, and a submission waits for every create in flight; - one build of a PSO at a time, so after_running and the teardown rules hold. LEONIDA_COMPILE_THREADS=1 keeps the layout before the pool. The design is MoonEyes' (#2077), ported onto #2098's scheduler. Tests: d3d12_compile_pool (CPU, jobs held at gates: settings, a long build does not hold up a small demanded one, heavy count, free worker, warm-ups one at a time and after demanded builds, order, one job per PSO, release/cancel/ stop_for_exit with jobs in flight), and d3d12_compile_teardown also with one worker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This draft follows #1723. When the shared Vulkan buffer arena fills, an eligible committed buffer can now use a dedicated allocation. An earlier Proton run stopped during upscaler initialization when no arena slice fit the requested buffer.
Claimed as RT-POST-LOAD-GPU-MEMORY. Coordination issue
Changes
Independent review work overlaps the fixed-count and counted indirect mesh paths and pipeline compile workers. Fixed-count mesh dispatches · Count-buffer mesh dispatches · Pipeline compile workers
Verification
db1a22d29, LinuxThe public commit still needs a title boot. Native Windows and playable world rendering remain unverified.
GPU used for the source integration was an NVIDIA GeForce RTX 4070 on Linux under Proton. Public-head runtime checks are in progress.
Contributors include Plaaasma and ivanepsilondelta. AI-assisted.