forge-indirect-drawing
Add GPU-driven indirect drawing with compute-based frustum culling to an SDL GPU project. A compute shader tests bounding spheres against frustum planes and…
от Nebulavenus★ 51 звезда на GitHub
Установить forge-indirect-drawing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Indirect Drawing with Compute Frustum Culling
Add GPU-driven rendering to an SDL GPU project where a compute shader performs frustum culling and writes indirect draw commands. The CPU uploads object data once; the GPU decides what to draw every frame.
Based on GPU Lesson 38.
When to use
- You have many instances of the same mesh and want the GPU to cull invisible ones
- You want to eliminate per-object CPU draw decisions entirely
- You need frustum culling without CPU-side bounding volume tests
- You want a debug visualization showing which objects are visible vs. culled
Core data structures
ObjectGPUData storage buffer
Each object's transform, color, bounding sphere, and draw arguments are packed into a single struct stored in a GPU storage buffer. Both the compute shader (for culling) and the vertex shader (for rendering) read from this buffer.
/* Must match the HLSL ObjectData struct exactly.
* Total: 112 bytes per object, 16-byte aligned. */
typedef struct ObjectGPUData {
mat4 model; /* offset 0: 64 bytes — model-to-world transform */
float color[4]; /* offset 64: 16 bytes — base color (RGBA) */
float bounding_sphere[4]; /* offset 80: 16 bytes — xyz=center(world), w=radius */
Uint32 num_indices; /* offset 96: 4 bytes — index count for this object */
Uint32 first_index; /* offset 100: 4 bytes — first index in shared index buffer */
Sint32 vertex_offset; /* offset 104: 4 bytes — added to each index */
Uint32 _pad; /* offset 108: 4 bytes — align to 16 bytes */
} ObjectGPUData; /* 112 bytes */
IndirectCommand (matches SDL_GPUIndexedIndirectDrawCommand)
/* 20 bytes per command — 5 x uint32. Written by the compute shader. */
struct IndirectCommand {
uint num_indices;
uint num_instances; /* 1 = visible, 0 = culled (hardware no-op) */
uint first_index;
int vertex_offset;
uint first_instance; /* = object index, used for storage buffer lookup */
};
CullUniforms
typedef struct CullUniforms {
float frustum_planes[6][4]; /* 6 planes, each (nx, ny, nz, d) */
Uint32 num_objects;
Uint32 enable_culling; /* 1 = cull, 0 = draw everything */
float _pad[2]; /* 16-byte alignment */
} CullUniforms;
Buffer creation and usage flags
Each buffer requires specific usage flags to allow cross-pipeline access:
/* Object data — read by compute (culling) and vertex shader (transforms) */
object_data_buf = upload_gpu_buffer(device,
SDL_GPU_BUFFERUSAGE_COMPUTE_STORAGE_READ |
SDL_GPU_BUFFERUSAGE_GRAPHICS_STORAGE_READ,
objects, num_objects * sizeof(ObjectGPUData));
/* Indirect draw commands — written by compute, consumed by indirect draw */
SDL_GPUBufferCreateInfo bi;
SDL_zero(bi);
bi.usage = SDL_GPU_BUFFERUSAGE_INDIRECT |
SDL_GPU_BUFFERUSAGE_COMPUTE_STORAGE_WRITE;
bi.size = num_objects * 20; /* 5 x uint32 per command */
indirect_buf = SDL_CreateGPUBuffer(device, &bi);
/* Visibility flags — written by compute, read by debug fragment shader */
SDL_zero(bi);
bi.usage = SDL_GPU_BUFFERUSAGE_COMPUTE_STORAGE_WRITE |
SDL_GPU_BUFFERUSAGE_GRAPHICS_STORAGE_READ;
bi.size = num_objects * sizeof(Uint32);
visibility_buf = SDL_CreateGPUBuffer(device, &bi);
/* Instance ID buffer — [0, 1, 2, ..., N-1] as a vertex buffer */
Uint32 ids[NUM_OBJECTS];
for (int i = 0; i < NUM_OBJECTS; i++) ids[i] = (Uint32)i;
instance_id_buf = upload_gpu_buffer(device,
SDL_GPU_BUFFERUSAGE_VERTEX,
ids, sizeof(ids));
Instance ID vertex buffer pattern
SV_InstanceID does not consistently include first_instance across all GPU
backends. The portable alternative is a vertex buffer containing [0, 1, ..., N-1]
bound at INSTANCE input rate. Each indirect draw command sets first_instance
to the object index, so the instance attribute value equals the object index
regardless of backend.
Vertex input state
SDL_GPUVertexAttribute attrs[4];
SDL_zero(attrs);
/* Per-vertex: position (float3), location 0 */
attrs[0].location = 0;
attrs[0].buffer_slot = 0;
attrs[0].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3;
attrs[0].offset = offsetof(SceneVertex, position);
/* Per-vertex: normal (float3), location 1 */
attrs[1].location = 1;
attrs[1].buffer_slot = 0;
attrs[1].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3;
attrs[1].offset = offsetof(SceneVertex, normal);
/* Per-vertex: UV (float2), location 2 */
attrs[2].location = 2;
attrs[2].buffer_slot = 0;
attrs[2].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2;
attrs[2].offset = offsetof(SceneVertex, uv);
/* Per-instance: object ID (uint32), location 3 */
attrs[3].location = 3;
attrs[3].buffer_slot = 1;
attrs[3].format = SDL_GPU_VERTEXELEMENTFORMAT_UINT;
attrs[3].offset = 0;
SDL_GPUVertexBufferDescription vb_descs[2];
SDL_zero(vb_descs
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл forge-indirect-drawing?
Add GPU-driven indirect drawing with compute-based frustum culling to an SDL GPU project. A compute shader tests bounding spheres against frustum planes and writes indirect draw commands — the CPU never decides what to draw. Uses SDL_DrawGPUIndexedPrimitivesIndirect with per-object storage buffers and the first_instance offset pattern for portable instance identification.
Как установить скилл forge-indirect-drawing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл forge-indirect-drawing запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…