ScarletNX / ScarletNX documentation / Regression inventory for the buffer cache rewrite · ← previous · next →
The cache and its keys
K1. The index of the cache is open addressed, and the entries are in one array.
- Without the rule: entries live twenty seconds after their last use, and draws make new ranges all the time. Chained
buckets of separately allocated entries grew long. The walk cost a cache miss for each entry, a twentieth of the GPU
thread in one game. A lookup now reads one slot of the index, rarely two.
- Comment:
buffer.c, above g_vb.
- Check: no test covers it. Compare
g_vb_probes with g_vb_lookups in a scene with many draws.
K2. The hash of a range mixes every bit of its start and its length.
- Without the rule: the comment gives the reason and no failure. Constant buffers are 256-byte aligned and buffers
are often 4K aligned, so the low bits of the start carry nothing.
- Comment:
buffer.c, vb_home.
- Check: no test covers it. The probe count of K1 shows a weak hash.
K3. A caller that knows its ranges first fetches every index slot, then every entry.
- Without the rule: a draw looked its buffers up one after another. Each lookup waited on two cache misses in a row,
88% of the own time of
buf_get in one game.
- Comment:
buffer.c, vk_buf_prefetch.
- Check: no test covers it. Profile
buf_get in a scene with many draws.
K4. An entry with no buffer of its own goes after two seconds, and one with a buffer after twenty seconds.
- Without the rule: ranges that are read once made most of the entries. Constants streamed through a ring and
vertices at new offsets are such ranges. The lookups of the entries in use missed the cache over them. The sweep
takes a sixteenth of the entries every fourth present, so an entry goes at most 64 presents after its time.
- Comment:
buffer.c, buf_frame.
- Check: no test covers it. Watch the count of live entries over a minute of play.
K5. A storage buffer with no size of its own binds inside a shared window of guest memory.
- Without the rule: each such buffer took the 16 MiB after its address. One game's terrain tiles, each about 1 MB
after the last, made thirty overlapping copies of 16 MiB, 430 MB. A write under them made up to sixteen of them
copy again. A window has its full size from the start, because each growth would copy the whole window again.
Windows go when the GPU mappings change and when they are unused for a while, before the entries for them age out.
- Comment:
buffer.c, above WIN_N (the code is win_get and vk_buf_get_window).
- Check: no test names
vk_buf_get_window. Bind two bare addresses 1 MB apart and count the copies.
K6. A range whose offset in a window does not meet the alignment of the device is copied alone.
- Without the rule: the comment gives no failure. A binding offset must be a multiple of the alignment.
- Comment:
buffer.c, win_get.
- Check: no test covers it.
K7. A vertex or index range of unknown extent binds in a window, as a bare storage buffer does.
- Without the rule: the comment gives no failure. The GPU reads the count of an indirect draw, so the binding must
read on to the end of the window, and draws over the same memory share one copy.
- Comment:
buffer.c, vk_buf_get_window_input.
- Check: no test names it.
K8. A vertex or index buffer binds at any offset that keeps its elements aligned.
- Without the rule: the lookup took only the alignment of uniform and storage bindings. A draw that read an earlier
draw's storage result at another offset composed it over guest memory. In one game 216,000 vertex buffer bindings
in 600 frames were composed that way, each a copy into staging and a GPU copy of the result over it.
- Comment:
buffer.c, vk_buf_get_input.
- Check: no test covers it.
K9. A stable range gets a buffer of its own in device memory, filled by a GPU copy that runs ahead of the
submission.
- Without the rule: mapped memory for these buffers is the BAR window on most GPUs, 256 MB. Thousands of own buffers
there crowded out the staging rings. One game's rings took writes at a twentieth of their speed for minutes, 18 to
25 fps against 43. The copy runs in the upload command buffer so that the open rendering pass goes on. On a tiling
GPU an end of the pass stores every target, and the next begin loads them again.
- Comment:
buffer.c, above make_own_.
- Check:
check_pass_breaks in tests/vulkan_pass_breaks.inc, the case of a range that held still for three checks.
K10. With unified memory, a lookup reads guest memory in place only when no result is pending and no byte is GPU
owned.
- Without the rule: a read in place misses bytes that only the GPU holds. A cached copy is also not valid while an
in-place write is pending over it, because the draw would read a copy from before the write.
- Comment:
buffer.c, buf_get.
- Check:
check_uma in tests/vulkan_headless.c and check_uma_writes in tests/vulkan_uma_imports.inc.
K11. A read-only storage buffer of a dispatch is checked with no delay, and with unified memory it binds in
place.
- Without the rule: a changed word changes the result of the program, so the check cannot be late. Copied, every
binding of one tensor took a 16 MiB GPU copy out of the import, then a hash and a 16 MiB copy on the GPU thread.
That was about 35 copies, 540 MB and 15 ms of GPU time for each frame of one game's upscaled intro movie. The
binding uses the alignment of storage bindings, not that of the staging ring, which can be larger.
- Comment:
buffer.c, vk_buf_get_strict. The comment also lists the order rules that keep the read correct.
- Check:
check_uma_dispatch in tests/vulkan_uma_imports.inc.
K12. A constant buffer binds in place, but the pages that the runtime wrote are copied.
- Without the rule: the comment gives no failure. The constant buffer updates of the runtime are among those pages.
- Comment:
buffer.c, vk_buf_get_uniform.
- Check:
check_uma_constants in tests/vulkan_uma_imports.inc.
K13. The load of a save state drops every buffer, texture and render target that the caches keep.
- Without the rule: guest memory under them is that of the state, and the host addresses of the entries are stale.
- Comment:
buffer.c, vk_buf_forget_all, and surface.c, vk_surf_forget_all.
- Check:
tests/vulkan_nvn_savestate.inc loads a state through the renderer. No test names the two functions.
← previous · next →