ComputeNode.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import Node from '../core/Node.js';
  2. import { NodeUpdateType } from '../core/constants.js';
  3. class ComputeNode extends Node {
  4. constructor( computeNode, count, workgroupSize = [ 64 ] ) {
  5. super( 'void' );
  6. this.isComputeNode = true;
  7. this.computeNode = computeNode;
  8. this.count = count;
  9. this.workgroupSize = workgroupSize;
  10. this.dispatchCount = 0;
  11. this.updateType = NodeUpdateType.Object;
  12. this.updateDispatchCount();
  13. }
  14. updateDispatchCount() {
  15. const { count, workgroupSize } = this;
  16. let size = workgroupSize[ 0 ];
  17. for ( let i = 1; i < workgroupSize.length; i ++ )
  18. size *= workgroupSize[ i ];
  19. this.dispatchCount = Math.ceil( count / size );
  20. }
  21. onInit() { }
  22. update( { renderer } ) {
  23. renderer.compute( this );
  24. }
  25. generate( builder ) {
  26. const { shaderStage } = builder;
  27. if ( shaderStage === 'compute' ) {
  28. const snippet = this.computeNode.build( builder, 'void' );
  29. if ( snippet !== '' ) {
  30. builder.addFlowCode( snippet );
  31. }
  32. }
  33. }
  34. }
  35. export default ComputeNode;