@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.
Files changed (120) hide show
  1. package/dist/adapter/helpers/accessor-to-format.js +102 -1
  2. package/dist/adapter/helpers/convert-texture-format.d.ts.map +1 -1
  3. package/dist/adapter/helpers/convert-texture-format.js +8 -5
  4. package/dist/adapter/helpers/generate-mipmaps.d.ts.map +1 -1
  5. package/dist/adapter/helpers/generate-mipmaps.js +85 -82
  6. package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
  7. package/dist/adapter/helpers/get-bind-group.js +57 -41
  8. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -1
  9. package/dist/adapter/helpers/get-vertex-buffer-layout.js +117 -80
  10. package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
  11. package/dist/adapter/helpers/webgpu-parameters.js +185 -125
  12. package/dist/adapter/resources/webgpu-buffer.d.ts +1 -1
  13. package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
  14. package/dist/adapter/resources/webgpu-buffer.js +117 -62
  15. package/dist/adapter/resources/webgpu-command-encoder.d.ts +7 -1
  16. package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
  17. package/dist/adapter/resources/webgpu-command-encoder.js +81 -49
  18. package/dist/adapter/resources/webgpu-compute-pass.d.ts +1 -1
  19. package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
  20. package/dist/adapter/resources/webgpu-compute-pass.js +71 -41
  21. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +1 -1
  22. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
  23. package/dist/adapter/resources/webgpu-compute-pipeline.js +28 -19
  24. package/dist/adapter/resources/webgpu-external-texture.d.ts +2 -2
  25. package/dist/adapter/resources/webgpu-external-texture.d.ts.map +1 -1
  26. package/dist/adapter/resources/webgpu-external-texture.js +33 -18
  27. package/dist/adapter/resources/webgpu-framebuffer.d.ts +1 -1
  28. package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
  29. package/dist/adapter/resources/webgpu-framebuffer.js +14 -7
  30. package/dist/adapter/resources/webgpu-query-set.d.ts +17 -0
  31. package/dist/adapter/resources/webgpu-query-set.d.ts.map +1 -0
  32. package/dist/adapter/resources/webgpu-query-set.js +25 -0
  33. package/dist/adapter/resources/webgpu-query.js +42 -1
  34. package/dist/adapter/resources/webgpu-render-pass.d.ts +4 -2
  35. package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
  36. package/dist/adapter/resources/webgpu-render-pass.js +133 -105
  37. package/dist/adapter/resources/webgpu-render-pipeline.d.ts +3 -4
  38. package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
  39. package/dist/adapter/resources/webgpu-render-pipeline.js +137 -80
  40. package/dist/adapter/resources/webgpu-sampler.d.ts +1 -1
  41. package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
  42. package/dist/adapter/resources/webgpu-sampler.js +18 -15
  43. package/dist/adapter/resources/webgpu-shader.d.ts +1 -1
  44. package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
  45. package/dist/adapter/resources/webgpu-shader.js +56 -45
  46. package/dist/adapter/resources/webgpu-texture-view.d.ts +20 -0
  47. package/dist/adapter/resources/webgpu-texture-view.d.ts.map +1 -0
  48. package/dist/adapter/resources/webgpu-texture-view.js +32 -0
  49. package/dist/adapter/resources/webgpu-texture.d.ts +5 -4
  50. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  51. package/dist/adapter/resources/webgpu-texture.js +130 -107
  52. package/dist/adapter/resources/webgpu-vertex-array.d.ts +7 -6
  53. package/dist/adapter/resources/webgpu-vertex-array.d.ts.map +1 -1
  54. package/dist/adapter/resources/webgpu-vertex-array.js +60 -39
  55. package/dist/adapter/webgpu-canvas-context.d.ts +3 -3
  56. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
  57. package/dist/adapter/webgpu-canvas-context.js +100 -67
  58. package/dist/adapter/webgpu-device.d.ts +24 -21
  59. package/dist/adapter/webgpu-device.d.ts.map +1 -1
  60. package/dist/adapter/webgpu-device.js +264 -220
  61. package/dist/adapter/webgpu-types.js +0 -2
  62. package/dist/dist.dev.js +782 -2222
  63. package/dist/glsl/glsllang.js +9 -6
  64. package/dist/index.cjs +279 -388
  65. package/dist/index.cjs.map +7 -0
  66. package/dist/index.d.ts +5 -5
  67. package/dist/index.d.ts.map +1 -1
  68. package/dist/index.js +5 -1
  69. package/dist.min.js +1 -22
  70. package/package.json +9 -7
  71. package/src/adapter/helpers/accessor-to-format.ts +5 -1
  72. package/src/adapter/helpers/convert-texture-format.ts +4 -1
  73. package/src/adapter/helpers/generate-mipmaps.ts +37 -26
  74. package/src/adapter/helpers/get-bind-group.ts +8 -2
  75. package/src/adapter/helpers/get-vertex-buffer-layout.ts +12 -4
  76. package/src/adapter/helpers/webgpu-parameters.ts +79 -15
  77. package/src/adapter/resources/webgpu-buffer.ts +21 -10
  78. package/src/adapter/resources/webgpu-command-encoder.ts +24 -9
  79. package/src/adapter/resources/webgpu-compute-pass.ts +26 -8
  80. package/src/adapter/resources/webgpu-compute-pipeline.ts +15 -10
  81. package/src/adapter/resources/webgpu-external-texture.ts +12 -6
  82. package/src/adapter/resources/webgpu-framebuffer.ts +4 -0
  83. package/src/adapter/resources/webgpu-query-set.ts +35 -0
  84. package/src/adapter/resources/webgpu-render-pass.ts +37 -14
  85. package/src/adapter/resources/webgpu-render-pipeline.ts +30 -41
  86. package/src/adapter/resources/webgpu-sampler.ts +1 -1
  87. package/src/adapter/resources/webgpu-shader.ts +5 -4
  88. package/src/adapter/resources/webgpu-texture-view.ts +43 -0
  89. package/src/adapter/resources/webgpu-texture.ts +23 -19
  90. package/src/adapter/resources/webgpu-vertex-array.ts +25 -17
  91. package/src/adapter/webgpu-canvas-context.ts +8 -3
  92. package/src/adapter/webgpu-device.ts +100 -88
  93. package/src/index.ts +2 -1
  94. package/dist/adapter/helpers/accessor-to-format.js.map +0 -1
  95. package/dist/adapter/helpers/convert-texture-format.js.map +0 -1
  96. package/dist/adapter/helpers/generate-mipmaps.js.map +0 -1
  97. package/dist/adapter/helpers/get-bind-group.js.map +0 -1
  98. package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +0 -1
  99. package/dist/adapter/helpers/webgpu-parameters.js.map +0 -1
  100. package/dist/adapter/resources/webgpu-buffer.js.map +0 -1
  101. package/dist/adapter/resources/webgpu-command-encoder.js.map +0 -1
  102. package/dist/adapter/resources/webgpu-compute-pass.js.map +0 -1
  103. package/dist/adapter/resources/webgpu-compute-pipeline.js.map +0 -1
  104. package/dist/adapter/resources/webgpu-external-texture.js.map +0 -1
  105. package/dist/adapter/resources/webgpu-framebuffer.js.map +0 -1
  106. package/dist/adapter/resources/webgpu-query.js.map +0 -1
  107. package/dist/adapter/resources/webgpu-render-pass.js.map +0 -1
  108. package/dist/adapter/resources/webgpu-render-pipeline.js.map +0 -1
  109. package/dist/adapter/resources/webgpu-sampler.js.map +0 -1
  110. package/dist/adapter/resources/webgpu-shader.js.map +0 -1
  111. package/dist/adapter/resources/webgpu-texture.js.map +0 -1
  112. package/dist/adapter/resources/webgpu-vertex-array.js.map +0 -1
  113. package/dist/adapter/webgpu-canvas-context.js.map +0 -1
  114. package/dist/adapter/webgpu-device.js.map +0 -1
  115. package/dist/adapter/webgpu-types.js.map +0 -1
  116. package/dist/glsl/glsllang.js.map +0 -1
  117. package/dist/index.js.map +0 -1
  118. package/src/adapter/resources/webgpu-query.ts +0 -43
  119. package/src/adapter/webgpu-types.ts +0 -0
  120. package/src/glsl/glsllang.ts +0 -14
@@ -1,4 +1,7 @@
1
- // luma.gl, MIT license
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({ minFilter: 'linear' });
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
- format: 'rgba8unorm',
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 = Math.floor(Math.log2(Math.max(imageBitmap.width, imageBitmap.height))) + 1;
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({ imageBitmap }, { texture }, textureSize);
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
- attachment: texture.createView({
77
- baseMipLevel: i,
78
- mipLevelCount: 1
79
- }),
80
- loadValue: { r: 1.0, g: 0.0, b: 0.0, a: 0.0 },
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
- binding: 0,
88
- resource: this.mipmapSampler,
89
- }, {
90
- binding: 1,
91
- resource: texture.createView({
92
- baseMipLevel: i - 1,
93
- mipLevelCount: 1
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, MIT license
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(binding => binding.name === bindingName || `${binding.name}uniforms` === bindingName.toLocaleLowerCase());
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, MIT license
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 = attributeLayout.stepMode || (attributeLayout.name.startsWith('instance') ? 'instance' : 'vertex');
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 = attributeLayout.stepMode || (attributeLayout.name.startsWith('instance') ? 'instance' : 'vertex');
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: attribute.stepMode || (attribute.name.startsWith('instance') ? 'instance' : 'vertex'),
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: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {
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: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {
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: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {
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: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {
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: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {
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: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {
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: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {
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: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {
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: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {
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: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {
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: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {
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: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {
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: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {
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: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {
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: (parameter: keyof Parameters, value: any, descriptor: GPURenderPipelineDescriptor) => {
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
- // WEBGPU Buffer implementation
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 = this.props.handle || this.device.handle.createBuffer({
25
- size,
26
- // usage defaults to vertex
27
- usage: this.props.usage || (GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST),
28
- mappedAtCreation: this.props.mappedAtCreation || mapBuffer,
29
- label: this.props.id
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(byteOffset: number = 0, byteLength: number = this.byteLength): Promise<Uint8Array> {
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, {usage: Buffer.MAP_READ | Buffer.COPY_DST, byteLength});
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
- // writeTimestamp(querySet: Query, queryIndex: number): void {}
124
-
125
- // resolveQuerySet(options: {
126
- // querySet: GPUQuerySet,
127
- // firstQuery: number,
128
- // queryCount: number,
129
- // destination: Buffer,
130
- // destinationOffset?: number;
131
- // }): void;
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
- this.handle = this.props.handle || device.commandEncoder?.beginComputePass({
17
- label: this.props.id,
18
- // timestampWrites?: GPUComputePassTimestampWrites;
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
- // prettier-ignore
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 = this.props.handle || this.device.handle.createComputePipeline({
20
- label: this.props.id,
21
- compute: {
22
- module: webgpuShader.handle,
23
- entryPoint: this.props.csEntryPoint,
24
- // constants: this.props.csConstants
25
- },
26
- layout: 'auto'
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, MIT license
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 = this.props.handle || this.device.handle.importExternalTexture({
19
- source: props.source,
20
- colorSpace: props.colorSpace
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 = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);
39
+ this.sampler =
40
+ sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);
35
41
  return this;
36
42
  }
37
43
  }
@@ -1,3 +1,7 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
1
5
  import type {FramebufferProps} from '@luma.gl/core';
2
6
  import {Framebuffer} from '@luma.gl/core';
3
7
  import {WebGPUDevice} from '../webgpu-device';
@@ -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
+ }