Skip to content

Commit 8ebbd0a

Browse files
authored
WebGPURenderer: Clean up. (#33305)
1 parent 707fc18 commit 8ebbd0a

4 files changed

Lines changed: 29 additions & 27 deletions

File tree

src/renderers/webgl-fallback/utils/WebGLTextureUtils.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,13 @@ class WebGLTextureUtils {
174174

175175
}
176176

177-
let ext_texture_norm16;
177+
let extTextureNorm16 = null;
178178

179179
if ( normalized ) {
180180

181-
ext_texture_norm16 = extensions.get( 'EXT_texture_norm16' );
181+
extTextureNorm16 = extensions.get( 'EXT_texture_norm16' );
182182

183-
if ( ! ext_texture_norm16 ) {
183+
if ( ! extTextureNorm16 ) {
184184

185185
warn( 'WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension' );
186186

@@ -196,8 +196,8 @@ class WebGLTextureUtils {
196196
if ( glType === gl.HALF_FLOAT ) internalFormat = gl.R16F;
197197
if ( glType === gl.UNSIGNED_BYTE ) internalFormat = gl.R8;
198198
if ( glType === gl.BYTE ) internalFormat = gl.R8_SNORM;
199-
if ( glType === gl.UNSIGNED_SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.R16_EXT;
200-
if ( glType === gl.SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.R16_SNORM_EXT;
199+
if ( glType === gl.UNSIGNED_SHORT && extTextureNorm16 ) internalFormat = extTextureNorm16.R16_EXT;
200+
if ( glType === gl.SHORT && extTextureNorm16 ) internalFormat = extTextureNorm16.R16_SNORM_EXT;
201201

202202
}
203203

@@ -218,8 +218,8 @@ class WebGLTextureUtils {
218218
if ( glType === gl.HALF_FLOAT ) internalFormat = gl.RG16F;
219219
if ( glType === gl.UNSIGNED_BYTE ) internalFormat = gl.RG8;
220220
if ( glType === gl.BYTE ) internalFormat = gl.RG8_SNORM;
221-
if ( glType === gl.UNSIGNED_SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RG16_EXT;
222-
if ( glType === gl.SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RG16_SNORM_EXT;
221+
if ( glType === gl.UNSIGNED_SHORT && extTextureNorm16 ) internalFormat = extTextureNorm16.RG16_EXT;
222+
if ( glType === gl.SHORT && extTextureNorm16 ) internalFormat = extTextureNorm16.RG16_SNORM_EXT;
223223

224224
}
225225

@@ -242,8 +242,8 @@ class WebGLTextureUtils {
242242
if ( glType === gl.HALF_FLOAT ) internalFormat = gl.RGB16F;
243243
if ( glType === gl.UNSIGNED_BYTE ) internalFormat = ( transfer === SRGBTransfer ) ? gl.SRGB8 : gl.RGB8;
244244
if ( glType === gl.BYTE ) internalFormat = gl.RGB8_SNORM;
245-
if ( glType === gl.UNSIGNED_SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RGB16_EXT;
246-
if ( glType === gl.SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RGB16_SNORM_EXT;
245+
if ( glType === gl.UNSIGNED_SHORT && extTextureNorm16 ) internalFormat = extTextureNorm16.RGB16_EXT;
246+
if ( glType === gl.SHORT && extTextureNorm16 ) internalFormat = extTextureNorm16.RGB16_SNORM_EXT;
247247
if ( glType === gl.UNSIGNED_SHORT_5_6_5 ) internalFormat = gl.RGB565;
248248
if ( glType === gl.UNSIGNED_SHORT_5_5_5_1 ) internalFormat = gl.RGB5_A1;
249249
if ( glType === gl.UNSIGNED_SHORT_4_4_4_4 ) internalFormat = gl.RGB4;
@@ -271,8 +271,8 @@ class WebGLTextureUtils {
271271
if ( glType === gl.HALF_FLOAT ) internalFormat = gl.RGBA16F;
272272
if ( glType === gl.UNSIGNED_BYTE ) internalFormat = ( transfer === SRGBTransfer ) ? gl.SRGB8_ALPHA8 : gl.RGBA8;
273273
if ( glType === gl.BYTE ) internalFormat = gl.RGBA8_SNORM;
274-
if ( glType === gl.UNSIGNED_SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RGBA16_EXT;
275-
if ( glType === gl.SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RGBA16_SNORM_EXT;
274+
if ( glType === gl.UNSIGNED_SHORT && extTextureNorm16 ) internalFormat = extTextureNorm16.RGBA16_EXT;
275+
if ( glType === gl.SHORT && extTextureNorm16 ) internalFormat = extTextureNorm16.RGBA16_SNORM_EXT;
276276
if ( glType === gl.UNSIGNED_SHORT_4_4_4_4 ) internalFormat = gl.RGBA4;
277277
if ( glType === gl.UNSIGNED_SHORT_5_5_5_1 ) internalFormat = gl.RGB5_A1;
278278

src/renderers/webgpu/nodes/WGSLNodeBuilder.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,6 +1876,7 @@ ${ flowData.code }
18761876
*/
18771877
getUniforms( shaderStage ) {
18781878

1879+
const backend = this.renderer.backend;
18791880
const uniforms = this.uniforms[ shaderStage ];
18801881

18811882
const bindingSnippets = [];
@@ -1913,7 +1914,7 @@ ${ flowData.code }
19131914

19141915
let multisampled = '';
19151916

1916-
const { primarySamples } = this.renderer.backend.utils.getTextureSampleData( texture );
1917+
const { primarySamples } = backend.utils.getTextureSampleData( texture );
19171918

19181919
if ( primarySamples > 1 ) {
19191920

@@ -1931,7 +1932,7 @@ ${ flowData.code }
19311932

19321933
} else if ( texture.isDepthTexture === true ) {
19331934

1934-
if ( this.renderer.backend.compatibilityMode && texture.compareFunction === null ) {
1935+
if ( backend.compatibilityMode && texture.compareFunction === null ) {
19351936

19361937
textureType = `texture${ multisampled }_2d<f32>`;
19371938

@@ -1943,7 +1944,7 @@ ${ flowData.code }
19431944

19441945
} else if ( uniform.node.isStorageTextureNode === true ) {
19451946

1946-
const format = getFormat( texture );
1947+
const format = getFormat( texture, backend.device );
19471948
const access = this.getStorageAccess( uniform.node, shaderStage );
19481949

19491950
const is3D = uniform.node.value.is3DTexture;

src/renderers/webgpu/utils/WebGPUConstants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ export const GPUTextureFormat = {
116116
BGRA8UnormSRGB: 'bgra8unorm-srgb',
117117
RG16Unorm: 'rg16unorm',
118118
RG16Snorm: 'rg16snorm',
119+
119120
// Packed 32-bit formats
121+
120122
RGB9E5UFloat: 'rgb9e5ufloat',
121123
RGB10A2Unorm: 'rgb10a2unorm',
122124
RG11B10UFloat: 'rg11b10ufloat',

src/renderers/webgpu/utils/WebGPUTextureUtils.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class WebGPUTextureUtils {
198198

199199
let textureGPU;
200200

201-
const format = getFormat( texture );
201+
const format = getFormat( texture, this.backend.device );
202202

203203
if ( texture.isCubeTexture ) {
204204

@@ -1213,11 +1213,10 @@ class WebGPUTextureUtils {
12131213
* Returns the GPU format for the given texture.
12141214
*
12151215
* @param {Texture} texture - The texture.
1216-
* @param {?GPUDevice} [device=null] - The GPU device which is used for feature detection.
1217-
* It is not necessary to apply the device for most formats.
1216+
* @param {GPUDevice} [device] - The GPU device which is used for feature detection.
12181217
* @return {string} The GPU format.
12191218
*/
1220-
export function getFormat( texture, device = null ) {
1219+
export function getFormat( texture, device ) {
12211220

12221221
const format = texture.format;
12231222
const type = texture.type;
@@ -1227,13 +1226,13 @@ export function getFormat( texture, device = null ) {
12271226

12281227
let formatGPU;
12291228

1230-
let texture_formats_tier1;
1229+
let textureFormatsTier1 = false;
12311230

12321231
if ( normalized ) {
12331232

1234-
texture_formats_tier1 = device && device.features.has( GPUFeatureName.TextureFormatsTier1 );
1233+
textureFormatsTier1 = device.features.has( GPUFeatureName.TextureFormatsTier1 );
12351234

1236-
if ( texture_formats_tier1 === false ) {
1235+
if ( textureFormatsTier1 === false ) {
12371236

12381237
warn( 'WebGPURenderer: Unable to use normalized textures without texture-formats-tier1 feature.' );
12391238

@@ -1381,11 +1380,11 @@ export function getFormat( texture, device = null ) {
13811380
break;
13821381

13831382
case ShortType:
1384-
formatGPU = texture_formats_tier1 ? GPUTextureFormat.RGBA16Snorm : GPUTextureFormat.RGBA16Sint;
1383+
formatGPU = textureFormatsTier1 ? GPUTextureFormat.RGBA16Snorm : GPUTextureFormat.RGBA16Sint;
13851384
break;
13861385

13871386
case UnsignedShortType:
1388-
formatGPU = texture_formats_tier1 ? GPUTextureFormat.RGBA16Unorm : GPUTextureFormat.RGBA16Uint;
1387+
formatGPU = textureFormatsTier1 ? GPUTextureFormat.RGBA16Unorm : GPUTextureFormat.RGBA16Uint;
13891388
break;
13901389

13911390
case UnsignedIntType:
@@ -1443,11 +1442,11 @@ export function getFormat( texture, device = null ) {
14431442
break;
14441443

14451444
case ShortType:
1446-
formatGPU = texture_formats_tier1 ? GPUTextureFormat.R16Snorm : GPUTextureFormat.R16Sint;
1445+
formatGPU = textureFormatsTier1 ? GPUTextureFormat.R16Snorm : GPUTextureFormat.R16Sint;
14471446
break;
14481447

14491448
case UnsignedShortType:
1450-
formatGPU = texture_formats_tier1 ? GPUTextureFormat.R16Unorm : GPUTextureFormat.R16Uint;
1449+
formatGPU = textureFormatsTier1 ? GPUTextureFormat.R16Unorm : GPUTextureFormat.R16Uint;
14511450
break;
14521451

14531452
case UnsignedIntType:
@@ -1486,11 +1485,11 @@ export function getFormat( texture, device = null ) {
14861485
break;
14871486

14881487
case ShortType:
1489-
formatGPU = texture_formats_tier1 ? GPUTextureFormat.RG16Snorm : GPUTextureFormat.RG16Sint;
1488+
formatGPU = textureFormatsTier1 ? GPUTextureFormat.RG16Snorm : GPUTextureFormat.RG16Sint;
14901489
break;
14911490

14921491
case UnsignedShortType:
1493-
formatGPU = texture_formats_tier1 ? GPUTextureFormat.RG16Unorm : GPUTextureFormat.RG16Uint;
1492+
formatGPU = textureFormatsTier1 ? GPUTextureFormat.RG16Unorm : GPUTextureFormat.RG16Uint;
14941493
break;
14951494

14961495
case UnsignedIntType:

0 commit comments

Comments
 (0)