WGSLNodeBuilder.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  1. import UniformsGroup from '../../common/UniformsGroup.js';
  2. import {
  3. FloatNodeUniform, Vector2NodeUniform, Vector3NodeUniform, Vector4NodeUniform,
  4. ColorNodeUniform, Matrix3NodeUniform, Matrix4NodeUniform
  5. } from '../../common/nodes/NodeUniform.js';
  6. import NodeSampler from '../../common/nodes/NodeSampler.js';
  7. import { NodeSampledTexture, NodeSampledCubeTexture } from '../../common/nodes/NodeSampledTexture.js';
  8. import UniformBuffer from '../../common/UniformBuffer.js';
  9. import StorageBuffer from '../../common/StorageBuffer.js';
  10. import { getVectorLength, getStrideLength } from '../../common/BufferUtils.js';
  11. import RenderTarget from '../../common/RenderTarget.js';
  12. import CubeRenderTarget from '../../common/CubeRenderTarget.js';
  13. import { NodeBuilder, CodeNode, NodeMaterial } from '../../../nodes/Nodes.js';
  14. import WGSLNodeParser from './WGSLNodeParser.js';
  15. /*
  16. const gpuShaderStageLib = {
  17. 'vertex': GPUShaderStage.VERTEX,
  18. 'fragment': GPUShaderStage.FRAGMENT,
  19. 'compute': GPUShaderStage.COMPUTE
  20. };
  21. */
  22. const supports = {
  23. instance: true
  24. };
  25. const wgslTypeLib = {
  26. float: 'f32',
  27. int: 'i32',
  28. uint: 'u32',
  29. bool: 'bool',
  30. color: 'vec3<f32>',
  31. vec2: 'vec2<f32>',
  32. ivec2: 'vec2<i32>',
  33. uvec2: 'vec2<u32>',
  34. bvec2: 'vec2<bool>',
  35. vec3: 'vec3<f32>',
  36. ivec3: 'vec3<i32>',
  37. uvec3: 'vec3<u32>',
  38. bvec3: 'vec3<bool>',
  39. vec4: 'vec4<f32>',
  40. ivec4: 'vec4<i32>',
  41. uvec4: 'vec4<u32>',
  42. bvec4: 'vec4<bool>',
  43. mat3: 'mat3x3<f32>',
  44. imat3: 'mat3x3<i32>',
  45. umat3: 'mat3x3<u32>',
  46. bmat3: 'mat3x3<bool>',
  47. mat4: 'mat4x4<f32>',
  48. imat4: 'mat4x4<i32>',
  49. umat4: 'mat4x4<u32>',
  50. bmat4: 'mat4x4<bool>'
  51. };
  52. const wgslMethods = {
  53. dFdx: 'dpdx',
  54. dFdy: 'dpdy',
  55. mod: 'threejs_mod',
  56. lessThanEqual: 'threejs_lessThanEqual',
  57. inversesqrt: 'inverseSqrt'
  58. };
  59. const wgslPolyfill = {
  60. lessThanEqual: new CodeNode( `
  61. fn threejs_lessThanEqual( a : vec3<f32>, b : vec3<f32> ) -> vec3<bool> {
  62. return vec3<bool>( a.x <= b.x, a.y <= b.y, a.z <= b.z );
  63. }
  64. ` ),
  65. mod: new CodeNode( `
  66. fn threejs_mod( x : f32, y : f32 ) -> f32 {
  67. return x - y * floor( x / y );
  68. }
  69. ` ),
  70. repeatWrapping: new CodeNode( `
  71. fn threejs_repeatWrapping( uv : vec2<f32>, dimension : vec2<u32> ) -> vec2<u32> {
  72. let uvScaled = vec2<u32>( uv * vec2<f32>( dimension ) );
  73. return ( ( uvScaled % dimension ) + dimension ) % dimension;
  74. }
  75. ` )
  76. };
  77. class WebGPUNodeBuilder extends NodeBuilder {
  78. constructor( object, renderer ) {
  79. super( object, renderer, new WGSLNodeParser() );
  80. this.uniformsGroup = {};
  81. this.builtins = {
  82. vertex: new Map(),
  83. fragment: new Map(),
  84. compute: new Map(),
  85. attribute: new Map()
  86. };
  87. }
  88. build() {
  89. const { object, material } = this;
  90. if ( material !== null ) {
  91. NodeMaterial.fromMaterial( material ).build( this );
  92. } else {
  93. this.addFlow( 'compute', object );
  94. }
  95. return super.build();
  96. }
  97. getSampler( textureProperty, uvSnippet, shaderStage = this.shaderStage ) {
  98. if ( shaderStage === 'fragment' ) {
  99. return `textureSample( ${textureProperty}, ${textureProperty}_sampler, ${uvSnippet} )`;
  100. } else {
  101. this._include( 'repeatWrapping' );
  102. const dimension = `textureDimensions( ${textureProperty}, 0 )`;
  103. return `textureLoad( ${textureProperty}, threejs_repeatWrapping( ${uvSnippet}, ${dimension} ), 0 )`;
  104. }
  105. }
  106. getVideoSampler( textureProperty, uvSnippet, shaderStage = this.shaderStage ) {
  107. if ( shaderStage === 'fragment' ) {
  108. return `textureSampleBaseClampToEdge( ${textureProperty}, ${textureProperty}_sampler, vec2<f32>( ${uvSnippet}.x, 1.0 - ${uvSnippet}.y ) )`;
  109. } else {
  110. console.error( `WebGPURenderer: THREE.VideoTexture does not support ${ shaderStage } shader.` );
  111. }
  112. }
  113. getSamplerLevel( textureProperty, uvSnippet, biasSnippet, shaderStage = this.shaderStage ) {
  114. if ( shaderStage === 'fragment' ) {
  115. return `textureSampleLevel( ${textureProperty}, ${textureProperty}_sampler, ${uvSnippet}, ${biasSnippet} )`;
  116. } else {
  117. this._include( 'repeatWrapping' );
  118. const dimension = `textureDimensions( ${textureProperty}, 0 )`;
  119. return `textureLoad( ${textureProperty}, threejs_repeatWrapping( ${uvSnippet}, ${dimension} ), i32( ${biasSnippet} ) )`;
  120. }
  121. }
  122. getTexture( texture, textureProperty, uvSnippet, shaderStage = this.shaderStage ) {
  123. let snippet = null;
  124. if ( texture.isVideoTexture === true ) {
  125. snippet = this.getVideoSampler( textureProperty, uvSnippet, shaderStage );
  126. } else {
  127. snippet = this.getSampler( textureProperty, uvSnippet, shaderStage );
  128. }
  129. return snippet;
  130. }
  131. getTextureLevel( texture, textureProperty, uvSnippet, biasSnippet, shaderStage = this.shaderStage ) {
  132. let snippet = null;
  133. if ( texture.isVideoTexture === true ) {
  134. snippet = this.getVideoSampler( textureProperty, uvSnippet, shaderStage );
  135. } else {
  136. snippet = this.getSamplerLevel( textureProperty, uvSnippet, biasSnippet, shaderStage );
  137. }
  138. return snippet;
  139. }
  140. getPropertyName( node, shaderStage = this.shaderStage ) {
  141. if ( node.isNodeVarying === true && node.needsInterpolation === true ) {
  142. if ( shaderStage === 'vertex' ) {
  143. return `NodeVaryings.${ node.name }`;
  144. }
  145. } else if ( node.isNodeUniform === true ) {
  146. const name = node.name;
  147. const type = node.type;
  148. if ( type === 'texture' || type === 'cubeTexture' ) {
  149. return name;
  150. } else if ( type === 'buffer' || type === 'storageBuffer' ) {
  151. return `NodeBuffer_${node.node.id}.${name}`;
  152. } else {
  153. return `NodeUniforms.${name}`;
  154. }
  155. }
  156. return super.getPropertyName( node );
  157. }
  158. getUniformFromNode( node, type, shaderStage ) {
  159. const uniformNode = super.getUniformFromNode( node, type, shaderStage );
  160. const nodeData = this.getDataFromNode( node, shaderStage );
  161. if ( nodeData.uniformGPU === undefined ) {
  162. let uniformGPU;
  163. const bindings = this.bindings[ shaderStage ];
  164. if ( type === 'texture' || type === 'cubeTexture' ) {
  165. const sampler = new NodeSampler( `${uniformNode.name}_sampler`, uniformNode.node );
  166. let texture = null;
  167. if ( type === 'texture' ) {
  168. texture = new NodeSampledTexture( uniformNode.name, uniformNode.node );
  169. } else if ( type === 'cubeTexture' ) {
  170. texture = new NodeSampledCubeTexture( uniformNode.name, uniformNode.node );
  171. }
  172. // add first textures in sequence and group for last
  173. const lastBinding = bindings[ bindings.length - 1 ];
  174. const index = lastBinding && lastBinding.isUniformsGroup ? bindings.length - 1 : bindings.length;
  175. if ( shaderStage === 'fragment' ) {
  176. bindings.splice( index, 0, sampler, texture );
  177. uniformGPU = [ sampler, texture ];
  178. } else {
  179. bindings.splice( index, 0, texture );
  180. uniformGPU = [ texture ];
  181. }
  182. } else if ( type === 'buffer' || type === 'storageBuffer' ) {
  183. const bufferClass = type === 'storageBuffer' ? StorageBuffer : UniformBuffer;
  184. const buffer = new bufferClass( 'NodeBuffer_' + node.id, node.value );
  185. //buffer.setVisibility( gpuShaderStageLib[ shaderStage ] );
  186. // add first textures in sequence and group for last
  187. const lastBinding = bindings[ bindings.length - 1 ];
  188. const index = lastBinding && lastBinding.isUniformsGroup ? bindings.length - 1 : bindings.length;
  189. bindings.splice( index, 0, buffer );
  190. uniformGPU = buffer;
  191. } else {
  192. let uniformsGroup = this.uniformsGroup[ shaderStage ];
  193. if ( uniformsGroup === undefined ) {
  194. uniformsGroup = new UniformsGroup( 'nodeUniforms' );
  195. //uniformsGroup.setVisibility( gpuShaderStageLib[ shaderStage ] );
  196. this.uniformsGroup[ shaderStage ] = uniformsGroup;
  197. bindings.push( uniformsGroup );
  198. }
  199. if ( node.isArrayUniformNode === true ) {
  200. uniformGPU = [];
  201. for ( const uniformNode of node.nodes ) {
  202. const uniformNodeGPU = this._getNodeUniform( uniformNode, type );
  203. // fit bounds to buffer
  204. uniformNodeGPU.boundary = getVectorLength( uniformNodeGPU.itemSize );
  205. uniformNodeGPU.itemSize = getStrideLength( uniformNodeGPU.itemSize );
  206. uniformsGroup.addUniform( uniformNodeGPU );
  207. uniformGPU.push( uniformNodeGPU );
  208. }
  209. } else {
  210. uniformGPU = this._getNodeUniform( uniformNode, type );
  211. uniformsGroup.addUniform( uniformGPU );
  212. }
  213. }
  214. nodeData.uniformGPU = uniformGPU;
  215. if ( shaderStage === 'vertex' ) {
  216. this.bindingsOffset[ 'fragment' ] = bindings.length;
  217. }
  218. }
  219. return uniformNode;
  220. }
  221. isReference( type ) {
  222. return super.isReference( type ) || type === 'texture_2d' || type === 'texture_cube';
  223. }
  224. getBuiltin( name, property, type, shaderStage = this.shaderStage ) {
  225. const map = this.builtins[ shaderStage ];
  226. if ( map.has( name ) === false ) {
  227. map.set( name, {
  228. name,
  229. property,
  230. type
  231. } );
  232. }
  233. return property;
  234. }
  235. getInstanceIndex() {
  236. if ( this.shaderStage === 'vertex' ) {
  237. return this.getBuiltin( 'instance_index', 'instanceIndex', 'u32', 'attribute' );
  238. }
  239. return 'instanceIndex';
  240. }
  241. getFrontFacing() {
  242. return this.getBuiltin( 'front_facing', 'isFront', 'bool' );
  243. }
  244. getFragCoord() {
  245. return this.getBuiltin( 'position', 'fragCoord', 'vec4<f32>', 'fragment' );
  246. }
  247. isFlipY() {
  248. return false;
  249. }
  250. getAttributes( shaderStage ) {
  251. const snippets = [];
  252. if ( shaderStage === 'compute' ) {
  253. this.getBuiltin( 'global_invocation_id', 'id', 'vec3<u32>', 'attribute' );
  254. }
  255. if ( shaderStage === 'vertex' || shaderStage === 'compute' ) {
  256. for ( const { name, property, type } of this.builtins.attribute.values() ) {
  257. snippets.push( `@builtin( ${name} ) ${property} : ${type}` );
  258. }
  259. const attributes = this.getAttributesArray();
  260. for ( let index = 0, length = attributes.length; index < length; index ++ ) {
  261. const attribute = attributes[ index ];
  262. const name = attribute.name;
  263. const type = this.getType( attribute.type );
  264. snippets.push( `@location( ${index} ) ${ name } : ${ type }` );
  265. }
  266. }
  267. return snippets.join( ',\n\t' );
  268. }
  269. getVar( type, name ) {
  270. return `var ${ name } : ${ this.getType( type ) }`;
  271. }
  272. getVars( shaderStage ) {
  273. const snippets = [];
  274. const vars = this.vars[ shaderStage ];
  275. for ( const variable of vars ) {
  276. snippets.push( `\t${ this.getVar( variable.type, variable.name ) };` );
  277. }
  278. return `\n${ snippets.join( '\n' ) }\n`;
  279. }
  280. getVaryings( shaderStage ) {
  281. const snippets = [];
  282. if ( shaderStage === 'vertex' ) {
  283. this.getBuiltin( 'position', 'Vertex', 'vec4<f32>', 'vertex' );
  284. }
  285. if ( shaderStage === 'vertex' || shaderStage === 'fragment' ) {
  286. const varyings = this.varyings;
  287. const vars = this.vars[ shaderStage ];
  288. for ( let index = 0; index < varyings.length; index ++ ) {
  289. const varying = varyings[ index ];
  290. if ( varying.needsInterpolation ) {
  291. let attributesSnippet = `@location( ${index} )`;
  292. if ( varying.type === 'int' || varying.type === 'uint' ) {
  293. attributesSnippet += ' @interpolate( flat )';
  294. }
  295. snippets.push( `${ attributesSnippet } ${ varying.name } : ${ this.getType( varying.type ) }` );
  296. } else if ( vars.includes( varying ) === false ) {
  297. vars.push( varying );
  298. }
  299. }
  300. }
  301. for ( const { name, property, type } of this.builtins[ shaderStage ].values() ) {
  302. snippets.push( `@builtin( ${name} ) ${property} : ${type}` );
  303. }
  304. const code = snippets.join( ',\n\t' );
  305. return shaderStage === 'vertex' ? this._getWGSLStruct( 'NodeVaryingsStruct', '\t' + code ) : code;
  306. }
  307. getUniforms( shaderStage ) {
  308. const uniforms = this.uniforms[ shaderStage ];
  309. const bindingSnippets = [];
  310. const bufferSnippets = [];
  311. const groupSnippets = [];
  312. let index = this.bindingsOffset[ shaderStage ];
  313. for ( const uniform of uniforms ) {
  314. if ( uniform.type === 'texture' || uniform.type === 'cubeTexture' ) {
  315. if ( shaderStage === 'fragment' ) {
  316. bindingSnippets.push( `@group( 0 ) @binding( ${index ++} ) var ${uniform.name}_sampler : sampler;` );
  317. }
  318. const texture = uniform.node.value;
  319. let textureType;
  320. if ( texture.isCubeTexture === true ) {
  321. textureType = 'texture_cube<f32>';
  322. } else if ( texture.isDepthTexture === true ) {
  323. textureType = 'texture_depth_2d';
  324. } else if ( texture.isVideoTexture === true ) {
  325. textureType = 'texture_external';
  326. } else {
  327. textureType = 'texture_2d<f32>';
  328. }
  329. bindingSnippets.push( `@group( 0 ) @binding( ${index ++} ) var ${uniform.name} : ${textureType};` );
  330. } else if ( uniform.type === 'buffer' || uniform.type === 'storageBuffer' ) {
  331. const bufferNode = uniform.node;
  332. const bufferType = this.getType( bufferNode.bufferType );
  333. const bufferCount = bufferNode.bufferCount;
  334. const bufferCountSnippet = bufferCount > 0 ? ', ' + bufferCount : '';
  335. const bufferSnippet = `\t${uniform.name} : array< ${bufferType}${bufferCountSnippet} >\n`;
  336. const bufferAccessMode = bufferNode.isStorageBufferNode ? 'storage,read_write' : 'uniform';
  337. bufferSnippets.push( this._getWGSLStructBinding( 'NodeBuffer_' + bufferNode.id, bufferSnippet, bufferAccessMode, index ++ ) );
  338. } else {
  339. const vectorType = this.getType( this.getVectorType( uniform.type ) );
  340. if ( Array.isArray( uniform.value ) === true ) {
  341. const length = uniform.value.length;
  342. groupSnippets.push( `uniform ${vectorType}[ ${length} ] ${uniform.name}` );
  343. } else {
  344. groupSnippets.push( `\t${uniform.name} : ${ vectorType}` );
  345. }
  346. }
  347. }
  348. let code = bindingSnippets.join( '\n' );
  349. code += bufferSnippets.join( '\n' );
  350. if ( groupSnippets.length > 0 ) {
  351. code += this._getWGSLStructBinding( 'NodeUniforms', groupSnippets.join( ',\n' ), 'uniform', index ++ );
  352. }
  353. return code;
  354. }
  355. buildCode() {
  356. const shadersData = this.material !== null ? { fragment: {}, vertex: {} } : { compute: {} };
  357. for ( const shaderStage in shadersData ) {
  358. let flow = '// code\n\n';
  359. flow += this.flowCode[ shaderStage ];
  360. const flowNodes = this.flowNodes[ shaderStage ];
  361. const mainNode = flowNodes[ flowNodes.length - 1 ];
  362. for ( const node of flowNodes ) {
  363. const flowSlotData = this.getFlowData( node/*, shaderStage*/ );
  364. const slotName = node.name;
  365. if ( slotName ) {
  366. if ( flow.length > 0 ) flow += '\n';
  367. flow += `\t// flow -> ${ slotName }\n\t`;
  368. }
  369. flow += `${ flowSlotData.code }\n\t`;
  370. if ( node === mainNode && shaderStage !== 'compute' ) {
  371. flow += '// result\n\t';
  372. if ( shaderStage === 'vertex' ) {
  373. flow += 'NodeVaryings.Vertex = ';
  374. } else if ( shaderStage === 'fragment' ) {
  375. flow += 'return ';
  376. }
  377. flow += `${ flowSlotData.result };`;
  378. }
  379. }
  380. const stageData = shadersData[ shaderStage ];
  381. stageData.uniforms = this.getUniforms( shaderStage );
  382. stageData.attributes = this.getAttributes( shaderStage );
  383. stageData.varyings = this.getVaryings( shaderStage );
  384. stageData.vars = this.getVars( shaderStage );
  385. stageData.codes = this.getCodes( shaderStage );
  386. stageData.flow = flow;
  387. }
  388. if ( this.material !== null ) {
  389. this.vertexShader = this._getWGSLVertexCode( shadersData.vertex );
  390. this.fragmentShader = this._getWGSLFragmentCode( shadersData.fragment );
  391. } else {
  392. this.computeShader = this._getWGSLComputeCode( shadersData.compute, ( this.object.workgroupSize || [ 64 ] ).join( ', ' ) );
  393. }
  394. }
  395. getRenderTarget( width, height, options ) {
  396. return new RenderTarget( width, height, options );
  397. }
  398. getCubeRenderTarget( size, options ) {
  399. return new CubeRenderTarget( size, options );
  400. }
  401. getMethod( method ) {
  402. if ( wgslPolyfill[ method ] !== undefined ) {
  403. this._include( method );
  404. }
  405. return wgslMethods[ method ] || method;
  406. }
  407. getType( type ) {
  408. return wgslTypeLib[ type ] || type;
  409. }
  410. isAvailable( name ) {
  411. return supports[ name ] === true;
  412. }
  413. _include( name ) {
  414. wgslPolyfill[ name ].build( this );
  415. }
  416. _getNodeUniform( uniformNode, type ) {
  417. if ( type === 'float' ) return new FloatNodeUniform( uniformNode );
  418. if ( type === 'vec2' ) return new Vector2NodeUniform( uniformNode );
  419. if ( type === 'vec3' ) return new Vector3NodeUniform( uniformNode );
  420. if ( type === 'vec4' ) return new Vector4NodeUniform( uniformNode );
  421. if ( type === 'color' ) return new ColorNodeUniform( uniformNode );
  422. if ( type === 'mat3' ) return new Matrix3NodeUniform( uniformNode );
  423. if ( type === 'mat4' ) return new Matrix4NodeUniform( uniformNode );
  424. throw new Error( `Uniform "${type}" not declared.` );
  425. }
  426. _getWGSLVertexCode( shaderData ) {
  427. return `${ this.getSignature() }
  428. // uniforms
  429. ${shaderData.uniforms}
  430. // varyings
  431. ${shaderData.varyings}
  432. // codes
  433. ${shaderData.codes}
  434. @vertex
  435. fn main( ${shaderData.attributes} ) -> NodeVaryingsStruct {
  436. // system
  437. var NodeVaryings: NodeVaryingsStruct;
  438. // vars
  439. ${shaderData.vars}
  440. // flow
  441. ${shaderData.flow}
  442. return NodeVaryings;
  443. }
  444. `;
  445. }
  446. _getWGSLFragmentCode( shaderData ) {
  447. return `${ this.getSignature() }
  448. // uniforms
  449. ${shaderData.uniforms}
  450. // codes
  451. ${shaderData.codes}
  452. @fragment
  453. fn main( ${shaderData.varyings} ) -> @location( 0 ) vec4<f32> {
  454. // vars
  455. ${shaderData.vars}
  456. // flow
  457. ${shaderData.flow}
  458. }
  459. `;
  460. }
  461. _getWGSLComputeCode( shaderData, workgroupSize ) {
  462. return `${ this.getSignature() }
  463. // system
  464. var<private> instanceIndex : u32;
  465. // uniforms
  466. ${shaderData.uniforms}
  467. // codes
  468. ${shaderData.codes}
  469. @compute @workgroup_size( ${workgroupSize} )
  470. fn main( ${shaderData.attributes} ) {
  471. // system
  472. instanceIndex = id.x;
  473. // vars
  474. ${shaderData.vars}
  475. // flow
  476. ${shaderData.flow}
  477. }
  478. `;
  479. }
  480. _getWGSLStruct( name, vars ) {
  481. return `
  482. struct ${name} {
  483. ${vars}
  484. };`;
  485. }
  486. _getWGSLStructBinding( name, vars, access, binding = 0, group = 0 ) {
  487. const structName = name + 'Struct';
  488. const structSnippet = this._getWGSLStruct( structName, vars );
  489. return `${structSnippet}
  490. @binding( ${binding} ) @group( ${group} )
  491. var<${access}> ${name} : ${structName};`;
  492. }
  493. }
  494. export default WebGPUNodeBuilder;