Преглед на файлове

WebGPURenderer: Make device capabilities handling more consistent. (#33094)

Michael Herzog преди 1 месец
родител
ревизия
7bbb584ae2

+ 1 - 1
src/nodes/core/NodeBuilder.js

@@ -866,7 +866,7 @@ class NodeBuilder {
 	 */
 	getUniformBufferLimit() {
 
-		return 16384;
+		return this.renderer.backend.capabilities.getUniformBufferLimit();
 
 	}
 

+ 0 - 8
src/renderers/common/Backend.js

@@ -604,14 +604,6 @@ class Backend {
 	 */
 	hasFeature( /*name*/ ) {}
 
-	/**
-	 * Returns the maximum anisotropy texture filtering value.
-	 *
-	 * @abstract
-	 * @return {number} The maximum anisotropy texture filtering value.
-	 */
-	getMaxAnisotropy() {}
-
 	/**
 	 * Returns the drawing buffer size.
 	 *

+ 1 - 1
src/renderers/common/Renderer.js

@@ -1778,7 +1778,7 @@ class Renderer {
 	 */
 	getMaxAnisotropy() {
 
-		return this.backend.getMaxAnisotropy();
+		return this.backend.capabilities.getMaxAnisotropy();
 
 	}
 

+ 0 - 11
src/renderers/webgl-fallback/WebGLBackend.js

@@ -2009,17 +2009,6 @@ class WebGLBackend extends Backend {
 
 	}
 
-	/**
-	 * Returns the maximum anisotropy texture filtering value.
-	 *
-	 * @return {number} The maximum anisotropy texture filtering value.
-	 */
-	getMaxAnisotropy() {
-
-		return this.capabilities.getMaxAnisotropy();
-
-	}
-
 	/**
 	 * Copies data of the given source texture to the given destination texture.
 	 *

+ 0 - 12
src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js

@@ -1316,18 +1316,6 @@ ${ flowData.code }
 
 	}
 
-	/**
-	 * Returns the maximum number of bytes available for uniform buffers.
-	 *
-	 * @return {number} The maximum number of bytes available for uniform buffers.
-	 */
-	getUniformBufferLimit() {
-
-		const gl = this.renderer.backend.gl;
-		return gl.getParameter( gl.MAX_UNIFORM_BLOCK_SIZE );
-
-	}
-
 	/**
 	 * Enables hardware clipping.
 	 *

+ 25 - 0
src/renderers/webgl-fallback/utils/WebGLCapabilities.js

@@ -27,6 +27,14 @@ class WebGLCapabilities {
 		 */
 		this.maxAnisotropy = null;
 
+		/**
+		 * This value holds the cached max uniform block size value.
+		 *
+		 * @type {?number}
+		 * @default null
+		 */
+		this.maxUniformBlockSize = null;
+
 	}
 
 	/**
@@ -59,6 +67,23 @@ class WebGLCapabilities {
 
 	}
 
+	/**
+	 * Returns the maximum number of bytes available for uniform buffers.
+	 *
+	 * @return {number} The maximum number of bytes available for uniform buffers.
+	 */
+	getUniformBufferLimit() {
+
+		if ( this.maxUniformBlockSize !== null ) return this.maxUniformBlockSize;
+
+		const gl = this.backend.gl;
+
+		this.maxUniformBlockSize = gl.getParameter( gl.MAX_UNIFORM_BLOCK_SIZE );
+
+		return this.maxUniformBlockSize;
+
+	}
+
 }
 
 export default WebGLCapabilities;

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

@@ -370,7 +370,7 @@ class WebGLTextureUtils {
 			if ( texture.anisotropy > 1 ) {
 
 				const extension = extensions.get( 'EXT_texture_filter_anisotropic' );
-				gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, backend.getMaxAnisotropy() ) );
+				gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, backend.capabilities.getMaxAnisotropy() ) );
 
 			}
 

+ 9 - 11
src/renderers/webgpu/WebGPUBackend.js

@@ -10,6 +10,7 @@ import Backend from '../common/Backend.js';
 import WebGPUUtils from './utils/WebGPUUtils.js';
 import WebGPUAttributeUtils from './utils/WebGPUAttributeUtils.js';
 import WebGPUBindingUtils from './utils/WebGPUBindingUtils.js';
+import WebGPUCapabilities from './utils/WebGPUCapabilities.js';
 import WebGPUPipelineUtils from './utils/WebGPUPipelineUtils.js';
 import WebGPUTextureUtils from './utils/WebGPUTextureUtils.js';
 
@@ -116,6 +117,14 @@ class WebGPUBackend extends Backend {
 		 */
 		this.bindingUtils = new WebGPUBindingUtils( this );
 
+		/**
+		 * A reference to a backend module holding device capability related
+		 * utility functions.
+		 *
+		 * @type {WebGPUCapabilities}
+		 */
+		this.capabilities = new WebGPUCapabilities( this );
+
 		/**
 		 * A reference to a backend module holding shader pipeline-related
 		 * utility functions.
@@ -2293,17 +2302,6 @@ class WebGPUBackend extends Backend {
 
 	// utils public
 
-	/**
-	 * Returns the maximum anisotropy texture filtering value.
-	 *
-	 * @return {number} The maximum anisotropy texture filtering value.
-	 */
-	getMaxAnisotropy() {
-
-		return 16;
-
-	}
-
 	/**
 	 * Checks if the given feature is supported by the backend.
 	 *

+ 0 - 11
src/renderers/webgpu/nodes/WGSLNodeBuilder.js

@@ -2280,17 +2280,6 @@ ${ flowData.code }
 
 	}
 
-	/**
-	 * Returns the maximum uniform buffer size limit.
-	 *
-	 * @return {number} The maximum uniform buffer size in bytes.
-	 */
-	getUniformBufferLimit() {
-
-		return this.renderer.backend.device.limits.maxUniformBufferBindingSize;
-
-	}
-
 	/**
 	 * Returns the native shader method name for a given generic name.
 	 *

+ 48 - 0
src/renderers/webgpu/utils/WebGPUCapabilities.js

@@ -0,0 +1,48 @@
+/**
+ * A WebGPU backend utility module for managing the device's capabilities.
+ *
+ * @private
+ */
+class WebGPUCapabilities {
+
+	/**
+	 * Constructs a new utility object.
+	 *
+	 * @param {WebGPUBackend} backend - The WebGPU backend.
+	 */
+	constructor( backend ) {
+
+		/**
+		 * A reference to the WebGPU backend.
+		 *
+		 * @type {WebGPUBackend}
+		 */
+		this.backend = backend;
+
+	}
+
+	/**
+	 * Returns the maximum anisotropy texture filtering value.
+	 *
+	 * @return {number} The maximum anisotropy texture filtering value.
+	 */
+	getMaxAnisotropy() {
+
+		return 16;
+
+	}
+
+	/**
+	 * Returns the maximum number of bytes available for uniform buffers.
+	 *
+	 * @return {number} The maximum number of bytes available for uniform buffers.
+	 */
+	getUniformBufferLimit() {
+
+		return this.backend.device.limits.maxUniformBufferBindingSize;
+
+	}
+
+}
+
+export default WebGPUCapabilities;

粤ICP备19079148号