@luma.gl/webgpu 9.0.0-beta.4 → 9.0.0-beta.6
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/accessor-to-format.js +102 -1
- package/dist/adapter/helpers/convert-texture-format.d.ts.map +1 -1
- package/dist/adapter/helpers/convert-texture-format.js +8 -5
- package/dist/adapter/helpers/generate-mipmaps.d.ts.map +1 -1
- package/dist/adapter/helpers/generate-mipmaps.js +85 -82
- package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
- package/dist/adapter/helpers/get-bind-group.js +57 -41
- package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -1
- package/dist/adapter/helpers/get-vertex-buffer-layout.js +117 -80
- package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
- package/dist/adapter/helpers/webgpu-parameters.js +185 -125
- package/dist/adapter/resources/webgpu-buffer.d.ts +1 -1
- package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-buffer.js +117 -62
- package/dist/adapter/resources/webgpu-command-encoder.d.ts +7 -1
- package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-command-encoder.js +81 -49
- package/dist/adapter/resources/webgpu-compute-pass.d.ts +1 -1
- package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pass.js +71 -41
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +1 -1
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pipeline.js +28 -19
- package/dist/adapter/resources/webgpu-external-texture.d.ts +2 -2
- package/dist/adapter/resources/webgpu-external-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-external-texture.js +33 -18
- package/dist/adapter/resources/webgpu-framebuffer.d.ts +1 -1
- package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-framebuffer.js +14 -7
- package/dist/adapter/resources/webgpu-query-set.d.ts +17 -0
- package/dist/adapter/resources/webgpu-query-set.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-query-set.js +25 -0
- package/dist/adapter/resources/webgpu-query.js +42 -1
- package/dist/adapter/resources/webgpu-render-pass.d.ts +4 -2
- package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pass.js +133 -105
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts +3 -4
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pipeline.js +137 -80
- package/dist/adapter/resources/webgpu-sampler.d.ts +1 -1
- package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-sampler.js +18 -15
- 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 +56 -45
- package/dist/adapter/resources/webgpu-texture-view.d.ts +20 -0
- package/dist/adapter/resources/webgpu-texture-view.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-texture-view.js +32 -0
- package/dist/adapter/resources/webgpu-texture.d.ts +5 -4
- package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-texture.js +130 -107
- package/dist/adapter/resources/webgpu-vertex-array.d.ts +7 -6
- package/dist/adapter/resources/webgpu-vertex-array.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-vertex-array.js +60 -39
- package/dist/adapter/webgpu-canvas-context.d.ts +3 -3
- package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgpu-canvas-context.js +100 -67
- package/dist/adapter/webgpu-device.d.ts +24 -21
- package/dist/adapter/webgpu-device.d.ts.map +1 -1
- package/dist/adapter/webgpu-device.js +264 -220
- package/dist/adapter/webgpu-types.js +0 -2
- package/dist/dist.dev.js +782 -2222
- package/dist/glsl/glsllang.js +9 -6
- package/dist/index.cjs +279 -388
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist.min.js +1 -22
- package/package.json +9 -7
- package/src/adapter/helpers/accessor-to-format.ts +5 -1
- package/src/adapter/helpers/convert-texture-format.ts +4 -1
- package/src/adapter/helpers/generate-mipmaps.ts +37 -26
- package/src/adapter/helpers/get-bind-group.ts +8 -2
- package/src/adapter/helpers/get-vertex-buffer-layout.ts +12 -4
- package/src/adapter/helpers/webgpu-parameters.ts +79 -15
- package/src/adapter/resources/webgpu-buffer.ts +21 -10
- package/src/adapter/resources/webgpu-command-encoder.ts +24 -9
- package/src/adapter/resources/webgpu-compute-pass.ts +26 -8
- package/src/adapter/resources/webgpu-compute-pipeline.ts +15 -10
- package/src/adapter/resources/webgpu-external-texture.ts +12 -6
- package/src/adapter/resources/webgpu-framebuffer.ts +4 -0
- package/src/adapter/resources/webgpu-query-set.ts +35 -0
- package/src/adapter/resources/webgpu-render-pass.ts +37 -14
- package/src/adapter/resources/webgpu-render-pipeline.ts +30 -41
- package/src/adapter/resources/webgpu-sampler.ts +1 -1
- package/src/adapter/resources/webgpu-shader.ts +5 -4
- package/src/adapter/resources/webgpu-texture-view.ts +43 -0
- package/src/adapter/resources/webgpu-texture.ts +23 -19
- package/src/adapter/resources/webgpu-vertex-array.ts +25 -17
- package/src/adapter/webgpu-canvas-context.ts +8 -3
- package/src/adapter/webgpu-device.ts +100 -88
- package/src/index.ts +2 -1
- package/dist/adapter/helpers/accessor-to-format.js.map +0 -1
- package/dist/adapter/helpers/convert-texture-format.js.map +0 -1
- package/dist/adapter/helpers/generate-mipmaps.js.map +0 -1
- package/dist/adapter/helpers/get-bind-group.js.map +0 -1
- package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +0 -1
- package/dist/adapter/helpers/webgpu-parameters.js.map +0 -1
- package/dist/adapter/resources/webgpu-buffer.js.map +0 -1
- package/dist/adapter/resources/webgpu-command-encoder.js.map +0 -1
- package/dist/adapter/resources/webgpu-compute-pass.js.map +0 -1
- package/dist/adapter/resources/webgpu-compute-pipeline.js.map +0 -1
- package/dist/adapter/resources/webgpu-external-texture.js.map +0 -1
- package/dist/adapter/resources/webgpu-framebuffer.js.map +0 -1
- package/dist/adapter/resources/webgpu-query.js.map +0 -1
- package/dist/adapter/resources/webgpu-render-pass.js.map +0 -1
- package/dist/adapter/resources/webgpu-render-pipeline.js.map +0 -1
- package/dist/adapter/resources/webgpu-sampler.js.map +0 -1
- package/dist/adapter/resources/webgpu-shader.js.map +0 -1
- package/dist/adapter/resources/webgpu-texture.js.map +0 -1
- package/dist/adapter/resources/webgpu-vertex-array.js.map +0 -1
- package/dist/adapter/webgpu-canvas-context.js.map +0 -1
- package/dist/adapter/webgpu-device.js.map +0 -1
- package/dist/adapter/webgpu-types.js.map +0 -1
- package/dist/glsl/glsllang.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/src/adapter/resources/webgpu-query.ts +0 -43
- package/src/adapter/webgpu-types.ts +0 -0
- package/src/glsl/glsllang.ts +0 -14
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
2
5
|
// Forked from Kangz/mipmapper.js under MIT license Copyright 2020 Brandon Jones
|
|
3
6
|
// https://gist.github.com/Kangz/782d5f1ae502daf53910a13f55db2f83
|
|
4
7
|
|
|
@@ -30,7 +33,7 @@ export class WebGPUMipmapGenerator {
|
|
|
30
33
|
constructor(device: GPUDevice, glslang) {
|
|
31
34
|
this.device = device;
|
|
32
35
|
|
|
33
|
-
this.mipmapSampler = device.createSampler({
|
|
36
|
+
this.mipmapSampler = device.createSampler({minFilter: 'linear'});
|
|
34
37
|
|
|
35
38
|
this.mipmapPipeline = device.createRenderPipeline({
|
|
36
39
|
vertexStage: {
|
|
@@ -46,9 +49,11 @@ export class WebGPUMipmapGenerator {
|
|
|
46
49
|
entryPoint: 'main'
|
|
47
50
|
},
|
|
48
51
|
primitiveTopology: 'triangle-strip',
|
|
49
|
-
colorStates: [
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
colorStates: [
|
|
53
|
+
{
|
|
54
|
+
format: 'rgba8unorm'
|
|
55
|
+
}
|
|
56
|
+
]
|
|
52
57
|
});
|
|
53
58
|
}
|
|
54
59
|
|
|
@@ -56,9 +61,10 @@ export class WebGPUMipmapGenerator {
|
|
|
56
61
|
const textureSize = {
|
|
57
62
|
width: imageBitmap.width,
|
|
58
63
|
height: imageBitmap.height,
|
|
59
|
-
depth: 1
|
|
60
|
-
}
|
|
61
|
-
const mipLevelCount =
|
|
64
|
+
depth: 1
|
|
65
|
+
};
|
|
66
|
+
const mipLevelCount =
|
|
67
|
+
Math.floor(Math.log2(Math.max(imageBitmap.width, imageBitmap.height))) + 1;
|
|
62
68
|
|
|
63
69
|
// Populate the top level of the srcTexture with the imageBitmap.
|
|
64
70
|
const texture = this.device.createTexture({
|
|
@@ -67,32 +73,37 @@ export class WebGPUMipmapGenerator {
|
|
|
67
73
|
usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.SAMPLED | GPUTextureUsage.OUTPUT_ATTACHMENT,
|
|
68
74
|
mipLevelCount
|
|
69
75
|
});
|
|
70
|
-
this.device.queue.copyImageBitmapToTexture({
|
|
76
|
+
this.device.queue.copyImageBitmapToTexture({imageBitmap}, {texture}, textureSize);
|
|
71
77
|
|
|
72
78
|
const commandEncoder = this.device.createCommandEncoder({});
|
|
73
79
|
for (let i = 1; i < mipLevelCount; ++i) {
|
|
74
80
|
const passEncoder = commandEncoder.beginRenderPass({
|
|
75
|
-
colorAttachments: [
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
colorAttachments: [
|
|
82
|
+
{
|
|
83
|
+
attachment: texture.createView({
|
|
84
|
+
baseMipLevel: i,
|
|
85
|
+
mipLevelCount: 1
|
|
86
|
+
}),
|
|
87
|
+
loadValue: {r: 1.0, g: 0.0, b: 0.0, a: 0.0}
|
|
88
|
+
}
|
|
89
|
+
]
|
|
82
90
|
});
|
|
83
91
|
|
|
84
92
|
const bindGroup = this.device.createBindGroup({
|
|
85
93
|
layout: this.mipmapPipeline.getBindGroupLayout(0),
|
|
86
|
-
bindings: [
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
bindings: [
|
|
95
|
+
{
|
|
96
|
+
binding: 0,
|
|
97
|
+
resource: this.mipmapSampler
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
binding: 1,
|
|
101
|
+
resource: texture.createView({
|
|
102
|
+
baseMipLevel: i - 1,
|
|
103
|
+
mipLevelCount: 1
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
]
|
|
96
107
|
});
|
|
97
108
|
|
|
98
109
|
passEncoder.setPipeline(this.mipmapPipeline);
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
2
5
|
import type {ShaderLayout, BindingDeclaration, Binding} from '@luma.gl/core';
|
|
3
6
|
import {Buffer, Sampler, Texture, log, cast} from '@luma.gl/core';
|
|
4
7
|
import type {WebGPUBuffer} from '../resources/webgpu-buffer';
|
|
@@ -41,7 +44,10 @@ export function getShaderLayoutBinding(
|
|
|
41
44
|
shaderLayout: ShaderLayout,
|
|
42
45
|
bindingName: string
|
|
43
46
|
): BindingDeclaration {
|
|
44
|
-
const bindingLayout = shaderLayout.bindings.find(
|
|
47
|
+
const bindingLayout = shaderLayout.bindings.find(
|
|
48
|
+
binding =>
|
|
49
|
+
binding.name === bindingName || `${binding.name}uniforms` === bindingName.toLocaleLowerCase()
|
|
50
|
+
);
|
|
45
51
|
if (!bindingLayout) {
|
|
46
52
|
log.warn(`Binding ${bindingName} not set: Not found in shader layout.`)();
|
|
47
53
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
2
5
|
import type {ShaderLayout, BufferLayout, AttributeDeclaration, VertexFormat} from '@luma.gl/core';
|
|
3
6
|
import {log, decodeVertexFormat} from '@luma.gl/core';
|
|
4
7
|
// import {getAttributeInfosFromLayouts} from '@luma.gl/core';
|
|
@@ -40,7 +43,9 @@ export function getVertexBufferLayout(
|
|
|
40
43
|
const attributeName = attributeMapping.attribute;
|
|
41
44
|
const attributeLayout = findAttributeLayout(shaderLayout, attributeName, usedAttributes);
|
|
42
45
|
|
|
43
|
-
stepMode =
|
|
46
|
+
stepMode =
|
|
47
|
+
attributeLayout.stepMode ||
|
|
48
|
+
(attributeLayout.name.startsWith('instance') ? 'instance' : 'vertex');
|
|
44
49
|
vertexAttributes.push({
|
|
45
50
|
format: getWebGPUVertexFormat(attributeMapping.format || mapping.format),
|
|
46
51
|
offset: attributeMapping.byteOffset,
|
|
@@ -57,7 +62,9 @@ export function getVertexBufferLayout(
|
|
|
57
62
|
}
|
|
58
63
|
byteStride = decodeVertexFormat(mapping.format).byteLength;
|
|
59
64
|
|
|
60
|
-
stepMode =
|
|
65
|
+
stepMode =
|
|
66
|
+
attributeLayout.stepMode ||
|
|
67
|
+
(attributeLayout.name.startsWith('instance') ? 'instance' : 'vertex');
|
|
61
68
|
vertexAttributes.push({
|
|
62
69
|
format: getWebGPUVertexFormat(mapping.format),
|
|
63
70
|
// We only support 0 offset for non-interleaved buffer layouts
|
|
@@ -79,7 +86,8 @@ export function getVertexBufferLayout(
|
|
|
79
86
|
if (!usedAttributes.has(attribute.name)) {
|
|
80
87
|
vertexBufferLayouts.push({
|
|
81
88
|
arrayStride: decodeVertexFormat('float32x3').byteLength,
|
|
82
|
-
stepMode:
|
|
89
|
+
stepMode:
|
|
90
|
+
attribute.stepMode || (attribute.name.startsWith('instance') ? 'instance' : 'vertex'),
|
|
83
91
|
attributes: [
|
|
84
92
|
{
|
|
85
93
|
format: getWebGPUVertexFormat('float32x3'),
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
1
5
|
import {Parameters} from '@luma.gl/core';
|
|
2
6
|
|
|
3
7
|
function addDepthStencil(descriptor: GPURenderPipelineDescriptor): GPUDepthStencilState {
|
|
@@ -33,17 +37,29 @@ export const PARAMETER_TABLE: Record<keyof Parameters, Function> = {
|
|
|
33
37
|
|
|
34
38
|
// DEPTH
|
|
35
39
|
|
|
36
|
-
depthWriteEnabled: (
|
|
40
|
+
depthWriteEnabled: (
|
|
41
|
+
parameter: keyof Parameters,
|
|
42
|
+
value: any,
|
|
43
|
+
descriptor: GPURenderPipelineDescriptor
|
|
44
|
+
) => {
|
|
37
45
|
const depthStencil = addDepthStencil(descriptor);
|
|
38
46
|
depthStencil.depthWriteEnabled = value;
|
|
39
47
|
},
|
|
40
48
|
|
|
41
|
-
depthCompare: (
|
|
49
|
+
depthCompare: (
|
|
50
|
+
parameter: keyof Parameters,
|
|
51
|
+
value: any,
|
|
52
|
+
descriptor: GPURenderPipelineDescriptor
|
|
53
|
+
) => {
|
|
42
54
|
const depthStencil = addDepthStencil(descriptor);
|
|
43
55
|
depthStencil.depthCompare = value;
|
|
44
56
|
},
|
|
45
57
|
|
|
46
|
-
depthFormat: (
|
|
58
|
+
depthFormat: (
|
|
59
|
+
parameter: keyof Parameters,
|
|
60
|
+
value: any,
|
|
61
|
+
descriptor: GPURenderPipelineDescriptor
|
|
62
|
+
) => {
|
|
47
63
|
const depthStencil = addDepthStencil(descriptor);
|
|
48
64
|
depthStencil.format = value;
|
|
49
65
|
},
|
|
@@ -53,47 +69,79 @@ export const PARAMETER_TABLE: Record<keyof Parameters, Function> = {
|
|
|
53
69
|
depthStencil.depthBias = value;
|
|
54
70
|
},
|
|
55
71
|
|
|
56
|
-
depthBiasSlopeScale: (
|
|
72
|
+
depthBiasSlopeScale: (
|
|
73
|
+
parameter: keyof Parameters,
|
|
74
|
+
value: any,
|
|
75
|
+
descriptor: GPURenderPipelineDescriptor
|
|
76
|
+
) => {
|
|
57
77
|
const depthStencil = addDepthStencil(descriptor);
|
|
58
78
|
depthStencil.depthBiasSlopeScale = value;
|
|
59
79
|
},
|
|
60
80
|
|
|
61
|
-
depthBiasClamp: (
|
|
81
|
+
depthBiasClamp: (
|
|
82
|
+
parameter: keyof Parameters,
|
|
83
|
+
value: any,
|
|
84
|
+
descriptor: GPURenderPipelineDescriptor
|
|
85
|
+
) => {
|
|
62
86
|
const depthStencil = addDepthStencil(descriptor);
|
|
63
87
|
depthStencil.depthBiasClamp = value;
|
|
64
88
|
},
|
|
65
89
|
|
|
66
90
|
// STENCIL
|
|
67
91
|
|
|
68
|
-
stencilReadMask: (
|
|
92
|
+
stencilReadMask: (
|
|
93
|
+
parameter: keyof Parameters,
|
|
94
|
+
value: any,
|
|
95
|
+
descriptor: GPURenderPipelineDescriptor
|
|
96
|
+
) => {
|
|
69
97
|
const depthStencil = addDepthStencil(descriptor);
|
|
70
98
|
depthStencil.stencilReadMask = value;
|
|
71
99
|
},
|
|
72
100
|
|
|
73
|
-
stencilWriteMask: (
|
|
101
|
+
stencilWriteMask: (
|
|
102
|
+
parameter: keyof Parameters,
|
|
103
|
+
value: any,
|
|
104
|
+
descriptor: GPURenderPipelineDescriptor
|
|
105
|
+
) => {
|
|
74
106
|
const depthStencil = addDepthStencil(descriptor);
|
|
75
107
|
depthStencil.stencilWriteMask = value;
|
|
76
108
|
},
|
|
77
109
|
|
|
78
|
-
stencilCompare: (
|
|
110
|
+
stencilCompare: (
|
|
111
|
+
parameter: keyof Parameters,
|
|
112
|
+
value: any,
|
|
113
|
+
descriptor: GPURenderPipelineDescriptor
|
|
114
|
+
) => {
|
|
79
115
|
const depthStencil = addDepthStencil(descriptor);
|
|
80
116
|
depthStencil.stencilFront.compare = value;
|
|
81
117
|
depthStencil.stencilBack.compare = value;
|
|
82
118
|
},
|
|
83
119
|
|
|
84
|
-
stencilPassOperation: (
|
|
120
|
+
stencilPassOperation: (
|
|
121
|
+
parameter: keyof Parameters,
|
|
122
|
+
value: any,
|
|
123
|
+
descriptor: GPURenderPipelineDescriptor
|
|
124
|
+
) => {
|
|
85
125
|
const depthStencil = addDepthStencil(descriptor);
|
|
86
126
|
depthStencil.stencilFront.passOp = value;
|
|
87
127
|
depthStencil.stencilBack.passOp = value;
|
|
88
128
|
},
|
|
89
129
|
|
|
90
|
-
stencilFailOperation: (
|
|
130
|
+
stencilFailOperation: (
|
|
131
|
+
parameter: keyof Parameters,
|
|
132
|
+
value: any,
|
|
133
|
+
descriptor: GPURenderPipelineDescriptor
|
|
134
|
+
) => {
|
|
91
135
|
const depthStencil = addDepthStencil(descriptor);
|
|
92
136
|
depthStencil.stencilFront.failOp = value;
|
|
93
137
|
depthStencil.stencilBack.failOp = value;
|
|
94
138
|
},
|
|
95
139
|
|
|
96
|
-
stencilDepthFailOperation: (
|
|
140
|
+
stencilDepthFailOperation: (
|
|
141
|
+
parameter: keyof Parameters,
|
|
142
|
+
value: any,
|
|
143
|
+
descriptor: GPURenderPipelineDescriptor
|
|
144
|
+
) => {
|
|
97
145
|
const depthStencil = addDepthStencil(descriptor);
|
|
98
146
|
depthStencil.stencilFront.depthFailOp = value;
|
|
99
147
|
depthStencil.stencilBack.depthFailOp = value;
|
|
@@ -101,17 +149,29 @@ export const PARAMETER_TABLE: Record<keyof Parameters, Function> = {
|
|
|
101
149
|
|
|
102
150
|
// MULTISAMPLE
|
|
103
151
|
|
|
104
|
-
sampleCount: (
|
|
152
|
+
sampleCount: (
|
|
153
|
+
parameter: keyof Parameters,
|
|
154
|
+
value: any,
|
|
155
|
+
descriptor: GPURenderPipelineDescriptor
|
|
156
|
+
) => {
|
|
105
157
|
descriptor.multisample = descriptor.multisample || {};
|
|
106
158
|
descriptor.multisample.count = value;
|
|
107
159
|
},
|
|
108
160
|
|
|
109
|
-
sampleMask: (
|
|
161
|
+
sampleMask: (
|
|
162
|
+
parameter: keyof Parameters,
|
|
163
|
+
value: any,
|
|
164
|
+
descriptor: GPURenderPipelineDescriptor
|
|
165
|
+
) => {
|
|
110
166
|
descriptor.multisample = descriptor.multisample || {};
|
|
111
167
|
descriptor.multisample.mask = value;
|
|
112
168
|
},
|
|
113
169
|
|
|
114
|
-
sampleAlphaToCoverageEnabled: (
|
|
170
|
+
sampleAlphaToCoverageEnabled: (
|
|
171
|
+
parameter: keyof Parameters,
|
|
172
|
+
value: any,
|
|
173
|
+
descriptor: GPURenderPipelineDescriptor
|
|
174
|
+
) => {
|
|
115
175
|
descriptor.multisample = descriptor.multisample || {};
|
|
116
176
|
descriptor.multisample.alphaToCoverageEnabled = value;
|
|
117
177
|
},
|
|
@@ -123,7 +183,11 @@ export const PARAMETER_TABLE: Record<keyof Parameters, Function> = {
|
|
|
123
183
|
targets[0].writeMask = value;
|
|
124
184
|
},
|
|
125
185
|
|
|
126
|
-
blendColorOperation: (
|
|
186
|
+
blendColorOperation: (
|
|
187
|
+
parameter: keyof Parameters,
|
|
188
|
+
value: any,
|
|
189
|
+
descriptor: GPURenderPipelineDescriptor
|
|
190
|
+
) => {
|
|
127
191
|
addColorState(descriptor);
|
|
128
192
|
// const targets = addColorState(descriptor);
|
|
129
193
|
// const target = targets[0];
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
//
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
2
5
|
import {Buffer, BufferProps} from '@luma.gl/core';
|
|
3
6
|
import type {WebGPUDevice} from '../webgpu-device';
|
|
4
7
|
|
|
@@ -21,13 +24,15 @@ export class WebGPUBuffer extends Buffer {
|
|
|
21
24
|
// WebGPU buffers must be aligned to 4 bytes
|
|
22
25
|
const size = Math.ceil(this.byteLength / 4) * 4;
|
|
23
26
|
|
|
24
|
-
this.handle =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
this.handle =
|
|
28
|
+
this.props.handle ||
|
|
29
|
+
this.device.handle.createBuffer({
|
|
30
|
+
size,
|
|
31
|
+
// usage defaults to vertex
|
|
32
|
+
usage: this.props.usage || GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
|
|
33
|
+
mappedAtCreation: this.props.mappedAtCreation || mapBuffer,
|
|
34
|
+
label: this.props.id
|
|
35
|
+
});
|
|
31
36
|
|
|
32
37
|
if (props.data) {
|
|
33
38
|
this._writeMapped(props.data);
|
|
@@ -54,9 +59,15 @@ export class WebGPUBuffer extends Buffer {
|
|
|
54
59
|
);
|
|
55
60
|
}
|
|
56
61
|
|
|
57
|
-
override async readAsync(
|
|
62
|
+
override async readAsync(
|
|
63
|
+
byteOffset: number = 0,
|
|
64
|
+
byteLength: number = this.byteLength
|
|
65
|
+
): Promise<Uint8Array> {
|
|
58
66
|
// We need MAP_READ flag, but only COPY_DST buffers can have MAP_READ flag, so we need to create a temp buffer
|
|
59
|
-
const tempBuffer = new WebGPUBuffer(this.device, {
|
|
67
|
+
const tempBuffer = new WebGPUBuffer(this.device, {
|
|
68
|
+
usage: Buffer.MAP_READ | Buffer.COPY_DST,
|
|
69
|
+
byteLength
|
|
70
|
+
});
|
|
60
71
|
|
|
61
72
|
// Now do a GPU-side copy into the temp buffer we can actually read.
|
|
62
73
|
// TODO - we are spinning up an independent command queue here, what does this mean
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
1
5
|
import {CommandEncoder, CommandEncoderProps, Buffer, Texture} from '@luma.gl/core';
|
|
2
6
|
import type {CopyTextureToTextureOptions, CopyTextureToBufferOptions} from '@luma.gl/core';
|
|
3
7
|
import {WebGPUDevice} from '../webgpu-device';
|
|
4
8
|
import {WebGPUBuffer} from './webgpu-buffer';
|
|
5
9
|
import {WebGPUTexture} from './webgpu-texture';
|
|
10
|
+
import {WebGPUQuerySet} from './webgpu-query-set';
|
|
6
11
|
|
|
7
12
|
export class WebGPUCommandEncoder extends CommandEncoder {
|
|
8
13
|
readonly device: WebGPUDevice;
|
|
@@ -120,13 +125,23 @@ export class WebGPUCommandEncoder extends CommandEncoder {
|
|
|
120
125
|
this.handle.insertDebugMarker(markerLabel);
|
|
121
126
|
}
|
|
122
127
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
128
|
+
override resolveQuerySet(
|
|
129
|
+
querySet: WebGPUQuerySet,
|
|
130
|
+
destination: Buffer,
|
|
131
|
+
options?: {
|
|
132
|
+
firstQuery?: number;
|
|
133
|
+
queryCount?: number;
|
|
134
|
+
destinationOffset?: number;
|
|
135
|
+
}
|
|
136
|
+
): void {
|
|
137
|
+
const webgpuQuerySet = querySet;
|
|
138
|
+
const webgpuBuffer = destination as WebGPUBuffer;
|
|
139
|
+
this.handle.resolveQuerySet(
|
|
140
|
+
webgpuQuerySet.handle,
|
|
141
|
+
options.firstQuery || 0,
|
|
142
|
+
options.queryCount || querySet.props.count - (options.firstQuery || 0),
|
|
143
|
+
webgpuBuffer.handle,
|
|
144
|
+
options.destinationOffset || 0
|
|
145
|
+
);
|
|
146
|
+
}
|
|
132
147
|
}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
1
5
|
import {ComputePass, ComputePassProps, ComputePipeline, Buffer, Binding} from '@luma.gl/core';
|
|
2
6
|
import {WebGPUDevice} from '../webgpu-device';
|
|
3
7
|
import {WebGPUBuffer} from './webgpu-buffer';
|
|
4
8
|
// import {WebGPUCommandEncoder} from './webgpu-command-encoder';
|
|
5
9
|
import {WebGPUComputePipeline} from './webgpu-compute-pipeline';
|
|
10
|
+
import {WebGPUQuerySet} from './webgpu-query-set';
|
|
6
11
|
|
|
7
12
|
export class WebGPUComputePass extends ComputePass {
|
|
8
13
|
readonly device: WebGPUDevice;
|
|
@@ -13,10 +18,25 @@ export class WebGPUComputePass extends ComputePass {
|
|
|
13
18
|
super(device, props);
|
|
14
19
|
this.device = device;
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
// Set up queries
|
|
22
|
+
let timestampWrites: GPUComputePassTimestampWrites | undefined;
|
|
23
|
+
if (device.features.has('timestamp-query')) {
|
|
24
|
+
const webgpuQuerySet = props.timestampQuerySet as WebGPUQuerySet;
|
|
25
|
+
if (webgpuQuerySet) {
|
|
26
|
+
timestampWrites = {
|
|
27
|
+
querySet: webgpuQuerySet.handle,
|
|
28
|
+
beginningOfPassWriteIndex: props.beginTimestampIndex,
|
|
29
|
+
endOfPassWriteIndex: props.endTimestampIndex
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
this.handle =
|
|
35
|
+
this.props.handle ||
|
|
36
|
+
device.commandEncoder?.beginComputePass({
|
|
37
|
+
label: this.props.id,
|
|
38
|
+
timestampWrites
|
|
39
|
+
});
|
|
20
40
|
}
|
|
21
41
|
|
|
22
42
|
/** @note no WebGPU destroy method, just gc */
|
|
@@ -62,14 +82,12 @@ export class WebGPUComputePass extends ComputePass {
|
|
|
62
82
|
pushDebugGroup(groupLabel: string): void {
|
|
63
83
|
this.handle.pushDebugGroup(groupLabel);
|
|
64
84
|
}
|
|
85
|
+
|
|
65
86
|
popDebugGroup(): void {
|
|
66
87
|
this.handle.popDebugGroup();
|
|
67
88
|
}
|
|
89
|
+
|
|
68
90
|
insertDebugMarker(markerLabel: string): void {
|
|
69
91
|
this.handle.insertDebugMarker(markerLabel);
|
|
70
92
|
}
|
|
71
|
-
|
|
72
|
-
// writeTimestamp(querySet: GPUQuerySet, queryIndex: number): void;
|
|
73
|
-
// beginPipelineStatisticsQuery(querySet: GPUQuerySet, queryIndex: number): void;
|
|
74
|
-
// endPipelineStatisticsQuery(querySet: GPUQuerySet, queryIndex: number): void;
|
|
75
93
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
//
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
2
5
|
import {ComputePipeline, ComputePipelineProps} from '@luma.gl/core';
|
|
3
6
|
|
|
4
7
|
import {WebGPUDevice} from '../webgpu-device';
|
|
@@ -16,15 +19,17 @@ export class WebGPUComputePipeline extends ComputePipeline {
|
|
|
16
19
|
this.device = device;
|
|
17
20
|
|
|
18
21
|
const webgpuShader = this.props.cs as WebGPUShader;
|
|
19
|
-
this.handle =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
this.handle =
|
|
23
|
+
this.props.handle ||
|
|
24
|
+
this.device.handle.createComputePipeline({
|
|
25
|
+
label: this.props.id,
|
|
26
|
+
compute: {
|
|
27
|
+
module: webgpuShader.handle,
|
|
28
|
+
entryPoint: this.props.csEntryPoint
|
|
29
|
+
// constants: this.props.csConstants
|
|
30
|
+
},
|
|
31
|
+
layout: 'auto'
|
|
32
|
+
});
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
/** For internal use in render passes */
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
2
5
|
import {ExternalTexture, ExternalTextureProps, Sampler, SamplerProps} from '@luma.gl/core';
|
|
3
6
|
import type {WebGPUDevice} from '../webgpu-device';
|
|
4
7
|
import {WebGPUSampler} from './webgpu-sampler';
|
|
@@ -15,10 +18,12 @@ export class WebGPUExternalTexture extends ExternalTexture {
|
|
|
15
18
|
constructor(device: WebGPUDevice, props: ExternalTextureProps) {
|
|
16
19
|
super(device, props);
|
|
17
20
|
this.device = device;
|
|
18
|
-
this.handle =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
this.handle =
|
|
22
|
+
this.props.handle ||
|
|
23
|
+
this.device.handle.importExternalTexture({
|
|
24
|
+
source: props.source,
|
|
25
|
+
colorSpace: props.colorSpace
|
|
26
|
+
});
|
|
22
27
|
this.sampler = null;
|
|
23
28
|
}
|
|
24
29
|
|
|
@@ -31,7 +36,8 @@ export class WebGPUExternalTexture extends ExternalTexture {
|
|
|
31
36
|
/** Set default sampler */
|
|
32
37
|
setSampler(sampler: Sampler | SamplerProps): this {
|
|
33
38
|
// We can accept a sampler instance or set of props;
|
|
34
|
-
this.sampler =
|
|
39
|
+
this.sampler =
|
|
40
|
+
sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);
|
|
35
41
|
return this;
|
|
36
42
|
}
|
|
37
43
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {QuerySet, QuerySetProps} from '@luma.gl/core';
|
|
6
|
+
import {WebGPUDevice} from '../webgpu-device';
|
|
7
|
+
|
|
8
|
+
export type QuerySetProps2 = {
|
|
9
|
+
type: 'occlusion' | 'timestamp';
|
|
10
|
+
count: number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Immutable
|
|
15
|
+
*/
|
|
16
|
+
export class WebGPUQuerySet extends QuerySet {
|
|
17
|
+
readonly device: WebGPUDevice;
|
|
18
|
+
readonly handle: GPUQuerySet;
|
|
19
|
+
|
|
20
|
+
constructor(device: WebGPUDevice, props: QuerySetProps) {
|
|
21
|
+
super(device, props);
|
|
22
|
+
this.device = device;
|
|
23
|
+
this.handle =
|
|
24
|
+
this.props.handle ||
|
|
25
|
+
this.device.handle.createQuerySet({
|
|
26
|
+
type: this.props.type,
|
|
27
|
+
count: this.props.count
|
|
28
|
+
});
|
|
29
|
+
this.handle.label = this.props.id;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
override destroy(): void {
|
|
33
|
+
this.handle.destroy();
|
|
34
|
+
}
|
|
35
|
+
}
|