@luma.gl/webgpu 9.0.0-alpha.11 → 9.0.0-alpha.12
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.
- package/dist/adapter/helpers/get-vertex-buffer-layout.js +0 -2
- package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +1 -1
- package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
- package/dist/adapter/helpers/webgpu-parameters.js +1 -2
- package/dist/adapter/helpers/webgpu-parameters.js.map +1 -1
- package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-buffer.js.map +1 -1
- package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-command-encoder.js.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pass.js.map +1 -1
- package/dist/adapter/resources/webgpu-external-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-external-texture.js.map +1 -1
- package/dist/adapter/resources/webgpu-framebuffer.js +0 -1
- package/dist/adapter/resources/webgpu-framebuffer.js.map +1 -1
- package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pass.js.map +1 -1
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pipeline.js +4 -2
- package/dist/adapter/resources/webgpu-render-pipeline.js.map +1 -1
- package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-sampler.js +3 -2
- package/dist/adapter/resources/webgpu-sampler.js.map +1 -1
- package/dist/adapter/resources/webgpu-shader.d.ts +1 -1
- package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-shader.js.map +1 -1
- package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-texture.js +1 -1
- package/dist/adapter/resources/webgpu-texture.js.map +1 -1
- package/dist/adapter/webgpu-canvas-context.d.ts +0 -2
- package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgpu-canvas-context.js +5 -4
- package/dist/adapter/webgpu-canvas-context.js.map +1 -1
- package/dist/adapter/webgpu-device.d.ts.map +1 -1
- package/dist/adapter/webgpu-device.js +4 -2
- package/dist/adapter/webgpu-device.js.map +1 -1
- package/package.json +3 -3
- package/src/adapter/helpers/get-vertex-buffer-layout.ts +1 -1
- package/src/adapter/helpers/webgpu-parameters.ts +3 -2
- package/src/adapter/resources/webgpu-buffer.ts +4 -4
- package/src/adapter/resources/webgpu-command-encoder.ts +5 -5
- package/src/adapter/resources/webgpu-compute-pass.ts +1 -1
- package/src/adapter/resources/webgpu-external-texture.ts +1 -1
- package/src/adapter/resources/webgpu-framebuffer.ts +1 -1
- package/src/adapter/resources/webgpu-query.ts +1 -1
- package/src/adapter/resources/webgpu-render-pass.ts +2 -2
- package/src/adapter/resources/webgpu-render-pipeline.ts +6 -5
- package/src/adapter/resources/webgpu-sampler.ts +3 -3
- package/src/adapter/resources/webgpu-shader.ts +2 -2
- package/src/adapter/resources/webgpu-texture.ts +3 -3
- package/src/adapter/webgpu-canvas-context.ts +6 -3
- package/src/adapter/webgpu-device.ts +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/adapter/resources/webgpu-shader.ts"],"names":["Shader","log","WebGPUShader","constructor","device","props","handle","pushErrorScope","createHandle","label","id","_checkCompilationError","popErrorScope","errorScope","error","shaderLog","compilationInfo","message","Error","destroy","source","language","includes","createShaderModule","code","transform","glsl","glslang","compileGLSL","type","messages"],"mappings":";AACA,SAAQA,MAAR,EAAgBC,GAAhB,QAA0B,cAA1B;AAUA,eAAe,MAAMC,YAAN,SAA2BF,MAA3B,CAAkC;AAI/CG,EAAAA,WAAW,CAACC,MAAD,EAAuBC,KAAvB,EAAiD;AAC1D,UAAMD,MAAN,EAAcC,KAAd;;AAD0D;;AAAA;;AAE1D,SAAKD,MAAL,GAAcA,MAAd;AAEA,SAAKA,MAAL,CAAYE,MAAZ,CAAmBC,cAAnB,CAAkC,YAAlC;AAEA,SAAKD,MAAL,GAAc,KAAKD,KAAL,CAAWC,MAAX,IAAqB,KAAKE,YAAL,EAAnC;AACA,SAAKF,MAAL,CAAYG,KAAZ,GAAoB,KAAKJ,KAAL,CAAWK,EAA/B;;AAEA,SAAKC,sBAAL,CAA4B,KAAKP,MAAL,CAAYE,MAAZ,CAAmBM,aAAnB,EAA5B;AACD;;AAE2B,QAAtBD,sBAAsB,CAACE,UAAD,
|
|
1
|
+
{"version":3,"sources":["../../../src/adapter/resources/webgpu-shader.ts"],"names":["Shader","log","WebGPUShader","constructor","device","props","handle","pushErrorScope","createHandle","label","id","_checkCompilationError","popErrorScope","errorScope","error","shaderLog","compilationInfo","message","Error","destroy","source","language","includes","createShaderModule","code","transform","glsl","glslang","compileGLSL","type","messages"],"mappings":";AACA,SAAQA,MAAR,EAAgBC,GAAhB,QAA0B,cAA1B;AAUA,eAAe,MAAMC,YAAN,SAA2BF,MAA3B,CAAkC;AAI/CG,EAAAA,WAAW,CAACC,MAAD,EAAuBC,KAAvB,EAAiD;AAC1D,UAAMD,MAAN,EAAcC,KAAd;;AAD0D;;AAAA;;AAE1D,SAAKD,MAAL,GAAcA,MAAd;AAEA,SAAKA,MAAL,CAAYE,MAAZ,CAAmBC,cAAnB,CAAkC,YAAlC;AAEA,SAAKD,MAAL,GAAc,KAAKD,KAAL,CAAWC,MAAX,IAAqB,KAAKE,YAAL,EAAnC;AACA,SAAKF,MAAL,CAAYG,KAAZ,GAAoB,KAAKJ,KAAL,CAAWK,EAA/B;;AAEA,SAAKC,sBAAL,CAA4B,KAAKP,MAAL,CAAYE,MAAZ,CAAmBM,aAAnB,EAA5B;AACD;;AAE2B,QAAtBD,sBAAsB,CAACE,UAAD,EAAsD;AAChF,UAAMC,KAAK,GAAG,MAAM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../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 | 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.compilationInfo();\n return compilationInfo.messages;\n }\n}\n"],"file":"webgpu-shader.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,
|
|
1
|
+
{"version":3,"file":"webgpu-texture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B,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",
|
|
23
|
+
_defineProperty(this, "sampler", void 0);
|
|
24
24
|
|
|
25
25
|
if (typeof this.props.format === 'number') {
|
|
26
26
|
throw new Error('number format');
|
|
@@ -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","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,UAAMD,MAAN,EAAcC,KAAd;;AADqD;;AAAA;;AAAA;;AAAA,qCAT9B,IAS8B;;AAGrD,QAAI,OAAO,KAAKA,KAAL,CAAWC,MAAlB,KAA6B,QAAjC,EAA2C;AACzC,YAAM,IAAIC,KAAJ,CAAU,eAAV,CAAN;AACD;;AAED,SAAKH,MAAL,GAAcA,MAA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D,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
|
+
{"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,QAA2D,cAA3D;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;;AAID,SAAKE,OAAL,GAAeP,KAAK,CAACO,OAAN,YAAyBZ,aAAzB,GAAyCK,KAAK,CAACO,OAA/C,GAAyD,IAAIZ,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cesContent":["// 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 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 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"],"file":"webgpu-texture.js"}
|
|
@@ -10,8 +10,6 @@ export default 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;
|
|
@@ -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,
|
|
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,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;IAYhF,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"}
|
|
@@ -12,10 +12,6 @@ export default class WebGPUCanvasContext extends CanvasContext {
|
|
|
12
12
|
|
|
13
13
|
_defineProperty(this, "format", void 0);
|
|
14
14
|
|
|
15
|
-
_defineProperty(this, "width", -1);
|
|
16
|
-
|
|
17
|
-
_defineProperty(this, "height", -1);
|
|
18
|
-
|
|
19
15
|
_defineProperty(this, "depthStencilFormat", 'depth24plus');
|
|
20
16
|
|
|
21
17
|
_defineProperty(this, "sampleCount", 1);
|
|
@@ -23,6 +19,11 @@ export default class WebGPUCanvasContext extends CanvasContext {
|
|
|
23
19
|
_defineProperty(this, "depthStencilAttachment", null);
|
|
24
20
|
|
|
25
21
|
this.device = device;
|
|
22
|
+
this.width = -1;
|
|
23
|
+
this.height = -1;
|
|
24
|
+
|
|
25
|
+
this._setAutoCreatedCanvasId("".concat(this.device.id, "-canvas"));
|
|
26
|
+
|
|
26
27
|
this.gpuCanvasContext = this.canvas.getContext('webgpu');
|
|
27
28
|
this.format = this.gpuCanvasContext.getPreferredFormat(adapter);
|
|
28
29
|
}
|
|
@@ -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","
|
|
1
|
+
{"version":3,"sources":["../../src/adapter/webgpu-canvas-context.ts"],"names":["CanvasContext","log","getWebGPUTextureFormat","WEBGPUFramebuffer","WebGPUCanvasContext","constructor","device","adapter","props","width","height","_setAutoCreatedCanvasId","id","gpuCanvasContext","canvas","getContext","format","getPreferredFormat","destroy","unconfigure","getCurrentFramebuffer","update","currentColorAttachment","createTexture","handle","getCurrentTexture","_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;AAS7DK,EAAAA,WAAW,CAACC,MAAD,EAAuBC,OAAvB,EAA4CC,KAA5C,EAAuE;AAChF,UAAMA,KAAN;;AADgF;;AAAA;;AAAA;;AAAA,gDAL9C,aAK8C;;AAAA,yCAJ5D,CAI4D;;AAAA,oDAFjC,IAEiC;;AAEhF,SAAKF,MAAL,GAAcA,MAAd;AAEA,SAAKG,KAAL,GAAa,CAAC,CAAd;AACA,SAAKC,MAAL,GAAc,CAAC,CAAf;;AAEA,SAAKC,uBAAL,WAAgC,KAAKL,MAAL,CAAYM,EAA5C;;AACA,SAAKC,gBAAL,GAAwB,KAAKC,MAAL,CAAYC,UAAZ,CAAuB,QAAvB,CAAxB;AACA,SAAKC,MAAL,GAAc,KAAKH,gBAAL,CAAsBI,kBAAtB,CAAyCV,OAAzC,CAAd;AACD;;AAEDW,EAAAA,OAAO,GAAS;AACd,SAAKL,gBAAL,CAAsBM,WAAtB;AACD;;AAGDC,EAAAA,qBAAqB,GAAsB;AAEzC,SAAKC,MAAL;AAGA,UAAMC,sBAAsB,GAAG,KAAKhB,MAAL,CAAYiB,aAAZ,CAA0B;AACvDX,MAAAA,EAAE,EAAE,uBADmD;AAEvDY,MAAAA,MAAM,EAAE,KAAK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AAA,MAAM,CAACC,OAAD,EAAwF;AAC5F,SAAKf,MAAL;AACD;;AAGDK,EAAAA,6BAA6B,GAAG;AAC9B,QAAI,CAAC,KAAKE,sBAAV,EAAkC;AAChC,WAAKA,sBAAL,GAA8B,KAAKtB,MAAL,CAAYiB,aAAZ,CAA0B;AACtDX,QAAAA,EAAE,EAAE,sBADkD;AAEtDI,QAAAA,MAAM,EAAE,KAAKqB,kBAFyC;AAGtD5B,QAAAA,KAAK,EAAE,KAAKA,KAH0C;AAItDC,QAAAA,MAAM,EAAE,KAAKA,MAJyC;AAKtD4B,QAAAA,KAAK,EAAEC,eAAe,CAACC;AAL+B,OAA1B,CAA9B;AAOD;;AACD,WAAO,KAAKZ,sBAAZ;AACD;;AA9F4D","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 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 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 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 +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,YAA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AG,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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
import { Device, CanvasContext, log } from '@luma.gl/api';
|
|
2
|
+
import { Device, CanvasContext, log, uid } from '@luma.gl/api';
|
|
3
3
|
import WebGPUBuffer from './resources/webgpu-buffer';
|
|
4
4
|
import WebGPUTexture from './resources/webgpu-texture';
|
|
5
5
|
import WebGPUExternalTexture from './resources/webgpu-external-texture';
|
|
@@ -48,7 +48,9 @@ export default class WebGPUDevice extends Device {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
constructor(device, adapter, props) {
|
|
51
|
-
super(props
|
|
51
|
+
super({ ...props,
|
|
52
|
+
id: props.id || uid('webgpu-device')
|
|
53
|
+
});
|
|
52
54
|
|
|
53
55
|
_defineProperty(this, "handle", void 0);
|
|
54
56
|
|
|
@@ -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","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,CAAnB,EAAsB,sBAAtB;AACA,UAAMC,OAAO,GAAG,MAAMN,SAAS,CAACC,GAAV,CAAcM,cAAd,CAA6B;AACjDC,MAAAA,eAAe,EAAE;AADgC,KAA7B,CAAtB;;AAIA,QAAI,CAAC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// <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"}
|
|
1
|
+
{"version":3,"sources":["../../src/adapter/webgpu-device.ts"],"names":["Device","CanvasContext","log","uid","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","id","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,EAAoCC,GAApC,QAA8C,cAA9C;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,SAA2Bd,MAA3B,CAAkC;AAe7B,SAAXe,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,EA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,CAAa,kCAAb;AACAhE,IAAAA,QAAQ,CAACgE,GAAT,CAAa,kCAAb;AAGAhE,IAAAA,QAAQ,CAACgE,GAAT,CAAa,gBAAb;AACAhE,IAAAA,QAAQ,CAACgE,GAAT,CAAa,iBAAb;AACAhE,IAAAA,QAAQ,CAACgE,GAAT,CAAa,kBAAb;AACAhE,IAAAA,QAAQ,CAACgE,GAAT,CAAa,kBAAb;AAEA,WAAOhE,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, uid} 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, id: props.id || uid('webgpu-device')});\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(): void {\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.
|
|
3
|
+
"version": "9.0.0-alpha.12",
|
|
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.
|
|
31
|
+
"@luma.gl/api": "9.0.0-alpha.12",
|
|
32
32
|
"@webgpu/types": "^0.1.9",
|
|
33
33
|
"probe.gl": "^3.2.1"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "4059dc47e41bc587b7e5871929aec3f97020015f"
|
|
36
36
|
}
|
|
@@ -24,7 +24,7 @@ export function getVertexBufferLayout(layout: ShaderLayout, bufferMap: BufferMap
|
|
|
24
24
|
|
|
25
25
|
// interleaved mapping {..., attributes: [{...}, ...]}
|
|
26
26
|
if ('attributes' in mapping) {
|
|
27
|
-
const arrayStride = mapping.byteStride;
|
|
27
|
+
// const arrayStride = mapping.byteStride; TODO
|
|
28
28
|
for (const interleaved of mapping.attributes) {
|
|
29
29
|
const attributeLayout = findAttributeLayout(layout, interleaved.name, usedAttributes);
|
|
30
30
|
|
|
@@ -121,8 +121,9 @@ export const PARAMETER_TABLE: Record<keyof Parameters, Function> = {
|
|
|
121
121
|
},
|
|
122
122
|
|
|
123
123
|
blendColorOperation: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {
|
|
124
|
-
|
|
125
|
-
const
|
|
124
|
+
addColorState(descriptor);
|
|
125
|
+
// const targets = addColorState(descriptor);
|
|
126
|
+
// const target = targets[0];
|
|
126
127
|
// const blend: GPUBlendState = target.blend || {color: {alpha: 0}};
|
|
127
128
|
// blend.color = blend.color || {};
|
|
128
129
|
// target.blend.color.operation = value;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// WEBGPU Buffer implementation
|
|
2
|
-
import {Buffer, BufferProps
|
|
2
|
+
import {Buffer, BufferProps} from '@luma.gl/api';
|
|
3
3
|
import type WebGPUDevice from '../webgpu-device';
|
|
4
4
|
|
|
5
5
|
function getByteLength(props: BufferProps): number {
|
|
@@ -36,12 +36,12 @@ export default class WebGPUBuffer extends Buffer {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
destroy(): void {
|
|
39
|
+
override destroy(): void {
|
|
40
40
|
this.handle.destroy();
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// WebGPU provides multiple ways to write a buffer...
|
|
44
|
-
write(data: ArrayBufferView, byteOffset = 0) {
|
|
44
|
+
override write(data: ArrayBufferView, byteOffset = 0) {
|
|
45
45
|
this.device.handle.queue.writeBuffer(
|
|
46
46
|
this.handle,
|
|
47
47
|
byteOffset,
|
|
@@ -51,7 +51,7 @@ export default class WebGPUBuffer extends Buffer {
|
|
|
51
51
|
);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
async readAsync(byteOffset: number = 0, byteLength: number = this.byteLength): Promise<ArrayBuffer> {
|
|
54
|
+
override async readAsync(byteOffset: number = 0, byteLength: number = this.byteLength): Promise<ArrayBuffer> {
|
|
55
55
|
// We need MAP_READ flag, but only COPY_DST buffers can have MAP_READ flag, so we need to create a temp buffer
|
|
56
56
|
const tempBuffer = new WebGPUBuffer(this.device, {usage: Buffer.MAP_READ | Buffer.COPY_DST, byteLength});
|
|
57
57
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {CommandEncoder, CommandEncoderProps,
|
|
1
|
+
import {CommandEncoder, CommandEncoderProps, Buffer, Texture, cast} from '@luma.gl/api';
|
|
2
2
|
import WebGPUDevice from '../webgpu-device';
|
|
3
3
|
import WEBGPUBuffer from './webgpu-buffer';
|
|
4
4
|
import WebGPUTexture from './webgpu-texture';
|
|
@@ -16,7 +16,7 @@ export default class WebGPUCommandEncoder extends CommandEncoder {
|
|
|
16
16
|
this.handle.label = this.props.id;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
destroy() {}
|
|
19
|
+
override destroy(): void {}
|
|
20
20
|
|
|
21
21
|
finish(options?: {id?: string}): GPUCommandBuffer {
|
|
22
22
|
return this.finish(options);
|
|
@@ -88,15 +88,15 @@ export default class WebGPUCommandEncoder extends CommandEncoder {
|
|
|
88
88
|
copySize: GPUExtent3D
|
|
89
89
|
}): void {}
|
|
90
90
|
|
|
91
|
-
pushDebugGroup(groupLabel: string): void {
|
|
91
|
+
override pushDebugGroup(groupLabel: string): void {
|
|
92
92
|
this.handle.pushDebugGroup(groupLabel);
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
popDebugGroup(): void {
|
|
95
|
+
override popDebugGroup(): void {
|
|
96
96
|
this.handle.popDebugGroup();
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
insertDebugMarker(markerLabel: string): void {
|
|
99
|
+
override insertDebugMarker(markerLabel: string): void {
|
|
100
100
|
this.handle.insertDebugMarker(markerLabel);
|
|
101
101
|
}
|
|
102
102
|
|
|
@@ -22,7 +22,7 @@ export default class WebGPUExternalTexture extends ExternalTexture {
|
|
|
22
22
|
this.sampler = null;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
destroy(): void {
|
|
25
|
+
override destroy(): void {
|
|
26
26
|
// External textures are destroyed automatically,
|
|
27
27
|
// as a microtask, instead of manually or upon garbage collection like other resources.
|
|
28
28
|
// this.handle.destroy();
|
|
@@ -7,7 +7,7 @@ import WebGPUTexture from './webgpu-texture';
|
|
|
7
7
|
|
|
8
8
|
// const DEFAULT_DEPTH_STENCIL_FORMAT: DepthStencilTextureFormat = 'depth24plus';
|
|
9
9
|
|
|
10
|
-
const MAX_COLOR_ATTACHMENTS = 8;
|
|
10
|
+
// const MAX_COLOR_ATTACHMENTS = 8;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Create new textures with correct size for all attachments.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {RenderPassProps, RenderPassParameters, Binding} from '@luma.gl/api';
|
|
2
|
-
import {Buffer, RenderPass, RenderPipeline, cast
|
|
2
|
+
import {Buffer, RenderPass, RenderPipeline, cast} from '@luma.gl/api';
|
|
3
3
|
import WebGPUDevice from '../webgpu-device';
|
|
4
4
|
import WebGPUBuffer from './webgpu-buffer';
|
|
5
5
|
// import WebGPUCommandEncoder from './webgpu-command-encoder';
|
|
@@ -22,7 +22,7 @@ export default class WebGPURenderPass extends RenderPass {
|
|
|
22
22
|
this.handle.label = this.props.id;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
destroy() {}
|
|
25
|
+
override destroy(): void {}
|
|
26
26
|
|
|
27
27
|
endPass(): void {
|
|
28
28
|
this.handle.endPass();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {Binding, RenderPass
|
|
1
|
+
import type {Binding, RenderPass} from '@luma.gl/api';
|
|
2
2
|
import {Buffer, RenderPipeline, RenderPipelineProps, cast, log, isObjectEmpty} from '@luma.gl/api';
|
|
3
3
|
import {applyParametersToRenderPipelineDescriptor} from '../helpers/webgpu-parameters';
|
|
4
4
|
import {getWebGPUTextureFormat} from '../helpers/convert-texture-format';
|
|
@@ -56,7 +56,7 @@ export default class WebGPURenderPipeline extends RenderPipeline {
|
|
|
56
56
|
return renderPipeline;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
destroy() {
|
|
59
|
+
override destroy(): void {
|
|
60
60
|
// WebGPURenderPipeline has no destroy method.
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -170,15 +170,16 @@ export default class WebGPURenderPipeline extends RenderPipeline {
|
|
|
170
170
|
firstInstance?: number;
|
|
171
171
|
baseVertex?: number;
|
|
172
172
|
}): void {
|
|
173
|
-
const webgpuRenderPass =
|
|
173
|
+
const webgpuRenderPass: WebGPURenderPass =
|
|
174
174
|
cast<WebGPURenderPass>(options.renderPass) || this.device.getDefaultRenderPass();
|
|
175
175
|
|
|
176
176
|
// Set pipeline
|
|
177
177
|
webgpuRenderPass.handle.setPipeline(this.handle);
|
|
178
178
|
|
|
179
179
|
// Set bindings (uniform buffers, textures etc)
|
|
180
|
-
|
|
181
|
-
|
|
180
|
+
const bindGroup = this._getBindGroup();
|
|
181
|
+
if (bindGroup) {
|
|
182
|
+
webgpuRenderPass.handle.setBindGroup(0, bindGroup);
|
|
182
183
|
}
|
|
183
184
|
|
|
184
185
|
// Set attributes
|
|
@@ -17,16 +17,16 @@ export default class WebGPUSampler extends Sampler {
|
|
|
17
17
|
this.device = device;
|
|
18
18
|
|
|
19
19
|
// Prepare sampler props
|
|
20
|
-
const samplerProps = this.props;
|
|
20
|
+
const samplerProps: Partial<WebGPUSamplerProps> = {...this.props};
|
|
21
21
|
if (samplerProps.type !== 'comparison-sampler') {
|
|
22
22
|
delete samplerProps.compare;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
this.handle = this.handle || this.device.handle.createSampler(
|
|
25
|
+
this.handle = this.handle || this.device.handle.createSampler(samplerProps);
|
|
26
26
|
this.handle.label = this.props.id;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
destroy(): void {
|
|
29
|
+
override destroy(): void {
|
|
30
30
|
// this.handle.destroy();
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -25,7 +25,7 @@ export default class WebGPUShader extends Shader {
|
|
|
25
25
|
this._checkCompilationError(this.device.handle.popErrorScope());
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
async _checkCompilationError(errorScope: Promise<GPUError>): Promise<void> {
|
|
28
|
+
async _checkCompilationError(errorScope: Promise<GPUError | null>): Promise<void> {
|
|
29
29
|
const error = await errorScope as GPUValidationError;
|
|
30
30
|
if (error) {
|
|
31
31
|
const shaderLog = await this.compilationInfo();
|
|
@@ -36,7 +36,7 @@ export default class WebGPUShader extends Shader {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
destroy() {
|
|
39
|
+
override destroy(): void {
|
|
40
40
|
// this.handle.destroy();
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// luma.gl, MIT license
|
|
2
|
-
import {Texture, TextureProps, Sampler, SamplerProps
|
|
2
|
+
import {Texture, TextureProps, Sampler, SamplerProps} from '@luma.gl/api';
|
|
3
3
|
import {getWebGPUTextureFormat} from '../helpers/convert-texture-format';
|
|
4
4
|
import type WebGPUDevice from '../webgpu-device';
|
|
5
5
|
import WebGPUSampler from './webgpu-sampler';
|
|
@@ -17,7 +17,7 @@ export default class WebGPUTexture extends Texture {
|
|
|
17
17
|
readonly device: WebGPUDevice;
|
|
18
18
|
readonly handle: GPUTexture;
|
|
19
19
|
readonly view: GPUTextureView;
|
|
20
|
-
sampler: WebGPUSampler
|
|
20
|
+
sampler: WebGPUSampler;
|
|
21
21
|
|
|
22
22
|
// static async createFromImageURL(src, usage = 0) {
|
|
23
23
|
// const img = document.createElement('img');
|
|
@@ -82,7 +82,7 @@ export default class WebGPUTexture extends Texture {
|
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
destroy(): void {
|
|
85
|
+
override destroy(): void {
|
|
86
86
|
this.handle.destroy();
|
|
87
87
|
}
|
|
88
88
|
|
|
@@ -11,8 +11,6 @@ export default class WebGPUCanvasContext extends CanvasContext {
|
|
|
11
11
|
readonly device: WebGPUDevice;
|
|
12
12
|
readonly gpuCanvasContext: GPUCanvasContext;
|
|
13
13
|
readonly format: TextureFormat;
|
|
14
|
-
width: number = -1;
|
|
15
|
-
height: number = -1;
|
|
16
14
|
depthStencilFormat: TextureFormat = 'depth24plus';
|
|
17
15
|
sampleCount: number = 1;
|
|
18
16
|
|
|
@@ -21,11 +19,16 @@ export default class WebGPUCanvasContext extends CanvasContext {
|
|
|
21
19
|
constructor(device: WebGPUDevice, adapter: GPUAdapter, props: CanvasContextProps) {
|
|
22
20
|
super(props);
|
|
23
21
|
this.device = device;
|
|
22
|
+
// TODO - hack to trigger resize?
|
|
23
|
+
this.width = -1;
|
|
24
|
+
this.height = -1;
|
|
25
|
+
|
|
26
|
+
this._setAutoCreatedCanvasId(`${this.device.id}-canvas`);
|
|
24
27
|
this.gpuCanvasContext = this.canvas.getContext('webgpu') as GPUCanvasContext;
|
|
25
28
|
this.format = this.gpuCanvasContext.getPreferredFormat(adapter);
|
|
26
29
|
}
|
|
27
30
|
|
|
28
|
-
destroy() {
|
|
31
|
+
destroy(): void {
|
|
29
32
|
this.gpuCanvasContext.unconfigure();
|
|
30
33
|
}
|
|
31
34
|
|