@carbonenginejs/runtime-resource 0.9.2 → 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 (544) hide show
  1. package/NOTICE +3 -2
  2. package/README.md +47 -6
  3. package/dist/CjsMotherLode.js +88 -88
  4. package/dist/CjsMotherLode.js.map +1 -1
  5. package/dist/CjsResMan.js +717 -228
  6. package/dist/CjsResMan.js.map +1 -1
  7. package/dist/CjsResManFetchProvider.js +94 -0
  8. package/dist/CjsResManFetchProvider.js.map +1 -0
  9. package/dist/{CjsResManQueue.js → CjsResManWorkQueue.js} +112 -25
  10. package/dist/CjsResManWorkQueue.js.map +1 -0
  11. package/dist/format/CjsBlueReader.js +89 -0
  12. package/dist/format/CjsBlueReader.js.map +1 -1
  13. package/dist/format/CjsFormat.js +42 -16
  14. package/dist/format/CjsFormat.js.map +1 -1
  15. package/dist/format/CjsReader.js +4 -0
  16. package/dist/format/CjsReader.js.map +1 -1
  17. package/dist/format/CjsResourceProbe.js +2 -0
  18. package/dist/format/CjsResourceProbe.js.map +1 -1
  19. package/dist/format/effect/effectPermutationGraph.js +257 -0
  20. package/dist/format/effect/effectPermutationGraph.js.map +1 -0
  21. package/dist/format/effect/effectReflectionPackage.js +636 -0
  22. package/dist/format/effect/effectReflectionPackage.js.map +1 -0
  23. package/dist/format/effect/sha256.js +114 -0
  24. package/dist/format/effect/sha256.js.map +1 -0
  25. package/dist/format/payloadContract.js +20 -0
  26. package/dist/format/payloadContract.js.map +1 -1
  27. package/dist/formats/black/CjsBlackFormat.js +15 -1
  28. package/dist/formats/black/CjsBlackFormat.js.map +1 -1
  29. package/dist/formats/black/core/CjsBlackBinaryReader.js +103 -0
  30. package/dist/formats/black/core/CjsBlackBinaryReader.js.map +1 -1
  31. package/dist/formats/black/core/CjsBlackPropertyReaders.js +61 -0
  32. package/dist/formats/black/core/CjsBlackPropertyReaders.js.map +1 -1
  33. package/dist/formats/black/core/CjsBlackReader.js +125 -0
  34. package/dist/formats/black/core/CjsBlackReader.js.map +1 -1
  35. package/dist/formats/black/core/CjsBlackSchemaRegistry.js +103 -0
  36. package/dist/formats/black/core/CjsBlackSchemaRegistry.js.map +1 -1
  37. package/dist/formats/black/core/helpers.js +17 -0
  38. package/dist/formats/black/core/helpers.js.map +1 -1
  39. package/dist/formats/bnk/CjsBnkFormat.js +8 -0
  40. package/dist/formats/bnk/CjsBnkFormat.js.map +1 -1
  41. package/dist/formats/bnk/core/helpers.js +20 -0
  42. package/dist/formats/bnk/core/helpers.js.map +1 -1
  43. package/dist/formats/bnk/core/musicNodes.js +40 -3
  44. package/dist/formats/bnk/core/musicNodes.js.map +1 -1
  45. package/dist/formats/bnk/core/soundbanksInfo.js +2 -0
  46. package/dist/formats/bnk/core/soundbanksInfo.js.map +1 -1
  47. package/dist/formats/cmf/core/binary.js +71 -0
  48. package/dist/formats/cmf/core/binary.js.map +1 -1
  49. package/dist/formats/cmf/core/buffers.js +4 -0
  50. package/dist/formats/cmf/core/buffers.js.map +1 -1
  51. package/dist/formats/cmf/core/helpers.js +31 -0
  52. package/dist/formats/cmf/core/helpers.js.map +1 -1
  53. package/dist/formats/cmf/core/schema.js +10 -0
  54. package/dist/formats/cmf/core/schema.js.map +1 -1
  55. package/dist/formats/cmf/core/shared.js +9 -0
  56. package/dist/formats/cmf/core/shared.js.map +1 -1
  57. package/dist/formats/cmf/core/writer.js +54 -0
  58. package/dist/formats/cmf/core/writer.js.map +1 -1
  59. package/dist/formats/dds/core/bc6h.js +10 -0
  60. package/dist/formats/dds/core/bc6h.js.map +1 -1
  61. package/dist/formats/dds/core/bc7.js +16 -0
  62. package/dist/formats/dds/core/bc7.js.map +1 -1
  63. package/dist/formats/dds/core/helpers.js +47 -0
  64. package/dist/formats/dds/core/helpers.js.map +1 -1
  65. package/dist/formats/dxbc/CjsDxbcFormat.js +142 -0
  66. package/dist/formats/dxbc/CjsDxbcFormat.js.map +1 -0
  67. package/dist/formats/dxbc/core/DxbcReader.js +266 -0
  68. package/dist/formats/dxbc/core/DxbcReader.js.map +1 -0
  69. package/dist/formats/dxbc/core/container.js +169 -0
  70. package/dist/formats/dxbc/core/container.js.map +1 -0
  71. package/dist/formats/dxbc/core/decoder.js +789 -0
  72. package/dist/formats/dxbc/core/decoder.js.map +1 -0
  73. package/dist/formats/dxbc/core/errors.js +19 -0
  74. package/dist/formats/dxbc/core/errors.js.map +1 -0
  75. package/dist/formats/dxbc/core/helpers.js +220 -0
  76. package/dist/formats/dxbc/core/helpers.js.map +1 -0
  77. package/dist/formats/dxbc/core/opcodes.js +45 -0
  78. package/dist/formats/dxbc/core/opcodes.js.map +1 -0
  79. package/dist/formats/dxbc/core/program.js +91 -0
  80. package/dist/formats/dxbc/core/program.js.map +1 -0
  81. package/dist/formats/dxbc/core/signature.js +172 -0
  82. package/dist/formats/dxbc/core/signature.js.map +1 -0
  83. package/dist/formats/dxbc/index.js +2 -0
  84. package/dist/formats/dxbc/index.js.map +1 -0
  85. package/dist/formats/fbx/core/helpers.js +21 -0
  86. package/dist/formats/fbx/core/helpers.js.map +1 -1
  87. package/dist/formats/flac/CjsFlacFormat.js +49 -0
  88. package/dist/formats/flac/CjsFlacFormat.js.map +1 -1
  89. package/dist/formats/flac/core/helpers.js +20 -0
  90. package/dist/formats/flac/core/helpers.js.map +1 -1
  91. package/dist/formats/gif/CjsGifFormat.js +49 -0
  92. package/dist/formats/gif/CjsGifFormat.js.map +1 -1
  93. package/dist/formats/gif/core/helpers.js +20 -0
  94. package/dist/formats/gif/core/helpers.js.map +1 -1
  95. package/dist/formats/gltf/core/helpers.js +15 -0
  96. package/dist/formats/gltf/core/helpers.js.map +1 -1
  97. package/dist/formats/gltf/core/parser.js +13 -0
  98. package/dist/formats/gltf/core/parser.js.map +1 -1
  99. package/dist/formats/gltf/core/targets.js +10 -0
  100. package/dist/formats/gltf/core/targets.js.map +1 -1
  101. package/dist/formats/gr2/core/bitknit2.js +2 -0
  102. package/dist/formats/gr2/core/bitknit2.js.map +1 -1
  103. package/dist/formats/gr2/core/helpers.js +20 -0
  104. package/dist/formats/gr2/core/helpers.js.map +1 -1
  105. package/dist/formats/gr2/core/targets.js +10 -0
  106. package/dist/formats/gr2/core/targets.js.map +1 -1
  107. package/dist/formats/hlsl/CjsHlslFormat.js +254 -0
  108. package/dist/formats/hlsl/CjsHlslFormat.js.map +1 -0
  109. package/dist/formats/hlsl/core/HlslBinaryUtils.js +15 -0
  110. package/dist/formats/hlsl/core/HlslBinaryUtils.js.map +1 -0
  111. package/dist/formats/hlsl/core/HlslEffectReadError.js +19 -0
  112. package/dist/formats/hlsl/core/HlslEffectReadError.js.map +1 -0
  113. package/dist/formats/hlsl/core/HlslEffectStateManager.js +130 -0
  114. package/dist/formats/hlsl/core/HlslEffectStateManager.js.map +1 -0
  115. package/dist/formats/hlsl/core/HlslReader.js +266 -0
  116. package/dist/formats/hlsl/core/HlslReader.js.map +1 -0
  117. package/dist/formats/hlsl/core/HlslRenderStateSetup.js +37 -0
  118. package/dist/formats/hlsl/core/HlslRenderStateSetup.js.map +1 -0
  119. package/dist/formats/hlsl/core/HlslResourceSetDescription.js +94 -0
  120. package/dist/formats/hlsl/core/HlslResourceSetDescription.js.map +1 -0
  121. package/dist/formats/hlsl/core/HlslShaderBytecode.js +44 -0
  122. package/dist/formats/hlsl/core/HlslShaderBytecode.js.map +1 -0
  123. package/dist/formats/hlsl/core/analysis.js +51 -0
  124. package/dist/formats/hlsl/core/analysis.js.map +1 -0
  125. package/dist/formats/hlsl/core/helpers.js +270 -0
  126. package/dist/formats/hlsl/core/helpers.js.map +1 -0
  127. package/dist/formats/hlsl/core/json.js +284 -0
  128. package/dist/formats/hlsl/core/json.js.map +1 -0
  129. package/dist/formats/hlsl/core/metadata.js +327 -0
  130. package/dist/formats/hlsl/core/metadata.js.map +1 -0
  131. package/dist/formats/hlsl/core/portableReflection.js +848 -0
  132. package/dist/formats/hlsl/core/portableReflection.js.map +1 -0
  133. package/dist/formats/hlsl/core/render-states.js +280 -0
  134. package/dist/formats/hlsl/core/render-states.js.map +1 -0
  135. package/dist/formats/hlsl/core/tr2/HlslRenderContextEnum.js +43 -0
  136. package/dist/formats/hlsl/core/tr2/HlslRenderContextEnum.js.map +1 -0
  137. package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js +294 -0
  138. package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js.map +1 -0
  139. package/dist/formats/hlsl/core/tr2/resources/HlslShaderPermutation.js +33 -0
  140. package/dist/formats/hlsl/core/tr2/resources/HlslShaderPermutation.js.map +1 -0
  141. package/dist/formats/hlsl/core/tr2/shader/HlslEffectBindingManifest.js +416 -0
  142. package/dist/formats/hlsl/core/tr2/shader/HlslEffectBindingManifest.js.map +1 -0
  143. package/dist/formats/hlsl/core/tr2/shader/HlslEffectConstant.js +40 -0
  144. package/dist/formats/hlsl/core/tr2/shader/HlslEffectConstant.js.map +1 -0
  145. package/dist/formats/hlsl/core/tr2/shader/HlslEffectDescription.js +742 -0
  146. package/dist/formats/hlsl/core/tr2/shader/HlslEffectDescription.js.map +1 -0
  147. package/dist/formats/hlsl/core/tr2/shader/HlslEffectLibrary.js +52 -0
  148. package/dist/formats/hlsl/core/tr2/shader/HlslEffectLibrary.js.map +1 -0
  149. package/dist/formats/hlsl/core/tr2/shader/HlslEffectParameterAnnotation.js +38 -0
  150. package/dist/formats/hlsl/core/tr2/shader/HlslEffectParameterAnnotation.js.map +1 -0
  151. package/dist/formats/hlsl/core/tr2/shader/HlslEffectResource.js +50 -0
  152. package/dist/formats/hlsl/core/tr2/shader/HlslEffectResource.js.map +1 -0
  153. package/dist/formats/hlsl/core/tr2/shader/HlslEffectStageInput.js +86 -0
  154. package/dist/formats/hlsl/core/tr2/shader/HlslEffectStageInput.js.map +1 -0
  155. package/dist/formats/hlsl/core/tr2/shader/HlslEffectTechnique.js +31 -0
  156. package/dist/formats/hlsl/core/tr2/shader/HlslEffectTechnique.js.map +1 -0
  157. package/dist/formats/hlsl/core/tr2/shader/HlslPass.js +42 -0
  158. package/dist/formats/hlsl/core/tr2/shader/HlslPass.js.map +1 -0
  159. package/dist/formats/hlsl/core/tr2/shader/HlslSamplerDescription.js +55 -0
  160. package/dist/formats/hlsl/core/tr2/shader/HlslSamplerDescription.js.map +1 -0
  161. package/dist/formats/hlsl/core/tr2/shader/HlslSamplerSetup.js +29 -0
  162. package/dist/formats/hlsl/core/tr2/shader/HlslSamplerSetup.js.map +1 -0
  163. package/dist/formats/hlsl/core/tr2/shader/HlslShader.js +220 -0
  164. package/dist/formats/hlsl/core/tr2/shader/HlslShader.js.map +1 -0
  165. package/dist/formats/hlsl/core/tr2/shader/HlslShaderOption.js +30 -0
  166. package/dist/formats/hlsl/core/tr2/shader/HlslShaderOption.js.map +1 -0
  167. package/dist/formats/hlsl/index.js +2 -0
  168. package/dist/formats/hlsl/index.js.map +1 -0
  169. package/dist/formats/hlsl/portable.js +2 -0
  170. package/dist/formats/hlsl/portable.js.map +1 -0
  171. package/dist/formats/index.js +4 -0
  172. package/dist/formats/index.js.map +1 -1
  173. package/dist/formats/jpeg/core/helpers.js +52 -0
  174. package/dist/formats/jpeg/core/helpers.js.map +1 -1
  175. package/dist/formats/jpeg/core/jpeg.js +93 -0
  176. package/dist/formats/jpeg/core/jpeg.js.map +1 -1
  177. package/dist/formats/mp3/core/helpers.js +37 -0
  178. package/dist/formats/mp3/core/helpers.js.map +1 -1
  179. package/dist/formats/mp4/core/helpers.js +35 -0
  180. package/dist/formats/mp4/core/helpers.js.map +1 -1
  181. package/dist/formats/ogg/CjsOggFormat.js +49 -0
  182. package/dist/formats/ogg/CjsOggFormat.js.map +1 -1
  183. package/dist/formats/ogg/core/helpers.js +23 -0
  184. package/dist/formats/ogg/core/helpers.js.map +1 -1
  185. package/dist/formats/ogg/core/vorbis.js +13 -0
  186. package/dist/formats/ogg/core/vorbis.js.map +1 -1
  187. package/dist/formats/png/core/helpers.js +52 -0
  188. package/dist/formats/png/core/helpers.js.map +1 -1
  189. package/dist/formats/red/CjsRedFormat.js +2 -0
  190. package/dist/formats/red/CjsRedFormat.js.map +1 -1
  191. package/dist/formats/red/core/CjsRedReader.js +52 -0
  192. package/dist/formats/red/core/CjsRedReader.js.map +1 -1
  193. package/dist/formats/red/core/helpers.js +19 -0
  194. package/dist/formats/red/core/helpers.js.map +1 -1
  195. package/dist/formats/stl/core/stl.js +8 -0
  196. package/dist/formats/stl/core/stl.js.map +1 -1
  197. package/dist/formats/stl/core/targets.js +10 -0
  198. package/dist/formats/stl/core/targets.js.map +1 -1
  199. package/dist/formats/tga/core/helpers.js +47 -0
  200. package/dist/formats/tga/core/helpers.js.map +1 -1
  201. package/dist/formats/wav/core/helpers.js +37 -0
  202. package/dist/formats/wav/core/helpers.js.map +1 -1
  203. package/dist/formats/webgl/CjsWebglFormat.js +221 -0
  204. package/dist/formats/webgl/CjsWebglFormat.js.map +1 -0
  205. package/dist/formats/webgl/core/cewg/CewgPackage.js +339 -0
  206. package/dist/formats/webgl/core/cewg/CewgPackage.js.map +1 -0
  207. package/dist/formats/webgl/core/cewg/CewgPackageBuilder.js +104 -0
  208. package/dist/formats/webgl/core/cewg/CewgPackageBuilder.js.map +1 -0
  209. package/dist/formats/webgl/core/cewg/binary.js +101 -0
  210. package/dist/formats/webgl/core/cewg/binary.js.map +1 -0
  211. package/dist/formats/webgl/core/cewgCompleteness.js +81 -0
  212. package/dist/formats/webgl/core/cewgCompleteness.js.map +1 -0
  213. package/dist/formats/webgl/core/effectPackage.js +789 -0
  214. package/dist/formats/webgl/core/effectPackage.js.map +1 -0
  215. package/dist/formats/webgl/core/effectPackageValidation.js +331 -0
  216. package/dist/formats/webgl/core/effectPackageValidation.js.map +1 -0
  217. package/dist/formats/webgl/core/errors.js +27 -0
  218. package/dist/formats/webgl/core/errors.js.map +1 -0
  219. package/dist/formats/webgl/core/glsl/DxbcGlslEmitter.js +2678 -0
  220. package/dist/formats/webgl/core/glsl/DxbcGlslEmitter.js.map +1 -0
  221. package/dist/formats/webgl/core/glsl/DxbcGlslHelpers.js +89 -0
  222. package/dist/formats/webgl/core/glsl/DxbcGlslHelpers.js.map +1 -0
  223. package/dist/formats/webgl/core/glsl/DxbcGlslOperandFormatter.js +428 -0
  224. package/dist/formats/webgl/core/glsl/DxbcGlslOperandFormatter.js.map +1 -0
  225. package/dist/formats/webgl/core/helpers.js +306 -0
  226. package/dist/formats/webgl/core/helpers.js.map +1 -0
  227. package/dist/formats/webgl/index.js +2 -0
  228. package/dist/formats/webgl/index.js.map +1 -0
  229. package/dist/formats/webgpu/CjsWebgpuFormat.js +376 -0
  230. package/dist/formats/webgpu/CjsWebgpuFormat.js.map +1 -0
  231. package/dist/formats/webgpu/core/cewgpu/CewgpuPackage.js +415 -0
  232. package/dist/formats/webgpu/core/cewgpu/CewgpuPackage.js.map +1 -0
  233. package/dist/formats/webgpu/core/cewgpu/CewgpuPackageBuilder.js +100 -0
  234. package/dist/formats/webgpu/core/cewgpu/CewgpuPackageBuilder.js.map +1 -0
  235. package/dist/formats/webgpu/core/cewgpu/binary.js +93 -0
  236. package/dist/formats/webgpu/core/cewgpu/binary.js.map +1 -0
  237. package/dist/formats/webgpu/core/cewgpu/tags.js +17 -0
  238. package/dist/formats/webgpu/core/cewgpu/tags.js.map +1 -0
  239. package/dist/formats/webgpu/core/effectAnalysis.js +82 -0
  240. package/dist/formats/webgpu/core/effectAnalysis.js.map +1 -0
  241. package/dist/formats/webgpu/core/effectBackendBodySet.js +305 -0
  242. package/dist/formats/webgpu/core/effectBackendBodySet.js.map +1 -0
  243. package/dist/formats/webgpu/core/effectPackageValidation.js +1078 -0
  244. package/dist/formats/webgpu/core/effectPackageValidation.js.map +1 -0
  245. package/dist/formats/webgpu/core/errors.js +20 -0
  246. package/dist/formats/webgpu/core/errors.js.map +1 -0
  247. package/dist/formats/webgpu/core/helpers.js +448 -0
  248. package/dist/formats/webgpu/core/helpers.js.map +1 -0
  249. package/dist/formats/webgpu/core/ir/analyzeRegisterValues.js +223 -0
  250. package/dist/formats/webgpu/core/ir/analyzeRegisterValues.js.map +1 -0
  251. package/dist/formats/webgpu/core/ir/buildControlFlow.js +220 -0
  252. package/dist/formats/webgpu/core/ir/buildControlFlow.js.map +1 -0
  253. package/dist/formats/webgpu/core/ir/indexableTemps.js +137 -0
  254. package/dist/formats/webgpu/core/ir/indexableTemps.js.map +1 -0
  255. package/dist/formats/webgpu/core/ir/inferValueTypes.js +454 -0
  256. package/dist/formats/webgpu/core/ir/inferValueTypes.js.map +1 -0
  257. package/dist/formats/webgpu/core/ir/lowerDxbcToIr.js +494 -0
  258. package/dist/formats/webgpu/core/ir/lowerDxbcToIr.js.map +1 -0
  259. package/dist/formats/webgpu/core/ir/resolveRegisterFlow.js +177 -0
  260. package/dist/formats/webgpu/core/ir/resolveRegisterFlow.js.map +1 -0
  261. package/dist/formats/webgpu/core/ir/sourceLanes.js +61 -0
  262. package/dist/formats/webgpu/core/ir/sourceLanes.js.map +1 -0
  263. package/dist/formats/webgpu/core/packageEffect.js +300 -0
  264. package/dist/formats/webgpu/core/packageEffect.js.map +1 -0
  265. package/dist/formats/webgpu/core/packageEffectSelection.js +164 -0
  266. package/dist/formats/webgpu/core/packageEffectSelection.js.map +1 -0
  267. package/dist/formats/webgpu/core/packageMetadata.js +8 -0
  268. package/dist/formats/webgpu/core/packageMetadata.js.map +1 -0
  269. package/dist/formats/webgpu/core/schema.js +4 -0
  270. package/dist/formats/webgpu/core/schema.js.map +1 -0
  271. package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js +275 -0
  272. package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js.map +1 -0
  273. package/dist/formats/webgpu/core/wgsl/buildWgslBindingPlan.js +182 -0
  274. package/dist/formats/webgpu/core/wgsl/buildWgslBindingPlan.js.map +1 -0
  275. package/dist/formats/webgpu/core/wgsl/buildWgslSet.js +324 -0
  276. package/dist/formats/webgpu/core/wgsl/buildWgslSet.js.map +1 -0
  277. package/dist/formats/webgpu/core/wgsl/emitWgsl.js +356 -0
  278. package/dist/formats/webgpu/core/wgsl/emitWgsl.js.map +1 -0
  279. package/dist/formats/webgpu/core/wgsl/hoistEscapingValues.js +77 -0
  280. package/dist/formats/webgpu/core/wgsl/hoistEscapingValues.js.map +1 -0
  281. package/dist/formats/webgpu/core/wgsl/lowerBindingLayout.js +451 -0
  282. package/dist/formats/webgpu/core/wgsl/lowerBindingLayout.js.map +1 -0
  283. package/dist/formats/webgpu/core/wgsl/lowerComputeProgram.js +754 -0
  284. package/dist/formats/webgpu/core/wgsl/lowerComputeProgram.js.map +1 -0
  285. package/dist/formats/webgpu/core/wgsl/lowerCreateHistogramsComputeProgram.js +457 -0
  286. package/dist/formats/webgpu/core/wgsl/lowerCreateHistogramsComputeProgram.js.map +1 -0
  287. package/dist/formats/webgpu/core/wgsl/lowerFragmentProgram.js +1572 -0
  288. package/dist/formats/webgpu/core/wgsl/lowerFragmentProgram.js.map +1 -0
  289. package/dist/formats/webgpu/core/wgsl/lowerMergeHistogramsComputeProgram.js +659 -0
  290. package/dist/formats/webgpu/core/wgsl/lowerMergeHistogramsComputeProgram.js.map +1 -0
  291. package/dist/formats/webgpu/core/wgsl/lowerParticleClearComputePrograms.js +734 -0
  292. package/dist/formats/webgpu/core/wgsl/lowerParticleClearComputePrograms.js.map +1 -0
  293. package/dist/formats/webgpu/core/wgsl/lowerParticleEmitComputeProgram.js +583 -0
  294. package/dist/formats/webgpu/core/wgsl/lowerParticleEmitComputeProgram.js.map +1 -0
  295. package/dist/formats/webgpu/core/wgsl/lowerSkinVerticesComputeProgram.js +621 -0
  296. package/dist/formats/webgpu/core/wgsl/lowerSkinVerticesComputeProgram.js.map +1 -0
  297. package/dist/formats/webgpu/core/wgsl/lowerSortComputeProgram.js +824 -0
  298. package/dist/formats/webgpu/core/wgsl/lowerSortComputeProgram.js.map +1 -0
  299. package/dist/formats/webgpu/core/wgsl/lowerSortInnerComputeProgram.js +697 -0
  300. package/dist/formats/webgpu/core/wgsl/lowerSortInnerComputeProgram.js.map +1 -0
  301. package/dist/formats/webgpu/core/wgsl/lowerSortStepComputeProgram.js +559 -0
  302. package/dist/formats/webgpu/core/wgsl/lowerSortStepComputeProgram.js.map +1 -0
  303. package/dist/formats/webgpu/core/wgsl/lowerVertexProgram.js +1328 -0
  304. package/dist/formats/webgpu/core/wgsl/lowerVertexProgram.js.map +1 -0
  305. package/dist/formats/webgpu/core/wgsl/particleEmitSemanticDigest.js +110 -0
  306. package/dist/formats/webgpu/core/wgsl/particleEmitSemanticDigest.js.map +1 -0
  307. package/dist/formats/webgpu/core/wgsl/precisionControls.js +55 -0
  308. package/dist/formats/webgpu/core/wgsl/precisionControls.js.map +1 -0
  309. package/dist/formats/webgpu/core/wgsl/selectionPlans.js +758 -0
  310. package/dist/formats/webgpu/core/wgsl/selectionPlans.js.map +1 -0
  311. package/dist/formats/webgpu/core/wgsl/uniformity.js +78 -0
  312. package/dist/formats/webgpu/core/wgsl/uniformity.js.map +1 -0
  313. package/dist/formats/webgpu/core/wgsl/validateExactComputeIr.js +196 -0
  314. package/dist/formats/webgpu/core/wgsl/validateExactComputeIr.js.map +1 -0
  315. package/dist/formats/webgpu/core/wgsl/validateHandleOperand.js +37 -0
  316. package/dist/formats/webgpu/core/wgsl/validateHandleOperand.js.map +1 -0
  317. package/dist/formats/webgpu/index.js +2 -0
  318. package/dist/formats/webgpu/index.js.map +1 -0
  319. package/dist/formats/webm/core/helpers.js +35 -0
  320. package/dist/formats/webm/core/helpers.js.map +1 -1
  321. package/dist/formats/webp/CjsWebpFormat.js +49 -0
  322. package/dist/formats/webp/CjsWebpFormat.js.map +1 -1
  323. package/dist/formats/webp/core/helpers.js +23 -0
  324. package/dist/formats/webp/core/helpers.js.map +1 -1
  325. package/dist/formats/wem/CjsWemFormat.js +8 -0
  326. package/dist/formats/wem/CjsWemFormat.js.map +1 -1
  327. package/dist/formats/wem/core/bitStream.js +2 -0
  328. package/dist/formats/wem/core/bitStream.js.map +1 -1
  329. package/dist/formats/wem/core/helpers.js +20 -0
  330. package/dist/formats/wem/core/helpers.js.map +1 -1
  331. package/dist/formats/yaml/CjsYamlFormat.js +45 -0
  332. package/dist/formats/yaml/CjsYamlFormat.js.map +1 -1
  333. package/dist/formats/yaml/core/CjsYamlReader.js +91 -0
  334. package/dist/formats/yaml/core/CjsYamlReader.js.map +1 -1
  335. package/dist/formats/yaml/core/helpers.js +10 -0
  336. package/dist/formats/yaml/core/helpers.js.map +1 -1
  337. package/dist/index.js +56 -43
  338. package/dist/index.js.map +1 -1
  339. package/dist/{CjsResource.js → resource/CjsResource.js} +232 -17
  340. package/dist/resource/CjsResource.js.map +1 -0
  341. package/dist/{resources → resource}/Tr2LightProfileRes.js +4 -3
  342. package/dist/resource/Tr2LightProfileRes.js.map +1 -0
  343. package/dist/{resources → resource/audio}/AudioGeometryResData.js +1 -1
  344. package/dist/resource/audio/AudioGeometryResData.js.map +1 -0
  345. package/dist/resource/audio/CjsAudioBufferRes.js +86 -0
  346. package/dist/resource/audio/CjsAudioBufferRes.js.map +1 -0
  347. package/dist/resource/audio/CjsAudioRes.js +213 -0
  348. package/dist/resource/audio/CjsAudioRes.js.map +1 -0
  349. package/dist/resource/audio/index.js +4 -0
  350. package/dist/resource/audio/index.js.map +1 -0
  351. package/dist/{resources → resource/geometry}/MeshDecalData.js +1 -1
  352. package/dist/resource/geometry/MeshDecalData.js.map +1 -0
  353. package/dist/{resources → resource/geometry}/MeshDecalLodData.js +1 -1
  354. package/dist/resource/geometry/MeshDecalLodData.js.map +1 -0
  355. package/dist/resource/geometry/TriGeometryRes.js +656 -0
  356. package/dist/resource/geometry/TriGeometryRes.js.map +1 -0
  357. package/dist/{resources → resource/geometry}/TriGeometryResAreaData.js +1 -1
  358. package/dist/resource/geometry/TriGeometryResAreaData.js.map +1 -0
  359. package/dist/{resources → resource/geometry}/TriGeometryResJointData.js +1 -1
  360. package/dist/resource/geometry/TriGeometryResJointData.js.map +1 -0
  361. package/dist/{resources → resource/geometry}/TriGeometryResLodData.js +1 -1
  362. package/dist/resource/geometry/TriGeometryResLodData.js.map +1 -0
  363. package/dist/{resources → resource/geometry}/TriGeometryResMeshData.js +1 -1
  364. package/dist/resource/geometry/TriGeometryResMeshData.js.map +1 -0
  365. package/dist/{resources → resource/geometry}/TriGeometryResSkeletonData.js +1 -1
  366. package/dist/resource/geometry/TriGeometryResSkeletonData.js.map +1 -0
  367. package/dist/{resources → resource/geometry}/TriJointBinding.js +1 -1
  368. package/dist/resource/geometry/TriJointBinding.js.map +1 -0
  369. package/dist/{resources → resource/geometry}/TriMorphTargetGeometryConstants.js +1 -1
  370. package/dist/resource/geometry/TriMorphTargetGeometryConstants.js.map +1 -0
  371. package/dist/{resources → resource/geometry}/TriRtGeometryConstants.js +1 -1
  372. package/dist/resource/geometry/TriRtGeometryConstants.js.map +1 -0
  373. package/dist/{resources → resource/geometry/granny}/GStateBindingCallbackData.js +1 -1
  374. package/dist/resource/geometry/granny/GStateBindingCallbackData.js.map +1 -0
  375. package/dist/{resources → resource/geometry/granny}/Tr2GrannyIntersectionResult.js +1 -1
  376. package/dist/resource/geometry/granny/Tr2GrannyIntersectionResult.js.map +1 -0
  377. package/dist/{resources → resource/geometry/granny}/Tr2GrannyStateRes.js +6 -5
  378. package/dist/resource/geometry/granny/Tr2GrannyStateRes.js.map +1 -0
  379. package/dist/{resources → resource/geometry/granny}/TriGrannyRes.js +6 -5
  380. package/dist/resource/geometry/granny/TriGrannyRes.js.map +1 -0
  381. package/dist/{resources → resource/geometry/granny}/enums.js +1 -9
  382. package/dist/resource/geometry/granny/enums.js.map +1 -0
  383. package/dist/resource/geometry/granny/index.js +6 -0
  384. package/dist/resource/geometry/granny/index.js.map +1 -0
  385. package/dist/resource/geometry/index.js +17 -0
  386. package/dist/resource/geometry/index.js.map +1 -0
  387. package/dist/resource/index.js +52 -0
  388. package/dist/resource/index.js.map +1 -0
  389. package/dist/resource/resourceBoundary.js +64 -0
  390. package/dist/resource/resourceBoundary.js.map +1 -0
  391. package/dist/resource/shader/Tr2EffectRes.js +429 -0
  392. package/dist/resource/shader/Tr2EffectRes.js.map +1 -0
  393. package/dist/resource/shader/Tr2MaterialArea.js +34 -0
  394. package/dist/resource/shader/Tr2MaterialArea.js.map +1 -0
  395. package/dist/resource/shader/Tr2MaterialMesh.js +30 -0
  396. package/dist/resource/shader/Tr2MaterialMesh.js.map +1 -0
  397. package/dist/resource/shader/Tr2MaterialRes.js +35 -0
  398. package/dist/resource/shader/Tr2MaterialRes.js.map +1 -0
  399. package/dist/resource/shader/Tr2Shader.js +256 -0
  400. package/dist/resource/shader/Tr2Shader.js.map +1 -0
  401. package/dist/resource/shader/Tr2ShaderPermutation.js +47 -0
  402. package/dist/resource/shader/Tr2ShaderPermutation.js.map +1 -0
  403. package/dist/resource/shader/index.js +17 -0
  404. package/dist/resource/shader/index.js.map +1 -0
  405. package/dist/resource/shader/portable.js +33 -0
  406. package/dist/resource/shader/portable.js.map +1 -0
  407. package/dist/resource/shader/reflection/Tr2EffectConstant.js +135 -0
  408. package/dist/resource/shader/reflection/Tr2EffectConstant.js.map +1 -0
  409. package/dist/resource/shader/reflection/Tr2EffectDefine.js +28 -0
  410. package/dist/resource/shader/reflection/Tr2EffectDefine.js.map +1 -0
  411. package/dist/resource/shader/reflection/Tr2EffectDescription.js +107 -0
  412. package/dist/resource/shader/reflection/Tr2EffectDescription.js.map +1 -0
  413. package/dist/resource/shader/reflection/Tr2EffectLibrary.js +145 -0
  414. package/dist/resource/shader/reflection/Tr2EffectLibrary.js.map +1 -0
  415. package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js +103 -0
  416. package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js.map +1 -0
  417. package/dist/resource/shader/reflection/Tr2EffectResource.js +84 -0
  418. package/dist/resource/shader/reflection/Tr2EffectResource.js.map +1 -0
  419. package/dist/resource/shader/reflection/Tr2EffectStageInput.js +239 -0
  420. package/dist/resource/shader/reflection/Tr2EffectStageInput.js.map +1 -0
  421. package/dist/resource/shader/reflection/Tr2EffectTechnique.js +66 -0
  422. package/dist/resource/shader/reflection/Tr2EffectTechnique.js.map +1 -0
  423. package/dist/resource/shader/reflection/Tr2Pass.js +109 -0
  424. package/dist/resource/shader/reflection/Tr2Pass.js.map +1 -0
  425. package/dist/resource/shader/sampler/Tr2SamplerSetup.js +75 -0
  426. package/dist/resource/shader/sampler/Tr2SamplerSetup.js.map +1 -0
  427. package/dist/{texture → resource/texture}/CjsTextureArrayRes.js +83 -6
  428. package/dist/resource/texture/CjsTextureArrayRes.js.map +1 -0
  429. package/dist/{texture/CjsTextureParameterProxy.js → resource/texture/CjsTextureArrayResParameterProxy.js} +56 -10
  430. package/dist/resource/texture/CjsTextureArrayResParameterProxy.js.map +1 -0
  431. package/dist/{resources → resource/texture}/Tr2ImageRes.js +6 -4
  432. package/dist/resource/texture/Tr2ImageRes.js.map +1 -0
  433. package/dist/{resources → resource/texture}/Tr2TextureLodManager.js +3 -1
  434. package/dist/resource/texture/Tr2TextureLodManager.js.map +1 -0
  435. package/dist/{resources → resource/texture}/Tr2TextureLodUpdateRequest.js +1 -1
  436. package/dist/resource/texture/Tr2TextureLodUpdateRequest.js.map +1 -0
  437. package/dist/{resources → resource/texture}/Tr2TexturePackChannel.js +1 -1
  438. package/dist/resource/texture/Tr2TexturePackChannel.js.map +1 -0
  439. package/dist/{resources → resource/texture}/Tr2TexturePipeline.js +6 -4
  440. package/dist/resource/texture/Tr2TexturePipeline.js.map +1 -0
  441. package/dist/{resources → resource/texture}/Tr2TexturePipelineParams.js +1 -1
  442. package/dist/resource/texture/Tr2TexturePipelineParams.js.map +1 -0
  443. package/dist/{resources → resource/texture}/Tr2TexturePipelineStepCompress.js +1 -1
  444. package/dist/resource/texture/Tr2TexturePipelineStepCompress.js.map +1 -0
  445. package/dist/{resources → resource/texture}/Tr2TexturePipelineStepGenerateMips.js +1 -1
  446. package/dist/resource/texture/Tr2TexturePipelineStepGenerateMips.js.map +1 -0
  447. package/dist/{resources → resource/texture}/Tr2TexturePipelineStepLimitSize.js +1 -1
  448. package/dist/resource/texture/Tr2TexturePipelineStepLimitSize.js.map +1 -0
  449. package/dist/{resources → resource/texture}/Tr2TexturePipelineStepLoad.js +1 -1
  450. package/dist/resource/texture/Tr2TexturePipelineStepLoad.js.map +1 -0
  451. package/dist/{resources → resource/texture}/Tr2TexturePipelineStepPack.js +1 -1
  452. package/dist/resource/texture/Tr2TexturePipelineStepPack.js.map +1 -0
  453. package/dist/{resources → resource/texture}/TriTextureRes.js +42 -26
  454. package/dist/resource/texture/TriTextureRes.js.map +1 -0
  455. package/dist/resource/texture/index.js +15 -0
  456. package/dist/resource/texture/index.js.map +1 -0
  457. package/dist/{resources → resource/texture}/texturePipelineBehavior.js +59 -59
  458. package/dist/resource/texture/texturePipelineBehavior.js.map +1 -0
  459. package/dist/worker/CjsResManMainThreadLoader.js +87 -0
  460. package/dist/worker/CjsResManMainThreadLoader.js.map +1 -0
  461. package/dist/worker/CjsResManWorker.js +217 -0
  462. package/dist/worker/CjsResManWorker.js.map +1 -0
  463. package/dist/worker/CjsResManWorkerLoader.js +434 -0
  464. package/dist/worker/CjsResManWorkerLoader.js.map +1 -0
  465. package/dist/worker/protocol.js +12 -0
  466. package/dist/worker/protocol.js.map +1 -0
  467. package/docs/README.md +16 -3
  468. package/docs/architecture.md +39 -16
  469. package/docs/concepts/resource-lifecycle.md +2 -1
  470. package/docs/formats/README.md +8 -0
  471. package/docs/formats/provenance.md +11 -3
  472. package/docs/reference/classes/README.md +6 -4
  473. package/docs/reference/classes/audio.md +30 -0
  474. package/docs/reference/classes/core.md +31 -11
  475. package/docs/reference/classes/formats.md +440 -0
  476. package/docs/reference/classes/resources.md +151 -41
  477. package/docs/reference/classes/texture.md +7 -7
  478. package/docs/reference/motherlode-cache.md +17 -0
  479. package/docs/reference/queues.md +9 -1
  480. package/docs/reference/workers.md +135 -0
  481. package/docs/roadmap.md +27 -1
  482. package/format-notices/dxbc/LICENSE +21 -0
  483. package/format-notices/dxbc/NOTICE +20 -0
  484. package/format-notices/hlsl/LICENSE +21 -0
  485. package/format-notices/hlsl/NOTICE +25 -0
  486. package/format-notices/webgl/LICENSE +21 -0
  487. package/format-notices/webgl/NOTICE +35 -0
  488. package/format-notices/webgpu/LICENSE +21 -0
  489. package/format-notices/webgpu/NOTICE +31 -0
  490. package/package.json +13 -1
  491. package/dist/CjsResManQueue.js.map +0 -1
  492. package/dist/CjsResource.js.map +0 -1
  493. package/dist/CjsResourceSource.js +0 -68
  494. package/dist/CjsResourceSource.js.map +0 -1
  495. package/dist/resourcePath.js +0 -18
  496. package/dist/resourcePath.js.map +0 -1
  497. package/dist/resourceStates.js +0 -9
  498. package/dist/resourceStates.js.map +0 -1
  499. package/dist/resources/AudioGeometryResData.js.map +0 -1
  500. package/dist/resources/GStateBindingCallbackData.js.map +0 -1
  501. package/dist/resources/MeshDecalData.js.map +0 -1
  502. package/dist/resources/MeshDecalLodData.js.map +0 -1
  503. package/dist/resources/Tr2EffectRes.js +0 -71
  504. package/dist/resources/Tr2EffectRes.js.map +0 -1
  505. package/dist/resources/Tr2GrannyIntersectionResult.js.map +0 -1
  506. package/dist/resources/Tr2GrannyStateRes.js.map +0 -1
  507. package/dist/resources/Tr2ImageRes.js.map +0 -1
  508. package/dist/resources/Tr2LightProfileRes.js.map +0 -1
  509. package/dist/resources/Tr2MaterialArea.js +0 -34
  510. package/dist/resources/Tr2MaterialArea.js.map +0 -1
  511. package/dist/resources/Tr2MaterialMesh.js +0 -31
  512. package/dist/resources/Tr2MaterialMesh.js.map +0 -1
  513. package/dist/resources/Tr2MaterialRes.js +0 -34
  514. package/dist/resources/Tr2MaterialRes.js.map +0 -1
  515. package/dist/resources/Tr2ShaderPermutation.js +0 -43
  516. package/dist/resources/Tr2ShaderPermutation.js.map +0 -1
  517. package/dist/resources/Tr2TextureLodManager.js.map +0 -1
  518. package/dist/resources/Tr2TextureLodUpdateRequest.js.map +0 -1
  519. package/dist/resources/Tr2TexturePackChannel.js.map +0 -1
  520. package/dist/resources/Tr2TexturePipeline.js.map +0 -1
  521. package/dist/resources/Tr2TexturePipelineParams.js.map +0 -1
  522. package/dist/resources/Tr2TexturePipelineStepCompress.js.map +0 -1
  523. package/dist/resources/Tr2TexturePipelineStepGenerateMips.js.map +0 -1
  524. package/dist/resources/Tr2TexturePipelineStepLimitSize.js.map +0 -1
  525. package/dist/resources/Tr2TexturePipelineStepLoad.js.map +0 -1
  526. package/dist/resources/Tr2TexturePipelineStepPack.js.map +0 -1
  527. package/dist/resources/TriGeometryRes.js +0 -239
  528. package/dist/resources/TriGeometryRes.js.map +0 -1
  529. package/dist/resources/TriGeometryResAreaData.js.map +0 -1
  530. package/dist/resources/TriGeometryResJointData.js.map +0 -1
  531. package/dist/resources/TriGeometryResLodData.js.map +0 -1
  532. package/dist/resources/TriGeometryResMeshData.js.map +0 -1
  533. package/dist/resources/TriGeometryResSkeletonData.js.map +0 -1
  534. package/dist/resources/TriGrannyRes.js.map +0 -1
  535. package/dist/resources/TriJointBinding.js.map +0 -1
  536. package/dist/resources/TriMorphTargetGeometryConstants.js.map +0 -1
  537. package/dist/resources/TriRtGeometryConstants.js.map +0 -1
  538. package/dist/resources/TriTextureRes.js.map +0 -1
  539. package/dist/resources/enums.js.map +0 -1
  540. package/dist/resources/resourceBoundary.js +0 -47
  541. package/dist/resources/resourceBoundary.js.map +0 -1
  542. package/dist/resources/texturePipelineBehavior.js.map +0 -1
  543. package/dist/texture/CjsTextureArrayRes.js.map +0 -1
  544. package/dist/texture/CjsTextureParameterProxy.js.map +0 -1
@@ -0,0 +1,415 @@
1
+ import { asUint8Array, WebgpuReader } from './binary.js';
2
+ import { validateCewgpuChunkTag } from './tags.js';
3
+ import { sha256Bytes } from '../../../../format/effect/sha256.js';
4
+ import { hydrateEffectReflectionForPermutation } from '../../../../format/effect/effectReflectionPackage.js';
5
+
6
+ const validatedEffectPackages = new WeakSet();
7
+ const CEWGPU_MAGIC = "CWGP";
8
+ const CEWGPU_FORMAT = "CEWGPU";
9
+ const CEWGPU_VERSION = 1;
10
+ const textDecoder = new TextDecoder("utf-8", {
11
+ fatal: false
12
+ });
13
+ const jsonTextDecoder = new TextDecoder("utf-8", {
14
+ fatal: true
15
+ });
16
+
17
+ /**
18
+ * Reader for CarbonEngineJS CEWGPU shader packages.
19
+ */
20
+ class CewgpuPackage {
21
+ /**
22
+ * Creates an empty package reader.
23
+ */
24
+ constructor() {
25
+ this.version = 0;
26
+ this.chunks = [];
27
+ this.chunkMap = new Map();
28
+ this.jsonCache = new Map();
29
+ this.reflectionBlobIndex = null;
30
+ this.readError = null;
31
+ this.sourcePath = "";
32
+ }
33
+
34
+ /**
35
+ * Reads a CEWGPU package from bytes.
36
+ *
37
+ * @param {ArrayBuffer|ArrayBufferView|Uint8Array} source CEWGPU bytes.
38
+ * @param {object} [options] Read options.
39
+ * @param {string} [options.sourcePath] Source path for diagnostics.
40
+ * @returns {boolean} True when the package was decoded.
41
+ */
42
+ Read(source, options = {}) {
43
+ this.version = 0;
44
+ this.chunks = [];
45
+ this.chunkMap = new Map();
46
+ this.jsonCache = new Map();
47
+ this.reflectionBlobIndex = null;
48
+ this.readError = null;
49
+ this.sourcePath = options.sourcePath || "";
50
+ try {
51
+ const bytes = asUint8Array(source);
52
+ const stream = new WebgpuReader(bytes, {
53
+ source: this.sourcePath || "CEWGPU"
54
+ });
55
+ const magic = decodeAscii(stream.readRaw(CEWGPU_MAGIC.length));
56
+ if (magic !== CEWGPU_MAGIC) {
57
+ throw new Error(`Invalid CEWGPU magic "${magic}"`);
58
+ }
59
+ this.version = stream.readUint32();
60
+ if (this.version !== CEWGPU_VERSION) {
61
+ throw new Error(`Unsupported CEWGPU version ${this.version}`);
62
+ }
63
+ const chunkCount = stream.readUint32();
64
+ for (let index = 0; index < chunkCount; index += 1) {
65
+ const tag = decodeAscii(stream.readRaw(4));
66
+ validateCewgpuChunkTag(tag);
67
+ if (this.chunkMap.has(tag)) {
68
+ throw new Error(`CEWGPU package contains duplicate chunk tag ${tag}`);
69
+ }
70
+ const size = stream.readUint32();
71
+ const offset = stream.offset;
72
+ const chunkBytes = stream.readRaw(size);
73
+ const chunk = {
74
+ tag,
75
+ size,
76
+ offset,
77
+ bytes: chunkBytes
78
+ };
79
+ this.chunks.push(chunk);
80
+ this.chunkMap.set(tag, chunk);
81
+ }
82
+ if (stream.remaining !== 0) {
83
+ throw new Error(`CEWGPU package has ${stream.remaining} trailing bytes`);
84
+ }
85
+ return true;
86
+ } catch (error) {
87
+ this.readError = error;
88
+ this.chunks = [];
89
+ this.chunkMap = new Map();
90
+ this.jsonCache = new Map();
91
+ this.reflectionBlobIndex = null;
92
+ return false;
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Reports whether the package decoded successfully.
98
+ *
99
+ * @returns {boolean} True when no read error is present.
100
+ */
101
+ IsGood() {
102
+ return !this.readError && this.version === CEWGPU_VERSION;
103
+ }
104
+
105
+ /**
106
+ * Gets a chunk by four-character tag.
107
+ *
108
+ * @param {string} tag Chunk tag.
109
+ * @returns {{tag:string,size:number,offset:number,bytes:Uint8Array}|null} Chunk record.
110
+ */
111
+ GetChunk(tag) {
112
+ return this.chunkMap.get(tag) || null;
113
+ }
114
+
115
+ /**
116
+ * Decodes a text chunk.
117
+ *
118
+ * @param {string} tag Chunk tag.
119
+ * @returns {string|null} Decoded text, or null when absent.
120
+ */
121
+ GetText(tag) {
122
+ const chunk = this.GetChunk(tag);
123
+ return chunk ? textDecoder.decode(chunk.bytes) : null;
124
+ }
125
+
126
+ /**
127
+ * Decodes a JSON chunk.
128
+ *
129
+ * @param {string} tag Chunk tag.
130
+ * @returns {object|null} Parsed JSON, or null when absent.
131
+ */
132
+ GetJson(tag) {
133
+ return cloneJson(getCachedJson(this, tag));
134
+ }
135
+
136
+ /**
137
+ * Gets translator summary metadata from the `INFO` chunk.
138
+ *
139
+ * @returns {object|null} Info JSON.
140
+ */
141
+ get info() {
142
+ return this.GetJson("INFO");
143
+ }
144
+
145
+ /**
146
+ * Gets caller-provided metadata from the `META` chunk.
147
+ *
148
+ * @returns {object|null} Metadata JSON.
149
+ */
150
+ get metadata() {
151
+ return this.GetJson("META");
152
+ }
153
+
154
+ /**
155
+ * Gets the complete source permutation graph when present.
156
+ *
157
+ * @returns {object|null} Parsed permutation graph.
158
+ */
159
+ get permutationGraph() {
160
+ return this.GetJson("PGRF");
161
+ }
162
+
163
+ /**
164
+ * Gets complete source effect reflection when present.
165
+ *
166
+ * @returns {object|null} Parsed reflection document.
167
+ */
168
+ get reflection() {
169
+ return this.GetJson("RFLX");
170
+ }
171
+
172
+ /**
173
+ * Gets the raw reflection blob store when present.
174
+ *
175
+ * @returns {Uint8Array|null} RBLB bytes.
176
+ */
177
+ get reflectionBlobBytes() {
178
+ return this.GetChunk("RBLB")?.bytes ?? null;
179
+ }
180
+
181
+ /**
182
+ * Copies one reflected byte payload by blob key or exact reference.
183
+ *
184
+ * A string performs an inventory-key lookup. An object must exactly match
185
+ * the stored blob key, offset, byte length, and digest.
186
+ *
187
+ * @param {string|object} value Blob key or exact RFLX byte-reference object.
188
+ * @returns {Uint8Array|null} Owned payload bytes, or null when unavailable.
189
+ */
190
+ GetReflectionBlob(value) {
191
+ const key = typeof value === "string" ? value : value?.blobKey;
192
+ if (!this.reflectionBlobIndex) {
193
+ this.reflectionBlobIndex = new Map((getCachedJson(this, "RFLX")?.blobStore?.blobs ?? []).map(entry => [entry.blobKey, entry]));
194
+ }
195
+ const entry = this.reflectionBlobIndex.get(key);
196
+ const bytes = this.reflectionBlobBytes;
197
+ if (!entry || !bytes) return null;
198
+ if (typeof value !== "string" && (!value || value.offset !== entry.offset || value.byteLength !== entry.byteLength || value.sha256 !== entry.sha256)) {
199
+ return null;
200
+ }
201
+ const end = entry.offset + entry.byteLength;
202
+ if (!Number.isSafeInteger(entry.offset) || entry.offset < 0 || !Number.isSafeInteger(entry.byteLength) || entry.byteLength < 0 || end > bytes.byteLength || sha256Bytes(bytes.subarray(entry.offset, end)) !== entry.sha256) {
203
+ return null;
204
+ }
205
+ return Uint8Array.from(bytes.subarray(entry.offset, end));
206
+ }
207
+
208
+ /**
209
+ * Gets fully hydrated portable source reflection for one permutation.
210
+ *
211
+ * The optional index defaults to `META.bodyIndex`. Every reflected byte
212
+ * field is returned as a fresh owned `Uint8Array`.
213
+ *
214
+ * @param {number} [permutationIndex] Exact PGRF permutation index.
215
+ * @returns {object|null} Validated portable reflection, or null when absent.
216
+ */
217
+ GetPortableEffectReflection(permutationIndex) {
218
+ if (!validatedEffectPackages.has(this)) return null;
219
+ const reflection = getCachedJson(this, "RFLX");
220
+ const permutationGraph = getCachedJson(this, "PGRF");
221
+ if (!reflection || !permutationGraph) return null;
222
+ const selectedIndex = permutationIndex ?? getCachedJson(this, "META")?.bodyIndex ?? 0;
223
+ return hydrateEffectReflectionForPermutation(reflection, permutationGraph, selectedIndex, reference => this.GetReflectionBlob(reference));
224
+ }
225
+
226
+ /**
227
+ * Gets the all-body backend translation graph when present.
228
+ *
229
+ * Selected-mode packages do not carry this chunk.
230
+ *
231
+ * @returns {object|null} Parsed `CJS_WGSL_BODY_SET` document.
232
+ */
233
+ get backendBodySet() {
234
+ return this.GetJson("WGSB");
235
+ }
236
+
237
+ /**
238
+ * Resolves the translated backend passes for one permutation index.
239
+ *
240
+ * Joins `PGRF` variant identity to the `WGSB` body record and expands every
241
+ * pass reference into its shared translation unit. Returns null when the
242
+ * package carries no all-body graph, and an explicitly unsupported record
243
+ * when that body could not be lowered.
244
+ *
245
+ * @param {number} [permutationIndex] Exact PGRF permutation index.
246
+ * @returns {object|null} Resolved backend body, or null when unavailable.
247
+ */
248
+ GetBackendBodyPrograms(permutationIndex) {
249
+ if (!validatedEffectPackages.has(this)) return null;
250
+ const bodySet = getCachedJson(this, "WGSB");
251
+ const permutationGraph = getCachedJson(this, "PGRF");
252
+ if (!bodySet || !permutationGraph) return null;
253
+ const index = permutationIndex ?? getCachedJson(this, "META")?.bodyIndex ?? 0;
254
+ const variant = permutationGraph.variants?.[index];
255
+ if (!variant) return null;
256
+ const body = bodySet.bodies?.find(entry => entry.bodyKey === variant.bodyKey);
257
+ if (!body) return null;
258
+ if (body.status !== "translated") {
259
+ return {
260
+ permutationIndex: index,
261
+ bodyKey: body.bodyKey,
262
+ status: body.status,
263
+ error: body.error,
264
+ passes: []
265
+ };
266
+ }
267
+ const units = new Map((bodySet.passUnits ?? []).map(unit => [unit.key, unit]));
268
+ return {
269
+ permutationIndex: index,
270
+ bodyKey: body.bodyKey,
271
+ status: body.status,
272
+ error: null,
273
+ passes: body.passes.map(pass => {
274
+ const unit = units.get(pass.unitKey);
275
+ if (!unit) {
276
+ throw new Error(`CEWGPU backend body ${body.bodyKey} references missing translation unit ${pass.unitKey}`);
277
+ }
278
+ return {
279
+ passKey: pass.passKey,
280
+ unitKey: pass.unitKey,
281
+ wgslSetVersion: unit.wgslSetVersion,
282
+ shaders: unit.shaders,
283
+ layouts: unit.layouts,
284
+ ...(unit.resourceTransforms ? {
285
+ resourceTransforms: unit.resourceTransforms
286
+ } : {})
287
+ };
288
+ })
289
+ };
290
+ }
291
+
292
+ /**
293
+ * Gets normalized shader analysis from the `ANLS` chunk.
294
+ *
295
+ * @returns {string|null} Analysis text.
296
+ */
297
+ get analysis() {
298
+ return this.GetText("ANLS");
299
+ }
300
+
301
+ /**
302
+ * Gets normalized shader analysis metadata when the `ANLS` chunk contains
303
+ * JSON.
304
+ *
305
+ * @returns {object|null} Parsed analysis, or null for raw text.
306
+ */
307
+ get analysisJson() {
308
+ try {
309
+ return this.GetJson("ANLS");
310
+ } catch {
311
+ return null;
312
+ }
313
+ }
314
+
315
+ /**
316
+ * Gets emitted WGSL when present.
317
+ *
318
+ * @returns {string|null} WGSL text.
319
+ */
320
+ get wgsl() {
321
+ return this.GetText("WGSL");
322
+ }
323
+
324
+ /**
325
+ * Gets emitted WGSL metadata when the `WGSL` chunk contains JSON.
326
+ *
327
+ * @returns {object|null} Parsed WGSL metadata, or null for raw source.
328
+ */
329
+ get wgslJson() {
330
+ try {
331
+ return this.GetJson("WGSL");
332
+ } catch {
333
+ return null;
334
+ }
335
+ }
336
+
337
+ /**
338
+ * Returns a JSON-safe package summary.
339
+ *
340
+ * @returns {object} Serializable summary.
341
+ */
342
+ toJSON() {
343
+ return {
344
+ format: CEWGPU_FORMAT,
345
+ version: this.version,
346
+ sourcePath: this.sourcePath,
347
+ chunks: this.chunks.map(chunk => ({
348
+ tag: chunk.tag,
349
+ size: chunk.size,
350
+ offset: chunk.offset
351
+ })),
352
+ readError: this.readError ? {
353
+ name: this.readError.name,
354
+ message: this.readError.message
355
+ } : null
356
+ };
357
+ }
358
+ }
359
+
360
+ /**
361
+ * Decode and cache one private JSON document.
362
+ *
363
+ * @param {CewgpuPackage} pkg Package reader.
364
+ * @param {string} tag Chunk tag.
365
+ * @returns {object|null} Private parsed JSON, or null when absent.
366
+ */
367
+ function getCachedJson(pkg, tag) {
368
+ if (!pkg.jsonCache.has(tag)) {
369
+ const chunk = pkg.GetChunk(tag);
370
+ pkg.jsonCache.set(tag, chunk ? JSON.parse(jsonTextDecoder.decode(chunk.bytes)) : null);
371
+ }
372
+ return pkg.jsonCache.get(tag);
373
+ }
374
+
375
+ /**
376
+ * Copy JSON-compatible data without reparsing its source chunk.
377
+ *
378
+ * @param {any} value Cached JSON value.
379
+ * @returns {any} Structurally independent JSON value.
380
+ */
381
+ function cloneJson(value) {
382
+ if (Array.isArray(value)) return value.map(cloneJson);
383
+ if (value && typeof value === "object") {
384
+ return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, cloneJson(entry)]));
385
+ }
386
+ return value;
387
+ }
388
+
389
+ /**
390
+ * Decodes an ASCII four-character code.
391
+ *
392
+ * @param {Uint8Array} bytes Four-byte tag payload.
393
+ * @returns {string} ASCII string.
394
+ */
395
+ function decodeAscii(bytes) {
396
+ return String.fromCharCode(...bytes);
397
+ }
398
+
399
+ /**
400
+ * Marks one package as having passed the canonical effect envelope.
401
+ *
402
+ * Reflection and backend accessors return null until this runs, so a
403
+ * hand-assembled or tampered container cannot be hydrated as if it had been
404
+ * validated. This is intentionally an internal deep import rather than
405
+ * package-root API.
406
+ *
407
+ * @param {CewgpuPackage} pkg Validated package reader.
408
+ * @returns {void}
409
+ */
410
+ function markEffectPackageValidated(pkg) {
411
+ validatedEffectPackages.add(pkg);
412
+ }
413
+
414
+ export { CewgpuPackage, markEffectPackageValidated };
415
+ //# sourceMappingURL=CewgpuPackage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CewgpuPackage.js","sources":["../../../../../../src/formats/webgpu/core/cewgpu/CewgpuPackage.js"],"sourcesContent":["import { WebgpuReader, asUint8Array } from \"./binary.js\";\nimport { validateCewgpuChunkTag } from \"./tags.js\";\nimport { sha256Bytes } from \"../../../../format/effect/sha256.js\";\nimport {\n hydrateEffectReflectionForPermutation\n} from \"../../../../format/effect/effectReflectionPackage.js\";\n\nconst validatedEffectPackages = new WeakSet();\nconst CEWGPU_MAGIC = \"CWGP\";\nconst CEWGPU_FORMAT = \"CEWGPU\";\nconst CEWGPU_VERSION = 1;\nconst textDecoder = new TextDecoder(\"utf-8\", { fatal: false });\nconst jsonTextDecoder = new TextDecoder(\"utf-8\", { fatal: true });\n\n/**\n * Reader for CarbonEngineJS CEWGPU shader packages.\n */\nexport class CewgpuPackage\n{\n /**\n * Creates an empty package reader.\n */\n constructor()\n {\n this.version = 0;\n this.chunks = [];\n this.chunkMap = new Map();\n this.jsonCache = new Map();\n this.reflectionBlobIndex = null;\n this.readError = null;\n this.sourcePath = \"\";\n }\n\n /**\n * Reads a CEWGPU package from bytes.\n *\n * @param {ArrayBuffer|ArrayBufferView|Uint8Array} source CEWGPU bytes.\n * @param {object} [options] Read options.\n * @param {string} [options.sourcePath] Source path for diagnostics.\n * @returns {boolean} True when the package was decoded.\n */\n Read(source, options = {})\n {\n this.version = 0;\n this.chunks = [];\n this.chunkMap = new Map();\n this.jsonCache = new Map();\n this.reflectionBlobIndex = null;\n this.readError = null;\n this.sourcePath = options.sourcePath || \"\";\n\n try\n {\n const bytes = asUint8Array(source);\n const stream = new WebgpuReader(bytes, { source: this.sourcePath || \"CEWGPU\" });\n const magic = decodeAscii(stream.readRaw(CEWGPU_MAGIC.length));\n if (magic !== CEWGPU_MAGIC)\n {\n throw new Error(`Invalid CEWGPU magic \"${magic}\"`);\n }\n\n this.version = stream.readUint32();\n if (this.version !== CEWGPU_VERSION)\n {\n throw new Error(`Unsupported CEWGPU version ${this.version}`);\n }\n\n const chunkCount = stream.readUint32();\n for (let index = 0; index < chunkCount; index += 1)\n {\n const tag = decodeAscii(stream.readRaw(4));\n validateCewgpuChunkTag(tag);\n if (this.chunkMap.has(tag))\n {\n throw new Error(`CEWGPU package contains duplicate chunk tag ${tag}`);\n }\n const size = stream.readUint32();\n const offset = stream.offset;\n const chunkBytes = stream.readRaw(size);\n const chunk = {\n tag,\n size,\n offset,\n bytes: chunkBytes\n };\n this.chunks.push(chunk);\n this.chunkMap.set(tag, chunk);\n }\n\n if (stream.remaining !== 0)\n {\n throw new Error(`CEWGPU package has ${stream.remaining} trailing bytes`);\n }\n\n return true;\n }\n catch (error)\n {\n this.readError = error;\n this.chunks = [];\n this.chunkMap = new Map();\n this.jsonCache = new Map();\n this.reflectionBlobIndex = null;\n return false;\n }\n }\n\n /**\n * Reports whether the package decoded successfully.\n *\n * @returns {boolean} True when no read error is present.\n */\n IsGood()\n {\n return !this.readError && this.version === CEWGPU_VERSION;\n }\n\n /**\n * Gets a chunk by four-character tag.\n *\n * @param {string} tag Chunk tag.\n * @returns {{tag:string,size:number,offset:number,bytes:Uint8Array}|null} Chunk record.\n */\n GetChunk(tag)\n {\n return this.chunkMap.get(tag) || null;\n }\n\n /**\n * Decodes a text chunk.\n *\n * @param {string} tag Chunk tag.\n * @returns {string|null} Decoded text, or null when absent.\n */\n GetText(tag)\n {\n const chunk = this.GetChunk(tag);\n return chunk ? textDecoder.decode(chunk.bytes) : null;\n }\n\n /**\n * Decodes a JSON chunk.\n *\n * @param {string} tag Chunk tag.\n * @returns {object|null} Parsed JSON, or null when absent.\n */\n GetJson(tag)\n {\n return cloneJson(getCachedJson(this, tag));\n }\n\n /**\n * Gets translator summary metadata from the `INFO` chunk.\n *\n * @returns {object|null} Info JSON.\n */\n get info()\n {\n return this.GetJson(\"INFO\");\n }\n\n /**\n * Gets caller-provided metadata from the `META` chunk.\n *\n * @returns {object|null} Metadata JSON.\n */\n get metadata()\n {\n return this.GetJson(\"META\");\n }\n\n /**\n * Gets the complete source permutation graph when present.\n *\n * @returns {object|null} Parsed permutation graph.\n */\n get permutationGraph()\n {\n return this.GetJson(\"PGRF\");\n }\n\n /**\n * Gets complete source effect reflection when present.\n *\n * @returns {object|null} Parsed reflection document.\n */\n get reflection()\n {\n return this.GetJson(\"RFLX\");\n }\n\n /**\n * Gets the raw reflection blob store when present.\n *\n * @returns {Uint8Array|null} RBLB bytes.\n */\n get reflectionBlobBytes()\n {\n return this.GetChunk(\"RBLB\")?.bytes ?? null;\n }\n\n /**\n * Copies one reflected byte payload by blob key or exact reference.\n *\n * A string performs an inventory-key lookup. An object must exactly match\n * the stored blob key, offset, byte length, and digest.\n *\n * @param {string|object} value Blob key or exact RFLX byte-reference object.\n * @returns {Uint8Array|null} Owned payload bytes, or null when unavailable.\n */\n GetReflectionBlob(value)\n {\n const key = typeof value === \"string\" ? value : value?.blobKey;\n if (!this.reflectionBlobIndex)\n {\n this.reflectionBlobIndex = new Map(\n (getCachedJson(this, \"RFLX\")?.blobStore?.blobs ?? []).map((entry) => [\n entry.blobKey,\n entry\n ])\n );\n }\n const entry = this.reflectionBlobIndex.get(key);\n const bytes = this.reflectionBlobBytes;\n if (!entry || !bytes) return null;\n if (typeof value !== \"string\"\n && (!value\n || value.offset !== entry.offset\n || value.byteLength !== entry.byteLength\n || value.sha256 !== entry.sha256))\n {\n return null;\n }\n const end = entry.offset + entry.byteLength;\n if (!Number.isSafeInteger(entry.offset) || entry.offset < 0\n || !Number.isSafeInteger(entry.byteLength) || entry.byteLength < 0\n || end > bytes.byteLength\n || sha256Bytes(bytes.subarray(entry.offset, end)) !== entry.sha256)\n {\n return null;\n }\n return Uint8Array.from(bytes.subarray(entry.offset, end));\n }\n\n /**\n * Gets fully hydrated portable source reflection for one permutation.\n *\n * The optional index defaults to `META.bodyIndex`. Every reflected byte\n * field is returned as a fresh owned `Uint8Array`.\n *\n * @param {number} [permutationIndex] Exact PGRF permutation index.\n * @returns {object|null} Validated portable reflection, or null when absent.\n */\n GetPortableEffectReflection(\n permutationIndex\n )\n {\n if (!validatedEffectPackages.has(this)) return null;\n const reflection = getCachedJson(this, \"RFLX\");\n const permutationGraph = getCachedJson(this, \"PGRF\");\n if (!reflection || !permutationGraph) return null;\n const selectedIndex = permutationIndex\n ?? getCachedJson(this, \"META\")?.bodyIndex\n ?? 0;\n return hydrateEffectReflectionForPermutation(\n reflection,\n permutationGraph,\n selectedIndex,\n (reference) => this.GetReflectionBlob(reference)\n );\n }\n\n /**\n * Gets the all-body backend translation graph when present.\n *\n * Selected-mode packages do not carry this chunk.\n *\n * @returns {object|null} Parsed `CJS_WGSL_BODY_SET` document.\n */\n get backendBodySet()\n {\n return this.GetJson(\"WGSB\");\n }\n\n /**\n * Resolves the translated backend passes for one permutation index.\n *\n * Joins `PGRF` variant identity to the `WGSB` body record and expands every\n * pass reference into its shared translation unit. Returns null when the\n * package carries no all-body graph, and an explicitly unsupported record\n * when that body could not be lowered.\n *\n * @param {number} [permutationIndex] Exact PGRF permutation index.\n * @returns {object|null} Resolved backend body, or null when unavailable.\n */\n GetBackendBodyPrograms(permutationIndex)\n {\n if (!validatedEffectPackages.has(this)) return null;\n const bodySet = getCachedJson(this, \"WGSB\");\n const permutationGraph = getCachedJson(this, \"PGRF\");\n if (!bodySet || !permutationGraph) return null;\n\n const index = permutationIndex\n ?? getCachedJson(this, \"META\")?.bodyIndex\n ?? 0;\n const variant = permutationGraph.variants?.[index];\n if (!variant) return null;\n\n const body = bodySet.bodies?.find((entry) => entry.bodyKey === variant.bodyKey);\n if (!body) return null;\n if (body.status !== \"translated\")\n {\n return {\n permutationIndex: index,\n bodyKey: body.bodyKey,\n status: body.status,\n error: body.error,\n passes: []\n };\n }\n\n const units = new Map((bodySet.passUnits ?? []).map((unit) => [ unit.key, unit ]));\n\n return {\n permutationIndex: index,\n bodyKey: body.bodyKey,\n status: body.status,\n error: null,\n passes: body.passes.map((pass) =>\n {\n const unit = units.get(pass.unitKey);\n if (!unit)\n {\n throw new Error(\n `CEWGPU backend body ${body.bodyKey} references missing translation unit ${pass.unitKey}`\n );\n }\n return {\n passKey: pass.passKey,\n unitKey: pass.unitKey,\n wgslSetVersion: unit.wgslSetVersion,\n shaders: unit.shaders,\n layouts: unit.layouts,\n ...(unit.resourceTransforms\n ? { resourceTransforms: unit.resourceTransforms }\n : {})\n };\n })\n };\n }\n\n /**\n * Gets normalized shader analysis from the `ANLS` chunk.\n *\n * @returns {string|null} Analysis text.\n */\n get analysis()\n {\n return this.GetText(\"ANLS\");\n }\n\n /**\n * Gets normalized shader analysis metadata when the `ANLS` chunk contains\n * JSON.\n *\n * @returns {object|null} Parsed analysis, or null for raw text.\n */\n get analysisJson()\n {\n try\n {\n return this.GetJson(\"ANLS\");\n }\n catch\n {\n return null;\n }\n }\n\n /**\n * Gets emitted WGSL when present.\n *\n * @returns {string|null} WGSL text.\n */\n get wgsl()\n {\n return this.GetText(\"WGSL\");\n }\n\n /**\n * Gets emitted WGSL metadata when the `WGSL` chunk contains JSON.\n *\n * @returns {object|null} Parsed WGSL metadata, or null for raw source.\n */\n get wgslJson()\n {\n try\n {\n return this.GetJson(\"WGSL\");\n }\n catch\n {\n return null;\n }\n }\n\n /**\n * Returns a JSON-safe package summary.\n *\n * @returns {object} Serializable summary.\n */\n toJSON()\n {\n return {\n format: CEWGPU_FORMAT,\n version: this.version,\n sourcePath: this.sourcePath,\n chunks: this.chunks.map((chunk) => ({\n tag: chunk.tag,\n size: chunk.size,\n offset: chunk.offset\n })),\n readError: this.readError ? {\n name: this.readError.name,\n message: this.readError.message\n } : null\n };\n }\n}\n\n/**\n * Decode and cache one private JSON document.\n *\n * @param {CewgpuPackage} pkg Package reader.\n * @param {string} tag Chunk tag.\n * @returns {object|null} Private parsed JSON, or null when absent.\n */\nfunction getCachedJson(pkg, tag)\n{\n if (!pkg.jsonCache.has(tag))\n {\n const chunk = pkg.GetChunk(tag);\n pkg.jsonCache.set(\n tag,\n chunk ? JSON.parse(jsonTextDecoder.decode(chunk.bytes)) : null\n );\n }\n return pkg.jsonCache.get(tag);\n}\n\n/**\n * Copy JSON-compatible data without reparsing its source chunk.\n *\n * @param {any} value Cached JSON value.\n * @returns {any} Structurally independent JSON value.\n */\nfunction cloneJson(value)\n{\n if (Array.isArray(value)) return value.map(cloneJson);\n if (value && typeof value === \"object\")\n {\n return Object.fromEntries(Object.entries(value).map(([ key, entry ]) => [\n key,\n cloneJson(entry)\n ]));\n }\n return value;\n}\n\n/**\n * Decodes an ASCII four-character code.\n *\n * @param {Uint8Array} bytes Four-byte tag payload.\n * @returns {string} ASCII string.\n */\nfunction decodeAscii(bytes)\n{\n return String.fromCharCode(...bytes);\n}\n\n/**\n * Marks one package as having passed the canonical effect envelope.\n *\n * Reflection and backend accessors return null until this runs, so a\n * hand-assembled or tampered container cannot be hydrated as if it had been\n * validated. This is intentionally an internal deep import rather than\n * package-root API.\n *\n * @param {CewgpuPackage} pkg Validated package reader.\n * @returns {void}\n */\nexport function markEffectPackageValidated(pkg)\n{\n validatedEffectPackages.add(pkg);\n}\n"],"names":["validatedEffectPackages","WeakSet","CEWGPU_MAGIC","CEWGPU_FORMAT","CEWGPU_VERSION","textDecoder","TextDecoder","fatal","jsonTextDecoder","CewgpuPackage","constructor","version","chunks","chunkMap","Map","jsonCache","reflectionBlobIndex","readError","sourcePath","Read","source","options","bytes","asUint8Array","stream","WebgpuReader","magic","decodeAscii","readRaw","length","Error","readUint32","chunkCount","index","tag","validateCewgpuChunkTag","has","size","offset","chunkBytes","chunk","push","set","remaining","error","IsGood","GetChunk","get","GetText","decode","GetJson","cloneJson","getCachedJson","info","metadata","permutationGraph","reflection","reflectionBlobBytes","GetReflectionBlob","value","key","blobKey","blobStore","blobs","map","entry","byteLength","sha256","end","Number","isSafeInteger","sha256Bytes","subarray","Uint8Array","from","GetPortableEffectReflection","permutationIndex","selectedIndex","bodyIndex","hydrateEffectReflectionForPermutation","reference","backendBodySet","GetBackendBodyPrograms","bodySet","variant","variants","body","bodies","find","bodyKey","status","passes","units","passUnits","unit","pass","unitKey","passKey","wgslSetVersion","shaders","layouts","resourceTransforms","analysis","analysisJson","wgsl","wgslJson","toJSON","format","name","message","pkg","JSON","parse","Array","isArray","Object","fromEntries","entries","String","fromCharCode","markEffectPackageValidated","add"],"mappings":";;;;;AAOA,MAAMA,uBAAuB,GAAG,IAAIC,OAAO,EAAE;AAC7C,MAAMC,YAAY,GAAG,MAAM;AAC3B,MAAMC,aAAa,GAAG,QAAQ;AAC9B,MAAMC,cAAc,GAAG,CAAC;AACxB,MAAMC,WAAW,GAAG,IAAIC,WAAW,CAAC,OAAO,EAAE;AAAEC,EAAAA,KAAK,EAAE;AAAM,CAAC,CAAC;AAC9D,MAAMC,eAAe,GAAG,IAAIF,WAAW,CAAC,OAAO,EAAE;AAAEC,EAAAA,KAAK,EAAE;AAAK,CAAC,CAAC;;AAEjE;AACA;AACA;AACO,MAAME,aAAa,CAC1B;AACI;AACJ;AACA;AACIC,EAAAA,WAAWA,GACX;IACI,IAAI,CAACC,OAAO,GAAG,CAAC;IAChB,IAAI,CAACC,MAAM,GAAG,EAAE;AAChB,IAAA,IAAI,CAACC,QAAQ,GAAG,IAAIC,GAAG,EAAE;AACzB,IAAA,IAAI,CAACC,SAAS,GAAG,IAAID,GAAG,EAAE;IAC1B,IAAI,CAACE,mBAAmB,GAAG,IAAI;IAC/B,IAAI,CAACC,SAAS,GAAG,IAAI;IACrB,IAAI,CAACC,UAAU,GAAG,EAAE;AACxB,EAAA;;AAEA;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACIC,EAAAA,IAAIA,CAACC,MAA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AAIsD,KAAK,CAACC,OAAO,CAACvD,KAAK,CAAC,EAAE,OAAOA,KAAK,CAACK,GAAG,CAACb,SAAS,CAAC;AACrD,EAAA,IAAIQ,KAAK,IAAI,OAAOA,KAAK,KAAK,QAAQ,EACtC;AACI,IAAA,OAAOwD,MAAM,CAACC,WAAW,CAACD,MAAM,CAACE,OAAO,CAAC1D,KAAK,CAAC,CAACK,GAAG,CAAC,CAAC,CAAEJ,GAAG,EAAEK,KAAK,CAAE,KAAK,CACpEL,GAAG,EACHT,SAAS,CAACc,KAAK,CAAC,CACnB,CAAC,CAAC;AACP,EAAA;AACA,EAAA,OAAON,KAAK;AAChB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAAShC,WAAWA,CAACL,KAAK,EAC1B;AACI,EAAA,OAAOgG,MAAM,CAACC,YAAY,CAAC,GAAGjG,KAAK,CAAC;AACxC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASkG,0BAA0BA,CAACV,GAAG,EAC9C;AACI9G,EAAAA,uBAAuB,CAACyH,GAAG,CAACX,GAAG,CAAC;AACpC;;;;"}
@@ -0,0 +1,100 @@
1
+ import { validateCewgpuChunkTag } from './tags.js';
2
+
3
+ const CEWGPU_MAGIC = "CWGP";
4
+ const CEWGPU_VERSION = 1;
5
+ const textEncoder = new TextEncoder();
6
+
7
+ /**
8
+ * Builds CarbonEngineJS CEWGPU package bytes.
9
+ */
10
+ class CewgpuPackageBuilder {
11
+ /**
12
+ * Builds a CEWGPU v1 package from ordered chunks.
13
+ *
14
+ * @param {Array<[string, string|object|Uint8Array|ArrayBuffer|ArrayBufferView]>} chunks Ordered package chunks.
15
+ * @returns {Uint8Array} Package bytes.
16
+ */
17
+ static build(chunks) {
18
+ const tags = new Set();
19
+ const encodedChunks = chunks.map(([tag, value]) => ({
20
+ tag: normalizeTag(tag, tags),
21
+ bytes: normalizeChunkValue(value)
22
+ }));
23
+ const size = CEWGPU_MAGIC.length + 8 + encodedChunks.reduce((sum, chunk) => sum + 8 + chunk.bytes.length, 0);
24
+ const out = new Uint8Array(size);
25
+ const view = new DataView(out.buffer, out.byteOffset, out.byteLength);
26
+ let offset = 0;
27
+ offset = writeAscii(out, offset, CEWGPU_MAGIC);
28
+ view.setUint32(offset, CEWGPU_VERSION, true);
29
+ offset += 4;
30
+ view.setUint32(offset, encodedChunks.length, true);
31
+ offset += 4;
32
+ for (const chunk of encodedChunks) {
33
+ offset = writeAscii(out, offset, chunk.tag);
34
+ view.setUint32(offset, chunk.bytes.length, true);
35
+ offset += 4;
36
+ out.set(chunk.bytes, offset);
37
+ offset += chunk.bytes.length;
38
+ }
39
+ return out;
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Normalizes a package chunk tag.
45
+ *
46
+ * @param {string} tag Four-character chunk tag.
47
+ * @param {Set<string>} tags Tags already present in the package.
48
+ * @returns {string} Normalized tag.
49
+ */
50
+ function normalizeTag(tag, tags) {
51
+ const normalized = validateCewgpuChunkTag(tag);
52
+ if (tags.has(normalized)) {
53
+ throw new Error(`CEWGPU package contains duplicate chunk tag ${normalized}`);
54
+ }
55
+ tags.add(normalized);
56
+ return normalized;
57
+ }
58
+
59
+ /**
60
+ * Normalizes a package chunk payload.
61
+ *
62
+ * @param {string|object|Uint8Array|ArrayBuffer|ArrayBufferView} value Chunk payload.
63
+ * @returns {Uint8Array} Payload bytes.
64
+ */
65
+ function normalizeChunkValue(value) {
66
+ if (typeof value === "string") {
67
+ return textEncoder.encode(value);
68
+ }
69
+ if (value instanceof Uint8Array) {
70
+ return value;
71
+ }
72
+ if (value instanceof ArrayBuffer) {
73
+ return new Uint8Array(value);
74
+ }
75
+ if (ArrayBuffer.isView(value)) {
76
+ return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
77
+ }
78
+ if (value && typeof value === "object") {
79
+ return textEncoder.encode(`${JSON.stringify(value)}\n`);
80
+ }
81
+ throw new Error("Unsupported CEWGPU chunk value");
82
+ }
83
+
84
+ /**
85
+ * Writes ASCII text into a byte buffer.
86
+ *
87
+ * @param {Uint8Array} out Output buffer.
88
+ * @param {number} offset Current byte offset.
89
+ * @param {string} value ASCII text.
90
+ * @returns {number} Updated byte offset.
91
+ */
92
+ function writeAscii(out, offset, value) {
93
+ for (let i = 0; i < value.length; i += 1) {
94
+ out[offset + i] = value.charCodeAt(i) & 0xff;
95
+ }
96
+ return offset + value.length;
97
+ }
98
+
99
+ export { CewgpuPackageBuilder };
100
+ //# sourceMappingURL=CewgpuPackageBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CewgpuPackageBuilder.js","sources":["../../../../../../src/formats/webgpu/core/cewgpu/CewgpuPackageBuilder.js"],"sourcesContent":["import { validateCewgpuChunkTag } from \"./tags.js\";\n\nconst CEWGPU_MAGIC = \"CWGP\";\nconst CEWGPU_VERSION = 1;\nconst textEncoder = new TextEncoder();\n\n/**\n * Builds CarbonEngineJS CEWGPU package bytes.\n */\nexport class CewgpuPackageBuilder\n{\n /**\n * Builds a CEWGPU v1 package from ordered chunks.\n *\n * @param {Array<[string, string|object|Uint8Array|ArrayBuffer|ArrayBufferView]>} chunks Ordered package chunks.\n * @returns {Uint8Array} Package bytes.\n */\n static build(chunks)\n {\n const tags = new Set();\n const encodedChunks = chunks.map(([ tag, value ]) => ({\n tag: normalizeTag(tag, tags),\n bytes: normalizeChunkValue(value)\n }));\n\n const size = CEWGPU_MAGIC.length + 8 + encodedChunks.reduce((sum, chunk) => sum + 8 + chunk.bytes.length, 0);\n const out = new Uint8Array(size);\n const view = new DataView(out.buffer, out.byteOffset, out.byteLength);\n let offset = 0;\n\n offset = writeAscii(out, offset, CEWGPU_MAGIC);\n view.setUint32(offset, CEWGPU_VERSION, true);\n offset += 4;\n view.setUint32(offset, encodedChunks.length, true);\n offset += 4;\n\n for (const chunk of encodedChunks)\n {\n offset = writeAscii(out, offset, chunk.tag);\n view.setUint32(offset, chunk.bytes.length, true);\n offset += 4;\n out.set(chunk.bytes, offset);\n offset += chunk.bytes.length;\n }\n\n return out;\n }\n}\n\n/**\n * Normalizes a package chunk tag.\n *\n * @param {string} tag Four-character chunk tag.\n * @param {Set<string>} tags Tags already present in the package.\n * @returns {string} Normalized tag.\n */\nfunction normalizeTag(tag, tags)\n{\n const normalized = validateCewgpuChunkTag(tag);\n if (tags.has(normalized))\n {\n throw new Error(`CEWGPU package contains duplicate chunk tag ${normalized}`);\n }\n tags.add(normalized);\n return normalized;\n}\n\n/**\n * Normalizes a package chunk payload.\n *\n * @param {string|object|Uint8Array|ArrayBuffer|ArrayBufferView} value Chunk payload.\n * @returns {Uint8Array} Payload bytes.\n */\nfunction normalizeChunkValue(value)\n{\n if (typeof value === \"string\")\n {\n return textEncoder.encode(value);\n }\n if (value instanceof Uint8Array)\n {\n return value;\n }\n if (value instanceof ArrayBuffer)\n {\n return new Uint8Array(value);\n }\n if (ArrayBuffer.isView(value))\n {\n return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);\n }\n if (value && typeof value === \"object\")\n {\n return textEncoder.encode(`${JSON.stringify(value)}\\n`);\n }\n throw new Error(\"Unsupported CEWGPU chunk value\");\n}\n\n/**\n * Writes ASCII text into a byte buffer.\n *\n * @param {Uint8Array} out Output buffer.\n * @param {number} offset Current byte offset.\n * @param {string} value ASCII text.\n * @returns {number} Updated byte offset.\n */\nfunction writeAscii(out, offset, value)\n{\n for (let i = 0; i < value.length; i += 1)\n {\n out[offset + i] = value.charCodeAt(i) & 0xff;\n }\n return offset + value.length;\n}\n"],"names":["CEWGPU_MAGIC","CEWGPU_VERSION","textEncoder","TextEncoder","CewgpuPackageBuilder","build","chunks","tags","Set","encodedChunks","map","tag","value","normalizeTag","bytes","normalizeChunkValue","size","length","reduce","sum","chunk","out","Uint8Array","view","DataView","buffer","byteOffset","byteLength","offset","writeAscii","setUint32","set","normalized","validateCewgpuChunkTag","has","Error","add","encode","ArrayBuffer","isView","JSON","stringify","i","charCodeAt"],"mappings":";;AAEA,MAAMA,YAAY,GAAG,MAAM;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O,IAAIU,UAAU,CAACV,KAAK,CAACa,MAAM,EAAEb,KAAK,CAACc,UAAU,EAAEd,KAAK,CAACe,UAAU,CAAC;AAC3E,EAAA;AACA,EAAA,IAAIf,KAAK,IAAI,OAAOA,KAAK,KAAK,QAAQ,EACtC;AACI,IAAA,OAAOV,WAAW,CAACmC,MAAM,CAAC,CAAA,EAAGG,IAAI,CAACC,SAAS,CAAC7B,KAAK,CAAC,CAAA,EAAA,CAAI,CAAC;AAC3D,EAAA;AACA,EAAA,MAAM,IAAIuB,KAAK,CAAC,gCAAgC,CAAC;AACrD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASN,UAAUA,CAACR,GAAG,EAAEO,MAAM,EAAEhB,KAAK,EACtC;AACI,EAAA,KAAK,IAAI8B,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAG9B,KAAK,CAACK,MAAM,EAAEyB,CAAC,IAAI,CAAC,EACxC;AACIrB,IAAAA,GAAG,CAACO,MAAM,GAAGc,CAAC,CAAC,GAAG9B,KAAK,CAAC+B,UAAU,CAACD,CAAC,CAAC,GAAG,IAAI;AAChD,EAAA;AACA,EAAA,OAAOd,MAAM,GAAGhB,KAAK,CAACK,MAAM;AAChC;;;;"}
@@ -0,0 +1,93 @@
1
+ import { WebgpuReadError } from '../errors.js';
2
+
3
+ /**
4
+ * Returns a byte view for supported binary inputs without copying when
5
+ * possible.
6
+ *
7
+ * @param {ArrayBuffer|ArrayBufferView|Uint8Array} value Binary payload.
8
+ * @returns {Uint8Array} Normalized byte view.
9
+ */
10
+ function asUint8Array(value) {
11
+ if (value instanceof Uint8Array) return value;
12
+ if (value instanceof ArrayBuffer) return new Uint8Array(value);
13
+ if (ArrayBuffer.isView(value)) {
14
+ return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
15
+ }
16
+ throw new TypeError("Expected an ArrayBuffer or Uint8Array");
17
+ }
18
+
19
+ /**
20
+ * Minimal little-endian binary reader for the flat CEWGPU chunk container.
21
+ */
22
+ class WebgpuReader {
23
+ /**
24
+ * Creates a reader over a byte payload.
25
+ *
26
+ * @param {ArrayBuffer|ArrayBufferView|Uint8Array} bytes Source payload.
27
+ * @param {object} [options] Reader bounds and metadata.
28
+ * @param {number} [options.offset] Initial byte offset.
29
+ * @param {number} [options.end] Exclusive end offset.
30
+ * @param {string} [options.source] Source name used in error details.
31
+ */
32
+ constructor(bytes, options = {}) {
33
+ this.bytes = asUint8Array(bytes);
34
+ this.view = new DataView(this.bytes.buffer, this.bytes.byteOffset, this.bytes.byteLength);
35
+ this.offset = Number(options.offset) || 0;
36
+ this.end = Number.isInteger(options.end) ? options.end : this.bytes.length;
37
+ this.source = options.source || "memory";
38
+ }
39
+
40
+ /**
41
+ * Returns the unread byte count inside the configured reader bounds.
42
+ *
43
+ * @returns {number} Remaining bytes.
44
+ */
45
+ get remaining() {
46
+ return this.end - this.offset;
47
+ }
48
+
49
+ /**
50
+ * Reads a byte range from the payload.
51
+ *
52
+ * @param {number} size Byte count to read.
53
+ * @returns {Uint8Array} View over the read bytes.
54
+ */
55
+ readRaw(size) {
56
+ this._require(size);
57
+ const start = this.offset;
58
+ this.offset += size;
59
+ return this.bytes.subarray(start, start + size);
60
+ }
61
+
62
+ /**
63
+ * Reads a little-endian unsigned 32-bit integer.
64
+ *
65
+ * @returns {number} Integer value.
66
+ */
67
+ readUint32() {
68
+ this._require(4);
69
+ const value = this.view.getUint32(this.offset, true);
70
+ this.offset += 4;
71
+ return value;
72
+ }
73
+
74
+ /**
75
+ * Ensures the requested read fits inside the configured payload bounds.
76
+ *
77
+ * @param {number} size Requested byte count.
78
+ * @private
79
+ */
80
+ _require(size) {
81
+ if (!Number.isInteger(size) || size < 0 || this.offset + size > this.end) {
82
+ throw new WebgpuReadError("Unexpected end of CEWGPU package data", {
83
+ source: this.source,
84
+ offset: this.offset,
85
+ requested: size,
86
+ end: this.end
87
+ });
88
+ }
89
+ }
90
+ }
91
+
92
+ export { WebgpuReader, asUint8Array };
93
+ //# sourceMappingURL=binary.js.map