@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,6 @@
|
|
|
1
1
|
import { CjsByteReader } from '../CjsByteReader.js';
|
|
2
2
|
import { CjsFormatReadError } from '../CjsFormatError.js';
|
|
3
|
-
import { CARBON_EFFECT_DATA_VERSION, readEffectDescription } from './carbonEffectRecords.js';
|
|
3
|
+
import { CARBON_EFFECT_MIN_DATA_VERSION, CARBON_EFFECT_DATA_VERSION, readEffectDescription } from './carbonEffectRecords.js';
|
|
4
4
|
|
|
5
5
|
// Source: trinity/trinity/Resources/Tr2EffectRes.cpp (DoLoad, GetShader)
|
|
6
6
|
// Source: trinity/shadercompiler/ShaderCompiler.cpp:746-845 (file assembly)
|
|
@@ -12,62 +12,88 @@ const CARBON_EFFECT_SOURCE_HASH_BYTES = 32;
|
|
|
12
12
|
/** Byte count of one offset-table row: `{u32 index, u32 offset, u32 size}`. */
|
|
13
13
|
const CARBON_EFFECT_RECORD_BYTES = 12;
|
|
14
14
|
|
|
15
|
-
/**
|
|
16
|
-
* Plain byte cursor over one description blob, carrying the Carbon effect error
|
|
17
|
-
* class and message.
|
|
18
|
-
*
|
|
19
|
-
* Separate from the container reader because the container reader parses its
|
|
20
|
-
* header in the constructor; a body needs a cursor, not a second header parse.
|
|
15
|
+
/**
|
|
16
|
+
* Plain byte cursor over one description blob, carrying the Carbon effect error
|
|
17
|
+
* class and message.
|
|
18
|
+
*
|
|
19
|
+
* Separate from the container reader because the container reader parses its
|
|
20
|
+
* header in the constructor; a body needs a cursor, not a second header parse.
|
|
21
21
|
*/
|
|
22
22
|
class CjsCarbonEffectBodyReader extends CjsByteReader {
|
|
23
23
|
static ReadError = CjsFormatReadError;
|
|
24
24
|
static endOfDataMessage = "Unexpected end of Carbon effect data";
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
/**
|
|
28
|
-
* Reader for Carbon's compiled-effect container
|
|
29
|
-
*
|
|
30
|
-
* The header is (`ShaderCompiler.cpp:822-831`):
|
|
31
|
-
*
|
|
32
|
-
* ```
|
|
33
|
-
* u32 version = 15
|
|
34
|
-
* u8[4] shaderCompilerVersion <- four bytes, not a u32
|
|
35
|
-
* char[32] sourceHash <- ASCII hex MD5 of the HLSL inputs
|
|
36
|
-
* u32 stringTableSize | arena
|
|
37
|
-
* u8 permutationCount | permutation records
|
|
38
|
-
* u32 recordCount | recordCount x { u32 index, u32 offset, u32 size }
|
|
39
|
-
* description blobs
|
|
40
|
-
* ```
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
27
|
+
/**
|
|
28
|
+
* Reader for Carbon's compiled-effect container, versions 8 through 15.
|
|
29
|
+
*
|
|
30
|
+
* The v15 header is (`ShaderCompiler.cpp:822-831`):
|
|
31
|
+
*
|
|
32
|
+
* ```
|
|
33
|
+
* u32 version = 15
|
|
34
|
+
* u8[4] shaderCompilerVersion <- four bytes, not a u32
|
|
35
|
+
* char[32] sourceHash <- ASCII hex MD5 of the HLSL inputs
|
|
36
|
+
* u32 stringTableSize | arena
|
|
37
|
+
* u8 permutationCount | permutation records
|
|
38
|
+
* u32 recordCount | recordCount x { u32 index, u32 offset, u32 size }
|
|
39
|
+
* description blobs
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* Versions 8..14 differ in the header by exactly one thing: the compiler
|
|
43
|
+
* version and source hash are absent, so `compilerVersion` and `sourceHash`
|
|
44
|
+
* are null for them. Everything else — arena, permutation records, offset
|
|
45
|
+
* table — is byte-identical across the accepted range.
|
|
46
|
+
*
|
|
47
|
+
* Carbon validates the version at 2..15 (`Tr2EffectRes.cpp:209`), then threads
|
|
48
|
+
* it through parsing rather than gating on it again: it forwards the version
|
|
49
|
+
* into the description reader (`Tr2EffectRes.cpp:128`), where
|
|
50
|
+
* `Tr2EffectDescription.cpp` branches at 22 conditional sites. The version
|
|
51
|
+
* decides the byte layout at nearly every level - whether a stage carries a
|
|
52
|
+
* register signature at all (`> 8`), where pipeline inputs are read (`< 14`),
|
|
53
|
+
* how a constant's type byte is decoded (`< 11`), and whether a resource
|
|
54
|
+
* carries `arrayElements` at all (`>= 13`).
|
|
55
|
+
*
|
|
56
|
+
* This reader carries the same parameter, restored per the 2026-08-02
|
|
57
|
+
* maintainer decision with 8 as the floor (see
|
|
58
|
+
* `CARBON_EFFECT_MIN_DATA_VERSION`). Reading a version is not supporting it:
|
|
59
|
+
* the reader's job ends at a correct record tree, normalized to the v15
|
|
60
|
+
* record shape, and what an engine can do with an old body is a separate
|
|
61
|
+
* question. Versions below 8 are still rejected outright — those branches
|
|
62
|
+
* have no examined file and no writer to check against, and applying newer
|
|
63
|
+
* rules to an older layout misaligns fields silently.
|
|
46
64
|
*/
|
|
47
65
|
class CjsCarbonEffectReader extends CjsCarbonEffectBodyReader {
|
|
48
66
|
/** Cursor class used for description blobs. */
|
|
49
67
|
static BodyReader = CjsCarbonEffectBodyReader;
|
|
50
68
|
|
|
51
|
-
/**
|
|
52
|
-
* Reads the container header, arena, permutation axes and offset table.
|
|
53
|
-
*
|
|
54
|
-
* @param {ArrayBuffer|ArrayBufferView|Uint8Array} bytes Container bytes.
|
|
55
|
-
* @param {object} [options] Read options.
|
|
56
|
-
* @param {string} [options.source] Source name used in error details.
|
|
57
|
-
* @param {boolean} [options.permissive] Accept a sparse or misordered offset
|
|
58
|
-
* table instead of rejecting it. For forensic inspection of a file already
|
|
59
|
-
* known to be malformed; never for a load path.
|
|
69
|
+
/**
|
|
70
|
+
* Reads the container header, arena, permutation axes and offset table.
|
|
71
|
+
*
|
|
72
|
+
* @param {ArrayBuffer|ArrayBufferView|Uint8Array} bytes Container bytes.
|
|
73
|
+
* @param {object} [options] Read options.
|
|
74
|
+
* @param {string} [options.source] Source name used in error details.
|
|
75
|
+
* @param {boolean} [options.permissive] Accept a sparse or misordered offset
|
|
76
|
+
* table instead of rejecting it. For forensic inspection of a file already
|
|
77
|
+
* known to be malformed; never for a load path.
|
|
60
78
|
*/
|
|
61
79
|
constructor(bytes, options = {}) {
|
|
62
80
|
super(bytes, options);
|
|
63
81
|
this.version = this.readUint32();
|
|
64
|
-
if (this.version
|
|
65
|
-
throw this._error(`Unsupported Carbon effect version ${this.version}; expected ${CARBON_EFFECT_DATA_VERSION}`, {
|
|
82
|
+
if (this.version < CARBON_EFFECT_MIN_DATA_VERSION || this.version > CARBON_EFFECT_DATA_VERSION) {
|
|
83
|
+
throw this._error(`Unsupported Carbon effect version ${this.version}; expected ${CARBON_EFFECT_MIN_DATA_VERSION}..${CARBON_EFFECT_DATA_VERSION}`, {
|
|
66
84
|
version: this.version
|
|
67
85
|
});
|
|
68
86
|
}
|
|
69
|
-
|
|
70
|
-
|
|
87
|
+
|
|
88
|
+
// The compiler version and source hash are the v15 header additions;
|
|
89
|
+
// an older header goes straight from the version to the arena.
|
|
90
|
+
if (this.version === CARBON_EFFECT_DATA_VERSION) {
|
|
91
|
+
this.compilerVersion = Array.from(this.readRaw(4));
|
|
92
|
+
this.sourceHash = Uint8Array.from(this.readRaw(CARBON_EFFECT_SOURCE_HASH_BYTES));
|
|
93
|
+
} else {
|
|
94
|
+
this.compilerVersion = null;
|
|
95
|
+
this.sourceHash = null;
|
|
96
|
+
}
|
|
71
97
|
this.stringTableSize = this.readUint32();
|
|
72
98
|
if (this.offset + this.stringTableSize > this.bytes.length) {
|
|
73
99
|
throw this._error("Invalid Carbon effect string-table size", {
|
|
@@ -87,11 +113,11 @@ class CjsCarbonEffectReader extends CjsCarbonEffectBodyReader {
|
|
|
87
113
|
}
|
|
88
114
|
}
|
|
89
115
|
|
|
90
|
-
/**
|
|
91
|
-
* Returns the product of the permutation axes' option counts — the number of
|
|
92
|
-
* offset-table rows a fully populated file has.
|
|
93
|
-
*
|
|
94
|
-
* @returns {number} Permutation count.
|
|
116
|
+
/**
|
|
117
|
+
* Returns the product of the permutation axes' option counts — the number of
|
|
118
|
+
* offset-table rows a fully populated file has.
|
|
119
|
+
*
|
|
120
|
+
* @returns {number} Permutation count.
|
|
95
121
|
*/
|
|
96
122
|
get permutationProduct() {
|
|
97
123
|
let product = 1;
|
|
@@ -101,26 +127,26 @@ class CjsCarbonEffectReader extends CjsCarbonEffectBodyReader {
|
|
|
101
127
|
return product;
|
|
102
128
|
}
|
|
103
129
|
|
|
104
|
-
/**
|
|
105
|
-
* Throws unless the offset table is dense and positionally indexed.
|
|
106
|
-
*
|
|
107
|
-
* Carbon indexes `m_offsets` positionally and never reads the stored `index`
|
|
108
|
-
* field (`Tr2EffectRes.cpp:121-126`), so a sparse or misordered table does
|
|
109
|
-
* not fail — it silently returns the wrong shader body. Carbon gets density
|
|
110
|
-
* incidentally, from `g_compiledEffects` being a `std::map` densely keyed by
|
|
111
|
-
* `AddPermutationsToWorkQueue`, and promises it nowhere.
|
|
112
|
-
*
|
|
113
|
-
* Measured across the whole shipped corpus at build 3444265 — 4833 files and
|
|
114
|
-
* 78,498 rows across `effect.dx11`, `effect.dx12` and `effect.metal` — both
|
|
115
|
-
* conditions hold in every file, so this runs by default.
|
|
116
|
-
*
|
|
117
|
-
* `--ignore-permutations` does make CCP's compiler emit only key 0 while
|
|
118
|
-
* declaring every axis, so a sparse file is producible. That argues for an
|
|
119
|
-
* escape hatch, not for permissiveness: because Carbon indexes positionally,
|
|
120
|
-
* accepting such a file returns the wrong permutation's shader silently, which
|
|
121
|
-
* is exactly the failure class this container port exists to close.
|
|
122
|
-
* `{ permissive: true }` is the opt-in, for inspecting a file already known to
|
|
123
|
-
* be malformed.
|
|
130
|
+
/**
|
|
131
|
+
* Throws unless the offset table is dense and positionally indexed.
|
|
132
|
+
*
|
|
133
|
+
* Carbon indexes `m_offsets` positionally and never reads the stored `index`
|
|
134
|
+
* field (`Tr2EffectRes.cpp:121-126`), so a sparse or misordered table does
|
|
135
|
+
* not fail — it silently returns the wrong shader body. Carbon gets density
|
|
136
|
+
* incidentally, from `g_compiledEffects` being a `std::map` densely keyed by
|
|
137
|
+
* `AddPermutationsToWorkQueue`, and promises it nowhere.
|
|
138
|
+
*
|
|
139
|
+
* Measured across the whole shipped corpus at build 3444265 — 4833 files and
|
|
140
|
+
* 78,498 rows across `effect.dx11`, `effect.dx12` and `effect.metal` — both
|
|
141
|
+
* conditions hold in every file, so this runs by default.
|
|
142
|
+
*
|
|
143
|
+
* `--ignore-permutations` does make CCP's compiler emit only key 0 while
|
|
144
|
+
* declaring every axis, so a sparse file is producible. That argues for an
|
|
145
|
+
* escape hatch, not for permissiveness: because Carbon indexes positionally,
|
|
146
|
+
* accepting such a file returns the wrong permutation's shader silently, which
|
|
147
|
+
* is exactly the failure class this container port exists to close.
|
|
148
|
+
* `{ permissive: true }` is the opt-in, for inspecting a file already known to
|
|
149
|
+
* be malformed.
|
|
124
150
|
*/
|
|
125
151
|
requireDensePermutationTable() {
|
|
126
152
|
if (!this.diagnostics.dense) {
|
|
@@ -136,32 +162,32 @@ class CjsCarbonEffectReader extends CjsCarbonEffectBodyReader {
|
|
|
136
162
|
}
|
|
137
163
|
}
|
|
138
164
|
|
|
139
|
-
/**
|
|
140
|
-
* Reads and parses one permutation's description blob.
|
|
141
|
-
*
|
|
142
|
-
* `backend` is **optional**, and omitting it is the interesting case. A
|
|
143
|
-
* Carbon file ends each pass at the render states; ours adds one eight-byte
|
|
144
|
-
* block reference. Nothing in the header distinguishes the two, and we
|
|
145
|
-
* deliberately do not add anything — no envelope, no version of our own,
|
|
146
|
-
* because CCP owns the version space and a container that announces itself
|
|
147
|
-
* is an invention nothing requires.
|
|
148
|
-
*
|
|
149
|
-
* Instead the blob describes itself, using a rule the format already has.
|
|
150
|
-
* Every sized record must parse to exactly its declared end (Rule 1), and a
|
|
151
|
-
* body's declared size is in the offset table. So the wrong interpretation
|
|
152
|
-
* either throws or leaves the cursor somewhere other than the end, and one
|
|
153
|
-
* retry settles it.
|
|
154
|
-
*
|
|
155
|
-
* Pass `backend` explicitly when the caller knows — the loader does, because
|
|
156
|
-
* backend selection is by resource path, mirroring Carbon's
|
|
157
|
-
* `effect.dx11`/`effect.dx12`/`effect.metal`. Auto-detection is for bytes
|
|
158
|
-
* that arrive without that context: tooling, caches, inspection.
|
|
159
|
-
*
|
|
160
|
-
* @param {number} index Permutation index, positional in the offset table.
|
|
161
|
-
* @param {object} [options] Read options.
|
|
162
|
-
* @param {boolean} [options.backend] Expect our optional per-pass trailing
|
|
163
|
-
* block. Omit to detect it from the blob's declared end.
|
|
164
|
-
* @returns {object} Description record tree.
|
|
165
|
+
/**
|
|
166
|
+
* Reads and parses one permutation's description blob.
|
|
167
|
+
*
|
|
168
|
+
* `backend` is **optional**, and omitting it is the interesting case. A
|
|
169
|
+
* Carbon file ends each pass at the render states; ours adds one eight-byte
|
|
170
|
+
* block reference. Nothing in the header distinguishes the two, and we
|
|
171
|
+
* deliberately do not add anything — no envelope, no version of our own,
|
|
172
|
+
* because CCP owns the version space and a container that announces itself
|
|
173
|
+
* is an invention nothing requires.
|
|
174
|
+
*
|
|
175
|
+
* Instead the blob describes itself, using a rule the format already has.
|
|
176
|
+
* Every sized record must parse to exactly its declared end (Rule 1), and a
|
|
177
|
+
* body's declared size is in the offset table. So the wrong interpretation
|
|
178
|
+
* either throws or leaves the cursor somewhere other than the end, and one
|
|
179
|
+
* retry settles it.
|
|
180
|
+
*
|
|
181
|
+
* Pass `backend` explicitly when the caller knows — the loader does, because
|
|
182
|
+
* backend selection is by resource path, mirroring Carbon's
|
|
183
|
+
* `effect.dx11`/`effect.dx12`/`effect.metal`. Auto-detection is for bytes
|
|
184
|
+
* that arrive without that context: tooling, caches, inspection.
|
|
185
|
+
*
|
|
186
|
+
* @param {number} index Permutation index, positional in the offset table.
|
|
187
|
+
* @param {object} [options] Read options.
|
|
188
|
+
* @param {boolean} [options.backend] Expect our optional per-pass trailing
|
|
189
|
+
* block. Omit to detect it from the blob's declared end.
|
|
190
|
+
* @returns {object} Description record tree.
|
|
165
191
|
*/
|
|
166
192
|
readDescription(index, options = {}) {
|
|
167
193
|
const record = this.records[index];
|
|
@@ -192,12 +218,12 @@ class CjsCarbonEffectReader extends CjsCarbonEffectBodyReader {
|
|
|
192
218
|
}
|
|
193
219
|
}
|
|
194
220
|
|
|
195
|
-
/**
|
|
196
|
-
* Parses one body under an exact backend-block assumption.
|
|
197
|
-
*
|
|
198
|
-
* @param {object} record Offset-table row.
|
|
199
|
-
* @param {boolean} backend Whether to expect the per-pass block.
|
|
200
|
-
* @returns {object} Description record tree.
|
|
221
|
+
/**
|
|
222
|
+
* Parses one body under an exact backend-block assumption.
|
|
223
|
+
*
|
|
224
|
+
* @param {object} record Offset-table row.
|
|
225
|
+
* @param {boolean} backend Whether to expect the per-pass block.
|
|
226
|
+
* @returns {object} Description record tree.
|
|
201
227
|
*/
|
|
202
228
|
#readDescriptionAs(record, backend) {
|
|
203
229
|
const reader = new this.constructor.BodyReader(this.bytes, {
|
|
@@ -208,15 +234,16 @@ class CjsCarbonEffectReader extends CjsCarbonEffectBodyReader {
|
|
|
208
234
|
stringTableSize: this.stringTableSize
|
|
209
235
|
});
|
|
210
236
|
return readEffectDescription(reader, {
|
|
211
|
-
backend
|
|
237
|
+
backend,
|
|
238
|
+
version: this.version
|
|
212
239
|
});
|
|
213
240
|
}
|
|
214
241
|
|
|
215
|
-
/**
|
|
216
|
-
* Returns the raw description-blob bytes for one permutation.
|
|
217
|
-
*
|
|
218
|
-
* @param {number} index Permutation index, positional in the offset table.
|
|
219
|
-
* @returns {Uint8Array} View over the body bytes.
|
|
242
|
+
/**
|
|
243
|
+
* Returns the raw description-blob bytes for one permutation.
|
|
244
|
+
*
|
|
245
|
+
* @param {number} index Permutation index, positional in the offset table.
|
|
246
|
+
* @returns {Uint8Array} View over the body bytes.
|
|
220
247
|
*/
|
|
221
248
|
bodyBytes(index) {
|
|
222
249
|
const record = this.records[index];
|
|
@@ -228,11 +255,11 @@ class CjsCarbonEffectReader extends CjsCarbonEffectBodyReader {
|
|
|
228
255
|
return this.bytes.subarray(record.offset, record.offset + record.size);
|
|
229
256
|
}
|
|
230
257
|
|
|
231
|
-
/**
|
|
232
|
-
* Reads the permutation axis records (`ShaderCompiler.cpp:769-795`,
|
|
233
|
-
* `Tr2EffectRes.cpp:263-292`).
|
|
234
|
-
*
|
|
235
|
-
* @returns {object[]} Permutation axes with arena references retained.
|
|
258
|
+
/**
|
|
259
|
+
* Reads the permutation axis records (`ShaderCompiler.cpp:769-795`,
|
|
260
|
+
* `Tr2EffectRes.cpp:263-292`).
|
|
261
|
+
*
|
|
262
|
+
* @returns {object[]} Permutation axes with arena references retained.
|
|
236
263
|
*/
|
|
237
264
|
#readPermutations() {
|
|
238
265
|
const permutations = [];
|
|
@@ -270,11 +297,11 @@ class CjsCarbonEffectReader extends CjsCarbonEffectBodyReader {
|
|
|
270
297
|
return permutations;
|
|
271
298
|
}
|
|
272
299
|
|
|
273
|
-
/**
|
|
274
|
-
* Reads the offset table (`ShaderCompiler.cpp:800-820`,
|
|
275
|
-
* `Tr2EffectRes.cpp:294-311`).
|
|
276
|
-
*
|
|
277
|
-
* @returns {object[]} Offset-table rows.
|
|
300
|
+
/**
|
|
301
|
+
* Reads the offset table (`ShaderCompiler.cpp:800-820`,
|
|
302
|
+
* `Tr2EffectRes.cpp:294-311`).
|
|
303
|
+
*
|
|
304
|
+
* @returns {object[]} Offset-table rows.
|
|
278
305
|
*/
|
|
279
306
|
#readRecords() {
|
|
280
307
|
const count = this.readUint32();
|
|
@@ -298,11 +325,11 @@ class CjsCarbonEffectReader extends CjsCarbonEffectBodyReader {
|
|
|
298
325
|
return records;
|
|
299
326
|
}
|
|
300
327
|
|
|
301
|
-
/**
|
|
302
|
-
* Validates every row's byte range and collects the structural diagnostics
|
|
303
|
-
* Carbon relies on without stating.
|
|
304
|
-
*
|
|
305
|
-
* @returns {object} Structural diagnostics.
|
|
328
|
+
/**
|
|
329
|
+
* Validates every row's byte range and collects the structural diagnostics
|
|
330
|
+
* Carbon relies on without stating.
|
|
331
|
+
*
|
|
332
|
+
* @returns {object} Structural diagnostics.
|
|
306
333
|
*/
|
|
307
334
|
#inspect() {
|
|
308
335
|
const headerEnd = this.headerEnd;
|
|
@@ -357,5 +384,25 @@ class CjsCarbonEffectReader extends CjsCarbonEffectBodyReader {
|
|
|
357
384
|
}
|
|
358
385
|
}
|
|
359
386
|
|
|
360
|
-
|
|
387
|
+
/**
|
|
388
|
+
* Reports whether a payload has the Carbon effect container shape.
|
|
389
|
+
*
|
|
390
|
+
* A **shape** check, not an identity check, and the distinction is the point:
|
|
391
|
+
* our containers are stock Carbon files, so nothing in the bytes separates one
|
|
392
|
+
* from a shipped `effect.dx11`. Identity comes from the resource path the file
|
|
393
|
+
* was resolved through - `effect.webgl/` versus `effect.dx11/` - exactly as it
|
|
394
|
+
* does for Carbon, whose own backend trees are byte-format-identical.
|
|
395
|
+
*
|
|
396
|
+
* Both backend sniffs call this rather than each keeping a copy of the version
|
|
397
|
+
* dword. Two hand-written copies of one constant are two chances to disagree.
|
|
398
|
+
*
|
|
399
|
+
* @param {Uint8Array} bytes Candidate payload.
|
|
400
|
+
* @returns {boolean} True when the payload opens on Carbon's version dword.
|
|
401
|
+
*/
|
|
402
|
+
function looksLikeCarbonEffectContainer(bytes) {
|
|
403
|
+
if (!bytes || bytes.length < 4) return false;
|
|
404
|
+
return bytes[0] === CARBON_EFFECT_DATA_VERSION && bytes[1] === 0 && bytes[2] === 0 && bytes[3] === 0;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
export { CARBON_EFFECT_RECORD_BYTES, CARBON_EFFECT_SOURCE_HASH_BYTES, CjsCarbonEffectBodyReader, CjsCarbonEffectReader, looksLikeCarbonEffectContainer };
|
|
361
408
|
//# sourceMappingURL=CjsCarbonEffectReader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CjsCarbonEffectReader.js","sources":["../../../../src/format/carbonEffect/CjsCarbonEffectReader.js"],"sourcesContent":["// Source: trinity/trinity/Resources/Tr2EffectRes.cpp (DoLoad, GetShader)\n// Source: trinity/shadercompiler/ShaderCompiler.cpp:746-845 (file assembly)\n\nimport { CjsByteReader } from \"../CjsByteReader.js\";\nimport { CjsFormatReadError } from \"../CjsFormatError.js\";\nimport { CARBON_EFFECT_DATA_VERSION, readEffectDescription } from \"./carbonEffectRecords.js\";\n\n/** Byte count of the ASCII-hex MD5 source hash in the v15 header. */\nexport const CARBON_EFFECT_SOURCE_HASH_BYTES = 32;\n\n/** Byte count of one offset-table row: `{u32 index, u32 offset, u32 size}`. */\nexport const CARBON_EFFECT_RECORD_BYTES = 12;\n\n/**\n * Plain byte cursor over one description blob, carrying the Carbon effect error\n * class and message.\n *\n * Separate from the container reader because the container reader parses its\n * header in the constructor; a body needs a cursor, not a second header parse.\n */\nexport class CjsCarbonEffectBodyReader extends CjsByteReader\n{\n static ReadError = CjsFormatReadError;\n\n static endOfDataMessage = \"Unexpected end of Carbon effect data\";\n}\n\n/**\n * Reader for Carbon's compiled-effect container at version 15.\n *\n * The header is (`ShaderCompiler.cpp:822-831`):\n *\n * ```\n * u32 version = 15\n * u8[4] shaderCompilerVersion <- four bytes, not a u32\n * char[32] sourceHash <- ASCII hex MD5 of the HLSL inputs\n * u32 stringTableSize | arena\n * u8 permutationCount | permutation records\n * u32 recordCount | recordCount x { u32 index, u32 offset, u32 size }\n * description blobs\n * ```\n *\n * Only version 15 is accepted. Carbon's own reader takes 2..15\n * (`Tr2EffectRes.cpp:209`) but marks the v13/v14 field-order boundaries\n * unverified, and every file in the shipped dx11/dx12 corpus is v15, so a\n * lower version here means something unexpected rather than something old.\n */\nexport class CjsCarbonEffectReader extends CjsCarbonEffectBodyReader\n{\n /** Cursor class used for description blobs. */\n static BodyReader = CjsCarbonEffectBodyReader;\n\n /**\n * Reads the container header, arena, permutation axes and offset table.\n *\n * @param {ArrayBuffer|ArrayBufferView|Uint8Array} bytes Container bytes.\n * @param {object} [options] Read options.\n * @param {string} [options.source] Source name used in error details.\n * @param {boolean} [options.permissive] Accept a sparse or misordered offset\n * table instead of rejecting it. For forensic inspection of a file already\n * known to be malformed; never for a load path.\n */\n constructor(bytes, options = {})\n {\n super(bytes, options);\n\n this.version = this.readUint32();\n if (this.version !== CARBON_EFFECT_DATA_VERSION)\n {\n throw this._error(\n `Unsupported Carbon effect version ${this.version}; expected ${CARBON_EFFECT_DATA_VERSION}`,\n { version: this.version }\n );\n }\n\n this.compilerVersion = Array.from(this.readRaw(4));\n this.sourceHash = Uint8Array.from(this.readRaw(CARBON_EFFECT_SOURCE_HASH_BYTES));\n\n this.stringTableSize = this.readUint32();\n if (this.offset + this.stringTableSize > this.bytes.length)\n {\n throw this._error(\"Invalid Carbon effect string-table size\", {\n stringTableSize: this.stringTableSize,\n byteLength: this.bytes.length\n });\n }\n this.stringTableBytes = this.bytes.subarray(this.offset, this.offset + this.stringTableSize);\n this.skip(this.stringTableSize);\n this.setStringTable(this.stringTableBytes, this.stringTableSize);\n\n this.permutations = this.#readPermutations();\n this.records = this.#readRecords();\n this.headerEnd = this.offset;\n this.diagnostics = this.#inspect();\n\n if (!options.permissive)\n {\n this.requireDensePermutationTable();\n }\n }\n\n /**\n * Returns the product of the permutation axes' option counts — the number of\n * offset-table rows a fully populated file has.\n *\n * @returns {number} Permutation count.\n */\n get permutationProduct()\n {\n let product = 1;\n for (const permutation of this.permutations)\n {\n product *= permutation.options.length;\n }\n return product;\n }\n\n /**\n * Throws unless the offset table is dense and positionally indexed.\n *\n * Carbon indexes `m_offsets` positionally and never reads the stored `index`\n * field (`Tr2EffectRes.cpp:121-126`), so a sparse or misordered table does\n * not fail — it silently returns the wrong shader body. Carbon gets density\n * incidentally, from `g_compiledEffects` being a `std::map` densely keyed by\n * `AddPermutationsToWorkQueue`, and promises it nowhere.\n *\n * Measured across the whole shipped corpus at build 3444265 — 4833 files and\n * 78,498 rows across `effect.dx11`, `effect.dx12` and `effect.metal` — both\n * conditions hold in every file, so this runs by default.\n *\n * `--ignore-permutations` does make CCP's compiler emit only key 0 while\n * declaring every axis, so a sparse file is producible. That argues for an\n * escape hatch, not for permissiveness: because Carbon indexes positionally,\n * accepting such a file returns the wrong permutation's shader silently, which\n * is exactly the failure class this container port exists to close.\n * `{ permissive: true }` is the opt-in, for inspecting a file already known to\n * be malformed.\n */\n requireDensePermutationTable()\n {\n if (!this.diagnostics.dense)\n {\n throw this._error(\"Carbon effect offset table is sparse\", {\n recordCount: this.records.length,\n permutationProduct: this.permutationProduct\n });\n }\n if (!this.diagnostics.indicesMatchPosition)\n {\n throw this._error(\"Carbon effect offset table is not positionally indexed\", {\n firstMismatch: this.diagnostics.firstIndexMismatch\n });\n }\n }\n\n /**\n * Reads and parses one permutation's description blob.\n *\n * `backend` is **optional**, and omitting it is the interesting case. A\n * Carbon file ends each pass at the render states; ours adds one eight-byte\n * block reference. Nothing in the header distinguishes the two, and we\n * deliberately do not add anything — no envelope, no version of our own,\n * because CCP owns the version space and a container that announces itself\n * is an invention nothing requires.\n *\n * Instead the blob describes itself, using a rule the format already has.\n * Every sized record must parse to exactly its declared end (Rule 1), and a\n * body's declared size is in the offset table. So the wrong interpretation\n * either throws or leaves the cursor somewhere other than the end, and one\n * retry settles it.\n *\n * Pass `backend` explicitly when the caller knows — the loader does, because\n * backend selection is by resource path, mirroring Carbon's\n * `effect.dx11`/`effect.dx12`/`effect.metal`. Auto-detection is for bytes\n * that arrive without that context: tooling, caches, inspection.\n *\n * @param {number} index Permutation index, positional in the offset table.\n * @param {object} [options] Read options.\n * @param {boolean} [options.backend] Expect our optional per-pass trailing\n * block. Omit to detect it from the blob's declared end.\n * @returns {object} Description record tree.\n */\n readDescription(index, options = {})\n {\n const record = this.records[index];\n if (!record)\n {\n throw this._error(`No Carbon effect body at permutation index ${index}`, {\n index,\n recordCount: this.records.length\n });\n }\n\n if (options.backend !== undefined)\n {\n return this.#readDescriptionAs(record, options.backend === true);\n }\n\n // Plain Carbon first: it is the larger population, and it is the reading\n // that must stay cheap.\n try\n {\n return this.#readDescriptionAs(record, false);\n }\n catch (withoutBlocks)\n {\n try\n {\n return this.#readDescriptionAs(record, true);\n }\n catch\n {\n // Report the plain-Carbon failure. If neither reading works the\n // blob is malformed, and the Carbon diagnosis is the useful one;\n // the backend attempt's error would describe a misparse of bytes\n // that were never a backend block.\n throw withoutBlocks;\n }\n }\n }\n\n /**\n * Parses one body under an exact backend-block assumption.\n *\n * @param {object} record Offset-table row.\n * @param {boolean} backend Whether to expect the per-pass block.\n * @returns {object} Description record tree.\n */\n #readDescriptionAs(record, backend)\n {\n const reader = new this.constructor.BodyReader(this.bytes, {\n source: this.source,\n offset: record.offset,\n end: record.offset + record.size,\n stringTable: this.stringTableBytes,\n stringTableSize: this.stringTableSize\n });\n return readEffectDescription(reader, { backend });\n }\n\n /**\n * Returns the raw description-blob bytes for one permutation.\n *\n * @param {number} index Permutation index, positional in the offset table.\n * @returns {Uint8Array} View over the body bytes.\n */\n bodyBytes(index)\n {\n const record = this.records[index];\n if (!record)\n {\n throw this._error(`No Carbon effect body at permutation index ${index}`, { index });\n }\n return this.bytes.subarray(record.offset, record.offset + record.size);\n }\n\n /**\n * Reads the permutation axis records (`ShaderCompiler.cpp:769-795`,\n * `Tr2EffectRes.cpp:263-292`).\n *\n * @returns {object[]} Permutation axes with arena references retained.\n */\n #readPermutations()\n {\n const permutations = [];\n const count = this.readUint8();\n for (let index = 0; index < count; index += 1)\n {\n const nameOffset = this.readUint32();\n const name = this.readStringAt(nameOffset);\n const defaultOption = this.readUint8();\n const descriptionOffset = this.readUint32();\n const description = this.readStringAt(descriptionOffset);\n const type = this.readUint8();\n\n const options = [];\n const optionCount = this.readUint8();\n for (let optionIndex = 0; optionIndex < optionCount; optionIndex += 1)\n {\n const offset = this.readUint32();\n options.push({ offset, value: this.readStringAt(offset) });\n }\n\n permutations.push({\n name: { offset: nameOffset, value: name },\n defaultOption,\n description: { offset: descriptionOffset, value: description },\n type,\n options\n });\n }\n return permutations;\n }\n\n /**\n * Reads the offset table (`ShaderCompiler.cpp:800-820`,\n * `Tr2EffectRes.cpp:294-311`).\n *\n * @returns {object[]} Offset-table rows.\n */\n #readRecords()\n {\n const count = this.readUint32();\n if (count === 0)\n {\n throw this._error(\"Carbon effect contains no compiled bodies\");\n }\n if (this.offset + count * CARBON_EFFECT_RECORD_BYTES > this.bytes.length)\n {\n throw this._error(\"Carbon effect offset table runs past the end of the file\", {\n recordCount: count,\n byteLength: this.bytes.length\n });\n }\n\n const records = [];\n for (let index = 0; index < count; index += 1)\n {\n records.push({\n index: this.readUint32(),\n offset: this.readUint32(),\n size: this.readUint32()\n });\n }\n return records;\n }\n\n /**\n * Validates every row's byte range and collects the structural diagnostics\n * Carbon relies on without stating.\n *\n * @returns {object} Structural diagnostics.\n */\n #inspect()\n {\n const headerEnd = this.headerEnd;\n const byteLength = this.bytes.length;\n let firstIndexMismatch = null;\n const uniqueOffsets = new Set();\n\n for (let index = 0; index < this.records.length; index += 1)\n {\n const record = this.records[index];\n if (record.index !== index && firstIndexMismatch === null)\n {\n firstIndexMismatch = { position: index, storedIndex: record.index };\n }\n const end = record.offset + record.size;\n if (record.offset < headerEnd || end > byteLength || record.size === 0)\n {\n throw this._error(`Carbon effect body record ${index} is out of range`, {\n position: index,\n offset: record.offset,\n size: record.size,\n headerEnd,\n byteLength\n });\n }\n uniqueOffsets.add(record.offset);\n }\n\n // The body region must begin exactly where the header ends. Carbon computes\n // its first body offset as `4 + 4 + 32 + headerSize + stringTable.GetSize()`\n // (`ShaderCompiler.cpp:801`), so a gap or an overlap means our reconstruction\n // of that arithmetic disagrees with the writer's — which would silently\n // misread every body rather than fail. Carbon's own reader does not check\n // this; measured across 4833 shipped files, every one starts its body region\n // flush against the header with no slack.\n const firstBody = Math.min(...this.records.map((record) => record.offset));\n if (firstBody !== headerEnd)\n {\n throw this._error(\"Carbon effect body region does not start where the header ends\", {\n firstBody,\n headerEnd,\n slack: firstBody - headerEnd\n });\n }\n\n return {\n recordCount: this.records.length,\n permutationProduct: this.permutationProduct,\n dense: this.records.length === this.permutationProduct,\n indicesMatchPosition: firstIndexMismatch === null,\n firstIndexMismatch,\n uniqueBodyCount: uniqueOffsets.size,\n aliasedRowCount: this.records.length - uniqueOffsets.size\n };\n }\n}\n\nexport default CjsCarbonEffectReader;\n"],"names":["CARBON_EFFECT_SOURCE_HASH_BYTES","CARBON_EFFECT_RECORD_BYTES","CjsCarbonEffectBodyReader","CjsByteReader","ReadError","CjsFormatReadError","endOfDataMessage","CjsCarbonEffectReader","BodyReader","constructor","bytes","options","version","readUint32","CARBON_EFFECT_DATA_VERSION","_error","compilerVersion","Array","from","readRaw","sourceHash","Uint8Array","stringTableSize","offset","length","byteLength","stringTableBytes","subarray","skip","setStringTable","permutations","records","headerEnd","diagnostics","permissive","requireDensePermutationTable","permutationProduct","product","permutation","dense","recordCount","indicesMatchPosition","firstMismatch","firstIndexMismatch","readDescription","index","record","backend","undefined","withoutBlocks","#readDescriptionAs","reader","source","end","size","stringTable","readEffectDescription","bodyBytes","#readPermutations","count","readUint8","nameOffset","name","readStringAt","defaultOption","descriptionOffset","description","type","optionCount","optionIndex","push","value","#readRecords","#inspect","uniqueOffsets","Set","position","storedIndex","add","firstBody","Math","min","map","slack","uniqueBodyCount","aliasedRowCount"],"mappings":";;;;AAAA;AACA;;;AAMA;AACO,MAAMA,+BAA+B,GAAG;;AAE/C;AACO,MAAMC,0BAA0B,GAAG;;AAE1C;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,yBAAyB,SAASC,aAAa,CAC5D;EACI,OAAOC,SAAS,GAAGC,kBAAkB;EAErC,OAAOC,gBAAgB,GAAG,sCAAsC;AACpE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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|
1
|
+
{"version":3,"file":"CjsCarbonEffectReader.js","sources":["../../../../src/format/carbonEffect/CjsCarbonEffectReader.js"],"sourcesContent":["// Source: trinity/trinity/Resources/Tr2EffectRes.cpp (DoLoad, GetShader)\r\n// Source: trinity/shadercompiler/ShaderCompiler.cpp:746-845 (file assembly)\r\n\r\nimport { CjsByteReader } from \"../CjsByteReader.js\";\r\nimport { CjsFormatReadError } from \"../CjsFormatError.js\";\r\nimport {\r\n CARBON_EFFECT_DATA_VERSION,\r\n CARBON_EFFECT_MIN_DATA_VERSION,\r\n readEffectDescription\r\n} from \"./carbonEffectRecords.js\";\r\n\r\n/** Byte count of the ASCII-hex MD5 source hash in the v15 header. */\r\nexport const CARBON_EFFECT_SOURCE_HASH_BYTES = 32;\r\n\r\n/** Byte count of one offset-table row: `{u32 index, u32 offset, u32 size}`. */\r\nexport const CARBON_EFFECT_RECORD_BYTES = 12;\r\n\r\n/**\r\n * Plain byte cursor over one description blob, carrying the Carbon effect error\r\n * class and message.\r\n *\r\n * Separate from the container reader because the container reader parses its\r\n * header in the constructor; a body needs a cursor, not a second header parse.\r\n */\r\nexport class CjsCarbonEffectBodyReader extends CjsByteReader\r\n{\r\n static ReadError = CjsFormatReadError;\r\n\r\n static endOfDataMessage = \"Unexpected end of Carbon effect data\";\r\n}\r\n\r\n/**\r\n * Reader for Carbon's compiled-effect container, versions 8 through 15.\r\n *\r\n * The v15 header is (`ShaderCompiler.cpp:822-831`):\r\n *\r\n * ```\r\n * u32 version = 15\r\n * u8[4] shaderCompilerVersion <- four bytes, not a u32\r\n * char[32] sourceHash <- ASCII hex MD5 of the HLSL inputs\r\n * u32 stringTableSize | arena\r\n * u8 permutationCount | permutation records\r\n * u32 recordCount | recordCount x { u32 index, u32 offset, u32 size }\r\n * description blobs\r\n * ```\r\n *\r\n * Versions 8..14 differ in the header by exactly one thing: the compiler\r\n * version and source hash are absent, so `compilerVersion` and `sourceHash`\r\n * are null for them. Everything else — arena, permutation records, offset\r\n * table — is byte-identical across the accepted range.\r\n *\r\n * Carbon validates the version at 2..15 (`Tr2EffectRes.cpp:209`), then threads\r\n * it through parsing rather than gating on it again: it forwards the version\r\n * into the description reader (`Tr2EffectRes.cpp:128`), where\r\n * `Tr2EffectDescription.cpp` branches at 22 conditional sites. The version\r\n * decides the byte layout at nearly every level - whether a stage carries a\r\n * register signature at all (`> 8`), where pipeline inputs are read (`< 14`),\r\n * how a constant's type byte is decoded (`< 11`), and whether a resource\r\n * carries `arrayElements` at all (`>= 13`).\r\n *\r\n * This reader carries the same parameter, restored per the 2026-08-02\r\n * maintainer decision with 8 as the floor (see\r\n * `CARBON_EFFECT_MIN_DATA_VERSION`). Reading a version is not supporting it:\r\n * the reader's job ends at a correct record tree, normalized to the v15\r\n * record shape, and what an engine can do with an old body is a separate\r\n * question. Versions below 8 are still rejected outright — those branches\r\n * have no examined file and no writer to check against, and applying newer\r\n * rules to an older layout misaligns fields silently.\r\n */\r\nexport class CjsCarbonEffectReader extends CjsCarbonEffectBodyReader\r\n{\r\n /** Cursor class used for description blobs. */\r\n static BodyReader = CjsCarbonEffectBodyReader;\r\n\r\n /**\r\n * Reads the container header, arena, permutation axes and offset table.\r\n *\r\n * @param {ArrayBuffer|ArrayBufferView|Uint8Array} bytes Container bytes.\r\n * @param {object} [options] Read options.\r\n * @param {string} [options.source] Source name used in error details.\r\n * @param {boolean} [options.permissive] Accept a sparse or misordered offset\r\n * table instead of rejecting it. For forensic inspection of a file already\r\n * known to be malformed; never for a load path.\r\n */\r\n constructor(bytes, options = {})\r\n {\r\n super(bytes, options);\r\n\r\n this.version = this.readUint32();\r\n if (this.version < CARBON_EFFECT_MIN_DATA_VERSION || this.version > CARBON_EFFECT_DATA_VERSION)\r\n {\r\n throw this._error(\r\n `Unsupported Carbon effect version ${this.version}; expected ${CARBON_EFFECT_MIN_DATA_VERSION}..${CARBON_EFFECT_DATA_VERSION}`,\r\n { version: this.version }\r\n );\r\n }\r\n\r\n // The compiler version and source hash are the v15 header additions;\r\n // an older header goes straight from the version to the arena.\r\n if (this.version === CARBON_EFFECT_DATA_VERSION)\r\n {\r\n this.compilerVersion = Array.from(this.readRaw(4));\r\n this.sourceHash = Uint8Array.from(this.readRaw(CARBON_EFFECT_SOURCE_HASH_BYTES));\r\n }\r\n else\r\n {\r\n this.compilerVersion = null;\r\n this.sourceHash = null;\r\n }\r\n\r\n this.stringTableSize = this.readUint32();\r\n if (this.offset + this.stringTableSize > this.bytes.length)\r\n {\r\n throw this._error(\"Invalid Carbon effect string-table size\", {\r\n stringTableSize: this.stringTableSize,\r\n byteLength: this.bytes.length\r\n });\r\n }\r\n this.stringTableBytes = this.bytes.subarray(this.offset, this.offset + this.stringTableSize);\r\n this.skip(this.stringTableSize);\r\n this.setStringTable(this.stringTableBytes, this.stringTableSize);\r\n\r\n this.permutations = this.#readPermutations();\r\n this.records = this.#readRecords();\r\n this.headerEnd = this.offset;\r\n this.diagnostics = this.#inspect();\r\n\r\n if (!options.permissive)\r\n {\r\n this.requireDensePermutationTable();\r\n }\r\n }\r\n\r\n /**\r\n * Returns the product of the permutation axes' option counts — the number of\r\n * offset-table rows a fully populated file has.\r\n *\r\n * @returns {number} Permutation count.\r\n */\r\n get permutationProduct()\r\n {\r\n let product = 1;\r\n for (const permutation of this.permutations)\r\n {\r\n product *= permutation.options.length;\r\n }\r\n return product;\r\n }\r\n\r\n /**\r\n * Throws unless the offset table is dense and positionally indexed.\r\n *\r\n * Carbon indexes `m_offsets` positionally and never reads the stored `index`\r\n * field (`Tr2EffectRes.cpp:121-126`), so a sparse or misordered table does\r\n * not fail — it silently returns the wrong shader body. Carbon gets density\r\n * incidentally, from `g_compiledEffects` being a `std::map` densely keyed by\r\n * `AddPermutationsToWorkQueue`, and promises it nowhere.\r\n *\r\n * Measured across the whole shipped corpus at build 3444265 — 4833 files and\r\n * 78,498 rows across `effect.dx11`, `effect.dx12` and `effect.metal` — both\r\n * conditions hold in every file, so this runs by default.\r\n *\r\n * `--ignore-permutations` does make CCP's compiler emit only key 0 while\r\n * declaring every axis, so a sparse file is producible. That argues for an\r\n * escape hatch, not for permissiveness: because Carbon indexes positionally,\r\n * accepting such a file returns the wrong permutation's shader silently, which\r\n * is exactly the failure class this container port exists to close.\r\n * `{ permissive: true }` is the opt-in, for inspecting a file already known to\r\n * be malformed.\r\n */\r\n requireDensePermutationTable()\r\n {\r\n if (!this.diagnostics.dense)\r\n {\r\n throw this._error(\"Carbon effect offset table is sparse\", {\r\n recordCount: this.records.length,\r\n permutationProduct: this.permutationProduct\r\n });\r\n }\r\n if (!this.diagnostics.indicesMatchPosition)\r\n {\r\n throw this._error(\"Carbon effect offset table is not positionally indexed\", {\r\n firstMismatch: this.diagnostics.firstIndexMismatch\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Reads and parses one permutation's description blob.\r\n *\r\n * `backend` is **optional**, and omitting it is the interesting case. A\r\n * Carbon file ends each pass at the render states; ours adds one eight-byte\r\n * block reference. Nothing in the header distinguishes the two, and we\r\n * deliberately do not add anything — no envelope, no version of our own,\r\n * because CCP owns the version space and a container that announces itself\r\n * is an invention nothing requires.\r\n *\r\n * Instead the blob describes itself, using a rule the format already has.\r\n * Every sized record must parse to exactly its declared end (Rule 1), and a\r\n * body's declared size is in the offset table. So the wrong interpretation\r\n * either throws or leaves the cursor somewhere other than the end, and one\r\n * retry settles it.\r\n *\r\n * Pass `backend` explicitly when the caller knows — the loader does, because\r\n * backend selection is by resource path, mirroring Carbon's\r\n * `effect.dx11`/`effect.dx12`/`effect.metal`. Auto-detection is for bytes\r\n * that arrive without that context: tooling, caches, inspection.\r\n *\r\n * @param {number} index Permutation index, positional in the offset table.\r\n * @param {object} [options] Read options.\r\n * @param {boolean} [options.backend] Expect our optional per-pass trailing\r\n * block. Omit to detect it from the blob's declared end.\r\n * @returns {object} Description record tree.\r\n */\r\n readDescription(index, options = {})\r\n {\r\n const record = this.records[index];\r\n if (!record)\r\n {\r\n throw this._error(`No Carbon effect body at permutation index ${index}`, {\r\n index,\r\n recordCount: this.records.length\r\n });\r\n }\r\n\r\n if (options.backend !== undefined)\r\n {\r\n return this.#readDescriptionAs(record, options.backend === true);\r\n }\r\n\r\n // Plain Carbon first: it is the larger population, and it is the reading\r\n // that must stay cheap.\r\n try\r\n {\r\n return this.#readDescriptionAs(record, false);\r\n }\r\n catch (withoutBlocks)\r\n {\r\n try\r\n {\r\n return this.#readDescriptionAs(record, true);\r\n }\r\n catch\r\n {\r\n // Report the plain-Carbon failure. If neither reading works the\r\n // blob is malformed, and the Carbon diagnosis is the useful one;\r\n // the backend attempt's error would describe a misparse of bytes\r\n // that were never a backend block.\r\n throw withoutBlocks;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Parses one body under an exact backend-block assumption.\r\n *\r\n * @param {object} record Offset-table row.\r\n * @param {boolean} backend Whether to expect the per-pass block.\r\n * @returns {object} Description record tree.\r\n */\r\n #readDescriptionAs(record, backend)\r\n {\r\n const reader = new this.constructor.BodyReader(this.bytes, {\r\n source: this.source,\r\n offset: record.offset,\r\n end: record.offset + record.size,\r\n stringTable: this.stringTableBytes,\r\n stringTableSize: this.stringTableSize\r\n });\r\n return readEffectDescription(reader, { backend, version: this.version });\r\n }\r\n\r\n /**\r\n * Returns the raw description-blob bytes for one permutation.\r\n *\r\n * @param {number} index Permutation index, positional in the offset table.\r\n * @returns {Uint8Array} View over the body bytes.\r\n */\r\n bodyBytes(index)\r\n {\r\n const record = this.records[index];\r\n if (!record)\r\n {\r\n throw this._error(`No Carbon effect body at permutation index ${index}`, { index });\r\n }\r\n return this.bytes.subarray(record.offset, record.offset + record.size);\r\n }\r\n\r\n /**\r\n * Reads the permutation axis records (`ShaderCompiler.cpp:769-795`,\r\n * `Tr2EffectRes.cpp:263-292`).\r\n *\r\n * @returns {object[]} Permutation axes with arena references retained.\r\n */\r\n #readPermutations()\r\n {\r\n const permutations = [];\r\n const count = this.readUint8();\r\n for (let index = 0; index < count; index += 1)\r\n {\r\n const nameOffset = this.readUint32();\r\n const name = this.readStringAt(nameOffset);\r\n const defaultOption = this.readUint8();\r\n const descriptionOffset = this.readUint32();\r\n const description = this.readStringAt(descriptionOffset);\r\n const type = this.readUint8();\r\n\r\n const options = [];\r\n const optionCount = this.readUint8();\r\n for (let optionIndex = 0; optionIndex < optionCount; optionIndex += 1)\r\n {\r\n const offset = this.readUint32();\r\n options.push({ offset, value: this.readStringAt(offset) });\r\n }\r\n\r\n permutations.push({\r\n name: { offset: nameOffset, value: name },\r\n defaultOption,\r\n description: { offset: descriptionOffset, value: description },\r\n type,\r\n options\r\n });\r\n }\r\n return permutations;\r\n }\r\n\r\n /**\r\n * Reads the offset table (`ShaderCompiler.cpp:800-820`,\r\n * `Tr2EffectRes.cpp:294-311`).\r\n *\r\n * @returns {object[]} Offset-table rows.\r\n */\r\n #readRecords()\r\n {\r\n const count = this.readUint32();\r\n if (count === 0)\r\n {\r\n throw this._error(\"Carbon effect contains no compiled bodies\");\r\n }\r\n if (this.offset + count * CARBON_EFFECT_RECORD_BYTES > this.bytes.length)\r\n {\r\n throw this._error(\"Carbon effect offset table runs past the end of the file\", {\r\n recordCount: count,\r\n byteLength: this.bytes.length\r\n });\r\n }\r\n\r\n const records = [];\r\n for (let index = 0; index < count; index += 1)\r\n {\r\n records.push({\r\n index: this.readUint32(),\r\n offset: this.readUint32(),\r\n size: this.readUint32()\r\n });\r\n }\r\n return records;\r\n }\r\n\r\n /**\r\n * Validates every row's byte range and collects the structural diagnostics\r\n * Carbon relies on without stating.\r\n *\r\n * @returns {object} Structural diagnostics.\r\n */\r\n #inspect()\r\n {\r\n const headerEnd = this.headerEnd;\r\n const byteLength = this.bytes.length;\r\n let firstIndexMismatch = null;\r\n const uniqueOffsets = new Set();\r\n\r\n for (let index = 0; index < this.records.length; index += 1)\r\n {\r\n const record = this.records[index];\r\n if (record.index !== index && firstIndexMismatch === null)\r\n {\r\n firstIndexMismatch = { position: index, storedIndex: record.index };\r\n }\r\n const end = record.offset + record.size;\r\n if (record.offset < headerEnd || end > byteLength || record.size === 0)\r\n {\r\n throw this._error(`Carbon effect body record ${index} is out of range`, {\r\n position: index,\r\n offset: record.offset,\r\n size: record.size,\r\n headerEnd,\r\n byteLength\r\n });\r\n }\r\n uniqueOffsets.add(record.offset);\r\n }\r\n\r\n // The body region must begin exactly where the header ends. Carbon computes\r\n // its first body offset as `4 + 4 + 32 + headerSize + stringTable.GetSize()`\r\n // (`ShaderCompiler.cpp:801`), so a gap or an overlap means our reconstruction\r\n // of that arithmetic disagrees with the writer's — which would silently\r\n // misread every body rather than fail. Carbon's own reader does not check\r\n // this; measured across 4833 shipped files, every one starts its body region\r\n // flush against the header with no slack.\r\n const firstBody = Math.min(...this.records.map((record) => record.offset));\r\n if (firstBody !== headerEnd)\r\n {\r\n throw this._error(\"Carbon effect body region does not start where the header ends\", {\r\n firstBody,\r\n headerEnd,\r\n slack: firstBody - headerEnd\r\n });\r\n }\r\n\r\n return {\r\n recordCount: this.records.length,\r\n permutationProduct: this.permutationProduct,\r\n dense: this.records.length === this.permutationProduct,\r\n indicesMatchPosition: firstIndexMismatch === null,\r\n firstIndexMismatch,\r\n uniqueBodyCount: uniqueOffsets.size,\r\n aliasedRowCount: this.records.length - uniqueOffsets.size\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * Reports whether a payload has the Carbon effect container shape.\r\n *\r\n * A **shape** check, not an identity check, and the distinction is the point:\r\n * our containers are stock Carbon files, so nothing in the bytes separates one\r\n * from a shipped `effect.dx11`. Identity comes from the resource path the file\r\n * was resolved through - `effect.webgl/` versus `effect.dx11/` - exactly as it\r\n * does for Carbon, whose own backend trees are byte-format-identical.\r\n *\r\n * Both backend sniffs call this rather than each keeping a copy of the version\r\n * dword. Two hand-written copies of one constant are two chances to disagree.\r\n *\r\n * @param {Uint8Array} bytes Candidate payload.\r\n * @returns {boolean} True when the payload opens on Carbon's version dword.\r\n */\r\nexport function looksLikeCarbonEffectContainer(bytes)\r\n{\r\n if (!bytes || bytes.length < 4) return false;\r\n return bytes[0] === CARBON_EFFECT_DATA_VERSION\r\n && bytes[1] === 0\r\n && bytes[2] === 0\r\n && bytes[3] === 0;\r\n}\r\n\r\nexport default CjsCarbonEffectReader;\r\n"],"names":["CARBON_EFFECT_SOURCE_HASH_BYTES","CARBON_EFFECT_RECORD_BYTES","CjsCarbonEffectBodyReader","CjsByteReader","ReadError","CjsFormatReadError","endOfDataMessage","CjsCarbonEffectReader","BodyReader","constructor","bytes","options","version","readUint32","CARBON_EFFECT_MIN_DATA_VERSION","CARBON_EFFECT_DATA_VERSION","_error","compilerVersion","Array","from","readRaw","sourceHash","Uint8Array","stringTableSize","offset","length","byteLength","stringTableBytes","subarray","skip","setStringTable","permutations","records","headerEnd","diagnostics","permissive","requireDensePermutationTable","permutationProduct","product","permutation","dense","recordCount","indicesMatchPosition","firstMismatch","firstIndexMismatch","readDescription","index","record","backend","undefined","withoutBlocks","#readDescriptionAs","reader","source","end","size","stringTable","readEffectDescription","bodyBytes","#readPermutations","count","readUint8","nameOffset","name","readStringAt","defaultOption","descriptionOffset","description","type","optionCount","optionIndex","push","value","#readRecords","#inspect","uniqueOffsets","Set","position","storedIndex","add","firstBody","Math","min","map","slack","uniqueBodyCount","aliasedRowCount","looksLikeCarbonEffectContainer"],"mappings":";;;;AAAA;AACA;;;AAUA;AACO,MAAMA,+BAA+B,GAAG;;AAE/C;AACO,MAAMC,0BAA0B,GAAG;;AAE1C;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,yBAAyB,SAASC,aAAa,CAC5D;EACI,OAAOC,SAAS,GAAGC,kBAAkB;EAErC,OAAOC,gBAAgB,GAAG,sCAAsC;AACpE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,qBAAqB,SAASL,yBAAyB,CACpE;AACI;EAC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