ComputeNode.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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.computeNode = computeNode;
  7. this.count = count;
  8. this.workgroupSize = workgroupSize;
  9. this.dispatchCount = 0;
  10. this.updateType = NodeUpdateType.Object;
  11. this.updateDispatchCount();
  12. }
  13. updateDispatchCount() {
  14. const { count, workgroupSize } = this;
  15. let size = workgroupSize[ 0 ];
  16. for ( let i = 1; i < workgroupSize.length; i ++ )
  17. size *= workgroupSize[ i ];
  18. this.dispatchCount = Math.ceil( count / size );
  19. }
  20. update( { renderer } ) {
  21. renderer.compute( this );
  22. }
  23. generate( builder ) {
  24. const { shaderStage } = builder;
  25. if ( shaderStage === 'compute' ) {
  26. const snippet = this.computeNode.build( builder, 'void' );
  27. if ( snippet !== '' ) {
  28. builder.addFlowCode( snippet );
  29. }
  30. }
  31. }
  32. }
  33. ComputeNode.prototype.isComputeNode = true;
  34. export default ComputeNode;