@luma.gl/webgpu 9.0.0-alpha.5 → 9.0.0-alpha.50
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/LICENSE +3 -1
- package/dist/adapter/helpers/accessor-to-format.js.map +1 -1
- package/dist/adapter/helpers/convert-texture-format.d.ts +2 -2
- package/dist/adapter/helpers/convert-texture-format.d.ts.map +1 -1
- package/dist/adapter/helpers/convert-texture-format.js +0 -1
- package/dist/adapter/helpers/convert-texture-format.js.map +1 -1
- package/dist/adapter/helpers/generate-mipmaps.d.ts +1 -1
- package/dist/adapter/helpers/generate-mipmaps.js +20 -15
- package/dist/adapter/helpers/generate-mipmaps.js.map +1 -1
- package/dist/adapter/helpers/get-bind-group.d.ts +4 -4
- package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
- package/dist/adapter/helpers/get-bind-group.js +8 -17
- package/dist/adapter/helpers/get-bind-group.js.map +1 -1
- package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts +5 -5
- package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -1
- package/dist/adapter/helpers/get-vertex-buffer-layout.js +32 -40
- package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +1 -1
- package/dist/adapter/helpers/webgpu-parameters.d.ts +2 -2
- package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
- package/dist/adapter/helpers/webgpu-parameters.js +51 -48
- package/dist/adapter/helpers/webgpu-parameters.js.map +1 -1
- package/dist/adapter/resources/webgpu-buffer.d.ts +5 -6
- package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-buffer.js +19 -33
- package/dist/adapter/resources/webgpu-buffer.js.map +1 -1
- package/dist/adapter/resources/webgpu-command-encoder.d.ts +6 -15
- package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-command-encoder.js +11 -29
- package/dist/adapter/resources/webgpu-command-encoder.js.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pass.d.ts +6 -6
- package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pass.js +14 -27
- package/dist/adapter/resources/webgpu-compute-pass.js.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +4 -4
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pipeline.js +6 -11
- package/dist/adapter/resources/webgpu-compute-pipeline.js.map +1 -1
- package/dist/adapter/resources/webgpu-external-texture.d.ts +5 -5
- package/dist/adapter/resources/webgpu-external-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-external-texture.js +6 -14
- package/dist/adapter/resources/webgpu-external-texture.js.map +1 -1
- package/dist/adapter/resources/webgpu-framebuffer.d.ts +4 -21
- package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-framebuffer.js +4 -105
- package/dist/adapter/resources/webgpu-framebuffer.js.map +1 -1
- package/dist/adapter/resources/webgpu-query.js.map +1 -1
- package/dist/adapter/resources/webgpu-render-pass.d.ts +12 -7
- package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pass.js +59 -36
- package/dist/adapter/resources/webgpu-render-pass.js.map +1 -1
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts +14 -10
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pipeline.js +50 -67
- package/dist/adapter/resources/webgpu-render-pipeline.js.map +1 -1
- package/dist/adapter/resources/webgpu-sampler.d.ts +5 -5
- package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-sampler.js +11 -11
- package/dist/adapter/resources/webgpu-sampler.js.map +1 -1
- package/dist/adapter/resources/webgpu-shader.d.ts +7 -7
- package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-shader.js +11 -25
- package/dist/adapter/resources/webgpu-shader.js.map +1 -1
- package/dist/adapter/resources/webgpu-texture.d.ts +15 -8
- package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-texture.js +17 -27
- package/dist/adapter/resources/webgpu-texture.js.map +1 -1
- package/dist/adapter/resources/webgpu-vertex-array.d.ts +26 -0
- package/dist/adapter/resources/webgpu-vertex-array.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-vertex-array.js +39 -0
- package/dist/adapter/resources/webgpu-vertex-array.js.map +1 -0
- package/dist/adapter/webgpu-canvas-context.d.ts +16 -12
- package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgpu-canvas-context.js +26 -47
- package/dist/adapter/webgpu-canvas-context.js.map +1 -1
- package/dist/adapter/webgpu-device.d.ts +39 -22
- package/dist/adapter/webgpu-device.d.ts.map +1 -1
- package/dist/adapter/webgpu-device.js +94 -95
- package/dist/adapter/webgpu-device.js.map +1 -1
- package/dist/adapter/webgpu-types.js.map +1 -1
- package/dist/dist.dev.js +2988 -0
- package/dist/glsl/glsllang.js +0 -1
- package/dist/glsl/glsllang.js.map +1 -1
- package/dist/index.cjs +1518 -0
- package/dist/index.d.ts +5 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -7
- package/dist/index.js.map +1 -1
- package/dist.min.js +20 -0
- package/package.json +18 -9
- package/src/adapter/helpers/accessor-to-format.ts +1 -2
- package/src/adapter/helpers/convert-texture-format.ts +1 -1
- package/src/adapter/helpers/generate-mipmaps.ts +2 -2
- package/src/adapter/helpers/get-bind-group.ts +22 -12
- package/src/adapter/helpers/get-vertex-buffer-layout.ts +55 -34
- package/src/adapter/helpers/webgpu-parameters.ts +56 -47
- package/src/adapter/resources/webgpu-buffer.ts +11 -12
- package/src/adapter/resources/webgpu-command-encoder.ts +62 -41
- package/src/adapter/resources/webgpu-compute-pass.ts +13 -13
- package/src/adapter/resources/webgpu-compute-pipeline.ts +6 -5
- package/src/adapter/resources/webgpu-external-texture.ts +5 -5
- package/src/adapter/resources/webgpu-framebuffer.ts +8 -109
- package/src/adapter/resources/webgpu-query.ts +3 -3
- package/src/adapter/resources/webgpu-render-pass.ts +74 -18
- package/src/adapter/resources/webgpu-render-pipeline.ts +64 -39
- package/src/adapter/resources/webgpu-sampler.ts +12 -5
- package/src/adapter/resources/webgpu-shader.ts +13 -10
- package/src/adapter/resources/webgpu-texture.ts +22 -8
- package/src/adapter/resources/webgpu-vertex-array.ts +74 -0
- package/src/adapter/webgpu-canvas-context.ts +52 -27
- package/src/adapter/webgpu-device.ts +158 -64
- package/src/index.ts +7 -9
- package/dist/bundle.d.ts +0 -2
- package/dist/bundle.d.ts.map +0 -1
- package/dist/bundle.js +0 -5
- package/dist/bundle.js.map +0 -1
- package/dist/init.d.ts +0 -2
- package/dist/init.d.ts.map +0 -1
- package/dist/init.js +0 -4
- package/dist/init.js.map +0 -1
- package/src/bundle.ts +0 -4
- package/src/init.ts +0 -4
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// luma.gl, MIT license
|
|
2
|
+
// Copyright (c) vis.gl contributors
|
|
3
|
+
|
|
4
|
+
import type {ShaderProps, CompilerMessage} from '@luma.gl/core';
|
|
5
|
+
import {Shader, log} from '@luma.gl/core';
|
|
6
|
+
import type {WebGPUDevice} from '../webgpu-device';
|
|
4
7
|
|
|
5
8
|
export type WebGPUShaderProps = ShaderProps & {
|
|
6
9
|
handle?: GPUShaderModule;
|
|
@@ -9,7 +12,7 @@ export type WebGPUShaderProps = ShaderProps & {
|
|
|
9
12
|
/**
|
|
10
13
|
* Immutable shader
|
|
11
14
|
*/
|
|
12
|
-
export
|
|
15
|
+
export class WebGPUShader extends Shader {
|
|
13
16
|
readonly device: WebGPUDevice;
|
|
14
17
|
readonly handle: GPUShaderModule;
|
|
15
18
|
|
|
@@ -25,7 +28,7 @@ export default class WebGPUShader extends Shader {
|
|
|
25
28
|
this._checkCompilationError(this.device.handle.popErrorScope());
|
|
26
29
|
}
|
|
27
30
|
|
|
28
|
-
async _checkCompilationError(errorScope: Promise<GPUError>): Promise<void> {
|
|
31
|
+
async _checkCompilationError(errorScope: Promise<GPUError | null>): Promise<void> {
|
|
29
32
|
const error = await errorScope as GPUValidationError;
|
|
30
33
|
if (error) {
|
|
31
34
|
const shaderLog = await this.compilationInfo();
|
|
@@ -36,16 +39,16 @@ export default class WebGPUShader extends Shader {
|
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
|
|
39
|
-
destroy() {
|
|
42
|
+
override destroy(): void {
|
|
40
43
|
// this.handle.destroy();
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
protected createHandle(): GPUShaderModule {
|
|
44
|
-
const {source} = this.props;
|
|
47
|
+
const {source, stage} = this.props;
|
|
45
48
|
|
|
46
49
|
let language = this.props.language;
|
|
47
50
|
// Compile from src
|
|
48
|
-
if (
|
|
51
|
+
if (language === 'auto') {
|
|
49
52
|
// wgsl uses C++ "auto" style arrow notation
|
|
50
53
|
language = source.includes('->') ? 'wgsl' : 'glsl';
|
|
51
54
|
}
|
|
@@ -57,7 +60,7 @@ export default class WebGPUShader extends Shader {
|
|
|
57
60
|
return this.device.handle.createShaderModule({
|
|
58
61
|
code: source,
|
|
59
62
|
// @ts-expect-error
|
|
60
|
-
transform: (glsl) => this.device.glslang.compileGLSL(glsl,
|
|
63
|
+
transform: (glsl) => this.device.glslang.compileGLSL(glsl, stage)
|
|
61
64
|
});
|
|
62
65
|
default:
|
|
63
66
|
throw new Error(language);
|
|
@@ -66,7 +69,7 @@ export default class WebGPUShader extends Shader {
|
|
|
66
69
|
|
|
67
70
|
/** Returns compilation info for this shader */
|
|
68
71
|
async compilationInfo(): Promise<readonly CompilerMessage[]> {
|
|
69
|
-
const compilationInfo = await this.handle.
|
|
72
|
+
const compilationInfo = await this.handle.getCompilationInfo();
|
|
70
73
|
return compilationInfo.messages;
|
|
71
74
|
}
|
|
72
75
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// luma.gl, MIT license
|
|
2
|
-
import {Texture, TextureProps, Sampler, SamplerProps
|
|
2
|
+
import {Texture, TextureProps, Sampler, SamplerProps} from '@luma.gl/core';
|
|
3
3
|
import {getWebGPUTextureFormat} from '../helpers/convert-texture-format';
|
|
4
|
-
import type WebGPUDevice from '../webgpu-device';
|
|
5
|
-
import WebGPUSampler from './webgpu-sampler';
|
|
4
|
+
import type {WebGPUDevice} from '../webgpu-device';
|
|
5
|
+
import {WebGPUSampler} from './webgpu-sampler';
|
|
6
6
|
|
|
7
7
|
const BASE_DIMENSIONS: Record<string, '1d' | '2d' | '3d'> = {
|
|
8
8
|
'1d': '1d',
|
|
@@ -13,12 +13,15 @@ const BASE_DIMENSIONS: Record<string, '1d' | '2d' | '3d'> = {
|
|
|
13
13
|
'3d': '3d'
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
export
|
|
16
|
+
export class WebGPUTexture extends Texture {
|
|
17
17
|
readonly device: WebGPUDevice;
|
|
18
18
|
readonly handle: GPUTexture;
|
|
19
19
|
readonly view: GPUTextureView;
|
|
20
20
|
sampler: WebGPUSampler;
|
|
21
21
|
|
|
22
|
+
override height: number = 1;
|
|
23
|
+
override width: number = 1;
|
|
24
|
+
|
|
22
25
|
// static async createFromImageURL(src, usage = 0) {
|
|
23
26
|
// const img = document.createElement('img');
|
|
24
27
|
// img.src = src;
|
|
@@ -40,8 +43,19 @@ export default class WebGPUTexture extends Texture {
|
|
|
40
43
|
this.setData({data: this.props.data} );
|
|
41
44
|
}
|
|
42
45
|
|
|
46
|
+
this.width = this.handle.width;
|
|
47
|
+
this.height = this.handle.height;
|
|
48
|
+
// Why not just read all properties directly from the texture
|
|
49
|
+
// this.depthOrArrayLayers = this.handle.depthOrArrayLayers;
|
|
50
|
+
// this.mipLevelCount = this.handle.mipLevelCount;
|
|
51
|
+
// this.sampleCount = this.handle.sampleCount;
|
|
52
|
+
// this.dimension = this.handle.dimension;
|
|
53
|
+
// this.format = this.handle.format;
|
|
54
|
+
// this.usage = this.handle.usage;
|
|
55
|
+
|
|
43
56
|
// Create a default sampler. This mimics the WebGL1 API where sampler props are stored on the texture
|
|
44
|
-
this.setSampler(props.sampler);
|
|
57
|
+
// this.setSampler(props.sampler);
|
|
58
|
+
this.sampler = props.sampler instanceof WebGPUSampler ? props.sampler : new WebGPUSampler(this.device, props.sampler);
|
|
45
59
|
|
|
46
60
|
// TODO - To support texture arrays we need to create custom views...
|
|
47
61
|
// But we are not ready to expose TextureViews to the public API.
|
|
@@ -81,7 +95,7 @@ export default class WebGPUTexture extends Texture {
|
|
|
81
95
|
});
|
|
82
96
|
}
|
|
83
97
|
|
|
84
|
-
destroy(): void {
|
|
98
|
+
override destroy(): void {
|
|
85
99
|
this.handle.destroy();
|
|
86
100
|
}
|
|
87
101
|
|
|
@@ -115,7 +129,7 @@ export default class WebGPUTexture extends Texture {
|
|
|
115
129
|
aspect?: 'all' | 'stencil-only' | 'depth-only';
|
|
116
130
|
colorSpace?: 'srgb';
|
|
117
131
|
premultipliedAlpha?: boolean;
|
|
118
|
-
}):
|
|
132
|
+
}): {width: number, height: number} {
|
|
119
133
|
const {
|
|
120
134
|
source,
|
|
121
135
|
width = options.source.width,
|
|
@@ -156,7 +170,7 @@ export default class WebGPUTexture extends Texture {
|
|
|
156
170
|
depth
|
|
157
171
|
]
|
|
158
172
|
);
|
|
159
|
-
return
|
|
173
|
+
return {width, height};
|
|
160
174
|
}
|
|
161
175
|
|
|
162
176
|
/*
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// luma.gl, MIT license
|
|
2
|
+
// Copyright (c) vis.gl contributors
|
|
3
|
+
|
|
4
|
+
import type {Device, Buffer, VertexArrayProps, RenderPass, TypedArray} from '@luma.gl/core';
|
|
5
|
+
import {VertexArray, log} from '@luma.gl/core';
|
|
6
|
+
import {getBrowser} from '@probe.gl/env';
|
|
7
|
+
|
|
8
|
+
import {WebGPUDevice} from '../webgpu-device';
|
|
9
|
+
import {WebGPUBuffer} from '../resources/webgpu-buffer';
|
|
10
|
+
|
|
11
|
+
import {WebGPURenderPass} from './webgpu-render-pass';
|
|
12
|
+
|
|
13
|
+
/** VertexArrayObject wrapper */
|
|
14
|
+
export class WebGPUVertexArray extends VertexArray {
|
|
15
|
+
override get [Symbol.toStringTag](): string {
|
|
16
|
+
return 'WebGPUVertexArray';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
readonly device: WebGPUDevice;
|
|
20
|
+
/** Vertex Array is a helper class under WebGPU */
|
|
21
|
+
readonly handle: never;
|
|
22
|
+
|
|
23
|
+
/** * Attribute 0 can not be disable on most desktop OpenGL based browsers */
|
|
24
|
+
static isConstantAttributeZeroSupported(device: Device): boolean {
|
|
25
|
+
return device.info.type === 'webgl2' || getBrowser() === 'Chrome';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Create a VertexArray
|
|
29
|
+
constructor(device: WebGPUDevice, props?: VertexArrayProps) {
|
|
30
|
+
super(device, props);
|
|
31
|
+
this.device = device;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
override destroy(): void {}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Set an elements buffer, for indexed rendering.
|
|
38
|
+
* Must be a Buffer bound to buffer with usage bit Buffer.INDEX set.
|
|
39
|
+
*/
|
|
40
|
+
setIndexBuffer(buffer: Buffer | null): void {
|
|
41
|
+
// assert(!elementBuffer || elementBuffer.glTarget === GL.ELEMENT_ARRAY_BUFFER, ERR_ELEMENTS);
|
|
42
|
+
this.indexBuffer = buffer;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */
|
|
46
|
+
setBuffer(location: number, buffer: Buffer): void {
|
|
47
|
+
// Sanity check target
|
|
48
|
+
// if (buffer.glUsage === GL.ELEMENT_ARRAY_BUFFER) {
|
|
49
|
+
// throw new Error('Use setIndexBuffer');
|
|
50
|
+
// }
|
|
51
|
+
|
|
52
|
+
this.attributes[location] = buffer;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Set a location in vertex attributes array to a constant value, disables the location */
|
|
56
|
+
override setConstant(location: number, value: TypedArray): void {
|
|
57
|
+
log.warn(`${this.id} constant attributes not supported on WebGPU`)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
override bindBeforeRender(renderPass: RenderPass, firstIndex?: number, indexCount?: number): void {
|
|
61
|
+
const webgpuRenderPass = renderPass as WebGPURenderPass;
|
|
62
|
+
const webgpuIndexBuffer = this.indexBuffer as WebGPUBuffer;
|
|
63
|
+
webgpuRenderPass.handle.setIndexBuffer(webgpuIndexBuffer?.handle, webgpuIndexBuffer?.indexType);
|
|
64
|
+
for (let location = 0; location < this.maxVertexAttributes; location++) {
|
|
65
|
+
const webgpuBuffer = this.attributes[location] as WebGPUBuffer;
|
|
66
|
+
webgpuRenderPass.handle.setVertexBuffer(location, webgpuBuffer.handle);
|
|
67
|
+
}
|
|
68
|
+
// TODO - emit warnings/errors/throw if constants have been set on this vertex array
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
override unbindAfterRender(renderPass: RenderPass): void {
|
|
72
|
+
// On WebGPU we don't unbind
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -1,52 +1,77 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
// / <reference types="@webgpu/types" />
|
|
2
|
+
import type {Texture, TextureFormat, CanvasContextProps} from '@luma.gl/core';
|
|
3
|
+
import {CanvasContext, log} from '@luma.gl/core';
|
|
3
4
|
import {getWebGPUTextureFormat} from './helpers/convert-texture-format';
|
|
4
|
-
import WebGPUDevice from './webgpu-device';
|
|
5
|
-
import
|
|
5
|
+
import {WebGPUDevice} from './webgpu-device';
|
|
6
|
+
import {WebGPUFramebuffer} from './resources/webgpu-framebuffer';
|
|
7
|
+
import {WebGPUTexture} from './resources/webgpu-texture';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
|
-
* Holds a WebGPU Canvas Context
|
|
10
|
+
* Holds a WebGPU Canvas Context
|
|
11
|
+
* The primary job of the CanvasContext is to generate textures for rendering into the current canvas
|
|
12
|
+
* It also manages canvas sizing calculations and resizing.
|
|
9
13
|
*/
|
|
10
|
-
export
|
|
14
|
+
export class WebGPUCanvasContext extends CanvasContext {
|
|
11
15
|
readonly device: WebGPUDevice;
|
|
12
16
|
readonly gpuCanvasContext: GPUCanvasContext;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
/** Format of returned textures: "bgra8unorm", "rgba8unorm", "rgba16float". */
|
|
18
|
+
readonly format: TextureFormat = navigator.gpu.getPreferredCanvasFormat();
|
|
19
|
+
/** Default stencil format for depth textures */
|
|
16
20
|
depthStencilFormat: TextureFormat = 'depth24plus';
|
|
17
|
-
sampleCount: number = 1;
|
|
18
21
|
|
|
19
|
-
private depthStencilAttachment: Texture;
|
|
22
|
+
private depthStencilAttachment: Texture | null = null;
|
|
20
23
|
|
|
21
24
|
constructor(device: WebGPUDevice, adapter: GPUAdapter, props: CanvasContextProps) {
|
|
22
25
|
super(props);
|
|
23
26
|
this.device = device;
|
|
24
|
-
|
|
25
|
-
this.
|
|
27
|
+
// TODO - hack to trigger resize?
|
|
28
|
+
this.width = -1;
|
|
29
|
+
this.height = -1;
|
|
30
|
+
|
|
31
|
+
this._setAutoCreatedCanvasId(`${this.device.id}-canvas`);
|
|
32
|
+
// @ts-ignore TODO - we don't handle OffscreenRenderingContext.
|
|
33
|
+
this.gpuCanvasContext = this.canvas.getContext('webgpu');
|
|
34
|
+
// TODO this has been replaced
|
|
35
|
+
// this.format = this.gpuCanvasContext.getPreferredFormat(adapter);
|
|
36
|
+
this.format = 'bgra8unorm';
|
|
26
37
|
}
|
|
27
38
|
|
|
28
|
-
|
|
39
|
+
/** Destroy any textures produced while configured and remove the context configuration. */
|
|
40
|
+
destroy(): void {
|
|
29
41
|
this.gpuCanvasContext.unconfigure();
|
|
30
42
|
}
|
|
31
43
|
|
|
44
|
+
getCurrentTexture(): WebGPUTexture {
|
|
45
|
+
// Wrap the current canvas context texture in a luma.gl texture
|
|
46
|
+
return this.device._createTexture({
|
|
47
|
+
id: 'default-render-target',
|
|
48
|
+
handle: this.gpuCanvasContext.getCurrentTexture()
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
32
52
|
/** Update framebuffer with properly resized "swap chain" texture views */
|
|
33
|
-
getCurrentFramebuffer():
|
|
53
|
+
getCurrentFramebuffer(): WebGPUFramebuffer {
|
|
34
54
|
// Ensure the canvas context size is updated
|
|
35
55
|
this.update();
|
|
36
56
|
|
|
57
|
+
// Wrap the current canvas context texture in a luma.gl texture
|
|
58
|
+
// const currentColorAttachment = this.device.createTexture({
|
|
59
|
+
// id: 'default-render-target',
|
|
60
|
+
// handle: this.gpuCanvasContext.getCurrentTexture(),
|
|
61
|
+
// format: this.format,
|
|
62
|
+
// width: this.width,
|
|
63
|
+
// height: this.height
|
|
64
|
+
// });
|
|
65
|
+
|
|
37
66
|
// Wrap the current canvas context texture in a luma.gl texture
|
|
38
|
-
const currentColorAttachment = this.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
format: this.format,
|
|
42
|
-
width: this.width,
|
|
43
|
-
height: this.height
|
|
44
|
-
});
|
|
67
|
+
const currentColorAttachment = this.getCurrentTexture();
|
|
68
|
+
this.width = currentColorAttachment.width;
|
|
69
|
+
this.height = currentColorAttachment.height;
|
|
45
70
|
|
|
46
71
|
// Resize the depth stencil attachment
|
|
47
72
|
this._createDepthStencilAttachment();
|
|
48
73
|
|
|
49
|
-
return new
|
|
74
|
+
return new WebGPUFramebuffer(this.device, {
|
|
50
75
|
colorAttachments: [currentColorAttachment],
|
|
51
76
|
depthStencilAttachment: this.depthStencilAttachment
|
|
52
77
|
});
|
|
@@ -64,7 +89,7 @@ export default class WebGPUCanvasContext extends CanvasContext {
|
|
|
64
89
|
|
|
65
90
|
if (this.depthStencilAttachment) {
|
|
66
91
|
this.depthStencilAttachment.destroy();
|
|
67
|
-
this.depthStencilAttachment =
|
|
92
|
+
this.depthStencilAttachment = null;
|
|
68
93
|
}
|
|
69
94
|
|
|
70
95
|
// Reconfigure the canvas size.
|
|
@@ -72,14 +97,14 @@ export default class WebGPUCanvasContext extends CanvasContext {
|
|
|
72
97
|
this.gpuCanvasContext.configure({
|
|
73
98
|
device: this.device.handle,
|
|
74
99
|
format: getWebGPUTextureFormat(this.format),
|
|
75
|
-
|
|
100
|
+
// Can be used to define e.g. -srgb views
|
|
101
|
+
// viewFormats: [...]
|
|
76
102
|
colorSpace: this.props.colorSpace,
|
|
77
|
-
|
|
103
|
+
alphaMode: this.props.alphaMode
|
|
78
104
|
});
|
|
79
105
|
|
|
80
106
|
log.log(1, `Resized to ${this.width}x${this.height}px`)();
|
|
81
107
|
}
|
|
82
|
-
|
|
83
108
|
}
|
|
84
109
|
|
|
85
110
|
resize(options?: {width?: number; height?: number; useDevicePixels?: boolean | number}): void {
|