@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,11 +1,11 @@
|
|
|
1
1
|
import { CjsSchema, impl, type } from '@carbonenginejs/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 { SHADER_STAGE_COUNT, requireShaderStageType } from './shaderStage.js';
|
|
5
5
|
import { Tr2EffectStageInput } from './Tr2EffectStageInput.js';
|
|
6
|
+
import { recordBytes, toRecordBlob } from './carbonRecordFields.js';
|
|
6
7
|
|
|
7
8
|
// Source: trinity/trinity/Shader/Tr2EffectDescription.h
|
|
8
|
-
const SHADER_TYPE_COUNT = 6;
|
|
9
9
|
|
|
10
10
|
/** Reflected effect pass; backend program and state handles remain engine-owned. */
|
|
11
11
|
class Tr2Pass extends CjsModel {
|
|
@@ -30,36 +30,44 @@ class Tr2Pass extends CjsModel {
|
|
|
30
30
|
/** Exact authored render-state pairs retained before an engine creates a state handle. */
|
|
31
31
|
renderStateValues = [];
|
|
32
32
|
|
|
33
|
+
/** Optional per-pass backend block, absent in a stock Carbon file. */
|
|
34
|
+
backendBlock = null;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Stage types in the order the file stored them.
|
|
38
|
+
*
|
|
39
|
+
* `stageInputs` is indexed by stage type, as Carbon's fixed array is, so the
|
|
40
|
+
* file's ordering is not recoverable from it. That ordering is authored rather
|
|
41
|
+
* than derivable: measured over 288,528 passes in the shipped corpus, 156 put
|
|
42
|
+
* geometry before pixel (`0,3,1`) and 12 put it after (`0,1,3`). Any sort loses
|
|
43
|
+
* one group or the other, so the sequence is kept.
|
|
44
|
+
*/
|
|
45
|
+
stageOrder = [];
|
|
46
|
+
|
|
33
47
|
/**
|
|
34
|
-
* Build one pass from its
|
|
48
|
+
* Build one pass from its Carbon v15 description record.
|
|
35
49
|
*
|
|
36
|
-
*
|
|
50
|
+
* Carbon writes only the stages a pass actually uses, but the class keeps a
|
|
51
|
+
* fixed six-slot array indexed by stage type, so absent stages are filled with
|
|
52
|
+
* explicit empty slots rather than left as holes. The stage's own type byte
|
|
53
|
+
* decides where it lands; position in the record does not.
|
|
54
|
+
*
|
|
55
|
+
* The optional backend block is retained verbatim and not interpreted here. It
|
|
56
|
+
* is the one place the container diverges by backend, and deciding what it
|
|
57
|
+
* means is the engine's job, not the reader's.
|
|
58
|
+
*
|
|
59
|
+
* @param {object} record Carbon pass record.
|
|
37
60
|
* @returns {Tr2Pass} Reflected pass.
|
|
38
61
|
*/
|
|
39
|
-
static
|
|
40
|
-
if (!isPlainObject(
|
|
41
|
-
throw new TypeError("
|
|
42
|
-
}
|
|
43
|
-
if (!isArray(value.renderStates)) {
|
|
44
|
-
throw new TypeError("Portable effect render states must be an array");
|
|
45
|
-
}
|
|
46
|
-
if (!isArray(value.stages)) {
|
|
47
|
-
throw new TypeError("Portable effect stages must be an array");
|
|
48
|
-
}
|
|
49
|
-
if (value.renderStateCount !== value.renderStates.length || value.stageCount !== value.stages.length) {
|
|
50
|
-
throw new Error("Portable effect pass counts disagree with its collections");
|
|
62
|
+
static fromCarbonBinary(record) {
|
|
63
|
+
if (!isPlainObject(record)) {
|
|
64
|
+
throw new TypeError("Carbon effect pass record must be an object");
|
|
51
65
|
}
|
|
52
66
|
const pass = new this();
|
|
53
67
|
const renderStateIds = new Set();
|
|
54
|
-
pass.renderStateValues =
|
|
55
|
-
if (!isUint32(entry?.state)) {
|
|
56
|
-
throw new RangeError("Portable render-state id must fit uint32");
|
|
57
|
-
}
|
|
58
|
-
if (!isUint32(entry?.value)) {
|
|
59
|
-
throw new RangeError("Portable render-state value must fit uint32");
|
|
60
|
-
}
|
|
68
|
+
pass.renderStateValues = record.renderStates.map(entry => {
|
|
61
69
|
if (renderStateIds.has(entry.state)) {
|
|
62
|
-
throw new Error(`
|
|
70
|
+
throw new Error(`Carbon effect render-state id ${entry.state} is duplicated`);
|
|
63
71
|
}
|
|
64
72
|
renderStateIds.add(entry.state);
|
|
65
73
|
return {
|
|
@@ -67,25 +75,72 @@ class Tr2Pass extends CjsModel {
|
|
|
67
75
|
value: entry.value
|
|
68
76
|
};
|
|
69
77
|
});
|
|
70
|
-
const stageTypes = new Set();
|
|
71
|
-
value.stages.forEach(stage => {
|
|
72
|
-
const stageType = requirePortableStageType(stage?.stageType);
|
|
73
|
-
if (stageTypes.has(stageType)) {
|
|
74
|
-
throw new Error(`Portable effect stage type ${stageType} is duplicated`);
|
|
75
|
-
}
|
|
76
|
-
stageTypes.add(stageType);
|
|
77
|
-
});
|
|
78
78
|
pass.stageInputs = Array.from({
|
|
79
|
-
length:
|
|
79
|
+
length: SHADER_STAGE_COUNT
|
|
80
80
|
}, (_, stageType) => Tr2EffectStageInput.createEmpty(stageType));
|
|
81
81
|
pass.shaderTypeMask = 0;
|
|
82
|
-
for (const
|
|
83
|
-
const stage = Tr2EffectStageInput.
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
for (const stageRecord of record.stages) {
|
|
83
|
+
const stage = Tr2EffectStageInput.fromCarbonBinary(stageRecord);
|
|
84
|
+
const stageType = requireShaderStageType(stage.stageType);
|
|
85
|
+
if ((pass.shaderTypeMask & 1 << stageType) !== 0) {
|
|
86
|
+
throw new Error(`Carbon effect stage type ${stageType} is duplicated`);
|
|
87
|
+
}
|
|
88
|
+
pass.stageInputs[stageType] = stage;
|
|
89
|
+
pass.shaderTypeMask = (pass.shaderTypeMask | 1 << stageType) >>> 0;
|
|
86
90
|
}
|
|
91
|
+
pass.stageOrder = record.stages.map(stage => stage.type);
|
|
92
|
+
pass.backendBlock = record.backendBlock ? {
|
|
93
|
+
bytes: recordBytes(record.backendBlock),
|
|
94
|
+
size: record.backendBlock.size
|
|
95
|
+
} : null;
|
|
87
96
|
return pass;
|
|
88
97
|
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The populated stages in the order they should be written.
|
|
101
|
+
*
|
|
102
|
+
* A retained order wins; anything present but unlisted follows in stage-type
|
|
103
|
+
* order, so a pass assembled by hand still emits every stage it has.
|
|
104
|
+
*
|
|
105
|
+
* @returns {Array<object>} Stages in file order.
|
|
106
|
+
*/
|
|
107
|
+
#orderedStages() {
|
|
108
|
+
const present = this.stageInputs.filter(stage => stage?.exists);
|
|
109
|
+
const ordered = [];
|
|
110
|
+
for (const stageType of this.stageOrder) {
|
|
111
|
+
const stage = present.find(entry => entry.stageType === stageType);
|
|
112
|
+
if (stage && !ordered.includes(stage)) ordered.push(stage);
|
|
113
|
+
}
|
|
114
|
+
for (const stage of present) {
|
|
115
|
+
if (!ordered.includes(stage)) ordered.push(stage);
|
|
116
|
+
}
|
|
117
|
+
return ordered;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Emit this pass as a Carbon v15 record.
|
|
122
|
+
*
|
|
123
|
+
* Only stages that exist are written, in ascending stage type. The class keeps
|
|
124
|
+
* six slots because Carbon addresses them positionally in memory; the file
|
|
125
|
+
* stores a count and only the populated ones.
|
|
126
|
+
*
|
|
127
|
+
* Render states are sorted by id because Carbon holds them in a `std::map`.
|
|
128
|
+
*
|
|
129
|
+
* @returns {object} Carbon pass record.
|
|
130
|
+
*/
|
|
131
|
+
toCarbonBinary() {
|
|
132
|
+
const record = {
|
|
133
|
+
stages: this.#orderedStages().map(stage => stage.toCarbonBinary()),
|
|
134
|
+
renderStates: this.renderStateValues.map(entry => ({
|
|
135
|
+
state: entry.state,
|
|
136
|
+
value: entry.value
|
|
137
|
+
})).sort((left, right) => left.state - right.state)
|
|
138
|
+
};
|
|
139
|
+
if (this.backendBlock) {
|
|
140
|
+
record.backendBlock = toRecordBlob(this.backendBlock.bytes, this.backendBlock.size);
|
|
141
|
+
}
|
|
142
|
+
return record;
|
|
143
|
+
}
|
|
89
144
|
}
|
|
90
145
|
|
|
91
146
|
// Declared imperatively rather than with decorators, so this module stays
|
|
@@ -103,7 +158,9 @@ CjsSchema.define(Tr2Pass, {
|
|
|
103
158
|
shaderProgram: type.uint32,
|
|
104
159
|
resourceSetDesc: type.rawStruct("Tr2ResourceSetDescriptionAL"),
|
|
105
160
|
indirectLayout: type.rawStruct("Tr2IndirectDrawBufferLayout"),
|
|
106
|
-
renderStateValues: [impl.adapted, impl.reason("Carbon stores a renderer-owned render-state handle; the device-free graph retains the authored state/value pairs until an engine realizes them."), type.rawStruct("CjsEffectRenderStateValues")]
|
|
161
|
+
renderStateValues: [impl.adapted, impl.reason("Carbon stores a renderer-owned render-state handle; the device-free graph retains the authored state/value pairs until an engine realizes them."), type.rawStruct("CjsEffectRenderStateValues")],
|
|
162
|
+
stageOrder: [impl.custom, impl.reason("Carbon indexes pass stages by type in a fixed array and loses the file's ordering; the device-free graph retains it so a body can be re-emitted as the file that produced it."), type.rawStruct("CjsEffectStageOrder")],
|
|
163
|
+
backendBlock: [impl.custom, impl.reason("Carbon ends a pass at its render states; CarbonEngineJS containers may append one per-pass block carrying the backend program, which the resource retains uninterpreted for an engine to realize."), type.rawStruct("CjsEffectBackendBlock")]
|
|
107
164
|
}
|
|
108
165
|
});
|
|
109
166
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tr2Pass.js","sources":["../../../../../src/resource/shader/reflection/Tr2Pass.js"],"sourcesContent":["// Source: trinity/trinity/Shader/Tr2EffectDescription.h\nimport { CjsSchema, impl, type } from \"@carbonenginejs/runtime-utils/schema\";\nimport { CjsModel } from \"@carbonenginejs/runtime-utils/model\";\nimport {\n isArray,\n isPlainObject,\n isUint32\n} from \"@carbonenginejs/runtime-utils/is\";\nimport { requirePortableStageType } from \"../portable.js\";\nimport { Tr2EffectStageInput } from \"./Tr2EffectStageInput.js\";\n\nconst SHADER_TYPE_COUNT = 6;\n\n/** Reflected effect pass; backend program and state handles remain engine-owned. */\nexport class Tr2Pass extends CjsModel\n{\n\n /** stageInputs (Tr2EffectStageInput) */\n stageInputs = [];\n\n /** renderStates (unsigned int) */\n renderStates = 0;\n\n /** shaderTypeMask (unsigned int) */\n shaderTypeMask = 0;\n\n /** shaderProgram (unsigned int) */\n shaderProgram = 0;\n\n /** resourceSetDesc (Tr2ResourceSetDescriptionAL) */\n resourceSetDesc = null;\n\n /** indirectLayout (Tr2IndirectDrawBufferLayout) */\n indirectLayout = null;\n\n /** Exact authored render-state pairs retained before an engine creates a state handle. */\n renderStateValues = [];\n\n /**\n * Build one pass from its portable JSON reflection record.\n *\n * @param {object} value Portable pass record.\n * @returns {Tr2Pass} Reflected pass.\n */\n static fromPortable(value)\n {\n if (!isPlainObject(value))\n {\n throw new TypeError(\"Portable effect pass must be an object\");\n }\n if (!isArray(value.renderStates))\n {\n throw new TypeError(\n \"Portable effect render states must be an array\"\n );\n }\n if (!isArray(value.stages))\n {\n throw new TypeError(\"Portable effect stages must be an array\");\n }\n if (value.renderStateCount !== value.renderStates.length\n || value.stageCount !== value.stages.length)\n {\n throw new Error(\n \"Portable effect pass counts disagree with its collections\"\n );\n }\n\n const pass = new this();\n const renderStateIds = new Set();\n pass.renderStateValues = value.renderStates.map(entry =>\n {\n if (!isUint32(entry?.state))\n {\n throw new RangeError(\"Portable render-state id must fit uint32\");\n }\n if (!isUint32(entry?.value))\n {\n throw new RangeError(\n \"Portable render-state value must fit uint32\"\n );\n }\n if (renderStateIds.has(entry.state))\n {\n throw new Error(\n `Portable render-state id ${entry.state} is duplicated`\n );\n }\n renderStateIds.add(entry.state);\n return {\n state: entry.state,\n value: entry.value\n };\n });\n\n const stageTypes = new Set();\n value.stages.forEach(stage =>\n {\n const stageType = requirePortableStageType(stage?.stageType);\n if (stageTypes.has(stageType))\n {\n throw new Error(\n `Portable effect stage type ${stageType} is duplicated`\n );\n }\n stageTypes.add(stageType);\n });\n pass.stageInputs = Array.from(\n { length: SHADER_TYPE_COUNT },\n (_, stageType) => Tr2EffectStageInput.createEmpty(stageType)\n );\n pass.shaderTypeMask = 0;\n\n for (const stageValue of value.stages)\n {\n const stage = Tr2EffectStageInput.fromPortable(stageValue);\n pass.stageInputs[stage.stageType] = stage;\n pass.shaderTypeMask = (\n pass.shaderTypeMask | (1 << stage.stageType)\n ) >>> 0;\n }\n\n return pass;\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(Tr2Pass, {\n className: \"Tr2Pass\",\n family: \"shader\",\n fields: {\n stageInputs: type.list(\"Tr2EffectStageInput\"),\n renderStates: type.uint32,\n shaderTypeMask: type.uint32,\n shaderProgram: type.uint32,\n resourceSetDesc: type.rawStruct(\"Tr2ResourceSetDescriptionAL\"),\n indirectLayout: type.rawStruct(\"Tr2IndirectDrawBufferLayout\"),\n renderStateValues: [ impl.adapted, impl.reason(\"Carbon stores a renderer-owned render-state handle; the device-free graph retains the authored state/value pairs until an engine realizes them.\"), type.rawStruct(\"CjsEffectRenderStateValues\") ]\n }\n});\n"],"names":["SHADER_TYPE_COUNT","Tr2Pass","CjsModel","stageInputs","renderStates","shaderTypeMask","shaderProgram","resourceSetDesc","indirectLayout","renderStateValues","fromPortable","value","isPlainObject","TypeError","isArray","stages","renderStateCount","length","stageCount","Error","pass","renderStateIds","Set","map","entry","isUint32","state","RangeError","has","add","stageTypes","forEach","stage","stageType","requirePortableStageType","Array","from","_","Tr2EffectStageInput","createEmpty","stageValue","CjsSchema","define","className","family","fields","type","list","uint32","rawStruct","impl","adapted","reason"],"mappings":";;;;;;AAAA;AAWA,MAAMA,iB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M,EACrC;AACE,MAAA,MAAMiB,KAAK,GAAGM,mBAAmB,CAAC5B,YAAY,CAAC8B,UAAU,CAAC;MAC1DpB,IAAI,CAACjB,WAAW,CAAC6B,KAAK,CAACC,SAAS,CAAC,GAAGD,KAAK;AACzCZ,MAAAA,IAAI,CAACf,cAAc,GAAG,CACpBe,IAAI,CAACf,cAAc,GAAI,CAAC,IAAI2B,KAAK,CAACC,SAAU,MACxC,CAAC;AACT,IAAA;AAEA,IAAA,OAAOb,IAAI;AACb,EAAA;AAEF;;AAEA;AACA;AACA;AACA;AACA;AACAqB,SAAS,CAACC,MAAM,CAACzC,OAAO,EAAE;AACxB0C,EAAAA,SAAS,EAAE,SAAS;AACpBC,EAAAA,MAAM,EAAE,QAAQ;AAChBC,EAAAA,MAAM,EAAE;AACN1C,IAAAA,WAAW,EAAE2C,IAAI,CAACC,IAAI,CAAC,qBAAqB,CAAC;IAC7C3C,YAAY,EAAE0C,IAAI,CAACE,MAAM;IACzB3C,cAAc,EAAEyC,IAAI,CAACE,MAAM;IAC3B1C,aAAa,EAAEwC,IAAI,CAACE,MAAM;AAC1BzC,IAAAA,eAAe,EAAEuC,IAAI,CAACG,SAAS,CAAC,6BAA6B,CAAC;AAC9DzC,IAAAA,cAAc,EAAEsC,IAAI,CAACG,SAAS,CAAC,6BAA6B,CAAC;AAC7DxC,IAAAA,iBAAiB,EAAE,CAAEyC,IAAI,CAACC,OAAO,EAAED,IAAI,CAACE,MAAM,CAAC,iJAAiJ,CAAC,EAAEN,IAAI,CAACG,SAAS,CAAC,4BAA4B,CAAC;AACjP;AACF,CAAC,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"Tr2Pass.js","sources":["../../../../../src/resource/shader/reflection/Tr2Pass.js"],"sourcesContent":["// Source: trinity/trinity/Shader/Tr2EffectDescription.h\nimport { CjsSchema, impl, type } from \"@carbonenginejs/runtime-utils/schema\";\nimport { CjsModel } from \"@carbonenginejs/runtime-utils/model\";\nimport {\n isPlainObject\n} from \"@carbonenginejs/runtime-utils/is\";\nimport { requireShaderStageType, SHADER_STAGE_COUNT } from \"./shaderStage.js\";\nimport { Tr2EffectStageInput } from \"./Tr2EffectStageInput.js\";\nimport { recordBytes, toRecordBlob } from \"./carbonRecordFields.js\";\n\n/** Reflected effect pass; backend program and state handles remain engine-owned. */\nexport class Tr2Pass extends CjsModel\n{\n\n /** stageInputs (Tr2EffectStageInput) */\n stageInputs = [];\n\n /** renderStates (unsigned int) */\n renderStates = 0;\n\n /** shaderTypeMask (unsigned int) */\n shaderTypeMask = 0;\n\n /** shaderProgram (unsigned int) */\n shaderProgram = 0;\n\n /** resourceSetDesc (Tr2ResourceSetDescriptionAL) */\n resourceSetDesc = null;\n\n /** indirectLayout (Tr2IndirectDrawBufferLayout) */\n indirectLayout = null;\n\n /** Exact authored render-state pairs retained before an engine creates a state handle. */\n renderStateValues = [];\n\n /** Optional per-pass backend block, absent in a stock Carbon file. */\n backendBlock = null;\n\n /**\n * Stage types in the order the file stored them.\n *\n * `stageInputs` is indexed by stage type, as Carbon's fixed array is, so the\n * file's ordering is not recoverable from it. That ordering is authored rather\n * than derivable: measured over 288,528 passes in the shipped corpus, 156 put\n * geometry before pixel (`0,3,1`) and 12 put it after (`0,1,3`). Any sort loses\n * one group or the other, so the sequence is kept.\n */\n stageOrder = [];\n\n /**\n * Build one pass from its Carbon v15 description record.\n *\n * Carbon writes only the stages a pass actually uses, but the class keeps a\n * fixed six-slot array indexed by stage type, so absent stages are filled with\n * explicit empty slots rather than left as holes. The stage's own type byte\n * decides where it lands; position in the record does not.\n *\n * The optional backend block is retained verbatim and not interpreted here. It\n * is the one place the container diverges by backend, and deciding what it\n * means is the engine's job, not the reader's.\n *\n * @param {object} record Carbon pass record.\n * @returns {Tr2Pass} Reflected pass.\n */\n static fromCarbonBinary(record)\n {\n if (!isPlainObject(record))\n {\n throw new TypeError(\"Carbon effect pass record must be an object\");\n }\n\n const pass = new this();\n const renderStateIds = new Set();\n pass.renderStateValues = record.renderStates.map(entry =>\n {\n if (renderStateIds.has(entry.state))\n {\n throw new Error(\n `Carbon effect render-state id ${entry.state} is duplicated`\n );\n }\n renderStateIds.add(entry.state);\n return { state: entry.state, value: entry.value };\n });\n\n pass.stageInputs = Array.from(\n { length: SHADER_STAGE_COUNT },\n (_, stageType) => Tr2EffectStageInput.createEmpty(stageType)\n );\n pass.shaderTypeMask = 0;\n\n for (const stageRecord of record.stages)\n {\n const stage = Tr2EffectStageInput.fromCarbonBinary(stageRecord);\n const stageType = requireShaderStageType(stage.stageType);\n if ((pass.shaderTypeMask & (1 << stageType)) !== 0)\n {\n throw new Error(\n `Carbon effect stage type ${stageType} is duplicated`\n );\n }\n pass.stageInputs[stageType] = stage;\n pass.shaderTypeMask = (pass.shaderTypeMask | (1 << stageType)) >>> 0;\n }\n\n pass.stageOrder = record.stages.map(stage => stage.type);\n pass.backendBlock = record.backendBlock\n ? { bytes: recordBytes(record.backendBlock), size: record.backendBlock.size }\n : null;\n\n return pass;\n }\n\n\n /**\n * The populated stages in the order they should be written.\n *\n * A retained order wins; anything present but unlisted follows in stage-type\n * order, so a pass assembled by hand still emits every stage it has.\n *\n * @returns {Array<object>} Stages in file order.\n */\n #orderedStages()\n {\n const present = this.stageInputs.filter(stage => stage?.exists);\n const ordered = [];\n for (const stageType of this.stageOrder)\n {\n const stage = present.find(entry => entry.stageType === stageType);\n if (stage && !ordered.includes(stage)) ordered.push(stage);\n }\n for (const stage of present)\n {\n if (!ordered.includes(stage)) ordered.push(stage);\n }\n return ordered;\n }\n\n /**\n * Emit this pass as a Carbon v15 record.\n *\n * Only stages that exist are written, in ascending stage type. The class keeps\n * six slots because Carbon addresses them positionally in memory; the file\n * stores a count and only the populated ones.\n *\n * Render states are sorted by id because Carbon holds them in a `std::map`.\n *\n * @returns {object} Carbon pass record.\n */\n toCarbonBinary()\n {\n const record = {\n stages: this.#orderedStages().map(stage => stage.toCarbonBinary()),\n renderStates: this.renderStateValues\n .map(entry => ({ state: entry.state, value: entry.value }))\n .sort((left, right) => left.state - right.state)\n };\n if (this.backendBlock)\n {\n record.backendBlock = toRecordBlob(\n this.backendBlock.bytes,\n this.backendBlock.size\n );\n }\n return record;\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(Tr2Pass, {\n className: \"Tr2Pass\",\n family: \"shader\",\n fields: {\n stageInputs: type.list(\"Tr2EffectStageInput\"),\n renderStates: type.uint32,\n shaderTypeMask: type.uint32,\n shaderProgram: type.uint32,\n resourceSetDesc: type.rawStruct(\"Tr2ResourceSetDescriptionAL\"),\n indirectLayout: type.rawStruct(\"Tr2IndirectDrawBufferLayout\"),\n renderStateValues: [ impl.adapted, impl.reason(\"Carbon stores a renderer-owned render-state handle; the device-free graph retains the authored state/value pairs until an engine realizes them.\"), type.rawStruct(\"CjsEffectRenderStateValues\") ],\n stageOrder: [ impl.custom, impl.reason(\"Carbon indexes pass stages by type in a fixed array and loses the file's ordering; the device-free graph retains it so a body can be re-emitted as the file that produced it.\"), type.rawStruct(\"CjsEffectStageOrder\") ],\n backendBlock: [ impl.custom, impl.reason(\"Carbon ends a pass at its render states; CarbonEngineJS containers may append one per-pass block carrying the backend program, which the resource retains uninterpreted for an engine to realize.\"), type.rawStruct(\"CjsEffectBackendBlock\") ]\n }\n});\n"],"names":["Tr2Pass","CjsModel","stageInputs","renderStates","shaderTypeMask","shaderProgram","resourceSetDesc","indirectLayout","renderStateValues","backendBlock","stageOrder","fromCarbonBinary","record","isPlainObject","TypeError","pass","renderStateIds","Set","map","entry","has","state","Error","add","value","Array","from","length","SHADER_STAGE_COUNT","_","stageType","Tr2EffectStageInput","createEmpty","stageRecord","stages","stage","requireShaderStageType","type","bytes","recordBytes","size","#orderedStages","present","filter","exists","ordered","find","includes","push","toCarbonBinary","sort","left","right","toRecordBlob","CjsSchema","define","className","family","fields","list","uint32","rawStruct","impl","adapted","reason","custom"],"mappings":";;;;;;;AAAA;;AAUA;AACO,MAAMA,OAAO,SAASC,QAAQ,CACrC;AAEE;AACAC,EAAAA,WAAW,GAAG,EAAE;;AAEhB;AACAC,EAAAA,YAAY,GAAG,CAAC;;AAEhB;AACAC,EAAAA,cAAc,GAAG,CAAC;;AAElB;AACAC,EAAAA,aAAa,GAAG,CAAC;;AAEjB;AACAC,EAAAA,eAAe,GAAG,IAAI;;AAEtB;AACAC,EAAAA,cAAc,GAAG,IAAI;;AAErB;AACAC,EAAAA,iBAAiB,GAAG,EAAE;;AAEtB;AACAC,EAAAA,YAAY,GAAG,IAAI;;AAEnB;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEC,EAAAA,UAAU,GAAG,EAAE;;AAEf;AACF;AACA;AACA;AACA;AACA;AACA;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,6CAA6C,CAAC;AACpE,IAAA;AAEA,IAAA,MAAMC,IAAI,GAAG,IAAI,IAAI,EAAE;AACvB,IAAA,MAAMC,cAAc,GAAG,IAAIC,GAAG,EAAE;IAChCF,IAAI,CAACP,iBAAiB,GAAGI,MAAM,CAACT,YAAY,CAACe,GAAG,CAACC,KAAK,IACtD;MACE,IAAIH,cAAc,CAACI,GAAG,CAACD,KAAK,CAACE,KAAK,CAAC,EACnC;QACE,MAAM,IAAIC,KAAK,CACb,CAAA,8BAAA,EAAiCH,KAAK,CAACE,KAAK,gBAC9C,CAAC;AACH,MAAA;AACAL,MAAAA,cAAc,CAACO,GAAG,CAACJ,KAAK,CAACE,KAAK,CAAC;MAC/B,OAAO;QAAEA,KAAK,EAAEF,KAAK,CAACE,KAAK;QAAEG,KAAK,EAAEL,KAAK,CAACK;OAAO;AACnD,IAAA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ChC,IAAI,CAAC5C,YAAY,CAAC6B,KAAK,EACvB,IAAI,CAAC7B,YAAY,CAAC+B,IACpB,CAAC;AACH,IAAA;AACA,IAAA,OAAO5B,MAAM;AACf,EAAA;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA0C,SAAS,CAACC,MAAM,CAACvD,OAAO,EAAE;AACxBwD,EAAAA,SAAS,EAAE,SAAS;AACpBC,EAAAA,MAAM,EAAE,QAAQ;AAChBC,EAAAA,MAAM,EAAE;AACNxD,IAAAA,WAAW,EAAEmC,IAAI,CAACsB,IAAI,CAAC,qBAAqB,CAAC;IAC7CxD,YAAY,EAAEkC,IAAI,CAACuB,MAAM;IACzBxD,cAAc,EAAEiC,IAAI,CAACuB,MAAM;IAC3BvD,aAAa,EAAEgC,IAAI,CAACuB,MAAM;AAC1BtD,IAAAA,eAAe,EAAE+B,IAAI,CAACwB,SAAS,CAAC,6BAA6B,CAAC;AAC9DtD,IAAAA,cAAc,EAAE8B,IAAI,CAACwB,SAAS,CAAC,6BAA6B,CAAC;AAC7DrD,IAAAA,iBAAiB,EAAE,CAAEsD,IAAI,CAACC,OAAO,EAAED,IAAI,CAACE,MAAM,CAAC,iJAAiJ,CAAC,EAAE3B,IAAI,CAACwB,SAAS,CAAC,4BAA4B,CAAC,CAAE;AACjPnD,IAAAA,UAAU,EAAE,CAAEoD,IAAI,CAACG,MAAM,EAAEH,IAAI,CAACE,MAAM,CAAC,+KAA+K,CAAC,EAAE3B,IAAI,CAACwB,SAAS,CAAC,qBAAqB,CAAC,CAAE;AAChQpD,IAAAA,YAAY,EAAE,CAAEqD,IAAI,CAACG,MAAM,EAAEH,IAAI,CAACE,MAAM,CAAC,mMAAmM,CAAC,EAAE3B,IAAI,CAACwB,SAAS,CAAC,uBAAuB,CAAC;AACxR;AACF,CAAC,CAAC;;;;"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// Shared field accessors for Carbon v15 description records.
|
|
2
|
+
//
|
|
3
|
+
// The record tree is what the one Carbon effect reader emits
|
|
4
|
+
// (`format/carbonEffect/carbonEffectRecords.js`). Each reflection class maps its
|
|
5
|
+
// own record, but three field encodings recur across all of them and are worth
|
|
6
|
+
// naming once rather than open-coding at every call site:
|
|
7
|
+
//
|
|
8
|
+
// - a string is an arena reference `{offset, value}`, not a string;
|
|
9
|
+
// - an annotation value is four raw little-endian bytes, because Carbon writes
|
|
10
|
+
// it through one union member and reads it through another, so the bytes are
|
|
11
|
+
// the only faithful carrier;
|
|
12
|
+
// - a blob is `{size, offset, bytes}` with `offset === 0xffffffff` meaning the
|
|
13
|
+
// reference was never set, which is not the same as an empty payload.
|
|
14
|
+
//
|
|
15
|
+
// Both directions live here, as `recordX` and `toRecordX` pairs. They are held
|
|
16
|
+
// apart by the round trip rather than by separation: records in, classes, records
|
|
17
|
+
// out, compared byte for byte over the shipped corpus, so a mistake that
|
|
18
|
+
// satisfied both sides would have to be an exact inverse of itself.
|
|
19
|
+
|
|
20
|
+
const rawValueBuffer = new DataView(new ArrayBuffer(4));
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Reads the text out of an arena string reference.
|
|
24
|
+
*
|
|
25
|
+
* @param {{offset:number,value:string}|null|undefined} ref String reference.
|
|
26
|
+
* @returns {string} The referenced text, or "" when unset.
|
|
27
|
+
*/
|
|
28
|
+
function recordText(ref) {
|
|
29
|
+
return String(ref?.value ?? "");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Decodes an annotation record's four raw bytes as the `u32` bit pattern the
|
|
34
|
+
* reflection classes carry as `rawValue`.
|
|
35
|
+
*
|
|
36
|
+
* Carbon stores the value as a `{float,int32_t}` union and the type byte decides
|
|
37
|
+
* which member is meaningful, so the bits travel untyped and each annotation type
|
|
38
|
+
* reinterprets them itself. Decoding to a number here — rather than to a float —
|
|
39
|
+
* is what keeps a value like `-FLT_MAX` exact.
|
|
40
|
+
*
|
|
41
|
+
* @param {Uint8Array|null|undefined} bytes Four little-endian bytes.
|
|
42
|
+
* @returns {number} The unsigned 32-bit pattern those bytes carry.
|
|
43
|
+
*/
|
|
44
|
+
function recordRawValue(bytes) {
|
|
45
|
+
if (!bytes || bytes.length < 4) return 0;
|
|
46
|
+
rawValueBuffer.setUint8(0, bytes[0]);
|
|
47
|
+
rawValueBuffer.setUint8(1, bytes[1]);
|
|
48
|
+
rawValueBuffer.setUint8(2, bytes[2]);
|
|
49
|
+
rawValueBuffer.setUint8(3, bytes[3]);
|
|
50
|
+
return rawValueBuffer.getUint32(0, true);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Re-encodes a record's `float` as the `u32` bit pattern the reflection classes
|
|
55
|
+
* carry in their `*Raw` sampler fields.
|
|
56
|
+
*
|
|
57
|
+
* The container stores sampler LOD and border values as real floats, but the
|
|
58
|
+
* class keeps the bits, so a value like `-FLT_MAX` survives serialization without
|
|
59
|
+
* a decimal round trip. Reading the float and re-encoding it here is exact: the
|
|
60
|
+
* record's value came from a `f32` read, so it is already representable.
|
|
61
|
+
*
|
|
62
|
+
* @param {number} value Float value from a sampler record.
|
|
63
|
+
* @returns {number} The unsigned 32-bit pattern encoding that float.
|
|
64
|
+
*/
|
|
65
|
+
function recordRawBits(value) {
|
|
66
|
+
rawValueBuffer.setFloat32(0, Number.isFinite(value) ? value : 0, true);
|
|
67
|
+
return rawValueBuffer.getUint32(0, true);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Wraps text as the arena string reference the writer interns.
|
|
72
|
+
*
|
|
73
|
+
* The offset is always 0: the writer assigns real offsets while building the
|
|
74
|
+
* arena, and any value here would be discarded. Carrying the text is the whole
|
|
75
|
+
* job.
|
|
76
|
+
*
|
|
77
|
+
* @param {string} value Text value.
|
|
78
|
+
* @returns {{offset:number,value:string}} String reference.
|
|
79
|
+
*/
|
|
80
|
+
function toRecordText(value) {
|
|
81
|
+
return {
|
|
82
|
+
offset: 0,
|
|
83
|
+
value: String(value ?? "")
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Encodes a `u32` bit pattern as an annotation record's four raw bytes.
|
|
89
|
+
*
|
|
90
|
+
* The inverse of {@link recordRawValue}, and raw for the same reason: the value
|
|
91
|
+
* is written through one union member and read through another, so no numeric
|
|
92
|
+
* conversion may happen on the way out either.
|
|
93
|
+
*
|
|
94
|
+
* @param {number} rawValue Unsigned 32-bit pattern.
|
|
95
|
+
* @returns {Uint8Array} Four little-endian bytes.
|
|
96
|
+
*/
|
|
97
|
+
function toRecordRawValue(rawValue) {
|
|
98
|
+
const bytes = new Uint8Array(4);
|
|
99
|
+
rawValueBuffer.setUint32(0, rawValue >>> 0, true);
|
|
100
|
+
for (let index = 0; index < 4; index += 1) {
|
|
101
|
+
bytes[index] = rawValueBuffer.getUint8(index);
|
|
102
|
+
}
|
|
103
|
+
return bytes;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Decodes a `*Raw` sampler field back to the float the record stores.
|
|
108
|
+
*
|
|
109
|
+
* The inverse of {@link recordRawBits}. Assigning the raw `u32` straight across
|
|
110
|
+
* would write `4286578687.0` where the file says `-3.4028235e38`, and every
|
|
111
|
+
* structural check in the container would accept it.
|
|
112
|
+
*
|
|
113
|
+
* @param {number} bits Raw 32-bit pattern.
|
|
114
|
+
* @returns {number} The float those bits encode.
|
|
115
|
+
*/
|
|
116
|
+
function toRecordFloat(bits) {
|
|
117
|
+
rawValueBuffer.setUint32(0, (bits ?? 0) >>> 0, true);
|
|
118
|
+
return rawValueBuffer.getFloat32(0, true);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Wraps bytes as the record codec's sized blob reference.
|
|
123
|
+
*
|
|
124
|
+
* A zero-length blob keeps the offset word the file carried, because the writer
|
|
125
|
+
* passes it straight through rather than interning anything. That word is
|
|
126
|
+
* usually `0xffffffff`, but not always — measured across the shipped corpus,
|
|
127
|
+
* 150 of 4833 files carry a live-looking offset behind a zero size, and
|
|
128
|
+
* normalizing it changes the bytes and can make two distinct bodies collapse
|
|
129
|
+
* into one. An empty payload and an absent one are not the same thing.
|
|
130
|
+
*
|
|
131
|
+
* @param {Uint8Array} bytes Payload bytes.
|
|
132
|
+
* @param {number} [declaredSize] Size to declare when tracked separately.
|
|
133
|
+
* @param {number} [unsetOffset] Offset word to keep when the size is zero.
|
|
134
|
+
* @returns {{size:number,offset:number,bytes:Uint8Array}} Blob reference.
|
|
135
|
+
*/
|
|
136
|
+
function toRecordBlob(bytes, declaredSize, unsetOffset = 0xffffffff) {
|
|
137
|
+
const owned = bytes instanceof Uint8Array ? bytes : new Uint8Array(0);
|
|
138
|
+
const size = declaredSize ?? owned.byteLength;
|
|
139
|
+
return {
|
|
140
|
+
size,
|
|
141
|
+
offset: size === 0 ? unsetOffset >>> 0 : 0,
|
|
142
|
+
bytes: owned
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Returns a blob reference's payload bytes, or an empty view when the reference
|
|
148
|
+
* was never set.
|
|
149
|
+
*
|
|
150
|
+
* @param {{size:number,offset:number,bytes:Uint8Array}|null|undefined} ref Blob.
|
|
151
|
+
* @returns {Uint8Array} Owned-by-the-container view over the payload.
|
|
152
|
+
*/
|
|
153
|
+
function recordBytes(ref) {
|
|
154
|
+
const bytes = ref?.bytes;
|
|
155
|
+
return bytes instanceof Uint8Array ? bytes : new Uint8Array(0);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export { recordBytes, recordRawBits, recordRawValue, recordText, toRecordBlob, toRecordFloat, toRecordRawValue, toRecordText };
|
|
159
|
+
//# sourceMappingURL=carbonRecordFields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"carbonRecordFields.js","sources":["../../../../../src/resource/shader/reflection/carbonRecordFields.js"],"sourcesContent":["// Shared field accessors for Carbon v15 description records.\n//\n// The record tree is what the one Carbon effect reader emits\n// (`format/carbonEffect/carbonEffectRecords.js`). Each reflection class maps its\n// own record, but three field encodings recur across all of them and are worth\n// naming once rather than open-coding at every call site:\n//\n// - a string is an arena reference `{offset, value}`, not a string;\n// - an annotation value is four raw little-endian bytes, because Carbon writes\n// it through one union member and reads it through another, so the bytes are\n// the only faithful carrier;\n// - a blob is `{size, offset, bytes}` with `offset === 0xffffffff` meaning the\n// reference was never set, which is not the same as an empty payload.\n//\n// Both directions live here, as `recordX` and `toRecordX` pairs. They are held\n// apart by the round trip rather than by separation: records in, classes, records\n// out, compared byte for byte over the shipped corpus, so a mistake that\n// satisfied both sides would have to be an exact inverse of itself.\n\nconst rawValueBuffer = new DataView(new ArrayBuffer(4));\n\n/**\n * Reads the text out of an arena string reference.\n *\n * @param {{offset:number,value:string}|null|undefined} ref String reference.\n * @returns {string} The referenced text, or \"\" when unset.\n */\nexport function recordText(ref)\n{\n return String(ref?.value ?? \"\");\n}\n\n/**\n * Decodes an annotation record's four raw bytes as the `u32` bit pattern the\n * reflection classes carry as `rawValue`.\n *\n * Carbon stores the value as a `{float,int32_t}` union and the type byte decides\n * which member is meaningful, so the bits travel untyped and each annotation type\n * reinterprets them itself. Decoding to a number here — rather than to a float —\n * is what keeps a value like `-FLT_MAX` exact.\n *\n * @param {Uint8Array|null|undefined} bytes Four little-endian bytes.\n * @returns {number} The unsigned 32-bit pattern those bytes carry.\n */\nexport function recordRawValue(bytes)\n{\n if (!bytes || bytes.length < 4) return 0;\n rawValueBuffer.setUint8(0, bytes[0]);\n rawValueBuffer.setUint8(1, bytes[1]);\n rawValueBuffer.setUint8(2, bytes[2]);\n rawValueBuffer.setUint8(3, bytes[3]);\n return rawValueBuffer.getUint32(0, true);\n}\n\n/**\n * Re-encodes a record's `float` as the `u32` bit pattern the reflection classes\n * carry in their `*Raw` sampler fields.\n *\n * The container stores sampler LOD and border values as real floats, but the\n * class keeps the bits, so a value like `-FLT_MAX` survives serialization without\n * a decimal round trip. Reading the float and re-encoding it here is exact: the\n * record's value came from a `f32` read, so it is already representable.\n *\n * @param {number} value Float value from a sampler record.\n * @returns {number} The unsigned 32-bit pattern encoding that float.\n */\nexport function recordRawBits(value)\n{\n rawValueBuffer.setFloat32(0, Number.isFinite(value) ? value : 0, true);\n return rawValueBuffer.getUint32(0, true);\n}\n\n/**\n * Wraps text as the arena string reference the writer interns.\n *\n * The offset is always 0: the writer assigns real offsets while building the\n * arena, and any value here would be discarded. Carrying the text is the whole\n * job.\n *\n * @param {string} value Text value.\n * @returns {{offset:number,value:string}} String reference.\n */\nexport function toRecordText(value)\n{\n return { offset: 0, value: String(value ?? \"\") };\n}\n\n/**\n * Encodes a `u32` bit pattern as an annotation record's four raw bytes.\n *\n * The inverse of {@link recordRawValue}, and raw for the same reason: the value\n * is written through one union member and read through another, so no numeric\n * conversion may happen on the way out either.\n *\n * @param {number} rawValue Unsigned 32-bit pattern.\n * @returns {Uint8Array} Four little-endian bytes.\n */\nexport function toRecordRawValue(rawValue)\n{\n const bytes = new Uint8Array(4);\n rawValueBuffer.setUint32(0, rawValue >>> 0, true);\n for (let index = 0; index < 4; index += 1)\n {\n bytes[index] = rawValueBuffer.getUint8(index);\n }\n return bytes;\n}\n\n/**\n * Decodes a `*Raw` sampler field back to the float the record stores.\n *\n * The inverse of {@link recordRawBits}. Assigning the raw `u32` straight across\n * would write `4286578687.0` where the file says `-3.4028235e38`, and every\n * structural check in the container would accept it.\n *\n * @param {number} bits Raw 32-bit pattern.\n * @returns {number} The float those bits encode.\n */\nexport function toRecordFloat(bits)\n{\n rawValueBuffer.setUint32(0, (bits ?? 0) >>> 0, true);\n return rawValueBuffer.getFloat32(0, true);\n}\n\n/**\n * Wraps bytes as the record codec's sized blob reference.\n *\n * A zero-length blob keeps the offset word the file carried, because the writer\n * passes it straight through rather than interning anything. That word is\n * usually `0xffffffff`, but not always — measured across the shipped corpus,\n * 150 of 4833 files carry a live-looking offset behind a zero size, and\n * normalizing it changes the bytes and can make two distinct bodies collapse\n * into one. An empty payload and an absent one are not the same thing.\n *\n * @param {Uint8Array} bytes Payload bytes.\n * @param {number} [declaredSize] Size to declare when tracked separately.\n * @param {number} [unsetOffset] Offset word to keep when the size is zero.\n * @returns {{size:number,offset:number,bytes:Uint8Array}} Blob reference.\n */\nexport function toRecordBlob(bytes, declaredSize, unsetOffset = 0xffffffff)\n{\n const owned = bytes instanceof Uint8Array ? bytes : new Uint8Array(0);\n const size = declaredSize ?? owned.byteLength;\n return { size, offset: size === 0 ? (unsetOffset >>> 0) : 0, bytes: owned };\n}\n\n/**\n * Returns a blob reference's payload bytes, or an empty view when the reference\n * was never set.\n *\n * @param {{size:number,offset:number,bytes:Uint8Array}|null|undefined} ref Blob.\n * @returns {Uint8Array} Owned-by-the-container view over the payload.\n */\nexport function recordBytes(ref)\n{\n const bytes = ref?.bytes;\n return bytes instanceof Uint8Array ? bytes : new Uint8Array(0);\n}\n"],"names":["rawValueBuffer","DataView","ArrayBuffer","recordText","ref","String","value","recordRawValue","bytes","length","setUint8","getUint32","recordRawBits","setFloat32","Number","isFinite","toRecordText","offset","toRecordRawValue","rawValue","Uint8Array","setUint32","index","getUint8","toRecordFloat","bits","getFloat32","toRecordBlob","declaredSize","unsetOffset","owned","size","byteLength","recordBytes"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMA,cAAc,GAAG,IAAIC,QAAQ,CAAC,IAAIC,WAAW,CAAC,CAAC,CAAC,CAAC;;AAEvD;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,UAAUA,CAACC,GAAG,EAC9B;AACE,EAAA,OAAOC,MAAM,CAACD,GAAG,EAAEE,KAAK,IAAI,EAAE,CAAC;AACjC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,cAAcA,CAACC,KAAK,EACpC;EACE,IAAI,CAACA,KAAK,IAAIA,KAAK,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KAAK,IAAI,CAAC,EACzC;IACEd,KAAK,CAACc,KAAK,CAAC,GAAGtB,cAAc,CAACuB,QAAQ,CAACD,KAAK,CAAC;AAC/C,EAAA;AACA,EAAA,OAAOd,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASgB,aAAaA,CAACC,IAAI,EAClC;AACEzB,EAAAA,cAAc,CAACqB,SAAS,CAAC,CAAC,EAAE,CAACI,IAAI,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC;AACpD,EAAA,OAAOzB,cAAc,CAAC0B,UAAU,CAAC,CAAC,EAAE,IAAI,CAAC;AAC3C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,YAAYA,CAACnB,KAAK,EAAEoB,YAAY,EAAEC,WAAW,GAAG,UAAU,EAC1E;AACE,EAAA,MAAMC,KAAK,GAAGtB,KAAK,YAAYY,UAAU,GAAGZ,KAAK,GAAG,IAAIY,UAAU,CAAC,CAAC,CAAC;AACrE,EAAA,MAAMW,IAAI,GAAGH,YAAY,IAAIE,KAAK,CAACE,UAAU;EAC7C,OAAO;IAAED,IAAI;IAAEd,MAAM,EAAEc,IAAI,KAAK,CAAC,GAAIF,WAAW,KAAK,CAAC,GAAI,CAAC;AAAErB,IAAAA,KAAK,EAAEsB;GAAO;AAC7E;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,WAAWA,CAAC7B,GAAG,EAC/B;AACE,EAAA,MAAMI,KAAK,GAAGJ,GAAG,EAAEI,KAAK;EACxB,OAAOA,KAAK,YAAYY,UAAU,GAAGZ,KAAK,GAAG,IAAIY,UAAU,CAAC,CAAC,CAAC;AAChE;;;;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Number of shader stages Carbon's fixed-width stage array holds. */
|
|
2
|
+
const SHADER_STAGE_COUNT = 6;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Require one of Carbon's six authored shader-stage indices.
|
|
6
|
+
*
|
|
7
|
+
* Carbon addresses stages positionally through a fixed-width array on the pass
|
|
8
|
+
* (`Tr2EffectDescription.h`), so a stage type is an index into that array and
|
|
9
|
+
* nothing outside `[0, 5]` addresses anything.
|
|
10
|
+
*
|
|
11
|
+
* @param {number} value Candidate stage type.
|
|
12
|
+
* @returns {number} The validated stage type.
|
|
13
|
+
*/
|
|
14
|
+
function requireShaderStageType(value) {
|
|
15
|
+
if (!Number.isSafeInteger(value) || value < 0 || value >= SHADER_STAGE_COUNT) {
|
|
16
|
+
throw new RangeError(`Shader stage type must be in [0, ${SHADER_STAGE_COUNT - 1}]`);
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { SHADER_STAGE_COUNT, requireShaderStageType };
|
|
22
|
+
//# sourceMappingURL=shaderStage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shaderStage.js","sources":["../../../../../src/resource/shader/reflection/shaderStage.js"],"sourcesContent":["/** Number of shader stages Carbon's fixed-width stage array holds. */\nexport const SHADER_STAGE_COUNT = 6;\n\n/**\n * Require one of Carbon's six authored shader-stage indices.\n *\n * Carbon addresses stages positionally through a fixed-width array on the pass\n * (`Tr2EffectDescription.h`), so a stage type is an index into that array and\n * nothing outside `[0, 5]` addresses anything.\n *\n * @param {number} value Candidate stage type.\n * @returns {number} The validated stage type.\n */\nexport function requireShaderStageType(value)\n{\n if (!Number.isSafeInteger(value) || value < 0 || value >= SHADER_STAGE_COUNT)\n {\n throw new RangeError(\n `Shader stage type must be in [0, ${SHADER_STAGE_COUNT - 1}]`\n );\n }\n return value;\n}\n"],"names":["SHADER_STAGE_COUNT","requireShaderStageType","value","Number","isSafeInteger","RangeError"],"mappings":"AAAA;AACO,MAAMA,kBAAkB,GAAG;;AAElC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,sBAAsBA,CAACC,KAAK,EAC5C;AACE,EAAA,IAAI,CAACC,MAAM,CAACC,aAAa,CAACF,KAAK,CAAC,IAAIA,KAAK,GAAG,CAAC,IAAIA,KAAK,IAAIF,kBAAkB,EAC5E;IACE,MAAM,IAAIK,UAAU,CAClB,CAAA,iCAAA,EAAoCL,kBAAkB,GAAG,CAAC,GAC5D,CAAC;AACH,EAAA;AACA,EAAA,OAAOE,KAAK;AACd;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CjsSchema, impl, type } from '@carbonenginejs/runtime-utils/schema';
|
|
2
2
|
import { CjsModel } from '@carbonenginejs/runtime-utils/model';
|
|
3
3
|
import { isPlainObject } from '@carbonenginejs/runtime-utils/is';
|
|
4
|
-
import {
|
|
4
|
+
import { recordText, recordRawBits, toRecordFloat, toRecordText } from '../reflection/carbonRecordFields.js';
|
|
5
5
|
|
|
6
6
|
// Source: trinity/trinity/Shader/Tr2EffectDescription.h
|
|
7
7
|
|
|
@@ -39,22 +39,80 @@ class Tr2SamplerSetup extends CjsModel {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
|
-
* Build one sampler from its
|
|
42
|
+
* Build one dynamic sampler from its Carbon v15 description record.
|
|
43
43
|
*
|
|
44
|
-
*
|
|
44
|
+
* The name is kept whatever `isDynamic` says. Carbon nulls a non-dynamic
|
|
45
|
+
* sampler's name while reading (`Tr2EffectDescription.cpp:430-433`), but that
|
|
46
|
+
* is a runtime decision made on the way to a device — the file still carries
|
|
47
|
+
* the string, and this graph has to be able to re-emit the file it came from.
|
|
48
|
+
* Dropping it loses arena content: measured across the shipped corpus, this
|
|
49
|
+
* single rule accounted for every non-byte-identical re-emission.
|
|
50
|
+
*
|
|
51
|
+
* A consumer that wants Carbon's runtime view asks for it: the name is
|
|
52
|
+
* meaningful only when `isDynamic`.
|
|
53
|
+
*
|
|
54
|
+
* @param {object} record Carbon sampler record.
|
|
45
55
|
* @returns {Tr2SamplerSetup} Reflected sampler.
|
|
46
56
|
*/
|
|
47
|
-
static
|
|
48
|
-
if (!isPlainObject(
|
|
49
|
-
throw new TypeError("
|
|
57
|
+
static fromCarbonBinary(record) {
|
|
58
|
+
if (!isPlainObject(record)) {
|
|
59
|
+
throw new TypeError("Carbon effect sampler record must be an object");
|
|
50
60
|
}
|
|
51
61
|
const sampler = new this();
|
|
52
|
-
sampler.
|
|
53
|
-
sampler.name =
|
|
54
|
-
sampler.
|
|
55
|
-
sampler.
|
|
62
|
+
sampler.isDynamic = !!record.isDynamic;
|
|
63
|
+
sampler.name = recordText(record.name);
|
|
64
|
+
sampler.hasName = sampler.name !== "";
|
|
65
|
+
sampler.sampler = {
|
|
66
|
+
comparison: !!record.comparison,
|
|
67
|
+
minFilter: record.minFilter,
|
|
68
|
+
magFilter: record.magFilter,
|
|
69
|
+
mipFilter: record.mipFilter,
|
|
70
|
+
addressU: record.addressU,
|
|
71
|
+
addressV: record.addressV,
|
|
72
|
+
addressW: record.addressW,
|
|
73
|
+
mipLODBiasRaw: recordRawBits(record.mipLODBias),
|
|
74
|
+
maxAnisotropy: record.maxAnisotropy,
|
|
75
|
+
comparisonFunc: record.comparisonFunc,
|
|
76
|
+
borderColorRaw: (record.borderColor ?? []).map(recordRawBits),
|
|
77
|
+
minLODRaw: recordRawBits(record.minLOD),
|
|
78
|
+
maxLODRaw: recordRawBits(record.maxLOD)
|
|
79
|
+
};
|
|
56
80
|
return sampler;
|
|
57
81
|
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Emit this sampler as a Carbon v15 record.
|
|
85
|
+
*
|
|
86
|
+
* The name is written whether or not it is meaningful: Carbon's writer always
|
|
87
|
+
* emits the field, and the string it emits is the one the compiler authored,
|
|
88
|
+
* not the one Carbon's reader keeps.
|
|
89
|
+
*
|
|
90
|
+
* @param {number} registerIndex Register this sampler is bound at.
|
|
91
|
+
* @returns {object} Carbon sampler record.
|
|
92
|
+
*/
|
|
93
|
+
toCarbonBinary(registerIndex) {
|
|
94
|
+
const descriptor = this.sampler ?? {};
|
|
95
|
+
return {
|
|
96
|
+
registerIndex,
|
|
97
|
+
name: toRecordText(this.name),
|
|
98
|
+
comparison: descriptor.comparison ? 1 : 0,
|
|
99
|
+
minFilter: descriptor.minFilter,
|
|
100
|
+
magFilter: descriptor.magFilter,
|
|
101
|
+
mipFilter: descriptor.mipFilter,
|
|
102
|
+
addressU: descriptor.addressU,
|
|
103
|
+
addressV: descriptor.addressV,
|
|
104
|
+
addressW: descriptor.addressW,
|
|
105
|
+
mipLODBias: toRecordFloat(descriptor.mipLODBiasRaw),
|
|
106
|
+
maxAnisotropy: descriptor.maxAnisotropy,
|
|
107
|
+
comparisonFunc: descriptor.comparisonFunc,
|
|
108
|
+
// On one line deliberately: the raw-field guard requires the
|
|
109
|
+
// reinterpretation to be visible on the same line as the raw access.
|
|
110
|
+
borderColor: (descriptor.borderColorRaw ?? [0, 0, 0, 0]).slice(0, 4).map(toRecordFloat),
|
|
111
|
+
minLOD: toRecordFloat(descriptor.minLODRaw),
|
|
112
|
+
maxLOD: toRecordFloat(descriptor.maxLODRaw),
|
|
113
|
+
isDynamic: this.isDynamic ? 1 : 0
|
|
114
|
+
};
|
|
115
|
+
}
|
|
58
116
|
}
|
|
59
117
|
|
|
60
118
|
// Declared imperatively rather than with decorators, so this module stays
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tr2SamplerSetup.js","sources":["../../../../../src/resource/shader/sampler/Tr2SamplerSetup.js"],"sourcesContent":["// Source: trinity/trinity/Shader/Tr2EffectDescription.h\nimport { CjsSchema, impl, type } from \"@carbonenginejs/runtime-utils/schema\";\nimport { CjsModel } from \"@carbonenginejs/runtime-utils/model\";\nimport { isPlainObject } from \"@carbonenginejs/runtime-utils/is\";\nimport {
|
|
1
|
+
{"version":3,"file":"Tr2SamplerSetup.js","sources":["../../../../../src/resource/shader/sampler/Tr2SamplerSetup.js"],"sourcesContent":["// Source: trinity/trinity/Shader/Tr2EffectDescription.h\nimport { CjsSchema, impl, type } from \"@carbonenginejs/runtime-utils/schema\";\nimport { CjsModel } from \"@carbonenginejs/runtime-utils/model\";\nimport { isPlainObject } from \"@carbonenginejs/runtime-utils/is\";\nimport {\n recordRawBits,\n recordText,\n toRecordFloat,\n toRecordText\n} from \"../reflection/carbonRecordFields.js\";\n\n/** Reflected sampler name and complete device-free sampler descriptor. */\nexport class Tr2SamplerSetup extends CjsModel\n{\n\n /** name (const char*) */\n name = \"\";\n\n /** Whether the source sampler carried a name rather than authored null. */\n hasName = false;\n\n /** sampler (Tr2SamplerStateAL) */\n sampler = null;\n\n /** Whether the sampler occupies a dynamic register rather than static signature state. */\n isDynamic = false;\n\n /**\n * Construct a canonical sampler record from JS/JSON model values.\n *\n * @param {object} values Canonical model values.\n * @param {object} options CjsModel import options.\n * @returns {Tr2SamplerSetup} Hydrated sampler.\n */\n static from(values = {}, options = {})\n {\n let normalized = values;\n if (values && Object.hasOwn(values, \"name\")\n && !Object.hasOwn(values, \"hasName\"))\n {\n normalized = {\n ...values,\n hasName: values.name !== null,\n name: values.name === null ? \"\" : values.name\n };\n }\n return super.from(normalized, options);\n }\n\n /**\n * Build one dynamic sampler from its Carbon v15 description record.\n *\n * The name is kept whatever `isDynamic` says. Carbon nulls a non-dynamic\n * sampler's name while reading (`Tr2EffectDescription.cpp:430-433`), but that\n * is a runtime decision made on the way to a device — the file still carries\n * the string, and this graph has to be able to re-emit the file it came from.\n * Dropping it loses arena content: measured across the shipped corpus, this\n * single rule accounted for every non-byte-identical re-emission.\n *\n * A consumer that wants Carbon's runtime view asks for it: the name is\n * meaningful only when `isDynamic`.\n *\n * @param {object} record Carbon sampler record.\n * @returns {Tr2SamplerSetup} Reflected sampler.\n */\n static fromCarbonBinary(record)\n {\n if (!isPlainObject(record))\n {\n throw new TypeError(\"Carbon effect sampler record must be an object\");\n }\n\n const sampler = new this();\n sampler.isDynamic = !!record.isDynamic;\n sampler.name = recordText(record.name);\n sampler.hasName = sampler.name !== \"\";\n sampler.sampler = {\n comparison: !!record.comparison,\n minFilter: record.minFilter,\n magFilter: record.magFilter,\n mipFilter: record.mipFilter,\n addressU: record.addressU,\n addressV: record.addressV,\n addressW: record.addressW,\n mipLODBiasRaw: recordRawBits(record.mipLODBias),\n maxAnisotropy: record.maxAnisotropy,\n comparisonFunc: record.comparisonFunc,\n borderColorRaw: (record.borderColor ?? []).map(recordRawBits),\n minLODRaw: recordRawBits(record.minLOD),\n maxLODRaw: recordRawBits(record.maxLOD)\n };\n return sampler;\n }\n\n\n /**\n * Emit this sampler as a Carbon v15 record.\n *\n * The name is written whether or not it is meaningful: Carbon's writer always\n * emits the field, and the string it emits is the one the compiler authored,\n * not the one Carbon's reader keeps.\n *\n * @param {number} registerIndex Register this sampler is bound at.\n * @returns {object} Carbon sampler record.\n */\n toCarbonBinary(registerIndex)\n {\n const descriptor = this.sampler ?? {};\n return {\n registerIndex,\n name: toRecordText(this.name),\n comparison: descriptor.comparison ? 1 : 0,\n minFilter: descriptor.minFilter,\n magFilter: descriptor.magFilter,\n mipFilter: descriptor.mipFilter,\n addressU: descriptor.addressU,\n addressV: descriptor.addressV,\n addressW: descriptor.addressW,\n mipLODBias: toRecordFloat(descriptor.mipLODBiasRaw),\n maxAnisotropy: descriptor.maxAnisotropy,\n comparisonFunc: descriptor.comparisonFunc,\n // On one line deliberately: the raw-field guard requires the\n // reinterpretation to be visible on the same line as the raw access.\n borderColor: (descriptor.borderColorRaw ?? [ 0, 0, 0, 0 ]).slice(0, 4).map(toRecordFloat),\n minLOD: toRecordFloat(descriptor.minLODRaw),\n maxLOD: toRecordFloat(descriptor.maxLODRaw),\n isDynamic: this.isDynamic ? 1 : 0\n };\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(Tr2SamplerSetup, {\n className: \"Tr2SamplerSetup\",\n family: \"shader\",\n fields: {\n name: type.string,\n hasName: [ impl.adapted, impl.reason(\"The schema string field cannot distinguish an authored null sampler name from an empty name; portable reflection must retain that distinction for static sampler records.\"), type.boolean ],\n sampler: type.rawStruct(\"Tr2SamplerStateAL\"),\n isDynamic: [ impl.adapted, impl.reason(\"The portable effect contract distinguishes dynamic and static sampler declarations before an engine creates sampler state.\"), type.boolean ]\n }\n});\n"],"names":["Tr2SamplerSetup","CjsModel","name","hasName","sampler","isDynamic","from","values","options","normalized","Object","hasOwn","fromCarbonBinary","record","isPlainObject","TypeError","recordText","comparison","minFilter","magFilter","mipFilter","addressU","addressV","addressW","mipLODBiasRaw","recordRawBits","mipLODBias","maxAnisotropy","comparisonFunc","borderColorRaw","borderColor","map","minLODRaw","minLOD","maxLODRaw","maxLOD","toCarbonBinary","registerIndex","descriptor","toRecordText","toRecordFloat","slice","CjsSchema","define","className","family","fields","type","string","impl","adapted","reason","boolean","rawStruct"],"mappings":";;;;;AAAA;;AAWA;AACO,MAAMA,eAAe,SAASC,QAAQ,CAC7C;AAEE;AACAC,EAAAA,IAAI,GAAG,EAAE;;AAET;AACAC,EAAAA,OAAO,GAAG,KAAK;;AAEf;AACAC,EAAAA,OAAO,GAAG,IAAI;;AAEd;AACAC,EAAAA,SAAS,GAAG,KAAK;;AAEjB;AACF;AACA;AACA;AACA;AACA;AACA;EACE,OAAOC,IAAIA,CAACC,MAAM,GAAG,EAAE,EAAEC,OAAO,GAAG,EAAE,EACrC;IACE,IAAIC,UAAU,GAAGF,MAAM;IACvB,IAAIA,MAAM,IAAIG,MAAM,CAACC,MAAM,CAACJ,MAAM,EAAE,MAAM,CAAC,IACtC,CAACG,MAAM,CAACC,MAAM,CAACJ,MAAM,EAAE,SAAS,CAAC,EACtC;AACEE,MAAAA,UAAU,GAAG;AACX,QAAA,GAAGF,MAAM;AACTJ,QAAAA,OAAO,EAAEI,MAAM,CAACL,IAAI,KAAK,IAAI;QAC7BA,IAAI,EA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AAG,CAAC,GAAG;KACjC;AACH,EAAA;AAEF;;AAEA;AACA;AACA;AACA;AACA;AACAqC,SAAS,CAACC,MAAM,CAAC3C,eAAe,EAAE;AAChC4C,EAAAA,SAAS,EAAE,iBAAiB;AAC5BC,EAAAA,MAAM,EAAE,QAAQ;AAChBC,EAAAA,MAAM,EAAE;IACN5C,IAAI,EAAE6C,IAAI,CAACC,MAAM;AACjB7C,IAAAA,OAAO,EAAE,CAAE8C,IAAI,CAACC,OAAO,EAAED,IAAI,CAACE,MAAM,CAAC,2KAA2K,CAAC,EAAEJ,IAAI,CAACK,OAAO,CAAE;AACjOhD,IAAAA,OAAO,EAAE2C,IAAI,CAACM,SAAS,CAAC,mBAAmB,CAAC;AAC5ChD,IAAAA,SAAS,EAAE,CAAE4C,IAAI,CAACC,OAAO,EAAED,IAAI,CAACE,MAAM,CAAC,4HAA4H,CAAC,EAAEJ,IAAI,CAACK,OAAO;AACpL;AACF,CAAC,CAAC;;;;"}
|
|
@@ -33,10 +33,11 @@ class CjsResManMainThreadLoader {
|
|
|
33
33
|
* @param {object} descriptor Registered format descriptor.
|
|
34
34
|
* @param {*} input Reader input.
|
|
35
35
|
* @param {object} [formatOptions={}] Normalized format options.
|
|
36
|
+
* @param {object|null} [context=null] Normalized resource path context.
|
|
36
37
|
* @returns {Promise<*>} Format result.
|
|
37
38
|
*/
|
|
38
|
-
ReadFormat(descriptor, input, formatOptions = {}) {
|
|
39
|
-
return readFormatOnCurrentThread(descriptor, input, formatOptions);
|
|
39
|
+
ReadFormat(descriptor, input, formatOptions = {}, context = null) {
|
|
40
|
+
return readFormatOnCurrentThread(descriptor, input, formatOptions, context);
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
/**
|
|
@@ -55,25 +56,26 @@ class CjsResManMainThreadLoader {
|
|
|
55
56
|
* @param {object} descriptor Registered format descriptor.
|
|
56
57
|
* @param {*} input Reader input.
|
|
57
58
|
* @param {object} formatOptions Normalized format options.
|
|
59
|
+
* @param {object|null} context Normalized resource path context.
|
|
58
60
|
* @returns {Promise<*>} Reader result.
|
|
59
61
|
*/
|
|
60
|
-
function readFormatOnCurrentThread(descriptor, input, formatOptions = {}) {
|
|
62
|
+
function readFormatOnCurrentThread(descriptor, input, formatOptions = {}, context = null) {
|
|
61
63
|
const Format = descriptor?.Format;
|
|
62
64
|
if (typeof Format !== "function") {
|
|
63
65
|
throw new TypeError("Resource format descriptor requires a Format class.");
|
|
64
66
|
}
|
|
65
67
|
if (typeof Format.readAsync === "function") {
|
|
66
|
-
return Format.readAsync(input, formatOptions);
|
|
68
|
+
return Format.readAsync(input, formatOptions, context);
|
|
67
69
|
}
|
|
68
70
|
if (typeof Format.read === "function") {
|
|
69
|
-
return Format.read(input, formatOptions);
|
|
71
|
+
return Format.read(input, formatOptions, context);
|
|
70
72
|
}
|
|
71
73
|
const reader = new Format(formatOptions);
|
|
72
74
|
if (typeof reader.ReadAsync === "function") {
|
|
73
|
-
return reader.ReadAsync(input, formatOptions);
|
|
75
|
+
return reader.ReadAsync(input, formatOptions, context);
|
|
74
76
|
}
|
|
75
77
|
if (typeof reader.Read === "function") {
|
|
76
|
-
return reader.Read(input, formatOptions);
|
|
78
|
+
return reader.Read(input, formatOptions, context);
|
|
77
79
|
}
|
|
78
80
|
throw new TypeError(`${Format.name} does not expose a read operation.`);
|
|
79
81
|
}
|