Commit Graph

12 Commits

Author SHA1 Message Date
4a305d0666 d3d12/vulkan: bind/map staging before binding VRAM buffer & document LEONIDA_EXTERNAL_WINDOWS_MB 2026-12-01 17:04:33 +02:00
8ebe7cc2e8 d3d12/vulkan + make_game: ReBAR DMA readback, budgeted staged slabs, test fixes & CLI wiring 2026-12-01 16:40:36 +02:00
9d41505a44 d3d12/vulkan: staged VRAM arena, DMA readback batching, parallel shadows, stream-pool fix
On top of PR #2566 (8db8335d2), combines verified runtime performance and
correctness improvements for non-ReBAR Vulkan GPUs (tested on Linux / Wine /
RTX 3090 24 GB, BAR1 = 246 MiB, driver 590.48.01):

- Stage 4 GiB GPU address arena + overflow TitleBufferWindows slabs in
  DEVICE_LOCAL VRAM with HOST_VISIBLE staging mirrors (arena_staging.h,
  arena_staging_test.cpp).
- Fix startup glibc realloc() race by caching max_compute_shared_memory_size,
  sharing mutex-guarded VkPipelineLayouts, and eagerly loading pipeline_cache()
  during single-threaded Device construction.
- Stage 9a-1: batch retired arena + external window host readbacks into a
  single copy_buffers_sync() submission on the dedicated DMA copy queue
  (wb: 27.6 ms -> 2.35 ms/frame).
- Stage 9a-2: parallelize ShadowPages::refresh across 4 persistent threads
  via ShadowRefreshPool (shadows: 26.9 ms -> 10.2 ms/frame).
- Fix resolve_pool_memory() zeroing out root descriptors probed with
  kRootViewBytes (64 KiB) near the end of committed stream-pool blocks
  (stream pool unbacked: 131,072 -> 16-33, root view unbacked: 0).

AI-assisted. Verified with 151/151 portable Linux CTest passing and Windows
MSVC build + retail boots on RTX 3090 (590.48.01).
2026-12-01 16:37:00 +02:00
9d46dd6475 d3d12: V# bases as signed offsets when every module sign-extends them; a sparse arena only then (RT-MEMORY-MODEL)
RADV puts sparse buffers 64 TiB above ordinary ones, so with the sparse arena of the previous commit every geometry
copy and title-window block lay below heap_base and TitleBufferWindows::allocate refused it (it accepted only a
positive offset below 2^47). Shaders translated since 2026-11-24 sign-extend a V#'s 48-bit base and say so in their
index entry (vsharp_base_sign_extended), and RADV hands out every address from one 2^47 half of the 48-bit space, so
any block is within reach of heap_base as a signed offset.

- shader_library.h: VsharpBaseCensus counts the marker over every loaded module; signed only when all have it.
- The device reads V# bases signed when the census says so (or with LEONIDA_IMPORT_BELOW_ARENA=1, as before). The
  import refusal still follows that setting alone. One line logs the census.
- create_arena: the arena is sparse only with signed offsets; otherwise one allocation, and one line says why.
- TitleBufferWindows::shader_reachable replaces the positive-only check. The first failure of each Vulkan call while
  making a block, and the first block refused for its address, are logged.
- rebase_title_vsharp sign-extends a base it already rewrote below heap_base.
- device_arena_memory (for tests); cs_user_data.comp reads V# bases sign-extended, as translated shaders do.

Tests: d3d12_title_va_game_device and d3d12_geometry_views_game_device (d3d12_title_va_test --game-device: the
device the game makes, with the arena's bind queue); geometry_views_test (shader_reachable at the measured RADV
addresses and the range edges); shader_library_test (the census). Wine suite on the iGPU: 429 pass / 23 fail against
425 / 23 on main 8bc59a74c, nothing pass to fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 17:03:39 -05:00
36771ec53d d3d12: geometry copies in system memory, and retired when the title remaps their pages
Geometry copies held 4.4-6 GB of VRAM in world runs and were never evicted: a view retired only when its range was
freed, decommitted or unmapped, and the title streams by remapping the frames of its pools.

- LEONIDA_GEOMETRY_HOST (unset by default): 1 puts the copies in system memory outside VRAM, write-back where the
  device offers a cached host type; 2 write-combined. The memory type is picked among the host-visible types that are
  not device-local (memory_type_order alone would give the BAR first); a device with none keeps its types. Logged once
  and in the geometry buffers line.
- LEONIDA_GEOMETRY_REMAP_RELEASE (on by default, 0 off): XMemMapPhysicalPages with pages, the scatter call and
  CopyPageMappingsBatchX report the pages whose frame changed (or went) as released (xmem's RemapReleases, collected
  under the fault lock, reported after it), so GeometryViews retires the copies over them through #2094's
  drain_released and kAfterExecutes reaping. A page mapped again to its own frame is no change.
- A retired view is copied once more from its pages when they are readable: a list recorded before a remap that took
  the view's address reads the new bytes, as the refresh this replaces would have given it.
- A stream-pool extent backed by a retired copy leaves pool_spans (it was kept for the device's life).
- A full release queue joins touching ranges before it collapses into one covering range.

Tests: geometry_views_test cases 14-16, xmem_test test_remap_releases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 09:07:51 -05:00
b21b47b052 d3d12: no table keeps naming a destroyed title-window block
#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>
2026-11-25 21:30:07 -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
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
c09ee75c0e d3d12: geometry views drain on the submit thread, bound the release queue, keep one empty block
- Drain released geometry ranges only in the submit-thread before_execute callback, removing recording-thread drain calls and GeometryViews::should_reclaim().
- Filter geometry_writes::note_released() against monotonic watched_lo/watched_hi bounds and collapse the queue on 65536-entry overflow instead of dropping ranges.
- Bound GeometryViews::retire_range() walks using max_view_bytes_ and an ordered refused_ map with max_refused_bytes_.
- Keep one empty 4 MiB spare block in TitleBufferWindows (dropping it when needed under a cap), remove failed_ reset in free(), and cover all four points in geometry_views_test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 20:54:56 +02:00
e54c69175a d3d12: evict geometry views on range release and retry refused ranges
RT-GEOMETRY-VIEW-EVICTION: free GeometryViews entries when their backing
title range is released or unmapped, deferring Vulkan storage reclamation
until in-flight GPU work completes, and retry cap-refused ranges once
budget is freed.

- Queue released title ranges from xmem (XMemFree/Default, VirtualFree
  MEM_RELEASE/MEM_DECOMMIT, XMemMapPhysicalPages unmap, CopyPageMappingsBatchX
  unmap range) via leonida::geometry_writes::note_released.
- Add coalesced sub-range freeing and empty-block Vulkan destruction to
  TitleBufferWindows.
- Retire overlapping views immediately from lookup/find/refresh/watch and
  title_va_aliases, and reap their backing storage once
  completed_retire_ticket() reaches the view's retire ticket.
- Track free_generation_ per refused key so resolve() short-circuits while
  nothing changed and retries once budget is reclaimed.
- Extend geometry_views_test.cpp with small-cap eviction, deferred GPU
  retirement, retry, and full block reclamation checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 20:46:30 +02:00
ba626820ec Integrate post-story-load memory, queue and Vulkan runtime changes
Preserve physical window aliases across remaps, order console list values,
and replay bounded indirect graphics with captured draw state. Coordinate
pipeline lifetime, texture refresh and queue teardown. Add synthetic CPU
and GPU coverage for the integrated paths.

Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com>
Co-authored-by: ivanepsilondelta <264061546+ivanepsilondelta@users.noreply.github.com>
2026-11-25 03:44:43 -06:00
273b3bdf9d [integration] Linux/Proton and native Windows: boot through the story load (RT-PROTON-STORY-LOAD)
One squashed commit of a fork that was developed on a Linux/Proton machine and
tested on two native Windows machines. On all of them the retail 1.0.2.1
package now launches, shows its launch movie, first-run pages and landing
prompt, runs the story load to its end with the loading slideshow drawing its
artwork, and enters the world phase. A first world frame is not verified yet.
docs/linux_proton.md has the setup, a healthy boot's timeline, the machines
and where it stops.

Runtime: frames in the title's own window; DirectStorage pinned reads,
page-list scatter/gather, BCPack and unshuffle with a locally generated
predictor file; pooled, device-local and deferred image backing for streamed
and placed textures; enhanced barriers into LAYOUT_UNDEFINED; a bindless table
that degrades instead of refusing a submission; a descriptor hash finalizer
(off until a library carries it); directly indexed heap offsets for compute
dispatches and VS/PS/GS draws; title buffer windows outside a fragmented
arena; opt-in device-local copies of streamed buffer views; write-fault
retries under the tracker lock, shared trackers and write-watched title memory
for native Windows; device-loss, compute-input and memory probes.

Translator: loop bounds at structured exits, the eight FidelityFX programs
that use a packed-dot form the disassembler skips, buffer bounds modes per
view kind, a compaction option, the hash finalizer option.

Tools and scripts: Linux boot scripts (Wine/Proton, no network), a Windows
boot script, the paired compute translation script.

No game data. AI-assisted (Claude Code and Codex agents), reviewed and booted
by people on the machines named in docs/linux_proton.md.

Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-24 11:42:12 -06:00