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
24 changes: 21 additions & 3 deletions docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -1908,9 +1908,27 @@ The runtime allocates image keys from `0x100000000` (4 GiB) in 256-byte steps, a
`GPU address arena: 4080 MiB of the 4095 MiB asked for, capped by the device's Resizable BAR memory types`.
Without Resizable BAR nothing changes.
- M4+: allocate the arena `DEVICE_LOCAL` and stage CPU writes (descriptor heaps, shader blobs, buffer uploads)
through a host-visible staging buffer, copied before the commands that use them. The hash table is not in the
arena either: it is a normal storage buffer in `DEVICE_LOCAL` memory, uploaded from a mapped staging copy before
the commands that read it (D3D-76).
through a host-visible staging buffer, copied before the commands that use them (`runtime/src/arena_staging.h`,
`LEONIDA_DEVICE_LOCAL_ARENA=auto|1|0`).
- In `auto` mode (the default), when the arena does not fit in `DEVICE_LOCAL | HOST_VISIBLE` memory (e.g. discrete
GPUs without Resizable BAR where BAR1 is 256 MiB or less) and both a pure `DEVICE_LOCAL` VRAM type and a
`HOST_VISIBLE | HOST_COHERENT` system-RAM staging type fit, `arena.buffer` is allocated in pure `DEVICE_LOCAL`
VRAM and `arena.mapped` points at the `HOST_VISIBLE | HOST_COHERENT` staging mirror (`arena.staging_buffer`). On
GPUs with Resizable BAR or unified memory, `auto` keeps the zero-copy single buffer; `LEONIDA_DEVICE_LOCAL_ARENA=1`
forces the staged path for testing, and `LEONIDA_DEVICE_LOCAL_ARENA=0` keeps the single host-visible arena.
- Overflow `TitleBufferWindows` slabs outside the main arena are budgeted by `LEONIDA_EXTERNAL_WINDOWS_MB` (default
4096 MiB total when staged — counting both VRAM and host staging mirror — or 2048 MiB when unstaged). Empty slabs
beyond one spare are reclaimed.
- CPU writes into `arena.mapped` (`ShadowPages`, console and standard shader-visible descriptor heaps, shader blobs,
`write_arena_value`, geometry leases, placed/committed buffer init and `Map`/`Unmap`) are tracked at exact byte
granularity (never rounded up to 4 KiB pages, so flushing a 256-byte shadow piece or 32-byte descriptor never
overwrites neighboring GPU writes on the same page), coalesced, and uploaded with batched `vkCmdCopyBuffer` plus
cross-queue timeline synchronization before each submission. GPU-to-CPU readbacks (`write_back_titles`, retired
shadow write-back, readable placed-buffer `Map()`, `read_arena`) subtract any unflushed dirty spans before copying
back via `VulkanContext::copy_buffer_sync()`. `arena_staging_test` (CPU) covers the policy and dirty tracker.
- The hash table is not in the
arena either: it is a normal storage buffer in `DEVICE_LOCAL` memory, uploaded from a mapped staging copy before
the commands that read it (D3D-76).
- Upload-heap buffers prefer `DEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENT` memory when the GPU has Resizable BAR
(D3D-96): the CPU writes them through the BAR and the GPU reads them from VRAM. `leonida::resizable_bar`
(`runtime/src/vulkan_memory.h`) calls it Resizable BAR when such a type sits in a device-local heap larger than
Expand Down
2 changes: 2 additions & 0 deletions docs/design.md

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion make_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,10 @@ def exe_shaders(game: str, work: str, mc_signature: str, jobs: int = 1, emulate:
("--texel-offset-fallback", "texel_offset_fallback"), ("--mesh-compute", "mesh_compute"),
("--f16-interp-fallback", "f16_interp_fallback"), ("--pc-tail-ubo", "pc_tail_ubo"),
("--compact-spirv", "compact_spirv"), ("--integer-dot-fallback", "integer_dot_fallback"),
("--mesh-serial-waves", "mesh_serial_waves"), ("--explicit-lod-bias", "explicit_lod_bias"))
("--mesh-serial-waves", "mesh_serial_waves"), ("--explicit-lod-bias", "explicit_lod_bias"),
("--compute-serial-waves", "compute_serial_waves"),
("--mesh-native-wave32", "mesh_native_wave32"),
("--spirv-opt", "spirv_opt"))


def fallback_flags(a) -> tuple[str, ...]:
Expand Down Expand Up @@ -3688,6 +3691,14 @@ def main() -> int:
"Only wave64 mesh shaders of more than 64 threads, a multiple of 64, with no LDS "
"instruction, store or atomic take that form; the others, and every shader translated "
"natively or with --mesh-compute, come out as before. Off by default")
ap.add_argument("--compute-serial-waves", action="store_true",
help="with wave64 emulation, serialize multi-wave compute shaders in 64 invocations instead "
"of side-by-side wave emulation (forwards --compute-serial-waves to rdna2spirv.py). Off by default")
ap.add_argument("--mesh-native-wave32", action="store_true",
help="forward --mesh-native-wave32 to rdna2spirv.py for eligible mesh shaders. Off by default")
ap.add_argument("--spirv-opt", action="store_true",
help="forward --spirv-opt to rdna2spirv.py (runs spirv-opt -O below 512 KiB and safe SSA passes "
"at >= 512 KiB with automatic fallback on validation failure). Off by default")
ap.add_argument("--native-mesh", action="store_true",
help="keep native mesh shaders on Intel's Windows Vulkan driver instead of turning on "
"--mesh-compute (for a driver that fixes BUILD-2202's crash)")
Expand Down
7 changes: 7 additions & 0 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5362,6 +5362,13 @@ if(TARGET Vulkan::Headers)
add_executable(arena_size_test test/arena_size_test.cpp)
target_link_libraries(arena_size_test PRIVATE Vulkan::Headers)
add_test(NAME arena_size COMMAND arena_size_test)
# Staged DEVICE_LOCAL GPU address arena policy and exact byte-range dirty tracker (src/arena_staging.h).
add_executable(arena_staging_test test/arena_staging_test.cpp)
target_link_libraries(arena_staging_test PRIVATE Vulkan::Headers)
if(WIN32 AND MSVC)
target_compile_options(arena_staging_test PRIVATE /W4 /permissive- /utf-8)
endif()
add_test(NAME arena_staging COMMAND arena_staging_test)
# The GPU address arena's free-block map: first fit, coalescing, and a walk a nested call re-cuts on the same
# thread (src/arena_blocks.h).
add_executable(arena_blocks_test test/arena_blocks_test.cpp)
Expand Down
Loading
Loading