1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import Node from '../core/Node.js';
- import { NodeUpdateType } from '../core/constants.js';
- class ComputeNode extends Node {
- constructor( computeNode, count, workgroupSize = [ 64 ] ) {
- super( 'void' );
- this.isComputeNode = true;
- this.computeNode = computeNode;
- this.count = count;
- this.workgroupSize = workgroupSize;
- this.dispatchCount = 0;
- this.updateType = NodeUpdateType.Object;
- this.updateDispatchCount();
- }
- updateDispatchCount() {
- const { count, workgroupSize } = this;
- let size = workgroupSize[ 0 ];
- for ( let i = 1; i < workgroupSize.length; i ++ )
- size *= workgroupSize[ i ];
- this.dispatchCount = Math.ceil( count / size );
- }
- onInit() { }
- update( { renderer } ) {
- renderer.compute( this );
- }
- generate( builder ) {
- const { shaderStage } = builder;
- if ( shaderStage === 'compute' ) {
- const snippet = this.computeNode.build( builder, 'void' );
- if ( snippet !== '' ) {
- builder.addFlowCode( snippet );
- }
- }
- }
- }
- export default ComputeNode;
|