Skip to content

B5: Add GPU-driven rendering with draw indirect#42

Merged
stainlu merged 1 commit into
mainfrom
v4-b5-gpu-driven
Mar 21, 2026
Merged

B5: Add GPU-driven rendering with draw indirect#42
stainlu merged 1 commit into
mainfrom
v4-b5-gpu-driven

Conversation

@stainlu
Copy link
Copy Markdown
Owner

@stainlu stainlu commented Mar 21, 2026

Summary

  • Add WGSL compute shader (gpu_cull.wgsl) that performs per-entity frustum culling and LOD selection on the GPU, outputting DrawIndexedIndirect arguments
  • Add GpuDrivenPipeline struct managing all GPU buffers (command upload, frustum data, indirect draw output, atomic draw count) and providing cull_and_prepare() / draw_indirect() methods
  • Add IndirectDrawBuffer and DrawCommandGpu types with exact GPU struct layout matching (verified by 8 tests including bytemuck round-trips and size assertions)

Design

One compute dispatch replaces CPU frustum culling + draw-call submission. Each entity gets a fixed slot in the indirect buffer; culled entities get index_count = 0 (zero-cost no-op). LOD selection uses squared-distance thresholds (up to 4 levels per entity). The atomic draw_count buffer tracks visible entities for optional multi-draw-indirect-count support.

Test plan

  • draw_command_gpu_layout -- verifies 184-byte struct size and field offsets via bytemuck
  • indirect_args_layout -- verifies 20-byte DrawIndexedIndirect matches wgpu layout
  • frustum_data_layout_and_construction -- 112-byte uniform, from_frustum() correctness
  • cull_params_layout -- 16-byte aligned uniform buffer
  • gpu_cull_shader_is_valid_wgsl -- shader source contains all expected constructs
  • workgroup_count_rounding -- verifies ceil division for dispatch sizing
  • indirect_buffer_size_calculation -- size constant matches struct size
  • draw_command_gpu_zeroed -- bytemuck Zeroable produces all-zero fields

🤖 Generated with Claude Code

Implement a GPU-driven rendering pipeline that replaces per-entity CPU
frustum culling and draw-call submission with a single compute dispatch.

- Add gpu_cull.wgsl compute shader: per-entity frustum culling, LOD
  selection based on camera distance, and DrawIndexedIndirect argument
  generation with atomic visible-count tracking
- Add GpuDrivenPipeline struct: manages GPU buffers for command upload,
  frustum data, cull parameters, indirect draw output, and draw count
- Add IndirectDrawBuffer: STORAGE|INDIRECT buffer of DrawIndexedIndirect
  structs consumed by draw_indexed_indirect
- Add DrawCommandGpu: CPU-side struct mirroring the WGSL layout with
  model matrix, AABB, mesh/material IDs, and up to 4 LOD levels
- Add 8 tests covering struct layouts, shader validity, bytemuck
  round-trips, frustum data construction, and workgroup count rounding

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying euca-engine with  Cloudflare Pages  Cloudflare Pages

Latest commit: e347556
Status: ✅  Deploy successful!
Preview URL: https://4a350dd5.euca-engine.pages.dev
Branch Preview URL: https://v4-b5-gpu-driven.euca-engine.pages.dev

View logs

@stainlu stainlu merged commit 452112e into main Mar 21, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant