@carbonenginejs/runtime-resource 0.12.2 → 0.14.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 (238) hide show
  1. package/README.md +21 -0
  2. package/dist/CjsResMan.js +393 -29
  3. package/dist/CjsResMan.js.map +1 -1
  4. package/dist/format/carbonEffect/CjsCarbonEffectReader.js +165 -118
  5. package/dist/format/carbonEffect/CjsCarbonEffectReader.js.map +1 -1
  6. package/dist/format/carbonEffect/buildCarbonEffectContainer.js +182 -0
  7. package/dist/format/carbonEffect/buildCarbonEffectContainer.js.map +1 -0
  8. package/dist/format/carbonEffect/carbonEffectBackendBlock.js +7 -113
  9. package/dist/format/carbonEffect/carbonEffectBackendBlock.js.map +1 -1
  10. package/dist/format/carbonEffect/carbonEffectRecords.js +258 -66
  11. package/dist/format/carbonEffect/carbonEffectRecords.js.map +1 -1
  12. package/dist/format/carbonEffect/carbonEffectResourceTransform.js +197 -0
  13. package/dist/format/carbonEffect/carbonEffectResourceTransform.js.map +1 -0
  14. package/dist/format/effect/effectBodyInventory.js +146 -0
  15. package/dist/format/effect/effectBodyInventory.js.map +1 -0
  16. package/dist/format/effect/effectPermutationGraph.js +13 -13
  17. package/dist/format/effect/effectPermutationGraph.js.map +1 -1
  18. package/dist/format/index.js +4 -4
  19. package/dist/formats/black/CjsBlackFormat.js +19 -1
  20. package/dist/formats/black/CjsBlackFormat.js.map +1 -1
  21. package/dist/formats/bnk/CjsBnkFormat.js +28 -9
  22. package/dist/formats/bnk/CjsBnkFormat.js.map +1 -1
  23. package/dist/formats/bnk/core/busNodes.js +252 -0
  24. package/dist/formats/bnk/core/busNodes.js.map +1 -0
  25. package/dist/formats/bnk/core/effectNodes.js +147 -0
  26. package/dist/formats/bnk/core/effectNodes.js.map +1 -0
  27. package/dist/formats/bnk/core/eventAction.js +135 -24
  28. package/dist/formats/bnk/core/eventAction.js.map +1 -1
  29. package/dist/formats/bnk/core/globalSettings.js +215 -0
  30. package/dist/formats/bnk/core/globalSettings.js.map +1 -0
  31. package/dist/formats/bnk/core/helpers.js +37 -5
  32. package/dist/formats/bnk/core/helpers.js.map +1 -1
  33. package/dist/formats/bnk/core/musicNodes.js +43 -19
  34. package/dist/formats/bnk/core/musicNodes.js.map +1 -1
  35. package/dist/formats/bnk/core/nodeBase.js +28 -7
  36. package/dist/formats/bnk/core/nodeBase.js.map +1 -1
  37. package/dist/formats/dds/core/helpers.js +40 -1
  38. package/dist/formats/dds/core/helpers.js.map +1 -1
  39. package/dist/formats/dxbc/CjsDxbcFormat.js +45 -0
  40. package/dist/formats/dxbc/CjsDxbcFormat.js.map +1 -1
  41. package/dist/formats/dxbc/core/disassemble.js +240 -0
  42. package/dist/formats/dxbc/core/disassemble.js.map +1 -0
  43. package/dist/formats/gltf/CjsGltfFormat.js +1 -39
  44. package/dist/formats/gltf/CjsGltfFormat.js.map +1 -1
  45. package/dist/formats/gltf/core/helpers.js +1 -21
  46. package/dist/formats/gltf/core/helpers.js.map +1 -1
  47. package/dist/formats/hlsl/CjsHlslFormat.js +0 -21
  48. package/dist/formats/hlsl/CjsHlslFormat.js.map +1 -1
  49. package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js +118 -49
  50. package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js.map +1 -1
  51. package/dist/formats/hlsl/core/detailMapFamily.js +128 -0
  52. package/dist/formats/hlsl/core/detailMapFamily.js.map +1 -0
  53. package/dist/formats/hlsl/core/localLightFamily.js +133 -0
  54. package/dist/formats/hlsl/core/localLightFamily.js.map +1 -0
  55. package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js +79 -73
  56. package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js.map +1 -1
  57. package/dist/formats/hlsl/core/tr2/shader/HlslEffectBindingManifest.js +8 -1
  58. package/dist/formats/hlsl/core/tr2/shader/HlslEffectBindingManifest.js.map +1 -1
  59. package/dist/formats/hlsl/core/tr2/shader/HlslEffectDescription.js +11 -691
  60. package/dist/formats/hlsl/core/tr2/shader/HlslEffectDescription.js.map +1 -1
  61. package/dist/formats/index.js +4 -2
  62. package/dist/formats/index.js.map +1 -1
  63. package/dist/formats/obj/CjsObjFormat.js +1 -22
  64. package/dist/formats/obj/CjsObjFormat.js.map +1 -1
  65. package/dist/formats/obj/core/helpers.js +1 -21
  66. package/dist/formats/obj/core/helpers.js.map +1 -1
  67. package/dist/formats/pickle/CjsPickleFormat.js +214 -0
  68. package/dist/formats/pickle/CjsPickleFormat.js.map +1 -0
  69. package/dist/formats/pickle/core/CjsPickleProtocol0Reader.js +551 -0
  70. package/dist/formats/pickle/core/CjsPickleProtocol0Reader.js.map +1 -0
  71. package/dist/formats/pickle/index.js +2 -0
  72. package/dist/formats/pickle/index.js.map +1 -0
  73. package/dist/formats/red/core/redGraph.js +11 -8
  74. package/dist/formats/red/core/redGraph.js.map +1 -1
  75. package/dist/formats/stl/CjsStlFormat.js +1 -46
  76. package/dist/formats/stl/CjsStlFormat.js.map +1 -1
  77. package/dist/formats/stl/core/helpers.js +1 -21
  78. package/dist/formats/stl/core/helpers.js.map +1 -1
  79. package/dist/formats/webgl/CjsWebglFormat.js +33 -55
  80. package/dist/formats/webgl/CjsWebglFormat.js.map +1 -1
  81. package/dist/formats/webgl/core/buildGlslEffectContainer.js +70 -0
  82. package/dist/formats/webgl/core/buildGlslEffectContainer.js.map +1 -0
  83. package/dist/formats/webgl/core/effectPackage.js +216 -108
  84. package/dist/formats/webgl/core/effectPackage.js.map +1 -1
  85. package/dist/formats/webgl/core/errors.js +1 -1
  86. package/dist/formats/webgl/core/errors.js.map +1 -1
  87. package/dist/formats/webgl/core/glsl/DxbcGlslEmitter.js +166 -24
  88. package/dist/formats/webgl/core/glsl/DxbcGlslEmitter.js.map +1 -1
  89. package/dist/formats/webgl/core/glsl/DxbcGlslOperandFormatter.js +63 -5
  90. package/dist/formats/webgl/core/glsl/DxbcGlslOperandFormatter.js.map +1 -1
  91. package/dist/formats/webgl/core/glsl/packedLightFixups.js +98 -0
  92. package/dist/formats/webgl/core/glsl/packedLightFixups.js.map +1 -0
  93. package/dist/formats/webgl/core/glslBackendBlock.js +552 -0
  94. package/dist/formats/webgl/core/glslBackendBlock.js.map +1 -0
  95. package/dist/formats/webgl/core/glslBackendBodySet.js +243 -0
  96. package/dist/formats/webgl/core/glslBackendBodySet.js.map +1 -0
  97. package/dist/formats/webgl/core/{cewgCompleteness.js → glslEffectCompleteness.js} +12 -8
  98. package/dist/formats/webgl/core/glslEffectCompleteness.js.map +1 -0
  99. package/dist/formats/webgl/core/helpers.js +33 -172
  100. package/dist/formats/webgl/core/helpers.js.map +1 -1
  101. package/dist/formats/webgl/core/inspectGlslEffectContainer.js +122 -0
  102. package/dist/formats/webgl/core/inspectGlslEffectContainer.js.map +1 -0
  103. package/dist/formats/webgl/core/readGlslEffectContainer.js +249 -0
  104. package/dist/formats/webgl/core/readGlslEffectContainer.js.map +1 -0
  105. package/dist/formats/webgpu/CjsWebgpuFormat.js +15 -15
  106. package/dist/formats/webgpu/CjsWebgpuFormat.js.map +1 -1
  107. package/dist/formats/webgpu/core/buildCarbonEffectContainer.js +37 -145
  108. package/dist/formats/webgpu/core/buildCarbonEffectContainer.js.map +1 -1
  109. package/dist/formats/webgpu/core/{cewgpu/CewgpuContainer.js → carbonWebgpu/CarbonWebgpuContainer.js} +13 -27
  110. package/dist/formats/webgpu/core/carbonWebgpu/CarbonWebgpuContainer.js.map +1 -0
  111. package/dist/formats/webgpu/core/{cewgpu → carbonWebgpu}/containerViews.js +1 -1
  112. package/dist/formats/webgpu/core/carbonWebgpu/containerViews.js.map +1 -0
  113. package/dist/formats/webgpu/core/{cewgpu → carbonWebgpu}/validateContainer.js +4 -4
  114. package/dist/formats/webgpu/core/carbonWebgpu/validateContainer.js.map +1 -0
  115. package/dist/formats/webgpu/core/effectBackendBodySet.js +18 -18
  116. package/dist/formats/webgpu/core/effectBackendBodySet.js.map +1 -1
  117. package/dist/formats/webgpu/core/errors.js +1 -1
  118. package/dist/formats/webgpu/core/errors.js.map +1 -1
  119. package/dist/formats/webgpu/core/helpers.js +22 -22
  120. package/dist/formats/webgpu/core/helpers.js.map +1 -1
  121. package/dist/formats/webgpu/core/packageEffect.js +11 -15
  122. package/dist/formats/webgpu/core/packageEffect.js.map +1 -1
  123. package/dist/formats/webgpu/core/packageEffectSelection.js +1 -1
  124. package/dist/formats/webgpu/core/packageEffectSelection.js.map +1 -1
  125. package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js +23 -23
  126. package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js.map +1 -1
  127. package/dist/formats/webgpu/core/wgsl/buildWgslSet.js +6 -6
  128. package/dist/formats/webgpu/core/wgsl/buildWgslSet.js.map +1 -1
  129. package/dist/formats/yaml/CjsYamlFormat.js +3 -3
  130. package/dist/formats/yaml/CjsYamlFormat.js.map +1 -1
  131. package/dist/formats/yaml/core/CjsYamlReader.js +4 -6
  132. package/dist/formats/yaml/core/CjsYamlReader.js.map +1 -1
  133. package/dist/formats/yaml/core/helpers.js +27 -1
  134. package/dist/formats/yaml/core/helpers.js.map +1 -1
  135. package/dist/index.js +2 -0
  136. package/dist/index.js.map +1 -1
  137. package/dist/resource/CjsLoadingObject.js +19 -0
  138. package/dist/resource/CjsLoadingObject.js.map +1 -0
  139. package/dist/resource/CjsResource.js +4 -0
  140. package/dist/resource/CjsResource.js.map +1 -1
  141. package/dist/resource/ResourceHandlerMode.js +14 -0
  142. package/dist/resource/ResourceHandlerMode.js.map +1 -0
  143. package/dist/resource/index.js +2 -0
  144. package/dist/resource/index.js.map +1 -1
  145. package/dist/resource/shader/Tr2EffectRes.js +118 -213
  146. package/dist/resource/shader/Tr2EffectRes.js.map +1 -1
  147. package/dist/resource/shader/Tr2Shader.js +37 -15
  148. package/dist/resource/shader/Tr2Shader.js.map +1 -1
  149. package/dist/resource/shader/reflection/Tr2EffectConstant.js +37 -29
  150. package/dist/resource/shader/reflection/Tr2EffectConstant.js.map +1 -1
  151. package/dist/resource/shader/reflection/Tr2EffectDescription.js +39 -34
  152. package/dist/resource/shader/reflection/Tr2EffectDescription.js.map +1 -1
  153. package/dist/resource/shader/reflection/Tr2EffectLibrary.js +51 -30
  154. package/dist/resource/shader/reflection/Tr2EffectLibrary.js.map +1 -1
  155. package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js +45 -25
  156. package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js.map +1 -1
  157. package/dist/resource/shader/reflection/Tr2EffectResource.js +51 -17
  158. package/dist/resource/shader/reflection/Tr2EffectResource.js.map +1 -1
  159. package/dist/resource/shader/reflection/Tr2EffectStageInput.js +219 -88
  160. package/dist/resource/shader/reflection/Tr2EffectStageInput.js.map +1 -1
  161. package/dist/resource/shader/reflection/Tr2EffectTechnique.js +28 -18
  162. package/dist/resource/shader/reflection/Tr2EffectTechnique.js.map +1 -1
  163. package/dist/resource/shader/reflection/Tr2Pass.js +96 -39
  164. package/dist/resource/shader/reflection/Tr2Pass.js.map +1 -1
  165. package/dist/resource/shader/reflection/carbonRecordFields.js +159 -0
  166. package/dist/resource/shader/reflection/carbonRecordFields.js.map +1 -0
  167. package/dist/resource/shader/reflection/shaderStage.js +22 -0
  168. package/dist/resource/shader/reflection/shaderStage.js.map +1 -0
  169. package/dist/resource/shader/sampler/Tr2SamplerSetup.js +68 -10
  170. package/dist/resource/shader/sampler/Tr2SamplerSetup.js.map +1 -1
  171. package/dist/worker/CjsResManMainThreadLoader.js +9 -7
  172. package/dist/worker/CjsResManMainThreadLoader.js.map +1 -1
  173. package/dist/worker/CjsResManWorker.js +5 -4
  174. package/dist/worker/CjsResManWorker.js.map +1 -1
  175. package/dist/worker/CjsResManWorkerLoader.js +9 -6
  176. package/dist/worker/CjsResManWorkerLoader.js.map +1 -1
  177. package/docs/README.md +2 -2
  178. package/docs/architecture.md +12 -3
  179. package/docs/concepts/resource-lifecycle.md +9 -8
  180. package/docs/concepts/shader-resource-model.md +14 -17
  181. package/docs/concepts/writing-an-engine-adapter.md +1 -1
  182. package/docs/formats/README.md +4 -2
  183. package/docs/formats/carbon-effect-container.md +127 -26
  184. package/docs/formats/dxbc/architecture.md +1 -1
  185. package/docs/formats/dxbc/reference/api.md +28 -0
  186. package/docs/formats/hlsl/README.md +3 -3
  187. package/docs/formats/hlsl/architecture.md +8 -9
  188. package/docs/formats/hlsl/guides/hydrating-json-output.md +3 -5
  189. package/docs/formats/hlsl/guides/reading-effects.md +5 -1
  190. package/docs/formats/hlsl/reference/advanced-analysis.md +20 -25
  191. package/docs/formats/hlsl/reference/api.md +0 -7
  192. package/docs/formats/hlsl/reference/json-graph.md +1 -4
  193. package/docs/formats/pickle.md +82 -0
  194. package/docs/formats/webgl/README.md +71 -13
  195. package/docs/formats/webgl/architecture.md +16 -17
  196. package/docs/formats/webgl/carbon-constant-layouts.md +3 -3
  197. package/docs/formats/webgl/decl-io.md +3 -3
  198. package/docs/formats/webgl/memory-structured.md +27 -8
  199. package/docs/formats/webgl/texture-sample.md +1 -1
  200. package/docs/formats/webgpu/README.md +3 -3
  201. package/docs/formats/webgpu/architecture.md +5 -6
  202. package/docs/formats/webgpu/formats/{cewgpu.md → carbon-webgpu.md} +10 -11
  203. package/docs/formats/webgpu/guides/effect-packaging.md +6 -8
  204. package/docs/formats/webgpu/reference/api.md +11 -12
  205. package/docs/formats/webgpu/reference/wgsl-compatibility.md +11 -8
  206. package/docs/formats/wwise.md +63 -2
  207. package/docs/reference/classes/core.md +10 -0
  208. package/docs/reference/classes/formats.md +40 -48
  209. package/docs/reference/classes/resources.md +2 -2
  210. package/docs/reference/queues.md +88 -4
  211. package/docs/reference/workers.md +7 -0
  212. package/package.json +61 -61
  213. package/dist/format/carbonEffect/carbonDescriptionFromPortable.js +0 -372
  214. package/dist/format/carbonEffect/carbonDescriptionFromPortable.js.map +0 -1
  215. package/dist/format/effect/effectReflectionPackage.js +0 -636
  216. package/dist/format/effect/effectReflectionPackage.js.map +0 -1
  217. package/dist/formats/hlsl/core/HlslReader.js +0 -16
  218. package/dist/formats/hlsl/core/HlslReader.js.map +0 -1
  219. package/dist/formats/hlsl/core/portableReflection.js +0 -848
  220. package/dist/formats/hlsl/core/portableReflection.js.map +0 -1
  221. package/dist/formats/hlsl/portable.js +0 -2
  222. package/dist/formats/hlsl/portable.js.map +0 -1
  223. package/dist/formats/webgl/core/cewg/CewgPackage.js +0 -340
  224. package/dist/formats/webgl/core/cewg/CewgPackage.js.map +0 -1
  225. package/dist/formats/webgl/core/cewg/CewgPackageBuilder.js +0 -104
  226. package/dist/formats/webgl/core/cewg/CewgPackageBuilder.js.map +0 -1
  227. package/dist/formats/webgl/core/cewg/binary.js +0 -19
  228. package/dist/formats/webgl/core/cewg/binary.js.map +0 -1
  229. package/dist/formats/webgl/core/cewgCompleteness.js.map +0 -1
  230. package/dist/formats/webgl/core/effectPackageValidation.js +0 -331
  231. package/dist/formats/webgl/core/effectPackageValidation.js.map +0 -1
  232. package/dist/formats/webgpu/core/cewgpu/CewgpuContainer.js.map +0 -1
  233. package/dist/formats/webgpu/core/cewgpu/containerViews.js.map +0 -1
  234. package/dist/formats/webgpu/core/cewgpu/validateContainer.js.map +0 -1
  235. package/dist/resource/shader/portable.js +0 -33
  236. package/dist/resource/shader/portable.js.map +0 -1
  237. package/docs/formats/hlsl/reference/portable-reflection.md +0 -141
  238. package/docs/formats/webgl/effect-reflection.md +0 -127
@@ -1 +1 @@
1
- {"version":3,"file":"CjsHlslFormat.js","sources":["../../../../src/formats/hlsl/CjsHlslFormat.js"],"sourcesContent":["/**\n * Exposed CarbonEngineJS-facing Tr2 effect container format class.\n *\n * Keep this file small and reviewable: the Tr2 effect graph parser lives\n * under src/core/tr2 (internal parsing machinery, not part of this\n * package's public surface); input/option normalization, the shared read\n * path, and the JSON emitters live under src/core.\n */\n\nimport { HlslEffectRes } from \"./core/tr2/resources/HlslEffectRes.js\";\nimport {\n CLASS_KEYS,\n DEFAULT_VALUES,\n OUTPUT_JSON,\n OUTPUT_METADATA,\n OUTPUT_RAW,\n inspectWithValues,\n normalizeValues,\n readWithValues,\n toBytes,\n toJsonValue,\n validateClass,\n validateClassKey\n} from \"./core/helpers.js\";\n\nconst FORMAT_NAME = \"CjsHlslFormat\";\n\n/**\n * CarbonEngineJS-facing reader for CCP's Tr2 compiled effect container\n * format (`.sm_hi` / `.sm_lo` / `.sm_depth` bodies).\n *\n * The Cjs prefix marks this as a JavaScript format/construction boundary.\n * This format profile has no dependency on any DXBC/shader-bytecode decoder: shader\n * bodies stay as opaque bytes in the emitted graph. The public contract is\n * plain JSON data (`emit: \"json\"`, the default) — the documented effect\n * graph shape described in `docs/reference/json-graph.md`. `emit: \"raw\"`\n * exposes the internal\n * HlslEffectRes graph directly; treat it as unstable, not schema-guaranteed\n * internals, useful mainly for resolving multiple permutations by hand.\n *\n * The `classes` option lets a caller register constructors for specific\n * node kinds in the emitted JSON graph (see `CjsHlslFormat.CLASS_KEYS`);\n * class registration does not depend on importing internal graph classes.\n */\nexport class CjsHlslFormat\n{\n\n #emit = DEFAULT_VALUES.emit;\n #source = DEFAULT_VALUES.source;\n #permutation = DEFAULT_VALUES.permutation;\n #classes = DEFAULT_VALUES.classes;\n\n /**\n * Create a reusable format profile.\n *\n * @param {object} [options] Default format values.\n */\n constructor(options = {})\n {\n this.SetValues(options);\n }\n\n /**\n * Set format values for this reusable profile.\n *\n * @param {object} [options] Values to merge into the profile.\n * @returns {CjsHlslFormat} This format profile.\n */\n SetValues(options = {})\n {\n const values = normalizeValues(this.GetValues(), options, FORMAT_NAME);\n\n this.#emit = values.emit;\n this.#source = values.source;\n this.#permutation = values.permutation;\n this.#classes = values.classes;\n\n return this;\n }\n\n /**\n * Get this profile's current values, optionally with per-call overrides.\n *\n * @param {object} [options] Optional values to merge into a copy.\n * @returns {object} A copy of the effective values.\n */\n GetValues(options = {})\n {\n return normalizeValues({\n emit: this.#emit,\n source: this.#source,\n permutation: this.#permutation,\n classes: this.#classes\n }, options, FORMAT_NAME);\n }\n\n /**\n * Set multiple node-class constructors for this profile.\n *\n * @param {object} [classes] Map of node class keys to constructors. See {@link CjsHlslFormat.CLASS_KEYS}.\n * @returns {CjsHlslFormat} This format profile.\n */\n SetClasses(classes = {})\n {\n return this.SetValues({ classes });\n }\n\n /**\n * Set one node-class constructor for this profile.\n *\n * @param {string} type Node class key.\n * @param {Function|null|undefined} Class Constructor to use, or nullish to delete.\n * @returns {CjsHlslFormat} This format profile.\n */\n SetClass(type, Class)\n {\n if (Class === null || Class === undefined)\n {\n validateClassKey(type, FORMAT_NAME);\n const classes = { ...this.#classes };\n delete classes[type];\n this.#classes = classes;\n return this;\n }\n\n validateClass(type, Class, FORMAT_NAME);\n return this.SetValues({ classes: { [type]: Class } });\n }\n\n /**\n * Get a configured node-class constructor.\n *\n * @param {string} type Node class key.\n * @returns {Function|undefined} The registered constructor, if any.\n */\n GetClass(type)\n {\n validateClassKey(type, FORMAT_NAME);\n return this.#classes[type];\n }\n\n /**\n * Whether this reader has a constructor registered for a node class key.\n *\n * @param {string} type Node class key.\n * @returns {boolean} True when a constructor is registered.\n */\n HasClass(type)\n {\n return !!this.GetClass(type);\n }\n\n /**\n * Read a Tr2 effect payload with this profile's values.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Tr2 effect container bytes.\n * @param {object} [options] Per-call value overrides.\n * @returns {HlslEffectRes|object} The raw HlslEffectRes instance, compact metadata, or the documented JSON graph.\n */\n Read(input, options = {})\n {\n return readWithValues(input, this.GetValues(options));\n }\n\n /**\n * Inspect a Tr2 effect payload: header facts plus the default (or\n * selected) permutation's technique names and stage counts.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Tr2 effect container bytes.\n * @param {object} [options] Per-call value overrides.\n * @returns {object} Plain summary data.\n */\n Inspect(input, options = {})\n {\n return inspectWithValues(input, this.GetValues(options));\n }\n\n /**\n * Convert format output to JSON-compatible data.\n *\n * @param {any} value Format output to convert.\n * @returns {any} Plain JSON-compatible data.\n */\n ToJSON(value)\n {\n return toJsonValue(value);\n }\n\n /**\n * Static payload sniff. Static methods use camelCase by convention.\n *\n * The Tr2 effect container has no magic number, so this attempts a\n * cheap header-only load (version, string table, permutation axes and\n * body offsets — no shader bodies) and reports whether it succeeded.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Candidate bytes.\n * @returns {boolean} True when the payload's header decodes as a supported Tr2 effect.\n */\n static isSupported(input)\n {\n try\n {\n const bytes = toBytes(input);\n return new HlslEffectRes().DoLoad(bytes, { source: \"isSupported\" });\n }\n catch\n {\n return false;\n }\n }\n\n /**\n * Static one-shot read.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Tr2 effect container bytes.\n * @param {object} [options] Format values.\n * @returns {HlslEffectRes|object} The raw HlslEffectRes instance, compact metadata, or the documented JSON graph.\n */\n static read(input, options = {})\n {\n return readWithValues(input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));\n }\n\n /**\n * Static one-shot inspection.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Tr2 effect container bytes.\n * @param {object} [options] Format values.\n * @returns {object} Plain summary data.\n */\n static inspect(input, options = {})\n {\n return inspectWithValues(input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));\n }\n\n /**\n * Static JSON-compatible conversion.\n *\n * @param {any} value Format output to convert.\n * @returns {any} Plain JSON-compatible data.\n */\n static toJSON(value)\n {\n return toJsonValue(value);\n }\n\n /**\n * Node-only convenience: reads a compiled Tr2 effect file from disk.\n *\n * @param {string} path Path to a compiled Carbon effect file (`.sm_hi` etc.).\n * @param {object} [options] Format values.\n * @returns {Promise<HlslEffectRes|object>} The raw HlslEffectRes instance, compact metadata, or the documented JSON graph.\n */\n static async readFile(path, options = {})\n {\n if (typeof path !== \"string\" || !path)\n {\n throw new TypeError(`${FORMAT_NAME}: readFile path must be a non-empty string`);\n }\n\n const { readFile } = await import(\"node:fs/promises\");\n const input = await readFile(path);\n\n return readWithValues(input, normalizeValues(DEFAULT_VALUES, { source: path, ...options }, FORMAT_NAME));\n }\n\n static OUTPUT_JSON = OUTPUT_JSON;\n static OUTPUT_METADATA = OUTPUT_METADATA;\n static OUTPUT_RAW = OUTPUT_RAW;\n static CLASS_KEYS = CLASS_KEYS;\n static type = Object.freeze([ \"shader\" ]);\n static mediaTypes = Object.freeze([ \"shader\" ]);\n static inputTypes = Object.freeze([ \"sm_hi\", \"sm_lo\", \"sm_depth\" ]);\n static outputTypes = Object.freeze([ OUTPUT_JSON, OUTPUT_METADATA ]);\n static debugOutputTypes = Object.freeze([ OUTPUT_RAW ]);\n\n}\n\nexport default CjsHlslFormat;\n"],"names":["FORMAT_NAME","CjsHlslFormat","DEFAULT_VALUES","emit","source","permutation","classes","constructor","options","SetValues","values","normalizeValues","GetValues","SetClasses","SetClass","type","Class","undefined","validateClassKey","validateClass","GetClass","HasClass","Read","input","readWithValues","Inspect","inspectWithValues","ToJSON","value","toJsonValue","isSupported","bytes","toBytes","HlslEffectRes","DoLoad","read","inspect","toJSON","readFile","path","TypeError","OUTPUT_JSON","OUTPUT_METADATA","OUTPUT_RAW","CLASS_KEYS","Object","freeze","mediaTypes","inputTypes","outputTypes","debugOutputTypes"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAkBA,MAAMA,WAAW,GAAG,eAAe;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,aAAa,CAC1B;AAEI,EAAA,KAAK,GAAGC,cAAc,CAACC,IAAI;AAC3B,EAAA,OAAO,GAAGD,cAAc,CAACE,MAAM;AAC/B,EAAA,YAAY,GAAGF,cAAc,CAACG,WAAW;AACzC,EAAA,QAAQ,GAAGH,cAAc,CAACI,OAAO;;AAEjC;AACJ;AACA;AACA;AACA;AACIC,EAAAA,WAAWA,CAACC,OAAO,GAAG,EAAE,EACxB;AACI,IAAA,IAAI,CAACC,SAAS,CAACD,OAAO,CAAC;AA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AEZ,eAAe,CAACT,cAAc,EAAE;AAAEE,MAAAA,MAAM,EAAEmC,IAAI;MAAE,GAAG/B;KAAS,EAAER,WAAW,CAAC,CAAC;AAC5G,EAAA;EAEA,OAAOyC,WAAW,GAAGA,WAAW;EAChC,OAAOC,eAAe,GAAGA,eAAe;EACxC,OAAOC,UAAU,GAAGA,UAAU;EAC9B,OAAOC,UAAU,GAAGA,UAAU;EAC9B,OAAO7B,IAAI,GAAG8B,MAAM,CAACC,MAAM,CAAC,CAAE,QAAQ,CAAE,CAAC;EACzC,OAAOC,UAAU,GAAGF,MAAM,CAACC,MAAM,CAAC,CAAE,QAAQ,CAAE,CAAC;AAC/C,EAAA,OAAOE,UAAU,GAAGH,MAAM,CAACC,MAAM,CAAC,CAAE,OAAO,EAAE,OAAO,EAAE,UAAU,CAAE,CAAC;EACnE,OAAOG,WAAW,GAAGJ,MAAM,CAACC,MAAM,CAAC,CAAEL,WAAW,EAAEC,eAAe,CAAE,CAAC;EACpE,OAAOQ,gBAAgB,GAAGL,MAAM,CAACC,MAAM,CAAC,CAAEH,UAAU,CAAE,CAAC;AAE3D;;;;"}
1
+ {"version":3,"file":"CjsHlslFormat.js","sources":["../../../../src/formats/hlsl/CjsHlslFormat.js"],"sourcesContent":["/**\n * Exposed CarbonEngineJS-facing Tr2 effect container format class.\n *\n * Keep this file small and reviewable: the Tr2 effect graph parser lives\n * under src/core/tr2 (internal parsing machinery, not part of this\n * package's public surface); input/option normalization, the shared read\n * path, and the JSON emitters live under src/core.\n */\n\nimport { HlslEffectRes } from \"./core/tr2/resources/HlslEffectRes.js\";\nimport {\n CLASS_KEYS,\n DEFAULT_VALUES,\n OUTPUT_JSON,\n OUTPUT_METADATA,\n OUTPUT_RAW,\n inspectWithValues,\n normalizeValues,\n readWithValues,\n toBytes,\n toJsonValue,\n validateClass,\n validateClassKey\n} from \"./core/helpers.js\";\n\nconst FORMAT_NAME = \"CjsHlslFormat\";\n\n/**\n * CarbonEngineJS-facing reader for CCP's Tr2 compiled effect container\n * format (`.sm_hi` / `.sm_lo` / `.sm_depth` bodies).\n *\n * The Cjs prefix marks this as a JavaScript format/construction boundary.\n * This format profile has no dependency on any DXBC/shader-bytecode decoder: shader\n * bodies stay as opaque bytes in the emitted graph. The public contract is\n * plain JSON data (`emit: \"json\"`, the default) — the documented effect\n * graph shape described in `docs/reference/json-graph.md`. `emit: \"raw\"`\n * exposes the internal\n * HlslEffectRes graph directly; treat it as unstable, not schema-guaranteed\n * internals, useful mainly for resolving multiple permutations by hand.\n *\n * The `classes` option lets a caller register constructors for specific\n * node kinds in the emitted JSON graph (see `CjsHlslFormat.CLASS_KEYS`);\n * class registration does not depend on importing internal graph classes.\n */\nexport class CjsHlslFormat\n{\n\n #emit = DEFAULT_VALUES.emit;\n #source = DEFAULT_VALUES.source;\n #permutation = DEFAULT_VALUES.permutation;\n #classes = DEFAULT_VALUES.classes;\n\n /**\n * Create a reusable format profile.\n *\n * @param {object} [options] Default format values.\n */\n constructor(options = {})\n {\n this.SetValues(options);\n }\n\n /**\n * Set format values for this reusable profile.\n *\n * @param {object} [options] Values to merge into the profile.\n * @returns {CjsHlslFormat} This format profile.\n */\n SetValues(options = {})\n {\n const values = normalizeValues(this.GetValues(), options, FORMAT_NAME);\n\n this.#emit = values.emit;\n this.#source = values.source;\n this.#permutation = values.permutation;\n this.#classes = values.classes;\n\n return this;\n }\n\n /**\n * Get this profile's current values, optionally with per-call overrides.\n *\n * @param {object} [options] Optional values to merge into a copy.\n * @returns {object} A copy of the effective values.\n */\n GetValues(options = {})\n {\n return normalizeValues({\n emit: this.#emit,\n source: this.#source,\n permutation: this.#permutation,\n classes: this.#classes\n }, options, FORMAT_NAME);\n }\n\n /**\n * Set multiple node-class constructors for this profile.\n *\n * @param {object} [classes] Map of node class keys to constructors. See {@link CjsHlslFormat.CLASS_KEYS}.\n * @returns {CjsHlslFormat} This format profile.\n */\n SetClasses(classes = {})\n {\n return this.SetValues({ classes });\n }\n\n /**\n * Set one node-class constructor for this profile.\n *\n * @param {string} type Node class key.\n * @param {Function|null|undefined} Class Constructor to use, or nullish to delete.\n * @returns {CjsHlslFormat} This format profile.\n */\n SetClass(type, Class)\n {\n if (Class === null || Class === undefined)\n {\n validateClassKey(type, FORMAT_NAME);\n const classes = { ...this.#classes };\n delete classes[type];\n this.#classes = classes;\n return this;\n }\n\n validateClass(type, Class, FORMAT_NAME);\n return this.SetValues({ classes: { [type]: Class } });\n }\n\n /**\n * Get a configured node-class constructor.\n *\n * @param {string} type Node class key.\n * @returns {Function|undefined} The registered constructor, if any.\n */\n GetClass(type)\n {\n validateClassKey(type, FORMAT_NAME);\n return this.#classes[type];\n }\n\n /**\n * Whether this reader has a constructor registered for a node class key.\n *\n * @param {string} type Node class key.\n * @returns {boolean} True when a constructor is registered.\n */\n HasClass(type)\n {\n return !!this.GetClass(type);\n }\n\n /**\n * Read a Tr2 effect payload with this profile's values.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Tr2 effect container bytes.\n * @param {object} [options] Per-call value overrides.\n * @returns {HlslEffectRes|object} The raw HlslEffectRes instance, compact metadata, or the documented JSON graph.\n */\n Read(input, options = {})\n {\n return readWithValues(input, this.GetValues(options));\n }\n\n /**\n * Inspect a Tr2 effect payload: header facts plus the default (or\n * selected) permutation's technique names and stage counts.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Tr2 effect container bytes.\n * @param {object} [options] Per-call value overrides.\n * @returns {object} Plain summary data.\n */\n Inspect(input, options = {})\n {\n return inspectWithValues(input, this.GetValues(options));\n }\n\n /**\n * Convert format output to JSON-compatible data.\n *\n * @param {any} value Format output to convert.\n * @returns {any} Plain JSON-compatible data.\n */\n ToJSON(value)\n {\n return toJsonValue(value);\n }\n\n /**\n * Static payload sniff. Static methods use camelCase by convention.\n *\n * The Tr2 effect container has no magic number, so this attempts a\n * cheap header-only load (version, string table, permutation axes and\n * body offsets — no shader bodies) and reports whether it succeeded.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Candidate bytes.\n * @returns {boolean} True when the payload's header decodes as a supported Tr2 effect.\n */\n static isSupported(input)\n {\n try\n {\n const bytes = toBytes(input);\n return new HlslEffectRes().DoLoad(bytes, { source: \"isSupported\" });\n }\n catch\n {\n return false;\n }\n }\n\n /**\n * Static one-shot read.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Tr2 effect container bytes.\n * @param {object} [options] Format values.\n * @returns {HlslEffectRes|object} The raw HlslEffectRes instance, compact metadata, or the documented JSON graph.\n */\n static read(input, options = {})\n {\n return readWithValues(input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));\n }\n\n /**\n * Static one-shot inspection.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Tr2 effect container bytes.\n * @param {object} [options] Format values.\n * @returns {object} Plain summary data.\n */\n static inspect(input, options = {})\n {\n return inspectWithValues(input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));\n }\n\n /**\n * Static JSON-compatible conversion.\n *\n * @param {any} value Format output to convert.\n * @returns {any} Plain JSON-compatible data.\n */\n static toJSON(value)\n {\n return toJsonValue(value);\n }\n\n static OUTPUT_JSON = OUTPUT_JSON;\n static OUTPUT_METADATA = OUTPUT_METADATA;\n static OUTPUT_RAW = OUTPUT_RAW;\n static CLASS_KEYS = CLASS_KEYS;\n static type = Object.freeze([ \"shader\" ]);\n static mediaTypes = Object.freeze([ \"shader\" ]);\n static inputTypes = Object.freeze([ \"sm_hi\", \"sm_lo\", \"sm_depth\" ]);\n static outputTypes = Object.freeze([ OUTPUT_JSON, OUTPUT_METADATA ]);\n static debugOutputTypes = Object.freeze([ OUTPUT_RAW ]);\n\n}\n\nexport default CjsHlslFormat;\n"],"names":["FORMAT_NAME","CjsHlslFormat","DEFAULT_VALUES","emit","source","permutation","classes","constructor","options","SetValues","values","normalizeValues","GetValues","SetClasses","SetClass","type","Class","undefined","validateClassKey","validateClass","GetClass","HasClass","Read","input","readWithValues","Inspect","inspectWithValues","ToJSON","value","toJsonValue","isSupported","bytes","toBytes","HlslEffectRes","DoLoad","read","inspect","toJSON","OUTPUT_JSON","OUTPUT_METADATA","OUTPUT_RAW","CLASS_KEYS","Object","freeze","mediaTypes","inputTypes","outputTypes","debugOutputTypes"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAkBA,MAAMA,WAAW,GAAG,eAAe;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,aAAa,CAC1B;AAEI,EAAA,KAAK,GAAGC,cAAc,CAACC,IAAI;AAC3B,EAAA,OAAO,GAAGD,cAAc,CAACE,MAAM;AAC/B,EAAA,YAAY,GAAGF,cAAc,CAACG,WAAW;AACzC,EAAA,QAAQ,GAAGH,cAAc,CAACI,OAAO;;AAEjC;AACJ;AACA;AACA;AACA;AACIC,EAAAA,WAAWA,CAACC,OAAO,GAAG,EAAE,EACxB;AACI,IAAA,IAAI,CAACC,SAAS,CAACD,OAAO,CAAC;AAC3B,EAAA;;AAEA;AACJ;AACA;AACA;AACA;AACA;AACIC,EAAAA,SAASA,CAACD,OAAO,GAAG,EAAE,EACtB;AACI,IAAA,MAAME,MAAM,GAAGC,eAAe,CAAC,IAAI,CAACC,SAAS,EAAE,EAAEJ,OAAO,EAAER,WAAW,CAAC;AAEtE,IAAA,IAAI,CAAC,KAAK,GAAGU,MAAM,CAACP,IAAI;AACxB,IAAA,IAAI,CAAC,OAAO,GAAGO,MAAM,CAACN,MAAM;AAC5B,IAAA,IAAI,CAAC,YAAY,GAAGM,MAAM,CAACL,WAAW;AACtC,IAAA,IAAI,CAAC,QAAQ,GAAGK,MAAM,CAACJ,OAAO;AAE9B,IAAA,OAAO,IAAI;AACf,EAAA;;AAEA;AACJ;AACA;AACA;AACA;AACA;AACIM,EAAAA,SAASA,CAACJ,OAAO,GAAG,EAAE,EACtB;AACI,IAAA,OAAOG,eAAe,CAAC;A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ACI,IAAA,OAAOkB,iBAAiB,CAACH,KAAK,EAAEZ,eAAe,CAACT,cAAc,EAAEM,OAAO,EAAER,WAAW,CAAC,CAAC;AAC1F,EAAA;;AAEA;AACJ;AACA;AACA;AACA;AACA;EACI,OAAOqC,MAAMA,CAACT,KAAK,EACnB;IACI,OAAOC,WAAW,CAACD,KAAK,CAAC;AAC7B,EAAA;EAEA,OAAOU,WAAW,GAAGA,WAAW;EAChC,OAAOC,eAAe,GAAGA,eAAe;EACxC,OAAOC,UAAU,GAAGA,UAAU;EAC9B,OAAOC,UAAU,GAAGA,UAAU;EAC9B,OAAO1B,IAAI,GAAG2B,MAAM,CAACC,MAAM,CAAC,CAAE,QAAQ,CAAE,CAAC;EACzC,OAAOC,UAAU,GAAGF,MAAM,CAACC,MAAM,CAAC,CAAE,QAAQ,CAAE,CAAC;AAC/C,EAAA,OAAOE,UAAU,GAAGH,MAAM,CAACC,MAAM,CAAC,CAAE,OAAO,EAAE,OAAO,EAAE,UAAU,CAAE,CAAC;EACnE,OAAOG,WAAW,GAAGJ,MAAM,CAACC,MAAM,CAAC,CAAEL,WAAW,EAAEC,eAAe,CAAE,CAAC;EACpE,OAAOQ,gBAAgB,GAAGL,MAAM,CAACC,MAAM,CAAC,CAAEH,UAAU,CAAE,CAAC;AAE3D;;;;"}
@@ -1,11 +1,13 @@
1
1
  import { CjsFormatReadError } from '../../../format/CjsFormatError.js';
2
2
  import { HlslEffectConstant } from './tr2/shader/HlslEffectConstant.js';
3
+ import { HlslEffectLibrary } from './tr2/shader/HlslEffectLibrary.js';
3
4
  import { HlslEffectParameterAnnotation } from './tr2/shader/HlslEffectParameterAnnotation.js';
4
5
  import { HlslEffectResource } from './tr2/shader/HlslEffectResource.js';
5
6
  import { HlslEffectStageInput } from './tr2/shader/HlslEffectStageInput.js';
6
7
  import { HlslEffectStateManager } from './HlslEffectStateManager.js';
7
8
  import { HlslEffectTechnique } from './tr2/shader/HlslEffectTechnique.js';
8
9
  import { HlslPass } from './tr2/shader/HlslPass.js';
10
+ import { HlslShaderBytecode } from './HlslShaderBytecode.js';
9
11
  import { HlslRenderContextEnum, HlslUsageCodeNames } from './tr2/HlslRenderContextEnum.js';
10
12
  import { HlslRenderStateSetup } from './HlslRenderStateSetup.js';
11
13
  import { HlslResourceSetDescription } from './HlslResourceSetDescription.js';
@@ -343,9 +345,8 @@ const REGISTER_RULES = Object.freeze({
343
345
  * Pipeline input rules.
344
346
  *
345
347
  * `usageName` is derived from the `usage` byte rather than carried: it is a
346
- * display name looked up from a table (`HlslEffectDescription.js:592`), exactly
347
- * as Carbon derives it through `GetStringForUsageCode` (`EffectData.h:86`).
348
- * Nothing goes on the wire for it.
348
+ * display name looked up from a table, exactly as Carbon derives it through
349
+ * `GetStringForUsageCode` (`EffectData.h:86`). Nothing goes on the wire for it.
349
350
  */
350
351
  const PIPELINE_INPUT_RULES = Object.freeze({
351
352
  usage: (target, value) => {
@@ -382,8 +383,8 @@ const ANNOTATION_RULES = Object.freeze({
382
383
  },
383
384
  // A non-string annotation value is four raw bytes: Carbon writes it through a
384
385
  // float union and reads it through a different one, so the bytes are the only
385
- // faithful form. The three typed views are derived from them exactly as the
386
- // source reader derives them (`HlslEffectDescription.js:480-483`).
386
+ // faithful form. The three typed views are derived from those bytes, one per
387
+ // union member Carbon reads back through.
387
388
  rawValue: (target, value, record) => {
388
389
  if (record.type === ANNOTATION_TYPE_STRING) return;
389
390
  const bits = rawUint32(value);
@@ -409,7 +410,7 @@ function mapTextureRecord(record) {
409
410
  *
410
411
  * A UAV record is one byte shorter than a texture record: it carries no
411
412
  * `isSRGB`. Carbon's reader hardcodes it false (`Tr2EffectDescription.cpp:450`),
412
- * and so does ours (`HlslEffectDescription.js:434`), so the runtime object's
413
+ * so the runtime object's
413
414
  * constructor default is restored explicitly rather than left to chance —
414
415
  * `metadata.toJSON()` emits the key for a UAV even though the wire never carries
415
416
  * it, because both kinds share `HlslEffectResource`.
@@ -429,9 +430,11 @@ function mapUavRecord(record) {
429
430
  * Two conversions beyond the flat-to-nested reshape:
430
431
  *
431
432
  * - Carbon nulls a sampler's name when it is not dynamic
432
- * (`Tr2EffectDescription.cpp:430-433`, mirrored at
433
- * `HlslEffectDescription.js:414-417`), so the wire's empty string must become
434
- * `null` again. Like `isSRGB`, this is *accidentally correct* if left alone —
433
+ * (`Tr2EffectDescription.cpp:430-433`), so the wire's empty string must become
434
+ * `null` again. A pre-v13 record carries no `isDynamic` at all; the class
435
+ * default (dynamic) then keeps the name, matching the legacy reader, which
436
+ * never assigned the flag for those versions. Like `isSRGB`, the nulling is
437
+ * *accidentally correct* if left alone —
435
438
  * `""` and `null` are both falsy, so `metadataName` and the heap-view lookup
436
439
  * behave identically — and only a structural diff catches it.
437
440
  * - `comparison` and `isDynamic` are `u8` on the wire and boolean at runtime.
@@ -450,9 +453,8 @@ function mapSamplerRecord(record) {
450
453
  /**
451
454
  * Maps one static sampler record onto its runtime signature entry.
452
455
  *
453
- * The runtime shape keeps the `*Raw` companions non-enumerable, matching
454
- * `readStaticSampler`, so a `cloneJson` of the descriptor sees the value form
455
- * only.
456
+ * The runtime shape keeps the `*Raw` companions non-enumerable, so a
457
+ * `cloneJson` of the descriptor sees the value form only.
456
458
  *
457
459
  * @param {object} record Wire static sampler record.
458
460
  * @returns {object} Runtime static sampler entry.
@@ -520,7 +522,7 @@ function mapAnnotationRecord(record) {
520
522
  *
521
523
  * Reproduced rather than stored: it is a function of the register type, the
522
524
  * stage type and the caller's per-frame start registers, none of which the
523
- * container needs to carry (`HlslEffectDescription.js:750-765`).
525
+ * container needs to carry.
524
526
  *
525
527
  * @param {object} register Runtime register declaration.
526
528
  * @param {number} stageType Stage enum value.
@@ -552,12 +554,13 @@ function applyStageData(input, data, stageType, context) {
552
554
  input.constants = (data.constants ?? []).map(mapConstantRecord);
553
555
 
554
556
  // The declared size is the unclamped one; the runtime clamps it to
555
- // SHADER_CONSTANTS_MAX and slices the payload to match
556
- // (`HlslEffectDescription.js:381-385`). `packMaterial` allocates an
557
+ // SHADER_CONSTANTS_MAX and slices the payload to match, as Carbon does
558
+ // (`Tr2EffectDescription.h:160`). `packMaterial` allocates an
557
559
  // ArrayBuffer of exactly this size, so restoring the unclamped value would
558
560
  // write past the layout the shader expects — on any effect above 4096 bytes
559
561
  // of constants, which is precisely the size a small fixture never reaches.
560
562
  const declaredSize = data.defaultValues?.size ?? 0;
563
+ input.sourceConstantValueSize = declaredSize;
561
564
  input.sourceConstantValues = Uint8Array.from(data.defaultValues?.bytes ?? new Uint8Array(0));
562
565
  input.m_constantValueSize = Math.min(declaredSize, HlslEffectStageInput.SHADER_CONSTANTS_MAX);
563
566
  input.constantValues = input.sourceConstantValues.slice(0, input.m_constantValueSize);
@@ -574,11 +577,10 @@ function applyStageData(input, data, stageType, context) {
574
577
  /**
575
578
  * Grows the constant block to cover a sampler heap-index constant.
576
579
  *
577
- * Reproduces `HlslEffectDescription.js:773-791`, which the source reader applies
578
- * to every constant once samplers are known: a `UINT`/dimension-1 constant whose
579
- * name matches a sampler is a heap index, and the declared constant-value size
580
- * can be smaller than the offset it sits at. The reader extends the block rather
581
- * than reading out of bounds.
580
+ * Applied to every constant once samplers are known, as Carbon's reader does:
581
+ * a `UINT`/dimension-1 constant whose name matches a sampler is a heap index,
582
+ * and the declared constant-value size can be smaller than the offset it sits
583
+ * at. The block is extended rather than read out of bounds.
582
584
  *
583
585
  * **This is derived, not stored, and missing it is not cosmetic.** `packMaterial`
584
586
  * allocates `new ArrayBuffer(constantValueSize)`, so an unpatched size
@@ -673,12 +675,77 @@ function buildPass(record, context) {
673
675
  return pass;
674
676
  }
675
677
 
678
+ /** Names an export slot per Carbon's raytracing export type codes. */
679
+ const LIBRARY_EXPORT_NAME_FIELDS = Object.freeze(["rayGenName", "missName", "closestHitName", "anyHitName", "intersectionName"]);
680
+
681
+ /** Library record rules; the nested pieces are handled by `buildLibrary`. */
682
+ const LIBRARY_RULES = Object.freeze({
683
+ payloadSize: (target, value) => {
684
+ target.payloadSize = value;
685
+ },
686
+ hitGroupName: (target, value) => {
687
+ target.hitGroupName = text(value);
688
+ },
689
+ // Consumed by buildLibrary: the blob becomes the registered bytecode.
690
+ shaderData: consumed,
691
+ // Consumed by buildLibrary: exports carry per-type name routing.
692
+ exports: consumed,
693
+ globalInputs: consumed,
694
+ localInputs: consumed
695
+ });
696
+
697
+ /**
698
+ * Rebuilds one runtime shader library from a wire library record.
699
+ *
700
+ * The two stage-data blocks reuse `applyStageData`, so a library's constants,
701
+ * defaults, resources, samplers and UAVs go through exactly the rules a pass
702
+ * stage goes through. The library bytecode is registered the way the runtime
703
+ * registers it: a compute-typed `HlslShaderBytecode` under the state manager's
704
+ * library registry, whose handles are a separate monotonic counter — adding
705
+ * libraries does not shift any shader or program handle.
706
+ *
707
+ * @param {object} record Wire library record.
708
+ * @param {object} context Adapter context.
709
+ * @returns {HlslEffectLibrary} Runtime library.
710
+ */
711
+ function buildLibrary(record, context) {
712
+ const library = mapClosed(record, LIBRARY_RULES, new HlslEffectLibrary(), "library");
713
+ const shaderType = HlslRenderContextEnum.COMPUTE_SHADER;
714
+ library.cjsShaderBytecode = new HlslShaderBytecode({
715
+ stageType: shaderType,
716
+ stageName: "library",
717
+ bytes: record.shaderData?.bytes ?? new Uint8Array(0),
718
+ shaderSize: record.shaderData?.size ?? 0,
719
+ stringTableOffset: record.shaderData?.offset ?? null
720
+ });
721
+ library.libraryHandle = context.effectStateManager.RegisterShaderLibrary(library.cjsShaderBytecode);
722
+ for (const entry of record.exports ?? []) {
723
+ const name = text(entry.name);
724
+ library.exports.push({
725
+ type: entry.type,
726
+ name
727
+ });
728
+ const field = LIBRARY_EXPORT_NAME_FIELDS[entry.type];
729
+ if (field) library[field] = name;
730
+ }
731
+ applyStageData(library.globalInput, record.globalInputs ?? {}, shaderType, context);
732
+ library.globalResourceSetDesc = new HlslResourceSetDescription([shaderType], [library.globalInput.signature]);
733
+ for (const [registerIndex, sampler] of library.globalInput.samplers.entries()) {
734
+ library.globalResourceSetDesc.SetSampler(shaderType, registerIndex, sampler.sampler);
735
+ }
736
+ applyStageData(library.localInput, record.localInputs ?? {}, shaderType, context);
737
+ return library;
738
+ }
739
+
676
740
  /**
677
741
  * Applies the `IsHeapView` annotations to the rebuilt resource-set descriptions.
678
742
  *
679
- * Derived exactly as the source reader derives it
680
- * (`HlslEffectDescription.js:799-851`), over the annotations the container
681
- * carries.
743
+ * Derived rather than carried, over the annotations the container holds,
744
+ * exactly as Carbon derives it after reading
745
+ * (`Tr2EffectDescription.cpp:474-530`): a parameter whose top-level
746
+ * annotations contain a true BOOL `IsHeapView` marks its register as a heap
747
+ * view in the owning resource-set description, for library global inputs as
748
+ * well as pass stages.
682
749
  *
683
750
  * @param {object} effectDescription Rebuilt effect description.
684
751
  */
@@ -689,6 +756,18 @@ function applyHeapViewAnnotations(effectDescription) {
689
756
  return annotations.some(annotation => annotation.name === "IsHeapView" && annotation.type === HlslEffectParameterAnnotation.Type.BOOL && annotation.boolValue);
690
757
  };
691
758
  for (const technique of effectDescription.techniques) {
759
+ for (const library of technique.libraries ?? []) {
760
+ const shaderType = HlslRenderContextEnum.COMPUTE_SHADER;
761
+ for (const [registerIndex, resource] of library.globalInput.resources.entries()) {
762
+ if (isHeapView(resource.name)) library.globalResourceSetDesc?.SetSrvHeapView(shaderType, registerIndex);
763
+ }
764
+ for (const [registerIndex, resource] of library.globalInput.uavs.entries()) {
765
+ if (isHeapView(resource.name)) library.globalResourceSetDesc?.SetUavHeapView(shaderType, registerIndex);
766
+ }
767
+ for (const [registerIndex, sampler] of library.globalInput.samplers.entries()) {
768
+ if (isHeapView(sampler.name)) library.globalResourceSetDesc?.SetSamplerHeapView(shaderType, registerIndex);
769
+ }
770
+ }
692
771
  for (const pass of technique.passes) {
693
772
  for (let stageType = 0; stageType < pass.stageInputs.length; stageType += 1) {
694
773
  const stage = pass.stageInputs[stageType];
@@ -741,37 +820,27 @@ function runtimeDescriptionFromCarbon(description, options = {}) {
741
820
  for (const record of description.techniques) {
742
821
  const technique = new HlslEffectTechnique();
743
822
  technique.name = text(record.name);
744
- // Raytracing libraries are carried on the wire and are deliberately NOT
745
- // rebuilt here. `libraries` stays empty.
746
- //
747
- // This began as a throw, on the reasoning that a silent drop hides a
748
- // whole missing section and that no shipped effect declared one. The
749
- // first half still stands; the second half was wrong, and the way it was
750
- // wrong is the useful part. The dx11 corpus has no libraries at all —
751
- // 1611 files, zero — so the refusal never fired. **Every dx12 body of
752
- // `unpacked_quadv5.sm_hi` carries one**: technique `RtShadow`, a
753
- // `ClosestHit` export, DXR raytracing shadows that dx11 has no analogue
754
- // for. All 288 distinct bodies. So the refusal blocked every dx12
755
- // package for a section nothing downstream reads.
756
- //
757
- // Dropping them is safe for a *specific, checked* reason rather than a
758
- // hopeful one: `buildEffectAnalysis` reaches libraries through no path.
759
- // `buildPasses` walks `technique.passes`; `buildStages` walks
760
- // `pass.stageInputs`; neither touches `technique.libraries`. The source
761
- // reader's heap-view pass does visit libraries, but only to populate
762
- // `library.globalResourceSetDesc`, which the manifest never reads.
763
- //
764
- // That claim is measured, not argued: the corpus analysis diff compares
765
- // source-derived against container-derived analysis over dx12 as well as
766
- // dx11, so every one of those library-bearing bodies is proof that the
767
- // drop is invisible to this view. If the analysis ever grows a library
768
- // section, that test goes red rather than this comment going stale.
769
823
  technique.passes = (record.passes ?? []).map(pass => buildPass(pass, context));
770
824
  for (const pass of technique.passes) technique.shaderTypeMask |= pass.shaderTypeMask;
825
+ // Raytracing libraries were once deliberately dropped here, when this
826
+ // adapter served only `buildEffectAnalysis` — which reaches libraries
827
+ // through no path, a claim the dx12 corpus diff measured (every body
828
+ // of `unpacked_quadv5.sm_hi` carries an `RtShadow` library, and the
829
+ // diff stayed green). Since the runtime read path converged on this
830
+ // adapter, that scope no longer holds: `metadata.js` and `json.js`
831
+ // emit `technique.libraries`, and the effect-resource contract
832
+ // requires every library's exports, inputs and payload preserved.
833
+ technique.libraries = (record.libraries ?? []).map(library => buildLibrary(library, context));
771
834
  effectDescription.techniques.push(technique);
772
835
  }
773
836
  for (const group of description.annotations ?? []) {
774
- effectDescription.annotations.set(text(group.name), (group.annotations ?? []).map(mapAnnotationRecord));
837
+ const name = text(group.name);
838
+ if (effectDescription.annotations.has(name)) {
839
+ throw new CjsFormatReadError(`Duplicate effect parameter annotation group ${name}`, {
840
+ name
841
+ });
842
+ }
843
+ effectDescription.annotations.set(name, (group.annotations ?? []).map(mapAnnotationRecord));
775
844
  }
776
845
  applyHeapViewAnnotations(effectDescription);
777
846
  return effectDescription;