@carbonenginejs/runtime-resource 0.12.2 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/dist/CjsResMan.js +393 -29
- package/dist/CjsResMan.js.map +1 -1
- package/dist/format/carbonEffect/CjsCarbonEffectReader.js +165 -118
- package/dist/format/carbonEffect/CjsCarbonEffectReader.js.map +1 -1
- package/dist/format/carbonEffect/buildCarbonEffectContainer.js +182 -0
- package/dist/format/carbonEffect/buildCarbonEffectContainer.js.map +1 -0
- package/dist/format/carbonEffect/carbonEffectBackendBlock.js +7 -113
- package/dist/format/carbonEffect/carbonEffectBackendBlock.js.map +1 -1
- package/dist/format/carbonEffect/carbonEffectRecords.js +258 -66
- package/dist/format/carbonEffect/carbonEffectRecords.js.map +1 -1
- package/dist/format/carbonEffect/carbonEffectResourceTransform.js +197 -0
- package/dist/format/carbonEffect/carbonEffectResourceTransform.js.map +1 -0
- package/dist/format/effect/effectBodyInventory.js +146 -0
- package/dist/format/effect/effectBodyInventory.js.map +1 -0
- package/dist/format/effect/effectPermutationGraph.js +13 -13
- package/dist/format/effect/effectPermutationGraph.js.map +1 -1
- package/dist/format/index.js +4 -4
- package/dist/formats/black/CjsBlackFormat.js +19 -1
- package/dist/formats/black/CjsBlackFormat.js.map +1 -1
- package/dist/formats/bnk/CjsBnkFormat.js +28 -9
- package/dist/formats/bnk/CjsBnkFormat.js.map +1 -1
- package/dist/formats/bnk/core/busNodes.js +252 -0
- package/dist/formats/bnk/core/busNodes.js.map +1 -0
- package/dist/formats/bnk/core/effectNodes.js +147 -0
- package/dist/formats/bnk/core/effectNodes.js.map +1 -0
- package/dist/formats/bnk/core/eventAction.js +135 -24
- package/dist/formats/bnk/core/eventAction.js.map +1 -1
- package/dist/formats/bnk/core/globalSettings.js +215 -0
- package/dist/formats/bnk/core/globalSettings.js.map +1 -0
- package/dist/formats/bnk/core/helpers.js +37 -5
- package/dist/formats/bnk/core/helpers.js.map +1 -1
- package/dist/formats/bnk/core/musicNodes.js +43 -19
- package/dist/formats/bnk/core/musicNodes.js.map +1 -1
- package/dist/formats/bnk/core/nodeBase.js +28 -7
- package/dist/formats/bnk/core/nodeBase.js.map +1 -1
- package/dist/formats/dds/core/helpers.js +40 -1
- package/dist/formats/dds/core/helpers.js.map +1 -1
- package/dist/formats/dxbc/CjsDxbcFormat.js +45 -0
- package/dist/formats/dxbc/CjsDxbcFormat.js.map +1 -1
- package/dist/formats/dxbc/core/disassemble.js +240 -0
- package/dist/formats/dxbc/core/disassemble.js.map +1 -0
- package/dist/formats/gltf/CjsGltfFormat.js +1 -39
- package/dist/formats/gltf/CjsGltfFormat.js.map +1 -1
- package/dist/formats/gltf/core/helpers.js +1 -21
- package/dist/formats/gltf/core/helpers.js.map +1 -1
- package/dist/formats/hlsl/CjsHlslFormat.js +0 -21
- package/dist/formats/hlsl/CjsHlslFormat.js.map +1 -1
- package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js +118 -49
- package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js.map +1 -1
- package/dist/formats/hlsl/core/detailMapFamily.js +128 -0
- package/dist/formats/hlsl/core/detailMapFamily.js.map +1 -0
- package/dist/formats/hlsl/core/localLightFamily.js +133 -0
- package/dist/formats/hlsl/core/localLightFamily.js.map +1 -0
- package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js +79 -73
- package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js.map +1 -1
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectBindingManifest.js +8 -1
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectBindingManifest.js.map +1 -1
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectDescription.js +11 -691
- package/dist/formats/hlsl/core/tr2/shader/HlslEffectDescription.js.map +1 -1
- package/dist/formats/index.js +4 -2
- package/dist/formats/index.js.map +1 -1
- package/dist/formats/obj/CjsObjFormat.js +1 -22
- package/dist/formats/obj/CjsObjFormat.js.map +1 -1
- package/dist/formats/obj/core/helpers.js +1 -21
- package/dist/formats/obj/core/helpers.js.map +1 -1
- package/dist/formats/pickle/CjsPickleFormat.js +214 -0
- package/dist/formats/pickle/CjsPickleFormat.js.map +1 -0
- package/dist/formats/pickle/core/CjsPickleProtocol0Reader.js +551 -0
- package/dist/formats/pickle/core/CjsPickleProtocol0Reader.js.map +1 -0
- package/dist/formats/pickle/index.js +2 -0
- package/dist/formats/pickle/index.js.map +1 -0
- package/dist/formats/red/core/redGraph.js +11 -8
- package/dist/formats/red/core/redGraph.js.map +1 -1
- package/dist/formats/stl/CjsStlFormat.js +1 -46
- package/dist/formats/stl/CjsStlFormat.js.map +1 -1
- package/dist/formats/stl/core/helpers.js +1 -21
- package/dist/formats/stl/core/helpers.js.map +1 -1
- package/dist/formats/webgl/CjsWebglFormat.js +33 -55
- package/dist/formats/webgl/CjsWebglFormat.js.map +1 -1
- package/dist/formats/webgl/core/buildGlslEffectContainer.js +70 -0
- package/dist/formats/webgl/core/buildGlslEffectContainer.js.map +1 -0
- package/dist/formats/webgl/core/effectPackage.js +216 -108
- package/dist/formats/webgl/core/effectPackage.js.map +1 -1
- package/dist/formats/webgl/core/errors.js +1 -1
- package/dist/formats/webgl/core/errors.js.map +1 -1
- package/dist/formats/webgl/core/glsl/DxbcGlslEmitter.js +166 -24
- package/dist/formats/webgl/core/glsl/DxbcGlslEmitter.js.map +1 -1
- package/dist/formats/webgl/core/glsl/DxbcGlslOperandFormatter.js +63 -5
- package/dist/formats/webgl/core/glsl/DxbcGlslOperandFormatter.js.map +1 -1
- package/dist/formats/webgl/core/glsl/packedLightFixups.js +98 -0
- package/dist/formats/webgl/core/glsl/packedLightFixups.js.map +1 -0
- package/dist/formats/webgl/core/glslBackendBlock.js +552 -0
- package/dist/formats/webgl/core/glslBackendBlock.js.map +1 -0
- package/dist/formats/webgl/core/glslBackendBodySet.js +243 -0
- package/dist/formats/webgl/core/glslBackendBodySet.js.map +1 -0
- package/dist/formats/webgl/core/{cewgCompleteness.js → glslEffectCompleteness.js} +12 -8
- package/dist/formats/webgl/core/glslEffectCompleteness.js.map +1 -0
- package/dist/formats/webgl/core/helpers.js +33 -172
- package/dist/formats/webgl/core/helpers.js.map +1 -1
- package/dist/formats/webgl/core/inspectGlslEffectContainer.js +122 -0
- package/dist/formats/webgl/core/inspectGlslEffectContainer.js.map +1 -0
- package/dist/formats/webgl/core/readGlslEffectContainer.js +249 -0
- package/dist/formats/webgl/core/readGlslEffectContainer.js.map +1 -0
- package/dist/formats/webgpu/CjsWebgpuFormat.js +15 -15
- package/dist/formats/webgpu/CjsWebgpuFormat.js.map +1 -1
- package/dist/formats/webgpu/core/buildCarbonEffectContainer.js +37 -145
- package/dist/formats/webgpu/core/buildCarbonEffectContainer.js.map +1 -1
- package/dist/formats/webgpu/core/{cewgpu/CewgpuContainer.js → carbonWebgpu/CarbonWebgpuContainer.js} +13 -27
- package/dist/formats/webgpu/core/carbonWebgpu/CarbonWebgpuContainer.js.map +1 -0
- package/dist/formats/webgpu/core/{cewgpu → carbonWebgpu}/containerViews.js +1 -1
- package/dist/formats/webgpu/core/carbonWebgpu/containerViews.js.map +1 -0
- package/dist/formats/webgpu/core/{cewgpu → carbonWebgpu}/validateContainer.js +4 -4
- package/dist/formats/webgpu/core/carbonWebgpu/validateContainer.js.map +1 -0
- package/dist/formats/webgpu/core/effectBackendBodySet.js +18 -18
- package/dist/formats/webgpu/core/effectBackendBodySet.js.map +1 -1
- package/dist/formats/webgpu/core/errors.js +1 -1
- package/dist/formats/webgpu/core/errors.js.map +1 -1
- package/dist/formats/webgpu/core/helpers.js +22 -22
- package/dist/formats/webgpu/core/helpers.js.map +1 -1
- package/dist/formats/webgpu/core/packageEffect.js +11 -15
- package/dist/formats/webgpu/core/packageEffect.js.map +1 -1
- package/dist/formats/webgpu/core/packageEffectSelection.js +1 -1
- package/dist/formats/webgpu/core/packageEffectSelection.js.map +1 -1
- package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js +23 -23
- package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js.map +1 -1
- package/dist/formats/webgpu/core/wgsl/buildWgslSet.js +6 -6
- package/dist/formats/webgpu/core/wgsl/buildWgslSet.js.map +1 -1
- package/dist/formats/yaml/CjsYamlFormat.js +3 -3
- package/dist/formats/yaml/CjsYamlFormat.js.map +1 -1
- package/dist/formats/yaml/core/CjsYamlReader.js +4 -6
- package/dist/formats/yaml/core/CjsYamlReader.js.map +1 -1
- package/dist/formats/yaml/core/helpers.js +27 -1
- package/dist/formats/yaml/core/helpers.js.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/resource/CjsLoadingObject.js +19 -0
- package/dist/resource/CjsLoadingObject.js.map +1 -0
- package/dist/resource/CjsResource.js +4 -0
- package/dist/resource/CjsResource.js.map +1 -1
- package/dist/resource/ResourceHandlerMode.js +14 -0
- package/dist/resource/ResourceHandlerMode.js.map +1 -0
- package/dist/resource/index.js +2 -0
- package/dist/resource/index.js.map +1 -1
- package/dist/resource/shader/Tr2EffectRes.js +118 -213
- package/dist/resource/shader/Tr2EffectRes.js.map +1 -1
- package/dist/resource/shader/Tr2Shader.js +37 -15
- package/dist/resource/shader/Tr2Shader.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectConstant.js +37 -29
- package/dist/resource/shader/reflection/Tr2EffectConstant.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectDescription.js +39 -34
- package/dist/resource/shader/reflection/Tr2EffectDescription.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectLibrary.js +51 -30
- package/dist/resource/shader/reflection/Tr2EffectLibrary.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js +45 -25
- package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectResource.js +51 -17
- package/dist/resource/shader/reflection/Tr2EffectResource.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectStageInput.js +219 -88
- package/dist/resource/shader/reflection/Tr2EffectStageInput.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectTechnique.js +28 -18
- package/dist/resource/shader/reflection/Tr2EffectTechnique.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2Pass.js +96 -39
- package/dist/resource/shader/reflection/Tr2Pass.js.map +1 -1
- package/dist/resource/shader/reflection/carbonRecordFields.js +159 -0
- package/dist/resource/shader/reflection/carbonRecordFields.js.map +1 -0
- package/dist/resource/shader/reflection/shaderStage.js +22 -0
- package/dist/resource/shader/reflection/shaderStage.js.map +1 -0
- package/dist/resource/shader/sampler/Tr2SamplerSetup.js +68 -10
- package/dist/resource/shader/sampler/Tr2SamplerSetup.js.map +1 -1
- package/dist/worker/CjsResManMainThreadLoader.js +9 -7
- package/dist/worker/CjsResManMainThreadLoader.js.map +1 -1
- package/dist/worker/CjsResManWorker.js +5 -4
- package/dist/worker/CjsResManWorker.js.map +1 -1
- package/dist/worker/CjsResManWorkerLoader.js +9 -6
- package/dist/worker/CjsResManWorkerLoader.js.map +1 -1
- package/docs/README.md +2 -2
- package/docs/architecture.md +12 -3
- package/docs/concepts/resource-lifecycle.md +9 -8
- package/docs/concepts/shader-resource-model.md +14 -17
- package/docs/concepts/writing-an-engine-adapter.md +1 -1
- package/docs/formats/README.md +4 -2
- package/docs/formats/carbon-effect-container.md +127 -26
- package/docs/formats/dxbc/architecture.md +1 -1
- package/docs/formats/dxbc/reference/api.md +28 -0
- package/docs/formats/hlsl/README.md +3 -3
- package/docs/formats/hlsl/architecture.md +8 -9
- package/docs/formats/hlsl/guides/hydrating-json-output.md +3 -5
- package/docs/formats/hlsl/guides/reading-effects.md +5 -1
- package/docs/formats/hlsl/reference/advanced-analysis.md +20 -25
- package/docs/formats/hlsl/reference/api.md +0 -7
- package/docs/formats/hlsl/reference/json-graph.md +1 -4
- package/docs/formats/pickle.md +82 -0
- package/docs/formats/webgl/README.md +71 -13
- package/docs/formats/webgl/architecture.md +16 -17
- package/docs/formats/webgl/carbon-constant-layouts.md +3 -3
- package/docs/formats/webgl/decl-io.md +3 -3
- package/docs/formats/webgl/memory-structured.md +27 -8
- package/docs/formats/webgl/texture-sample.md +1 -1
- package/docs/formats/webgpu/README.md +3 -3
- package/docs/formats/webgpu/architecture.md +5 -6
- package/docs/formats/webgpu/formats/{cewgpu.md → carbon-webgpu.md} +10 -11
- package/docs/formats/webgpu/guides/effect-packaging.md +6 -8
- package/docs/formats/webgpu/reference/api.md +11 -12
- package/docs/formats/webgpu/reference/wgsl-compatibility.md +11 -8
- package/docs/formats/wwise.md +63 -2
- package/docs/reference/classes/core.md +10 -0
- package/docs/reference/classes/formats.md +40 -48
- package/docs/reference/classes/resources.md +2 -2
- package/docs/reference/queues.md +88 -4
- package/docs/reference/workers.md +7 -0
- package/package.json +61 -61
- package/dist/format/carbonEffect/carbonDescriptionFromPortable.js +0 -372
- package/dist/format/carbonEffect/carbonDescriptionFromPortable.js.map +0 -1
- package/dist/format/effect/effectReflectionPackage.js +0 -636
- package/dist/format/effect/effectReflectionPackage.js.map +0 -1
- package/dist/formats/hlsl/core/HlslReader.js +0 -16
- package/dist/formats/hlsl/core/HlslReader.js.map +0 -1
- package/dist/formats/hlsl/core/portableReflection.js +0 -848
- package/dist/formats/hlsl/core/portableReflection.js.map +0 -1
- package/dist/formats/hlsl/portable.js +0 -2
- package/dist/formats/hlsl/portable.js.map +0 -1
- package/dist/formats/webgl/core/cewg/CewgPackage.js +0 -340
- package/dist/formats/webgl/core/cewg/CewgPackage.js.map +0 -1
- package/dist/formats/webgl/core/cewg/CewgPackageBuilder.js +0 -104
- package/dist/formats/webgl/core/cewg/CewgPackageBuilder.js.map +0 -1
- package/dist/formats/webgl/core/cewg/binary.js +0 -19
- package/dist/formats/webgl/core/cewg/binary.js.map +0 -1
- package/dist/formats/webgl/core/cewgCompleteness.js.map +0 -1
- package/dist/formats/webgl/core/effectPackageValidation.js +0 -331
- package/dist/formats/webgl/core/effectPackageValidation.js.map +0 -1
- package/dist/formats/webgpu/core/cewgpu/CewgpuContainer.js.map +0 -1
- package/dist/formats/webgpu/core/cewgpu/containerViews.js.map +0 -1
- package/dist/formats/webgpu/core/cewgpu/validateContainer.js.map +0 -1
- package/dist/resource/shader/portable.js +0 -33
- package/dist/resource/shader/portable.js.map +0 -1
- package/docs/formats/hlsl/reference/portable-reflection.md +0 -141
- package/docs/formats/webgl/effect-reflection.md +0 -127
|
@@ -1 +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,CAAC,OAAO,GAAGO,MAAM,CAACN,MAAM;AAC5B,IAAA,IAAI,CAAC,YAAY,GAAGM,MAAM,CAACL,WAAW;AACtC,IAAA,IAAI,CAAC,QAAQ,GAAGK,MAAM,CAACJ,OAAO;AAE9B,IAAA,OAAO,IAAI;AACf,EAAA;;AAEA;AACJ;AACA;AACA;AACA;AACA;AACIM,EAAAA,SAASA,CAACJ,OAAO,GAAG,EAAE,EACtB;AACI,IAAA,OAAOG,eAAe,CAAC;AACnBR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L,WAAW,EAAEC,eAAe,CAAE,CAAC;EACpE,OAAOQ,gBAAgB,GAAGL,MAAM,CAACC,MAAM,CAAC,CAAEH,UAAU,CAAE,CAAC;AAE3D;;;;"}
|
|
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 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","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;A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C,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;;;;"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { CjsFormatReadError } from '../../../format/CjsFormatError.js';
|
|
2
2
|
import { HlslEffectConstant } from './tr2/shader/HlslEffectConstant.js';
|
|
3
|
+
import { HlslEffectLibrary } from './tr2/shader/HlslEffectLibrary.js';
|
|
3
4
|
import { HlslEffectParameterAnnotation } from './tr2/shader/HlslEffectParameterAnnotation.js';
|
|
4
5
|
import { HlslEffectResource } from './tr2/shader/HlslEffectResource.js';
|
|
5
6
|
import { HlslEffectStageInput } from './tr2/shader/HlslEffectStageInput.js';
|
|
6
7
|
import { HlslEffectStateManager } from './HlslEffectStateManager.js';
|
|
7
8
|
import { HlslEffectTechnique } from './tr2/shader/HlslEffectTechnique.js';
|
|
8
9
|
import { HlslPass } from './tr2/shader/HlslPass.js';
|
|
10
|
+
import { HlslShaderBytecode } from './HlslShaderBytecode.js';
|
|
9
11
|
import { HlslRenderContextEnum, HlslUsageCodeNames } from './tr2/HlslRenderContextEnum.js';
|
|
10
12
|
import { HlslRenderStateSetup } from './HlslRenderStateSetup.js';
|
|
11
13
|
import { HlslResourceSetDescription } from './HlslResourceSetDescription.js';
|
|
@@ -343,9 +345,8 @@ const REGISTER_RULES = Object.freeze({
|
|
|
343
345
|
* Pipeline input rules.
|
|
344
346
|
*
|
|
345
347
|
* `usageName` is derived from the `usage` byte rather than carried: it is a
|
|
346
|
-
* display name looked up from a table
|
|
347
|
-
*
|
|
348
|
-
* Nothing goes on the wire for it.
|
|
348
|
+
* display name looked up from a table, exactly as Carbon derives it through
|
|
349
|
+
* `GetStringForUsageCode` (`EffectData.h:86`). Nothing goes on the wire for it.
|
|
349
350
|
*/
|
|
350
351
|
const PIPELINE_INPUT_RULES = Object.freeze({
|
|
351
352
|
usage: (target, value) => {
|
|
@@ -382,8 +383,8 @@ const ANNOTATION_RULES = Object.freeze({
|
|
|
382
383
|
},
|
|
383
384
|
// A non-string annotation value is four raw bytes: Carbon writes it through a
|
|
384
385
|
// float union and reads it through a different one, so the bytes are the only
|
|
385
|
-
// faithful form. The three typed views are derived from
|
|
386
|
-
//
|
|
386
|
+
// faithful form. The three typed views are derived from those bytes, one per
|
|
387
|
+
// union member Carbon reads back through.
|
|
387
388
|
rawValue: (target, value, record) => {
|
|
388
389
|
if (record.type === ANNOTATION_TYPE_STRING) return;
|
|
389
390
|
const bits = rawUint32(value);
|
|
@@ -409,7 +410,7 @@ function mapTextureRecord(record) {
|
|
|
409
410
|
*
|
|
410
411
|
* A UAV record is one byte shorter than a texture record: it carries no
|
|
411
412
|
* `isSRGB`. Carbon's reader hardcodes it false (`Tr2EffectDescription.cpp:450`),
|
|
412
|
-
*
|
|
413
|
+
* so the runtime object's
|
|
413
414
|
* constructor default is restored explicitly rather than left to chance —
|
|
414
415
|
* `metadata.toJSON()` emits the key for a UAV even though the wire never carries
|
|
415
416
|
* it, because both kinds share `HlslEffectResource`.
|
|
@@ -429,9 +430,11 @@ function mapUavRecord(record) {
|
|
|
429
430
|
* Two conversions beyond the flat-to-nested reshape:
|
|
430
431
|
*
|
|
431
432
|
* - Carbon nulls a sampler's name when it is not dynamic
|
|
432
|
-
* (`Tr2EffectDescription.cpp:430-433
|
|
433
|
-
* `
|
|
434
|
-
*
|
|
433
|
+
* (`Tr2EffectDescription.cpp:430-433`), so the wire's empty string must become
|
|
434
|
+
* `null` again. A pre-v13 record carries no `isDynamic` at all; the class
|
|
435
|
+
* default (dynamic) then keeps the name, matching the legacy reader, which
|
|
436
|
+
* never assigned the flag for those versions. Like `isSRGB`, the nulling is
|
|
437
|
+
* *accidentally correct* if left alone —
|
|
435
438
|
* `""` and `null` are both falsy, so `metadataName` and the heap-view lookup
|
|
436
439
|
* behave identically — and only a structural diff catches it.
|
|
437
440
|
* - `comparison` and `isDynamic` are `u8` on the wire and boolean at runtime.
|
|
@@ -450,9 +453,8 @@ function mapSamplerRecord(record) {
|
|
|
450
453
|
/**
|
|
451
454
|
* Maps one static sampler record onto its runtime signature entry.
|
|
452
455
|
*
|
|
453
|
-
* The runtime shape keeps the `*Raw` companions non-enumerable,
|
|
454
|
-
* `
|
|
455
|
-
* only.
|
|
456
|
+
* The runtime shape keeps the `*Raw` companions non-enumerable, so a
|
|
457
|
+
* `cloneJson` of the descriptor sees the value form only.
|
|
456
458
|
*
|
|
457
459
|
* @param {object} record Wire static sampler record.
|
|
458
460
|
* @returns {object} Runtime static sampler entry.
|
|
@@ -520,7 +522,7 @@ function mapAnnotationRecord(record) {
|
|
|
520
522
|
*
|
|
521
523
|
* Reproduced rather than stored: it is a function of the register type, the
|
|
522
524
|
* stage type and the caller's per-frame start registers, none of which the
|
|
523
|
-
* container needs to carry
|
|
525
|
+
* container needs to carry.
|
|
524
526
|
*
|
|
525
527
|
* @param {object} register Runtime register declaration.
|
|
526
528
|
* @param {number} stageType Stage enum value.
|
|
@@ -552,12 +554,13 @@ function applyStageData(input, data, stageType, context) {
|
|
|
552
554
|
input.constants = (data.constants ?? []).map(mapConstantRecord);
|
|
553
555
|
|
|
554
556
|
// The declared size is the unclamped one; the runtime clamps it to
|
|
555
|
-
// SHADER_CONSTANTS_MAX and slices the payload to match
|
|
556
|
-
// (`
|
|
557
|
+
// SHADER_CONSTANTS_MAX and slices the payload to match, as Carbon does
|
|
558
|
+
// (`Tr2EffectDescription.h:160`). `packMaterial` allocates an
|
|
557
559
|
// ArrayBuffer of exactly this size, so restoring the unclamped value would
|
|
558
560
|
// write past the layout the shader expects — on any effect above 4096 bytes
|
|
559
561
|
// of constants, which is precisely the size a small fixture never reaches.
|
|
560
562
|
const declaredSize = data.defaultValues?.size ?? 0;
|
|
563
|
+
input.sourceConstantValueSize = declaredSize;
|
|
561
564
|
input.sourceConstantValues = Uint8Array.from(data.defaultValues?.bytes ?? new Uint8Array(0));
|
|
562
565
|
input.m_constantValueSize = Math.min(declaredSize, HlslEffectStageInput.SHADER_CONSTANTS_MAX);
|
|
563
566
|
input.constantValues = input.sourceConstantValues.slice(0, input.m_constantValueSize);
|
|
@@ -574,11 +577,10 @@ function applyStageData(input, data, stageType, context) {
|
|
|
574
577
|
/**
|
|
575
578
|
* Grows the constant block to cover a sampler heap-index constant.
|
|
576
579
|
*
|
|
577
|
-
*
|
|
578
|
-
*
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
* than reading out of bounds.
|
|
580
|
+
* Applied to every constant once samplers are known, as Carbon's reader does:
|
|
581
|
+
* a `UINT`/dimension-1 constant whose name matches a sampler is a heap index,
|
|
582
|
+
* and the declared constant-value size can be smaller than the offset it sits
|
|
583
|
+
* at. The block is extended rather than read out of bounds.
|
|
582
584
|
*
|
|
583
585
|
* **This is derived, not stored, and missing it is not cosmetic.** `packMaterial`
|
|
584
586
|
* allocates `new ArrayBuffer(constantValueSize)`, so an unpatched size
|
|
@@ -673,12 +675,77 @@ function buildPass(record, context) {
|
|
|
673
675
|
return pass;
|
|
674
676
|
}
|
|
675
677
|
|
|
678
|
+
/** Names an export slot per Carbon's raytracing export type codes. */
|
|
679
|
+
const LIBRARY_EXPORT_NAME_FIELDS = Object.freeze(["rayGenName", "missName", "closestHitName", "anyHitName", "intersectionName"]);
|
|
680
|
+
|
|
681
|
+
/** Library record rules; the nested pieces are handled by `buildLibrary`. */
|
|
682
|
+
const LIBRARY_RULES = Object.freeze({
|
|
683
|
+
payloadSize: (target, value) => {
|
|
684
|
+
target.payloadSize = value;
|
|
685
|
+
},
|
|
686
|
+
hitGroupName: (target, value) => {
|
|
687
|
+
target.hitGroupName = text(value);
|
|
688
|
+
},
|
|
689
|
+
// Consumed by buildLibrary: the blob becomes the registered bytecode.
|
|
690
|
+
shaderData: consumed,
|
|
691
|
+
// Consumed by buildLibrary: exports carry per-type name routing.
|
|
692
|
+
exports: consumed,
|
|
693
|
+
globalInputs: consumed,
|
|
694
|
+
localInputs: consumed
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* Rebuilds one runtime shader library from a wire library record.
|
|
699
|
+
*
|
|
700
|
+
* The two stage-data blocks reuse `applyStageData`, so a library's constants,
|
|
701
|
+
* defaults, resources, samplers and UAVs go through exactly the rules a pass
|
|
702
|
+
* stage goes through. The library bytecode is registered the way the runtime
|
|
703
|
+
* registers it: a compute-typed `HlslShaderBytecode` under the state manager's
|
|
704
|
+
* library registry, whose handles are a separate monotonic counter — adding
|
|
705
|
+
* libraries does not shift any shader or program handle.
|
|
706
|
+
*
|
|
707
|
+
* @param {object} record Wire library record.
|
|
708
|
+
* @param {object} context Adapter context.
|
|
709
|
+
* @returns {HlslEffectLibrary} Runtime library.
|
|
710
|
+
*/
|
|
711
|
+
function buildLibrary(record, context) {
|
|
712
|
+
const library = mapClosed(record, LIBRARY_RULES, new HlslEffectLibrary(), "library");
|
|
713
|
+
const shaderType = HlslRenderContextEnum.COMPUTE_SHADER;
|
|
714
|
+
library.cjsShaderBytecode = new HlslShaderBytecode({
|
|
715
|
+
stageType: shaderType,
|
|
716
|
+
stageName: "library",
|
|
717
|
+
bytes: record.shaderData?.bytes ?? new Uint8Array(0),
|
|
718
|
+
shaderSize: record.shaderData?.size ?? 0,
|
|
719
|
+
stringTableOffset: record.shaderData?.offset ?? null
|
|
720
|
+
});
|
|
721
|
+
library.libraryHandle = context.effectStateManager.RegisterShaderLibrary(library.cjsShaderBytecode);
|
|
722
|
+
for (const entry of record.exports ?? []) {
|
|
723
|
+
const name = text(entry.name);
|
|
724
|
+
library.exports.push({
|
|
725
|
+
type: entry.type,
|
|
726
|
+
name
|
|
727
|
+
});
|
|
728
|
+
const field = LIBRARY_EXPORT_NAME_FIELDS[entry.type];
|
|
729
|
+
if (field) library[field] = name;
|
|
730
|
+
}
|
|
731
|
+
applyStageData(library.globalInput, record.globalInputs ?? {}, shaderType, context);
|
|
732
|
+
library.globalResourceSetDesc = new HlslResourceSetDescription([shaderType], [library.globalInput.signature]);
|
|
733
|
+
for (const [registerIndex, sampler] of library.globalInput.samplers.entries()) {
|
|
734
|
+
library.globalResourceSetDesc.SetSampler(shaderType, registerIndex, sampler.sampler);
|
|
735
|
+
}
|
|
736
|
+
applyStageData(library.localInput, record.localInputs ?? {}, shaderType, context);
|
|
737
|
+
return library;
|
|
738
|
+
}
|
|
739
|
+
|
|
676
740
|
/**
|
|
677
741
|
* Applies the `IsHeapView` annotations to the rebuilt resource-set descriptions.
|
|
678
742
|
*
|
|
679
|
-
* Derived
|
|
680
|
-
*
|
|
681
|
-
*
|
|
743
|
+
* Derived rather than carried, over the annotations the container holds,
|
|
744
|
+
* exactly as Carbon derives it after reading
|
|
745
|
+
* (`Tr2EffectDescription.cpp:474-530`): a parameter whose top-level
|
|
746
|
+
* annotations contain a true BOOL `IsHeapView` marks its register as a heap
|
|
747
|
+
* view in the owning resource-set description, for library global inputs as
|
|
748
|
+
* well as pass stages.
|
|
682
749
|
*
|
|
683
750
|
* @param {object} effectDescription Rebuilt effect description.
|
|
684
751
|
*/
|
|
@@ -689,6 +756,18 @@ function applyHeapViewAnnotations(effectDescription) {
|
|
|
689
756
|
return annotations.some(annotation => annotation.name === "IsHeapView" && annotation.type === HlslEffectParameterAnnotation.Type.BOOL && annotation.boolValue);
|
|
690
757
|
};
|
|
691
758
|
for (const technique of effectDescription.techniques) {
|
|
759
|
+
for (const library of technique.libraries ?? []) {
|
|
760
|
+
const shaderType = HlslRenderContextEnum.COMPUTE_SHADER;
|
|
761
|
+
for (const [registerIndex, resource] of library.globalInput.resources.entries()) {
|
|
762
|
+
if (isHeapView(resource.name)) library.globalResourceSetDesc?.SetSrvHeapView(shaderType, registerIndex);
|
|
763
|
+
}
|
|
764
|
+
for (const [registerIndex, resource] of library.globalInput.uavs.entries()) {
|
|
765
|
+
if (isHeapView(resource.name)) library.globalResourceSetDesc?.SetUavHeapView(shaderType, registerIndex);
|
|
766
|
+
}
|
|
767
|
+
for (const [registerIndex, sampler] of library.globalInput.samplers.entries()) {
|
|
768
|
+
if (isHeapView(sampler.name)) library.globalResourceSetDesc?.SetSamplerHeapView(shaderType, registerIndex);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
692
771
|
for (const pass of technique.passes) {
|
|
693
772
|
for (let stageType = 0; stageType < pass.stageInputs.length; stageType += 1) {
|
|
694
773
|
const stage = pass.stageInputs[stageType];
|
|
@@ -741,37 +820,27 @@ function runtimeDescriptionFromCarbon(description, options = {}) {
|
|
|
741
820
|
for (const record of description.techniques) {
|
|
742
821
|
const technique = new HlslEffectTechnique();
|
|
743
822
|
technique.name = text(record.name);
|
|
744
|
-
// Raytracing libraries are carried on the wire and are deliberately NOT
|
|
745
|
-
// rebuilt here. `libraries` stays empty.
|
|
746
|
-
//
|
|
747
|
-
// This began as a throw, on the reasoning that a silent drop hides a
|
|
748
|
-
// whole missing section and that no shipped effect declared one. The
|
|
749
|
-
// first half still stands; the second half was wrong, and the way it was
|
|
750
|
-
// wrong is the useful part. The dx11 corpus has no libraries at all —
|
|
751
|
-
// 1611 files, zero — so the refusal never fired. **Every dx12 body of
|
|
752
|
-
// `unpacked_quadv5.sm_hi` carries one**: technique `RtShadow`, a
|
|
753
|
-
// `ClosestHit` export, DXR raytracing shadows that dx11 has no analogue
|
|
754
|
-
// for. All 288 distinct bodies. So the refusal blocked every dx12
|
|
755
|
-
// package for a section nothing downstream reads.
|
|
756
|
-
//
|
|
757
|
-
// Dropping them is safe for a *specific, checked* reason rather than a
|
|
758
|
-
// hopeful one: `buildEffectAnalysis` reaches libraries through no path.
|
|
759
|
-
// `buildPasses` walks `technique.passes`; `buildStages` walks
|
|
760
|
-
// `pass.stageInputs`; neither touches `technique.libraries`. The source
|
|
761
|
-
// reader's heap-view pass does visit libraries, but only to populate
|
|
762
|
-
// `library.globalResourceSetDesc`, which the manifest never reads.
|
|
763
|
-
//
|
|
764
|
-
// That claim is measured, not argued: the corpus analysis diff compares
|
|
765
|
-
// source-derived against container-derived analysis over dx12 as well as
|
|
766
|
-
// dx11, so every one of those library-bearing bodies is proof that the
|
|
767
|
-
// drop is invisible to this view. If the analysis ever grows a library
|
|
768
|
-
// section, that test goes red rather than this comment going stale.
|
|
769
823
|
technique.passes = (record.passes ?? []).map(pass => buildPass(pass, context));
|
|
770
824
|
for (const pass of technique.passes) technique.shaderTypeMask |= pass.shaderTypeMask;
|
|
825
|
+
// Raytracing libraries were once deliberately dropped here, when this
|
|
826
|
+
// adapter served only `buildEffectAnalysis` — which reaches libraries
|
|
827
|
+
// through no path, a claim the dx12 corpus diff measured (every body
|
|
828
|
+
// of `unpacked_quadv5.sm_hi` carries an `RtShadow` library, and the
|
|
829
|
+
// diff stayed green). Since the runtime read path converged on this
|
|
830
|
+
// adapter, that scope no longer holds: `metadata.js` and `json.js`
|
|
831
|
+
// emit `technique.libraries`, and the effect-resource contract
|
|
832
|
+
// requires every library's exports, inputs and payload preserved.
|
|
833
|
+
technique.libraries = (record.libraries ?? []).map(library => buildLibrary(library, context));
|
|
771
834
|
effectDescription.techniques.push(technique);
|
|
772
835
|
}
|
|
773
836
|
for (const group of description.annotations ?? []) {
|
|
774
|
-
|
|
837
|
+
const name = text(group.name);
|
|
838
|
+
if (effectDescription.annotations.has(name)) {
|
|
839
|
+
throw new CjsFormatReadError(`Duplicate effect parameter annotation group ${name}`, {
|
|
840
|
+
name
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
effectDescription.annotations.set(name, (group.annotations ?? []).map(mapAnnotationRecord));
|
|
775
844
|
}
|
|
776
845
|
applyHeapViewAnnotations(effectDescription);
|
|
777
846
|
return effectDescription;
|