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.

CPU: a bind GPU: a draw slot numbers in the draw's data
Classic: bind before every draw bind setA draw 1 bind setB draw 2 bind setC draw 3 bind setD draw 4 Bindless: bind once bind the one big set(all textures) draw 1 3, 7 draw 2 3, 9 draw 3 12 draw 4 5, 7 … thousands more
Classic: one set per material. The CPU must know every draw, and its order, while it records. Bindless: each draw carries slot numbers in its own data. Nothing is bound between draws, so the draws can be one indirect call that the GPU fills in itself. Classic binding ties the CPU to every draw; bindless removes the CPU from the loop.

Binding per draw has three costs:

… × 10,000 draws = milliseconds of binds

CPU time

Each bind is a driver call, and the driver checks and copies state. With 10,000 draws this adds up to milliseconds.

a pool of sets: one per material

Many small sets

Every material needs its own set, allocated from a pool and kept alive. Changing a material means writing a new set.

culling (GPU) draw 516 draw 517 draw 518 CPU bind before 517?

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.

material record (in a GPU buffer) base color texture2 normal texture5 roughness texturenone base color factor1, 1, 1 shader color = textures[m.baseColor].Sample(uv) n = textures[m.normal].Sample(uv) the one texture array, bound once slot 0grass slot 1rock slot 2brick color slot 3sky slot 4empty slot 5brick normal slot 6empty … slot N−1
The record says "which"; the array says "what". A material change is a change of a few numbers in a buffer. The slot numbers are plain integers. They can live in any buffer the shader reads: material tables, instance tables, push constants.

Try it. Pick the record a draw reads, then write other slot numbers into it.

records and written slots the base color lookup the shader and its normal lookup an empty slot that is read
Click the three records: only the numbers the shader reads change. Then give a record another base color, a normal map as its color, and an empty slot.

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.

pool one set = one material's 4 descriptors

Classic: many small sets

A handful of descriptors per material. One set per material, often per frame. A large pool, often reset every frame.

pool 012 N−1 one set = an array of N descriptors

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:

PieceWhat it isClassic useBindless use
DescriptorA record of a few bytes: image view, sampler, layout (or a buffer range).A handful per materialOne per texture, for its whole life
Set layoutThe shape of a group: "binding 0 is 4 textures, binding 1 is a buffer".One per shader kindOne: "binding 0 is an array of N textures"
SetOne group of descriptors with that shape.One per material, often per frameOne for the whole program
PoolMemory that sets are carved from.Large, often reset every frameSized for the one set
BindA command that makes a set visible to the next draws.Before each drawOnce 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.

a written slot an empty slot GPU work that uses the set the CPU the shader
Sampler2D textures[ ] 1 no size in the shader frames in flight: the set is bound and in use 012 345 678 910… 2 empty: allowed new texture 3 written while the set is in use 4 length set at allocation 1148 5 4 threads of one wave, each with its own index wave
One array, five relaxed rules. Without 2 and 3 every new texture would need a new, fully valid set.
Feature (Vulkan name)What it allowsWhy 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.
The array size is a choice

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.

Uniform: one load for the wave 3 3 3 3 3 3 3 3 load descriptor 3 once, every thread samples it Non-uniform, marked: the compiler loops 3 3 7 3 9 9 3 7 pass 1: threads with 3 load and sample 3 pass 2: threads with 7 load and sample 7 pass 3: threads with 9 load and sample 9 Non-uniform, not marked: undefined wanted 3 3 7 3 9 9 3 7 3 3 3 3 3 3 3 3 sampled the hardware may load one descriptor (often the first thread's) for all
Each box is one thread of a wave, with the index it uses. Marking the index tells the compiler to handle each different value in turn. It costs a few extra instructions, and one pass per distinct index in the wave.
The bug is silent

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 fromUniform?Mark it?
A push constant, or a field of a uniform bufferYes: the same for the whole drawNo
A per-draw record, the same for every vertex and pixel of the drawYes, 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 bufferNoYes
A compute shader thread that reads its own itemNoYes

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:

012 345 678 9 used used used used free used used used free never … counter = 9: the first slot never used free list [ 4, 8 ]
Slots 4 and 8 were freed and wait in the free list. The counter marks the first slot never used. The array never moves and never gets holes that need packing: a free slot simply waits for the next texture.
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

GPU frame 9 runs CPU frame 10 records slot 4 still holds T's descriptor retire list slot 4, frame 10 free list [ ] Frames 9 and 10 may both sample slot 4. Nothing about the slot changes yet.

"Free" only records the wish. The descriptor and the image stay as they are.

Frame 11 starts: wait for frame 9

GPU frame 9 done frame 10 runs CPU frame 11 records slot 4 frame 10 still reads it retire list slot 4, frame 10 free list [ ] The finished frame (9) is older than the tag (10), so the slot keeps waiting.

Each frame start checks the retire list against the newest finished frame.

Frame 12 starts: frame 10 is done

GPU frame 10 done frame 11 runs CPU frame 12 records slot 4 T's image destroyed now retire list [ ] free list [ 4 ] Frames 11 and 12 were recorded after the free, so no record they read may name slot 4 any more.

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

GPU frame 11 runs CPU frame 12 records slot 4 now holds U's descriptor retire list [ ] free list [ ] Writing a slot that no pending work reads is exactly what "update after bind" allows.

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.

slot in use freed, waits for the GPU free; dashed: never used reused too early
Free a texture, then press "Next frame" until its slot reaches the free list: two frame starts. Turn the retire list off, free a texture and add a new one in the same frame.
The two rules of slot lifetime
  • 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:

emissive texture 0xFFFFFFFF none? yes skip: the factor alone no sample × factor

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.

emissive texture slot 0 always sample × factor, no branch … 1×1 slot 0: reserved, one white texel

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).

TextureDefault texelWhy that value changes nothing
Base colorwhite (1, 1, 1, 1)factor × 1 = factor
Metallic-roughnesswhitefactor × 1 = factor
Occlusionwhite1 means "not occluded"
Emissivewhitefactor × 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 image samplers image 0+ linear repeat image 1+ linear clamp image 2+ linear repeat textures[i].Sample(uv) Separate images and samplers image 0 image 1 image 2 sampler 0: linear repeat sampler 1: linear clamp images[i].Sample(samplers[s], uv)
Combined: one number per texture. The sampler is fixed when the slot is written: the same image with another sampler needs a second slot. Separate: two numbers, or a fixed sampler in the shader; any image can be read with any sampler. Engines need only a handful of samplers. APIs limit how many can exist: Vulkan only promises 4000.
CombinedSeparate
Shader codeSimplest: one indexTwo indices, or a sampler chosen in the shader
Same image, two samplersTwo slotsOne slot, two sampler indices
PortabilityVulkan, OpenGL. Direct3D 12 and WebGPU have no combined type.Works everywhere
SpeedAbout the same on current GPUsAbout the same; a fixed sampler can be a constant

9Other ways to build the array

APIThe big array isThe shader writes
Vulkan, descriptor indexingA descriptor set with one large, partially bound bindingtextures[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 12A shader-visible descriptor heapResourceDescriptorHeap[i] (Shader Model 6.6), or an unbounded array
MetalAn argument buffer that holds texture referencesa 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).

CPU · when a material or pass first needs the texture TextureHandle from loadTexture, … addBindlessTexture → updateBindlessDescriptorSet descriptor at a freed slot, else nextBindlessTextureIndex++ textures.slots[index] the texture's slot CPU · writeMaterialRow convertToGfxMaterial getBindlessTextureIndex × 5 MaterialData slot numbers, not handles fragMain gTextures[index].Sample(uv) reads the descriptor
Two lookups: handle → slot on the CPU (an array at the handle's index), slot → descriptor on the GPU (the array). With no slot, 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

PartThis pageRASM
The arrayone large binding in one setBinding 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 imagesone more array, of images shaders writeBinding 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).
Featuressection 4All 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 layoutone for every shaderOne, 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 indexingmark per-pixel indicesNothing 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 allocationcounter + free listThe 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 listsection 6The 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 texturesThe "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.)
Samplerscombined or separateCombined. 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 loadinggray or checkerNone. 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 bufferssection 9Not used.

Who takes a slot

CallerWhich texturesSampler
createMaterialeach valid texture it gets that has no slot yetLINEAR_REPEAT
updateMaterialeach valid texture of the new values that has no slot yetLINEAR_REPEAT
loadMaterial (glTF)each uploaded image, once per image, sampler and color spacefrom the glTF sampler (toSamplerType)
Renderer::setEnvironmentImagean environment's image (LINEAR_REPEAT, since it wraps around) and its three cubesLINEAR_CLAMP
Renderer::createEnvironmentsthe BRDF LUT, onceLINEAR_CLAMP
Renderer::getUiTexturea loaded texture that has no slot yet, for ImGui::ImageLINEAR_REPEAT
The UI (buildUi)Dear ImGui's own texturesLINEAR_CLAMP
RenderContext::createRenderTargeteach 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)

M's row baseColorTextureIndex 2 → 8 setRow: dirty in both slots Entity E waitingForTextures false E's scene draw list E's draws are in T had no slot, so addBindlessTexture gives it slot 8. T is not loaded yet, so the material counts as "textures loading".

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

M's row baseColorTextureIndex 8 Entity E waitingForTextures true entitiesWaitingForTextures E's scene draw list marked for rebuild: next syncGpuScene, E's draws are out It checks every entity (it also runs when doubleSided changed, to fix the cull modes).

E disappears from the image until T is ready. No frame ever samples slot 8 before T has pixels.

3. finishLoads: T is decoded

Texture T fillTexture: pixels + mips isLoaded(T) = true GpuScene texturesFinished true E's scene draw list E's draws are still out finishLoads runs at the start of beginFrame, before syncGpuScene.

The flag tells syncGpuScene that it is worth checking the waiting entities again.

4. syncGpuScene: E comes back

M's row uploaded since step 1 base color: slot 8 Entity E waitingForTextures false E's scene draw list rebuilt: E's draws are in, now sampling T markDrawListsDirty marks only the scenes that hold E.

From this frame on, E draws with T. Changing only factors (colors, roughness) never makes an entity wait.

Where it lives in code

WhatWhere
Set layout, pool and setEngine::Engine in src/renderer/renderer.cpp
Handle → slotRenderer::addBindlessTexture, Renderer::getBindlessTextureIndex in src/renderer/renderer.cpp; RenderContext::getBindlessTextureIndex
Slot free list and counter, descriptor write, retireRenderContext::updateBindlessDescriptorSet, RenderContext::destroyTexture in src/rhi/renderContext.cpp; VulkanDevice::updateBindlessTexture in src/rhi/vulkan/vulkanDevice.cpp
Layout flags and featuresVulkanDevice::createBindlessDescriptorSetLayout, VulkanDevice::createDescriptorPool, the device feature list in src/rhi/vulkan/vulkanDevice.cpp
The six samplerssamplerDesc, RenderContext::initialize in src/rhi/renderContext.cpp
Slot numbers into the rowconvertToGfxMaterial, Renderer::writeMaterialRow in src/renderer/gpuScene.cpp
Materials that take slotsRenderer::createMaterial, Renderer::updateMaterial, AssetLoader::Impl::loadMaterial in src/assets/material.cpp
Waiting for texturestexturesLoaded, Renderer::refreshEntitiesAfterMaterialChange, Renderer::syncGpuScene in src/renderer/gpuScene.cpp
Shader sidegTextures in shaders/passes/rasm.slang and shaders/passes/hiz.slang; hasTexture, sampleBaseColor in shaders/lib/core.slang
Keep these true
  • "No texture" is INVALID_TEXTURE_INDEX in the row, never 0: slot 0 is a real texture. The shader must check hasTexture before it indexes gTextures.
  • 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 why endPass moves 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::Material is 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.
Not done yet

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