@carbonenginejs/runtime-resource 0.10.0 → 0.11.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/dist/format/effect/effectPermutationGraph.js +257 -0
- package/dist/format/effect/effectPermutationGraph.js.map +1 -0
- package/dist/format/effect/effectReflectionPackage.js +636 -0
- package/dist/format/effect/effectReflectionPackage.js.map +1 -0
- package/dist/format/effect/sha256.js +114 -0
- package/dist/format/effect/sha256.js.map +1 -0
- package/dist/formats/dxbc/CjsDxbcFormat.js +142 -0
- package/dist/formats/dxbc/CjsDxbcFormat.js.map +1 -0
- package/dist/formats/dxbc/core/DxbcReader.js +266 -0
- package/dist/formats/dxbc/core/DxbcReader.js.map +1 -0
- package/dist/formats/dxbc/core/container.js +169 -0
- package/dist/formats/dxbc/core/container.js.map +1 -0
- package/dist/formats/dxbc/core/decoder.js +789 -0
- package/dist/formats/dxbc/core/decoder.js.map +1 -0
- package/dist/formats/dxbc/core/errors.js +19 -0
- package/dist/formats/dxbc/core/errors.js.map +1 -0
- package/dist/formats/dxbc/core/helpers.js +220 -0
- package/dist/formats/dxbc/core/helpers.js.map +1 -0
- package/dist/formats/dxbc/core/opcodes.js +45 -0
- package/dist/formats/dxbc/core/opcodes.js.map +1 -0
- package/dist/formats/dxbc/core/program.js +91 -0
- package/dist/formats/dxbc/core/program.js.map +1 -0
- package/dist/formats/dxbc/core/signature.js +172 -0
- package/dist/formats/dxbc/core/signature.js.map +1 -0
- package/dist/formats/dxbc/index.js +2 -0
- package/dist/formats/dxbc/index.js.map +1 -0
- package/dist/formats/hlsl/CjsHlslFormat.js +254 -0
- package/dist/formats/hlsl/CjsHlslFormat.js.map +1 -0
- package/dist/formats/hlsl/core/HlslBinaryUtils.js +15 -0
- package/dist/formats/hlsl/core/HlslBinaryUtils.js.map +1 -0
- package/dist/formats/hlsl/core/HlslEffectReadError.js +19 -0
- package/dist/formats/hlsl/core/HlslEffectReadError.js.map +1 -0
- package/dist/formats/hlsl/core/HlslEffectStateManager.js +130 -0
- package/dist/formats/hlsl/core/HlslEffectStateManager.js.map +1 -0
- package/dist/formats/hlsl/core/HlslReader.js +266 -0
- package/dist/formats/hlsl/core/HlslReader.js.map +1 -0
- package/dist/formats/hlsl/core/HlslRenderStateSetup.js +37 -0
- package/dist/formats/hlsl/core/HlslRenderStateSetup.js.map +1 -0
- package/dist/formats/hlsl/core/HlslResourceSetDescription.js +94 -0
- package/dist/formats/hlsl/core/HlslResourceSetDescription.js.map +1 -0
- package/dist/formats/hlsl/core/HlslShaderBytecode.js +44 -0
- package/dist/formats/hlsl/core/HlslShaderBytecode.js.map +1 -0
- package/dist/formats/hlsl/core/analysis.js +51 -0
- package/dist/formats/hlsl/core/analysis.js.map +1 -0
- package/dist/formats/hlsl/core/helpers.js +270 -0
- package/dist/formats/hlsl/core/helpers.js.map +1 -0
- package/dist/formats/hlsl/core/json.js +284 -0
- package/dist/formats/hlsl/core/json.js.map +1 -0
- package/dist/formats/hlsl/core/metadata.js +327 -0
- package/dist/formats/hlsl/core/metadata.js.map +1 -0
- package/dist/formats/hlsl/core/portableReflection.js +848 -0
- package/dist/formats/hlsl/core/portableReflection.js.map +1 -0
- package/dist/formats/hlsl/core/render-states.js +280 -0
- package/dist/formats/hlsl/core/render-states.js.map +1 -0
- package/dist/formats/hlsl/core/tr2/HlslRenderContextEnum.js +43 -0
- package/dist/formats/hlsl/core/tr2/HlslRenderContextEnum.js.map +1 -0
- package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js +294 -0
- package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js.map +1 -0
- package/dist/formats/hlsl/core/tr2/resources/HlslShaderPermutation.js +33 -0
- package/dist/formats/hlsl/core/tr2/resources/HlslShaderPermutation.js.map +1 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectBindingManifest.js +416 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectBindingManifest.js.map +1 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectConstant.js +40 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectConstant.js.map +1 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectDescription.js +742 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectDescription.js.map +1 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectLibrary.js +52 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectLibrary.js.map +1 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectParameterAnnotation.js +38 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectParameterAnnotation.js.map +1 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectResource.js +50 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectResource.js.map +1 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectStageInput.js +86 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectStageInput.js.map +1 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectTechnique.js +31 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectTechnique.js.map +1 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslPass.js +42 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslPass.js.map +1 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslSamplerDescription.js +55 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslSamplerDescription.js.map +1 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslSamplerSetup.js +29 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslSamplerSetup.js.map +1 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslShader.js +220 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslShader.js.map +1 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslShaderOption.js +30 -0
- package/dist/formats/hlsl/core/tr2/shader/HlslShaderOption.js.map +1 -0
- package/dist/formats/hlsl/index.js +2 -0
- package/dist/formats/hlsl/index.js.map +1 -0
- package/dist/formats/hlsl/portable.js +2 -0
- package/dist/formats/hlsl/portable.js.map +1 -0
- package/dist/formats/index.js +4 -0
- package/dist/formats/index.js.map +1 -1
- package/dist/formats/webgl/CjsWebglFormat.js +221 -0
- package/dist/formats/webgl/CjsWebglFormat.js.map +1 -0
- package/dist/formats/webgl/core/cewg/CewgPackage.js +339 -0
- package/dist/formats/webgl/core/cewg/CewgPackage.js.map +1 -0
- package/dist/formats/webgl/core/cewg/CewgPackageBuilder.js +104 -0
- package/dist/formats/webgl/core/cewg/CewgPackageBuilder.js.map +1 -0
- package/dist/formats/webgl/core/cewg/binary.js +101 -0
- package/dist/formats/webgl/core/cewg/binary.js.map +1 -0
- package/dist/formats/webgl/core/cewgCompleteness.js +81 -0
- package/dist/formats/webgl/core/cewgCompleteness.js.map +1 -0
- package/dist/formats/webgl/core/effectPackage.js +789 -0
- package/dist/formats/webgl/core/effectPackage.js.map +1 -0
- package/dist/formats/webgl/core/effectPackageValidation.js +331 -0
- package/dist/formats/webgl/core/effectPackageValidation.js.map +1 -0
- package/dist/formats/webgl/core/errors.js +27 -0
- package/dist/formats/webgl/core/errors.js.map +1 -0
- package/dist/formats/webgl/core/glsl/DxbcGlslEmitter.js +2678 -0
- package/dist/formats/webgl/core/glsl/DxbcGlslEmitter.js.map +1 -0
- package/dist/formats/webgl/core/glsl/DxbcGlslHelpers.js +89 -0
- package/dist/formats/webgl/core/glsl/DxbcGlslHelpers.js.map +1 -0
- package/dist/formats/webgl/core/glsl/DxbcGlslOperandFormatter.js +428 -0
- package/dist/formats/webgl/core/glsl/DxbcGlslOperandFormatter.js.map +1 -0
- package/dist/formats/webgl/core/helpers.js +306 -0
- package/dist/formats/webgl/core/helpers.js.map +1 -0
- package/dist/formats/webgl/index.js +2 -0
- package/dist/formats/webgl/index.js.map +1 -0
- package/dist/formats/webgpu/CjsWebgpuFormat.js +376 -0
- package/dist/formats/webgpu/CjsWebgpuFormat.js.map +1 -0
- package/dist/formats/webgpu/core/cewgpu/CewgpuPackage.js +415 -0
- package/dist/formats/webgpu/core/cewgpu/CewgpuPackage.js.map +1 -0
- package/dist/formats/webgpu/core/cewgpu/CewgpuPackageBuilder.js +100 -0
- package/dist/formats/webgpu/core/cewgpu/CewgpuPackageBuilder.js.map +1 -0
- package/dist/formats/webgpu/core/cewgpu/binary.js +93 -0
- package/dist/formats/webgpu/core/cewgpu/binary.js.map +1 -0
- package/dist/formats/webgpu/core/cewgpu/tags.js +17 -0
- package/dist/formats/webgpu/core/cewgpu/tags.js.map +1 -0
- package/dist/formats/webgpu/core/effectAnalysis.js +82 -0
- package/dist/formats/webgpu/core/effectAnalysis.js.map +1 -0
- package/dist/formats/webgpu/core/effectBackendBodySet.js +305 -0
- package/dist/formats/webgpu/core/effectBackendBodySet.js.map +1 -0
- package/dist/formats/webgpu/core/effectPackageValidation.js +1078 -0
- package/dist/formats/webgpu/core/effectPackageValidation.js.map +1 -0
- package/dist/formats/webgpu/core/errors.js +20 -0
- package/dist/formats/webgpu/core/errors.js.map +1 -0
- package/dist/formats/webgpu/core/helpers.js +448 -0
- package/dist/formats/webgpu/core/helpers.js.map +1 -0
- package/dist/formats/webgpu/core/ir/analyzeRegisterValues.js +223 -0
- package/dist/formats/webgpu/core/ir/analyzeRegisterValues.js.map +1 -0
- package/dist/formats/webgpu/core/ir/buildControlFlow.js +220 -0
- package/dist/formats/webgpu/core/ir/buildControlFlow.js.map +1 -0
- package/dist/formats/webgpu/core/ir/indexableTemps.js +137 -0
- package/dist/formats/webgpu/core/ir/indexableTemps.js.map +1 -0
- package/dist/formats/webgpu/core/ir/inferValueTypes.js +454 -0
- package/dist/formats/webgpu/core/ir/inferValueTypes.js.map +1 -0
- package/dist/formats/webgpu/core/ir/lowerDxbcToIr.js +494 -0
- package/dist/formats/webgpu/core/ir/lowerDxbcToIr.js.map +1 -0
- package/dist/formats/webgpu/core/ir/resolveRegisterFlow.js +177 -0
- package/dist/formats/webgpu/core/ir/resolveRegisterFlow.js.map +1 -0
- package/dist/formats/webgpu/core/ir/sourceLanes.js +61 -0
- package/dist/formats/webgpu/core/ir/sourceLanes.js.map +1 -0
- package/dist/formats/webgpu/core/packageEffect.js +300 -0
- package/dist/formats/webgpu/core/packageEffect.js.map +1 -0
- package/dist/formats/webgpu/core/packageEffectSelection.js +164 -0
- package/dist/formats/webgpu/core/packageEffectSelection.js.map +1 -0
- package/dist/formats/webgpu/core/packageMetadata.js +8 -0
- package/dist/formats/webgpu/core/packageMetadata.js.map +1 -0
- package/dist/formats/webgpu/core/schema.js +4 -0
- package/dist/formats/webgpu/core/schema.js.map +1 -0
- package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js +275 -0
- package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js.map +1 -0
- package/dist/formats/webgpu/core/wgsl/buildWgslBindingPlan.js +182 -0
- package/dist/formats/webgpu/core/wgsl/buildWgslBindingPlan.js.map +1 -0
- package/dist/formats/webgpu/core/wgsl/buildWgslSet.js +324 -0
- package/dist/formats/webgpu/core/wgsl/buildWgslSet.js.map +1 -0
- package/dist/formats/webgpu/core/wgsl/emitWgsl.js +356 -0
- package/dist/formats/webgpu/core/wgsl/emitWgsl.js.map +1 -0
- package/dist/formats/webgpu/core/wgsl/hoistEscapingValues.js +77 -0
- package/dist/formats/webgpu/core/wgsl/hoistEscapingValues.js.map +1 -0
- package/dist/formats/webgpu/core/wgsl/lowerBindingLayout.js +451 -0
- package/dist/formats/webgpu/core/wgsl/lowerBindingLayout.js.map +1 -0
- package/dist/formats/webgpu/core/wgsl/lowerComputeProgram.js +754 -0
- package/dist/formats/webgpu/core/wgsl/lowerComputeProgram.js.map +1 -0
- package/dist/formats/webgpu/core/wgsl/lowerCreateHistogramsComputeProgram.js +457 -0
- package/dist/formats/webgpu/core/wgsl/lowerCreateHistogramsComputeProgram.js.map +1 -0
- package/dist/formats/webgpu/core/wgsl/lowerFragmentProgram.js +1572 -0
- package/dist/formats/webgpu/core/wgsl/lowerFragmentProgram.js.map +1 -0
- package/dist/formats/webgpu/core/wgsl/lowerMergeHistogramsComputeProgram.js +659 -0
- package/dist/formats/webgpu/core/wgsl/lowerMergeHistogramsComputeProgram.js.map +1 -0
- package/dist/formats/webgpu/core/wgsl/lowerParticleClearComputePrograms.js +734 -0
- package/dist/formats/webgpu/core/wgsl/lowerParticleClearComputePrograms.js.map +1 -0
- package/dist/formats/webgpu/core/wgsl/lowerParticleEmitComputeProgram.js +583 -0
- package/dist/formats/webgpu/core/wgsl/lowerParticleEmitComputeProgram.js.map +1 -0
- package/dist/formats/webgpu/core/wgsl/lowerSkinVerticesComputeProgram.js +621 -0
- package/dist/formats/webgpu/core/wgsl/lowerSkinVerticesComputeProgram.js.map +1 -0
- package/dist/formats/webgpu/core/wgsl/lowerSortComputeProgram.js +824 -0
- package/dist/formats/webgpu/core/wgsl/lowerSortComputeProgram.js.map +1 -0
- package/dist/formats/webgpu/core/wgsl/lowerSortInnerComputeProgram.js +697 -0
- package/dist/formats/webgpu/core/wgsl/lowerSortInnerComputeProgram.js.map +1 -0
- package/dist/formats/webgpu/core/wgsl/lowerSortStepComputeProgram.js +559 -0
- package/dist/formats/webgpu/core/wgsl/lowerSortStepComputeProgram.js.map +1 -0
- package/dist/formats/webgpu/core/wgsl/lowerVertexProgram.js +1328 -0
- package/dist/formats/webgpu/core/wgsl/lowerVertexProgram.js.map +1 -0
- package/dist/formats/webgpu/core/wgsl/particleEmitSemanticDigest.js +110 -0
- package/dist/formats/webgpu/core/wgsl/particleEmitSemanticDigest.js.map +1 -0
- package/dist/formats/webgpu/core/wgsl/precisionControls.js +55 -0
- package/dist/formats/webgpu/core/wgsl/precisionControls.js.map +1 -0
- package/dist/formats/webgpu/core/wgsl/selectionPlans.js +758 -0
- package/dist/formats/webgpu/core/wgsl/selectionPlans.js.map +1 -0
- package/dist/formats/webgpu/core/wgsl/uniformity.js +78 -0
- package/dist/formats/webgpu/core/wgsl/uniformity.js.map +1 -0
- package/dist/formats/webgpu/core/wgsl/validateExactComputeIr.js +196 -0
- package/dist/formats/webgpu/core/wgsl/validateExactComputeIr.js.map +1 -0
- package/dist/formats/webgpu/core/wgsl/validateHandleOperand.js +37 -0
- package/dist/formats/webgpu/core/wgsl/validateHandleOperand.js.map +1 -0
- package/dist/formats/webgpu/index.js +2 -0
- package/dist/formats/webgpu/index.js.map +1 -0
- package/dist/resource/shader/Tr2EffectRes.js +159 -150
- package/dist/resource/shader/Tr2EffectRes.js.map +1 -1
- package/dist/resource/shader/Tr2MaterialArea.js +23 -28
- package/dist/resource/shader/Tr2MaterialArea.js.map +1 -1
- package/dist/resource/shader/Tr2MaterialMesh.js +21 -27
- package/dist/resource/shader/Tr2MaterialMesh.js.map +1 -1
- package/dist/resource/shader/Tr2MaterialRes.js +24 -29
- package/dist/resource/shader/Tr2MaterialRes.js.map +1 -1
- package/dist/resource/shader/Tr2Shader.js +45 -39
- package/dist/resource/shader/Tr2Shader.js.map +1 -1
- package/dist/resource/shader/Tr2ShaderPermutation.js +30 -32
- package/dist/resource/shader/Tr2ShaderPermutation.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectConstant.js +113 -78
- package/dist/resource/shader/reflection/Tr2EffectConstant.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectDefine.js +17 -23
- package/dist/resource/shader/reflection/Tr2EffectDefine.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectDescription.js +23 -29
- package/dist/resource/shader/reflection/Tr2EffectDescription.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectLibrary.js +44 -40
- package/dist/resource/shader/reflection/Tr2EffectLibrary.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js +82 -86
- package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectResource.js +55 -61
- package/dist/resource/shader/reflection/Tr2EffectResource.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectStageInput.js +49 -45
- package/dist/resource/shader/reflection/Tr2EffectStageInput.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectTechnique.js +25 -30
- package/dist/resource/shader/reflection/Tr2EffectTechnique.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2Pass.js +30 -32
- package/dist/resource/shader/reflection/Tr2Pass.js.map +1 -1
- package/dist/resource/shader/sampler/Tr2SamplerSetup.js +21 -26
- package/dist/resource/shader/sampler/Tr2SamplerSetup.js.map +1 -1
- package/docs/formats/README.md +4 -0
- package/docs/formats/provenance.md +11 -3
- package/docs/reference/classes/formats.md +440 -0
- package/format-notices/dxbc/LICENSE +21 -0
- package/format-notices/dxbc/NOTICE +20 -0
- package/format-notices/hlsl/LICENSE +21 -0
- package/format-notices/hlsl/NOTICE +25 -0
- package/format-notices/webgl/LICENSE +21 -0
- package/format-notices/webgl/NOTICE +35 -0
- package/format-notices/webgpu/LICENSE +21 -0
- package/format-notices/webgpu/NOTICE +31 -0
- package/package.json +6 -1
- package/dist/resource/shader/portableValidation.js +0 -461
- package/dist/resource/shader/portableValidation.js.map +0 -1
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { asUint8Array, WebglReader } from './binary.js';
|
|
2
|
+
import { sha256Bytes } from '../../../../format/effect/sha256.js';
|
|
3
|
+
import { hydrateEffectReflectionForPermutation } from '../../../../format/effect/effectReflectionPackage.js';
|
|
4
|
+
|
|
5
|
+
const CEWG_MAGIC = "CEWG";
|
|
6
|
+
const CEWG_FORMAT = "CEWG";
|
|
7
|
+
const CEWG_VERSION = 1;
|
|
8
|
+
const textDecoder = new TextDecoder("utf-8", {
|
|
9
|
+
fatal: false
|
|
10
|
+
});
|
|
11
|
+
const jsonTextDecoder = new TextDecoder("utf-8", {
|
|
12
|
+
fatal: true
|
|
13
|
+
});
|
|
14
|
+
const validatedEffectReflectionPackages = new WeakSet();
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Reader for CarbonEngineJS CEWG shader packages emitted by `hlsl2webgl`.
|
|
18
|
+
*/
|
|
19
|
+
class CewgPackage {
|
|
20
|
+
/**
|
|
21
|
+
* Creates an empty package reader.
|
|
22
|
+
*/
|
|
23
|
+
constructor() {
|
|
24
|
+
this.version = 0;
|
|
25
|
+
this.chunks = [];
|
|
26
|
+
this.chunkMap = new Map();
|
|
27
|
+
this.jsonCache = new Map();
|
|
28
|
+
this.reflectionBlobIndex = null;
|
|
29
|
+
this.readError = null;
|
|
30
|
+
this.sourcePath = "";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Reads a CEWG package from bytes.
|
|
35
|
+
*
|
|
36
|
+
* @param {ArrayBuffer|ArrayBufferView|Uint8Array} source CEWG binary bytes.
|
|
37
|
+
* @param {object} [options] Read options.
|
|
38
|
+
* @param {string} [options.sourcePath] Source path for diagnostics.
|
|
39
|
+
* @returns {boolean} True when the package was decoded.
|
|
40
|
+
*/
|
|
41
|
+
Read(source, options = {}) {
|
|
42
|
+
validatedEffectReflectionPackages.delete(this);
|
|
43
|
+
this.version = 0;
|
|
44
|
+
this.chunks = [];
|
|
45
|
+
this.chunkMap = new Map();
|
|
46
|
+
this.jsonCache = new Map();
|
|
47
|
+
this.reflectionBlobIndex = null;
|
|
48
|
+
this.readError = null;
|
|
49
|
+
this.sourcePath = options.sourcePath || "";
|
|
50
|
+
try {
|
|
51
|
+
const bytes = asUint8Array(source);
|
|
52
|
+
const stream = new WebglReader(bytes, {
|
|
53
|
+
source: this.sourcePath || "CEWG"
|
|
54
|
+
});
|
|
55
|
+
const magic = decodeAscii(stream.readRaw(CEWG_MAGIC.length));
|
|
56
|
+
if (magic !== CEWG_MAGIC) {
|
|
57
|
+
throw new Error(`Invalid CEWG magic "${magic}"`);
|
|
58
|
+
}
|
|
59
|
+
this.version = stream.readUint32();
|
|
60
|
+
if (this.version !== CEWG_VERSION) {
|
|
61
|
+
throw new Error(`Unsupported CEWG version ${this.version}`);
|
|
62
|
+
}
|
|
63
|
+
const chunkCount = stream.readUint32();
|
|
64
|
+
for (let index = 0; index < chunkCount; index += 1) {
|
|
65
|
+
const tag = decodeAscii(stream.readRaw(4));
|
|
66
|
+
validateChunkTag(tag);
|
|
67
|
+
if (this.chunkMap.has(tag)) {
|
|
68
|
+
throw new Error(`CEWG package contains duplicate chunk tag ${tag}`);
|
|
69
|
+
}
|
|
70
|
+
const size = stream.readUint32();
|
|
71
|
+
const offset = stream.offset;
|
|
72
|
+
const chunkBytes = stream.readRaw(size);
|
|
73
|
+
const chunk = {
|
|
74
|
+
tag,
|
|
75
|
+
size,
|
|
76
|
+
offset,
|
|
77
|
+
bytes: chunkBytes
|
|
78
|
+
};
|
|
79
|
+
this.chunks.push(chunk);
|
|
80
|
+
this.chunkMap.set(tag, chunk);
|
|
81
|
+
}
|
|
82
|
+
if (stream.remaining !== 0) {
|
|
83
|
+
throw new Error(`CEWG package has ${stream.remaining} trailing bytes`);
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
} catch (error) {
|
|
87
|
+
this.readError = error;
|
|
88
|
+
this.chunks = [];
|
|
89
|
+
this.chunkMap = new Map();
|
|
90
|
+
this.jsonCache = new Map();
|
|
91
|
+
this.reflectionBlobIndex = null;
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Reports whether the package decoded successfully.
|
|
98
|
+
*
|
|
99
|
+
* @returns {boolean} True when no read error is present.
|
|
100
|
+
*/
|
|
101
|
+
IsGood() {
|
|
102
|
+
return !this.readError && this.version === CEWG_VERSION;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Gets a chunk by four-character tag.
|
|
107
|
+
*
|
|
108
|
+
* @param {string} tag Chunk tag.
|
|
109
|
+
* @returns {{tag:string,size:number,offset:number,bytes:Uint8Array}|null} Chunk record.
|
|
110
|
+
*/
|
|
111
|
+
GetChunk(tag) {
|
|
112
|
+
return this.chunkMap.get(tag) || null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Decodes a text chunk.
|
|
117
|
+
*
|
|
118
|
+
* @param {string} tag Chunk tag.
|
|
119
|
+
* @returns {string|null} Decoded text, or null when absent.
|
|
120
|
+
*/
|
|
121
|
+
GetText(tag) {
|
|
122
|
+
const chunk = this.GetChunk(tag);
|
|
123
|
+
return chunk ? textDecoder.decode(chunk.bytes) : null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Decodes a JSON chunk.
|
|
128
|
+
*
|
|
129
|
+
* @param {string} tag Chunk tag.
|
|
130
|
+
* @returns {object|null} Parsed JSON, or null when absent.
|
|
131
|
+
*/
|
|
132
|
+
GetJson(tag) {
|
|
133
|
+
return cloneJson(getCachedJson(this, tag));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Gets translator summary metadata from the `INFO` chunk.
|
|
138
|
+
*
|
|
139
|
+
* @returns {object|null} Info JSON.
|
|
140
|
+
*/
|
|
141
|
+
get info() {
|
|
142
|
+
return this.GetJson("INFO");
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Gets caller-provided Carbon metadata from the `META` chunk.
|
|
147
|
+
*
|
|
148
|
+
* @returns {object|null} Metadata JSON.
|
|
149
|
+
*/
|
|
150
|
+
get metadata() {
|
|
151
|
+
return this.GetJson("META");
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Gets the complete source permutation graph when present.
|
|
156
|
+
*
|
|
157
|
+
* @returns {object|null} Parsed permutation graph.
|
|
158
|
+
*/
|
|
159
|
+
get permutationGraph() {
|
|
160
|
+
return this.GetJson("PGRF");
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Gets complete source effect reflection when present.
|
|
165
|
+
*
|
|
166
|
+
* @returns {object|null} Parsed reflection document.
|
|
167
|
+
*/
|
|
168
|
+
get reflection() {
|
|
169
|
+
return this.GetJson("RFLX");
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Gets the raw reflection blob store when present.
|
|
174
|
+
*
|
|
175
|
+
* @returns {Uint8Array|null} RBLB bytes.
|
|
176
|
+
*/
|
|
177
|
+
get reflectionBlobBytes() {
|
|
178
|
+
return this.GetChunk("RBLB")?.bytes ?? null;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Copies one reflected byte payload by blob key or exact reference.
|
|
183
|
+
*
|
|
184
|
+
* @param {string|object} value Blob key or exact RFLX byte-reference object.
|
|
185
|
+
* @returns {Uint8Array|null} Owned payload bytes, or null when unavailable.
|
|
186
|
+
*/
|
|
187
|
+
GetReflectionBlob(value) {
|
|
188
|
+
const key = typeof value === "string" ? value : value?.blobKey;
|
|
189
|
+
if (!this.reflectionBlobIndex) {
|
|
190
|
+
this.reflectionBlobIndex = new Map((getCachedJson(this, "RFLX")?.blobStore?.blobs ?? []).map(entry => [entry.blobKey, entry]));
|
|
191
|
+
}
|
|
192
|
+
const entry = this.reflectionBlobIndex.get(key);
|
|
193
|
+
const bytes = this.reflectionBlobBytes;
|
|
194
|
+
if (!entry || !bytes) return null;
|
|
195
|
+
if (typeof value !== "string" && (!value || value.offset !== entry.offset || value.byteLength !== entry.byteLength || value.sha256 !== entry.sha256)) {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
const end = entry.offset + entry.byteLength;
|
|
199
|
+
if (!Number.isSafeInteger(entry.offset) || entry.offset < 0 || !Number.isSafeInteger(entry.byteLength) || entry.byteLength < 0 || end > bytes.byteLength || sha256Bytes(bytes.subarray(entry.offset, end)) !== entry.sha256) {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
return Uint8Array.from(bytes.subarray(entry.offset, end));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Gets fully hydrated portable source reflection for one permutation.
|
|
207
|
+
*
|
|
208
|
+
* Every reflected byte field is returned as a fresh owned `Uint8Array`.
|
|
209
|
+
*
|
|
210
|
+
* @param {number} [permutationIndex] Exact PGRF permutation index.
|
|
211
|
+
* @returns {object|null} Validated portable reflection, or null when absent.
|
|
212
|
+
*/
|
|
213
|
+
GetPortableEffectReflection(permutationIndex) {
|
|
214
|
+
if (!validatedEffectReflectionPackages.has(this)) return null;
|
|
215
|
+
const reflection = getCachedJson(this, "RFLX");
|
|
216
|
+
const permutationGraph = getCachedJson(this, "PGRF");
|
|
217
|
+
if (!reflection || !permutationGraph) return null;
|
|
218
|
+
const selectedIndex = permutationIndex ?? getCachedJson(this, "INFO")?.defaultPermutationIndex ?? 0;
|
|
219
|
+
return hydrateEffectReflectionForPermutation(reflection, permutationGraph, selectedIndex, reference => this.GetReflectionBlob(reference));
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Gets translated GLSL source from the `GLSL` chunk.
|
|
224
|
+
*
|
|
225
|
+
* @returns {string|null} GLSL source.
|
|
226
|
+
*/
|
|
227
|
+
get glsl() {
|
|
228
|
+
return this.GetText("GLSL");
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Gets translated GLSL metadata when the `GLSL` chunk contains JSON.
|
|
233
|
+
*
|
|
234
|
+
* Whole-effect packages store a JSON stage set in this chunk; single-stage
|
|
235
|
+
* packages store raw GLSL text and return null here.
|
|
236
|
+
*
|
|
237
|
+
* @returns {object|null} Parsed GLSL stage set, or null for raw source.
|
|
238
|
+
*/
|
|
239
|
+
get glslJson() {
|
|
240
|
+
try {
|
|
241
|
+
return this.GetJson("GLSL");
|
|
242
|
+
} catch {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Gets original DXBC bytes when present.
|
|
249
|
+
*
|
|
250
|
+
* @returns {Uint8Array|null} DXBC bytes.
|
|
251
|
+
*/
|
|
252
|
+
get dxbc() {
|
|
253
|
+
return this.GetChunk("DXBC")?.bytes || null;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Returns a JSON-safe package summary.
|
|
258
|
+
*
|
|
259
|
+
* @returns {object} Serializable summary.
|
|
260
|
+
*/
|
|
261
|
+
toJSON() {
|
|
262
|
+
return {
|
|
263
|
+
format: CEWG_FORMAT,
|
|
264
|
+
version: this.version,
|
|
265
|
+
sourcePath: this.sourcePath,
|
|
266
|
+
chunks: this.chunks.map(chunk => ({
|
|
267
|
+
tag: chunk.tag,
|
|
268
|
+
size: chunk.size,
|
|
269
|
+
offset: chunk.offset
|
|
270
|
+
})),
|
|
271
|
+
readError: this.readError ? {
|
|
272
|
+
name: this.readError.name,
|
|
273
|
+
message: this.readError.message
|
|
274
|
+
} : null
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Marks one package as having passed the canonical v3 reflection envelope.
|
|
281
|
+
*
|
|
282
|
+
* This is intentionally an internal deep import rather than package-root API.
|
|
283
|
+
*
|
|
284
|
+
* @param {CewgPackage} pkg Validated package reader.
|
|
285
|
+
* @returns {void}
|
|
286
|
+
*/
|
|
287
|
+
function markEffectReflectionValidated(pkg) {
|
|
288
|
+
validatedEffectReflectionPackages.add(pkg);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Decode and cache one private JSON document.
|
|
293
|
+
*
|
|
294
|
+
* @param {CewgPackage} pkg Package reader.
|
|
295
|
+
* @param {string} tag Chunk tag.
|
|
296
|
+
* @returns {object|null} Private parsed JSON, or null when absent.
|
|
297
|
+
*/
|
|
298
|
+
function getCachedJson(pkg, tag) {
|
|
299
|
+
if (!pkg.jsonCache.has(tag)) {
|
|
300
|
+
const chunk = pkg.GetChunk(tag);
|
|
301
|
+
pkg.jsonCache.set(tag, chunk ? JSON.parse(jsonTextDecoder.decode(chunk.bytes)) : null);
|
|
302
|
+
}
|
|
303
|
+
return pkg.jsonCache.get(tag);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Copy JSON-compatible data without reparsing its source chunk.
|
|
308
|
+
*
|
|
309
|
+
* @param {any} value Cached JSON value.
|
|
310
|
+
* @returns {any} Structurally independent JSON value.
|
|
311
|
+
*/
|
|
312
|
+
function cloneJson(value) {
|
|
313
|
+
if (Array.isArray(value)) return value.map(cloneJson);
|
|
314
|
+
if (value && typeof value === "object") {
|
|
315
|
+
return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, cloneJson(entry)]));
|
|
316
|
+
}
|
|
317
|
+
return value;
|
|
318
|
+
}
|
|
319
|
+
function validateChunkTag(tag) {
|
|
320
|
+
if (typeof tag !== "string" || tag.length !== 4 || [...tag].some(character => {
|
|
321
|
+
const code = character.charCodeAt(0);
|
|
322
|
+
return code < 0x21 || code > 0x7e;
|
|
323
|
+
})) {
|
|
324
|
+
throw new Error(`Invalid CEWG chunk tag ${JSON.stringify(tag)}`);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Decodes an ASCII four-character code.
|
|
330
|
+
*
|
|
331
|
+
* @param {Uint8Array} bytes Four-byte tag payload.
|
|
332
|
+
* @returns {string} ASCII string.
|
|
333
|
+
*/
|
|
334
|
+
function decodeAscii(bytes) {
|
|
335
|
+
return String.fromCharCode(...bytes);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export { CewgPackage, markEffectReflectionValidated };
|
|
339
|
+
//# sourceMappingURL=CewgPackage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CewgPackage.js","sources":["../../../../../../src/formats/webgl/core/cewg/CewgPackage.js"],"sourcesContent":["import { WebglReader, asUint8Array } from \"./binary.js\";\nimport { sha256Bytes } from \"../../../../format/effect/sha256.js\";\nimport {\n hydrateEffectReflectionForPermutation\n} from \"../../../../format/effect/effectReflectionPackage.js\";\n\nconst CEWG_MAGIC = \"CEWG\";\nconst CEWG_FORMAT = \"CEWG\";\nconst CEWG_VERSION = 1;\nconst textDecoder = new TextDecoder(\"utf-8\", { fatal: false });\nconst jsonTextDecoder = new TextDecoder(\"utf-8\", { fatal: true });\nconst validatedEffectReflectionPackages = new WeakSet();\n\n/**\n * Reader for CarbonEngineJS CEWG shader packages emitted by `hlsl2webgl`.\n */\nexport class CewgPackage\n{\n /**\n * Creates an empty package reader.\n */\n constructor()\n {\n this.version = 0;\n this.chunks = [];\n this.chunkMap = new Map();\n this.jsonCache = new Map();\n this.reflectionBlobIndex = null;\n this.readError = null;\n this.sourcePath = \"\";\n }\n\n /**\n * Reads a CEWG package from bytes.\n *\n * @param {ArrayBuffer|ArrayBufferView|Uint8Array} source CEWG binary bytes.\n * @param {object} [options] Read options.\n * @param {string} [options.sourcePath] Source path for diagnostics.\n * @returns {boolean} True when the package was decoded.\n */\n Read(source, options = {})\n {\n validatedEffectReflectionPackages.delete(this);\n this.version = 0;\n this.chunks = [];\n this.chunkMap = new Map();\n this.jsonCache = new Map();\n this.reflectionBlobIndex = null;\n this.readError = null;\n this.sourcePath = options.sourcePath || \"\";\n\n try\n {\n const bytes = asUint8Array(source);\n const stream = new WebglReader(bytes, { source: this.sourcePath || \"CEWG\" });\n const magic = decodeAscii(stream.readRaw(CEWG_MAGIC.length));\n if (magic !== CEWG_MAGIC)\n {\n throw new Error(`Invalid CEWG magic \"${magic}\"`);\n }\n\n this.version = stream.readUint32();\n if (this.version !== CEWG_VERSION)\n {\n throw new Error(`Unsupported CEWG version ${this.version}`);\n }\n\n const chunkCount = stream.readUint32();\n for (let index = 0; index < chunkCount; index += 1)\n {\n const tag = decodeAscii(stream.readRaw(4));\n validateChunkTag(tag);\n if (this.chunkMap.has(tag))\n {\n throw new Error(`CEWG package contains duplicate chunk tag ${tag}`);\n }\n const size = stream.readUint32();\n const offset = stream.offset;\n const chunkBytes = stream.readRaw(size);\n const chunk = {\n tag,\n size,\n offset,\n bytes: chunkBytes\n };\n this.chunks.push(chunk);\n this.chunkMap.set(tag, chunk);\n }\n\n if (stream.remaining !== 0)\n {\n throw new Error(`CEWG package has ${stream.remaining} trailing bytes`);\n }\n\n return true;\n }\n catch (error)\n {\n this.readError = error;\n this.chunks = [];\n this.chunkMap = new Map();\n this.jsonCache = new Map();\n this.reflectionBlobIndex = null;\n return false;\n }\n }\n\n /**\n * Reports whether the package decoded successfully.\n *\n * @returns {boolean} True when no read error is present.\n */\n IsGood()\n {\n return !this.readError && this.version === CEWG_VERSION;\n }\n\n /**\n * Gets a chunk by four-character tag.\n *\n * @param {string} tag Chunk tag.\n * @returns {{tag:string,size:number,offset:number,bytes:Uint8Array}|null} Chunk record.\n */\n GetChunk(tag)\n {\n return this.chunkMap.get(tag) || null;\n }\n\n /**\n * Decodes a text chunk.\n *\n * @param {string} tag Chunk tag.\n * @returns {string|null} Decoded text, or null when absent.\n */\n GetText(tag)\n {\n const chunk = this.GetChunk(tag);\n return chunk ? textDecoder.decode(chunk.bytes) : null;\n }\n\n /**\n * Decodes a JSON chunk.\n *\n * @param {string} tag Chunk tag.\n * @returns {object|null} Parsed JSON, or null when absent.\n */\n GetJson(tag)\n {\n return cloneJson(getCachedJson(this, tag));\n }\n\n /**\n * Gets translator summary metadata from the `INFO` chunk.\n *\n * @returns {object|null} Info JSON.\n */\n get info()\n {\n return this.GetJson(\"INFO\");\n }\n\n /**\n * Gets caller-provided Carbon metadata from the `META` chunk.\n *\n * @returns {object|null} Metadata JSON.\n */\n get metadata()\n {\n return this.GetJson(\"META\");\n }\n\n /**\n * Gets the complete source permutation graph when present.\n *\n * @returns {object|null} Parsed permutation graph.\n */\n get permutationGraph()\n {\n return this.GetJson(\"PGRF\");\n }\n\n /**\n * Gets complete source effect reflection when present.\n *\n * @returns {object|null} Parsed reflection document.\n */\n get reflection()\n {\n return this.GetJson(\"RFLX\");\n }\n\n /**\n * Gets the raw reflection blob store when present.\n *\n * @returns {Uint8Array|null} RBLB bytes.\n */\n get reflectionBlobBytes()\n {\n return this.GetChunk(\"RBLB\")?.bytes ?? null;\n }\n\n /**\n * Copies one reflected byte payload by blob key or exact reference.\n *\n * @param {string|object} value Blob key or exact RFLX byte-reference object.\n * @returns {Uint8Array|null} Owned payload bytes, or null when unavailable.\n */\n GetReflectionBlob(value)\n {\n const key = typeof value === \"string\" ? value : value?.blobKey;\n if (!this.reflectionBlobIndex)\n {\n this.reflectionBlobIndex = new Map(\n (getCachedJson(this, \"RFLX\")?.blobStore?.blobs ?? []).map((entry) => [\n entry.blobKey,\n entry\n ])\n );\n }\n const entry = this.reflectionBlobIndex.get(key);\n const bytes = this.reflectionBlobBytes;\n if (!entry || !bytes) return null;\n if (typeof value !== \"string\"\n && (!value\n || value.offset !== entry.offset\n || value.byteLength !== entry.byteLength\n || value.sha256 !== entry.sha256))\n {\n return null;\n }\n const end = entry.offset + entry.byteLength;\n if (!Number.isSafeInteger(entry.offset) || entry.offset < 0\n || !Number.isSafeInteger(entry.byteLength) || entry.byteLength < 0\n || end > bytes.byteLength\n || sha256Bytes(bytes.subarray(entry.offset, end)) !== entry.sha256)\n {\n return null;\n }\n return Uint8Array.from(bytes.subarray(entry.offset, end));\n }\n\n /**\n * Gets fully hydrated portable source reflection for one permutation.\n *\n * Every reflected byte field is returned as a fresh owned `Uint8Array`.\n *\n * @param {number} [permutationIndex] Exact PGRF permutation index.\n * @returns {object|null} Validated portable reflection, or null when absent.\n */\n GetPortableEffectReflection(permutationIndex)\n {\n if (!validatedEffectReflectionPackages.has(this)) return null;\n const reflection = getCachedJson(this, \"RFLX\");\n const permutationGraph = getCachedJson(this, \"PGRF\");\n if (!reflection || !permutationGraph) return null;\n const selectedIndex = permutationIndex\n ?? getCachedJson(this, \"INFO\")?.defaultPermutationIndex\n ?? 0;\n return hydrateEffectReflectionForPermutation(\n reflection,\n permutationGraph,\n selectedIndex,\n (reference) => this.GetReflectionBlob(reference)\n );\n }\n\n /**\n * Gets translated GLSL source from the `GLSL` chunk.\n *\n * @returns {string|null} GLSL source.\n */\n get glsl()\n {\n return this.GetText(\"GLSL\");\n }\n\n /**\n * Gets translated GLSL metadata when the `GLSL` chunk contains JSON.\n *\n * Whole-effect packages store a JSON stage set in this chunk; single-stage\n * packages store raw GLSL text and return null here.\n *\n * @returns {object|null} Parsed GLSL stage set, or null for raw source.\n */\n get glslJson()\n {\n try\n {\n return this.GetJson(\"GLSL\");\n }\n catch\n {\n return null;\n }\n }\n\n /**\n * Gets original DXBC bytes when present.\n *\n * @returns {Uint8Array|null} DXBC bytes.\n */\n get dxbc()\n {\n return this.GetChunk(\"DXBC\")?.bytes || null;\n }\n\n /**\n * Returns a JSON-safe package summary.\n *\n * @returns {object} Serializable summary.\n */\n toJSON()\n {\n return {\n format: CEWG_FORMAT,\n version: this.version,\n sourcePath: this.sourcePath,\n chunks: this.chunks.map((chunk) => ({\n tag: chunk.tag,\n size: chunk.size,\n offset: chunk.offset\n })),\n readError: this.readError ? {\n name: this.readError.name,\n message: this.readError.message\n } : null\n };\n }\n}\n\n/**\n * Marks one package as having passed the canonical v3 reflection envelope.\n *\n * This is intentionally an internal deep import rather than package-root API.\n *\n * @param {CewgPackage} pkg Validated package reader.\n * @returns {void}\n */\nexport function markEffectReflectionValidated(pkg)\n{\n validatedEffectReflectionPackages.add(pkg);\n}\n\n/**\n * Decode and cache one private JSON document.\n *\n * @param {CewgPackage} pkg Package reader.\n * @param {string} tag Chunk tag.\n * @returns {object|null} Private parsed JSON, or null when absent.\n */\nfunction getCachedJson(pkg, tag)\n{\n if (!pkg.jsonCache.has(tag))\n {\n const chunk = pkg.GetChunk(tag);\n pkg.jsonCache.set(\n tag,\n chunk ? JSON.parse(jsonTextDecoder.decode(chunk.bytes)) : null\n );\n }\n return pkg.jsonCache.get(tag);\n}\n\n/**\n * Copy JSON-compatible data without reparsing its source chunk.\n *\n * @param {any} value Cached JSON value.\n * @returns {any} Structurally independent JSON value.\n */\nfunction cloneJson(value)\n{\n if (Array.isArray(value)) return value.map(cloneJson);\n if (value && typeof value === \"object\")\n {\n return Object.fromEntries(Object.entries(value).map(([ key, entry ]) => [\n key,\n cloneJson(entry)\n ]));\n }\n return value;\n}\n\nfunction validateChunkTag(tag)\n{\n if (typeof tag !== \"string\"\n || tag.length !== 4\n || [ ...tag ].some((character) =>\n {\n const code = character.charCodeAt(0);\n return code < 0x21 || code > 0x7e;\n }))\n {\n throw new Error(`Invalid CEWG chunk tag ${JSON.stringify(tag)}`);\n }\n}\n\n/**\n * Decodes an ASCII four-character code.\n *\n * @param {Uint8Array} bytes Four-byte tag payload.\n * @returns {string} ASCII string.\n */\nfunction decodeAscii(bytes)\n{\n return String.fromCharCode(...bytes);\n}\n"],"names":["CEWG_MAGIC","CEWG_FORMAT","CEWG_VERSION","textDecoder","TextDecoder","fatal","jsonTextDecoder","validatedEffectReflectionPackages","WeakSet","CewgPackage","constructor","version","chunks","chunkMap","Map","jsonCache","reflectionBlobIndex","readError","sourcePath","Read","source","options","delete","bytes","asUint8Array","stream","WebglReader","magic","decodeAscii","readRaw","length","Error","readUint32","chunkCount","index","tag","validateChunkTag","has","size","offset","chunkBytes","chunk","push","set","remaining","error","IsGood","GetChunk","get","GetText","decode","GetJson","cloneJson","getCachedJson","info","metadata","permutationGraph","reflection","reflectionBlobBytes","GetReflectionBlob","value","key","blobKey","blobStore","blobs","map","entry","byteLength","sha256","end","Number","isSafeInteger","sha256Bytes","subarray","Uint8Array","from","GetPortableEffectReflection","permutationIndex","selectedIndex","defaultPermutationIndex","hydrateEffectReflectionForPermutation","reference","glsl","glslJson","dxbc","toJSON","format","name","message","markEffectReflectionValidated","pkg","add","JSON","parse","Array","isArray","Object","fromEntries","entries","some","character","code","charCodeAt","stringify","String","fromCharCode"],"mappings":";;;;AAMA,MAAMA,UAAU,GAAG,MAAM;AACzB,MAAMC,WAAW,GAAG,MAAM;AAC1B,MAAMC,YAAY,GAAG,CAAC;AACtB,MAAMC,WAAW,GAAG,IAAIC,WAAW,CAAC,OAAO,EAAE;AAAEC,EAAAA,KAAK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K,CAAC,CACnB,CAAC,CAAC;AACP,EAAA;AACA,EAAA,OAAON,KAAK;AAChB;AAEA,SAASxB,gBAAgBA,CAACD,GAAG,EAC7B;AACI,EAAA,IAAI,OAAOA,GAAG,KAAK,QAAQ,IACpBA,GAAG,CAACL,MAAM,KAAK,CAAC,IAChB,CAAE,GAAGK,GAAG,CAAE,CAACgE,IAAI,CAAEC,SAAS,IAC7B;AACI,IAAA,MAAMC,IAAI,GAAGD,SAAS,CAACE,UAAU,CAAC,CAAC,CAAC;AACpC,IAAA,OAAOD,IAAI,GAAG,IAAI,IAAIA,IAAI,GAAG,IAAI;AACrC,EAAA,CAAC,CAAC,EACN;IACI,MAAM,IAAItE,KAAK,CAAC,CAAA,uBAAA,EAA0B6D,IAAI,CAACW,SAAS,CAACpE,GAAG,CAAC,CAAA,CAAE,CAAC;AACpE,EAAA;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAASP,WAAWA,CAACL,KAAK,EAC1B;AACI,EAAA,OAAOiF,MAAM,CAACC,YAAY,CAAC,GAAGlF,KAAK,CAAC;AACxC;;;;"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const CEWG_MAGIC = "CEWG";
|
|
2
|
+
const CEWG_VERSION = 1;
|
|
3
|
+
const textEncoder = new TextEncoder();
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Builds CarbonEngineJS CEWG shader package bytes.
|
|
7
|
+
*/
|
|
8
|
+
class CewgPackageBuilder {
|
|
9
|
+
/**
|
|
10
|
+
* Builds a CEWG v1 package from ordered chunks.
|
|
11
|
+
*
|
|
12
|
+
* @param {Array<[string, string|object|Uint8Array|ArrayBuffer|ArrayBufferView]>} chunks Ordered package chunks.
|
|
13
|
+
* @returns {Uint8Array} Package bytes.
|
|
14
|
+
*/
|
|
15
|
+
static build(chunks) {
|
|
16
|
+
const encodedChunks = chunks.map(([tag, value]) => ({
|
|
17
|
+
tag: normalizeTag(tag),
|
|
18
|
+
bytes: normalizeChunkValue(value)
|
|
19
|
+
}));
|
|
20
|
+
const tags = new Set();
|
|
21
|
+
for (const chunk of encodedChunks) {
|
|
22
|
+
if (tags.has(chunk.tag)) {
|
|
23
|
+
throw new Error(`CEWG package contains duplicate chunk tag ${chunk.tag}`);
|
|
24
|
+
}
|
|
25
|
+
tags.add(chunk.tag);
|
|
26
|
+
}
|
|
27
|
+
const size = CEWG_MAGIC.length + 8 + encodedChunks.reduce((sum, chunk) => sum + 8 + chunk.bytes.length, 0);
|
|
28
|
+
const out = new Uint8Array(size);
|
|
29
|
+
const view = new DataView(out.buffer, out.byteOffset, out.byteLength);
|
|
30
|
+
let offset = 0;
|
|
31
|
+
offset = writeAscii(out, offset, CEWG_MAGIC);
|
|
32
|
+
view.setUint32(offset, CEWG_VERSION, true);
|
|
33
|
+
offset += 4;
|
|
34
|
+
view.setUint32(offset, encodedChunks.length, true);
|
|
35
|
+
offset += 4;
|
|
36
|
+
for (const chunk of encodedChunks) {
|
|
37
|
+
offset = writeAscii(out, offset, chunk.tag);
|
|
38
|
+
view.setUint32(offset, chunk.bytes.length, true);
|
|
39
|
+
offset += 4;
|
|
40
|
+
out.set(chunk.bytes, offset);
|
|
41
|
+
offset += chunk.bytes.length;
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Normalizes a package chunk tag.
|
|
49
|
+
*
|
|
50
|
+
* @param {string} tag Four-character chunk tag.
|
|
51
|
+
* @returns {string} Normalized tag.
|
|
52
|
+
*/
|
|
53
|
+
function normalizeTag(tag) {
|
|
54
|
+
if (typeof tag !== "string" || tag.length !== 4 || [...tag].some(character => {
|
|
55
|
+
const code = character.charCodeAt(0);
|
|
56
|
+
return code < 0x21 || code > 0x7e;
|
|
57
|
+
})) {
|
|
58
|
+
throw new Error(`CEWG chunk tag must contain four printable ASCII characters: ${tag}`);
|
|
59
|
+
}
|
|
60
|
+
return tag;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Normalizes a package chunk payload.
|
|
65
|
+
*
|
|
66
|
+
* @param {string|object|Uint8Array|ArrayBuffer|ArrayBufferView} value Chunk payload.
|
|
67
|
+
* @returns {Uint8Array} Payload bytes.
|
|
68
|
+
*/
|
|
69
|
+
function normalizeChunkValue(value) {
|
|
70
|
+
if (typeof value === "string") {
|
|
71
|
+
return textEncoder.encode(value);
|
|
72
|
+
}
|
|
73
|
+
if (value instanceof Uint8Array) {
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
76
|
+
if (value instanceof ArrayBuffer) {
|
|
77
|
+
return new Uint8Array(value);
|
|
78
|
+
}
|
|
79
|
+
if (ArrayBuffer.isView(value)) {
|
|
80
|
+
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
81
|
+
}
|
|
82
|
+
if (value && typeof value === "object") {
|
|
83
|
+
return textEncoder.encode(`${JSON.stringify(value)}\n`);
|
|
84
|
+
}
|
|
85
|
+
throw new Error("Unsupported CEWG chunk value");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Writes ASCII text into a byte buffer.
|
|
90
|
+
*
|
|
91
|
+
* @param {Uint8Array} out Output buffer.
|
|
92
|
+
* @param {number} offset Current byte offset.
|
|
93
|
+
* @param {string} value ASCII text.
|
|
94
|
+
* @returns {number} Updated byte offset.
|
|
95
|
+
*/
|
|
96
|
+
function writeAscii(out, offset, value) {
|
|
97
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
98
|
+
out[offset + i] = value.charCodeAt(i) & 0xff;
|
|
99
|
+
}
|
|
100
|
+
return offset + value.length;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { CewgPackageBuilder };
|
|
104
|
+
//# sourceMappingURL=CewgPackageBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CewgPackageBuilder.js","sources":["../../../../../../src/formats/webgl/core/cewg/CewgPackageBuilder.js"],"sourcesContent":["const CEWG_MAGIC = \"CEWG\";\nconst CEWG_VERSION = 1;\nconst textEncoder = new TextEncoder();\n\n/**\n * Builds CarbonEngineJS CEWG shader package bytes.\n */\nexport class CewgPackageBuilder\n{\n /**\n * Builds a CEWG v1 package from ordered chunks.\n *\n * @param {Array<[string, string|object|Uint8Array|ArrayBuffer|ArrayBufferView]>} chunks Ordered package chunks.\n * @returns {Uint8Array} Package bytes.\n */\n static build(chunks)\n {\n const encodedChunks = chunks.map(([ tag, value ]) => ({\n tag: normalizeTag(tag),\n bytes: normalizeChunkValue(value)\n }));\n const tags = new Set();\n for (const chunk of encodedChunks)\n {\n if (tags.has(chunk.tag))\n {\n throw new Error(`CEWG package contains duplicate chunk tag ${chunk.tag}`);\n }\n tags.add(chunk.tag);\n }\n\n const size = CEWG_MAGIC.length + 8 + encodedChunks.reduce((sum, chunk) => sum + 8 + chunk.bytes.length, 0);\n const out = new Uint8Array(size);\n const view = new DataView(out.buffer, out.byteOffset, out.byteLength);\n let offset = 0;\n\n offset = writeAscii(out, offset, CEWG_MAGIC);\n view.setUint32(offset, CEWG_VERSION, true);\n offset += 4;\n view.setUint32(offset, encodedChunks.length, true);\n offset += 4;\n\n for (const chunk of encodedChunks)\n {\n offset = writeAscii(out, offset, chunk.tag);\n view.setUint32(offset, chunk.bytes.length, true);\n offset += 4;\n out.set(chunk.bytes, offset);\n offset += chunk.bytes.length;\n }\n\n return out;\n }\n}\n\n/**\n * Normalizes a package chunk tag.\n *\n * @param {string} tag Four-character chunk tag.\n * @returns {string} Normalized tag.\n */\nfunction normalizeTag(tag)\n{\n if (typeof tag !== \"string\"\n || tag.length !== 4\n || [ ...tag ].some((character) =>\n {\n const code = character.charCodeAt(0);\n return code < 0x21 || code > 0x7e;\n }))\n {\n throw new Error(`CEWG chunk tag must contain four printable ASCII characters: ${tag}`);\n }\n return tag;\n}\n\n/**\n * Normalizes a package chunk payload.\n *\n * @param {string|object|Uint8Array|ArrayBuffer|ArrayBufferView} value Chunk payload.\n * @returns {Uint8Array} Payload bytes.\n */\nfunction normalizeChunkValue(value)\n{\n if (typeof value === \"string\")\n {\n return textEncoder.encode(value);\n }\n if (value instanceof Uint8Array)\n {\n return value;\n }\n if (value instanceof ArrayBuffer)\n {\n return new Uint8Array(value);\n }\n if (ArrayBuffer.isView(value))\n {\n return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);\n }\n if (value && typeof value === \"object\")\n {\n return textEncoder.encode(`${JSON.stringify(value)}\\n`);\n }\n throw new Error(\"Unsupported CEWG chunk value\");\n}\n\n/**\n * Writes ASCII text into a byte buffer.\n *\n * @param {Uint8Array} out Output buffer.\n * @param {number} offset Current byte offset.\n * @param {string} value ASCII text.\n * @returns {number} Updated byte offset.\n */\nfunction writeAscii(out, offset, value)\n{\n for (let i = 0; i < value.length; i += 1)\n {\n out[offset + i] = value.charCodeAt(i) & 0xff;\n }\n return offset + value.length;\n}\n"],"names":["CEWG_MAGIC","CEWG_VERSION","textEncoder","TextEncoder","CewgPackageBuilder","build","chunks","encodedChunks","map","tag","value","normalizeTag","bytes","normalizeChunkValue","tags","Set","chunk","has","Error","add","size","length","reduce","sum","out","Uint8Array","view","DataView","buffer","byteOffset","byteLength","offset","writeAscii","setUint32","set","some","character","code","charCodeAt","encode","ArrayBuffer","isView","JSON","stringify","i"],"mappings":"AAAA,MAAMA,UAAU,GAAG,MAAM;AACzB,MAAMC,YAAY,GAAG,CAAC;AACtB,MAAMC,WAAW,GAAG,IAAIC,WAAW,EAAE;;AAErC;AACA;AACA;AACO,MAAMC,kBAAkB,CAC/B;AACI;AACJ;AACA;AACA;AACA;AACA;EACI,OAAOC,KAAKA,CAACC,MAAM,EACnB;AACI,IAAA,MAAMC,aAAa,GAAGD,MAAM,CAACE,GAAG,CAAC,CAAC,CAAEC,GAAG,EAAEC,KAAK,CAAE,MAAM;AAClDD,MAAAA,GAAG,EAAEE,YAAY,CAACF,GAAG,CAAC;MACtBG,KAAK,EAAEC,mBAAmB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ACI,IAAA,OAAO,IAAIe,UAAU,CAACf,KAAK,CAACkB,MAAM,EAAElB,KAAK,CAACmB,UAAU,EAAEnB,KAAK,CAACoB,UAAU,CAAC;AAC3E,EAAA;AACA,EAAA,IAAIpB,KAAK,IAAI,OAAOA,KAAK,KAAK,QAAQ,EACtC;AACI,IAAA,OAAOR,WAAW,CAACqC,MAAM,CAAC,CAAA,EAAGG,IAAI,CAACC,SAAS,CAACjC,KAAK,CAAC,CAAA,EAAA,CAAI,CAAC;AAC3D,EAAA;AACA,EAAA,MAAM,IAAIQ,KAAK,CAAC,8BAA8B,CAAC;AACnD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASc,UAAUA,CAACR,GAAG,EAAEO,MAAM,EAAErB,KAAK,EACtC;AACI,EAAA,KAAK,IAAIkC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGlC,KAAK,CAACW,MAAM,EAAEuB,CAAC,IAAI,CAAC,EACxC;AACIpB,IAAAA,GAAG,CAACO,MAAM,GAAGa,CAAC,CAAC,GAAGlC,KAAK,CAAC4B,UAAU,CAACM,CAAC,CAAC,GAAG,IAAI;AAChD,EAAA;AACA,EAAA,OAAOb,MAAM,GAAGrB,KAAK,CAACW,MAAM;AAChC;;;;"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { WebglReadError } from '../errors.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a byte view for supported binary inputs without copying when possible.
|
|
5
|
+
*
|
|
6
|
+
* @param {ArrayBuffer|ArrayBufferView|Uint8Array} value Binary payload to normalize.
|
|
7
|
+
* @returns {Uint8Array} Byte view over the supplied payload.
|
|
8
|
+
*/
|
|
9
|
+
function asUint8Array(value) {
|
|
10
|
+
if (value instanceof Uint8Array) {
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
if (value instanceof ArrayBuffer) {
|
|
14
|
+
return new Uint8Array(value);
|
|
15
|
+
}
|
|
16
|
+
if (ArrayBuffer.isView(value)) {
|
|
17
|
+
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
18
|
+
}
|
|
19
|
+
throw new TypeError("Expected an ArrayBuffer or Uint8Array");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Minimal little-endian binary reader for the flat CEWG chunk container.
|
|
24
|
+
*
|
|
25
|
+
* Trimmed from Carbon's compiled-effect `WebglReader` (see
|
|
26
|
+
* `@carbonenginejs/format-dxbc`'s and `@carbonenginejs/format-hlsl`'s vendored
|
|
27
|
+
* copies): the CEWG format has no string table, so only raw-byte and uint32
|
|
28
|
+
* reads plus offset/remaining tracking are implemented here.
|
|
29
|
+
*/
|
|
30
|
+
class WebglReader {
|
|
31
|
+
/**
|
|
32
|
+
* Creates a reader over a byte payload.
|
|
33
|
+
*
|
|
34
|
+
* @param {ArrayBuffer|ArrayBufferView|Uint8Array} bytes Source payload.
|
|
35
|
+
* @param {object} [options] Reader bounds and metadata.
|
|
36
|
+
* @param {number} [options.offset] Initial byte offset.
|
|
37
|
+
* @param {number} [options.end] Exclusive end offset.
|
|
38
|
+
* @param {string} [options.source] Source name used in error details.
|
|
39
|
+
*/
|
|
40
|
+
constructor(bytes, options = {}) {
|
|
41
|
+
this.bytes = asUint8Array(bytes);
|
|
42
|
+
this.view = new DataView(this.bytes.buffer, this.bytes.byteOffset, this.bytes.byteLength);
|
|
43
|
+
this.offset = Number(options.offset) || 0;
|
|
44
|
+
this.end = Number.isInteger(options.end) ? options.end : this.bytes.length;
|
|
45
|
+
this.source = options.source || "memory";
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Returns the unread byte count inside the configured reader bounds.
|
|
50
|
+
*
|
|
51
|
+
* @returns {number} Remaining bytes.
|
|
52
|
+
*/
|
|
53
|
+
get remaining() {
|
|
54
|
+
return this.end - this.offset;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Reads a byte range from the payload.
|
|
59
|
+
*
|
|
60
|
+
* @param {number} size Byte count to read.
|
|
61
|
+
* @returns {Uint8Array} View over the read bytes.
|
|
62
|
+
*/
|
|
63
|
+
readRaw(size) {
|
|
64
|
+
this._require(size);
|
|
65
|
+
const start = this.offset;
|
|
66
|
+
this.offset += size;
|
|
67
|
+
return this.bytes.subarray(start, start + size);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Reads a little-endian unsigned 32-bit integer.
|
|
72
|
+
*
|
|
73
|
+
* @returns {number} Integer value.
|
|
74
|
+
*/
|
|
75
|
+
readUint32() {
|
|
76
|
+
this._require(4);
|
|
77
|
+
const value = this.view.getUint32(this.offset, true);
|
|
78
|
+
this.offset += 4;
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Ensures the requested read fits inside the configured payload bounds.
|
|
84
|
+
*
|
|
85
|
+
* @param {number} size Requested byte count.
|
|
86
|
+
* @private
|
|
87
|
+
*/
|
|
88
|
+
_require(size) {
|
|
89
|
+
if (!Number.isInteger(size) || size < 0 || this.offset + size > this.end) {
|
|
90
|
+
throw new WebglReadError("Unexpected end of CEWG package data", {
|
|
91
|
+
source: this.source,
|
|
92
|
+
offset: this.offset,
|
|
93
|
+
requested: size,
|
|
94
|
+
end: this.end
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { WebglReader, asUint8Array };
|
|
101
|
+
//# sourceMappingURL=binary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binary.js","sources":["../../../../../../src/formats/webgl/core/cewg/binary.js"],"sourcesContent":["import { WebglReadError } from \"../errors.js\";\n\n/**\n * Returns a byte view for supported binary inputs without copying when possible.\n *\n * @param {ArrayBuffer|ArrayBufferView|Uint8Array} value Binary payload to normalize.\n * @returns {Uint8Array} Byte view over the supplied payload.\n */\nexport function asUint8Array(value)\n{\n if (value instanceof Uint8Array)\n {\n return value;\n }\n if (value instanceof ArrayBuffer)\n {\n return new Uint8Array(value);\n }\n if (ArrayBuffer.isView(value))\n {\n return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);\n }\n throw new TypeError(\"Expected an ArrayBuffer or Uint8Array\");\n}\n\n/**\n * Minimal little-endian binary reader for the flat CEWG chunk container.\n *\n * Trimmed from Carbon's compiled-effect `WebglReader` (see\n * `@carbonenginejs/format-dxbc`'s and `@carbonenginejs/format-hlsl`'s vendored\n * copies): the CEWG format has no string table, so only raw-byte and uint32\n * reads plus offset/remaining tracking are implemented here.\n */\nexport class WebglReader\n{\n /**\n * Creates a reader over a byte payload.\n *\n * @param {ArrayBuffer|ArrayBufferView|Uint8Array} bytes Source payload.\n * @param {object} [options] Reader bounds and metadata.\n * @param {number} [options.offset] Initial byte offset.\n * @param {number} [options.end] Exclusive end offset.\n * @param {string} [options.source] Source name used in error details.\n */\n constructor(bytes, options = {})\n {\n this.bytes = asUint8Array(bytes);\n this.view = new DataView(this.bytes.buffer, this.bytes.byteOffset, this.bytes.byteLength);\n this.offset = Number(options.offset) || 0;\n this.end = Number.isInteger(options.end) ? options.end : this.bytes.length;\n this.source = options.source || \"memory\";\n }\n\n /**\n * Returns the unread byte count inside the configured reader bounds.\n *\n * @returns {number} Remaining bytes.\n */\n get remaining()\n {\n return this.end - this.offset;\n }\n\n /**\n * Reads a byte range from the payload.\n *\n * @param {number} size Byte count to read.\n * @returns {Uint8Array} View over the read bytes.\n */\n readRaw(size)\n {\n this._require(size);\n const start = this.offset;\n this.offset += size;\n return this.bytes.subarray(start, start + size);\n }\n\n /**\n * Reads a little-endian unsigned 32-bit integer.\n *\n * @returns {number} Integer value.\n */\n readUint32()\n {\n this._require(4);\n const value = this.view.getUint32(this.offset, true);\n this.offset += 4;\n return value;\n }\n\n /**\n * Ensures the requested read fits inside the configured payload bounds.\n *\n * @param {number} size Requested byte count.\n * @private\n */\n _require(size)\n {\n if (!Number.isInteger(size) || size < 0 || this.offset + size > this.end)\n {\n throw new WebglReadError(\"Unexpected end of CEWG package data\", {\n source: this.source,\n offset: this.offset,\n requested: size,\n end: this.end\n });\n }\n }\n}\n"],"names":["asUint8Array","value","Uint8Array","ArrayBuffer","isView","buffer","byteOffset","byteLength","TypeError","WebglReader","constructor","bytes","options","view","DataView","offset","Number","end","isInteger","length","source","remaining","readRaw","size","_require","start","subarray","readUint32","getUint32","WebglReadError","requested"],"mappings":";;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,YAAYA,CAACC,KAAK,EAClC;EACI,IAAIA,KAAK,YAAYC,UAAU,EAC/B;AACI,IAAA,OAAOD,KAAK;AAChB,EAAA;EACA,IAAIA,KAAK,YAAYE,WAAW,EAChC;AACI,IAAA,OAAO,IAAID,UAAU,CAACD,KAAK,CAAC;AAChC,EAAA;AACA,EAAA,IAAIE,WAAW,CAACC,MAAM,CAACH,KAAK,CAAC,EAC7B;AACI,IAAA,OAAO,IAAIC,UAAU,CAACD,KAAK,CAACI,MAAM,EAAEJ,KAAK,CAACK,UAAU,EAAEL,KAAK,CAACM,UAAU,CAAC;AAC3E,EAAA;AACA,EAAA,MAAM,IAAIC,SAAS,CAAC,uCAAuC,CAAC;AAChE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,WAAW,CACxB;AACI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACIC,EAAAA,WAAWA,CAACC,KAAK,EAAEC,OAAO,GAAG,EAAE,EAC/B;AACI,IAAA,IAAI,CAACD,KAAK,GAAGX,YAAY,CAACW,KAAK,CAAC;IAChC,IAAI,CAACE,IAAI,GAAG,IAAIC,QAAQ,CAAC,IAAI,CAACH,KAAK,CAACN,MAAM,EAAE,IAAI,CAACM,KAAK,CAACL,UAAU,EAAE,IAAI,CAACK,KAAK,CAACJ,UAAU,CAAC;IACzF,IAAI,CAACQ,MAAM,GAAGC,MAAM,CAACJ,OAAO,CAACG,MAA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