@carbonenginejs/runtime-resource 0.10.0 → 0.11.1
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,172 @@
|
|
|
1
|
+
import { DxbcReader } from './DxbcReader.js';
|
|
2
|
+
import { DxbcReadError } from './errors.js';
|
|
3
|
+
|
|
4
|
+
const SIGNATURE_TABLE_HEADER_SIZE = 8;
|
|
5
|
+
const semanticNameDecoder = new TextDecoder("latin1");
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Per-fourCC signature element layouts.
|
|
9
|
+
*
|
|
10
|
+
* `ISGN`/`OSGN`/`PCSG` use the 24-byte Shader Model 4 layout. `OSG5` prefixes
|
|
11
|
+
* a stream index. `ISG1`/`OSG1`/`PSG1` prefix a stream index and append a
|
|
12
|
+
* minimum-precision field.
|
|
13
|
+
*/
|
|
14
|
+
const SIGNATURE_ELEMENT_LAYOUTS = Object.freeze({
|
|
15
|
+
ISGN: {
|
|
16
|
+
stride: 24,
|
|
17
|
+
hasStream: false,
|
|
18
|
+
hasMinPrecision: false
|
|
19
|
+
},
|
|
20
|
+
OSGN: {
|
|
21
|
+
stride: 24,
|
|
22
|
+
hasStream: false,
|
|
23
|
+
hasMinPrecision: false
|
|
24
|
+
},
|
|
25
|
+
PCSG: {
|
|
26
|
+
stride: 24,
|
|
27
|
+
hasStream: false,
|
|
28
|
+
hasMinPrecision: false
|
|
29
|
+
},
|
|
30
|
+
OSG5: {
|
|
31
|
+
stride: 28,
|
|
32
|
+
hasStream: true,
|
|
33
|
+
hasMinPrecision: false
|
|
34
|
+
},
|
|
35
|
+
ISG1: {
|
|
36
|
+
stride: 32,
|
|
37
|
+
hasStream: true,
|
|
38
|
+
hasMinPrecision: true
|
|
39
|
+
},
|
|
40
|
+
OSG1: {
|
|
41
|
+
stride: 32,
|
|
42
|
+
hasStream: true,
|
|
43
|
+
hasMinPrecision: true
|
|
44
|
+
},
|
|
45
|
+
PSG1: {
|
|
46
|
+
stride: 32,
|
|
47
|
+
hasStream: true,
|
|
48
|
+
hasMinPrecision: true
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Register component type names indexed by DXBC signature component-type ids.
|
|
54
|
+
*/
|
|
55
|
+
const DxbcComponentTypeNames = Object.freeze(["unknown", "uint32", "int32", "float32"]);
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* DXBC input/output signature chunk reader for `ISGN`-family chunks.
|
|
59
|
+
*/
|
|
60
|
+
class DxbcSignatureChunk {
|
|
61
|
+
/**
|
|
62
|
+
* Creates an empty signature chunk; call a read entry point to populate its parameter records.
|
|
63
|
+
*/
|
|
64
|
+
constructor() {
|
|
65
|
+
this.fourCC = "";
|
|
66
|
+
this.elements = [];
|
|
67
|
+
this.source = "memory";
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Reads a signature chunk payload into semantic/register element records.
|
|
72
|
+
*
|
|
73
|
+
* @param {{fourCC:string,bytes:Uint8Array}} chunk Chunk record from `DxbcContainer`.
|
|
74
|
+
* @param {object} [options] Read options.
|
|
75
|
+
* @param {string} [options.source] Source name used in error details.
|
|
76
|
+
* @returns {DxbcSignatureChunk} This signature.
|
|
77
|
+
*/
|
|
78
|
+
Read(chunk, options = {}) {
|
|
79
|
+
this.fourCC = chunk.fourCC;
|
|
80
|
+
this.source = options.source || "memory";
|
|
81
|
+
const layout = SIGNATURE_ELEMENT_LAYOUTS[this.fourCC];
|
|
82
|
+
if (!layout) {
|
|
83
|
+
throw new DxbcReadError("Unsupported DXBC signature chunk", {
|
|
84
|
+
source: this.source,
|
|
85
|
+
fourCC: this.fourCC
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const bytes = chunk.bytes;
|
|
89
|
+
const reader = new DxbcReader(bytes, {
|
|
90
|
+
source: this.source
|
|
91
|
+
});
|
|
92
|
+
const elementCount = reader.readUint32();
|
|
93
|
+
const elementOffset = reader.readUint32() || SIGNATURE_TABLE_HEADER_SIZE;
|
|
94
|
+
if (elementOffset + elementCount * layout.stride > bytes.length) {
|
|
95
|
+
throw new DxbcReadError("DXBC signature elements lie outside the chunk", {
|
|
96
|
+
source: this.source,
|
|
97
|
+
fourCC: this.fourCC,
|
|
98
|
+
elementCount,
|
|
99
|
+
elementOffset,
|
|
100
|
+
chunkSize: bytes.length
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
this.elements = [];
|
|
104
|
+
reader.offset = elementOffset;
|
|
105
|
+
for (let index = 0; index < elementCount; index += 1) {
|
|
106
|
+
const stream = layout.hasStream ? reader.readUint32() : 0;
|
|
107
|
+
const semanticNameOffset = reader.readUint32();
|
|
108
|
+
const semanticIndex = reader.readUint32();
|
|
109
|
+
const systemValueType = reader.readUint32();
|
|
110
|
+
const componentType = reader.readUint32();
|
|
111
|
+
const registerIndex = reader.readUint32();
|
|
112
|
+
const mask = reader.readUint8();
|
|
113
|
+
const readWriteMask = reader.readUint8();
|
|
114
|
+
reader.Skip(2);
|
|
115
|
+
const minPrecision = layout.hasMinPrecision ? reader.readUint32() : 0;
|
|
116
|
+
this.elements.push({
|
|
117
|
+
semanticName: this._readSemanticName(bytes, semanticNameOffset, index),
|
|
118
|
+
semanticIndex,
|
|
119
|
+
systemValueType,
|
|
120
|
+
componentType,
|
|
121
|
+
componentTypeName: DxbcComponentTypeNames[componentType] || "unknown",
|
|
122
|
+
registerIndex,
|
|
123
|
+
mask,
|
|
124
|
+
readWriteMask,
|
|
125
|
+
stream,
|
|
126
|
+
minPrecision
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Finds a signature element by semantic name and index.
|
|
134
|
+
*
|
|
135
|
+
* @param {string} semanticName Case-insensitive semantic name such as `"TEXCOORD"`.
|
|
136
|
+
* @param {number} [semanticIndex] Semantic index, defaulting to 0.
|
|
137
|
+
* @returns {object|null} Element record or null.
|
|
138
|
+
*/
|
|
139
|
+
findElement(semanticName, semanticIndex = 0) {
|
|
140
|
+
const wanted = String(semanticName).toUpperCase();
|
|
141
|
+
return this.elements.find(element => element.semanticName.toUpperCase() === wanted && element.semanticIndex === semanticIndex) || null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Resolves a null-terminated semantic name inside the chunk payload.
|
|
146
|
+
*
|
|
147
|
+
* @param {Uint8Array} bytes Chunk payload.
|
|
148
|
+
* @param {number} offset Name offset relative to the chunk payload start.
|
|
149
|
+
* @param {number} index Element index used in error details.
|
|
150
|
+
* @returns {string} Decoded semantic name.
|
|
151
|
+
* @private
|
|
152
|
+
*/
|
|
153
|
+
_readSemanticName(bytes, offset, index) {
|
|
154
|
+
if (offset >= bytes.length) {
|
|
155
|
+
throw new DxbcReadError("DXBC signature semantic name lies outside the chunk", {
|
|
156
|
+
source: this.source,
|
|
157
|
+
fourCC: this.fourCC,
|
|
158
|
+
elementIndex: index,
|
|
159
|
+
offset,
|
|
160
|
+
chunkSize: bytes.length
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
let end = offset;
|
|
164
|
+
while (end < bytes.length && bytes[end] !== 0) {
|
|
165
|
+
end += 1;
|
|
166
|
+
}
|
|
167
|
+
return semanticNameDecoder.decode(bytes.subarray(offset, end));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export { DxbcComponentTypeNames, DxbcSignatureChunk };
|
|
172
|
+
//# sourceMappingURL=signature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature.js","sources":["../../../../../src/formats/dxbc/core/signature.js"],"sourcesContent":["import { DxbcReader } from \"./DxbcReader.js\";\nimport { DxbcReadError } from \"./errors.js\";\n\nconst SIGNATURE_TABLE_HEADER_SIZE = 8;\n\nconst semanticNameDecoder = new TextDecoder(\"latin1\");\n\n/**\n * Per-fourCC signature element layouts.\n *\n * `ISGN`/`OSGN`/`PCSG` use the 24-byte Shader Model 4 layout. `OSG5` prefixes\n * a stream index. `ISG1`/`OSG1`/`PSG1` prefix a stream index and append a\n * minimum-precision field.\n */\nconst SIGNATURE_ELEMENT_LAYOUTS = Object.freeze({\n ISGN: { stride: 24, hasStream: false, hasMinPrecision: false },\n OSGN: { stride: 24, hasStream: false, hasMinPrecision: false },\n PCSG: { stride: 24, hasStream: false, hasMinPrecision: false },\n OSG5: { stride: 28, hasStream: true, hasMinPrecision: false },\n ISG1: { stride: 32, hasStream: true, hasMinPrecision: true },\n OSG1: { stride: 32, hasStream: true, hasMinPrecision: true },\n PSG1: { stride: 32, hasStream: true, hasMinPrecision: true }\n});\n\n/**\n * Register component type names indexed by DXBC signature component-type ids.\n */\nexport const DxbcComponentTypeNames = Object.freeze([ \"unknown\", \"uint32\", \"int32\", \"float32\" ]);\n\n/**\n * DXBC input/output signature chunk reader for `ISGN`-family chunks.\n */\nexport class DxbcSignatureChunk\n{\n /**\n * Creates an empty signature chunk; call a read entry point to populate its parameter records.\n */\n constructor()\n {\n this.fourCC = \"\";\n this.elements = [];\n this.source = \"memory\";\n }\n\n /**\n * Reads a signature chunk payload into semantic/register element records.\n *\n * @param {{fourCC:string,bytes:Uint8Array}} chunk Chunk record from `DxbcContainer`.\n * @param {object} [options] Read options.\n * @param {string} [options.source] Source name used in error details.\n * @returns {DxbcSignatureChunk} This signature.\n */\n Read(chunk, options = {})\n {\n this.fourCC = chunk.fourCC;\n this.source = options.source || \"memory\";\n const layout = SIGNATURE_ELEMENT_LAYOUTS[this.fourCC];\n if (!layout)\n {\n throw new DxbcReadError(\"Unsupported DXBC signature chunk\", {\n source: this.source,\n fourCC: this.fourCC\n });\n }\n\n const bytes = chunk.bytes;\n const reader = new DxbcReader(bytes, { source: this.source });\n const elementCount = reader.readUint32();\n const elementOffset = reader.readUint32() || SIGNATURE_TABLE_HEADER_SIZE;\n if (elementOffset + elementCount * layout.stride > bytes.length)\n {\n throw new DxbcReadError(\"DXBC signature elements lie outside the chunk\", {\n source: this.source,\n fourCC: this.fourCC,\n elementCount,\n elementOffset,\n chunkSize: bytes.length\n });\n }\n\n this.elements = [];\n reader.offset = elementOffset;\n for (let index = 0; index < elementCount; index += 1)\n {\n const stream = layout.hasStream ? reader.readUint32() : 0;\n const semanticNameOffset = reader.readUint32();\n const semanticIndex = reader.readUint32();\n const systemValueType = reader.readUint32();\n const componentType = reader.readUint32();\n const registerIndex = reader.readUint32();\n const mask = reader.readUint8();\n const readWriteMask = reader.readUint8();\n reader.Skip(2);\n const minPrecision = layout.hasMinPrecision ? reader.readUint32() : 0;\n\n this.elements.push({\n semanticName: this._readSemanticName(bytes, semanticNameOffset, index),\n semanticIndex,\n systemValueType,\n componentType,\n componentTypeName: DxbcComponentTypeNames[componentType] || \"unknown\",\n registerIndex,\n mask,\n readWriteMask,\n stream,\n minPrecision\n });\n }\n return this;\n }\n\n /**\n * Finds a signature element by semantic name and index.\n *\n * @param {string} semanticName Case-insensitive semantic name such as `\"TEXCOORD\"`.\n * @param {number} [semanticIndex] Semantic index, defaulting to 0.\n * @returns {object|null} Element record or null.\n */\n findElement(semanticName, semanticIndex = 0)\n {\n const wanted = String(semanticName).toUpperCase();\n return this.elements.find(\n (element) => element.semanticName.toUpperCase() === wanted && element.semanticIndex === semanticIndex\n ) || null;\n }\n\n /**\n * Resolves a null-terminated semantic name inside the chunk payload.\n *\n * @param {Uint8Array} bytes Chunk payload.\n * @param {number} offset Name offset relative to the chunk payload start.\n * @param {number} index Element index used in error details.\n * @returns {string} Decoded semantic name.\n * @private\n */\n _readSemanticName(bytes, offset, index)\n {\n if (offset >= bytes.length)\n {\n throw new DxbcReadError(\"DXBC signature semantic name lies outside the chunk\", {\n source: this.source,\n fourCC: this.fourCC,\n elementIndex: index,\n offset,\n chunkSize: bytes.length\n });\n }\n let end = offset;\n while (end < bytes.length && bytes[end] !== 0)\n {\n end += 1;\n }\n return semanticNameDecoder.decode(bytes.subarray(offset, end));\n }\n}\n"],"names":["SIGNATURE_TABLE_HEADER_SIZE","semanticNameDecoder","TextDecoder","SIGNATURE_ELEMENT_LAYOUTS","Object","freeze","ISGN","stride","hasStream","hasMinPrecision","OSGN","PCSG","OSG5","ISG1","OSG1","PSG1","DxbcComponentTypeNames","DxbcSignatureChunk","constructor","fourCC","elements","source","Read","chunk","options","layout","DxbcReadError","bytes","reader","DxbcReader","elementCount","readUint32","elementOffset","length","chunkSize","offset","index","stream","semanticNameOffset","semanticIndex","systemValueType","componentType","registerIndex","mask","readUint8","readWriteMask","Skip","minPrecision","push","semanticName","_readSemanticName","componentTypeName","findElement","wanted","String","toUpperCase","find","element","elementIndex","end","decode","subarray"],"mappings":";;;AAGA,MAAMA,2BAA2B,GAAG,CAAC;AAErC,MAAMC,mBAAmB,GAAG,IAAIC,WAAW,CAAC,QAAQ,CAAC;;AAErD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,yBAAyB,GAAGC,MAAM,CAACC,MAAM,CAAC;AAC5CC,EAAAA,IAAI,EAAE;AAAEC,IAAAA,MAAM,EAAE,EAAE;AAAEC,IAAAA,SAAS,EAAE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AAM,IAAII,OAAO,CAAClB,aAAa,KAAKA,aAC5F,CAAC,IAAI,IAAI;AACb,EAAA;;AAEA;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACIW,EAAAA,iBAAiBA,CAACvB,KAAK,EAAEQ,MAAM,EAAEC,KAAK,EACtC;AACI,IAAA,IAAID,MAAM,IAAIR,KAAK,CAACM,MAAM,EAC1B;AACI,MAAA,MAAM,IAAIP,aAAa,CAAC,qDAAqD,EAAE;QAC3EL,MAAM,EAAE,IAAI,CAACA,MAAM;QACnBF,MAAM,EAAE,IAAI,CAACA,MAAM;AACnBuC,QAAAA,YAAY,EAAEtB,KAAK;QACnBD,MAAM;QACND,SAAS,EAAEP,KAAK,CAACM;AACrB,OAAC,CAAC;AACN,IAAA;IACA,IAAI0B,GAAG,GAAGxB,MAAM;AAChB,IAAA,OAAOwB,GAAG,GAAGhC,KAAK,CAACM,MAAM,IAAIN,KAAK,CAACgC,GAAG,CAAC,KAAK,CAAC,EAC7C;AACIA,MAAAA,GAAG,IAAI,CAAC;AACZ,IAAA;AACA,IAAA,OAAO1D,mBAAmB,CAAC2D,MAAM,CAACjC,KAAK,CAACkC,QAAQ,CAAC1B,MAAM,EAAEwB,GAAG,CAAC,CAAC;AAClE,EAAA;AACJ;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { HlslEffectRes } from './core/tr2/resources/HlslEffectRes.js';
|
|
2
|
+
import { DEFAULT_VALUES, normalizeValues, validateClassKey, validateClass, readWithValues, inspectWithValues, toJsonValue, toBytes, OUTPUT_JSON, OUTPUT_METADATA, OUTPUT_RAW } from './core/helpers.js';
|
|
3
|
+
import { CLASS_KEYS } from './core/json.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Exposed CarbonEngineJS-facing Tr2 effect container format class.
|
|
7
|
+
*
|
|
8
|
+
* Keep this file small and reviewable: the Tr2 effect graph parser lives
|
|
9
|
+
* under src/core/tr2 (internal parsing machinery, not part of this
|
|
10
|
+
* package's public surface); input/option normalization, the shared read
|
|
11
|
+
* path, and the JSON emitters live under src/core.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const FORMAT_NAME = "CjsHlslFormat";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* CarbonEngineJS-facing reader for CCP's Tr2 compiled effect container
|
|
18
|
+
* format (`.sm_hi` / `.sm_lo` / `.sm_depth` bodies).
|
|
19
|
+
*
|
|
20
|
+
* The Cjs prefix marks this as a JavaScript format/construction boundary.
|
|
21
|
+
* This format profile has no dependency on any DXBC/shader-bytecode decoder: shader
|
|
22
|
+
* bodies stay as opaque bytes in the emitted graph. The public contract is
|
|
23
|
+
* plain JSON data (`emit: "json"`, the default) — the documented effect
|
|
24
|
+
* graph shape described in `docs/reference/json-graph.md`. `emit: "raw"`
|
|
25
|
+
* exposes the internal
|
|
26
|
+
* HlslEffectRes graph directly; treat it as unstable, not schema-guaranteed
|
|
27
|
+
* internals, useful mainly for resolving multiple permutations by hand.
|
|
28
|
+
*
|
|
29
|
+
* The `classes` option lets a caller register constructors for specific
|
|
30
|
+
* node kinds in the emitted JSON graph (see `CjsHlslFormat.CLASS_KEYS`);
|
|
31
|
+
* class registration does not depend on importing internal graph classes.
|
|
32
|
+
*/
|
|
33
|
+
class CjsHlslFormat {
|
|
34
|
+
#emit = DEFAULT_VALUES.emit;
|
|
35
|
+
#source = DEFAULT_VALUES.source;
|
|
36
|
+
#permutation = DEFAULT_VALUES.permutation;
|
|
37
|
+
#classes = DEFAULT_VALUES.classes;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Create a reusable format profile.
|
|
41
|
+
*
|
|
42
|
+
* @param {object} [options] Default format values.
|
|
43
|
+
*/
|
|
44
|
+
constructor(options = {}) {
|
|
45
|
+
this.SetValues(options);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Set format values for this reusable profile.
|
|
50
|
+
*
|
|
51
|
+
* @param {object} [options] Values to merge into the profile.
|
|
52
|
+
* @returns {CjsHlslFormat} This format profile.
|
|
53
|
+
*/
|
|
54
|
+
SetValues(options = {}) {
|
|
55
|
+
const values = normalizeValues(this.GetValues(), options, FORMAT_NAME);
|
|
56
|
+
this.#emit = values.emit;
|
|
57
|
+
this.#source = values.source;
|
|
58
|
+
this.#permutation = values.permutation;
|
|
59
|
+
this.#classes = values.classes;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Get this profile's current values, optionally with per-call overrides.
|
|
65
|
+
*
|
|
66
|
+
* @param {object} [options] Optional values to merge into a copy.
|
|
67
|
+
* @returns {object} A copy of the effective values.
|
|
68
|
+
*/
|
|
69
|
+
GetValues(options = {}) {
|
|
70
|
+
return normalizeValues({
|
|
71
|
+
emit: this.#emit,
|
|
72
|
+
source: this.#source,
|
|
73
|
+
permutation: this.#permutation,
|
|
74
|
+
classes: this.#classes
|
|
75
|
+
}, options, FORMAT_NAME);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Set multiple node-class constructors for this profile.
|
|
80
|
+
*
|
|
81
|
+
* @param {object} [classes] Map of node class keys to constructors. See {@link CjsHlslFormat.CLASS_KEYS}.
|
|
82
|
+
* @returns {CjsHlslFormat} This format profile.
|
|
83
|
+
*/
|
|
84
|
+
SetClasses(classes = {}) {
|
|
85
|
+
return this.SetValues({
|
|
86
|
+
classes
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Set one node-class constructor for this profile.
|
|
92
|
+
*
|
|
93
|
+
* @param {string} type Node class key.
|
|
94
|
+
* @param {Function|null|undefined} Class Constructor to use, or nullish to delete.
|
|
95
|
+
* @returns {CjsHlslFormat} This format profile.
|
|
96
|
+
*/
|
|
97
|
+
SetClass(type, Class) {
|
|
98
|
+
if (Class === null || Class === undefined) {
|
|
99
|
+
validateClassKey(type, FORMAT_NAME);
|
|
100
|
+
const classes = {
|
|
101
|
+
...this.#classes
|
|
102
|
+
};
|
|
103
|
+
delete classes[type];
|
|
104
|
+
this.#classes = classes;
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
validateClass(type, Class, FORMAT_NAME);
|
|
108
|
+
return this.SetValues({
|
|
109
|
+
classes: {
|
|
110
|
+
[type]: Class
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Get a configured node-class constructor.
|
|
117
|
+
*
|
|
118
|
+
* @param {string} type Node class key.
|
|
119
|
+
* @returns {Function|undefined} The registered constructor, if any.
|
|
120
|
+
*/
|
|
121
|
+
GetClass(type) {
|
|
122
|
+
validateClassKey(type, FORMAT_NAME);
|
|
123
|
+
return this.#classes[type];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Whether this reader has a constructor registered for a node class key.
|
|
128
|
+
*
|
|
129
|
+
* @param {string} type Node class key.
|
|
130
|
+
* @returns {boolean} True when a constructor is registered.
|
|
131
|
+
*/
|
|
132
|
+
HasClass(type) {
|
|
133
|
+
return !!this.GetClass(type);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Read a Tr2 effect payload with this profile's values.
|
|
138
|
+
*
|
|
139
|
+
* @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Tr2 effect container bytes.
|
|
140
|
+
* @param {object} [options] Per-call value overrides.
|
|
141
|
+
* @returns {HlslEffectRes|object} The raw HlslEffectRes instance, compact metadata, or the documented JSON graph.
|
|
142
|
+
*/
|
|
143
|
+
Read(input, options = {}) {
|
|
144
|
+
return readWithValues(input, this.GetValues(options));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Inspect a Tr2 effect payload: header facts plus the default (or
|
|
149
|
+
* selected) permutation's technique names and stage counts.
|
|
150
|
+
*
|
|
151
|
+
* @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Tr2 effect container bytes.
|
|
152
|
+
* @param {object} [options] Per-call value overrides.
|
|
153
|
+
* @returns {object} Plain summary data.
|
|
154
|
+
*/
|
|
155
|
+
Inspect(input, options = {}) {
|
|
156
|
+
return inspectWithValues(input, this.GetValues(options));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Convert format output to JSON-compatible data.
|
|
161
|
+
*
|
|
162
|
+
* @param {any} value Format output to convert.
|
|
163
|
+
* @returns {any} Plain JSON-compatible data.
|
|
164
|
+
*/
|
|
165
|
+
ToJSON(value) {
|
|
166
|
+
return toJsonValue(value);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Static payload sniff. Static methods use camelCase by convention.
|
|
171
|
+
*
|
|
172
|
+
* The Tr2 effect container has no magic number, so this attempts a
|
|
173
|
+
* cheap header-only load (version, string table, permutation axes and
|
|
174
|
+
* body offsets — no shader bodies) and reports whether it succeeded.
|
|
175
|
+
*
|
|
176
|
+
* @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Candidate bytes.
|
|
177
|
+
* @returns {boolean} True when the payload's header decodes as a supported Tr2 effect.
|
|
178
|
+
*/
|
|
179
|
+
static isSupported(input) {
|
|
180
|
+
try {
|
|
181
|
+
const bytes = toBytes(input);
|
|
182
|
+
return new HlslEffectRes().DoLoad(bytes, {
|
|
183
|
+
source: "isSupported"
|
|
184
|
+
});
|
|
185
|
+
} catch {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Static one-shot read.
|
|
192
|
+
*
|
|
193
|
+
* @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Tr2 effect container bytes.
|
|
194
|
+
* @param {object} [options] Format values.
|
|
195
|
+
* @returns {HlslEffectRes|object} The raw HlslEffectRes instance, compact metadata, or the documented JSON graph.
|
|
196
|
+
*/
|
|
197
|
+
static read(input, options = {}) {
|
|
198
|
+
return readWithValues(input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Static one-shot inspection.
|
|
203
|
+
*
|
|
204
|
+
* @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Tr2 effect container bytes.
|
|
205
|
+
* @param {object} [options] Format values.
|
|
206
|
+
* @returns {object} Plain summary data.
|
|
207
|
+
*/
|
|
208
|
+
static inspect(input, options = {}) {
|
|
209
|
+
return inspectWithValues(input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Static JSON-compatible conversion.
|
|
214
|
+
*
|
|
215
|
+
* @param {any} value Format output to convert.
|
|
216
|
+
* @returns {any} Plain JSON-compatible data.
|
|
217
|
+
*/
|
|
218
|
+
static toJSON(value) {
|
|
219
|
+
return toJsonValue(value);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Node-only convenience: reads a compiled Tr2 effect file from disk.
|
|
224
|
+
*
|
|
225
|
+
* @param {string} path Path to a compiled Carbon effect file (`.sm_hi` etc.).
|
|
226
|
+
* @param {object} [options] Format values.
|
|
227
|
+
* @returns {Promise<HlslEffectRes|object>} The raw HlslEffectRes instance, compact metadata, or the documented JSON graph.
|
|
228
|
+
*/
|
|
229
|
+
static async readFile(path, options = {}) {
|
|
230
|
+
if (typeof path !== "string" || !path) {
|
|
231
|
+
throw new TypeError(`${FORMAT_NAME}: readFile path must be a non-empty string`);
|
|
232
|
+
}
|
|
233
|
+
const {
|
|
234
|
+
readFile
|
|
235
|
+
} = await import('node:fs/promises');
|
|
236
|
+
const input = await readFile(path);
|
|
237
|
+
return readWithValues(input, normalizeValues(DEFAULT_VALUES, {
|
|
238
|
+
source: path,
|
|
239
|
+
...options
|
|
240
|
+
}, FORMAT_NAME));
|
|
241
|
+
}
|
|
242
|
+
static OUTPUT_JSON = OUTPUT_JSON;
|
|
243
|
+
static OUTPUT_METADATA = OUTPUT_METADATA;
|
|
244
|
+
static OUTPUT_RAW = OUTPUT_RAW;
|
|
245
|
+
static CLASS_KEYS = CLASS_KEYS;
|
|
246
|
+
static type = Object.freeze(["shader"]);
|
|
247
|
+
static mediaTypes = Object.freeze(["shader"]);
|
|
248
|
+
static inputTypes = Object.freeze(["sm_hi", "sm_lo", "sm_depth"]);
|
|
249
|
+
static outputTypes = Object.freeze([OUTPUT_JSON, OUTPUT_METADATA]);
|
|
250
|
+
static debugOutputTypes = Object.freeze([OUTPUT_RAW]);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export { CjsHlslFormat, CjsHlslFormat as default };
|
|
254
|
+
//# sourceMappingURL=CjsHlslFormat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CjsHlslFormat.js","sources":["../../../../src/formats/hlsl/CjsHlslFormat.js"],"sourcesContent":["/**\n * Exposed CarbonEngineJS-facing Tr2 effect container format class.\n *\n * Keep this file small and reviewable: the Tr2 effect graph parser lives\n * under src/core/tr2 (internal parsing machinery, not part of this\n * package's public surface); input/option normalization, the shared read\n * path, and the JSON emitters live under src/core.\n */\n\nimport { HlslEffectRes } from \"./core/tr2/resources/HlslEffectRes.js\";\nimport {\n CLASS_KEYS,\n DEFAULT_VALUES,\n OUTPUT_JSON,\n OUTPUT_METADATA,\n OUTPUT_RAW,\n inspectWithValues,\n normalizeValues,\n readWithValues,\n toBytes,\n toJsonValue,\n validateClass,\n validateClassKey\n} from \"./core/helpers.js\";\n\nconst FORMAT_NAME = \"CjsHlslFormat\";\n\n/**\n * CarbonEngineJS-facing reader for CCP's Tr2 compiled effect container\n * format (`.sm_hi` / `.sm_lo` / `.sm_depth` bodies).\n *\n * The Cjs prefix marks this as a JavaScript format/construction boundary.\n * This format profile has no dependency on any DXBC/shader-bytecode decoder: shader\n * bodies stay as opaque bytes in the emitted graph. The public contract is\n * plain JSON data (`emit: \"json\"`, the default) — the documented effect\n * graph shape described in `docs/reference/json-graph.md`. `emit: \"raw\"`\n * exposes the internal\n * HlslEffectRes graph directly; treat it as unstable, not schema-guaranteed\n * internals, useful mainly for resolving multiple permutations by hand.\n *\n * The `classes` option lets a caller register constructors for specific\n * node kinds in the emitted JSON graph (see `CjsHlslFormat.CLASS_KEYS`);\n * class registration does not depend on importing internal graph classes.\n */\nexport class CjsHlslFormat\n{\n\n #emit = DEFAULT_VALUES.emit;\n #source = DEFAULT_VALUES.source;\n #permutation = DEFAULT_VALUES.permutation;\n #classes = DEFAULT_VALUES.classes;\n\n /**\n * Create a reusable format profile.\n *\n * @param {object} [options] Default format values.\n */\n constructor(options = {})\n {\n this.SetValues(options);\n }\n\n /**\n * Set format values for this reusable profile.\n *\n * @param {object} [options] Values to merge into the profile.\n * @returns {CjsHlslFormat} This format profile.\n */\n SetValues(options = {})\n {\n const values = normalizeValues(this.GetValues(), options, FORMAT_NAME);\n\n this.#emit = values.emit;\n this.#source = values.source;\n this.#permutation = values.permutation;\n this.#classes = values.classes;\n\n return this;\n }\n\n /**\n * Get this profile's current values, optionally with per-call overrides.\n *\n * @param {object} [options] Optional values to merge into a copy.\n * @returns {object} A copy of the effective values.\n */\n GetValues(options = {})\n {\n return normalizeValues({\n emit: this.#emit,\n source: this.#source,\n permutation: this.#permutation,\n classes: this.#classes\n }, options, FORMAT_NAME);\n }\n\n /**\n * Set multiple node-class constructors for this profile.\n *\n * @param {object} [classes] Map of node class keys to constructors. See {@link CjsHlslFormat.CLASS_KEYS}.\n * @returns {CjsHlslFormat} This format profile.\n */\n SetClasses(classes = {})\n {\n return this.SetValues({ classes });\n }\n\n /**\n * Set one node-class constructor for this profile.\n *\n * @param {string} type Node class key.\n * @param {Function|null|undefined} Class Constructor to use, or nullish to delete.\n * @returns {CjsHlslFormat} This format profile.\n */\n SetClass(type, Class)\n {\n if (Class === null || Class === undefined)\n {\n validateClassKey(type, FORMAT_NAME);\n const classes = { ...this.#classes };\n delete classes[type];\n this.#classes = classes;\n return this;\n }\n\n validateClass(type, Class, FORMAT_NAME);\n return this.SetValues({ classes: { [type]: Class } });\n }\n\n /**\n * Get a configured node-class constructor.\n *\n * @param {string} type Node class key.\n * @returns {Function|undefined} The registered constructor, if any.\n */\n GetClass(type)\n {\n validateClassKey(type, FORMAT_NAME);\n return this.#classes[type];\n }\n\n /**\n * Whether this reader has a constructor registered for a node class key.\n *\n * @param {string} type Node class key.\n * @returns {boolean} True when a constructor is registered.\n */\n HasClass(type)\n {\n return !!this.GetClass(type);\n }\n\n /**\n * Read a Tr2 effect payload with this profile's values.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Tr2 effect container bytes.\n * @param {object} [options] Per-call value overrides.\n * @returns {HlslEffectRes|object} The raw HlslEffectRes instance, compact metadata, or the documented JSON graph.\n */\n Read(input, options = {})\n {\n return readWithValues(input, this.GetValues(options));\n }\n\n /**\n * Inspect a Tr2 effect payload: header facts plus the default (or\n * selected) permutation's technique names and stage counts.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Tr2 effect container bytes.\n * @param {object} [options] Per-call value overrides.\n * @returns {object} Plain summary data.\n */\n Inspect(input, options = {})\n {\n return inspectWithValues(input, this.GetValues(options));\n }\n\n /**\n * Convert format output to JSON-compatible data.\n *\n * @param {any} value Format output to convert.\n * @returns {any} Plain JSON-compatible data.\n */\n ToJSON(value)\n {\n return toJsonValue(value);\n }\n\n /**\n * Static payload sniff. Static methods use camelCase by convention.\n *\n * The Tr2 effect container has no magic number, so this attempts a\n * cheap header-only load (version, string table, permutation axes and\n * body offsets — no shader bodies) and reports whether it succeeded.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Candidate bytes.\n * @returns {boolean} True when the payload's header decodes as a supported Tr2 effect.\n */\n static isSupported(input)\n {\n try\n {\n const bytes = toBytes(input);\n return new HlslEffectRes().DoLoad(bytes, { source: \"isSupported\" });\n }\n catch\n {\n return false;\n }\n }\n\n /**\n * Static one-shot read.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Tr2 effect container bytes.\n * @param {object} [options] Format values.\n * @returns {HlslEffectRes|object} The raw HlslEffectRes instance, compact metadata, or the documented JSON graph.\n */\n static read(input, options = {})\n {\n return readWithValues(input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));\n }\n\n /**\n * Static one-shot inspection.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Tr2 effect container bytes.\n * @param {object} [options] Format values.\n * @returns {object} Plain summary data.\n */\n static inspect(input, options = {})\n {\n return inspectWithValues(input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));\n }\n\n /**\n * Static JSON-compatible conversion.\n *\n * @param {any} value Format output to convert.\n * @returns {any} Plain JSON-compatible data.\n */\n static toJSON(value)\n {\n return toJsonValue(value);\n }\n\n /**\n * Node-only convenience: reads a compiled Tr2 effect file from disk.\n *\n * @param {string} path Path to a compiled Carbon effect file (`.sm_hi` etc.).\n * @param {object} [options] Format values.\n * @returns {Promise<HlslEffectRes|object>} The raw HlslEffectRes instance, compact metadata, or the documented JSON graph.\n */\n static async readFile(path, options = {})\n {\n if (typeof path !== \"string\" || !path)\n {\n throw new TypeError(`${FORMAT_NAME}: readFile path must be a non-empty string`);\n }\n\n const { readFile } = await import(\"node:fs/promises\");\n const input = await readFile(path);\n\n return readWithValues(input, normalizeValues(DEFAULT_VALUES, { source: path, ...options }, FORMAT_NAME));\n }\n\n static OUTPUT_JSON = OUTPUT_JSON;\n static OUTPUT_METADATA = OUTPUT_METADATA;\n static OUTPUT_RAW = OUTPUT_RAW;\n static CLASS_KEYS = CLASS_KEYS;\n static type = Object.freeze([ \"shader\" ]);\n static mediaTypes = Object.freeze([ \"shader\" ]);\n static inputTypes = Object.freeze([ \"sm_hi\", \"sm_lo\", \"sm_depth\" ]);\n static outputTypes = Object.freeze([ OUTPUT_JSON, OUTPUT_METADATA ]);\n static debugOutputTypes = Object.freeze([ OUTPUT_RAW ]);\n\n}\n\nexport default CjsHlslFormat;\n"],"names":["FORMAT_NAME","CjsHlslFormat","DEFAULT_VALUES","emit","source","permutation","classes","constructor","options","SetValues","values","normalizeValues","GetValues","SetClasses","SetClass","type","Class","undefined","validateClassKey","validateClass","GetClass","HasClass","Read","input","readWithValues","Inspect","inspectWithValues","ToJSON","value","toJsonValue","isSupported","bytes","toBytes","HlslEffectRes","DoLoad","read","inspect","toJSON","readFile","path","TypeError","OUTPUT_JSON","OUTPUT_METADATA","OUTPUT_RAW","CLASS_KEYS","Object","freeze","mediaTypes","inputTypes","outputTypes","debugOutputTypes"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAkBA,MAAMA,WAAW,GAAG,eAAe;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,aAAa,CAC1B;AAEI,EAAA,KAAK,GAAGC,cAAc,CAACC,IAAI;AAC3B,EAAA,OAAO,GAAGD,cAAc,CAACE,MAAM;AAC/B,EAAA,YAAY,GAAGF,cAAc,CAACG,WAAW;AACzC,EAAA,QAAQ,GAAGH,cAAc,CAACI,OAAO;;AAEjC;AACJ;AACA;AACA;AACA;AACIC,EAAAA,WAAWA,CAACC,OAAO,GAAG,EAAE,EACxB;AACI,IAAA,IAAI,CAACC,SAAS,CAACD,OAAO,CAAC;AAC3B,EAAA;;AAEA;AACJ;AACA;AACA;AACA;AACA;AACIC,EAAAA,SAASA,CAACD,OAAO,GAAG,EAAE,EACtB;AACI,IAAA,MAAME,MAAM,GAAGC,eAAe,CAAC,IAAI,CAACC,SAAS,EAAE,EAAEJ,OAAO,EAAER,WAAW,CAAC;AAEtE,IAAA,IAAI,CAAC,KAAK,GAAGU,MAAM,CAACP,IAAI;AACxB,IAAA,IAAI,CAA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,IAAI,GAAG8B,MAAM,CAACC,MAAM,CAAC,CAAE,QAAQ,CAAE,CAAC;EACzC,OAAOC,UAAU,GAAGF,MAAM,CAACC,MAAM,CAAC,CAAE,QAAQ,CAAE,CAAC;AAC/C,EAAA,OAAOE,UAAU,GAAGH,MAAM,CAACC,MAAM,CAAC,CAAE,OAAO,EAAE,OAAO,EAAE,UAAU,CAAE,CAAC;EACnE,OAAOG,WAAW,GAAGJ,MAAM,CAACC,MAAM,CAAC,CAAEL,WAAW,EAAEC,eAAe,CAAE,CAAC;EACpE,OAAOQ,gBAAgB,GAAGL,MAAM,CAACC,MAAM,CAAC,CAAEH,UAAU,CAAE,CAAC;AAE3D;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reinterprets a little-endian uint32 annotation payload as a float32.
|
|
3
|
+
*
|
|
4
|
+
* @param {number} value Unsigned 32-bit integer containing float bits.
|
|
5
|
+
* @returns {number} Float value represented by the same bits.
|
|
6
|
+
*/
|
|
7
|
+
function cjsUint32ToFloat32(value) {
|
|
8
|
+
const bytes = new Uint8Array(4);
|
|
9
|
+
const view = new DataView(bytes.buffer);
|
|
10
|
+
view.setUint32(0, value >>> 0, true);
|
|
11
|
+
return view.getFloat32(0, true);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { cjsUint32ToFloat32 };
|
|
15
|
+
//# sourceMappingURL=HlslBinaryUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HlslBinaryUtils.js","sources":["../../../../../src/formats/hlsl/core/HlslBinaryUtils.js"],"sourcesContent":["/**\n * Reinterprets a little-endian uint32 annotation payload as a float32.\n *\n * @param {number} value Unsigned 32-bit integer containing float bits.\n * @returns {number} Float value represented by the same bits.\n */\nexport function cjsUint32ToFloat32(value)\n{\n const bytes = new Uint8Array(4);\n const view = new DataView(bytes.buffer);\n view.setUint32(0, value >>> 0, true);\n return view.getFloat32(0, true);\n}\n"],"names":["cjsUint32ToFloat32","value","bytes","Uint8Array","view","DataView","buffer","setUint32","getFloat32"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,kBAAkBA,CAACC,KAAK,EACxC;AACI,EAAA,MAAMC,KAAK,GAAG,IAAIC,UAAU,CAAC,CAAC,CAAC;EAC/B,MAAMC,IAAI,GAAG,IAAIC,QAAQ,CAACH,KAAK,CAACI,MAAM,CAAC;EACvCF,IAAI,CAACG,SAAS,CAAC,CAAC,EAAEN,KAAK,KAAK,CAAC,EAAE,IAAI,CAAC;AACpC,EAAA,OAAOG,IAAI,CAACI,UAAU,CAAC,CAAC,EAAE,IAAI,CAAC;AACnC;;;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error raised when a Carbon/Trinity effect payload cannot be decoded safely.
|
|
3
|
+
*/
|
|
4
|
+
class HlslEffectReadError extends Error {
|
|
5
|
+
/**
|
|
6
|
+
* Creates an effect-read error with structured location details.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} message Human-readable failure reason.
|
|
9
|
+
* @param {object} [details] Extra reader state such as source, offset, or size.
|
|
10
|
+
*/
|
|
11
|
+
constructor(message, details = {}) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "HlslEffectReadError";
|
|
14
|
+
this.details = details;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { HlslEffectReadError };
|
|
19
|
+
//# sourceMappingURL=HlslEffectReadError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HlslEffectReadError.js","sources":["../../../../../src/formats/hlsl/core/HlslEffectReadError.js"],"sourcesContent":["/**\n * Error raised when a Carbon/Trinity effect payload cannot be decoded safely.\n */\nexport class HlslEffectReadError extends Error\n{\n /**\n * Creates an effect-read error with structured location details.\n *\n * @param {string} message Human-readable failure reason.\n * @param {object} [details] Extra reader state such as source, offset, or size.\n */\n constructor(message, details = {})\n {\n super(message);\n this.name = \"HlslEffectReadError\";\n this.details = details;\n }\n}\n"],"names":["HlslEffectReadError","Error","constructor","message","details","name"],"mappings":"AAAA;AACA;AACA;AACO,MAAMA,mBAAmB,SAASC,KAAK,CAC9C;AACI;AACJ;AACA;AACA;AACA;AACA;AACIC,EAAAA,WAAWA,CAACC,OAAO,EAAEC,OAAO,GAAG,EAAE,EACjC;IACI,KAAK,CAACD,OAAO,CAAC;IACd,IAAI,CAACE,IAAI,GAAG,qBAAqB;IACjC,IAAI,CAACD,OAAO,GAAGA,OAAO;AAC1B,EAAA;AACJ;;;;"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { HlslRenderStateSetup } from './HlslRenderStateSetup.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* In-memory JavaScript substitute for Carbon's effect state manager registry.
|
|
5
|
+
*/
|
|
6
|
+
class HlslEffectStateManager {
|
|
7
|
+
/**
|
|
8
|
+
* Creates empty registries for shaders, programs, render states, and libraries.
|
|
9
|
+
*/
|
|
10
|
+
constructor() {
|
|
11
|
+
this._nextShader = 1;
|
|
12
|
+
this._nextProgram = 1;
|
|
13
|
+
this._nextRenderState = 1;
|
|
14
|
+
this._nextLibrary = 1;
|
|
15
|
+
this.shaders = new Map();
|
|
16
|
+
this.shaderPrograms = new Map();
|
|
17
|
+
this.renderStates = new Map();
|
|
18
|
+
this.shaderLibraries = new Map();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Registers a shader stage payload and returns a stable numeric handle.
|
|
23
|
+
*
|
|
24
|
+
* @param {number} stageType Trinity shader stage enum value.
|
|
25
|
+
* @param {object} bytecode Captured shader bytecode.
|
|
26
|
+
* @param {object} signature Stage signature metadata.
|
|
27
|
+
* @param {string} [effectName] Source effect name or path.
|
|
28
|
+
* @returns {number} Shader handle.
|
|
29
|
+
*/
|
|
30
|
+
RegisterShader(stageType, bytecode, signature, effectName = "") {
|
|
31
|
+
const handle = this._nextShader++;
|
|
32
|
+
this.shaders.set(handle, {
|
|
33
|
+
stageType,
|
|
34
|
+
bytecode,
|
|
35
|
+
signature,
|
|
36
|
+
effectName
|
|
37
|
+
});
|
|
38
|
+
return handle;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Registers a shader program from one or more shader handles.
|
|
43
|
+
*
|
|
44
|
+
* @param {number[]} shaderHandles Shader handles in effect stage order.
|
|
45
|
+
* @param {number} [stageCount] Number of active stage handles to use.
|
|
46
|
+
* @returns {number} Shader program handle.
|
|
47
|
+
*/
|
|
48
|
+
RegisterShaderProgram(shaderHandles, stageCount = shaderHandles.length) {
|
|
49
|
+
const handle = this._nextProgram++;
|
|
50
|
+
this.shaderPrograms.set(handle, {
|
|
51
|
+
shaderHandles: shaderHandles.slice(0, stageCount),
|
|
52
|
+
stageCount
|
|
53
|
+
});
|
|
54
|
+
return handle;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Registers a program override pairing for Carbon-compatible call sites.
|
|
59
|
+
*
|
|
60
|
+
* @param {number} program Base shader program handle.
|
|
61
|
+
* @param {number} overrideProgram Override shader program handle.
|
|
62
|
+
* @returns {number} Override program handle.
|
|
63
|
+
*/
|
|
64
|
+
RegisterShaderProgramOverride(program, overrideProgram) {
|
|
65
|
+
const handle = this._nextProgram++;
|
|
66
|
+
this.shaderPrograms.set(handle, {
|
|
67
|
+
program,
|
|
68
|
+
overrideProgram,
|
|
69
|
+
isOverride: true
|
|
70
|
+
});
|
|
71
|
+
return handle;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Registers a render-state setup and returns its handle.
|
|
76
|
+
*
|
|
77
|
+
* @param {HlslRenderStateSetup|Map<number, number>|object} states Render-state setup.
|
|
78
|
+
* @returns {number} Render-state handle.
|
|
79
|
+
*/
|
|
80
|
+
RegisterRenderStateSetup(states) {
|
|
81
|
+
const handle = this._nextRenderState++;
|
|
82
|
+
this.renderStates.set(handle, states instanceof HlslRenderStateSetup ? states : new HlslRenderStateSetup(states));
|
|
83
|
+
return handle;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Registers a DXIL/DXBC library bytecode payload and returns its handle.
|
|
88
|
+
*
|
|
89
|
+
* @param {object} bytecode Captured shader-library bytecode.
|
|
90
|
+
* @returns {number} Shader library handle.
|
|
91
|
+
*/
|
|
92
|
+
RegisterShaderLibrary(bytecode) {
|
|
93
|
+
const handle = this._nextLibrary++;
|
|
94
|
+
this.shaderLibraries.set(handle, bytecode);
|
|
95
|
+
return handle;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Looks up a registered shader by handle.
|
|
100
|
+
*
|
|
101
|
+
* @param {number} handle Shader handle.
|
|
102
|
+
* @returns {object|null} Registered shader metadata or null.
|
|
103
|
+
*/
|
|
104
|
+
GetShader(handle) {
|
|
105
|
+
return this.shaders.get(handle) || null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Looks up a registered shader program by handle.
|
|
110
|
+
*
|
|
111
|
+
* @param {number} handle Shader program handle.
|
|
112
|
+
* @returns {object|null} Registered program metadata or null.
|
|
113
|
+
*/
|
|
114
|
+
GetShaderProgram(handle) {
|
|
115
|
+
return this.shaderPrograms.get(handle) || null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Looks up a registered render-state setup by handle.
|
|
120
|
+
*
|
|
121
|
+
* @param {number} handle Render-state handle.
|
|
122
|
+
* @returns {HlslRenderStateSetup|null} Registered render-state setup or null.
|
|
123
|
+
*/
|
|
124
|
+
GetRenderStateSetup(handle) {
|
|
125
|
+
return this.renderStates.get(handle) || null;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export { HlslEffectStateManager };
|
|
130
|
+
//# sourceMappingURL=HlslEffectStateManager.js.map
|