@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.
- package/README.md +21 -0
- package/dist/CjsResMan.js +393 -29
- package/dist/CjsResMan.js.map +1 -1
- package/dist/format/carbonEffect/CjsCarbonEffectReader.js +165 -118
- package/dist/format/carbonEffect/CjsCarbonEffectReader.js.map +1 -1
- package/dist/format/carbonEffect/buildCarbonEffectContainer.js +182 -0
- package/dist/format/carbonEffect/buildCarbonEffectContainer.js.map +1 -0
- package/dist/format/carbonEffect/carbonEffectBackendBlock.js +7 -113
- package/dist/format/carbonEffect/carbonEffectBackendBlock.js.map +1 -1
- package/dist/format/carbonEffect/carbonEffectRecords.js +258 -66
- package/dist/format/carbonEffect/carbonEffectRecords.js.map +1 -1
- package/dist/format/carbonEffect/carbonEffectResourceTransform.js +197 -0
- package/dist/format/carbonEffect/carbonEffectResourceTransform.js.map +1 -0
- package/dist/format/effect/effectBodyInventory.js +146 -0
- package/dist/format/effect/effectBodyInventory.js.map +1 -0
- package/dist/format/effect/effectPermutationGraph.js +13 -13
- package/dist/format/effect/effectPermutationGraph.js.map +1 -1
- package/dist/format/index.js +4 -4
- package/dist/formats/black/CjsBlackFormat.js +19 -1
- package/dist/formats/black/CjsBlackFormat.js.map +1 -1
- package/dist/formats/bnk/CjsBnkFormat.js +28 -9
- package/dist/formats/bnk/CjsBnkFormat.js.map +1 -1
- package/dist/formats/bnk/core/busNodes.js +252 -0
- package/dist/formats/bnk/core/busNodes.js.map +1 -0
- package/dist/formats/bnk/core/effectNodes.js +147 -0
- package/dist/formats/bnk/core/effectNodes.js.map +1 -0
- package/dist/formats/bnk/core/eventAction.js +135 -24
- package/dist/formats/bnk/core/eventAction.js.map +1 -1
- package/dist/formats/bnk/core/globalSettings.js +215 -0
- package/dist/formats/bnk/core/globalSettings.js.map +1 -0
- package/dist/formats/bnk/core/helpers.js +37 -5
- package/dist/formats/bnk/core/helpers.js.map +1 -1
- package/dist/formats/bnk/core/musicNodes.js +43 -19
- package/dist/formats/bnk/core/musicNodes.js.map +1 -1
- package/dist/formats/bnk/core/nodeBase.js +28 -7
- package/dist/formats/bnk/core/nodeBase.js.map +1 -1
- package/dist/formats/dds/core/helpers.js +40 -1
- package/dist/formats/dds/core/helpers.js.map +1 -1
- package/dist/formats/dxbc/CjsDxbcFormat.js +45 -0
- package/dist/formats/dxbc/CjsDxbcFormat.js.map +1 -1
- package/dist/formats/dxbc/core/disassemble.js +240 -0
- package/dist/formats/dxbc/core/disassemble.js.map +1 -0
- package/dist/formats/gltf/CjsGltfFormat.js +1 -39
- package/dist/formats/gltf/CjsGltfFormat.js.map +1 -1
- package/dist/formats/gltf/core/helpers.js +1 -21
- package/dist/formats/gltf/core/helpers.js.map +1 -1
- package/dist/formats/hlsl/CjsHlslFormat.js +0 -21
- package/dist/formats/hlsl/CjsHlslFormat.js.map +1 -1
- package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js +118 -49
- package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js.map +1 -1
- package/dist/formats/hlsl/core/detailMapFamily.js +128 -0
- package/dist/formats/hlsl/core/detailMapFamily.js.map +1 -0
- package/dist/formats/hlsl/core/localLightFamily.js +133 -0
- package/dist/formats/hlsl/core/localLightFamily.js.map +1 -0
- package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js +79 -73
- package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js.map +1 -1
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectBindingManifest.js +8 -1
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectBindingManifest.js.map +1 -1
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectDescription.js +11 -691
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectDescription.js.map +1 -1
- package/dist/formats/index.js +4 -2
- package/dist/formats/index.js.map +1 -1
- package/dist/formats/obj/CjsObjFormat.js +1 -22
- package/dist/formats/obj/CjsObjFormat.js.map +1 -1
- package/dist/formats/obj/core/helpers.js +1 -21
- package/dist/formats/obj/core/helpers.js.map +1 -1
- package/dist/formats/pickle/CjsPickleFormat.js +214 -0
- package/dist/formats/pickle/CjsPickleFormat.js.map +1 -0
- package/dist/formats/pickle/core/CjsPickleProtocol0Reader.js +551 -0
- package/dist/formats/pickle/core/CjsPickleProtocol0Reader.js.map +1 -0
- package/dist/formats/pickle/index.js +2 -0
- package/dist/formats/pickle/index.js.map +1 -0
- package/dist/formats/red/core/redGraph.js +11 -8
- package/dist/formats/red/core/redGraph.js.map +1 -1
- package/dist/formats/stl/CjsStlFormat.js +1 -46
- package/dist/formats/stl/CjsStlFormat.js.map +1 -1
- package/dist/formats/stl/core/helpers.js +1 -21
- package/dist/formats/stl/core/helpers.js.map +1 -1
- package/dist/formats/webgl/CjsWebglFormat.js +33 -55
- package/dist/formats/webgl/CjsWebglFormat.js.map +1 -1
- package/dist/formats/webgl/core/buildGlslEffectContainer.js +70 -0
- package/dist/formats/webgl/core/buildGlslEffectContainer.js.map +1 -0
- package/dist/formats/webgl/core/effectPackage.js +216 -108
- package/dist/formats/webgl/core/effectPackage.js.map +1 -1
- package/dist/formats/webgl/core/errors.js +1 -1
- package/dist/formats/webgl/core/errors.js.map +1 -1
- package/dist/formats/webgl/core/glsl/DxbcGlslEmitter.js +166 -24
- package/dist/formats/webgl/core/glsl/DxbcGlslEmitter.js.map +1 -1
- package/dist/formats/webgl/core/glsl/DxbcGlslOperandFormatter.js +63 -5
- package/dist/formats/webgl/core/glsl/DxbcGlslOperandFormatter.js.map +1 -1
- package/dist/formats/webgl/core/glsl/packedLightFixups.js +98 -0
- package/dist/formats/webgl/core/glsl/packedLightFixups.js.map +1 -0
- package/dist/formats/webgl/core/glslBackendBlock.js +552 -0
- package/dist/formats/webgl/core/glslBackendBlock.js.map +1 -0
- package/dist/formats/webgl/core/glslBackendBodySet.js +243 -0
- package/dist/formats/webgl/core/glslBackendBodySet.js.map +1 -0
- package/dist/formats/webgl/core/{cewgCompleteness.js → glslEffectCompleteness.js} +12 -8
- package/dist/formats/webgl/core/glslEffectCompleteness.js.map +1 -0
- package/dist/formats/webgl/core/helpers.js +33 -172
- package/dist/formats/webgl/core/helpers.js.map +1 -1
- package/dist/formats/webgl/core/inspectGlslEffectContainer.js +122 -0
- package/dist/formats/webgl/core/inspectGlslEffectContainer.js.map +1 -0
- package/dist/formats/webgl/core/readGlslEffectContainer.js +249 -0
- package/dist/formats/webgl/core/readGlslEffectContainer.js.map +1 -0
- package/dist/formats/webgpu/CjsWebgpuFormat.js +15 -15
- package/dist/formats/webgpu/CjsWebgpuFormat.js.map +1 -1
- package/dist/formats/webgpu/core/buildCarbonEffectContainer.js +37 -145
- package/dist/formats/webgpu/core/buildCarbonEffectContainer.js.map +1 -1
- package/dist/formats/webgpu/core/{cewgpu/CewgpuContainer.js → carbonWebgpu/CarbonWebgpuContainer.js} +13 -27
- package/dist/formats/webgpu/core/carbonWebgpu/CarbonWebgpuContainer.js.map +1 -0
- package/dist/formats/webgpu/core/{cewgpu → carbonWebgpu}/containerViews.js +1 -1
- package/dist/formats/webgpu/core/carbonWebgpu/containerViews.js.map +1 -0
- package/dist/formats/webgpu/core/{cewgpu → carbonWebgpu}/validateContainer.js +4 -4
- package/dist/formats/webgpu/core/carbonWebgpu/validateContainer.js.map +1 -0
- package/dist/formats/webgpu/core/effectBackendBodySet.js +18 -18
- package/dist/formats/webgpu/core/effectBackendBodySet.js.map +1 -1
- package/dist/formats/webgpu/core/errors.js +1 -1
- package/dist/formats/webgpu/core/errors.js.map +1 -1
- package/dist/formats/webgpu/core/helpers.js +22 -22
- package/dist/formats/webgpu/core/helpers.js.map +1 -1
- package/dist/formats/webgpu/core/packageEffect.js +11 -15
- package/dist/formats/webgpu/core/packageEffect.js.map +1 -1
- package/dist/formats/webgpu/core/packageEffectSelection.js +1 -1
- package/dist/formats/webgpu/core/packageEffectSelection.js.map +1 -1
- package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js +23 -23
- package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js.map +1 -1
- package/dist/formats/webgpu/core/wgsl/buildWgslSet.js +6 -6
- package/dist/formats/webgpu/core/wgsl/buildWgslSet.js.map +1 -1
- package/dist/formats/yaml/CjsYamlFormat.js +3 -3
- package/dist/formats/yaml/CjsYamlFormat.js.map +1 -1
- package/dist/formats/yaml/core/CjsYamlReader.js +4 -6
- package/dist/formats/yaml/core/CjsYamlReader.js.map +1 -1
- package/dist/formats/yaml/core/helpers.js +27 -1
- package/dist/formats/yaml/core/helpers.js.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/resource/CjsLoadingObject.js +19 -0
- package/dist/resource/CjsLoadingObject.js.map +1 -0
- package/dist/resource/CjsResource.js +4 -0
- package/dist/resource/CjsResource.js.map +1 -1
- package/dist/resource/ResourceHandlerMode.js +14 -0
- package/dist/resource/ResourceHandlerMode.js.map +1 -0
- package/dist/resource/index.js +2 -0
- package/dist/resource/index.js.map +1 -1
- package/dist/resource/shader/Tr2EffectRes.js +118 -213
- package/dist/resource/shader/Tr2EffectRes.js.map +1 -1
- package/dist/resource/shader/Tr2Shader.js +37 -15
- package/dist/resource/shader/Tr2Shader.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectConstant.js +37 -29
- package/dist/resource/shader/reflection/Tr2EffectConstant.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectDescription.js +39 -34
- package/dist/resource/shader/reflection/Tr2EffectDescription.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectLibrary.js +51 -30
- package/dist/resource/shader/reflection/Tr2EffectLibrary.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js +45 -25
- package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectResource.js +51 -17
- package/dist/resource/shader/reflection/Tr2EffectResource.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectStageInput.js +219 -88
- package/dist/resource/shader/reflection/Tr2EffectStageInput.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectTechnique.js +28 -18
- package/dist/resource/shader/reflection/Tr2EffectTechnique.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2Pass.js +96 -39
- package/dist/resource/shader/reflection/Tr2Pass.js.map +1 -1
- package/dist/resource/shader/reflection/carbonRecordFields.js +159 -0
- package/dist/resource/shader/reflection/carbonRecordFields.js.map +1 -0
- package/dist/resource/shader/reflection/shaderStage.js +22 -0
- package/dist/resource/shader/reflection/shaderStage.js.map +1 -0
- package/dist/resource/shader/sampler/Tr2SamplerSetup.js +68 -10
- package/dist/resource/shader/sampler/Tr2SamplerSetup.js.map +1 -1
- package/dist/worker/CjsResManMainThreadLoader.js +9 -7
- package/dist/worker/CjsResManMainThreadLoader.js.map +1 -1
- package/dist/worker/CjsResManWorker.js +5 -4
- package/dist/worker/CjsResManWorker.js.map +1 -1
- package/dist/worker/CjsResManWorkerLoader.js +9 -6
- package/dist/worker/CjsResManWorkerLoader.js.map +1 -1
- package/docs/README.md +2 -2
- package/docs/architecture.md +12 -3
- package/docs/concepts/resource-lifecycle.md +9 -8
- package/docs/concepts/shader-resource-model.md +14 -17
- package/docs/concepts/writing-an-engine-adapter.md +1 -1
- package/docs/formats/README.md +4 -2
- package/docs/formats/carbon-effect-container.md +127 -26
- package/docs/formats/dxbc/architecture.md +1 -1
- package/docs/formats/dxbc/reference/api.md +28 -0
- package/docs/formats/hlsl/README.md +3 -3
- package/docs/formats/hlsl/architecture.md +8 -9
- package/docs/formats/hlsl/guides/hydrating-json-output.md +3 -5
- package/docs/formats/hlsl/guides/reading-effects.md +5 -1
- package/docs/formats/hlsl/reference/advanced-analysis.md +20 -25
- package/docs/formats/hlsl/reference/api.md +0 -7
- package/docs/formats/hlsl/reference/json-graph.md +1 -4
- package/docs/formats/pickle.md +82 -0
- package/docs/formats/webgl/README.md +71 -13
- package/docs/formats/webgl/architecture.md +16 -17
- package/docs/formats/webgl/carbon-constant-layouts.md +3 -3
- package/docs/formats/webgl/decl-io.md +3 -3
- package/docs/formats/webgl/memory-structured.md +27 -8
- package/docs/formats/webgl/texture-sample.md +1 -1
- package/docs/formats/webgpu/README.md +3 -3
- package/docs/formats/webgpu/architecture.md +5 -6
- package/docs/formats/webgpu/formats/{cewgpu.md → carbon-webgpu.md} +10 -11
- package/docs/formats/webgpu/guides/effect-packaging.md +6 -8
- package/docs/formats/webgpu/reference/api.md +11 -12
- package/docs/formats/webgpu/reference/wgsl-compatibility.md +11 -8
- package/docs/formats/wwise.md +63 -2
- package/docs/reference/classes/core.md +10 -0
- package/docs/reference/classes/formats.md +40 -48
- package/docs/reference/classes/resources.md +2 -2
- package/docs/reference/queues.md +88 -4
- package/docs/reference/workers.md +7 -0
- package/package.json +61 -61
- package/dist/format/carbonEffect/carbonDescriptionFromPortable.js +0 -372
- package/dist/format/carbonEffect/carbonDescriptionFromPortable.js.map +0 -1
- package/dist/format/effect/effectReflectionPackage.js +0 -636
- package/dist/format/effect/effectReflectionPackage.js.map +0 -1
- package/dist/formats/hlsl/core/HlslReader.js +0 -16
- package/dist/formats/hlsl/core/HlslReader.js.map +0 -1
- package/dist/formats/hlsl/core/portableReflection.js +0 -848
- package/dist/formats/hlsl/core/portableReflection.js.map +0 -1
- package/dist/formats/hlsl/portable.js +0 -2
- package/dist/formats/hlsl/portable.js.map +0 -1
- package/dist/formats/webgl/core/cewg/CewgPackage.js +0 -340
- package/dist/formats/webgl/core/cewg/CewgPackage.js.map +0 -1
- package/dist/formats/webgl/core/cewg/CewgPackageBuilder.js +0 -104
- package/dist/formats/webgl/core/cewg/CewgPackageBuilder.js.map +0 -1
- package/dist/formats/webgl/core/cewg/binary.js +0 -19
- package/dist/formats/webgl/core/cewg/binary.js.map +0 -1
- package/dist/formats/webgl/core/cewgCompleteness.js.map +0 -1
- package/dist/formats/webgl/core/effectPackageValidation.js +0 -331
- package/dist/formats/webgl/core/effectPackageValidation.js.map +0 -1
- package/dist/formats/webgpu/core/cewgpu/CewgpuContainer.js.map +0 -1
- package/dist/formats/webgpu/core/cewgpu/containerViews.js.map +0 -1
- package/dist/formats/webgpu/core/cewgpu/validateContainer.js.map +0 -1
- package/dist/resource/shader/portable.js +0 -33
- package/dist/resource/shader/portable.js.map +0 -1
- package/docs/formats/hlsl/reference/portable-reflection.md +0 -141
- 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
|
|
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
|
-
*
|
|
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
|
|
152
|
-
validateEffectBodyReflection(portable);
|
|
177
|
+
static fromCarbonBinary(reader, index) {
|
|
153
178
|
const shader = new this();
|
|
154
|
-
shader.effect = Tr2EffectDescription.
|
|
179
|
+
shader.effect = Tr2EffectDescription.fromCarbonBinary(reader.readDescription(index));
|
|
155
180
|
shader.ProcessEffect();
|
|
156
181
|
return shader;
|
|
157
182
|
}
|
|
158
183
|
|
|
159
184
|
/**
|
|
160
|
-
*
|
|
185
|
+
* Find a named value across stage collections in Carbon lookup order.
|
|
161
186
|
*
|
|
162
|
-
* @param {
|
|
163
|
-
* @
|
|
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,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,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AAE;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,EAA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,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
|
|
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
|
|
35
|
+
* Build one constant from its Carbon v15 description record.
|
|
35
36
|
*
|
|
36
|
-
*
|
|
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
|
|
40
|
-
if (!isPlainObject(
|
|
41
|
-
throw new TypeError("
|
|
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 =
|
|
60
|
-
constant.offset =
|
|
61
|
-
constant.size =
|
|
62
|
-
constant.type =
|
|
63
|
-
constant.dimension =
|
|
64
|
-
constant.elements =
|
|
65
|
-
constant.isSRGB = !!
|
|
66
|
-
constant.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
|
|
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;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;AACA;AACA;AACA;AACA;EACE,OAAOC,gBAAgBA,CAACC,MAAM,EAC9B;AACE,IAAA,IAAI,CAACC,aAAa,CAACD,MAAM,CAAC,EAC1B;AACE,MAAA,MAAM,IAAIE,SAAS,CAAC,iDAAiD,CAAC;AACxE,IAAA;AAEA,IAAA,MAAMC,QAAQ,GAAG,IAAI,IAAI,EAAE;IAC3BA,QAAQ,CAACZ,IAAI,GAAGa,UAAU,CAACJ,MAAM,CAACT,IAAI,CAAC;AACvCY,IAAAA,QAAQ,CAACX,MAAM,GAAGQ,MAAM,CAACR,MAAM;AAC/BW,IAAAA,QAAQ,CAACV,IAAI,GAAGO,MAAM,CAACP,IAAI;AAC3BU,IAAAA,QAAQ,CAACT,IAAI,GAAGM,MAAM,CAACN,IAAI;AAC3BS,IAAAA,QAAQ,CAACR,SAAS,GAAGK,MAAM,CAACL,SAAS;AACrCQ,IAAAA,QAAQ,CAACP,QAAQ,GAAGI,MAAM,CAACJ,QAAQ;AACnCO,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0B,MAAAA,IAAI,EAAE;AAAS;AAAE,GAAC,EAC5C;AAAE7B,IAAAA,IAAI,EAAE,MAAM;AAAEG,IAAAA,IAAI,EAAE;AAAE0B,MAAAA,IAAI,EAAE;AAAS;AAAE,GAAC,EAC1C;AAAE7B,IAAAA,IAAI,EAAE,MAAM;AAAE8B,IAAAA,IAAI,EAAE;AAAEC,MAAAA,QAAQ,EAAE;KAAQ;AAAE5B,IAAAA,IAAI,EAAE;AAAE0B,MAAAA,IAAI,EAAE;AAAQ;AAAE,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
|
|
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
|
|
52
|
+
* Build one complete effect description from its Carbon v15 record tree.
|
|
51
53
|
*
|
|
52
|
-
*
|
|
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
|
|
56
|
-
if (!isPlainObject(
|
|
57
|
-
throw new TypeError("
|
|
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 =
|
|
70
|
-
|
|
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
|
-
/**
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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 {
|
|
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,wBAAA,EAA2BJ,aAAa,oBAC1C,CAAC;AACH,QAAA;AACAT,QAAAA,WAAW,CAACc,GAAG,CACbC,MAAM,CAACN,aAAa,CAAC,EACrBC,OAAO,CAACM,GAAG,CAACC,MAAM,IAAIA,MAAM,YAAYC,4BAA4B,GAChED,MAAM,GACNC,4BAA4B,CAAChB,IAAI,CAACe,MAAM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s/runtime-utils/schema';
|
|
2
2
|
import { CjsModel } from '@carbonenginejs/runtime-utils/model';
|
|
3
|
-
import { isPlainObject
|
|
4
|
-
import {
|
|
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
|
|
78
|
+
* Build one raytracing library from its Carbon v15 description record.
|
|
78
79
|
*
|
|
79
|
-
*
|
|
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
|
|
83
|
-
if (!isPlainObject(
|
|
84
|
-
throw new TypeError("
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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 =
|
|
115
|
-
|
|
116
|
-
|
|
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
|