Get the latest tech news

Testing WebGPU data layouts with Facet


rking on GPU compute shaders, it's common to want to share snippets of configuration data between the host and the shader. Here's a toy example, adapted from fidget-wgpu: // WGSL struct Config { /// Screen-to-model transform matrix mat: mat3x3f, /// Image size, in pixels image_size: vec2u, /// Z position at which to render the image z: f32, } // Rust #[derive( zerocopy::IntoBytes, zerocopy::Immutable, zerocopy::FromBytes, zerocopy::KnownLayout )] #[repr(C)] struct Config { mat: [[f32; 3]; 3], image_size: [u32; 2], z: f32, } Thanks to the zerocopy annotations, we can call as_bytes() and write the configuration data directly into a WebGPU buffer, which is very convenient! Unfortunately, there are often subtle difference between Rust and WebGPU's layout rules.

None

Get the Android app

Or read this on Hacker News

Read more on:

Photo of webgpu

webgpu

Photo of data layouts

data layouts

Photo of Facet

Facet

Related news:

News photo

Modder gets Nvidia's DLSS 5 working in a web browser using WebGPU — 147MB browser port runs on non-Nvidia GPUs and macOS but takes two seconds per render

News photo

27.5KB language-agnostic WebGPU syntax highlighter

News photo

Show HN: Galaxium, an experimental WebGPU space explorer