Skip to content
Merged
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
12 changes: 6 additions & 6 deletions src/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { GPUFeatureName, GPULoadOp, GPUStoreOp, GPUIndexFormat, GPUTextureViewDi
import WGSLNodeBuilder from './nodes/WGSLNodeBuilder.js';
import Backend from '../common/Backend.js';

import WebGPUUtils from './utils/WebGPUUtils.js';
import WebGPUUtils, { submit } from './utils/WebGPUUtils.js';
import WebGPUAttributeUtils from './utils/WebGPUAttributeUtils.js';
import WebGPUBindingUtils from './utils/WebGPUBindingUtils.js';
import WebGPUCapabilities from './utils/WebGPUCapabilities.js';
Expand Down Expand Up @@ -1105,7 +1105,7 @@ class WebGPUBackend extends Backend {

}

this.device.queue.submit( [ renderContextData.encoder.finish() ] );
submit( this.device, renderContextData.encoder.finish() );


//
Expand Down Expand Up @@ -1378,7 +1378,7 @@ class WebGPUBackend extends Backend {

currentPass.end();

device.queue.submit( [ encoder.finish() ] );
submit( device, encoder.finish() );

}

Expand Down Expand Up @@ -1525,7 +1525,7 @@ class WebGPUBackend extends Backend {

groupData.passEncoderGPU.end();

this.device.queue.submit( [ groupData.cmdEncoderGPU.finish() ] );
submit( this.device, groupData.cmdEncoderGPU.finish() );

}

Expand Down Expand Up @@ -2490,7 +2490,7 @@ class WebGPUBackend extends Backend {
]
);

this.device.queue.submit( [ encoder.finish() ] );
submit( this.device, encoder.finish() );

if ( dstLevel === 0 && dstTexture.generateMipmaps ) {

Expand Down Expand Up @@ -2616,7 +2616,7 @@ class WebGPUBackend extends Backend {

} else {

this.device.queue.submit( [ encoder.finish() ] );
submit( this.device, encoder.finish() );

}

Expand Down
3 changes: 2 additions & 1 deletion src/renderers/webgpu/utils/WebGPUAttributeUtils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GPUInputStepMode } from './WebGPUConstants.js';
import { submit } from './WebGPUUtils.js';

import { Float16BufferAttribute } from '../../../core/BufferAttribute.js';
import { isTypedArray, error } from '../../../utils.js';
Expand Down Expand Up @@ -418,7 +419,7 @@ class WebGPUAttributeUtils {
);

const gpuCommands = cmdEncoder.finish();
device.queue.submit( [ gpuCommands ] );
submit( device, gpuCommands );

// map the data to the CPU
await readBufferGPU.mapAsync( GPUMapMode.READ, 0, byteLength );
Expand Down
5 changes: 3 additions & 2 deletions src/renderers/webgpu/utils/WebGPUTexturePassUtils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import DataMap from '../../common/DataMap.js';
import { GPUFilterMode, GPULoadOp, GPUStoreOp } from './WebGPUConstants.js';
import { submit } from './WebGPUUtils.js';

/**
* A WebGPU backend utility module used by {@link WebGPUTextureUtils}.
Expand Down Expand Up @@ -259,7 +260,7 @@ fn main_cube( Varys: VarysStruct ) -> @location( 0 ) vec4<f32> {
pass( copyTransferPipeline, textureGPU, baseArrayLayer, tempTexture, 0, false );
pass( flipTransferPipeline, tempTexture, 0, textureGPU, baseArrayLayer, true );

this.device.queue.submit( [ commandEncoder.finish() ] );
submit( this.device, commandEncoder.finish() );

tempTexture.destroy();

Expand All @@ -281,7 +282,7 @@ fn main_cube( Varys: VarysStruct ) -> @location( 0 ) vec4<f32> {

this._mipmapRunBundles( commandEncoder, passes );

if ( encoder === null ) this.device.queue.submit( [ commandEncoder.finish() ] );
if ( encoder === null ) submit( this.device, commandEncoder.finish() );

textureData.layers = passes;

Expand Down
3 changes: 2 additions & 1 deletion src/renderers/webgpu/utils/WebGPUTextureUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
import { ColorManagement } from '../../../math/ColorManagement.js';

import WebGPUTexturePassUtils from './WebGPUTexturePassUtils.js';
import { submit } from './WebGPUUtils.js';

import {
ByteType, ShortType,
Expand Down Expand Up @@ -708,7 +709,7 @@ class WebGPUTextureUtils {

const typedArrayType = this._getTypedArrayType( format );

device.queue.submit( [ encoder.finish() ] );
submit( device, encoder.finish() );

await readBuffer.mapAsync( GPUMapMode.READ );

Expand Down
3 changes: 2 additions & 1 deletion src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { error, warnOnce } from '../../../utils.js';
import TimestampQueryPool from '../../common/TimestampQueryPool.js';
import { submit } from './WebGPUUtils.js';

/**
* Manages a pool of WebGPU timestamp queries for performance measurement.
Expand Down Expand Up @@ -155,7 +156,7 @@ class WebGPUTimestampQueryPool extends TimestampQueryPool {
);

const commandBuffer = commandEncoder.finish();
this.device.queue.submit( [ commandBuffer ] );
submit( this.device, commandBuffer );

if ( this.resultBuffer.mapState !== 'unmapped' ) {

Expand Down
20 changes: 20 additions & 0 deletions src/renderers/webgpu/utils/WebGPUUtils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { HalfFloatType, UnsignedByteType } from '../../../constants.js';
import { GPUPrimitiveTopology, GPUTextureFormat } from './WebGPUConstants.js';

const _commandList = [ null ];

/**
* A WebGPU backend utility module with common helpers.
*
Expand Down Expand Up @@ -266,4 +268,22 @@ class WebGPUUtils {

}

/**
* Submits a single GPU command to the device queue using a shared, module-scoped
* array to avoid per-call array allocations.
*
* @private
* @param {GPUDevice} device - The GPU device.
* @param {GPUCommandBuffer} command - The command buffer to submit.
*/
export function submit( device, command ) {

_commandList[ 0 ] = command;

device.queue.submit( _commandList );

_commandList[ 0 ] = null;

}

export default WebGPUUtils;
Loading