1. Every buffer binding from the GPU mirror. Vertex, index, uniform, storage and indirect bindings take a
(buffer, offset) in the GPU mirror (mirror.c), which takes the pages the CPU wrote one time at each submit. Today
buf_get looks up a cache of guest ranges with content hashes (buffer.c), copies the changed ranges into staging,
and cb_get checks the pending results of each binding. The other project makes each NVN memory pool a buffer, syncs
the pages that write-watch marked in a command buffer before the first use in a submission, and finds a binding by a
search of a sorted index. Expected: the largest gain for each draw. Buffer device addresses are a later step that lets
a shader read a buffer by its guest address with no binding at all.
2. Uniform blocks copied one time for each submission. When the recording of a submission starts, copy every uniform range it binds into an arena, merged and aligned to 256 bytes. Draws bind by an offset in the arena. A GPU write in the same submission drops the copies it covers. This also gives each draw the bytes it had when the game submitted it, where a game writes its uniform buffers again after the submit. Item 1 needs it.
3. Generations for each address in the memos. tex_resolve drops its memo on gpu_mem_generation() and on the
counts of pending results and of images (g_pend_any.adds, g_gfx_img_any), which are global. cb_kept compares
vk_compute_adds() and vk_buf_adds(). A compute result anywhere in memory makes every memo miss, and an Ounce game
mixes many dispatches with its draws. Key each memo to generations of the addresses it read, held in a small hashed
table of the storage address.
4. The key of a program made one time. Make the program key when the game sets the program
(nvnProgramSetShaders and its Ounce form), keep it in the program object, and make it again only when a GPU or CPU
write reaches the code pages (writes.c). Today graphics programs and the compute programs that miss the fast
cache of compute.c hash their code at the draw or dispatch (vk_shader_hash, and sm86_program with sm86_hash
for SM86). Check first how much of this the fast cache of compute.c already does.
5. The flags of NVN memory pools. A pool with NVN_MEMORY_POOL_FLAGS_CPU_NO_ACCESS never needs traps, write
logs, masks or landings, because the CPU cannot read it. A pool with GPU no access needs no GPU memory. Storage
bindings come from the bound ranges, so only the bound ranges that a shader writes come back. nvn.h defines the
flags and no code reads them. Expected: GPU time for the logs and folds, CPU time for the harvest, and VRAM for the
masks.
6. A draw whose bindings did not change skips its descriptor build. Compare a signature of the inputs of the
descriptors of a draw, and compare the bytes of the bound slots only when a bind ran since the last draw. Skip a push
equal to the last under the same layout. Reuse a set whose descriptors pack to the same bytes, through update
templates. The other project skips about a quarter of its draws this way. stage_set builds the writes of each
stage and then hashes them (desc_set_cached).
In an Ounce game's race on the desktop of 2026-11-23, a counter in stage_set found 4,107 stages set a present.
Only 5.0% of them had the bindings, programs and inline constants of the last draw's same stage (DsState's
DS_BIND and DS_PROGRAMS generations, the stage's inline generations and the root's), all of those with no
GPU-side write to memory since. stage_set_ was 17.8% of the GPU thread, so a skip of the unchanged stages could
save under 1% of it there. Most of stage_set_ is the constant buffer lookups of item 1 (cb_get 5.7%,
cb_window_place 1.9%). The item waits for a game whose stages repeat.
7. Bindless textures. A Maxwell or SM86 shader reads a texture handle from a constant buffer and indexes the
texture and sampler pools. Let the translated shader index a descriptor heap that mirrors those pools and lasts
across draws, so that the renderer resolves no texture handle for each stage of each draw. The risk is in what
tex_resolve picks for each handle: render targets, scaled targets and converted formats. A heap entry must change
when its surface changes. This gives the most and risks the most, so it comes after items 1 to 6.
The design of 2026-11-23 builds on the texture table (vk/table.c), a heap of views and samplers that lasts across
frames, with update-after-bind. An Ounce game's race already reads its SM86 textures through it ("SM86 textures
through the texture table, one word a texture"), so what each draw still pays is the resolve that finds those words:
fs_key's tex_resolve (5.9% of the GPU thread) and the texture part of stage_set_. The constant buffers that
stage_set_ binds (cb_get 5.7%, cb_window_place 1.9%) stay, so the gain is about 10% of the GPU thread, not
most of stage_set_. (descriptors.c does not write the pool registrations of NVN into descriptor memory: only its
comment said so.)
fs_key's texture bits with
uniform branches.tex_memo_unwritten makes), a new surface at an
address (surf_changed), a new draw to a target a record crops, a new scale, an image swapped (tex_image_swap:
texconv, ASTC to BC7) and a view destroyed. The next draw that names a cleared index resolves it once, the old way.The steps, each one landed and measured alone, behind a setting that is off until the race and a Maxwell game run
clean with it: the measure, item 3, the pool map in a shadow mode that draw_state_check compares with the full
resolve, the barriers at the writers, the SM86 translator, the renderer's skip for plain slots, the Maxwell
translator, the indexed tables, then the setting on. Each has its test in tests/: a header written between two
draws, a target redrawn under a crop, an ASTC texture swapped to BC7, integer and signed formats through one slot
under GPU-assisted validation, a feedback draw, and the shader corpus under spirv-val.
Steps 1 to 6 are in, behind pool_map_shadow, writer_barriers and pool_map, all off. On the desktop the race
found every texture slot plain, about 1,300 TIC indices resolved about ten times each a present, and no record the
full resolve contradicted. Where guest memory is shared with the CPU, the map needs a storage buffer in place of
device addresses, and a draw that skips the resolve needs each record's own check of the writes since: the branch
bindless-uma has both. There it took 57% of the slots with no resolve and made the race slower. An A/B/B/A with a
pipeline cache warmed for each side gave 75.5 and 82.0 fps off and 64.1 and 69.4 on, about 2 ms more of the GPU
thread a present. The map's own work for each draw (its pages, and the checks by address after each submission and
dispatch moves the stamps) costs more than the resolves it skips.
The profile, on 2026-11-24 after the merge of main (the branch bindless-merged, with each side's pipeline cache
warm): 79.3 and 82.4 fps off, 75.6 and 72.6 on. The renderer thread rose from 25.0% to 28.5% of the samples:
vk_pool_gpu_draw took 2.0%. At each new frame it encodes again, entry by entry, every page of the map that has
records (about 405 of the texture pool's 514 pages, 3.4 MB a present), where 13 pages changed.vk_pool_gpu_skip, map_skip) took 0.85%.tex_bind_view, vk_sampler, vk_table_words) was about 0.9%. Inclusive tex_resolve
stayed at 2.72%: the slots the map skips are the ones the memo answered already.Pages kept encoded, and written only where they change (versions freed once their submission is done), would remove the 2%, and leave the map near even. A map that wins must check nothing for each draw: each entry of the texture table kept valid by the writes that change it (uploads, the pool's header writes, drawn targets), so a draw binds the table alone. That is a new validity model for the texture cache, not a change to this map.
7b. A texture table kept valid by writes. The design that replaces the map's checks.
What it can save, from the profile above with the map off: inclusive tex_resolve is 2.7% of the samples, about 11% of
the renderer thread. Some of stage_set_ (5.7% inclusive) and fs_key (3.0%) is texture work too. The ceiling is
about 15% of the renderer thread, and less where the memo already answers.
What a draw must still do: read its handle words from the constant buffers. Nothing else says which textures the draw reads, and a texture that no draw resolved has no image yet. The model does not load every texture that the game registered: the pools of an Ounce game name about 131,000 headers, and the game uses about 1,300 of them.
The model:
An entry for each TIC index that a draw resolved: the texture, its view and sampler slots, and a valid bit.
This is the pool map's record (pool_map.c), with the stamps and the checks by address removed. A draw reads
each handle and tests the bit. A set bit binds the slots with no other read. A clear bit takes today's full path
(tex_resolve, vk_tex_recheck, take of drawn targets) and sets the bit again.
Events clear the bits. Each of the memo's checks becomes the event that makes it fail:
| Today's check for each draw | The event that clears the bits |
|---|---|
The surface table at the texture's address (vk_surf_epoch_at) | A surface made, freed or moved there: the entries of the textures at that address |
CPU writes to the headers (tex_memo_unwritten) | A write-tracking intake of a pool page: the headers that changed, compared with the record |
| GPU-side writes to the headers | gpu_mem_written_by over a pool page: the same compare |
Pending results over the headers or the texture (tex_memo_unpended) | A result added over a texture's memory: its entries |
A pending storage image over the texture (tex_memo_image_pending) | The same, when the image is added |
A drawn target under the texture (over, wgen) | vk_rt_drawn over a texture's memory: its entries |
The texels (vk_tex_recheck) | A CPU write to a texture's pages at the intake, or a GPU-side write over them: its entries |
An index from guest address to the textures that have entries. These are the textures that drawing uses, about 1,300. The index is buckets of 64 KiB with a list of textures each, so an event with a range finds them with no search of the surface table. Each texture keeps the list of its entries. A first test of a bitmap of the pages in the index lets most events (most DMA copies, most publishes) return at once.
Pages on the GPU written only where they change. An entry's words go into its page in CPU memory when it changes. A changed page is written into a new block of the buffer, and the old block is freed when the submission that last used it is done. This is how drivers version buffers that the GPU reads. A frame no longer writes every page again.
The order of events. An event and the draws are on the renderer thread, in stream order. The front end's
writes come to the renderer in that order already (gpu_mem_written_by, the intake of the scans at a submission).
A bit that a write clears is clear before the next draw that the write comes before.
Made from docs/dev/draw-cost.md at 69237645142c. GPL-3.0-or-later.