Skip to content

Instantly share code, notes, and snippets.

@chromy
Created October 14, 2023 07:50
Show Gist options
  • Save chromy/06e9648d06a9cbe7eac93485aebb00b5 to your computer and use it in GitHub Desktop.
Save chromy/06e9648d06a9cbe7eac93485aebb00b5 to your computer and use it in GitHub Desktop.
import {wgsl, linkBundle, bindBundle, extractBindings, bundleToAttributes} from "@use-gpu/shader/wgsl";
const bundle = bindBundle(wgsl`
struct VertexOut {
@builtin(position) position : vec4f,
@location(0) color : vec4f
}
struct Uniforms {
modelViewProjectionMatrix : mat4x4<f32>,
}
@group(0) @binding(0) var<uniform> uniforms : Uniforms;
@vertex
fn main(
@builtin(instance_index) instanceIdx : u32,
@location(0) position: vec4f) -> VertexOut {
var output : VertexOut;
output.position = position;
output.position.x += f32(instanceIdx);
output.position = uniforms.modelViewProjectionMatrix * output.position;
output.color = vec4f(0.0, 0.0, 0.1 * f32(instanceIdx+1), 1.0);
return output;
}
`);
console.log("linked:", linkBundle(bundle));
// Crashes at
// > for (const d of externals) if (d.func ?? d.variable) {
// https://gitlab.com/unconed/use.gpu/-/blob/master/packages/shader/src/util/bundle.ts#L108
console.log("attributes:", bundleToAttributes(bundle));
// I also tried this and variants:
// console.log("bindings", extractBindings([[vertexMod], [fragMod]], "0"));
// tsc --module nodenext --target es2022 extract_bindings.ts && node extract_bindings.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment