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
27 changes: 24 additions & 3 deletions docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -2439,16 +2439,37 @@ Pipeline creation:
is when each is compiled alone, so a PSO released meanwhile waits for the submission. The workers have ended before
the session cache is read at device teardown. `LEONIDA_PIPELINE_THREADS=<n>` sets the workers: unset, half the
logical processors and at most 8; `0` compiles each pipeline on the submitting thread where `prepare()` meets it.
Graphics pipelines of 1 MiB of SPIR-V or more, and compute pipelines over 128 KiB (`LEONIDA_SERIAL_BIG_COMPILES`),
are compiled one after another beside the smaller ones, because a compile takes the driver some hundred bytes of
memory for each byte of SPIR-V ([pipeline_check.md](pipeline_check.md)); so are the variants of one PSO.
Large pipelines (below) are compiled within a memory budget, and the variants of one PSO one after another.
`LEONIDA_ASYNC_PIPELINES=1` is not changed: its builds stay on the compile worker. Measured with synthetic programs
never compiled before and the warm-up off (RTX 3080, NVIDIA 621.24, Windows 11, 16 logical processors, 8 workers,
three runs each): the first submission of 192 graphics pipelines takes 126 to 143 ms instead of 861 to 882, of 192
variants 124 to 130 instead of 856 to 863, of 96 compute pipelines 74 to 81 instead of 486 to 519, and the process
holds about 50 MiB more (the driver keeps memory for each thread that compiles). One `VkPipelineCache` is enough: one
cache per thread, merged, was about as fast. Tested by `pipeline_workers`, `replay_pipeline_compiles` and
`d3d12_pipeline_workers`.
- Large pipelines: a compile takes the driver some hundred bytes of memory for each byte of SPIR-V
([pipeline_check.md](pipeline_check.md), "Limiting concurrent compilation of large modules"), so compute modules over
128 KiB and graphics pipelines of 1 MiB or more compile side by side only while their estimates (512 bytes for each
byte of SPIR-V) fit a budget: three quarters of the smaller of the free RAM and the room under the commit limit, read
again whenever a place at the gate (`runtime/src/large_module_gate.h`, one for the process) is given or returned. One
always gets in when none is, so a pipeline larger than the budget compiles alone. An estimate counts in full until
the compile ends, although the driver has taken part of it by then. They get in in the order they came; while the
first in line does not fit, the next behind it that does may pass, as long as all that have passed it would fit the
budget together with it, so that a stream of small ones does not keep it out. The ones a submission waits for (and
those of `LEONIDA_ASYNC_PIPELINES`) go before the warm-up's, which take a quarter of the budget at most and none while
a submission that has large ones is compiling on its workers. A thread that waits for its place holds no PSO's lock,
and one that has a place waits for none. `PipelineCompiles::build` gives a submission
as many jobs for large ones as its smallest could be in at once, largest first; where the next one does not fit, the
job compiles small ones in the meantime. `LEONIDA_SERIAL_BIG_COMPILES=1` compiles them one after another instead, as
before there was a budget, `=0` has no limit, `LEONIDA_BIG_COMPILE_BUDGET_MB` fixes the budget. Measured with
synthetic integer modules never compiled before and the warm-up off (RTX 3080, NVIDIA 621.24, Ryzen 7 5800X3D, 8
workers and the submitting thread, three alternating runs each): the first submission of 16 modules of 256 KiB takes
0.8 s instead of 4.0 to 4.8 s, 16 of 512 KiB 2.0 to 2.2 s instead of 10.2 to 11.4, 15 of 1 MiB 5.8 to 6.1 s instead
of 29.2 to 31.2, 12 of 0.5 to 2 MiB 8.0 to 10.5 s instead of 38.9 to 39.9. While the 15 of 1 MiB compile, private
memory peaks 656 to 676 MiB over what it was, instead of 140 to 147 (one compile takes 85 to 131 bytes for each byte
of SPIR-V here, and the driver keeps memory for each thread that compiles). With a budget of 1536 MiB, two at once,
they take 18.5 s and peak 202 MiB over. Not measured: other drivers, and the title. Tested by `big_compile_gate`,
`replay_pipeline_compiles` and `d3d12_big_compute`.

**Open:** whether the game uses `D3D12_PIPELINE_STATE_STREAM_DESC` for mesh/RT and which subobject types appear.
The trace will enumerate them.
Expand Down
2 changes: 1 addition & 1 deletion docs/pipeline_check.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ acceptance only.

A SPIR-V module larger than 4 MiB is "large". [#884](https://github.com/ItsNotRexed/Leonida/issues/884)
showed why that matters: several compiles that each needed gigabytes of host RAM ran at the same time. Large
modules now share a memory budget (`runtime/test/large_module_gate.h`): each one reserves 512 bytes of RAM per
modules now share a memory budget (`runtime/src/large_module_gate.h`): each one reserves 512 bytes of RAM per
SPIR-V byte, and they enter the driver while their reservations fit three quarters of the memory available when
the run starts, up to `--jobs` of them. One large module always gets in when none is compiling, so a module
bigger than the whole budget still compiles, alone among the large ones. Small modules are never held back. On
Expand Down
38 changes: 37 additions & 1 deletion runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,12 @@ if(BUILD_TESTING)
add_executable(xdxr_build_output_test test/xdxr_build_output_test.cpp)
add_test(NAME xdxr_build_output COMMAND xdxr_build_output_test)

# The gate of large_module_gate.h as the runtime uses it for large pipelines (LEONIDA_BIG_COMPILE_BUDGET_MB): pure
# stdlib.
add_executable(big_compile_gate_test test/big_compile_gate_test.cpp)
target_link_libraries(big_compile_gate_test PRIVATE Threads::Threads)
add_test(NAME big_compile_gate COMMAND big_compile_gate_test)
set_tests_properties(big_compile_gate PROPERTIES TIMEOUT 120)
# vk_pipeline_check's memory budget for large modules: pure stdlib, no Vulkan device.
add_executable(large_module_gate_test test/large_module_gate_test.cpp)
find_package(Threads REQUIRED)
Expand Down Expand Up @@ -2387,8 +2393,38 @@ if(TARGET Vulkan::Headers)
add_test(NAME d3d12_pipeline_workers_eager COMMAND d3d12_pipeline_workers_test)
set_tests_properties(d3d12_pipeline_workers d3d12_pipeline_workers_eager PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 180
FAIL_REGULAR_EXPRESSION "Validation Error;VUID-")
# One large pipeline after another: the jobs of the pool are then known (d3d12_big_compute has the budget).
set_tests_properties(d3d12_pipeline_workers PROPERTIES ENVIRONMENT "LEONIDA_SERIAL_BIG_COMPILES=1")
set_tests_properties(d3d12_pipeline_workers_eager PROPERTIES
ENVIRONMENT "LEONIDA_LAZY_PIPELINES=0;LEONIDA_LAZY_COMPUTE=0")
ENVIRONMENT "LEONIDA_LAZY_PIPELINES=0;LEONIDA_LAZY_COMPUTE=0;LEONIDA_SERIAL_BIG_COMPILES=1")
# Large pipelines compiled within a memory budget, with real large compute modules: the same values for each setting
# (read once for each process). 260 MiB holds three of the modules, 1 MiB none. The modules' compile runs on the test's
# threads, so they get the loader's stack (docs/pipeline_check.md, "Stack reserve").
add_executable(d3d12_big_compute_test test/d3d12_big_compute_test.cpp)
target_link_libraries(d3d12_big_compute_test PRIVATE gta6rt_d3d12_com)
target_compile_definitions(d3d12_big_compute_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX)
target_compile_options(d3d12_big_compute_test PRIVATE /W4 /permissive- /utf-8)
target_link_options(d3d12_big_compute_test PRIVATE /STACK:${GTA6RT_STACK})
add_test(NAME d3d12_big_compute COMMAND d3d12_big_compute_test)
add_test(NAME d3d12_big_compute_budget COMMAND d3d12_big_compute_test)
add_test(NAME d3d12_big_compute_tight COMMAND d3d12_big_compute_test)
add_test(NAME d3d12_big_compute_serial COMMAND d3d12_big_compute_test)
add_test(NAME d3d12_big_compute_unlimited COMMAND d3d12_big_compute_test)
add_test(NAME d3d12_big_compute_warmup COMMAND d3d12_big_compute_test warmup)
add_test(NAME d3d12_big_compute_eager COMMAND d3d12_big_compute_test eager)
set_tests_properties(d3d12_big_compute d3d12_big_compute_budget d3d12_big_compute_tight d3d12_big_compute_serial
d3d12_big_compute_unlimited d3d12_big_compute_warmup d3d12_big_compute_eager
PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 600
FAIL_REGULAR_EXPRESSION "Validation Error;VUID-")
set_tests_properties(d3d12_big_compute_budget PROPERTIES ENVIRONMENT "LEONIDA_BIG_COMPILE_BUDGET_MB=260")
set_tests_properties(d3d12_big_compute_tight d3d12_big_compute_warmup PROPERTIES
ENVIRONMENT "LEONIDA_BIG_COMPILE_BUDGET_MB=1")
set_tests_properties(d3d12_big_compute_eager PROPERTIES
ENVIRONMENT "LEONIDA_BIG_COMPILE_BUDGET_MB=1;LEONIDA_LAZY_COMPUTE=0")
set_tests_properties(d3d12_big_compute_serial PROPERTIES # neither of these two has a budget
ENVIRONMENT "LEONIDA_SERIAL_BIG_COMPILES=1;LEONIDA_BIG_COMPILE_BUDGET_MB=4096")
set_tests_properties(d3d12_big_compute_unlimited PROPERTIES
ENVIRONMENT "LEONIDA_SERIAL_BIG_COMPILES=0;LEONIDA_BIG_COMPILE_BUDGET_MB=1")
# ExecuteCommandLists refuses a list whose type isn't the queue's (debug-layer message 836).
add_executable(d3d12_queue_list_type_test test/d3d12_queue_list_type_test.cpp)
target_link_libraries(d3d12_queue_list_type_test PRIVATE gta6rt_d3d12_com)
Expand Down
3 changes: 2 additions & 1 deletion runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ ones marked *diagnostic* only add log lines or exist to compare a run with and w
| `LEONIDA_LAZY_PIPELINES` | on | Graphics pipelines are built at their first draw. `0` builds each at `CreatePipelineState`, as before; the title creates far more pipelines at startup than it draws with. |
| `LEONIDA_LAZY_COMPUTE` | on | Compute pipelines are built at the first dispatch that names them, or earlier by the warm-up thread. `0` builds each at `CreateComputePipelineState`. |
| `LEONIDA_COMPUTE_WARMUP_MAX_BYTES` | `1048576` | The largest SPIR-V module, in bytes, the background warm-up thread (`LEONIDA_COMPUTE_WARMUP`) builds ahead of its first dispatch. Larger modules wait for that dispatch. |
| `LEONIDA_SERIAL_BIG_COMPILES` | on | Compute modules over 128 KiB of SPIR-V compile one at a time, because the driver's compiler needs hundreds of MiB for each. `0` lets them compile side by side. |
| `LEONIDA_SERIAL_BIG_COMPILES` | unset | Large pipelines (compute modules over 128 KiB of SPIR-V, graphics pipelines of 1 MiB or more) compile side by side while their estimates, 512 bytes of memory for each byte of SPIR-V, fit a budget (`LEONIDA_BIG_COMPILE_BUDGET_MB`): one always does, what a submission waits for goes before the warm-up, and the warm-up takes a quarter of the budget at most. `1` compiles the compute ones one at a time, and the graphics ones of a submission one after another, as before there was a budget. `0` lets all of them compile side by side. |
| `LEONIDA_BIG_COMPILE_BUDGET_MB` | unset | The budget, in MiB: a fixed number (`0`: one large pipeline at a time) instead of three quarters of the memory that is free at the moment, which is the smaller of the free RAM and the room under the commit limit, read again for each pipeline. Text that is not a number is ignored. |
| `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. |
Expand Down
Loading
Loading