@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,16 +1,13 @@
1
1
  import { CjsSchema, carbon, impl } from '@carbonenginejs/runtime-utils/schema';
2
2
  import { CjsResource } from '../CjsResource.js';
3
3
  import { validateResourcePayload } from '../resourceBoundary.js';
4
+ import { CjsCarbonEffectReader } from '../../format/carbonEffect/CjsCarbonEffectReader.js';
4
5
  import { Tr2Shader } from './Tr2Shader.js';
5
6
 
6
7
  // Source: trinity/trinity/Resources/Tr2EffectRes.h
7
8
  // Source: trinity/trinity/Resources/Tr2EffectRes.cpp
8
9
  // Source: trinity/trinity/Resources/Tr2EffectRes_Blue.cpp
9
10
  const globalEffectOptions = [];
10
- const SHA256 = /^[0-9a-f]{64}$/u;
11
- const UINT8_MAX = 0xff;
12
- const UINT32_MAX = 0xffffffff;
13
- const MAX_EFFECT_PERMUTATIONS = 0x10000;
14
11
 
15
12
  /**
16
13
  * Tr2EffectRes resource record.
@@ -20,6 +17,47 @@ const MAX_EFFECT_PERMUTATIONS = 0x10000;
20
17
  */
21
18
  class Tr2EffectRes extends CjsResource {
22
19
  #shaders = new Map();
20
+ #reader = null;
21
+
22
+ /**
23
+ * Read a Carbon effect container and take ownership of its reader.
24
+ *
25
+ * Carbon's `DoLoad` (`Tr2EffectRes.cpp:137`) does exactly this work: it clears
26
+ * the previous state, then fills `m_version`, the string table, the permutation
27
+ * axes and the offset table from the file, and stops there. Bodies are read
28
+ * later, one at a time, by `GetShader`. The one difference is where the bytes
29
+ * come from — Carbon locks its own data stream, and this takes them as an
30
+ * argument.
31
+ *
32
+ * The container is parsed once, here: version, arena, permutation axes and
33
+ * offset table. Bodies are not. Each one is decoded on first request and
34
+ * memoised, by seeking the retained reader rather than re-reading the header —
35
+ * a container with 512 permutations that renders two of them parses two bodies.
36
+ *
37
+ * The reader is retained rather than discarded because a body cannot be read
38
+ * without it: strings are offsets into the container's arena, which lives in
39
+ * the header this method consumed.
40
+ *
41
+ * @param {ArrayBuffer|ArrayBufferView|Uint8Array} data Container bytes.
42
+ * @param {object|null} options Model values applied after the read.
43
+ * @returns {Tr2EffectRes}
44
+ */
45
+ DoLoad(data, options = null) {
46
+ const reader = new CjsCarbonEffectReader(data);
47
+ this.#shaders.clear();
48
+ this.#reader = reader;
49
+ super.SetPayload({
50
+ permutations: reader.permutations.map(axis => ({
51
+ name: axis.name.value,
52
+ options: axis.options.map(option => option.value),
53
+ defaultOption: axis.defaultOption,
54
+ description: axis.description.value,
55
+ type: axis.type
56
+ }))
57
+ });
58
+ this.SetValues(options || {});
59
+ return this;
60
+ }
23
61
 
24
62
  /** Creates a Tr2EffectRes with caller-provided initial state. */
25
63
  constructor(values = null) {
@@ -41,11 +79,13 @@ class Tr2EffectRes extends CjsResource {
41
79
  SetPayload(payload = null, options = null) {
42
80
  if (payload === null) {
43
81
  this.#shaders.clear();
82
+ this.#reader = null;
44
83
  super.SetPayload(null);
45
84
  return this;
46
85
  }
47
86
  validateResourcePayload("Tr2EffectRes", payload, validateEffectPayload);
48
87
  this.#shaders.clear();
88
+ this.#reader = null;
49
89
  super.SetPayload(payload);
50
90
  this.SetValues(options || {});
51
91
  return this;
@@ -53,7 +93,7 @@ class Tr2EffectRes extends CjsResource {
53
93
 
54
94
  /**
55
95
  * Select and hydrate one canonical shader from the complete permutation
56
- * graph exposed by a CEWG/CEWGPU raw package.
96
+ * graph exposed by a Carbon WebGL/Carbon WebGPU raw package.
57
97
  *
58
98
  * Global options have Carbon-compatible precedence over caller options.
59
99
  * Unknown option values retain the authored default.
@@ -64,10 +104,6 @@ class Tr2EffectRes extends CjsResource {
64
104
  */
65
105
  GetShader(options = [], count = null) {
66
106
  const axes = getPermutationAxes(this.GetPayload());
67
- if (!axes.length) {
68
- const portableIndex = Tr2Shader.isPortableReflection(this.GetPayload()) ? this.GetPayload().permutationIndex : 0;
69
- return this.GetShaderByIndex(portableIndex);
70
- }
71
107
  const localOptions = normalizeShaderOptions(options);
72
108
  const localCount = Number.isSafeInteger(count) ? Math.max(0, Math.min(count, localOptions.length)) : localOptions.length;
73
109
  let multiplier = 1;
@@ -117,14 +153,10 @@ class Tr2EffectRes extends CjsResource {
117
153
  if (variantCount !== null && index >= variantCount) {
118
154
  return null;
119
155
  }
120
- const portable = getPortableReflection(payload, index);
121
- if (!portable) {
156
+ if (!this.#reader) {
122
157
  return null;
123
158
  }
124
- if (portable.permutationIndex !== index) {
125
- throw new Error(`Portable effect reflection index ${portable.permutationIndex} does not match requested index ${index}`);
126
- }
127
- const shader = Tr2Shader.fromPortable(portable);
159
+ const shader = Tr2Shader.fromCarbonBinary(this.#reader, index);
128
160
  this.#shaders.set(index, shader);
129
161
  return shader;
130
162
  }
@@ -161,200 +193,49 @@ class Tr2EffectRes extends CjsResource {
161
193
  /** Release the payload and every shader graph hydrated from it. */
162
194
  ReleasePayload() {
163
195
  this.#shaders.clear();
196
+ this.#reader = null;
164
197
  return super.ReleasePayload();
165
198
  }
166
199
  static payload = "shader";
167
200
  }
168
201
 
169
202
  /**
170
- * Merge Carbon-style global effect option overrides.
203
+ * Validate an attached permutation payload.
171
204
  *
172
- * An empty value removes the override. Existing Tr2EffectRes shader caches
173
- * remain valid objects; callers rebuild effects to request the new selection.
205
+ * Carbon has no equivalent: it fills `m_permutations` from the file and never
206
+ * accepts one from a caller. This exists only so an attached payload cannot
207
+ * silently produce a wrong permutation index, and it checks the one thing the
208
+ * index arithmetic depends on - that every axis has options and a default that
209
+ * addresses one of them.
174
210
  *
175
- * @param {Array<object>|Map<string,string>} changes Option changes.
211
+ * @param {object} payload Attached payload.
176
212
  */
177
- function ModifyGlobalEffectOptions(changes = []) {
178
- for (const change of normalizeShaderOptions(changes)) {
179
- const index = globalEffectOptions.findIndex(option => option.name === change.name);
180
- if (!change.value) {
181
- if (index >= 0) {
182
- globalEffectOptions.splice(index, 1);
183
- }
184
- } else if (index >= 0) {
185
- globalEffectOptions[index] = change;
186
- } else {
187
- globalEffectOptions.push(change);
188
- }
213
+ function validateEffectPayload(payload) {
214
+ if (!Array.isArray(payload.permutations)) {
215
+ throw new TypeError("Tr2EffectRes payload requires a permutations array");
189
216
  }
217
+ payload.permutations.forEach(normalizePermutationAxis);
190
218
  }
191
219
 
192
220
  /**
193
- * Return an owned snapshot of the current global option overrides.
221
+ * The permutation axes an attached payload declares.
194
222
  *
195
- * @returns {Array<{name:string,value:string}>} Global option choices.
223
+ * @param {object|null} payload Attached payload.
224
+ * @returns {Array<object>} Normalized axes, empty when there are none.
196
225
  */
197
- function GetGlobalEffectOptions() {
198
- return globalEffectOptions.map(option => ({
199
- ...option
200
- }));
201
- }
202
- function validateEffectPayload(payload) {
203
- const graph = payload.permutationGraph;
204
- if (graph !== null && graph !== undefined) {
205
- validatePermutationGraph(graph);
206
- } else if (Array.isArray(payload.permutations)) {
207
- if (payload.permutations.every(permutation => Array.isArray(permutation?.options))) {
208
- payload.permutations.forEach(normalizePermutationAxis);
209
- } else {
210
- validateLegacyPermutationDescription(payload.permutations);
211
- }
212
- } else if (!Tr2Shader.isPortableReflection(payload)) {
213
- throw new TypeError("Tr2EffectRes payload requires a complete permutation graph, permutations array, or one portable reflection");
214
- }
215
- if (Array.isArray(payload.portableReflections)) {
216
- const expectedCount = getPermutationVariantCount(payload);
217
- if (expectedCount !== null && payload.portableReflections.length !== expectedCount) {
218
- throw new Error("Tr2EffectRes portable reflection count disagrees with its permutations");
219
- }
220
- payload.portableReflections.forEach((reflection, index) => {
221
- if (!Tr2Shader.isPortableReflection(reflection) || reflection.permutationIndex !== index) {
222
- throw new Error(`Tr2EffectRes portable reflection ${index} is malformed`);
223
- }
224
- });
225
- }
226
- }
227
- function validateLegacyPermutationDescription(permutations) {
228
- for (const [index, permutation] of permutations.entries()) {
229
- if (!permutation || typeof permutation !== "object" || Array.isArray(permutation) || typeof permutation.name !== "string" || !permutation.name) {
230
- throw new TypeError(`Tr2EffectRes legacy permutation ${index} is malformed`);
231
- }
232
- }
233
- }
234
- function validatePermutationGraph(graph) {
235
- if (!graph || typeof graph !== "object" || Array.isArray(graph) || graph.format !== "CJS_EFFECT_PERMUTATION_GRAPH" || graph.formatVersion !== 1 || !graph.coverage || typeof graph.coverage !== "object" || Array.isArray(graph.coverage) || graph.coverage.permutations !== "complete" || graph.coverage.bodies !== "identity-only" || graph.coverage.reflection !== "absent" || !Array.isArray(graph.axes) || !Array.isArray(graph.variants) || !Array.isArray(graph.bodies)) {
236
- throw new TypeError("Tr2EffectRes requires CJS_EFFECT_PERMUTATION_GRAPH version 1");
237
- }
238
- const axisNames = new Set();
239
- const axes = graph.axes.map((axis, index) => validatePermutationAxis(axis, index, axisNames));
240
- const expectedCount = getPermutationProduct(axes);
241
- if (graph.variants.length !== expectedCount || !graph.bodies.length || graph.bodies.length > graph.variants.length) {
242
- throw new Error("Tr2EffectRes permutation graph requires complete variants and bodies");
243
- }
244
- const bodies = new Map();
245
- const bodyDigests = new Set();
246
- graph.bodies.forEach((body, bodyIndex) => {
247
- if (!body || typeof body !== "object" || Array.isArray(body) || typeof body.key !== "string" || !body.key || body.key !== body.key.trim() || !Number.isSafeInteger(body.byteLength) || body.byteLength < 1 || body.byteLength > UINT32_MAX || typeof body.sha256 !== "string" || !SHA256.test(body.sha256) || bodies.has(body.key) || bodyDigests.has(body.sha256)) {
248
- throw new Error(`Tr2EffectRes permutation body ${bodyIndex} is malformed or duplicated`);
249
- }
250
- bodyDigests.add(body.sha256);
251
- bodies.set(body.key, {
252
- byteLength: body.byteLength,
253
- references: 0
254
- });
255
- });
256
- const bodyKeyBySourceRecord = new Map();
257
- const sourceRecords = [];
258
- graph.variants.forEach((variant, permutationIndex) => {
259
- const expectedOptions = decodePermutationOptions(permutationIndex, axes);
260
- if (!variant || typeof variant !== "object" || Array.isArray(variant) || variant.permutationIndex !== permutationIndex || !Array.isArray(variant.optionIndices) || variant.optionIndices.length !== expectedOptions.length || variant.optionIndices.some((value, index) => value !== expectedOptions[index]) || typeof variant.bodyKey !== "string" || !bodies.has(variant.bodyKey)) {
261
- throw new Error(`Tr2EffectRes permutation variant ${permutationIndex} is malformed`);
262
- }
263
- const sourceRecord = validatePermutationSourceRecord(variant.sourceRecord, permutationIndex);
264
- const body = bodies.get(variant.bodyKey);
265
- if (sourceRecord.byteLength !== body.byteLength) {
266
- throw new Error(`Tr2EffectRes permutation variant ${permutationIndex} body length disagrees`);
267
- }
268
- const recordKey = `${sourceRecord.offset}:${sourceRecord.byteLength}`;
269
- const existingBodyKey = bodyKeyBySourceRecord.get(recordKey);
270
- if (existingBodyKey && existingBodyKey !== variant.bodyKey) {
271
- throw new Error(`Tr2EffectRes source record ${recordKey} maps to multiple bodies`);
272
- }
273
- bodyKeyBySourceRecord.set(recordKey, variant.bodyKey);
274
- sourceRecords.push(sourceRecord);
275
- body.references += 1;
276
- });
277
- validateDisjointPermutationRecords(sourceRecords);
278
- for (const [bodyKey, body] of bodies) {
279
- if (!body.references) {
280
- throw new Error(`Tr2EffectRes permutation body ${bodyKey} is unreferenced`);
281
- }
282
- }
283
- }
284
- function validatePermutationAxis(axis, index, names) {
285
- if (!axis || typeof axis !== "object" || Array.isArray(axis) || axis.index !== index || typeof axis.name !== "string" || !axis.name || axis.name !== axis.name.trim() || names.has(axis.name) || !Array.isArray(axis.options) || !axis.options.length || axis.options.length > UINT8_MAX || !Number.isSafeInteger(axis.defaultOption) || axis.defaultOption < 0 || axis.defaultOption >= axis.options.length || typeof axis.description !== "string" || !Number.isSafeInteger(axis.type) || axis.type < 0 || axis.type > UINT8_MAX) {
286
- throw new Error(`Tr2EffectRes permutation axis ${index} is malformed or duplicated`);
287
- }
288
- names.add(axis.name);
289
- const options = new Set();
290
- for (const option of axis.options) {
291
- if (typeof option !== "string" || !option || option !== option.trim() || options.has(option)) {
292
- throw new Error(`Tr2EffectRes permutation axis ${index} options are malformed`);
293
- }
294
- options.add(option);
295
- }
296
- return normalizePermutationAxis(axis);
297
- }
298
- function getPermutationProduct(axes) {
299
- let product = 1;
300
- for (const axis of axes) {
301
- product *= axis.options.length;
302
- if (!Number.isSafeInteger(product) || product < 1 || product > MAX_EFFECT_PERMUTATIONS) {
303
- throw new Error("Tr2EffectRes permutation count exceeds the implementation limit");
304
- }
305
- }
306
- return product;
307
- }
308
- function decodePermutationOptions(permutationIndex, axes) {
309
- let value = permutationIndex;
310
- return axes.map(axis => {
311
- const optionIndex = value % axis.options.length;
312
- value = Math.floor(value / axis.options.length);
313
- return optionIndex;
314
- });
315
- }
316
- function validatePermutationSourceRecord(record, permutationIndex) {
317
- const offset = record?.offset;
318
- const byteLength = record?.byteLength;
319
- const end = offset + byteLength;
320
- if (!record || typeof record !== "object" || Array.isArray(record) || !Number.isSafeInteger(offset) || offset < 0 || offset > UINT32_MAX || !Number.isSafeInteger(byteLength) || byteLength < 1 || byteLength > UINT32_MAX || !Number.isSafeInteger(end) || end > UINT32_MAX + 1) {
321
- throw new Error(`Tr2EffectRes permutation variant ${permutationIndex} source record is malformed`);
322
- }
323
- return {
324
- offset,
325
- byteLength
326
- };
327
- }
328
- function validateDisjointPermutationRecords(records) {
329
- const unique = new Map();
330
- for (const record of records) {
331
- const key = `${record.offset}:${record.byteLength}`;
332
- if (!unique.has(key)) {
333
- unique.set(key, {
334
- offset: record.offset,
335
- end: record.offset + record.byteLength
336
- });
337
- }
338
- }
339
- const ordered = Array.from(unique.values()).sort((left, right) => left.offset - right.offset || left.end - right.end);
340
- for (let index = 1; index < ordered.length; index += 1) {
341
- if (ordered[index].offset < ordered[index - 1].end) {
342
- throw new Error("Tr2EffectRes permutation source body records partially overlap");
343
- }
344
- }
345
- }
346
226
  function getPermutationAxes(payload) {
347
- if (!payload) {
227
+ if (!Array.isArray(payload?.permutations)) {
348
228
  return [];
349
229
  }
350
- if (payload.permutationGraph) {
351
- return payload.permutationGraph.axes.map(normalizePermutationAxis);
352
- }
353
- if (Array.isArray(payload.permutations) && payload.permutations.every(permutation => Array.isArray(permutation?.options))) {
354
- return payload.permutations.map(normalizePermutationAxis);
355
- }
356
- return [];
230
+ return payload.permutations.map(normalizePermutationAxis);
357
231
  }
232
+
233
+ /**
234
+ * Normalize and validate one permutation axis.
235
+ *
236
+ * @param {object} axis Candidate axis.
237
+ * @returns {object} Owned, validated axis.
238
+ */
358
239
  function normalizePermutationAxis(axis) {
359
240
  if (!axis || typeof axis !== "object" || Array.isArray(axis) || typeof axis.name !== "string" || !axis.name || !Array.isArray(axis.options) || !axis.options.length || axis.options.some(option => typeof option !== "string" || !option) || !Number.isSafeInteger(axis.defaultOption) || axis.defaultOption < 0 || axis.defaultOption >= axis.options.length) {
360
241
  throw new TypeError("Tr2EffectRes permutation axis is malformed");
@@ -367,33 +248,57 @@ function normalizePermutationAxis(axis) {
367
248
  type: Number(axis.type ?? 0)
368
249
  };
369
250
  }
251
+
252
+ /**
253
+ * The number of permutations the axes describe - the product of their option
254
+ * counts, which is also the number of offset-table rows a dense container has.
255
+ *
256
+ * @param {object|null} payload Attached payload.
257
+ * @returns {number|null} Permutation count, or null when no axes are declared.
258
+ */
370
259
  function getPermutationVariantCount(payload) {
371
- if (Array.isArray(payload?.permutationGraph?.variants)) {
372
- return payload.permutationGraph.variants.length;
373
- }
374
260
  const axes = getPermutationAxes(payload);
375
- if (axes.length) {
376
- return axes.reduce((count, axis) => count * axis.options.length, 1);
377
- }
378
- return null;
379
- }
380
- function getPortableReflection(payload, index) {
381
- if (!payload) {
261
+ if (!axes.length) {
382
262
  return null;
383
263
  }
384
- if (typeof payload.GetPortableEffectReflection === "function") {
385
- return payload.GetPortableEffectReflection(index);
386
- }
387
- if (typeof payload.getPortableEffectReflection === "function") {
388
- return payload.getPortableEffectReflection(index);
389
- }
390
- if (Tr2Shader.isPortableReflection(payload)) {
391
- return index === payload.permutationIndex ? payload : null;
392
- }
393
- if (Array.isArray(payload.portableReflections)) {
394
- return payload.portableReflections[index] ?? null;
264
+ return axes.reduce((count, axis) => count * axis.options.length, 1);
265
+ }
266
+
267
+ /**
268
+ * Return an owned snapshot of the current global option overrides.
269
+ *
270
+ * Carbon returns a const reference to the live vector; a JS caller cannot be
271
+ * held to that, so this copies rather than exposing the array for mutation.
272
+ *
273
+ * @returns {Array<{name:string,value:string}>} Global option choices.
274
+ */
275
+ function GetGlobalEffectOptions() {
276
+ return globalEffectOptions.map(option => ({
277
+ ...option
278
+ }));
279
+ }
280
+
281
+ /**
282
+ * Merge Carbon-style global effect option overrides.
283
+ *
284
+ * An empty value removes the override. Existing Tr2EffectRes shader caches
285
+ * remain valid objects; callers rebuild effects to request the new selection.
286
+ *
287
+ * @param {Array<object>|Map<string,string>} changes Option changes.
288
+ */
289
+ function ModifyGlobalEffectOptions(changes = []) {
290
+ for (const change of normalizeShaderOptions(changes)) {
291
+ const index = globalEffectOptions.findIndex(option => option.name === change.name);
292
+ if (!change.value) {
293
+ if (index >= 0) {
294
+ globalEffectOptions.splice(index, 1);
295
+ }
296
+ } else if (index >= 0) {
297
+ globalEffectOptions[index] = change;
298
+ } else {
299
+ globalEffectOptions.push(change);
300
+ }
395
301
  }
396
- return null;
397
302
  }
398
303
  function normalizeShaderOptions(options) {
399
304
  if (options instanceof Map) {
@@ -420,7 +325,7 @@ CjsSchema.define(Tr2EffectRes, {
420
325
  className: "Tr2EffectRes",
421
326
  family: "resources",
422
327
  methods: {
423
- GetShader: [carbon.method, impl.adapted, impl.reason("Carbon reads the selected body directly from compiled effect bytes and registers renderer handles; CarbonEngineJS hydrates the format package's validated portable reflection without realizing GPU state.")],
328
+ GetShader: [carbon.method, impl.adapted, impl.reason("Carbon reads the selected body from the compiled effect bytes and registers renderer handles; CarbonEngineJS reads the same bytes and stops at the device-free graph, leaving GPU realization to the engine.")],
424
329
  GetShaderByIndex: [impl.custom, impl.reason("Carbon selects compiled bodies through GetShader; CarbonEngineJS exposes exact package-index hydration for deterministic package consumers and tests.")],
425
330
  GetPermutationDescription: [carbon.method, impl.adapted, impl.reason("Carbon exposes a Python tuple through Blue; CarbonEngineJS returns a JSON-friendly plain axis description.")],
426
331
  ReleaseResources: [carbon.method, impl.adapted, impl.reason("Backend resources are engine-owned; the resource-side release clears only hydrated device-free shader graphs.")]
@@ -1 +1 @@
1
- {"version":3,"file":"Tr2EffectRes.js","sources":["../../../../src/resource/shader/Tr2EffectRes.js"],"sourcesContent":["// Source: trinity/trinity/Resources/Tr2EffectRes.h\n// Source: trinity/trinity/Resources/Tr2EffectRes.cpp\n// Source: trinity/trinity/Resources/Tr2EffectRes_Blue.cpp\nimport { CjsSchema, carbon, impl, type } from \"@carbonenginejs/runtime-utils/schema\";\nimport { CjsResource } from \"../CjsResource.js\";\nimport { validateResourcePayload } from \"../resourceBoundary.js\";\nimport { Tr2Shader } from \"./Tr2Shader.js\";\n\nconst globalEffectOptions = [];\nconst SHA256 = /^[0-9a-f]{64}$/u;\nconst UINT8_MAX = 0xff;\nconst UINT32_MAX = 0xffffffff;\nconst MAX_EFFECT_PERMUTATIONS = 0x10000;\n\n/**\n * Tr2EffectRes resource record.\n *\n * This stores effect/shader payload facts. Engine-gpu decides shader module,\n * pipeline, bind group, and sampler realization.\n */\nexport class Tr2EffectRes extends CjsResource\n{\n\n #shaders = new Map();\n\n /** Creates a Tr2EffectRes with caller-provided initial state. */\n constructor(values = null)\n {\n super();\n this.SetValues(values || {}, {\n markDirty: false,\n skipUpdate: true,\n skipEvents: true\n });\n }\n\n /**\n * Attach a plain shader/effect payload.\n *\n * @param {object|null} payload\n * @param {object|null} options\n * @returns {Tr2EffectRes}\n */\n SetPayload(payload = null, options = null)\n {\n if (payload === null)\n {\n this.#shaders.clear();\n super.SetPayload(null);\n return this;\n }\n validateResourcePayload(\n \"Tr2EffectRes\",\n payload,\n validateEffectPayload\n );\n this.#shaders.clear();\n super.SetPayload(payload);\n this.SetValues(options || {});\n return this;\n }\n\n /**\n * Select and hydrate one canonical shader from the complete permutation\n * graph exposed by a CEWG/CEWGPU raw package.\n *\n * Global options have Carbon-compatible precedence over caller options.\n * Unknown option values retain the authored default.\n *\n * @param {Array<object>|Map<string,string>} options Local name/value choices.\n * @param {number|null} count Number of local entries to consider.\n * @returns {Tr2Shader|null} Selected device-free shader reflection.\n */\n GetShader(options = [], count = null)\n {\n const axes = getPermutationAxes(this.GetPayload());\n if (!axes.length)\n {\n const portableIndex = Tr2Shader.isPortableReflection(this.GetPayload())\n ? this.GetPayload().permutationIndex\n : 0;\n return this.GetShaderByIndex(portableIndex);\n }\n const localOptions = normalizeShaderOptions(options);\n const localCount = Number.isSafeInteger(count)\n ? Math.max(0, Math.min(count, localOptions.length))\n : localOptions.length;\n let multiplier = 1;\n let index = 0;\n\n for (const axis of axes)\n {\n let selectedIndex = axis.defaultOption;\n const globalOption = globalEffectOptions.find(\n option => option.name === axis.name\n );\n if (globalOption)\n {\n const requestedIndex = axis.options.indexOf(globalOption.value);\n if (requestedIndex >= 0)\n {\n selectedIndex = requestedIndex;\n }\n }\n else\n {\n for (let optionIndex = 0; optionIndex < localCount; optionIndex += 1)\n {\n const localOption = localOptions[optionIndex];\n if (localOption.name !== axis.name)\n {\n continue;\n }\n const requestedIndex = axis.options.indexOf(localOption.value);\n if (requestedIndex >= 0)\n {\n selectedIndex = requestedIndex;\n }\n }\n }\n\n index += selectedIndex * multiplier;\n multiplier *= axis.options.length;\n }\n\n return this.GetShaderByIndex(index);\n }\n\n /**\n * Hydrate one exact permutation-table index and cache the resulting runtime\n * graph for this payload.\n *\n * @param {number} index Exact permutation index.\n * @returns {Tr2Shader|null} Canonical shader or null when reflection is absent.\n */\n GetShaderByIndex(index)\n {\n if (!Number.isSafeInteger(index) || index < 0)\n {\n throw new TypeError(\n \"Tr2EffectRes shader index must be a non-negative safe integer\"\n );\n }\n if (this.#shaders.has(index))\n {\n return this.#shaders.get(index);\n }\n\n const payload = this.GetPayload();\n const variantCount = getPermutationVariantCount(payload);\n if (variantCount !== null && index >= variantCount)\n {\n return null;\n }\n\n const portable = getPortableReflection(payload, index);\n if (!portable)\n {\n return null;\n }\n if (portable.permutationIndex !== index)\n {\n throw new Error(\n `Portable effect reflection index ${portable.permutationIndex} does not match requested index ${index}`\n );\n }\n\n const shader = Tr2Shader.fromPortable(portable);\n this.#shaders.set(index, shader);\n return shader;\n }\n\n /**\n * Return a small JSON-friendly permutation description.\n *\n * @returns {Array<*>}\n */\n GetPermutationDescription()\n {\n const payload = this.GetPayload();\n const axes = getPermutationAxes(payload);\n if (!axes.length && Array.isArray(payload?.permutations))\n {\n return payload.permutations.map(permutation => ({ ...permutation }));\n }\n return axes.map(axis => ({\n name: axis.name,\n options: [ ...axis.options ],\n defaultOption: axis.defaultOption,\n description: axis.description,\n type: axis.type\n }));\n }\n\n /**\n * Drop hydrated shader graphs while retaining the validated CPU payload.\n */\n ReleaseResources()\n {\n this.#shaders.clear();\n }\n\n /** Release the payload and every shader graph hydrated from it. */\n ReleasePayload()\n {\n this.#shaders.clear();\n return super.ReleasePayload();\n }\n\n static payload = \"shader\";\n\n}\n\n/**\n * Merge Carbon-style global effect option overrides.\n *\n * An empty value removes the override. Existing Tr2EffectRes shader caches\n * remain valid objects; callers rebuild effects to request the new selection.\n *\n * @param {Array<object>|Map<string,string>} changes Option changes.\n */\nexport function ModifyGlobalEffectOptions(changes = [])\n{\n for (const change of normalizeShaderOptions(changes))\n {\n const index = globalEffectOptions.findIndex(\n option => option.name === change.name\n );\n if (!change.value)\n {\n if (index >= 0)\n {\n globalEffectOptions.splice(index, 1);\n }\n }\n else if (index >= 0)\n {\n globalEffectOptions[index] = change;\n }\n else\n {\n globalEffectOptions.push(change);\n }\n }\n}\n\n/**\n * Return an owned snapshot of the current global option overrides.\n *\n * @returns {Array<{name:string,value:string}>} Global option choices.\n */\nexport function GetGlobalEffectOptions()\n{\n return globalEffectOptions.map(option => ({ ...option }));\n}\n\nfunction validateEffectPayload(payload)\n{\n const graph = payload.permutationGraph;\n if (graph !== null && graph !== undefined)\n {\n validatePermutationGraph(graph);\n }\n else if (Array.isArray(payload.permutations))\n {\n if (payload.permutations.every(permutation =>\n Array.isArray(permutation?.options)))\n {\n payload.permutations.forEach(normalizePermutationAxis);\n }\n else\n {\n validateLegacyPermutationDescription(payload.permutations);\n }\n }\n else if (!Tr2Shader.isPortableReflection(payload))\n {\n throw new TypeError(\n \"Tr2EffectRes payload requires a complete permutation graph, permutations array, or one portable reflection\"\n );\n }\n\n if (Array.isArray(payload.portableReflections))\n {\n const expectedCount = getPermutationVariantCount(payload);\n if (expectedCount !== null\n && payload.portableReflections.length !== expectedCount)\n {\n throw new Error(\n \"Tr2EffectRes portable reflection count disagrees with its permutations\"\n );\n }\n payload.portableReflections.forEach((reflection, index) =>\n {\n if (!Tr2Shader.isPortableReflection(reflection)\n || reflection.permutationIndex !== index)\n {\n throw new Error(\n `Tr2EffectRes portable reflection ${index} is malformed`\n );\n }\n });\n }\n}\n\nfunction validateLegacyPermutationDescription(permutations)\n{\n for (const [ index, permutation ] of permutations.entries())\n {\n if (!permutation\n || typeof permutation !== \"object\"\n || Array.isArray(permutation)\n || typeof permutation.name !== \"string\"\n || !permutation.name)\n {\n throw new TypeError(\n `Tr2EffectRes legacy permutation ${index} is malformed`\n );\n }\n }\n}\n\nfunction validatePermutationGraph(graph)\n{\n if (!graph || typeof graph !== \"object\" || Array.isArray(graph)\n || graph.format !== \"CJS_EFFECT_PERMUTATION_GRAPH\"\n || graph.formatVersion !== 1\n || !graph.coverage || typeof graph.coverage !== \"object\"\n || Array.isArray(graph.coverage)\n || graph.coverage.permutations !== \"complete\"\n || graph.coverage.bodies !== \"identity-only\"\n || graph.coverage.reflection !== \"absent\"\n || !Array.isArray(graph.axes)\n || !Array.isArray(graph.variants)\n || !Array.isArray(graph.bodies))\n {\n throw new TypeError(\n \"Tr2EffectRes requires CJS_EFFECT_PERMUTATION_GRAPH version 1\"\n );\n }\n\n const axisNames = new Set();\n const axes = graph.axes.map((axis, index) =>\n validatePermutationAxis(axis, index, axisNames));\n const expectedCount = getPermutationProduct(axes);\n if (graph.variants.length !== expectedCount\n || !graph.bodies.length\n || graph.bodies.length > graph.variants.length)\n {\n throw new Error(\n \"Tr2EffectRes permutation graph requires complete variants and bodies\"\n );\n }\n\n const bodies = new Map();\n const bodyDigests = new Set();\n graph.bodies.forEach((body, bodyIndex) =>\n {\n if (!body || typeof body !== \"object\" || Array.isArray(body)\n || typeof body.key !== \"string\" || !body.key\n || body.key !== body.key.trim()\n || !Number.isSafeInteger(body.byteLength) || body.byteLength < 1\n || body.byteLength > UINT32_MAX\n || typeof body.sha256 !== \"string\" || !SHA256.test(body.sha256)\n || bodies.has(body.key)\n || bodyDigests.has(body.sha256))\n {\n throw new Error(\n `Tr2EffectRes permutation body ${bodyIndex} is malformed or duplicated`\n );\n }\n bodyDigests.add(body.sha256);\n bodies.set(body.key, {\n byteLength: body.byteLength,\n references: 0\n });\n });\n\n const bodyKeyBySourceRecord = new Map();\n const sourceRecords = [];\n graph.variants.forEach((variant, permutationIndex) =>\n {\n const expectedOptions = decodePermutationOptions(permutationIndex, axes);\n if (!variant || typeof variant !== \"object\" || Array.isArray(variant)\n || variant.permutationIndex !== permutationIndex\n || !Array.isArray(variant.optionIndices)\n || variant.optionIndices.length !== expectedOptions.length\n || variant.optionIndices.some((value, index) =>\n value !== expectedOptions[index])\n || typeof variant.bodyKey !== \"string\"\n || !bodies.has(variant.bodyKey))\n {\n throw new Error(\n `Tr2EffectRes permutation variant ${permutationIndex} is malformed`\n );\n }\n\n const sourceRecord = validatePermutationSourceRecord(\n variant.sourceRecord,\n permutationIndex\n );\n const body = bodies.get(variant.bodyKey);\n if (sourceRecord.byteLength !== body.byteLength)\n {\n throw new Error(\n `Tr2EffectRes permutation variant ${permutationIndex} body length disagrees`\n );\n }\n const recordKey = `${sourceRecord.offset}:${sourceRecord.byteLength}`;\n const existingBodyKey = bodyKeyBySourceRecord.get(recordKey);\n if (existingBodyKey && existingBodyKey !== variant.bodyKey)\n {\n throw new Error(\n `Tr2EffectRes source record ${recordKey} maps to multiple bodies`\n );\n }\n bodyKeyBySourceRecord.set(recordKey, variant.bodyKey);\n sourceRecords.push(sourceRecord);\n body.references += 1;\n });\n\n validateDisjointPermutationRecords(sourceRecords);\n for (const [ bodyKey, body ] of bodies)\n {\n if (!body.references)\n {\n throw new Error(\n `Tr2EffectRes permutation body ${bodyKey} is unreferenced`\n );\n }\n }\n}\n\nfunction validatePermutationAxis(axis, index, names)\n{\n if (!axis || typeof axis !== \"object\" || Array.isArray(axis)\n || axis.index !== index\n || typeof axis.name !== \"string\" || !axis.name\n || axis.name !== axis.name.trim() || names.has(axis.name)\n || !Array.isArray(axis.options) || !axis.options.length\n || axis.options.length > UINT8_MAX\n || !Number.isSafeInteger(axis.defaultOption)\n || axis.defaultOption < 0\n || axis.defaultOption >= axis.options.length\n || typeof axis.description !== \"string\"\n || !Number.isSafeInteger(axis.type)\n || axis.type < 0 || axis.type > UINT8_MAX)\n {\n throw new Error(\n `Tr2EffectRes permutation axis ${index} is malformed or duplicated`\n );\n }\n names.add(axis.name);\n const options = new Set();\n for (const option of axis.options)\n {\n if (typeof option !== \"string\" || !option\n || option !== option.trim() || options.has(option))\n {\n throw new Error(\n `Tr2EffectRes permutation axis ${index} options are malformed`\n );\n }\n options.add(option);\n }\n return normalizePermutationAxis(axis);\n}\n\nfunction getPermutationProduct(axes)\n{\n let product = 1;\n for (const axis of axes)\n {\n product *= axis.options.length;\n if (!Number.isSafeInteger(product)\n || product < 1\n || product > MAX_EFFECT_PERMUTATIONS)\n {\n throw new Error(\n \"Tr2EffectRes permutation count exceeds the implementation limit\"\n );\n }\n }\n return product;\n}\n\nfunction decodePermutationOptions(permutationIndex, axes)\n{\n let value = permutationIndex;\n return axes.map(axis =>\n {\n const optionIndex = value % axis.options.length;\n value = Math.floor(value / axis.options.length);\n return optionIndex;\n });\n}\n\nfunction validatePermutationSourceRecord(record, permutationIndex)\n{\n const offset = record?.offset;\n const byteLength = record?.byteLength;\n const end = offset + byteLength;\n if (!record || typeof record !== \"object\" || Array.isArray(record)\n || !Number.isSafeInteger(offset) || offset < 0 || offset > UINT32_MAX\n || !Number.isSafeInteger(byteLength) || byteLength < 1\n || byteLength > UINT32_MAX\n || !Number.isSafeInteger(end)\n || end > UINT32_MAX + 1)\n {\n throw new Error(\n `Tr2EffectRes permutation variant ${permutationIndex} source record is malformed`\n );\n }\n return { offset, byteLength };\n}\n\nfunction validateDisjointPermutationRecords(records)\n{\n const unique = new Map();\n for (const record of records)\n {\n const key = `${record.offset}:${record.byteLength}`;\n if (!unique.has(key))\n {\n unique.set(key, {\n offset: record.offset,\n end: record.offset + record.byteLength\n });\n }\n }\n const ordered = Array.from(unique.values()).sort((left, right) =>\n left.offset - right.offset || left.end - right.end);\n for (let index = 1; index < ordered.length; index += 1)\n {\n if (ordered[index].offset < ordered[index - 1].end)\n {\n throw new Error(\n \"Tr2EffectRes permutation source body records partially overlap\"\n );\n }\n }\n}\n\nfunction getPermutationAxes(payload)\n{\n if (!payload)\n {\n return [];\n }\n if (payload.permutationGraph)\n {\n return payload.permutationGraph.axes.map(normalizePermutationAxis);\n }\n if (Array.isArray(payload.permutations)\n && payload.permutations.every(permutation =>\n Array.isArray(permutation?.options)))\n {\n return payload.permutations.map(normalizePermutationAxis);\n }\n return [];\n}\n\nfunction normalizePermutationAxis(axis)\n{\n if (!axis || typeof axis !== \"object\" || Array.isArray(axis)\n || typeof axis.name !== \"string\" || !axis.name\n || !Array.isArray(axis.options) || !axis.options.length\n || axis.options.some(option => typeof option !== \"string\" || !option)\n || !Number.isSafeInteger(axis.defaultOption)\n || axis.defaultOption < 0\n || axis.defaultOption >= axis.options.length)\n {\n throw new TypeError(\"Tr2EffectRes permutation axis is malformed\");\n }\n return {\n name: axis.name,\n options: [ ...axis.options ],\n defaultOption: axis.defaultOption,\n description: String(axis.description ?? \"\"),\n type: Number(axis.type ?? 0)\n };\n}\n\nfunction getPermutationVariantCount(payload)\n{\n if (Array.isArray(payload?.permutationGraph?.variants))\n {\n return payload.permutationGraph.variants.length;\n }\n const axes = getPermutationAxes(payload);\n if (axes.length)\n {\n return axes.reduce((count, axis) => count * axis.options.length, 1);\n }\n return null;\n}\n\nfunction getPortableReflection(payload, index)\n{\n if (!payload)\n {\n return null;\n }\n if (typeof payload.GetPortableEffectReflection === \"function\")\n {\n return payload.GetPortableEffectReflection(index);\n }\n if (typeof payload.getPortableEffectReflection === \"function\")\n {\n return payload.getPortableEffectReflection(index);\n }\n if (Tr2Shader.isPortableReflection(payload))\n {\n return index === payload.permutationIndex ? payload : null;\n }\n if (Array.isArray(payload.portableReflections))\n {\n return payload.portableReflections[index] ?? null;\n }\n return null;\n}\n\nfunction normalizeShaderOptions(options)\n{\n if (options instanceof Map)\n {\n return Array.from(options, ([ name, value ]) => ({\n name: String(name),\n value: String(value)\n }));\n }\n if (!Array.isArray(options))\n {\n return [];\n }\n return options.map(option => ({\n name: String(option?.name ?? \"\"),\n value: String(option?.value ?? \"\")\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(Tr2EffectRes, {\n className: \"Tr2EffectRes\",\n family: \"resources\",\n methods: {\n GetShader: [ carbon.method, impl.adapted, impl.reason(\"Carbon reads the selected body directly from compiled effect bytes and registers renderer handles; CarbonEngineJS hydrates the format package's validated portable reflection without realizing GPU state.\") ],\n GetShaderByIndex: [ impl.custom, impl.reason(\"Carbon selects compiled bodies through GetShader; CarbonEngineJS exposes exact package-index hydration for deterministic package consumers and tests.\") ],\n GetPermutationDescription: [ carbon.method, impl.adapted, impl.reason(\"Carbon exposes a Python tuple through Blue; CarbonEngineJS returns a JSON-friendly plain axis description.\") ],\n ReleaseResources: [ carbon.method, impl.adapted, impl.reason(\"Backend resources are engine-owned; the resource-side release clears only hydrated device-free shader graphs.\") ]\n }\n});\n"],"names":["globalEffectOptions","SHA256","UINT8_MAX","UINT32_MAX","MAX_EFFECT_PERMUTATIONS","Tr2EffectRes","CjsResource","Map","constructor","values","SetValues","markDirty","skipUpdate","skipEvents","SetPayload","payload","options","clear","validateResourcePayload","validateEffectPayload","GetShader","count","axes","getPermutationAxes","GetPayload","length","portableIndex","Tr2Shader","isPortableReflection","permutationIndex","GetShaderByIndex","localOptions","normalizeShaderOptions","localCount","Number","isSafeInteger","Math","max","min","multiplier","index","axis","selectedIndex","defaultOption","globalOption","find","option","name","requestedIndex","indexOf","value","optionIndex","localOption","TypeError","has","get","variantCount","getPermutationVariantCount","portable","getPortableReflection","Error","shader","fromPortable","set","GetPermutationDescription","Array","isArray","permutations","map","permutation","description","type","ReleaseResources","ReleasePayload","ModifyGlobalEffectOptions","changes","change","findIndex","splice","push","GetGlobalEffectOptions","graph","permutationGraph","undefined","validatePermutationGraph","every","forEach","normalizePermutationAxis","validateLegacyPermutationDescription","portableReflections","expectedCount","reflection","entries","format","formatVersion","coverage","bodies","variants","axisNames","Set","validatePermutationAxis","getPermutationProduct","bodyDigests","body","bodyIndex","key","trim","byteLength","sha256","test","add","references","bodyKeyBySourceRecord","sourceRecords","variant","expectedOptions","decodePermutationOptions","optionIndices","some","bodyKey","sourceRecord","validatePermutationSourceRecord","recordKey","offset","existingBodyKey","validateDisjointPermutationRecords","names","product","floor","record","end","records","unique","ordered","from","sort","left","right","String","reduce","GetPortableEffectReflection","getPortableEffectReflection","CjsSchema","define","className","family","methods","carbon","method","impl","adapted","reason","custom"],"mappings":";;;;;AAAA;AACA;AACA;AAMA,MAAMA,mBAAmB,GAAG,EAAE;AAC9B,MAAMC,MAAM,GAAG,iBAAiB;AAChC,MAAMC,SAAS,GAAG,IAAI;AACtB,MAAMC,UAAU,GAAG,UAAU;AAC7B,MAAMC,uBAAuB,GAAG,OAAO;;AAEvC;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,YAAY,SAASC,WAAW,CAC7C;AAEE,EAAA,QAAQ,GAAG,IAAIC,GAAG,EAAE;;AAEpB;AACAC,EAAAA,WAAWA,CAACC,MAAM,GAAG,IAAI,EACzB;AACE,IAAA,KAAK,EAAE;AACP,IAAA,IAAI,CAACC,SAAS,CAACD,MAAM,IAAI,EAAE,EAAE;AAC3BE,MAAAA,SAAS,EAAE,KAAK;AAChBC,MAAAA,UAAU,EAAE,IAAI;AAChBC,MAAAA,UAAU,EAAE;AACd,KAAC,CAAC;AACJ,EAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACEC,UAAUA,CAACC,OAAO,GAAG,IAAI,EAAEC,OAAO,GAAG,IAAI,EACzC;IACE,IAAID,OAAO,KAAK,IAAI,EACpB;AACE,MAAA,IAAI,CAAC,QAAQ,CAACE,KAAK,EAAE;AACrB,MAAA,KAAK,CAACH,UAAU,CAAC,IAAI,CAAC;AACtB,MAAA,OAAO,IAAI;AACb,IAAA;AACAI,IAAAA,uBAAuB,CACrB,cAAc,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AACxF,KAAK;AACrB,KAAC,CAAC,CAAC;AACL,EAAA;AACA,EAAA,IAAI,CAACe,KAAK,CAACC,OAAO,CAAClD,OAAO,CAAC,EAC3B;AACE,IAAA,OAAO,EAAE;AACX,EAAA;AACA,EAAA,OAAOA,OAAO,CAACoD,GAAG,CAACtB,MAAM,KAAK;IAC5BC,IAAI,EAAE2F,MAAM,CAAC5F,MAAM,EAAEC,IAAI,IAAI,EAAE,CAAC;AAChCG,IAAAA,KAAK,EAAEwF,MAAM,CAAC5F,MAAM,EAAEI,KAAK,IAAI,EAAE;AACnC,GAAC,CAAC,CAAC;AACL;;AAEA;AACA;AACA;AACA;AACA;AACA4F,SAAS,CAACC,MAAM,CAAC1I,YAAY,EAAE;AAC7B2I,EAAAA,SAAS,EAAE,cAAc;AACzBC,EAAAA,MAAM,EAAE,WAAW;AACnBC,EAAAA,OAAO,EAAE;AACP9H,IAAAA,SAAS,EAAE,CAAE+H,MAAM,CAACC,MAAM,EAAEC,IAAI,CAACC,OAAO,EAAED,IAAI,CAACE,MAAM,CAAC,4MAA4M,CAAC,CAAE;AACrQzH,IAAAA,gBAAgB,EAAE,CAAEuH,IAAI,CAACG,MAAM,EAAEH,IAAI,CAACE,MAAM,CAAC,uJAAuJ,CAAC,CAAE;AACvMvF,IAAAA,yBAAyB,EAAE,CAAEmF,MAAM,CAACC,MAAM,EAAEC,IAAI,CAACC,OAAO,EAAED,IAAI,CAACE,MAAM,CAAC,4GAA4G,CAAC,CAAE;AACrL/E,IAAAA,gBAAgB,EAAE,CAAE2E,MAAM,CAACC,MAAM,EAAEC,IAAI,CAACC,OAAO,EAAED,IAAI,CAACE,MAAM,CAAC,+GAA+G,CAAC;AAC/K;AACF,CAAC,CAAC;;;;"}
1
+ {"version":3,"file":"Tr2EffectRes.js","sources":["../../../../src/resource/shader/Tr2EffectRes.js"],"sourcesContent":["// Source: trinity/trinity/Resources/Tr2EffectRes.h\n// Source: trinity/trinity/Resources/Tr2EffectRes.cpp\n// Source: trinity/trinity/Resources/Tr2EffectRes_Blue.cpp\nimport { CjsSchema, carbon, impl, type } from \"@carbonenginejs/runtime-utils/schema\";\nimport { CjsResource } from \"../CjsResource.js\";\nimport { validateResourcePayload } from \"../resourceBoundary.js\";\nimport { CjsCarbonEffectReader } from \"../../format/carbonEffect/CjsCarbonEffectReader.js\";\nimport { Tr2Shader } from \"./Tr2Shader.js\";\n\nconst globalEffectOptions = [];\n\n/**\n * Tr2EffectRes resource record.\n *\n * This stores effect/shader payload facts. Engine-gpu decides shader module,\n * pipeline, bind group, and sampler realization.\n */\nexport class Tr2EffectRes extends CjsResource\n{\n\n #shaders = new Map();\n\n #reader = null;\n\n /**\n * Read a Carbon effect container and take ownership of its reader.\n *\n * Carbon's `DoLoad` (`Tr2EffectRes.cpp:137`) does exactly this work: it clears\n * the previous state, then fills `m_version`, the string table, the permutation\n * axes and the offset table from the file, and stops there. Bodies are read\n * later, one at a time, by `GetShader`. The one difference is where the bytes\n * come from — Carbon locks its own data stream, and this takes them as an\n * argument.\n *\n * The container is parsed once, here: version, arena, permutation axes and\n * offset table. Bodies are not. Each one is decoded on first request and\n * memoised, by seeking the retained reader rather than re-reading the header —\n * a container with 512 permutations that renders two of them parses two bodies.\n *\n * The reader is retained rather than discarded because a body cannot be read\n * without it: strings are offsets into the container's arena, which lives in\n * the header this method consumed.\n *\n * @param {ArrayBuffer|ArrayBufferView|Uint8Array} data Container bytes.\n * @param {object|null} options Model values applied after the read.\n * @returns {Tr2EffectRes}\n */\n DoLoad(data, options = null)\n {\n const reader = new CjsCarbonEffectReader(data);\n this.#shaders.clear();\n this.#reader = reader;\n super.SetPayload({\n permutations: reader.permutations.map(axis => ({\n name: axis.name.value,\n options: axis.options.map(option => option.value),\n defaultOption: axis.defaultOption,\n description: axis.description.value,\n type: axis.type\n }))\n });\n this.SetValues(options || {});\n return this;\n }\n\n /** Creates a Tr2EffectRes with caller-provided initial state. */\n constructor(values = null)\n {\n super();\n this.SetValues(values || {}, {\n markDirty: false,\n skipUpdate: true,\n skipEvents: true\n });\n }\n\n /**\n * Attach a plain shader/effect payload.\n *\n * @param {object|null} payload\n * @param {object|null} options\n * @returns {Tr2EffectRes}\n */\n SetPayload(payload = null, options = null)\n {\n if (payload === null)\n {\n this.#shaders.clear();\n this.#reader = null;\n super.SetPayload(null);\n return this;\n }\n validateResourcePayload(\n \"Tr2EffectRes\",\n payload,\n validateEffectPayload\n );\n this.#shaders.clear();\n this.#reader = null;\n super.SetPayload(payload);\n this.SetValues(options || {});\n return this;\n }\n\n /**\n * Select and hydrate one canonical shader from the complete permutation\n * graph exposed by a Carbon WebGL/Carbon WebGPU raw package.\n *\n * Global options have Carbon-compatible precedence over caller options.\n * Unknown option values retain the authored default.\n *\n * @param {Array<object>|Map<string,string>} options Local name/value choices.\n * @param {number|null} count Number of local entries to consider.\n * @returns {Tr2Shader|null} Selected device-free shader reflection.\n */\n GetShader(options = [], count = null)\n {\n const axes = getPermutationAxes(this.GetPayload());\n const localOptions = normalizeShaderOptions(options);\n const localCount = Number.isSafeInteger(count)\n ? Math.max(0, Math.min(count, localOptions.length))\n : localOptions.length;\n let multiplier = 1;\n let index = 0;\n\n for (const axis of axes)\n {\n let selectedIndex = axis.defaultOption;\n const globalOption = globalEffectOptions.find(\n option => option.name === axis.name\n );\n if (globalOption)\n {\n const requestedIndex = axis.options.indexOf(globalOption.value);\n if (requestedIndex >= 0)\n {\n selectedIndex = requestedIndex;\n }\n }\n else\n {\n for (let optionIndex = 0; optionIndex < localCount; optionIndex += 1)\n {\n const localOption = localOptions[optionIndex];\n if (localOption.name !== axis.name)\n {\n continue;\n }\n const requestedIndex = axis.options.indexOf(localOption.value);\n if (requestedIndex >= 0)\n {\n selectedIndex = requestedIndex;\n }\n }\n }\n\n index += selectedIndex * multiplier;\n multiplier *= axis.options.length;\n }\n\n return this.GetShaderByIndex(index);\n }\n\n /**\n * Hydrate one exact permutation-table index and cache the resulting runtime\n * graph for this payload.\n *\n * @param {number} index Exact permutation index.\n * @returns {Tr2Shader|null} Canonical shader or null when reflection is absent.\n */\n GetShaderByIndex(index)\n {\n if (!Number.isSafeInteger(index) || index < 0)\n {\n throw new TypeError(\n \"Tr2EffectRes shader index must be a non-negative safe integer\"\n );\n }\n if (this.#shaders.has(index))\n {\n return this.#shaders.get(index);\n }\n\n const payload = this.GetPayload();\n const variantCount = getPermutationVariantCount(payload);\n if (variantCount !== null && index >= variantCount)\n {\n return null;\n }\n\n if (!this.#reader)\n {\n return null;\n }\n\n const shader = Tr2Shader.fromCarbonBinary(this.#reader, index);\n this.#shaders.set(index, shader);\n return shader;\n }\n\n /**\n * Return a small JSON-friendly permutation description.\n *\n * @returns {Array<*>}\n */\n GetPermutationDescription()\n {\n const payload = this.GetPayload();\n const axes = getPermutationAxes(payload);\n if (!axes.length && Array.isArray(payload?.permutations))\n {\n return payload.permutations.map(permutation => ({ ...permutation }));\n }\n return axes.map(axis => ({\n name: axis.name,\n options: [ ...axis.options ],\n defaultOption: axis.defaultOption,\n description: axis.description,\n type: axis.type\n }));\n }\n\n /**\n * Drop hydrated shader graphs while retaining the validated CPU payload.\n */\n ReleaseResources()\n {\n this.#shaders.clear();\n }\n\n /** Release the payload and every shader graph hydrated from it. */\n ReleasePayload()\n {\n this.#shaders.clear();\n this.#reader = null;\n return super.ReleasePayload();\n }\n\n static payload = \"shader\";\n\n}\n\n/**\n * Validate an attached permutation payload.\n *\n * Carbon has no equivalent: it fills `m_permutations` from the file and never\n * accepts one from a caller. This exists only so an attached payload cannot\n * silently produce a wrong permutation index, and it checks the one thing the\n * index arithmetic depends on - that every axis has options and a default that\n * addresses one of them.\n *\n * @param {object} payload Attached payload.\n */\nfunction validateEffectPayload(payload)\n{\n if (!Array.isArray(payload.permutations))\n {\n throw new TypeError(\n \"Tr2EffectRes payload requires a permutations array\"\n );\n }\n payload.permutations.forEach(normalizePermutationAxis);\n}\n\n/**\n * The permutation axes an attached payload declares.\n *\n * @param {object|null} payload Attached payload.\n * @returns {Array<object>} Normalized axes, empty when there are none.\n */\nfunction getPermutationAxes(payload)\n{\n if (!Array.isArray(payload?.permutations))\n {\n return [];\n }\n return payload.permutations.map(normalizePermutationAxis);\n}\n\n/**\n * Normalize and validate one permutation axis.\n *\n * @param {object} axis Candidate axis.\n * @returns {object} Owned, validated axis.\n */\nfunction normalizePermutationAxis(axis)\n{\n if (!axis || typeof axis !== \"object\" || Array.isArray(axis)\n || typeof axis.name !== \"string\" || !axis.name\n || !Array.isArray(axis.options) || !axis.options.length\n || axis.options.some(option => typeof option !== \"string\" || !option)\n || !Number.isSafeInteger(axis.defaultOption)\n || axis.defaultOption < 0\n || axis.defaultOption >= axis.options.length)\n {\n throw new TypeError(\"Tr2EffectRes permutation axis is malformed\");\n }\n return {\n name: axis.name,\n options: [ ...axis.options ],\n defaultOption: axis.defaultOption,\n description: String(axis.description ?? \"\"),\n type: Number(axis.type ?? 0)\n };\n}\n\n/**\n * The number of permutations the axes describe - the product of their option\n * counts, which is also the number of offset-table rows a dense container has.\n *\n * @param {object|null} payload Attached payload.\n * @returns {number|null} Permutation count, or null when no axes are declared.\n */\nfunction getPermutationVariantCount(payload)\n{\n const axes = getPermutationAxes(payload);\n if (!axes.length)\n {\n return null;\n }\n return axes.reduce((count, axis) => count * axis.options.length, 1);\n}\n\n/**\n * Return an owned snapshot of the current global option overrides.\n *\n * Carbon returns a const reference to the live vector; a JS caller cannot be\n * held to that, so this copies rather than exposing the array for mutation.\n *\n * @returns {Array<{name:string,value:string}>} Global option choices.\n */\nexport function GetGlobalEffectOptions()\n{\n return globalEffectOptions.map(option => ({ ...option }));\n}\n\n/**\n * Merge Carbon-style global effect option overrides.\n *\n * An empty value removes the override. Existing Tr2EffectRes shader caches\n * remain valid objects; callers rebuild effects to request the new selection.\n *\n * @param {Array<object>|Map<string,string>} changes Option changes.\n */\nexport function ModifyGlobalEffectOptions(changes = [])\n{\n for (const change of normalizeShaderOptions(changes))\n {\n const index = globalEffectOptions.findIndex(\n option => option.name === change.name\n );\n if (!change.value)\n {\n if (index >= 0)\n {\n globalEffectOptions.splice(index, 1);\n }\n }\n else if (index >= 0)\n {\n globalEffectOptions[index] = change;\n }\n else\n {\n globalEffectOptions.push(change);\n }\n }\n}\n\nfunction normalizeShaderOptions(options)\n{\n if (options instanceof Map)\n {\n return Array.from(options, ([ name, value ]) => ({\n name: String(name),\n value: String(value)\n }));\n }\n if (!Array.isArray(options))\n {\n return [];\n }\n return options.map(option => ({\n name: String(option?.name ?? \"\"),\n value: String(option?.value ?? \"\")\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(Tr2EffectRes, {\n className: \"Tr2EffectRes\",\n family: \"resources\",\n methods: {\n GetShader: [ carbon.method, impl.adapted, impl.reason(\"Carbon reads the selected body from the compiled effect bytes and registers renderer handles; CarbonEngineJS reads the same bytes and stops at the device-free graph, leaving GPU realization to the engine.\") ],\n GetShaderByIndex: [ impl.custom, impl.reason(\"Carbon selects compiled bodies through GetShader; CarbonEngineJS exposes exact package-index hydration for deterministic package consumers and tests.\") ],\n GetPermutationDescription: [ carbon.method, impl.adapted, impl.reason(\"Carbon exposes a Python tuple through Blue; CarbonEngineJS returns a JSON-friendly plain axis description.\") ],\n ReleaseResources: [ carbon.method, impl.adapted, impl.reason(\"Backend resources are engine-owned; the resource-side release clears only hydrated device-free shader graphs.\") ]\n }\n});\n"],"names":["globalEffectOptions","Tr2EffectRes","CjsResource","Map","DoLoad","data","options","reader","CjsCarbonEffectReader","clear","SetPayload","permutations","map","axis","name","value","option","defaultOption","description","type","SetValues","constructor","values","markDirty","skipUpdate","skipEvents","payload","validateResourcePayload","validateEffectPayload","GetShader","count","axes","getPermutationAxes","GetPayload","localOptions","normalizeShaderOptions","localCount","Number","isSafeInteger","Math","max","min","length","multiplier","index","selectedIndex","globalOption","find","requestedIndex","indexOf","optionIndex","localOption","GetShaderByIndex","TypeError","has","get","variantCount","getPermutationVariantCount","shader","Tr2Shader","fromCarbonBinary","set","GetPermutationDescription","Array","isArray","permutation","ReleaseResources","ReleasePayload","forEach","normalizePermutationAxis","some","String","reduce","GetGlobalEffectOptions","ModifyGlobalEffectOptions","changes","change","findIndex","splice","push","from","CjsSchema","define","className","family","methods","carbon","method","impl","adapted","reason","custom"],"mappings":";;;;;;AAAA;AACA;AACA;AAOA,MAAMA,mBAAmB,GAAG,EAAE;;AAE9B;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,YAAY,SAASC,WAAW,CAC7C;AAEE,EAAA,QAAQ,GAAG,IAAIC,GAAG,EAAE;EAEpB,OAAO,GAAG,IAAI;;AAEd;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEC,EAAAA,MAAMA,CAACC,IAAI,EAAEC,OAAO,GAAG,IAAI,EAC3B;AACE,IAAA,MAAMC,MAAM,GAAG,IAAIC,qBAAqB,CAACH,IAAI,CAAC;AAC9C,IAAA,IAAI,CAAC,QAAQ,CAACI,KAAK,EAAE;AACrB,IAAA,IAAI,CAAC,OAAO,GAAGF,MAAM;IACrB,KAAK,CAACG,UAAU,CAAC;MACfC,YAAY,EAAEJ,MAAM,CAACI,YAAY,CAACC,GAAG,CAACC,IAAI,KAAK;AAC7CC,QAAAA,IAAI,EAAED,IAAI,CAACC,IAAI,CAACC,KAAK;AACrBT,QAAAA,OAAO,EAAEO,IAAI,CAACP,OAAO,CAACM,GAAG,CAACI,MAAM,IAAIA,MAAM,CAACD,KAAK,CAAC;QACjDE,aAAa,EAAEJ,IAAI,CAACI,aAAa;AACjCC,QAAAA,WAAW,EAAEL,IAAI,CAACK,WAAW,CAACH,KAAK;QACnCI,IAAI,EAAEN,IAAI,CAACM;AACb,OAAC,CAAC;AACJ,KAAC,CAAC;AACF,IAAA,IAAI,CAACC,SA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