@carbonenginejs/runtime-resource 0.10.0 → 0.11.0

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 (254) hide show
  1. package/dist/format/effect/effectPermutationGraph.js +257 -0
  2. package/dist/format/effect/effectPermutationGraph.js.map +1 -0
  3. package/dist/format/effect/effectReflectionPackage.js +636 -0
  4. package/dist/format/effect/effectReflectionPackage.js.map +1 -0
  5. package/dist/format/effect/sha256.js +114 -0
  6. package/dist/format/effect/sha256.js.map +1 -0
  7. package/dist/formats/dxbc/CjsDxbcFormat.js +142 -0
  8. package/dist/formats/dxbc/CjsDxbcFormat.js.map +1 -0
  9. package/dist/formats/dxbc/core/DxbcReader.js +266 -0
  10. package/dist/formats/dxbc/core/DxbcReader.js.map +1 -0
  11. package/dist/formats/dxbc/core/container.js +169 -0
  12. package/dist/formats/dxbc/core/container.js.map +1 -0
  13. package/dist/formats/dxbc/core/decoder.js +789 -0
  14. package/dist/formats/dxbc/core/decoder.js.map +1 -0
  15. package/dist/formats/dxbc/core/errors.js +19 -0
  16. package/dist/formats/dxbc/core/errors.js.map +1 -0
  17. package/dist/formats/dxbc/core/helpers.js +220 -0
  18. package/dist/formats/dxbc/core/helpers.js.map +1 -0
  19. package/dist/formats/dxbc/core/opcodes.js +45 -0
  20. package/dist/formats/dxbc/core/opcodes.js.map +1 -0
  21. package/dist/formats/dxbc/core/program.js +91 -0
  22. package/dist/formats/dxbc/core/program.js.map +1 -0
  23. package/dist/formats/dxbc/core/signature.js +172 -0
  24. package/dist/formats/dxbc/core/signature.js.map +1 -0
  25. package/dist/formats/dxbc/index.js +2 -0
  26. package/dist/formats/dxbc/index.js.map +1 -0
  27. package/dist/formats/hlsl/CjsHlslFormat.js +254 -0
  28. package/dist/formats/hlsl/CjsHlslFormat.js.map +1 -0
  29. package/dist/formats/hlsl/core/HlslBinaryUtils.js +15 -0
  30. package/dist/formats/hlsl/core/HlslBinaryUtils.js.map +1 -0
  31. package/dist/formats/hlsl/core/HlslEffectReadError.js +19 -0
  32. package/dist/formats/hlsl/core/HlslEffectReadError.js.map +1 -0
  33. package/dist/formats/hlsl/core/HlslEffectStateManager.js +130 -0
  34. package/dist/formats/hlsl/core/HlslEffectStateManager.js.map +1 -0
  35. package/dist/formats/hlsl/core/HlslReader.js +266 -0
  36. package/dist/formats/hlsl/core/HlslReader.js.map +1 -0
  37. package/dist/formats/hlsl/core/HlslRenderStateSetup.js +37 -0
  38. package/dist/formats/hlsl/core/HlslRenderStateSetup.js.map +1 -0
  39. package/dist/formats/hlsl/core/HlslResourceSetDescription.js +94 -0
  40. package/dist/formats/hlsl/core/HlslResourceSetDescription.js.map +1 -0
  41. package/dist/formats/hlsl/core/HlslShaderBytecode.js +44 -0
  42. package/dist/formats/hlsl/core/HlslShaderBytecode.js.map +1 -0
  43. package/dist/formats/hlsl/core/analysis.js +51 -0
  44. package/dist/formats/hlsl/core/analysis.js.map +1 -0
  45. package/dist/formats/hlsl/core/helpers.js +270 -0
  46. package/dist/formats/hlsl/core/helpers.js.map +1 -0
  47. package/dist/formats/hlsl/core/json.js +284 -0
  48. package/dist/formats/hlsl/core/json.js.map +1 -0
  49. package/dist/formats/hlsl/core/metadata.js +327 -0
  50. package/dist/formats/hlsl/core/metadata.js.map +1 -0
  51. package/dist/formats/hlsl/core/portableReflection.js +848 -0
  52. package/dist/formats/hlsl/core/portableReflection.js.map +1 -0
  53. package/dist/formats/hlsl/core/render-states.js +280 -0
  54. package/dist/formats/hlsl/core/render-states.js.map +1 -0
  55. package/dist/formats/hlsl/core/tr2/HlslRenderContextEnum.js +43 -0
  56. package/dist/formats/hlsl/core/tr2/HlslRenderContextEnum.js.map +1 -0
  57. package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js +294 -0
  58. package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js.map +1 -0
  59. package/dist/formats/hlsl/core/tr2/resources/HlslShaderPermutation.js +33 -0
  60. package/dist/formats/hlsl/core/tr2/resources/HlslShaderPermutation.js.map +1 -0
  61. package/dist/formats/hlsl/core/tr2/shader/HlslEffectBindingManifest.js +416 -0
  62. package/dist/formats/hlsl/core/tr2/shader/HlslEffectBindingManifest.js.map +1 -0
  63. package/dist/formats/hlsl/core/tr2/shader/HlslEffectConstant.js +40 -0
  64. package/dist/formats/hlsl/core/tr2/shader/HlslEffectConstant.js.map +1 -0
  65. package/dist/formats/hlsl/core/tr2/shader/HlslEffectDescription.js +742 -0
  66. package/dist/formats/hlsl/core/tr2/shader/HlslEffectDescription.js.map +1 -0
  67. package/dist/formats/hlsl/core/tr2/shader/HlslEffectLibrary.js +52 -0
  68. package/dist/formats/hlsl/core/tr2/shader/HlslEffectLibrary.js.map +1 -0
  69. package/dist/formats/hlsl/core/tr2/shader/HlslEffectParameterAnnotation.js +38 -0
  70. package/dist/formats/hlsl/core/tr2/shader/HlslEffectParameterAnnotation.js.map +1 -0
  71. package/dist/formats/hlsl/core/tr2/shader/HlslEffectResource.js +50 -0
  72. package/dist/formats/hlsl/core/tr2/shader/HlslEffectResource.js.map +1 -0
  73. package/dist/formats/hlsl/core/tr2/shader/HlslEffectStageInput.js +86 -0
  74. package/dist/formats/hlsl/core/tr2/shader/HlslEffectStageInput.js.map +1 -0
  75. package/dist/formats/hlsl/core/tr2/shader/HlslEffectTechnique.js +31 -0
  76. package/dist/formats/hlsl/core/tr2/shader/HlslEffectTechnique.js.map +1 -0
  77. package/dist/formats/hlsl/core/tr2/shader/HlslPass.js +42 -0
  78. package/dist/formats/hlsl/core/tr2/shader/HlslPass.js.map +1 -0
  79. package/dist/formats/hlsl/core/tr2/shader/HlslSamplerDescription.js +55 -0
  80. package/dist/formats/hlsl/core/tr2/shader/HlslSamplerDescription.js.map +1 -0
  81. package/dist/formats/hlsl/core/tr2/shader/HlslSamplerSetup.js +29 -0
  82. package/dist/formats/hlsl/core/tr2/shader/HlslSamplerSetup.js.map +1 -0
  83. package/dist/formats/hlsl/core/tr2/shader/HlslShader.js +220 -0
  84. package/dist/formats/hlsl/core/tr2/shader/HlslShader.js.map +1 -0
  85. package/dist/formats/hlsl/core/tr2/shader/HlslShaderOption.js +30 -0
  86. package/dist/formats/hlsl/core/tr2/shader/HlslShaderOption.js.map +1 -0
  87. package/dist/formats/hlsl/index.js +2 -0
  88. package/dist/formats/hlsl/index.js.map +1 -0
  89. package/dist/formats/hlsl/portable.js +2 -0
  90. package/dist/formats/hlsl/portable.js.map +1 -0
  91. package/dist/formats/index.js +4 -0
  92. package/dist/formats/index.js.map +1 -1
  93. package/dist/formats/webgl/CjsWebglFormat.js +221 -0
  94. package/dist/formats/webgl/CjsWebglFormat.js.map +1 -0
  95. package/dist/formats/webgl/core/cewg/CewgPackage.js +339 -0
  96. package/dist/formats/webgl/core/cewg/CewgPackage.js.map +1 -0
  97. package/dist/formats/webgl/core/cewg/CewgPackageBuilder.js +104 -0
  98. package/dist/formats/webgl/core/cewg/CewgPackageBuilder.js.map +1 -0
  99. package/dist/formats/webgl/core/cewg/binary.js +101 -0
  100. package/dist/formats/webgl/core/cewg/binary.js.map +1 -0
  101. package/dist/formats/webgl/core/cewgCompleteness.js +81 -0
  102. package/dist/formats/webgl/core/cewgCompleteness.js.map +1 -0
  103. package/dist/formats/webgl/core/effectPackage.js +789 -0
  104. package/dist/formats/webgl/core/effectPackage.js.map +1 -0
  105. package/dist/formats/webgl/core/effectPackageValidation.js +331 -0
  106. package/dist/formats/webgl/core/effectPackageValidation.js.map +1 -0
  107. package/dist/formats/webgl/core/errors.js +27 -0
  108. package/dist/formats/webgl/core/errors.js.map +1 -0
  109. package/dist/formats/webgl/core/glsl/DxbcGlslEmitter.js +2678 -0
  110. package/dist/formats/webgl/core/glsl/DxbcGlslEmitter.js.map +1 -0
  111. package/dist/formats/webgl/core/glsl/DxbcGlslHelpers.js +89 -0
  112. package/dist/formats/webgl/core/glsl/DxbcGlslHelpers.js.map +1 -0
  113. package/dist/formats/webgl/core/glsl/DxbcGlslOperandFormatter.js +428 -0
  114. package/dist/formats/webgl/core/glsl/DxbcGlslOperandFormatter.js.map +1 -0
  115. package/dist/formats/webgl/core/helpers.js +306 -0
  116. package/dist/formats/webgl/core/helpers.js.map +1 -0
  117. package/dist/formats/webgl/index.js +2 -0
  118. package/dist/formats/webgl/index.js.map +1 -0
  119. package/dist/formats/webgpu/CjsWebgpuFormat.js +376 -0
  120. package/dist/formats/webgpu/CjsWebgpuFormat.js.map +1 -0
  121. package/dist/formats/webgpu/core/cewgpu/CewgpuPackage.js +415 -0
  122. package/dist/formats/webgpu/core/cewgpu/CewgpuPackage.js.map +1 -0
  123. package/dist/formats/webgpu/core/cewgpu/CewgpuPackageBuilder.js +100 -0
  124. package/dist/formats/webgpu/core/cewgpu/CewgpuPackageBuilder.js.map +1 -0
  125. package/dist/formats/webgpu/core/cewgpu/binary.js +93 -0
  126. package/dist/formats/webgpu/core/cewgpu/binary.js.map +1 -0
  127. package/dist/formats/webgpu/core/cewgpu/tags.js +17 -0
  128. package/dist/formats/webgpu/core/cewgpu/tags.js.map +1 -0
  129. package/dist/formats/webgpu/core/effectAnalysis.js +82 -0
  130. package/dist/formats/webgpu/core/effectAnalysis.js.map +1 -0
  131. package/dist/formats/webgpu/core/effectBackendBodySet.js +305 -0
  132. package/dist/formats/webgpu/core/effectBackendBodySet.js.map +1 -0
  133. package/dist/formats/webgpu/core/effectPackageValidation.js +1078 -0
  134. package/dist/formats/webgpu/core/effectPackageValidation.js.map +1 -0
  135. package/dist/formats/webgpu/core/errors.js +20 -0
  136. package/dist/formats/webgpu/core/errors.js.map +1 -0
  137. package/dist/formats/webgpu/core/helpers.js +448 -0
  138. package/dist/formats/webgpu/core/helpers.js.map +1 -0
  139. package/dist/formats/webgpu/core/ir/analyzeRegisterValues.js +223 -0
  140. package/dist/formats/webgpu/core/ir/analyzeRegisterValues.js.map +1 -0
  141. package/dist/formats/webgpu/core/ir/buildControlFlow.js +220 -0
  142. package/dist/formats/webgpu/core/ir/buildControlFlow.js.map +1 -0
  143. package/dist/formats/webgpu/core/ir/indexableTemps.js +137 -0
  144. package/dist/formats/webgpu/core/ir/indexableTemps.js.map +1 -0
  145. package/dist/formats/webgpu/core/ir/inferValueTypes.js +454 -0
  146. package/dist/formats/webgpu/core/ir/inferValueTypes.js.map +1 -0
  147. package/dist/formats/webgpu/core/ir/lowerDxbcToIr.js +494 -0
  148. package/dist/formats/webgpu/core/ir/lowerDxbcToIr.js.map +1 -0
  149. package/dist/formats/webgpu/core/ir/resolveRegisterFlow.js +177 -0
  150. package/dist/formats/webgpu/core/ir/resolveRegisterFlow.js.map +1 -0
  151. package/dist/formats/webgpu/core/ir/sourceLanes.js +61 -0
  152. package/dist/formats/webgpu/core/ir/sourceLanes.js.map +1 -0
  153. package/dist/formats/webgpu/core/packageEffect.js +300 -0
  154. package/dist/formats/webgpu/core/packageEffect.js.map +1 -0
  155. package/dist/formats/webgpu/core/packageEffectSelection.js +164 -0
  156. package/dist/formats/webgpu/core/packageEffectSelection.js.map +1 -0
  157. package/dist/formats/webgpu/core/packageMetadata.js +8 -0
  158. package/dist/formats/webgpu/core/packageMetadata.js.map +1 -0
  159. package/dist/formats/webgpu/core/schema.js +4 -0
  160. package/dist/formats/webgpu/core/schema.js.map +1 -0
  161. package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js +275 -0
  162. package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js.map +1 -0
  163. package/dist/formats/webgpu/core/wgsl/buildWgslBindingPlan.js +182 -0
  164. package/dist/formats/webgpu/core/wgsl/buildWgslBindingPlan.js.map +1 -0
  165. package/dist/formats/webgpu/core/wgsl/buildWgslSet.js +324 -0
  166. package/dist/formats/webgpu/core/wgsl/buildWgslSet.js.map +1 -0
  167. package/dist/formats/webgpu/core/wgsl/emitWgsl.js +356 -0
  168. package/dist/formats/webgpu/core/wgsl/emitWgsl.js.map +1 -0
  169. package/dist/formats/webgpu/core/wgsl/hoistEscapingValues.js +77 -0
  170. package/dist/formats/webgpu/core/wgsl/hoistEscapingValues.js.map +1 -0
  171. package/dist/formats/webgpu/core/wgsl/lowerBindingLayout.js +451 -0
  172. package/dist/formats/webgpu/core/wgsl/lowerBindingLayout.js.map +1 -0
  173. package/dist/formats/webgpu/core/wgsl/lowerComputeProgram.js +754 -0
  174. package/dist/formats/webgpu/core/wgsl/lowerComputeProgram.js.map +1 -0
  175. package/dist/formats/webgpu/core/wgsl/lowerCreateHistogramsComputeProgram.js +457 -0
  176. package/dist/formats/webgpu/core/wgsl/lowerCreateHistogramsComputeProgram.js.map +1 -0
  177. package/dist/formats/webgpu/core/wgsl/lowerFragmentProgram.js +1572 -0
  178. package/dist/formats/webgpu/core/wgsl/lowerFragmentProgram.js.map +1 -0
  179. package/dist/formats/webgpu/core/wgsl/lowerMergeHistogramsComputeProgram.js +659 -0
  180. package/dist/formats/webgpu/core/wgsl/lowerMergeHistogramsComputeProgram.js.map +1 -0
  181. package/dist/formats/webgpu/core/wgsl/lowerParticleClearComputePrograms.js +734 -0
  182. package/dist/formats/webgpu/core/wgsl/lowerParticleClearComputePrograms.js.map +1 -0
  183. package/dist/formats/webgpu/core/wgsl/lowerParticleEmitComputeProgram.js +583 -0
  184. package/dist/formats/webgpu/core/wgsl/lowerParticleEmitComputeProgram.js.map +1 -0
  185. package/dist/formats/webgpu/core/wgsl/lowerSkinVerticesComputeProgram.js +621 -0
  186. package/dist/formats/webgpu/core/wgsl/lowerSkinVerticesComputeProgram.js.map +1 -0
  187. package/dist/formats/webgpu/core/wgsl/lowerSortComputeProgram.js +824 -0
  188. package/dist/formats/webgpu/core/wgsl/lowerSortComputeProgram.js.map +1 -0
  189. package/dist/formats/webgpu/core/wgsl/lowerSortInnerComputeProgram.js +697 -0
  190. package/dist/formats/webgpu/core/wgsl/lowerSortInnerComputeProgram.js.map +1 -0
  191. package/dist/formats/webgpu/core/wgsl/lowerSortStepComputeProgram.js +559 -0
  192. package/dist/formats/webgpu/core/wgsl/lowerSortStepComputeProgram.js.map +1 -0
  193. package/dist/formats/webgpu/core/wgsl/lowerVertexProgram.js +1328 -0
  194. package/dist/formats/webgpu/core/wgsl/lowerVertexProgram.js.map +1 -0
  195. package/dist/formats/webgpu/core/wgsl/particleEmitSemanticDigest.js +110 -0
  196. package/dist/formats/webgpu/core/wgsl/particleEmitSemanticDigest.js.map +1 -0
  197. package/dist/formats/webgpu/core/wgsl/precisionControls.js +55 -0
  198. package/dist/formats/webgpu/core/wgsl/precisionControls.js.map +1 -0
  199. package/dist/formats/webgpu/core/wgsl/selectionPlans.js +758 -0
  200. package/dist/formats/webgpu/core/wgsl/selectionPlans.js.map +1 -0
  201. package/dist/formats/webgpu/core/wgsl/uniformity.js +78 -0
  202. package/dist/formats/webgpu/core/wgsl/uniformity.js.map +1 -0
  203. package/dist/formats/webgpu/core/wgsl/validateExactComputeIr.js +196 -0
  204. package/dist/formats/webgpu/core/wgsl/validateExactComputeIr.js.map +1 -0
  205. package/dist/formats/webgpu/core/wgsl/validateHandleOperand.js +37 -0
  206. package/dist/formats/webgpu/core/wgsl/validateHandleOperand.js.map +1 -0
  207. package/dist/formats/webgpu/index.js +2 -0
  208. package/dist/formats/webgpu/index.js.map +1 -0
  209. package/dist/resource/shader/Tr2EffectRes.js +159 -150
  210. package/dist/resource/shader/Tr2EffectRes.js.map +1 -1
  211. package/dist/resource/shader/Tr2MaterialArea.js +23 -28
  212. package/dist/resource/shader/Tr2MaterialArea.js.map +1 -1
  213. package/dist/resource/shader/Tr2MaterialMesh.js +21 -27
  214. package/dist/resource/shader/Tr2MaterialMesh.js.map +1 -1
  215. package/dist/resource/shader/Tr2MaterialRes.js +24 -29
  216. package/dist/resource/shader/Tr2MaterialRes.js.map +1 -1
  217. package/dist/resource/shader/Tr2Shader.js +45 -39
  218. package/dist/resource/shader/Tr2Shader.js.map +1 -1
  219. package/dist/resource/shader/Tr2ShaderPermutation.js +30 -32
  220. package/dist/resource/shader/Tr2ShaderPermutation.js.map +1 -1
  221. package/dist/resource/shader/reflection/Tr2EffectConstant.js +113 -78
  222. package/dist/resource/shader/reflection/Tr2EffectConstant.js.map +1 -1
  223. package/dist/resource/shader/reflection/Tr2EffectDefine.js +17 -23
  224. package/dist/resource/shader/reflection/Tr2EffectDefine.js.map +1 -1
  225. package/dist/resource/shader/reflection/Tr2EffectDescription.js +23 -29
  226. package/dist/resource/shader/reflection/Tr2EffectDescription.js.map +1 -1
  227. package/dist/resource/shader/reflection/Tr2EffectLibrary.js +44 -40
  228. package/dist/resource/shader/reflection/Tr2EffectLibrary.js.map +1 -1
  229. package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js +82 -86
  230. package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js.map +1 -1
  231. package/dist/resource/shader/reflection/Tr2EffectResource.js +55 -61
  232. package/dist/resource/shader/reflection/Tr2EffectResource.js.map +1 -1
  233. package/dist/resource/shader/reflection/Tr2EffectStageInput.js +49 -45
  234. package/dist/resource/shader/reflection/Tr2EffectStageInput.js.map +1 -1
  235. package/dist/resource/shader/reflection/Tr2EffectTechnique.js +25 -30
  236. package/dist/resource/shader/reflection/Tr2EffectTechnique.js.map +1 -1
  237. package/dist/resource/shader/reflection/Tr2Pass.js +30 -32
  238. package/dist/resource/shader/reflection/Tr2Pass.js.map +1 -1
  239. package/dist/resource/shader/sampler/Tr2SamplerSetup.js +21 -26
  240. package/dist/resource/shader/sampler/Tr2SamplerSetup.js.map +1 -1
  241. package/docs/formats/README.md +4 -0
  242. package/docs/formats/provenance.md +11 -3
  243. package/docs/reference/classes/formats.md +440 -0
  244. package/format-notices/dxbc/LICENSE +21 -0
  245. package/format-notices/dxbc/NOTICE +20 -0
  246. package/format-notices/hlsl/LICENSE +21 -0
  247. package/format-notices/hlsl/NOTICE +25 -0
  248. package/format-notices/webgl/LICENSE +21 -0
  249. package/format-notices/webgl/NOTICE +35 -0
  250. package/format-notices/webgpu/LICENSE +21 -0
  251. package/format-notices/webgpu/NOTICE +31 -0
  252. package/package.json +6 -1
  253. package/dist/resource/shader/portableValidation.js +0 -461
  254. package/dist/resource/shader/portableValidation.js.map +0 -1
@@ -0,0 +1,451 @@
1
+ import { normalizeResourceTransformPlan } from './buildResourceTransformPlan.js';
2
+
3
+ const KIND_ORDER = Object.freeze({
4
+ "uniform-buffer": 0,
5
+ "sampled-resource": 1,
6
+ sampler: 2,
7
+ "storage-resource": 3
8
+ });
9
+ const KIND_PREFIX = Object.freeze({
10
+ "uniform-buffer": "cb",
11
+ "sampled-resource": "t",
12
+ sampler: "s",
13
+ "storage-resource": "u"
14
+ });
15
+ const STAGE_VISIBILITY = Object.freeze({
16
+ vertex: "vertex",
17
+ pixel: "fragment",
18
+ compute: "compute"
19
+ });
20
+ const STAGES = Object.freeze(["vertex", "fragment", "compute"]);
21
+ const LEGACY_SHARED_STAGES = Object.freeze(["vertex", "fragment"]);
22
+ const IDENTITY_PATTERN = /^(uniform-buffer|sampled-resource|sampler|storage-resource):\d+:\d+$/u;
23
+ function bindingRegister(binding) {
24
+ return binding.range?.lowerBound ?? binding.registerIndex;
25
+ }
26
+ function bindingSpace(binding) {
27
+ return binding.range?.registerSpace ?? 0;
28
+ }
29
+ function bindingIdentity(binding) {
30
+ return `${binding.resourceKind}:${bindingSpace(binding)}:${bindingRegister(binding)}`;
31
+ }
32
+ function validateScopeIdentity(identity, scopeIdentity, stages) {
33
+ if (scopeIdentity === identity) return;
34
+ if (stages.length !== 1 || scopeIdentity !== `${identity}@${stages[0]}`) {
35
+ throw new Error(`WGSL binding plan contains invalid scope identity ${scopeIdentity || "<empty>"}`);
36
+ }
37
+ }
38
+ function bindingFingerprint(binding) {
39
+ return JSON.stringify({
40
+ resourceKind: binding.resourceKind,
41
+ generatedSymbol: binding.generatedSymbol,
42
+ registerSpace: binding.registerSpace,
43
+ registerIndex: binding.registerIndex,
44
+ type: binding.type,
45
+ transformId: binding.transformId ?? null,
46
+ arrayLayerCount: binding.arrayLayerCount ?? null,
47
+ structureStride: binding.structureStride ?? null,
48
+ buffer: binding.buffer || null,
49
+ texture: binding.texture || null,
50
+ sampler: binding.sampler || null
51
+ });
52
+ }
53
+ function declarationFor(program, binding) {
54
+ return program.declarations.find(entry => entry.dxbcOffset === binding.declarationOffset) || null;
55
+ }
56
+ function uniformLayout(program, binding) {
57
+ const declaration = declarationFor(program, binding);
58
+ const sizeInVec4 = declaration?.data?.sizeInVec4;
59
+ if (!Number.isInteger(sizeInVec4) || sizeInVec4 < 1) {
60
+ throw new Error(`WGSL uniform ${binding.id} has no positive vec4 size`);
61
+ }
62
+ if (binding.accessPattern !== "immediate_indexed" && binding.accessPattern !== "dynamic_indexed") {
63
+ throw new Error(`WGSL uniform ${binding.id} requires unsupported ${binding.accessPattern || "unknown"} indexing`);
64
+ }
65
+ return {
66
+ declaration: `var<uniform>`,
67
+ type: `array<vec4<f32>, ${sizeInVec4}>`,
68
+ buffer: {
69
+ type: "uniform",
70
+ hasDynamicOffset: false,
71
+ minBindingSize: sizeInVec4 * 16
72
+ }
73
+ };
74
+ }
75
+ const TEXTURE_DIMENSIONS = Object.freeze({
76
+ texture2d: {
77
+ type: "texture_2d<f32>",
78
+ viewDimension: "2d"
79
+ },
80
+ texturecube: {
81
+ type: "texture_cube<f32>",
82
+ viewDimension: "cube"
83
+ },
84
+ texture3d: {
85
+ type: "texture_3d<f32>",
86
+ viewDimension: "3d"
87
+ },
88
+ texture2darray: {
89
+ type: "texture_2d_array<f32>",
90
+ viewDimension: "2d-array"
91
+ }
92
+ });
93
+ function textureLayout(binding) {
94
+ const dimension = TEXTURE_DIMENSIONS[binding.resourceDimension];
95
+ if (!dimension) {
96
+ throw new Error(`WGSL sampled resource ${binding.id} has unsupported dimension ${binding.resourceDimension}`);
97
+ }
98
+ const returns = binding.returnType?.returnTypeNames || [];
99
+ if (returns.length !== 4 || returns.some(entry => entry !== "float")) {
100
+ throw new Error(`WGSL sampled resource ${binding.id} requires a float4 return type`);
101
+ }
102
+ return {
103
+ declaration: "var",
104
+ type: dimension.type,
105
+ texture: {
106
+ sampleType: "float",
107
+ viewDimension: dimension.viewDimension,
108
+ multisampled: false
109
+ }
110
+ };
111
+ }
112
+ function structuredBufferLayout(binding) {
113
+ const stride = binding.structureStride;
114
+ if (!Number.isInteger(stride) || stride < 4 || stride % 4 !== 0) {
115
+ throw new Error(`WGSL structured resource ${binding.id} requires a positive DWORD-aligned stride`);
116
+ }
117
+ if (binding.resourceDimension !== null || binding.returnType !== null) {
118
+ throw new Error(`WGSL structured resource ${binding.id} has unexpected typed-resource metadata`);
119
+ }
120
+ return {
121
+ declaration: "var<storage, read>",
122
+ type: "array<u32>",
123
+ structureStride: stride,
124
+ buffer: {
125
+ type: "read-only-storage",
126
+ hasDynamicOffset: false,
127
+ minBindingSize: stride
128
+ }
129
+ };
130
+ }
131
+ function typedBufferLayout(program, binding) {
132
+ if (binding.structureStride !== null && binding.structureStride !== undefined) {
133
+ throw new Error(`WGSL typed buffer resource ${binding.id} has unexpected structured-resource metadata`);
134
+ }
135
+ const returns = binding.returnType?.returnTypeNames || [];
136
+ if (program.stage === "compute") {
137
+ const component = returns.length === 4 && returns.every(entry => entry === returns[0]) ? {
138
+ sint: "i32",
139
+ uint: "u32"
140
+ }[returns[0]] : null;
141
+ if (!component) {
142
+ throw new Error(`WGSL compute typed buffer resource ${binding.id} return type is not supported; bounded scalar-word profiles require uniform sint or uint components`);
143
+ }
144
+ return {
145
+ declaration: "var<storage, read>",
146
+ type: `array<${component}>`,
147
+ buffer: {
148
+ type: "read-only-storage",
149
+ hasDynamicOffset: false,
150
+ minBindingSize: 4
151
+ }
152
+ };
153
+ }
154
+ throw new Error(`WGSL typed buffer resource ${binding.id} is not supported in the ${program.stage} stage without explicit bound-view format metadata`);
155
+ }
156
+ function sampledResourceLayout(program, binding) {
157
+ if (binding.resourceDimension === "buffer") return typedBufferLayout(program, binding);
158
+ return binding.structureStride === null || binding.structureStride === undefined ? textureLayout(binding) : structuredBufferLayout(binding);
159
+ }
160
+ function uavBufferLayout(program, binding, policy) {
161
+ // Writable storage is admitted for fragment and compute shaders. Vertex
162
+ // storage writes remain outside the current portability contract.
163
+ if (program.stage !== "pixel" && program.stage !== "compute") {
164
+ throw new Error(`WGSL storage resource ${binding.id} is not supported in the ${program.stage} stage`);
165
+ }
166
+ if (binding.structureStride !== null && binding.structureStride !== undefined) {
167
+ const stride = binding.structureStride;
168
+ if (program.stage !== "compute") {
169
+ throw new Error(`WGSL structured storage resource ${binding.id} is not supported in the ${program.stage} stage`);
170
+ }
171
+ if (!Number.isInteger(stride) || stride < 4 || stride % 4 !== 0) {
172
+ throw new Error(`WGSL structured storage resource ${binding.id} requires a positive DWORD-aligned stride`);
173
+ }
174
+ if (binding.resourceDimension !== null || binding.returnType !== null) {
175
+ throw new Error(`WGSL structured storage resource ${binding.id} has unexpected typed-resource metadata`);
176
+ }
177
+ return {
178
+ declaration: "var<storage, read_write>",
179
+ type: "array<u32>",
180
+ structureStride: stride,
181
+ buffer: {
182
+ type: "storage",
183
+ hasDynamicOffset: false,
184
+ minBindingSize: stride
185
+ }
186
+ };
187
+ }
188
+ const returns = binding.returnType?.returnTypeNames || [];
189
+ const identity = `storage-resource:${bindingSpace(binding)}:${bindingRegister(binding)}`;
190
+ const signedAtomic = policy.signedAtomicI32Identities.has(identity);
191
+ const scalar = signedAtomic ? "sint" : "uint";
192
+ if (binding.resourceDimension !== "buffer" || returns.length !== 4 || returns.some(entry => entry !== scalar)) {
193
+ throw new Error(`WGSL storage resource ${binding.id} shape is not supported; ` + (signedAtomic ? "the exact profile requires a uniform sint typed buffer UAV" : "only typed uint buffer UAVs are supported"));
194
+ }
195
+ return {
196
+ declaration: "var<storage, read_write>",
197
+ type: `array<atomic<${signedAtomic ? "i32" : "u32"}>>`,
198
+ buffer: {
199
+ type: "storage",
200
+ hasDynamicOffset: false,
201
+ minBindingSize: 4
202
+ }
203
+ };
204
+ }
205
+ function samplerLayout(program, binding) {
206
+ const declaration = declarationFor(program, binding);
207
+ const mode = declaration?.data?.samplerModeName;
208
+ if (mode && mode !== "default") {
209
+ throw new Error(`WGSL sampler ${binding.id} has unsupported mode ${mode}`);
210
+ }
211
+ return {
212
+ declaration: "var",
213
+ type: "sampler",
214
+ sampler: {
215
+ type: "filtering"
216
+ }
217
+ };
218
+ }
219
+ function lowerOne(program, binding, bindingIndex, policy) {
220
+ const registerIndex = bindingRegister(binding);
221
+ const registerSpace = bindingSpace(binding);
222
+ if (!Number.isInteger(registerIndex) || registerIndex < 0 || !Number.isInteger(registerSpace) || registerSpace < 0) {
223
+ throw new Error(`WGSL binding ${binding.id} has an unresolved register identity`);
224
+ }
225
+ if (binding.range?.unbounded || binding.range?.registerCount !== 1) {
226
+ throw new Error(`WGSL binding ${binding.id} requires an unsupported array or unbounded range`);
227
+ }
228
+ let layout;
229
+ if (binding.resourceKind === "uniform-buffer") layout = uniformLayout(program, binding);else if (binding.resourceKind === "sampled-resource") layout = sampledResourceLayout(program, binding);else if (binding.resourceKind === "sampler") layout = samplerLayout(program, binding);else if (binding.resourceKind === "storage-resource") {
230
+ layout = uavBufferLayout(program, binding, policy);
231
+ } else throw new Error(`WGSL binding ${binding.id} has unsupported kind ${binding.resourceKind}`);
232
+ const identity = `${binding.resourceKind}:${registerSpace}:${registerIndex}`;
233
+ const visibility = STAGE_VISIBILITY[program.stage];
234
+ if (!visibility) throw new Error(`WGSL binding ${binding.id} has unsupported stage ${program.stage || "unknown"}`);
235
+ return {
236
+ kind: "wgsl-binding",
237
+ id: binding.id,
238
+ identity,
239
+ scopeIdentity: `${identity}@${visibility}`,
240
+ resourceKind: binding.resourceKind,
241
+ generatedSymbol: `${KIND_PREFIX[binding.resourceKind]}${registerIndex}${registerSpace ? `_space${registerSpace}` : ""}`,
242
+ registerSpace,
243
+ registerIndex,
244
+ rangeId: binding.range?.rangeId ?? null,
245
+ group: 0,
246
+ binding: bindingIndex,
247
+ visibility,
248
+ declarationOffset: binding.declarationOffset,
249
+ ...(typeof binding.transformId === "string" ? {
250
+ transformId: binding.transformId,
251
+ arrayLayerCount: binding.arrayLayerCount
252
+ } : {}),
253
+ ...layout
254
+ };
255
+ }
256
+ function deepFreeze(value) {
257
+ if (!value || typeof value !== "object" || Object.isFrozen(value)) return value;
258
+ for (const entry of Object.values(value)) deepFreeze(entry);
259
+ return Object.freeze(value);
260
+ }
261
+ function normalizeBindingPlan(plan, stage) {
262
+ if (plan === null || plan === undefined) return null;
263
+ if (plan?.format !== "CJS_WGSL_BINDING_PLAN" || ![1, 2, 3].includes(plan.formatVersion) || !Array.isArray(plan.bindings)) {
264
+ throw new TypeError("WGSL binding plan must be a CJS_WGSL_BINDING_PLAN version 1, 2, or 3 document");
265
+ }
266
+ const resourceTransformPlan = plan.resourceTransforms === undefined ? null : normalizeResourceTransformPlan({
267
+ format: "CJS_WGSL_RESOURCE_TRANSFORM_PLAN",
268
+ formatVersion: 1,
269
+ resourceTransforms: plan.resourceTransforms
270
+ });
271
+ if (plan.formatVersion === 3 !== Boolean(resourceTransformPlan)) {
272
+ throw new Error("WGSL binding plan version 3 requires resource transforms, and earlier versions cannot contain them");
273
+ }
274
+ const visibility = STAGE_VISIBILITY[stage];
275
+ if (!visibility) throw new Error(`WGSL binding plan cannot target unsupported stage ${stage || "unknown"}`);
276
+ const requestedShared = plan.sharedIdentities === undefined ? [] : plan.sharedIdentities;
277
+ if (!Array.isArray(requestedShared) || requestedShared.some(entry => typeof entry !== "string" || !IDENTITY_PATTERN.test(entry)) || new Set(requestedShared).size !== requestedShared.length) {
278
+ throw new Error("WGSL binding plan contains invalid shared identities");
279
+ }
280
+ const sharedIdentities = new Set(requestedShared);
281
+ const confirmedShared = new Set();
282
+ const identities = new Map(STAGES.map(name => [name, new Map()]));
283
+ const scopeIdentities = new Set();
284
+ const slots = new Map();
285
+ for (const entry of plan.bindings) {
286
+ const identity = bindingIdentity(entry);
287
+ const stages = plan.formatVersion === 1 ? sharedIdentities.has(identity) ? LEGACY_SHARED_STAGES : [visibility] : entry.stages;
288
+ const scopeIdentity = plan.formatVersion === 1 ? sharedIdentities.has(identity) ? identity : `${identity}@${visibility}` : entry.scopeIdentity;
289
+ if (!IDENTITY_PATTERN.test(identity) || entry.identity !== identity || !Array.isArray(stages) || !stages.length || stages.some(name => !STAGES.includes(name)) || new Set(stages).size !== stages.length || !Number.isInteger(entry.group) || entry.group < 0 || !Number.isInteger(entry.binding) || entry.binding < 0) {
290
+ throw new Error(`WGSL binding plan contains an invalid entry ${entry.identity || identity}`);
291
+ }
292
+ validateScopeIdentity(identity, scopeIdentity, stages);
293
+ if (stages.length > 1) {
294
+ if (scopeIdentity !== identity || !sharedIdentities.has(identity)) {
295
+ throw new Error(`WGSL binding plan shares unconfirmed identity ${identity}`);
296
+ }
297
+ confirmedShared.add(identity);
298
+ } else if (sharedIdentities.has(identity)) {
299
+ throw new Error(`WGSL shared identity ${identity} does not cover multiple stages`);
300
+ } else if (plan.formatVersion >= 2 && scopeIdentity === identity) {
301
+ throw new Error(`WGSL binding plan uses unshared base identity ${identity}`);
302
+ }
303
+ if (scopeIdentities.has(scopeIdentity)) {
304
+ throw new Error(`WGSL binding plan contains duplicate scope identity ${scopeIdentity}`);
305
+ }
306
+ scopeIdentities.add(scopeIdentity);
307
+ const normalizedEntry = plan.formatVersion === 1 ? {
308
+ ...entry,
309
+ identity,
310
+ scopeIdentity
311
+ } : entry;
312
+ for (const name of stages) {
313
+ if (identities.get(name).has(identity)) {
314
+ throw new Error(`WGSL binding plan contains overlapping ${name} identity ${identity}`);
315
+ }
316
+ identities.get(name).set(identity, normalizedEntry);
317
+ }
318
+ const slot = `${entry.group}:${entry.binding}`;
319
+ if (slots.has(slot)) throw new Error(`WGSL binding plan assigns ${slot} to multiple scope identities`);
320
+ slots.set(slot, scopeIdentity);
321
+ }
322
+ for (const identity of sharedIdentities) {
323
+ if (!confirmedShared.has(identity)) throw new Error(`WGSL binding plan does not contain shared identity ${identity}`);
324
+ }
325
+ return {
326
+ bindings: identities.get(visibility),
327
+ exactStageCoverage: plan.formatVersion >= 2,
328
+ resourceTransformPlan
329
+ };
330
+ }
331
+ function transformBindings(bindings, plan, stage) {
332
+ if (!plan) return bindings;
333
+ const transforms = plan.resourceTransforms.filter(transform => transform.stage === stage);
334
+ if (!transforms.length) return bindings;
335
+ const byIdentity = new Map(bindings.map(binding => [bindingIdentity(binding), binding]));
336
+ const inputs = new Map();
337
+ for (const transform of transforms) {
338
+ for (const input of transform.inputs) {
339
+ if (inputs.has(input.identity)) {
340
+ throw new Error(`WGSL resource transforms overlap ${input.identity}`);
341
+ }
342
+ if (!byIdentity.has(input.identity)) {
343
+ throw new Error(`WGSL resource transform ${transform.id} references missing ${input.identity}`);
344
+ }
345
+ inputs.set(input.identity, {
346
+ transform,
347
+ input
348
+ });
349
+ }
350
+ }
351
+ const output = [];
352
+ for (const binding of bindings) {
353
+ const identity = bindingIdentity(binding);
354
+ const mapped = inputs.get(identity);
355
+ if (!mapped) {
356
+ output.push(binding);
357
+ continue;
358
+ }
359
+ if (mapped.input.layer !== 0) continue;
360
+ const {
361
+ transform
362
+ } = mapped;
363
+ if (transform.output.identity !== identity || binding.resourceKind !== "sampled-resource" || binding.resourceDimension !== "texture2d" || binding.structureStride !== null) {
364
+ throw new Error(`WGSL resource transform ${transform.id} cannot replace ${identity}`);
365
+ }
366
+ output.push({
367
+ ...binding,
368
+ resourceDimension: "texture2darray",
369
+ transformId: transform.id,
370
+ arrayLayerCount: transform.output.layerCount
371
+ });
372
+ }
373
+ return output;
374
+ }
375
+ function normalizeLayoutPolicy(value) {
376
+ if (value === undefined || value === null) {
377
+ return {
378
+ signedAtomicI32Identities: new Set()
379
+ };
380
+ }
381
+ if (!value || typeof value !== "object" || Array.isArray(value) || Object.keys(value).length !== 1 || !Array.isArray(value.signedAtomicI32Identities) || value.signedAtomicI32Identities.some(identity => typeof identity !== "string" || !/^storage-resource:\d+:\d+$/u.test(identity)) || new Set(value.signedAtomicI32Identities).size !== value.signedAtomicI32Identities.length) {
382
+ throw new TypeError("WGSL binding layout profile policy must contain unique signedAtomicI32Identities");
383
+ }
384
+ return {
385
+ signedAtomicI32Identities: new Set(value.signedAtomicI32Identities)
386
+ };
387
+ }
388
+
389
+ /**
390
+ * Converts D3D register declarations to one deterministic WebGPU bind group.
391
+ * Register spaces participate in ordering and identity; SM 5.1 range ids are
392
+ * deliberately not treated as globally unique bindings.
393
+ *
394
+ * @param {object} program Frozen CJS shader IR.
395
+ * @param {object|null} [bindingPlan] Optional pass-global canonical binding plan.
396
+ * @param {object|null} [layoutPolicy] Exact-profile-only typed-layout policy.
397
+ * @param {object|null} [resourceTransformPlan] Validated physical-resource overlay.
398
+ * @returns {object[]} Frozen WebGPU binding records.
399
+ */
400
+ function lowerBindingLayout(program, bindingPlan = null, layoutPolicy = null, resourceTransformPlan = null) {
401
+ if (program?.format !== "CJS_SHADER_IR" || program.formatVersion !== 1) {
402
+ throw new TypeError("WGSL binding lowering expects CJS_SHADER_IR version 1 input");
403
+ }
404
+ const policy = normalizeLayoutPolicy(layoutPolicy);
405
+ const planned = normalizeBindingPlan(bindingPlan, program.stage);
406
+ const explicitTransforms = normalizeResourceTransformPlan(resourceTransformPlan);
407
+ if (planned?.resourceTransformPlan && explicitTransforms && JSON.stringify(planned.resourceTransformPlan) !== JSON.stringify(explicitTransforms)) {
408
+ throw new Error("WGSL binding plan and explicit resource transform plan disagree");
409
+ }
410
+ const transforms = planned?.resourceTransformPlan || explicitTransforms;
411
+ const sorted = transformBindings(Array.from(program.bindings).sort((left, right) => bindingSpace(left) - bindingSpace(right) || (KIND_ORDER[left.resourceKind] ?? 99) - (KIND_ORDER[right.resourceKind] ?? 99) || bindingRegister(left) - bindingRegister(right) || left.declarationOffset - right.declarationOffset), transforms, STAGE_VISIBILITY[program.stage]);
412
+ const identities = new Set();
413
+ for (const binding of sorted) {
414
+ const identity = `${binding.resourceKind}:${bindingSpace(binding)}:${bindingRegister(binding)}`;
415
+ if (identities.has(identity)) throw new Error(`WGSL binding layout contains duplicate ${identity}`);
416
+ identities.add(identity);
417
+ }
418
+ const lowered = sorted.map((binding, index) => lowerOne(program, binding, index, policy));
419
+ const symbols = new Map();
420
+ for (const binding of lowered) {
421
+ const identity = bindingIdentity(binding);
422
+ if (symbols.has(binding.generatedSymbol) && symbols.get(binding.generatedSymbol) !== identity) {
423
+ throw new Error(`WGSL binding layout uses ${binding.generatedSymbol} for multiple identities`);
424
+ }
425
+ symbols.set(binding.generatedSymbol, identity);
426
+ }
427
+ if (!planned) return deepFreeze(lowered);
428
+ if (planned.exactStageCoverage && planned.bindings.size !== lowered.length) {
429
+ const declared = new Set(lowered.map(bindingIdentity));
430
+ const unexpected = Array.from(planned.bindings.keys()).find(identity => !declared.has(identity));
431
+ throw new Error(`WGSL binding plan contains unexpected ${lowered[0]?.visibility || STAGE_VISIBILITY[program.stage]} identity ${unexpected || "unknown"}`);
432
+ }
433
+ return deepFreeze(lowered.map(binding => {
434
+ const identity = bindingIdentity(binding);
435
+ const entry = planned.bindings.get(identity);
436
+ if (!entry) throw new Error(`WGSL binding plan does not contain ${identity}`);
437
+ if (bindingFingerprint(entry) !== bindingFingerprint(binding)) {
438
+ throw new Error(`WGSL binding plan layout for ${identity} does not match the shader declaration`);
439
+ }
440
+ return {
441
+ ...binding,
442
+ identity,
443
+ scopeIdentity: entry.scopeIdentity || identity,
444
+ group: entry.group,
445
+ binding: entry.binding
446
+ };
447
+ }));
448
+ }
449
+
450
+ export { lowerBindingLayout };
451
+ //# sourceMappingURL=lowerBindingLayout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lowerBindingLayout.js","sources":["../../../../../../src/formats/webgpu/core/wgsl/lowerBindingLayout.js"],"sourcesContent":["import { normalizeResourceTransformPlan } from \"./buildResourceTransformPlan.js\";\n\nconst KIND_ORDER = Object.freeze({\n \"uniform-buffer\": 0,\n \"sampled-resource\": 1,\n sampler: 2,\n \"storage-resource\": 3\n});\n\nconst KIND_PREFIX = Object.freeze({\n \"uniform-buffer\": \"cb\",\n \"sampled-resource\": \"t\",\n sampler: \"s\",\n \"storage-resource\": \"u\"\n});\n\nconst STAGE_VISIBILITY = Object.freeze({ vertex: \"vertex\", pixel: \"fragment\", compute: \"compute\" });\nconst STAGES = Object.freeze([ \"vertex\", \"fragment\", \"compute\" ]);\nconst LEGACY_SHARED_STAGES = Object.freeze([ \"vertex\", \"fragment\" ]);\nconst IDENTITY_PATTERN = /^(uniform-buffer|sampled-resource|sampler|storage-resource):\\d+:\\d+$/u;\n\nfunction bindingRegister(binding)\n{\n return binding.range?.lowerBound ?? binding.registerIndex;\n}\n\nfunction bindingSpace(binding)\n{\n return binding.range?.registerSpace ?? 0;\n}\n\nfunction bindingIdentity(binding)\n{\n return `${binding.resourceKind}:${bindingSpace(binding)}:${bindingRegister(binding)}`;\n}\n\nfunction validateScopeIdentity(identity, scopeIdentity, stages)\n{\n if (scopeIdentity === identity) return;\n if (stages.length !== 1 || scopeIdentity !== `${identity}@${stages[0]}`)\n {\n throw new Error(`WGSL binding plan contains invalid scope identity ${scopeIdentity || \"<empty>\"}`);\n }\n}\n\nfunction bindingFingerprint(binding)\n{\n return JSON.stringify({\n resourceKind: binding.resourceKind,\n generatedSymbol: binding.generatedSymbol,\n registerSpace: binding.registerSpace,\n registerIndex: binding.registerIndex,\n type: binding.type,\n transformId: binding.transformId ?? null,\n arrayLayerCount: binding.arrayLayerCount ?? null,\n structureStride: binding.structureStride ?? null,\n buffer: binding.buffer || null,\n texture: binding.texture || null,\n sampler: binding.sampler || null\n });\n}\n\nfunction declarationFor(program, binding)\n{\n return program.declarations.find((entry) => entry.dxbcOffset === binding.declarationOffset) || null;\n}\n\nfunction uniformLayout(program, binding)\n{\n const declaration = declarationFor(program, binding);\n const sizeInVec4 = declaration?.data?.sizeInVec4;\n if (!Number.isInteger(sizeInVec4) || sizeInVec4 < 1)\n {\n throw new Error(`WGSL uniform ${binding.id} has no positive vec4 size`);\n }\n if (binding.accessPattern !== \"immediate_indexed\" && binding.accessPattern !== \"dynamic_indexed\")\n {\n throw new Error(`WGSL uniform ${binding.id} requires unsupported ${binding.accessPattern || \"unknown\"} indexing`);\n }\n return {\n declaration: `var<uniform>`,\n type: `array<vec4<f32>, ${sizeInVec4}>`,\n buffer: {\n type: \"uniform\",\n hasDynamicOffset: false,\n minBindingSize: sizeInVec4 * 16\n }\n };\n}\n\nconst TEXTURE_DIMENSIONS = Object.freeze({\n texture2d: { type: \"texture_2d<f32>\", viewDimension: \"2d\" },\n texturecube: { type: \"texture_cube<f32>\", viewDimension: \"cube\" },\n texture3d: { type: \"texture_3d<f32>\", viewDimension: \"3d\" },\n texture2darray: { type: \"texture_2d_array<f32>\", viewDimension: \"2d-array\" }\n});\n\nfunction textureLayout(binding)\n{\n const dimension = TEXTURE_DIMENSIONS[binding.resourceDimension];\n if (!dimension)\n {\n throw new Error(`WGSL sampled resource ${binding.id} has unsupported dimension ${binding.resourceDimension}`);\n }\n const returns = binding.returnType?.returnTypeNames || [];\n if (returns.length !== 4 || returns.some((entry) => entry !== \"float\"))\n {\n throw new Error(`WGSL sampled resource ${binding.id} requires a float4 return type`);\n }\n return {\n declaration: \"var\",\n type: dimension.type,\n texture: {\n sampleType: \"float\",\n viewDimension: dimension.viewDimension,\n multisampled: false\n }\n };\n}\n\nfunction structuredBufferLayout(binding)\n{\n const stride = binding.structureStride;\n if (!Number.isInteger(stride) || stride < 4 || stride % 4 !== 0)\n {\n throw new Error(`WGSL structured resource ${binding.id} requires a positive DWORD-aligned stride`);\n }\n if (binding.resourceDimension !== null || binding.returnType !== null)\n {\n throw new Error(`WGSL structured resource ${binding.id} has unexpected typed-resource metadata`);\n }\n return {\n declaration: \"var<storage, read>\",\n type: \"array<u32>\",\n structureStride: stride,\n buffer: {\n type: \"read-only-storage\",\n hasDynamicOffset: false,\n minBindingSize: stride\n }\n };\n}\n\nfunction typedBufferLayout(program, binding)\n{\n if (binding.structureStride !== null && binding.structureStride !== undefined)\n {\n throw new Error(`WGSL typed buffer resource ${binding.id} has unexpected structured-resource metadata`);\n }\n const returns = binding.returnType?.returnTypeNames || [];\n if (program.stage === \"compute\")\n {\n const component = returns.length === 4 && returns.every((entry) => entry === returns[0])\n ? { sint: \"i32\", uint: \"u32\" }[returns[0]]\n : null;\n if (!component)\n {\n throw new Error(`WGSL compute typed buffer resource ${binding.id} return type is not supported; bounded scalar-word profiles require uniform sint or uint components`);\n }\n return {\n declaration: \"var<storage, read>\",\n type: `array<${component}>`,\n buffer: {\n type: \"read-only-storage\",\n hasDynamicOffset: false,\n minBindingSize: 4\n }\n };\n }\n throw new Error(`WGSL typed buffer resource ${binding.id} is not supported in the ${program.stage} stage without explicit bound-view format metadata`);\n}\n\nfunction sampledResourceLayout(program, binding)\n{\n if (binding.resourceDimension === \"buffer\") return typedBufferLayout(program, binding);\n return binding.structureStride === null || binding.structureStride === undefined\n ? textureLayout(binding)\n : structuredBufferLayout(binding);\n}\n\nfunction uavBufferLayout(program, binding, policy)\n{\n // Writable storage is admitted for fragment and compute shaders. Vertex\n // storage writes remain outside the current portability contract.\n if (program.stage !== \"pixel\" && program.stage !== \"compute\")\n {\n throw new Error(`WGSL storage resource ${binding.id} is not supported in the ${program.stage} stage`);\n }\n if (binding.structureStride !== null && binding.structureStride !== undefined)\n {\n const stride = binding.structureStride;\n if (program.stage !== \"compute\")\n {\n throw new Error(`WGSL structured storage resource ${binding.id} is not supported in the ${program.stage} stage`);\n }\n if (!Number.isInteger(stride) || stride < 4 || stride % 4 !== 0)\n {\n throw new Error(`WGSL structured storage resource ${binding.id} requires a positive DWORD-aligned stride`);\n }\n if (binding.resourceDimension !== null || binding.returnType !== null)\n {\n throw new Error(`WGSL structured storage resource ${binding.id} has unexpected typed-resource metadata`);\n }\n return {\n declaration: \"var<storage, read_write>\",\n type: \"array<u32>\",\n structureStride: stride,\n buffer: {\n type: \"storage\",\n hasDynamicOffset: false,\n minBindingSize: stride\n }\n };\n }\n const returns = binding.returnType?.returnTypeNames || [];\n const identity = `storage-resource:${bindingSpace(binding)}:${bindingRegister(binding)}`;\n const signedAtomic = policy.signedAtomicI32Identities.has(identity);\n const scalar = signedAtomic ? \"sint\" : \"uint\";\n if (binding.resourceDimension !== \"buffer\"\n || returns.length !== 4 || returns.some((entry) => entry !== scalar))\n {\n throw new Error(\n `WGSL storage resource ${binding.id} shape is not supported; `\n + (signedAtomic\n ? \"the exact profile requires a uniform sint typed buffer UAV\"\n : \"only typed uint buffer UAVs are supported\")\n );\n }\n return {\n declaration: \"var<storage, read_write>\",\n type: `array<atomic<${signedAtomic ? \"i32\" : \"u32\"}>>`,\n buffer: {\n type: \"storage\",\n hasDynamicOffset: false,\n minBindingSize: 4\n }\n };\n}\n\nfunction samplerLayout(program, binding)\n{\n const declaration = declarationFor(program, binding);\n const mode = declaration?.data?.samplerModeName;\n if (mode && mode !== \"default\")\n {\n throw new Error(`WGSL sampler ${binding.id} has unsupported mode ${mode}`);\n }\n return {\n declaration: \"var\",\n type: \"sampler\",\n sampler: { type: \"filtering\" }\n };\n}\n\nfunction lowerOne(program, binding, bindingIndex, policy)\n{\n const registerIndex = bindingRegister(binding);\n const registerSpace = bindingSpace(binding);\n if (!Number.isInteger(registerIndex) || registerIndex < 0\n || !Number.isInteger(registerSpace) || registerSpace < 0)\n {\n throw new Error(`WGSL binding ${binding.id} has an unresolved register identity`);\n }\n if (binding.range?.unbounded || binding.range?.registerCount !== 1)\n {\n throw new Error(`WGSL binding ${binding.id} requires an unsupported array or unbounded range`);\n }\n let layout;\n if (binding.resourceKind === \"uniform-buffer\") layout = uniformLayout(program, binding);\n else if (binding.resourceKind === \"sampled-resource\") layout = sampledResourceLayout(program, binding);\n else if (binding.resourceKind === \"sampler\") layout = samplerLayout(program, binding);\n else if (binding.resourceKind === \"storage-resource\")\n {\n layout = uavBufferLayout(program, binding, policy);\n }\n else throw new Error(`WGSL binding ${binding.id} has unsupported kind ${binding.resourceKind}`);\n const identity = `${binding.resourceKind}:${registerSpace}:${registerIndex}`;\n const visibility = STAGE_VISIBILITY[program.stage];\n if (!visibility) throw new Error(`WGSL binding ${binding.id} has unsupported stage ${program.stage || \"unknown\"}`);\n return {\n kind: \"wgsl-binding\",\n id: binding.id,\n identity,\n scopeIdentity: `${identity}@${visibility}`,\n resourceKind: binding.resourceKind,\n generatedSymbol: `${KIND_PREFIX[binding.resourceKind]}${registerIndex}${registerSpace ? `_space${registerSpace}` : \"\"}`,\n registerSpace,\n registerIndex,\n rangeId: binding.range?.rangeId ?? null,\n group: 0,\n binding: bindingIndex,\n visibility,\n declarationOffset: binding.declarationOffset,\n ...(typeof binding.transformId === \"string\"\n ? {\n transformId: binding.transformId,\n arrayLayerCount: binding.arrayLayerCount\n }\n : {}),\n ...layout\n };\n}\n\nfunction deepFreeze(value)\n{\n if (!value || typeof value !== \"object\" || Object.isFrozen(value)) return value;\n for (const entry of Object.values(value)) deepFreeze(entry);\n return Object.freeze(value);\n}\n\nfunction normalizeBindingPlan(plan, stage)\n{\n if (plan === null || plan === undefined) return null;\n if (plan?.format !== \"CJS_WGSL_BINDING_PLAN\"\n || ![ 1, 2, 3 ].includes(plan.formatVersion)\n || !Array.isArray(plan.bindings))\n {\n throw new TypeError(\"WGSL binding plan must be a CJS_WGSL_BINDING_PLAN version 1, 2, or 3 document\");\n }\n const resourceTransformPlan = plan.resourceTransforms === undefined\n ? null\n : normalizeResourceTransformPlan({\n format: \"CJS_WGSL_RESOURCE_TRANSFORM_PLAN\",\n formatVersion: 1,\n resourceTransforms: plan.resourceTransforms\n });\n if ((plan.formatVersion === 3) !== Boolean(resourceTransformPlan))\n {\n throw new Error(\"WGSL binding plan version 3 requires resource transforms, and earlier versions cannot contain them\");\n }\n const visibility = STAGE_VISIBILITY[stage];\n if (!visibility) throw new Error(`WGSL binding plan cannot target unsupported stage ${stage || \"unknown\"}`);\n const requestedShared = plan.sharedIdentities === undefined ? [] : plan.sharedIdentities;\n if (!Array.isArray(requestedShared)\n || requestedShared.some((entry) => typeof entry !== \"string\" || !IDENTITY_PATTERN.test(entry))\n || new Set(requestedShared).size !== requestedShared.length)\n {\n throw new Error(\"WGSL binding plan contains invalid shared identities\");\n }\n const sharedIdentities = new Set(requestedShared);\n const confirmedShared = new Set();\n const identities = new Map(STAGES.map((name) => [ name, new Map() ]));\n const scopeIdentities = new Set();\n const slots = new Map();\n for (const entry of plan.bindings)\n {\n const identity = bindingIdentity(entry);\n const stages = plan.formatVersion === 1\n ? (sharedIdentities.has(identity) ? LEGACY_SHARED_STAGES : [ visibility ])\n : entry.stages;\n const scopeIdentity = plan.formatVersion === 1\n ? (sharedIdentities.has(identity) ? identity : `${identity}@${visibility}`)\n : entry.scopeIdentity;\n if (!IDENTITY_PATTERN.test(identity)\n || entry.identity !== identity\n || !Array.isArray(stages) || !stages.length\n || stages.some((name) => !STAGES.includes(name))\n || new Set(stages).size !== stages.length\n || !Number.isInteger(entry.group) || entry.group < 0\n || !Number.isInteger(entry.binding) || entry.binding < 0)\n {\n throw new Error(`WGSL binding plan contains an invalid entry ${entry.identity || identity}`);\n }\n validateScopeIdentity(identity, scopeIdentity, stages);\n if (stages.length > 1)\n {\n if (scopeIdentity !== identity || !sharedIdentities.has(identity))\n {\n throw new Error(`WGSL binding plan shares unconfirmed identity ${identity}`);\n }\n confirmedShared.add(identity);\n }\n else if (sharedIdentities.has(identity))\n {\n throw new Error(`WGSL shared identity ${identity} does not cover multiple stages`);\n }\n else if (plan.formatVersion >= 2 && scopeIdentity === identity)\n {\n throw new Error(`WGSL binding plan uses unshared base identity ${identity}`);\n }\n if (scopeIdentities.has(scopeIdentity))\n {\n throw new Error(`WGSL binding plan contains duplicate scope identity ${scopeIdentity}`);\n }\n scopeIdentities.add(scopeIdentity);\n const normalizedEntry = plan.formatVersion === 1\n ? { ...entry, identity, scopeIdentity }\n : entry;\n for (const name of stages)\n {\n if (identities.get(name).has(identity))\n {\n throw new Error(`WGSL binding plan contains overlapping ${name} identity ${identity}`);\n }\n identities.get(name).set(identity, normalizedEntry);\n }\n const slot = `${entry.group}:${entry.binding}`;\n if (slots.has(slot)) throw new Error(`WGSL binding plan assigns ${slot} to multiple scope identities`);\n slots.set(slot, scopeIdentity);\n }\n for (const identity of sharedIdentities)\n {\n if (!confirmedShared.has(identity)) throw new Error(`WGSL binding plan does not contain shared identity ${identity}`);\n }\n return {\n bindings: identities.get(visibility),\n exactStageCoverage: plan.formatVersion >= 2,\n resourceTransformPlan\n };\n}\n\nfunction transformBindings(bindings, plan, stage)\n{\n if (!plan) return bindings;\n const transforms = plan.resourceTransforms.filter((transform) =>\n transform.stage === stage);\n if (!transforms.length) return bindings;\n const byIdentity = new Map(bindings.map((binding) => [ bindingIdentity(binding), binding ]));\n const inputs = new Map();\n for (const transform of transforms)\n {\n for (const input of transform.inputs)\n {\n if (inputs.has(input.identity))\n {\n throw new Error(`WGSL resource transforms overlap ${input.identity}`);\n }\n if (!byIdentity.has(input.identity))\n {\n throw new Error(`WGSL resource transform ${transform.id} references missing ${input.identity}`);\n }\n inputs.set(input.identity, { transform, input });\n }\n }\n const output = [];\n for (const binding of bindings)\n {\n const identity = bindingIdentity(binding);\n const mapped = inputs.get(identity);\n if (!mapped)\n {\n output.push(binding);\n continue;\n }\n if (mapped.input.layer !== 0) continue;\n const { transform } = mapped;\n if (transform.output.identity !== identity\n || binding.resourceKind !== \"sampled-resource\"\n || binding.resourceDimension !== \"texture2d\"\n || binding.structureStride !== null)\n {\n throw new Error(`WGSL resource transform ${transform.id} cannot replace ${identity}`);\n }\n output.push({\n ...binding,\n resourceDimension: \"texture2darray\",\n transformId: transform.id,\n arrayLayerCount: transform.output.layerCount\n });\n }\n return output;\n}\n\nfunction normalizeLayoutPolicy(value)\n{\n if (value === undefined || value === null)\n {\n return { signedAtomicI32Identities: new Set() };\n }\n if (!value || typeof value !== \"object\" || Array.isArray(value)\n || Object.keys(value).length !== 1\n || !Array.isArray(value.signedAtomicI32Identities)\n || value.signedAtomicI32Identities.some((identity) =>\n typeof identity !== \"string\"\n || !/^storage-resource:\\d+:\\d+$/u.test(identity))\n || new Set(value.signedAtomicI32Identities).size\n !== value.signedAtomicI32Identities.length)\n {\n throw new TypeError(\n \"WGSL binding layout profile policy must contain unique signedAtomicI32Identities\"\n );\n }\n return {\n signedAtomicI32Identities: new Set(value.signedAtomicI32Identities)\n };\n}\n\n/**\n * Converts D3D register declarations to one deterministic WebGPU bind group.\n * Register spaces participate in ordering and identity; SM 5.1 range ids are\n * deliberately not treated as globally unique bindings.\n *\n * @param {object} program Frozen CJS shader IR.\n * @param {object|null} [bindingPlan] Optional pass-global canonical binding plan.\n * @param {object|null} [layoutPolicy] Exact-profile-only typed-layout policy.\n * @param {object|null} [resourceTransformPlan] Validated physical-resource overlay.\n * @returns {object[]} Frozen WebGPU binding records.\n */\nexport function lowerBindingLayout(\n program,\n bindingPlan = null,\n layoutPolicy = null,\n resourceTransformPlan = null\n)\n{\n if (program?.format !== \"CJS_SHADER_IR\" || program.formatVersion !== 1)\n {\n throw new TypeError(\"WGSL binding lowering expects CJS_SHADER_IR version 1 input\");\n }\n const policy = normalizeLayoutPolicy(layoutPolicy);\n const planned = normalizeBindingPlan(bindingPlan, program.stage);\n const explicitTransforms = normalizeResourceTransformPlan(resourceTransformPlan);\n if (planned?.resourceTransformPlan && explicitTransforms\n && JSON.stringify(planned.resourceTransformPlan) !== JSON.stringify(explicitTransforms))\n {\n throw new Error(\"WGSL binding plan and explicit resource transform plan disagree\");\n }\n const transforms = planned?.resourceTransformPlan || explicitTransforms;\n const sorted = transformBindings(Array.from(program.bindings).sort((left, right) =>\n bindingSpace(left) - bindingSpace(right)\n || (KIND_ORDER[left.resourceKind] ?? 99) - (KIND_ORDER[right.resourceKind] ?? 99)\n || bindingRegister(left) - bindingRegister(right)\n || left.declarationOffset - right.declarationOffset), transforms, STAGE_VISIBILITY[program.stage]);\n const identities = new Set();\n for (const binding of sorted)\n {\n const identity = `${binding.resourceKind}:${bindingSpace(binding)}:${bindingRegister(binding)}`;\n if (identities.has(identity)) throw new Error(`WGSL binding layout contains duplicate ${identity}`);\n identities.add(identity);\n }\n const lowered = sorted.map((binding, index) =>\n lowerOne(program, binding, index, policy));\n const symbols = new Map();\n for (const binding of lowered)\n {\n const identity = bindingIdentity(binding);\n if (symbols.has(binding.generatedSymbol) && symbols.get(binding.generatedSymbol) !== identity)\n {\n throw new Error(`WGSL binding layout uses ${binding.generatedSymbol} for multiple identities`);\n }\n symbols.set(binding.generatedSymbol, identity);\n }\n if (!planned) return deepFreeze(lowered);\n if (planned.exactStageCoverage && planned.bindings.size !== lowered.length)\n {\n const declared = new Set(lowered.map(bindingIdentity));\n const unexpected = Array.from(planned.bindings.keys()).find((identity) => !declared.has(identity));\n throw new Error(`WGSL binding plan contains unexpected ${lowered[0]?.visibility || STAGE_VISIBILITY[program.stage]} identity ${unexpected || \"unknown\"}`);\n }\n return deepFreeze(lowered.map((binding) =>\n {\n const identity = bindingIdentity(binding);\n const entry = planned.bindings.get(identity);\n if (!entry) throw new Error(`WGSL binding plan does not contain ${identity}`);\n if (bindingFingerprint(entry) !== bindingFingerprint(binding))\n {\n throw new Error(`WGSL binding plan layout for ${identity} does not match the shader declaration`);\n }\n return {\n ...binding,\n identity,\n scopeIdentity: entry.scopeIdentity || identity,\n group: entry.group,\n binding: entry.binding\n };\n }));\n}\n"],"names":["KIND_ORDER","Object","freeze","sampler","KIND_PREFIX","STAGE_VISIBILITY","vertex","pixel","compute","STAGES","LEGACY_SHARED_STAGES","IDENTITY_PATTERN","bindingRegister","binding","range","lowerBound","registerIndex","bindingSpace","registerSpace","bindingIdentity","resourceKind","validateScopeIdentity","identity","scopeIdentity","stages","length","Error","bindingFingerprint","JSON","stringify","generatedSymbol","type","transformId","arrayLayerCount","structureStride","buffer","texture","declarationFor","program","declarations","find","entry","dxbcOffset","declarationOffset","uniformLayout","declaration","sizeInVec4","data","Number","isInteger","id","accessPattern","hasDynamicOffset","minBindingSize","TEXTURE_DIMENSIONS","texture2d","viewDimension","texturecube","texture3d","texture2darray","textureLayout","dimension","resourceDimension","returns","returnType","returnTypeNames","some","sampleType","multisampled","structuredBufferLayout","stride","typedBufferLayout","undefined","stage","component","every","sint","uint","sampledResourceLayout","uavBufferLayout","policy","signedAtomic","signedAtomicI32Identities","has","scalar","samplerLayout","mode","samplerModeName","lowerOne","bindingIndex","unbounded","registerCount","layout","visibility","kind","rangeId","group","deepFreeze","value","isFrozen","values","normalizeBindingPlan","plan","format","includes","formatVersion","Array","isArray","bindings","TypeError","resourceTransformPlan","resourceTransforms","normalizeResourceTransformPlan","Boolean","requestedShared","sharedIdentities","test","Set","size","confirmedShared","identities","Map","map","name","scopeIdentities","slots","add","normalizedEntry","get","set","slot","exactStageCoverage","transformBindings","transforms","filter","transform","byIdentity","inputs","input","output","mapped","push","layer","layerCount","normalizeLayoutPolicy","keys","lowerBindingLayout","bindingPlan","layoutPolicy","planned","explicitTransforms","sorted","from","sort","left","right","lowered","index","symbols","declared","unexpected"],"mappings":";;AAEA,MAAMA,UAAU,GAAGC,MAAM,CAACC,MAAM,CAAC;AAC7B,EAAA,gBAAgB,EAAE,CAAC;AACnB,EAAA,kBAAkB,EAAE,CAAC;AACrBC,EAAAA,OAAO,EAAE,CAAC;AACV,EAAA,kBAAkB,EAAE;AACxB,CAAC,CAAC;AAEF,MAAMC,WAAW,GAAGH,MAAM,CAACC,MAAM,CAAC;AAC9B,EAAA,gBAAgB,EAAE,IAAI;AACtB,EAAA,kBAAkB,EAAE,GAAG;AACvBC,EAAAA,OAAO,EAAE,GAAG;AACZ,EAAA,kBAAkB,EAAE;AACxB,CAAC,CAAC;AAEF,MAAME,gBAAgB,GAAGJ,MAAM,CAACC,MAAM,CAAC;AAAEI,EAAAA,MAAM,EAAE,QAAQ;AAAEC,EAAAA,KAAK,EAAE,UAAU;AAAEC,EAAAA,OAAO,EAAE;AAAU,CAAC,CAAC;AACnG,MAAMC,MAAM,GAAGR,MAAM,CAACC,MAAM,CAAC,CAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,CAAE,CAAC;AACjE,MAAMQ,oBAAoB,GAAGT,MAAM,CAACC,MAAM,CAAC,CAAE,QAAQ,EAAE,UAAU,CAAE,CAAC;AACpE,MAAMS,gBAAgB,GAAG,uEAAuE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