Răsfoiți Sursa

WebGPUBackend: Add support indirectOffset based on IndirectStorageBufferAttribute count (#32413)

Renaud Rohlinger 1 lună în urmă
părinte
comite
8687381d9e

+ 3 - 3
src/core/BufferGeometry.js

@@ -112,11 +112,11 @@ class BufferGeometry extends EventDispatcher {
 		this.indirect = null;
 
 		/**
-		 * The offset, in bytes, into the indirect drawing buffer where the value data begins.
+		 * The offset, in bytes, into the indirect drawing buffer where the value data begins. If an array is provided, multiple indirect draw calls will be made for each offset.
 		 *
 		 * Can only be used with {@link WebGPURenderer} and a WebGPU backend.
 		 *
-		 * @type {number}
+		 * @type {number|Array<number>}
 		 * @default 0
 		 */
 		this.indirectOffset = 0;
@@ -234,7 +234,7 @@ class BufferGeometry extends EventDispatcher {
 	 * Sets the given indirect attribute to this geometry.
 	 *
 	 * @param {BufferAttribute} indirect - The attribute holding indirect draw calls.
-	 * @param {number} [indirectOffset=0] - The offset, in bytes, into the indirect drawing buffer where the value data begins.
+	 * @param {number|Array<number>} [indirectOffset=0] - The offset, in bytes, into the indirect drawing buffer where the value data begins. If an array is provided, multiple indirect draw calls will be made for each offset.
 	 * @return {BufferGeometry} A reference to this instance.
 	 */
 	setIndirect( indirect, indirectOffset = 0 ) {

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

@@ -447,7 +447,7 @@ class RenderObject {
 	/**
 	 * Returns the byte offset into the indirect attribute buffer.
 	 *
-	 * @return {number} The byte offset into the indirect attribute buffer.
+	 * @return {number|Array<number>} The byte offset into the indirect attribute buffer.
 	 */
 	getIndirectOffset() {
 

+ 13 - 2
src/renderers/webgpu/WebGPUBackend.js

@@ -1601,8 +1601,13 @@ class WebGPUBackend extends Backend {
 
 					const buffer = this.get( indirect ).buffer;
 					const indirectOffset = renderObject.getIndirectOffset();
+					const indirectOffsets = Array.isArray( indirectOffset ) ? indirectOffset : [ indirectOffset ];
 
-					passEncoderGPU.drawIndexedIndirect( buffer, indirectOffset );
+					for ( let i = 0; i < indirectOffsets.length; i ++ ) {
+
+						passEncoderGPU.drawIndexedIndirect( buffer, indirectOffsets[ i ] );
+
+					}
 
 				} else {
 
@@ -1622,8 +1627,14 @@ class WebGPUBackend extends Backend {
 
 					const buffer = this.get( indirect ).buffer;
 					const indirectOffset = renderObject.getIndirectOffset();
+					const indirectOffsets = Array.isArray( indirectOffset ) ? indirectOffset : [ indirectOffset ];
+
+					for ( let i = 0; i < indirectOffsets.length; i ++ ) {
+
+						passEncoderGPU.drawIndirect( buffer, indirectOffsets[ i ] );
+
+					}
 
-					passEncoderGPU.drawIndirect( buffer, indirectOffset );
 
 				} else {
 

粤ICP备19079148号