@luma.gl/core 9.2.6 → 9.3.0-alpha.11

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 (282) hide show
  1. package/dist/adapter/canvas-context.d.ts +6 -162
  2. package/dist/adapter/canvas-context.d.ts.map +1 -1
  3. package/dist/adapter/canvas-context.js +5 -419
  4. package/dist/adapter/canvas-context.js.map +1 -1
  5. package/dist/adapter/canvas-observer.d.ts +32 -0
  6. package/dist/adapter/canvas-observer.d.ts.map +1 -0
  7. package/dist/adapter/canvas-observer.js +90 -0
  8. package/dist/adapter/canvas-observer.js.map +1 -0
  9. package/dist/adapter/canvas-surface.d.ts +150 -0
  10. package/dist/adapter/canvas-surface.d.ts.map +1 -0
  11. package/dist/adapter/canvas-surface.js +392 -0
  12. package/dist/adapter/canvas-surface.js.map +1 -0
  13. package/dist/adapter/device.d.ts +81 -16
  14. package/dist/adapter/device.d.ts.map +1 -1
  15. package/dist/adapter/device.js +193 -11
  16. package/dist/adapter/device.js.map +1 -1
  17. package/dist/adapter/luma.d.ts.map +1 -1
  18. package/dist/adapter/luma.js +2 -1
  19. package/dist/adapter/luma.js.map +1 -1
  20. package/dist/adapter/presentation-context.d.ts +11 -0
  21. package/dist/adapter/presentation-context.d.ts.map +1 -0
  22. package/dist/adapter/presentation-context.js +12 -0
  23. package/dist/adapter/presentation-context.js.map +1 -0
  24. package/dist/adapter/resources/buffer.d.ts +1 -1
  25. package/dist/adapter/resources/buffer.d.ts.map +1 -1
  26. package/dist/adapter/resources/buffer.js +14 -6
  27. package/dist/adapter/resources/buffer.js.map +1 -1
  28. package/dist/adapter/resources/command-buffer.d.ts +3 -1
  29. package/dist/adapter/resources/command-buffer.d.ts.map +1 -1
  30. package/dist/adapter/resources/command-buffer.js +3 -1
  31. package/dist/adapter/resources/command-buffer.js.map +1 -1
  32. package/dist/adapter/resources/command-encoder.d.ts +30 -7
  33. package/dist/adapter/resources/command-encoder.d.ts.map +1 -1
  34. package/dist/adapter/resources/command-encoder.js +68 -2
  35. package/dist/adapter/resources/command-encoder.js.map +1 -1
  36. package/dist/adapter/resources/compute-pipeline.d.ts +2 -2
  37. package/dist/adapter/resources/compute-pipeline.d.ts.map +1 -1
  38. package/dist/adapter/resources/fence.d.ts +16 -0
  39. package/dist/adapter/resources/fence.d.ts.map +1 -0
  40. package/dist/adapter/resources/fence.js +17 -0
  41. package/dist/adapter/resources/fence.js.map +1 -0
  42. package/dist/adapter/resources/framebuffer.d.ts +1 -1
  43. package/dist/adapter/resources/framebuffer.d.ts.map +1 -1
  44. package/dist/adapter/resources/framebuffer.js +15 -12
  45. package/dist/adapter/resources/framebuffer.js.map +1 -1
  46. package/dist/adapter/resources/query-set.d.ts +17 -1
  47. package/dist/adapter/resources/query-set.d.ts.map +1 -1
  48. package/dist/adapter/resources/query-set.js.map +1 -1
  49. package/dist/adapter/resources/render-pipeline.d.ts +28 -10
  50. package/dist/adapter/resources/render-pipeline.d.ts.map +1 -1
  51. package/dist/adapter/resources/render-pipeline.js +21 -2
  52. package/dist/adapter/resources/render-pipeline.js.map +1 -1
  53. package/dist/adapter/resources/resource.d.ts +13 -0
  54. package/dist/adapter/resources/resource.d.ts.map +1 -1
  55. package/dist/adapter/resources/resource.js +243 -14
  56. package/dist/adapter/resources/resource.js.map +1 -1
  57. package/dist/adapter/resources/shader.js +27 -25
  58. package/dist/adapter/resources/shader.js.map +1 -1
  59. package/dist/adapter/resources/shared-render-pipeline.d.ts +22 -0
  60. package/dist/adapter/resources/shared-render-pipeline.d.ts.map +1 -0
  61. package/dist/adapter/resources/shared-render-pipeline.js +25 -0
  62. package/dist/adapter/resources/shared-render-pipeline.js.map +1 -0
  63. package/dist/adapter/resources/texture-view.d.ts +1 -1
  64. package/dist/adapter/resources/texture-view.d.ts.map +1 -1
  65. package/dist/adapter/resources/texture.d.ts +168 -28
  66. package/dist/adapter/resources/texture.d.ts.map +1 -1
  67. package/dist/adapter/resources/texture.js +284 -25
  68. package/dist/adapter/resources/texture.js.map +1 -1
  69. package/dist/adapter/types/attachments.d.ts +1 -1
  70. package/dist/adapter/types/attachments.d.ts.map +1 -1
  71. package/dist/adapter/types/buffer-layout.d.ts +1 -1
  72. package/dist/adapter/types/buffer-layout.d.ts.map +1 -1
  73. package/dist/adapter/types/parameters.d.ts +3 -1
  74. package/dist/adapter/types/parameters.d.ts.map +1 -1
  75. package/dist/adapter/types/parameters.js +1 -0
  76. package/dist/adapter/types/parameters.js.map +1 -1
  77. package/dist/adapter/types/shader-layout.d.ts +10 -6
  78. package/dist/adapter/types/shader-layout.d.ts.map +1 -1
  79. package/dist/adapter/types/uniforms.d.ts +6 -0
  80. package/dist/adapter/types/uniforms.d.ts.map +1 -1
  81. package/dist/adapter-utils/bind-groups.d.ts +9 -0
  82. package/dist/adapter-utils/bind-groups.d.ts.map +1 -0
  83. package/dist/adapter-utils/bind-groups.js +41 -0
  84. package/dist/adapter-utils/bind-groups.js.map +1 -0
  85. package/dist/adapter-utils/format-compiler-log.d.ts.map +1 -1
  86. package/dist/adapter-utils/format-compiler-log.js +23 -15
  87. package/dist/adapter-utils/format-compiler-log.js.map +1 -1
  88. package/dist/adapter-utils/get-attribute-from-layouts.d.ts +2 -2
  89. package/dist/adapter-utils/get-attribute-from-layouts.d.ts.map +1 -1
  90. package/dist/adapter-utils/get-attribute-from-layouts.js +6 -6
  91. package/dist/adapter-utils/get-attribute-from-layouts.js.map +1 -1
  92. package/dist/dist.dev.js +2734 -644
  93. package/dist/dist.min.js +10 -9
  94. package/dist/factories/bind-group-factory.d.ts +20 -0
  95. package/dist/factories/bind-group-factory.d.ts.map +1 -0
  96. package/dist/factories/bind-group-factory.js +88 -0
  97. package/dist/factories/bind-group-factory.js.map +1 -0
  98. package/dist/factories/core-module-state.d.ts +7 -0
  99. package/dist/factories/core-module-state.d.ts.map +1 -0
  100. package/dist/{shadertypes/data-types/shader-types.js → factories/core-module-state.js} +1 -1
  101. package/dist/factories/core-module-state.js.map +1 -0
  102. package/dist/factories/pipeline-factory.d.ts +54 -0
  103. package/dist/factories/pipeline-factory.d.ts.map +1 -0
  104. package/dist/factories/pipeline-factory.js +270 -0
  105. package/dist/factories/pipeline-factory.js.map +1 -0
  106. package/dist/factories/shader-factory.d.ts +20 -0
  107. package/dist/factories/shader-factory.d.ts.map +1 -0
  108. package/dist/factories/shader-factory.js +84 -0
  109. package/dist/factories/shader-factory.js.map +1 -0
  110. package/dist/index.cjs +2447 -534
  111. package/dist/index.cjs.map +4 -4
  112. package/dist/index.d.ts +30 -14
  113. package/dist/index.d.ts.map +1 -1
  114. package/dist/index.js +19 -7
  115. package/dist/index.js.map +1 -1
  116. package/dist/portable/shader-block-writer.d.ts +51 -0
  117. package/dist/portable/shader-block-writer.d.ts.map +1 -0
  118. package/dist/portable/shader-block-writer.js +185 -0
  119. package/dist/portable/shader-block-writer.js.map +1 -0
  120. package/dist/portable/uniform-block.d.ts +1 -1
  121. package/dist/portable/uniform-block.d.ts.map +1 -1
  122. package/dist/portable/uniform-store.d.ts +55 -24
  123. package/dist/portable/uniform-store.d.ts.map +1 -1
  124. package/dist/portable/uniform-store.js +73 -25
  125. package/dist/portable/uniform-store.js.map +1 -1
  126. package/dist/shadertypes/data-types/data-type-decoder.d.ts +20 -0
  127. package/dist/shadertypes/data-types/data-type-decoder.d.ts.map +1 -0
  128. package/dist/shadertypes/data-types/data-type-decoder.js +79 -0
  129. package/dist/shadertypes/data-types/data-type-decoder.js.map +1 -0
  130. package/dist/shadertypes/data-types/data-types.d.ts +31 -12
  131. package/dist/shadertypes/data-types/data-types.d.ts.map +1 -1
  132. package/dist/shadertypes/data-types/decode-data-types.d.ts.map +1 -1
  133. package/dist/shadertypes/data-types/decode-data-types.js +4 -3
  134. package/dist/shadertypes/data-types/decode-data-types.js.map +1 -1
  135. package/dist/{image-utils → shadertypes/image-types}/image-types.d.ts +0 -6
  136. package/dist/shadertypes/image-types/image-types.d.ts.map +1 -0
  137. package/dist/shadertypes/image-types/image-types.js.map +1 -0
  138. package/dist/shadertypes/shader-types/shader-block-layout.d.ts +72 -0
  139. package/dist/shadertypes/shader-types/shader-block-layout.d.ts.map +1 -0
  140. package/dist/shadertypes/shader-types/shader-block-layout.js +209 -0
  141. package/dist/shadertypes/shader-types/shader-block-layout.js.map +1 -0
  142. package/dist/shadertypes/shader-types/shader-type-decoder.d.ts +41 -0
  143. package/dist/shadertypes/shader-types/shader-type-decoder.d.ts.map +1 -0
  144. package/dist/shadertypes/{data-types/decode-shader-types.js → shader-types/shader-type-decoder.js} +43 -4
  145. package/dist/shadertypes/shader-types/shader-type-decoder.js.map +1 -0
  146. package/dist/shadertypes/shader-types/shader-types.d.ts +101 -0
  147. package/dist/shadertypes/shader-types/shader-types.d.ts.map +1 -0
  148. package/dist/shadertypes/shader-types/shader-types.js +30 -0
  149. package/dist/shadertypes/shader-types/shader-types.js.map +1 -0
  150. package/dist/shadertypes/texture-types/pixel-utils.d.ts.map +1 -0
  151. package/dist/shadertypes/{textures → texture-types}/pixel-utils.js +4 -4
  152. package/dist/shadertypes/texture-types/pixel-utils.js.map +1 -0
  153. package/dist/shadertypes/texture-types/texture-format-decoder.d.ts +36 -0
  154. package/dist/shadertypes/texture-types/texture-format-decoder.d.ts.map +1 -0
  155. package/dist/shadertypes/{textures → texture-types}/texture-format-decoder.js +110 -38
  156. package/dist/shadertypes/texture-types/texture-format-decoder.js.map +1 -0
  157. package/dist/shadertypes/texture-types/texture-format-generics.d.ts +34 -0
  158. package/dist/shadertypes/texture-types/texture-format-generics.d.ts.map +1 -0
  159. package/dist/shadertypes/texture-types/texture-format-generics.js.map +1 -0
  160. package/dist/shadertypes/texture-types/texture-format-table.d.ts.map +1 -0
  161. package/dist/shadertypes/{textures → texture-types}/texture-format-table.js +12 -11
  162. package/dist/shadertypes/texture-types/texture-format-table.js.map +1 -0
  163. package/dist/shadertypes/{textures → texture-types}/texture-formats.d.ts +51 -17
  164. package/dist/shadertypes/texture-types/texture-formats.d.ts.map +1 -0
  165. package/dist/shadertypes/{textures → texture-types}/texture-formats.js +1 -0
  166. package/dist/shadertypes/texture-types/texture-formats.js.map +1 -0
  167. package/dist/shadertypes/texture-types/texture-layout.d.ts +5 -0
  168. package/dist/shadertypes/texture-types/texture-layout.d.ts.map +1 -0
  169. package/dist/shadertypes/texture-types/texture-layout.js +41 -0
  170. package/dist/shadertypes/texture-types/texture-layout.js.map +1 -0
  171. package/dist/shadertypes/vertex-types/vertex-format-decoder.d.ts +24 -0
  172. package/dist/shadertypes/vertex-types/vertex-format-decoder.d.ts.map +1 -0
  173. package/dist/shadertypes/vertex-types/vertex-format-decoder.js +144 -0
  174. package/dist/shadertypes/vertex-types/vertex-format-decoder.js.map +1 -0
  175. package/dist/shadertypes/vertex-types/vertex-formats.d.ts +50 -0
  176. package/dist/shadertypes/vertex-types/vertex-formats.d.ts.map +1 -0
  177. package/dist/shadertypes/vertex-types/vertex-formats.js.map +1 -0
  178. package/dist/utils/array-equal.d.ts +1 -1
  179. package/dist/utils/array-equal.d.ts.map +1 -1
  180. package/dist/utils/array-equal.js +15 -9
  181. package/dist/utils/array-equal.js.map +1 -1
  182. package/dist/utils/assert.d.ts +5 -0
  183. package/dist/utils/assert.d.ts.map +1 -0
  184. package/dist/utils/assert.js +17 -0
  185. package/dist/utils/assert.js.map +1 -0
  186. package/dist/utils/stats-manager.d.ts.map +1 -1
  187. package/dist/utils/stats-manager.js +61 -1
  188. package/dist/utils/stats-manager.js.map +1 -1
  189. package/package.json +6 -6
  190. package/src/adapter/canvas-context.ts +7 -556
  191. package/src/adapter/canvas-observer.ts +130 -0
  192. package/src/adapter/canvas-surface.ts +521 -0
  193. package/src/adapter/device.ts +311 -25
  194. package/src/adapter/luma.ts +1 -0
  195. package/src/adapter/presentation-context.ts +16 -0
  196. package/src/adapter/resources/buffer.ts +13 -5
  197. package/src/adapter/resources/command-buffer.ts +4 -2
  198. package/src/adapter/resources/command-encoder.ts +101 -10
  199. package/src/adapter/resources/compute-pipeline.ts +2 -2
  200. package/src/adapter/resources/fence.ts +32 -0
  201. package/src/adapter/resources/framebuffer.ts +16 -13
  202. package/src/adapter/resources/query-set.ts +17 -1
  203. package/src/adapter/resources/render-pipeline.ts +52 -16
  204. package/src/adapter/resources/resource.ts +289 -14
  205. package/src/adapter/resources/shader.ts +28 -28
  206. package/src/adapter/resources/shared-render-pipeline.ts +40 -0
  207. package/src/adapter/resources/texture-view.ts +1 -1
  208. package/src/adapter/resources/texture.ts +427 -49
  209. package/src/adapter/types/attachments.ts +1 -1
  210. package/src/adapter/types/buffer-layout.ts +1 -1
  211. package/src/adapter/types/parameters.ts +4 -1
  212. package/src/adapter/types/shader-layout.ts +15 -9
  213. package/src/adapter/types/uniforms.ts +12 -0
  214. package/src/adapter-utils/bind-groups.ts +71 -0
  215. package/src/adapter-utils/format-compiler-log.ts +23 -15
  216. package/src/adapter-utils/get-attribute-from-layouts.ts +8 -11
  217. package/src/factories/bind-group-factory.ts +157 -0
  218. package/src/factories/core-module-state.ts +11 -0
  219. package/src/factories/pipeline-factory.ts +328 -0
  220. package/src/factories/shader-factory.ts +103 -0
  221. package/src/index.ts +70 -26
  222. package/src/portable/shader-block-writer.ts +254 -0
  223. package/src/portable/uniform-block.ts +1 -1
  224. package/src/portable/uniform-store.ts +98 -40
  225. package/src/shadertypes/data-types/data-type-decoder.ts +105 -0
  226. package/src/shadertypes/data-types/data-types.ts +100 -48
  227. package/src/shadertypes/data-types/decode-data-types.ts +4 -3
  228. package/src/{image-utils → shadertypes/image-types}/image-types.ts +0 -7
  229. package/src/shadertypes/shader-types/shader-block-layout.ts +340 -0
  230. package/src/shadertypes/{data-types/decode-shader-types.ts → shader-types/shader-type-decoder.ts} +88 -14
  231. package/src/shadertypes/shader-types/shader-types.ts +207 -0
  232. package/src/shadertypes/{textures → texture-types}/pixel-utils.ts +4 -4
  233. package/src/shadertypes/{textures → texture-types}/texture-format-decoder.ts +167 -46
  234. package/src/shadertypes/{textures → texture-types}/texture-format-generics.ts +42 -48
  235. package/src/shadertypes/{textures → texture-types}/texture-format-table.ts +12 -11
  236. package/src/shadertypes/{textures → texture-types}/texture-formats.ts +73 -17
  237. package/src/shadertypes/texture-types/texture-layout.ts +60 -0
  238. package/src/shadertypes/vertex-types/vertex-format-decoder.ts +175 -0
  239. package/src/shadertypes/vertex-types/vertex-formats.ts +196 -0
  240. package/src/utils/array-equal.ts +21 -9
  241. package/src/utils/assert.ts +18 -0
  242. package/src/utils/stats-manager.ts +76 -2
  243. package/dist/image-utils/image-types.d.ts.map +0 -1
  244. package/dist/image-utils/image-types.js.map +0 -1
  245. package/dist/portable/uniform-buffer-layout.d.ts +0 -28
  246. package/dist/portable/uniform-buffer-layout.d.ts.map +0 -1
  247. package/dist/portable/uniform-buffer-layout.js +0 -96
  248. package/dist/portable/uniform-buffer-layout.js.map +0 -1
  249. package/dist/shadertypes/data-types/decode-shader-types.d.ts +0 -17
  250. package/dist/shadertypes/data-types/decode-shader-types.d.ts.map +0 -1
  251. package/dist/shadertypes/data-types/decode-shader-types.js.map +0 -1
  252. package/dist/shadertypes/data-types/shader-types.d.ts +0 -45
  253. package/dist/shadertypes/data-types/shader-types.d.ts.map +0 -1
  254. package/dist/shadertypes/data-types/shader-types.js.map +0 -1
  255. package/dist/shadertypes/textures/pixel-utils.d.ts.map +0 -1
  256. package/dist/shadertypes/textures/pixel-utils.js.map +0 -1
  257. package/dist/shadertypes/textures/texture-format-decoder.d.ts +0 -18
  258. package/dist/shadertypes/textures/texture-format-decoder.d.ts.map +0 -1
  259. package/dist/shadertypes/textures/texture-format-decoder.js.map +0 -1
  260. package/dist/shadertypes/textures/texture-format-generics.d.ts +0 -33
  261. package/dist/shadertypes/textures/texture-format-generics.d.ts.map +0 -1
  262. package/dist/shadertypes/textures/texture-format-generics.js.map +0 -1
  263. package/dist/shadertypes/textures/texture-format-table.d.ts.map +0 -1
  264. package/dist/shadertypes/textures/texture-format-table.js.map +0 -1
  265. package/dist/shadertypes/textures/texture-formats.d.ts.map +0 -1
  266. package/dist/shadertypes/textures/texture-formats.js.map +0 -1
  267. package/dist/shadertypes/vertex-arrays/decode-vertex-format.d.ts +0 -18
  268. package/dist/shadertypes/vertex-arrays/decode-vertex-format.d.ts.map +0 -1
  269. package/dist/shadertypes/vertex-arrays/decode-vertex-format.js +0 -100
  270. package/dist/shadertypes/vertex-arrays/decode-vertex-format.js.map +0 -1
  271. package/dist/shadertypes/vertex-arrays/vertex-formats.d.ts +0 -27
  272. package/dist/shadertypes/vertex-arrays/vertex-formats.d.ts.map +0 -1
  273. package/dist/shadertypes/vertex-arrays/vertex-formats.js.map +0 -1
  274. package/src/portable/uniform-buffer-layout.ts +0 -118
  275. package/src/shadertypes/data-types/shader-types.ts +0 -87
  276. package/src/shadertypes/vertex-arrays/decode-vertex-format.ts +0 -124
  277. package/src/shadertypes/vertex-arrays/vertex-formats.ts +0 -91
  278. /package/dist/{image-utils → shadertypes/image-types}/image-types.js +0 -0
  279. /package/dist/shadertypes/{textures → texture-types}/pixel-utils.d.ts +0 -0
  280. /package/dist/shadertypes/{textures → texture-types}/texture-format-generics.js +0 -0
  281. /package/dist/shadertypes/{textures → texture-types}/texture-format-table.d.ts +0 -0
  282. /package/dist/shadertypes/{vertex-arrays → vertex-types}/vertex-formats.js +0 -0
@@ -2,29 +2,56 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {PrimitiveDataType} from './data-types';
6
- import type {
7
- VariableShaderType,
8
- AttributeShaderType,
9
- AttributeShaderTypeInfo,
10
- VariableShaderTypeAlias,
11
- AttributeShaderTypeAlias
5
+ import {type PrimitiveDataType} from '../data-types/data-types';
6
+ import {
7
+ type VariableShaderType,
8
+ type AttributeShaderType,
9
+ type VariableShaderTypeAlias,
10
+ type AttributeShaderTypeAlias
12
11
  } from './shader-types';
13
12
 
14
- /** Split a uniform type string into type and components */
15
- export function getVariableShaderTypeInfo(format: VariableShaderType): {
13
+ /** Information extracted from a VariableShaderType constant */
14
+ export type VariableShaderTypeInfo = {
16
15
  type: PrimitiveDataType;
17
16
  components: number;
18
- } {
19
- const decoded = UNIFORM_FORMATS[format];
17
+ };
18
+
19
+ /** Information extracted from a AttributeShaderType constant */
20
+ export type AttributeShaderTypeInfo = {
21
+ /** WGSL-style primitive data type, f32, i32, u32 */
22
+ primitiveType: PrimitiveDataType;
23
+ /** Whether this is a normalized integer (that must be used as float) */
24
+ components: 1 | 2 | 3 | 4;
25
+ /** Length in bytes of the data for one vertex */
26
+ byteLength?: number;
27
+ /** Whether this is for integer or float vert */
28
+ integer: boolean;
29
+ /** Whether this data type is signed */
30
+ signed: boolean;
31
+ };
32
+
33
+ /** Split a uniform type string into type and components */
34
+ export function getVariableShaderTypeInfo(
35
+ format: VariableShaderType | VariableShaderTypeAlias
36
+ ): VariableShaderTypeInfo {
37
+ const resolvedFormat = resolveVariableShaderTypeAlias(format);
38
+ const decoded = UNIFORM_FORMATS[resolvedFormat];
39
+ if (!decoded) {
40
+ throw new Error(`Unsupported variable shader type: ${format}`);
41
+ }
20
42
  return decoded;
21
43
  }
22
44
 
23
45
  /** Decodes a vertex type, returning byte length and flags (integer, signed, normalized) */
24
46
  export function getAttributeShaderTypeInfo(
25
- attributeType: AttributeShaderType
47
+ attributeType: AttributeShaderType | AttributeShaderTypeAlias
26
48
  ): AttributeShaderTypeInfo {
27
- const [primitiveType, components] = TYPE_INFO[attributeType];
49
+ const resolvedAttributeType = resolveAttributeShaderTypeAlias(attributeType);
50
+ const decoded = TYPE_INFO[resolvedAttributeType];
51
+ if (!decoded) {
52
+ throw new Error(`Unsupported attribute shader type: ${attributeType}`);
53
+ }
54
+ const [primitiveType, components] = decoded;
28
55
  const integer: boolean = primitiveType === 'i32' || primitiveType === 'u32';
29
56
  const signed: boolean = primitiveType !== 'u32';
30
57
 
@@ -38,6 +65,39 @@ export function getAttributeShaderTypeInfo(
38
65
  };
39
66
  }
40
67
 
68
+ export class ShaderTypeDecoder {
69
+ getVariableShaderTypeInfo(
70
+ format: VariableShaderType | VariableShaderTypeAlias
71
+ ): VariableShaderTypeInfo {
72
+ return getVariableShaderTypeInfo(format);
73
+ }
74
+
75
+ getAttributeShaderTypeInfo(
76
+ attributeType: AttributeShaderType | AttributeShaderTypeAlias
77
+ ): AttributeShaderTypeInfo {
78
+ return getAttributeShaderTypeInfo(attributeType);
79
+ }
80
+
81
+ makeShaderAttributeType(
82
+ primitiveType: PrimitiveDataType,
83
+ components: 1 | 2 | 3 | 4
84
+ ): AttributeShaderType {
85
+ return makeShaderAttributeType(primitiveType, components);
86
+ }
87
+
88
+ resolveAttributeShaderTypeAlias(
89
+ alias: AttributeShaderTypeAlias | AttributeShaderType
90
+ ): AttributeShaderType {
91
+ return resolveAttributeShaderTypeAlias(alias);
92
+ }
93
+
94
+ resolveVariableShaderTypeAlias(
95
+ alias: VariableShaderTypeAlias | VariableShaderType
96
+ ): VariableShaderType {
97
+ return resolveVariableShaderTypeAlias(alias);
98
+ }
99
+ }
100
+
41
101
  export function makeShaderAttributeType(
42
102
  primitiveType: PrimitiveDataType,
43
103
  components: 1 | 2 | 3 | 4
@@ -57,6 +117,9 @@ export function resolveVariableShaderTypeAlias(
57
117
  return WGSL_VARIABLE_TYPE_ALIAS_MAP[alias as VariableShaderTypeAlias] || alias;
58
118
  }
59
119
 
120
+ /** Decoder for luma.gl shader types */
121
+ export const shaderTypeDecoder = new ShaderTypeDecoder();
122
+
60
123
  // TABLES
61
124
 
62
125
  const PRIMITIVE_TYPE_SIZES: Record<PrimitiveDataType, 2 | 4> = {
@@ -168,7 +231,18 @@ export const WGSL_ATTRIBUTE_TYPE_ALIAS_MAP: Record<AttributeShaderTypeAlias, Att
168
231
 
169
232
  /** @todo These tables are quite big, consider parsing alias strings instead */
170
233
  export const WGSL_VARIABLE_TYPE_ALIAS_MAP: Record<VariableShaderTypeAlias, VariableShaderType> = {
171
- ...WGSL_ATTRIBUTE_TYPE_ALIAS_MAP,
234
+ vec2i: 'vec2<i32>',
235
+ vec3i: 'vec3<i32>',
236
+ vec4i: 'vec4<i32>',
237
+ vec2u: 'vec2<u32>',
238
+ vec3u: 'vec3<u32>',
239
+ vec4u: 'vec4<u32>',
240
+ vec2f: 'vec2<f32>',
241
+ vec3f: 'vec3<f32>',
242
+ vec4f: 'vec4<f32>',
243
+ vec2h: 'vec2<f16>',
244
+ vec3h: 'vec3<f16>',
245
+ vec4h: 'vec4<f16>',
172
246
  mat2x2f: 'mat2x2<f32>',
173
247
  mat2x3f: 'mat2x3<f32>',
174
248
  mat2x4f: 'mat2x4<f32>',
@@ -0,0 +1,207 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {PrimitiveDataType} from '../data-types/data-types';
6
+
7
+ /**
8
+ * @type the type of an attribute as defined in the shader source code.
9
+ * @note This is a subset of shader variable types
10
+ * @note Buffers with various `VertexFormat`s can be supplied for each type, GPU will convert them at runtime/
11
+ */
12
+ export type AttributeShaderType =
13
+ | 'i32'
14
+ | 'u32'
15
+ | 'f32'
16
+ | 'f16'
17
+ | `vec2<${PrimitiveDataType}>`
18
+ | `vec3<${PrimitiveDataType}>`
19
+ | `vec4<${PrimitiveDataType}>`;
20
+
21
+ /**
22
+ * @type Describes the type of a variable that can declared in shader source code.
23
+ * @note Uniforms can be declared using these types
24
+ * @note Uniforms can be of a wider range of types than attributes.
25
+ * @note to WebGL users: "bindings" (textures, samplers, and uniform buffers) are considered "bindings", not shader variables/uniforms
26
+ */
27
+ export type VariableShaderType =
28
+ | 'i32'
29
+ | 'u32'
30
+ | 'f32'
31
+ | 'f16'
32
+ | `vec2<${PrimitiveDataType}>`
33
+ | `vec3<${PrimitiveDataType}>`
34
+ | `vec4<${PrimitiveDataType}>`
35
+ | `mat2x2<${PrimitiveDataType}>`
36
+ | `mat2x3<${PrimitiveDataType}>`
37
+ | `mat2x4<${PrimitiveDataType}>`
38
+ | `mat3x2<${PrimitiveDataType}>`
39
+ | `mat3x3<${PrimitiveDataType}>`
40
+ | `mat3x4<${PrimitiveDataType}>`
41
+ | `mat4x2<${PrimitiveDataType}>`
42
+ | `mat4x3<${PrimitiveDataType}>`
43
+ | `mat4x4<${PrimitiveDataType}>`;
44
+
45
+ /** @type A composite shader type can include structs and arrays, recursively */
46
+ export type CompositeShaderType = VariableShaderType | StructShaderType | ArrayShaderType;
47
+
48
+ /** @type Represents a struct in WGSL */
49
+ export type StructShaderType = {
50
+ [memberName: string]: CompositeShaderType;
51
+ };
52
+
53
+ /** @type Represents an array in WGSL */
54
+ export type ArrayShaderType = readonly [type: CompositeShaderType, length: number];
55
+
56
+ // Alias types
57
+
58
+ /** @type Shorthand type aliases recognized by WGSL */
59
+ export type AttributeShaderTypeAlias = keyof AttributeShaderTypeAliasMap;
60
+
61
+ /** @note work around for lack of type narrowing in conditional generics */
62
+ // biome-ignore format: preserve layout
63
+ type AttributeShaderTypeAliasMap = {
64
+ vec2f: 'vec2<f32>';
65
+ vec3f: 'vec3<f32>';
66
+ vec4f: 'vec4<f32>';
67
+ vec2i: 'vec2<i32>';
68
+ vec3i: 'vec3<i32>';
69
+ vec4i: 'vec4<i32>';
70
+ vec2u: 'vec2<u32>';
71
+ vec3u: 'vec3<u32>';
72
+ vec4u: 'vec4<u32>';
73
+ vec2h: 'vec2<f16>';
74
+ vec3h: 'vec3<f16>';
75
+ vec4h: 'vec4<f16>';
76
+ };
77
+
78
+ /** @type Shorthand type aliases recognized by WGSL */
79
+ export type VariableShaderTypeAlias = keyof VariableShaderTypeAliasMap;
80
+
81
+ /** @note work around for lack of type narrowing in conditional generics */
82
+ // biome-ignore format: preserve layout
83
+ type VariableShaderTypeAliasMap = {
84
+ // Vector aliases
85
+ vec2f: 'vec2<f32>';
86
+ vec3f: 'vec3<f32>';
87
+ vec4f: 'vec4<f32>';
88
+ vec2i: 'vec2<i32>';
89
+ vec3i: 'vec3<i32>';
90
+ vec4i: 'vec4<i32>';
91
+ vec2u: 'vec2<u32>';
92
+ vec3u: 'vec3<u32>';
93
+ vec4u: 'vec4<u32>';
94
+ vec2h: 'vec2<f16>';
95
+ vec3h: 'vec3<f16>';
96
+ vec4h: 'vec4<f16>';
97
+
98
+ // Matrix aliases
99
+ mat2x2f: 'mat2x2<f32>';
100
+ mat2x3f: 'mat2x3<f32>';
101
+ mat2x4f: 'mat2x4<f32>';
102
+ mat3x2f: 'mat3x2<f32>';
103
+ mat3x3f: 'mat3x3<f32>';
104
+ mat3x4f: 'mat3x4<f32>';
105
+ mat4x2f: 'mat4x2<f32>';
106
+ mat4x3f: 'mat4x3<f32>';
107
+ mat4x4f: 'mat4x4<f32>';
108
+
109
+ mat2x2i: 'mat2x2<i32>';
110
+ mat2x3i: 'mat2x3<i32>';
111
+ mat2x4i: 'mat2x4<i32>';
112
+ mat3x2i: 'mat3x2<i32>';
113
+ mat3x3i: 'mat3x3<i32>';
114
+ mat3x4i: 'mat3x4<i32>';
115
+ mat4x2i: 'mat4x2<i32>';
116
+ mat4x3i: 'mat4x3<i32>';
117
+ mat4x4i: 'mat4x4<i32>';
118
+
119
+ mat2x2u: 'mat2x2<u32>';
120
+ mat2x3u: 'mat2x3<u32>';
121
+ mat2x4u: 'mat2x4<u32>';
122
+ mat3x2u: 'mat3x2<u32>';
123
+ mat3x3u: 'mat3x3<u32>';
124
+ mat3x4u: 'mat3x4<u32>';
125
+ mat4x2u: 'mat4x2<u32>';
126
+ mat4x3u: 'mat4x3<u32>';
127
+ mat4x4u: 'mat4x4<u32>';
128
+
129
+ mat2x2h: 'mat2x2<f16>';
130
+ mat2x3h: 'mat2x3<f16>';
131
+ mat2x4h: 'mat2x4<f16>';
132
+ mat3x2h: 'mat3x2<f16>';
133
+ mat3x3h: 'mat3x3<f16>';
134
+ mat3x4h: 'mat3x4<f16>';
135
+ mat4x2h: 'mat4x2<f16>';
136
+ mat4x3h: 'mat4x3<f16>';
137
+ mat4x4h: 'mat4x4<f16>';
138
+ };
139
+
140
+ // GENERICS
141
+
142
+ /** @type The unaliased type */
143
+ export type AttributeShaderTypeT<T extends AttributeShaderTypeAlias | AttributeShaderType> =
144
+ T extends AttributeShaderTypeAlias ? AttributeShaderTypeAliasMap[T] : T;
145
+
146
+ /** @type The unaliased type */
147
+ export type VariableShaderTypeT<T extends VariableShaderType | keyof VariableShaderTypeAliasMap> =
148
+ T extends VariableShaderTypeAlias ? VariableShaderTypeAliasMap[T] : T;
149
+
150
+ // HELPER TYPES
151
+
152
+ // biome-ignore format: preserve layout
153
+ type TypeOfAliasSuffix<T extends string> =
154
+ T extends 'f' ? 'f32' :
155
+ T extends 'i' ? 'i32' :
156
+ T extends 'u' ? 'u32' :
157
+ T extends 'h' ? 'f16' :
158
+ never;
159
+
160
+ // biome-ignore format: preserve layout
161
+ export type AttributeShaderTypeAliasT<T extends AttributeShaderTypeAlias> =
162
+ T extends `vec2${infer S}` ? `vec2<${TypeOfAliasSuffix<S>}>` :
163
+ T extends `vec3${infer S}` ? `vec3<${TypeOfAliasSuffix<S>}>` :
164
+ T extends `vec4${infer S}` ? `vec4<${TypeOfAliasSuffix<S>}>` :
165
+ never;
166
+
167
+ // biome-ignore format: preserve layout
168
+ export type VariableShaderTypeAliasT<T extends VariableShaderTypeAlias> =
169
+ T extends `vec2${infer S}` ? `vec2<${TypeOfAliasSuffix<S>}>` :
170
+ T extends `vec3${infer S}` ? `vec3<${TypeOfAliasSuffix<S>}>` :
171
+ T extends `vec4${infer S}` ? `vec4<${TypeOfAliasSuffix<S>}>` :
172
+ T extends `mat2x2${infer S}` ? `mat2x2<${TypeOfAliasSuffix<S>}>` :
173
+ T extends `mat2x3${infer S}` ? `mat2x3<${TypeOfAliasSuffix<S>}>` :
174
+ T extends `mat2x4${infer S}` ? `mat2x4<${TypeOfAliasSuffix<S>}>` :
175
+ T extends `mat3x2${infer S}` ? `mat3x2<${TypeOfAliasSuffix<S>}>` :
176
+ T extends `mat3x3${infer S}` ? `mat3x3<${TypeOfAliasSuffix<S>}>` :
177
+ T extends `mat3x4${infer S}` ? `mat3x4<${TypeOfAliasSuffix<S>}>` :
178
+ T extends `mat4x2${infer S}` ? `mat4x2<${TypeOfAliasSuffix<S>}>` :
179
+ T extends `mat4x3${infer S}` ? `mat4x3<${TypeOfAliasSuffix<S>}>` :
180
+ T extends `mat4x4${infer S}` ? `mat4x4<${TypeOfAliasSuffix<S>}>` :
181
+ never;
182
+
183
+ // : T extends `vec2<${infer S}>`
184
+ // ? `vec2<${S}>`
185
+ // : T extends `vec3<${infer S}>`
186
+ // ? `vec3<${S}>`
187
+ // : T extends `vec4<${infer S}>`
188
+ // ? `vec4<${S}>`
189
+ // : T extends `mat2x2<${infer S}>`
190
+ // ? `mat2x2<${S}>`
191
+ // : T extends `mat2x3<${infer S}>`
192
+ // ? `mat2x3<${S}>`
193
+ // : T extends `mat2x4<${infer S}>`
194
+ // ? `mat2x4<${S}>`
195
+ // : T extends `mat3x2<${infer S}>`
196
+ // ? `mat3x2<${S}>`
197
+ // : T extends `mat3x3<${infer S}>`
198
+ // ? `mat3x3<${S}>`
199
+ // : T extends `mat3x4<${infer S}>`
200
+ // ? `mat3x4<${S}>`
201
+ // : T extends `mat4x2<${infer S}>`
202
+ // ? `mat4x2<${S}>`
203
+ // : T extends `mat4x3<${infer S}>`
204
+ // ? `mat4x3<${S}>`
205
+ // : T extends `mat4x4<${infer S}>`
206
+ // ? `mat4x4<${S}>`
207
+ // : never;
@@ -77,7 +77,7 @@ export function readPixel(
77
77
 
78
78
  // Extract each of the four channels.
79
79
  for (let i = 0; i < 4; i++) {
80
- const bits = bitsPerChannel[i];
80
+ const bits = bitsPerChannel[i] ?? 0;
81
81
  // If a channel's bit width is zero or negative, consider it not present.
82
82
  if (bits <= 0) {
83
83
  channels.push(0);
@@ -88,7 +88,7 @@ export function readPixel(
88
88
  }
89
89
  }
90
90
 
91
- return [channels[0], channels[1], channels[2], channels[3]];
91
+ return [channels[0] ?? 0, channels[1] ?? 0, channels[2] ?? 0, channels[3] ?? 0];
92
92
  }
93
93
 
94
94
  /**
@@ -130,10 +130,10 @@ export function writePixel(
130
130
  ): void {
131
131
  let currentBitOffset = bitOffset;
132
132
  for (let channel = 0; channel < 4; channel++) {
133
- const bits = bitsPerChannel[channel];
133
+ const bits = bitsPerChannel[channel] ?? 0;
134
134
  // Clamp the channel value to the maximum allowed by the bit width.
135
135
  const maxValue = (1 << bits) - 1;
136
- const channelValue = pixel[channel] & maxValue;
136
+ const channelValue = (pixel[channel] ?? 0) & maxValue;
137
137
  writeBitsToDataView(dataView, currentBitOffset, bits, channelValue);
138
138
  currentBitOffset += bits;
139
139
  }
@@ -3,83 +3,149 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {NormalizedDataType} from '../data-types/data-types';
6
- import {getDataTypeInfo} from '../data-types/decode-data-types';
6
+ import {dataTypeDecoder} from '../data-types/data-type-decoder';
7
7
  import type {
8
8
  TextureFormat,
9
9
  TextureFormatCompressed,
10
10
  TextureFormatInfo,
11
11
  TextureFormatCapabilities,
12
- TextureFormatColor
12
+ TextureFormatColor,
13
+ TextureMemoryLayout,
14
+ TextureFormatDepthStencil
13
15
  } from './texture-formats';
14
16
  import {getTextureFormatDefinition} from './texture-format-table';
15
17
 
16
- // prettier-ignore
18
+ const RGB_FORMAT_REGEX = /^(r|rg|rgb|rgba|bgra)([0-9]*)([a-z]*)(-srgb)?(-webgl)?$/;
19
+ const COLOR_FORMAT_PREFIXES = ['rgb', 'rgba', 'bgra'];
20
+ const DEPTH_FORMAT_PREFIXES = ['depth', 'stencil'];
21
+ // biome-ignore format: preserve layout
17
22
  const COMPRESSED_TEXTURE_FORMAT_PREFIXES = [
18
23
  'bc1', 'bc2', 'bc3', 'bc4', 'bc5', 'bc6', 'bc7', 'etc1', 'etc2', 'eac', 'atc', 'astc', 'pvrtc'
19
24
  ];
20
25
 
21
- const RGB_FORMAT_REGEX = /^(r|rg|rgb|rgba|bgra)([0-9]*)([a-z]*)(-srgb)?(-webgl)?$/;
22
-
26
+ // HELPERS - MEMORY LAYOUT
27
+
28
+ /** Options to calculate a texture layout */
29
+ export type TextureMemoryLayoutOptions = {
30
+ /** Number of bytes per pixel */
31
+ format: TextureFormat;
32
+ /** Width of the texture in pixels */
33
+ width: number;
34
+ /** Height of the texture in pixels */
35
+ height: number;
36
+ /** Number of images in the texture */
37
+ depth: number;
38
+ /** Alignment of each row */
39
+ byteAlignment: number;
40
+ };
41
+
42
+ /** Class that helps applications work with texture formats */
23
43
  export class TextureFormatDecoder {
24
- /** Returns information about a texture format, e.g. attatchment type, components, byte length and flags (integer, signed, normalized) */
25
- getInfo(format: TextureFormat): TextureFormatInfo {
26
- return getTextureFormatInfo(format);
27
- }
28
-
29
44
  /** Checks if a texture format is color */
30
45
  isColor(format: TextureFormat): format is TextureFormatColor {
31
- return format.startsWith('rgba') || format.startsWith('bgra') || format.startsWith('rgb');
46
+ return COLOR_FORMAT_PREFIXES.some(prefix => format.startsWith(prefix));
32
47
  }
33
48
 
34
49
  /** Checks if a texture format is depth or stencil */
35
- isDepthStencil(format: TextureFormat): boolean {
36
- return format.startsWith('depth') || format.startsWith('stencil');
50
+ isDepthStencil(format: TextureFormat): format is TextureFormatDepthStencil {
51
+ return DEPTH_FORMAT_PREFIXES.some(prefix => format.startsWith(prefix));
37
52
  }
38
53
 
39
54
  /** Checks if a texture format is compressed */
40
55
  isCompressed(format: TextureFormat): format is TextureFormatCompressed {
41
- return COMPRESSED_TEXTURE_FORMAT_PREFIXES.some(prefix => (format as string).startsWith(prefix));
56
+ return COMPRESSED_TEXTURE_FORMAT_PREFIXES.some(prefix => format.startsWith(prefix));
42
57
  }
43
58
 
44
- /**
45
- * Returns the "static" capabilities of a texture format.
46
- * @note Needs to be checked against current device
47
- */
48
- getCapabilities(format: TextureFormat): TextureFormatCapabilities {
49
- const info = getTextureFormatDefinition(format);
50
-
51
- const formatCapabilities: Required<TextureFormatCapabilities> = {
52
- format,
53
- create: info.f ?? true,
54
- render: info.render ?? true,
55
- filter: info.filter ?? true,
56
- blend: info.blend ?? true,
57
- store: info.store ?? true
58
- };
59
-
60
- const formatInfo = getTextureFormatInfo(format);
61
- const isDepthStencil = format.startsWith('depth') || format.startsWith('stencil');
62
- const isSigned = formatInfo?.signed;
63
- const isInteger = formatInfo?.integer;
64
- const isWebGLSpecific = formatInfo?.webgl;
59
+ /** Returns information about a texture format, e.g. attachment type, components, byte length and flags (integer, signed, normalized) */
60
+ getInfo(format: TextureFormat): TextureFormatInfo {
61
+ return getTextureFormatInfo(format);
62
+ }
65
63
 
66
- // signed formats are not renderable
67
- formatCapabilities.render &&= !isSigned;
68
- // signed and integer formats are not filterable
69
- formatCapabilities.filter &&= !isDepthStencil && !isSigned && !isInteger && !isWebGLSpecific;
64
+ /** "static" capabilities of a texture format. @note Needs to be adjusted against current device */
65
+ getCapabilities(format: TextureFormat): TextureFormatCapabilities {
66
+ return getTextureFormatCapabilities(format);
67
+ }
70
68
 
71
- return formatCapabilities;
69
+ /** Computes the memory layout for a texture, in particular including row byte alignment */
70
+ computeMemoryLayout(opts: TextureMemoryLayoutOptions): TextureMemoryLayout {
71
+ return computeTextureMemoryLayout(opts);
72
72
  }
73
73
  }
74
74
 
75
+ /** Decoder for luma.gl texture types */
75
76
  export const textureFormatDecoder = new TextureFormatDecoder();
76
77
 
77
- // HELPERS
78
+ // HELPERS - MEMORY LAYOUT
79
+
80
+ /** Get the memory layout of a texture */
81
+ function computeTextureMemoryLayout({
82
+ format,
83
+ width,
84
+ height,
85
+ depth,
86
+ byteAlignment
87
+ }: TextureMemoryLayoutOptions): TextureMemoryLayout {
88
+ const formatInfo = textureFormatDecoder.getInfo(format);
89
+ const {
90
+ bytesPerPixel,
91
+ bytesPerBlock = bytesPerPixel,
92
+ blockWidth = 1,
93
+ blockHeight = 1,
94
+ compressed = false
95
+ } = formatInfo;
96
+ const blockColumns = compressed ? Math.ceil(width / blockWidth) : width;
97
+ const blockRows = compressed ? Math.ceil(height / blockHeight) : height;
98
+ // byteAlignment comes from the backend/call site. WebGPU buffer copies use 256, queue.writeTexture uses 1.
99
+ const unpaddedBytesPerRow = blockColumns * bytesPerBlock;
100
+ const bytesPerRow = Math.ceil(unpaddedBytesPerRow / byteAlignment) * byteAlignment;
101
+ const rowsPerImage = blockRows;
102
+ const byteLength = bytesPerRow * rowsPerImage * depth;
103
+
104
+ return {
105
+ bytesPerPixel,
106
+ bytesPerRow,
107
+ rowsPerImage,
108
+ depthOrArrayLayers: depth,
109
+ bytesPerImage: bytesPerRow * rowsPerImage,
110
+ byteLength
111
+ };
112
+ }
113
+
114
+ // HELPERS - CAPABILITIES
115
+
116
+ function getTextureFormatCapabilities(format: TextureFormat): TextureFormatCapabilities {
117
+ const info = getTextureFormatDefinition(format);
118
+
119
+ const formatCapabilities: Required<TextureFormatCapabilities> = {
120
+ format,
121
+ create: info.f ?? true,
122
+ render: info.render ?? true,
123
+ filter: info.filter ?? true,
124
+ blend: info.blend ?? true,
125
+ store: info.store ?? true
126
+ };
127
+
128
+ const formatInfo = getTextureFormatInfo(format);
129
+ const isDepthStencil = format.startsWith('depth') || format.startsWith('stencil');
130
+ const isSigned = formatInfo?.signed;
131
+ const isInteger = formatInfo?.integer;
132
+ const isWebGLSpecific = formatInfo?.webgl;
133
+ const isCompressed = Boolean(formatInfo?.compressed);
134
+
135
+ // Only uncompressed color formats can be used as color-renderable attachments.
136
+ formatCapabilities.render &&= !isDepthStencil && !isCompressed;
137
+ // signed and integer formats are not filterable
138
+ formatCapabilities.filter &&= !isDepthStencil && !isSigned && !isInteger && !isWebGLSpecific;
139
+
140
+ return formatCapabilities;
141
+ }
142
+
143
+ // HELPER - FORMAT INFO
78
144
 
79
145
  /**
80
146
  * Decodes a texture format, returning e.g. attatchment type, components, byte length and flags (integer, signed, normalized)
81
147
  */
82
- function getTextureFormatInfo(format: TextureFormat): TextureFormatInfo {
148
+ export function getTextureFormatInfo(format: TextureFormat): TextureFormatInfo {
83
149
  let formatInfo: TextureFormatInfo = getTextureFormatInfoUsingTable(format);
84
150
 
85
151
  if (textureFormatDecoder.isCompressed(format)) {
@@ -88,6 +154,7 @@ function getTextureFormatInfo(format: TextureFormat): TextureFormatInfo {
88
154
  formatInfo.bytesPerPixel = 1;
89
155
  formatInfo.srgb = false;
90
156
  formatInfo.compressed = true;
157
+ formatInfo.bytesPerBlock = getCompressedTextureBlockByteLength(format);
91
158
 
92
159
  const blockSize = getCompressedTextureBlockSize(format);
93
160
  if (blockSize) {
@@ -97,13 +164,13 @@ function getTextureFormatInfo(format: TextureFormat): TextureFormatInfo {
97
164
  }
98
165
 
99
166
  // Fill in missing information that can be derived from the format string
100
- const matches = RGB_FORMAT_REGEX.exec(format as string);
167
+ const matches = !formatInfo.packed ? RGB_FORMAT_REGEX.exec(format as string) : null;
101
168
  if (matches) {
102
169
  const [, channels, length, type, srgb, suffix] = matches;
103
170
  const dataType = `${type}${length}` as NormalizedDataType;
104
- const decodedType = getDataTypeInfo(dataType);
171
+ const decodedType = dataTypeDecoder.getDataTypeInfo(dataType);
105
172
  const bits = decodedType.byteLength * 8;
106
- const components = channels.length as 1 | 2 | 3 | 4;
173
+ const components = (channels?.length ?? 1) as 1 | 2 | 3 | 4;
107
174
  const bitsPerChannel: [number, number, number, number] = [
108
175
  bits,
109
176
  components >= 2 ? bits : 0,
@@ -121,7 +188,7 @@ function getTextureFormatInfo(format: TextureFormat): TextureFormatInfo {
121
188
  signed: decodedType.signed,
122
189
  normalized: decodedType.normalized,
123
190
  bitsPerChannel,
124
- bytesPerPixel: decodedType.byteLength * channels.length,
191
+ bytesPerPixel: decodedType.byteLength * components,
125
192
  packed: formatInfo.packed,
126
193
  srgb: formatInfo.srgb
127
194
  };
@@ -190,9 +257,63 @@ function getCompressedTextureBlockSize(
190
257
  const [, blockWidth, blockHeight] = matches;
191
258
  return {blockWidth: Number(blockWidth), blockHeight: Number(blockHeight)};
192
259
  }
260
+
261
+ if (
262
+ format.startsWith('bc') ||
263
+ format.startsWith('etc1') ||
264
+ format.startsWith('etc2') ||
265
+ format.startsWith('eac') ||
266
+ format.startsWith('atc')
267
+ ) {
268
+ return {blockWidth: 4, blockHeight: 4};
269
+ }
270
+
271
+ if (format.startsWith('pvrtc-rgb4') || format.startsWith('pvrtc-rgba4')) {
272
+ return {blockWidth: 4, blockHeight: 4};
273
+ }
274
+
275
+ if (format.startsWith('pvrtc-rgb2') || format.startsWith('pvrtc-rgba2')) {
276
+ return {blockWidth: 8, blockHeight: 4};
277
+ }
278
+
193
279
  return null;
194
280
  }
195
281
 
282
+ function getCompressedTextureBlockByteLength(format: TextureFormatCompressed): number {
283
+ if (
284
+ format.startsWith('bc1') ||
285
+ format.startsWith('bc4') ||
286
+ format.startsWith('etc1') ||
287
+ format.startsWith('etc2-rgb8') ||
288
+ format.startsWith('etc2-rgb8a1') ||
289
+ format.startsWith('eac-r11') ||
290
+ format === 'atc-rgb-unorm-webgl'
291
+ ) {
292
+ return 8;
293
+ }
294
+
295
+ if (
296
+ format.startsWith('bc2') ||
297
+ format.startsWith('bc3') ||
298
+ format.startsWith('bc5') ||
299
+ format.startsWith('bc6h') ||
300
+ format.startsWith('bc7') ||
301
+ format.startsWith('etc2-rgba8') ||
302
+ format.startsWith('eac-rg11') ||
303
+ format.startsWith('astc') ||
304
+ format === 'atc-rgba-unorm-webgl' ||
305
+ format === 'atc-rgbai-unorm-webgl'
306
+ ) {
307
+ return 16;
308
+ }
309
+
310
+ if (format.startsWith('pvrtc')) {
311
+ return 8;
312
+ }
313
+
314
+ return 16;
315
+ }
316
+
196
317
  /*
197
318
  'r8unorm': {s: "float"}, // ✓ ✓ ✓ },
198
319
  'r8snorm': {s: "float"}, // ✓ },