Skip to content

Commit edfe67a

Browse files
committed
add exportable GPUShaderStage to WebGPUConstants
1 parent 2ddfcf0 commit edfe67a

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
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: 5 additions & 5 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

@@ -374,19 +374,19 @@ class WebGPUBindingUtils {
374374
const usage = GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST;
375375

376376
const visibilities = [];
377-
if ( binding.visibility & 1 ) {
377+
if ( binding.visibility & GPUShaderStage.VERTEX ) {
378378

379379
visibilities.push( 'vertex' );
380380

381381
}
382382

383-
if ( binding.visibility & 2 ) {
383+
if ( binding.visibility & GPUShaderStage.FRAGMENT ) {
384384

385385
visibilities.push( 'fragment' );
386386

387387
}
388388

389-
if ( binding.visibility & 4 ) {
389+
if ( binding.visibility & GPUShaderStage.COMPUTE ) {
390390

391391
visibilities.push( 'compute' );
392392

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)