@luma.gl/webgpu 9.0.0-alpha.2 → 9.0.0-alpha.21

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 (114) hide show
  1. package/LICENSE +32 -0
  2. package/dist/adapter/helpers/accessor-to-format.js.map +1 -1
  3. package/dist/adapter/helpers/convert-texture-format.d.ts +1 -1
  4. package/dist/adapter/helpers/convert-texture-format.js +0 -1
  5. package/dist/adapter/helpers/convert-texture-format.js.map +1 -1
  6. package/dist/adapter/helpers/generate-mipmaps.d.ts +1 -1
  7. package/dist/adapter/helpers/generate-mipmaps.js +1 -8
  8. package/dist/adapter/helpers/generate-mipmaps.js.map +1 -1
  9. package/dist/adapter/helpers/get-bind-group.d.ts +1 -1
  10. package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
  11. package/dist/adapter/helpers/get-bind-group.js +0 -9
  12. package/dist/adapter/helpers/get-bind-group.js.map +1 -1
  13. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts +1 -1
  14. package/dist/adapter/helpers/get-vertex-buffer-layout.js +3 -17
  15. package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +1 -1
  16. package/dist/adapter/helpers/webgpu-parameters.d.ts +1 -1
  17. package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
  18. package/dist/adapter/helpers/webgpu-parameters.js +50 -47
  19. package/dist/adapter/helpers/webgpu-parameters.js.map +1 -1
  20. package/dist/adapter/resources/webgpu-buffer.d.ts +3 -4
  21. package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
  22. package/dist/adapter/resources/webgpu-buffer.js +12 -26
  23. package/dist/adapter/resources/webgpu-buffer.js.map +1 -1
  24. package/dist/adapter/resources/webgpu-command-encoder.d.ts +3 -4
  25. package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
  26. package/dist/adapter/resources/webgpu-command-encoder.js +7 -24
  27. package/dist/adapter/resources/webgpu-command-encoder.js.map +1 -1
  28. package/dist/adapter/resources/webgpu-compute-pass.d.ts +5 -5
  29. package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
  30. package/dist/adapter/resources/webgpu-compute-pass.js +11 -23
  31. package/dist/adapter/resources/webgpu-compute-pass.js.map +1 -1
  32. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +3 -3
  33. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
  34. package/dist/adapter/resources/webgpu-compute-pipeline.js +3 -7
  35. package/dist/adapter/resources/webgpu-compute-pipeline.js.map +1 -1
  36. package/dist/adapter/resources/webgpu-external-texture.d.ts +4 -4
  37. package/dist/adapter/resources/webgpu-external-texture.d.ts.map +1 -1
  38. package/dist/adapter/resources/webgpu-external-texture.js +2 -9
  39. package/dist/adapter/resources/webgpu-external-texture.js.map +1 -1
  40. package/dist/adapter/resources/webgpu-framebuffer.d.ts +5 -5
  41. package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
  42. package/dist/adapter/resources/webgpu-framebuffer.js +12 -30
  43. package/dist/adapter/resources/webgpu-framebuffer.js.map +1 -1
  44. package/dist/adapter/resources/webgpu-query.js.map +1 -1
  45. package/dist/adapter/resources/webgpu-render-pass.d.ts +5 -5
  46. package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
  47. package/dist/adapter/resources/webgpu-render-pass.js +17 -30
  48. package/dist/adapter/resources/webgpu-render-pass.js.map +1 -1
  49. package/dist/adapter/resources/webgpu-render-pipeline.d.ts +7 -4
  50. package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
  51. package/dist/adapter/resources/webgpu-render-pipeline.js +25 -43
  52. package/dist/adapter/resources/webgpu-render-pipeline.js.map +1 -1
  53. package/dist/adapter/resources/webgpu-sampler.d.ts +3 -3
  54. package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
  55. package/dist/adapter/resources/webgpu-sampler.js +8 -7
  56. package/dist/adapter/resources/webgpu-sampler.js.map +1 -1
  57. package/dist/adapter/resources/webgpu-shader.d.ts +4 -4
  58. package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
  59. package/dist/adapter/resources/webgpu-shader.js +2 -16
  60. package/dist/adapter/resources/webgpu-shader.js.map +1 -1
  61. package/dist/adapter/resources/webgpu-texture.d.ts +4 -4
  62. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  63. package/dist/adapter/resources/webgpu-texture.js +4 -20
  64. package/dist/adapter/resources/webgpu-texture.js.map +1 -1
  65. package/dist/adapter/webgpu-canvas-context.d.ts +5 -7
  66. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
  67. package/dist/adapter/webgpu-canvas-context.js +10 -31
  68. package/dist/adapter/webgpu-canvas-context.js.map +1 -1
  69. package/dist/adapter/webgpu-device.d.ts +19 -19
  70. package/dist/adapter/webgpu-device.d.ts.map +1 -1
  71. package/dist/adapter/webgpu-device.js +42 -71
  72. package/dist/adapter/webgpu-device.js.map +1 -1
  73. package/dist/adapter/webgpu-types.js.map +1 -1
  74. package/dist/dist.dev.js +3060 -0
  75. package/dist/glsl/glsllang.js +0 -1
  76. package/dist/glsl/glsllang.js.map +1 -1
  77. package/dist/index.cjs +1442 -0
  78. package/dist/index.d.ts +5 -7
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +5 -7
  81. package/dist/index.js.map +1 -1
  82. package/dist.min.js +17 -0
  83. package/package.json +18 -9
  84. package/src/.DS_Store +0 -0
  85. package/src/adapter/.DS_Store +0 -0
  86. package/src/adapter/helpers/generate-mipmaps.ts +1 -1
  87. package/src/adapter/helpers/get-bind-group.ts +4 -4
  88. package/src/adapter/helpers/get-vertex-buffer-layout.ts +3 -3
  89. package/src/adapter/helpers/webgpu-parameters.ts +55 -46
  90. package/src/adapter/resources/webgpu-buffer.ts +6 -10
  91. package/src/adapter/resources/webgpu-command-encoder.ts +22 -20
  92. package/src/adapter/resources/webgpu-compute-pass.ts +12 -12
  93. package/src/adapter/resources/webgpu-compute-pipeline.ts +5 -4
  94. package/src/adapter/resources/webgpu-external-texture.ts +4 -4
  95. package/src/adapter/resources/webgpu-framebuffer.ts +18 -18
  96. package/src/adapter/resources/webgpu-query.ts +2 -2
  97. package/src/adapter/resources/webgpu-render-pass.ts +15 -12
  98. package/src/adapter/resources/webgpu-render-pipeline.ts +32 -15
  99. package/src/adapter/resources/webgpu-sampler.ts +11 -4
  100. package/src/adapter/resources/webgpu-shader.ts +7 -5
  101. package/src/adapter/resources/webgpu-texture.ts +7 -6
  102. package/src/adapter/webgpu-canvas-context.ts +16 -12
  103. package/src/adapter/webgpu-device.ts +63 -50
  104. package/src/index.ts +6 -9
  105. package/dist/bundle.d.ts +0 -2
  106. package/dist/bundle.d.ts.map +0 -1
  107. package/dist/bundle.js +0 -5
  108. package/dist/bundle.js.map +0 -1
  109. package/dist/init.d.ts +0 -2
  110. package/dist/init.d.ts.map +0 -1
  111. package/dist/init.js +0 -4
  112. package/dist/init.js.map +0 -1
  113. package/src/bundle.ts +0 -4
  114. package/src/init.ts +0 -4
@@ -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,CAAYE,MAAZ,CAAmBkB,oBAAnB,CAAwCH,UAAxC,CAAvB;AACA1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AAM,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","_defineProperty","handle","createHandle","label","id","vs","fs","_bufferSlots","layout","bufferMap","_buffers","Array","Object","keys","length","fill","_bindGroupLayout","getBindGroupLayout","descriptor","_getRenderPipelineDescriptor","renderPipeline","createRenderPipeline","groupCollapsed","concat","JSON","stringify","groupEnd","destroy","setIndexBuffer","indexBuffer","_indexBuffer","setAttributes","attributes","name","buffer","entries","bufferIndex","Error","setBindings","bindings","assign","_bindGroup","setUniforms","uniforms","_getBuffers","_getBindGroup","vertex","module","entryPoint","vsEntryPoint","buffers","fragment","_this$device","_this$device$canvasCo","fsEntryPoint","targets","format","canvasContext","topology","primitive","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":["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 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;\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) || this.createHandle();\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.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 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 /** 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 // 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':\n case 'line-loop':\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,\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"],"mappings":";AACA,SAAgBA,cAAc,EAAuBC,IAAI,EAAEC,GAAG,EAAEC,aAAa,QAAO,cAAc;AAAC,SAC3FC,yCAAyC;AAAA,SACzCC,sBAAsB;AAAA,SACtBC,YAAY;AAAA,SACZC,qBAAqB,EAAEC,cAAc;AAa7C,OAAO,MAAMC,oBAAoB,SAAST,cAAc,CAAC;EAiBvDU,WAAWA,CAACC,MAAoB,EAAEC,KAA0B,EAAE;IAC5D,KAAK,CAACD,MAAM,EAAEC,KAAK,CAAC;IAACC,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA,aAbG,IAAI;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA,uBAIc,IAA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AEgE,CAAC,EAAE;MACvC,MAAM5C,MAAM,GAAG9C,IAAI,CAAe8D,OAAO,CAAC4B,CAAC,CAAC,CAAC;MAC7C,IAAI,CAAC5C,MAAM,EAAE;QACX,MAAM6C,SAAS,GAAG,IAAI,CAAChF,KAAK,CAACS,MAAM,CAACwB,UAAU,CAACgD,IAAI,CAChDD,SAAS,IAAKA,SAAS,CAACE,QAAQ,KAAKH,CAAC,CACxC;QACD,MAAM,IAAIzC,KAAK,sCAAAd,MAAA,CACwB,CAAAwD,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAE9C,IAAI,KAAI,EAAE,kBAAAV,MAAA,CAAe,IAAI,CAACxB,KAAK,CAACK,EAAE,OACvF;MACH;MACA2D,gBAAgB,CAAC9D,MAAM,CAACiF,eAAe,CAACJ,CAAC,EAAE5C,MAAM,CAACjC,MAAM,CAAC;IAC3D;EAsBF;AACF"}
@@ -1,13 +1,13 @@
1
- /// <reference types="@webgpu/types" />
1
+ /// <reference types="dist" />
2
2
  import { Sampler, SamplerProps } from '@luma.gl/api';
3
- import type WebGPUDevice from '../webgpu-device';
3
+ import type { WebGPUDevice } from '../webgpu-device';
4
4
  export declare 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,cAAc,CAAC;AACnD,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAEnD,oBAAY,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,20 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  import { Sampler } from '@luma.gl/api';
3
- export default class WebGPUSampler extends Sampler {
3
+ export class WebGPUSampler extends Sampler {
4
4
  constructor(device, props) {
5
5
  super(device, props);
6
-
7
6
  _defineProperty(this, "device", void 0);
8
-
9
7
  _defineProperty(this, "handle", void 0);
10
-
11
8
  this.device = device;
12
- this.handle = this.handle || this.device.handle.createSampler(this.props);
9
+ const samplerProps = {
10
+ ...this.props
11
+ };
12
+ if (samplerProps.type !== 'comparison-sampler') {
13
+ delete samplerProps.compare;
14
+ }
15
+ this.handle = this.handle || this.device.handle.createSampler(samplerProps);
13
16
  this.handle.label = this.props.id;
14
17
  }
15
-
16
18
  destroy() {}
17
-
18
19
  }
19
20
  //# 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","_defineProperty","samplerProps","type","compare","handle","createSampler","label","id","destroy"],"sources":["../../../src/adapter/resources/webgpu-sampler.ts"],"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 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,cAAc;AAUlD,OAAO,MAAMC,aAAa,SAASD,OAAO,CAAC;EAIzCE,WAAWA,CAACC,MAAoB,EAAEC,KAAyB,EAAE;IAC3D,KAAK,CAACD,MAAM,EAAEC,KAAK,CAAC;IAACC,eAAA;IAAAA,eAAA;IACrB,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,CAACC,MAAM,GAAG,IAAI,CAACA,MAAM,IAAI,IAAI,CAACN,MAAM,CAACM,MAAM,CAACC,aAAa,CAACJ,YAAY,CAAC;IAC3E,IAAI,CAACG,MAAM,CAACE,KAAK,GAAG,IAAI,CAACP,KAAK,CAACQ,EAAE;EACnC;EAESC,OAAOA,CAAA,EAAS,CAEzB;AACF"}
@@ -1,18 +1,18 @@
1
- /// <reference types="@webgpu/types" />
1
+ /// <reference types="dist" />
2
2
  import type { ShaderProps, CompilerMessage } from '@luma.gl/api';
3
3
  import { Shader } from '@luma.gl/api';
4
- import type WebGPUDevice from '../webgpu-device';
4
+ import type { WebGPUDevice } from '../webgpu-device';
5
5
  export declare 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,GAAG;IAC5C,MAAM,CAAC,EAAE,eAAe,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,MAAM;IAC9C,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;gBAErB,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,iBAAiB;IAYpD,sBAAsB,CAAC,UAAU,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAW1E,OAAO;IAIP,SAAS,CAAC,YAAY,IAAI,eAAe;IAwBzC,+CAA+C;IACzC,eAAe,IAAI,OAAO,CAAC,SAAS,eAAe,EAAE,CAAC;CAI7D"}
1
+ {"version":3,"file":"webgpu-shader.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgpu-shader.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAC,WAAW,EAAE,eAAe,EAAC,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAC,MAAM,EAAM,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAEnD,oBAAY,iBAAiB,GAAG,WAAW,GAAG;IAC5C,MAAM,CAAC,EAAE,eAAe,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,qBAAa,YAAa,SAAQ,MAAM;IACtC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;gBAErB,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,iBAAiB;IAYpD,sBAAsB,CAAC,UAAU,EAAE,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAWxE,OAAO,IAAI,IAAI;IAIxB,SAAS,CAAC,YAAY,IAAI,eAAe;IAwBzC,+CAA+C;IACzC,eAAe,IAAI,OAAO,CAAC,SAAS,eAAe,EAAE,CAAC;CAI7D"}
@@ -1,64 +1,50 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  import { Shader, log } from '@luma.gl/api';
3
- export default class WebGPUShader extends Shader {
3
+ export class WebGPUShader extends Shader {
4
4
  constructor(device, props) {
5
5
  super(device, props);
6
-
7
6
  _defineProperty(this, "device", void 0);
8
-
9
7
  _defineProperty(this, "handle", void 0);
10
-
11
8
  this.device = device;
12
9
  this.device.handle.pushErrorScope('validation');
13
10
  this.handle = this.props.handle || this.createHandle();
14
11
  this.handle.label = this.props.id;
15
-
16
12
  this._checkCompilationError(this.device.handle.popErrorScope());
17
13
  }
18
-
19
14
  async _checkCompilationError(errorScope) {
20
15
  const error = await errorScope;
21
-
22
16
  if (error) {
23
17
  const shaderLog = await this.compilationInfo();
24
18
  log.error("Shader compilation error: ".concat(error.message), shaderLog)();
25
19
  throw new Error("Shader compilation error: ".concat(error.message));
26
20
  }
27
21
  }
28
-
29
22
  destroy() {}
30
-
31
23
  createHandle() {
32
24
  const {
33
25
  source
34
26
  } = this.props;
35
27
  let language = this.props.language;
36
-
37
28
  if (!language) {
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
39
  transform: glsl => this.device.glslang.compileGLSL(glsl, type)
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,G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AMA,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","_defineProperty","handle","pushErrorScope","createHandle","label","id","_checkCompilationError","popErrorScope","errorScope","error","shaderLog","compilationInfo","concat","message","Error","destroy","source","language","includes","createShaderModule","code","transform","glsl","glslang","compileGLSL","type","getCompilationInfo","messages"],"sources":["../../../src/adapter/resources/webgpu-shader.ts"],"sourcesContent":["// luma.gl, MIT license\n\nimport 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 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} = 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.getCompilationInfo();\n return compilationInfo.messages;\n }\n}\n"],"mappings":";AAGA,SAAQA,MAAM,EAAEC,GAAG,QAAO,cAAc;AAUxC,OAAO,MAAMC,YAAY,SAASF,MAAM,CAAC;EAIvCG,WAAWA,CAACC,MAAoB,EAAEC,KAAwB,EAAE;IAC1D,KAAK,CAACD,MAAM,EAAEC,KAAK,CAAC;IAACC,eAAA;IAAAA,eAAA;IACrB,IAAI,CAACF,MAAM,GAAGA,MAAM;IAEpB,IAAI,CAACA,MAAM,CAACG,MAAM,CAACC,cAAc,CAAC,YAAY,CAAC;IAE/C,IAAI,CAACD,MAAM,GAAG,IAAI,CAACF,KAAK,CAACE,MAAM,IAAI,IAAI,CAACE,YAAY,EAAE;IACtD,IAAI,CAACF,MAAM,CAACG,KAAK,GAAG,IAAI,CAACL,KAAK,CAACM,EAAE;IAEjC,IAAI,CAACC,sBAAsB,CAAC,IAAI,CAACR,MAAM,CAACG,MAAM,CAACM,aAAa,EAAE,CAAC;EACjE;EAEA,MAAMD,sBAAsBA,CAACE,UAAoC,EAAiB;IAChF,MAAMC,KAAK,GAAG,MAAMD,UAAgC;IACpD,IAAIC,KAAK,EAAE;MACT,MAAMC,SAAS,GAAG,MAAM,IAAI,CAACC,eAAe,EAAE;MAC9ChB,GAAG,CAACc,KAAK,8BAAAG,MAAA,CAA8BH,KAAK,CAACI,OAAO,GAAIH,SAAS,CAAC,EAAE;MAGpE,MAAM,IAAII,KAAK,8BAAAF,MAAA,CAA8BH,KAAK,CAACI,OAAO,EAAG;IAC/D;EACF;EAESE,OAAOA,CAAA,EAAS,CAEzB;EAEUZ,YAAYA,CAAA,EAAoB;IACxC,MAAM;MAACa;IAAM,CAAC,GAAG,IAAI,CAACjB,KAAK;IAE3B,IAAIkB,QAAQ,GAAG,IAAI,CAAClB,KAAK,CAACkB,QAAQ;IAElC,IAAI,CAACA,QAAQ,EAAE;MAEbA,QAAQ,GAAGD,MAAM,CAACE,QAAQ,CAAC,IAAI,CAAC,GAAG,MAAM,GAAG,MAAM;IACpD;IAEA,QAAOD,QAAQ;MACb,KAAK,MAAM;QACT,OAAO,IAAI,CAACnB,MAAM,CAACG,MAAM,CAACkB,kBAAkB,CAAC;UAACC,IAAI,EAAEJ;QAAM,CAAC,CAAC;MAC9D,KAAK,MAAM;QACT,OAAO,IAAI,CAAClB,MAAM,CAACG,MAAM,CAACkB,kBAAkB,CAAC;UAC3CC,IAAI,EAAEJ,MAAM;UAEZK,SAAS,EAAGC,IAAI,IAAK,IAAI,CAACxB,MAAM,CAACyB,OAAO,CAACC,WAAW,CAACF,IAAI,EAAEG,IAAI;QACjE,CAAC,CAAC;MACJ;QACE,MAAM,IAAIX,KAAK,CAACG,QAAQ,CAAC;IAAC;EAEhC;EAGA,MAAMN,eAAeA,CAAA,EAAwC;IAC3D,MAAMA,eAAe,GAAG,MAAM,IAAI,CAACV,MAAM,CAACyB,kBAAkB,EAAE;IAC9D,OAAOf,eAAe,CAACgB,QAAQ;EACjC;AACF"}
@@ -1,9 +1,9 @@
1
- /// <reference types="@webgpu/types" />
1
+ /// <reference types="dist" />
2
2
  /// <reference types="offscreencanvas" />
3
3
  import { Texture, TextureProps, Sampler, SamplerProps } from '@luma.gl/api';
4
- import type WebGPUDevice from '../webgpu-device';
5
- import WebGPUSampler from './webgpu-sampler';
6
- export default class WebGPUTexture extends Texture {
4
+ import type { WebGPUDevice } from '../webgpu-device';
5
+ import { WebGPUSampler } from './webgpu-sampler';
6
+ export declare class WebGPUTexture extends Texture {
7
7
  readonly device: WebGPUDevice;
8
8
  readonly handle: GPUTexture;
9
9
  readonly view: GPUTextureView;
@@ -1 +1 @@
1
- {"version":3,"file":"webgpu-texture.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgpu-texture.ts"],"names":[],"mappings":";;AACA,OAAO,EAAC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAS,MAAM,c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}
@@ -1,7 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  import { Texture } from '@luma.gl/api';
3
- import { getWebGPUTextureFormat } from '../helpers/convert-texture-format';
4
- import WebGPUSampler from './webgpu-sampler';
3
+ import { getWebGPUTextureFormat } from "../helpers/convert-texture-format.js";
4
+ import { WebGPUSampler } from "./webgpu-sampler.js";
5
5
  const BASE_DIMENSIONS = {
6
6
  '1d': '1d',
7
7
  '2d': '2d',
@@ -10,42 +10,31 @@ const BASE_DIMENSIONS = {
10
10
  'cube-array': '2d',
11
11
  '3d': '3d'
12
12
  };
13
- export default class WebGPUTexture extends Texture {
13
+ export class WebGPUTexture extends Texture {
14
14
  constructor(device, props) {
15
15
  super(device, props);
16
-
17
16
  _defineProperty(this, "device", void 0);
18
-
19
17
  _defineProperty(this, "handle", void 0);
20
-
21
18
  _defineProperty(this, "view", void 0);
22
-
23
19
  _defineProperty(this, "sampler", void 0);
24
-
25
20
  if (typeof this.props.format === 'number') {
26
21
  throw new Error('number format');
27
22
  }
28
-
29
23
  this.device = device;
30
24
  this.handle = this.props.handle || this.createHandle();
31
-
32
25
  if (this.props.data) {
33
26
  this.setData({
34
27
  data: this.props.data
35
28
  });
36
29
  }
37
-
38
- this.setSampler(props.sampler);
30
+ this.sampler = props.sampler instanceof WebGPUSampler ? props.sampler : new WebGPUSampler(this.device, props.sampler);
39
31
  this.view = this.handle.createView({});
40
32
  }
41
-
42
33
  createHandle() {
43
34
  var _this$props$data, _this$props$data2;
44
-
45
35
  if (typeof this.props.format === 'number') {
46
36
  throw new Error('number format');
47
37
  }
48
-
49
38
  const width = this.props.width || ((_this$props$data = this.props.data) === null || _this$props$data === void 0 ? void 0 : _this$props$data.width) || 1;
50
39
  const height = this.props.height || ((_this$props$data2 = this.props.data) === null || _this$props$data2 === void 0 ? void 0 : _this$props$data2.height) || 1;
51
40
  return this.device.handle.createTexture({
@@ -61,22 +50,18 @@ export default class WebGPUTexture extends Texture {
61
50
  sampleCount: this.props.samples
62
51
  });
63
52
  }
64
-
65
53
  destroy() {
66
54
  this.handle.destroy();
67
55
  }
68
-
69
56
  setSampler(sampler) {
70
57
  this.sampler = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);
71
58
  return this;
72
59
  }
73
-
74
60
  setData(options) {
75
61
  return this.setImage({
76
62
  source: options.data
77
63
  });
78
64
  }
79
-
80
65
  setImage(options) {
81
66
  const {
82
67
  source,
@@ -106,6 +91,5 @@ export default class WebGPUTexture extends Texture {
106
91
  }, [width, height, depth]);
107
92
  return this;
108
93
  }
109
-
110
94
  }
111
95
  //# sourceMappingURL=webgpu-texture.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/adapter/resources/webgpu-texture.ts"],"names":["Texture","getWebGPUTextureFormat","WebGPUSampler","BASE_DIMENSIONS","WebGPUTexture","constructor","device","props","format","Error","handle","createHandle","data","setData","setSampler","sampler","view","createView","width","height","createTexture","size","depthOrArrayLayers","depth","dimension","usage","mipLevelCount","mipLevels","sampleCount","samples","destroy","options","setImage","source","sourceX","sourceY","mipLevel","x","y","z","aspect","colorSpace","premultipliedAlpha","queue","copyExternalImageToTexture","origin","texture"],"mappings":";AACA,SAAQA,OAAR,QAAmE,cAAnE;AACA,SAAQC,sBAAR,QAAqC,mCAArC;AAEA,OAAOC,aAAP,MAA0B,kBAA1B;AAEA,MAAMC,eAAmD,GAAG;AAC1D,QAAM,IADoD;AAE1D,QAAM,IAFoD;AAG1D,cAAY,IAH8C;AAI1D,UAAQ,IAJkD;AAK1D,gBAAc,IAL4C;AAM1D,QAAM;AANoD,CAA5D;AASA,eAAe,MAAMC,aAAN,SAA4BJ,OAA5B,CAAoC;AAajDK,EAAAA,WAAW,CAACC,MAAD,EAAuBC,KAAvB,EAA4C;AACrD,UAAMD,MAAN,EAAcC,KAAd;;AADqD;;AAAA;;AAAA;;AAAA;;AAGrD,QAAI,OAAO,KAAKA,KAAL,CAAWC,MAAlB,KAA6B,QA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;AACEW,MAAAA,OAAO,EAAE,KAAKpC,MADhB;AAEEmC,MAAAA,MAAM,EAAE,CAACR,CAAD,EAAIC,CAAJ,EAAOC,CAAP,CAFV;AAGEH,MAAAA,QAHF;AAIEI,MAAAA,MAJF;AAKEC,MAAAA,UALF;AAMEC,MAAAA;AANF,KAPF,EAgBE,CACExB,KADF,EAEEC,MAFF,EAGEI,KAHF,CAhBF;AAsBA,WAAO,IAAP;AACD;;AAhJgD","sourcesContent":["// luma.gl, MIT license\nimport {Texture, TextureProps, Sampler, SamplerProps, assert} from '@luma.gl/api';\nimport {getWebGPUTextureFormat} from '../helpers/convert-texture-format';\nimport type WebGPUDevice from '../webgpu-device';\nimport WebGPUSampler from './webgpu-sampler';\n\nconst BASE_DIMENSIONS: Record<string, '1d' | '2d' | '3d'> = {\n '1d': '1d',\n '2d': '2d',\n '2d-array': '2d',\n 'cube': '2d',\n 'cube-array': '2d',\n '3d': '3d'\n};\n\nexport default class WebGPUTexture extends Texture {\n readonly device: WebGPUDevice;\n readonly handle: GPUTexture;\n readonly view: GPUTextureView;\n sampler: WebGPUSampler;\n\n // static async createFromImageURL(src, usage = 0) {\n // const img = document.createElement('img');\n // img.src = src;\n // await img.decode();\n // return WebGPUTexture(img, usage);\n // }\n\n constructor(device: WebGPUDevice, props: TextureProps) {\n super(device, props);\n\n if (typeof this.props.format === 'number') {\n throw new Error('number format');\n }\n\n this.device = device;\n this.handle = this.props.handle || this.createHandle();\n\n if (this.props.data) {\n this.setData({data: this.props.data} );\n }\n\n // Create a default sampler. This mimics the WebGL1 API where sampler props are stored on the texture\n this.setSampler(props.sampler);\n\n // TODO - To support texture arrays we need to create custom views...\n // But we are not ready to expose TextureViews to the public API.\n this.view = this.handle.createView({\n // format: this.props.format,\n // dimension: this.props.dimension,\n // aspect = \"all\";\n // baseMipLevel: 0;\n // mipLevelCount;\n // baseArrayLayer = 0;\n // arrayLayerCount;\n });\n }\n\n protected createHandle(): GPUTexture {\n if (typeof this.props.format === 'number') {\n throw new Error('number format');\n }\n\n // Deduce size from data - TODO this is a hack\n // @ts-expect-error\n const width = this.props.width || this.props.data?.width || 1;\n // @ts-expect-error\n const height = this.props.height || this.props.data?.height || 1;\n\n return this.device.handle.createTexture({\n size: {\n width,\n height,\n depthOrArrayLayers: this.props.depth\n },\n dimension: BASE_DIMENSIONS[this.props.dimension],\n format: getWebGPUTextureFormat(this.props.format),\n usage: this.props.usage,\n mipLevelCount: this.props.mipLevels,\n sampleCount: this.props.samples\n });\n }\n\n destroy(): void {\n this.handle.destroy();\n }\n\n /**\n * Set default sampler\n * Accept a sampler instance or set of props;\n */\n setSampler(sampler: Sampler | SamplerProps): this {\n this.sampler = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);\n return this;\n }\n\n setData(options: {\n data: any;\n }) {\n return this.setImage({source: options.data});\n }\n\n /** Set image */\n setImage(options: {\n source: ImageBitmap | HTMLCanvasElement | OffscreenCanvas;\n width?: number;\n height?: number;\n depth?: number;\n sourceX?: number;\n sourceY?: number;\n mipLevel?: number;\n x?: number;\n y?: number;\n z?: number;\n aspect?: 'all' | 'stencil-only' | 'depth-only';\n colorSpace?: 'srgb';\n premultipliedAlpha?: boolean;\n }): this {\n const {\n source,\n width = options.source.width,\n height = options.source.height,\n depth = 1,\n sourceX = 0,\n sourceY = 0,\n mipLevel = 0,\n x = 0,\n y = 0,\n z = 0,\n aspect = 'all',\n colorSpace = 'srgb',\n premultipliedAlpha = false\n } = options;\n\n // TODO - max out width\n\n this.device.handle.queue.copyExternalImageToTexture(\n // source: GPUImageCopyExternalImage\n {\n source,\n origin: [sourceX, sourceY]\n },\n // destination: GPUImageCopyTextureTagged\n {\n texture: this.handle,\n origin: [x, y, z],\n mipLevel,\n aspect,\n colorSpace,\n premultipliedAlpha\n },\n // copySize: GPUExtent3D\n [\n width,\n height,\n depth\n ]\n );\n return this;\n }\n\n /*\n async readPixels() {\n const readbackBuffer = device.createBuffer({\n usage: Buffer.COPY_DST | Buffer.MAP_READ,\n size: 4 * textureWidth * textureHeight,\n });\n\n // Copy data from the texture to the buffer.\n const encoder = device.createCommandEncoder();\n encoder.copyTextureToBuffer(\n { texture },\n { buffer, rowPitch: textureWidth * 4 },\n [textureWidth, textureHeight],\n );\n device.submit([encoder.finish()]);\n\n // Get the data on the CPU.\n await buffer.mapAsync(GPUMapMode.READ);\n saveScreenshot(buffer.getMappedRange());\n buffer.unmap();\n }\n\n setImageData(imageData, usage): this {\n let data = null;\n\n const bytesPerRow = Math.ceil((img.width * 4) / 256) * 256;\n if (bytesPerRow == img.width * 4) {\n data = imageData.data;\n } else {\n data = new Uint8Array(bytesPerRow * img.height);\n let imagePixelIndex = 0;\n for (let y = 0; y < img.height; ++y) {\n for (let x = 0; x < img.width; ++x) {\n const i = x * 4 + y * bytesPerRow;\n data[i] = imageData.data[imagePixelIndex];\n data[i + 1] = imageData.data[imagePixelIndex + 1];\n data[i + 2] = imageData.data[imagePixelIndex + 2];\n data[i + 3] = imageData.data[imagePixelIndex + 3];\n imagePixelIndex += 4;\n }\n }\n }\n return this;\n }\n\n setData(data): this {\n const textureDataBuffer = this.device.handle.createBuffer({\n size: data.byteLength,\n usage: Buffer.COPY_DST | Buffer.COPY_SRC,\n mappedAtCreation: true\n });\n new Uint8Array(textureDataBuffer.getMappedRange()).set(data);\n textureDataBuffer.unmap();\n\n this.setBuffer(textureDataBuffer);\n\n textureDataBuffer.destroy();\n return this;\n }\n\n setBuffer(textureDataBuffer, {bytesPerRow}): this {\n const commandEncoder = this.device.handle.createCommandEncoder();\n commandEncoder.copyBufferToTexture(\n {\n buffer: textureDataBuffer,\n bytesPerRow\n },\n {\n texture: this.handle\n },\n {\n width,\n height,\n depth\n }\n );\n\n this.device.handle.defaultQueue.submit([commandEncoder.finish()]);\n return this;\n }\n */\n}\n"],"file":"webgpu-texture.js"}
1
+ {"version":3,"file":"webgpu-texture.js","names":["Texture","getWebGPUTextureFormat","WebGPUSampler","BASE_DIMENSIONS","WebGPUTexture","constructor","device","props","_defineProperty","format","Error","handle","createHandle","data","setData","sampler","view","createView","_this$props$data","_this$props$data2","width","height","createTexture","size","depthOrArrayLayers","depth","dimension","usage","mipLevelCount","mipLevels","sampleCount","samples","destroy","setSampler","options","setImage","source","sourceX","sourceY","mipLevel","x","y","z","aspect","colorSpace","premultipliedAlpha","queue","copyExternalImageToTexture","origin","texture"],"sources":["../../../src/adapter/resources/webgpu-texture.ts"],"sourcesContent":["// luma.gl, MIT license\nimport {Texture, TextureProps, Sampler, SamplerProps} from '@luma.gl/api';\nimport {getWebGPUTextureFormat} from '../helpers/convert-texture-format';\nimport type {WebGPUDevice} from '../webgpu-device';\nimport {WebGPUSampler} from './webgpu-sampler';\n\nconst BASE_DIMENSIONS: Record<string, '1d' | '2d' | '3d'> = {\n '1d': '1d',\n '2d': '2d',\n '2d-array': '2d',\n 'cube': '2d',\n 'cube-array': '2d',\n '3d': '3d'\n};\n\nexport class WebGPUTexture extends Texture {\n readonly device: WebGPUDevice;\n readonly handle: GPUTexture;\n readonly view: GPUTextureView;\n sampler: WebGPUSampler;\n\n // static async createFromImageURL(src, usage = 0) {\n // const img = document.createElement('img');\n // img.src = src;\n // await img.decode();\n // return WebGPUTexture(img, usage);\n // }\n\n constructor(device: WebGPUDevice, props: TextureProps) {\n super(device, props);\n\n if (typeof this.props.format === 'number') {\n throw new Error('number format');\n }\n\n this.device = device;\n this.handle = this.props.handle || this.createHandle();\n\n if (this.props.data) {\n this.setData({data: this.props.data} );\n }\n\n // Create a default sampler. This mimics the WebGL1 API where sampler props are stored on the texture\n // this.setSampler(props.sampler);\n this.sampler = props.sampler instanceof WebGPUSampler ? props.sampler : new WebGPUSampler(this.device, props.sampler);\n\n // TODO - To support texture arrays we need to create custom views...\n // But we are not ready to expose TextureViews to the public API.\n this.view = this.handle.createView({\n // format: this.props.format,\n // dimension: this.props.dimension,\n // aspect = \"all\";\n // baseMipLevel: 0;\n // mipLevelCount;\n // baseArrayLayer = 0;\n // arrayLayerCount;\n });\n }\n\n protected createHandle(): GPUTexture {\n if (typeof this.props.format === 'number') {\n throw new Error('number format');\n }\n\n // Deduce size from data - TODO this is a hack\n // @ts-expect-error\n const width = this.props.width || this.props.data?.width || 1;\n // @ts-expect-error\n const height = this.props.height || this.props.data?.height || 1;\n\n return this.device.handle.createTexture({\n size: {\n width,\n height,\n depthOrArrayLayers: this.props.depth\n },\n dimension: BASE_DIMENSIONS[this.props.dimension],\n format: getWebGPUTextureFormat(this.props.format),\n usage: this.props.usage,\n mipLevelCount: this.props.mipLevels,\n sampleCount: this.props.samples\n });\n }\n\n override destroy(): void {\n this.handle.destroy();\n }\n\n /**\n * Set default sampler\n * Accept a sampler instance or set of props;\n */\n setSampler(sampler: Sampler | SamplerProps): this {\n this.sampler = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);\n return this;\n }\n\n setData(options: {\n data: any;\n }) {\n return this.setImage({source: options.data});\n }\n\n /** Set image */\n setImage(options: {\n source: ImageBitmap | HTMLCanvasElement | OffscreenCanvas;\n width?: number;\n height?: number;\n depth?: number;\n sourceX?: number;\n sourceY?: number;\n mipLevel?: number;\n x?: number;\n y?: number;\n z?: number;\n aspect?: 'all' | 'stencil-only' | 'depth-only';\n colorSpace?: 'srgb';\n premultipliedAlpha?: boolean;\n }): this {\n const {\n source,\n width = options.source.width,\n height = options.source.height,\n depth = 1,\n sourceX = 0,\n sourceY = 0,\n mipLevel = 0,\n x = 0,\n y = 0,\n z = 0,\n aspect = 'all',\n colorSpace = 'srgb',\n premultipliedAlpha = false\n } = options;\n\n // TODO - max out width\n\n this.device.handle.queue.copyExternalImageToTexture(\n // source: GPUImageCopyExternalImage\n {\n source,\n origin: [sourceX, sourceY]\n },\n // destination: GPUImageCopyTextureTagged\n {\n texture: this.handle,\n origin: [x, y, z],\n mipLevel,\n aspect,\n colorSpace,\n premultipliedAlpha\n },\n // copySize: GPUExtent3D\n [\n width,\n height,\n depth\n ]\n );\n return this;\n }\n\n /*\n async readPixels() {\n const readbackBuffer = device.createBuffer({\n usage: Buffer.COPY_DST | Buffer.MAP_READ,\n size: 4 * textureWidth * textureHeight,\n });\n\n // Copy data from the texture to the buffer.\n const encoder = device.createCommandEncoder();\n encoder.copyTextureToBuffer(\n { texture },\n { buffer, rowPitch: textureWidth * 4 },\n [textureWidth, textureHeight],\n );\n device.submit([encoder.finish()]);\n\n // Get the data on the CPU.\n await buffer.mapAsync(GPUMapMode.READ);\n saveScreenshot(buffer.getMappedRange());\n buffer.unmap();\n }\n\n setImageData(imageData, usage): this {\n let data = null;\n\n const bytesPerRow = Math.ceil((img.width * 4) / 256) * 256;\n if (bytesPerRow == img.width * 4) {\n data = imageData.data;\n } else {\n data = new Uint8Array(bytesPerRow * img.height);\n let imagePixelIndex = 0;\n for (let y = 0; y < img.height; ++y) {\n for (let x = 0; x < img.width; ++x) {\n const i = x * 4 + y * bytesPerRow;\n data[i] = imageData.data[imagePixelIndex];\n data[i + 1] = imageData.data[imagePixelIndex + 1];\n data[i + 2] = imageData.data[imagePixelIndex + 2];\n data[i + 3] = imageData.data[imagePixelIndex + 3];\n imagePixelIndex += 4;\n }\n }\n }\n return this;\n }\n\n setData(data): this {\n const textureDataBuffer = this.device.handle.createBuffer({\n size: data.byteLength,\n usage: Buffer.COPY_DST | Buffer.COPY_SRC,\n mappedAtCreation: true\n });\n new Uint8Array(textureDataBuffer.getMappedRange()).set(data);\n textureDataBuffer.unmap();\n\n this.setBuffer(textureDataBuffer);\n\n textureDataBuffer.destroy();\n return this;\n }\n\n setBuffer(textureDataBuffer, {bytesPerRow}): this {\n const commandEncoder = this.device.handle.createCommandEncoder();\n commandEncoder.copyBufferToTexture(\n {\n buffer: textureDataBuffer,\n bytesPerRow\n },\n {\n texture: this.handle\n },\n {\n width,\n height,\n depth\n }\n );\n\n this.device.handle.defaultQueue.submit([commandEncoder.finish()]);\n return this;\n }\n */\n}\n"],"mappings":";AACA,SAAQA,OAAO,QAA4C,cAAc;AAAC,SAClEC,sBAAsB;AAAA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B,KAAK,GAAGc,OAAO,CAACE,MAAM,CAAChB,KAAK;MAC5BC,MAAM,GAAGa,OAAO,CAACE,MAAM,CAACf,MAAM;MAC9BI,KAAK,GAAG,CAAC;MACTY,OAAO,GAAG,CAAC;MACXC,OAAO,GAAG,CAAC;MACXC,QAAQ,GAAG,CAAC;MACZC,CAAC,GAAG,CAAC;MACLC,CAAC,GAAG,CAAC;MACLC,CAAC,GAAG,CAAC;MACLC,MAAM,GAAG,KAAK;MACdC,UAAU,GAAG,MAAM;MACnBC,kBAAkB,GAAG;IACvB,CAAC,GAAGX,OAAO;IAIX,IAAI,CAAC5B,MAAM,CAACK,MAAM,CAACmC,KAAK,CAACC,0BAA0B,CAEjD;MACEX,MAAM;MACNY,MAAM,EAAE,CAACX,OAAO,EAAEC,OAAO;IAC3B,CAAC,EAED;MACEW,OAAO,EAAE,IAAI,CAACtC,MAAM;MACpBqC,MAAM,EAAE,CAACR,CAAC,EAAEC,CAAC,EAAEC,CAAC,CAAC;MACjBH,QAAQ;MACRI,MAAM;MACNC,UAAU;MACVC;IACF,CAAC,EAED,CACEzB,KAAK,EACLC,MAAM,EACNI,KAAK,CACN,CACF;IACD,OAAO,IAAI;EACb;AAmFF"}
@@ -1,24 +1,22 @@
1
- /// <reference types="@webgpu/types" />
1
+ /// <reference types="dist" />
2
2
  import type { Texture, TextureFormat, CanvasContextProps } from '@luma.gl/api';
3
3
  import { CanvasContext } from '@luma.gl/api';
4
- import WebGPUDevice from './webgpu-device';
5
- import WEBGPUFramebuffer from './resources/webgpu-framebuffer';
4
+ import { WebGPUDevice } from './webgpu-device';
5
+ import { WebGPUFramebuffer } from './resources/webgpu-framebuffer';
6
6
  /**
7
7
  * Holds a WebGPU Canvas Context which handles resizing etc
8
8
  */
9
- export default class WebGPUCanvasContext extends CanvasContext {
9
+ export declare class WebGPUCanvasContext extends CanvasContext {
10
10
  readonly device: WebGPUDevice;
11
11
  readonly gpuCanvasContext: GPUCanvasContext;
12
12
  readonly format: TextureFormat;
13
- width: number;
14
- height: number;
15
13
  depthStencilFormat: TextureFormat;
16
14
  sampleCount: number;
17
15
  private depthStencilAttachment;
18
16
  constructor(device: WebGPUDevice, adapter: GPUAdapter, props: CanvasContextProps);
19
17
  destroy(): void;
20
18
  /** Update framebuffer with properly resized "swap chain" texture views */
21
- getCurrentFramebuffer(): WEBGPUFramebuffer;
19
+ getCurrentFramebuffer(): WebGPUFramebuffer;
22
20
  /** Resizes and updates render targets if necessary */
23
21
  update(): void;
24
22
  resize(options?: {
@@ -1 +1 @@
1
- {"version":3,"file":"webgpu-canvas-context.d.ts","sourceRoot":"","sources":["../../src/adapter/webgpu-canvas-context.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAC,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAC,aAAa,EAAM,MAAM,cAAc,CAAC;AAEhD,OAAO,YAAY,MAAM,iBAAiB,CAAC;AAC3C,OAAO,iBAAiB,MAAM,gCAAgC,CAAC;AAE/D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,aAAa;IAC5D,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAC5C,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAM;IACnB,MAAM,EAAE,MAAM,CAAM;IACpB,kBAAkB,EAAE,aAAa,CAAiB;IAClD,WAAW,EAAE,MAAM,CAAK;IAExB,OAAO,CAAC,sBAAsB,CAAU;gBAE5B,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,kBAAkB;IAOhF,OAAO;IAIP,0EAA0E;IAC1E,qBAAqB,IAAI,iBAAiB;IAsB1C,sDAAsD;IACtD,MAAM;IA6BN,MAAM,CAAC,OAAO,CAAC,EAAE;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,eAAe,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;KAAC,GAAG,IAAI;IAI7F,8FAA8F;IAC9F,6BAA6B;CAY9B"}
1
+ {"version":3,"file":"webgpu-canvas-context.d.ts","sourceRoot":"","sources":["../../src/adapter/webgpu-canvas-context.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAC,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAC,aAAa,EAAM,MAAM,cAAc,CAAC;AAEhD,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAC,iBAAiB,EAAC,MAAM,gCAAgC,CAAC;AAEjE;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,aAAa;IACpD,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAC5C,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,kBAAkB,EAAE,aAAa,CAAiB;IAClD,WAAW,EAAE,MAAM,CAAK;IAExB,OAAO,CAAC,sBAAsB,CAAwB;gBAE1C,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,kBAAkB;IAahF,OAAO,IAAI,IAAI;IAIf,0EAA0E;IAC1E,qBAAqB,IAAI,iBAAiB;IAsB1C,sDAAsD;IACtD,MAAM;IA6BN,MAAM,CAAC,OAAO,CAAC,EAAE;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,eAAe,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;KAAC,GAAG,IAAI;IAI7F,8FAA8F;IAC9F,6BAA6B;CAY9B"}
@@ -1,36 +1,26 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  import { CanvasContext, log } from '@luma.gl/api';
3
- import { getWebGPUTextureFormat } from './helpers/convert-texture-format';
4
- import WEBGPUFramebuffer from './resources/webgpu-framebuffer';
5
- export default class WebGPUCanvasContext extends CanvasContext {
3
+ import { getWebGPUTextureFormat } from "./helpers/convert-texture-format.js";
4
+ import { WebGPUFramebuffer } from "./resources/webgpu-framebuffer.js";
5
+ export class WebGPUCanvasContext extends CanvasContext {
6
6
  constructor(device, adapter, props) {
7
7
  super(props);
8
-
9
8
  _defineProperty(this, "device", void 0);
10
-
11
9
  _defineProperty(this, "gpuCanvasContext", void 0);
12
-
13
10
  _defineProperty(this, "format", void 0);
14
-
15
- _defineProperty(this, "width", -1);
16
-
17
- _defineProperty(this, "height", -1);
18
-
19
11
  _defineProperty(this, "depthStencilFormat", 'depth24plus');
20
-
21
12
  _defineProperty(this, "sampleCount", 1);
22
-
23
- _defineProperty(this, "depthStencilAttachment", void 0);
24
-
13
+ _defineProperty(this, "depthStencilAttachment", null);
25
14
  this.device = device;
15
+ this.width = -1;
16
+ this.height = -1;
17
+ this._setAutoCreatedCanvasId("".concat(this.device.id, "-canvas"));
26
18
  this.gpuCanvasContext = this.canvas.getContext('webgpu');
27
19
  this.format = this.gpuCanvasContext.getPreferredFormat(adapter);
28
20
  }
29
-
30
21
  destroy() {
31
22
  this.gpuCanvasContext.unconfigure();
32
23
  }
33
-
34
24
  getCurrentFramebuffer() {
35
25
  this.update();
36
26
  const currentColorAttachment = this.device.createTexture({
@@ -40,43 +30,34 @@ export default class WebGPUCanvasContext extends CanvasContext {
40
30
  width: this.width,
41
31
  height: this.height
42
32
  });
43
-
44
33
  this._createDepthStencilAttachment();
45
-
46
- return new WEBGPUFramebuffer(this.device, {
34
+ return new WebGPUFramebuffer(this.device, {
47
35
  colorAttachments: [currentColorAttachment],
48
36
  depthStencilAttachment: this.depthStencilAttachment
49
37
  });
50
38
  }
51
-
52
39
  update() {
53
40
  const [width, height] = this.getPixelSize();
54
41
  const sizeChanged = width !== this.width || height !== this.height;
55
-
56
42
  if (sizeChanged) {
57
43
  this.width = width;
58
44
  this.height = height;
59
-
60
45
  if (this.depthStencilAttachment) {
61
46
  this.depthStencilAttachment.destroy();
62
- this.depthStencilAttachment = undefined;
47
+ this.depthStencilAttachment = null;
63
48
  }
64
-
65
49
  this.gpuCanvasContext.configure({
66
50
  device: this.device.handle,
67
51
  format: getWebGPUTextureFormat(this.format),
68
- size: [this.width, this.height],
69
52
  colorSpace: this.props.colorSpace,
70
- compositingAlphaMode: this.props.compositingAlphaMode
53
+ alphaMode: this.props.alphaMode
71
54
  });
72
55
  log.log(1, "Resized to ".concat(this.width, "x").concat(this.height, "px"))();
73
56
  }
74
57
  }
75
-
76
58
  resize(options) {
77
59
  this.update();
78
60
  }
79
-
80
61
  _createDepthStencilAttachment() {
81
62
  if (!this.depthStencilAttachment) {
82
63
  this.depthStencilAttachment = this.device.createTexture({
@@ -87,9 +68,7 @@ export default class WebGPUCanvasContext extends CanvasContext {
87
68
  usage: GPUTextureUsage.RENDER_ATTACHMENT
88
69
  });
89
70
  }
90
-
91
71
  return this.depthStencilAttachment;
92
72
  }
93
-
94
73
  }
95
74
  //# sourceMappingURL=webgpu-canvas-context.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/adapter/webgpu-canvas-context.ts"],"names":["CanvasContext","log","getWebGPUTextureFormat","WEBGPUFramebuffer","WebGPUCanvasContext","constructor","device","adapter","props","gpuCanvasContext","canvas","getContext","format","getPreferredFormat","destroy","unconfigure","getCurrentFramebuffer","update","currentColorAttachment","createTexture","id","handle","getCurrentTexture","width","height","_createDepthStencilAttachment","colorAttachments","depthStencilAttachment","getPixelSize","sizeChanged","undefined","configure","size","colorSpace","compositingAlphaMode","resize","options","depthStencilFormat","usage","GPUTextureUsage","RENDER_ATTACHMENT"],"mappings":";AACA,SAAQA,aAAR,EAAuBC,GAAvB,QAAiC,cAAjC;AACA,SAAQC,sBAAR,QAAqC,kCAArC;AAEA,OAAOC,iBAAP,MAA8B,gCAA9B;A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ext, log} from '@luma.gl/api';\nimport {getWebGPUTextureFormat} from './helpers/convert-texture-format';\nimport WebGPUDevice from './webgpu-device';\nimport WEBGPUFramebuffer from './resources/webgpu-framebuffer';\n\n/** \n * Holds a WebGPU Canvas Context which handles resizing etc \n */\nexport default class WebGPUCanvasContext extends CanvasContext {\n readonly device: WebGPUDevice;\n readonly gpuCanvasContext: GPUCanvasContext;\n readonly format: TextureFormat;\n width: number = -1;\n height: number = -1;\n depthStencilFormat: TextureFormat = 'depth24plus';\n sampleCount: number = 1;\n\n private depthStencilAttachment: Texture;\n\n constructor(device: WebGPUDevice, adapter: GPUAdapter, props: CanvasContextProps) {\n super(props);\n this.device = device;\n this.gpuCanvasContext = this.canvas.getContext('webgpu') as GPUCanvasContext;\n this.format = this.gpuCanvasContext.getPreferredFormat(adapter);\n }\n\n destroy() {\n this.gpuCanvasContext.unconfigure();\n }\n\n /** Update framebuffer with properly resized \"swap chain\" texture views */\n getCurrentFramebuffer(): WEBGPUFramebuffer {\n // Ensure the canvas context size is updated\n this.update();\n\n // Wrap the current canvas context texture in a luma.gl texture \n const currentColorAttachment = this.device.createTexture({\n id: 'default-render-target',\n handle: this.gpuCanvasContext.getCurrentTexture(),\n format: this.format,\n width: this.width,\n height: this.height\n });\n\n // Resize the depth stencil attachment\n this._createDepthStencilAttachment();\n\n return new WEBGPUFramebuffer(this.device, {\n colorAttachments: [currentColorAttachment],\n depthStencilAttachment: this.depthStencilAttachment\n });\n }\n\n /** Resizes and updates render targets if necessary */\n update() {\n const [width, height] = this.getPixelSize();\n\n const sizeChanged = width !== this.width || height !== this.height;\n\n if (sizeChanged) {\n this.width = width;\n this.height = height;\n\n if (this.depthStencilAttachment) {\n this.depthStencilAttachment.destroy();\n this.depthStencilAttachment = undefined;\n }\n\n // Reconfigure the canvas size.\n // https://www.w3.org/TR/webgpu/#canvas-configuration\n this.gpuCanvasContext.configure({\n device: this.device.handle,\n format: getWebGPUTextureFormat(this.format),\n size: [this.width, this.height],\n colorSpace: this.props.colorSpace,\n compositingAlphaMode: this.props.compositingAlphaMode\n });\n\n log.log(1, `Resized to ${this.width}x${this.height}px`)();\n }\n\n }\n\n resize(options?: {width?: number; height?: number; useDevicePixels?: boolean | number}): void {\n this.update();\n }\n\n /** We build render targets on demand (i.e. not when size changes but when about to render) */\n _createDepthStencilAttachment() {\n if (!this.depthStencilAttachment) {\n this.depthStencilAttachment = this.device.createTexture({\n id: 'depth-stencil-target',\n format: this.depthStencilFormat,\n width: this.width,\n height: this.height,\n usage: GPUTextureUsage.RENDER_ATTACHMENT\n });\n }\n return this.depthStencilAttachment;\n }\n}\n"],"file":"webgpu-canvas-context.js"}
1
+ {"version":3,"file":"webgpu-canvas-context.js","names":["CanvasContext","log","getWebGPUTextureFormat","WebGPUFramebuffer","WebGPUCanvasContext","constructor","device","adapter","props","_defineProperty","width","height","_setAutoCreatedCanvasId","concat","id","gpuCanvasContext","canvas","getContext","format","getPreferredFormat","destroy","unconfigure","getCurrentFramebuffer","update","currentColorAttachment","createTexture","handle","getCurrentTexture","_createDepthStencilAttachment","colorAttachments","depthStencilAttachment","getPixelSize","sizeChanged","configure","colorSpace","alphaMode","resize","options","depthStencilFormat","usage","GPUTextureUsage","RENDER_ATTACHMENT"],"sources":["../../src/adapter/webgpu-canvas-context.ts"],"sourcesContent":["import type {Texture, TextureFormat, CanvasContextProps} from '@luma.gl/api';\nimport {CanvasContext, log} from '@luma.gl/api';\nimport {getWebGPUTextureFormat} from './helpers/convert-texture-format';\nimport {WebGPUDevice} from './webgpu-device';\nimport {WebGPUFramebuffer} from './resources/webgpu-framebuffer';\n\n/** \n * Holds a WebGPU Canvas Context which handles resizing etc \n */\nexport class WebGPUCanvasContext extends CanvasContext {\n readonly device: WebGPUDevice;\n readonly gpuCanvasContext: GPUCanvasContext;\n readonly format: TextureFormat;\n depthStencilFormat: TextureFormat = 'depth24plus';\n sampleCount: number = 1;\n\n private depthStencilAttachment: Texture | null = null;\n\n constructor(device: WebGPUDevice, adapter: GPUAdapter, props: CanvasContextProps) {\n super(props);\n this.device = device;\n // TODO - hack to trigger resize?\n this.width = -1;\n this.height = -1;\n \n this._setAutoCreatedCanvasId(`${this.device.id}-canvas`);\n this.gpuCanvasContext = this.canvas.getContext('webgpu') as GPUCanvasContext;\n // @ts-expect-error TODO this has been replaced\n this.format = this.gpuCanvasContext.getPreferredFormat(adapter);\n }\n\n destroy(): void {\n this.gpuCanvasContext.unconfigure();\n }\n\n /** Update framebuffer with properly resized \"swap chain\" texture views */\n getCurrentFramebuffer(): WebGPUFramebuffer {\n // Ensure the canvas context size is updated\n this.update();\n\n // Wrap the current canvas context texture in a luma.gl texture \n const currentColorAttachment = this.device.createTexture({\n id: 'default-render-target',\n handle: this.gpuCanvasContext.getCurrentTexture(),\n format: this.format,\n width: this.width,\n height: this.height\n });\n\n // Resize the depth stencil attachment\n this._createDepthStencilAttachment();\n\n return new WebGPUFramebuffer(this.device, {\n colorAttachments: [currentColorAttachment],\n depthStencilAttachment: this.depthStencilAttachment\n });\n }\n\n /** Resizes and updates render targets if necessary */\n update() {\n const [width, height] = this.getPixelSize();\n\n const sizeChanged = width !== this.width || height !== this.height;\n\n if (sizeChanged) {\n this.width = width;\n this.height = height;\n\n if (this.depthStencilAttachment) {\n this.depthStencilAttachment.destroy();\n this.depthStencilAttachment = null;\n }\n\n // Reconfigure the canvas size.\n // https://www.w3.org/TR/webgpu/#canvas-configuration\n this.gpuCanvasContext.configure({\n device: this.device.handle,\n format: getWebGPUTextureFormat(this.format),\n // size: [this.width, this.height],\n colorSpace: this.props.colorSpace,\n alphaMode: this.props.alphaMode\n });\n\n log.log(1, `Resized to ${this.width}x${this.height}px`)();\n }\n\n }\n\n resize(options?: {width?: number; height?: number; useDevicePixels?: boolean | number}): void {\n this.update();\n }\n\n /** We build render targets on demand (i.e. not when size changes but when about to render) */\n _createDepthStencilAttachment() {\n if (!this.depthStencilAttachment) {\n this.depthStencilAttachment = this.device.createTexture({\n id: 'depth-stencil-target',\n format: this.depthStencilFormat,\n width: this.width,\n height: this.height,\n usage: GPUTextureUsage.RENDER_ATTACHMENT\n });\n }\n return this.depthStencilAttachment;\n }\n}\n"],"mappings":";AACA,SAAQA,aAAa,EAAEC,GAAG,QAAO,cAAc;AAAC,SACxCC,sBAAsB;AAAA,SAEtBC,iBAAiB;AAKzB,OAAO,MAAMC,mBAAmB,SAASJ,aAAa,CAAC;EASrDK,WAAWA,CAACC,MAAoB,EAAEC,OAAmB,EAAEC,KAAyB,EAAE;IAChF,KAAK,CAACA,KAAK,CAAC;IAACC,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA,6BANqB,aAAa;IAAAA,eAAA,sBAC3B,CAAC;IAAAA,eAAA,iCAE0B,IAAI;IAInD,IAAI,CAACH,MAAM,GAAGA,MAAM;IAEpB,IAAI,CAACI,KAAK,GAAG,CAAC,CAAC;IACf,IAAI,CAACC,MAAM,GAAG,CAAC,CAAC;IAEhB,IAAI,CAACC,uBAAuB,IAAAC,MAAA,CAAI,IAAI,CAACP,MAAM,CAACQ,EAAE,aAAU;IACxD,IAAI,CAACC,gBAAgB,GAAG,IAAI,CAACC,MAAM,CAACC,UAAU,CAAC,QAAQ,CAAqB;IAE5E,IAAI,CAACC,MAAM,GAAG,IAAI,CAACH,gBAAgB,CAACI,kBAAkB,CAACZ,OAAO,CAAC;EACjE;EAEAa,OAAOA,CAAA,EAAS;IACd,IAAI,CAACL,gBAAgB,CAACM,WAAW,EAAE;EACrC;EAGAC,qBAAqBA,CAAA,EAAsB;IAEzC,IAAI,CAACC,MAAM,EAAE;IAGb,MAAMC,sBAAsB,GAAG,IAAI,CAAClB,MAAM,CAACmB,aAAa,CAAC;MACvDX,EAAE,EAAE,uBAAuB;MAC3BY,MAAM,EAAE,IAAI,CAACX,gBAAgB,CAACY,iBAAiB,EAAE;MACjDT,MAAM,EAAE,IAAI,CAACA,MAAM;MACnBR,KAAK,EAAE,IAAI,CAACA,KAAK;MACjBC,MAAM,EAAE,IAAI,CAACA;I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