Skip to content

Return values of atomic* functions are not properly handled when pointerNode is a struct storage buffer #31100

@HongchengZhao

Description

@HongchengZhao

Description

There still exists some bugs with #30971, the return value of atomic* functions are not properly handled when pointerNode is a struct storage buffer. I find it has something to do with the pointerNode's type being void.

Reproduction steps

  1. See the code below

Code

const DrawIndirectInfo = struct(
    {
      vertexCount: "uint",
      instanceCount: { type: "uint", atomic: true },
      firstVertex: "uint",
      firstInstance: "uint",
      offset: "uint",
    },
    "DrawIndirectInfo"
  );
  
const indirect = new THREE.IndirectStorageBufferAttribute(new Uint32Array(5), 5);
const drawBuffer = storage(indirect, DrawIndirectInfo).label("drawBuffer");
const foo = instancedArray(1, "uint").toAtomic().label("foo");

const updateDrawBuffer = Fn(() => {
    If(instanceIndex.equal(0), () => {
        const count = atomicAdd(drawBuffer.get("instanceCount"), uint(1)).toConst("count");

        const bar = atomicAdd(foo.element(0), uint(1)).toConst("bar");
      });
 })().debug((builder, code) => console.log(code)).compute(1, [1]);

renderer.computeAsync(updateDrawBuffer);

Live example

Screenshots

Image

Version

176

Device

No response

Browser

No response

OS

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    TSLThree.js Shading Language

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions