@luma.gl/shadertools 9.3.0-alpha.4 → 9.3.0-alpha.8

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 (157) hide show
  1. package/dist/dist.dev.js +4657 -523
  2. package/dist/dist.min.js +1952 -301
  3. package/dist/index.cjs +2804 -406
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +10 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +4 -0
  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 +211 -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 +3 -0
  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 +22 -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 +112 -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/uniform-types.d.ts +11 -7
  37. package/dist/lib/utils/uniform-types.d.ts.map +1 -1
  38. package/dist/modules/engine/picking/picking.d.ts +3 -0
  39. package/dist/modules/engine/picking/picking.d.ts.map +1 -1
  40. package/dist/modules/engine/picking/picking.js +3 -0
  41. package/dist/modules/engine/picking/picking.js.map +1 -1
  42. package/dist/modules/engine/skin/skin.d.ts +30 -0
  43. package/dist/modules/engine/skin/skin.d.ts.map +1 -0
  44. package/dist/modules/engine/skin/skin.js +86 -0
  45. package/dist/modules/engine/skin/skin.js.map +1 -0
  46. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +1 -0
  47. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
  48. package/dist/modules/lighting/gouraud-material/gouraud-material.js +3 -0
  49. package/dist/modules/lighting/gouraud-material/gouraud-material.js.map +1 -1
  50. package/dist/modules/lighting/ibl/ibl.d.ts +26 -0
  51. package/dist/modules/lighting/ibl/ibl.d.ts.map +1 -0
  52. package/dist/modules/lighting/ibl/ibl.js +33 -0
  53. package/dist/modules/lighting/ibl/ibl.js.map +1 -0
  54. package/dist/modules/lighting/lambert-material/lambert-material.d.ts +10 -0
  55. package/dist/modules/lighting/lambert-material/lambert-material.d.ts.map +1 -0
  56. package/dist/modules/lighting/lambert-material/lambert-material.js +33 -0
  57. package/dist/modules/lighting/lambert-material/lambert-material.js.map +1 -0
  58. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts +3 -0
  59. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts.map +1 -0
  60. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.js +60 -0
  61. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.js.map +1 -0
  62. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.d.ts +2 -0
  63. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.d.ts.map +1 -0
  64. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.js +73 -0
  65. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.js.map +1 -0
  66. package/dist/modules/lighting/lights/lighting-glsl.d.ts +1 -1
  67. package/dist/modules/lighting/lights/lighting-glsl.d.ts.map +1 -1
  68. package/dist/modules/lighting/lights/lighting-glsl.js +43 -37
  69. package/dist/modules/lighting/lights/lighting-glsl.js.map +1 -1
  70. package/dist/modules/lighting/lights/lighting-wgsl.d.ts +1 -1
  71. package/dist/modules/lighting/lights/lighting-wgsl.d.ts.map +1 -1
  72. package/dist/modules/lighting/lights/lighting-wgsl.js +46 -18
  73. package/dist/modules/lighting/lights/lighting-wgsl.js.map +1 -1
  74. package/dist/modules/lighting/lights/lighting.d.ts +104 -62
  75. package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
  76. package/dist/modules/lighting/lights/lighting.js +107 -68
  77. package/dist/modules/lighting/lights/lighting.js.map +1 -1
  78. package/dist/modules/lighting/no-material/dirlight.d.ts +7 -2
  79. package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
  80. package/dist/modules/lighting/no-material/dirlight.js +3 -1
  81. package/dist/modules/lighting/no-material/dirlight.js.map +1 -1
  82. package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts +1 -1
  83. package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts.map +1 -1
  84. package/dist/modules/lighting/pbr-material/pbr-material-glsl.js +524 -28
  85. package/dist/modules/lighting/pbr-material/pbr-material-glsl.js.map +1 -1
  86. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts +2 -2
  87. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts.map +1 -1
  88. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js +784 -101
  89. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -1
  90. package/dist/modules/lighting/pbr-material/pbr-material.d.ts +110 -45
  91. package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
  92. package/dist/modules/lighting/pbr-material/pbr-material.js +85 -9
  93. package/dist/modules/lighting/pbr-material/pbr-material.js.map +1 -1
  94. package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +1 -1
  95. package/dist/modules/lighting/pbr-material/pbr-projection.js +13 -1
  96. package/dist/modules/lighting/pbr-material/pbr-projection.js.map +1 -1
  97. package/dist/modules/lighting/phong-material/phong-material.d.ts +1 -0
  98. package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
  99. package/dist/modules/lighting/phong-material/phong-material.js +4 -0
  100. package/dist/modules/lighting/phong-material/phong-material.js.map +1 -1
  101. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +2 -2
  102. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
  103. package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +15 -4
  104. package/dist/modules/lighting/phong-material/phong-shaders-glsl.js.map +1 -1
  105. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts +1 -40
  106. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts.map +1 -1
  107. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js +71 -76
  108. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js.map +1 -1
  109. package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts +1 -1
  110. package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts.map +1 -1
  111. package/dist/modules/math/fp64/fp64-arithmetic-glsl.js +41 -10
  112. package/dist/modules/math/fp64/fp64-arithmetic-glsl.js.map +1 -1
  113. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts +2 -0
  114. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts.map +1 -0
  115. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js +212 -0
  116. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js.map +1 -0
  117. package/dist/modules/math/fp64/fp64.d.ts +1 -0
  118. package/dist/modules/math/fp64/fp64.d.ts.map +1 -1
  119. package/dist/modules/math/fp64/fp64.js +8 -2
  120. package/dist/modules/math/fp64/fp64.js.map +1 -1
  121. package/dist/modules/math/random/random.d.ts +1 -1
  122. package/dist/modules/math/random/random.d.ts.map +1 -1
  123. package/dist/modules/math/random/random.js +2 -3
  124. package/dist/modules/math/random/random.js.map +1 -1
  125. package/package.json +3 -3
  126. package/src/index.ts +20 -2
  127. package/src/lib/preprocessor/preprocessor.ts +44 -8
  128. package/src/lib/shader-assembler.ts +25 -3
  129. package/src/lib/shader-assembly/assemble-shaders.ts +377 -12
  130. package/src/lib/shader-assembly/wgsl-binding-debug.ts +216 -0
  131. package/src/lib/shader-generator/glsl/generate-glsl.ts +7 -1
  132. package/src/lib/shader-generator/wgsl/generate-wgsl.ts +6 -0
  133. package/src/lib/shader-module/shader-module-uniform-layout.ts +194 -0
  134. package/src/lib/shader-module/shader-module.ts +17 -7
  135. package/src/lib/utils/uniform-types.ts +24 -9
  136. package/src/modules/engine/picking/picking.ts +3 -0
  137. package/src/modules/engine/skin/skin.ts +114 -0
  138. package/src/modules/lighting/gouraud-material/gouraud-material.ts +4 -0
  139. package/src/modules/lighting/ibl/ibl.ts +44 -0
  140. package/src/modules/lighting/lambert-material/lambert-material.ts +42 -0
  141. package/src/modules/lighting/lambert-material/lambert-shaders-glsl.ts +61 -0
  142. package/src/modules/lighting/lambert-material/lambert-shaders-wgsl.ts +73 -0
  143. package/src/modules/lighting/lights/lighting-glsl.ts +43 -37
  144. package/src/modules/lighting/lights/lighting-wgsl.ts +46 -18
  145. package/src/modules/lighting/lights/lighting.ts +198 -99
  146. package/src/modules/lighting/no-material/dirlight.ts +3 -1
  147. package/src/modules/lighting/pbr-material/pbr-material-glsl.ts +524 -28
  148. package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +784 -101
  149. package/src/modules/lighting/pbr-material/pbr-material.ts +111 -18
  150. package/src/modules/lighting/pbr-material/pbr-projection.ts +14 -1
  151. package/src/modules/lighting/phong-material/phong-material.ts +5 -0
  152. package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +15 -4
  153. package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +71 -77
  154. package/src/modules/math/fp64/fp64-arithmetic-glsl.ts +41 -10
  155. package/src/modules/math/fp64/fp64-arithmetic-wgsl.ts +212 -0
  156. package/src/modules/math/fp64/fp64.ts +9 -3
  157. package/src/modules/math/random/random.ts +2 -3
package/dist/index.d.ts CHANGED
@@ -3,13 +3,16 @@
3
3
  * Install https://marketplace.visualstudio.com/items?itemName=boyswan.glsl-literal
4
4
  */
5
5
  export type { PlatformInfo } from "./lib/shader-assembly/platform-info.js";
6
+ export type { ShaderBindingDebugRow } from "./lib/shader-assembly/wgsl-binding-debug.js";
6
7
  export type { ShaderModule } from "./lib/shader-module/shader-module.js";
7
8
  export type { ShaderPass } from "./lib/shader-module/shader-pass.js";
8
- export type { UniformTypes } from "./lib/utils/uniform-types.js";
9
+ export type { ShaderModuleUniformValue, UniformTypes } from "./lib/utils/uniform-types.js";
9
10
  export { initializeShaderModule, initializeShaderModules } from "./lib/shader-module/shader-module.js";
10
11
  export { getShaderModuleUniforms } from "./lib/shader-module/shader-module.js";
11
12
  export { getShaderModuleDependencies } from "./lib/shader-module/shader-module-dependencies.js";
12
13
  export { checkShaderModuleDeprecations } from "./lib/shader-module/shader-module.js";
14
+ export type { ShaderModuleUniformLayoutStage, ShaderModuleUniformLayoutValidationResult } from "./lib/shader-module/shader-module-uniform-layout.js";
15
+ export { getShaderModuleUniformBlockFields, getShaderModuleUniformBlockName, getShaderModuleUniformLayoutValidationResult, validateShaderModuleUniformLayout } from "./lib/shader-module/shader-module-uniform-layout.js";
13
16
  export { getShaderModuleSource } from "./lib/shader-assembly/assemble-shaders.js";
14
17
  export { resolveModules as _resolveModules } from "./lib/shader-module/shader-module-dependencies.js";
15
18
  export { getDependencyGraph as _getDependencyGraph } from "./lib/shader-module/shader-module-dependencies.js";
@@ -31,10 +34,15 @@ export { fp32 } from "./modules/math/fp32/fp32.js";
31
34
  export { fp64, fp64arithmetic } from "./modules/math/fp64/fp64.js";
32
35
  export type { PickingProps, PickingUniforms } from "./modules/engine/picking/picking.js";
33
36
  export { picking } from "./modules/engine/picking/picking.js";
34
- export { type Light, type AmbientLight, type PointLight, type DirectionalLight } from "./modules/lighting/lights/lighting.js";
37
+ export { skin } from "./modules/engine/skin/skin.js";
38
+ export { type Light, type AmbientLight, type PointLight, type SpotLight, type DirectionalLight, type LightingLightUniform } from "./modules/lighting/lights/lighting.js";
35
39
  export type { LightingProps, LightingUniforms } from "./modules/lighting/lights/lighting.js";
36
40
  export { lighting } from "./modules/lighting/lights/lighting.js";
41
+ export type { IBLBindings } from "./modules/lighting/ibl/ibl.js";
42
+ export { ibl } from "./modules/lighting/ibl/ibl.js";
37
43
  export { dirlight } from "./modules/lighting/no-material/dirlight.js";
44
+ export type { LambertMaterialProps } from "./modules/lighting/lambert-material/lambert-material.js";
45
+ export { lambertMaterial } from "./modules/lighting/lambert-material/lambert-material.js";
38
46
  export type { GouraudMaterialProps } from "./modules/lighting/gouraud-material/gouraud-material.js";
39
47
  export { gouraudMaterial } from "./modules/lighting/gouraud-material/gouraud-material.js";
40
48
  export type { PhongMaterialProps } from "./modules/lighting/phong-material/phong-material.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,YAAY,EAAC,YAAY,EAAC,+CAA4C;AAItE,YAAY,EAAC,YAAY,EAAC,6CAA0C;AACpE,YAAY,EAAC,UAAU,EAAC,2CAAwC;AAChE,YAAY,EAAC,YAAY,EAAC,qCA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gD;AACjE,YAAY,EAAC,oBAAoB,EAAC,gEAA6D;AAC/F,OAAO,EAAC,eAAe,EAAC,gEAA6D;AACrF,YAAY,EAAC,oBAAoB,EAAC,gEAA6D;AAC/F,OAAO,EAAC,eAAe,EAAC,gEAA6D;AACrF,YAAY,EAAC,kBAAkB,EAAC,4DAAyD;AACzF,OAAO,EAAC,aAAa,EAAC,4DAAyD;AAC/E,YAAY,EACV,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACpB,wDAAqD;AACtD,YAAY,EAAC,kBAAkB,EAAC,0DAAuD;AAEvF,OAAO,EAAC,WAAW,EAAC,wDAAqD"}
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ export { initializeShaderModule, initializeShaderModules } from "./lib/shader-mo
5
5
  export { getShaderModuleUniforms } from "./lib/shader-module/shader-module.js";
6
6
  export { getShaderModuleDependencies } from "./lib/shader-module/shader-module-dependencies.js";
7
7
  export { checkShaderModuleDeprecations } from "./lib/shader-module/shader-module.js";
8
+ export { getShaderModuleUniformBlockFields, getShaderModuleUniformBlockName, getShaderModuleUniformLayoutValidationResult, validateShaderModuleUniformLayout } from "./lib/shader-module/shader-module-uniform-layout.js";
8
9
  export { getShaderModuleSource } from "./lib/shader-assembly/assemble-shaders.js";
9
10
  export { resolveModules as _resolveModules } from "./lib/shader-module/shader-module-dependencies.js";
10
11
  export { getDependencyGraph as _getDependencyGraph } from "./lib/shader-module/shader-module-dependencies.js";
@@ -28,8 +29,11 @@ export { random } from "./modules/math/random/random.js";
28
29
  export { fp32 } from "./modules/math/fp32/fp32.js";
29
30
  export { fp64, fp64arithmetic } from "./modules/math/fp64/fp64.js";
30
31
  export { picking } from "./modules/engine/picking/picking.js";
32
+ export { skin } from "./modules/engine/skin/skin.js";
31
33
  export { lighting } from "./modules/lighting/lights/lighting.js";
34
+ export { ibl } from "./modules/lighting/ibl/ibl.js";
32
35
  export { dirlight } from "./modules/lighting/no-material/dirlight.js";
36
+ export { lambertMaterial } from "./modules/lighting/lambert-material/lambert-material.js";
33
37
  export { gouraudMaterial } from "./modules/lighting/gouraud-material/gouraud-material.js";
34
38
  export { phongMaterial } from "./modules/lighting/phong-material/phong-material.js";
35
39
  export { pbrMaterial } from "./modules/lighting/pbr-material/pbr-material.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAgBpC,OAAO,EAAC,sBAAsB,EAAE,uBAAuB,EAAC,6CAA0C;AAClG,OAAO,EAAC,uBAAuB,EAAC,6CAA0C;AAC1E,OAAO,EAAC,2BAA2B,EAAC,0DAAuD;AAC3F,OAAO,EAAC,6BAA6B,EAAC,6CAA0C;AAEhF,OAAO,EAAC,qBAAqB,EAAC,kDAA+C;AAE7E,OAAO,EAAC,cAAc,IAAI,eAAe,EAAC,0DAAuD;AACjG,OAAO,EAAC,kBAAkB,IAAI,mBAAmB,EAAC,0DAAuD;AAEzG,kBAAkB;AAClB,OAAO,EAAC,eAAe,EAAC,kCAA+B;AAIvD,iBAAiB;AAEjB,8BAA8B;AAC9B,OAAO,EAAC,aAAa,EAAC,4CAAyC;AAC/D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,EACd,yCAAsC;AAIvC,OAAO,EAAC,uBAAuB,EAAC,kDAA+C;AAC/E,OAAO,EAAC,UAAU,EAAC,mDAAgD;AAEnE,uDAAuD;AACvD,OAAO,EAAC,UAAU,EAAC,2CAAwC;AAC3D,OAAO,EAAC,sBAAsB,EAAC,kDAA+C;AAC9E,OAAO,EAAC,cAAc,EAAC,mDAAgD;AAEvE,aAAa;AACb,OAAO,EAAC,WAAW,EAAE,aAAa,EAAC,0CAAuC;AAC1E,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAC,0CAAuC;AAEpF,iBAAiB;AACjB,OAAO,EAAC,MA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AC3D,OAAO,EAAC,sBAAsB,EAAC,kDAA+C;AAC9E,OAAO,EAAC,cAAc,EAAC,mDAAgD;AAEvE,aAAa;AACb,OAAO,EAAC,WAAW,EAAE,aAAa,EAAC,0CAAuC;AAC1E,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAC,0CAAuC;AAEpF,iBAAiB;AACjB,OAAO,EAAC,MAAM,EAAC,wCAAqC;AAEpD,OAAO,EAAC,IAAI,EAAC,oCAAiC;AAC9C,OAAO,EAAC,IAAI,EAAE,cAAc,EAAC,oCAAiC;AAQ9D,OAAO,EAAC,OAAO,EAAC,4CAAyC;AACzD,OAAO,EAAC,IAAI,EAAC,sCAAmC;AAahD,OAAO,EAAC,QAAQ,EAAC,8CAA2C;AAE5D,OAAO,EAAC,GAAG,EAAC,sCAAmC;AAC/C,OAAO,EAAC,QAAQ,EAAC,mDAAgD;AAEjE,OAAO,EAAC,eAAe,EAAC,gEAA6D;AAErF,OAAO,EAAC,eAAe,EAAC,gEAA6D;AAErF,OAAO,EAAC,aAAa,EAAC,4DAAyD;AAQ/E,OAAO,EAAC,WAAW,EAAC,wDAAqD"}
@@ -1 +1 @@
1
- {"version":3,"file":"preprocessor.d.ts","sourceRoot":"","sources":["../../../src/lib/preprocessor/preprocessor.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC,CAAC;AAEF,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,MAAM,CAmBhF"}
1
+ {"version":3,"file":"preprocessor.d.ts","sourceRoot":"","sources":["../../../src/lib/preprocessor/preprocessor.ts"],"names":[],"mappings":"AAcA,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC,CAAC;AAEF,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,MAAM,CAgDhF"}
@@ -1,27 +1,54 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
- const IFDEF_REGEXP = /^\s*\#\s*ifdef\s*([a-zA-Z_]+)\s*$/;
4
+ const DEFINE_NAME_PATTERN = '([a-zA-Z_][a-zA-Z0-9_]*)';
5
+ const IFDEF_REGEXP = new RegExp(`^\\s*\\#\\s*ifdef\\s*${DEFINE_NAME_PATTERN}\\s*$`);
6
+ const IFNDEF_REGEXP = new RegExp(`^\\s*\\#\\s*ifndef\\s*${DEFINE_NAME_PATTERN}\\s*(?:\\/\\/.*)?$`);
7
+ const ELSE_REGEXP = /^\s*\#\s*else\s*(?:\/\/.*)?$/;
5
8
  const ENDIF_REGEXP = /^\s*\#\s*endif\s*$/;
9
+ const IFDEF_WITH_COMMENT_REGEXP = new RegExp(`^\\s*\\#\\s*ifdef\\s*${DEFINE_NAME_PATTERN}\\s*(?:\\/\\/.*)?$`);
10
+ const ENDIF_WITH_COMMENT_REGEXP = /^\s*\#\s*endif\s*(?:\/\/.*)?$/;
6
11
  export function preprocess(source, options) {
7
12
  const lines = source.split('\n');
8
13
  const output = [];
14
+ const conditionalStack = [];
9
15
  let conditional = true;
10
- let currentDefine = null;
11
16
  for (const line of lines) {
12
- const matchIf = line.match(IFDEF_REGEXP);
13
- const matchEnd = line.match(ENDIF_REGEXP);
14
- if (matchIf) {
15
- currentDefine = matchIf[1];
16
- conditional = Boolean(options?.defines?.[currentDefine]);
17
+ const matchIf = line.match(IFDEF_WITH_COMMENT_REGEXP) || line.match(IFDEF_REGEXP);
18
+ const matchIfNot = line.match(IFNDEF_REGEXP);
19
+ const matchElse = line.match(ELSE_REGEXP);
20
+ const matchEnd = line.match(ENDIF_WITH_COMMENT_REGEXP) || line.match(ENDIF_REGEXP);
21
+ if (matchIf || matchIfNot) {
22
+ const defineName = (matchIf || matchIfNot)?.[1];
23
+ const defineValue = Boolean(options?.defines?.[defineName]);
24
+ const branchTaken = matchIf ? defineValue : !defineValue;
25
+ const active = conditional && branchTaken;
26
+ conditionalStack.push({ parentActive: conditional, branchTaken, active });
27
+ conditional = active;
28
+ }
29
+ else if (matchElse) {
30
+ const currentConditional = conditionalStack[conditionalStack.length - 1];
31
+ if (!currentConditional) {
32
+ throw new Error('Encountered #else without matching #ifdef or #ifndef');
33
+ }
34
+ currentConditional.active =
35
+ currentConditional.parentActive && !currentConditional.branchTaken;
36
+ currentConditional.branchTaken = true;
37
+ conditional = currentConditional.active;
17
38
  }
18
39
  else if (matchEnd) {
19
- conditional = true;
40
+ conditionalStack.pop();
41
+ conditional = conditionalStack.length
42
+ ? conditionalStack[conditionalStack.length - 1].active
43
+ : true;
20
44
  }
21
45
  else if (conditional) {
22
46
  output.push(line);
23
47
  }
24
48
  }
49
+ if (conditionalStack.length > 0) {
50
+ throw new Error('Unterminated conditional block in shader source');
51
+ }
25
52
  return output.join('\n');
26
53
  }
27
54
  //# sourceMappingURL=preprocessor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"preprocessor.js","sourceRoot":"","sources":["../../../src/lib/preprocessor/preprocessor.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,MAAM,YAAY,GAAG,mCAAmC,CAAC;AACzD,MAAM,YAAY,GAAG,oBAAoB,CAAC;AAM1C,MAAM,UAAU,UAAU,CAAC,MAAc,EAAE,OAA6B;IACtE,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,IAAI,WAAW,GAAG,IAAI,CAAC;IACvB,IAAI,aAAa,GAAkB,IAAI,CAAC;IACxC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAA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,WAAW,CAAC;YACrE,kBAAkB,CAAC,WAAW,GAAG,IAAI,CAAC;YACtC,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC;QAC1C,CAAC;aAAM,IAAI,QAAQ,EAAE,CAAC;YACpB,gBAAgB,CAAC,GAAG,EAAE,CAAC;YACvB,WAAW,GAAG,gBAAgB,CAAC,MAAM;gBACnC,CAAC,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,MAAM;gBACtD,CAAC,CAAC,IAAI,CAAC;QACX,CAAC;aAAM,IAAI,WAAW,EAAE,CAAC;YACvB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IAED,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import type { ShaderModule } from "./shader-module/shader-module.js";
2
2
  import { AssembleShaderProps, GetUniformsFunc } from "./shader-assembly/assemble-shaders.js";
3
+ import { type ShaderBindingDebugRow } from "./shader-assembly/wgsl-binding-debug.js";
3
4
  /**
4
5
  * A stateful version of `assembleShaders` that can be used to assemble shaders.
5
6
  * Supports setting of default modules and hooks.
@@ -11,6 +12,8 @@ export declare class ShaderAssembler {
11
12
  private readonly _hookFunctions;
12
13
  /** Shader modules */
13
14
  private _defaultModules;
15
+ /** Stable per-run WGSL auto-binding assignments keyed by group/module/binding. */
16
+ private readonly _wgslBindingRegistry;
14
17
  /**
15
18
  * A default shader assembler instance - the natural place to register default modules and hooks
16
19
  * @returns
@@ -40,6 +43,13 @@ export declare class ShaderAssembler {
40
43
  source: string;
41
44
  getUniforms: GetUniformsFunc;
42
45
  modules: ShaderModule[];
46
+ bindingAssignments: {
47
+ moduleName: string;
48
+ name: string;
49
+ group: number;
50
+ location: number;
51
+ }[];
52
+ bindingTable: ShaderBindingDebugRow[];
43
53
  };
44
54
  /**
45
55
  * Assemble a pair of shaders into a single shader program
@@ -1 +1 @@
1
- {"version":3,"file":"shader-assembler.d.ts","sourceRoot":"","sources":["../../src/lib/shader-assembler.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,YAAY,EAAC,yCAAsC;AAEhE,OAAO,EACL,mBAAmB,EACnB,eAAe,EAGhB,8CAA2C;AAG5C;;;GAGG;AACH,qBAAa,eAAe;IAC1B,uCAAuC;IACvC,MAAM,CAAC,sBAAsB,EAAE,eAAe,CAAC;IAC/C,qBAAqB;IACrB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAa;IAC5C,qBAAqB;IACrB,OAAO,CAAC,eAAe,CAAsB;IAE7C;;;OAGG;IACH,MAAM,CAAC,yBAAyB,IAAI,eAAe;IAMnD;;OAEG;IACH,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;IAU5C;;OAEG;IACH,mBAAmB,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;IAK/C;;;;OAIG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAO7C;;;;;OAKG;IACH,kBAAkB,CAAC,KAAK,EAAE,mBAAmB,GAAG;QAC9C,MAAM,EAAE,MAAM,CAAC;QACf,WAAW,EAAE,eAAe,CAAC;QAC7B,OAAO,EAAE,YAAY,EAAE,CAAC;KACzB;IAgBD;;;;;OAKG;IACH,sBAAsB,CAAC,KAAK,EAAE,mBAAmB,GAAG;QAClD,EAAE,EAAE,MAAM,CAAC;QACX,EAAE,EAAE,MAAM,CAAC;QACX,WAAW,EAAE,eAAe,CAAC;QAC7B,OAAO,EAAE,YAAY,EAAE,CAAC;KACzB;IAgBD;;OAEG;IACH,cAAc,CAAC,UAAU,GAAE,YAAY,EAAO,GAAG,YAAY,EAAE;CA0BhE"}
1
+ {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AAE,MAAM,CAAC;QACX,WAAW,EAAE,eAAe,CAAC;QAC7B,OAAO,EAAE,YAAY,EAAE,CAAC;KACzB;IAgBD;;OAEG;IACH,cAAc,CAAC,UAAU,GAAE,YAAY,EAAO,GAAG,YAAY,EAAE;CA0BhE"}
@@ -3,6 +3,7 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
  import { initializeShaderModules } from "./shader-module/shader-module.js";
5
5
  import { assembleWGSLShader, assembleGLSLShaderPair } from "./shader-assembly/assemble-shaders.js";
6
+ import { getShaderBindingDebugRowsFromWGSL } from "./shader-assembly/wgsl-binding-debug.js";
6
7
  import { preprocess } from "./preprocessor/preprocessor.js";
7
8
  /**
8
9
  * A stateful version of `assembleShaders` that can be used to assemble shaders.
@@ -15,6 +16,8 @@ export class ShaderAssembler {
15
16
  _hookFunctions = [];
16
17
  /** Shader modules */
17
18
  _defaultModules = [];
19
+ /** Stable per-run WGSL auto-binding assignments keyed by group/module/binding. */
20
+ _wgslBindingRegistry = new Map();
18
21
  /**
19
22
  * A default shader assembler instance - the natural place to register default modules and hooks
20
23
  * @returns
@@ -59,16 +62,30 @@ export class ShaderAssembler {
59
62
  assembleWGSLShader(props) {
60
63
  const modules = this._getModuleList(props.modules); // Combine with default modules
61
64
  const hookFunctions = this._hookFunctions; // TODO - combine with default hook functions
62
- const { source, getUniforms } = assembleWGSLShader({
65
+ const { source, getUniforms, bindingAssignments } = assembleWGSLShader({
63
66
  ...props,
64
67
  // @ts-expect-error
65
68
  source: props.source,
69
+ _bindingRegistry: this._wgslBindingRegistry,
66
70
  modules,
67
71
  hookFunctions
68
72
  });
73
+ const defines = {
74
+ ...modules.reduce((accumulator, module) => {
75
+ Object.assign(accumulator, module.defines);
76
+ return accumulator;
77
+ }, {}),
78
+ ...props.defines
79
+ };
69
80
  // WGSL does not have built-in preprocessing support (just compile time constants)
70
- const preprocessedSource = props.platformInfo.shaderLanguage === 'wgsl' ? preprocess(source) : source;
71
- return { source: preprocessedSource, getUniforms, modules };
81
+ const preprocessedSource = props.platformInfo.shaderLanguage === 'wgsl' ? preprocess(source, { defines }) : source;
82
+ return {
83
+ source: preprocessedSource,
84
+ getUniforms,
85
+ modules,
86
+ bindingAssignments,
87
+ bindingTable: getShaderBindingDebugRowsFromWGSL(preprocessedSource, bindingAssignments)
88
+ };
72
89
  }
73
90
  /**
74
91
  * Assemble a pair of shaders into a single shader program
@@ -1 +1 @@
1
- {"version":3,"file":"shader-assembler.js","sourceRoot":"","sources":["../../src/lib/shader-assembler.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAGpC,OAAO,EAAC,uBAAuB,EAAC,yCAAsC;AACtE,OAAO,EAGL,kBAAkB,EAClB,sBAAsB,EACvB,8CAA2C;AAC5C,OAAO,EAAC,UAAU,EAAC,uCAAoC;AAEvD;;;GAGG;AACH,MAAM,OAAO,eAAe;IAC1B,uCAAuC;IACvC,MAAM,CAAC,sBAAsB,CAAkB;IAC/C,qBAAqB;IACJ,cAAc,GAAU,EAAE,CAAC;IAC5C,qBAAqB;IACb,eAAe,GAAmB,EAAE,CAAC;IAE7C;;;OAGG;IACH,MAAM,CAAC,yBAAyB;QAC9B,eAAe,CAAC,sBAAsB;YACpC,eAAe,CAAC,sBAAsB,IAAI,IAAI,eAAe,EAAE,CAAC;QAClE,OAAO,eAAe,CAAC,sBAAsB,CAAC;IAChD,CAAC;IAED;;OAEG;IACH,gBAAgB,CAAC,MAAoB;QACnC,IACE,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CACxB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CACpE,EACD,CAAC;YACD,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,mBAAmB,CAA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;YAChE,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;YACvC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;YACzB,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC;YAC1B,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;QACpB,CAAC;QAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,GAAG,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC;YACtD,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;YAC7B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;YACzB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBAChB,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC;gBAC1B,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;YACpB,CAAC;QACH,CAAC;QAED,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC;QAEvB,uBAAuB,CAAC,OAAO,CAAC,CAAC;QACjC,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
@@ -2,6 +2,7 @@ import { PlatformInfo } from "./platform-info.js";
2
2
  import type { ShaderInjection } from "./shader-injections.js";
3
3
  import type { ShaderModule } from "../shader-module/shader-module.js";
4
4
  import { ShaderHook } from "./shader-hooks.js";
5
+ import { type ShaderBindingDebugRow } from "./wgsl-binding-debug.js";
5
6
  /**
6
7
  * Options for `ShaderAssembler.assembleShaders()`
7
8
  */
@@ -54,6 +55,8 @@ type AssembleStageOptions = {
54
55
  prologue?: boolean;
55
56
  /** logger object */
56
57
  log?: any;
58
+ /** @internal Stable per-assembler WGSL binding assignments. */
59
+ _bindingRegistry?: Map<string, number>;
57
60
  };
58
61
  export type HookFunction = {
59
62
  hook: string;
@@ -71,9 +74,18 @@ export type GetUniformsFunc = (opts: Record<string, any>) => Record<string, any>
71
74
  export declare function assembleWGSLShader(options: AssembleShaderOptions & {
72
75
  /** Single WGSL shader */
73
76
  source: string;
77
+ /** @internal Stable per-assembler WGSL binding assignments. */
78
+ _bindingRegistry?: Map<string, number>;
74
79
  }): {
75
80
  source: string;
76
81
  getUniforms: GetUniformsFunc;
82
+ bindingAssignments: {
83
+ moduleName: string;
84
+ name: string;
85
+ group: number;
86
+ location: number;
87
+ }[];
88
+ bindingTable: ShaderBindingDebugRow[];
77
89
  };
78
90
  /**
79
91
  * Injects dependent shader module sources into pair of main vertex/fragment shader sources for GLSL
@@ -95,7 +107,10 @@ export declare function assembleGLSLShaderPair(options: AssembleShaderOptions &
95
107
  * @param options
96
108
  * @returns
97
109
  */
98
- export declare function assembleShaderWGSL(platformInfo: PlatformInfo, options: AssembleStageOptions): string;
110
+ export declare function assembleShaderWGSL(platformInfo: PlatformInfo, options: AssembleStageOptions): {
111
+ source: string;
112
+ bindingAssignments: WGSLBindingAssignment[];
113
+ };
99
114
  /**
100
115
  * Returns a combined `getUniforms` covering the options for all the modules,
101
116
  * the created function will pass on options to the inidividual `getUniforms`
@@ -106,6 +121,12 @@ export declare function assembleShaderWGSL(platformInfo: PlatformInfo, options:
106
121
  */
107
122
  export declare function assembleGetUniforms(modules: ShaderModule[]): (opts: Record<string, any>) => Record<string, any>;
108
123
  /** Extracts the source code chunk for the specified shader type from the named shader module */
109
- export declare function getShaderModuleSource(module: ShaderModule, stage: 'vertex' | 'fragment' | 'wgsl'): string;
124
+ export declare function getShaderModuleSource(module: ShaderModule, stage: 'vertex' | 'fragment' | 'wgsl', log?: any): string;
125
+ type WGSLBindingAssignment = {
126
+ moduleName: string;
127
+ name: string;
128
+ group: number;
129
+ location: number;
130
+ };
110
131
  export {};
111
132
  //# sourceMappingURL=assemble-shaders.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"assemble-shaders.d.ts","sourceRoot":"","sources":["../../../src/lib/shader-assembly/assemble-shaders.ts"],"names":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B,EAAE,CAAA;CAAC,CAiI/D;AA4JD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,YAAY,EAAE,IAC7B,MAAM,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAU5E;AAkCD,gGAAgG;AAChG,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,EACrC,GAAG,CAAC,EAAE,GAAG,GACR,MAAM,CAgCR;AAQD,KAAK,qBAAqB,GAAG;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC"}
@@ -6,10 +6,21 @@ import { getPlatformShaderDefines } from "./platform-defines.js";
6
6
  import { injectShader, DECLARATION_INJECT_MARKER } from "./shader-injections.js";
7
7
  import { transpileGLSLShader } from "../shader-transpiler/transpile-glsl-shader.js";
8
8
  import { checkShaderModuleDeprecations } from "../shader-module/shader-module.js";
9
+ import { validateShaderModuleUniformLayout } from "../shader-module/shader-module-uniform-layout.js";
9
10
  import { normalizeShaderHooks, getShaderHooks } from "./shader-hooks.js";
10
11
  import { assert } from "../utils/assert.js";
11
12
  import { getShaderInfo } from "../glsl-utils/get-shader-info.js";
13
+ import { getShaderBindingDebugRowsFromWGSL } from "./wgsl-binding-debug.js";
12
14
  const INJECT_SHADER_DECLARATIONS = `\n\n${DECLARATION_INJECT_MARKER}\n`;
15
+ const MODULE_WGSL_BINDING_DECLARATION_REGEXES = [
16
+ /@binding\(\s*(auto|\d+)\s*\)\s*@group\(\s*(\d+)\s*\)\s*(var(?:<[^>]+>)?\s+([A-Za-z_][A-Za-z0-9_]*))/g,
17
+ /@group\(\s*(\d+)\s*\)\s*@binding\(\s*(auto|\d+)\s*\)\s*(var(?:<[^>]+>)?\s+([A-Za-z_][A-Za-z0-9_]*))/g
18
+ ];
19
+ const WGSL_BINDING_DECLARATION_REGEXES = [
20
+ /@binding\(\s*(\d+)\s*\)\s*@group\(\s*(\d+)\s*\)\s*(var(?:<[^>]+>)?\s+([A-Za-z_][A-Za-z0-9_]*))/g,
21
+ /@group\(\s*(\d+)\s*\)\s*@binding\(\s*(\d+)\s*\)\s*(var(?:<[^>]+>)?\s+([A-Za-z_][A-Za-z0-9_]*))/g
22
+ ];
23
+ const RESERVED_APPLICATION_GROUP_0_BINDING_LIMIT = 100;
13
24
  /**
14
25
  * Precision prologue to inject before functions are injected in shader
15
26
  * TODO - extract any existing prologue in the fragment source and move it up...
@@ -22,14 +33,17 @@ precision highp float;
22
33
  */
23
34
  export function assembleWGSLShader(options) {
24
35
  const modules = getShaderModuleDependencies(options.modules || []);
36
+ const { source, bindingAssignments } = assembleShaderWGSL(options.platformInfo, {
37
+ ...options,
38
+ source: options.source,
39
+ stage: 'vertex',
40
+ modules
41
+ });
25
42
  return {
26
- source: assembleShaderWGSL(options.platformInfo, {
27
- ...options,
28
- source: options.source,
29
- stage: 'vertex',
30
- modules
31
- }),
32
- getUniforms: assembleGetUniforms(modules)
43
+ source,
44
+ getUniforms: assembleGetUniforms(modules),
45
+ bindingAssignments,
46
+ bindingTable: getShaderBindingDebugRowsFromWGSL(source, bindingAssignments)
33
47
  };
34
48
  }
35
49
  /**
@@ -121,11 +135,20 @@ export function assembleShaderWGSL(platformInfo, options) {
121
135
  }
122
136
  // TODO - hack until shadertool modules support WebGPU
123
137
  const modulesToInject = modules;
138
+ const usedBindingsByGroup = getUsedBindingsByGroupFromApplicationWGSL(coreSource);
139
+ const reservedBindingKeysByGroup = reserveRegisteredModuleBindings(modulesToInject, options._bindingRegistry, usedBindingsByGroup);
140
+ const bindingAssignments = [];
124
141
  for (const module of modulesToInject) {
125
142
  if (log) {
126
143
  checkShaderModuleDeprecations(module, coreSource, log);
127
144
  }
128
- const moduleSource = getShaderModuleSource(module, 'wgsl');
145
+ const relocation = relocateWGSLModuleBindings(getShaderModuleSource(module, 'wgsl', log), module, {
146
+ usedBindingsByGroup,
147
+ bindingRegistry: options._bindingRegistry,
148
+ reservedBindingKeysByGroup
149
+ });
150
+ bindingAssignments.push(...relocation.bindingAssignments);
151
+ const moduleSource = relocation.source;
129
152
  // Add the module source, and a #define that declares it presence
130
153
  assembledSource += moduleSource;
131
154
  const injections = module.injections?.[stage] || {};
@@ -147,11 +170,13 @@ export function assembleShaderWGSL(platformInfo, options) {
147
170
  assembledSource += INJECT_SHADER_DECLARATIONS;
148
171
  assembledSource = injectShader(assembledSource, stage, declInjections);
149
172
  assembledSource += getShaderHooks(hookFunctionMap[stage], hookInjections);
173
+ assembledSource += formatWGSLBindingAssignmentComments(bindingAssignments);
150
174
  // Add the version directive and actual source of this shader
151
175
  assembledSource += coreSource;
152
176
  // Apply any requested shader injections
153
177
  assembledSource = injectShader(assembledSource, stage, mainInjections);
154
- return assembledSource;
178
+ assertNoUnresolvedAutoBindings(assembledSource);
179
+ return { source: assembledSource, bindingAssignments };
155
180
  }
156
181
  /**
157
182
  * Pulls together complete source code for either a vertex or a fragment shader
@@ -234,7 +259,7 @@ ${getApplicationDefines(allDefines)}
234
259
  if (log) {
235
260
  checkShaderModuleDeprecations(module, coreSource, log);
236
261
  }
237
- const moduleSource = getShaderModuleSource(module, stage);
262
+ const moduleSource = getShaderModuleSource(module, stage, log);
238
263
  // Add the module source, and a #define that declares it presence
239
264
  assembledSource += moduleSource;
240
265
  const injections = module.instance?.normalizedInjections[stage] || {};
@@ -317,7 +342,7 @@ function getApplicationDefines(defines = {}) {
317
342
  return sourceText;
318
343
  }
319
344
  /** Extracts the source code chunk for the specified shader type from the named shader module */
320
- export function getShaderModuleSource(module, stage) {
345
+ export function getShaderModuleSource(module, stage, log) {
321
346
  let moduleSource;
322
347
  switch (stage) {
323
348
  case 'vertex':
@@ -335,6 +360,7 @@ export function getShaderModuleSource(module, stage) {
335
360
  if (!module.name) {
336
361
  throw new Error('Shader module must have a name');
337
362
  }
363
+ validateShaderModuleUniformLayout(module, stage, { log });
338
364
  const moduleName = module.name.toUpperCase().replace(/[^0-9a-z]/gi, '_');
339
365
  let source = `\
340
366
  // ----- MODULE ${module.name} ---------------
@@ -346,6 +372,180 @@ export function getShaderModuleSource(module, stage) {
346
372
  source += `${moduleSource}\n`;
347
373
  return source;
348
374
  }
375
+ function getUsedBindingsByGroupFromApplicationWGSL(source) {
376
+ const usedBindingsByGroup = new Map();
377
+ for (const regex of WGSL_BINDING_DECLARATION_REGEXES) {
378
+ regex.lastIndex = 0;
379
+ let match;
380
+ while ((match = regex.exec(source))) {
381
+ const isBindingFirst = regex === WGSL_BINDING_DECLARATION_REGEXES[0];
382
+ const location = Number(match[isBindingFirst ? 1 : 2]);
383
+ const group = Number(match[isBindingFirst ? 2 : 1]);
384
+ const name = match[4];
385
+ validateApplicationWGSLBinding(group, location, name);
386
+ registerUsedBindingLocation(usedBindingsByGroup, group, location, `application binding "${name}"`);
387
+ }
388
+ }
389
+ return usedBindingsByGroup;
390
+ }
391
+ function relocateWGSLModuleBindings(moduleSource, module, context) {
392
+ const bindingAssignments = [];
393
+ const relocationState = {
394
+ sawSupportedBindingDeclaration: false,
395
+ nextHintedBindingLocation: typeof module.firstBindingSlot === 'number' ? module.firstBindingSlot : null
396
+ };
397
+ let relocatedSource = relocateWGSLModuleBindingsWithRegex(moduleSource, MODULE_WGSL_BINDING_DECLARATION_REGEXES[0], { isBindingFirst: true, module, context, bindingAssignments, relocationState });
398
+ relocatedSource = relocateWGSLModuleBindingsWithRegex(relocatedSource, MODULE_WGSL_BINDING_DECLARATION_REGEXES[1], { isBindingFirst: false, module, context, bindingAssignments, relocationState });
399
+ if (moduleSource.includes('@binding(auto)') && !relocationState.sawSupportedBindingDeclaration) {
400
+ throw new Error(`Unsupported @binding(auto) declaration form in module "${module.name}". ` +
401
+ 'Use "@group(N) @binding(auto) var ..." or "@binding(auto) @group(N) var ..." on a single line.');
402
+ }
403
+ return { source: relocatedSource, bindingAssignments };
404
+ }
405
+ function relocateWGSLModuleBindingsWithRegex(source, regex, params) {
406
+ return source.replace(regex, (...replaceArguments) => relocateWGSLModuleBindingMatch(replaceArguments, params));
407
+ }
408
+ function relocateWGSLModuleBindingMatch(replaceArguments, params) {
409
+ const { isBindingFirst, module, context, bindingAssignments, relocationState } = params;
410
+ relocationState.sawSupportedBindingDeclaration = true;
411
+ const match = replaceArguments[0];
412
+ const bindingToken = replaceArguments[isBindingFirst ? 1 : 2];
413
+ const groupToken = replaceArguments[isBindingFirst ? 2 : 1];
414
+ const name = replaceArguments[4];
415
+ const group = Number(groupToken);
416
+ if (bindingToken === 'auto') {
417
+ const registryKey = getBindingRegistryKey(group, module.name, name);
418
+ const registryLocation = context.bindingRegistry?.get(registryKey);
419
+ const location = registryLocation !== undefined
420
+ ? registryLocation
421
+ : relocationState.nextHintedBindingLocation === null
422
+ ? allocateAutoBindingLocation(group, context.usedBindingsByGroup)
423
+ : allocateAutoBindingLocation(group, context.usedBindingsByGroup, relocationState.nextHintedBindingLocation);
424
+ validateModuleWGSLBinding(module.name, group, location, name);
425
+ if (registryLocation !== undefined &&
426
+ claimReservedBindingLocation(context.reservedBindingKeysByGroup, group, location, registryKey)) {
427
+ bindingAssignments.push({ moduleName: module.name, name, group, location });
428
+ return match.replace(/@binding\(\s*auto\s*\)/, `@binding(${location})`);
429
+ }
430
+ registerUsedBindingLocation(context.usedBindingsByGroup, group, location, `module "${module.name}" binding "${name}"`);
431
+ context.bindingRegistry?.set(registryKey, location);
432
+ bindingAssignments.push({ moduleName: module.name, name, group, location });
433
+ if (relocationState.nextHintedBindingLocation !== null && registryLocation === undefined) {
434
+ relocationState.nextHintedBindingLocation = location + 1;
435
+ }
436
+ return match.replace(/@binding\(\s*auto\s*\)/, `@binding(${location})`);
437
+ }
438
+ const location = Number(bindingToken);
439
+ validateModuleWGSLBinding(module.name, group, location, name);
440
+ registerUsedBindingLocation(context.usedBindingsByGroup, group, location, `module "${module.name}" binding "${name}"`);
441
+ bindingAssignments.push({ moduleName: module.name, name, group, location });
442
+ return match;
443
+ }
444
+ function reserveRegisteredModuleBindings(modules, bindingRegistry, usedBindingsByGroup) {
445
+ const reservedBindingKeysByGroup = new Map();
446
+ if (!bindingRegistry) {
447
+ return reservedBindingKeysByGroup;
448
+ }
449
+ for (const module of modules) {
450
+ for (const binding of getModuleWGSLBindingDeclarations(module)) {
451
+ const registryKey = getBindingRegistryKey(binding.group, module.name, binding.name);
452
+ const location = bindingRegistry.get(registryKey);
453
+ if (location !== undefined) {
454
+ const reservedBindingKeys = reservedBindingKeysByGroup.get(binding.group) || new Map();
455
+ const existingReservation = reservedBindingKeys.get(location);
456
+ if (existingReservation && existingReservation !== registryKey) {
457
+ throw new Error(`Duplicate WGSL binding reservation for modules "${existingReservation}" and "${registryKey}": group ${binding.group}, binding ${location}.`);
458
+ }
459
+ registerUsedBindingLocation(usedBindingsByGroup, binding.group, location, `registered module binding "${registryKey}"`);
460
+ reservedBindingKeys.set(location, registryKey);
461
+ reservedBindingKeysByGroup.set(binding.group, reservedBindingKeys);
462
+ }
463
+ }
464
+ }
465
+ return reservedBindingKeysByGroup;
466
+ }
467
+ function claimReservedBindingLocation(reservedBindingKeysByGroup, group, location, registryKey) {
468
+ const reservedBindingKeys = reservedBindingKeysByGroup.get(group);
469
+ if (!reservedBindingKeys) {
470
+ return false;
471
+ }
472
+ const reservedKey = reservedBindingKeys.get(location);
473
+ if (!reservedKey) {
474
+ return false;
475
+ }
476
+ if (reservedKey !== registryKey) {
477
+ throw new Error(`Registered module binding "${registryKey}" collided with "${reservedKey}": group ${group}, binding ${location}.`);
478
+ }
479
+ return true;
480
+ }
481
+ function getModuleWGSLBindingDeclarations(module) {
482
+ const declarations = [];
483
+ const moduleSource = module.source || '';
484
+ for (const regex of MODULE_WGSL_BINDING_DECLARATION_REGEXES) {
485
+ regex.lastIndex = 0;
486
+ let match;
487
+ while ((match = regex.exec(moduleSource))) {
488
+ const isBindingFirst = regex === MODULE_WGSL_BINDING_DECLARATION_REGEXES[0];
489
+ declarations.push({
490
+ name: match[4],
491
+ group: Number(match[isBindingFirst ? 2 : 1])
492
+ });
493
+ }
494
+ }
495
+ return declarations;
496
+ }
497
+ function validateApplicationWGSLBinding(group, location, name) {
498
+ if (group === 0 && location >= RESERVED_APPLICATION_GROUP_0_BINDING_LIMIT) {
499
+ throw new Error(`Application binding "${name}" in group 0 uses reserved binding ${location}. ` +
500
+ `Application-owned explicit group-0 bindings must stay below ${RESERVED_APPLICATION_GROUP_0_BINDING_LIMIT}.`);
501
+ }
502
+ }
503
+ function validateModuleWGSLBinding(moduleName, group, location, name) {
504
+ if (group === 0 && location < RESERVED_APPLICATION_GROUP_0_BINDING_LIMIT) {
505
+ throw new Error(`Module "${moduleName}" binding "${name}" in group 0 uses reserved application binding ${location}. ` +
506
+ `Module-owned explicit group-0 bindings must be ${RESERVED_APPLICATION_GROUP_0_BINDING_LIMIT} or higher.`);
507
+ }
508
+ }
509
+ function registerUsedBindingLocation(usedBindingsByGroup, group, location, label) {
510
+ const usedBindings = usedBindingsByGroup.get(group) || new Set();
511
+ if (usedBindings.has(location)) {
512
+ throw new Error(`Duplicate WGSL binding assignment for ${label}: group ${group}, binding ${location}.`);
513
+ }
514
+ usedBindings.add(location);
515
+ usedBindingsByGroup.set(group, usedBindings);
516
+ }
517
+ function allocateAutoBindingLocation(group, usedBindingsByGroup, preferredBindingLocation) {
518
+ const usedBindings = usedBindingsByGroup.get(group) || new Set();
519
+ let nextBinding = preferredBindingLocation ??
520
+ (group === 0
521
+ ? RESERVED_APPLICATION_GROUP_0_BINDING_LIMIT
522
+ : usedBindings.size > 0
523
+ ? Math.max(...usedBindings) + 1
524
+ : 0);
525
+ while (usedBindings.has(nextBinding)) {
526
+ nextBinding++;
527
+ }
528
+ return nextBinding;
529
+ }
530
+ function assertNoUnresolvedAutoBindings(source) {
531
+ if (/@binding\(\s*auto\s*\)/.test(source)) {
532
+ throw new Error('Unresolved @binding(auto) remained in assembled WGSL source.');
533
+ }
534
+ }
535
+ function formatWGSLBindingAssignmentComments(bindingAssignments) {
536
+ if (bindingAssignments.length === 0) {
537
+ return '';
538
+ }
539
+ let source = '// ----- MODULE WGSL BINDING ASSIGNMENTS ---------------\n';
540
+ for (const bindingAssignment of bindingAssignments) {
541
+ source += `// ${bindingAssignment.moduleName}.${bindingAssignment.name} -> @group(${bindingAssignment.group}) @binding(${bindingAssignment.location})\n`;
542
+ }
543
+ source += '\n';
544
+ return source;
545
+ }
546
+ function getBindingRegistryKey(group, moduleName, bindingName) {
547
+ return `${group}:${moduleName}:${bindingName}`;
548
+ }
349
549
  /*
350
550
  function getHookFunctions(
351
551
  hookFunctions: Record<string, HookFunction>,