@luma.gl/webgpu 9.0.0-alpha.7 → 9.0.0-alpha.9

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 (46) hide show
  1. package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
  2. package/dist/adapter/helpers/webgpu-parameters.js +47 -38
  3. package/dist/adapter/helpers/webgpu-parameters.js.map +1 -1
  4. package/dist/adapter/resources/webgpu-buffer.d.ts +0 -1
  5. package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
  6. package/dist/adapter/resources/webgpu-buffer.js +0 -4
  7. package/dist/adapter/resources/webgpu-buffer.js.map +1 -1
  8. package/dist/adapter/resources/webgpu-command-encoder.d.ts +0 -1
  9. package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
  10. package/dist/adapter/resources/webgpu-command-encoder.js +7 -7
  11. package/dist/adapter/resources/webgpu-command-encoder.js.map +1 -1
  12. package/dist/adapter/resources/webgpu-compute-pass.d.ts +1 -1
  13. package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
  14. package/dist/adapter/resources/webgpu-compute-pass.js +5 -3
  15. package/dist/adapter/resources/webgpu-compute-pass.js.map +1 -1
  16. package/dist/adapter/resources/webgpu-framebuffer.d.ts +1 -1
  17. package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
  18. package/dist/adapter/resources/webgpu-framebuffer.js +1 -1
  19. package/dist/adapter/resources/webgpu-framebuffer.js.map +1 -1
  20. package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
  21. package/dist/adapter/resources/webgpu-render-pass.js +9 -3
  22. package/dist/adapter/resources/webgpu-render-pass.js.map +1 -1
  23. package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
  24. package/dist/adapter/resources/webgpu-render-pipeline.js +13 -3
  25. package/dist/adapter/resources/webgpu-render-pipeline.js.map +1 -1
  26. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  27. package/dist/adapter/resources/webgpu-texture.js +2 -2
  28. package/dist/adapter/resources/webgpu-texture.js.map +1 -1
  29. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
  30. package/dist/adapter/webgpu-canvas-context.js +2 -2
  31. package/dist/adapter/webgpu-canvas-context.js.map +1 -1
  32. package/dist/adapter/webgpu-device.d.ts +6 -6
  33. package/dist/adapter/webgpu-device.d.ts.map +1 -1
  34. package/dist/adapter/webgpu-device.js +31 -14
  35. package/dist/adapter/webgpu-device.js.map +1 -1
  36. package/package.json +3 -3
  37. package/src/adapter/helpers/webgpu-parameters.ts +48 -45
  38. package/src/adapter/resources/webgpu-buffer.ts +0 -4
  39. package/src/adapter/resources/webgpu-command-encoder.ts +8 -7
  40. package/src/adapter/resources/webgpu-compute-pass.ts +2 -2
  41. package/src/adapter/resources/webgpu-framebuffer.ts +1 -1
  42. package/src/adapter/resources/webgpu-render-pass.ts +6 -3
  43. package/src/adapter/resources/webgpu-render-pipeline.ts +13 -4
  44. package/src/adapter/resources/webgpu-texture.ts +3 -2
  45. package/src/adapter/webgpu-canvas-context.ts +2 -2
  46. package/src/adapter/webgpu-device.ts +44 -32
@@ -20,7 +20,7 @@ export default class WebGPURenderPipeline extends RenderPipeline {
20
20
 
21
21
  _defineProperty(this, "_buffers", void 0);
22
22
 
23
- _defineProperty(this, "_indexBuffer", void 0);
23
+ _defineProperty(this, "_indexBuffer", null);
24
24
 
25
25
  _defineProperty(this, "_bindGroupLayout", void 0);
26
26
 
@@ -94,15 +94,25 @@ export default class WebGPURenderPipeline extends RenderPipeline {
94
94
  let fragment;
95
95
 
96
96
  if (this.props.fs) {
97
+ var _this$device, _this$device$canvasCo;
98
+
97
99
  fragment = {
98
100
  module: cast(this.props.fs).handle,
99
101
  entryPoint: this.props.fsEntryPoint || 'main',
100
102
  targets: [{
101
- format: getWebGPUTextureFormat(this.device.canvasContext.format)
103
+ format: getWebGPUTextureFormat((_this$device = this.device) === null || _this$device === void 0 ? void 0 : (_this$device$canvasCo = _this$device.canvasContext) === null || _this$device$canvasCo === void 0 ? void 0 : _this$device$canvasCo.format)
102
104
  }]
103
105
  };
104
106
  }
105
107
 
108
+ switch (this.props.topology) {
109
+ case 'triangle-fan':
110
+ case 'line-loop':
111
+ throw new Error("WebGPU does not support primitive topology ".concat(this.props.topology));
112
+
113
+ default:
114
+ }
115
+
106
116
  let descriptor = {
107
117
  vertex,
108
118
  fragment,
@@ -127,7 +137,7 @@ export default class WebGPURenderPipeline extends RenderPipeline {
127
137
  if (options.indexCount) {
128
138
  webgpuRenderPass.handle.drawIndexed(options.indexCount, options.instanceCount, options.firstIndex, options.baseVertex, options.firstInstance);
129
139
  } else {
130
- webgpuRenderPass.handle.draw(options.vertexCount, options.instanceCount, options.firstIndex, options.firstInstance);
140
+ webgpuRenderPass.handle.draw(options.vertexCount || 0, options.instanceCount, options.firstIndex, options.firstInstance);
131
141
  }
132
142
  }
133
143
 
@@ -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","vs","fs","_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","entryPoint","vsEntryPoint","buffers","fragment","fsEntryPoint","targets","format","canvasContext","primitive","topology","parameters","draw","options","webgpuRenderPass","renderPass","getDefaultRenderPass","setPipeline","setBindGroup","_setAttributeBuffers","indexCount","drawIndexed","instanceCount","firstIndex","baseVertex","first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,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGzB,OAAO,CAACnC,MAA5B,EAAoC,EAAE4D,CAAtC,EAAyC;AACvC,YAAMzC,MAAM,GAAG5C,IAAI,CAAe4D,OAAO,CAACyB,CAAD,CAAtB,CAAnB;;AACA,UAAI,CAACzC,MAAL,EAAa;AACX,cAAM0C,SAAS,GAAG,KAAK3E,KAAL,CAAWQ,MAAX,CAAkBuB,UAAlB,CAA6B6C,IAA7B,CACfD,SAAD,IAAeA,SAAS,CAACE,QAAV,KAAuBH,CADtB,CAAlB;AAGA,cAAM,IAAItC,KAAJ,6CACiC,CAAAuC,SAAS,SAAT,IAAAA,SAAS,WAAT,YAAAA,SAAS,CAAE3C,IAAX,KAAmB,EADpD,yBACqE,KAAKhC,KAAL,CAAWI,EADhF,OAAN;AAGD;;AACDwD,MAAAA,gBAAgB,CAAC3D,MAAjB,CAAwB6E,eAAxB,CAAwCJ,CAAxC,EAA2CzC,MAAM,CAAChC,MAAlD;AACD;AAsBF;;AAzN8D","sourcesContent":["import type {Binding, RenderPass, Shader} 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 vs: WebGPUShader;\n fs: WebGPUShader | null = null;\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.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 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,"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","vs","fs","_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","entryPoint","vsEntryPoint","buffers","fragment","fsEntryPoint","targets","format","canvasContext","topology","primitive","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;AAiB/DU,EAAAA,WAAW,CAACC,MAAD,EAAuBC,KAAvB,EAAmD;AAC5D,UAAMD,MAAN,EAAcC,KAAd;;AAD4D;;AAAA;;AAAA;;AAAA,gCAZpC,IAYoC;;AAAA;;AAAA;;AAAA,0CARlB,IAQkB;;AAAA;;AAAA,wCAFpB,IAEoB;;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,EAAL,GAAUhB,IAAI,CAAeW,KAAK,CAACK,EAArB,CAAd;AACA,SAAKC,EAAL,GAAUjB,IAAI,CAAeW,KAAK,CAACM,EAArB,CAAd;AAE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8D","sourcesContent":["import type {Binding, RenderPass, Shader} 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 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 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 // 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 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 || 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"],"file":"webgpu-render-pipeline.js"}
@@ -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,cAAc,CAAC;AAElF,OAAO,KAAK,YAAY,MAAM,kBAAkB,CAAC;AACjD,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAW7C,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,OAAO;IAChD,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,OAAO,EAAE,aAAa,CAAC;gBASX,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY;IA8BrD,SAAS,CAAC,YAAY,IAAI,UAAU;IAyBpC,OAAO,IAAI,IAAI;IAIf;;;OAGG;IACH,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,YAAY,GAAG,IAAI;IAKjD,OAAO,CAAC,OAAO,EAAE;QACf,IAAI,EAAE,GAAG,CA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GAAG,YAAY,GAAG,IAAI;IAKjD,OAAO,CAAC,OAAO,EAAE;QACf,IAAI,EAAE,GAAG,CAAC;KACX;IAID,gBAAgB;IAChB,QAAQ,CAAC,OAAO,EAAE;QAChB,MAAM,EAAE,WAAW,GAAG,iBAAiB,GAAG,eAAe,CAAC;QAC1D,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,CAAC,CAAC,EAAE,MAAM,CAAC;QACX,CAAC,CAAC,EAAE,MAAM,CAAC;QACX,CAAC,CAAC,EAAE,MAAM,CAAC;QACX,MAAM,CAAC,EAAE,KAAK,GAAG,cAAc,GAAG,YAAY,CAAC;QAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,kBAAkB,CAAC,EAAE,OAAO,CAAC;KAC9B,GAAG,IAAI;CA6HT"}
@@ -20,7 +20,7 @@ export default class WebGPUTexture extends Texture {
20
20
 
21
21
  _defineProperty(this, "view", void 0);
22
22
 
23
- _defineProperty(this, "sampler", void 0);
23
+ _defineProperty(this, "sampler", null);
24
24
 
25
25
  if (typeof this.props.format === 'number') {
26
26
  throw new Error('number format');
@@ -35,7 +35,7 @@ export default class WebGPUTexture extends Texture {
35
35
  });
36
36
  }
37
37
 
38
- this.setSampler(props.sampler);
38
+ this.sampler = props.sampler instanceof WebGPUSampler ? props.sampler : new WebGPUSampler(this.device, props.sampler);
39
39
  this.view = this.handle.createView({});
40
40
  }
41
41
 
@@ -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,QAAjC,EAA2C;AACzC,YAAM,IAAIC,KAAJ,CAAU,eAAV,CAAN;AACD;;AAED,SAAKH,MAAL,GAAcA,MAAd;AACA,SAAKI,MAAL,GAAc,KAAKH,KAAL,CAAWG,MAAX,IAAqB,KAAKC,YAAL,EAAnC;;AAEA,QAAI,KAAKJ,KAAL,CAAWK,IAAf,EAAqB;AACnB,WAAKC,OAAL,CAAa;AAACD,QAAAA,IAAI,EAAE,KAAKL,KAAL,CAAWK;AAAlB,OAAb;AACD;;AAGD,SAAKE,UAAL,CAAgBP,KAAK,CAACQ,OAAtB;AAIA,SAAKC,IAAL,GAAY,KAAKN,MAAL,CAAYO,UAAZ,CAAuB,EAAvB,CAAZ;AASD;;AAESN,EAAAA,YAAY,GAAe;AAAA;;AACnC,QAAI,OAAO,KAAKJ,KAAL,CAAWC,MAAlB,KAA6B,QAAjC,EAA2C;AACzC,YAAM,IAAIC,KAAJ,CAAU,eAAV,CAAN;AACD;;AAID,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ACJE,MAAAA,MADI;AAEJf,MAAAA,KAAK,GAAGa,OAAO,CAACE,MAAR,CAAef,KAFnB;AAGJC,MAAAA,MAAM,GAAGY,OAAO,CAACE,MAAR,CAAed,MAHpB;AAIJI,MAAAA,KAAK,GAAG,CAJJ;AAKJW,MAAAA,OAAO,GAAG,CALN;AAMJC,MAAAA,OAAO,GAAG,CANN;AAOJC,MAAAA,QAAQ,GAAG,CAPP;AAQJC,MAAAA,CAAC,GAAG,CARA;AASJC,MAAAA,CAAC,GAAG,CATA;AAUJC,MAAAA,CAAC,GAAG,CAVA;AAWJC,MAAAA,MAAM,GAAG,KAXL;AAYJC,MAAAA,UAAU,GAAG,MAZT;AAaJC,MAAAA,kBAAkB,GAAG;AAbjB,QAcFX,OAdJ;AAkBA,SAAKzB,MAAL,CAAYI,MAAZ,CAAmBiC,KAAnB,CAAyBC,0BAAzB,CAEE;AACEX,MAAAA,MADF;AAEEY,MAAAA,MAAM,EAAE,CAACX,OAAD,EAAUC,OAAV;AAFV,KAFF,EAOE;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,"sources":["../../../src/adapter/resources/webgpu-texture.ts"],"names":["Texture","getWebGPUTextureFormat","WebGPUSampler","BASE_DIMENSIONS","WebGPUTexture","constructor","device","props","format","Error","handle","createHandle","data","setData","sampler","view","createView","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"],"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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G,KAXL;AAYJC,MAAAA,UAAU,GAAG,MAZT;AAaJC,MAAAA,kBAAkB,GAAG;AAbjB,QAcFX,OAdJ;AAkBA,SAAKzB,MAAL,CAAYI,MAAZ,CAAmBiC,KAAnB,CAAyBC,0BAAzB,CAEE;AACEX,MAAAA,MADF;AAEEY,MAAAA,MAAM,EAAE,CAACX,OAAD,EAAUC,OAAV;AAFV,KAFF,EAOE;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,CACEzB,KADF,EAEEC,MAFF,EAGEI,KAHF,CAhBF;AAsBA,WAAO,IAAP;AACD;;AAjJgD","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 = null;\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 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 +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,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,CAAwB;gBAE1C,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"}
@@ -20,7 +20,7 @@ export default class WebGPUCanvasContext extends CanvasContext {
20
20
 
21
21
  _defineProperty(this, "sampleCount", 1);
22
22
 
23
- _defineProperty(this, "depthStencilAttachment", void 0);
23
+ _defineProperty(this, "depthStencilAttachment", null);
24
24
 
25
25
  this.device = device;
26
26
  this.gpuCanvasContext = this.canvas.getContext('webgpu');
@@ -59,7 +59,7 @@ export default class WebGPUCanvasContext extends CanvasContext {
59
59
 
60
60
  if (this.depthStencilAttachment) {
61
61
  this.depthStencilAttachment.destroy();
62
- this.depthStencilAttachment = undefined;
62
+ this.depthStencilAttachment = null;
63
63
  }
64
64
 
65
65
  this.gpuCanvasContext.configure({
@@ -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;AAKA,eAAe,MAAMC,mBAAN,SAAkCJ,aAAlC,CAAgD;AAW7DK,EAAAA,WAAW,CAACC,MAAD,EAAuBC,OAAvB,EAA4CC,KAA5C,EAAuE;AAChF,UAAMA,KAAN;;AADgF;;AAAA;;AAAA;;AAAA,mCAPlE,CAAC,CAOiE;;AAAA,oCANjE,CAAC,CAMgE;;AAAA,gDAL9C,aAK8C;;AAAA,yCAJ5D,CAI4D;;AAAA;;AAEhF,SAAKF,MAAL,GAAcA,MAAd;AACA,SAAKG,gBAAL,GAAwB,KAAKC,MAAL,CAAYC,UAAZ,CAAuB,QAAvB,CAAxB;AACA,SAAKC,MAAL,GAAc,KAAKH,gBAAL,CAAsBI,kBAAtB,CAAyCN,O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AKC,MAAlB,CAHwB;AAI9BS,QAAAA,UAAU,EAAE,KAAKzB,KAAL,CAAWyB,UAJO;AAK9BC,QAAAA,oBAAoB,EAAE,KAAK1B,KAAL,CAAW0B;AALH,OAAhC;AAQAjC,MAAAA,GAAG,CAACA,GAAJ,CAAQ,CAAR,uBAAyB,KAAKsB,KAA9B,cAAuC,KAAKC,MAA5C;AACD;AAEF;;AAEDW,EAAAA,MAAM,CAACC,OAAD,EAAwF;AAC5F,SAAKnB,MAAL;AACD;;AAGDQ,EAAAA,6BAA6B,GAAG;AAC9B,QAAI,CAAC,KAAKE,sBAAV,EAAkC;AAChC,WAAKA,sBAAL,GAA8B,KAAKrB,MAAL,CAAYa,aAAZ,CAA0B;AACtDC,QAAAA,EAAE,EAAE,sBADkD;AAEtDR,QAAAA,MAAM,EAAE,KAAKyB,kBAFyC;AAGtDd,QAAAA,KAAK,EAAE,KAAKA,KAH0C;AAItDC,QAAAA,MAAM,EAAE,KAAKA,MAJyC;AAKtDc,QAAAA,KAAK,EAAEC,eAAe,CAACC;AAL+B,OAA1B,CAA9B;AAOD;;AACD,WAAO,KAAKb,sBAAZ;AACD;;AA3F4D","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 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,"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","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;AAKA,eAAe,MAAMC,mBAAN,SAAkCJ,aAAlC,CAAgD;AAW7DK,EAAAA,WAAW,CAACC,MAAD,EAAuBC,OAAvB,EAA4CC,KAA5C,EAAuE;AAChF,UAAMA,KAAN;;AADgF;;AAAA;;AAAA;;AAAA,mCAPlE,CAAC,CAOiE;;AAAA,oCANjE,CAAC,CAMgE;;AAAA,gDAL9C,aAK8C;;AAAA,yCAJ5D,CAI4D;;AAAA,oDAFjC,IAEiC;;AAEhF,SAAKF,MAAL,GAAcA,MAAd;AACA,SAAKG,gBAAL,GAAwB,KAAKC,MAAL,CAAYC,UAAZ,CAAuB,QAAvB,CAAxB;AACA,SAAKC,MAAL,GAAc,KAAKH,gBAAL,CAAsBI,kBAAtB,CAAyCN,OAAzC,CAAd;AACD;;AAEDO,EAAAA,OAAO,GAAG;AACR,SAAKL,gBAAL,CAAsBM,WAAtB;AACD;;AAGDC,EAAAA,qBAAqB,GAAsB;AAEzC,SAAKC,MAAL;AAGA,UAAMC,sBAAsB,GAAG,KAAKZ,MAAL,CAAYa,aAAZ,CAA0B;AACvDC,MAAAA,EAAE,EAAE,uBADmD;AAEvDC,MAAAA,MAAM,EAAE,KAAKZ,gBAAL,CAAsBa,iBAAtB,EAF+C;AAGvDV,MAAAA,MAAM,EAAE,KA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BAA6B,GAAG;AAC9B,QAAI,CAAC,KAAKE,sBAAV,EAAkC;AAChC,WAAKA,sBAAL,GAA8B,KAAKrB,MAAL,CAAYa,aAAZ,CAA0B;AACtDC,QAAAA,EAAE,EAAE,sBADkD;AAEtDR,QAAAA,MAAM,EAAE,KAAKwB,kBAFyC;AAGtDb,QAAAA,KAAK,EAAE,KAAKA,KAH0C;AAItDC,QAAAA,MAAM,EAAE,KAAKA,MAJyC;AAKtDa,QAAAA,KAAK,EAAEC,eAAe,CAACC;AAL+B,OAA1B,CAA9B;AAOD;;AACD,WAAO,KAAKZ,sBAAZ;AACD;;AA3F4D","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 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 | null = null;\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 = 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 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"}
@@ -20,9 +20,9 @@ export default class WebGPUDevice extends Device {
20
20
  reason: 'destroyed';
21
21
  message: string;
22
22
  }>;
23
- canvasContext: WebGPUCanvasContext | undefined;
24
- commandEncoder: GPUCommandEncoder;
25
- renderPass: WebGPURenderPass;
23
+ canvasContext: WebGPUCanvasContext | null;
24
+ commandEncoder: GPUCommandEncoder | null;
25
+ renderPass: WebGPURenderPass | null;
26
26
  private _info;
27
27
  private _isLost;
28
28
  static type: string;
@@ -52,9 +52,9 @@ export default class WebGPUDevice extends Device {
52
52
  * Allows a render pass to begin against a canvas context
53
53
  * @todo need to support a "Framebuffer" equivalent (aka preconfigured RenderPassDescriptors?).
54
54
  */
55
- beginRenderPass(props?: RenderPassProps): WebGPURenderPass;
56
- beginComputePass(props?: ComputePassProps): WebGPUComputePass;
57
- createCanvasContext(props?: CanvasContextProps): WebGPUCanvasContext;
55
+ beginRenderPass(props: RenderPassProps): WebGPURenderPass;
56
+ beginComputePass(props: ComputePassProps): WebGPUComputePass;
57
+ createCanvasContext(props: CanvasContextProps): WebGPUCanvasContext;
58
58
  /**
59
59
  * Gets default renderpass encoder.
60
60
  * Creates a new encoder against default canvasContext if not already created
@@ -1 +1 @@
1
- {"version":3,"file":"webgpu-device.d.ts","sourceRoot":"","sources":["../../src/adapter/webgpu-device.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,aAAa,EACb,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,MAAM,EAA2B,MAAM,cAAc,CAAC;AAC9D,OAAO,YAAY,MAAM,2BAA2B,CAAC;AACrD,OAAO,aAAa,MAAM,4BAA4B,CAAC;AACvD,OAAO,qBAAqB,MAAM,qCAAqC,CAAC;AACxE,OAAO,aAAa,MAAM,4BAA4B,CAAC;AACvD,OAAO,YAAY,MAAM,2BAA2B,CAAC;AACrD,OAAO,oBAAoB,MAAM,oCAAoC,CAAC;AACtE,OAAO,iBAAiB,MAAM,gCAAgC,CAAC;AAC/D,OAAO,qBAAqB,MAAM,qCAAqC,CAAC;AACxE,OAAO,gBAAgB,MAAM,gCAAgC,CAAC;AAC9D,OAAO,iBAAiB,MAAM,iCAAiC,CAAC;AAEhE,OAAO,mBAAmB,MAAM,yBAAyB,CAAC;AAG1D,mCAAmC;AACnC,MAAM,CAAC,OAAO,OAAO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a;IAIlD,qBAAqB,CAAC,KAAK,EAAE,oBAAoB,GAAG,qBAAqB;IAIzE,YAAY,CAAC,KAAK,EAAE,WAAW,GAAG,YAAY;IAI9C,aAAa,CAAC,KAAK,EAAE,YAAY,GAAG,aAAa;IAIjD,oBAAoB,CAAC,KAAK,EAAE,mBAAmB,GAAG,oBAAoB;IAItE,iBAAiB,CAAC,KAAK,EAAE,gBAAgB,GAAG,iBAAiB;IAI7D,qBAAqB,CAAC,KAAK,EAAE,oBAAoB,GAAG,qBAAqB;IAMzE;;;OAGG;IACH,eAAe,CAAC,KAAK,EAAE,eAAe,GAAG,gBAAgB;IAKzD,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,GAAG,iBAAiB;IAK5D,mBAAmB,CAAC,KAAK,EAAE,kBAAkB,GAAG,mBAAmB;IAInE;;;;OAIG;IACH,oBAAoB,IAAI,gBAAgB;IASxC,MAAM,IAAI,IAAI;IAUd,YAAY;CAsDb"}
@@ -22,21 +22,26 @@ export default class WebGPUDevice extends Device {
22
22
 
23
23
  log.groupCollapsed(1, 'WebGPUDevice created')();
24
24
  const adapter = await navigator.gpu.requestAdapter({
25
- powerPreference: "high-performance"
25
+ powerPreference: 'high-performance'
26
26
  });
27
- log.probe(1, "Adapter available")();
27
+
28
+ if (!adapter) {
29
+ throw new Error('Failed to request WebGPU adapter');
30
+ }
31
+
32
+ log.probe(1, 'Adapter available')();
28
33
  const gpuDevice = await adapter.requestDevice({
29
34
  requiredFeatures: adapter.features
30
35
  });
31
- log.probe(1, "GPUDevice available")();
36
+ log.probe(1, 'GPUDevice available')();
32
37
 
33
38
  if (typeof props.canvas === 'string') {
34
39
  await CanvasContext.pageLoaded;
35
- log.probe(1, "DOM is loaded")();
40
+ log.probe(1, 'DOM is loaded')();
36
41
  }
37
42
 
38
43
  const device = new WebGPUDevice(gpuDevice, adapter, props);
39
- log.probe(1, "Device created", device.info)();
44
+ log.probe(1, 'Device created', device.info)();
40
45
  log.table(1, device.info)();
41
46
  log.groupEnd(1)();
42
47
  return device;
@@ -51,11 +56,11 @@ export default class WebGPUDevice extends Device {
51
56
 
52
57
  _defineProperty(this, "lost", void 0);
53
58
 
54
- _defineProperty(this, "canvasContext", void 0);
59
+ _defineProperty(this, "canvasContext", null);
55
60
 
56
- _defineProperty(this, "commandEncoder", void 0);
61
+ _defineProperty(this, "commandEncoder", null);
57
62
 
58
- _defineProperty(this, "renderPass", void 0);
63
+ _defineProperty(this, "renderPass", null);
59
64
 
60
65
  _defineProperty(this, "_info", void 0);
61
66
 
@@ -79,9 +84,13 @@ export default class WebGPUDevice extends Device {
79
84
  vendorMasked: '',
80
85
  rendererMasked: ''
81
86
  };
82
- this.lost = this.handle.lost;
83
- this.lost.then(_ => {
87
+ this.lost = new Promise(async resolve => {
88
+ const lostInfo = await this.handle.lost;
84
89
  this._isLost = true;
90
+ resolve({
91
+ reason: 'destroyed',
92
+ message: lostInfo.message
93
+ });
85
94
  });
86
95
 
87
96
  if (props.canvas) {
@@ -168,16 +177,24 @@ export default class WebGPUDevice extends Device {
168
177
  }
169
178
 
170
179
  getDefaultRenderPass() {
180
+ var _this$canvasContext;
181
+
171
182
  this.renderPass = this.renderPass || this.beginRenderPass({
172
- framebuffer: this.canvasContext.getCurrentFramebuffer()
183
+ framebuffer: (_this$canvasContext = this.canvasContext) === null || _this$canvasContext === void 0 ? void 0 : _this$canvasContext.getCurrentFramebuffer()
173
184
  });
174
185
  return this.renderPass;
175
186
  }
176
187
 
177
188
  submit() {
178
- this.renderPass.endPass();
179
- const commandBuffer = this.commandEncoder.finish();
180
- this.handle.queue.submit([commandBuffer]);
189
+ var _this$renderPass, _this$commandEncoder;
190
+
191
+ (_this$renderPass = this.renderPass) === null || _this$renderPass === void 0 ? void 0 : _this$renderPass.endPass();
192
+ const commandBuffer = (_this$commandEncoder = this.commandEncoder) === null || _this$commandEncoder === void 0 ? void 0 : _this$commandEncoder.finish();
193
+
194
+ if (commandBuffer) {
195
+ this.handle.queue.submit([commandBuffer]);
196
+ }
197
+
181
198
  this.commandEncoder = null;
182
199
  this.renderPass = null;
183
200
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/adapter/webgpu-device.ts"],"names":["Device","CanvasContext","log","WebGPUBuffer","WebGPUTexture","WebGPUExternalTexture","WebGPUSampler","WebGPUShader","WebGPURenderPipeline","WebGPUComputePipeline","WebGPURenderPass","WebGPUComputePass","WebGPUCanvasContext","WebGPUDevice","isSupported","Boolean","navigator","gpu","create","props","Error","groupCollapsed","adapter","requestAdapter","powerPreference","probe","gpuDevice","requestDevice","requiredFeatures","features","canvas","pageLoaded","device","info","table","groupEnd","constructor","handle","_info","type","vendor","name","renderer","version","shadingLanguages","shadingLanguageVersions","glsl","wgsl","vendorMasked","rendererMasked","lost","then","_","_isLost","canvasContext","_getFeatures","destroy","limits","isTextureFormatSupported","format","includes","isTextureFormatFilterable","isTextureFormatRenderable","isLost","_createBuffer","_createTexture","createExternalTexture","createShader","createSampler","createRenderPipeline","createFramebuffer","createComputePipeline","beginRenderPass","commandEncoder","createCommandEncoder","beginComputePass","createCanvasContext","getDefaultRenderPass","renderPass","framebuffer","getCurrentFramebuffer","submit","endPass","commandBuffer","finish","queue","Set","has","delete","add"],"mappings":";AAoBA,SAAQA,MAAR,EAAgBC,aAAhB,EAA+BC,GAA/B,QAA+C,cAA/C;AACA,OAAOC,YAAP,MAAyB,2BAAzB;AACA,OAAOC,aAAP,MAA0B,4BAA1B;AACA,OAAOC,qBAAP,MAAkC,qCAAlC;AACA,OAAOC,aAAP,MAA0B,4BAA1B;AACA,OAAOC,YAAP,MAAyB,2BAAzB;AACA,OAAOC,oBAAP,MAAiC,oCAAjC;AAEA,OAAOC,qBAAP,MAAkC,qCAAlC;AACA,OAAOC,gBAAP,MAA6B,gCAA7B;AACA,OAAOC,iBAAP,MAA8B,iCAA9B;AAEA,OAAOC,mBAAP,MAAgC,yBAAhC;AAIA,eAAe,MAAMC,YAAN,SAA2Bb,MAA3B,CAAkC;AAe7B,SAAXc,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AT,CAAa,kBAAb;AAEA,WAAO5D,QAAP;AACD;;AApP8C;;gBAA5BhB,Y,UAYG,Q","sourcesContent":["/// <reference types=\"@webgpu/types\" />\n\nimport type {\n DeviceProps,\n DeviceInfo,\n DeviceLimits,\n DeviceFeature,\n CanvasContextProps,\n BufferProps,\n SamplerProps,\n ShaderProps,\n TextureProps,\n TextureFormat,\n ExternalTextureProps,\n FramebufferProps,\n RenderPipelineProps,\n ComputePipelineProps,\n RenderPassProps,\n ComputePassProps\n} from '@luma.gl/api';\nimport {Device, CanvasContext, log, cast} from '@luma.gl/api';\nimport WebGPUBuffer from './resources/webgpu-buffer';\nimport WebGPUTexture from './resources/webgpu-texture';\nimport WebGPUExternalTexture from './resources/webgpu-external-texture';\nimport WebGPUSampler from './resources/webgpu-sampler';\nimport WebGPUShader from './resources/webgpu-shader';\nimport WebGPURenderPipeline from './resources/webgpu-render-pipeline';\nimport WebGPUFramebuffer from './resources/webgpu-framebuffer';\nimport WebGPUComputePipeline from './resources/webgpu-compute-pipeline';\nimport WebGPURenderPass from './resources/webgpu-render-pass';\nimport WebGPUComputePass from './resources/webgpu-compute-pass';\n\nimport WebGPUCanvasContext from './webgpu-canvas-context';\n// import {loadGlslangModule} from '../glsl/glslang';\n\n/** WebGPU Device implementation */\nexport default class WebGPUDevice extends Device {\n readonly handle: GPUDevice;\n readonly adapter: GPUAdapter;\n readonly lost: Promise<{reason: 'destroyed', message: string}>;\n canvasContext: WebGPUCanvasContext | undefined;\n\n commandEncoder: GPUCommandEncoder;\n renderPass: WebGPURenderPass;\n\n private _info: DeviceInfo;\n private _isLost: boolean = false;\n\n static type: string = 'webgpu';\n\n /** Check if WebGPU is available */\n static isSupported(): boolean {\n return Boolean(typeof navigator !== 'undefined' && navigator.gpu);\n }\n\n static async create(props: DeviceProps): Promise<WebGPUDevice> {\n if (!navigator.gpu) {\n throw new Error('WebGPU not available. Open in Chrome Canary and turn on chrome://flags/#enable-unsafe-webgpu');\n }\n log.groupCollapsed(1, 'WebGPUDevice created')();\n const adapter = await navigator.gpu.requestAdapter({\n powerPreference: \"high-performance\"\n // forceSoftware: false\n });\n log.probe(1, \"Adapter available\")();\n\n const gpuDevice = await adapter.requestDevice({\n requiredFeatures: adapter.features as ReadonlySet<GPUFeatureName>,\n // TODO ensure we obtain best limits\n // requiredLimits: adapter.limits\n });\n log.probe(1, \"GPUDevice available\")();\n\n if (typeof props.canvas === 'string') {\n await CanvasContext.pageLoaded;\n log.probe(1, \"DOM is loaded\")();\n }\n\n const device = new WebGPUDevice(gpuDevice, adapter, props);\n log.probe(1, \"Device created\", device.info)();\n log.table(1, device.info)();\n log.groupEnd(1)();\n return device;\n }\n\n constructor(device: GPUDevice, adapter: GPUAdapter, props: DeviceProps) {\n super(props);\n this.handle = device;\n this.adapter = adapter;\n\n this._info = {\n type: 'webgpu',\n vendor: this.adapter.name,\n renderer: '',\n version: '',\n gpu: 'unknown', // 'nvidia' | 'amd' | 'intel' | 'apple' | 'unknown',\n shadingLanguages: ['glsl', 'wgsl'],\n shadingLanguageVersions: {\n glsl: '450',\n wgsl: '100'\n },\n vendorMasked: '',\n rendererMasked: ''\n };\n\n this.lost = this.handle.lost;\n this.lost.then(_ => {\n this._isLost = true;\n });\n\n // Note: WebGPU devices can be created without a canvas, for compute shader purposes\n if (props.canvas) {\n this.canvasContext = new WebGPUCanvasContext(this, this.adapter, {canvas: props.canvas});\n }\n\n this.features = this._getFeatures();\n }\n\n // TODO\n // Load the glslang module now so that it is available synchronously when compiling shaders\n // const {glsl = true} = props;\n // this.glslang = glsl && await loadGlslangModule();\n\n destroy() {\n this.handle.destroy();\n }\n\n get info(): DeviceInfo {\n return this._info;\n }\n\n features: Set<DeviceFeature>;\n\n get limits(): DeviceLimits {\n return this.handle.limits;\n }\n\n isTextureFormatSupported(format: TextureFormat): boolean {\n return !format.includes('webgl');\n }\n\n /** @todo implement proper check? */\n isTextureFormatFilterable(format: TextureFormat): boolean {\n return this.isTextureFormatSupported(format); \n }\n\n /** @todo implement proper check? */\n isTextureFormatRenderable(format: TextureFormat): boolean {\n return this.isTextureFormatSupported(format); \n }\n\n get isLost(): boolean {\n return this._isLost;\n }\n\n _createBuffer(props: BufferProps): WebGPUBuffer {\n return new WebGPUBuffer(this, props);\n }\n\n _createTexture(props: TextureProps): WebGPUTexture {\n return new WebGPUTexture(this, props);\n }\n\n createExternalTexture(props: ExternalTextureProps): WebGPUExternalTexture {\n return new WebGPUExternalTexture(this, props);\n }\n\n createShader(props: ShaderProps): WebGPUShader {\n return new WebGPUShader(this, props);\n }\n\n createSampler(props: SamplerProps): WebGPUSampler {\n return new WebGPUSampler(this, props);\n }\n\n createRenderPipeline(props: RenderPipelineProps): WebGPURenderPipeline {\n return new WebGPURenderPipeline(this, props);\n }\n\n createFramebuffer(props: FramebufferProps): WebGPUFramebuffer {\n throw new Error('Not implemented');\n }\n\n createComputePipeline(props: ComputePipelineProps): WebGPUComputePipeline {\n return new WebGPUComputePipeline(this, props);\n }\n\n // WebGPU specifics\n\n /** \n * Allows a render pass to begin against a canvas context\n * @todo need to support a \"Framebuffer\" equivalent (aka preconfigured RenderPassDescriptors?).\n */\n beginRenderPass(props?: RenderPassProps): WebGPURenderPass {\n this.commandEncoder = this.commandEncoder || this.handle.createCommandEncoder();\n return new WebGPURenderPass(this, props);\n }\n\n beginComputePass(props?: ComputePassProps): WebGPUComputePass {\n this.commandEncoder = this.commandEncoder || this.handle.createCommandEncoder();\n return new WebGPUComputePass(this, props);\n }\n\n createCanvasContext(props?: CanvasContextProps): WebGPUCanvasContext {\n return new WebGPUCanvasContext(this, this.adapter, props);\n }\n\n /** \n * Gets default renderpass encoder.\n * Creates a new encoder against default canvasContext if not already created \n * @note Called internally by Model.\n */\n getDefaultRenderPass(): WebGPURenderPass {\n this.renderPass = this.renderPass || this.beginRenderPass({\n framebuffer: this.canvasContext.getCurrentFramebuffer()\n });\n return this.renderPass;\n }\n\n submit(): void {\n this.renderPass.endPass();\n const commandBuffer = this.commandEncoder.finish();\n this.handle.queue.submit([commandBuffer]);\n this.commandEncoder = null;\n this.renderPass = null;\n }\n\n _getFeatures() {\n // WebGPU Features\n const features = new Set<DeviceFeature>(this.handle.features as Set<DeviceFeature>);\n\n // Fixups for pre-standard names: https://github.com/webgpu-native/webgpu-headers/issues/133\n // @ts-expect-error Chrome Canary v99\n if (features.has('depth-clamping')) {\n // @ts-expect-error Chrome Canary v99\n features.delete('depth-clamping');\n features.add('depth-clip-control');\n }\n\n // Add subsets\n if (features.has('texture-compression-bc')) {\n features.add('texture-compression-bc5-webgl');\n }\n\n features.add('webgpu');\n\n features.add('timer-query-webgl');\n\n // WEBGL1 SUPPORT\n features.add('vertex-array-object-webgl1');\n features.add('instanced-rendering-webgl1');\n features.add('multiple-render-targets-webgl1');\n features.add('index-uint32-webgl1');\n features.add('blend-minmax-webgl1');\n features.add('texture-blend-float-webgl1');\n \n // TEXTURES, RENDERBUFFERS\n features.add('texture-formats-srgb-webgl1');\n \n // TEXTURES\n features.add('texture-formats-depth-webgl1');\n features.add('texture-formats-float32-webgl1');\n features.add('texture-formats-float16-webgl1');\n \n features.add('texture-filter-linear-float32-webgl');\n features.add('texture-filter-linear-float16-webgl');\n features.add('texture-filter-anisotropic-webgl');\n \n // FRAMEBUFFERS, TEXTURES AND RENDERBUFFERS\n features.add('texture-renderable-rgba32float-webgl');\n features.add('texture-renderable-float32-webgl');\n features.add('texture-renderable-float16-webgl');\n \n // GLSL extensions\n features.add('glsl-frag-data');\n features.add('glsl-frag-depth');\n features.add('glsl-derivatives');\n features.add('glsl-texture-lod');\n\n return features;\n }\n}\n"],"file":"webgpu-device.js"}
1
+ {"version":3,"sources":["../../src/adapter/webgpu-device.ts"],"names":["Device","CanvasContext","log","WebGPUBuffer","WebGPUTexture","WebGPUExternalTexture","WebGPUSampler","WebGPUShader","WebGPURenderPipeline","WebGPUComputePipeline","WebGPURenderPass","WebGPUComputePass","WebGPUCanvasContext","WebGPUDevice","isSupported","Boolean","navigator","gpu","create","props","Error","groupCollapsed","adapter","requestAdapter","powerPreference","probe","gpuDevice","requestDevice","requiredFeatures","features","canvas","pageLoaded","device","info","table","groupEnd","constructor","handle","_info","type","vendor","name","renderer","version","shadingLanguages","shadingLanguageVersions","glsl","wgsl","vendorMasked","rendererMasked","lost","Promise","resolve","lostInfo","_isLost","reason","message","canvasContext","_getFeatures","destroy","limits","isTextureFormatSupported","format","includes","isTextureFormatFilterable","isTextureFormatRenderable","isLost","_createBuffer","_createTexture","createExternalTexture","createShader","createSampler","createRenderPipeline","createFramebuffer","createComputePipeline","beginRenderPass","commandEncoder","createCommandEncoder","beginComputePass","createCanvasContext","getDefaultRenderPass","renderPass","framebuffer","getCurrentFramebuffer","submit","endPass","commandBuffer","finish","queue","Set","has","delete","add"],"mappings":";AAoBA,SAAQA,MAAR,EAAgBC,aAAhB,EAA+BC,GAA/B,QAA+C,cAA/C;AACA,OAAOC,YAAP,MAAyB,2BAAzB;AACA,OAAOC,aAAP,MAA0B,4BAA1B;AACA,OAAOC,qBAAP,MAAkC,qCAAlC;AACA,OAAOC,aAAP,MAA0B,4BAA1B;AACA,OAAOC,YAAP,MAAyB,2BAAzB;AACA,OAAOC,oBAAP,MAAiC,oCAAjC;AAEA,OAAOC,qBAAP,MAAkC,qCAAlC;AACA,OAAOC,gBAAP,MAA6B,gCAA7B;AACA,OAAOC,iBAAP,MAA8B,iCAA9B;AAEA,OAAOC,mBAAP,MAAgC,yBAAhC;AAIA,eAAe,MAAMC,YAAN,SAA2Bb,MAA3B,CAAkC;AAe7B,SAAXc,WAAW,GAAY;AAC5B,WAAOC,OAAO,CAAC,OAAOC,SAAP,KAAqB,WAArB,IAAoCA,SAAS,CAACC,GAA/C,CAAd;AACD;;AAEkB,eAANC,MAAM,CAACC,KAAD,EAA4C;AAC7D,QAAI,CAACH,SAAS,CAACC,GAAf,EAAoB;AAClB,YAAM,IAAIG,KAAJ,CACJ,8FADI,CAAN;AAGD;;AACDlB,IAAAA,GAAG,CAACmB,cAAJ,CAAmB,CAA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Q,CAAC+D,GAAT,CAAa,kBAAb;AACA/D,IAAAA,QAAQ,CAAC+D,GAAT,CAAa,kBAAb;AAEA,WAAO/D,QAAP;AACD;;AAhQ8C;;gBAA5BhB,Y,UAYG,Q","sourcesContent":["/// <reference types=\"@webgpu/types\" />\n\nimport type {\n DeviceProps,\n DeviceInfo,\n DeviceLimits,\n DeviceFeature,\n CanvasContextProps,\n BufferProps,\n SamplerProps,\n ShaderProps,\n TextureProps,\n TextureFormat,\n ExternalTextureProps,\n FramebufferProps,\n RenderPipelineProps,\n ComputePipelineProps,\n RenderPassProps,\n ComputePassProps\n} from '@luma.gl/api';\nimport {Device, CanvasContext, log, cast} from '@luma.gl/api';\nimport WebGPUBuffer from './resources/webgpu-buffer';\nimport WebGPUTexture from './resources/webgpu-texture';\nimport WebGPUExternalTexture from './resources/webgpu-external-texture';\nimport WebGPUSampler from './resources/webgpu-sampler';\nimport WebGPUShader from './resources/webgpu-shader';\nimport WebGPURenderPipeline from './resources/webgpu-render-pipeline';\nimport WebGPUFramebuffer from './resources/webgpu-framebuffer';\nimport WebGPUComputePipeline from './resources/webgpu-compute-pipeline';\nimport WebGPURenderPass from './resources/webgpu-render-pass';\nimport WebGPUComputePass from './resources/webgpu-compute-pass';\n\nimport WebGPUCanvasContext from './webgpu-canvas-context';\n// import {loadGlslangModule} from '../glsl/glslang';\n\n/** WebGPU Device implementation */\nexport default class WebGPUDevice extends Device {\n readonly handle: GPUDevice;\n readonly adapter: GPUAdapter;\n readonly lost: Promise<{reason: 'destroyed'; message: string}>;\n canvasContext: WebGPUCanvasContext | null = null;\n\n commandEncoder: GPUCommandEncoder | null = null;\n renderPass: WebGPURenderPass | null = null;\n\n private _info: DeviceInfo;\n private _isLost: boolean = false;\n\n static type: string = 'webgpu';\n\n /** Check if WebGPU is available */\n static isSupported(): boolean {\n return Boolean(typeof navigator !== 'undefined' && navigator.gpu);\n }\n\n static async create(props: DeviceProps): Promise<WebGPUDevice> {\n if (!navigator.gpu) {\n throw new Error(\n 'WebGPU not available. Open in Chrome Canary and turn on chrome://flags/#enable-unsafe-webgpu'\n );\n }\n log.groupCollapsed(1, 'WebGPUDevice created')();\n const adapter = await navigator.gpu.requestAdapter({\n powerPreference: 'high-performance'\n // forceSoftware: false\n });\n if (!adapter) {\n throw new Error('Failed to request WebGPU adapter');\n }\n\n log.probe(1, 'Adapter available')();\n\n const gpuDevice = await adapter.requestDevice({\n requiredFeatures: adapter.features as ReadonlySet<GPUFeatureName>\n // TODO ensure we obtain best limits\n // requiredLimits: adapter.limits\n });\n log.probe(1, 'GPUDevice available')();\n\n if (typeof props.canvas === 'string') {\n await CanvasContext.pageLoaded;\n log.probe(1, 'DOM is loaded')();\n }\n\n const device = new WebGPUDevice(gpuDevice, adapter, props);\n log.probe(1, 'Device created', device.info)();\n log.table(1, device.info)();\n log.groupEnd(1)();\n return device;\n }\n\n constructor(device: GPUDevice, adapter: GPUAdapter, props: DeviceProps) {\n super(props);\n this.handle = device;\n this.adapter = adapter;\n\n this._info = {\n type: 'webgpu',\n vendor: this.adapter.name,\n renderer: '',\n version: '',\n gpu: 'unknown', // 'nvidia' | 'amd' | 'intel' | 'apple' | 'unknown',\n shadingLanguages: ['glsl', 'wgsl'],\n shadingLanguageVersions: {\n glsl: '450',\n wgsl: '100'\n },\n vendorMasked: '',\n rendererMasked: ''\n };\n\n // \"Context\" loss handling\n this.lost = new Promise<{reason: 'destroyed'; message: string}>(async (resolve) => {\n const lostInfo = await this.handle.lost;\n this._isLost = true;\n resolve({reason: 'destroyed', message: lostInfo.message});\n });\n\n // Note: WebGPU devices can be created without a canvas, for compute shader purposes\n if (props.canvas) {\n this.canvasContext = new WebGPUCanvasContext(this, this.adapter, {canvas: props.canvas});\n }\n\n this.features = this._getFeatures();\n }\n\n // TODO\n // Load the glslang module now so that it is available synchronously when compiling shaders\n // const {glsl = true} = props;\n // this.glslang = glsl && await loadGlslangModule();\n\n destroy() {\n this.handle.destroy();\n }\n\n get info(): DeviceInfo {\n return this._info;\n }\n\n features: Set<DeviceFeature>;\n\n get limits(): DeviceLimits {\n return this.handle.limits;\n }\n\n isTextureFormatSupported(format: TextureFormat): boolean {\n return !format.includes('webgl');\n }\n\n /** @todo implement proper check? */\n isTextureFormatFilterable(format: TextureFormat): boolean {\n return this.isTextureFormatSupported(format);\n }\n\n /** @todo implement proper check? */\n isTextureFormatRenderable(format: TextureFormat): boolean {\n return this.isTextureFormatSupported(format);\n }\n\n get isLost(): boolean {\n return this._isLost;\n }\n\n _createBuffer(props: BufferProps): WebGPUBuffer {\n return new WebGPUBuffer(this, props);\n }\n\n _createTexture(props: TextureProps): WebGPUTexture {\n return new WebGPUTexture(this, props);\n }\n\n createExternalTexture(props: ExternalTextureProps): WebGPUExternalTexture {\n return new WebGPUExternalTexture(this, props);\n }\n\n createShader(props: ShaderProps): WebGPUShader {\n return new WebGPUShader(this, props);\n }\n\n createSampler(props: SamplerProps): WebGPUSampler {\n return new WebGPUSampler(this, props);\n }\n\n createRenderPipeline(props: RenderPipelineProps): WebGPURenderPipeline {\n return new WebGPURenderPipeline(this, props);\n }\n\n createFramebuffer(props: FramebufferProps): WebGPUFramebuffer {\n throw new Error('Not implemented');\n }\n\n createComputePipeline(props: ComputePipelineProps): WebGPUComputePipeline {\n return new WebGPUComputePipeline(this, props);\n }\n\n // WebGPU specifics\n\n /**\n * Allows a render pass to begin against a canvas context\n * @todo need to support a \"Framebuffer\" equivalent (aka preconfigured RenderPassDescriptors?).\n */\n beginRenderPass(props: RenderPassProps): WebGPURenderPass {\n this.commandEncoder = this.commandEncoder || this.handle.createCommandEncoder();\n return new WebGPURenderPass(this, props);\n }\n\n beginComputePass(props: ComputePassProps): WebGPUComputePass {\n this.commandEncoder = this.commandEncoder || this.handle.createCommandEncoder();\n return new WebGPUComputePass(this, props);\n }\n\n createCanvasContext(props: CanvasContextProps): WebGPUCanvasContext {\n return new WebGPUCanvasContext(this, this.adapter, props);\n }\n\n /**\n * Gets default renderpass encoder.\n * Creates a new encoder against default canvasContext if not already created\n * @note Called internally by Model.\n */\n getDefaultRenderPass(): WebGPURenderPass {\n this.renderPass =\n this.renderPass ||\n this.beginRenderPass({\n framebuffer: this.canvasContext?.getCurrentFramebuffer()\n });\n return this.renderPass;\n }\n\n submit(): void {\n this.renderPass?.endPass();\n const commandBuffer = this.commandEncoder?.finish();\n if (commandBuffer) {\n this.handle.queue.submit([commandBuffer]);\n }\n this.commandEncoder = null;\n this.renderPass = null;\n }\n\n _getFeatures() {\n // WebGPU Features\n const features = new Set<DeviceFeature>(this.handle.features as Set<DeviceFeature>);\n\n // Fixups for pre-standard names: https://github.com/webgpu-native/webgpu-headers/issues/133\n // @ts-expect-error Chrome Canary v99\n if (features.has('depth-clamping')) {\n // @ts-expect-error Chrome Canary v99\n features.delete('depth-clamping');\n features.add('depth-clip-control');\n }\n\n // Add subsets\n if (features.has('texture-compression-bc')) {\n features.add('texture-compression-bc5-webgl');\n }\n\n features.add('webgpu');\n\n features.add('timer-query-webgl');\n\n // WEBGL1 SUPPORT\n features.add('vertex-array-object-webgl1');\n features.add('instanced-rendering-webgl1');\n features.add('multiple-render-targets-webgl1');\n features.add('index-uint32-webgl1');\n features.add('blend-minmax-webgl1');\n features.add('texture-blend-float-webgl1');\n\n // TEXTURES, RENDERBUFFERS\n features.add('texture-formats-srgb-webgl1');\n\n // TEXTURES\n features.add('texture-formats-depth-webgl1');\n features.add('texture-formats-float32-webgl1');\n features.add('texture-formats-float16-webgl1');\n\n features.add('texture-filter-linear-float32-webgl');\n features.add('texture-filter-linear-float16-webgl');\n features.add('texture-filter-anisotropic-webgl');\n\n // FRAMEBUFFERS, TEXTURES AND RENDERBUFFERS\n features.add('texture-renderable-rgba32float-webgl');\n features.add('texture-renderable-float32-webgl');\n features.add('texture-renderable-float16-webgl');\n\n // GLSL extensions\n features.add('glsl-frag-data');\n features.add('glsl-frag-depth');\n features.add('glsl-derivatives');\n features.add('glsl-texture-lod');\n\n return features;\n }\n}\n"],"file":"webgpu-device.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luma.gl/webgpu",
3
- "version": "9.0.0-alpha.7",
3
+ "version": "9.0.0-alpha.9",
4
4
  "description": "WebGPU adapter for the luma.gl API",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -28,9 +28,9 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@babel/runtime": "^7.0.0",
31
- "@luma.gl/api": "9.0.0-alpha.7",
31
+ "@luma.gl/api": "9.0.0-alpha.9",
32
32
  "@webgpu/types": "^0.1.9",
33
33
  "probe.gl": "^3.2.1"
34
34
  },
35
- "gitHead": "c1fbf71bb1311dcdc54338d82d299f8ed0d73346"
35
+ "gitHead": "b84aae16edcdee2be84d2861c81cc6584e336b28"
36
36
  }