GPU data

GPU memory and uploads

A GPU reads its data fastest from its own memory, but the data starts on the CPU. This page explains the kinds of GPU memory, how the CPU writes into them, and the usual ways to move data across: mapped writes, staging copies, ring buffers and per-frame copies. The last part shows how RASM does it.

CPU work / CPU memory GPU work GPU buffer / memory

In short

  • A discrete GPU has its own fast memory (VRAM). The CPU reaches it only across the PCIe bus, if at all.
  • The API lists memory types with flags: device-local (fast for the GPU), host-visible (the CPU can map it), coherent, cached.
  • Memory the CPU cannot map is filled with a staging copy: the CPU writes a host-visible buffer, and the GPU copies it over.
  • A ring buffer reuses one staging buffer forever. A fence tells when the GPU has finished reading each part.
  • Many small copies go out in one batch. Barriers order them against the frames that read the data.
  • Data the GPU reads every frame and the CPU changes every frame needs one copy per frame in flight.
  • Engines sub-allocate: a few big memory blocks, with many buffers inside each.

1Two memories, one bus

A discrete GPU is a card with its own memory chips, called VRAM. VRAM is very fast for the GPU. The CPU's memory (system RAM) is on the other side of the PCIe bus, which is much slower. An integrated GPU (most laptops, phones, Apple silicon) has no VRAM: CPU and GPU share the same RAM.

Discrete GPU CPU system RAMe.g. 32 GB GPU VRAMe.g. 12 GB wide: 100s of GB/s PCIe: narrow 16–32 GB/s Integrated GPU CPU GPU one shared RAMboth read and write it
The bus is the narrow part. Every byte the CPU makes must cross it once; the GPU then reads it many times from VRAM. The rule that follows: put data the GPU reads often in VRAM, and move it across the bus as few times as possible.
100s of GB/sthe GPU reading its own VRAMsometimes more than 1 TB/s
≈ 16 GB/sthe bus between CPU and GPUPCIe 3.0 x16
≈ 32 GB/sthe same bus, one generation laterPCIe 4.0 x16

2Heaps and memory types

Vulkan (and Direct3D 12 and Metal, with other names) describe the memory as heaps and memory types. A heap is a pool of physical memory with a size. A memory type is a way to use a heap, described by flags. Every allocation picks one memory type. The four flags:

GPU VRAM fast

device-local

Fast for the GPU. On a discrete GPU this is VRAM.

CPU pointer map, then copy bytes

host-visible

The CPU can map it: get a normal pointer and write or read with memcpy.

CPU bytes GPU no flush, no invalidate visible in both directions

host-coherent

CPU writes become visible to the GPU without an extra call (and the other way round).

CPU memory cached: fast not cached: very slow

host-cached

CPU reads go through the CPU cache, so reading is fast. Without it, reads are very slow.

A typical discrete GPU on a desktop PC shows something like this:

Heap 0 · VRAM · 12 GB device-local textures, vertex data, GPU-only buffers the CPU cannot map it device-local + host-visible the BAR window: the CPU writes into VRAM directly, across PCIe old: only 256 MB of it with resizable BAR (ReBAR): all of VRAM Heap 1 · system RAM · 32 GB host-visible + coherent write-combined: fast to write in order, very slow to read back staging buffers live here host-visible + coherent + cached normal CPU memory: fast to read readback buffers live here the GPU reads it across PCIe
An integrated GPU usually has one heap whose types are device-local and host-visible at the same time: everything can be mapped. The exact list differs per GPU and driver. Code should not hard-code type indices: it asks for the flags it needs and picks a matching type.

Write-combined memory

Host-visible memory that is not cached is usually write-combined: the CPU collects writes in a small buffer and sends them over the bus in big pieces.

one pass, in order sent over the bus in big pieces

Write once, in order

Writing it in order, once, with memcpy, is fast.

reads, and writes at scattered places each read crosses the bus

Read, or write here and there

Reading it, or writing scattered bytes, or doing x += 1 on it, is very slow, because each read crosses the bus.

Write-only

So treat mapped upload memory as write-only.

Coherent or not

CPU writes memory GPU reads visible at the next submit

Coherent

After the CPU writes, the bytes are visible to the GPU at the next submit. Nothing else is needed.

CPU memory GPU write, then flush invalidate, then read

Not coherent

After writing, the CPU must flush the range (vkFlushMappedMemoryRanges). Before reading what the GPU wrote, it must invalidate the range. Ranges are rounded to nonCoherentAtomSize, a device limit of up to 256 bytes.

New memory is cleared first

The OS never gives a program bytes another program left behind. So new video memory is cleared before the program can use it. On Windows the video memory manager does this. The clear runs by itself, and the device's next submit waits until it is done.

576 MiB allocated, then an empty submit at once device-local only 13 ms · 0.024 ms a MiB device-local + host-visible (resizable BAR) 110 ms · 0.19 ms a MiB The same submit 200 ms after the allocation waits for nothing: the clear was already done.
Measured on an RTX 3060 under Windows, with a small Vulkan program that only allocates and submits. Other GPUs and drivers have other numbers, but the order is the same.
Big buffers

Put a big buffer the CPU does not map in device-local-only memory, and make it at startup, not while frames run.

3Two ways to fill a buffer

There are two ways to get bytes from the CPU into a buffer that the GPU reads.

A. Direct write CPUmemcpy host-visible buffermapped pointer shader reads GPUdraw or dispatch One step, no command. B. Staging copy CPUmemcpy staging buffersystem RAM, mapped copy cmd device-localVRAM GPUfast reads Two steps. The bytes cross PCIe once, during the copy.
A is good for small data that changes every frame. If the buffer is in system RAM, every GPU read crosses PCIe. In B, every read after the copy is from VRAM. The copy is a GPU command, so it must be recorded, submitted, and ordered before the work that reads the data. With resizable BAR or an integrated GPU, path A can write straight into device-local memory, and the staging step is not needed.
DataSizeChangesUsual path
Per-frame constants (camera, lights)bytes to KBevery frameA, into host-visible memory, one copy per frame in flight
Meshes, static tablesMB to GBonce, at loadB, into device-local memory
TexturesMB to GBonceB (images need a copy into their tiled layout, see section 8)
Big tables with a few changed rowsMBa few rows per frameB with only the changed rows, or A with ReBAR

4The staging ring

Making a new staging buffer for every upload is slow, and freeing it needs to wait for the GPU copy. Instead, engines keep one big staging buffer and use it as a ring. Two counters describe it: head, where the next write goes, and tail, the oldest byte the GPU may still read. Bytes between them are in use. A fence (or a timeline value) per submitted batch tells when its bytes are free again.

This example uses a 64 MiB ring. A piece is never split across the end of the ring; a piece that does not fit before the end skips to the start. Click through it.

1. An empty ring

free 016324864 MiB tail = head = 0 One mapped buffer, made once. Every upload copies into it first. head and tail only grow; the position in the ring is the counter modulo 64 MiB.

Counters that never wrap make the math simple: head − tail is the space in use, and head mod size is the next position.

2. Upload 40 MiB

16 MiB 16 MiB 8 MiB pending: one copy of 40 MiB (the chunks are next to each other on both sides) 016324864 MiB tail = 0 head = 40 MiB A big upload is cut into chunks of at most 16 MiB (a quarter of the ring), so one chunk plus any skipped space always fits in an empty ring. Neighbouring chunks to neighbouring destinations merge into one copy.

Nothing has reached the GPU yet. The copy command waits in a list until the next submit.

3. Submit: the batch goes to the GPU

batch 1 · the GPU copies it submitted: batch 1 signals fence value 1; it ends at 40 MiB 016324864 MiB tail = 0 head = 40 MiB The batch remembers two numbers: its fence value (1) and where it ends in the ring (40 MiB). That is all the ring needs to free the space later.

The CPU does not wait. It goes on recording the next frame.

4. Next frame: space comes back, a piece skips to the start

B · 12 MiB free A · 16 MiB skipped pending: A and B, two copies 016324864 MiB head = 76 MiB (76 mod 64 = 12) tail = 40 MiB Fence value 1 is reached, so tail moves to batch 1's end. A goes at 40 MiB. B (12 MiB) would cross the end, so head skips 8 MiB and B goes at 0. In use: 76 − 40 = 36 MiB, the skipped part included.

Checking a fence value does not block. The ring only learns about finished batches; it never waits for them here.

5. If the GPU is late: the ring is full

B · 12 MiB free (batch 1 and A are copied) skipped full: submit what is pending, wait for every copy, then tail = head 016324864 MiB head = 76 MiB tail = 56 MiB If fence value 1 is not reached, tail is still 0, and 56 + 8 + 12 − 0 = 76 MiB > 64 MiB. So A is submitted as batch 2, the CPU waits for value 2, and tail jumps to head (56 MiB). Then B goes at 0.

This wait stalls the CPU. It only happens when more than a ring's worth of data is uploaded before the GPU catches up, for example a big level loaded in one frame.

Now run the ring yourself. It starts at step 3: 40 MiB are submitted as batch 1, and the GPU has not finished them.

pending: written, not submitted submitted: the GPU may still read it free; dashed: skipped
Click the GPU, then upload 16 MiB and 12 MiB: this is step 4. Reload the page and upload them without clicking the GPU: the 12 MiB do not fit, and the CPU stalls, as in step 5.

The ring size is a trade-off. Bigger means fewer stalls but more memory that sits idle most of the time. As a rough number, a 64 MiB ring can move a lot per frame before the bus itself becomes the limit:

64 MiBthe ring in this example
≈ 25 GB/sa rough speed over PCIe
≈ 2.7 msto copy a whole ring across the bus64 MiB / 25 GB/s

5Batching and ordering the copies

A copy command is cheap, but a submit is not. So uploads are collected and sent as one batch: one command buffer with many copies, submitted once per frame, before the frame's own work.

CPU frame N records uploads → pending copies submit batch first, then frame frame N+1 records a new batch 1st: upload batch 2nd: frame N GPU one queue frame N−1 still running copies then signal the fence frame N reads the new data barrier: wait for earlier work barrier: later work sees the copies
On one queue, two barriers are enough to order the copies. The first protects data that frame N−1 still reads. The second makes the copies visible to frame N.
staging buffer 1 copy, not 2

Merging

Two copies whose source and destination ranges both continue each other become one bigger copy.

A B ? same bytes: A or B last?

Overlapping writes

Copies in one batch have no barrier between them, so their order is not defined. Two writes to the same bytes in one batch must go into two batches (or the second must replace the first on the CPU).

graphics queue frame frame copy queue copies semaphore

A transfer queue

Many GPUs have a separate copy queue that runs next to the graphics queue. Copies there do not slow the frame, but they need a semaphore to order them, and buffers may need a queue ownership transfer. See GPU synchronization.

staging pending copy destroyed

Destroying a buffer with pending copies

Drop its pending copies, and wait for submitted batches that write it. Otherwise the GPU copies into freed memory.

6Sub-allocation

Asking the driver for memory (vkAllocateMemory) is slow, and the number of live allocations is limited: the Vulkan spec only promises 4096 (maxMemoryAllocationCount). A scene can have far more buffers than that. So engines allocate a few big blocks and place many buffers inside each one: sub-allocation.

block 1 256 MiB, one driver allocation vertex buffer index buffer table free alignment gaps block 2 256 MiB texture (optimal tiling) free
Each resource asks for a size and an alignment. The allocator finds a free range, and binds the resource at that offset. A very large or often-recreated resource (a full-screen render target, for example) may get a dedicated allocation of its own instead. Drivers sometimes ask for this.

Four kinds of allocator share out a block:

next only forward

Linear (bump)

One pointer that only moves forward. Free all at once by resetting it.

Good for: data that lives exactly one frame, or forever (load once, never free).

wraps around tail head

Ring

A linear allocator that wraps around, freed in the order it was used (section 4).

Good for: staging, per-frame constants.

the list of free ranges mixed sizes

Free list (or TLSF)

Keeps a list of free ranges; finds one big enough; merges neighbours on free.

Good for: general buffers and textures of mixed sizes and lifetimes.

every slot the same size free free

Pool

Many slots of one fixed size.

Good for: many objects of the same size.

Most Vulkan engines do not write this themselves. The Vulkan Memory Allocator (VMA) library from AMD picks memory types from usage hints, manages blocks with a free-list allocator, and handles alignment, dedicated allocations and memory budgets. Direct3D 12 has the same idea in D3D12MA.

7Changing data the GPU is reading

The CPU is usually a frame ahead of the GPU (see Frames in flight). If the CPU writes a buffer while the GPU still reads it for the previous frame, the GPU can see half old and half new data.

the CPU writes for frame N new old frame N−1 reads: half new, half old

A direct mapped write

It is not ordered at all: the bytes change under the frame that reads them.

one queue, in order N−1 reads copy N reads new barrier barrier

A staging copy

It is safe: its barrier waits for the frame that still reads.

For data that is written directly, the usual answer is one buffer per frame in flight:

frame 10 CPU writes copy 0 GPU reads copy 1 (frame 9) frame 11 CPU writes copy 1 GPU reads copy 0 (frame 10) after the fence of frame 9 CPU shadow row 2 rows 5, 6 dirty per copy copy 0: {2, 5, 6} copy 1: {2, 5, 6}
N copies for N frames in flight. The CPU keeps the newest values in a shadow array, and each copy catches up when its turn comes. Each copy gets the changed rows in its own frame, merged into ranges (row 2, rows 5–6). A row changed ten times is sent once per copy.
copy 0 copy 1 one change, sent to each copy

Per-frame copies

Simple and fast. Costs N times the memory. Every change must be sent N times, once to each copy.

frames read this new free the new range is written once

Write only new ranges

For data that only grows (a mesh pool), write each new range once, in a part no frame has read yet. One copy is enough.

8Textures

A texture is not stored row by row in GPU memory. The GPU uses an optimal tiling: a hidden, vendor-specific order (blocks, swizzles) that makes nearby texels close in memory. The CPU cannot write that order itself.

CPU memory: row by row 0123 4567 891011 12131415 a copy command, or host image copy the texels are reordered on the way GPU memory: optimal tiling 0145 2367 891213 10111415
The numbers show the order in memory. The order on the right is only an example: the real one is hidden and differs per vendor. Texels that are neighbours in the image stay close in memory.

So textures need either a copy command or a special CPU path:

Classic: staging + GPU copy rowsto staging layout→ copy destination copy buffer→ image, level 0 blit mipslevel by level layout→ shader read Host image copy layout on the CPUundefined → shader read copy memory → imageevery mip level, from CPU memory ready to sampleno command buffer, no staging
Host image copy (Vulkan 1.4 core, before that VK_EXT_host_image_copy) lets the driver do the tiling on the CPU. The mips must then come from the CPU too: resized in software, or stored in the file. The classic path works everywhere and uses the GPU's fast blit. Host image copy is simpler and needs no GPU time, but needs the feature, and the driver may then keep the image in host-visible memory, which can cost the GPU (texture uploads).

Mip levels add about a third. Formats with block compression (BC7, ASTC) are usually made offline. See Mipmaps and texture sampling.

64 MiBa 4096 × 4096 RGBA8 texture4096 · 4096 · 4 bytes
85 MiBthe same texture with all its mipsabout a third more
4× or moresmaller with block compressionBC7, ASTC

9Reading data back

Sometimes the CPU needs a result the GPU computed: a count, a picked object, a timing. Reading back has its own steps, in this order:

  1. Use host-cached memory. Reading write-combined memory is very slow (section 2). Ask for host-visible and host-cached.
  2. On the GPU: a barrier to the host. After the shader or copy that writes the data, a barrier with the host as the destination stage makes the writes available to the CPU.
  3. On the CPU: wait for the fence. Wait for the fence of that submit. Until then the data may not be there yet.
  4. Invalidate, then copy. If the memory is not coherent, invalidate the range first. Then copy the bytes out.

Waiting for this frame's fence would stall the CPU until the GPU catches up. So engines read results a frame or two late: in frame N they read what frame N − 2 wrote, after the fence they already wait for anyway.

GPU frame N−2: done, result written frame N−1 runs CPU frame N: wait for the fence of N−2 read the result of N−2 two frames late, no extra wait
The CPU never waits for the frame it has just submitted.

10In RASM

RASM uses VMA for all memory. A buffer is one of three kinds, set by two flags in BufferDesc. RenderContext::fillBuffer then picks path A or B of section 3 by itself: a mapped buffer gets a memcpy, any other buffer goes through the staging ring in UploadManager.

BufferDesc VMA flags Memory you get hostReadable = true the CPU reads it back HOST_ACCESS_RANDOM + MAPPED host-visible, cached mapped · readBuffer works hostVisible = true the CPU rewrites it often HOST_ACCESS_SEQUENTIAL_WRITE + MAPPED host-visible mapped · write-only neither flag the default (or staged, without a discrete GPU) HOST_ACCESS_SEQUENTIAL_WRITE + MAPPED + ALLOW_TRANSFER_INSTEAD device-local + host-visible BAR, ReBAR, integrated → mapped device-local only not mapped → staging ring staged = true filled once, on a discrete GPU no host access not MAPPED device-local only not mapped → staging ring
The last row keeps big buffers out of host-visible memory, whose clear held back the first frame (section 2, P35): the geometry pools (about 280 MiB) and the animation pool are staged. Buffer::mapped says which case you got: it is true when VMA returned a mapped pointer. hostReadable replaces the other flags, so it wins over hostVisible.
fillBuffer(buffer, data, size, offset) mapped? yes no VulkanDevice::fillBuffer memcpy + vmaFlushAllocation: there at once UploadManager::upload into the ring: there after the next submit
The caller does not choose the path. The same call is a memcpy on one GPU and a staged copy on another, so code that calls fillBuffer must be correct on both.

Where RASM follows the textbook, and where it differs

PartThis pageRASM
Picking memory typesask for flags, never hard-code typesVMA with VMA_MEMORY_USAGE_AUTO and host-access flags (VulkanDevice::createBuffer). The allocator is made with the memory-budget and device-address flags.
New memory is clearedbig buffers the CPU does not map in device-local-only memory, made at startupThe pools the CPU fills once are BufferDesc::staged: the geometry pools and the animation pool. On a discrete GPU they ask for no host access. Before (P35) they were in resizable-BAR memory: about 280 MiB made the first frame's fence wait up to 50 ms on an RTX 3060, and now about 1 ms. They are made when the renderer starts, except the point pool, which comes with the first point cloud. Other buffers stay mappable where all of video memory is host-visible, so the scene tables are written at once each frame; they come out of host-visible VMA blocks, and a new block is cleared too.
Sub-allocationa few blocks, many buffersVMA does it for buffers and sampled textures, which ask for no host access. Attachments and storage textures each get a dedicated allocation (VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT), except transient render targets: the render graph places them in shared heaps, and two that are never used at the same time share bytes (Transient memory and aliasing).
Staging ringone buffer, head/tail, a fence per batchThe same, in UploadManager: RING_SIZE = 64 MiB, chunks of at most MAX_CHUNK_SIZE = 16 MiB, counters that never wrap, one timeline fence. The stepper in section 4 is RASM's real behaviour. A ring is a BufferUsage::TRANSFER buffer: system memory, or video memory where all of it is host-visible (resizable BAR), never a small BAR heap (P10). With a transfer queue a second ring serves the loads.
Batchesone per frame, before the frameTwo command buffers take turns (batches). RenderContext::submit calls flush before every submit. flush also runs when the ring is full, and when a write overlaps bytes the batch already writes to the same buffer.
Mergingneighbouring copies become oneThe same (addCopy).
Orderingtwo barriers, or a transfer queue and a semaphoreTwo global barriers in VulkanCommandBuffer::copyBuffers, on the graphics queue. With async compute, the compute queue is outside those barriers: the upload submit waits for the last compute submit, and each compute submit waits for the last upload (UploadManager::lastSubmit). The loads' copies have a second UploadManager on a transfer queue, with its own ring, and the frames wait only for load values the CPU saw reached (transfer queues).
Sharing between queuesexclusive, or concurrentExclusive with one queue. With a compute queue, every buffer and image is created VK_SHARING_MODE_CONCURRENT for both queue families, so nothing moves ownership. Some GPUs compress such images less (P11). With a transfer queue, buffers are concurrent for it too, and a texture filled from the ring moves to the graphics family by a release and an acquire (transfer queues).
Destroy with pending copiesdrop them, wait for submitted onesThe same, later: destroyBuffer hands the buffer to the release queue, whose free calls cancelUploads once the frame fences and the upload fence have passed its last use (deferred destruction), so nothing waits.
The staging buffer's memorysystem RAMCreated hostVisible. Every RASM buffer has the device-address usage bit, which VMA counts as GPU access, so VMA prefers device-local memory for it. On a GPU with a BAR heap the ring may land in VRAM.
Data the GPU reads every frameone copy per frame in flightGpuTable (the instance, material and light tables, the animated entities and the morph weight overrides): a CPU shadow, one buffer per frame slot, dirty rows per slot merged into ranges by mergeRows, uploaded in syncGpuScene after that slot's fence wait. SceneData: one hostVisible buffer per slot. See The GPU scene tables.
Data that only growswrite only new rangesGeometryPool: a range allocator (RangeAllocator, first fit) over each of six device-local buffers (vertices, indices, colors, skin weights, morph deltas, the geometry table), sized from EngineConfig. The animation pool is one more, sized by EngineConfig::animationPoolBytes. A destroyed mesh's ranges come back once the GPU is done with them (deferred destruction).
Buffers that grow—Draw lists, visible draws and Hi-Z buffers are per frame slot. When one is too small, it is destroyed and a bigger one is made (draw buffers at least double), right after that slot's fence wait. Visible draws and Hi-Z grow with RenderContext::resizeBuffer, which keeps the handle, so the render graph passes that declared it stay valid; the contents and the device address change.
Texturesclassic, or host image copyBoth, per format. RenderContext::fillTexture takes every mip (a load's are made on its worker, buildTextureLevels). Where host copy costs the GPU nothing for the format (VulkanDevice::queryFormatSupport, texture uploads), VulkanDevice::fillTexture changes the layout with vkTransitionImageLayout and copies all levels with vkCopyMemoryToImage. Otherwise, or with EngineConfig::hostImageCopy false, UploadManager::uploadTexture puts the levels in the staging ring as whole rows of blocks, 16-byte aligned, at most a chunk each, so a texture larger than the ring spans batches; copyToTextures records, per batch, UNDEFINED (the texture's first copy) or SHADER_READ_ONLY → TRANSFER_DST, the copies, and → SHADER_READ_ONLY.
Readbackcached memory, barrier, fence, invalidateThe same: a hostReadable buffer, readBuffer calls vmaInvalidateAllocation. updateFrameStats reads a slot's cull stats right after beginFrame waited for that slot's fence: the numbers of the slot's last frame, two frames ago. Renderer::readFrame and readTexture copy an image into a hostReadable buffer of its own, read after the fence of the frame that copied it (Headless rendering and readbacks).

Which buffer is which kind

BufferKindCopiesWritten by
Upload staging ringshostVisible, BufferUsage::TRANSFER1, or 2 with a transfer queueUploadManager::upload
Scene datahostVisible1 per frame slot, room for MAX_SCENE_VIEWS = 32 scene viewsprepareSceneView
Cull statshostVisible + hostReadable1 per frame slotthe GPU; read by updateFrameStats
Readback buffershostReadable1 per readback, freed when it is takenthe GPU's copy; read by takeReadback
Instance, material and light tables, animated entities, morph weight overridesdefault1 per frame slotGpuTable::upload
Vertex, index, color, skin and morph pools, geometry tabledefault1GeometryPool::upload
Animation pooldefault1Renderer::uploadMeshAnimation
Draw infodefault1 per scene and frame slotuploadDrawList
Visible draws, draw counts, Hi-Z, visibilitydefaultper scene view (and slot, except visibility)only the GPU, except visibility's first fill

Every buffer also gets the device-address bit and both transfer bits, whatever its BufferUsage (toVkBufferUsageFlags). So any buffer can be a copy source or destination, and can be read by a shader through its address (see Buffer device addresses).

Where it lives in code

WhatWhere
Memory flags, buffer and texture creationVulkanDevice::createBuffer, VulkanDevice::createTexture, toVkBufferUsageFlags in src/rhi/vulkan/vulkanDevice.cpp
The two flagsBufferDesc in include/rasm/render/resource.h; Buffer::mapped in src/rhi/device.h
Path choice, submit, destroy, readbackRenderContext::fillBuffer, submit, destroyBuffer, readBuffer in src/rhi/renderContext.cpp
Direct write and readVulkanDevice::fillBuffer, VulkanDevice::readBuffer in src/rhi/vulkan/vulkanDevice.cpp
Staging ring and batchesUploadManager in src/rhi/uploadManager.h, src/rhi/uploadManager.cpp
Copy barriersVulkanCommandBuffer::copyBuffers in src/rhi/vulkan/vulkanCommandBuffer.cpp
Per-slot tablesGpuTable, mergeRows in src/renderer/gpuTable.cpp
Geometry poolGeometryPool in src/renderer/geometryPool.cpp
Readback buffersrecordReadbacks, takeReadback in src/renderer/readback.cpp
Texture uploadRenderContext::fillTexture; VulkanDevice::fillTexture (host copy) in src/rhi/vulkan/vulkanDevice.cpp; UploadManager::uploadTexture and VulkanCommandBuffer::copyToTextures (staging)
Tests (no GPU)tests/uploadManagerTests.cpp, tests/gpuTableTests.cpp
Keep these true
  • Never fillBuffer a range that a frame in flight reads. On a mapped buffer the write lands at once, with no ordering. Use one buffer per frame slot, or a new range.
  • GPU scene tables are written only in syncGpuScene, after that slot's fence wait, through GpuTable::setRow.
  • Staged data arrives with the next submit, not when fillBuffer returns.
  • Read only hostReadable buffers, and only after a barrier to the host stage and a fence wait.
  • createBuffer always makes a new buffer (B1). Destroy the one you replace, and only when no frame in flight uses it.
  • Keep MAX_CHUNK_SIZE at most a quarter of RING_SIZE, so a skipped end plus a chunk always fit in an empty ring.
  • Normal, metallic-roughness and AO textures are R8G8B8A8_UNORM; color and emissive are R8G8B8A8_SRGB.
Not done yet

D13: uploads are recorded on the main thread. D14: some callers ignore the result of fillBuffer.

Further reading