Skip to content

Commit ca16243

Browse files
mvaligurskyMartin Valigursky
and
Martin Valigursky
authored
Renamed internal class ShaderUtils to ShaderDefinitionUtils (#7652)
* Renamed internal class ShaderUtils to ShaderDefinitionUtils * comment --------- Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
1 parent 5f43b93 commit ca16243

File tree

9 files changed

+29
-29
lines changed

9 files changed

+29
-29
lines changed

src/platform/graphics/shader-utils.js renamed to src/platform/graphics/shader-definition-utils.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ const _attrib2Semantic = {
3737
};
3838

3939
/**
40-
* A class providing utility functions for shader creation.
40+
* A class providing utility functions for shader definition creation.
4141
*
4242
* @ignore
4343
*/
44-
class ShaderUtils {
44+
class ShaderDefinitionUtils {
4545
/**
4646
* Creates a shader definition.
4747
*
@@ -110,8 +110,8 @@ class ShaderUtils {
110110
let vertCode;
111111
let fragCode;
112112

113-
const vertexDefinesCode = ShaderUtils.getDefinesCode(device, options.vertexDefines);
114-
const fragmentDefinesCode = ShaderUtils.getDefinesCode(device, options.fragmentDefines);
113+
const vertexDefinesCode = ShaderDefinitionUtils.getDefinesCode(device, options.vertexDefines);
114+
const fragmentDefinesCode = ShaderDefinitionUtils.getDefinesCode(device, options.fragmentDefines);
115115
const wgsl = options.shaderLanguage === SHADERLANGUAGE_WGSL;
116116

117117
if (wgsl) {
@@ -133,22 +133,22 @@ class ShaderUtils {
133133
} else {
134134

135135
// vertex code
136-
vertCode = `${ShaderUtils.versionCode(device) +
136+
vertCode = `${ShaderDefinitionUtils.versionCode(device) +
137137
getDefines(webgpuVS, gles3VS, true, options) +
138138
vertexDefinesCode +
139-
ShaderUtils.precisionCode(device)}
139+
ShaderDefinitionUtils.precisionCode(device)}
140140
${sharedGLSL}
141-
${ShaderUtils.getShaderNameCode(name)}
141+
${ShaderDefinitionUtils.getShaderNameCode(name)}
142142
${options.vertexCode}`;
143143

144144
// fragment code
145145
fragCode = `${(options.fragmentPreamble || '') +
146-
ShaderUtils.versionCode(device) +
146+
ShaderDefinitionUtils.versionCode(device) +
147147
getDefines(webgpuFS, gles3FS, false, options) +
148148
fragmentDefinesCode +
149-
ShaderUtils.precisionCode(device)}
149+
ShaderDefinitionUtils.precisionCode(device)}
150150
${sharedGLSL}
151-
${ShaderUtils.getShaderNameCode(name)}
151+
${ShaderDefinitionUtils.getShaderNameCode(name)}
152152
${options.fragmentCode}`;
153153
}
154154

@@ -279,4 +279,4 @@ class ShaderUtils {
279279
}
280280
}
281281

282-
export { ShaderUtils };
282+
export { ShaderDefinitionUtils };

src/platform/graphics/shader.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { platform } from '../../core/platform.js';
44
import { Preprocessor } from '../../core/preprocessor.js';
55
import { SHADERLANGUAGE_GLSL, SHADERLANGUAGE_WGSL } from './constants.js';
66
import { DebugGraphics } from './debug-graphics.js';
7-
import { ShaderUtils } from './shader-utils.js';
7+
import { ShaderDefinitionUtils } from './shader-definition-utils.js';
88

99
/**
1010
* @import { BindGroupFormat } from './bind-group-format.js'
@@ -143,7 +143,7 @@ class Shader {
143143

144144
// if no attributes are specified, try to extract the default names after the shader has been pre-processed
145145
if (definition.shaderLanguage === SHADERLANGUAGE_GLSL) {
146-
definition.attributes ??= ShaderUtils.collectAttributes(definition.vshader);
146+
definition.attributes ??= ShaderDefinitionUtils.collectAttributes(definition.vshader);
147147
}
148148

149149
// Strip unused color attachments from fragment shader.

src/platform/graphics/transform-feedback.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { BUFFER_GPUDYNAMIC, PRIMITIVE_POINTS } from './constants.js';
33
import { VertexBuffer } from './vertex-buffer.js';
44
import { DebugGraphics } from './debug-graphics.js';
55
import { Shader } from './shader.js';
6-
import { ShaderUtils } from './shader-utils.js';
6+
import { ShaderDefinitionUtils } from './shader-definition-utils.js';
77

88
/**
99
* @import { GraphicsDevice } from './graphics-device.js'
@@ -120,7 +120,7 @@ class TransformFeedback {
120120
* @returns {Shader} A shader to use in the process() function.
121121
*/
122122
static createShader(graphicsDevice, vertexCode, name) {
123-
return new Shader(graphicsDevice, ShaderUtils.createDefinition(graphicsDevice, {
123+
return new Shader(graphicsDevice, ShaderDefinitionUtils.createDefinition(graphicsDevice, {
124124
name,
125125
vertexCode,
126126
useTransformFeedback: true,

src/scene/materials/shader-material.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { Material } from './material.js';
2323
* inputs to the shader. Defaults to undefined, which generates the default attributes.
2424
* @property {string | string[]} [fragmentOutputTypes] - Fragment shader output types, which default to
2525
* vec4. Passing a string will set the output type for all color attachments. Passing an array will
26-
* set the output type for each color attachment. @see ShaderUtils.createDefinition
26+
* set the output type for each color attachment. @see ShaderDefinitionUtils.createDefinition
2727
*/
2828

2929
/**

src/scene/shader-lib/programs/lit.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { LitShader } from './lit-shader.js';
22
import { LitOptionsUtils } from './lit-options-utils.js';
33
import { ShaderGenerator } from './shader-generator.js';
44
import { SHADERLANGUAGE_GLSL, SHADERLANGUAGE_WGSL, SHADERTAG_MATERIAL } from '../../../platform/graphics/constants.js';
5-
import { ShaderUtils } from '../../../platform/graphics/shader-utils.js';
5+
import { ShaderDefinitionUtils } from '../../../platform/graphics/shader-definition-utils.js';
66
import { hashCode } from '../../../core/hash.js';
77

88
/**
@@ -68,7 +68,7 @@ class ShaderGeneratorLit extends ShaderGenerator {
6868
definitionOptions.fragmentIncludes = includes;
6969
definitionOptions.fragmentDefines = fDefines;
7070

71-
return ShaderUtils.createDefinition(device, definitionOptions);
71+
return ShaderDefinitionUtils.createDefinition(device, definitionOptions);
7272
}
7373
}
7474

src/scene/shader-lib/programs/particle.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SEMANTIC_POSITION, SEMANTIC_TEXCOORD0, SHADERLANGUAGE_GLSL, SHADERLANGUAGE_WGSL } from '../../../platform/graphics/constants.js';
2-
import { ShaderUtils } from '../../../platform/graphics/shader-utils.js';
2+
import { ShaderDefinitionUtils } from '../../../platform/graphics/shader-definition-utils.js';
33
import { blendNames } from '../../constants.js';
44
import { shaderChunksWGSL } from '../chunks-wgsl/chunks-wgsl.js';
55
import { shaderChunks } from '../chunks/chunks.js';
@@ -81,7 +81,7 @@ class ShaderGeneratorParticle extends ShaderGenerator {
8181
...options.chunks
8282
}));
8383

84-
return ShaderUtils.createDefinition(device, {
84+
return ShaderDefinitionUtils.createDefinition(device, {
8585
name: 'ParticleShader',
8686
shaderLanguage: shaderLanguage,
8787
attributes: attributes,

src/scene/shader-lib/programs/shader-generator-shader.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { hashCode } from '../../../core/hash.js';
22
import { SEMANTIC_ATTR15, SEMANTIC_BLENDINDICES, SEMANTIC_BLENDWEIGHT, SHADERLANGUAGE_GLSL, SHADERLANGUAGE_WGSL } from '../../../platform/graphics/constants.js';
3-
import { ShaderUtils } from '../../../platform/graphics/shader-utils.js';
3+
import { ShaderDefinitionUtils } from '../../../platform/graphics/shader-definition-utils.js';
44
import { shaderChunksWGSL } from '../chunks-wgsl/chunks-wgsl.js';
55
import { shaderChunks } from '../chunks/chunks.js';
66
import { ShaderGenerator } from './shader-generator.js';
@@ -105,7 +105,7 @@ class ShaderGeneratorShader extends ShaderGenerator {
105105
this.createVertexDefinition(definitionOptions, options, sharedIncludes, wgsl);
106106
this.createFragmentDefinition(definitionOptions, options, sharedIncludes, wgsl);
107107

108-
return ShaderUtils.createDefinition(device, definitionOptions);
108+
return ShaderDefinitionUtils.createDefinition(device, definitionOptions);
109109
}
110110
}
111111

src/scene/shader-lib/programs/standard.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ChunkUtils } from '../chunk-utils.js';
1010
import { StandardMaterialOptions } from '../../materials/standard-material-options.js';
1111
import { LitOptionsUtils } from './lit-options-utils.js';
1212
import { ShaderGenerator } from './shader-generator.js';
13-
import { ShaderUtils } from '../../../platform/graphics/shader-utils.js';
13+
import { ShaderDefinitionUtils } from '../../../platform/graphics/shader-definition-utils.js';
1414
import { SHADERLANGUAGE_GLSL, SHADERLANGUAGE_WGSL, SHADERTAG_MATERIAL } from '../../../platform/graphics/constants.js';
1515

1616
/**
@@ -445,7 +445,7 @@ class ShaderGeneratorStandard extends ShaderGenerator {
445445

446446
options.defines.forEach((value, key) => fDefines.set(key, value));
447447

448-
const definition = ShaderUtils.createDefinition(device, {
448+
const definition = ShaderDefinitionUtils.createDefinition(device, {
449449
name: 'StandardShader',
450450
attributes: litShader.attributes,
451451
shaderLanguage: shaderLanguage,

src/scene/shader-lib/utils.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Shader } from '../../platform/graphics/shader.js';
2-
import { ShaderUtils } from '../../platform/graphics/shader-utils.js';
2+
import { ShaderDefinitionUtils } from '../../platform/graphics/shader-definition-utils.js';
33
import { shaderChunks } from './chunks/chunks.js';
44
import { getProgramLibrary } from './get-program-library.js';
55
import { Debug } from '../../core/debug.js';
@@ -28,7 +28,7 @@ import { ShaderPass } from '../shader-pass.js';
2828
* @param {string | string[]} [shaderDefinitionOptions.fragmentOutputTypes] - Fragment shader
2929
* output types, which default to vec4. Passing a string will set the output type for all color
3030
* attachments. Passing an array will set the output type for each color attachment.
31-
* @see ShaderUtils.createDefinition
31+
* @see ShaderDefinitionUtils.createDefinition
3232
* @returns {Shader} The newly created shader.
3333
* @category Graphics
3434
*/
@@ -44,7 +44,7 @@ function createShader(device, vsName, fsName, useTransformFeedback = false, shad
4444
};
4545
}
4646

47-
return new Shader(device, ShaderUtils.createDefinition(device, {
47+
return new Shader(device, ShaderDefinitionUtils.createDefinition(device, {
4848
...shaderDefinitionOptions,
4949
name: `${vsName}_${fsName}`,
5050
vertexCode: shaderChunks[vsName],
@@ -75,7 +75,7 @@ function createShader(device, vsName, fsName, useTransformFeedback = false, shad
7575
* @param {string | string[]} [shaderDefinitionOptions.fragmentOutputTypes] - Fragment shader
7676
* output types, which default to vec4. Passing a string will set the output type for all color
7777
* attachments. Passing an array will set the output type for each color attachment.
78-
* @see ShaderUtils.createDefinition
78+
* @see ShaderDefinitionUtils.createDefinition
7979
* @returns {Shader} The newly created shader.
8080
* @category Graphics
8181
*/
@@ -97,7 +97,7 @@ function createShaderFromCode(device, vsCode, fsCode, uniqueName, attributes, us
9797
const programLibrary = getProgramLibrary(device);
9898
let shader = programLibrary.getCachedShader(uniqueName);
9999
if (!shader) {
100-
shader = new Shader(device, ShaderUtils.createDefinition(device, {
100+
shader = new Shader(device, ShaderDefinitionUtils.createDefinition(device, {
101101
...shaderDefinitionOptions,
102102
name: uniqueName,
103103
vertexCode: vsCode,

0 commit comments

Comments
 (0)