@luma.gl/webgpu 9.0.0-alpha.4 → 9.0.0-alpha.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/LICENSE +3 -1
  2. package/dist/adapter/helpers/accessor-to-format.js.map +1 -1
  3. package/dist/adapter/helpers/convert-texture-format.d.ts +2 -2
  4. package/dist/adapter/helpers/convert-texture-format.d.ts.map +1 -1
  5. package/dist/adapter/helpers/convert-texture-format.js +0 -1
  6. package/dist/adapter/helpers/convert-texture-format.js.map +1 -1
  7. package/dist/adapter/helpers/generate-mipmaps.d.ts +1 -1
  8. package/dist/adapter/helpers/generate-mipmaps.js +19 -14
  9. package/dist/adapter/helpers/generate-mipmaps.js.map +1 -1
  10. package/dist/adapter/helpers/get-bind-group.d.ts +4 -4
  11. package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
  12. package/dist/adapter/helpers/get-bind-group.js +8 -17
  13. package/dist/adapter/helpers/get-bind-group.js.map +1 -1
  14. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts +5 -5
  15. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -1
  16. package/dist/adapter/helpers/get-vertex-buffer-layout.js +33 -40
  17. package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +1 -1
  18. package/dist/adapter/helpers/webgpu-parameters.d.ts +2 -2
  19. package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
  20. package/dist/adapter/helpers/webgpu-parameters.js +51 -48
  21. package/dist/adapter/helpers/webgpu-parameters.js.map +1 -1
  22. package/dist/adapter/resources/webgpu-buffer.d.ts +4 -5
  23. package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
  24. package/dist/adapter/resources/webgpu-buffer.js +16 -31
  25. package/dist/adapter/resources/webgpu-buffer.js.map +1 -1
  26. package/dist/adapter/resources/webgpu-command-encoder.d.ts +6 -15
  27. package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
  28. package/dist/adapter/resources/webgpu-command-encoder.js +11 -29
  29. package/dist/adapter/resources/webgpu-command-encoder.js.map +1 -1
  30. package/dist/adapter/resources/webgpu-compute-pass.d.ts +6 -6
  31. package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
  32. package/dist/adapter/resources/webgpu-compute-pass.js +14 -27
  33. package/dist/adapter/resources/webgpu-compute-pass.js.map +1 -1
  34. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +4 -4
  35. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
  36. package/dist/adapter/resources/webgpu-compute-pipeline.js +6 -11
  37. package/dist/adapter/resources/webgpu-compute-pipeline.js.map +1 -1
  38. package/dist/adapter/resources/webgpu-external-texture.d.ts +5 -5
  39. package/dist/adapter/resources/webgpu-external-texture.d.ts.map +1 -1
  40. package/dist/adapter/resources/webgpu-external-texture.js +6 -14
  41. package/dist/adapter/resources/webgpu-external-texture.js.map +1 -1
  42. package/dist/adapter/resources/webgpu-framebuffer.d.ts +4 -21
  43. package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
  44. package/dist/adapter/resources/webgpu-framebuffer.js +4 -105
  45. package/dist/adapter/resources/webgpu-framebuffer.js.map +1 -1
  46. package/dist/adapter/resources/webgpu-query.js.map +1 -1
  47. package/dist/adapter/resources/webgpu-render-pass.d.ts +12 -7
  48. package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
  49. package/dist/adapter/resources/webgpu-render-pass.js +59 -36
  50. package/dist/adapter/resources/webgpu-render-pass.js.map +1 -1
  51. package/dist/adapter/resources/webgpu-render-pipeline.d.ts +14 -10
  52. package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
  53. package/dist/adapter/resources/webgpu-render-pipeline.js +50 -67
  54. package/dist/adapter/resources/webgpu-render-pipeline.js.map +1 -1
  55. package/dist/adapter/resources/webgpu-sampler.d.ts +5 -5
  56. package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
  57. package/dist/adapter/resources/webgpu-sampler.js +11 -11
  58. package/dist/adapter/resources/webgpu-sampler.js.map +1 -1
  59. package/dist/adapter/resources/webgpu-shader.d.ts +7 -7
  60. package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
  61. package/dist/adapter/resources/webgpu-shader.js +11 -25
  62. package/dist/adapter/resources/webgpu-shader.js.map +1 -1
  63. package/dist/adapter/resources/webgpu-texture.d.ts +15 -8
  64. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  65. package/dist/adapter/resources/webgpu-texture.js +17 -27
  66. package/dist/adapter/resources/webgpu-texture.js.map +1 -1
  67. package/dist/adapter/resources/webgpu-vertex-array.d.ts +26 -0
  68. package/dist/adapter/resources/webgpu-vertex-array.d.ts.map +1 -0
  69. package/dist/adapter/resources/webgpu-vertex-array.js +39 -0
  70. package/dist/adapter/resources/webgpu-vertex-array.js.map +1 -0
  71. package/dist/adapter/webgpu-canvas-context.d.ts +16 -12
  72. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
  73. package/dist/adapter/webgpu-canvas-context.js +26 -47
  74. package/dist/adapter/webgpu-canvas-context.js.map +1 -1
  75. package/dist/adapter/webgpu-device.d.ts +38 -22
  76. package/dist/adapter/webgpu-device.d.ts.map +1 -1
  77. package/dist/adapter/webgpu-device.js +87 -91
  78. package/dist/adapter/webgpu-device.js.map +1 -1
  79. package/dist/adapter/webgpu-types.js.map +1 -1
  80. package/dist/dist.dev.js +3586 -0
  81. package/dist/glsl/glsllang.js +0 -1
  82. package/dist/glsl/glsllang.js.map +1 -1
  83. package/dist/index.cjs +1519 -0
  84. package/dist/index.d.ts +5 -7
  85. package/dist/index.d.ts.map +1 -1
  86. package/dist/index.js +5 -7
  87. package/dist/index.js.map +1 -1
  88. package/dist.min.js +18 -0
  89. package/package.json +18 -9
  90. package/src/adapter/helpers/accessor-to-format.ts +2 -2
  91. package/src/adapter/helpers/convert-texture-format.ts +1 -1
  92. package/src/adapter/helpers/generate-mipmaps.ts +1 -1
  93. package/src/adapter/helpers/get-bind-group.ts +22 -12
  94. package/src/adapter/helpers/get-vertex-buffer-layout.ts +58 -34
  95. package/src/adapter/helpers/webgpu-parameters.ts +56 -47
  96. package/src/adapter/resources/webgpu-buffer.ts +6 -10
  97. package/src/adapter/resources/webgpu-command-encoder.ts +62 -41
  98. package/src/adapter/resources/webgpu-compute-pass.ts +13 -13
  99. package/src/adapter/resources/webgpu-compute-pipeline.ts +6 -5
  100. package/src/adapter/resources/webgpu-external-texture.ts +5 -5
  101. package/src/adapter/resources/webgpu-framebuffer.ts +8 -109
  102. package/src/adapter/resources/webgpu-query.ts +3 -3
  103. package/src/adapter/resources/webgpu-render-pass.ts +74 -18
  104. package/src/adapter/resources/webgpu-render-pipeline.ts +64 -39
  105. package/src/adapter/resources/webgpu-sampler.ts +12 -5
  106. package/src/adapter/resources/webgpu-shader.ts +13 -10
  107. package/src/adapter/resources/webgpu-texture.ts +22 -8
  108. package/src/adapter/resources/webgpu-vertex-array.ts +74 -0
  109. package/src/adapter/webgpu-canvas-context.ts +52 -27
  110. package/src/adapter/webgpu-device.ts +150 -60
  111. package/src/index.ts +7 -9
  112. package/dist/bundle.d.ts +0 -2
  113. package/dist/bundle.d.ts.map +0 -1
  114. package/dist/bundle.js +0 -5
  115. package/dist/bundle.js.map +0 -1
  116. package/dist/init.d.ts +0 -2
  117. package/dist/init.d.ts.map +0 -1
  118. package/dist/init.js +0 -4
  119. package/dist/init.js.map +0 -1
  120. package/src/bundle.ts +0 -4
  121. package/src/init.ts +0 -4
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/adapter/resources/webgpu-render-pass.ts"],"names":["RenderPass","cast","WebGPURenderPass","constructor","device","props","framebuffer","canvasContext","getCurrentFramebuffer","renderPassDescriptor","handle","commandEncoder","beginRenderPass","label","id","destroy","endPass","setPipeline","pipeline","setBindings","bindings","setBindGroup","_getBindGroup","setIndexBuffer","buffer","indexFormat","offset","size","setVertexBuffer","slot","draw","options","indexCount","drawIndexed","instanceCount","firstIndex","baseVertex","firstInstance","vertexCount","drawIndirect","setParameters","parameters","blendConstant","stencilReference","scissorRect","viewport","setBlendConstant","setStencilReference","setScissorRect","setViewport","pushDebugGroup","groupLabel","popDebugGroup","insertDebugMarker","markerLabel"],"mappings":";AACA,SAAgBA,UAAhB,EAA4CC,IAA5C,QAA4D,cAA5D;AAMA,eAAe,MAAMC,gBAAN,SAA+BF,UAA/B,CAA0C;AAOvDG,EAAAA,WAAW,CAACC,MAAD,EAAuBC,KAAsB,GAAG,EAAhD,EAAoD;AAC7D,UAAMD,MAAN,EAAcC,KAAd;;AAD6D;;AAAA;;AAAA,sCAFvB,IAEuB;;AAE7D,SAAKD,MAAL,GAAcA,MAAd;AACA,UAAME,WAAW,GAAGD,KAAK,CAACC,WAAN,IAAqBF,MAAM,CAACG,aAAP,CAAqBC,qBAArB,EAAzC;AAEA,UAAMC,oBAAoB,GAAGH,WAAW,CAACG,oBAAzC;AACA,SAAKC,MAAL,GAAc,KAAKL,KAAL,CAAWK,MAAX,IAAqBN,MAAM,CAACO,cAAP,CAAsBC,eAAtB,CAAsCH,oBAAtC,CAAnC;AACA,SAAKC,MAAL,CAAYG,KAAZ,GAAoB,KAAKR,KAAL,CAAWS,EAA/B;AACD;;AAEDC,EAAAA,OAAO,GAAG,CAAE;;AAEZC,EAAAA,OAAO,GAAS;AACd,SAAKN,MAAL,CAAYM,OAAZ;AACD;;AAEDC,EAAAA,WAAW,CAACC,QAAD,EAAiC;AAC1C,SAAKA,QAAL,GAAgBjB,IAAI,CAAuBiB,QAAvB,CAApB;AACA,SAAKR,MAAL,CAAYO,WAAZ,CAAwB,KAAKC,QAAL,CAAcR,MAAtC;AACD;;AAGDS,EAAAA,WAAW,CAACC,QAAD,EAA0C;AACnD,SAAKF,QAAL,CAAcC,WAAd,CAA0BC,QAA1B;AACA,SAAKV,MAAL,CAAYW,YAAZ,CAAyB,CAAzB,EAA4B,KAAKH,QAAL,CAAcI,aAA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,WAAJ,EAAiB;AACf,WAAKlC,MAAL,CAAYsC,cAAZ,CAA2BJ,WAAW,CAAC,CAAD,CAAtC,EAA2CA,WAAW,CAAC,CAAD,CAAtD,EAA2DA,WAAW,CAAC,CAAD,CAAtE,EAA2EA,WAAW,CAAC,CAAD,CAAtF;AACD;;AAED,QAAIC,QAAJ,EAAc;AACZ,WAAKnC,MAAL,CAAYuC,WAAZ,CACEJ,QAAQ,CAAC,CAAD,CADV,EAEEA,QAAQ,CAAC,CAAD,CAFV,EAGEA,QAAQ,CAAC,CAAD,CAHV,EAIEA,QAAQ,CAAC,CAAD,CAJV,EAKEA,QAAQ,CAAC,CAAD,CALV,EAMEA,QAAQ,CAAC,CAAD,CANV;AAQD;AACF;;AAEDK,EAAAA,cAAc,CAACC,UAAD,EAA2B;AACvC,SAAKzC,MAAL,CAAYwC,cAAZ,CAA2BC,UAA3B;AACD;;AACDC,EAAAA,aAAa,GAAS;AACpB,SAAK1C,MAAL,CAAY0C,aAAZ;AACD;;AACDC,EAAAA,iBAAiB,CAACC,WAAD,EAA4B;AAC3C,SAAK5C,MAAL,CAAY2C,iBAAZ,CAA8BC,WAA9B;AACD;;AA/GsD","sourcesContent":["import type {RenderPassProps, RenderPassParameters, Binding} from '@luma.gl/api';\nimport {Buffer, RenderPass, RenderPipeline, cast, log} from '@luma.gl/api';\nimport WebGPUDevice from '../webgpu-device';\nimport WebGPUBuffer from './webgpu-buffer';\n// import WebGPUCommandEncoder from './webgpu-command-encoder';\nimport WebGPURenderPipeline from './webgpu-render-pipeline';\n\nexport default class WebGPURenderPass extends RenderPass {\n readonly device: WebGPUDevice;\n readonly handle: GPURenderPassEncoder;\n\n /** Active pipeline */\n pipeline: WebGPURenderPipeline | null = null;\n\n constructor(device: WebGPUDevice, props: RenderPassProps = {}) {\n super(device, props);\n this.device = device;\n const framebuffer = props.framebuffer || device.canvasContext.getCurrentFramebuffer();\n // @ts-expect-error\n const renderPassDescriptor = framebuffer.renderPassDescriptor;\n this.handle = this.props.handle || device.commandEncoder.beginRenderPass(renderPassDescriptor);\n this.handle.label = this.props.id;\n }\n\n destroy() {}\n\n endPass(): void {\n this.handle.endPass();\n }\n\n setPipeline(pipeline: RenderPipeline): void {\n this.pipeline = cast<WebGPURenderPipeline>(pipeline);\n this.handle.setPipeline(this.pipeline.handle);\n }\n\n /** Sets an array of bindings (uniform buffers, samplers, textures, ...) */\n setBindings(bindings: Record<string, Binding>): void {\n this.pipeline.setBindings(bindings);\n this.handle.setBindGroup(0, this.pipeline._getBindGroup());\n }\n\n setIndexBuffer(\n buffer: Buffer,\n indexFormat: GPUIndexFormat,\n offset: number = 0,\n size?: number\n ): void {\n this.handle.setIndexBuffer(cast<WebGPUBuffer>(buffer).handle, indexFormat, offset, size);\n }\n\n setVertexBuffer(slot: number, buffer: Buffer, offset: number = 0): void {\n this.handle.setVertexBuffer(slot, cast<WebGPUBuffer>(buffer).handle, offset);\n }\n\n draw(options: {\n vertexCount?: number;\n indexCount?: number;\n instanceCount?: number;\n firstVertex?: number;\n firstIndex?: number;\n firstInstance?: number;\n baseVertex?: number;\n }): void {\n if (options.indexCount) {\n this.handle.drawIndexed(\n options.indexCount,\n options.instanceCount,\n options.firstIndex,\n options.baseVertex,\n options.firstInstance\n );\n } else {\n this.handle.draw(\n options.vertexCount,\n options.instanceCount,\n options.firstIndex,\n options.firstInstance\n );\n }\n }\n\n drawIndirect(): void {\n // drawIndirect(indirectBuffer: GPUBuffer, indirectOffset: number): void;\n // drawIndexedIndirect(indirectBuffer: GPUBuffer, indirectOffset: number): void;\n }\n\n setParameters(parameters: RenderPassParameters): void {\n const {blendConstant, stencilReference, scissorRect, viewport} = parameters;\n if (blendConstant) {\n this.handle.setBlendConstant(blendConstant);\n }\n if (stencilReference) {\n this.handle.setStencilReference(stencilReference);\n }\n if (scissorRect) {\n this.handle.setScissorRect(scissorRect[0], scissorRect[1], scissorRect[2], scissorRect[3]);\n }\n // TODO - explain how 3 dimensions vs 2 in WebGL works.\n if (viewport) {\n this.handle.setViewport(\n viewport[0],\n viewport[1],\n viewport[2],\n viewport[3],\n viewport[4],\n viewport[5]\n );\n }\n }\n\n pushDebugGroup(groupLabel: string): void {\n this.handle.pushDebugGroup(groupLabel);\n }\n popDebugGroup(): void {\n this.handle.popDebugGroup();\n }\n insertDebugMarker(markerLabel: string): void {\n this.handle.insertDebugMarker(markerLabel);\n }\n\n // writeTimestamp(querySet: GPUQuerySet, queryIndex: number): void;\n // beginOcclusionQuery(queryIndex: number): void;\n // endOcclusionQuery(): void;\n // beginPipelineStatisticsQuery(querySet: GPUQuerySet, queryIndex: number): void;\n // endPipelineStatisticsQuery(querySet: GPUQuerySet, queryIndex: number): void;\n\n // executeBundles(bundles: Iterable<GPURenderBundle>): void;\n}\n"],"file":"webgpu-render-pass.js"}
1
+ {"version":3,"file":"webgpu-render-pass.js","names":["RenderPass","cast","log","WebGPURenderPass","constructor","device","props","arguments","length","undefined","handle","pipeline","framebuffer","canvasContext","getCurrentFramebuffer","renderPassDescriptor","getRenderPassDescriptor","groupCollapsed","id","probe","JSON","stringify","groupEnd","commandEncoder","beginRenderPass","label","destroy","end","setPipeline","setBindings","bindings","_this$pipeline","_this$pipeline2","bindGroup","_getBindGroup","setBindGroup","setIndexBuffer","buffer","indexFormat","offset","size","setVertexBuffer","slot","draw","options","indexCount","drawIndexed","instanceCount","firstIndex","baseVertex","firstInstance","vertexCount","drawIndirect","setParameters","parameters","blendConstant","stencilReference","scissorRect","viewport","setBlendConstant","setStencilReference","setScissorRect","setViewport","pushDebugGroup","groupLabel","popDebugGroup","insertDebugMarker","markerLabel","colorAttachments","map","colorAttachment","loadOp","clearColor","colorClearValue","storeOp","discard","view","createView","depthStencilAttachment","depthReadOnly","depthClearValue","clearDepth","hasDepthAspect","depthLoadOp","depthStoreOp","hasStencilAspect","stencilLoadOp","clearStencil","stencilStoreOp"],"sources":["../../../src/adapter/resources/webgpu-render-pass.ts"],"sourcesContent":["import type {RenderPassProps, RenderPassParameters, Binding, Framebuffer} from '@luma.gl/core';\nimport {Buffer, RenderPass, RenderPipeline, cast, log} from '@luma.gl/core';\nimport {WebGPUDevice} from '../webgpu-device';\nimport {WebGPUBuffer} from './webgpu-buffer';\nimport {WebGPUTexture} from './webgpu-texture';\n// import {WebGPUCommandEncoder} from './webgpu-command-encoder';\nimport {WebGPURenderPipeline} from './webgpu-render-pipeline';\n\nexport class WebGPURenderPass extends RenderPass {\n readonly device: WebGPUDevice;\n readonly handle: GPURenderPassEncoder;\n\n /** Active pipeline */\n pipeline: WebGPURenderPipeline | null = null;\n\n constructor(device: WebGPUDevice, props: RenderPassProps = {}) {\n super(device, props);\n this.device = device;\n const framebuffer = props.framebuffer || device.canvasContext.getCurrentFramebuffer() ;\n const renderPassDescriptor = this.getRenderPassDescriptor(framebuffer);\n log.groupCollapsed(1, `new WebGPURenderPass(${this.id})`)();\n log.probe(1, JSON.stringify(renderPassDescriptor, null, 2))();\n log.groupEnd(1)();\n this.handle = this.props.handle || device.commandEncoder.beginRenderPass(renderPassDescriptor);\n this.handle.label = this.props.id;\n }\n\n override destroy(): void {}\n\n end(): void {\n this.handle.end();\n }\n\n setPipeline(pipeline: RenderPipeline): void {\n this.pipeline = cast<WebGPURenderPipeline>(pipeline);\n this.handle.setPipeline(this.pipeline.handle);\n }\n\n /** Sets an array of bindings (uniform buffers, samplers, textures, ...) */\n setBindings(bindings: Record<string, Binding>): void {\n this.pipeline?.setBindings(bindings);\n const bindGroup = this.pipeline?._getBindGroup();\n if (bindGroup) {\n this.handle.setBindGroup(0, bindGroup);\n }\n }\n\n setIndexBuffer(\n buffer: Buffer,\n indexFormat: GPUIndexFormat,\n offset: number = 0,\n size?: number\n ): void {\n this.handle.setIndexBuffer(cast<WebGPUBuffer>(buffer).handle, indexFormat, offset, size);\n }\n\n setVertexBuffer(slot: number, buffer: Buffer, offset: number = 0): void {\n this.handle.setVertexBuffer(slot, cast<WebGPUBuffer>(buffer).handle, offset);\n }\n\n draw(options: {\n vertexCount?: number;\n indexCount?: number;\n instanceCount?: number;\n firstVertex?: number;\n firstIndex?: number;\n firstInstance?: number;\n baseVertex?: number;\n }): void {\n if (options.indexCount) {\n this.handle.drawIndexed(\n options.indexCount,\n options.instanceCount,\n options.firstIndex,\n options.baseVertex,\n options.firstInstance\n );\n } else {\n this.handle.draw(\n options.vertexCount || 0,\n options.instanceCount || 1,\n options.firstIndex,\n options.firstInstance\n );\n }\n }\n\n drawIndirect(): void {\n // drawIndirect(indirectBuffer: GPUBuffer, indirectOffset: number): void;\n // drawIndexedIndirect(indirectBuffer: GPUBuffer, indirectOffset: number): void;\n }\n\n setParameters(parameters: RenderPassParameters): void {\n const {blendConstant, stencilReference, scissorRect, viewport} = parameters;\n if (blendConstant) {\n this.handle.setBlendConstant(blendConstant);\n }\n if (stencilReference) {\n this.handle.setStencilReference(stencilReference);\n }\n if (scissorRect) {\n this.handle.setScissorRect(scissorRect[0], scissorRect[1], scissorRect[2], scissorRect[3]);\n }\n // TODO - explain how 3 dimensions vs 2 in WebGL works.\n if (viewport) {\n this.handle.setViewport(\n viewport[0],\n viewport[1],\n viewport[2],\n viewport[3],\n viewport[4],\n viewport[5]\n );\n }\n }\n\n pushDebugGroup(groupLabel: string): void {\n this.handle.pushDebugGroup(groupLabel);\n }\n popDebugGroup(): void {\n this.handle.popDebugGroup();\n }\n insertDebugMarker(markerLabel: string): void {\n this.handle.insertDebugMarker(markerLabel);\n }\n\n // writeTimestamp(querySet: GPUQuerySet, queryIndex: number): void;\n // beginOcclusionQuery(queryIndex: number): void;\n // endOcclusionQuery(): void;\n // beginPipelineStatisticsQuery(querySet: GPUQuerySet, queryIndex: number): void;\n // endPipelineStatisticsQuery(querySet: GPUQuerySet, queryIndex: number): void;\n\n // executeBundles(bundles: Iterable<GPURenderBundle>): void;\n\n // INTERNAL\n\n /** \n * Partial render pass descriptor. Used by WebGPURenderPass.\n * @returns attachments fields of a renderpass descriptor. \n */\n protected getRenderPassDescriptor(framebuffer: Framebuffer): GPURenderPassDescriptor {\n const renderPassDescriptor: GPURenderPassDescriptor = {\n colorAttachments: []\n };\n\n renderPassDescriptor.colorAttachments = framebuffer.colorAttachments.map(colorAttachment => ({\n // clear values\n loadOp: this.props.clearColor !== false ? 'clear' : 'load',\n colorClearValue: this.props.clearColor || [0, 0, 0, 0],\n storeOp: this.props.discard? 'discard': 'store',\n // ...colorAttachment,\n view: (colorAttachment as WebGPUTexture).handle.createView()\n }));\n\n if (framebuffer.depthStencilAttachment) {\n renderPassDescriptor.depthStencilAttachment = {\n view: (framebuffer.depthStencilAttachment as WebGPUTexture).handle.createView()\n };\n const {depthStencilAttachment} = renderPassDescriptor;\n\n // DEPTH\n if (this.props.depthReadOnly) {\n depthStencilAttachment.depthReadOnly = true;\n }\n depthStencilAttachment.depthClearValue = this.props.clearDepth || 0;\n\n // WebGPU only wants us to set these parameters if the texture format actually has a depth aspect\n const hasDepthAspect = true;\n if (hasDepthAspect) {\n depthStencilAttachment.depthLoadOp = this.props.clearDepth !== false ? 'clear' : 'load';\n depthStencilAttachment.depthStoreOp = 'store'; // TODO - support 'discard'?\n }\n\n // WebGPU only wants us to set these parameters if the texture format actually has a stencil aspect\n const hasStencilAspect = false;\n if (hasStencilAspect) {\n depthStencilAttachment.stencilLoadOp = this.props.clearStencil !== false ? 'clear' : 'load';\n depthStencilAttachment.stencilStoreOp = 'store'; // TODO - support 'discard'?\n }\n }\n\n return renderPassDescriptor;\n }\n}\n"],"mappings":"AACA,SAAgBA,UAAU,EAAkBC,IAAI,EAAEC,GAAG,QAAO,eAAe;AAO3E,OAAO,MAAMC,gBAAgB,SAASH,UAAU,CAAC;EAO/CI,WAAWA,CAACC,MAAoB,EAA+B;IAAA,IAA7BC,KAAsB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAC3D,KAAK,CAACF,MAAM,EAAEC,KAAK,CAAC;IAAC,KAPdD,MAAM;IAAA,KACNK,MAAM;IAAA,KAGfC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CAACU,cAAc,GAAG,OAAO;MACjD;IACF;IAEA,OAAOzE,oBAAoB;EAC7B;AACF"}
@@ -1,12 +1,15 @@
1
- /// <reference types="@webgpu/types" />
2
- import type { Binding, RenderPass } from '@luma.gl/api';
3
- import { Buffer, RenderPipeline, RenderPipelineProps } from '@luma.gl/api';
4
- import type WebGPUDevice from '../webgpu-device';
5
- import type WebGPURenderPass from './webgpu-render-pass';
1
+ /// <reference types="dist" />
2
+ import type { TypedArray, Binding, UniformValue, RenderPass } from '@luma.gl/core';
3
+ import { Buffer, RenderPipeline, RenderPipelineProps } from '@luma.gl/core';
4
+ import type { WebGPUDevice } from '../webgpu-device';
5
+ import type { WebGPUShader } from './webgpu-shader';
6
+ import type { WebGPURenderPass } from './webgpu-render-pass';
6
7
  /** Creates a new render pipeline when parameters change */
7
- export default class WebGPURenderPipeline extends RenderPipeline {
8
+ export declare class WebGPURenderPipeline extends RenderPipeline {
8
9
  device: WebGPUDevice;
9
10
  handle: GPURenderPipeline;
11
+ vs: WebGPUShader;
12
+ fs: WebGPUShader | null;
10
13
  private _bufferSlots;
11
14
  private _buffers;
12
15
  private _indexBuffer;
@@ -14,17 +17,18 @@ export default class WebGPURenderPipeline extends RenderPipeline {
14
17
  private _bindGroupLayout;
15
18
  private _bindGroup;
16
19
  constructor(device: WebGPUDevice, props: RenderPipelineProps);
17
- protected createHandle(): GPURenderPipeline;
18
20
  destroy(): void;
19
21
  setIndexBuffer(indexBuffer: Buffer): void;
20
22
  setAttributes(attributes: Record<string, Buffer>): void;
21
- /** Set the bindings */
23
+ setConstantAttributes(attributes: Record<string, TypedArray>): void;
22
24
  setBindings(bindings: Record<string, Binding>): void;
23
- setUniforms(uniforms: Record<string, any>): void;
25
+ setUniforms(uniforms: Record<string, UniformValue>): void;
24
26
  _getBuffers(): Buffer[];
25
27
  /** Return a bind group created by setBindings */
26
28
  _getBindGroup(): GPUBindGroup;
27
- /** Populate the complex WebGPU GPURenderPipelineDescriptor */
29
+ /**
30
+ * Populate the complex WebGPU GPURenderPipelineDescriptor
31
+ */
28
32
  protected _getRenderPipelineDescriptor(): GPURenderPipelineDescriptor;
29
33
  draw(options: {
30
34
  renderPass?: RenderPass;
@@ -1 +1 @@
1
- {"version":3,"file":"webgpu-render-pipeline.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgpu-render-pipeline.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAC,OAAO,EAAE,UAAU,EAAC,MAAM,cAAc,CAAC;AACtD,OAAO,EAAC,MAAM,EAAE,cAAc,EAAE,mBAAmB,EAA2B,MAAM,cAAc,CAAC;AASnG,OAAO,KAAK,YAAY,MAAM,kBAAkB,CAAC;AAGjD,OAAO,KAAK,gBAAgB,MAAM,sBAAsB,CAAC;AAIzD,2DAA2D;AAC3D,MAAM,CAAC,OAAO,OAAO,oBAAqB,SAAQ,cAAc;IAC9D,MAAM,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE,iBAAiB,CAAC;IAE1B,OAAO,CAAC,YAAY,CAAyB;IAC7C,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,YAAY,CAAe;IAInC,4CAA4C;IAC5C,OAAO,CAAC,gBAAgB,CAAqB;IAC7C,OAAO,CAAC,UAAU,CAAsB;gBAE5B,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,mBAAmB;IAW5D,SAAS,CAAC,YAAY,IAAI,iBAAiB;IAS3C,OAAO;IAIP,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAIzC,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IAmBvD,uBAAuB;IACvB,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAapD,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAMhD,WAAW;IAIX,iDAAiD;IACjD,aAAa;IAK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U,CAA6B;gBAEnC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,mBAAmB;IAoBnD,OAAO,IAAI,IAAI;IAIxB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAIzC,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IAmBvD,qBAAqB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,IAAI;IAInE,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAkBpD,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,IAAI;IAMzD,WAAW;IAIX,iDAAiD;IACjD,aAAa;IAKb;;OAEG;IACH,SAAS,CAAC,4BAA4B;IA+CtC,IAAI,CAAC,OAAO,EAAE;QACZ,UAAU,CAAC,EAAE,UAAU,CAAC;QACxB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,GAAG,IAAI;IAkCR,oBAAoB,CAAC,gBAAgB,EAAE,gBAAgB;CAwCxD"}
@@ -1,148 +1,131 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import { RenderPipeline, cast, log, isObjectEmpty } from '@luma.gl/api';
3
- import { applyParametersToRenderPipelineDescriptor } from '../helpers/webgpu-parameters';
4
- import { getWebGPUTextureFormat } from '../helpers/convert-texture-format';
5
- import { getBindGroup } from '../helpers/get-bind-group';
6
- import { getVertexBufferLayout, getBufferSlots } from '../helpers/get-vertex-buffer-layout';
7
- export default class WebGPURenderPipeline extends RenderPipeline {
1
+ import { RenderPipeline, cast, log, isObjectEmpty } from '@luma.gl/core';
2
+ import { applyParametersToRenderPipelineDescriptor } from "../helpers/webgpu-parameters.js";
3
+ import { getWebGPUTextureFormat } from "../helpers/convert-texture-format.js";
4
+ import { getBindGroup } from "../helpers/get-bind-group.js";
5
+ import { getVertexBufferLayout, getBufferSlots } from "../helpers/get-vertex-buffer-layout.js";
6
+ export class WebGPURenderPipeline extends RenderPipeline {
8
7
  constructor(device, props) {
9
8
  super(device, props);
10
-
11
- _defineProperty(this, "device", void 0);
12
-
13
- _defineProperty(this, "handle", void 0);
14
-
15
- _defineProperty(this, "_bufferSlots", void 0);
16
-
17
- _defineProperty(this, "_buffers", void 0);
18
-
19
- _defineProperty(this, "_indexBuffer", void 0);
20
-
21
- _defineProperty(this, "_bindGroupLayout", void 0);
22
-
23
- _defineProperty(this, "_bindGroup", null);
24
-
9
+ this.device = void 0;
10
+ this.handle = void 0;
11
+ this.vs = void 0;
12
+ this.fs = null;
13
+ this._bufferSlots = void 0;
14
+ this._buffers = void 0;
15
+ this._indexBuffer = null;
16
+ this._bindGroupLayout = null;
17
+ this._bindGroup = null;
25
18
  this.device = device;
26
- this.handle = this.props.handle || this.createHandle();
19
+ this.handle = this.props.handle;
20
+ if (!this.handle) {
21
+ const descriptor = this._getRenderPipelineDescriptor();
22
+ log.groupCollapsed(1, `new WebGPURenderPipeline(${this.id})`)();
23
+ log.probe(1, JSON.stringify(descriptor, null, 2))();
24
+ log.groupEnd(1)();
25
+ this.handle = this.device.handle.createRenderPipeline(descriptor);
26
+ }
27
27
  this.handle.label = this.props.id;
28
- this._bufferSlots = getBufferSlots(this.props.layout, this.props.bufferMap);
28
+ this.vs = cast(props.vs);
29
+ this.fs = cast(props.fs);
30
+ this._bufferSlots = getBufferSlots(this.props.shaderLayout, this.props.bufferLayout);
29
31
  this._buffers = new Array(Object.keys(this._bufferSlots).length).fill(null);
30
- this._bindGroupLayout = this.handle.getBindGroupLayout(0);
31
- }
32
-
33
- createHandle() {
34
- const descriptor = this._getRenderPipelineDescriptor();
35
-
36
- const renderPipeline = this.device.handle.createRenderPipeline(descriptor);
37
- log.groupCollapsed(1, "new WebGPRenderPipeline(".concat(this.id, ")"))();
38
- log.log(1, JSON.stringify(descriptor, null, 2))();
39
- log.groupEnd(1)();
40
- return renderPipeline;
41
32
  }
42
-
43
33
  destroy() {}
44
-
45
34
  setIndexBuffer(indexBuffer) {
46
35
  this._indexBuffer = cast(indexBuffer);
47
36
  }
48
-
49
37
  setAttributes(attributes) {
50
38
  for (const [name, buffer] of Object.entries(attributes)) {
51
39
  const bufferIndex = this._bufferSlots[name];
52
-
53
40
  if (bufferIndex >= 0) {
54
41
  this._buffers[bufferIndex] = buffer;
55
42
  } else {
56
- throw new Error("Setting attribute '".concat(name, "' not listed in shader layout for program ").concat(this.id));
43
+ throw new Error(`Setting attribute '${name}' not listed in shader layout for program ${this.id}`);
57
44
  }
58
45
  }
59
46
  }
60
-
47
+ setConstantAttributes(attributes) {
48
+ throw new Error('not implemented');
49
+ }
61
50
  setBindings(bindings) {
62
51
  if (!isObjectEmpty(this.props.bindings)) {
63
52
  Object.assign(this.props.bindings, bindings);
64
- this._bindGroup = getBindGroup(this.device.handle, this._bindGroupLayout, this.props.layout, this.props.bindings);
53
+ this._bindGroupLayout = this._bindGroupLayout || this.handle.getBindGroupLayout(0);
54
+ this._bindGroup = getBindGroup(this.device.handle, this._bindGroupLayout, this.props.shaderLayout, this.props.bindings);
65
55
  }
66
56
  }
67
-
68
57
  setUniforms(uniforms) {
69
58
  if (!isObjectEmpty(uniforms)) {
70
59
  throw new Error('WebGPU does not support uniforms');
71
60
  }
72
61
  }
73
-
74
62
  _getBuffers() {
75
63
  return this._buffers;
76
64
  }
77
-
78
65
  _getBindGroup() {
79
66
  return this._bindGroup;
80
67
  }
81
-
82
68
  _getRenderPipelineDescriptor() {
83
69
  const vertex = {
84
70
  module: cast(this.props.vs).handle,
85
71
  entryPoint: this.props.vsEntryPoint || 'main',
86
- buffers: getVertexBufferLayout(this.props.layout, this.props.bufferMap)
72
+ buffers: getVertexBufferLayout(this.props.shaderLayout, this.props.bufferLayout)
87
73
  };
88
74
  let fragment;
89
-
90
75
  if (this.props.fs) {
76
+ var _this$device;
91
77
  fragment = {
92
78
  module: cast(this.props.fs).handle,
93
79
  entryPoint: this.props.fsEntryPoint || 'main',
94
80
  targets: [{
95
- format: getWebGPUTextureFormat(this.device.canvasContext.format)
81
+ format: getWebGPUTextureFormat((_this$device = this.device) === null || _this$device === void 0 || (_this$device = _this$device.canvasContext) === null || _this$device === void 0 ? void 0 : _this$device.format)
96
82
  }]
97
83
  };
98
84
  }
99
-
100
- let descriptor = {
85
+ switch (this.props.topology) {
86
+ case 'triangle-fan-webgl':
87
+ case 'line-loop-webgl':
88
+ throw new Error(`WebGPU does not support primitive topology ${this.props.topology}`);
89
+ default:
90
+ }
91
+ const descriptor = {
101
92
  vertex,
102
93
  fragment,
103
94
  primitive: {
104
95
  topology: this.props.topology
105
- }
96
+ },
97
+ layout: 'auto'
106
98
  };
107
99
  applyParametersToRenderPipelineDescriptor(descriptor, this.props.parameters);
108
100
  return descriptor;
109
101
  }
110
-
111
102
  draw(options) {
112
103
  const webgpuRenderPass = cast(options.renderPass) || this.device.getDefaultRenderPass();
113
104
  webgpuRenderPass.handle.setPipeline(this.handle);
114
-
115
- if (this._getBindGroup()) {
116
- webgpuRenderPass.handle.setBindGroup(0, this._getBindGroup());
105
+ const bindGroup = this._getBindGroup();
106
+ if (bindGroup) {
107
+ webgpuRenderPass.handle.setBindGroup(0, bindGroup);
117
108
  }
118
-
119
109
  this._setAttributeBuffers(webgpuRenderPass);
120
-
121
110
  if (options.indexCount) {
122
111
  webgpuRenderPass.handle.drawIndexed(options.indexCount, options.instanceCount, options.firstIndex, options.baseVertex, options.firstInstance);
123
112
  } else {
124
- webgpuRenderPass.handle.draw(options.vertexCount, options.instanceCount, options.firstIndex, options.firstInstance);
113
+ webgpuRenderPass.handle.draw(options.vertexCount || 0, options.instanceCount || 1, options.firstInstance);
125
114
  }
126
115
  }
127
-
128
116
  _setAttributeBuffers(webgpuRenderPass) {
129
117
  if (this._indexBuffer) {
130
118
  webgpuRenderPass.handle.setIndexBuffer(this._indexBuffer.handle, this._indexBuffer.props.indexType);
131
119
  }
132
-
133
120
  const buffers = this._getBuffers();
134
-
135
121
  for (let i = 0; i < buffers.length; ++i) {
136
122
  const buffer = cast(buffers[i]);
137
-
138
123
  if (!buffer) {
139
- const attribute = this.props.layout.attributes.find(attribute => attribute.location === i);
140
- throw new Error("No buffer provided for attribute '".concat((attribute === null || attribute === void 0 ? void 0 : attribute.name) || '', "' in Model '").concat(this.props.id, "'"));
124
+ const attribute = this.props.shaderLayout.attributes.find(attribute => attribute.location === i);
125
+ throw new Error(`No buffer provided for attribute '${(attribute === null || attribute === void 0 ? void 0 : attribute.name) || ''}' in Model '${this.props.id}'`);
141
126
  }
142
-
143
127
  webgpuRenderPass.handle.setVertexBuffer(i, buffer.handle);
144
128
  }
145
129
  }
146
-
147
130
  }
148
131
  //# sourceMappingURL=webgpu-render-pipeline.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/adapter/resources/webgpu-render-pipeline.ts"],"names":["RenderPipeline","cast","log","isObjectEmpty","applyParametersToRenderPipelineDescriptor","getWebGPUTextureFormat","getBindGroup","getVertexBufferLayout","getBufferSlots","WebGPURenderPipeline","constructor","device","props","handle","createHandle","label","id","_bufferSlots","layout","bufferMap","_buffers","Array","Object","keys","length","fill","_bindGroupLayout","getBindGroupLayout","descriptor","_getRenderPipelineDescriptor","renderPipeline","createRenderPipeline","groupCollapsed","JSON","stringify","groupEnd","destroy","setIndexBuffer","indexBuffer","_indexBuffer","setAttributes","attributes","name","buffer","entries","bufferIndex","Error","setBindings","bindings","assign","_bindGroup","setUniforms","uniforms","_getBuffers","_getBindGroup","vertex","module","vs","entryPoint","vsEntryPoint","buffers","fragment","fs","fsEntryPoint","targets","format","canvasContext","primitive","topology","parameters","draw","options","webgpuRenderPass","renderPass","getDefaultRenderPass","setPipeline","setBindGroup","_setAttributeBuffers","indexCount","drawIndexed","instanceCount","firstIndex","baseVertex","firstInstance","vertexCount","indexType","i","attribute","find","location","setVertexBuffer"],"mappings":";AACA,SAAgBA,cAAhB,EAAqDC,IAArD,EAA2DC,GAA3D,EAAgEC,aAAhE,QAAoF,cAApF;AACA,SAAQC,yCAAR,QAAwD,8BAAxD;AACA,SAAQC,sBAAR,QAAqC,mCAArC;AACA,SAAQC,YAAR,QAA2B,2BAA3B;AACA,SAAQC,qBAAR,EAA+BC,cAA/B,QAAoD,qCAApD;AAaA,eAAe,MAAMC,oBAAN,SAAmCT,cAAnC,CAAkD;AAc/DU,EAAAA,WAAW,CAACC,MAAD,EAAuBC,KAAvB,EAAmD;AAC5D,UAAMD,MAAN,EAAcC,KAAd;;AAD4D;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA,wCAF3B,IAE2B;;AAE5D,SAAKD,MAAL,GAAcA,MAAd;AACA,SAAKE,MAAL,GAAe,KAAKD,KAAL,CAAWC,MAAZ,IAA4C,KAAKC,YAAL,EAA1D;AACA,SAAKD,MAAL,CAAYE,KAAZ,GAAoB,KAAKH,KAAL,CAAWI,EAA/B;AAEA,SAAKC,YAAL,GAAoBT,cAAc,CAAC,KAAKI,KAAL,CAAWM,MAAZ,EAAoB,KAAKN,KAAL,CAAWO,SAA/B,CAAlC;AACA,SAAKC,QAAL,GAAgB,IAAIC,KAAJ,CAAkBC,MAAM,CAACC,IAAP,CAAY,KAAKN,YAAjB,EAA+BO,MAAjD,EAAyDC,IAAzD,CAA8D,IAA9D,CAAhB;AACA,SAAKC,gBAAL,GAAwB,KAAKb,MAAL,CAAYc,kBAAZ,CAA+B,CAA/B,CAAxB;AACD;;AAESb,EAAAA,YAAY,GAAsB;AAC1C,UAAMc,UAAU,GAAG,KAAKC,4BAAL,EAAnB;;AACA,UAAMC,cAAc,GAAG,KAAKnB,MAAL,CA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ACpC,MAA5B,EAAoC,EAAE8D,CAAtC,EAAyC;AACvC,YAAM3C,MAAM,GAAG1C,IAAI,CAAe2D,OAAO,CAAC0B,CAAD,CAAtB,CAAnB;;AACA,UAAI,CAAC3C,MAAL,EAAa;AACX,cAAM4C,SAAS,GAAG,KAAK3E,KAAL,CAAWM,MAAX,CAAkBuB,UAAlB,CAA6B+C,IAA7B,CACfD,SAAD,IAAeA,SAAS,CAACE,QAAV,KAAuBH,CADtB,CAAlB;AAGA,cAAM,IAAIxC,KAAJ,6CACiC,CAAAyC,SAAS,SAAT,IAAAA,SAAS,WAAT,YAAAA,SAAS,CAAE7C,IAAX,KAAmB,EADpD,yBACqE,KAAK9B,KAAL,CAAWI,EADhF,OAAN;AAGD;;AACDwD,MAAAA,gBAAgB,CAAC3D,MAAjB,CAAwB6E,eAAxB,CAAwCJ,CAAxC,EAA2C3C,MAAM,CAAC9B,MAAlD;AACD;AAsBF;;AAnN8D","sourcesContent":["import type {Binding, RenderPass} from '@luma.gl/api';\nimport {Buffer, RenderPipeline, RenderPipelineProps, cast, log, isObjectEmpty} from '@luma.gl/api';\nimport {applyParametersToRenderPipelineDescriptor} from '../helpers/webgpu-parameters';\nimport {getWebGPUTextureFormat} from '../helpers/convert-texture-format';\nimport {getBindGroup} from '../helpers/get-bind-group';\nimport {getVertexBufferLayout, getBufferSlots} from '../helpers/get-vertex-buffer-layout';\n// import {convertAttributesVertexBufferToLayout} from '../helpers/get-vertex-buffer-layout';\n// import {mapAccessorToWebGPUFormat} from './helpers/accessor-to-format';\n// import type {BufferAccessors} from './webgpu-pipeline';\n\nimport type WebGPUDevice from '../webgpu-device';\nimport type WebGPUBuffer from './webgpu-buffer';\nimport type WebGPUShader from './webgpu-shader';\nimport type WebGPURenderPass from './webgpu-render-pass';\n\n// RENDER PIPELINE\n\n/** Creates a new render pipeline when parameters change */\nexport default class WebGPURenderPipeline extends RenderPipeline {\n device: WebGPUDevice;\n handle: GPURenderPipeline;\n\n private _bufferSlots: Record<string, number>;\n private _buffers: Buffer[];\n private _indexBuffer: WebGPUBuffer;\n // private _firstIndex: number;\n // private _lastIndex: number;\n\n /** For internal use to create BindGroups */\n private _bindGroupLayout: GPUBindGroupLayout;\n private _bindGroup: GPUBindGroup = null;\n\n constructor(device: WebGPUDevice, props: RenderPipelineProps) {\n super(device, props);\n this.device = device;\n this.handle = (this.props.handle as GPURenderPipeline) || this.createHandle();\n this.handle.label = this.props.id;\n\n this._bufferSlots = getBufferSlots(this.props.layout, this.props.bufferMap);\n this._buffers = new Array<Buffer>(Object.keys(this._bufferSlots).length).fill(null);\n this._bindGroupLayout = this.handle.getBindGroupLayout(0);\n }\n\n protected createHandle(): GPURenderPipeline {\n const descriptor = this._getRenderPipelineDescriptor();\n const renderPipeline = this.device.handle.createRenderPipeline(descriptor);\n log.groupCollapsed(1, `new WebGPRenderPipeline(${this.id})`)();\n log.log(1, JSON.stringify(descriptor, null, 2))();\n log.groupEnd(1)();\n return renderPipeline;\n }\n\n destroy() {\n // WebGPURenderPipeline has no destroy method.\n }\n\n setIndexBuffer(indexBuffer: Buffer): void {\n this._indexBuffer = cast<WebGPUBuffer>(indexBuffer);\n }\n\n setAttributes(attributes: Record<string, Buffer>): void {\n for (const [name, buffer] of Object.entries(attributes)) {\n const bufferIndex = this._bufferSlots[name];\n if (bufferIndex >= 0) {\n this._buffers[bufferIndex] = buffer;\n } else {\n throw new Error(\n `Setting attribute '${name}' not listed in shader layout for program ${this.id}`\n );\n }\n }\n // for (let i = 0; i < this._bufferSlots.length; ++i) {\n // const bufferName = this._bufferSlots[i];\n // if (attributes[bufferName]) {\n // this.handle\n // }\n // }\n }\n\n /** Set the bindings */\n setBindings(bindings: Record<string, Binding>): void {\n if (!isObjectEmpty(this.props.bindings)) {\n Object.assign(this.props.bindings, bindings);\n // Set up the bindings\n this._bindGroup = getBindGroup(\n this.device.handle,\n this._bindGroupLayout,\n this.props.layout,\n this.props.bindings\n );\n }\n }\n\n setUniforms(uniforms: Record<string, any>): void {\n if (!isObjectEmpty(uniforms)) {\n throw new Error('WebGPU does not support uniforms');\n }\n }\n\n _getBuffers() {\n return this._buffers;\n }\n\n /** Return a bind group created by setBindings */\n _getBindGroup() {\n // assert(this._bindGroup);\n return this._bindGroup;\n }\n\n /** Populate the complex WebGPU GPURenderPipelineDescriptor */\n protected _getRenderPipelineDescriptor() {\n // Set up the vertex stage\n const vertex: GPUVertexState = {\n module: cast<WebGPUShader>(this.props.vs).handle,\n entryPoint: this.props.vsEntryPoint || 'main',\n buffers: getVertexBufferLayout(this.props.layout, this.props.bufferMap)\n };\n\n // Set up the fragment stage\n let fragment: GPUFragmentState | undefined;\n if (this.props.fs) {\n fragment = {\n module: cast<WebGPUShader>(this.props.fs).handle,\n entryPoint: this.props.fsEntryPoint || 'main',\n targets: [\n {\n format: getWebGPUTextureFormat(this.device.canvasContext.format)\n }\n ]\n };\n }\n\n // Create a partially populated descriptor\n let descriptor: GPURenderPipelineDescriptor = {\n vertex,\n fragment,\n primitive: {\n topology: this.props.topology\n }\n };\n\n // Set parameters on the descriptor\n applyParametersToRenderPipelineDescriptor(descriptor, this.props.parameters);\n\n return descriptor;\n }\n\n draw(options: {\n renderPass?: RenderPass;\n vertexCount?: number;\n indexCount?: number;\n instanceCount?: number;\n firstVertex?: number;\n firstIndex?: number;\n firstInstance?: number;\n baseVertex?: number;\n }): void {\n const webgpuRenderPass =\n cast<WebGPURenderPass>(options.renderPass) || this.device.getDefaultRenderPass();\n\n // Set pipeline\n webgpuRenderPass.handle.setPipeline(this.handle);\n\n // Set bindings (uniform buffers, textures etc)\n if (this._getBindGroup()) {\n webgpuRenderPass.handle.setBindGroup(0, this._getBindGroup());\n }\n\n // Set attributes\n this._setAttributeBuffers(webgpuRenderPass);\n\n // Draw\n if (options.indexCount) {\n webgpuRenderPass.handle.drawIndexed(\n options.indexCount,\n options.instanceCount,\n options.firstIndex,\n options.baseVertex,\n options.firstInstance\n );\n } else {\n webgpuRenderPass.handle.draw(\n options.vertexCount,\n options.instanceCount,\n options.firstIndex,\n options.firstInstance\n );\n }\n }\n\n _setAttributeBuffers(webgpuRenderPass: WebGPURenderPass) {\n if (this._indexBuffer) {\n webgpuRenderPass.handle.setIndexBuffer(this._indexBuffer.handle, this._indexBuffer.props.indexType);\n }\n\n const buffers = this._getBuffers();\n for (let i = 0; i < buffers.length; ++i) {\n const buffer = cast<WebGPUBuffer>(buffers[i]);\n if (!buffer) {\n const attribute = this.props.layout.attributes.find(\n (attribute) => attribute.location === i\n );\n throw new Error(\n `No buffer provided for attribute '${attribute?.name || ''}' in Model '${this.props.id}'`\n );\n }\n webgpuRenderPass.handle.setVertexBuffer(i, buffer.handle);\n }\n\n // TODO - HANDLE buffer maps\n /*\n for (const [bufferName, attributeMapping] of Object.entries(this.props.bufferMap)) {\n const buffer = cast<WebGPUBuffer>(this.props.attributes[bufferName]);\n if (!buffer) {\n log.warn(`Missing buffer for buffer map ${bufferName}`)();\n continue;\n }\n\n if ('location' in attributeMapping) {\n // @ts-expect-error TODO model must not depend on webgpu\n renderPass.handle.setVertexBuffer(layout.location, buffer.handle);\n } else {\n for (const [bufferName, mapping] of Object.entries(attributeMapping)) {\n // @ts-expect-error TODO model must not depend on webgpu\n renderPass.handle.setVertexBuffer(field.location, buffer.handle);\n }\n }\n }\n */\n }\n}\n"],"file":"webgpu-render-pipeline.js"}
1
+ {"version":3,"file":"webgpu-render-pipeline.js","names":["RenderPipeline","cast","log","isObjectEmpty","applyParametersToRenderPipelineDescriptor","getWebGPUTextureFormat","getBindGroup","getVertexBufferLayout","getBufferSlots","WebGPURenderPipeline","constructor","device","props","handle","vs","fs","_bufferSlots","_buffers","_indexBuffer","_bindGroupLayout","_bindGroup","descriptor","_getRenderPipelineDescriptor","groupCollapsed","id","probe","JSON","stringify","groupEnd","createRenderPipeline","label","shaderLayout","bufferLayout","Array","Object","keys","length","fill","destroy","setIndexBuffer","indexBuffer","setAttributes","attributes","name","buffer","entries","bufferIndex","Error","setConstantAttributes","setBindings","bindings","assign","getBindGroupLayout","setUniforms","uniforms","_getBuffers","_getBindGroup","vertex","module","entryPoint","vsEntryPoint","buffers","fragment","_this$device","fsEntryPoint","targets","format","canvasContext","topology","primitive","layout","parameters","draw","options","webgpuRenderPass","renderPass","getDefaultRenderPass","setPipeline","bindGroup","setBindGroup","_setAttributeBuffers","indexCount","drawIndexed","instanceCount","firstIndex","baseVertex","firstInstance","vertexCount","indexType","i","attribute","find","location","setVertexBuffer"],"sources":["../../../src/adapter/resources/webgpu-render-pipeline.ts"],"sourcesContent":["// luma.gl MIT license\n\nimport type {TypedArray, Binding, UniformValue, RenderPass} from '@luma.gl/core';\nimport {Buffer, RenderPipeline, RenderPipelineProps, cast, log, isObjectEmpty} from '@luma.gl/core';\nimport {applyParametersToRenderPipelineDescriptor} from '../helpers/webgpu-parameters';\nimport {getWebGPUTextureFormat} from '../helpers/convert-texture-format';\nimport {getBindGroup} from '../helpers/get-bind-group';\nimport {getVertexBufferLayout, getBufferSlots} from '../helpers/get-vertex-buffer-layout';\n// import {convertAttributesVertexBufferToLayout} from '../helpers/get-vertex-buffer-layout';\n// import {mapAccessorToWebGPUFormat} from './helpers/accessor-to-format';\n// import type {BufferAccessors} from './webgpu-pipeline';\n\nimport type {WebGPUDevice} from '../webgpu-device';\nimport type {WebGPUBuffer} from './webgpu-buffer';\nimport type {WebGPUShader} from './webgpu-shader';\nimport type {WebGPURenderPass} from './webgpu-render-pass';\n\n// RENDER PIPELINE\n\n/** Creates a new render pipeline when parameters change */\nexport class WebGPURenderPipeline extends RenderPipeline {\n device: WebGPUDevice;\n handle: GPURenderPipeline;\n\n vs: WebGPUShader;\n fs: WebGPUShader | null = null;\n\n private _bufferSlots: Record<string, number>;\n private _buffers: Buffer[];\n private _indexBuffer: WebGPUBuffer | null = null;\n // private _firstIndex: number;\n // private _lastIndex: number;\n\n /** For internal use to create BindGroups */\n private _bindGroupLayout: GPUBindGroupLayout | null = null;\n private _bindGroup: GPUBindGroup | null = null;\n\n constructor(device: WebGPUDevice, props: RenderPipelineProps) {\n super(device, props);\n this.device = device;\n this.handle = this.props.handle as GPURenderPipeline;\n if (!this.handle) {\n const descriptor = this._getRenderPipelineDescriptor();\n log.groupCollapsed(1, `new WebGPURenderPipeline(${this.id})`)();\n log.probe(1, JSON.stringify(descriptor, null, 2))();\n log.groupEnd(1)();\n this.handle = this.device.handle.createRenderPipeline(descriptor); \n }\n this.handle.label = this.props.id;\n\n this.vs = cast<WebGPUShader>(props.vs);\n this.fs = cast<WebGPUShader>(props.fs);\n\n this._bufferSlots = getBufferSlots(this.props.shaderLayout, this.props.bufferLayout);\n this._buffers = new Array<Buffer>(Object.keys(this._bufferSlots).length).fill(null);\n }\n\n override destroy(): void {\n // WebGPURenderPipeline has no destroy method.\n }\n\n setIndexBuffer(indexBuffer: Buffer): void {\n this._indexBuffer = cast<WebGPUBuffer>(indexBuffer);\n }\n\n setAttributes(attributes: Record<string, Buffer>): void {\n for (const [name, buffer] of Object.entries(attributes)) {\n const bufferIndex = this._bufferSlots[name];\n if (bufferIndex >= 0) {\n this._buffers[bufferIndex] = buffer;\n } else {\n throw new Error(\n `Setting attribute '${name}' not listed in shader layout for program ${this.id}`\n );\n }\n }\n // for (let i = 0; i < this._bufferSlots.length; ++i) {\n // const bufferName = this._bufferSlots[i];\n // if (attributes[bufferName]) {\n // this.handle\n // }\n // }\n }\n\n setConstantAttributes(attributes: Record<string, TypedArray>): void {\n throw new Error('not implemented');\n }\n\n setBindings(bindings: Record<string, Binding>): void {\n if (!isObjectEmpty(this.props.bindings)) {\n // Do we want to save things on CPU side?\n Object.assign(this.props.bindings, bindings);\n\n // Get hold of the bind group layout. We don't want to do this unless we know there is at least one bind group\n this._bindGroupLayout = this._bindGroupLayout || this.handle.getBindGroupLayout(0);\n\n // Set up the bindings\n this._bindGroup = getBindGroup(\n this.device.handle,\n this._bindGroupLayout,\n this.props.shaderLayout,\n this.props.bindings\n );\n }\n }\n\n setUniforms(uniforms: Record<string, UniformValue>): void {\n if (!isObjectEmpty(uniforms)) {\n throw new Error('WebGPU does not support uniforms');\n }\n }\n\n _getBuffers() {\n return this._buffers;\n }\n\n /** Return a bind group created by setBindings */\n _getBindGroup() {\n // assert(this._bindGroup);\n return this._bindGroup;\n }\n\n /** \n * Populate the complex WebGPU GPURenderPipelineDescriptor \n */\n protected _getRenderPipelineDescriptor() {\n // Set up the vertex stage\n const vertex: GPUVertexState = {\n module: cast<WebGPUShader>(this.props.vs).handle,\n entryPoint: this.props.vsEntryPoint || 'main',\n buffers: getVertexBufferLayout(this.props.shaderLayout, this.props.bufferLayout)\n };\n\n // Set up the fragment stage\n let fragment: GPUFragmentState | undefined;\n if (this.props.fs) {\n fragment = {\n module: cast<WebGPUShader>(this.props.fs).handle,\n entryPoint: this.props.fsEntryPoint || 'main',\n targets: [\n {\n // TODO exclamation mark hack!\n format: getWebGPUTextureFormat(this.device?.canvasContext?.format)\n }\n ]\n };\n }\n\n // WebGPU has more restrictive topology support than WebGL\n switch (this.props.topology) {\n case 'triangle-fan-webgl':\n case 'line-loop-webgl':\n throw new Error(`WebGPU does not support primitive topology ${this.props.topology}`);\n default:\n }\n\n // Create a partially populated descriptor\n const descriptor: GPURenderPipelineDescriptor = {\n vertex,\n fragment,\n primitive: {\n topology: this.props.topology\n },\n layout: 'auto'\n };\n\n // Set parameters on the descriptor\n applyParametersToRenderPipelineDescriptor(descriptor, this.props.parameters);\n\n return descriptor;\n }\n\n draw(options: {\n renderPass?: RenderPass;\n vertexCount?: number;\n indexCount?: number;\n instanceCount?: number;\n firstVertex?: number;\n firstIndex?: number;\n firstInstance?: number;\n baseVertex?: number;\n }): void {\n const webgpuRenderPass: WebGPURenderPass =\n cast<WebGPURenderPass>(options.renderPass) || this.device.getDefaultRenderPass();\n\n // Set pipeline\n webgpuRenderPass.handle.setPipeline(this.handle);\n\n // Set bindings (uniform buffers, textures etc)\n const bindGroup = this._getBindGroup();\n if (bindGroup) {\n webgpuRenderPass.handle.setBindGroup(0, bindGroup);\n }\n\n // Set attributes\n this._setAttributeBuffers(webgpuRenderPass);\n\n // Draw\n if (options.indexCount) {\n webgpuRenderPass.handle.drawIndexed(\n options.indexCount,\n options.instanceCount,\n options.firstIndex,\n options.baseVertex,\n options.firstInstance\n );\n } else {\n webgpuRenderPass.handle.draw(\n options.vertexCount || 0,\n options.instanceCount || 1, // If 0, nothing will be drawn\n options.firstInstance\n );\n }\n }\n\n _setAttributeBuffers(webgpuRenderPass: WebGPURenderPass) {\n if (this._indexBuffer) {\n webgpuRenderPass.handle.setIndexBuffer(this._indexBuffer.handle, this._indexBuffer.props.indexType);\n }\n\n const buffers = this._getBuffers();\n for (let i = 0; i < buffers.length; ++i) {\n const buffer = cast<WebGPUBuffer>(buffers[i]);\n if (!buffer) {\n const attribute = this.props.shaderLayout.attributes.find(\n (attribute) => attribute.location === i\n );\n throw new Error(\n `No buffer provided for attribute '${attribute?.name || ''}' in Model '${this.props.id}'`\n );\n }\n webgpuRenderPass.handle.setVertexBuffer(i, buffer.handle);\n }\n\n // TODO - HANDLE buffer maps\n /*\n for (const [bufferName, attributeMapping] of Object.entries(this.props.bufferLayout)) {\n const buffer = cast<WebGPUBuffer>(this.props.attributes[bufferName]);\n if (!buffer) {\n log.warn(`Missing buffer for buffer map ${bufferName}`)();\n continue;\n }\n\n if ('location' in attributeMapping) {\n // @ts-expect-error TODO model must not depend on webgpu\n renderPass.handle.setVertexBuffer(layout.location, buffer.handle);\n } else {\n for (const [bufferName, mapping] of Object.entries(attributeMapping)) {\n // @ts-expect-error TODO model must not depend on webgpu\n renderPass.handle.setVertexBuffer(field.location, buffer.handle);\n }\n }\n }\n */\n }\n}\n"],"mappings":"AAGA,SAAgBA,cAAc,EAAuBC,IAAI,EAAEC,GAAG,EAAEC,aAAa,QAAO,eAAe;AAAC,SAC5FC,yCAAyC;AAAA,SACzCC,sBAAsB;AAAA,SACtBC,YAAY;AAAA,SACZC,qBAAqB,EAAEC,cAAc;AAa7C,OAAO,MAAMC,oBAAoB,SAAST,cAAc,C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N,oBAAoBA,CAACN,gBAAkC,EAAE;IACvD,IAAI,IAAI,CAACxD,YAAY,EAAE;MACrBwD,gBAAgB,CAAC7D,MAAM,CAAC0B,cAAc,CAAC,IAAI,CAACrB,YAAY,CAACL,MAAM,EAAE,IAAI,CAACK,YAAY,CAACN,KAAK,CAAC4E,SAAS,CAAC;IACrG;IAEA,MAAM3B,OAAO,GAAG,IAAI,CAACN,WAAW,CAAC,CAAC;IAClC,KAAK,IAAIkC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAG5B,OAAO,CAACzB,MAAM,EAAE,EAAEqD,CAAC,EAAE;MACvC,MAAM7C,MAAM,GAAG3C,IAAI,CAAe4D,OAAO,CAAC4B,CAAC,CAAC,CAAC;MAC7C,IAAI,CAAC7C,MAAM,EAAE;QACX,MAAM8C,SAAS,GAAG,IAAI,CAAC9E,KAAK,CAACmB,YAAY,CAACW,UAAU,CAACiD,IAAI,CACtDD,SAAS,IAAKA,SAAS,CAACE,QAAQ,KAAKH,CACxC,CAAC;QACD,MAAM,IAAI1C,KAAK,CACZ,qCAAoC,CAAA2C,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAE/C,IAAI,KAAI,EAAG,eAAc,IAAI,CAAC/B,KAAK,CAACY,EAAG,GACzF,CAAC;MACH;MACAkD,gBAAgB,CAAC7D,MAAM,CAACgF,eAAe,CAACJ,CAAC,EAAE7C,MAAM,CAAC/B,MAAM,CAAC;IAC3D;EAsBF;AACF"}
@@ -1,13 +1,13 @@
1
- /// <reference types="@webgpu/types" />
2
- import { Sampler, SamplerProps } from '@luma.gl/api';
3
- import type WebGPUDevice from '../webgpu-device';
4
- export declare type WebGPUSamplerProps = SamplerProps & {
1
+ /// <reference types="dist" />
2
+ import { Sampler, SamplerProps } from '@luma.gl/core';
3
+ import type { WebGPUDevice } from '../webgpu-device';
4
+ export type WebGPUSamplerProps = SamplerProps & {
5
5
  handle?: GPUSampler;
6
6
  };
7
7
  /**
8
8
  *
9
9
  */
10
- export default class WebGPUSampler extends Sampler {
10
+ export declare class WebGPUSampler extends Sampler {
11
11
  readonly device: WebGPUDevice;
12
12
  readonly handle: GPUSampler;
13
13
  constructor(device: WebGPUDevice, props: WebGPUSamplerProps);
@@ -1 +1 @@
1
- {"version":3,"file":"webgpu-sampler.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgpu-sampler.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,OAAO,EAAE,YAAY,EAAC,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,YAAY,MAAM,kBAAkB,CAAC;AAEjD,oBAAY,kBAAkB,GAAG,YAAY,GAAG;IAC9C,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,OAAO;IAChD,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;gBAEhB,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,kBAAkB;IAO3D,OAAO,IAAI,IAAI;CAGhB"}
1
+ {"version":3,"file":"webgpu-sampler.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgpu-sampler.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,OAAO,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAEnD,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG;IAC9C,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB,CAAA;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,OAAO;IACxC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;gBAEhB,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,kBAAkB;IAclD,OAAO,IAAI,IAAI;CAGzB"}
@@ -1,19 +1,19 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import { Sampler } from '@luma.gl/api';
3
- export default class WebGPUSampler extends Sampler {
1
+ import { Sampler } from '@luma.gl/core';
2
+ export class WebGPUSampler extends Sampler {
4
3
  constructor(device, props) {
5
4
  super(device, props);
6
-
7
- _defineProperty(this, "device", void 0);
8
-
9
- _defineProperty(this, "handle", void 0);
10
-
5
+ this.device = void 0;
6
+ this.handle = void 0;
11
7
  this.device = device;
12
- this.handle = this.handle || this.device.handle.createSampler(this.props);
8
+ const samplerProps = {
9
+ ...this.props
10
+ };
11
+ if (samplerProps.type !== 'comparison-sampler') {
12
+ delete samplerProps.compare;
13
+ }
14
+ this.handle = this.handle || this.device.handle.createSampler(samplerProps);
13
15
  this.handle.label = this.props.id;
14
16
  }
15
-
16
17
  destroy() {}
17
-
18
18
  }
19
19
  //# sourceMappingURL=webgpu-sampler.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/adapter/resources/webgpu-sampler.ts"],"names":["Sampler","WebGPUSampler","constructor","device","props","handle","createSampler","label","id","destroy"],"mappings":";AAAA,SAAQA,OAAR,QAAoC,cAApC;AAUA,eAAe,MAAMC,aAAN,SAA4BD,OAA5B,CAAoC;AAIjDE,EAAAA,WAAW,CAACC,MAAD,EAAuBC,KAAvB,EAAkD;AAC3D,UAAMD,MAAN,EAAcC,KAAd;;AAD2D;;AAAA;;AAE3D,SAAKD,MAAL,GAAcA,MAAd;AACA,SAAKE,MAAL,GAAc,KAAKA,MAAL,IAAe,KAAKF,MAAL,CAAYE,MAAZ,CAAmBC,aAAnB,CAAiC,KAAKF,KAAtC,CAA7B;AACA,SAAKC,MAAL,CAAYE,KAAZ,GAAoB,KAAKH,KAAL,CAAWI,EAA/B;AACD;;AAEDC,EAAAA,OAAO,GAAS,CAEf;;AAbgD","sourcesContent":["import {Sampler, SamplerProps} from '@luma.gl/api';\nimport type WebGPUDevice from '../webgpu-device';\n\nexport type WebGPUSamplerProps = SamplerProps & {\n handle?: GPUSampler;\n}\n\n/**\n *\n */\nexport default class WebGPUSampler extends Sampler {\n readonly device: WebGPUDevice;\n readonly handle: GPUSampler;\n\n constructor(device: WebGPUDevice, props: WebGPUSamplerProps) {\n super(device, props);\n this.device = device;\n this.handle = this.handle || this.device.handle.createSampler(this.props);\n this.handle.label = this.props.id;\n }\n\n destroy(): void {\n // this.handle.destroy();\n }\n}\n"],"file":"webgpu-sampler.js"}
1
+ {"version":3,"file":"webgpu-sampler.js","names":["Sampler","WebGPUSampler","constructor","device","props","handle","samplerProps","type","compare","createSampler","label","id","destroy"],"sources":["../../../src/adapter/resources/webgpu-sampler.ts"],"sourcesContent":["import {Sampler, SamplerProps} from '@luma.gl/core';\nimport type {WebGPUDevice} from '../webgpu-device';\n\nexport type WebGPUSamplerProps = SamplerProps & {\n handle?: GPUSampler;\n}\n\n/**\n *\n */\nexport class WebGPUSampler extends Sampler {\n readonly device: WebGPUDevice;\n readonly handle: GPUSampler;\n\n constructor(device: WebGPUDevice, props: WebGPUSamplerProps) {\n super(device, props);\n this.device = device;\n\n // Prepare sampler props\n const samplerProps: Partial<WebGPUSamplerProps> = {...this.props};\n if (samplerProps.type !== 'comparison-sampler') {\n delete samplerProps.compare;\n }\n\n this.handle = this.handle || this.device.handle.createSampler(samplerProps);\n this.handle.label = this.props.id;\n }\n\n override destroy(): void {\n // this.handle.destroy();\n }\n}\n"],"mappings":"AAAA,SAAQA,OAAO,QAAqB,eAAe;AAUnD,OAAO,MAAMC,aAAa,SAASD,OAAO,CAAC;EAIzCE,WAAWA,CAACC,MAAoB,EAAEC,KAAyB,EAAE;IAC3D,KAAK,CAACD,MAAM,EAAEC,KAAK,CAAC;IAAC,KAJdD,MAAM;IAAA,KACNE,MAAM;IAIb,IAAI,CAACF,MAAM,GAAGA,MAAM;IAGpB,MAAMG,YAAyC,GAAG;MAAC,GAAG,IAAI,CAACF;IAAK,CAAC;IACjE,IAAIE,YAAY,CAACC,IAAI,KAAK,oBAAoB,EAAE;MAC9C,OAAOD,YAAY,CAACE,OAAO;IAC7B;IAEA,IAAI,CAACH,MAAM,GAAG,IAAI,CAACA,MAAM,IAAI,IAAI,CAACF,MAAM,CAACE,MAAM,CAACI,aAAa,CAACH,YAAY,CAAC;IAC3E,IAAI,CAACD,MAAM,CAACK,KAAK,GAAG,IAAI,CAACN,KAAK,CAACO,EAAE;EACnC;EAESC,OAAOA,CAAA,EAAS,CAEzB;AACF"}
@@ -1,18 +1,18 @@
1
- /// <reference types="@webgpu/types" />
2
- import type { ShaderProps, CompilerMessage } from '@luma.gl/api';
3
- import { Shader } from '@luma.gl/api';
4
- import type WebGPUDevice from '../webgpu-device';
5
- export declare type WebGPUShaderProps = ShaderProps & {
1
+ /// <reference types="dist" />
2
+ import type { ShaderProps, CompilerMessage } from '@luma.gl/core';
3
+ import { Shader } from '@luma.gl/core';
4
+ import type { WebGPUDevice } from '../webgpu-device';
5
+ export type WebGPUShaderProps = ShaderProps & {
6
6
  handle?: GPUShaderModule;
7
7
  };
8
8
  /**
9
9
  * Immutable shader
10
10
  */
11
- export default class WebGPUShader extends Shader {
11
+ export declare class WebGPUShader extends Shader {
12
12
  readonly device: WebGPUDevice;
13
13
  readonly handle: GPUShaderModule;
14
14
  constructor(device: WebGPUDevice, props: WebGPUShaderProps);
15
- _checkCompilationError(errorScope: Promise<GPUError>): Promise<void>;
15
+ _checkCompilationError(errorScope: Promise<GPUError | null>): Promise<void>;
16
16
  destroy(): void;
17
17
  protected createHandle(): GPUShaderModule;
18
18
  /** Returns compilation info for this shader */
@@ -1 +1 @@
1
- {"version":3,"file":"webgpu-shader.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgpu-shader.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAC,WAAW,EAAE,eAAe,EAAC,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAC,MAAM,EAAM,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,YAAY,MAAM,kBAAkB,CAAC;AAEjD,oBAAY,iBAAiB,GAAG,WAAW,G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AS,eAAe,EAAE,CAAC;CAI7D"}
@@ -1,64 +1,50 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import { Shader, log } from '@luma.gl/api';
3
- export default class WebGPUShader extends Shader {
1
+ import { Shader, log } from '@luma.gl/core';
2
+ export class WebGPUShader extends Shader {
4
3
  constructor(device, props) {
5
4
  super(device, props);
6
-
7
- _defineProperty(this, "device", void 0);
8
-
9
- _defineProperty(this, "handle", void 0);
10
-
5
+ this.device = void 0;
6
+ this.handle = void 0;
11
7
  this.device = device;
12
8
  this.device.handle.pushErrorScope('validation');
13
9
  this.handle = this.props.handle || this.createHandle();
14
10
  this.handle.label = this.props.id;
15
-
16
11
  this._checkCompilationError(this.device.handle.popErrorScope());
17
12
  }
18
-
19
13
  async _checkCompilationError(errorScope) {
20
14
  const error = await errorScope;
21
-
22
15
  if (error) {
23
16
  const shaderLog = await this.compilationInfo();
24
- log.error("Shader compilation error: ".concat(error.message), shaderLog)();
25
- throw new Error("Shader compilation error: ".concat(error.message));
17
+ log.error(`Shader compilation error: ${error.message}`, shaderLog)();
18
+ throw new Error(`Shader compilation error: ${error.message}`);
26
19
  }
27
20
  }
28
-
29
21
  destroy() {}
30
-
31
22
  createHandle() {
32
23
  const {
33
- source
24
+ source,
25
+ stage
34
26
  } = this.props;
35
27
  let language = this.props.language;
36
-
37
- if (!language) {
28
+ if (language === 'auto') {
38
29
  language = source.includes('->') ? 'wgsl' : 'glsl';
39
30
  }
40
-
41
31
  switch (language) {
42
32
  case 'wgsl':
43
33
  return this.device.handle.createShaderModule({
44
34
  code: source
45
35
  });
46
-
47
36
  case 'glsl':
48
37
  return this.device.handle.createShaderModule({
49
38
  code: source,
50
- transform: glsl => this.device.glslang.compileGLSL(glsl, type)
39
+ transform: glsl => this.device.glslang.compileGLSL(glsl, stage)
51
40
  });
52
-
53
41
  default:
54
42
  throw new Error(language);
55
43
  }
56
44
  }
57
-
58
45
  async compilationInfo() {
59
- const compilationInfo = await this.handle.compilationInfo();
46
+ const compilationInfo = await this.handle.getCompilationInfo();
60
47
  return compilationInfo.messages;
61
48
  }
62
-
63
49
  }
64
50
  //# sourceMappingURL=webgpu-shader.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/adapter/resources/webgpu-shader.ts"],"names":["Shader","log","WebGPUShader","constructor","device","props","handle","pushErrorScope","createHandle","label","id","_checkCompilationError","popErrorScope","errorScope","error","shaderLog","compilationInfo","message","Error","destroy","source","language","includes","createShaderModule","code","transform","glsl","glslang","compileGLSL","type","messages"],"mappings":";AACA,SAAQA,MAAR,EAAgBC,GAAhB,QAA0B,cAA1B;AAUA,eAAe,MAAMC,YAAN,SAA2BF,MAA3B,CAAkC;AAI/CG,EAAAA,WAAW,CAACC,MAAD,EAAuBC,KAAvB,EAAiD;AAC1D,UAAMD,MAAN,EAAcC,KAAd;;AAD0D;;AAAA;;AAE1D,SAAKD,MAAL,GAAcA,MAAd;AAEA,SAAKA,MAAL,CAAYE,MAAZ,CAAmBC,cAAnB,CAAkC,YAAlC;AAEA,SAAKD,MAAL,GAAc,KAAKD,KAAL,CAAWC,MAAX,IAAqB,KAAKE,YAAL,EAAnC;AACA,SAAKF,MAAL,CAAYG,KAAZ,GAAoB,KAAKJ,KAAL,CAAWK,EAA/B;;AAEA,SAAKC,sBAAL,CAA4B,KAAKP,MAAL,CAAYE,MAAZ,CAAmBM,aAAnB,EAA5B;AACD;;AAE2B,QAAtBD,sBAAsB,CAACE,UAAD,EAA+C;AACzE,UAAMC,KAAK,GAAG,MAAMD,UAApB;;AACA,QAAIC,KAAJ,EAAW;AACT,YAAMC,SAAS,GAAG,MAAM,KAAKC,eAAL,EAAxB;AACAf,MAAAA,GAAG,CAACa,KAAJ,qCAAuCA,KAAK,CAACG,OAA7C,GAAwDF,SAAxD;AAGA,YAAM,IAAIG,KAAJ,qCAAuCJ,KAAK,CAACG,OAA7C,EAAN;AACD;AACF;;AAEDE,EAAAA,OAAO,GAAG,CAET;;AAESX,EAAAA,YAAY,GAAoB;AACxC,UAAM;AAACY,MAAAA;AAAD,QAAW,KAAKf,KAAtB;AAEA,QAAIgB,QAAQ,GAAG,KAAKhB,KAAL,CAAWgB,QAA1B;;AAEA,QAAI,CAACA,QAAL,EAAe;AAEbA,MAAAA,QAAQ,GAAGD,MAAM,CAACE,QAAP,CAAgB,IAAhB,IAAwB,MAAxB,GAAiC,MAA5C;AACD;;AAED,YAAOD,QAAP;AACE,WAAK,MAAL;AACE,eAAO,KAAKjB,MAAL,CAAYE,MAAZ,CAAmBiB,kBAAnB,CAAsC;AAACC,UAAAA,IAAI,EAAEJ;AAAP,SAAtC,CAAP;;AACF,WAAK,MAAL;AACE,eAAO,KAAKhB,MAAL,CAAYE,MAAZ,CAAmBiB,kBAAnB,CAAsC;AAC3CC,UAAAA,IAAI,EAAEJ,MADqC;AAG3CK,UAAAA,SAAS,EAAGC,IAAD,IAAU,KAAKtB,MAAL,CAAYuB,OAAZ,CAAoBC,WAApB,CAAgCF,IAAhC,EAAsCG,IAAtC;AAHsB,SAAtC,CAAP;;AAKF;AACE,cAAM,IAAIX,KAAJ,CAAUG,QAAV,CAAN;AAVJ;AAYD;;AAGoB,QAAfL,eAAe,GAAwC;AAC3D,UAAMA,eAAe,GAAG,MAAM,KAAKV,MAAL,CAAYU,eAAZ,EAA9B;AACA,WAAOA,eAAe,CAACc,QAAvB;AACD;;AA3D8C","sourcesContent":["import type {ShaderProps, CompilerMessage} from '@luma.gl/api';\nimport {Shader, log} from '@luma.gl/api';\nimport type WebGPUDevice from '../webgpu-device';\n\nexport type WebGPUShaderProps = ShaderProps & {\n handle?: GPUShaderModule;\n};\n\n/**\n * Immutable shader\n */\nexport default class WebGPUShader extends Shader {\n readonly device: WebGPUDevice;\n readonly handle: GPUShaderModule;\n\n constructor(device: WebGPUDevice, props: WebGPUShaderProps) {\n super(device, props);\n this.device = device;\n\n this.device.handle.pushErrorScope('validation');\n\n this.handle = this.props.handle || this.createHandle();\n this.handle.label = this.props.id;\n\n this._checkCompilationError(this.device.handle.popErrorScope());\n }\n\n async _checkCompilationError(errorScope: Promise<GPUError>): Promise<void> {\n const error = await errorScope as GPUValidationError;\n if (error) {\n const shaderLog = await this.compilationInfo();\n log.error(`Shader compilation error: ${error.message}`, shaderLog)();\n // Note: Even though this error is asynchronous and thrown after the constructor completes,\n // it will result in a useful stack trace leading back to the constructor\n throw new Error(`Shader compilation error: ${error.message}`);\n }\n }\n\n destroy() {\n // this.handle.destroy();\n }\n\n protected createHandle(): GPUShaderModule {\n const {source} = this.props;\n\n let language = this.props.language;\n // Compile from src\n if (!language) {\n // wgsl uses C++ \"auto\" style arrow notation\n language = source.includes('->') ? 'wgsl' : 'glsl';\n }\n\n switch(language) {\n case 'wgsl':\n return this.device.handle.createShaderModule({code: source});\n case 'glsl':\n return this.device.handle.createShaderModule({\n code: source,\n // @ts-expect-error\n transform: (glsl) => this.device.glslang.compileGLSL(glsl, type)\n });\n default:\n throw new Error(language);\n }\n }\n\n /** Returns compilation info for this shader */\n async compilationInfo(): Promise<readonly CompilerMessage[]> {\n const compilationInfo = await this.handle.compilationInfo();\n return compilationInfo.messages;\n }\n}\n"],"file":"webgpu-shader.js"}
1
+ {"version":3,"file":"webgpu-shader.js","names":["Shader","log","WebGPUShader","constructor","device","props","handle","pushErrorScope","createHandle","label","id","_checkCompilationError","popErrorScope","errorScope","error","shaderLog","compilationInfo","message","Error","destroy","source","stage","language","includes","createShaderModule","code","transform","glsl","glslang","compileGLSL","getCompilationInfo","messages"],"sources":["../../../src/adapter/resources/webgpu-shader.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {ShaderProps, CompilerMessage} from '@luma.gl/core';\nimport {Shader, log} from '@luma.gl/core';\nimport type {WebGPUDevice} from '../webgpu-device';\n\nexport type WebGPUShaderProps = ShaderProps & {\n handle?: GPUShaderModule;\n};\n\n/**\n * Immutable shader\n */\nexport class WebGPUShader extends Shader {\n readonly device: WebGPUDevice;\n readonly handle: GPUShaderModule;\n\n constructor(device: WebGPUDevice, props: WebGPUShaderProps) {\n super(device, props);\n this.device = device;\n\n this.device.handle.pushErrorScope('validation');\n\n this.handle = this.props.handle || this.createHandle();\n this.handle.label = this.props.id;\n\n this._checkCompilationError(this.device.handle.popErrorScope());\n }\n\n async _checkCompilationError(errorScope: Promise<GPUError | null>): Promise<void> {\n const error = await errorScope as GPUValidationError;\n if (error) {\n const shaderLog = await this.compilationInfo();\n log.error(`Shader compilation error: ${error.message}`, shaderLog)();\n // Note: Even though this error is asynchronous and thrown after the constructor completes,\n // it will result in a useful stack trace leading back to the constructor\n throw new Error(`Shader compilation error: ${error.message}`);\n }\n }\n\n override destroy(): void {\n // this.handle.destroy();\n }\n\n protected createHandle(): GPUShaderModule {\n const {source, stage} = this.props;\n\n let language = this.props.language;\n // Compile from src\n if (language === 'auto') {\n // wgsl uses C++ \"auto\" style arrow notation\n language = source.includes('->') ? 'wgsl' : 'glsl';\n }\n\n switch(language) {\n case 'wgsl':\n return this.device.handle.createShaderModule({code: source});\n case 'glsl':\n return this.device.handle.createShaderModule({\n code: source,\n // @ts-expect-error\n transform: (glsl) => this.device.glslang.compileGLSL(glsl, stage)\n });\n default:\n throw new Error(language);\n }\n }\n\n /** Returns compilation info for this shader */\n async compilationInfo(): Promise<readonly CompilerMessage[]> {\n const compilationInfo = await this.handle.getCompilationInfo();\n return compilationInfo.messages;\n }\n}\n"],"mappings":"AAIA,SAAQA,MAAM,EAAEC,GAAG,QAAO,eAAe;AAUzC,OAAO,MAAMC,YAAY,SAASF,MAAM,CAAC;EAIvCG,WAAWA,CAACC,MAAoB,EAAEC,KAAwB,EAAE;IAC1D,KAAK,CAACD,MAAM,EAAEC,KAAK,CAAC;IAAC,KAJdD,MAAM;IAAA,KACNE,MAAM;IAIb,IAAI,CAACF,MAAM,GAAGA,MAAM;IAEpB,IAAI,CAACA,MAAM,CAACE,MAAM,CAACC,cAAc,CAAC,YAAY,CAAC;IAE/C,IAAI,CAACD,MAAM,GA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