Skip to content

WebGPUBackend - Cannot use Compute Indirect Unless Buffer is in Compute Function. #32168

@cmhhelgeson

Description

@cmhhelgeson

Related issue: #31488

Description

Passing only an indirect buffer without accessing the buffer in a compute function produces this error.

Image

Likely because this code in WebGPUBackend.js doesn't have a fallback condition when dispatchBuffer returns undefined.

Although indirect compute is most useful when the number of workgroups is defined by the GPU, I think for the sake of correctness we should still be able to create a minimum viable example where the indirect buffer is used without being modified.

// Line 1381 - 1389 of Renderer.js

if ( dispatchSize && typeof dispatchSize === 'object' && dispatchSize.isIndirectStorageBufferAttribute ) {
	const dispatchBuffer = this.get( dispatchSize ).buffer;
	passEncoderGPU.dispatchWorkgroupsIndirect( dispatchBuffer, 0 );
	return;
}

Reproduction steps

  1. On webgpu_compute_particles rain, at the top of the file, create an IndirectStorageBufferAttribute with the requisite number of workgroups to calculate the initial number of renderer rain particles.
const maxParticleCount = 50000;
const workgroupSize = 64;
const instanceCount = maxParticleCount / 2;
const startNumWorkgroups = Math.ceil( instanceCount / workgroupSize );

const workgroupGridIndirectBuffer = new THREE.IndirectStorageBufferAttribute( new Uint32Array( [ startNumWorkgroups, 1, 1 ]), 1 );
  1. Modify computeParticles to account for the fact that the dispatchSize will be determined by a combination of the workgroupSize and the indirectBuffer rather than the count.
// count not taken into consideration when buffer is indirect
computeParticles = computeUpdate().compute( null, [ 64, 1, 1 ] ).setName( 'Particles' );
  1. Modify the computeParticles call in the animation loop.
renderer.compute( computeParticles, workgroupGridIndirectBuffer );

Code

Seen above.

Live example

WebGPU Example

Screenshots

No response

Version

r181

Device

Desktop

Browser

Chrome

OS

Windows

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions