TSL Compute read / write

Reading/Writing Multiple Entries from InstanceArrays in TSL Compute Shaders

Hi everyone,

In TSL and compute system I have a question about accessing multiple entries from instanceArrays within both compute shaders and mesh shaders.

What I’m trying to achieve:

I’d like to read and write multiple consecutive entries from an instanceArray buffer for each instance, rather than just a single entry per instance.

Specific use cases:

1. In Computes :

javascript

// Reading multiple entries
const datValue0 = positionBuffer.element(instanceIndex).toVar();
const datValue1 = positionBuffer.element(instanceIndex + 1).toVar();

// Writing to multiple entries
positionBuffer.element(instanceIndex).assign(someValue);
positionBuffer.element(instanceIndex + 1).assign(anotherValue);

2. In Mesh Shaders (vertex/fragment):

javascript

// Reading multiple entries for rendering
const datValue0 = positionBuffer.element(instanceIndex).toVar();
const datValue1 = positionBuffer.element(instanceIndex + 1).toVar();

Is this pattern supported?
Can I safely read/write multiple consecutive buffer entries in a compute using instanceIndex + offset for example? I’ve red a few things about atomics is that related ?

In GPGPU with textures, obviously you cannot write multiples values at different indexes, but I could read multiples in both the simulation and the actual rendering, since a pixel is an index with a texture fetch, is that somehow possible to read multiples values with the current setup ?

1 Like