@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,6 +1,5 @@
1
1
  import { impl, CjsSchema, carbon, type } from '@carbonenginejs/runtime-utils/schema';
2
2
  import { CjsModel } from '@carbonenginejs/runtime-utils/model';
3
- import { validateEffectBodyReflection, isEffectBodyReflection } from '../../formats/hlsl/core/portableReflection.js';
4
3
  import { Tr2EffectDescription } from './reflection/Tr2EffectDescription.js';
5
4
 
6
5
  // Source: trinity/trinity/Shader/Tr2Shader.h
@@ -142,31 +141,54 @@ class Tr2Shader extends CjsModel {
142
141
  }
143
142
 
144
143
  /**
145
- * Build one canonical GPU-free shader from complete portable reflection.
146
- * Each child reflection class owns conversion of its own portable record.
144
+ * Build one GPU-free shader from one body of a Carbon effect container.
147
145
  *
148
- * @param {object} portable Portable effect-body reflection.
146
+ * `reader` is the container reader the resource opened and retains; this method
147
+ * never opens anything of its own. A body is not independently readable — its
148
+ * strings are offsets into the container's shared arena, and its layout depends
149
+ * on the container's version — so handing each body its own reader would mean
150
+ * re-parsing the header per permutation and losing the arena.
151
+ *
152
+ * Carbon passes exactly that bundle, as loose arguments
153
+ * (`Tr2EffectRes.cpp:126-134`):
154
+ *
155
+ * ```cpp
156
+ * auto offset = m_offsets[index];
157
+ * auto buffer = ...m_data.get() + offset.offset;
158
+ * shader->GetEffect().Read( buffer, offset.size, m_version,
159
+ * m_stringTable, m_stringTableSize, path );
160
+ * shader->ProcessEffect();
161
+ * ```
162
+ *
163
+ * The resource owns `m_data`, `m_offsets`, `m_version` and the string table,
164
+ * and hands the body a pointer plus the version and arena. Here that same state
165
+ * is held by the reader the resource retains, so passing the reader passes the
166
+ * whole bundle and the resource itself adds nothing a body needs.
167
+ *
168
+ * Reading is backend-agnostic. A dx11 body reads exactly as a webgl one does;
169
+ * they differ only in what the optional per-pass block carries, and this method
170
+ * retains that block without interpreting it. What can be *realized* from the
171
+ * result is the engine's question, not the reader's.
172
+ *
173
+ * @param {object} reader Container reader owned by the resource.
174
+ * @param {number} index Permutation index within the container.
149
175
  * @returns {Tr2Shader} Canonical selected shader.
150
176
  */
151
- static fromPortable(portable) {
152
- validateEffectBodyReflection(portable);
177
+ static fromCarbonBinary(reader, index) {
153
178
  const shader = new this();
154
- shader.effect = Tr2EffectDescription.fromPortable(portable.effect);
179
+ shader.effect = Tr2EffectDescription.fromCarbonBinary(reader.readDescription(index));
155
180
  shader.ProcessEffect();
156
181
  return shader;
157
182
  }
158
183
 
159
184
  /**
160
- * Whether a value has the supported complete portable-reflection envelope.
185
+ * Find a named value across stage collections in Carbon lookup order.
161
186
  *
162
- * @param {*} value Candidate value.
163
- * @returns {boolean} Whether the portable envelope is supported.
187
+ * @param {Tr2EffectDescription} effect Effect description to search.
188
+ * @param {string} name Entry name.
189
+ * @param {string} key Stage collection key.
190
+ * @returns {*|null} Matching value, or `null`.
164
191
  */
165
- static isPortableReflection(value) {
166
- return isEffectBodyReflection(value);
167
- }
168
-
169
- /** Find one named reflection entry across every stage. */
170
192
  static findStageValue(effect, name, key) {
171
193
  for (const stage of Tr2Shader.iterateStages(effect)) {
172
194
  const found = Tr2Shader.findNamedCollectionValue(stage?.[key], name);
@@ -1 +1 @@
1
- {"version":3,"file":"Tr2Shader.js","sources":["../../../../src/resource/shader/Tr2Shader.js"],"sourcesContent":["// Source: trinity/trinity/Shader/Tr2Shader.h\n// Source: trinity/trinity/Shader/Tr2Shader.cpp\nimport { CjsSchema, carbon, impl, type } from \"@carbonenginejs/runtime-utils/schema\";\nimport { CjsModel } from \"@carbonenginejs/runtime-utils/model\";\nimport {\n isEffectBodyReflection,\n validateEffectBodyReflection\n} from \"../../formats/hlsl/portable.js\";\nimport { Tr2EffectDescription } from \"./reflection/Tr2EffectDescription.js\";\n\n/** GPU-free selected shader and its complete source reflection graph. */\nexport class Tr2Shader extends CjsModel\n{\n\n /** m_sortValue (unsigned int) */\n sortValue = 0;\n\n /** m_effect (Tr2EffectDescription) */\n effect = new Tr2EffectDescription();\n\n /** m_hasVertexBufferAccessInRtShadow (bool) */\n hasVertexBufferAccessInRtShadow = false;\n\n /**\n * Index of the named technique; 0 for Carbon's empty-string any-technique\n * sentinel and -1 when the shader has no techniques or the name is unknown.\n */\n GetTechniqueIndex(name = \"Main\")\n {\n const techniques = this.effect?.techniques ?? [];\n if (!techniques.length)\n {\n return -1;\n }\n if (name === \"\")\n {\n return 0;\n }\n return techniques.findIndex(technique => technique?.name === name);\n }\n\n /** Number of passes in a technique; 0 for an unknown index. */\n GetPassCount(techniqueIndex = 0)\n {\n return this.effect?.techniques?.[techniqueIndex]?.passes?.length ?? 0;\n }\n\n /**\n * The reflected constant of this name from any stage of any pass, or null;\n * the description is metadata, not a bound GPU slot.\n */\n GetConstant(name)\n {\n return Tr2Shader.findStageValue(this.effect, name, \"constants\");\n }\n\n /**\n * The reflected resource of this name, searching stage resources before\n * UAVs; null when neither has it.\n */\n GetResource(name)\n {\n for (const stage of Tr2Shader.iterateStages(this.effect))\n {\n const resource = Tr2Shader.findNamedCollectionValue(\n stage?.resources,\n name\n );\n if (resource)\n {\n return resource;\n }\n const uav = Tr2Shader.findNamedCollectionValue(stage?.uavs, name);\n if (uav)\n {\n return uav;\n }\n }\n return null;\n }\n\n /**\n * The annotation set authored for a parameter name, or null; the shape\n * depends on the reflection source.\n */\n GetParameterAnnotations(parameterName)\n {\n return Tr2Shader.findAnnotationSet(\n this.effect?.annotations,\n parameterName\n );\n }\n\n /** The packed draw-sort key; 0 until ProcessEffect has run. */\n GetSortValue()\n {\n return this.sortValue;\n }\n\n /** The reflected effect description, by reference rather than copy. */\n GetEffectDescription()\n {\n return this.effect;\n }\n\n /** The same object GetEffectDescription returns. */\n GetEffect()\n {\n return this.effect;\n }\n\n /** The technique's bitmask of shader stages, or 0 for an unknown index. */\n GetShaderTypeMask(techniqueIndex = 0)\n {\n return Number(\n this.effect?.techniques?.[techniqueIndex]?.shaderTypeMask ?? 0\n );\n }\n\n /**\n * Pack the first technique/pass's renderer handles into Carbon's sort key.\n * A device-free source graph retains 0 while its handles remain invalid.\n */\n ProcessEffect()\n {\n this.sortValue = 0;\n const pass = this.effect?.techniques?.[0]?.passes?.[0];\n if (!pass)\n {\n return;\n }\n const stages = pass.stageInputs ?? [];\n const pixelHandle = Number(\n stages[1]?.shader ?? stages[1]?.m_shader ?? 0xffffffff\n );\n const vertexHandle = Number(\n stages[0]?.shader ?? stages[0]?.m_shader ?? 0xffffffff\n );\n if (pixelHandle === 0xffffffff || vertexHandle === 0xffffffff)\n {\n return;\n }\n const pixelShader = pixelHandle & 0x3ff;\n const vertexShader = vertexHandle & 0x3ff;\n const renderStates = Number(pass.renderStates ?? 0) & 0x3ff;\n const passCount = Number(\n this.effect?.techniques?.[0]?.passes?.length ?? 0\n ) & 0x3;\n this.sortValue = (\n (passCount << 30)\n | (pixelShader << 20)\n | (vertexShader << 10)\n | renderStates\n ) >>> 0;\n }\n\n /** Whether this shader accesses vertex buffers in RT shadow mode. */\n HasVertexBufferAccessInRtShadow()\n {\n return this.hasVertexBufferAccessInRtShadow;\n }\n\n /**\n * Construct a canonical shader graph from JS/JSON model values.\n *\n * @param {object} values Canonical model values.\n * @param {object} options CjsModel import options.\n * @returns {Tr2Shader} Hydrated shader graph.\n */\n static from(values = {}, options = {})\n {\n let normalized = values;\n if (values?.effect\n && !(values.effect instanceof Tr2EffectDescription))\n {\n normalized = {\n ...values,\n effect: Tr2EffectDescription.from(values.effect, options)\n };\n }\n const shader = super.from(normalized, options);\n if (!Object.hasOwn(values ?? {}, \"sortValue\"))\n {\n shader.ProcessEffect();\n }\n return shader;\n }\n\n /**\n * Build one canonical GPU-free shader from complete portable reflection.\n * Each child reflection class owns conversion of its own portable record.\n *\n * @param {object} portable Portable effect-body reflection.\n * @returns {Tr2Shader} Canonical selected shader.\n */\n static fromPortable(portable)\n {\n validateEffectBodyReflection(portable);\n\n const shader = new this();\n shader.effect = Tr2EffectDescription.fromPortable(portable.effect);\n shader.ProcessEffect();\n return shader;\n }\n\n /**\n * Whether a value has the supported complete portable-reflection envelope.\n *\n * @param {*} value Candidate value.\n * @returns {boolean} Whether the portable envelope is supported.\n */\n static isPortableReflection(value)\n {\n return isEffectBodyReflection(value);\n }\n\n /** Find one named reflection entry across every stage. */\n static findStageValue(effect, name, key)\n {\n for (const stage of Tr2Shader.iterateStages(effect))\n {\n const found = Tr2Shader.findNamedCollectionValue(stage?.[key], name);\n if (found)\n {\n return found;\n }\n }\n return null;\n }\n\n /** Flatten pass stage inputs in Carbon lookup order. */\n static iterateStages(effect)\n {\n const stages = [];\n for (const technique of effect?.techniques ?? [])\n {\n for (const pass of technique?.passes ?? [])\n {\n stages.push(...pass?.stageInputs ?? []);\n }\n }\n return stages;\n }\n\n /** Find a named entry in an array, Map, or plain object collection. */\n static findNamedCollectionValue(values, name)\n {\n if (!values)\n {\n return null;\n }\n if (Array.isArray(values))\n {\n return values.find(\n value => value?.name === name || value?.[1]?.name === name\n ) ?? null;\n }\n if (values instanceof Map)\n {\n for (const value of values.values())\n {\n if (value?.name === name)\n {\n return value;\n }\n }\n return null;\n }\n for (const value of Object.values(values))\n {\n if (value?.name === name)\n {\n return value;\n }\n }\n return null;\n }\n\n /** Resolve a parameter's annotations from a Map, array, or plain object. */\n static findAnnotationSet(annotations, parameterName)\n {\n if (!annotations)\n {\n return null;\n }\n if (annotations instanceof Map)\n {\n return annotations.get(parameterName) ?? null;\n }\n if (Array.isArray(annotations))\n {\n const entry = annotations.find(\n item => item?.name === parameterName\n || item?.[0] === parameterName\n );\n return entry?.annotations ?? entry?.value ?? entry?.[1] ?? null;\n }\n return annotations[parameterName] ?? null;\n }\n\n}\n\n// Declared as data rather than with decorators, so this module stays plain ESM\n// that loads from source without a transform. The decorator vocabulary is used\n// verbatim as values, so the registered metadata is identical to the decorated\n// form. Field order is key order, and it drives GetValues() export order.\n// Statics belong in `methods`: the prototype is what carries instance fields.\nconst UNVALIDATED_TECHNIQUE_INDEX = impl.reason(\n \"Carbon assumes an already-validated technique index; CarbonEngineJS safely returns zero for an unavailable index.\"\n);\n\nCjsSchema.define(Tr2Shader, {\n className: \"Tr2Shader\",\n family: \"shader\",\n fields: {\n sortValue: type.uint32,\n effect: type.rawStruct(\"Tr2EffectDescription\"),\n hasVertexBufferAccessInRtShadow: type.boolean\n },\n methods: {\n GetTechniqueIndex: [ carbon.method, impl.adapted, impl.reason(\"Carbon returns success through a bool plus output index; CarbonEngineJS returns the index directly or -1 while preserving exact name lookup.\") ],\n GetPassCount: [ carbon.method, impl.adapted, UNVALIDATED_TECHNIQUE_INDEX ],\n GetConstant: [ carbon.method, impl.implemented ],\n GetResource: [ carbon.method, impl.implemented ],\n GetParameterAnnotations: [ carbon.method, impl.implemented ],\n GetSortValue: [ carbon.method, impl.implemented ],\n GetEffectDescription: [ carbon.method, impl.implemented ],\n GetEffect: [ carbon.method, impl.implemented ],\n GetShaderTypeMask: [ carbon.method, impl.adapted, UNVALIDATED_TECHNIQUE_INDEX ],\n ProcessEffect: [ carbon.method, impl.adapted, impl.reason(\"Carbon packs renderer handles assigned while reading; the device-free graph leaves the sort key zero until an engine assigns valid handles.\") ],\n HasVertexBufferAccessInRtShadow: [ carbon.method, impl.implemented ]\n }\n});\n"],"names":["Tr2Shader","CjsModel","sortValue","effect","Tr2EffectDescription","hasVertexBufferAccessInRtShadow","GetTechniqueIndex","name","techniques","length","findIndex","technique","GetPassCount","techniqueIndex","passes","GetConstant","findStageValue","GetResource","stage","iterateStages","resource","findNamedCollectionValue","resources","uav","uavs","GetParameterAnnotations","parameterName","findAnnotationSet","annotations","GetSortValue","GetEffectDescription","GetEffect","GetShaderTypeMask","Number","shaderTypeMask","ProcessEffect","pass","stages","stageInputs","pixelHandle","shader","m_shader","vertexHandle","pixelShader","vertexShader","renderStates","passCount","HasVertexBufferAccessInRtShadow","from","values","options","normalized","Object","hasOwn","fromPortable","portable","validateEffectBodyReflection","isPortableReflection","value","isEffectBodyReflection","key","found","push","Array","isArray","find","Map","get","entry","item","UNVALIDATED_TECHNIQUE_INDEX","impl","reason","CjsSchema","define","className","family","fields","type","uint32","rawStruct","boolean","methods","carbon","method","adapted","implemented"],"mappings":";;;;;AAAA;AACA;;AASA;AACO,MAAMA,SAAS,SAASC,QAAQ,CACvC;AAEE;AACAC,EAAAA,SAAS,GAAG,CAAC;;AAEb;AACAC,EAAAA,MAAM,GAAG,IAAIC,oBAAoB,EAAE;;AAEnC;AACAC,EAAAA,+BAA+B,GAAG,KAAK;;AAEvC;AACF;AACA;AACA;AACEC,EAAAA,iBAAiBA,CAACC,IAAI,GAAG,MAAM,EAC/B;IACE,MAAMC,UAAU,GAAG,IAAI,CAACL,MAAM,EAAEK,UAAU,IAAI,EAAE;AAChD,IAAA,IAAI,CA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AAI,CAACc,OAAO,EAAEf,2BAA2B,CAAE;AAC/EnC,IAAAA,aAAa,EAAE,CAAEgD,MAAM,CAACC,MAAM,EAAEb,IAAI,CAACc,OAAO,EAAEd,IAAI,CAACC,MAAM,CAAC,6IAA6I,CAAC,CAAE;IAC1MzB,+BAA+B,EAAE,CAAEoC,MAAM,CAACC,MAAM,EAAEb,IAAI,CAACe,WAAW;AACpE;AACF,CAAC,CAAC;;;;"}
1
+ {"version":3,"file":"Tr2Shader.js","sources":["../../../../src/resource/shader/Tr2Shader.js"],"sourcesContent":["// Source: trinity/trinity/Shader/Tr2Shader.h\n// Source: trinity/trinity/Shader/Tr2Shader.cpp\nimport { CjsSchema, carbon, impl, type } from \"@carbonenginejs/runtime-utils/schema\";\nimport { CjsModel } from \"@carbonenginejs/runtime-utils/model\";\nimport { Tr2EffectDescription } from \"./reflection/Tr2EffectDescription.js\";\n\n/** GPU-free selected shader and its complete source reflection graph. */\nexport class Tr2Shader extends CjsModel\n{\n\n /** m_sortValue (unsigned int) */\n sortValue = 0;\n\n /** m_effect (Tr2EffectDescription) */\n effect = new Tr2EffectDescription();\n\n /** m_hasVertexBufferAccessInRtShadow (bool) */\n hasVertexBufferAccessInRtShadow = false;\n\n /**\n * Index of the named technique; 0 for Carbon's empty-string any-technique\n * sentinel and -1 when the shader has no techniques or the name is unknown.\n */\n GetTechniqueIndex(name = \"Main\")\n {\n const techniques = this.effect?.techniques ?? [];\n if (!techniques.length)\n {\n return -1;\n }\n if (name === \"\")\n {\n return 0;\n }\n return techniques.findIndex(technique => technique?.name === name);\n }\n\n /** Number of passes in a technique; 0 for an unknown index. */\n GetPassCount(techniqueIndex = 0)\n {\n return this.effect?.techniques?.[techniqueIndex]?.passes?.length ?? 0;\n }\n\n /**\n * The reflected constant of this name from any stage of any pass, or null;\n * the description is metadata, not a bound GPU slot.\n */\n GetConstant(name)\n {\n return Tr2Shader.findStageValue(this.effect, name, \"constants\");\n }\n\n /**\n * The reflected resource of this name, searching stage resources before\n * UAVs; null when neither has it.\n */\n GetResource(name)\n {\n for (const stage of Tr2Shader.iterateStages(this.effect))\n {\n const resource = Tr2Shader.findNamedCollectionValue(\n stage?.resources,\n name\n );\n if (resource)\n {\n return resource;\n }\n const uav = Tr2Shader.findNamedCollectionValue(stage?.uavs, name);\n if (uav)\n {\n return uav;\n }\n }\n return null;\n }\n\n /**\n * The annotation set authored for a parameter name, or null; the shape\n * depends on the reflection source.\n */\n GetParameterAnnotations(parameterName)\n {\n return Tr2Shader.findAnnotationSet(\n this.effect?.annotations,\n parameterName\n );\n }\n\n /** The packed draw-sort key; 0 until ProcessEffect has run. */\n GetSortValue()\n {\n return this.sortValue;\n }\n\n /** The reflected effect description, by reference rather than copy. */\n GetEffectDescription()\n {\n return this.effect;\n }\n\n /** The same object GetEffectDescription returns. */\n GetEffect()\n {\n return this.effect;\n }\n\n /** The technique's bitmask of shader stages, or 0 for an unknown index. */\n GetShaderTypeMask(techniqueIndex = 0)\n {\n return Number(\n this.effect?.techniques?.[techniqueIndex]?.shaderTypeMask ?? 0\n );\n }\n\n /**\n * Pack the first technique/pass's renderer handles into Carbon's sort key.\n * A device-free source graph retains 0 while its handles remain invalid.\n */\n ProcessEffect()\n {\n this.sortValue = 0;\n const pass = this.effect?.techniques?.[0]?.passes?.[0];\n if (!pass)\n {\n return;\n }\n const stages = pass.stageInputs ?? [];\n const pixelHandle = Number(\n stages[1]?.shader ?? stages[1]?.m_shader ?? 0xffffffff\n );\n const vertexHandle = Number(\n stages[0]?.shader ?? stages[0]?.m_shader ?? 0xffffffff\n );\n if (pixelHandle === 0xffffffff || vertexHandle === 0xffffffff)\n {\n return;\n }\n const pixelShader = pixelHandle & 0x3ff;\n const vertexShader = vertexHandle & 0x3ff;\n const renderStates = Number(pass.renderStates ?? 0) & 0x3ff;\n const passCount = Number(\n this.effect?.techniques?.[0]?.passes?.length ?? 0\n ) & 0x3;\n this.sortValue = (\n (passCount << 30)\n | (pixelShader << 20)\n | (vertexShader << 10)\n | renderStates\n ) >>> 0;\n }\n\n /** Whether this shader accesses vertex buffers in RT shadow mode. */\n HasVertexBufferAccessInRtShadow()\n {\n return this.hasVertexBufferAccessInRtShadow;\n }\n\n /**\n * Construct a canonical shader graph from JS/JSON model values.\n *\n * @param {object} values Canonical model values.\n * @param {object} options CjsModel import options.\n * @returns {Tr2Shader} Hydrated shader graph.\n */\n static from(values = {}, options = {})\n {\n let normalized = values;\n if (values?.effect\n && !(values.effect instanceof Tr2EffectDescription))\n {\n normalized = {\n ...values,\n effect: Tr2EffectDescription.from(values.effect, options)\n };\n }\n const shader = super.from(normalized, options);\n if (!Object.hasOwn(values ?? {}, \"sortValue\"))\n {\n shader.ProcessEffect();\n }\n return shader;\n }\n\n /**\n * Build one GPU-free shader from one body of a Carbon effect container.\n *\n * `reader` is the container reader the resource opened and retains; this method\n * never opens anything of its own. A body is not independently readable — its\n * strings are offsets into the container's shared arena, and its layout depends\n * on the container's version — so handing each body its own reader would mean\n * re-parsing the header per permutation and losing the arena.\n *\n * Carbon passes exactly that bundle, as loose arguments\n * (`Tr2EffectRes.cpp:126-134`):\n *\n * ```cpp\n * auto offset = m_offsets[index];\n * auto buffer = ...m_data.get() + offset.offset;\n * shader->GetEffect().Read( buffer, offset.size, m_version,\n * m_stringTable, m_stringTableSize, path );\n * shader->ProcessEffect();\n * ```\n *\n * The resource owns `m_data`, `m_offsets`, `m_version` and the string table,\n * and hands the body a pointer plus the version and arena. Here that same state\n * is held by the reader the resource retains, so passing the reader passes the\n * whole bundle and the resource itself adds nothing a body needs.\n *\n * Reading is backend-agnostic. A dx11 body reads exactly as a webgl one does;\n * they differ only in what the optional per-pass block carries, and this method\n * retains that block without interpreting it. What can be *realized* from the\n * result is the engine's question, not the reader's.\n *\n * @param {object} reader Container reader owned by the resource.\n * @param {number} index Permutation index within the container.\n * @returns {Tr2Shader} Canonical selected shader.\n */\n static fromCarbonBinary(reader, index)\n {\n const shader = new this();\n shader.effect = Tr2EffectDescription.fromCarbonBinary(\n reader.readDescription(index)\n );\n shader.ProcessEffect();\n return shader;\n }\n\n /**\n * Find a named value across stage collections in Carbon lookup order.\n *\n * @param {Tr2EffectDescription} effect Effect description to search.\n * @param {string} name Entry name.\n * @param {string} key Stage collection key.\n * @returns {*|null} Matching value, or `null`.\n */\n static findStageValue(effect, name, key)\n {\n for (const stage of Tr2Shader.iterateStages(effect))\n {\n const found = Tr2Shader.findNamedCollectionValue(stage?.[key], name);\n if (found)\n {\n return found;\n }\n }\n return null;\n }\n\n /** Flatten pass stage inputs in Carbon lookup order. */\n static iterateStages(effect)\n {\n const stages = [];\n for (const technique of effect?.techniques ?? [])\n {\n for (const pass of technique?.passes ?? [])\n {\n stages.push(...pass?.stageInputs ?? []);\n }\n }\n return stages;\n }\n\n /** Find a named entry in an array, Map, or plain object collection. */\n static findNamedCollectionValue(values, name)\n {\n if (!values)\n {\n return null;\n }\n if (Array.isArray(values))\n {\n return values.find(\n value => value?.name === name || value?.[1]?.name === name\n ) ?? null;\n }\n if (values instanceof Map)\n {\n for (const value of values.values())\n {\n if (value?.name === name)\n {\n return value;\n }\n }\n return null;\n }\n for (const value of Object.values(values))\n {\n if (value?.name === name)\n {\n return value;\n }\n }\n return null;\n }\n\n /** Resolve a parameter's annotations from a Map, array, or plain object. */\n static findAnnotationSet(annotations, parameterName)\n {\n if (!annotations)\n {\n return null;\n }\n if (annotations instanceof Map)\n {\n return annotations.get(parameterName) ?? null;\n }\n if (Array.isArray(annotations))\n {\n const entry = annotations.find(\n item => item?.name === parameterName\n || item?.[0] === parameterName\n );\n return entry?.annotations ?? entry?.value ?? entry?.[1] ?? null;\n }\n return annotations[parameterName] ?? null;\n }\n\n}\n\n// Declared as data rather than with decorators, so this module stays plain ESM\n// that loads from source without a transform. The decorator vocabulary is used\n// verbatim as values, so the registered metadata is identical to the decorated\n// form. Field order is key order, and it drives GetValues() export order.\n// Statics belong in `methods`: the prototype is what carries instance fields.\nconst UNVALIDATED_TECHNIQUE_INDEX = impl.reason(\n \"Carbon assumes an already-validated technique index; CarbonEngineJS safely returns zero for an unavailable index.\"\n);\n\nCjsSchema.define(Tr2Shader, {\n className: \"Tr2Shader\",\n family: \"shader\",\n fields: {\n sortValue: type.uint32,\n effect: type.rawStruct(\"Tr2EffectDescription\"),\n hasVertexBufferAccessInRtShadow: type.boolean\n },\n methods: {\n GetTechniqueIndex: [ carbon.method, impl.adapted, impl.reason(\"Carbon returns success through a bool plus output index; CarbonEngineJS returns the index directly or -1 while preserving exact name lookup.\") ],\n GetPassCount: [ carbon.method, impl.adapted, UNVALIDATED_TECHNIQUE_INDEX ],\n GetConstant: [ carbon.method, impl.implemented ],\n GetResource: [ carbon.method, impl.implemented ],\n GetParameterAnnotations: [ carbon.method, impl.implemented ],\n GetSortValue: [ carbon.method, impl.implemented ],\n GetEffectDescription: [ carbon.method, impl.implemented ],\n GetEffect: [ carbon.method, impl.implemented ],\n GetShaderTypeMask: [ carbon.method, impl.adapted, UNVALIDATED_TECHNIQUE_INDEX ],\n ProcessEffect: [ carbon.method, impl.adapted, impl.reason(\"Carbon packs renderer handles assigned while reading; the device-free graph leaves the sort key zero until an engine assigns valid handles.\") ],\n HasVertexBufferAccessInRtShadow: [ carbon.method, impl.implemented ]\n }\n});\n"],"names":["Tr2Shader","CjsModel","sortValue","effect","Tr2EffectDescription","hasVertexBufferAccessInRtShadow","GetTechniqueIndex","name","techniques","length","findIndex","technique","GetPassCount","techniqueIndex","passes","GetConstant","findStageValue","GetResource","stage","iterateStages","resource","findNamedCollectionValue","resources","uav","uavs","GetParameterAnnotations","parameterName","findAnnotationSet","annotations","GetSortValue","GetEffectDescription","GetEffect","GetShaderTypeMask","Number","shaderTypeMask","ProcessEffect","pass","stages","stageInputs","pixelHandle","shader","m_shader","vertexHandle","pixelShader","vertexShader","renderStates","passCount","HasVertexBufferAccessInRtShadow","from","values","options","normalized","Object","hasOwn","fromCarbonBinary","reader","index","readDescription","key","found","push","Array","isArray","find","value","Map","get","entry","item","UNVALIDATED_TECHNIQUE_INDEX","impl","reason","CjsSchema","define","className","family","fields","type","uint32","rawStruct","boolean","methods","carbon","method","adapted","implemented"],"mappings":";;;;AAAA;AACA;;AAKA;AACO,MAAMA,SAAS,SAASC,QAAQ,CACvC;AAEE;AACAC,EAAAA,SAAS,GAAG,CAAC;;AAEb;AACAC,EAAAA,MAAM,GAAG,IAAIC,oBAAoB,EAAE;;AAEnC;AACAC,EAAAA,+BAA+B,GAAG,KAAK;;AAEvC;AACF;AACA;AACA;AACEC,EAAAA,iBAAiBA,CAACC,IAAI,GAAG,MAAM,EAC/B;IACE,MAAMC,UAAU,GAAG,IAAI,CAACL,MAAM,EAAEK,UAAU,IAAI,EAAE;AAChD,IAAA,IAAI,CAACA,UAAU,CAACC,MAAM,EACtB;AACE,MAAA,OAAO,EAAE;AACX,IAAA;IACA,IAAIF,IAAI,KAAK,EAAE,EACf;AACE,MAAA,OAAO,CAAC;AACV,IAAA;IACA,OAAOC,UAAU,CAACE,SAAS,CAACC,SAAS,IAAIA,SAAS,EAAEJ,IAAI,KAAKA,IAAI,CAAC;AACpE,EAAA;;AAEA;AACAK,EAAAA,YAAYA,CAACC,cAAc,GAAG,CAAC,EAC/B;AACE,IAAA,OAAO,IAAI,CAACV,MAAM,EAAEK,UAAU,GAAGK,cAAc,CAAC,EAAEC,MAAM,EAAEL,MAAM,IAAI,CAAC;AACvE,EAAA;;AAEA;AACF;AACA;AACA;EACEM,WAAWA,CAACR,IAAI,EAChB;IACE,OAAOP,SAAS,CAACgB,cAAc,CAAC,IAAI,CAACb,MAAM,EAAEI,IAAI,EAAE,WAAW,CAAC;AACjE,EAAA;;AAEA;AACF;AACA;AACA;EACEU,WAAWA,CAACV,IAAI,EAChB;IACE,KAAK,MAAMW,KAAK,IAAIlB,SAAS,CAACmB,aAAa,CAAC,IAAI,CAAChB,MAAM,CAAC,EACxD;MACE,MAAMiB,QAAQ,GAAGpB,SAAS,CAACqB,wBAAwB,CACjDH,KAAK,EAAEI,SAAS,EAChBf,IACF,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,MAAM,EAAEb,IAAI,CAACe,WAAW,CAAE;IAChDpE,WAAW,EAAE,CAAEiE,MAAM,CAACC,MAAM,EAAEb,IAAI,CAACe,WAAW,CAAE;IAChD5D,uBAAuB,EAAE,CAAEyD,MAAM,CAACC,MAAM,EAAEb,IAAI,CAACe,WAAW,CAAE;IAC5DxD,YAAY,EAAE,CAAEqD,MAAM,CAACC,MAAM,EAAEb,IAAI,CAACe,WAAW,CAAE;IACjDvD,oBAAoB,EAAE,CAAEoD,MAAM,CAACC,MAAM,EAAEb,IAAI,CAACe,WAAW,CAAE;IACzDtD,SAAS,EAAE,CAAEmD,MAAM,CAACC,MAAM,EAAEb,IAAI,CAACe,WAAW,CAAE;IAC9CrD,iBAAiB,EAAE,CAAEkD,MAAM,CAACC,MAAM,EAAEb,IAAI,CAACc,OAAO,EAAEf,2BAA2B,CAAE;AAC/ElC,IAAAA,aAAa,EAAE,CAAE+C,MAAM,CAACC,MAAM,EAAEb,IAAI,CAACc,OAAO,EAAEd,IAAI,CAACC,MAAM,CAAC,6IAA6I,CAAC,CAAE;IAC1MxB,+BAA+B,EAAE,CAAEmC,MAAM,CAACC,MAAM,EAAEb,IAAI,CAACe,WAAW;AACpE;AACF,CAAC,CAAC;;;;"}
@@ -1,6 +1,7 @@
1
1
  import { CjsSchema } from '@carbonenginejs/runtime-utils/schema';
2
2
  import { CjsModel } from '@carbonenginejs/runtime-utils/model';
3
- import { isPlainObject, isUint32 } from '@carbonenginejs/runtime-utils/is';
3
+ import { isPlainObject } from '@carbonenginejs/runtime-utils/is';
4
+ import { recordText, toRecordText } from './carbonRecordFields.js';
4
5
 
5
6
  // Source: trinity/trinity/Shader/Tr2EffectDescription.h
6
7
 
@@ -31,41 +32,48 @@ class Tr2EffectConstant extends CjsModel {
31
32
  isAutoregister = false;
32
33
 
33
34
  /**
34
- * Build one constant from its portable JSON reflection record.
35
+ * Build one constant from its Carbon v15 description record.
35
36
  *
36
- * @param {object} value Portable constant record.
37
+ * The record's numeric fields are already the widths Carbon declares, so this
38
+ * is a rename plus the two byte-to-bool conversions; only `name` needs
39
+ * dereferencing, because strings live in the container's arena.
40
+ *
41
+ * @param {object} record Carbon constant record.
37
42
  * @returns {Tr2EffectConstant} Reflected constant.
38
43
  */
39
- static fromPortable(value) {
40
- if (!isPlainObject(value)) {
41
- throw new TypeError("Portable effect constant must be an object");
42
- }
43
- if (!isUint32(value.offset)) {
44
- throw new RangeError("Portable constant offset must fit uint32");
45
- }
46
- if (!isUint32(value.size)) {
47
- throw new RangeError("Portable constant size must fit uint32");
48
- }
49
- if (!isUint32(value.type)) {
50
- throw new RangeError("Portable constant type must fit uint32");
51
- }
52
- if (!isUint32(value.dimension)) {
53
- throw new RangeError("Portable constant dimension must fit uint32");
54
- }
55
- if (!isUint32(value.elements)) {
56
- throw new RangeError("Portable constant element count must fit uint32");
44
+ static fromCarbonBinary(record) {
45
+ if (!isPlainObject(record)) {
46
+ throw new TypeError("Carbon effect constant record must be an object");
57
47
  }
58
48
  const constant = new this();
59
- constant.name = String(value.name ?? "");
60
- constant.offset = value.offset;
61
- constant.size = value.size;
62
- constant.type = value.type;
63
- constant.dimension = value.dimension;
64
- constant.elements = value.elements;
65
- constant.isSRGB = !!value.isSRGB;
66
- constant.isAutoregister = !!value.isAutoregister;
49
+ constant.name = recordText(record.name);
50
+ constant.offset = record.offset;
51
+ constant.size = record.size;
52
+ constant.type = record.type;
53
+ constant.dimension = record.dimension;
54
+ constant.elements = record.elements;
55
+ constant.isSRGB = !!record.isSRGB;
56
+ constant.isAutoregister = !!record.isAutoregister;
67
57
  return constant;
68
58
  }
59
+
60
+ /**
61
+ * Emit this constant as a Carbon v15 description record.
62
+ *
63
+ * @returns {object} Carbon constant record.
64
+ */
65
+ toCarbonBinary() {
66
+ return {
67
+ name: toRecordText(this.name),
68
+ offset: this.offset,
69
+ size: this.size,
70
+ type: this.type,
71
+ dimension: this.dimension,
72
+ elements: this.elements,
73
+ isSRGB: this.isSRGB ? 1 : 0,
74
+ isAutoregister: this.isAutoregister ? 1 : 0
75
+ };
76
+ }
69
77
  static Type = Object.freeze({
70
78
  FLOAT: 0,
71
79
  INT: 1,
@@ -1 +1 @@
1
- {"version":3,"file":"Tr2EffectConstant.js","sources":["../../../../../src/resource/shader/reflection/Tr2EffectConstant.js"],"sourcesContent":["// Source: trinity/trinity/Shader/Tr2EffectDescription.h\nimport { CjsSchema } from \"@carbonenginejs/runtime-utils/schema\";\nimport { CjsModel } from \"@carbonenginejs/runtime-utils/model\";\nimport {\n isPlainObject,\n isUint32\n} from \"@carbonenginejs/runtime-utils/is\";\n\n/** Reflected shader constant metadata. */\nexport class Tr2EffectConstant extends CjsModel\n{\n\n /** name (BlueSharedString) */\n name = \"\";\n\n /** offset (unsigned) */\n offset = 0;\n\n /** size (unsigned) */\n size = 0;\n\n /** type (Type - enum Type) */\n type = 0;\n\n /** dimension (unsigned) */\n dimension = 0;\n\n /** elements (unsigned) */\n elements = 0;\n\n /** isSRGB (bool) */\n isSRGB = false;\n\n /** isAutoregister (bool) */\n isAutoregister = false;\n\n /**\n * Build one constant from its portable JSON reflection record.\n *\n * @param {object} value Portable constant record.\n * @returns {Tr2EffectConstant} Reflected constant.\n */\n static fromPortable(value)\n {\n if (!isPlainObject(value))\n {\n throw new TypeError(\"Portable effect constant must be an object\");\n }\n if (!isUint32(value.offset))\n {\n throw new RangeError(\"Portable constant offset must fit uint32\");\n }\n if (!isUint32(value.size))\n {\n throw new RangeError(\"Portable constant size must fit uint32\");\n }\n if (!isUint32(value.type))\n {\n throw new RangeError(\"Portable constant type must fit uint32\");\n }\n if (!isUint32(value.dimension))\n {\n throw new RangeError(\"Portable constant dimension must fit uint32\");\n }\n if (!isUint32(value.elements))\n {\n throw new RangeError(\n \"Portable constant element count must fit uint32\"\n );\n }\n\n const constant = new this();\n constant.name = String(value.name ?? \"\");\n constant.offset = value.offset;\n constant.size = value.size;\n constant.type = value.type;\n constant.dimension = value.dimension;\n constant.elements = value.elements;\n constant.isSRGB = !!value.isSRGB;\n constant.isAutoregister = !!value.isAutoregister;\n return constant;\n }\n\n static Type = Object.freeze({\n FLOAT: 0,\n INT: 1,\n UINT: 2,\n BOOL: 3,\n OTHER: 4\n });\n\n}\n\n// Declared imperatively rather than with decorators, so this module stays plain\n// ESM that loads from source without a transform, which lets its tests import\n// source instead of build output.\n//\n// Field order matters: it drives GetValues() export order. Statics belong in\n// `methods` here rather than in a decorateMethod() call, which targets the\n// prototype and would register a static as an instance field.\nCjsSchema.define(Tr2EffectConstant, {\n className: \"Tr2EffectConstant\",\n family: \"shader\",\n fields: [\n { name: \"name\", type: { kind: \"string\" } },\n { name: \"offset\", type: { kind: \"uint32\" } },\n { name: \"size\", type: { kind: \"uint32\" } },\n { name: \"type\", enum: { enumType: \"Type\" }, type: { kind: \"int32\" } },\n { name: \"dimension\", type: { kind: \"uint32\" } },\n { name: \"elements\", type: { kind: \"uint32\" } },\n { name: \"isSRGB\", type: { kind: \"boolean\" } },\n { name: \"isAutoregister\", type: { kind: \"boolean\" } }\n ]\n});\n"],"names":["Tr2EffectConstant","CjsModel","name","offset","size","type","dimension","elements","isSRGB","isAutoregister","fromPortable","value","isPlainObject","TypeError","isUint32","RangeError","constant","String","Type","Object","freeze","FLOAT","INT","UINT","BOOL","OTHER","CjsSchema","define","className","family","fields","kind","enum","enumType"],"mappings":";;;;AAAA;;AAQA;AACO,MAAMA,iBAAiB,SAASC,QAAQ,CAC/C;AAEE;AACAC,EAAAA,IAAI,GAAG,EAAE;;AAET;AACAC,EAAAA,MAAM,GAAG,CAAC;;AAEV;AACAC,EAAAA,IAAI,GAAG,CAAC;;AAER;AACAC,EAAAA,IAAI,GAAG,CAAC;;AAER;AACAC,EAAAA,SAAS,GAAG,CAAC;;AAEb;AACAC,EAAAA,QAAQ,GAAG,CAAC;;AAEZ;AACAC,EAAAA,MAAM,GAAG,KAAK;;AAEd;AACAC,EAAAA,cAAc,GAAG,KAAK;;AAEtB;AACF;AACA;AACA;AACA;AACA;EACE,OAAOC,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IAAAA,IAAI,EAAE,UAAU;AAAEG,IAAAA,IAAI,EAAE;AAAE0B,MAAAA,IAAI,EAAE;AAAS;AAAE,GAAC,EAC9C;AAAE7B,IAAAA,IAAI,EAAE,QAAQ;AAAEG,IAAAA,IAAI,EAAE;AAAE0B,MAAAA,IAAI,EAAE;AAAU;AAAE,GAAC,EAC7C;AAAE7B,IAAAA,IAAI,EAAE,gBAAgB;AAAEG,IAAAA,IAAI,EAAE;AAAE0B,MAAAA,IAAI,EAAE;AAAU;GAAG;AAEzD,CAAC,CAAC;;;;"}
1
+ {"version":3,"file":"Tr2EffectConstant.js","sources":["../../../../../src/resource/shader/reflection/Tr2EffectConstant.js"],"sourcesContent":["// Source: trinity/trinity/Shader/Tr2EffectDescription.h\nimport { CjsSchema } from \"@carbonenginejs/runtime-utils/schema\";\nimport { CjsModel } from \"@carbonenginejs/runtime-utils/model\";\nimport {\n isPlainObject\n} from \"@carbonenginejs/runtime-utils/is\";\nimport { recordText, toRecordText } from \"./carbonRecordFields.js\";\n\n/** Reflected shader constant metadata. */\nexport class Tr2EffectConstant extends CjsModel\n{\n\n /** name (BlueSharedString) */\n name = \"\";\n\n /** offset (unsigned) */\n offset = 0;\n\n /** size (unsigned) */\n size = 0;\n\n /** type (Type - enum Type) */\n type = 0;\n\n /** dimension (unsigned) */\n dimension = 0;\n\n /** elements (unsigned) */\n elements = 0;\n\n /** isSRGB (bool) */\n isSRGB = false;\n\n /** isAutoregister (bool) */\n isAutoregister = false;\n\n /**\n * Build one constant from its Carbon v15 description record.\n *\n * The record's numeric fields are already the widths Carbon declares, so this\n * is a rename plus the two byte-to-bool conversions; only `name` needs\n * dereferencing, because strings live in the container's arena.\n *\n * @param {object} record Carbon constant record.\n * @returns {Tr2EffectConstant} Reflected constant.\n */\n static fromCarbonBinary(record)\n {\n if (!isPlainObject(record))\n {\n throw new TypeError(\"Carbon effect constant record must be an object\");\n }\n\n const constant = new this();\n constant.name = recordText(record.name);\n constant.offset = record.offset;\n constant.size = record.size;\n constant.type = record.type;\n constant.dimension = record.dimension;\n constant.elements = record.elements;\n constant.isSRGB = !!record.isSRGB;\n constant.isAutoregister = !!record.isAutoregister;\n return constant;\n }\n\n /**\n * Emit this constant as a Carbon v15 description record.\n *\n * @returns {object} Carbon constant record.\n */\n toCarbonBinary()\n {\n return {\n name: toRecordText(this.name),\n offset: this.offset,\n size: this.size,\n type: this.type,\n dimension: this.dimension,\n elements: this.elements,\n isSRGB: this.isSRGB ? 1 : 0,\n isAutoregister: this.isAutoregister ? 1 : 0\n };\n }\n\n static Type = Object.freeze({\n FLOAT: 0,\n INT: 1,\n UINT: 2,\n BOOL: 3,\n OTHER: 4\n });\n\n}\n\n// Declared imperatively rather than with decorators, so this module stays plain\n// ESM that loads from source without a transform, which lets its tests import\n// source instead of build output.\n//\n// Field order matters: it drives GetValues() export order. Statics belong in\n// `methods` here rather than in a decorateMethod() call, which targets the\n// prototype and would register a static as an instance field.\nCjsSchema.define(Tr2EffectConstant, {\n className: \"Tr2EffectConstant\",\n family: \"shader\",\n fields: [\n { name: \"name\", type: { kind: \"string\" } },\n { name: \"offset\", type: { kind: \"uint32\" } },\n { name: \"size\", type: { kind: \"uint32\" } },\n { name: \"type\", enum: { enumType: \"Type\" }, type: { kind: \"int32\" } },\n { name: \"dimension\", type: { kind: \"uint32\" } },\n { name: \"elements\", type: { kind: \"uint32\" } },\n { name: \"isSRGB\", type: { kind: \"boolean\" } },\n { name: \"isAutoregister\", type: { kind: \"boolean\" } }\n ]\n});\n"],"names":["Tr2EffectConstant","CjsModel","name","offset","size","type","dimension","elements","isSRGB","isAutoregister","fromCarbonBinary","record","isPlainObject","TypeError","constant","recordText","toCarbonBinary","toRecordText","Type","Object","freeze","FLOAT","INT","UINT","BOOL","OTHER","CjsSchema","define","className","family","fields","kind","enum","enumType"],"mappings":";;;;;AAAA;;AAQA;AACO,MAAMA,iBAAiB,SAASC,QAAQ,CAC/C;AAEE;AACAC,EAAAA,IAAI,GAAG,EAAE;;AAET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E,GAAC,EACrE;AAAE7B,IAAAA,IAAI,EAAE,WAAW;AAAEG,IAAAA,IAAI,EAAE;AAAE0B,MAAAA,IAAI,EAAE;AAAS;AAAE,GAAC,EAC/C;AAAE7B,IAAAA,IAAI,EAAE,UAAU;AAAEG,IAAAA,IAAI,EAAE;AAAE0B,MAAAA,IAAI,EAAE;AAAS;AAAE,GAAC,EAC9C;AAAE7B,IAAAA,IAAI,EAAE,QAAQ;AAAEG,IAAAA,IAAI,EAAE;AAAE0B,MAAAA,IAAI,EAAE;AAAU;AAAE,GAAC,EAC7C;AAAE7B,IAAAA,IAAI,EAAE,gBAAgB;AAAEG,IAAAA,IAAI,EAAE;AAAE0B,MAAAA,IAAI,EAAE;AAAU;GAAG;AAEzD,CAAC,CAAC;;;;"}
@@ -1,8 +1,10 @@
1
1
  import { CjsSchema, type } from '@carbonenginejs/runtime-utils/schema';
2
2
  import { CjsModel } from '@carbonenginejs/runtime-utils/model';
3
- import { isPlainObject, isArray } from '@carbonenginejs/runtime-utils/is';
3
+ import { isPlainObject } from '@carbonenginejs/runtime-utils/is';
4
4
  import { Tr2EffectParameterAnnotation } from './Tr2EffectParameterAnnotation.js';
5
5
  import { Tr2EffectTechnique } from './Tr2EffectTechnique.js';
6
+ import { recordText, toRecordText } from './carbonRecordFields.js';
7
+ import { compareUtf8 } from '../../../format/compareUtf8.js';
6
8
 
7
9
  // Source: trinity/trinity/Shader/Tr2EffectDescription.h
8
10
  // Source: trinity/trinity/Shader/Tr2EffectDescription.cpp
@@ -47,47 +49,50 @@ class Tr2EffectDescription extends CjsModel {
47
49
  }
48
50
 
49
51
  /**
50
- * Build one complete effect description from its portable JSON record.
52
+ * Build one complete effect description from its Carbon v15 record tree.
51
53
  *
52
- * @param {object} value Portable effect-description record.
54
+ * This is the whole body: every technique, and the effect-level annotation
55
+ * groups keyed by the parameter they annotate. Carbon sorts those keys by
56
+ * `strcmp` on the way out, and the map preserves whatever order the file used,
57
+ * so nothing here depends on the ordering being meaningful.
58
+ *
59
+ * @param {object} record Carbon effect description record.
53
60
  * @returns {Tr2EffectDescription} Reflected description.
54
61
  */
55
- static fromPortable(value) {
56
- if (!isPlainObject(value)) {
57
- throw new TypeError("Portable effect description must be an object");
58
- }
59
- if (!isArray(value.annotations)) {
60
- throw new TypeError("Portable effect annotation groups must be an array");
61
- }
62
- if (!isArray(value.techniques)) {
63
- throw new TypeError("Portable effect techniques must be an array");
64
- }
65
- if (value.annotationGroupCount !== value.annotations.length || value.techniqueCount !== value.techniques.length) {
66
- throw new Error("Portable effect description counts disagree with its collections");
62
+ static fromCarbonBinary(record) {
63
+ if (!isPlainObject(record)) {
64
+ throw new TypeError("Carbon effect description record must be an object");
67
65
  }
68
66
  const effect = new this();
69
- effect.annotations = this.readPortableAnnotationGroups(value.annotations);
70
- effect.techniques = value.techniques.map(entry => Tr2EffectTechnique.fromPortable(entry));
67
+ effect.annotations = new Map();
68
+ for (const group of record.annotations) {
69
+ const parameterName = recordText(group.name);
70
+ if (effect.annotations.has(parameterName)) {
71
+ throw new Error(`Carbon effect annotation group "${parameterName}" is duplicated`);
72
+ }
73
+ effect.annotations.set(parameterName, group.annotations.map(entry => Tr2EffectParameterAnnotation.fromCarbonBinary(entry)));
74
+ }
75
+ effect.techniques = record.techniques.map(entry => Tr2EffectTechnique.fromCarbonBinary(entry));
71
76
  return effect;
72
77
  }
73
78
 
74
- /** Build parameter-name-indexed annotation groups. */
75
- static readPortableAnnotationGroups(values) {
76
- const result = new Map();
77
- for (const value of values) {
78
- if (!isPlainObject(value)) {
79
- throw new TypeError("Portable effect annotation group must be an object");
80
- }
81
- const parameterName = String(value.parameterName ?? "");
82
- if (!isArray(value.annotations)) {
83
- throw new TypeError(`Portable annotations for parameter "${parameterName}" must be an array`);
84
- }
85
- if (result.has(parameterName)) {
86
- throw new Error(`Portable effect annotation group "${parameterName}" is duplicated`);
87
- }
88
- result.set(parameterName, value.annotations.map(entry => Tr2EffectParameterAnnotation.fromPortable(entry)));
89
- }
90
- return result;
79
+ /**
80
+ * Emit this description as a Carbon v15 record tree.
81
+ *
82
+ * Effect-level annotation groups are sorted by parameter name, and each
83
+ * group's annotations by their own name, because Carbon sorts both by `strcmp`
84
+ * before writing.
85
+ *
86
+ * @returns {object} Carbon effect description record.
87
+ */
88
+ toCarbonBinary() {
89
+ return {
90
+ techniques: this.techniques.map(technique => technique.toCarbonBinary()),
91
+ annotations: Array.from(this.annotations, ([name, annotations]) => ({
92
+ name: toRecordText(name),
93
+ annotations: annotations.map(entry => entry.toCarbonBinary()).sort((left, right) => compareUtf8(left.name.value, right.name.value))
94
+ })).sort((left, right) => compareUtf8(left.name.value, right.name.value))
95
+ };
91
96
  }
92
97
  }
93
98
 
@@ -1 +1 @@
1
- {"version":3,"file":"Tr2EffectDescription.js","sources":["../../../../../src/resource/shader/reflection/Tr2EffectDescription.js"],"sourcesContent":["// Source: trinity/trinity/Shader/Tr2EffectDescription.h\n// Source: trinity/trinity/Shader/Tr2EffectDescription.cpp\nimport { CjsSchema, impl, type } from \"@carbonenginejs/runtime-utils/schema\";\nimport { CjsModel } from \"@carbonenginejs/runtime-utils/model\";\nimport {\n isArray,\n isPlainObject\n} from \"@carbonenginejs/runtime-utils/is\";\nimport { Tr2EffectParameterAnnotation } from \"./Tr2EffectParameterAnnotation.js\";\nimport { Tr2EffectTechnique } from \"./Tr2EffectTechnique.js\";\n\n/** Complete device-free effect description for one selected shader body. */\nexport class Tr2EffectDescription extends CjsModel\n{\n\n /** techniques (TrackableStdVector<Tr2EffectTechnique>) */\n techniques = [];\n\n /** annotations (Tr2EffectAnnotationMap) */\n annotations = new Map();\n\n /**\n * Construct a canonical effect description from JS/JSON model values.\n *\n * @param {object} values Canonical model values.\n * @param {object} options CjsModel import options.\n * @returns {Tr2EffectDescription} Hydrated description.\n */\n static from(values = {}, options = {})\n {\n let normalized = values;\n let annotations = null;\n if (values && Object.hasOwn(values, \"annotations\"))\n {\n const entries = values.annotations instanceof Map\n ? values.annotations\n : Object.entries(values.annotations ?? {});\n annotations = new Map();\n for (const [ parameterName, records ] of entries)\n {\n if (!Array.isArray(records))\n {\n throw new TypeError(\n `Effect annotations for \"${parameterName}\" must be an array`\n );\n }\n annotations.set(\n String(parameterName),\n records.map(record => record instanceof Tr2EffectParameterAnnotation\n ? record\n : Tr2EffectParameterAnnotation.from(record, options))\n );\n }\n normalized = { ...values, annotations };\n }\n const effect = super.from(normalized, options);\n if (annotations)\n {\n effect.annotations = annotations;\n }\n return effect;\n }\n\n /**\n * Build one complete effect description from its portable JSON record.\n *\n * @param {object} value Portable effect-description record.\n * @returns {Tr2EffectDescription} Reflected description.\n */\n static fromPortable(value)\n {\n if (!isPlainObject(value))\n {\n throw new TypeError(\"Portable effect description must be an object\");\n }\n if (!isArray(value.annotations))\n {\n throw new TypeError(\n \"Portable effect annotation groups must be an array\"\n );\n }\n if (!isArray(value.techniques))\n {\n throw new TypeError(\"Portable effect techniques must be an array\");\n }\n if (value.annotationGroupCount !== value.annotations.length\n || value.techniqueCount !== value.techniques.length)\n {\n throw new Error(\n \"Portable effect description counts disagree with its collections\"\n );\n }\n\n const effect = new this();\n effect.annotations = this.readPortableAnnotationGroups(\n value.annotations\n );\n effect.techniques = value.techniques.map(\n entry => Tr2EffectTechnique.fromPortable(entry)\n );\n return effect;\n }\n\n /** Build parameter-name-indexed annotation groups. */\n static readPortableAnnotationGroups(values)\n {\n const result = new Map();\n for (const value of values)\n {\n if (!isPlainObject(value))\n {\n throw new TypeError(\n \"Portable effect annotation group must be an object\"\n );\n }\n const parameterName = String(value.parameterName ?? \"\");\n if (!isArray(value.annotations))\n {\n throw new TypeError(\n `Portable annotations for parameter \"${parameterName}\" must be an array`\n );\n }\n if (result.has(parameterName))\n {\n throw new Error(\n `Portable effect annotation group \"${parameterName}\" is duplicated`\n );\n }\n result.set(\n parameterName,\n value.annotations.map(\n entry => Tr2EffectParameterAnnotation.fromPortable(entry)\n )\n );\n }\n return result;\n }\n\n}\n\n// Declared imperatively rather than with decorators, so this module stays\n// plain ESM that loads from source without a transform. The decorator\n// expressions are reused verbatim, so the registered metadata is identical.\n// Statics belong in `methods`: decorateMethod targets the prototype and\n// would register a static as an instance field.\nCjsSchema.define(Tr2EffectDescription, {\n className: \"Tr2EffectDescription\",\n family: \"shader\",\n fields: {\n techniques: type.list(\"Tr2EffectTechnique\"),\n annotations: type.map(\"Tr2EffectParameterAnnotationMap\")\n }\n});\n"],"names":["Tr2EffectDescription","CjsModel","techniques","annotations","Map","from","values","options","normalized","Object","hasOwn","entries","parameterName","records","Array","isArray","TypeError","set","String","map","record","Tr2EffectParameterAnnotation","effect","fromPortable","value","isPlainObject","annotationGroupCount","length","techniqueCount","Error","readPortableAnnotationGroups","entry","Tr2EffectTechnique","result","has","CjsSchema","define","className","family","fields","type","list"],"mappings":";;;;;;AAAA;AACA;;AAUA;AACO,MAAMA,oBAAoB,SAASC,QAAQ,CAClD;AAEE;AACAC,EAAAA,UAAU,GAAG,EAAE;;AAEf;AACAC,EAAAA,WAAW,GAAG,IAAIC,GAAG,EAAE;;AAEvB;AACF;AACA;AACA;AACA;AACA;AACA;EACE,OAAOC,IAAIA,CAACC,MAAM,GAAG,EAAE,EAAEC,OAAO,GAAG,EAAE,EACrC;IACE,IAAIC,UAAU,GAAGF,MAAM;IACvB,IAAIH,WAAW,GAAG,IAAI;IACtB,IAAIG,MAAM,IAAIG,MAAM,CAACC,MAAM,CAACJ,MAAM,EAAE,aAAa,CAAC,EAClD;MACE,MAAMK,OAAO,GAAGL,MAAM,CAACH,WAAW,YAAYC,GAAG,GAC7CE,MAAM,CAACH,WAAW,GAClBM,MAAM,CAACE,OAAO,CAACL,MAAM,CAACH,WAAW,IAAI,EAAE,CAAC;AAC5CA,MAAAA,WAAW,GAAG,IAAIC,GAAG,EAAE;MACvB,KAAK,MAAM,CAAEQ,aAAa,EAAEC,OAAO,CAAE,IAAIF,OAAO,EAChD;AACE,QAAA,IAAI,CAACG,KAAK,CAACC,OAAO,CAACF,OAAO,CAAC,EAC3B;AAC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BAAoB,EAAE;AACrCqC,EAAAA,SAAS,EAAE,sBAAsB;AACjCC,EAAAA,MAAM,EAAE,QAAQ;AAChBC,EAAAA,MAAM,EAAE;AACNrC,IAAAA,UAAU,EAAEsC,IAAI,CAACC,IAAI,CAAC,oBAAoB,CAAC;AAC3CtC,IAAAA,WAAW,EAAEqC,IAAI,CAACrB,GAAG,CAAC,iCAAiC;AACzD;AACF,CAAC,CAAC;;;;"}
1
+ {"version":3,"file":"Tr2EffectDescription.js","sources":["../../../../../src/resource/shader/reflection/Tr2EffectDescription.js"],"sourcesContent":["// Source: trinity/trinity/Shader/Tr2EffectDescription.h\n// Source: trinity/trinity/Shader/Tr2EffectDescription.cpp\nimport { CjsSchema, impl, type } from \"@carbonenginejs/runtime-utils/schema\";\nimport { CjsModel } from \"@carbonenginejs/runtime-utils/model\";\nimport { isPlainObject } from \"@carbonenginejs/runtime-utils/is\";\nimport { Tr2EffectParameterAnnotation } from \"./Tr2EffectParameterAnnotation.js\";\nimport { Tr2EffectTechnique } from \"./Tr2EffectTechnique.js\";\nimport { recordText, toRecordText } from \"./carbonRecordFields.js\";\nimport { compareUtf8 } from \"../../../format/compareUtf8.js\";\n\n/** Complete device-free effect description for one selected shader body. */\nexport class Tr2EffectDescription extends CjsModel\n{\n\n /** techniques (TrackableStdVector<Tr2EffectTechnique>) */\n techniques = [];\n\n /** annotations (Tr2EffectAnnotationMap) */\n annotations = new Map();\n\n /**\n * Construct a canonical effect description from JS/JSON model values.\n *\n * @param {object} values Canonical model values.\n * @param {object} options CjsModel import options.\n * @returns {Tr2EffectDescription} Hydrated description.\n */\n static from(values = {}, options = {})\n {\n let normalized = values;\n let annotations = null;\n if (values && Object.hasOwn(values, \"annotations\"))\n {\n const entries = values.annotations instanceof Map\n ? values.annotations\n : Object.entries(values.annotations ?? {});\n annotations = new Map();\n for (const [ parameterName, records ] of entries)\n {\n if (!Array.isArray(records))\n {\n throw new TypeError(\n `Effect annotations for \"${parameterName}\" must be an array`\n );\n }\n annotations.set(\n String(parameterName),\n records.map(record => record instanceof Tr2EffectParameterAnnotation\n ? record\n : Tr2EffectParameterAnnotation.from(record, options))\n );\n }\n normalized = { ...values, annotations };\n }\n const effect = super.from(normalized, options);\n if (annotations)\n {\n effect.annotations = annotations;\n }\n return effect;\n }\n\n /**\n * Build one complete effect description from its Carbon v15 record tree.\n *\n * This is the whole body: every technique, and the effect-level annotation\n * groups keyed by the parameter they annotate. Carbon sorts those keys by\n * `strcmp` on the way out, and the map preserves whatever order the file used,\n * so nothing here depends on the ordering being meaningful.\n *\n * @param {object} record Carbon effect description record.\n * @returns {Tr2EffectDescription} Reflected description.\n */\n static fromCarbonBinary(record)\n {\n if (!isPlainObject(record))\n {\n throw new TypeError(\"Carbon effect description record must be an object\");\n }\n\n const effect = new this();\n effect.annotations = new Map();\n for (const group of record.annotations)\n {\n const parameterName = recordText(group.name);\n if (effect.annotations.has(parameterName))\n {\n throw new Error(\n `Carbon effect annotation group \"${parameterName}\" is duplicated`\n );\n }\n effect.annotations.set(\n parameterName,\n group.annotations.map(\n entry => Tr2EffectParameterAnnotation.fromCarbonBinary(entry)\n )\n );\n }\n effect.techniques = record.techniques.map(\n entry => Tr2EffectTechnique.fromCarbonBinary(entry)\n );\n return effect;\n }\n\n\n /**\n * Emit this description as a Carbon v15 record tree.\n *\n * Effect-level annotation groups are sorted by parameter name, and each\n * group's annotations by their own name, because Carbon sorts both by `strcmp`\n * before writing.\n *\n * @returns {object} Carbon effect description record.\n */\n toCarbonBinary()\n {\n return {\n techniques: this.techniques.map(technique => technique.toCarbonBinary()),\n annotations: Array.from(this.annotations, ([ name, annotations ]) => ({\n name: toRecordText(name),\n annotations: annotations\n .map(entry => entry.toCarbonBinary())\n .sort((left, right) => compareUtf8(left.name.value, right.name.value))\n })).sort((left, right) => compareUtf8(left.name.value, right.name.value))\n };\n }\n}\n\n// Declared imperatively rather than with decorators, so this module stays\n// plain ESM that loads from source without a transform. The decorator\n// expressions are reused verbatim, so the registered metadata is identical.\n// Statics belong in `methods`: decorateMethod targets the prototype and\n// would register a static as an instance field.\nCjsSchema.define(Tr2EffectDescription, {\n className: \"Tr2EffectDescription\",\n family: \"shader\",\n fields: {\n techniques: type.list(\"Tr2EffectTechnique\"),\n annotations: type.map(\"Tr2EffectParameterAnnotationMap\")\n }\n});\n"],"names":["Tr2EffectDescription","CjsModel","techniques","annotations","Map","from","values","options","normalized","Object","hasOwn","entries","parameterName","records","Array","isArray","TypeError","set","String","map","record","Tr2EffectParameterAnnotation","effect","fromCarbonBinary","isPlainObject","group","recordText","name","has","Error","entry","Tr2EffectTechnique","toCarbonBinary","technique","toRecordText","sort","left","right","compareUtf8","value","CjsSchema","define","className","family","fields","type","list"],"mappings":";;;;;;;;AAAA;AACA;;AASA;AACO,MAAMA,oBAAoB,SAASC,QAAQ,CAClD;AAEE;AACAC,EAAAA,UAAU,GAAG,EAAE;;AAEf;AACAC,EAAAA,WAAW,GAAG,IAAIC,GAAG,EAAE;;AAEvB;AACF;AACA;AACA;AACA;AACA;AACA;EACE,OAAOC,IAAIA,CAACC,MAAM,GAAG,EAAE,EAAEC,OAAO,GAAG,EAAE,EACrC;IACE,IAAIC,UAAU,GAAGF,MAAM;IACvB,IAAIH,WAAW,GAAG,IAAI;IACtB,IAAIG,MAAM,IAAIG,MAAM,CAACC,MAAM,CAACJ,MAAM,EAAE,aAAa,CAAC,EAClD;MACE,MAAMK,OAAO,GAAGL,MAAM,CAACH,WAAW,YAAYC,GAAG,GAC7CE,MAAM,CAACH,WAAW,GAClBM,MAAM,CAACE,OAAO,CAACL,MAAM,CAACH,WAAW,IAAI,EAAE,CAAC;AAC5CA,MAAAA,WAAW,GAAG,IAAIC,GAAG,EAAE;MACvB,KAAK,MAAM,CAAEQ,aAAa,EAAEC,OAAO,CAAE,IAAIF,OAAO,EAChD;AACE,QAAA,IAAI,CAACG,KAAK,CAACC,OAAO,CAACF,OAAO,CAAC,EAC3B;AACE,UAAA,MAAM,IAAIG,SAAS,CACjB,CAAA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N1C,IAAAA,UAAU,EAAE2C,IAAI,CAACC,IAAI,CAAC,oBAAoB,CAAC;AAC3C3C,IAAAA,WAAW,EAAE0C,IAAI,CAAC1B,GAAG,CAAC,iCAAiC;AACzD;AACF,CAAC,CAAC;;;;"}
@@ -1,8 +1,9 @@
1
1
  import { CjsSchema, impl, type } from '@carbonenginejs/runtime-utils/schema';
2
2
  import { CjsModel } from '@carbonenginejs/runtime-utils/model';
3
- import { isPlainObject, isArray, isUint32 } from '@carbonenginejs/runtime-utils/is';
4
- import { clonePortableSourceProgram } from '../portable.js';
3
+ import { isPlainObject } from '@carbonenginejs/runtime-utils/is';
4
+ import { copyBytes } from '@carbonenginejs/runtime-utils/bytes';
5
5
  import { Tr2EffectStageInput } from './Tr2EffectStageInput.js';
6
+ import { recordText, recordBytes, toRecordText, toRecordBlob } from './carbonRecordFields.js';
6
7
 
7
8
  // Source: trinity/trinity/Shader/Tr2EffectDescription.h
8
9
 
@@ -74,36 +75,27 @@ class Tr2EffectLibrary extends CjsModel {
74
75
  }
75
76
 
76
77
  /**
77
- * Build one shader library from its portable JSON reflection record.
78
+ * Build one raytracing library from its Carbon v15 description record.
78
79
  *
79
- * @param {object} value Portable library record.
80
+ * A library carries two `StageData` blocks of its own — a global and a local
81
+ * input — which are the same block a stage carries, minus the stage wrapper.
82
+ *
83
+ * @param {object} record Carbon library record.
80
84
  * @returns {Tr2EffectLibrary} Reflected library.
81
85
  */
82
- static fromPortable(value) {
83
- if (!isPlainObject(value)) {
84
- throw new TypeError("Portable effect library must be an object");
85
- }
86
- if (!isArray(value.exports)) {
87
- throw new TypeError("Portable effect library exports must be an array");
88
- }
89
- if (value.exportCount !== value.exports.length) {
90
- throw new Error("Portable effect library export count disagrees with its collection");
86
+ static fromCarbonBinary(record) {
87
+ if (!isPlainObject(record)) {
88
+ throw new TypeError("Carbon effect library record must be an object");
91
89
  }
92
90
  const library = new this();
93
- if (!isUint32(value.payloadSize)) {
94
- throw new RangeError("Portable effect library payload size must fit uint32");
95
- }
96
- library.payloadSize = value.payloadSize;
97
- library.hitGroupName = String(value.hitGroupName ?? "");
98
- library.exports = value.exports.map(entry => {
99
- if (!isUint32(entry?.type)) {
100
- throw new RangeError("Portable effect library export type must fit uint32");
101
- }
102
- return {
103
- type: entry.type,
104
- name: String(entry?.name ?? "")
105
- };
106
- });
91
+ library.payloadSize = record.payloadSize;
92
+ library.hitGroupName = recordText(record.hitGroupName);
93
+ library.exports = record.exports.map(entry => ({
94
+ type: entry.type,
95
+ name: recordText(entry.name)
96
+ }));
97
+ // The export type is the only thing that names an entry point; the record
98
+ // stores a flat list and the named fields are a view onto it.
107
99
  for (const entry of library.exports) {
108
100
  if (entry.type === 0) library.rayGenName = entry.name;
109
101
  if (entry.type === 1) library.missName = entry.name;
@@ -111,11 +103,40 @@ class Tr2EffectLibrary extends CjsModel {
111
103
  if (entry.type === 3) library.anyHitName = entry.name;
112
104
  if (entry.type === 4) library.intersectionName = entry.name;
113
105
  }
114
- library.sourceProgram = clonePortableSourceProgram(value.sourceProgram, "library");
115
- library.globalInput = Tr2EffectStageInput.fromPortableInput(value.globalInput);
116
- library.localInput = Tr2EffectStageInput.fromPortableInput(value.localInput);
106
+ library.sourceProgram = {
107
+ kind: "library",
108
+ bytes: copyBytes(recordBytes(record.shaderData)),
109
+ shaderSize: record.shaderData.size,
110
+ // See Tr2EffectStageInput: only a zero-size blob's word is portable.
111
+ unsetOffset: record.shaderData.size === 0 ? record.shaderData.offset : 0xffffffff
112
+ };
113
+ library.globalInput = Tr2EffectStageInput.fromCarbonBinaryInput(record.globalInputs);
114
+ library.localInput = Tr2EffectStageInput.fromCarbonBinaryInput(record.localInputs);
117
115
  return library;
118
116
  }
117
+
118
+ /**
119
+ * Emit this library as a Carbon v15 record.
120
+ *
121
+ * `exports` is authoritative; the named entry-point fields are a view onto it
122
+ * and are not written separately.
123
+ *
124
+ * @returns {object} Carbon library record.
125
+ */
126
+ toCarbonBinary() {
127
+ const program = this.sourceProgram ?? {};
128
+ return {
129
+ payloadSize: this.payloadSize >>> 0,
130
+ shaderData: toRecordBlob(program.bytes, program.shaderSize, program.unsetOffset),
131
+ exports: this.exports.map(entry => ({
132
+ type: entry.type,
133
+ name: toRecordText(entry.name)
134
+ })),
135
+ hitGroupName: toRecordText(this.hitGroupName),
136
+ globalInputs: this.globalInput.toCarbonBinaryInput(),
137
+ localInputs: this.localInput.toCarbonBinaryInput()
138
+ };
139
+ }
119
140
  }
120
141
 
121
142
  // Declared imperatively rather than with decorators, so this module stays