@luma.gl/shadertools 9.2.5 → 9.3.0-alpha.10

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 (174) hide show
  1. package/dist/dist.dev.js +4798 -6439
  2. package/dist/dist.min.js +2047 -311
  3. package/dist/index.cjs +3033 -507
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +12 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +5 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/lib/preprocessor/preprocessor.d.ts.map +1 -1
  10. package/dist/lib/preprocessor/preprocessor.js +35 -8
  11. package/dist/lib/preprocessor/preprocessor.js.map +1 -1
  12. package/dist/lib/shader-assembler.d.ts +10 -0
  13. package/dist/lib/shader-assembler.d.ts.map +1 -1
  14. package/dist/lib/shader-assembler.js +20 -3
  15. package/dist/lib/shader-assembler.js.map +1 -1
  16. package/dist/lib/shader-assembly/assemble-shaders.d.ts +23 -2
  17. package/dist/lib/shader-assembly/assemble-shaders.d.ts.map +1 -1
  18. package/dist/lib/shader-assembly/assemble-shaders.js +214 -11
  19. package/dist/lib/shader-assembly/assemble-shaders.js.map +1 -1
  20. package/dist/lib/shader-assembly/wgsl-binding-debug.d.ts +37 -0
  21. package/dist/lib/shader-assembly/wgsl-binding-debug.d.ts.map +1 -0
  22. package/dist/lib/shader-assembly/wgsl-binding-debug.js +140 -0
  23. package/dist/lib/shader-assembly/wgsl-binding-debug.js.map +1 -0
  24. package/dist/lib/shader-generator/glsl/generate-glsl.js +7 -4
  25. package/dist/lib/shader-generator/glsl/generate-glsl.js.map +1 -1
  26. package/dist/lib/shader-generator/wgsl/generate-wgsl.d.ts.map +1 -1
  27. package/dist/lib/shader-generator/wgsl/generate-wgsl.js +3 -0
  28. package/dist/lib/shader-generator/wgsl/generate-wgsl.js.map +1 -1
  29. package/dist/lib/shader-module/shader-module-uniform-layout.d.ts +91 -0
  30. package/dist/lib/shader-module/shader-module-uniform-layout.d.ts.map +1 -0
  31. package/dist/lib/shader-module/shader-module-uniform-layout.js +209 -0
  32. package/dist/lib/shader-module/shader-module-uniform-layout.js.map +1 -0
  33. package/dist/lib/shader-module/shader-module.d.ts +12 -6
  34. package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
  35. package/dist/lib/shader-module/shader-module.js.map +1 -1
  36. package/dist/lib/utils/assert.d.ts.map +1 -1
  37. package/dist/lib/utils/assert.js +3 -1
  38. package/dist/lib/utils/assert.js.map +1 -1
  39. package/dist/lib/utils/uniform-types.d.ts +11 -7
  40. package/dist/lib/utils/uniform-types.d.ts.map +1 -1
  41. package/dist/modules/engine/picking/picking.d.ts +5 -2
  42. package/dist/modules/engine/picking/picking.d.ts.map +1 -1
  43. package/dist/modules/engine/picking/picking.js +5 -2
  44. package/dist/modules/engine/picking/picking.js.map +1 -1
  45. package/dist/modules/engine/project/project.d.ts +1 -1
  46. package/dist/modules/engine/project/project.js +1 -1
  47. package/dist/modules/engine/skin/skin.d.ts +30 -0
  48. package/dist/modules/engine/skin/skin.d.ts.map +1 -0
  49. package/dist/modules/engine/skin/skin.js +86 -0
  50. package/dist/modules/engine/skin/skin.js.map +1 -0
  51. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +1 -0
  52. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
  53. package/dist/modules/lighting/gouraud-material/gouraud-material.js +3 -0
  54. package/dist/modules/lighting/gouraud-material/gouraud-material.js.map +1 -1
  55. package/dist/modules/lighting/ibl/ibl.d.ts +26 -0
  56. package/dist/modules/lighting/ibl/ibl.d.ts.map +1 -0
  57. package/dist/modules/lighting/ibl/ibl.js +33 -0
  58. package/dist/modules/lighting/ibl/ibl.js.map +1 -0
  59. package/dist/modules/lighting/lambert-material/lambert-material.d.ts +10 -0
  60. package/dist/modules/lighting/lambert-material/lambert-material.d.ts.map +1 -0
  61. package/dist/modules/lighting/lambert-material/lambert-material.js +33 -0
  62. package/dist/modules/lighting/lambert-material/lambert-material.js.map +1 -0
  63. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts +3 -0
  64. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts.map +1 -0
  65. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.js +60 -0
  66. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.js.map +1 -0
  67. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.d.ts +2 -0
  68. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.d.ts.map +1 -0
  69. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.js +73 -0
  70. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.js.map +1 -0
  71. package/dist/modules/lighting/lights/lighting-glsl.d.ts +1 -1
  72. package/dist/modules/lighting/lights/lighting-glsl.d.ts.map +1 -1
  73. package/dist/modules/lighting/lights/lighting-glsl.js +44 -38
  74. package/dist/modules/lighting/lights/lighting-glsl.js.map +1 -1
  75. package/dist/modules/lighting/lights/lighting-wgsl.d.ts +1 -1
  76. package/dist/modules/lighting/lights/lighting-wgsl.d.ts.map +1 -1
  77. package/dist/modules/lighting/lights/lighting-wgsl.js +46 -18
  78. package/dist/modules/lighting/lights/lighting-wgsl.js.map +1 -1
  79. package/dist/modules/lighting/lights/lighting.d.ts +104 -62
  80. package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
  81. package/dist/modules/lighting/lights/lighting.js +107 -68
  82. package/dist/modules/lighting/lights/lighting.js.map +1 -1
  83. package/dist/modules/lighting/no-material/dirlight.d.ts +8 -3
  84. package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
  85. package/dist/modules/lighting/no-material/dirlight.js +4 -2
  86. package/dist/modules/lighting/no-material/dirlight.js.map +1 -1
  87. package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts +1 -1
  88. package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts.map +1 -1
  89. package/dist/modules/lighting/pbr-material/pbr-material-glsl.js +581 -28
  90. package/dist/modules/lighting/pbr-material/pbr-material-glsl.js.map +1 -1
  91. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts +2 -2
  92. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts.map +1 -1
  93. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js +850 -107
  94. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -1
  95. package/dist/modules/lighting/pbr-material/pbr-material.d.ts +172 -41
  96. package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
  97. package/dist/modules/lighting/pbr-material/pbr-material.js +109 -1
  98. package/dist/modules/lighting/pbr-material/pbr-material.js.map +1 -1
  99. package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +1 -1
  100. package/dist/modules/lighting/pbr-material/pbr-projection.js +14 -2
  101. package/dist/modules/lighting/pbr-material/pbr-projection.js.map +1 -1
  102. package/dist/modules/lighting/pbr-material/pbr-scene.d.ts +40 -0
  103. package/dist/modules/lighting/pbr-material/pbr-scene.d.ts.map +1 -0
  104. package/dist/modules/lighting/pbr-material/pbr-scene.js +67 -0
  105. package/dist/modules/lighting/pbr-material/pbr-scene.js.map +1 -0
  106. package/dist/modules/lighting/phong-material/phong-material.d.ts +1 -0
  107. package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
  108. package/dist/modules/lighting/phong-material/phong-material.js +4 -0
  109. package/dist/modules/lighting/phong-material/phong-material.js.map +1 -1
  110. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +2 -2
  111. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
  112. package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +17 -6
  113. package/dist/modules/lighting/phong-material/phong-shaders-glsl.js.map +1 -1
  114. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts +1 -40
  115. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts.map +1 -1
  116. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js +71 -76
  117. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js.map +1 -1
  118. package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts +1 -1
  119. package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts.map +1 -1
  120. package/dist/modules/math/fp64/fp64-arithmetic-glsl.js +42 -11
  121. package/dist/modules/math/fp64/fp64-arithmetic-glsl.js.map +1 -1
  122. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts +2 -0
  123. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts.map +1 -0
  124. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js +212 -0
  125. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js.map +1 -0
  126. package/dist/modules/math/fp64/fp64.d.ts +1 -0
  127. package/dist/modules/math/fp64/fp64.d.ts.map +1 -1
  128. package/dist/modules/math/fp64/fp64.js +8 -2
  129. package/dist/modules/math/fp64/fp64.js.map +1 -1
  130. package/dist/modules/math/random/random.d.ts +1 -1
  131. package/dist/modules/math/random/random.d.ts.map +1 -1
  132. package/dist/modules/math/random/random.js +2 -3
  133. package/dist/modules/math/random/random.js.map +1 -1
  134. package/package.json +4 -5
  135. package/src/index.ts +37 -6
  136. package/src/lib/preprocessor/preprocessor.ts +44 -8
  137. package/src/lib/shader-assembler.ts +25 -3
  138. package/src/lib/shader-assembly/assemble-shaders.ts +384 -12
  139. package/src/lib/shader-assembly/wgsl-binding-debug.ts +216 -0
  140. package/src/lib/shader-generator/glsl/generate-glsl.ts +11 -5
  141. package/src/lib/shader-generator/wgsl/generate-wgsl.ts +6 -0
  142. package/src/lib/shader-module/shader-module-uniform-layout.ts +346 -0
  143. package/src/lib/shader-module/shader-module.ts +17 -7
  144. package/src/lib/utils/assert.ts +3 -1
  145. package/src/lib/utils/uniform-types.ts +24 -9
  146. package/src/modules/engine/picking/picking.ts +5 -2
  147. package/src/modules/engine/project/project.ts +1 -1
  148. package/src/modules/engine/skin/skin.ts +114 -0
  149. package/src/modules/lighting/gouraud-material/gouraud-material.ts +4 -0
  150. package/src/modules/lighting/ibl/ibl.ts +44 -0
  151. package/src/modules/lighting/lambert-material/lambert-material.ts +42 -0
  152. package/src/modules/lighting/lambert-material/lambert-shaders-glsl.ts +61 -0
  153. package/src/modules/lighting/lambert-material/lambert-shaders-wgsl.ts +73 -0
  154. package/src/modules/lighting/lights/lighting-glsl.ts +44 -38
  155. package/src/modules/lighting/lights/lighting-wgsl.ts +46 -18
  156. package/src/modules/lighting/lights/lighting.ts +198 -99
  157. package/src/modules/lighting/no-material/dirlight.ts +4 -2
  158. package/src/modules/lighting/pbr-material/pbr-material-glsl.ts +581 -28
  159. package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +850 -107
  160. package/src/modules/lighting/pbr-material/pbr-material.ts +185 -5
  161. package/src/modules/lighting/pbr-material/pbr-projection.ts +15 -2
  162. package/src/modules/lighting/pbr-material/pbr-scene.ts +91 -0
  163. package/src/modules/lighting/phong-material/phong-material.ts +5 -0
  164. package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +17 -6
  165. package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +71 -77
  166. package/src/modules/math/fp64/fp64-arithmetic-glsl.ts +42 -11
  167. package/src/modules/math/fp64/fp64-arithmetic-wgsl.ts +212 -0
  168. package/src/modules/math/fp64/fp64.ts +9 -3
  169. package/src/modules/math/random/random.ts +2 -3
  170. package/dist/lib/wgsl/get-shader-layout-wgsl.d.ts +0 -8
  171. package/dist/lib/wgsl/get-shader-layout-wgsl.d.ts.map +0 -1
  172. package/dist/lib/wgsl/get-shader-layout-wgsl.js +0 -95
  173. package/dist/lib/wgsl/get-shader-layout-wgsl.js.map +0 -1
  174. package/src/lib/wgsl/get-shader-layout-wgsl.ts +0 -105
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luma.gl/shadertools",
3
- "version": "9.2.5",
3
+ "version": "9.3.0-alpha.10",
4
4
  "description": "Shader module system for luma.gl",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -46,12 +46,11 @@
46
46
  "prepublishOnly": "npm run build-minified-bundle && npm run build-dev-bundle"
47
47
  },
48
48
  "peerDependencies": {
49
- "@luma.gl/core": "~9.2.0"
49
+ "@luma.gl/core": "9.3.0-alpha.6"
50
50
  },
51
51
  "dependencies": {
52
52
  "@math.gl/core": "^4.1.0",
53
- "@math.gl/types": "^4.1.0",
54
- "wgsl_reflect": "^1.2.0"
53
+ "@math.gl/types": "^4.1.0"
55
54
  },
56
- "gitHead": "a8efd26edd0c61c7bb29ea700c6c38f544f60326"
55
+ "gitHead": "ca3a841517106f8608ce392440fa7f324863a84f"
57
56
  }
package/src/index.ts CHANGED
@@ -9,17 +9,31 @@
9
9
  * Install https://marketplace.visualstudio.com/items?itemName=boyswan.glsl-literal
10
10
  */
11
11
  export type {PlatformInfo} from './lib/shader-assembly/platform-info';
12
+ export type {ShaderBindingDebugRow} from './lib/shader-assembly/wgsl-binding-debug';
12
13
 
13
14
  // ShaderModules
14
15
 
15
16
  export type {ShaderModule} from './lib/shader-module/shader-module';
16
17
  export type {ShaderPass} from './lib/shader-module/shader-pass';
17
- export type {UniformTypes} from './lib/utils/uniform-types';
18
+ export type {ShaderModuleUniformValue, UniformTypes} from './lib/utils/uniform-types';
18
19
 
19
20
  export {initializeShaderModule, initializeShaderModules} from './lib/shader-module/shader-module';
20
21
  export {getShaderModuleUniforms} from './lib/shader-module/shader-module';
21
22
  export {getShaderModuleDependencies} from './lib/shader-module/shader-module-dependencies';
22
23
  export {checkShaderModuleDeprecations} from './lib/shader-module/shader-module';
24
+ export type {
25
+ GLSLUniformBlockInfo,
26
+ ShaderModuleUniformLayoutStage,
27
+ ShaderModuleUniformLayoutValidationResult
28
+ } from './lib/shader-module/shader-module-uniform-layout';
29
+ export {
30
+ getGLSLUniformBlocks,
31
+ getShaderModuleUniformBlockFields,
32
+ getShaderModuleUniformBlockName,
33
+ getShaderModuleUniformLayoutValidationResult,
34
+ validateShaderModuleUniformLayout,
35
+ warnIfGLSLUniformBlocksAreNotStd140
36
+ } from './lib/shader-module/shader-module-uniform-layout';
23
37
 
24
38
  export {getShaderModuleSource} from './lib/shader-assembly/assemble-shaders';
25
39
 
@@ -53,9 +67,6 @@ export {preprocess} from './lib/preprocessor/preprocessor';
53
67
  export {assembleGLSLShaderPair} from './lib/shader-assembly/assemble-shaders';
54
68
  export {combineInjects} from './lib/shader-assembly/shader-injections';
55
69
 
56
- // EXPERIMENTAL WGSL
57
- export {getShaderLayoutFromWGSL} from './lib/wgsl/get-shader-layout-wgsl';
58
-
59
70
  // data utils
60
71
  export {toHalfFloat, fromHalfFloat} from './modules/math/fp16/fp16-utils';
61
72
  export {fp64ify, fp64LowPart, fp64ifyMatrix4} from './modules/math/fp64/fp64-utils';
@@ -68,16 +79,30 @@ export {fp64, fp64arithmetic} from './modules/math/fp64/fp64';
68
79
 
69
80
  // engine shader modules
70
81
 
71
- // // projection
82
+ // projection
72
83
  // export type {ProjectionUniforms} from './modules/engine/project/project';
73
84
  // export {projection} from './modules/engine/project/project';
74
85
  export type {PickingProps, PickingUniforms} from './modules/engine/picking/picking';
75
86
  export {picking} from './modules/engine/picking/picking';
87
+ export {skin} from './modules/engine/skin/skin';
88
+
89
+ // lighting
90
+ export {
91
+ type Light,
92
+ type AmbientLight,
93
+ type PointLight,
94
+ type SpotLight,
95
+ type DirectionalLight,
96
+ type LightingLightUniform
97
+ } from './modules/lighting/lights/lighting';
76
98
 
77
- // // lighting
78
99
  export type {LightingProps, LightingUniforms} from './modules/lighting/lights/lighting';
79
100
  export {lighting} from './modules/lighting/lights/lighting';
101
+ export type {IBLBindings} from './modules/lighting/ibl/ibl';
102
+ export {ibl} from './modules/lighting/ibl/ibl';
80
103
  export {dirlight} from './modules/lighting/no-material/dirlight';
104
+ export type {LambertMaterialProps} from './modules/lighting/lambert-material/lambert-material';
105
+ export {lambertMaterial} from './modules/lighting/lambert-material/lambert-material';
81
106
  export type {GouraudMaterialProps} from './modules/lighting/gouraud-material/gouraud-material';
82
107
  export {gouraudMaterial} from './modules/lighting/gouraud-material/gouraud-material';
83
108
  export type {PhongMaterialProps} from './modules/lighting/phong-material/phong-material';
@@ -87,6 +112,12 @@ export type {
87
112
  PBRMaterialProps,
88
113
  PBRMaterialUniforms
89
114
  } from './modules/lighting/pbr-material/pbr-material';
115
+ export type {
116
+ PBRSceneBindings,
117
+ PBRSceneProps,
118
+ PBRSceneUniforms
119
+ } from './modules/lighting/pbr-material/pbr-scene';
90
120
  export type {PBRProjectionProps} from './modules/lighting/pbr-material/pbr-projection';
91
121
 
92
122
  export {pbrMaterial} from './modules/lighting/pbr-material/pbr-material';
123
+ export {pbrScene} from './modules/lighting/pbr-material/pbr-scene';
@@ -2,8 +2,15 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- const IFDEF_REGEXP = /^\s*\#\s*ifdef\s*([a-zA-Z_]+)\s*$/;
5
+ const DEFINE_NAME_PATTERN = '([a-zA-Z_][a-zA-Z0-9_]*)';
6
+ const IFDEF_REGEXP = new RegExp(`^\\s*\\#\\s*ifdef\\s*${DEFINE_NAME_PATTERN}\\s*$`);
7
+ const IFNDEF_REGEXP = new RegExp(`^\\s*\\#\\s*ifndef\\s*${DEFINE_NAME_PATTERN}\\s*(?:\\/\\/.*)?$`);
8
+ const ELSE_REGEXP = /^\s*\#\s*else\s*(?:\/\/.*)?$/;
6
9
  const ENDIF_REGEXP = /^\s*\#\s*endif\s*$/;
10
+ const IFDEF_WITH_COMMENT_REGEXP = new RegExp(
11
+ `^\\s*\\#\\s*ifdef\\s*${DEFINE_NAME_PATTERN}\\s*(?:\\/\\/.*)?$`
12
+ );
13
+ const ENDIF_WITH_COMMENT_REGEXP = /^\s*\#\s*endif\s*(?:\/\/.*)?$/;
7
14
 
8
15
  export type PreprocessorOptions = {
9
16
  defines?: Record<string, boolean>;
@@ -13,19 +20,48 @@ export function preprocess(source: string, options?: PreprocessorOptions): strin
13
20
  const lines = source.split('\n');
14
21
  const output: string[] = [];
15
22
 
23
+ const conditionalStack: Array<{
24
+ parentActive: boolean;
25
+ branchTaken: boolean;
26
+ active: boolean;
27
+ }> = [];
16
28
  let conditional = true;
17
- let currentDefine: string | null = null;
29
+
18
30
  for (const line of lines) {
19
- const matchIf = line.match(IFDEF_REGEXP);
20
- const matchEnd = line.match(ENDIF_REGEXP);
21
- if (matchIf) {
22
- currentDefine = matchIf[1];
23
- conditional = Boolean(options?.defines?.[currentDefine]);
31
+ const matchIf = line.match(IFDEF_WITH_COMMENT_REGEXP) || line.match(IFDEF_REGEXP);
32
+ const matchIfNot = line.match(IFNDEF_REGEXP);
33
+ const matchElse = line.match(ELSE_REGEXP);
34
+ const matchEnd = line.match(ENDIF_WITH_COMMENT_REGEXP) || line.match(ENDIF_REGEXP);
35
+
36
+ if (matchIf || matchIfNot) {
37
+ const defineName = (matchIf || matchIfNot)?.[1];
38
+ const defineValue: boolean = Boolean(options?.defines?.[defineName!]);
39
+ const branchTaken: boolean = matchIf ? defineValue : !defineValue;
40
+ const active: boolean = conditional && branchTaken;
41
+ conditionalStack.push({parentActive: conditional, branchTaken, active});
42
+ conditional = active;
43
+ } else if (matchElse) {
44
+ const currentConditional = conditionalStack[conditionalStack.length - 1];
45
+ if (!currentConditional) {
46
+ throw new Error('Encountered #else without matching #ifdef or #ifndef');
47
+ }
48
+ currentConditional.active =
49
+ currentConditional.parentActive && !currentConditional.branchTaken;
50
+ currentConditional.branchTaken = true;
51
+ conditional = currentConditional.active;
24
52
  } else if (matchEnd) {
25
- conditional = true;
53
+ conditionalStack.pop();
54
+ conditional = conditionalStack.length
55
+ ? conditionalStack[conditionalStack.length - 1].active
56
+ : true;
26
57
  } else if (conditional) {
27
58
  output.push(line);
28
59
  }
29
60
  }
61
+
62
+ if (conditionalStack.length > 0) {
63
+ throw new Error('Unterminated conditional block in shader source');
64
+ }
65
+
30
66
  return output.join('\n');
31
67
  }
@@ -10,6 +10,10 @@ import {
10
10
  assembleWGSLShader,
11
11
  assembleGLSLShaderPair
12
12
  } from './shader-assembly/assemble-shaders';
13
+ import {
14
+ getShaderBindingDebugRowsFromWGSL,
15
+ type ShaderBindingDebugRow
16
+ } from './shader-assembly/wgsl-binding-debug';
13
17
  import {preprocess} from './preprocessor/preprocessor';
14
18
 
15
19
  /**
@@ -23,6 +27,8 @@ export class ShaderAssembler {
23
27
  private readonly _hookFunctions: any[] = [];
24
28
  /** Shader modules */
25
29
  private _defaultModules: ShaderModule[] = [];
30
+ /** Stable per-run WGSL auto-binding assignments keyed by group/module/binding. */
31
+ private readonly _wgslBindingRegistry = new Map<string, number>();
26
32
 
27
33
  /**
28
34
  * A default shader assembler instance - the natural place to register default modules and hooks
@@ -77,20 +83,36 @@ export class ShaderAssembler {
77
83
  source: string;
78
84
  getUniforms: GetUniformsFunc;
79
85
  modules: ShaderModule[];
86
+ bindingAssignments: {moduleName: string; name: string; group: number; location: number}[];
87
+ bindingTable: ShaderBindingDebugRow[];
80
88
  } {
81
89
  const modules = this._getModuleList(props.modules); // Combine with default modules
82
90
  const hookFunctions = this._hookFunctions; // TODO - combine with default hook functions
83
- const {source, getUniforms} = assembleWGSLShader({
91
+ const {source, getUniforms, bindingAssignments} = assembleWGSLShader({
84
92
  ...props,
85
93
  // @ts-expect-error
86
94
  source: props.source,
95
+ _bindingRegistry: this._wgslBindingRegistry,
87
96
  modules,
88
97
  hookFunctions
89
98
  });
99
+ const defines = {
100
+ ...modules.reduce<Record<string, boolean>>((accumulator, module) => {
101
+ Object.assign(accumulator, module.defines);
102
+ return accumulator;
103
+ }, {}),
104
+ ...props.defines
105
+ };
90
106
  // WGSL does not have built-in preprocessing support (just compile time constants)
91
107
  const preprocessedSource =
92
- props.platformInfo.shaderLanguage === 'wgsl' ? preprocess(source) : source;
93
- return {source: preprocessedSource, getUniforms, modules};
108
+ props.platformInfo.shaderLanguage === 'wgsl' ? preprocess(source, {defines}) : source;
109
+ return {
110
+ source: preprocessedSource,
111
+ getUniforms,
112
+ modules,
113
+ bindingAssignments,
114
+ bindingTable: getShaderBindingDebugRowsFromWGSL(preprocessedSource, bindingAssignments)
115
+ };
94
116
  }
95
117
 
96
118
  /**