Skip to content

Commit f9dced0

Browse files
authored
WebGPUBindingUtils - Buffer Labeling Adjustment (#32247)
1 parent 1d641e7 commit f9dced0

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

src/renderers/webgpu/nodes/WGSLNodeBuilder.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ import ExpressionNode from '../../../nodes/code/ExpressionNode.js';
1919
import { FloatType, RepeatWrapping, ClampToEdgeWrapping, MirroredRepeatWrapping, NearestFilter } from '../../../constants.js';
2020
import { warn, error } from '../../../utils.js';
2121

22-
// GPUShaderStage is not defined in browsers not supporting WebGPU
23-
const GPUShaderStage = ( typeof self !== 'undefined' ) ? self.GPUShaderStage : { VERTEX: 1, FRAGMENT: 2, COMPUTE: 4 };
22+
import { GPUShaderStage } from '../utils/WebGPUConstants.js';
2423

2524
const accessNames = {
2625
[ NodeAccess.READ_ONLY ]: 'read',
@@ -35,9 +34,9 @@ const wrapNames = {
3534
};
3635

3736
const gpuShaderStageLib = {
38-
'vertex': GPUShaderStage ? GPUShaderStage.VERTEX : 1,
39-
'fragment': GPUShaderStage ? GPUShaderStage.FRAGMENT : 2,
40-
'compute': GPUShaderStage ? GPUShaderStage.COMPUTE : 4
37+
'vertex': GPUShaderStage.VERTEX,
38+
'fragment': GPUShaderStage.FRAGMENT,
39+
'compute': GPUShaderStage.COMPUTE
4140
};
4241

4342
const supports = {

src/renderers/webgpu/utils/WebGPUBindingUtils.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
GPUTextureAspect, GPUTextureViewDimension, GPUTextureSampleType, GPUBufferBindingType, GPUStorageTextureAccess,
3-
GPUSamplerBindingType
3+
GPUSamplerBindingType, GPUShaderStage
44
} from './WebGPUConstants.js';
55

66
import { FloatType, IntType, UnsignedIntType } from '../../../constants.js';
@@ -70,7 +70,7 @@ class WebGPUBindingUtils {
7070

7171
if ( binding.isStorageBuffer ) {
7272

73-
if ( binding.visibility & 4 ) {
73+
if ( binding.visibility & GPUShaderStage.COMPUTE ) {
7474

7575
// compute
7676

@@ -373,8 +373,29 @@ class WebGPUBindingUtils {
373373

374374
const usage = GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST;
375375

376+
const visibilities = [];
377+
if ( binding.visibility & GPUShaderStage.VERTEX ) {
378+
379+
visibilities.push( 'vertex' );
380+
381+
}
382+
383+
if ( binding.visibility & GPUShaderStage.FRAGMENT ) {
384+
385+
visibilities.push( 'fragment' );
386+
387+
}
388+
389+
if ( binding.visibility & GPUShaderStage.COMPUTE ) {
390+
391+
visibilities.push( 'compute' );
392+
393+
}
394+
395+
const bufferVisibility = `(${visibilities.join( ',' )})`;
396+
376397
const bufferGPU = device.createBuffer( {
377-
label: 'bindingBuffer_' + binding.name,
398+
label: `bindingBuffer${binding.id}_${binding.name}_${bufferVisibility}`,
378399
size: byteLength,
379400
usage: usage
380401
} );

src/renderers/webgpu/utils/WebGPUConstants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export const GPUPrimitiveTopology = {
66
TriangleStrip: 'triangle-strip',
77
};
88

9+
export const GPUShaderStage = ( typeof self !== 'undefined' ) ? self.GPUShaderStage : { VERTEX: 1, FRAGMENT: 2, COMPUTE: 4 };
10+
911
export const GPUCompareFunction = {
1012
Never: 'never',
1113
Less: 'less',

0 commit comments

Comments
 (0)