Просмотр исходного кода

WebGPURenderer: Improve checks for uniform buffer limits (#32949)

sunag 3 недель назад
Родитель
Сommit
04961bea57

+ 2 - 4
src/nodes/accessors/InstanceNode.js

@@ -301,11 +301,9 @@ class InstanceNode extends Node {
 
 		} else {
 
-			// WebGPU has a 64kb UBO limit, WebGL 2 ensures only 16KB; fallback to attributes if a certain count is exceeded
+			const uniformBufferSize = count * 16 * 4; // count * 16 components * 4 bytes (float)
 
-			const limit = ( builder.renderer.backend.isWebGPUBackend === true ) ? 1000 : 250;
-
-			if ( count <= limit ) {
+			if ( uniformBufferSize <= builder.getUniformBufferLimit() ) {
 
 				instanceMatrixNode = buffer( instanceMatrix.array, 'mat4', Math.max( count, 1 ) ).element( instanceIndex );
 

+ 11 - 0
src/nodes/core/NodeBuilder.js

@@ -829,6 +829,17 @@ class NodeBuilder {
 
 	}
 
+	/**
+	 * Returns the maximum number of bytes available for uniform buffers.
+	 *
+	 * @return {number} The maximum number of bytes available for uniform buffers.
+	 */
+	getUniformBufferLimit() {
+
+		return 16384;
+
+	}
+
 	/**
 	 * Adds the given node to the internal node chain.
 	 * This is used to check recursive calls in node-graph.

+ 2 - 1
src/nodes/geometry/RangeNode.js

@@ -168,8 +168,9 @@ class RangeNode extends Node {
 			}
 
 			const nodeType = this.getNodeType( builder );
+			const uniformBufferSize = object.count * 4 * 4; // count * 4 components * 4 bytes (float)
 
-			if ( object.count <= 4096 ) {
+			if ( uniformBufferSize <= builder.getUniformBufferLimit() ) {
 
 				output = buffer( array, 'vec4', object.count ).element( instanceIndex ).convert( nodeType );
 

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

@@ -1307,6 +1307,18 @@ ${ 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.
 	 *

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

@@ -2143,7 +2143,6 @@ ${ flowData.code }
 
 	}
 
-
 	/**
 	 * Returns the WGSL type of the given node data type.
 	 *
@@ -2186,6 +2185,17 @@ ${ 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.
 	 *

粤ICP备19079148号