GPU data
Bindless resources
In the classic model, the CPU tells the GPU which textures a draw may use, before each draw. In the bindless model, all textures sit in one big array that is bound once, and the shader picks a texture by its number. This page explains how that works, which GPU features it needs, and how to manage the numbers safely. The last part shows how RASM does it.
In short
- A descriptor is a small GPU record that says "this image, read with this sampler". Shaders reach textures only through descriptors.
- Classic binding changes the bound descriptors before each draw. Bindless puts every descriptor in one array, binds it once, and stores slot numbers in the data the shader reads.
- It needs descriptor indexing: an array with no fixed size, empty slots allowed (partially bound), writes while the array is bound (update after bind), and indexing that may differ per pixel (non-uniform).
- Slots are handed out by a small allocator, usually a counter plus a free list.
- A freed slot can be reused only after every frame that may still read it has finished on the GPU.
- Bindless makes GPU-driven rendering possible: the GPU can choose the draws, because no draw needs the CPU to bind anything.
1The problem: binding per draw
A shader cannot read "texture number 7" by itself. It reads textures through descriptors: small records, prepared by the CPU, that hold an image view, a sampler and the layout the image is in. In the classic model, each draw gets its own small group of descriptors, and the CPU binds that group right before the draw.
Binding per draw has three costs:
CPU time
Each bind is a driver call, and the driver checks and copies state. With 10,000 draws this adds up to milliseconds.
Many small sets
Every material needs its own set, allocated from a pool and kept alive. Changing a material means writing a new set.
No GPU-driven draws
If a compute shader decides which objects to draw (after culling, for example), the CPU does not know the draws. It cannot bind a set "before draw 517", because it never sees draw 517.
2The idea: one array, and numbers in the data
Bindless turns the problem around. All textures go into one big descriptor array, created once and bound once. Each texture gets a fixed slot in it: a number from 0 to the array size minus 1. The data that the shader reads anyway (a material record, an instance record) stores slot numbers instead of textures. The shader reads the number and indexes the array.
Try it. Pick the record a draw reads, then write other slot numbers into it.
Now a draw needs nothing bound of its own. Two draws with different materials differ only in which record they read, and that is data. Data can be written by the GPU too, so a compute shader can build the whole list of draws.
3Descriptors, sets and pools
The words differ between APIs, but the pieces are the same. A pool is memory. Sets are carved from it. Each set is a group of descriptors, and its layout gives the group its shape.
Classic: many small sets
A handful of descriptors per material. One set per material, often per frame. A large pool, often reset every frame.
Bindless: one set
One descriptor per texture, for its whole life. One set for the whole program, in a pool sized for it.
Here are the pieces with the Vulkan names:
| Piece | What it is | Classic use | Bindless use |
|---|---|---|---|
| Descriptor | A record of a few bytes: image view, sampler, layout (or a buffer range). | A handful per material | One per texture, for its whole life |
| Set layout | The shape of a group: "binding 0 is 4 textures, binding 1 is a buffer". | One per shader kind | One: "binding 0 is an array of N textures" |
| Set | One group of descriptors with that shape. | One per material, often per frame | One for the whole program |
| Pool | Memory that sets are carved from. | Large, often reset every frame | Sized for the one set |
| Bind | A command that makes a set visible to the next draws. | Before each draw | Once per pass (or per pipeline change) |
Direct3D 12 calls the array a descriptor heap and Metal calls it an argument buffer. The idea is the same in all three.
4The GPU features it needs
The first versions of Vulkan and Direct3D had fixed-size arrays that had to be fully valid, and could not change while a command buffer used them. Bindless needs five relaxations. In Vulkan they are called descriptor indexing (an extension first, core since Vulkan 1.2). The picture shows where each one acts; the table names them.
| Feature (Vulkan name) | What it allows | Why bindless needs it |
|---|---|---|
| 1 · Runtime array runtimeDescriptorArray | A shader array with no size: Sampler2D gTextures[]. | The shader should not hard-code how many textures exist. |
| 2 · Partially bound descriptorBindingPartiallyBound | Slots that were never written are allowed, as long as no shader reads them. | The array is big (thousands of slots) and mostly empty at the start. |
| 3 · Update after bind descriptorBindingSampledImageUpdateAfterBind | Writing slots of a set that is bound, or used by work on the GPU, without breaking that work. | Textures arrive while frames are being recorded and run. Without it, every new texture would need a new set. |
| 4 · Variable count descriptorBindingVariableDescriptorCount | The last binding's size is chosen when the set is allocated, not when the layout is made. | One layout can serve sets of different sizes. Optional. |
| 5 · Non-uniform indexing shaderSampledImageArrayNonUniformIndexing | Index values that differ between the threads of one wave. | Neighboring pixels may belong to different materials. See below. |
Each feature also has a limit. The important one is the size of the array: how many sampled images one set and one shader stage may see with update after bind. On current desktop GPUs this is hundreds of thousands to millions, so the array size is a choice, not a hard wall.
Non-uniform indexing
A GPU runs threads in groups of 32 or 64, called waves (or warps). A wave runs one instruction for all its threads at once. A descriptor is often loaded into scalar registers that the whole wave shares. That only works when every thread in the wave uses the same index. An index with this property is called dynamically uniform.
On some GPUs it looks right. On others the red threads show the wrong texture, usually in thin lines along the edges where two materials meet on screen. A wave covers a block of pixels, so only blocks that touch two materials go wrong.
In HLSL and Slang the mark is NonUniformResourceIndex(i); in GLSL it is nonuniformEXT(i). When do you need it?
| Where the index comes from | Uniform? | Mark it? |
|---|---|---|
| A push constant, or a field of a uniform buffer | Yes: the same for the whole draw | No |
| A per-draw record, the same for every vertex and pixel of the draw | Yes, within one draw. In Vulkan each draw of a multi-draw indirect call is its own group for this rule. | No (marking is still safe, and cheap when all values are equal) |
| A per-pixel value: a material ID read from a G-buffer, a decal list, a visibility buffer | No | Yes |
| A compute shader thread that reads its own item | No | Yes |
5Handing out slots
A slot number is a small resource of its own. Something must decide which slot a new texture gets, and remember which slots are free. The usual allocator is a counter and a free list:
allocate():
if freeList is not empty: return freeList.pop()
if counter == capacity: fail ("array full")
counter = counter + 1
return counter - 1
free(slot):
freeList.push(slot) // only when no GPU work can still read it
Some engines also reserve the first slots for fixed textures: slot 0 for a white texture, slot 1 for a flat normal map, and so on. Then "slot 0" can mean "no texture", and the shader needs no special case (see section 7).
6When a slot can be reused
The CPU runs ahead of the GPU by one or more frames (see frames in flight). When the program frees a texture during frame N, the GPU may still be running frame N − 1, and frame N is not even submitted yet. Both may read that slot. If a new texture takes the slot now, those frames draw the new texture on the old objects, or read an image that no longer exists.
The fix is a retire list: a freed slot first waits, tagged with the frame that freed it. Once the GPU has finished that frame (its fence has signaled), the slot moves to the free list. The image memory waits in the same way. Here is one slot, with 2 frames in flight:
Frame 10: the app frees texture T
"Free" only records the wish. The descriptor and the image stay as they are.
Frame 11 starts: wait for frame 9
Each frame start checks the retire list against the newest finished frame.
Frame 12 starts: frame 10 is done
This last condition is the program's job: every material that used T must have been changed before the free.
Frame 12: a new texture U takes slot 4
The wait is F frames for F frames in flight. With 2 frames, a slot is reused at the earliest two frame starts after its free.
The picture below runs the allocator of section 5 with this retire list, two frames in flight. Then turn the list off, and see what goes wrong.
- Never write a slot that work on the GPU may still read. Update after bind allows writes to a bound set, not writes under a running read.
- Never let a record keep a stale slot number. If material M still says "4" after slot 4 went to U, M draws with U. This is the same problem that generational handles solve for CPU handles.
7A material without a texture
Most materials do not use every texture slot. A rock may have a color and a normal map, but no emissive map. The shader must still produce the right result. There are two common ways:
A "none" number and a branch
Store a special value, such as 0xFFFFFFFF, for "no texture". The shader checks it and skips the sample, using the material's factor alone. No extra textures are needed. The cost is a branch per texture, and the special value must never reach the array.
Default textures
Reserve slots for tiny 1×1 textures that change nothing, and point empty slots at them. The shader always samples: no branch, one code path. The cost is a few slots and a sample that reads the same texel every time (it stays in the cache).
| Texture | Default texel | Why that value changes nothing |
|---|---|---|
| Base color | white (1, 1, 1, 1) | factor × 1 = factor |
| Metallic-roughness | white | factor × 1 = factor |
| Occlusion | white | 1 means "not occluded" |
| Emissive | white | factor × 1 = factor; the emissive factor is 0 when the material does not glow |
| Normal map | (0.5, 0.5, 1.0) | decodes to (0, 0, 1): the surface normal itself (see normal mapping) |
A third value is a placeholder: a gray or checker texture shown while the real one is still loading. A slot can also be pointed at the placeholder first and rewritten when the real texture is ready, because the slot number does not change.
8Samplers: combined or separate
A sampler holds how to read a texture: the filter (nearest, linear), the mip filter and the wrap mode (see mipmaps and sampling). A bindless design has to decide where samplers live.
| Combined | Separate | |
|---|---|---|
| Shader code | Simplest: one index | Two indices, or a sampler chosen in the shader |
| Same image, two samplers | Two slots | One slot, two sampler indices |
| Portability | Vulkan, OpenGL. Direct3D 12 and WebGPU have no combined type. | Works everywhere |
| Speed | About the same on current GPUs | About the same; a fixed sampler can be a constant |
9Other ways to build the array
| API | The big array is | The shader writes |
|---|---|---|
| Vulkan, descriptor indexing | A descriptor set with one large, partially bound binding | textures[i] |
| Vulkan, descriptor buffers (VK_EXT_descriptor_buffer) | A plain GPU buffer. The app asks the driver for each descriptor's bytes and copies them in itself; no sets or pools. | textures[i], same as above |
| Direct3D 12 | A shader-visible descriptor heap | ResourceDescriptorHeap[i] (Shader Model 6.6), or an unbounded array |
| Metal | An argument buffer that holds texture references | a field of the argument buffer |
Descriptor buffers make the memory explicit: descriptors become bytes the app manages like any other buffer data, with the same frame-in-flight rules. That makes them a natural fit for engines that already manage GPU buffers by hand. They are newer, so their support is narrower than descriptor indexing.
10Trade-offs and pitfalls
What it gives
- Very little CPU work per draw, and none between GPU-chosen draws.
- One pipeline layout for every shader that reads textures.
- Materials become plain data, easy to change and to upload.
- Shaders can read any texture: decals, terrain splat maps, a visibility buffer that shades any material.
What it costs
- The driver no longer checks which textures a draw uses. A wrong index reads the wrong texture or crashes the GPU, with no error.
- Lifetime is the app's job: slots, retire lists and stale numbers.
- The driver no longer knows which images a draw reads, so the app must put every image in the right layout itself (see GPU synchronization).
- Debuggers show "an array of 1000 textures" instead of "this draw's 4 textures".
What goes wrong in practice, by what you see on screen:
- Wrong texture in thin lines along material edges, on some GPUs only
- A per-pixel index is not marked non-uniform. Mark the index (section 4).
- Garbage, black, or a lost device
- A shader reads a slot that was never written. Use a "none" value with a branch, or default textures.
- Objects without a texture show the first texture loaded
- 0 means "none", but slot 0 is a real texture. Use a value that is never a slot, or reserve slot 0 for white.
- The previous frame flickers with the new texture
- A slot was freed at once and reused. Use a retire list (section 6).
- Validation errors; corrupt texels on some GPUs
- An image is in the wrong layout when it is sampled. Move images to the read layout before the draws that read them.
11In RASM
RASM has one bindless set for the whole engine: an array of RendererConfig::maxBindlessTextures combined image samplers, 16384 by default. A material row on the GPU stores slot numbers, and a texture handle becomes a slot number the first time a material or a pass needs it. A texture holds its slot until it is destroyed; then the slot goes through the retire list of section 6 and is reused (deferred destruction).
getBindlessTextureIndex returns UINT32_MAX, the same value as INVALID_TEXTURE_INDEX, and hasTexture in the shader skips the sample. The row reaches the GPU through syncGpuScene, like every table row.Where RASM follows the textbook, and where it differs
| Part | This page | RASM |
|---|---|---|
| The array | one large binding in one set | Binding 0 of set 0: RendererConfig::maxBindlessTextures COMBINED_IMAGE_SAMPLERs (16384 by default), visible to every stage (ShaderType::ALL). Made once by RenderContext::initialize, lowered with a warning to what the device allows (Vulkan: maxDescriptorSetUpdateAfterBindSampledImages and Samplers, per stage too, and a stage's resources less the storage images of binding 1) and to MAX_BINDLESS_TEXTURES (65536: a slot fits 16 bits); getBindlessTextureCapacity gives the count, and so does the renderer's getConfig. The shaders declare Sampler2D gTextures[] with [[vk::binding(0, 0)]]. rasm.slang also declares SamplerCube gCubeTextures[] on the same binding, for the slots that hold a cube (a point light's shadow, an environment's cubes); a slot is read only through the declaration that matches its view. |
| Storage images | one more array, of images shaders write | Binding 1 of the same set: MAX_BINDLESS_STORAGE_IMAGES = 1024 STORAGE_IMAGEs (BindlessDescriptorSetLayoutDesc::storageImageCount, checked against the device at startup), with the same flags. Each slot is one mip of a SAMPLED_STORAGE texture, written with RenderContext::updateBindlessStorageImage in the GENERAL layout; a shader declares it with its format, [format("rgba16f")] RWTexture2DArray<float4> gStorageImages[]. The first RESERVED_STORAGE_IMAGES (32) are the environment bake's, which rewrites the same slots for every bake, after the frames that used them are done (Image-based lighting). The others go to the colors of storage render targets, one each for the target's life, given back when a graph's transient target is destroyed (Bloom). |
| Features | section 4 | All five are required at device creation, plus update-after-bind for storage images. The binding has VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT and VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT; the layout and pool have the matching update-after-bind flags. The variable count is enabled but not used: the size is fixed. |
| Pipeline layout | one for every shader | One, made with the set layout (createPipelineLayout, called from VulkanDevice::createBindlessDescriptorSetLayout) and destroyed with it: the set and one PUSH_CONSTANTS_SIZE range that the vertex, fragment and compute stages all see, and the task and mesh stages where the device has mesh shaders. Every pipeline, graphics, mesh or compute, uses it, so the set stays bound across pipeline changes and RenderContext::pushConstants needs no stage. |
| Non-uniform indexing | mark per-pixel indices | Nothing is marked. The index comes from the draw's instance row (materialIndex, passed with nointerpolation), so it is the same for every pixel of one draw, and each draw of the indirect call is its own group. Other users index with a push constant (01_render_graph) or a SceneData field (hiz.slang). |
| Slot allocation | counter + free list | The same: freeBindlessSlots, then the counter nextBindlessTextureIndex, in RenderContext. A texture holds one slot: asked again, it returns it unchanged, since a frame in flight may sample it (another sampler is an error). A caller may name a slot; the texture that held it loses it, and the counter moves past it. |
| Freeing, retire list | section 6 | The same: RenderContext::destroyTexture gives the image and the slot to the release queue, which frees them once the GPU has finished every frame that may sample them (deferred destruction). Renderer::destroyTexture first removes the texture from every material that has it, so no row keeps the slot number. A render target that is rebuilt (on resize) or placed again keeps its slots: the device is idle then, and the new textures take the old slots. Dear ImGui's replaced textures go the same way. |
| Missing textures | "none" value or default textures | The "none" value: INVALID_TEXTURE_INDEX (0xFFFFFFFF) and a branch on hasTexture. No default textures. The shader uses the factor alone, which is the glTF rule. (The default material is a material, not a texture.) |
| Samplers | combined or separate | Combined. Six shared samplers, one per SamplerType, picked when the slot is written (LINEAR_REPEAT by default). One handle has one slot, so a glTF image used with two samplers is uploaded twice. |
| Placeholder while loading | gray or checker | None. A texture from loadTexture may get a slot before its pixels exist, but an entity is not drawn until every texture of its materials is loaded, so the empty image is never read. |
| Descriptor buffers | section 9 | Not used. |
Who takes a slot
| Caller | Which textures | Sampler |
|---|---|---|
createMaterial | each valid texture it gets that has no slot yet | LINEAR_REPEAT |
updateMaterial | each valid texture of the new values that has no slot yet | LINEAR_REPEAT |
loadMaterial (glTF) | each uploaded image, once per image, sampler and color space | from the glTF sampler (toSamplerType) |
Renderer::setEnvironmentImage | an environment's image (LINEAR_REPEAT, since it wraps around) and its three cubes | LINEAR_CLAMP |
Renderer::createEnvironments | the BRDF LUT, once | LINEAR_CLAMP |
Renderer::getUiTexture | a loaded texture that has no slot yet, for ImGui::Image | LINEAR_REPEAT |
The UI (buildUi) | Dear ImGui's own textures | LINEAR_CLAMP |
RenderContext::createRenderTarget | each color texture (of each frame slot's copy, with history); with occlusionCulling (always for a depth-only target or one with a MOTION_FORMAT color), also a D32_SFLOAT depth texture. A rebuilt or re-placed target keeps its slots. | LINEAR_CLAMP, depth NEAREST_CLAMP |
loadTexture and Renderer::createTexture do not take a slot. When every slot is held or waits for the GPU, updateBindlessDescriptorSet logs how many wait and names RendererConfig::maxBindlessTextures, and returns UINT32_MAX. examples/17_streaming pushes thousands of textures through the set, a few each frame, and a tile streamer counts the slots as one of its budgets.
A material that waits for its texture
The slot is written at once, but the texture may still be decoding on a worker thread (see streaming assets). The engine therefore keeps every entity that uses it out of the draw lists until the pixels arrive. Here is what happens when the app gives material M of entity E a new texture T that is still loading:
1. updateMaterial(M, values)
updateMaterial copies the new values over the record, keeps the handle, and calls writeMaterialRow. The row index does not change, so no instance row changes.
2. refreshEntitiesAfterMaterialChange
E disappears from the image until T is ready. No frame ever samples slot 8 before T has pixels.
3. finishLoads: T is decoded
The flag tells syncGpuScene that it is worth checking the waiting entities again.
4. syncGpuScene: E comes back
From this frame on, E draws with T. Changing only factors (colors, roughness) never makes an entity wait.
Where it lives in code
| What | Where |
|---|---|
| Set layout, pool and set | Engine::Engine in src/renderer/renderer.cpp |
| Handle → slot | Renderer::addBindlessTexture, Renderer::getBindlessTextureIndex in src/renderer/renderer.cpp; RenderContext::getBindlessTextureIndex |
| Slot free list and counter, descriptor write, retire | RenderContext::updateBindlessDescriptorSet, RenderContext::destroyTexture in src/rhi/renderContext.cpp; VulkanDevice::updateBindlessTexture in src/rhi/vulkan/vulkanDevice.cpp |
| Layout flags and features | VulkanDevice::createBindlessDescriptorSetLayout, VulkanDevice::createDescriptorPool, the device feature list in src/rhi/vulkan/vulkanDevice.cpp |
| The six samplers | samplerDesc, RenderContext::initialize in src/rhi/renderContext.cpp |
| Slot numbers into the row | convertToGfxMaterial, Renderer::writeMaterialRow in src/renderer/gpuScene.cpp |
| Materials that take slots | Renderer::createMaterial, Renderer::updateMaterial, AssetLoader::Impl::loadMaterial in src/assets/material.cpp |
| Waiting for textures | texturesLoaded, Renderer::refreshEntitiesAfterMaterialChange, Renderer::syncGpuScene in src/renderer/gpuScene.cpp |
| Shader side | gTextures in shaders/passes/rasm.slang and shaders/passes/hiz.slang; hasTexture, sampleBaseColor in shaders/lib/core.slang |
- "No texture" is
INVALID_TEXTURE_INDEXin the row, never 0: slot 0 is a real texture. The shader must checkhasTexturebefore it indexesgTextures. - An image must be in the shader-read layout whenever a draw may sample its slot: the descriptor promises
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL. That is whyendPassmoves a render target's color attachment there (B10). - Do not rewrite a slot that a frame in flight may read. A destroyed texture's slot comes back through the release queue; a rebuilt render target rewrites its own slots with the device idle.
- A new texture field in
gfx::Materialis a CPU↔GPU struct change: see struct layout. - If an index ever comes from per-pixel data (a G-buffer, a decal list), mark it non-uniform.
A texture destroyed through RenderContext::destroyTexture directly, not Renderer::destroyTexture, stays in the materials that use it. The array size and the 256 materials are fixed at compile time (D15). No default textures. See also the bindless API.
Further reading
- The Vulkan specification, chapter "Resource Descriptors", and the VK_EXT_descriptor_indexing and VK_EXT_descriptor_buffer extension specifications.
- Khronos, Vulkan Guide: the chapter on descriptor indexing.
- Microsoft, HLSL Shader Model 6.6: "Dynamic Resources" (ResourceDescriptorHeap).
- Matt Pettineo, Bindless Texturing for Deferred Rendering and Decals (2016).