Skip to content

Commit 7bbb584

Browse files
authored
WebGPURenderer: Make device capabilities handling more consistent. (mrdoob#33094)
1 parent ffb3ef5 commit 7bbb584

10 files changed

Lines changed: 85 additions & 56 deletions

File tree

src/nodes/core/NodeBuilder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ class NodeBuilder {
866866
*/
867867
getUniformBufferLimit() {
868868

869-
return 16384;
869+
return this.renderer.backend.capabilities.getUniformBufferLimit();
870870

871871
}
872872

src/renderers/common/Backend.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -604,14 +604,6 @@ class Backend {
604604
*/
605605
hasFeature( /*name*/ ) {}
606606

607-
/**
608-
* Returns the maximum anisotropy texture filtering value.
609-
*
610-
* @abstract
611-
* @return {number} The maximum anisotropy texture filtering value.
612-
*/
613-
getMaxAnisotropy() {}
614-
615607
/**
616608
* Returns the drawing buffer size.
617609
*

src/renderers/common/Renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,7 @@ class Renderer {
17781778
*/
17791779
getMaxAnisotropy() {
17801780

1781-
return this.backend.getMaxAnisotropy();
1781+
return this.backend.capabilities.getMaxAnisotropy();
17821782

17831783
}
17841784

src/renderers/webgl-fallback/WebGLBackend.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,17 +2009,6 @@ class WebGLBackend extends Backend {
20092009

20102010
}
20112011

2012-
/**
2013-
* Returns the maximum anisotropy texture filtering value.
2014-
*
2015-
* @return {number} The maximum anisotropy texture filtering value.
2016-
*/
2017-
getMaxAnisotropy() {
2018-
2019-
return this.capabilities.getMaxAnisotropy();
2020-
2021-
}
2022-
20232012
/**
20242013
* Copies data of the given source texture to the given destination texture.
20252014
*

src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,18 +1316,6 @@ ${ flowData.code }
13161316

13171317
}
13181318

1319-
/**
1320-
* Returns the maximum number of bytes available for uniform buffers.
1321-
*
1322-
* @return {number} The maximum number of bytes available for uniform buffers.
1323-
*/
1324-
getUniformBufferLimit() {
1325-
1326-
const gl = this.renderer.backend.gl;
1327-
return gl.getParameter( gl.MAX_UNIFORM_BLOCK_SIZE );
1328-
1329-
}
1330-
13311319
/**
13321320
* Enables hardware clipping.
13331321
*

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ class WebGLCapabilities {
2727
*/
2828
this.maxAnisotropy = null;
2929

30+
/**
31+
* This value holds the cached max uniform block size value.
32+
*
33+
* @type {?number}
34+
* @default null
35+
*/
36+
this.maxUniformBlockSize = null;
37+
3038
}
3139

3240
/**
@@ -59,6 +67,23 @@ class WebGLCapabilities {
5967

6068
}
6169

70+
/**
71+
* Returns the maximum number of bytes available for uniform buffers.
72+
*
73+
* @return {number} The maximum number of bytes available for uniform buffers.
74+
*/
75+
getUniformBufferLimit() {
76+
77+
if ( this.maxUniformBlockSize !== null ) return this.maxUniformBlockSize;
78+
79+
const gl = this.backend.gl;
80+
81+
this.maxUniformBlockSize = gl.getParameter( gl.MAX_UNIFORM_BLOCK_SIZE );
82+
83+
return this.maxUniformBlockSize;
84+
85+
}
86+
6287
}
6388

6489
export default WebGLCapabilities;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ class WebGLTextureUtils {
370370
if ( texture.anisotropy > 1 ) {
371371

372372
const extension = extensions.get( 'EXT_texture_filter_anisotropic' );
373-
gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, backend.getMaxAnisotropy() ) );
373+
gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, backend.capabilities.getMaxAnisotropy() ) );
374374

375375
}
376376

src/renderers/webgpu/WebGPUBackend.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Backend from '../common/Backend.js';
1010
import WebGPUUtils from './utils/WebGPUUtils.js';
1111
import WebGPUAttributeUtils from './utils/WebGPUAttributeUtils.js';
1212
import WebGPUBindingUtils from './utils/WebGPUBindingUtils.js';
13+
import WebGPUCapabilities from './utils/WebGPUCapabilities.js';
1314
import WebGPUPipelineUtils from './utils/WebGPUPipelineUtils.js';
1415
import WebGPUTextureUtils from './utils/WebGPUTextureUtils.js';
1516

@@ -116,6 +117,14 @@ class WebGPUBackend extends Backend {
116117
*/
117118
this.bindingUtils = new WebGPUBindingUtils( this );
118119

120+
/**
121+
* A reference to a backend module holding device capability related
122+
* utility functions.
123+
*
124+
* @type {WebGPUCapabilities}
125+
*/
126+
this.capabilities = new WebGPUCapabilities( this );
127+
119128
/**
120129
* A reference to a backend module holding shader pipeline-related
121130
* utility functions.
@@ -2293,17 +2302,6 @@ class WebGPUBackend extends Backend {
22932302

22942303
// utils public
22952304

2296-
/**
2297-
* Returns the maximum anisotropy texture filtering value.
2298-
*
2299-
* @return {number} The maximum anisotropy texture filtering value.
2300-
*/
2301-
getMaxAnisotropy() {
2302-
2303-
return 16;
2304-
2305-
}
2306-
23072305
/**
23082306
* Checks if the given feature is supported by the backend.
23092307
*

src/renderers/webgpu/nodes/WGSLNodeBuilder.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,17 +2280,6 @@ ${ flowData.code }
22802280

22812281
}
22822282

2283-
/**
2284-
* Returns the maximum uniform buffer size limit.
2285-
*
2286-
* @return {number} The maximum uniform buffer size in bytes.
2287-
*/
2288-
getUniformBufferLimit() {
2289-
2290-
return this.renderer.backend.device.limits.maxUniformBufferBindingSize;
2291-
2292-
}
2293-
22942283
/**
22952284
* Returns the native shader method name for a given generic name.
22962285
*
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* A WebGPU backend utility module for managing the device's capabilities.
3+
*
4+
* @private
5+
*/
6+
class WebGPUCapabilities {
7+
8+
/**
9+
* Constructs a new utility object.
10+
*
11+
* @param {WebGPUBackend} backend - The WebGPU backend.
12+
*/
13+
constructor( backend ) {
14+
15+
/**
16+
* A reference to the WebGPU backend.
17+
*
18+
* @type {WebGPUBackend}
19+
*/
20+
this.backend = backend;
21+
22+
}
23+
24+
/**
25+
* Returns the maximum anisotropy texture filtering value.
26+
*
27+
* @return {number} The maximum anisotropy texture filtering value.
28+
*/
29+
getMaxAnisotropy() {
30+
31+
return 16;
32+
33+
}
34+
35+
/**
36+
* Returns the maximum number of bytes available for uniform buffers.
37+
*
38+
* @return {number} The maximum number of bytes available for uniform buffers.
39+
*/
40+
getUniformBufferLimit() {
41+
42+
return this.backend.device.limits.maxUniformBufferBindingSize;
43+
44+
}
45+
46+
}
47+
48+
export default WebGPUCapabilities;

0 commit comments

Comments
 (0)