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

WebGPURenderer: Introducing an `IndirectStorageBufferAttribute` (#29594)

* Introducing an indirectStorageBuffer for drawIndirect

* Update NodeStorageBuffer.js

fixed lint issue

* Update StorageBufferNode.js

fixed lint issue

* Update IndirectStorageBufferAttribute.js

fixed lint issue

* Update StorageBufferNode.js

fixed lint issues

* Update StorageBufferNode.js

fixed lint issues

* Update StorageBufferNode.js

fixed lint issues

* Update StorageBufferNode.js

fixed lint issue

* PR update

* Update StorageBuffer.js

* Update Bindings.js

* Update Bindings.js

* Update StorageBufferNode.js

* rev

* cleanup

---------

Co-authored-by: Attila Schroeder <attila-schroeder.79@gmail.com>
Co-authored-by: sunag <sunagbrasil@gmail.com>
Spiri0 1 год назад
Родитель
Сommit
df215c82bd

+ 3 - 3
src/nodes/accessors/StorageBufferNode.js

@@ -66,7 +66,7 @@ class StorageBufferNode extends BufferNode {
 
 	getInputType( /*builder*/ ) {
 
-		return 'storageBuffer';
+		return this.value.isIndirectStorageBufferAttribute ? 'indirectStorageBuffer' : 'storageBuffer';
 
 	}
 
@@ -130,7 +130,7 @@ class StorageBufferNode extends BufferNode {
 
 	getNodeType( builder ) {
 
-		if ( builder.isAvailable( 'storageBuffer' ) ) {
+		if ( builder.isAvailable( 'storageBuffer' ) || builder.isAvailable( 'indirectStorageBuffer' ) ) {
 
 			return super.getNodeType( builder );
 
@@ -144,7 +144,7 @@ class StorageBufferNode extends BufferNode {
 
 	generate( builder ) {
 
-		if ( builder.isAvailable( 'storageBuffer' ) ) {
+		if ( builder.isAvailable( 'storageBuffer' ) || builder.isAvailable( 'indirectStorageBuffer' ) ) {
 
 			return super.generate( builder );
 

+ 4 - 0
src/renderers/common/Attributes.js

@@ -45,6 +45,10 @@ class Attributes extends DataMap {
 
 				this.backend.createStorageAttribute( attribute );
 
+			} else if ( type === AttributeType.INDIRECT ) {
+
+				this.backend.createIndirectStorageAttribute( attribute );
+
 			}
 
 			data.version = this._getBufferAttribute( attribute ).version;

+ 2 - 1
src/renderers/common/Bindings.js

@@ -101,8 +101,9 @@ class Bindings extends DataMap {
 			} else if ( binding.isStorageBuffer ) {
 
 				const attribute = binding.attribute;
+				const attributeType = attribute.isIndirectStorageBufferAttribute ? AttributeType.INDIRECT : AttributeType.STORAGE;
 
-				this.attributes.update( attribute, AttributeType.STORAGE );
+				this.attributes.update( attribute, attributeType );
 
 			}
 

+ 2 - 1
src/renderers/common/Constants.js

@@ -1,7 +1,8 @@
 export const AttributeType = {
 	VERTEX: 1,
 	INDEX: 2,
-	STORAGE: 4
+	STORAGE: 3,
+	INDIRECT: 4
 };
 
 // size of a chunk in bytes (STD140 layout)

+ 15 - 0
src/renderers/common/IndirectStorageBufferAttribute.js

@@ -0,0 +1,15 @@
+import StorageBufferAttribute from './StorageBufferAttribute.js';
+
+class IndirectStorageBufferAttribute extends StorageBufferAttribute {
+
+	constructor( array, itemSize ) {
+
+		super( array, itemSize, Uint32Array );
+
+		this.isIndirectStorageBufferAttribute = true;
+
+	}
+
+}
+
+export default IndirectStorageBufferAttribute;

+ 6 - 0
src/renderers/webgpu/WebGPUBackend.js

@@ -1335,6 +1335,12 @@ class WebGPUBackend extends Backend {
 
 	}
 
+	createIndirectStorageAttribute( attribute ) {
+
+		this.attributeUtils.createAttribute( attribute, GPUBufferUsage.STORAGE | GPUBufferUsage.INDIRECT | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST );
+
+	}
+
 	updateAttribute( attribute ) {
 
 		this.attributeUtils.updateAttribute( attribute );

+ 5 - 4
src/renderers/webgpu/nodes/WGSLNodeBuilder.js

@@ -386,7 +386,7 @@ class WGSLNodeBuilder extends NodeBuilder {
 
 				return name;
 
-			} else if ( type === 'buffer' || type === 'storageBuffer' ) {
+			} else if ( type === 'buffer' || type === 'storageBuffer' || type === 'indirectStorageBuffer' ) {
 
 				return `NodeBuffer_${ node.id }.${name}`;
 
@@ -525,9 +525,10 @@ class WGSLNodeBuilder extends NodeBuilder {
 
 				}
 
-			} else if ( type === 'buffer' || type === 'storageBuffer' ) {
+			} else if ( type === 'buffer' || type === 'storageBuffer' || type === 'indirectStorageBuffer' ) {
+
+				const bufferClass = type === 'buffer' ? NodeUniformBuffer : NodeStorageBuffer;
 
-				const bufferClass = type === 'storageBuffer' ? NodeStorageBuffer : NodeUniformBuffer;
 				const buffer = new bufferClass( node, group );
 				buffer.setVisibility( gpuShaderStageLib[ shaderStage ] );
 
@@ -1067,7 +1068,7 @@ ${ flowData.code }
 
 				bindingSnippets.push( `@binding( ${ uniformIndexes.binding ++ } ) @group( ${ uniformIndexes.group } ) var ${ uniform.name } : ${ textureType };` );
 
-			} else if ( uniform.type === 'buffer' || uniform.type === 'storageBuffer' ) {
+			} else if ( uniform.type === 'buffer' || uniform.type === 'storageBuffer' || uniform.type === 'indirectStorageBuffer' ) {
 
 				const bufferNode = uniform.node;
 				const bufferType = this.getType( bufferNode.bufferType );

粤ICP备19079148号