Skip to content

Commit 468f47a

Browse files
authored
WebGPURenderer: Introduce compatibilityMode (#30854)
* introduce compatibility mode * cleanup
1 parent 8cccca7 commit 468f47a

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

examples/webgpu_loader_gltf.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
} );
7878

7979

80-
renderer = new THREE.WebGPURenderer( { antialias: true } );
80+
renderer = new THREE.WebGPURenderer( { antialias: true/*, compatibilityMode: true*/ } );
8181
renderer.setPixelRatio( window.devicePixelRatio );
8282
renderer.setSize( window.innerWidth, window.innerHeight );
8383
renderer.toneMapping = THREE.ACESFilmicToneMapping;

src/renderers/common/Textures.js

+2-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import DataMap from './DataMap.js';
22

33
import { Vector3 } from '../../math/Vector3.js';
44
import { DepthTexture } from '../../textures/DepthTexture.js';
5-
import { DepthStencilFormat, DepthFormat, UnsignedIntType, UnsignedInt248Type, EquirectangularReflectionMapping, EquirectangularRefractionMapping, CubeReflectionMapping, CubeRefractionMapping, UnsignedByteType } from '../../constants.js';
5+
import { DepthStencilFormat, DepthFormat, UnsignedIntType, UnsignedInt248Type, UnsignedByteType } from '../../constants.js';
66

77
const _size = /*@__PURE__*/ new Vector3();
88

@@ -421,21 +421,7 @@ class Textures extends DataMap {
421421
*/
422422
needsMipmaps( texture ) {
423423

424-
return this.isEnvironmentTexture( texture ) || texture.isCompressedTexture === true || texture.generateMipmaps;
425-
426-
}
427-
428-
/**
429-
* Returns `true` if the given texture is an environment map.
430-
*
431-
* @param {Texture} texture - The texture.
432-
* @return {boolean} Whether the given texture is an environment map or not.
433-
*/
434-
isEnvironmentTexture( texture ) {
435-
436-
const mapping = texture.mapping;
437-
438-
return ( mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping ) || ( mapping === CubeReflectionMapping || mapping === CubeRefractionMapping );
424+
return texture.isCompressedTexture === true || texture.generateMipmaps;
439425

440426
}
441427

src/renderers/webgpu/WebGPUBackend.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,17 @@ class WebGPUBackend extends Backend {
6363

6464
// some parameters require default values other than "undefined"
6565
this.parameters.alpha = ( parameters.alpha === undefined ) ? true : parameters.alpha;
66+
this.parameters.compatibilityMode = ( parameters.compatibilityMode === undefined ) ? false : parameters.compatibilityMode;
6667

6768
this.parameters.requiredLimits = ( parameters.requiredLimits === undefined ) ? {} : parameters.requiredLimits;
6869

70+
/**
71+
* Indicates whether the backend is in compatibility mode or not.
72+
* @type {boolean}
73+
* @default false
74+
*/
75+
this.compatibilityMode = this.parameters.compatibilityMode;
76+
6977
/**
7078
* A reference to the device.
7179
*
@@ -168,7 +176,8 @@ class WebGPUBackend extends Backend {
168176
if ( parameters.device === undefined ) {
169177

170178
const adapterOptions = {
171-
powerPreference: parameters.powerPreference
179+
powerPreference: parameters.powerPreference,
180+
featureLevel: parameters.compatibilityMode ? 'compatibility' : undefined
172181
};
173182

174183
const adapter = ( typeof navigator !== 'undefined' ) ? await navigator.gpu.requestAdapter( adapterOptions ) : null;

src/renderers/webgpu/utils/WebGPUTextureUtils.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
GPUTextureFormat, GPUAddressMode, GPUFilterMode, GPUTextureDimension, GPUFeatureName
2+
GPUTextureFormat, GPUAddressMode, GPUFilterMode, GPUTextureDimension, GPUFeatureName, GPUTextureViewDimension
33
} from './WebGPUConstants.js';
44

55
import WebGPUTexturePassUtils from './WebGPUTexturePassUtils.js';
@@ -270,6 +270,12 @@ class WebGPUTextureUtils {
270270

271271
}
272272

273+
if ( texture.isCubeTexture ) {
274+
275+
textureDescriptorGPU.textureBindingViewDimension = GPUTextureViewDimension.Cube;
276+
277+
}
278+
273279
textureData.texture = backend.device.createTexture( textureDescriptorGPU );
274280

275281
}

0 commit comments

Comments
 (0)