Skip to content

d3d12: merge bundle of eight open runtime PRs, conflicts fixed (#2020 #2166 #1851 #2465 #1705 #2117 #2012 #407) - #2509

Merged
aslan2142 merged 29 commits into
ProjectLeonida:mainfrom
OreoFR:consolidate/eight-gb-world
Nov 27, 2026
Merged

aslan2142 merged 29 commits into
ProjectLeonida:mainfrom
OreoFR:consolidate/eight-gb-world

Conversation

@OreoFR

@OreoFR OreoFR commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

A merge bundle asked for by @aslan2142: eight open runtime PRs merged onto main 39f52f3 in one branch, with their conflicts fixed, so they can be reviewed and merged together. No new code beyond the conflict resolutions. Each PR keeps its own commits and authors (merge commits, no squash).

Claims: this bundles the PRs' own items, it claims nothing new: RT-PLACED-DEFER-STAGED (#2020), RT-TITLE-PARTIAL-MIPS (#2166), RT-HOST-IMAGE-COPY-SWITCH (#1851), RT-TITLE-WINDOW-RETIRE (#2465), RT-TITLE-HASH-WC-STREAM (#1705), RT-CONSOLE-VSHARP-MEMO (#2117), RT-TITLE-TEXTURE-REFRESH-ENVELOPE-AND-WRAP (#2012), STAGED-COPY-OWN-WAIT (#407).

Depends on: #2020, #2166, #1851, #2465, #1705, #2117, #2012, #407 (merging this one merges them; the separate PRs can then be closed).

What was merged, in order

PR Author What Conflicts
#2020 @DadaCap a placed BC image the title has not filled shares a zero image none
#2166 @DadaCap readable smaller mips of a title texture whose larger ones are missing none
#1851 @QemmHD LEONIDA_HOST_IMAGE_COPY switch, auto off on NVIDIA none
#2465 @DadaCap retire a title window nothing reaches none
#1705 @DadaCap the texture hash reads write-combined memory through a streaming copy none
#2117 @azsekazvamdimitar console heap V# words fixed once a pass none
#2012 @IlyassRS3 O(1) envelope fast path in title_texture_refresh runtime/CMakeLists.txt
#407 @Kokonotcu CPU subresource copies wait for their own submission only runtime/shims/d3d12_vulkan_device.cpp (3)

How the conflicts were fixed

Tests

On an RTX 4070 Laptop GPU 8 GB (NVIDIA 621.40, Windows 11), RelWithDebInfo, Ninja:

AI-assisted (Claude Code, Claude Opus 5.5). Tested on an RTX 4070 Laptop GPU 8 GB, NVIDIA 621.40, Windows 11.

🤖 Generated with Claude Code

Kokonotcu and others added 29 commits November 23, 2026 20:44
WriteToSubresource/ReadFromSubresource without host image copy replay a
CopyTextureRegion on a staging VulkanQueue and wait for it. The wait was
VulkanQueue::idle(): vkQueueWaitIdle on info.queue, the VkQueue the first
D3D12 direct queue also uses, under the device's submit lock. Every such
CPU copy waited for all the game work queued there, and no queue could
submit meanwhile.

- VulkanQueue::wait_submitted waits on the queue's own progress timeline
  for what it submitted, without the submit lock (bounded slices, wakes on
  device loss). The staging copy uses it instead of idle().
- The staging queue is on a VkQueue the game's first queues are not on
  (CreateCommandQueue hands each family's out from the first, so the
  last): the copy family's for colour textures, whose engine runs beside
  queued graphics work; the graphics family's for depth/stencil and rgb96
  textures, whose copies may run the D24/rgb96 compute pass. A second
  graphics VkQueue alone did not help on NVIDIA: the timeline wait still
  took the whole 32 ms, the copy ran behind the busy queue. Where the
  family has one VkQueue the copy shares info.queue as before.
- No waits on other queues are attached: D3D12 requires the application
  to have seen the texture's GPU work complete before a CPU copy (it waits
  on a fence its queue signalled), and that host wait followed by this
  submission orders the work before the copy and makes its writes visible.
  Pending work of other queues would only be waited for needlessly.

Measured (d3d12_staged_copy_wait_test, RTX 3080 Laptop, standalone
device): a staged 64x64 WriteToSubresource while the direct queue has 32 ms
of buffer copies queued took 31.8 ms before, 0.10 ms now (the direct queue
still busy after it); the bytes round-trip. d3d12_subresource_copy (both
paths, 109 steps against the host and Microsoft's answers), d3d12_rgb96 and
the new test are clean under LEONIDA_VK_VALIDATION=1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ined memory through a streaming copy (RT-TITLE-HASH-WC-STREAM)

refresh_title_textures hashes every byte of a mapped texture of up to 4 MiB each sixth pass, straight from the
title's pages. In a real boot those pages are write-combined, where ordinary loads are not cached: on the intro one
such hash took 36 ms on average and up to 78 ms, so every sixth pass cost one to two frames and the title presented
24 frames a second where it paces itself for 30. The bytes now come through copy_guarded's streaming copy, as the
fill of the same texture already does, and the copy is hashed: 0.4 to 1.1 ms.

The test places a mapped plane in ordinary and in write-combined pages and changes one byte the sampled hash does not
cover.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The layer enables VK_EXT_host_image_copy for WriteToSubresource and
ReadFromSubresource whenever the device has the extension and its
hostImageCopy feature. On an RTX 4070 SUPER (Windows 11) a real boot lost
the device with WRITE_INVALID in 7 of 7 runs that used host image copies
and in 0 of 2 that did not. The mechanism is not known yet.

LEONIDA_HOST_IMAGE_COPY chooses: 0 never, 1 whenever available, auto (the
default, also for unset or unrecognized text) as 1 except on NVIDIA
(vendorID 0x10DE), where it is off. Off, the extension is neither enabled
nor chained, so no image gets host-transfer usage and every CPU texture
copy takes the existing staging submit, as on a device without it.

The choice is a pure function (src/host_image_copy_policy.h) with a unit
test of its table, and device creation logs one line with the choice and
the reason in place of the old "no VK_EXT_host_image_copy" line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf
…copies too

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…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
…-mips

# Conflicts:
#	runtime/shims/d3d12_vulkan_device.cpp
…checks kept)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
DadaCap identified the short-mapping case in the review of PR ProjectLeonida#1920. Reuse and allocation now require full coverage, preserving both live aliases when a request spans a boundary.
…t still goes back (RT-TITLE-WINDOW-RETIRE)

On top of ProjectLeonida#1920, which keeps stream-pool extents inside the free span in
both views and makes TitleVaAliases::add_twin refuse an overlap. Other
ranges still replace a window's ranges whole by design: a slot-133 buffer
the title places over the window's pages, a BVH input's exact copy, an
upload alias. The window was then left in title_windows and pool_spans,
refreshed at every submission and charged to LEONIDA_TITLE_WINDOWS_MB, with
nothing left to reach it. A retail run showed most of the windows' memory
growth to be such orphans; the title released none of the windows' pages,
so retiring a window with its pages never fired.

A window no range answers from any more is retired after the next
submission's refresh: the alias table's listener records removed ranges'
copies, and the touched windows TitleVaAliases::answers_into finds
unreached leave pool_spans and the budget at once.

Its memory is freed only once nothing can still reach it. A command list
resolves its root views when they are recorded (GraphicsCommandList::
address), so a list recorded before the retirement and executed, or
executed again, after it still names the window; so does the copy of the
lists a held batch (a Wait before its Signal) or the async worker keeps.
Each backend CommandList, and each copy, now carries the epoch its
recording began in (src/command_list_epochs.h); a retired window takes its
ticket only once no list older than its retirement is alive and the
replays in progress then have recorded their submissions, and is freed
when that ticket has completed.

Until then the copy stays a target of its pages' tracker, still
refreshed, and what the GPU wrote in it goes back to the title's pages:
with its submissions' write-back, and once more when it is freed. The
second is needed because a list's ranges are noted when it is recorded,
so a held batch's can go back, tagged with a later submission's ticket,
before the batch has run. A retired copy goes back only where no live copy
changed the bytes, and every copy is compared, 256 bytes at a time, with
the title's bytes as they were before any copy went back: a copy that
still held them used to overwrite another's result when it came later in
the tracker.

Tests: d3d12_title_window_orphans. A window a slot-133 buffer replaced is
retired, its bytes returned and its memory freed. A writing batch held on
a fence on another queue, recorded before the next submission's refresh
retires its window, keeps the window alive past a completed submission,
and once it has run and its list is reset, its 64 words reach the title's
pages and the window is freed. Without the retirement the window stays
(3 -> 3 windows); without the list epochs it is freed while the held batch
still names it; without the last copy back 0 of 64 words arrive.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
…over them, not a zero-size view (RT-TITLE-WINDOW-RETIRE)

ProjectLeonida#1920 stops a new pool extent at the next mapping in either view and, in
d78b0e9, refuses a mapping shorter than the request: such a request
gets a zero-size view (loads 0, stores dropped). That keeps the views from
reaching past their copies, which the first version of this fix did not,
but a refusal is a regression for requests main served: a V# or a root
view (64 KiB, kRootViewBytes) that crosses from one extent into the next,
or starts inside one and ends past it. Stream-pool extents sit next to
each other, so these are common. Retail runs (local, RTX 5080): our
first version, which gave such requests a short mapping, crashed in the
title in one run (m176); with one mapping over the request instead, runs
m177-m179 ran without one. The crash's cause was not established.

At ProjectLeonida#1920's two refusals of a request longer than what would serve it
(the extent clipped by clip_title_pool_extent, or the mapping holding its
first byte), resolve_pool_memory now tries, after ProjectLeonida#1920's reuse,
cover_pool_request: one mapping over the request and every window it
reaches, each whole, in both views (title_pool_cover). It is entered with
the new TitleVaAliases::replace_twin, since add_twin refuses an overlap;
the windows it replaces are retired at the next submission like any
window nothing answers from (previous commit), and their bytes are not
charged to the budget twice meanwhile. With a range in the way that is not
a window (a slot-133 buffer, a geometry copy), or pages that are not
readable, ProjectLeonida#1920's refusal stands. ProjectLeonida#1920's own refusal when the window
cannot be made or entered is unchanged.

TitleVaAliases::resolve and resolve_title_memory already ask again for a
range that ends before the view (ProjectLeonida#1920); vsharp_address did not, so a
V# whose base lies in a short range was refused without asking: it now
asks resolve_title_memory first.

Tests: ProjectLeonida#1920's pass unchanged (their seam cases cross a range that is
not a window, which still gets a zero-size view). title_window_plan: the
cover takes a window whole in both views, refuses a buffer in the way and
past the cap, and replace_twin enters it where add_twin refuses.
d3d12_title_window_orphans: a 64 KiB CBV across two extents' seam gets
one 448 KiB mapping, a valid V# and the right words on the GPU, and the two
extents are retired at the next submission; without the cover its V# base
is 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
…or (RT-TITLE-WINDOW-RETIRE)

ShadowPages::write_back builds the list of targets with bytes in a run while it holds the tracker's lock_. Nothing
under that lock may touch the process heap: a title thread inside HeapAlloc can fault on a guarded heap-header page
and wait for lock_, while this thread would wait for the heap lock in push_back. Use the class's Vector alias
(leonida::host_heap), as the tracker's other containers do. Found in review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
…ot (RT-CONSOLE-VSHARP-MEMO)

The title writes the same words into thousands of slots of its console
descriptor heap, many of them data that reads as a V# into title memory
with no copy, and each fix_vsharp of those costs VirtualQuery calls: a
third of the submitting thread's time after the story load under Wine.
refresh_console_heap now keeps fix_vsharp's answers for the pass over the
copied slots and, separately, for the pass over the slots the changes
since the last submission touch, and drops them after each.

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

AI-assisted; tested under WineHQ 11.22 and GE-Proton11-14 on an RTX 3090
(NVIDIA 590.48.01).
# Conflicts:
#	runtime/CMakeLists.txt
#	runtime/test/d3d12_title_va_test.cpp
…-TITLE-WINDOW-RETIRE)

title_pool_cover translated a mapping found in the pool's other view back
with `x - (twin - va)` modulo 2^64. A window that starts below the twin
view (m.title_va < twin - va) wrapped to near UINT64_MAX, passed the
pool bounds check, and replace_twin then erased it whole, leaving the
part of it outside the cover unanswered. A twin view that does not fit
in 64 bits (twin < va - pool_lo, or pool_hi - va > UINT64_MAX - twin)
made the twin-view query wrap into an empty range, so a range in the way
was not seen at all.

The twin view's bounds [twin_lo, twin_hi) are now checked up front,
queried in non-wrapping coordinates, and a hit outside the view it was
found in refuses the cover like one outside the pool.

title_window_plan_test: check_pool_cover_bounds with the review's
example (pool [0x100000, 0x500000), va 0x120000, twin 0x420000, window
[0x200000, 0x440000)) and the two overflow cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
…-WINDOW-RETIRE)

cover_pool_request planned its cover (title_pool_cover) under short
shared locks of the alias table, then made the mapping and entered it
with replace_twin, which erased every range in the span unconditionally.
A slot-133 buffer is entered (Resource::alias_title_va) without
title_window_mutex, so one placed in either view of the span in between
was erased with the windows. And replace_twin's result was ignored: the
cover was recorded in pool_spans and returned as made either way.

replace_twin now takes the caller's predicate and, under the same
unique lock as the replacement, refuses with nothing changed when a
range it would erase is not one the caller planned to replace. The
cover passes the windows its plan found. On refusal the window it made
is dropped at once (drop_title_window: nothing answered from it, so no
submission names it) and the request falls back to the zero-size view
as before. The same drop now follows add_twin's refusal in
resolve_pool_memory, which left its new window charged to the budget
and refreshed with nothing answering from it.

title_window_plan_test: a non-window range entered in the cover's span
(CPU view, then twin view) between title_pool_cover and replace_twin is
refused and left intact.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
…W-RETIRE)

ShadowPages::write_back compared the copies in 256-byte pieces and kept
one flag per piece: once a live copy had changed any byte of it, a
retired window's copy was left out of the whole piece. A retired window
and the slot-133 buffer that replaced it can have written disjoint
bytes of one piece (the window [384, 512), the buffer [256, 384)), so
the window's bytes were dropped. The batch path (`only` null) had the
same flag (`live = live || pass == 0`).

The piece now keeps a fixed 256-entry mask on the stack (no heap under
lock_) of the bytes a live copy changed, set in the first pass; a
retired copy goes back on every byte it changed that no live copy did,
in runs. Copies are still compared against the title's bytes as they
were before any copy went back, and a live copy now writes only the
bytes it changed, so one live copy no longer writes the title's older
bytes over another's result in the same piece.

d3d12_title_va_test --window-orphans: the held submission writes through
the window from ring + 384, a later one through the buffer placed over
the ring from ring + 128, and all the held words must reach the title's
pages (32 of 64 did before). The ring is write-combined so the buffer is
a copy on every driver. New ctest entry d3d12_title_window_orphans_free
runs it with LEONIDA_TITLE_WRITEBACK=0, where the window's free is the
only way back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
…E-WINDOW-RETIRE)

retire_orphan_windows frees the retired windows whose submissions have
completed after this submission's refresh_shadows, and freeing writes
the window's copy back to the title's pages once more
(free_retired_shadow). The refresh had already copied those pages to
the live copies, so the slot-133 buffer that replaced the window read
the older bytes until the next submission.

Moving the free ahead of the refresh, as suggested, is not enough on
its own: the write-back opens the pages it writes, and the refresh's own
copy back of the live copies' batches (write_back_titles) then takes
those pages for ones the title wrote and drops the buffer's GPU results
there (measured with this test: with the free moved first, the words
written through the buffer did not all reach the pages). So the free stays after the refresh, and a
retired copy's bytes that go back are written into every other copy over
them that still held the title's older bytes, as the next refresh would;
a copy that changed a byte keeps its own. Under lock_, in place, no
allocation. The epoch/ticket gating (src/command_list_epochs.h,
stamp_retired_windows) is untouched.

d3d12_title_va_test --window-orphans: the submission that frees the
window reads the held words through the buffer placed over the ring.
With LEONIDA_TITLE_WRITEBACK=0 (d3d12_title_window_orphans_free) it read
0 of 64 before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
submit_write keeps main's second root UAV (va2) and our wait flag: (s, va, va2 = 0, wait = true); the two callers that only execute pass va2 = 0 explicitly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwSKP7weM2P7sk5skto
# Conflicts:
#	runtime/CMakeLists.txt
# Conflicts:
#	runtime/shims/d3d12_vulkan_device.cpp
…ctLeonida#407 merge (comment only)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aslan2142
aslan2142 merged commit 34e33d3 into ProjectLeonida:main Nov 27, 2026
6 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants