wde_wgpu/
lib.rs

1//! WaterDropEngine's `wde-wgpu` crate is a lightweight layer over `wgpu` that keeps the
2//! low-level power of WebGPU while offering opinionated building blocks for buffers,
3//! textures, render/compute pipelines, and pass orchestration. All submodules are
4//! re-exported at the crate root (e.g. `wde_wgpu::buffer`, `wde_wgpu::command_buffer`)
5//! to keep imports short and examples consistent.
6//!
7//! # Architecture
8//! - **Instance and surface**: [`instance::create_instance`] produces a `instance::RenderInstance`
9//!   holding the `wgpu::Device`, `Queue`, and optional `Surface`. [`instance::setup_surface`] stores
10//!   a [`wgpu::SurfaceConfiguration`] once the window size is known and [`instance::resize`]
11//!   reapplies it on swapchain loss or window resize.
12//! - **Resources**: [`buffer::Buffer`] and [`texture::Texture`] wrap GPU memory and add
13//!   convenience copy helpers plus defaults for common usages (render targets, depth).
14//! - **Pipelines**: [`render_pipeline::RenderPipeline`] and [`compute_pipeline::ComputePipeline`]
15//!   compile WGSL source, build pipeline layouts (bind groups + push constants), and expose
16//!   `is_initialized` + getters for the underlying `wgpu` objects.
17//! - **Pass orchestration**: [`command_buffer::CommandBuffer`] records GPU work. It spawns
18//!   [`render_pass::RenderPassInstance`] and [`compute_pass::WComputePass`] with guard rails that
19//!   check for missing pipelines/buffers before issuing draws or dispatches.
20//! - **Bind groups**: [`bind_group`] helps assemble layouts and bind groups that match WGSL
21//!   declarations.
22//! - **Vertex helpers**: [`vertex::Vertex`] provides a canonical position/uv/normal layout
23//!   and a ready-to-use `wgpu::VertexBufferLayout`.
24//!
25//! # Core usage patterns
26//! - Configure a surface once, then react to [`instance::RenderEvent::Resize`] with [`instance::resize`].
27//! - Build resources up-front (`Buffer`, `Texture`), then stage per-frame uploads via
28//!   [`buffer::Buffer::write`] or `queue.write_texture` wrappers.
29//! - Keep pipeline creation deterministic: set shaders, bind group layouts, push constants,
30//!   then call `init` and gate draws/dispatches on `is_initialized`.
31//! - Record work inside a `CommandBuffer`; each render/compute pass enforces that required
32//!   state (pipeline, vertex/index buffers) is set before issuing commands.
33//!
34//! # Modules
35//! - [`instance`]: device, queue, surface, events, presentation helpers.
36//! - [`buffer`] / [`texture`]: GPU buffers and 2D textures with helper views/samplers.
37//! - [`render_pipeline`] / [`compute_pipeline`]: WGSL compilation + pipeline layout creation.
38//! - [`render_pass`] / [`compute_pass`] / [`command_buffer`]: pass-level helpers with safety checks.
39//! - [`bind_group`]: bind group layout builders and bind group creation.
40//! - [`vertex`]: canonical vertex layout used across examples.
41//!
42//! # Examples and further reading
43//! - Minimal WGSL shaders live in `res/` (see `res/examples` for full scenes).
44//! - Bind group helpers sit in [`bind_group`]; pair them with pipeline layouts for material
45//!   or compute resource binding.
46//! - For GPU-driven draws, see indirect helpers on [`render_pass::RenderPassInstance`].
47//! - The examples under `res/examples` show complete scenes; start with `display_texture` for
48//!   a minimal textured quad.
49pub mod instance;
50pub mod passes;
51pub mod pipelines;
52pub mod resources;
53pub mod utils;
54
55// Re-exports to provide `wde_wgpu::buffer`, `wde_wgpu::command_buffer`, etc.
56pub use instance::RenderInstanceData;
57pub use passes::{command_buffer, compute_pass, render_pass};
58pub use pipelines::{bind_group, compute_pipeline, render_pipeline};
59pub use resources::{buffer, texture};
60pub use utils::vertex;