Expand description
WaterDropEngine’s wde-wgpu crate is a lightweight layer over wgpu that keeps the
low-level power of WebGPU while offering opinionated building blocks for buffers,
textures, render/compute pipelines, and pass orchestration. All submodules are
re-exported at the crate root (e.g. wde_wgpu::buffer, wde_wgpu::command_buffer)
to keep imports short and examples consistent.
§Architecture
- Instance and surface:
instance::create_instanceproduces ainstance::RenderInstanceholding thewgpu::Device,Queue, and optionalSurface.instance::setup_surfacestores a [wgpu::SurfaceConfiguration] once the window size is known andinstance::resizereapplies it on swapchain loss or window resize. - Resources:
buffer::Bufferandtexture::Texturewrap GPU memory and add convenience copy helpers plus defaults for common usages (render targets, depth). - Pipelines:
render_pipeline::RenderPipelineandcompute_pipeline::ComputePipelinecompile WGSL source, build pipeline layouts (bind groups + push constants), and exposeis_initialized+ getters for the underlyingwgpuobjects. - Pass orchestration:
command_buffer::CommandBufferrecords GPU work. It spawnsrender_pass::RenderPassInstanceandcompute_pass::WComputePasswith guard rails that check for missing pipelines/buffers before issuing draws or dispatches. - Bind groups:
bind_grouphelps assemble layouts and bind groups that match WGSL declarations. - Vertex helpers:
vertex::Vertexprovides a canonical position/uv/normal layout and a ready-to-usewgpu::VertexBufferLayout.
§Core usage patterns
- Configure a surface once, then react to
instance::RenderEvent::Resizewithinstance::resize. - Build resources up-front (
Buffer,Texture), then stage per-frame uploads viabuffer::Buffer::writeorqueue.write_texturewrappers. - Keep pipeline creation deterministic: set shaders, bind group layouts, push constants,
then call
initand gate draws/dispatches onis_initialized. - Record work inside a
CommandBuffer; each render/compute pass enforces that required state (pipeline, vertex/index buffers) is set before issuing commands.
§Modules
instance: device, queue, surface, events, presentation helpers.buffer/texture: GPU buffers and 2D textures with helper views/samplers.render_pipeline/compute_pipeline: WGSL compilation + pipeline layout creation.render_pass/compute_pass/command_buffer: pass-level helpers with safety checks.bind_group: bind group layout builders and bind group creation.vertex: canonical vertex layout used across examples.
§Examples and further reading
- Minimal WGSL shaders live in
res/(seeres/examplesfor full scenes). - Bind group helpers sit in
bind_group; pair them with pipeline layouts for material or compute resource binding. - For GPU-driven draws, see indirect helpers on
render_pass::RenderPassInstance. - The examples under
res/examplesshow complete scenes; start withdisplay_texturefor a minimal textured quad.
Re-exports§
pub use instance::RenderInstanceData;pub use passes::command_buffer;pub use passes::compute_pass;pub use passes::render_pass;pub use pipelines::bind_group;pub use pipelines::compute_pipeline;pub use pipelines::render_pipeline;pub use resources::buffer;pub use resources::texture;pub use utils::vertex;