Function makeShaderDataDefinitions

  • Given a WGSL shader, returns data definitions for structures, uniforms, and storage buffers

    Example:

    const code = `
    struct MyStruct {
    color: vec4f,
    brightness: f32,
    kernel: array<f32, 9>,
    };
    @group(0) @binding(0) var<uniform> myUniforms: MyUniforms;
    `;
    const defs = makeShaderDataDefinitions(code);
    const myUniformValues = makeStructuredView(defs.uniforms.myUniforms);

    myUniformValues.set({
    color: [1, 0, 1, 1],
    brightness: 0.8,
    kernel: [
    1, 0, -1,
    2, 0, -2,
    1, 0, -1,
    ],
    });
    device.queue.writeBuffer(uniformBuffer, 0, myUniformValues.arrayBuffer);

    Parameters

    • code: string

      WGSL shader. Note: it is not required for this to be a complete shader

    Returns ShaderDataDefinitions

    definitions of the structures by name. Useful for passing to makeStructuredView

Generated using TypeDoc