WebGPUBackend.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. /*// debugger tools
  2. import 'https://greggman.github.io/webgpu-avoid-redundant-state-setting/webgpu-check-redundant-state-setting.js';
  3. //*/
  4. import { GPUFeatureName, GPUTextureFormat, GPULoadOp, GPUStoreOp, GPUIndexFormat, GPUTextureViewDimension } from './utils/WebGPUConstants.js';
  5. import WGSLNodeBuilder from './nodes/WGSLNodeBuilder.js';
  6. import Backend from '../common/Backend.js';
  7. import { DepthTexture, DepthFormat, DepthStencilFormat, UnsignedInt248Type, UnsignedIntType, WebGPUCoordinateSystem } from 'three';
  8. import WebGPUUtils from './utils/WebGPUUtils.js';
  9. import WebGPUAttributeUtils from './utils/WebGPUAttributeUtils.js';
  10. import WebGPUBindingUtils from './utils/WebGPUBindingUtils.js';
  11. import WebGPUPipelineUtils from './utils/WebGPUPipelineUtils.js';
  12. import WebGPUTextureUtils from './utils/WebGPUTextureUtils.js';
  13. // statics
  14. let _staticAdapter = null;
  15. if ( navigator.gpu !== undefined ) {
  16. _staticAdapter = await navigator.gpu.requestAdapter();
  17. }
  18. //
  19. class WebGPUBackend extends Backend {
  20. constructor( parameters = {} ) {
  21. super( parameters );
  22. // some parameters require default values other than "undefined"
  23. this.parameters.antialias = ( parameters.antialias === true );
  24. if ( this.parameters.antialias === true ) {
  25. this.parameters.sampleCount = ( parameters.sampleCount === undefined ) ? 4 : parameters.sampleCount;
  26. } else {
  27. this.parameters.sampleCount = 1;
  28. }
  29. this.parameters.requiredLimits = ( parameters.requiredLimits === undefined ) ? {} : parameters.requiredLimits;
  30. this.adapter = null;
  31. this.device = null;
  32. this.context = null;
  33. this.colorBuffer = null;
  34. this.defaultDepthTexture = new DepthTexture();
  35. this.defaultDepthTexture.name = 'depthBuffer';
  36. this.utils = new WebGPUUtils( this );
  37. this.attributeUtils = new WebGPUAttributeUtils( this );
  38. this.bindingUtils = new WebGPUBindingUtils( this );
  39. this.pipelineUtils = new WebGPUPipelineUtils( this );
  40. this.textureUtils = new WebGPUTextureUtils( this );
  41. }
  42. async init( renderer ) {
  43. await super.init( renderer );
  44. //
  45. const parameters = this.parameters;
  46. const adapterOptions = {
  47. powerPreference: parameters.powerPreference
  48. };
  49. const adapter = await navigator.gpu.requestAdapter( adapterOptions );
  50. if ( adapter === null ) {
  51. throw new Error( 'WebGPUBackend: Unable to create WebGPU adapter.' );
  52. }
  53. // feature support
  54. const features = Object.values( GPUFeatureName );
  55. const supportedFeatures = [];
  56. for ( const name of features ) {
  57. if ( adapter.features.has( name ) ) {
  58. supportedFeatures.push( name );
  59. }
  60. }
  61. const deviceDescriptor = {
  62. requiredFeatures: supportedFeatures,
  63. requiredLimits: parameters.requiredLimits
  64. };
  65. const device = await adapter.requestDevice( deviceDescriptor );
  66. const context = ( parameters.context !== undefined ) ? parameters.context : renderer.domElement.getContext( 'webgpu' );
  67. this.adapter = adapter;
  68. this.device = device;
  69. this.context = context;
  70. this.updateSize();
  71. }
  72. get coordinateSystem() {
  73. return WebGPUCoordinateSystem;
  74. }
  75. async getArrayBufferAsync( attribute ) {
  76. return await this.attributeUtils.getArrayBufferAsync( attribute );
  77. }
  78. beginRender( renderContext ) {
  79. const renderContextData = this.get( renderContext );
  80. const device = this.device;
  81. const descriptor = {
  82. colorAttachments: [ {
  83. view: null
  84. } ],
  85. depthStencilAttachment: {
  86. view: null
  87. }
  88. };
  89. const colorAttachment = descriptor.colorAttachments[ 0 ];
  90. const depthStencilAttachment = descriptor.depthStencilAttachment;
  91. const antialias = this.parameters.antialias;
  92. if ( renderContext.texture !== null ) {
  93. const textureData = this.get( renderContext.texture );
  94. const depthTextureData = this.get( renderContext.depthTexture );
  95. const view = textureData.texture.createView( {
  96. baseMipLevel: 0,
  97. mipLevelCount: 1,
  98. baseArrayLayer: renderContext.activeCubeFace,
  99. dimension: GPUTextureViewDimension.TwoD
  100. } );
  101. if ( textureData.msaaTexture !== undefined ) {
  102. colorAttachment.view = textureData.msaaTexture.createView();
  103. colorAttachment.resolveTarget = view;
  104. } else {
  105. colorAttachment.view = view;
  106. colorAttachment.resolveTarget = undefined;
  107. }
  108. depthStencilAttachment.view = depthTextureData.texture.createView();
  109. if ( renderContext.stencil && renderContext.depthTexture.format === DepthFormat ) {
  110. renderContext.stencil = false;
  111. }
  112. } else {
  113. if ( antialias === true ) {
  114. colorAttachment.view = this.colorBuffer.createView();
  115. colorAttachment.resolveTarget = this.context.getCurrentTexture().createView();
  116. } else {
  117. colorAttachment.view = this.context.getCurrentTexture().createView();
  118. colorAttachment.resolveTarget = undefined;
  119. }
  120. depthStencilAttachment.view = this._getDepthBufferGPU( renderContext ).createView();
  121. }
  122. if ( renderContext.clearColor ) {
  123. colorAttachment.clearValue = renderContext.clearColorValue;
  124. colorAttachment.loadOp = GPULoadOp.Clear;
  125. colorAttachment.storeOp = GPUStoreOp.Store;
  126. } else {
  127. colorAttachment.loadOp = GPULoadOp.Load;
  128. colorAttachment.storeOp = GPUStoreOp.Store;
  129. }
  130. //
  131. if ( renderContext.depth ) {
  132. if ( renderContext.clearDepth ) {
  133. depthStencilAttachment.depthClearValue = renderContext.clearDepthValue;
  134. depthStencilAttachment.depthLoadOp = GPULoadOp.Clear;
  135. depthStencilAttachment.depthStoreOp = GPUStoreOp.Store;
  136. } else {
  137. depthStencilAttachment.depthLoadOp = GPULoadOp.Load;
  138. depthStencilAttachment.depthStoreOp = GPUStoreOp.Store;
  139. }
  140. }
  141. if ( renderContext.stencil ) {
  142. if ( renderContext.clearStencil ) {
  143. depthStencilAttachment.stencilClearValue = renderContext.clearStencilValue;
  144. depthStencilAttachment.stencilLoadOp = GPULoadOp.Clear;
  145. depthStencilAttachment.stencilStoreOp = GPUStoreOp.Store;
  146. } else {
  147. depthStencilAttachment.stencilLoadOp = GPULoadOp.Load;
  148. depthStencilAttachment.stencilStoreOp = GPUStoreOp.Store;
  149. }
  150. }
  151. //
  152. const encoder = device.createCommandEncoder( { label: 'renderContext_' + renderContext.id } );
  153. const currentPass = encoder.beginRenderPass( descriptor );
  154. //
  155. renderContextData.descriptor = descriptor;
  156. renderContextData.encoder = encoder;
  157. renderContextData.currentPass = currentPass;
  158. renderContextData.currentAttributesSet = {};
  159. //
  160. if ( renderContext.viewport ) {
  161. this.updateViewport( renderContext );
  162. }
  163. if ( renderContext.scissor ) {
  164. const { x, y, width, height } = renderContext.scissorValue;
  165. currentPass.setScissorRect( x, y, width, height );
  166. }
  167. }
  168. finishRender( renderContext ) {
  169. const renderContextData = this.get( renderContext );
  170. renderContextData.currentPass.end();
  171. this.device.queue.submit( [ renderContextData.encoder.finish() ] );
  172. //
  173. if ( renderContext.texture !== null && renderContext.texture.generateMipmaps === true ) {
  174. this.textureUtils.generateMipmaps( renderContext.texture );
  175. }
  176. }
  177. updateViewport( renderContext ) {
  178. const { currentPass } = this.get( renderContext );
  179. const { x, y, width, height, minDepth, maxDepth } = renderContext.viewportValue;
  180. currentPass.setViewport( x, y, width, height, minDepth, maxDepth );
  181. }
  182. clear( renderContext, color, depth, stencil ) {
  183. const device = this.device;
  184. const renderContextData = this.get( renderContext );
  185. const { descriptor } = renderContextData;
  186. depth = depth && renderContext.depth;
  187. stencil = stencil && renderContext.stencil;
  188. const colorAttachment = descriptor.colorAttachments[ 0 ];
  189. const depthStencilAttachment = descriptor.depthStencilAttachment;
  190. const antialias = this.parameters.antialias;
  191. // @TODO: Include render target in clear operation.
  192. if ( antialias === true ) {
  193. colorAttachment.view = this.colorBuffer.createView();
  194. colorAttachment.resolveTarget = this.context.getCurrentTexture().createView();
  195. } else {
  196. colorAttachment.view = this.context.getCurrentTexture().createView();
  197. colorAttachment.resolveTarget = undefined;
  198. }
  199. descriptor.depthStencilAttachment.view = this._getDepthBufferGPU( renderContext ).createView();
  200. if ( color ) {
  201. colorAttachment.loadOp = GPULoadOp.Clear;
  202. colorAttachment.clearValue = renderContext.clearColorValue;
  203. } else {
  204. colorAttachment.loadOp = GPULoadOp.Load;
  205. }
  206. if ( depth ) {
  207. depthStencilAttachment.depthLoadOp = GPULoadOp.Clear;
  208. depthStencilAttachment.depthClearValue = renderContext.clearDepthValue;
  209. } else {
  210. depthStencilAttachment.depthLoadOp = GPULoadOp.Load;
  211. }
  212. if ( stencil ) {
  213. depthStencilAttachment.stencilLoadOp = GPULoadOp.Clear;
  214. depthStencilAttachment.stencilClearValue = renderContext.clearStencilValue;
  215. } else {
  216. depthStencilAttachment.stencilLoadOp = GPULoadOp.Load;
  217. }
  218. renderContextData.encoder = device.createCommandEncoder( {} );
  219. renderContextData.currentPass = renderContextData.encoder.beginRenderPass( descriptor );
  220. renderContextData.currentPass.end();
  221. device.queue.submit( [ renderContextData.encoder.finish() ] );
  222. }
  223. // compute
  224. beginCompute( computeGroup ) {
  225. const groupGPU = this.get( computeGroup );
  226. groupGPU.cmdEncoderGPU = this.device.createCommandEncoder( {} );
  227. groupGPU.passEncoderGPU = groupGPU.cmdEncoderGPU.beginComputePass();
  228. }
  229. compute( computeGroup, computeNode, bindings, pipeline ) {
  230. const { passEncoderGPU } = this.get( computeGroup );
  231. // pipeline
  232. const pipelineGPU = this.get( pipeline ).pipeline;
  233. passEncoderGPU.setPipeline( pipelineGPU );
  234. // bind group
  235. const bindGroupGPU = this.get( bindings ).group;
  236. passEncoderGPU.setBindGroup( 0, bindGroupGPU );
  237. passEncoderGPU.dispatchWorkgroups( computeNode.dispatchCount );
  238. }
  239. finishCompute( computeGroup ) {
  240. const groupData = this.get( computeGroup );
  241. groupData.passEncoderGPU.end();
  242. this.device.queue.submit( [ groupData.cmdEncoderGPU.finish() ] );
  243. }
  244. // render object
  245. draw( renderObject, info ) {
  246. const { object, geometry, context, pipeline } = renderObject;
  247. const bindingsData = this.get( renderObject.getBindings() );
  248. const contextData = this.get( context );
  249. const pipelineGPU = this.get( pipeline ).pipeline;
  250. const attributesSet = contextData.currentAttributesSet;
  251. // pipeline
  252. const passEncoderGPU = contextData.currentPass;
  253. passEncoderGPU.setPipeline( pipelineGPU );
  254. // bind group
  255. const bindGroupGPU = bindingsData.group;
  256. passEncoderGPU.setBindGroup( 0, bindGroupGPU );
  257. // attributes
  258. const index = renderObject.getIndex();
  259. const hasIndex = ( index !== null );
  260. // index
  261. if ( hasIndex === true ) {
  262. if ( attributesSet.index !== index ) {
  263. const buffer = this.get( index ).buffer;
  264. const indexFormat = ( index.array instanceof Uint16Array ) ? GPUIndexFormat.Uint16 : GPUIndexFormat.Uint32;
  265. passEncoderGPU.setIndexBuffer( buffer, indexFormat );
  266. attributesSet.index = index;
  267. }
  268. }
  269. // vertex buffers
  270. const vertexBuffers = renderObject.getVertexBuffers();
  271. for ( let i = 0, l = vertexBuffers.length; i < l; i ++ ) {
  272. const vertexBuffer = vertexBuffers[ i ];
  273. if ( attributesSet[ i ] !== vertexBuffer ) {
  274. const buffer = this.get( vertexBuffer ).buffer;
  275. passEncoderGPU.setVertexBuffer( i, buffer );
  276. attributesSet[ i ] = vertexBuffer;
  277. }
  278. }
  279. // draw
  280. const drawRange = geometry.drawRange;
  281. const firstVertex = drawRange.start;
  282. const instanceCount = this.getInstanceCount( renderObject );
  283. if ( hasIndex === true ) {
  284. const indexCount = ( drawRange.count !== Infinity ) ? drawRange.count : index.count;
  285. passEncoderGPU.drawIndexed( indexCount, instanceCount, firstVertex, 0, 0 );
  286. info.update( object, indexCount, instanceCount );
  287. } else {
  288. const positionAttribute = geometry.attributes.position;
  289. const vertexCount = ( drawRange.count !== Infinity ) ? drawRange.count : positionAttribute.count;
  290. passEncoderGPU.draw( vertexCount, instanceCount, firstVertex, 0 );
  291. info.update( object, vertexCount, instanceCount );
  292. }
  293. }
  294. // cache key
  295. needsUpdate( renderObject ) {
  296. const renderObjectGPU = this.get( renderObject );
  297. const { object, material } = renderObject;
  298. const utils = this.utils;
  299. const sampleCount = utils.getSampleCount( renderObject.context );
  300. const colorSpace = utils.getCurrentColorSpace( renderObject.context );
  301. const colorFormat = utils.getCurrentColorFormat( renderObject.context );
  302. const depthStencilFormat = utils.getCurrentDepthStencilFormat( renderObject.context );
  303. const primitiveTopology = utils.getPrimitiveTopology( object, material );
  304. let needsUpdate = false;
  305. if ( renderObjectGPU.sampleCount !== sampleCount || renderObjectGPU.colorSpace !== colorSpace ||
  306. renderObjectGPU.colorFormat !== colorFormat || renderObjectGPU.depthStencilFormat !== depthStencilFormat ||
  307. renderObjectGPU.primitiveTopology !== primitiveTopology ) {
  308. renderObjectGPU.sampleCount = sampleCount;
  309. renderObjectGPU.colorSpace = colorSpace;
  310. renderObjectGPU.colorFormat = colorFormat;
  311. renderObjectGPU.depthStencilFormat = depthStencilFormat;
  312. renderObjectGPU.primitiveTopology = primitiveTopology;
  313. needsUpdate = true;
  314. }
  315. return needsUpdate;
  316. }
  317. getCacheKey( renderObject ) {
  318. const { object, material } = renderObject;
  319. const utils = this.utils;
  320. const renderContext = renderObject.context;
  321. return [
  322. utils.getSampleCount( renderContext ),
  323. utils.getCurrentColorSpace( renderContext ), utils.getCurrentColorFormat( renderContext ), utils.getCurrentDepthStencilFormat( renderContext ),
  324. utils.getPrimitiveTopology( object, material )
  325. ].join();
  326. }
  327. // textures
  328. createSampler( texture ) {
  329. this.textureUtils.createSampler( texture );
  330. }
  331. destroySampler( texture ) {
  332. this.textureUtils.destroySampler( texture );
  333. }
  334. createDefaultTexture( texture ) {
  335. this.textureUtils.createDefaultTexture( texture );
  336. }
  337. createTexture( texture, options ) {
  338. this.textureUtils.createTexture( texture, options );
  339. }
  340. updateTexture( texture ) {
  341. this.textureUtils.updateTexture( texture );
  342. }
  343. destroyTexture( texture ) {
  344. this.textureUtils.destroyTexture( texture );
  345. }
  346. copyTextureToBuffer( texture, x, y, width, height ) {
  347. return this.textureUtils.copyTextureToBuffer( texture, x, y, width, height );
  348. }
  349. // node builder
  350. createNodeBuilder( object, renderer, scene = null ) {
  351. return new WGSLNodeBuilder( object, renderer, scene );
  352. }
  353. // program
  354. createProgram( program ) {
  355. const programGPU = this.get( program );
  356. programGPU.module = {
  357. module: this.device.createShaderModule( { code: program.code, label: program.stage } ),
  358. entryPoint: 'main'
  359. };
  360. }
  361. destroyProgram( program ) {
  362. this.delete( program );
  363. }
  364. // pipelines
  365. createRenderPipeline( renderObject ) {
  366. this.pipelineUtils.createRenderPipeline( renderObject );
  367. }
  368. createComputePipeline( computePipeline, bindings ) {
  369. this.pipelineUtils.createComputePipeline( computePipeline, bindings );
  370. }
  371. // bindings
  372. createBindings( bindings ) {
  373. this.bindingUtils.createBindings( bindings );
  374. }
  375. updateBindings( bindings ) {
  376. this.bindingUtils.createBindings( bindings );
  377. }
  378. updateBinding( binding ) {
  379. this.bindingUtils.updateBinding( binding );
  380. }
  381. // attributes
  382. createIndexAttribute( attribute ) {
  383. this.attributeUtils.createAttribute( attribute, GPUBufferUsage.INDEX | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST );
  384. }
  385. createAttribute( attribute ) {
  386. this.attributeUtils.createAttribute( attribute, GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST );
  387. }
  388. createStorageAttribute( attribute ) {
  389. this.attributeUtils.createAttribute( attribute, GPUBufferUsage.STORAGE | GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST );
  390. }
  391. updateAttribute( attribute ) {
  392. this.attributeUtils.updateAttribute( attribute );
  393. }
  394. destroyAttribute( attribute ) {
  395. this.attributeUtils.destroyAttribute( attribute );
  396. }
  397. // canvas
  398. updateSize() {
  399. this._configureContext();
  400. this._setupColorBuffer();
  401. }
  402. // utils public
  403. hasFeature( name ) {
  404. const adapter = this.adapter || _staticAdapter;
  405. //
  406. const features = Object.values( GPUFeatureName );
  407. if ( features.includes( name ) === false ) {
  408. throw new Error( 'THREE.WebGPURenderer: Unknown WebGPU GPU feature: ' + name );
  409. }
  410. //
  411. return adapter.features.has( name );
  412. }
  413. copyFramebufferToTexture( texture, renderContext ) {
  414. const renderContextData = this.get( renderContext );
  415. const { encoder, descriptor } = renderContextData;
  416. let sourceGPU = null;
  417. if ( texture.isFramebufferTexture ) {
  418. sourceGPU = this.context.getCurrentTexture();
  419. } else if ( texture.isDepthTexture ) {
  420. sourceGPU = this._getDepthBufferGPU( renderContext );
  421. }
  422. const destinationGPU = this.get( texture ).texture;
  423. renderContextData.currentPass.end();
  424. encoder.copyTextureToTexture(
  425. {
  426. texture: sourceGPU,
  427. origin: { x: 0, y: 0, z: 0 }
  428. },
  429. {
  430. texture: destinationGPU
  431. },
  432. [
  433. texture.image.width,
  434. texture.image.height
  435. ]
  436. );
  437. if ( texture.generateMipmaps ) this.textureUtils.generateMipmaps( texture );
  438. descriptor.colorAttachments[ 0 ].loadOp = GPULoadOp.Load;
  439. if ( renderContext.depth ) descriptor.depthStencilAttachment.depthLoadOp = GPULoadOp.Load;
  440. if ( renderContext.stencil ) descriptor.depthStencilAttachment.stencilLoadOp = GPULoadOp.Load;
  441. renderContextData.currentPass = encoder.beginRenderPass( descriptor );
  442. renderContextData.currentAttributesSet = {};
  443. }
  444. // utils
  445. _getDepthBufferGPU( renderContext ) {
  446. const { width, height } = this.getDrawingBufferSize();
  447. const depthTexture = this.defaultDepthTexture;
  448. const depthTextureGPU = this.get( depthTexture ).texture;
  449. let format, type;
  450. if ( renderContext.stencil ) {
  451. format = DepthStencilFormat;
  452. type = UnsignedInt248Type;
  453. } else if ( renderContext.depth ) {
  454. format = DepthFormat;
  455. type = UnsignedIntType;
  456. }
  457. if ( depthTextureGPU !== undefined ) {
  458. if ( depthTexture.image.width === width && depthTexture.image.height === height && depthTexture.format === format && depthTexture.type === type ) {
  459. return depthTextureGPU;
  460. }
  461. this.textureUtils.destroyTexture( depthTexture );
  462. }
  463. depthTexture.name = 'depthBuffer';
  464. depthTexture.format = format;
  465. depthTexture.type = type;
  466. depthTexture.image.width = width;
  467. depthTexture.image.height = height;
  468. this.textureUtils.createTexture( depthTexture, { sampleCount: this.parameters.sampleCount } );
  469. return this.get( depthTexture ).texture;
  470. }
  471. _configureContext() {
  472. this.context.configure( {
  473. device: this.device,
  474. format: GPUTextureFormat.BGRA8Unorm,
  475. usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
  476. alphaMode: 'premultiplied'
  477. } );
  478. }
  479. _setupColorBuffer() {
  480. if ( this.colorBuffer ) this.colorBuffer.destroy();
  481. const { width, height } = this.getDrawingBufferSize();
  482. //const format = navigator.gpu.getPreferredCanvasFormat(); // @TODO: Move to WebGPUUtils
  483. this.colorBuffer = this.device.createTexture( {
  484. label: 'colorBuffer',
  485. size: {
  486. width: width,
  487. height: height,
  488. depthOrArrayLayers: 1
  489. },
  490. sampleCount: this.parameters.sampleCount,
  491. format: GPUTextureFormat.BGRA8Unorm,
  492. usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC
  493. } );
  494. }
  495. }
  496. export default WebGPUBackend;