Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9b77601
CPU subresource copies wait for their own submission only (review D9)
Kokonotcu Nov 24, 2026
abe3f20
d3d12: the every-byte hash of a mapped title texture reads write-comb…
DadaCap Nov 25, 2026
59c1586
d3d12: LEONIDA_HOST_IMAGE_COPY switch, auto off on NVIDIA
QemmHD Nov 25, 2026
fba6ce2
runtime: add O(1) envelope fast path and explicit wrap to title_textu…
IlyassRS3 Nov 25, 2026
e500e99
d3d12: CPU-fillable placed BC images share a zero image without host …
DadaCap Nov 25, 2026
a1df171
d3d12: LEONIDA_TITLE_PARTIAL_MIPS fills the readable smaller mips of …
DadaCap Nov 25, 2026
f36d89e
Merge remote-tracking branch 'origin/main' into title-texture-partial…
DadaCap Nov 26, 2026
c842321
Merge origin/main into placed-defer-no-host-copy (both staged-device …
DadaCap Nov 27, 2026
7557fe8
Keep live VA mappings when mirroring a stream pool
lixonik Nov 25, 2026
d78b0e9
Refuse stream-pool mappings shorter than the requested span
lixonik Nov 27, 2026
555cf92
d3d12: retire a title window nothing reaches; what the GPU wrote in i…
DadaCap Nov 27, 2026
8e8fe24
d3d12: a stream-pool request that runs into windows gets one mapping …
DadaCap Nov 27, 2026
2773ab8
d3d12: the write-back's list of copies over a run is a host_heap vect…
DadaCap Nov 27, 2026
2a19104
d3d12: a console heap's V# words are fixed once a pass, not once a sl…
azsekazvamdimitar Nov 25, 2026
916868e
Merge remote-tracking branch 'origin/main' into window-retire-on-1920
DadaCap Nov 27, 2026
b8754f6
title_window_plan: bound the twin view without modular arithmetic (RT…
DadaCap Nov 27, 2026
e1f8251
d3d12: a pool cover replaces only the windows it planned to (RT-TITLE…
DadaCap Nov 27, 2026
7afb872
d3d12: a retired window's copy goes back byte by byte (RT-TITLE-WINDO…
DadaCap Nov 27, 2026
4392670
d3d12: a freed window's last bytes reach the live copies too (RT-TITL…
DadaCap Nov 27, 2026
5e8d334
Merge origin/main into window-retire-on-1920
DadaCap Nov 27, 2026
c20733f
Merge #2020 into consolidate/eight-gb-world
OreoFR Nov 27, 2026
00f317f
Merge #2166 into consolidate/eight-gb-world
OreoFR Nov 27, 2026
6014cb1
Merge #1851 into consolidate/eight-gb-world
OreoFR Nov 27, 2026
048eeed
Merge #2465 into consolidate/eight-gb-world
OreoFR Nov 27, 2026
75151be
Merge #1705 into consolidate/eight-gb-world
OreoFR Nov 27, 2026
f47ca26
Merge #2117 into consolidate/eight-gb-world
OreoFR Nov 27, 2026
bab6356
Merge #2012 into consolidate/eight-gb-world
OreoFR Nov 27, 2026
e65692a
Merge #407 into consolidate/eight-gb-world
OreoFR Nov 27, 2026
466dfb7
d3d12: the staging queues' comment above their fields after the #407 …
OreoFR Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 60 additions & 7 deletions docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -1707,8 +1707,30 @@ The copies:
(logged once otherwise).
- Any **other address in the title's memory** gets a window: the 64 KiB-aligned pages it covers, clipped to the
title's range, copied into the arena now and before every submission, through the same shadow refresh as slot 133
(so dirty-page tracking for that refresh applies to both). Windows stay until the device goes, up to
`LEONIDA_TITLE_WINDOWS_MB` (64 MiB by default). A window that
(so dirty-page tracking for that refresh applies to both). A window never covers bytes an existing range already
serves: it stays inside the free span around the address (and a stream-pool extent inside the free span in both of
the pair's views), because a range entered over a live one replaces it whole, and the copy that range answered from
would be left reached by nothing. Windows stay while an address range still answers from them, up to
`LEONIDA_TITLE_WINDOWS_MB` (64 MiB by default). A window that no range answers from any more (a slot-133 buffer the
title placed over its pages, or a BVH input's exact copy, replaced its ranges) is **retired** after the next
submission's refresh: the alias table's listener records the removed ranges' copies, and a window none of its
ranges is left for loses its stream-pool extent and its bytes of the budget at once. Its memory is freed once every
`ExecuteCommandLists` replay in progress then has recorded its submissions, every command list whose recording
began before the retirement is gone (reset, released, or a held batch's or the async worker's copy of it run), and
the submissions recorded by then have completed: a list resolves its root views when they are recorded, so one
recorded before the retirement and executed, or executed again, after it still names the window
(`src/command_list_epochs.h`). Until then its copy stays a target of its pages' tracker, refreshed like the others,
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 (a range noted when a list was recorded can be copied back before a held batch has run). A retired copy goes
back only on the bytes no live copy over them changed, byte by byte (the window and the buffer that replaced it can
each have written their own bytes of one 256-byte piece), and every copy is compared with the title's bytes as
they were before any copy went back. The bytes a retired copy returns are also written into every other copy over
them that still held the title's older bytes, as the next refresh would: a window is freed after its submission's
refresh, and the range that replaced it reads its last bytes in that same submission. `d3d12_title_window_orphans` covers it, with a writing batch held on a fence
while the next submission's refresh retires its window. A window is
not retired when its pages are released or remapped: a retail run measured no release at all of the pages windows
cover (the title remaps its pool frames instead), and the tracker follows the pages.
A tracker the window shared with a copy still live keeps its extent (a retirement never splits one). A window that
cannot fit between the title's address reservations can use a separate mapped buffer. The buffer's device address
must fit as a positive 47-bit offset from the arena base. The same window cap and dirty-page refresh apply.
`LEONIDA_STREAM_BUFFER_WINDOWS=0` requires the window to fit in the arena.
Expand All @@ -1721,7 +1743,7 @@ The copies:
title itself wrote in between keeps the title's newer bytes and its GPU result is dropped. The copy back asks the
write watch first (the refresh's own asking comes after it, so a hot page's last answer is a submission old), passes
over pages whose mapping changed, that a kernel write may be filling or that xmem maps at another address too, and
writes only the 256-byte pieces where the copy differs from the title's bytes: a read-only view writes nothing and
writes only the bytes where the copy differs from the title's (compared in 256-byte pieces): a read-only view writes nothing and
its pages stay guarded. The copy runs under the tracker's lock and can still fault on a page another guard keeps
read-only (the geometry watch, another view's shadow): the fault handler asks every tracker over the address, this
one included, and on the thread whose copy faulted it does not take that lock again (an SRW lock is not
Expand All @@ -1738,9 +1760,22 @@ The copies:
loses the device. The refusal and the count of zero-size views are logged.
- A **stream pool** (the title's CPU view paired with a 16-24 GiB GPU-only
alias) is not windowed per request. The GPU-only pages are translated to the CPU view of the same frames (rule B in
that note), and **one mapping serves a page-aligned readable run** of the pool (at most 1 MiB, a geometry copy when
the cap allows, a window otherwise). Both addresses of the pair are entered in the table, so a V# naming either
reaches that one mapping instead of asking for a second one; `LEONIDA_GEOMETRY_MB` is the preferred backing.
that note), and **one mapping serves a page-aligned readable run** of the pool (at most 1 MiB, and never past the
next mapping in either view; a geometry copy when the cap allows, a window otherwise). A request whose byte a
mapping already holds in either view is served by it when the mapping holds all of the request's bytes, and the
other view is entered as far as that mapping reaches. A request never gets a mapping shorter than its bytes (a V#'s
size, 64 KiB for a root view): one that runs into the next mapping, or past the end of the one holding its first
byte, gets one mapping over itself and every window it reaches, each whole, in both views (`title_pool_cover`,
`TitleVaAliases::replace_twin`), and those windows are retired at the next submission. `replace_twin` checks, under
the lock it replaces them under, that every range it would erase is one of those windows: a slot-133 buffer is
entered without the window lock, so one placed in the span after the plan makes it refuse, the new window is dropped
and the request falls back as below. Only with a range in the way
that is not a window (a slot-133 buffer, a geometry copy) or that reaches past the pool in its view, or pages that are
not readable, does it get a zero-size
view: a refusal there would also have the root views a title rings through a pool read zeros where it served them
before. `vsharp_address` asks again, like `TitleVaAliases::resolve`, when the range holding a V#'s base ends before
the V# does. Both addresses of the pair are entered in the table, so a V# naming either reaches that one mapping instead of
asking for a second one; `LEONIDA_GEOMETRY_MB` is the preferred backing.
Acceleration-structure destinations and scratch also resolve through the table, and a structure no window holds
whole gets a copy of its whole range, so the BVH builder's commands are recorded.
- `LEONIDA_GEOMETRY_MB` sets the device-local memory cap for streamed buffer views. The default is 0.
Expand Down Expand Up @@ -3513,14 +3548,24 @@ The console has two list topologies Vulkan lacks: rectangle list (`IASetPrimitiv
the driver's), as on D3D12.
- GPU-writable slot-133 images on a default heap bind memory when replay, presentation or creation of a shader
view first needs their Vulkan image. D3D12 placement and logical attachment views can precede that bind.
A CPU-fillable, typed BC texture can initially sample an immutable zero image of the same format, extent,
A CPU-fillable, typed BC texture (filled by host copies or the staged upload) can initially sample
an immutable zero image of the same format, extent,
layer count and mip count. A CPU upload or explicit GPU command gives the placement private backing and
republishes its existing descriptor keys. The cache holds at most 256 MiB. `LEONIDA_PLACED_IMAGE_DEFER=0`
restores eager binding.
- A slot-70 sampled texture whose source pages are unreadable reserves its image backing on the first
complete CPU read. Copies of descriptors written earlier resolve to the fallback until that upload succeeds.
`LEONIDA_TITLE_IMAGE_DEFER=0` allocates these textures eagerly. The memory probe reports the live unbound
image count and its Vulkan memory requirements in MiB.
- With `LEONIDA_TITLE_PARTIAL_MIPS=1`, such a texture can be filled before all its pages are readable. 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
the first `mip_chain_bytes(layout, m)` bytes from its base (`xg_xs_layout.h`; checked in `xg_xs_test` for tiled,
tail and linear layouts). The probe (`texture_memory_readable_bytes`) returns how many bytes from the base are
readable and `first_mip_within` the first mip those hold. When the last slot-70 view starts at that mip or later,
the mips from there on are filled and only the descriptor keys of views that start there or later are published.
The others stay on the fallback (`PendingImage::first_mip`) until a later fill has their mips. The image still has
memory for every mip: `LEONIDA_TITLE_PARTIAL_MIPS_MB` (2048) limits the image memory of the textures filled in
part. Arrays, cubes and volumes are filled whole or not at all.
- Small optimal Vulkan images synthesized for slot-70 texture views share memory pages. Each slice meets the
image's size, alignment and memory type requirements. The GPU retirement queue destroys the image before its
slice can be reused. Large images, dedicated-only images, and failed pool allocations use individual memory
Expand Down Expand Up @@ -3566,6 +3611,14 @@ The console has two list topologies Vulkan lacks: rectangle list (`IASetPrimitiv
without host-transfer usage before it is bound, and takes the staging path. `d3d12_vulkan_device_test` and
`d3d12_subresource_copy_test` force this branch on any GPU with `VulkanDeviceInfo::force_host_transfer_retry`
(their third CPU-copy path; the second compares it with the host runtime).
- `LEONIDA_HOST_IMAGE_COPY` chooses whether the device enables the extension at all (`src/host_image_copy_policy.h`,
tested by `host_image_copy_policy_test`): `1` wherever the device has it, `0` never, and `auto`, the default, as
`1` except on NVIDIA (`vendorID` `0x10DE`), where it is off. 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; why is
still under investigation. Off, the extension is neither enabled nor chained, no texture gets host-transfer
usage, and every copy takes the staging path, as on a device without the extension. Device creation logs one
line, `[rt] d3d12: host image copy: on (available)` or `off (...)` with the reason. Results with
`LEONIDA_HOST_IMAGE_COPY=1` on other NVIDIA GPUs and drivers are welcome in an issue.
- 96-bit textures (`R32G32B32_FLOAT`/`_UINT`/`_SINT`/`_TYPELESS`, D3D-62) are `R32G32B32A32` images
(`ResourceBinding::rgb96`), on every GPU. Most GPUs have no optimal-tiling RGB32 image (an RX 9070 XT reports
no optimal features for `R32G32B32_SFLOAT`), and one that has would not avoid the repack: D3D12 places
Expand Down
22 changes: 22 additions & 0 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,12 @@ if(BUILD_TESTING)
add_executable(vulkan_device_filter_test test/vulkan_device_filter_test.cpp)
target_include_directories(vulkan_device_filter_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
add_test(NAME vulkan_device_filter COMMAND vulkan_device_filter_test)
# LEONIDA_HOST_IMAGE_COPY's choice (runtime/src/host_image_copy_policy.h): pure stdlib, no Vulkan instance.
add_executable(host_image_copy_policy_test test/host_image_copy_policy_test.cpp)
target_include_directories(host_image_copy_policy_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
add_test(NAME host_image_copy_policy COMMAND host_image_copy_policy_test)
add_executable(title_texture_refresh_test test/title_texture_refresh_test.cpp)
add_test(NAME title_texture_refresh COMMAND title_texture_refresh_test)
add_executable(vk_presenter_capture_colour_test test/vk_presenter_capture_colour_test.cpp)
add_test(NAME vk_presenter_capture_colour COMMAND vk_presenter_capture_colour_test)
if(TARGET gta6rt)
Expand Down Expand Up @@ -2985,6 +2991,13 @@ if(TARGET Vulkan::Headers)
target_compile_options(d3d12_fence_timing_test PRIVATE /W4 /permissive- /utf-8)
add_test(NAME d3d12_fence_timing COMMAND d3d12_fence_timing_test)
set_tests_properties(d3d12_fence_timing PROPERTIES SKIP_RETURN_CODE 77)
# CPU subresource copies through the staging queue wait for their own submission, not the direct queue (D9).
add_executable(d3d12_staged_copy_wait_test test/d3d12_staged_copy_wait_test.cpp)
target_link_libraries(d3d12_staged_copy_wait_test PRIVATE gta6rt_d3d12_com)
target_compile_definitions(d3d12_staged_copy_wait_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX)
target_compile_options(d3d12_staged_copy_wait_test PRIVATE /W4 /permissive- /utf-8)
add_test(NAME d3d12_staged_copy_wait COMMAND d3d12_staged_copy_wait_test)
set_tests_properties(d3d12_staged_copy_wait PROPERTIES SKIP_RETURN_CODE 77)
# Fence events the host runtime sets or refuses (released fences, no fences), compared with the host devices.
add_executable(d3d12_fence_events_test test/d3d12_fence_events_test.cpp)
target_link_libraries(d3d12_fence_events_test PRIVATE gta6rt_d3d12_com d3d12 dxgi)
Expand Down Expand Up @@ -3993,6 +4006,15 @@ if(TARGET Vulkan::Headers)
# the title's pages at the next refresh, and the title's own newer words still win (#1537, WRITE_INVALID).
add_test(NAME d3d12_title_window_write_back COMMAND d3d12_title_va_test --window-writeback)
set_tests_properties(d3d12_title_window_write_back PROPERTIES SKIP_RETURN_CODE 77)
# No window nothing reaches: a stream-pool request just before an extent stops where it starts, and a window a
# slot-133 buffer replaced is retired at the next submission, its bytes returned and its memory freed.
add_test(NAME d3d12_title_window_orphans COMMAND d3d12_title_va_test --window-orphans)
set_tests_properties(d3d12_title_window_orphans PROPERTIES SKIP_RETURN_CODE 77)
# The same with no per-submission copy back: a retired window's GPU writes reach the title's pages only when it
# is freed, on the bytes no live copy changed (a buffer over the same 256-byte piece wrote the others).
add_test(NAME d3d12_title_window_orphans_free COMMAND d3d12_title_va_test --window-orphans)
set_tests_properties(d3d12_title_window_orphans_free PROPERTIES SKIP_RETURN_CODE 77
ENVIRONMENT "LEONIDA_TITLE_WRITEBACK=0")
# A write-back copy that faults on a page another guard (a geometry watch cell) keeps read-only: the fault
# handler asks the tracker whose copy faulted too, which must not take its lock again on that thread (#2418).
add_test(NAME d3d12_title_window_write_back_fault COMMAND d3d12_title_va_test --window-writeback-fault)
Expand Down
3 changes: 3 additions & 0 deletions runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ ones marked *diagnostic* only add log lines or exist to compare a run with and w
| `LEONIDA_CONSOLE_FORMATS` | on | Texture descriptions the console accepts and a PC GPU may not (an R9G9B9E5 render target, an sRGB RGBA8 or BGRA8 texture with unordered access) get a host format that can do the job. `0` refuses them, as a PC D3D12 runtime does. |
| `LEONIDA_CONSOLE_HEAP_SHADOW` | on | A console descriptor heap has a copy in the descriptor arena that the shaders read. `0` keeps its bytes in the title's memory only (the comparison for a run that misbehaves with the copy). |
| `LEONIDA_IMPORT_BELOW_ARENA` | unset | `1` keeps a host-memory import that the driver put below the GPU address arena. By default such an import is not used and the shadow buffer in the arena answers, because a V# cannot name an address below the arena. |
| `LEONIDA_HOST_IMAGE_COPY` | `auto` | Whether `WriteToSubresource`/`ReadFromSubresource` copy on the CPU with `VK_EXT_host_image_copy`. `auto` (unset, or any text other than `0` and `1`) uses it where the device has it, except on NVIDIA (vendor `0x10DE`), where a real boot lost the device; `1` uses it wherever the device has it; `0` never enables the extension, so every CPU texture copy takes the staging submit. Device creation logs one `[rt] d3d12: host image copy:` line with the choice and why (`docs/d3d12_vulkan.md`). |
| `LEONIDA_ORDER_TEXTURE_UPLOADS` | on | A title texture in a host-transfer image is filled through the ordered host copy (`write_host_texture`). `0` fills it with `WriteToSubresource`. |
| `LEONIDA_PLACED_IMAGE_KEYS` | on | A texture the title placed at its own address (device slot 133) and that the GPU writes keeps its own image address as its T# key. `0` re-keys it to the title address, like a texture the GPU does not write. |
| `LEONIDA_PLACED_TEXTURE_UAV` | on | Device slot 71 writes an unordered-access view of a texture in the title's placed memory. `0` writes a null descriptor. |
Expand Down Expand Up @@ -397,6 +398,8 @@ ones marked *diagnostic* only add log lines or exist to compare a run with and w
| `LEONIDA_TITLE_VIEW_REFRESH_MS` | `0` | The shortest time, in milliseconds, between two checks of a title texture's bytes when a device slot 70 view of it is written. `0` checks at every view. The periodic pass still checks the texture on its own period, and a texture known stale is checked at once. Has no effect with `LEONIDA_TITLE_FILL_ASYNC=1`. |
| `LEONIDA_TITLE_EVERY_BUDGET_US` | `0` | Microseconds one pass over the textures filled from the title's memory may spend on the textures it visits every pass (mapped by the title, or known stale), resuming where the last pass stopped; the texture that crosses the limit is finished. A mapped texture never filled yet is visited first whatever the limit. `0` visits all of them every pass. It limits the synchronous pass only: with `LEONIDA_TEXTURE_REFRESH_ASYNC=1` the pass runs on the refresh worker, and the limit does not apply. |
| `LEONIDA_TITLE_TEXTURE_FILL_MS` | `8` | Milliseconds one pass over the textures filled from the title's memory may spend filling; a texture already started is finished. `0` removes the time limit and leaves `LEONIDA_TITLE_TEXTURE_FILL_MB` to bound the pass. |
| `LEONIDA_TITLE_PARTIAL_MIPS` | unset | `1`: a 2D texture of one slice the title keeps in its own memory, whose larger mips are not readable, is filled from the first mip that is when its last slot-70 view starts there or later. Views that start above keep the fallback until a later fill has their mips. Unset, a texture waits for all its mips. |
| `LEONIDA_TITLE_PARTIAL_MIPS_MB` | `2048` | With `LEONIDA_TITLE_PARTIAL_MIPS=1`, the image memory the textures filled in part may hold, in MiB: each has memory for all its mips. A texture past it keeps the fallback. |
| `LEONIDA_MAP_READBACK` | unset | `1` writes the GPU's texels of a small render or unordered-access target the title placed into the title's pages when the title maps it, so a CPU read of the target sees what the GPU rendered (the title reads its exposure statistics that way). Only a single-row, single-mip, single-layer, single-sample 2D target of at most 4 KiB a row; the copy waits for the GPU's work already submitted, and a page that is not writable is left as it is. Unset, the title reads its own pages, which the GPU never writes. |
| `LEONIDA_SLOT133_IMPORT` | on | *Diagnostic.* `0` imports no title-placed buffer (device slot 133) as host memory: each takes the shadow-buffer fallback, so no GPU store can reach the title's memory through an import. |
| `LEONIDA_ARENA_NULL_MB` | `0` | `n` (MiB) keeps the first `n` MiB of the descriptor arena, at `heap_base + 0`, zeroed and never allocated, and moves the zero page and the quad indices above it. A translated shader whose address arithmetic starts from a null base then reads or writes there instead of in a title buffer or the shared zero page. Ignored when it would take half of the arena or more; the device logs the region it made. |
Expand Down
Loading
Loading