@luma.gl/core 9.2.0-alpha.1 → 9.2.0-alpha.5
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/canvas-context.d.ts +19 -5
- package/dist/adapter/canvas-context.d.ts.map +1 -1
- package/dist/adapter/canvas-context.js +53 -3
- package/dist/adapter/canvas-context.js.map +1 -1
- package/dist/adapter/device.d.ts +56 -11
- package/dist/adapter/device.d.ts.map +1 -1
- package/dist/adapter/device.js +78 -22
- package/dist/adapter/device.js.map +1 -1
- package/dist/adapter/luma.js +1 -1
- package/dist/adapter/resources/buffer.d.ts +13 -7
- package/dist/adapter/resources/buffer.d.ts.map +1 -1
- package/dist/adapter/resources/buffer.js +1 -5
- package/dist/adapter/resources/buffer.js.map +1 -1
- package/dist/adapter/resources/command-encoder.d.ts +0 -1
- package/dist/adapter/resources/command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/command-encoder.js.map +1 -1
- package/dist/adapter/resources/framebuffer.d.ts +3 -3
- package/dist/adapter/resources/framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/pipeline-layout.d.ts +13 -0
- package/dist/adapter/resources/pipeline-layout.d.ts.map +1 -0
- package/dist/adapter/resources/pipeline-layout.js +21 -0
- package/dist/adapter/resources/pipeline-layout.js.map +1 -0
- package/dist/adapter/resources/render-pipeline.d.ts +4 -4
- package/dist/adapter/resources/render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/resource.d.ts +1 -0
- package/dist/adapter/resources/resource.d.ts.map +1 -1
- package/dist/adapter/resources/resource.js.map +1 -1
- package/dist/adapter/resources/texture-view.d.ts +1 -1
- package/dist/adapter/resources/texture-view.d.ts.map +1 -1
- package/dist/adapter/resources/texture.d.ts +1 -1
- package/dist/adapter/resources/texture.d.ts.map +1 -1
- package/dist/adapter/resources/vertex-array.js +1 -1
- package/dist/adapter/resources/vertex-array.js.map +1 -1
- package/dist/adapter/types/attachments.d.ts +3 -3
- package/dist/adapter/types/attachments.d.ts.map +1 -1
- package/dist/adapter/types/buffer-layout.d.ts +1 -1
- package/dist/adapter/types/buffer-layout.d.ts.map +1 -1
- package/dist/adapter/types/parameters.d.ts +2 -2
- package/dist/adapter/types/parameters.d.ts.map +1 -1
- package/dist/adapter/types/shader-layout.d.ts +5 -6
- package/dist/adapter/types/shader-layout.d.ts.map +1 -1
- package/dist/adapter-utils/get-attribute-from-layouts.d.ts +3 -3
- package/dist/adapter-utils/get-attribute-from-layouts.d.ts.map +1 -1
- package/dist/adapter-utils/get-attribute-from-layouts.js +2 -2
- package/dist/adapter-utils/get-attribute-from-layouts.js.map +1 -1
- package/dist/dist.dev.js +430 -274
- package/dist/dist.min.js +5 -4
- package/dist/index.cjs +426 -273
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +18 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/portable/uniform-block.d.ts +1 -1
- package/dist/portable/uniform-block.d.ts.map +1 -1
- package/dist/portable/uniform-buffer-layout.d.ts +3 -3
- package/dist/portable/uniform-buffer-layout.d.ts.map +1 -1
- package/dist/portable/uniform-buffer-layout.js +8 -9
- package/dist/portable/uniform-buffer-layout.js.map +1 -1
- package/dist/portable/uniform-store.d.ts +2 -1
- package/dist/portable/uniform-store.d.ts.map +1 -1
- package/dist/portable/uniform-store.js +1 -1
- package/dist/portable/uniform-store.js.map +1 -1
- package/dist/shadertypes/{data-types.d.ts → data-types/data-types.d.ts} +4 -0
- package/dist/shadertypes/data-types/data-types.d.ts.map +1 -0
- package/dist/shadertypes/data-types/data-types.js.map +1 -0
- package/dist/shadertypes/{utils → data-types}/decode-data-types.d.ts +4 -4
- package/dist/shadertypes/data-types/decode-data-types.d.ts.map +1 -0
- package/dist/shadertypes/data-types/decode-data-types.js +74 -0
- package/dist/shadertypes/data-types/decode-data-types.js.map +1 -0
- package/dist/shadertypes/{utils → data-types}/decode-shader-types.d.ts +2 -2
- package/dist/shadertypes/data-types/decode-shader-types.d.ts.map +1 -0
- package/dist/shadertypes/data-types/decode-shader-types.js.map +1 -0
- package/dist/shadertypes/data-types/shader-types.d.ts.map +1 -0
- package/dist/shadertypes/data-types/shader-types.js.map +1 -0
- package/dist/shadertypes/textures/pixel-utils.d.ts +112 -0
- package/dist/shadertypes/textures/pixel-utils.d.ts.map +1 -0
- package/dist/shadertypes/textures/pixel-utils.js +193 -0
- package/dist/shadertypes/textures/pixel-utils.js.map +1 -0
- package/dist/shadertypes/textures/texture-format-decoder.d.ts +18 -0
- package/dist/shadertypes/textures/texture-format-decoder.d.ts.map +1 -0
- package/dist/shadertypes/{utils/decode-texture-format.js → textures/texture-format-decoder.js} +48 -35
- package/dist/shadertypes/textures/texture-format-decoder.js.map +1 -0
- package/dist/shadertypes/textures/texture-format-generics.d.ts +33 -0
- package/dist/shadertypes/textures/texture-format-generics.d.ts.map +1 -0
- package/dist/shadertypes/{texture-formats.js → textures/texture-format-generics.js} +1 -1
- package/dist/shadertypes/textures/texture-format-generics.js.map +1 -0
- package/dist/shadertypes/{utils → textures}/texture-format-table.d.ts +2 -1
- package/dist/shadertypes/textures/texture-format-table.d.ts.map +1 -0
- package/dist/shadertypes/{utils → textures}/texture-format-table.js +41 -42
- package/dist/shadertypes/textures/texture-format-table.js.map +1 -0
- package/dist/shadertypes/textures/texture-formats.d.ts +90 -0
- package/dist/shadertypes/textures/texture-formats.d.ts.map +1 -0
- package/dist/shadertypes/textures/texture-formats.js +58 -0
- package/dist/shadertypes/textures/texture-formats.js.map +1 -0
- package/dist/shadertypes/{utils → vertex-arrays}/decode-vertex-format.d.ts +2 -2
- package/dist/shadertypes/vertex-arrays/decode-vertex-format.d.ts.map +1 -0
- package/dist/shadertypes/{utils → vertex-arrays}/decode-vertex-format.js +4 -4
- package/dist/shadertypes/vertex-arrays/decode-vertex-format.js.map +1 -0
- package/dist/shadertypes/{vertex-formats.d.ts → vertex-arrays/vertex-formats.d.ts} +5 -3
- package/dist/shadertypes/vertex-arrays/vertex-formats.d.ts.map +1 -0
- package/dist/shadertypes/vertex-arrays/vertex-formats.js.map +1 -0
- package/package.json +2 -2
- package/src/adapter/canvas-context.ts +66 -8
- package/src/adapter/device.ts +132 -47
- package/src/adapter/resources/buffer.ts +30 -14
- package/src/adapter/resources/command-encoder.ts +0 -2
- package/src/adapter/resources/framebuffer.ts +5 -5
- package/src/adapter/resources/pipeline-layout.ts +30 -0
- package/src/adapter/resources/render-pipeline.ts +6 -6
- package/src/adapter/resources/resource.ts +1 -0
- package/src/adapter/resources/texture-view.ts +1 -1
- package/src/adapter/resources/texture.ts +1 -1
- package/src/adapter/resources/vertex-array.ts +1 -1
- package/src/adapter/types/attachments.ts +5 -5
- package/src/adapter/types/buffer-layout.ts +1 -1
- package/src/adapter/types/parameters.ts +2 -2
- package/src/adapter/types/shader-layout.ts +8 -5
- package/src/adapter-utils/get-attribute-from-layouts.ts +5 -5
- package/src/index.ts +60 -36
- package/src/portable/uniform-block.ts +1 -1
- package/src/portable/uniform-buffer-layout.ts +13 -12
- package/src/portable/uniform-store.ts +6 -2
- package/src/shadertypes/data-types/data-types.ts +96 -0
- package/src/shadertypes/data-types/decode-data-types.ts +91 -0
- package/src/shadertypes/{utils → data-types}/decode-shader-types.ts +2 -2
- package/src/shadertypes/textures/pixel-utils.ts +239 -0
- package/src/shadertypes/{utils/decode-texture-format.ts → textures/texture-format-decoder.ts} +63 -47
- package/src/shadertypes/textures/texture-format-generics.ts +190 -0
- package/src/shadertypes/{utils → textures}/texture-format-table.ts +62 -52
- package/src/shadertypes/{texture-formats.ts → textures/texture-formats.ts} +229 -147
- package/src/shadertypes/{utils → vertex-arrays}/decode-vertex-format.ts +6 -10
- package/src/shadertypes/{vertex-formats.ts → vertex-arrays/vertex-formats.ts} +20 -6
- package/dist/adapter-utils/buffer-layout-helper.d.ts +0 -11
- package/dist/adapter-utils/buffer-layout-helper.d.ts.map +0 -1
- package/dist/adapter-utils/buffer-layout-helper.js +0 -33
- package/dist/adapter-utils/buffer-layout-helper.js.map +0 -1
- package/dist/shadertypes/data-types.d.ts.map +0 -1
- package/dist/shadertypes/data-types.js.map +0 -1
- package/dist/shadertypes/shader-types.d.ts.map +0 -1
- package/dist/shadertypes/shader-types.js.map +0 -1
- package/dist/shadertypes/texture-formats.d.ts +0 -74
- package/dist/shadertypes/texture-formats.d.ts.map +0 -1
- package/dist/shadertypes/texture-formats.js.map +0 -1
- package/dist/shadertypes/utils/decode-data-types.d.ts.map +0 -1
- package/dist/shadertypes/utils/decode-data-types.js +0 -114
- package/dist/shadertypes/utils/decode-data-types.js.map +0 -1
- package/dist/shadertypes/utils/decode-shader-types.d.ts.map +0 -1
- package/dist/shadertypes/utils/decode-shader-types.js.map +0 -1
- package/dist/shadertypes/utils/decode-texture-format.d.ts +0 -15
- package/dist/shadertypes/utils/decode-texture-format.d.ts.map +0 -1
- package/dist/shadertypes/utils/decode-texture-format.js.map +0 -1
- package/dist/shadertypes/utils/decode-vertex-format.d.ts.map +0 -1
- package/dist/shadertypes/utils/decode-vertex-format.js.map +0 -1
- package/dist/shadertypes/utils/texture-format-table.d.ts.map +0 -1
- package/dist/shadertypes/utils/texture-format-table.js.map +0 -1
- package/dist/shadertypes/vertex-formats.d.ts.map +0 -1
- package/dist/shadertypes/vertex-formats.js.map +0 -1
- package/src/adapter-utils/buffer-layout-helper.ts +0 -41
- package/src/shadertypes/data-types.ts +0 -42
- package/src/shadertypes/utils/decode-data-types.ts +0 -131
- /package/dist/shadertypes/{data-types.js → data-types/data-types.js} +0 -0
- /package/dist/shadertypes/{utils → data-types}/decode-shader-types.js +0 -0
- /package/dist/shadertypes/{shader-types.d.ts → data-types/shader-types.d.ts} +0 -0
- /package/dist/shadertypes/{shader-types.js → data-types/shader-types.js} +0 -0
- /package/dist/shadertypes/{vertex-formats.js → vertex-arrays/vertex-formats.js} +0 -0
- /package/src/shadertypes/{shader-types.ts → data-types/shader-types.ts} +0 -0
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {log} from '../utils/log';
|
|
6
|
-
import type {PrimitiveDataType, NormalizedDataType} from '../shadertypes/data-types';
|
|
7
|
-
import type {AttributeShaderType} from '../shadertypes/shader-types';
|
|
8
|
-
import type {VertexFormat} from '../shadertypes/vertex-formats';
|
|
9
|
-
import {getAttributeShaderTypeInfo} from '../shadertypes/
|
|
6
|
+
import type {PrimitiveDataType, NormalizedDataType} from '../shadertypes/data-types/data-types';
|
|
7
|
+
import type {AttributeShaderType} from '../shadertypes/data-types/shader-types';
|
|
8
|
+
import type {VertexFormat} from '../shadertypes/vertex-arrays/vertex-formats';
|
|
9
|
+
import {getAttributeShaderTypeInfo} from '../shadertypes/data-types/decode-shader-types';
|
|
10
10
|
import {
|
|
11
11
|
getVertexFormatInfo,
|
|
12
12
|
getCompatibleVertexFormat
|
|
13
|
-
} from '../shadertypes/
|
|
13
|
+
} from '../shadertypes/vertex-arrays/decode-vertex-format';
|
|
14
14
|
import type {ShaderLayout, AttributeDeclaration} from '../adapter/types/shader-layout';
|
|
15
15
|
import type {BufferLayout} from '../adapter/types/buffer-layout';
|
|
16
16
|
|
package/src/index.ts
CHANGED
|
@@ -21,17 +21,13 @@ export type {CanvasContextProps} from './adapter/canvas-context';
|
|
|
21
21
|
export {CanvasContext} from './adapter/canvas-context';
|
|
22
22
|
|
|
23
23
|
// GPU RESOURCES
|
|
24
|
-
export type
|
|
25
|
-
export {Resource} from './adapter/resources/resource';
|
|
24
|
+
export {Resource, type ResourceProps} from './adapter/resources/resource';
|
|
26
25
|
|
|
27
|
-
export type
|
|
28
|
-
export {Buffer} from './adapter/resources/buffer';
|
|
26
|
+
export {Buffer, type BufferProps, type BufferMapCallback} from './adapter/resources/buffer';
|
|
29
27
|
|
|
30
|
-
export type
|
|
31
|
-
export {Texture} from './adapter/resources/texture';
|
|
28
|
+
export {Texture, type TextureProps} from './adapter/resources/texture';
|
|
32
29
|
|
|
33
|
-
export type
|
|
34
|
-
export {TextureView} from './adapter/resources/texture-view';
|
|
30
|
+
export {TextureView, type TextureViewProps} from './adapter/resources/texture-view';
|
|
35
31
|
|
|
36
32
|
export type {ExternalTextureProps} from './adapter/resources/external-texture';
|
|
37
33
|
export {ExternalTexture} from './adapter/resources/external-texture';
|
|
@@ -72,6 +68,9 @@ export {TransformFeedback} from './adapter/resources/transform-feedback';
|
|
|
72
68
|
export type {QuerySetProps} from './adapter/resources/query-set';
|
|
73
69
|
export {QuerySet} from './adapter/resources/query-set';
|
|
74
70
|
|
|
71
|
+
export type {PipelineLayoutProps} from './adapter/resources/pipeline-layout';
|
|
72
|
+
export {PipelineLayout} from './adapter/resources/pipeline-layout';
|
|
73
|
+
|
|
75
74
|
// PORTABLE API - UNIFORM BUFFERS
|
|
76
75
|
export {UniformBufferLayout} from './portable/uniform-buffer-layout';
|
|
77
76
|
export {UniformBlock} from './portable/uniform-block';
|
|
@@ -82,7 +81,11 @@ export {UniformStore} from './portable/uniform-store';
|
|
|
82
81
|
export type {CompilerMessage} from './adapter/types/compiler-message';
|
|
83
82
|
|
|
84
83
|
export type {ExternalImage} from './image-utils/image-types';
|
|
85
|
-
|
|
84
|
+
|
|
85
|
+
export {
|
|
86
|
+
type CopyExternalImageOptions,
|
|
87
|
+
type CopyImageDataOptions
|
|
88
|
+
} from './adapter/resources/texture';
|
|
86
89
|
|
|
87
90
|
export type {Parameters, PrimitiveTopology, IndexFormat} from './adapter/types/parameters';
|
|
88
91
|
|
|
@@ -110,7 +113,12 @@ export type {
|
|
|
110
113
|
ComputeShaderLayout,
|
|
111
114
|
AttributeDeclaration,
|
|
112
115
|
BindingDeclaration,
|
|
113
|
-
Binding
|
|
116
|
+
Binding,
|
|
117
|
+
UniformBufferBindingLayout,
|
|
118
|
+
StorageBufferBindingLayout,
|
|
119
|
+
TextureBindingLayout,
|
|
120
|
+
SamplerBindingLayout,
|
|
121
|
+
StorageTextureBindingLayout
|
|
114
122
|
} from './adapter/types/shader-layout';
|
|
115
123
|
export type {BufferLayout, BufferAttributeLayout} from './adapter/types/buffer-layout';
|
|
116
124
|
export type {
|
|
@@ -133,41 +141,58 @@ export type {
|
|
|
133
141
|
BigTypedArrayConstructor
|
|
134
142
|
} from './types';
|
|
135
143
|
|
|
136
|
-
// GPU TYPE UTILS -
|
|
137
|
-
|
|
138
|
-
export type {PrimitiveDataType, SignedDataType, NormalizedDataType} from './shadertypes/data-types';
|
|
139
|
-
export type {AttributeShaderType, VariableShaderType} from './shadertypes/shader-types';
|
|
140
|
-
export type {VertexFormat} from './shadertypes/vertex-formats';
|
|
141
|
-
export type {
|
|
142
|
-
TextureFormat,
|
|
143
|
-
ColorTextureFormat,
|
|
144
|
-
DepthStencilTextureFormat,
|
|
145
|
-
TextureCompression,
|
|
146
|
-
TextureFormatInfo,
|
|
147
|
-
TextureFormatCapabilities
|
|
148
|
-
} from './shadertypes/texture-formats';
|
|
149
|
-
|
|
150
|
-
// GPU TYPE UTILS - GPU MEMORY LAYOUT HELPERS - CAN BE USED BY APPS BUT MOSTLY USED INTERNALLY
|
|
144
|
+
// GPU TYPE UTILS - BASIC DATA TYPES
|
|
151
145
|
|
|
146
|
+
export {
|
|
147
|
+
type PrimitiveDataType,
|
|
148
|
+
type SignedDataType,
|
|
149
|
+
type NormalizedDataType,
|
|
150
|
+
type DataTypeInfo,
|
|
151
|
+
type DataTypeArray,
|
|
152
|
+
type NormalizedDataTypeArray
|
|
153
|
+
} from './shadertypes/data-types/data-types';
|
|
154
|
+
export {
|
|
155
|
+
type AttributeShaderType,
|
|
156
|
+
type VariableShaderType
|
|
157
|
+
} from './shadertypes/data-types/shader-types';
|
|
152
158
|
export {
|
|
153
159
|
getDataTypeInfo,
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
} from './shadertypes/
|
|
160
|
+
getDataType,
|
|
161
|
+
getTypedArrayConstructor,
|
|
162
|
+
getNormalizedDataType
|
|
163
|
+
} from './shadertypes/data-types/decode-data-types';
|
|
158
164
|
export {
|
|
159
165
|
getVariableShaderTypeInfo,
|
|
160
166
|
getAttributeShaderTypeInfo
|
|
161
|
-
} from './shadertypes/
|
|
167
|
+
} from './shadertypes/data-types/decode-shader-types';
|
|
168
|
+
|
|
169
|
+
// GPU TYPE UTILS - VERTEX ARRAYs
|
|
170
|
+
|
|
171
|
+
export {type VertexFormat} from './shadertypes/vertex-arrays/vertex-formats';
|
|
172
|
+
|
|
162
173
|
export {
|
|
163
174
|
getVertexFormatInfo,
|
|
164
175
|
getVertexFormatFromAttribute,
|
|
165
176
|
makeVertexFormat
|
|
166
|
-
} from './shadertypes/
|
|
177
|
+
} from './shadertypes/vertex-arrays/decode-vertex-format';
|
|
178
|
+
|
|
179
|
+
// GPU TYPE UTILS - Texture Formats
|
|
180
|
+
|
|
181
|
+
export {
|
|
182
|
+
type TextureFormat,
|
|
183
|
+
type TextureFormatColor,
|
|
184
|
+
type TextureFormatDepthStencil,
|
|
185
|
+
type TextureCompression,
|
|
186
|
+
type TextureFormatInfo,
|
|
187
|
+
type TextureFormatCapabilities
|
|
188
|
+
} from './shadertypes/textures/texture-formats';
|
|
189
|
+
|
|
167
190
|
export {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
} from './shadertypes/
|
|
191
|
+
TextureFormatDecoder,
|
|
192
|
+
textureFormatDecoder
|
|
193
|
+
} from './shadertypes/textures/texture-format-decoder';
|
|
194
|
+
|
|
195
|
+
export {type PixelData, readPixel, writePixel} from './shadertypes/textures/pixel-utils';
|
|
171
196
|
|
|
172
197
|
// GENERAL EXPORTS - FOR APPLICATIONS
|
|
173
198
|
|
|
@@ -186,11 +211,10 @@ export type {
|
|
|
186
211
|
export {log} from './utils/log';
|
|
187
212
|
export {getScratchArray} from './utils/array-utils-flat';
|
|
188
213
|
export type {AttributeInfo} from './adapter-utils/get-attribute-from-layouts';
|
|
189
|
-
export {BufferLayoutHelper as _BufferLayoutHelper} from './adapter-utils/buffer-layout-helper';
|
|
190
214
|
export {getAttributeInfosFromLayouts} from './adapter-utils/get-attribute-from-layouts';
|
|
191
215
|
|
|
192
216
|
// TEST EXPORTS
|
|
193
217
|
export {
|
|
194
218
|
getTextureFormatDefinition as _getTextureFormatDefinition,
|
|
195
219
|
getTextureFormatTable as _getTextureFormatTable
|
|
196
|
-
} from './shadertypes/
|
|
220
|
+
} from './shadertypes/textures/texture-format-table';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {VariableShaderType} from '../shadertypes/shader-types';
|
|
5
|
+
import type {VariableShaderType} from '../shadertypes/data-types/shader-types';
|
|
6
6
|
import type {UniformValue} from '../adapter/types/uniforms';
|
|
7
7
|
import {
|
|
8
8
|
ShaderLayout,
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {PrimitiveDataType} from '../shadertypes/data-types';
|
|
6
|
-
import type {VariableShaderType} from '../shadertypes/shader-types';
|
|
7
|
-
import {alignTo} from '../shadertypes/
|
|
8
|
-
import {getVariableShaderTypeInfo} from '../shadertypes/
|
|
5
|
+
import type {PrimitiveDataType} from '../shadertypes/data-types/data-types';
|
|
6
|
+
import type {VariableShaderType} from '../shadertypes/data-types/shader-types';
|
|
7
|
+
import {alignTo} from '../shadertypes/data-types/decode-data-types';
|
|
8
|
+
import {getVariableShaderTypeInfo} from '../shadertypes/data-types/decode-shader-types';
|
|
9
9
|
|
|
10
10
|
import type {UniformValue} from '../adapter/types/uniforms';
|
|
11
11
|
import {getScratchArrayBuffer} from '../utils/array-utils-flat';
|
|
@@ -29,14 +29,19 @@ export class UniformBufferLayout {
|
|
|
29
29
|
readonly byteLength: number;
|
|
30
30
|
|
|
31
31
|
/** Create a new UniformBufferLayout given a map of attributes. */
|
|
32
|
-
constructor(
|
|
32
|
+
constructor(
|
|
33
|
+
uniformTypes: Record<string, VariableShaderType>,
|
|
34
|
+
uniformSizes: Record<string, number> = {}
|
|
35
|
+
) {
|
|
33
36
|
/** number of 4 byte slots taken */
|
|
34
37
|
let size: number = 0;
|
|
35
38
|
|
|
36
39
|
// Add layout (type, size and offset) definitions for each uniform in the layout
|
|
37
40
|
for (const [key, uniformType] of Object.entries(uniformTypes)) {
|
|
38
41
|
const typeAndComponents = getVariableShaderTypeInfo(uniformType);
|
|
39
|
-
const {type, components
|
|
42
|
+
const {type, components} = typeAndComponents;
|
|
43
|
+
// Calculate total count for uniform arrays.
|
|
44
|
+
const count = components * (uniformSizes?.[key] ?? 1);
|
|
40
45
|
// First, align (bump) current offset to an even multiple of current object (1, 2, 4)
|
|
41
46
|
size = alignTo(size, count);
|
|
42
47
|
// Use the aligned size as the offset of the current uniform.
|
|
@@ -53,10 +58,8 @@ export class UniformBufferLayout {
|
|
|
53
58
|
|
|
54
59
|
/** Get the data for the complete buffer */
|
|
55
60
|
getData(uniformValues: Record<string, UniformValue>): Uint8Array {
|
|
56
|
-
const bufferSize = Math.max(this.byteLength, minBufferSize);
|
|
57
|
-
|
|
58
61
|
// Allocate three typed arrays pointing at same memory
|
|
59
|
-
const arrayBuffer = getScratchArrayBuffer(
|
|
62
|
+
const arrayBuffer = getScratchArrayBuffer(this.byteLength);
|
|
60
63
|
const typedArrays = {
|
|
61
64
|
i32: new Int32Array(arrayBuffer),
|
|
62
65
|
u32: new Uint32Array(arrayBuffer),
|
|
@@ -64,8 +67,6 @@ export class UniformBufferLayout {
|
|
|
64
67
|
// TODO not implemented
|
|
65
68
|
f16: new Uint16Array(arrayBuffer)
|
|
66
69
|
};
|
|
67
|
-
// TODO is this needed?
|
|
68
|
-
// typedArrays.i32.fill(0);
|
|
69
70
|
|
|
70
71
|
for (const [name, value] of Object.entries(uniformValues)) {
|
|
71
72
|
const uniformLayout = this.layout[name];
|
|
@@ -101,7 +102,7 @@ export class UniformBufferLayout {
|
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
|
|
104
|
-
return new Uint8Array(arrayBuffer);
|
|
105
|
+
return new Uint8Array(arrayBuffer, 0, this.byteLength);
|
|
105
106
|
}
|
|
106
107
|
|
|
107
108
|
/** Does this layout have a field with specified name */
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {VariableShaderType} from '../shadertypes/shader-types';
|
|
5
|
+
import type {VariableShaderType} from '../shadertypes/data-types/shader-types';
|
|
6
6
|
import type {UniformValue} from '../adapter/types/uniforms';
|
|
7
7
|
import type {Device} from '../adapter/device';
|
|
8
8
|
import {Buffer} from '../adapter/resources/buffer';
|
|
@@ -39,6 +39,7 @@ export class UniformStore<
|
|
|
39
39
|
keyof TPropGroups,
|
|
40
40
|
{
|
|
41
41
|
uniformTypes?: Record<string, VariableShaderType>;
|
|
42
|
+
uniformSizes?: Record<string, number>;
|
|
42
43
|
defaultProps?: Record<string, unknown>;
|
|
43
44
|
defaultUniforms?: Record<string, UniformValue>;
|
|
44
45
|
}
|
|
@@ -48,7 +49,10 @@ export class UniformStore<
|
|
|
48
49
|
const uniformBufferName = bufferName as keyof TPropGroups;
|
|
49
50
|
|
|
50
51
|
// Create a layout object to help us generate correctly formatted binary uniform buffers
|
|
51
|
-
const uniformBufferLayout = new UniformBufferLayout(
|
|
52
|
+
const uniformBufferLayout = new UniformBufferLayout(
|
|
53
|
+
block.uniformTypes ?? {},
|
|
54
|
+
block.uniformSizes ?? {}
|
|
55
|
+
);
|
|
52
56
|
this.uniformBufferLayouts.set(uniformBufferName, uniformBufferLayout);
|
|
53
57
|
|
|
54
58
|
// Create a Uniform block to store the uniforms for each buffer.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Primitive data types that shaders can perform calculations in and declare variables with.
|
|
7
|
+
* @note attribute inputs and texture samples can be populated from a different in-memory types, see below.
|
|
8
|
+
* @note `f16` requires the `f16` extension
|
|
9
|
+
*/
|
|
10
|
+
export type PrimitiveDataType = 'u32' | 'i32' | 'f32' | 'f16';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Signed data types describe signed and unsigned integers as well as floats of varying sizes
|
|
14
|
+
* @note These formats describe physical memory layouts in vertex and pixel formats, they are not used inside shaders
|
|
15
|
+
*/
|
|
16
|
+
export type SignedDataType =
|
|
17
|
+
| 'uint8'
|
|
18
|
+
| 'sint8'
|
|
19
|
+
| 'uint16'
|
|
20
|
+
| 'sint16'
|
|
21
|
+
| 'uint32'
|
|
22
|
+
| 'sint32'
|
|
23
|
+
| 'float16'
|
|
24
|
+
| 'float32';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Normalized data types describe signed and unsigned integers as well as floats of varying sizes together with normalization behavior
|
|
28
|
+
* @note These formats describe physical memory layouts in vertex and pixel formats, they are not used inside shaders
|
|
29
|
+
* @note Normalization means that these formats are converted into floats on read (shader must use f32 to process them)
|
|
30
|
+
* @note WebGPU does not support normalized 32 bit integer attributes: 'unorm32' | 'snorm32'
|
|
31
|
+
*/
|
|
32
|
+
export type NormalizedDataType = SignedDataType | 'unorm8' | 'snorm8' | 'unorm16' | 'snorm16';
|
|
33
|
+
|
|
34
|
+
/** Returns information about a signed or normalized DataType */
|
|
35
|
+
export type DataTypeInfo = {
|
|
36
|
+
signedType: SignedDataType;
|
|
37
|
+
primitiveType: PrimitiveDataType;
|
|
38
|
+
byteLength: 1 | 2 | 4;
|
|
39
|
+
normalized: boolean;
|
|
40
|
+
integer: boolean;
|
|
41
|
+
signed: boolean;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** Returns a typed array appropriate to hold the actual values of a data type (integers for normalized integers) */
|
|
45
|
+
export type DataTypeArray<T extends NormalizedDataType> = T extends 'uint8'
|
|
46
|
+
? Uint8Array
|
|
47
|
+
: T extends 'sint8'
|
|
48
|
+
? Int8Array
|
|
49
|
+
: T extends 'unorm8'
|
|
50
|
+
? Uint8Array
|
|
51
|
+
: T extends 'snorm8'
|
|
52
|
+
? Int8Array
|
|
53
|
+
: T extends 'uint16'
|
|
54
|
+
? Uint16Array
|
|
55
|
+
: T extends 'sint16'
|
|
56
|
+
? Int16Array
|
|
57
|
+
: T extends 'unorm16'
|
|
58
|
+
? Uint16Array
|
|
59
|
+
: T extends 'snorm16'
|
|
60
|
+
? Int16Array
|
|
61
|
+
: T extends 'uint32'
|
|
62
|
+
? Uint32Array
|
|
63
|
+
: T extends 'sint32'
|
|
64
|
+
? Int32Array
|
|
65
|
+
: T extends 'float16'
|
|
66
|
+
? Uint16Array
|
|
67
|
+
: T extends 'float32'
|
|
68
|
+
? Float32Array
|
|
69
|
+
: never;
|
|
70
|
+
|
|
71
|
+
/** Returns a type array appropriate to hold the logical values of a data type (floats for normalized integers) */
|
|
72
|
+
export type NormalizedDataTypeArray<T extends NormalizedDataType> = T extends 'uint8'
|
|
73
|
+
? Uint8Array
|
|
74
|
+
: T extends 'sint8'
|
|
75
|
+
? Int8Array
|
|
76
|
+
: T extends 'unorm8'
|
|
77
|
+
? Float32Array
|
|
78
|
+
: T extends 'snorm8'
|
|
79
|
+
? Float32Array
|
|
80
|
+
: T extends 'uint16'
|
|
81
|
+
? Uint16Array
|
|
82
|
+
: T extends 'sint16'
|
|
83
|
+
? Int16Array
|
|
84
|
+
: T extends 'unorm16'
|
|
85
|
+
? Uint16Array
|
|
86
|
+
: T extends 'snorm16'
|
|
87
|
+
? Int16Array
|
|
88
|
+
: T extends 'uint32'
|
|
89
|
+
? Uint32Array
|
|
90
|
+
: T extends 'sint32'
|
|
91
|
+
? Int32Array
|
|
92
|
+
: T extends 'float16'
|
|
93
|
+
? Float32Array
|
|
94
|
+
: T extends 'float32'
|
|
95
|
+
? Float32Array
|
|
96
|
+
: never;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {TypedArray, TypedArrayConstructor} from '../../types';
|
|
6
|
+
import {PrimitiveDataType, SignedDataType, NormalizedDataType, DataTypeInfo} from './data-types';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Gets info about a data type constant (signed or normalized)
|
|
10
|
+
* @returns underlying primitive / signed types, byte length, normalization, integer, signed flags
|
|
11
|
+
*/
|
|
12
|
+
export function getDataTypeInfo(type: NormalizedDataType): DataTypeInfo {
|
|
13
|
+
const [signedType, primitiveType, byteLength] = NORMALIZED_TYPE_MAP[type];
|
|
14
|
+
const normalized: boolean = type.includes('norm');
|
|
15
|
+
const integer: boolean = !normalized && !type.startsWith('float');
|
|
16
|
+
const signed: boolean = type.startsWith('s');
|
|
17
|
+
return {
|
|
18
|
+
signedType,
|
|
19
|
+
primitiveType,
|
|
20
|
+
byteLength,
|
|
21
|
+
normalized,
|
|
22
|
+
integer,
|
|
23
|
+
signed
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Build a vertex format from a signed data type and a component */
|
|
28
|
+
export function getNormalizedDataType(signedDataType: SignedDataType): NormalizedDataType {
|
|
29
|
+
const dataType: NormalizedDataType = signedDataType;
|
|
30
|
+
// prettier-ignore
|
|
31
|
+
switch (dataType) {
|
|
32
|
+
case 'uint8': return 'unorm8';
|
|
33
|
+
case 'sint8': return 'snorm8';
|
|
34
|
+
case 'uint16': return 'unorm16';
|
|
35
|
+
case 'sint16': return 'snorm16';
|
|
36
|
+
default: return dataType;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Align offset to 1, 2 or 4 elements (4, 8 or 16 bytes) */
|
|
41
|
+
export function alignTo(size: number, count: number): number {
|
|
42
|
+
// prettier-ignore
|
|
43
|
+
switch (count) {
|
|
44
|
+
case 1: return size; // Pad upwards to even multiple of 2
|
|
45
|
+
case 2: return size + (size % 2); // Pad upwards to even multiple of 2
|
|
46
|
+
default: return size + ((4 - (size % 4)) % 4); // Pad upwards to even multiple of 4
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Returns the VariableShaderType that corresponds to a typed array */
|
|
51
|
+
export function getDataType(arrayOrType: TypedArray | TypedArrayConstructor): SignedDataType {
|
|
52
|
+
const Constructor = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
|
|
53
|
+
if (Constructor === Uint8ClampedArray) {
|
|
54
|
+
return 'uint8';
|
|
55
|
+
}
|
|
56
|
+
const info = Object.values(NORMALIZED_TYPE_MAP).find(entry => Constructor === entry[4]);
|
|
57
|
+
if (!info) {
|
|
58
|
+
throw new Error(Constructor.name);
|
|
59
|
+
}
|
|
60
|
+
return info[0];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Returns the TypedArray that corresponds to a shader data type */
|
|
64
|
+
export function getTypedArrayConstructor(type: NormalizedDataType): TypedArrayConstructor {
|
|
65
|
+
const [, , , , Constructor] = NORMALIZED_TYPE_MAP[type];
|
|
66
|
+
return Constructor;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const NORMALIZED_TYPE_MAP: Record<
|
|
70
|
+
NormalizedDataType,
|
|
71
|
+
[
|
|
72
|
+
SignedDataType,
|
|
73
|
+
PrimitiveDataType,
|
|
74
|
+
bytes: 1 | 2 | 4,
|
|
75
|
+
normalized: boolean,
|
|
76
|
+
arrayConstructor: TypedArrayConstructor
|
|
77
|
+
]
|
|
78
|
+
> = {
|
|
79
|
+
uint8: ['uint8', 'u32', 1, false, Uint8Array],
|
|
80
|
+
sint8: ['sint8', 'i32', 1, false, Int8Array],
|
|
81
|
+
unorm8: ['uint8', 'f32', 1, true, Uint8Array],
|
|
82
|
+
snorm8: ['sint8', 'f32', 1, true, Int8Array],
|
|
83
|
+
uint16: ['uint16', 'u32', 2, false, Uint16Array],
|
|
84
|
+
sint16: ['sint16', 'i32', 2, false, Int16Array],
|
|
85
|
+
unorm16: ['uint16', 'u32', 2, true, Uint16Array],
|
|
86
|
+
snorm16: ['sint16', 'i32', 2, true, Int16Array],
|
|
87
|
+
float16: ['float16', 'f16', 2, false, Uint16Array],
|
|
88
|
+
float32: ['float32', 'f32', 4, false, Float32Array],
|
|
89
|
+
uint32: ['uint32', 'u32', 4, false, Uint32Array],
|
|
90
|
+
sint32: ['sint32', 'i32', 4, false, Int32Array]
|
|
91
|
+
};
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {PrimitiveDataType} from '
|
|
5
|
+
import {PrimitiveDataType} from './data-types';
|
|
6
6
|
import type {
|
|
7
7
|
VariableShaderType,
|
|
8
8
|
AttributeShaderType,
|
|
9
9
|
AttributeShaderTypeInfo,
|
|
10
10
|
VariableShaderTypeAlias,
|
|
11
11
|
AttributeShaderTypeAlias
|
|
12
|
-
} from '
|
|
12
|
+
} from './shader-types';
|
|
13
13
|
|
|
14
14
|
/** Split a uniform type string into type and components */
|
|
15
15
|
export function getVariableShaderTypeInfo(format: VariableShaderType): {
|