Files
2nd/10_Wiki/Topic_Programming/Frontend/Indirect Draw.md
T
Antigravity Agent 9148c358d0 docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를
Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류.

- 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로
  자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거,
  동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거.
- 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming,
  Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business,
  Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로,
  나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는
  title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백).
  원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지.
- 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서.
- 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는
  지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지.
- Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경.
- 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
2026-07-05 00:33:48 +09:00

5.9 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-indirect-draw Indirect Draw 10_Wiki/Topics verified self
Indirect Drawing
GPU-Driven Rendering
drawIndirect
none A 0.9 applied
graphics
gpu
webgpu
vulkan
rendering
performance
2026-05-10 pending
language framework
wgsl webgpu

Indirect Draw

매 한 줄

"매 indirect draw 는 draw call args 의 GPU buffer 의 read — CPU roundtrip 없이 GPU 의 self-dispatch". 2026 의 GPU-driven rendering pipeline 의 foundation: Vulkan/D3D12/Metal/WebGPU 의 support. 매 culling, LOD, instancing 의 GPU 에서 결정 → CPU draw-call overhead 의 elimination.

매 핵심

매 vs Direct Draw

  • Direct: draw(vertexCount, instanceCount, firstVertex, firstInstance) — args from CPU.
  • Indirect: drawIndirect(buffer, offset) — args read from GPU buffer.
  • Multi-draw indirect (MDI): thousands of draws from one CPU command.

매 Args Layout (WebGPU)

struct DrawIndirectArgs {
  vertexCount: u32,
  instanceCount: u32,
  firstVertex: u32,
  firstInstance: u32,
}
struct DrawIndexedIndirectArgs {
  indexCount: u32,
  instanceCount: u32,
  firstIndex: u32,
  baseVertex: i32,
  firstInstance: u32,
}

매 Pipeline (GPU-driven)

  1. Compute shader: per-object frustum/occlusion cull → write visible list.
  2. Compute shader: write indirect args buffer (instanceCount=0 for culled).
  3. drawIndexedIndirect (or MDI) reads buffer → renders only visible.

매 응용

  1. Massive instanced scenes (foliage, crowds, particles).
  2. GPU-driven culling (frustum, occlusion via Hi-Z).
  3. LOD selection on GPU.
  4. Variable-rate / batched rendering (cluster culling, Nanite-style).

💻 패턴

WebGPU Indirect Draw Setup

// Args buffer (visible after compute)
const indirectBuffer = device.createBuffer({
  size: 16,  // 4 u32
  usage: GPUBufferUsage.INDIRECT | GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST,
});

// Initialize: 36 verts, 1000 instances, offset 0/0
device.queue.writeBuffer(indirectBuffer, 0,
  new Uint32Array([36, 1000, 0, 0]));

// In render pass
pass.setPipeline(pipeline);
pass.setVertexBuffer(0, vertices);
pass.drawIndirect(indirectBuffer, 0);

Culling Compute Shader (WGSL)

struct DrawArgs { vertexCount: u32, instanceCount: u32,
                  firstVertex: u32, firstInstance: u32 }

@group(0) @binding(0) var<storage, read>       objects: array<Object>;
@group(0) @binding(1) var<storage, read_write> drawArgs: DrawArgs;
@group(0) @binding(2) var<storage, read_write> visibleInstances: array<u32>;
@group(0) @binding(3) var<uniform>              camera: Camera;

@compute @workgroup_size(64)
fn cullCS(@builtin(global_invocation_id) gid: vec3<u32>) {
  let i = gid.x;
  if (i >= arrayLength(&objects)) { return; }
  let obj = objects[i];
  if (frustumTest(obj.bounds, camera.frustum)) {
    let slot = atomicAdd(&drawArgs.instanceCount, 1u);
    visibleInstances[slot] = i;
  }
}

Reset Pass (clear instanceCount)

// Each frame, before culling, zero out instanceCount
device.queue.writeBuffer(indirectBuffer, 4, new Uint32Array([0]));

Multi-Draw Indirect (Vulkan)

// Draw N different meshes from one buffer
vkCmdDrawIndexedIndirect(cmd, indirectBuf, 0,
                         /*drawCount*/ N,
                         /*stride*/ sizeof(VkDrawIndexedIndirectCommand));

// Or with count buffer (drawCount is itself on GPU)
vkCmdDrawIndexedIndirectCount(cmd, indirectBuf, 0,
                              countBuf, 0, /*maxDraws*/ N,
                              sizeof(VkDrawIndexedIndirectCommand));

Three.js (R175+ has WebGPU)

import { WebGPURenderer, BatchedMesh } from 'three';
const renderer = new WebGPURenderer();
// BatchedMesh internally uses indirect draw + instancing
const batched = new BatchedMesh(maxInstances, maxVerts, maxIndices);
batched.addGeometry(geom1);
batched.addGeometry(geom2);
// One draw call, GPU handles per-instance state

Hi-Z Occlusion Culling (sketch)

// Sample Hi-Z mip — fastest mip where bounding sphere covers >1 texel
fn occluded(bsphere: vec4<f32>) -> bool {
  let screenRect = projectToScreen(bsphere);
  let mip = computeMip(screenRect);
  let depth = textureSampleLevel(hiZ, samp, screenRect.center, mip).r;
  return bsphereMinDepth(bsphere) > depth;
}

매 결정 기준

상황 Approach
<100 unique objects Direct draw / instancing — overhead 의 not worth
1k-1M instances Indirect draw + GPU cull
Many distinct meshes Multi-draw indirect (Vulkan/D3D12); WebGPU 의 batched
Foliage/crowd Indirect + GPU LOD selection
Mobile / low-end Direct draw (compute overhead 의 watch)

기본값: large dynamic scene 의 GPU-driven indirect pipeline. Small scene 의 direct draw.

🔗 Graph

🤖 LLM 활용

언제: GPU-driven pipeline 의 design, culling 의 implement, draw-call overhead 의 reduce. 언제 X: simple scene 의 indirect draw 의 over-engineering — direct 의 fine.

안티패턴

  • CPU readback of indirect buffer: 매 stall. GPU 의 self-contained 의 keep.
  • Per-frame full buffer rewrite: defeats purpose. 매 GPU compute 의 update.
  • No Hi-Z for occlusion: false positives — Hi-Z 또는 conservative AABB 의 사용.
  • Indirect for tiny scenes: compute dispatch overhead > savings.
  • WebGL fallback assumed: WebGL 의 no indirect draw — WebGPU required.

🧪 검증 / 중복

  • Verified (WebGPU spec, Vulkan spec, GPU Gems / Activision Nanite paper).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — indirect draw / GPU-driven rendering full content