I’m trying to use a wgslFn like
const computeShader = wgslFn(/* wgsl */`
struct SomeOtherData {
first: f32,
second: f32,
firstInt: i32,
secondInt: i32,
}
fn compute(
positionBuffer: ptr<storage, array<vec3<f32>>, read_write>,
velocitiesBuffer: ptr<storage, array<vec3<f32>>, read_write>,
otherData: ptr<storage, array<SomeOtherData>, read_write>,
index: u32,
deltaTime: f32,
gravity: vec3<f32>
) -> void {
// Use the otherData somehow
velocitiesBuffer[index] += gravity * deltaTime;
positionBuffer[index] += velocitiesBuffer[index] * deltaTime;
}
`);
const computeShaderParams = {
positionBuffer: positionsStorage,
velocitiesBuffer: velocitiesStorage,
otherData: otherDataStorage,
index: instanceIndex,
deltaTime: deltaTime,
gravity: gravity
}
const computePositions = computeShader(computeShaderParams).compute(positionBuffer.count);
Doing this gets the error
Uncaught Error: FunctionNode: Function is not a WGSL code.
This only happens when I have a struct definition in the wgslFn. I am unsure of how to have more interesting datatypes exist in a wgslFn.
Ideally I would like to move entirely away from using anything TSL (there is simply not enough documentation), but I am not sure of how to have a shared position buffer between ThreeJs and a webgpu object created like
const positionStorage= device.createBuffer({
label: "Vertex Positions",
size: positionArray.byteLength,
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST,
});
Any help with this would be much appreciated, or just pointing me to more extensive documentation than the examples (which all use pure TSL) or the github docs.