Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/renderers/common/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2308,10 +2308,13 @@ class Renderer {
* if the renderer has been initialized.
*
* @param {Node|Array<Node>} computeNodes - The compute node(s).
* @param {Array<number>|number} [dispatchSizeOrCount=null] - Array with [ x, y, z ] values for dispatch or a single number for the count.
* @param {number|Array<number>|GPUBuffer} [dispatchSize=null]
* - A single number representing count, or
* - An array [x, y, z] representing dispatch size, or
* - A GPUBuffer for indirect dispatch size.
* @return {Promise|undefined} A Promise that resolve when the compute has finished. Only returned when the renderer has not been initialized.
*/
compute( computeNodes, dispatchSizeOrCount = null ) {
compute( computeNodes, dispatchSize = null ) {

if ( this._isDeviceLost === true ) return;

Expand Down Expand Up @@ -2390,7 +2393,7 @@ class Renderer {
const computeBindings = bindings.getForCompute( computeNode );
const computePipeline = pipelines.getForCompute( computeNode, computeBindings );

backend.compute( computeNodes, computeNode, computeBindings, computePipeline, dispatchSizeOrCount );
backend.compute( computeNodes, computeNode, computeBindings, computePipeline, dispatchSize );

}

Expand All @@ -2407,14 +2410,17 @@ class Renderer {
*
* @async
* @param {Node|Array<Node>} computeNodes - The compute node(s).
* @param {Array<number>|number} [dispatchSizeOrCount=null] - Array with [ x, y, z ] values for dispatch or a single number for the count.
* @param {number|Array<number>|GPUBuffer} [dispatchSize=null]
* - A single number representing count, or
* - An array [x, y, z] representing dispatch size, or
* - A GPUBuffer for indirect dispatch size.
* @return {Promise} A Promise that resolve when the compute has finished.
*/
async computeAsync( computeNodes, dispatchSizeOrCount = null ) {
async computeAsync( computeNodes, dispatchSize = null ) {

if ( this._initialized === false ) await this.init();

this.compute( computeNodes, dispatchSizeOrCount );
this.compute( computeNodes, dispatchSize );

}

Expand Down
31 changes: 20 additions & 11 deletions src/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -1317,9 +1317,12 @@ class WebGPUBackend extends Backend {
* @param {Node} computeNode - The compute node.
* @param {Array<BindGroup>} bindings - The bindings.
* @param {ComputePipeline} pipeline - The compute pipeline.
* @param {Array<number>|number} [dispatchSizeOrCount=null] - Array with [ x, y, z ] values for dispatch or a single number for the count.
* @param {number|Array<number>|GPUBuffer} [dispatchSize=null]
* - A single number representing count, or
* - An array [x, y, z] representing dispatch size, or
* - A GPUBuffer for indirect dispatch size.
*/
compute( computeGroup, computeNode, bindings, pipeline, dispatchSizeOrCount = null ) {
compute( computeGroup, computeNode, bindings, pipeline, dispatchSize = null ) {

const computeNodeData = this.get( computeNode );
const { passEncoderGPU } = this.get( computeGroup );
Expand All @@ -1341,19 +1344,29 @@ class WebGPUBackend extends Backend {

}

let dispatchSize;
if ( dispatchSize === null ) {

if ( dispatchSizeOrCount === null ) {
dispatchSize = computeNode.count;

dispatchSizeOrCount = computeNode.count;
}

// When the dispatchSize is set with a StorageBuffer from the GPU.

if ( dispatchSize && typeof dispatchSize === 'object' && dispatchSize.isIndirectStorageBufferAttribute ) {

const dispatchBuffer = this.get( dispatchSize ).buffer;

passEncoderGPU.dispatchWorkgroupsIndirect( dispatchBuffer, 0 );

return;

}

if ( typeof dispatchSizeOrCount === 'number' ) {
if ( typeof dispatchSize === 'number' ) {

// If a single number is given, we calculate the dispatch size based on the workgroup size

const count = dispatchSizeOrCount;
const count = dispatchSize;

if ( computeNodeData.dispatchSize === undefined || computeNodeData.count !== count ) {

Expand Down Expand Up @@ -1390,10 +1403,6 @@ class WebGPUBackend extends Backend {

dispatchSize = computeNodeData.dispatchSize;

} else {

dispatchSize = dispatchSizeOrCount;

}

//
Expand Down