docs.rs failed to build minwebgpu-0.2.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build:
minwebgpu-0.1.0
⚡ minwebgpu
Modern WebGPU wrapper for next-generation web graphics
A safe, ergonomic Rust wrapper around WebGPU for high-performance graphics and compute in the browser. Built for the future of web graphics with compute shader support, modern rendering pipelines, and optimal WebAssembly integration.
✨ Features
🚀 Next-Gen Graphics
- WebGPU Native - Direct WebGPU API access with Rust safety
- Compute Shaders - GPU compute for parallel processing
- Modern Pipelines - Descriptor-based render and compute pipelines
- Memory Efficient - Optimal memory management and buffer operations
🛠️ Core Capabilities
- Render Pipelines - Advanced rendering with modern GPU features
- Compute Pipelines - Parallel computation on the GPU
- Buffer Management - Type-safe buffer operations and memory handling
- Texture Support - 2D/3D textures, cube maps, and texture arrays
- Shader Modules - WGSL shader compilation and validation
- Command Encoding - Efficient command buffer recording
🚀 Quick Start
Add to Your Project
[]
= { = true, = ["enabled"] }
= "0.2"
= "0.3"
Basic Setup
use minwebgpu as gpu;
use *;
pub async
Simple Triangle Render Pipeline
use minwebgpu as gpu;
// WGSL vertex shader
let vertex_shader = r#"
@vertex
fn vs_main(@location(0) position: vec2<f32>) -> @builtin(position) vec4<f32> {
return vec4<f32>(position, 0.0, 1.0);
}
"#;
// WGSL fragment shader
let fragment_shader = r#"
@fragment
fn fs_main() -> @location(0) vec4<f32> {
return vec4<f32>(1.0, 0.0, 0.0, 1.0);
}
"#;
// Create shader modules
let vs_module = create;
let fs_module = create;
// Create render pipeline
let pipeline = desc
.fragment
.primitive
.create?;
Compute Shader Example
use minwebgpu as gpu;
// WGSL compute shader
let compute_shader = r#"
@group(0) @binding(0) var<storage, read_write> data: array<f32>;
@compute @workgroup_size(64)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
let index = global_id.x;
if (index >= arrayLength(&data)) { return; }
data[index] = data[index] * 2.0;
}
"#;
// Create compute pipeline
let compute_module = create;
let compute_pipeline = desc.create?;
// Create storage buffer
let buffer = new.create?;
// Dispatch compute work
let mut encoder = device.create_command_encoder;
let mut compute_pass = encoder.begin_compute_pass;
compute_pass.set_pipeline;
compute_pass.set_bind_group;
compute_pass.dispatch_workgroups;
compute_pass.end;
📚 API Overview
| Module | Description | Key Types |
|---|---|---|
instance |
WebGPU instance and adapter | Instance, Adapter |
device |
Device and queue management | Device, Queue |
shader |
WGSL shader compilation | ShaderModule, create() |
buffer |
Buffer operations | Buffer, BufferInitDescriptor |
texture |
Texture management | Texture, TextureView, Sampler |
render_pipeline |
Render pipeline creation | RenderPipeline, desc() |
compute_pipeline |
Compute pipeline creation | ComputePipeline, desc() |
command |
Command encoding | CommandEncoder, RenderPass, ComputePass |
🎯 Key Concepts
Render Pipelines
WebGPU uses descriptor-based pipeline creation:
let pipeline = desc
.fragment
.primitive
.depth_stencil
.multisample
.create?;
Buffer Management
Type-safe buffer operations:
// Vertex buffer
let vertices: = ;
let vertex_buffer = new.create?;
// Uniform buffer
let uniforms = UniformData ;
let uniform_buffer = new.create?;
Bind Groups
Resource binding for shaders:
let bind_group_layout = device.create_bind_group_layout;
let bind_group = device.create_bind_group;
🎮 Examples
- Hello Triangle - Basic WebGPU triangle
- Deferred Rendering - Advanced lighting with WebGPU
- Compute Particles - GPU particle simulation
🔧 Advanced Features
Compute Shaders
// Parallel array processing
let compute_pipeline = desc.create?;
// Dispatch with workgroups
compute_pass.dispatch_workgroups;
Multi-Target Rendering
let pipeline = desc
.fragment
.create?;
Memory-Mapped Buffers
// Create mappable buffer
let buffer = device.create_buffer;
// Map and read data
let buffer_slice = buffer.slice;
buffer_slice.map_async.await?;
let data = buffer_slice.get_mapped_range;
// Process data...
buffer.unmap;
🛠️ Building
WebGPU requires modern browser support:
Browser Requirements
- Chrome/Edge: Version 94+
- Firefox: Version 110+ (behind flag)
- Safari: Version 16.4+
Build Commands
# Build for web
# Development with trunk
🤝 Contributing
Part of the CGTools workspace. Feel free to submit issues and pull requests on GitHub.
📄 License
MIT