Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 6 additions & 20 deletions docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -1737,24 +1737,14 @@ The copies:
as VIctory keeps its copies of title memory (approach only). In a world run on the RX 7900 XTX the copies held
4.4-6 GB of VRAM. The cost moves to the bus: the GPU reads every vertex and index of a copy from system memory,
so a geometry-heavy pass can take longer; measure frame time with and without it before making it a default.
- **When a copy goes**: a view is retired when its title range is freed, decommitted or unmapped. With
`LEONIDA_GEOMETRY_REMAP_RELEASE=1` (off by default) also when a remap gives one of its pages another frame or
none (`XMemMapPhysicalPages` with pages, the scatter call, `CopyPageMappingsBatchX`; xmem's `RemapReleases`):
the title streams by remapping its pools' frames, and otherwise the copies of what those pages held stay for the
device's life (`evicted 0` in every world run). It is off because a remap leaves the address valid on the
console, and not everything that names a copy's address is rewritten when the copy goes: a root view is
resolved while its list is recorded (`d3d12_com.cpp`, `GraphicsCommandList::address`), so a list recorded before the
retirement and executed after it reads the freed copy, and so does a placed buffer view written outside a
console heap. On by default, it retired 15 010 copies in 40 s of a world run on the
RX 7900 XTX (RADV) and ended it in a GPUVM page fault and a lost device; the same run without it went eight
minutes with no fault. Making it safe needs a copy kept until nothing recorded or written can still name it.
A page mapped again to the frame it had is no change. A retired
- **When a copy goes**: a view is retired when its title range is freed, decommitted or unmapped. A remap of
physical pages retires nothing: the copies follow the new pages through the refresh. A retired
view leaves the lookups at once, its alias ranges and translated heap slots are invalidated, its stream-pool
extent is forgotten, and its memory is freed only after every ExecuteCommandLists replay in progress at the
retirement has recorded its submissions and those have completed (`kAfterExecutes`). Before it leaves the
refresh it is copied once more from its pages if they are readable: a list recorded before a remap that took the
view's address (a root view) reads the new bytes, as on the console. The next view of the range makes a new copy.
`geometry_views_test` cases 14-16 and `xmem_test` (`test_remap_releases`) cover this without a GPU.
refresh it is copied once more from its pages if they are still readable (a heap block freed in memory that
stays committed). The next view of the range makes a new copy.
`geometry_views_test` cases 14-16 cover this without a GPU.
- **Which pages changed** since the last refresh: where xmem reserved the title's memory with `MEM_WRITE_WATCH`
(`XMemVirtualAlloc`'s ordinary regions and the title's `VirtualAlloc` reservations, not placeholders or
physical-page windows), the kernel says (`GetWriteWatch` with reset, its answers kept for every copy over the page:
Expand Down Expand Up @@ -2062,11 +2052,7 @@ The game can use D3D12 descriptors in three ways, and the layer must handle all
arguments for direct and indirect compute dispatches with an inline signature. Bound console descriptor heap
base addresses are remapped through `console_descriptor_table_va` so that user SGPRs receive the arena copy's
shader virtual address (where GPU descriptor reads land, preventing `READ_INVALID` device loss during world
load), while unshadowed host heaps remain unchanged. The CPU reads that copy too (the release sweep of
`LEONIDA_CONSOLE_RELEASE_FILTER=1`), uncached across PCIe when it is in ReBAR memory. `LEONIDA_HEAP_MIRROR=1`
gives those reads a host-RAM mirror of the copy (`src/console_heap_copy.h`). It is off by default: with it, a
world run on the RX 7900 XTX (RADV) hung in a library compute program about a minute in and lost the device,
and without it the same run went on for more than five minutes. Why is not known yet. An unbound heap contributes
load), while unshadowed host heaps remain unchanged. An unbound heap contributes
zero, and rebinding affects later commands. A heap that cannot fit in the inline user data is reported once,
and a signature whose compute arguments spill gets nothing written (logged once). Set
`LEONIDA_COMPUTE_DIRECT_HEAPS=0` to restore the previous compute arguments.
Expand Down
22 changes: 0 additions & 22 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3732,22 +3732,6 @@ if(TARGET Vulkan::Headers)
target_compile_options(d3d12_unmapped_vsharp_test PRIVATE /W4 /permissive- /utf-8)
add_test(NAME d3d12_unmapped_vsharp COMMAND d3d12_unmapped_vsharp_test)
set_tests_properties(d3d12_unmapped_vsharp PROPERTIES SKIP_RETURN_CODE 77 ENVIRONMENT "LEONIDA_CONSOLE_FIX_US=0")
# The host-RAM mirror of a console heap's GPU copy (src/console_heap_copy.h) agrees with the copy through the first
# refresh, title writes and a filtered release sweep; run again without the mirror, where the copy must not change.
add_executable(d3d12_console_heap_mirror_test test/d3d12_console_heap_mirror_test.cpp shims/d3d12_xs_device.cpp)
target_link_libraries(d3d12_console_heap_mirror_test PRIVATE gta6rt_d3d12_com d3d12 dxgi)
target_compile_definitions(d3d12_console_heap_mirror_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX LEONIDA_VULKAN_DEVICE)
target_compile_options(d3d12_console_heap_mirror_test PRIVATE /W4 /permissive- /utf-8)
add_test(NAME d3d12_console_heap_mirror COMMAND d3d12_console_heap_mirror_test)
set_tests_properties(d3d12_console_heap_mirror PROPERTIES SKIP_RETURN_CODE 77 ENVIRONMENT
"LEONIDA_CONSOLE_FIX_US=0;LEONIDA_CONSOLE_RELEASE_FILTER=1;LEONIDA_HEAP_MIRROR=1;LEONIDA_HEAP_MIRROR_CHECK=1")
add_test(NAME d3d12_console_heap_mirror_off COMMAND d3d12_console_heap_mirror_test)
set_tests_properties(d3d12_console_heap_mirror_off PROPERTIES SKIP_RETURN_CODE 77 ENVIRONMENT
"LEONIDA_CONSOLE_FIX_US=0;LEONIDA_CONSOLE_RELEASE_FILTER=1;LEONIDA_HEAP_MIRROR=0")
# The default: no mirror unless LEONIDA_HEAP_MIRROR=1.
add_test(NAME d3d12_console_heap_mirror_default COMMAND d3d12_console_heap_mirror_test)
set_tests_properties(d3d12_console_heap_mirror_default PROPERTIES SKIP_RETURN_CODE 77 ENVIRONMENT
"LEONIDA_CONSOLE_FIX_US=0;LEONIDA_CONSOLE_RELEASE_FILTER=1")
add_executable(d3d12_indirect_zero_test test/d3d12_indirect_zero_test.cpp)
target_link_libraries(d3d12_indirect_zero_test PRIVATE gta6rt_d3d12_com d3d12 dxgi)
target_compile_definitions(d3d12_indirect_zero_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX)
Expand Down Expand Up @@ -4700,12 +4684,6 @@ if(TARGET Vulkan::Headers)
target_compile_options(console_heap_vsharp_slots_test PRIVATE /W4 /permissive- /utf-8)
endif()
add_test(NAME console_heap_vsharp_slots COMMAND console_heap_vsharp_slots_test)
# Host-RAM mirror of a console resource heap's GPU copy (src/console_heap_copy.h).
add_executable(console_heap_copy_test test/console_heap_copy_test.cpp)
if(WIN32 AND MSVC)
target_compile_options(console_heap_copy_test PRIVATE /W4 /permissive- /utf-8)
endif()
add_test(NAME console_heap_copy COMMAND console_heap_copy_test)
# Queue construction cleans its Vulkan handles if holder registration runs out of host memory.
add_executable(vk_host_texture_order_test test/vk_host_texture_order_test.cpp)
target_link_libraries(vk_host_texture_order_test PRIVATE Vulkan::Headers ${CMAKE_DL_LIBS})
Expand Down
3 changes: 0 additions & 3 deletions runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ ones marked *diagnostic* only add log lines or exist to compare a run with and w
| `LEONIDA_GEOMETRY_ASYNC` | unset | Trades correctness for speed. `1` refreshes the geometry copies (`shims/d3d12_geometry_views.h`) on a worker thread of the layer, started at submission and not waited for, instead of on the title's submitting thread. A draw may read a copy the worker is still writing: wrong vertices for a frame. |
| `LEONIDA_GEOMETRY_WHOLE_VIEWS` | unset | A geometry copy that is already filled copies only the 64 KiB tiles of title memory written since the last refresh (`shims/d3d12_geometry_views.h`). Any value other than `0` copies every view over a written tile whole, as before. |
| `LEONIDA_GEOMETRY_HOST` | unset | Where the geometry copies (`shims/d3d12_geometry_views.h`, under `LEONIDA_GEOMETRY_MB`) live. Unset or `0`: device-local memory through the BAR while the driver gives it (several GB of VRAM in a world run). `1`: system memory outside VRAM, write-back where the device offers a cached host type; `2`: system memory, write-combined. The GPU then reads every vertex and index of a copy over the bus, which can cost frame time in geometry-heavy passes. A device whose host-visible memory is all device-local (an integrated GPU) keeps its types. The choice is logged once and in the `geometry buffers` line. |
| `LEONIDA_GEOMETRY_REMAP_RELEASE` | unset | Experimental, unsafe in world runs. `1`: a remap of physical pages (`XMemMapPhysicalPages`, the scatter call, `CopyPageMappingsBatchX`) that gives a page another frame, or none, retires the geometry copies over it, as freeing or unmapping it does, so the copies of what the title's stream pools held do not stay for the device's life. A retired copy is copied once more from the new pages if they are readable, then freed once the submissions in progress at the retirement have finished. A remap leaves the address valid, though, and a root view resolved while a list was recorded (executed after the retirement) or a placed buffer view written outside a console heap still names the freed copy: on by default it ended a world run on an RX 7900 XTX in a GPUVM page fault and a lost device. Unset or any other value: a remap retires nothing, and the copies follow the new pages through the refresh. |
| `LEONIDA_TITLE_FILL_ASYNC` | unset | Trades correctness for speed. `1` stops device slot 70 views from hashing and filling the texture they name on the title's thread: a texture never filled or known stale is queued for a worker thread that fills one texture at a time. Until then a shader samples the image as it is, empty or a frame behind. |
| `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. |
Expand Down Expand Up @@ -425,8 +424,6 @@ ones marked *diagnostic* only add log lines or exist to compare a run with and w
| `LEONIDA_CONSOLE_GPU_TSHARPS` | on | With `LEONIDA_CONSOLE_HEAP_GPU=1`, the T#s of changed slots are registered by the resolver thread and the refresh only decodes them. `0` registers them on the submitting thread, under the fix budget. |
| `LEONIDA_CONSOLE_GPU_RETRY_MS` | `2000` | With `LEONIDA_CONSOLE_HEAP_GPU=1`, how often V# words that got no backing are asked for again, on a timer that bounds the cost per submission. |
| `LEONIDA_CONSOLE_GPU_FILTER` | `LEONIDA_CONSOLE_RELEASE_FILTER`'s value | With `LEONIDA_CONSOLE_HEAP_GPU=1`, `1`: a released backing, an alias range that went or a word answered since asks for a rescan of only the slots it touches, not of every V# slot. Overflows and key resets still rescan everything. |
| `LEONIDA_HEAP_MIRROR` | unset | Experimental. `1`: a host-RAM mirror of a console resource heap's copy in the arena (`src/console_heap_copy.h`), so the CPU reads of the copy (the `LEONIDA_CONSOLE_RELEASE_FILTER` sweep) come from host RAM, not uncached device memory across PCIe. Off by default: with it, a world run on an RX 7900 XTX hung in a compute program about a minute in and lost the device; without it the same run went on for more than five minutes. Unset or any other value: no mirror, and the sweep reads the copy. A copy in an import of host memory, and one the `LEONIDA_CONSOLE_HEAP_GPU` pass writes, never has one. |
| `LEONIDA_HEAP_MIRROR_CHECK` | unset | `1`: at every release sweep the mirror is compared with the copy (a read of the whole copy); the first differing slots are logged, and the heap log line counts the checks and differing slots. |
| `LEONIDA_CONSOLE_RELEASE_FILTER` | unset | `1`: when a backing is released, only the console-heap slots whose V#s point into it are fixed again (by actual Vulkan address), instead of every V# slot of the heap. The heap log line counts the sweeps, live slots, fixes and full fallbacks. |
| `LEONIDA_SHADOW_GPU` | unset | `1`: aliased pages of the slot-133 shadows are copied on the GPU at the start of a submission, from an import of the mapped title section (`VK_EXT_external_memory_host`, per 2 MiB window, kept while xmem's map journal shows no change over it). Destinations outside the arena and pages that do not import are copied by the CPU as before. |
| `LEONIDA_SHADOW_GPU_MB` | `1024` | With `LEONIDA_SHADOW_GPU=1`, the MiB of title memory imported for those copies at most. |
Expand Down
4 changes: 0 additions & 4 deletions runtime/shims/d3d12_com.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,6 @@ std::uint64_t device_arena_size(ID3D12Device* device);
// Copies `bytes` of the device's GPU address arena at console VA `va` (what shaders read there: a heap's GPU copy,
// the null slots after it) into `out`. False without an arena or when the range is not inside it. For tests.
bool read_arena(ID3D12Device* device, std::uint64_t va, void* out, std::size_t bytes);
// The slots whose host-RAM mirror differs from the GPU copy of the console descriptor heap at `console_va`
// (src/console_heap_copy.h), compared now: 0 when they agree, -1 when there is no such heap or it has no mirror.
// For tests.
long long console_heap_mirror_mismatches(ID3D12Device* device, std::uint64_t console_va);

// The blocks of device memory that textures share (src/image_memory.h): how many, their bytes, and the textures in
// them. For tests.
Expand Down
6 changes: 3 additions & 3 deletions runtime/shims/d3d12_compute_input_probe.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ bool gpu_words_now(State& state, std::uint64_t at, std::array<std::uint32_t, 8>&
for (const auto& heap : state.console_heaps) {
const auto delta = at - heap->shader_va;
if (heap->copy && delta <= heap->bytes && sizeof(out) <= heap->bytes - delta) {
std::memcpy(out.data(), heap->copy.gpu() + delta, sizeof(out));
std::memcpy(out.data(), heap->copy + delta, sizeof(out));
return true;
}
}
Expand Down Expand Up @@ -249,7 +249,7 @@ void recheck(State& state) {
if (!lock.owns_lock()) std::fputs("[rt] compute-input: after loss, console heaps locked\n", stderr);
else
for (const auto& heap : state.console_heaps)
if (heap->copy) scan("console", heap->shader_va, heap->copy.gpu(), heap->bytes);
if (heap->copy) scan("console", heap->shader_va, heap->copy, heap->bytes);
}
{
std::unique_lock lock(state.visible_heap_mutex, std::try_to_lock);
Expand Down Expand Up @@ -294,7 +294,7 @@ Backing descriptor(State& state, std::uint64_t seq, std::size_t list, std::size_
for (const auto& heap : state.console_heaps) {
const auto delta = at - heap->shader_va;
if (heap->copy && delta <= heap->bytes && sizeof(gpu) <= heap->bytes - delta) {
std::memcpy(gpu.data(), heap->copy.view() + delta, sizeof(gpu));
std::memcpy(gpu.data(), heap->copy + delta, sizeof(gpu));
have_gpu = true;
break;
}
Expand Down
8 changes: 4 additions & 4 deletions runtime/shims/d3d12_geometry_views.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,10 @@ class GeometryViews {
// deferring its backing storage reclamation until GPU submissions through `retire_ticket` have completed
// (kAfterExecutes: through the submissions of every replay in progress now, see execute_end).
// With `final_copy` (a refresh's copy), a ready view whose title range is readable now is copied from it once more
// before it leaves the refresh: a range the title remapped holds new bytes, and a list recorded before the remap
// that took the view's address (a root view) and runs in a submission the view waits for reads those, as it would
// have read them in the console's memory, and as the refresh this retirement replaces would have copied them.
// Freed or unmapped memory is not readable, so such a view keeps what it held.
// before it leaves the refresh: a released range that is still readable (a heap block freed in memory that stays
// committed) may hold new bytes, and a list recorded before the release that runs in a submission the view waits
// for reads those, as it would have read them in the console's memory. Decommitted or unmapped memory is not
// readable, so such a view keeps what it held.
template<class OnRetire = NoopRetire, class Copy = NoCopy>
std::size_t retire_range(Address begin, Address end, std::uint64_t retire_ticket = 0,
OnRetire&& on_retire = {}, Copy&& final_copy = {}) {
Expand Down
Loading
Loading