ScarletNX / ScarletNX documentation / Regression inventory for the buffer cache rewrite · ← previous · next →
Staging and rings
S1. The rings, the descriptor pools and the dead list of a frame are not used again before its last submission
finished.
- Without the rule: an end of the frame at each submit would reset them in the middle of a draw and wait for the
GPU at every submit.
- Comment:
cmd.c, the file header.
- Check:
check_chunk_after_done and check_staging_overflow in tests/vulkan_headless.c.
S2. The rings take chunks of one size from a pool, and the pool keeps what the last frames used.
- Without the rule: a ring that doubled up to the allocation limit stayed there for 300 frames. The pool keeps as
many chunks and big buffers as the most that a frame of the last
VK_POOL_FRAMES took. A request bigger than a
chunk gets a buffer of the chunk size doubled until it fits.
- Comment:
cmd.c, above Chunk, and pool_recycle.
- Check:
check_staging_burst, check_small_uploads, check_big_uploads and check_chunks_both_slots in
tests/vulkan_headless.c.
S3. Of the pooled chunks, the ring takes first the one that the CPU wrote most.
- Without the rule: the first CPU write to each page of a chunk is a page fault. An 8192x8192 texture's upload took
43 ms in a new 32 MiB buffer, and 28 ms in a ring written before. An ASTC texture's 16 MiB copy source took 14 ms
in a chunk written 64 KiB into, where its 8 MiB level took 0.3 ms in one written whole.
- Comment:
cmd.c, above pool_before.
- Check:
check_chunk_written_first and check_big_reuse in tests/vulkan_headless.c.
S4. A ring with no pooled chunk left hands out of its smallest pooled big buffer.
- Without the rule: a frame of more small requests than the pool kept chunks for wrote new chunks, with a page
fault on each page.
- Comment:
cmd.c, above chunk_take.
- Check:
check_chunks_from_big in tests/vulkan_headless.c.
S5. Streamed uploads and buffer snapshots go to host memory, not to the mapped window of device memory.
- Without the rule: with no resizable BAR that window is a heap of its own, 246 MiB on an RTX 2080, which the whole
desktop shares. Past its room the driver moves the memory, and every CPU write to it faulted in the kernel. One
game ran at 10 frames a second for twenty seconds, its GPU thread half in the kernel.
- Comment:
cmd.c, above BAR_RING_MAX, and above vk_stage_upload.
- Check:
check_guest_staging in tests/vulkan_guest_staging.inc.
S6. The room in the window comes from the budget in the way that the driver counts it.
- Without the rule: the NVIDIA driver (615.78) counts the use of the whole system in the window. A process that
allocated nothing is told 155 of 246 MiB used and 91 budgeted. Read as the use of this process, that looked past
the budget all the time. Each frame's ring was freed and made again in the window, a 16 MiB allocation and free
every frame, about a millisecond. A menu at 760 frames a second ran at 3200 without it. A chunk goes there only
with room for it and a sixteenth of the heap to spare.
- Comment:
cmd.c, above BAR_RING_MAX (the code is bar_room).
- Check: no test covers
bar_room. The ctest vk_memory_model covers where the memory of a device is.
S7. A ring takes at most 32 MiB of the window, and the process at most a quarter of it.
- Without the rule: within the budget, the NVIDIA driver failed to map a 64 MiB ring with 86 MiB budgeted and
reported success. CPU writes to it ran at 18 MB/s against 5 GB/s. Every frame of that slot took half a second, in
two games, in most runs. No 16 or 32 MiB ring failed. With resizable BAR too, the rings grew to 256 MiB there,
and one game's draws took up to 1.5 s each to write their data.
- Comment:
cmd.c, above BAR_RING_MAX, and bar_room.
- Check: no test covers it. The staging statistics of
vk_buffer_stats give the bytes by memory kind.
S8. Guest input that a copy or a conversion reads one time stays near the GPU when the GPU owns it.
- Without the rule: CPU-only bytes that go through the device window are slow CPU writes, and GPU-owned bytes that
go through host memory cross the bus. Both rings share the fence of the frame.
- Comment:
cmd.c, above vk_stage_guest_input.
- Check:
check_guest_staging in tests/vulkan_guest_staging.inc.
S9. The storage results of a frame are copied on the GPU into host-cached memory before the CPU reads them.
- Without the rule: the staging ring can be device memory behind the BAR, where every CPU read crosses PCIe
uncached. The compare of a frame's results there cost one game most of its GPU thread. For logged results the
reads of the logged runs there were 19% of a Switch game's GPU thread, with 728 results a frame of 3.8 KB on
average. Consecutive results share one copy command.
- Comment:
cmd.c, above vk_stage_back, and buffer.c, vk_buf_host_barrier.
- Check: no test holds the memory kind.
check_storage_logged covers the bytes.
S10. What the GPU makes for itself to read goes in the device ring of the frame.
- Without the rule: in host memory each byte crossed PCIe two times or more. Composed storage ranges were about
45 MB a frame in one game, most of its traffic from the GPU to the host.
- Comment:
cmd.c, above vk_stage_device. buffer.c, above gfx_composed, and buf_get_owned.
- Check:
check_guest_staging in tests/vulkan_guest_staging.inc.
S11. A read of guest memory into device memory copies the owned bytes on the GPU and takes staging only from the
first CPU byte.
- Without the rule: the GPU copied its own results and render targets out to host memory and read them back, about
34 MB a frame in one game's menu. In a texture test 60% of the destinations of the copy engine were held whole by
owners. The staging chunks that they took and never wrote cost a page fault for each page later, 7 ms for an
8 MiB copy source.
- Comment:
owned.c, above DevRead.
- Check:
check_owned_read_device in tests/vulkan_owned_readback.inc.
S12. The span of a published storage image is staged straight into the buffer that becomes its owner.
- Without the rule: staged in host memory, the span went out and came back several times, 12 to 14 MB a frame in
one game.
- Comment:
surface.c, vk_surf_publish.
- Check:
check_storage_image_keep covers the publish. No test holds the bytes that cross the bus.
S13. The original bytes of an atlas page are read from guest memory, not from staging.
- Without the rule: staging can be device memory behind the BAR. That copy was most of the
memcpy time of the GPU
thread in one game.
- Comment:
buffer.c, draw_output_page.
- Check: no test covers it.
S14. Each submit makes the host writes to the rings visible to the GPU.
- Without the rule: staging memory is not always host coherent, and the GPU reads stale bytes. The compute arena
has the same rule.
- Comment:
cmd.c, rings_flush and submit. compute.c, vk_dispatch.
- Check: no test runs on memory that is not coherent.
S15. The upload command buffer runs first in its submission, so its copies do not end a rendering pass.
- Without the rule: each fill of a new buffer ended the pass. A copy goes there only when nothing before it reads
the destination. A read of owned bytes goes there only when all of them were written before this submission.
- Comment:
cmd.c, above vk_cmd_upload, and owned.c, above read_settled.
- Check:
check_pass_breaks in tests/vulkan_pass_breaks.inc.
S16. A resource that is deferred for destroy waits for the frame that is recorded from now on.
- Without the rule: after a frame advance the current slot still holds the work of an older frame. A resource
pushed there went with that older frame while newer work could still use it. The pooled buffer of an owner
returns at the recycle of the frame for the same reason.
- Comment:
cmd.c, above vk_defer_image. owned.c, res_release. surface.c, above surf_free.
- Check: no test names
vk_defer_image. check_chunk_after_done covers the same rule for chunks.
S17. A compute arena that draws read waits for the frame of those draws, and the arena grows only between
batches.
- Without the rule: the draws can still run after the batch landed, and within a batch the recorded commands point
into the arena.
- Comment:
compute.c, above cs_arena_done, and above g_ar_want.
- Check: no test covers it.
← previous · next →