How to use StorageBufferAttribute as a input to wgslFn?

@sunag

I want to use wgslFn instead of Fn to do some work on the position attribute. Here’s my code.

const positionBaseAttribute = geometry.attributes.position;

const positionStorageBufferAttribute = new TSL.StorageBufferAttribute( positionBaseAttribute.count, 4 );

const positionStorageAttribute = storage( positionStorageBufferAttribute, 'vec4', positionStorageBufferAttribute.count );

let computeNode = wgslFn(`
        fn doWork(v: array<vec4<f32>,${positionBaseAttribute.count}> ) -> array<vec4<f32>>{
          ...
          return v;
        }
        `)({v:positionStorageAttribute}).compute(positionBaseAttribute.count)


await renderer.computeAsync( computeNode );

const outArray = new Float32Array( await renderer.getArrayBufferAsync( positionStorageBufferAttribute ) );

It looks like the wgsl has a limit to the size of an array I can input. This is the error i get:

Error while parsing WGSL: :22:16 error: array count (3780060) must be less than 65536
fn doWork ( v: array<vec4<f32>,3780060> ) -> array<vec4<f32>>{
               ^^^^^^^^^^^^^^^^^^^^^^^^

:22:13 note: while instantiating parameter v
fn doWork ( v: array<vec4<f32>,3780060> ) -> array<vec4<f32>>{
            ^


 - While validating [ShaderModuleDescriptor "compute"]
 - While calling [Device].CreateShaderModule([ShaderModuleDescriptor "compute"]).

@miguelmyers8 Sorry for the delay, we have implemented pointer for use of array in wgslFn.

1 Like

I think I have exactly what you are looking for as an example in codePen

I was also moved by the topic at the beginning of October

1 Like