#buffer #web-gpu #uniform #serialization #layout #member #vec4

serde_webgpu

Serialize WebGPU uniform buffer member layout

4 releases

0.2.1 Oct 25, 2023
0.2.0 Oct 24, 2023
0.1.1 Jun 4, 2023
0.1.0 Jun 3, 2023

#1794 in Encoding

MIT/Apache

23KB
624 lines

serde_webgpu

Serialize content to WebGPU.

#[derive(Serialize)]
struct Uniform {
    a: f16,
    b: mat4x4<f32>,
}

let uniform = Uniform {
    a: f16::from_f32(123.456),
    b: [
        vec4([1.0, 2.0, 3.0, 4.0]),
        vec4([4.0, 5.0, 7.0, 8.0]),
        vec4([1.0, 2.0, 3.0, 4.0]),
        vec4([5.0, 6.0, 7.0, 8.0]),
    ],
};

serialize_webgpu_buffer(&uniform).unwrap();

lib.rs:


#[derive(Serialize)]
struct Uniform {
    a: f16,
    b: mat4x4<f32>,
}

let uniform = Uniform {
    a: f16::from_f32(123.456),
    b: [
        vec4([1.0, 2.0, 3.0, 4.0]),
        vec4([4.0, 5.0, 7.0, 8.0]),
        vec4([1.0, 2.0, 3.0, 4.0]),
        vec4([5.0, 6.0, 7.0, 8.0]),
    ],
};

serialize_webgpu_buffer(&uniform).unwrap();

Dependencies

~0.6–1.2MB
~27K SLoC