@carbonenginejs/runtime-resource 0.12.0 → 0.12.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/CjsResMan.js +4 -4
- package/dist/CjsResMan.js.map +1 -1
- package/dist/_virtual/_rollupPluginBabelHelpers.js +1 -4
- package/dist/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
- package/dist/format/CjsByteReader.js +310 -0
- package/dist/format/CjsByteReader.js.map +1 -0
- package/dist/format/CjsByteWriter.js +242 -0
- package/dist/format/CjsByteWriter.js.map +1 -0
- package/dist/format/CjsFormatError.js +41 -0
- package/dist/format/CjsFormatError.js.map +1 -0
- package/dist/format/CjsStringTable.js +268 -0
- package/dist/format/CjsStringTable.js.map +1 -0
- package/dist/format/carbonEffect/CjsCarbonEffectReader.js +361 -0
- package/dist/format/carbonEffect/CjsCarbonEffectReader.js.map +1 -0
- package/dist/format/carbonEffect/CjsCarbonEffectWriter.js +373 -0
- package/dist/format/carbonEffect/CjsCarbonEffectWriter.js.map +1 -0
- package/dist/format/carbonEffect/carbonDescriptionFromPortable.js +372 -0
- package/dist/format/carbonEffect/carbonDescriptionFromPortable.js.map +1 -0
- package/dist/format/carbonEffect/carbonEffectBackendBlock.js +427 -0
- package/dist/format/carbonEffect/carbonEffectBackendBlock.js.map +1 -0
- package/dist/format/carbonEffect/carbonEffectRecords.js +955 -0
- package/dist/format/carbonEffect/carbonEffectRecords.js.map +1 -0
- package/dist/format/compareUtf8.js +36 -0
- package/dist/format/compareUtf8.js.map +1 -0
- package/dist/format/index.js +11 -0
- package/dist/format/index.js.map +1 -0
- package/dist/formats/bnk/CjsBnkFormat.js +10 -4
- package/dist/formats/bnk/CjsBnkFormat.js.map +1 -1
- package/dist/formats/bnk/core/eventAction.js +305 -0
- package/dist/formats/bnk/core/eventAction.js.map +1 -0
- package/dist/formats/bnk/core/helpers.js +11 -2
- package/dist/formats/bnk/core/helpers.js.map +1 -1
- package/dist/formats/bnk/core/nodeBase.js +532 -0
- package/dist/formats/bnk/core/nodeBase.js.map +1 -0
- package/dist/formats/bnk/core/sfxNodes.js +252 -152
- package/dist/formats/bnk/core/sfxNodes.js.map +1 -1
- package/dist/formats/hlsl/core/HlslReader.js +7 -257
- package/dist/formats/hlsl/core/HlslReader.js.map +1 -1
- package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js +781 -0
- package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js.map +1 -0
- package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js +21 -1
- package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js.map +1 -1
- package/dist/formats/index.js +1 -1
- package/dist/formats/webgl/core/cewg/CewgPackage.js +2 -1
- package/dist/formats/webgl/core/cewg/CewgPackage.js.map +1 -1
- package/dist/formats/webgl/core/cewg/binary.js +11 -93
- package/dist/formats/webgl/core/cewg/binary.js.map +1 -1
- package/dist/formats/webgl/core/effectPackage.js +1 -1
- package/dist/formats/webgpu/CjsWebgpuFormat.js +4 -23
- package/dist/formats/webgpu/CjsWebgpuFormat.js.map +1 -1
- package/dist/formats/webgpu/core/buildCarbonEffectContainer.js +197 -0
- package/dist/formats/webgpu/core/buildCarbonEffectContainer.js.map +1 -0
- package/dist/formats/webgpu/core/cewgpu/CewgpuContainer.js +368 -0
- package/dist/formats/webgpu/core/cewgpu/CewgpuContainer.js.map +1 -0
- package/dist/formats/webgpu/core/cewgpu/containerViews.js +355 -0
- package/dist/formats/webgpu/core/cewgpu/containerViews.js.map +1 -0
- package/dist/formats/webgpu/core/cewgpu/validateContainer.js +90 -0
- package/dist/formats/webgpu/core/cewgpu/validateContainer.js.map +1 -0
- package/dist/formats/webgpu/core/effectBackendBodySet.js +21 -20
- package/dist/formats/webgpu/core/effectBackendBodySet.js.map +1 -1
- package/dist/formats/webgpu/core/helpers.js +87 -92
- package/dist/formats/webgpu/core/helpers.js.map +1 -1
- package/dist/formats/webgpu/core/ir/analyzeRegisterValues.js +14 -13
- package/dist/formats/webgpu/core/ir/analyzeRegisterValues.js.map +1 -1
- package/dist/formats/webgpu/core/ir/inferValueTypes.js +10 -8
- package/dist/formats/webgpu/core/ir/inferValueTypes.js.map +1 -1
- package/dist/formats/webgpu/core/packageEffect.js +94 -9
- package/dist/formats/webgpu/core/packageEffect.js.map +1 -1
- package/dist/formats/webgpu/core/packageMetadata.js +10 -1
- package/dist/formats/webgpu/core/packageMetadata.js.map +1 -1
- package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js +17 -15
- package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js.map +1 -1
- package/dist/formats/webgpu/core/wgsl/buildWgslBindingPlan.js +13 -12
- package/dist/formats/webgpu/core/wgsl/buildWgslBindingPlan.js.map +1 -1
- package/dist/formats/webgpu/core/wgsl/buildWgslSet.js +9 -8
- package/dist/formats/webgpu/core/wgsl/buildWgslSet.js.map +1 -1
- package/dist/formats/webgpu/core/wgsl/lowerComputeProgram.js +23 -22
- package/dist/formats/webgpu/core/wgsl/lowerComputeProgram.js.map +1 -1
- package/dist/formats/webgpu/core/wgsl/selectionPlans.js +46 -44
- package/dist/formats/webgpu/core/wgsl/selectionPlans.js.map +1 -1
- package/dist/resource/CjsResource.js +700 -684
- package/dist/resource/CjsResource.js.map +1 -1
- package/dist/resource/Tr2LightProfileRes.js +18 -27
- package/dist/resource/Tr2LightProfileRes.js.map +1 -1
- package/dist/resource/audio/CjsAudioBufferRes.js +2 -2
- package/dist/resource/audio/CjsAudioBufferRes.js.map +1 -1
- package/dist/resource/audio/CjsAudioRes.js +2 -2
- package/dist/resource/audio/CjsAudioRes.js.map +1 -1
- package/dist/resource/geometry/TriGeometryRes.js +605 -586
- package/dist/resource/geometry/TriGeometryRes.js.map +1 -1
- package/dist/resource/geometry/granny/Tr2GrannyStateRes.js +21 -30
- package/dist/resource/geometry/granny/Tr2GrannyStateRes.js.map +1 -1
- package/dist/resource/geometry/granny/TriGrannyRes.js +21 -30
- package/dist/resource/geometry/granny/TriGrannyRes.js.map +1 -1
- package/dist/resource/shader/Tr2EffectRes.js +9 -7
- package/dist/resource/shader/Tr2EffectRes.js.map +1 -1
- package/dist/resource/shader/Tr2MaterialArea.js +5 -3
- package/dist/resource/shader/Tr2MaterialArea.js.map +1 -1
- package/dist/resource/shader/Tr2MaterialMesh.js +4 -2
- package/dist/resource/shader/Tr2MaterialMesh.js.map +1 -1
- package/dist/resource/shader/Tr2MaterialRes.js +5 -3
- package/dist/resource/shader/Tr2MaterialRes.js.map +1 -1
- package/dist/resource/shader/Tr2Shader.js +26 -21
- package/dist/resource/shader/Tr2Shader.js.map +1 -1
- package/dist/resource/shader/Tr2ShaderPermutation.js +8 -6
- package/dist/resource/shader/Tr2ShaderPermutation.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectDefine.js +5 -3
- package/dist/resource/shader/reflection/Tr2EffectDefine.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectDescription.js +5 -3
- package/dist/resource/shader/reflection/Tr2EffectDescription.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectLibrary.js +17 -15
- package/dist/resource/shader/reflection/Tr2EffectLibrary.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js +11 -9
- package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectResource.js +8 -6
- package/dist/resource/shader/reflection/Tr2EffectResource.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectStageInput.js +15 -13
- package/dist/resource/shader/reflection/Tr2EffectStageInput.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectTechnique.js +7 -5
- package/dist/resource/shader/reflection/Tr2EffectTechnique.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2Pass.js +11 -9
- package/dist/resource/shader/reflection/Tr2Pass.js.map +1 -1
- package/dist/resource/shader/sampler/Tr2SamplerSetup.js +8 -6
- package/dist/resource/shader/sampler/Tr2SamplerSetup.js.map +1 -1
- package/dist/resource/texture/CjsTextureArrayRes.js +400 -411
- package/dist/resource/texture/CjsTextureArrayRes.js.map +1 -1
- package/dist/resource/texture/Tr2ImageRes.js +99 -95
- package/dist/resource/texture/Tr2ImageRes.js.map +1 -1
- package/dist/resource/texture/TriTextureRes.js +312 -273
- package/dist/resource/texture/TriTextureRes.js.map +1 -1
- package/docs/README.md +13 -1
- package/docs/architecture.md +3 -3
- package/docs/concepts/resource-lifecycle.md +9 -2
- package/docs/concepts/shader-resource-model.md +114 -0
- package/docs/concepts/writing-an-engine-adapter.md +115 -0
- package/docs/formats/README.md +24 -1
- package/docs/formats/carbon-effect-container.md +452 -0
- package/docs/formats/dxbc/reference/classes/README.md +5 -72
- package/docs/formats/hlsl/reference/api.md +5 -4
- package/docs/formats/hlsl/reference/classes/README.md +6 -11
- package/docs/formats/provenance.md +23 -13
- package/docs/formats/webgl/reference/classes/README.md +5 -92
- package/docs/formats/webgpu/README.md +19 -16
- package/docs/formats/webgpu/architecture.md +15 -12
- package/docs/formats/webgpu/formats/cewgpu.md +175 -438
- package/docs/formats/webgpu/guides/effect-packaging.md +132 -140
- package/docs/formats/webgpu/reference/api.md +131 -131
- package/docs/formats/webgpu/reference/classes/README.md +5 -62
- package/docs/formats/webgpu/reference/wgsl-compatibility.md +146 -45
- package/docs/formats/wwise.md +34 -8
- package/docs/reference/classes/core.md +80 -0
- package/docs/reference/classes/formats.md +18 -28
- package/docs/reference/events.md +25 -0
- package/docs/reference/motherlode-cache.md +22 -8
- package/docs/reference/workers.md +5 -5
- package/docs/roadmap.md +61 -41
- package/package.json +2 -1
- package/dist/formats/webgpu/core/cewgpu/CewgpuPackage.js +0 -415
- package/dist/formats/webgpu/core/cewgpu/CewgpuPackage.js.map +0 -1
- package/dist/formats/webgpu/core/cewgpu/CewgpuPackageBuilder.js +0 -100
- package/dist/formats/webgpu/core/cewgpu/CewgpuPackageBuilder.js.map +0 -1
- package/dist/formats/webgpu/core/cewgpu/binary.js +0 -93
- package/dist/formats/webgpu/core/cewgpu/binary.js.map +0 -1
- package/dist/formats/webgpu/core/cewgpu/tags.js +0 -17
- package/dist/formats/webgpu/core/cewgpu/tags.js.map +0 -1
- package/dist/formats/webgpu/core/effectPackageValidation.js +0 -1078
- package/dist/formats/webgpu/core/effectPackageValidation.js.map +0 -1
- package/docs/formats/hlsl/reference/classes/carbon-compatibility.md +0 -66
- package/docs/formats/hlsl/reference/classes/public-api.md +0 -26
- package/docs/formats/hlsl/reference/classes/tr2-effect-model.md +0 -150
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"carbonDescriptionToRuntime.js","sources":["../../../../../src/formats/hlsl/core/carbonDescriptionToRuntime.js"],"sourcesContent":["import { CjsFormatReadError } from \"../../../format/CjsFormatError.js\";\nimport { HlslEffectConstant } from \"./tr2/shader/HlslEffectConstant.js\";\nimport { HlslEffectParameterAnnotation } from \"./tr2/shader/HlslEffectParameterAnnotation.js\";\nimport { HlslEffectResource } from \"./tr2/shader/HlslEffectResource.js\";\nimport { HlslEffectStageInput } from \"./tr2/shader/HlslEffectStageInput.js\";\nimport { HlslEffectStateManager } from \"./HlslEffectStateManager.js\";\nimport { HlslEffectTechnique } from \"./tr2/shader/HlslEffectTechnique.js\";\nimport { HlslPass } from \"./tr2/shader/HlslPass.js\";\nimport { HlslRenderContextEnum, HlslUsageCodeNames } from \"./tr2/HlslRenderContextEnum.js\";\nimport { HlslRenderStateSetup } from \"./HlslRenderStateSetup.js\";\nimport { HlslResourceSetDescription } from \"./HlslResourceSetDescription.js\";\nimport { HlslSamplerDescription } from \"./tr2/shader/HlslSamplerDescription.js\";\nimport { HlslSamplerSetup } from \"./tr2/shader/HlslSamplerSetup.js\";\n\n/**\n * Rebuilds the runtime effect-description shape from a Carbon record tree.\n *\n * This is a **shape adapter and nothing else**. It adds no semantics: its whole\n * job is to turn the parsed container records into the object graph\n * `HlslEffectBindingManifest.fromEffectDescription` already consumes, so that\n * `buildEffectAnalysis` runs unchanged on a container-derived description. The\n * derived view stays the same function it has always been rather than a\n * reimplementation free to drift from it.\n *\n * ## Why this is not a field copy\n *\n * The wire shape and the runtime shape are genuinely different shapes, and every\n * difference is a place a copying adapter produces something that reads as\n * plausible and is wrong:\n *\n * | wire | runtime | conversion |\n * |---|---|---|\n * | `name: {offset, value}` | `name: \"NormalMap\"` | unwrap the arena string reference |\n * | `count` | `arrayElements` | **renamed** — see `mapTextureRecord` |\n * | `isSRGB: 0` | `isSRGB: false` | integer to boolean |\n * | flat sampler fields | `{name, sampler: {...}}` | **re-nested** — see `mapSamplerRecord` |\n * | UAV has no `isSRGB` | `isSRGB: false` | **synthesised** — see `mapUavRecord` |\n * | `registerIndex` field | map key | consumed as the key, not a payload field |\n *\n * Three of those are silent when wrong. `arrayElements` is read at\n * `packageHelpers.js:869` and a rename yields `undefined` there. `isSRGB` as `0`\n * is *accidentally correct* — `0` is falsy, `1` is truthy — so it survives every\n * behavioural test and only a structural diff sees it. A flat sampler puts all\n * fourteen descriptor fields at the wrong depth at once.\n *\n * ## The tables are closed\n *\n * Every record is built through `mapClosed`, which walks the **source** keys and\n * throws on any key with no rule. Nothing is spread and nothing is copied\n * wholesale. That converts \"did we enumerate every field?\" — a question whose\n * wrong answer shows up months later as `undefined` in the engine — into an error\n * the first time the adapter meets a record it does not fully understand.\n *\n * This is deliberately redundant with the two-sided diff in\n * `test/formats/webgpu/carbon-analysis-adapter.test.mjs`, and neither replaces the\n * other. The table catches *the wire has something we do not handle*; the diff\n * catches *our output differs from the reference*. A complete table can still map\n * a field wrongly, and a passing diff on one fixture says nothing about a key that\n * fixture never exercises.\n *\n * ## What is derived rather than stored\n *\n * `m_shader`, `pass.shaderProgram` and `pass.renderStates` are registration\n * handles from `HlslEffectStateManager`, which are monotonic counters and\n * therefore reproduce exactly when registration happens in the same order. That\n * is why stages are walked in **wire array order** rather than by ascending\n * stage type: the source reader registers them in the order the file lists them.\n * `resourceSetDesc` and its `heapViews` are likewise rebuilt by running the same\n * derivation the source reader runs, not carried on the wire.\n */\n\n/** Carbon annotation type for a string-valued annotation. */\nconst ANNOTATION_TYPE_STRING = HlslEffectParameterAnnotation.Type.STRING;\n\nconst rawView = new DataView(new ArrayBuffer(4));\n\n/**\n * Unwraps an arena string reference to its text.\n *\n * @param {{offset:number, value:string}|null} reference Wire string reference.\n * @returns {string} The referenced text.\n */\nfunction text(reference)\n{\n return typeof reference?.value === \"string\" ? reference.value : \"\";\n}\n\n/**\n * Converts a wire `u8` flag to the boolean the runtime shape carries.\n *\n * @param {number} value Wire flag.\n * @returns {boolean} Boolean form.\n */\nfunction flag(value)\n{\n return Boolean(value);\n}\n\n/**\n * Reads four wire bytes as the little-endian `u32` the runtime annotation holds.\n *\n * @param {Uint8Array|null} bytes Four raw bytes.\n * @returns {number} Unsigned 32-bit value.\n */\nfunction rawUint32(bytes)\n{\n if (!bytes || bytes.length < 4) return 0;\n rawView.setUint8(0, bytes[0]);\n rawView.setUint8(1, bytes[1]);\n rawView.setUint8(2, bytes[2]);\n rawView.setUint8(3, bytes[3]);\n return rawView.getUint32(0, true);\n}\n\n/**\n * Reinterprets a `u32` bit pattern as the float it encodes.\n *\n * @param {number} bits Raw 32-bit pattern.\n * @returns {number} The float those bits encode.\n */\nfunction floatFromBits(bits)\n{\n rawView.setUint32(0, bits >>> 0, true);\n return rawView.getFloat32(0, true);\n}\n\n/**\n * Builds an object from a record by walking the record's own keys against a\n * closed rule table, throwing on any key the table does not name.\n *\n * Walking the **source** keys is the point. A table walked from its own entries\n * would silently ignore a field the wire gained, which is exactly the failure\n * this exists to make loud.\n *\n * @param {object} record Source wire record.\n * @param {object} rules Rule table keyed by source field name.\n * @param {object} target Object to populate.\n * @param {string} what Record kind, for the error message.\n * @returns {object} The populated target.\n */\nfunction mapClosed(record, rules, target, what)\n{\n for (const key of Object.keys(record))\n {\n const rule = rules[key];\n if (!rule)\n {\n throw new CjsFormatReadError(\n `Carbon ${what} record carries field \"${key}\" with no mapping rule`,\n { record: what, field: key }\n );\n }\n rule(target, record[key], record);\n }\n return target;\n}\n\n/** Consumes a field that is deliberately not part of the runtime payload. */\nconst consumed = () => {};\n\n/** Texture record rules. `count` is Carbon's name for `arrayElements`. */\nconst TEXTURE_RULES = Object.freeze({\n // Carried as the map key by the caller, not as a payload field.\n registerIndex: consumed,\n name: (target, value) => { target.name = text(value); },\n type: (target, value) => { target.type = value; },\n // RENAME: the wire calls this `count`; the runtime calls it `arrayElements`.\n // Copying the field name yields `arrayElements: undefined`, read silently at\n // `packageHelpers.js:869`.\n count: (target, value) => { target.arrayElements = value; },\n isSRGB: (target, value) => { target.isSRGB = flag(value); },\n isAutoregister: (target, value) => { target.isAutoregister = flag(value); }\n});\n\n/** UAV record rules. A UAV record has no `isSRGB`; it is synthesised. */\nconst UAV_RULES = Object.freeze({\n registerIndex: consumed,\n name: (target, value) => { target.name = text(value); },\n type: (target, value) => { target.type = value; },\n // RENAME: same as the texture record.\n count: (target, value) => { target.arrayElements = value; },\n isAutoregister: (target, value) => { target.isAutoregister = flag(value); }\n});\n\n/** Sampler record rules. The wire record is flat; the runtime shape is nested. */\nconst SAMPLER_RULES = Object.freeze({\n registerIndex: consumed,\n // Handled after the walk: the name depends on `isDynamic`, which the walk\n // may not have reached yet.\n name: consumed,\n isDynamic: (target, value) => { target.sampler.isDynamic = flag(value); },\n comparison: (target, value) => { target.sampler.comparison = flag(value); },\n minFilter: (target, value) => { target.sampler.minFilter = value; },\n magFilter: (target, value) => { target.sampler.magFilter = value; },\n mipFilter: (target, value) => { target.sampler.mipFilter = value; },\n addressU: (target, value) => { target.sampler.addressU = value; },\n addressV: (target, value) => { target.sampler.addressV = value; },\n addressW: (target, value) => { target.sampler.addressW = value; },\n mipLODBias: (target, value) => { target.sampler.mipLODBias = value; },\n maxAnisotropy: (target, value) => { target.sampler.maxAnisotropy = value; },\n comparisonFunc: (target, value) => { target.sampler.comparisonFunc = value; },\n borderColor: (target, value) => { target.sampler.borderColor = value.slice(0, 4); },\n minLOD: (target, value) => { target.sampler.minLOD = value; },\n maxLOD: (target, value) => { target.sampler.maxLOD = value; }\n});\n\n/** Static sampler rules. `borderColor` is a one-byte enum here, not four floats. */\nconst STATIC_SAMPLER_RULES = Object.freeze({\n registerIndex: (target, value) => { target.registerIndex = value; },\n registerSpace: (target, value) => { target.registerSpace = value; },\n comparison: (target, value) => { target.sampler.comparison = flag(value); },\n minFilter: (target, value) => { target.sampler.minFilter = value; },\n magFilter: (target, value) => { target.sampler.magFilter = value; },\n mipFilter: (target, value) => { target.sampler.mipFilter = value; },\n addressU: (target, value) => { target.sampler.addressU = value; },\n addressV: (target, value) => { target.sampler.addressV = value; },\n addressW: (target, value) => { target.sampler.addressW = value; },\n mipLODBias: (target, value) => { target.sampler.mipLODBias = value; },\n maxAnisotropy: (target, value) => { target.sampler.maxAnisotropy = value; },\n comparisonFunc: (target, value) => { target.sampler.comparisonFunc = value; },\n borderColor: (target, value) => { target.sampler.borderColor = value; },\n minLOD: (target, value) => { target.sampler.minLOD = value; },\n maxLOD: (target, value) => { target.sampler.maxLOD = value; }\n});\n\n/** Constant record rules. */\nconst CONSTANT_RULES = Object.freeze({\n name: (target, value) => { target.name = text(value); },\n offset: (target, value) => { target.offset = value; },\n size: (target, value) => { target.size = value; },\n type: (target, value) => { target.type = value; },\n dimension: (target, value) => { target.dimension = value; },\n elements: (target, value) => { target.elements = value; },\n isSRGB: (target, value) => { target.isSRGB = flag(value); },\n isAutoregister: (target, value) => { target.isAutoregister = flag(value); }\n});\n\n/** Register declaration rules. */\nconst REGISTER_RULES = Object.freeze({\n registerType: (target, value) => { target.registerType = value; },\n registerIndex: (target, value) => { target.registerIndex = value; },\n // Carbon stores one field its reader calls `arrayCount` and its writer calls\n // `registerCount`. The runtime shape carries both names, always equal — the\n // producer refuses to write them when they disagree.\n registerCount: (target, value) => { target.registerCount = value; target.arrayCount = value; },\n registerSpace: (target, value) => { target.registerSpace = value; }\n});\n\n/**\n * Pipeline input rules.\n *\n * `usageName` is derived from the `usage` byte rather than carried: it is a\n * display name looked up from a table (`HlslEffectDescription.js:592`), exactly\n * as Carbon derives it through `GetStringForUsageCode` (`EffectData.h:86`).\n * Nothing goes on the wire for it.\n */\nconst PIPELINE_INPUT_RULES = Object.freeze({\n usage: (target, value) =>\n {\n target.usage = value;\n target.usageName = HlslUsageCodeNames[value] || `USAGE_${value}`;\n },\n registerIndex: (target, value) => { target.registerIndex = value; },\n usageIndex: (target, value) => { target.usageIndex = value; },\n usedMask: (target, value) => { target.usedMask = value; },\n type: (target, value) => { target.type = value; },\n dimension: (target, value) => { target.dimension = value; }\n});\n\n/** Annotation rules. */\nconst ANNOTATION_RULES = Object.freeze({\n name: (target, value) => { target.name = text(value); },\n type: (target, value) => { target.type = value; },\n stringValue: (target, value) => { if (value) target.stringValue = text(value); },\n // A non-string annotation value is four raw bytes: Carbon writes it through a\n // float union and reads it through a different one, so the bytes are the only\n // faithful form. The three typed views are derived from them exactly as the\n // source reader derives them (`HlslEffectDescription.js:480-483`).\n rawValue: (target, value, record) =>\n {\n if (record.type === ANNOTATION_TYPE_STRING) return;\n const bits = rawUint32(value);\n target.rawValue = bits;\n target.boolValue = bits !== 0;\n target.intValue = bits | 0;\n target.floatValue = floatFromBits(bits);\n }\n});\n\n/**\n * Maps one texture record onto its runtime resource object.\n *\n * @param {object} record Wire texture record.\n * @returns {HlslEffectResource} Runtime resource.\n */\nfunction mapTextureRecord(record)\n{\n return mapClosed(record, TEXTURE_RULES, new HlslEffectResource(), \"texture\");\n}\n\n/**\n * Maps one UAV record onto its runtime resource object.\n *\n * A UAV record is one byte shorter than a texture record: it carries no\n * `isSRGB`. Carbon's reader hardcodes it false (`Tr2EffectDescription.cpp:450`),\n * and so does ours (`HlslEffectDescription.js:434`), so the runtime object's\n * constructor default is restored explicitly rather than left to chance —\n * `metadata.toJSON()` emits the key for a UAV even though the wire never carries\n * it, because both kinds share `HlslEffectResource`.\n *\n * @param {object} record Wire UAV record.\n * @returns {HlslEffectResource} Runtime resource.\n */\nfunction mapUavRecord(record)\n{\n const resource = mapClosed(record, UAV_RULES, new HlslEffectResource(), \"uav\");\n resource.isSRGB = false;\n return resource;\n}\n\n/**\n * Maps one sampler record onto its runtime sampler setup.\n *\n * Two conversions beyond the flat-to-nested reshape:\n *\n * - Carbon nulls a sampler's name when it is not dynamic\n * (`Tr2EffectDescription.cpp:430-433`, mirrored at\n * `HlslEffectDescription.js:414-417`), so the wire's empty string must become\n * `null` again. Like `isSRGB`, this is *accidentally correct* if left alone —\n * `\"\"` and `null` are both falsy, so `metadataName` and the heap-view lookup\n * behave identically — and only a structural diff catches it.\n * - `comparison` and `isDynamic` are `u8` on the wire and boolean at runtime.\n *\n * @param {object} record Wire sampler record.\n * @returns {HlslSamplerSetup} Runtime sampler setup.\n */\nfunction mapSamplerRecord(record)\n{\n const setup = new HlslSamplerSetup();\n setup.sampler = new HlslSamplerDescription();\n mapClosed(record, SAMPLER_RULES, setup, \"sampler\");\n setup.name = setup.sampler.isDynamic ? text(record.name) : null;\n return setup;\n}\n\n/**\n * Maps one static sampler record onto its runtime signature entry.\n *\n * The runtime shape keeps the `*Raw` companions non-enumerable, matching\n * `readStaticSampler`, so a `cloneJson` of the descriptor sees the value form\n * only.\n *\n * @param {object} record Wire static sampler record.\n * @returns {object} Runtime static sampler entry.\n */\nfunction mapStaticSamplerRecord(record)\n{\n const entry = { registerIndex: 0, registerSpace: 0, sampler: {\n comparison: false,\n minFilter: 0,\n magFilter: 0,\n mipFilter: 0,\n addressU: 0,\n addressV: 0,\n addressW: 0,\n mipLODBias: 0,\n maxAnisotropy: 0,\n comparisonFunc: 0,\n borderColor: 0,\n minLOD: 0,\n maxLOD: 0\n } };\n mapClosed(record, STATIC_SAMPLER_RULES, entry, \"static sampler\");\n Object.defineProperties(entry.sampler, {\n mipLODBiasRaw: { value: 0, writable: true },\n minLODRaw: { value: 0, writable: true },\n maxLODRaw: { value: 0, writable: true }\n });\n return entry;\n}\n\n/**\n * Maps one constant record onto its runtime constant object.\n *\n * @param {object} record Wire constant record.\n * @returns {HlslEffectConstant} Runtime constant.\n */\nfunction mapConstantRecord(record)\n{\n return mapClosed(record, CONSTANT_RULES, new HlslEffectConstant(), \"constant\");\n}\n\n/**\n * Maps one annotation record onto its runtime annotation object.\n *\n * @param {object} record Wire annotation record.\n * @returns {HlslEffectParameterAnnotation} Runtime annotation.\n */\nfunction mapAnnotationRecord(record)\n{\n return mapClosed(record, ANNOTATION_RULES, new HlslEffectParameterAnnotation(), \"annotation\");\n}\n\n/**\n * Restores the `dynamic` flag the source reader derives per register.\n *\n * Reproduced rather than stored: it is a function of the register type, the\n * stage type and the caller's per-frame start registers, none of which the\n * container needs to carry (`HlslEffectDescription.js:750-765`).\n *\n * @param {object} register Runtime register declaration.\n * @param {number} stageType Stage enum value.\n * @param {object} context Adapter context carrying the per-frame registers.\n * @returns {boolean} True when the register is dynamic.\n */\nfunction isRegisterDynamic(register, stageType, context)\n{\n if (register.registerType !== 0) return true;\n if (stageType === HlslRenderContextEnum.VERTEX_SHADER\n && register.registerIndex === context.perFrameVSStartRegister) return false;\n if (stageType === HlslRenderContextEnum.PIXEL_SHADER\n && register.registerIndex === context.perFramePSStartRegister) return false;\n return true;\n}\n\n/**\n * Populates one runtime stage input from a wire `StageData` block.\n *\n * @param {HlslEffectStageInput} input Destination stage input.\n * @param {object} data Wire stage data.\n * @param {number} stageType Stage enum value.\n * @param {object} context Adapter context.\n */\nfunction applyStageData(input, data, stageType, context)\n{\n input.signature.registers = (data.registers ?? []).map((record) =>\n {\n const register = mapClosed(record, REGISTER_RULES, {}, \"register\");\n register.dynamic = isRegisterDynamic(register, stageType, context);\n return register;\n });\n input.signature.samplers = (data.staticSamplers ?? []).map(mapStaticSamplerRecord);\n\n input.constants = (data.constants ?? []).map(mapConstantRecord);\n\n // The declared size is the unclamped one; the runtime clamps it to\n // SHADER_CONSTANTS_MAX and slices the payload to match\n // (`HlslEffectDescription.js:381-385`). `packMaterial` allocates an\n // ArrayBuffer of exactly this size, so restoring the unclamped value would\n // write past the layout the shader expects — on any effect above 4096 bytes\n // of constants, which is precisely the size a small fixture never reaches.\n const declaredSize = data.defaultValues?.size ?? 0;\n input.sourceConstantValues = Uint8Array.from(data.defaultValues?.bytes ?? new Uint8Array(0));\n input.m_constantValueSize = Math.min(declaredSize, HlslEffectStageInput.SHADER_CONSTANTS_MAX);\n input.constantValues = input.sourceConstantValues.slice(0, input.m_constantValueSize);\n\n input.resources = new Map((data.textures ?? [])\n .map((record) => [ record.registerIndex, mapTextureRecord(record) ]));\n input.samplers = new Map((data.samplers ?? [])\n .map((record) => [ record.registerIndex, mapSamplerRecord(record) ]));\n input.uavs = new Map((data.uavs ?? [])\n .map((record) => [ record.registerIndex, mapUavRecord(record) ]));\n\n input.annotation = (data.annotations ?? []).map(mapAnnotationRecord);\n\n // Runs last, because it needs the sampler map. See the function's own note\n // for why it exists.\n for (const constant of input.constants) patchSamplerHeapIndexConstant(input, constant);\n}\n\n/**\n * Grows the constant block to cover a sampler heap-index constant.\n *\n * Reproduces `HlslEffectDescription.js:773-791`, which the source reader applies\n * to every constant once samplers are known: a `UINT`/dimension-1 constant whose\n * name matches a sampler is a heap index, and the declared constant-value size\n * can be smaller than the offset it sits at. The reader extends the block rather\n * than reading out of bounds.\n *\n * **This is derived, not stored, and missing it is not cosmetic.** `packMaterial`\n * allocates `new ArrayBuffer(constantValueSize)`, so an unpatched size\n * under-allocates and the write runs past the end of the buffer the shader\n * expects. It appears only on dx12 -- the whole dx11 corpus is unaffected --\n * which is exactly why the analysis diff had to cover dx12 before this was\n * trustworthy. On `quaddetailv5.sm_depth` the declared 608 becomes 620.\n *\n * @param {object} input Runtime stage input, with samplers already populated.\n * @param {object} constant Runtime constant record.\n */\nfunction patchSamplerHeapIndexConstant(input, constant)\n{\n if (constant.type !== HlslEffectConstant.Type.UINT || constant.dimension !== 1) return;\n\n for (const sampler of input.samplers.values())\n {\n if (sampler.name !== constant.name) continue;\n const neededSize = constant.offset + constant.size;\n if (neededSize > input.m_constantValueSize)\n {\n const next = new Uint8Array(neededSize);\n next.set(input.constantValues);\n input.constantValues = next;\n input.m_constantValueSize = neededSize;\n }\n break;\n }\n}\n\n/**\n * Rebuilds one runtime pass from a wire pass record.\n *\n * @param {object} record Wire pass record.\n * @param {object} context Adapter context.\n * @returns {HlslPass} Runtime pass.\n */\nfunction buildPass(record, context)\n{\n const pass = new HlslPass();\n const shaderTypes = [];\n const signatures = [];\n const shaderHandles = [];\n\n // Wire array order, not ascending stage type. The source reader registers\n // shaders in the order the file lists its stages, and the state manager's\n // handles are monotonic counters, so any other order reproduces the shape\n // with the handles permuted.\n for (const stage of record.stages ?? [])\n {\n const stageType = stage.type;\n const input = pass.stageInputs[stageType];\n if (!input)\n {\n throw new CjsFormatReadError(\n `Carbon stage record declares stage type ${stageType}, outside the runtime stage range`,\n { stageType }\n );\n }\n if (input.m_exists)\n {\n throw new CjsFormatReadError(\n `Carbon pass declares stage type ${stageType} twice; the later stage would clobber the earlier`,\n { stageType }\n );\n }\n\n input.m_exists = true;\n input.signature.threadGroupSize = {\n x: stage.threadGroupSize[0],\n y: stage.threadGroupSize[1],\n z: stage.threadGroupSize[2]\n };\n input.signature.pipelineInputs = (stage.pipelineInputs ?? [])\n .map((entry) => mapClosed(entry, PIPELINE_INPUT_RULES, {}, \"pipeline input\"));\n\n applyStageData(input, stage, stageType, context);\n\n input.cjsShaderBytecode = context.bytecodeFor\n ? context.bytecodeFor(stage, stageType, pass)\n : null;\n\n input.m_shader = context.effectStateManager.RegisterShader(\n stageType,\n input.cjsShaderBytecode,\n input.signature,\n context.effectName\n );\n shaderHandles.push(input.m_shader);\n shaderTypes.push(stageType);\n signatures.push(input.signature);\n pass.shaderTypeMask |= (1 << stageType);\n }\n\n pass.resourceSetDesc = new HlslResourceSetDescription(shaderTypes, signatures);\n for (let stageType = 0; stageType < HlslRenderContextEnum.SHADER_TYPE_COUNT; stageType += 1)\n {\n const input = pass.stageInputs[stageType];\n if (!input?.m_exists) continue;\n for (const [ registerIndex, sampler ] of input.samplers.entries())\n {\n pass.resourceSetDesc.SetSampler(stageType, registerIndex, sampler.sampler);\n }\n }\n\n pass.shaderProgram = context.effectStateManager.RegisterShaderProgram(\n shaderHandles,\n shaderHandles.length\n );\n\n const states = new Map();\n for (const entry of record.renderStates ?? [])\n {\n if (states.has(entry.state))\n {\n throw new CjsFormatReadError(\n `Carbon pass declares render state ${entry.state} twice`,\n { state: entry.state }\n );\n }\n states.set(entry.state, entry.value);\n }\n pass.cjsRenderStateSetup = new HlslRenderStateSetup(states);\n pass.renderStates = context.effectStateManager.RegisterRenderStateSetup(pass.cjsRenderStateSetup);\n\n return pass;\n}\n\n/**\n * Applies the `IsHeapView` annotations to the rebuilt resource-set descriptions.\n *\n * Derived exactly as the source reader derives it\n * (`HlslEffectDescription.js:799-851`), over the annotations the container\n * carries.\n *\n * @param {object} effectDescription Rebuilt effect description.\n */\nfunction applyHeapViewAnnotations(effectDescription)\n{\n const isHeapView = (name) =>\n {\n if (!name) return false;\n const annotations = effectDescription.annotations.get(name) || [];\n return annotations.some((annotation) =>\n annotation.name === \"IsHeapView\"\n && annotation.type === HlslEffectParameterAnnotation.Type.BOOL\n && annotation.boolValue);\n };\n\n for (const technique of effectDescription.techniques)\n {\n for (const pass of technique.passes)\n {\n for (let stageType = 0; stageType < pass.stageInputs.length; stageType += 1)\n {\n const stage = pass.stageInputs[stageType];\n if (!stage?.m_exists) continue;\n for (const [ registerIndex, resource ] of stage.resources.entries())\n {\n if (isHeapView(resource.name)) pass.resourceSetDesc?.SetSrvHeapView(stageType, registerIndex);\n }\n for (const [ registerIndex, resource ] of stage.uavs.entries())\n {\n if (isHeapView(resource.name)) pass.resourceSetDesc?.SetUavHeapView(stageType, registerIndex);\n }\n for (const [ registerIndex, sampler ] of stage.samplers.entries())\n {\n if (isHeapView(sampler.name)) pass.resourceSetDesc?.SetSamplerHeapView(stageType, registerIndex);\n }\n }\n }\n }\n}\n\n/**\n * Rebuilds the runtime effect-description shape from a Carbon record tree.\n *\n * @param {object} description Parsed Carbon description record tree.\n * @param {object} [options] Adapter options.\n * @param {string} [options.effectName] Effect name or source path.\n * @param {number} [options.version] Carbon effect-data version.\n * @param {number} [options.perFrameVSStartRegister] Per-frame vertex start register.\n * @param {number} [options.perFramePSStartRegister] Per-frame pixel start register.\n * @param {Function} [options.bytecodeFor] Supplies `cjsShaderBytecode` per stage.\n * @param {HlslEffectStateManager} [options.effectStateManager] Registry override.\n * @returns {object} Runtime-shaped effect description.\n */\nexport function runtimeDescriptionFromCarbon(description, options = {})\n{\n if (!description?.techniques)\n {\n throw new CjsFormatReadError(\"Carbon description has no techniques\", {});\n }\n\n const context = {\n effectName: options.effectName ?? \"\",\n effectStateManager: options.effectStateManager ?? new HlslEffectStateManager(),\n bytecodeFor: options.bytecodeFor ?? null,\n perFrameVSStartRegister: Number.isInteger(options.perFrameVSStartRegister)\n ? options.perFrameVSStartRegister\n : null,\n perFramePSStartRegister: Number.isInteger(options.perFramePSStartRegister)\n ? options.perFramePSStartRegister\n : null\n };\n\n const effectDescription = {\n effectName: context.effectName,\n version: options.version ?? 15,\n techniques: [],\n annotations: new Map(),\n effectStateManager: context.effectStateManager\n };\n\n for (const record of description.techniques)\n {\n const technique = new HlslEffectTechnique();\n technique.name = text(record.name);\n // Raytracing libraries are carried on the wire and are deliberately NOT\n // rebuilt here. `libraries` stays empty.\n //\n // This began as a throw, on the reasoning that a silent drop hides a\n // whole missing section and that no shipped effect declared one. The\n // first half still stands; the second half was wrong, and the way it was\n // wrong is the useful part. The dx11 corpus has no libraries at all —\n // 1611 files, zero — so the refusal never fired. **Every dx12 body of\n // `unpacked_quadv5.sm_hi` carries one**: technique `RtShadow`, a\n // `ClosestHit` export, DXR raytracing shadows that dx11 has no analogue\n // for. All 288 distinct bodies. So the refusal blocked every dx12\n // package for a section nothing downstream reads.\n //\n // Dropping them is safe for a *specific, checked* reason rather than a\n // hopeful one: `buildEffectAnalysis` reaches libraries through no path.\n // `buildPasses` walks `technique.passes`; `buildStages` walks\n // `pass.stageInputs`; neither touches `technique.libraries`. The source\n // reader's heap-view pass does visit libraries, but only to populate\n // `library.globalResourceSetDesc`, which the manifest never reads.\n //\n // That claim is measured, not argued: the corpus analysis diff compares\n // source-derived against container-derived analysis over dx12 as well as\n // dx11, so every one of those library-bearing bodies is proof that the\n // drop is invisible to this view. If the analysis ever grows a library\n // section, that test goes red rather than this comment going stale.\n technique.passes = (record.passes ?? []).map((pass) => buildPass(pass, context));\n for (const pass of technique.passes) technique.shaderTypeMask |= pass.shaderTypeMask;\n effectDescription.techniques.push(technique);\n }\n\n for (const group of description.annotations ?? [])\n {\n effectDescription.annotations.set(\n text(group.name),\n (group.annotations ?? []).map(mapAnnotationRecord)\n );\n }\n\n applyHeapViewAnnotations(effectDescription);\n\n return effectDescription;\n}\n\nexport default runtimeDescriptionFromCarbon;\n"],"names":["ANNOTATION_TYPE_STRING","HlslEffectParameterAnnotation","Type","STRING","rawView","DataView","ArrayBuffer","text","reference","value","flag","Boolean","rawUint32","bytes","length","setUint8","getUint32","floatFromBits","bits","setUint32","getFloat32","mapClosed","record","rules","target","what","key","Object","keys","rule","CjsFormatReadError","field","consumed","TEXTURE_RULES","freeze","registerIndex","name","type","count","arrayElements","isSRGB","isAutoregister","UAV_RULES","SAMPLER_RULES","isDynamic","sampler","comparison","minFilter","magFilter","mipFilter","addressU","addressV","addressW","mipLODBias","maxAnisotropy","comparisonFunc","borderColor","slice","minLOD","maxLOD","STATIC_SAMPLER_RULES","registerSpace","CONSTANT_RULES","offset","size","dimension","elements","REGISTER_RULES","registerType","registerCount","arrayCount","PIPELINE_INPUT_RULES","usage","usageName","HlslUsageCodeNames","usageIndex","usedMask","ANNOTATION_RULES","stringValue","rawValue","boolValue","intValue","floatValue","mapTextureRecord","HlslEffectResource","mapUavRecord","resource","mapSamplerRecord","setup","HlslSamplerSetup","HlslSamplerDescription","mapStaticSamplerRecord","entry","defineProperties","mipLODBiasRaw","writable","minLODRaw","maxLODRaw","mapConstantRecord","HlslEffectConstant","mapAnnotationRecord","isRegisterDynamic","register","stageType","context","HlslRenderContextEnum","VERTEX_SHADER","perFrameVSStartRegister","PIXEL_SHADER","perFramePSStartRegister","applyStageData","input","data","signature","registers","map","dynamic","samplers","staticSamplers","constants","declaredSize","defaultValues","sourceConstantValues","Uint8Array","from","m_constantValueSize","Math","min","HlslEffectStageInput","SHADER_CONSTANTS_MAX","constantValues","resources","Map","textures","uavs","annotation","annotations","constant","patchSamplerHeapIndexConstant","UINT","values","neededSize","next","set","buildPass","pass","HlslPass","shaderTypes","signatures","shaderHandles","stage","stages","stageInputs","m_exists","threadGroupSize","x","y","z","pipelineInputs","cjsShaderBytecode","bytecodeFor","m_shader","effectStateManager","RegisterShader","effectName","push","shaderTypeMask","resourceSetDesc","HlslResourceSetDescription","SHADER_TYPE_COUNT","entries","SetSampler","shaderProgram","RegisterShaderProgram","states","renderStates","has","state","cjsRenderStateSetup","HlslRenderStateSetup","RegisterRenderStateSetup","applyHeapViewAnnotations","effectDescription","isHeapView","get","some","BOOL","technique","techniques","passes","SetSrvHeapView","SetUavHeapView","SetSamplerHeapView","runtimeDescriptionFromCarbon","description","options","HlslEffectStateManager","Number","isInteger","version","HlslEffectTechnique","group"],"mappings":";;;;;;;;;;;;;;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,MAAMA,sBAAsB,GAAGC,6BAA6B,CAACC,IAAI,CAACC,MAAM;AAExE,MAAMC,OAAO,GAAG,IAAIC,QAAQ,CAAC,IAAIC,WAAW,CAAC,CAAC,CAAC,CAAC;;AAEhD;AACA;AACA;AACA;AACA;AACA;AACA,SA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,CAAC;AACL,EAAA;EAEAiF,wBAAwB,CAACC,iBAAiB,CAAC;AAE3C,EAAA,OAAOA,iBAAiB;AAC5B;;;;"}
|
|
@@ -27,6 +27,7 @@ class HlslEffectRes {
|
|
|
27
27
|
this.m_permutations = [];
|
|
28
28
|
this.m_shaders = new Map();
|
|
29
29
|
this.m_compilerVersion = null;
|
|
30
|
+
this.m_compilerVersionBytes = null;
|
|
30
31
|
this.m_hash = new Uint8Array(0);
|
|
31
32
|
this.sourcePath = "";
|
|
32
33
|
this.loadError = null;
|
|
@@ -59,7 +60,24 @@ class HlslEffectRes {
|
|
|
59
60
|
throw new Error(`Unsupported HlslEffectRes version ${this.m_version}; expected ${MIN_SUPPORTED_EFFECT_VERSION}..${MAX_SUPPORTED_EFFECT_VERSION}`);
|
|
60
61
|
}
|
|
61
62
|
if (this.m_version >= 15) {
|
|
62
|
-
|
|
63
|
+
// The header slot is four bytes, not a u32:
|
|
64
|
+
// `constexpr uint8_t ShaderCompilerVersion[4]` = {major, minor,
|
|
65
|
+
// patch, tweak} (ShaderCompilerConfig.h.in:5), of which Carbon's
|
|
66
|
+
// rebuild check compares only the first three
|
|
67
|
+
// (ModifiedTime.cpp:77). A shipped v15 header reads `01 02 06 00`
|
|
68
|
+
// — compiler 1.2.6.0, matching the ShaderCompiler project
|
|
69
|
+
// version. As a u32 that is 0x00060201, which means nothing.
|
|
70
|
+
//
|
|
71
|
+
// `m_compilerVersionBytes` is the truthful reading and is what new
|
|
72
|
+
// code should use. `m_compilerVersion` keeps the dword form because
|
|
73
|
+
// it is republished as `source.compilerVersion` in the portable
|
|
74
|
+
// reflection, where it is asserted to be an unsigned integer
|
|
75
|
+
// (portableReflection.js:645) and covered by a package digest —
|
|
76
|
+
// changing its shape changes package bytes, which belongs with the
|
|
77
|
+
// format rewrite rather than here.
|
|
78
|
+
const compilerVersionBytes = stream.readRaw(4);
|
|
79
|
+
this.m_compilerVersionBytes = Array.from(compilerVersionBytes);
|
|
80
|
+
this.m_compilerVersion = new DataView(compilerVersionBytes.buffer, compilerVersionBytes.byteOffset, 4).getUint32(0, true);
|
|
63
81
|
this.m_hash = stream.readRaw(32);
|
|
64
82
|
}
|
|
65
83
|
this.m_stringTableSize = stream.readUint32();
|
|
@@ -235,6 +253,7 @@ class HlslEffectRes {
|
|
|
235
253
|
return {
|
|
236
254
|
version: this.m_version,
|
|
237
255
|
compilerVersion: this.m_compilerVersion,
|
|
256
|
+
compilerVersionBytes: this.m_compilerVersionBytes,
|
|
238
257
|
sourcePath: this.sourcePath,
|
|
239
258
|
stringTableSize: this.m_stringTableSize,
|
|
240
259
|
offsetCount: this.m_offsetCount,
|
|
@@ -264,6 +283,7 @@ class HlslEffectRes {
|
|
|
264
283
|
this.m_permutations = [];
|
|
265
284
|
this.m_shaders = new Map();
|
|
266
285
|
this.m_compilerVersion = null;
|
|
286
|
+
this.m_compilerVersionBytes = null;
|
|
267
287
|
this.m_hash = new Uint8Array(0);
|
|
268
288
|
this.loadError = null;
|
|
269
289
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HlslEffectRes.js","sources":["../../../../../../../src/formats/hlsl/core/tr2/resources/HlslEffectRes.js"],"sourcesContent":["import { HlslReader } from \"../../HlslReader.js\";\nimport { asUint8Array } from \"@carbonenginejs/runtime-utils/bytes\";\nimport { HlslEffectStateManager } from \"../../HlslEffectStateManager.js\";\nimport { HlslShader } from \"../shader/HlslShader.js\";\nimport { HlslShaderOption } from \"../shader/HlslShaderOption.js\";\nimport { HlslShaderPermutation } from \"./HlslShaderPermutation.js\";\n\nconst MIN_SUPPORTED_EFFECT_VERSION = 8;\nconst MAX_SUPPORTED_EFFECT_VERSION = 15;\n\n/**\n * Carbon/Trinity effect resource reader for compiled shader metadata.\n */\nexport class HlslEffectRes\n{\n static globalEffectOptions = [];\n\n /**\n * Creates an empty effect resource ready to load a compiled `.sm_*` payload.\n */\n constructor()\n {\n this.m_data = new Uint8Array(0);\n this.m_version = 0;\n this.m_stringTable = new Uint8Array(0);\n this.m_stringTableSize = 0;\n this.m_offsets = [];\n this.m_offsetCount = 0;\n this.m_permutations = [];\n this.m_shaders = new Map();\n this.m_compilerVersion = null;\n this.m_hash = new Uint8Array(0);\n this.sourcePath = \"\";\n this.loadError = null;\n this.effectStateManager = new HlslEffectStateManager();\n }\n\n /**\n * Reads the effect header, string table, permutation axes, and body offsets.\n *\n * @param {ArrayBuffer|ArrayBufferView|Uint8Array} source Compiled effect bytes.\n * @param {object} [options] Load metadata and dependency overrides.\n * @param {string} [options.sourcePath] Source path used in reports.\n * @param {string} [options.source] Alternate source label.\n * @param {HlslEffectStateManager} [options.effectStateManager] Registry to receive decoded state.\n * @returns {boolean} True when the header was decoded successfully.\n */\n DoLoad(source, options = {})\n {\n this._reset();\n this.sourcePath = options.sourcePath || options.source || \"\";\n this.effectStateManager = options.effectStateManager || new HlslEffectStateManager();\n\n try\n {\n // Carbon owns a memcpy of the loaded resource. Keep the JS graph\n // equally isolated from later caller mutation.\n this.m_data = Uint8Array.from(asUint8Array(source));\n const stream = new HlslReader(this.m_data, { source: this.sourcePath || \"HlslEffectRes\" });\n this.m_version = stream.readUint32();\n\n if (this.m_version < MIN_SUPPORTED_EFFECT_VERSION || this.m_version > MAX_SUPPORTED_EFFECT_VERSION)\n {\n throw new Error(`Unsupported HlslEffectRes version ${this.m_version}; expected ${MIN_SUPPORTED_EFFECT_VERSION}..${MAX_SUPPORTED_EFFECT_VERSION}`);\n }\n\n if (this.m_version >= 15)\n {\n this.m_compilerVersion = stream.readUint32();\n this.m_hash = stream.readRaw(32);\n }\n\n this.m_stringTableSize = stream.readUint32();\n if (this.m_stringTableSize > this.m_data.length || stream.offset + this.m_stringTableSize > this.m_data.length)\n {\n throw new Error(\"Invalid effect string table size\");\n }\n this.m_stringTable = this.m_data.subarray(stream.offset, stream.offset + this.m_stringTableSize);\n stream.skip(this.m_stringTableSize);\n stream.setStringTable(this.m_stringTable, this.m_stringTableSize);\n\n const permutationCount = stream.readUint8();\n for (let index = 0; index < permutationCount; index += 1)\n {\n const permutation = new HlslShaderPermutation();\n permutation.name = stream.readString();\n permutation.defaultOption = stream.readUint8();\n permutation.description = stream.readString();\n permutation.type = this.m_version > 5 ? stream.readUint8() : 0;\n\n const optionCount = stream.readUint8();\n for (let optionIndex = 0; optionIndex < optionCount; optionIndex += 1)\n {\n permutation.options.push(stream.readString());\n }\n this.m_permutations.push(permutation);\n }\n\n const headerSize = stream.readUint32();\n if (headerSize === 0)\n {\n throw new Error(\"Effect contains no compiled shader bodies\");\n }\n\n this.m_offsetCount = headerSize;\n for (let index = 0; index < headerSize; index += 1)\n {\n const record = {\n index: stream.readUint32(),\n offset: stream.readUint32(),\n size: stream.readUint32()\n };\n record.end = record.offset + record.size;\n if (record.end > this.m_data.length)\n {\n throw new Error(`Invalid effect body record ${index}`);\n }\n this.m_offsets.push(record);\n }\n\n return true;\n }\n catch (error)\n {\n this.loadError = error;\n this.m_shaders.clear();\n return false;\n }\n }\n\n /**\n * Mirrors Carbon's prepare hook by clearing cached shader bodies.\n *\n * @returns {boolean} True when preparation completed.\n */\n DoPrepare()\n {\n this.m_shaders.clear();\n return true;\n }\n\n /**\n * Resolves a permutation option set to a decoded `HlslShader`.\n *\n * @param {Array<HlslShaderOption|object>|Map<string, string>} [options] Local option choices.\n * @param {number|null} [count] Number of local option entries to consider.\n * @returns {HlslShader|null} Decoded shader or null when no matching body exists.\n */\n GetShader(options = [], count = null)\n {\n if (!this.IsGood())\n {\n return null;\n }\n\n const normalizedOptions = normalizeShaderOptions(options);\n const optionCount = Number.isInteger(count) ? Math.min(count, normalizedOptions.length) : normalizedOptions.length;\n let multiplier = 1;\n let index = 0;\n\n for (const permutation of this.m_permutations)\n {\n let value = permutation.defaultOption;\n const globalOption = HlslEffectRes.globalEffectOptions.find((entry) => entry.name === permutation.name);\n const localOption = normalizedOptions.slice(0, optionCount).find((entry) => entry.name === permutation.name);\n const selected = globalOption || localOption;\n\n if (selected)\n {\n const selectedIndex = permutation.options.findIndex((option) => option === selected.value);\n if (selectedIndex >= 0)\n {\n value = selectedIndex;\n }\n }\n\n index += value * multiplier;\n multiplier *= permutation.options.length || 1;\n }\n\n return this.GetShaderByIndex(index);\n }\n\n /**\n * Decodes the body at an exact permutation-table index without applying\n * global or local option overrides.\n *\n * @param {number} index Exact zero-based permutation-table index.\n * @returns {HlslShader|null} Decoded shader or null when the index/body is unavailable.\n */\n GetShaderByIndex(index)\n {\n if (!Number.isSafeInteger(index) || index < 0)\n {\n throw new TypeError(\"HlslEffectRes body index must be a non-negative safe integer\");\n }\n if (!this.IsGood())\n {\n return null;\n }\n if (this.m_shaders.has(index))\n {\n return this.m_shaders.get(index);\n }\n\n const offset = this.m_offsets[index];\n if (!offset)\n {\n return null;\n }\n\n const shader = new HlslShader();\n const buffer = this.m_data.subarray(offset.offset, offset.end);\n const ok = shader.GetEffect().Read(\n buffer,\n offset.size,\n this.m_version,\n this.m_stringTable,\n this.m_stringTableSize,\n this.sourcePath,\n { effectStateManager: this.effectStateManager }\n );\n if (!ok)\n {\n return null;\n }\n\n shader.ProcessEffect();\n this.m_shaders.set(index, shader);\n return shader;\n }\n\n /**\n * Reports whether the effect header has been loaded without error.\n *\n * @returns {boolean} True when this resource has usable effect data.\n */\n IsGood()\n {\n return !this.loadError && this.m_data.length > 0 && this.m_version >= MIN_SUPPORTED_EFFECT_VERSION;\n }\n\n /**\n * Reports whether byte memory usage is known for this resource.\n *\n * @returns {boolean} Always true for byte-backed JavaScript resources.\n */\n IsMemoryUsageKnown()\n {\n return true;\n }\n\n /**\n * Returns the byte size of the loaded effect payload.\n *\n * @returns {number} Loaded byte count.\n */\n GetMemoryUsage()\n {\n return this.m_data.length;\n }\n\n /**\n * Clears decoded shader body caches while keeping the loaded header data.\n */\n ReleaseResources()\n {\n this.m_shaders.clear();\n }\n\n /**\n * Returns JSON-safe permutation metadata for tooling and reports.\n *\n * @returns {object[]} Permutation descriptions.\n */\n GetPermutationDescription()\n {\n return this.m_permutations.map((permutation) => permutation.toJSON());\n }\n\n /**\n * Returns a JSON-safe summary of the loaded effect resource.\n *\n * @returns {object} Serializable effect resource summary.\n */\n toJSON()\n {\n return {\n version: this.m_version,\n compilerVersion: this.m_compilerVersion,\n sourcePath: this.sourcePath,\n stringTableSize: this.m_stringTableSize,\n offsetCount: this.m_offsetCount,\n permutations: this.m_permutations.map((entry) => entry.toJSON()),\n offsets: this.m_offsets.map((entry) => ({ ...entry })),\n loadError: this.loadError ? {\n name: this.loadError.name,\n message: this.loadError.message\n } : null\n };\n }\n\n /**\n * Resets loaded state before a new `DoLoad` attempt.\n *\n * @private\n */\n _reset()\n {\n this.m_data = new Uint8Array(0);\n this.m_version = 0;\n this.m_stringTable = new Uint8Array(0);\n this.m_stringTableSize = 0;\n this.m_offsets = [];\n this.m_offsetCount = 0;\n this.m_permutations = [];\n this.m_shaders = new Map();\n this.m_compilerVersion = null;\n this.m_hash = new Uint8Array(0);\n this.loadError = null;\n }\n}\n\n/**\n * Applies global shader option overrides used during permutation lookup.\n *\n * @param {Array<HlslShaderOption|object>|Map<string, string>} [changes] Option changes to merge.\n */\nexport function ModifyGlobalEffectOptions(changes = [])\n{\n for (const change of normalizeShaderOptions(changes))\n {\n const index = HlslEffectRes.globalEffectOptions.findIndex((entry) => entry.name === change.name);\n if (!change.value)\n {\n if (index >= 0) HlslEffectRes.globalEffectOptions.splice(index, 1);\n }\n else if (index >= 0)\n {\n HlslEffectRes.globalEffectOptions[index] = change;\n }\n else\n {\n HlslEffectRes.globalEffectOptions.push(change);\n }\n }\n}\n\n/**\n * Returns the current global shader option overrides.\n *\n * @returns {HlslShaderOption[]} Copy of global shader option overrides.\n */\nexport function GetGlobalEffectOptions()\n{\n return HlslEffectRes.globalEffectOptions.slice();\n}\n\n/**\n * Converts supported option input shapes to `HlslShaderOption` instances.\n *\n * @param {Array<HlslShaderOption|object>|Map<string, string>} options Option input.\n * @returns {HlslShaderOption[]} Normalized option list.\n */\nfunction normalizeShaderOptions(options)\n{\n if (options instanceof Map)\n {\n return Array.from(options.entries()).map(([ name, value ]) => new HlslShaderOption(name, value));\n }\n if (!Array.isArray(options))\n {\n return [];\n }\n return options.map((entry) =>\n {\n if (entry instanceof HlslShaderOption)\n {\n return entry;\n }\n return new HlslShaderOption(entry?.name || \"\", entry?.value || \"\");\n });\n}\n"],"names":["MIN_SUPPORTED_EFFECT_VERSION","MAX_SUPPORTED_EFFECT_VERSION","HlslEffectRes","globalEffectOptions","constructor","m_data","Uint8Array","m_version","m_stringTable","m_stringTableSize","m_offsets","m_offsetCount","m_permutations","m_shaders","Map","m_compilerVersion","m_hash","sourcePath","loadError","effectStateManager","HlslEffectStateManager","DoLoad","source","options","_reset","from","asUint8Array","stream","HlslReader","readUint32","Error","readRaw","length","offset","subarray","skip","setStringTable","permutationCount","readUint8","index","permutation","HlslShaderPermutation","name","readString","defaultOption","description","type","optionCount","optionIndex","push","headerSize","record","size","end","error","clear","DoPrepare","GetShader","count","IsGood","normalizedOptions","normalizeShaderOptions","Number","isInteger","Math","min","multiplier","value","globalOption","find","entry","localOption","slice","selected","selectedIndex","findIndex","option","GetShaderByIndex","isSafeInteger","TypeError","has","get","shader","HlslShader","buffer","ok","GetEffect","Read","ProcessEffect","set","IsMemoryUsageKnown","GetMemoryUsage","ReleaseResources","GetPermutationDescription","map","toJSON","version","compilerVersion","stringTableSize","offsetCount","permutations","offsets","message","Array","entries","HlslShaderOption","isArray"],"mappings":";;;;;;;AAOA,MAAMA,4BAA4B,GAAG,CAAC;AACtC,MAAMC,4BAA4B,GAAG,EAAE;;AAEvC;AACA;AACA;AACO,MAAMC,aAAa,CAC1B;EACI,OAAOC,mBAAmB,GAAG,EAAE;;AAE/B;AACJ;AACA;AACIC,EAAAA,WAAWA,GACX;AACI,IAAA,IAAI,CAACC,MAAM,GAAG,IAAIC,UAAU,CAAC,CAAC,CAAC;IAC/B,IAAI,CAACC,SAAS,GAAG,CAAC;AAClB,IAAA,IAAI,CAACC,aAAa,GAAG,IAAIF,UAAU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,SAAS,GAAG,IAAIC,GAAG,EAAE;IAC1B,IAAI,CAACC,iBAAiB,GAAG,IAAI;AAC7B,IAAA,IAAI,CAACC,MAAM,GAAG,IAAIV,UAAU,CAAC,CAAC,CAAC;IAC/B,IAAI,CAACY,SAAS,GAAG,IAAI;AACzB,EAAA;AACJ;;AAqCA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS2C,sBAAsBA,CAACtC,OAAO,EACvC;EACI,IAAIA,OAAO,YAAYT,GAAG,EAC1B;IACI,OAAOyF,KAAK,CAAC9E,IAAI,CAACF,OAAO,CAACiF,OAAO,EAAE,CAAC,CAACV,GAAG,CAAC,CAAC,CAAEpD,IAAI,EAAEyB,KAAK,CAAE,KAAK,IAAIsC,gBAAgB,CAAC/D,IAAI,EAAEyB,KAAK,CAAC,CAAC;AACpG,EAAA;AACA,EAAA,IAAI,CAACoC,KAAK,CAACG,OAAO,CAACnF,OAAO,CAAC,EAC3B;AACI,IAAA,OAAO,EAAE;AACb,EAAA;AACA,EAAA,OAAOA,OAAO,CAACuE,GAAG,CAAExB,KAAK,IACzB;IACI,IAAIA,KAAK,YAAYmC,gBAAgB,EACrC;AACI,MAAA,OAAOnC,KAAK;AAChB,IAAA;AACA,IAAA,OAAO,IAAImC,gBAAgB,CAACnC,KAAK,EAAE5B,IAAI,IAAI,EAAE,EAAE4B,KAAK,EAAEH,KAAK,IAAI,EAAE,CAAC;AACtE,EAAA,CAAC,CAAC;AACN;;;;"}
|
|
1
|
+
{"version":3,"file":"HlslEffectRes.js","sources":["../../../../../../../src/formats/hlsl/core/tr2/resources/HlslEffectRes.js"],"sourcesContent":["import { HlslReader } from \"../../HlslReader.js\";\nimport { asUint8Array } from \"@carbonenginejs/runtime-utils/bytes\";\nimport { HlslEffectStateManager } from \"../../HlslEffectStateManager.js\";\nimport { HlslShader } from \"../shader/HlslShader.js\";\nimport { HlslShaderOption } from \"../shader/HlslShaderOption.js\";\nimport { HlslShaderPermutation } from \"./HlslShaderPermutation.js\";\n\nconst MIN_SUPPORTED_EFFECT_VERSION = 8;\nconst MAX_SUPPORTED_EFFECT_VERSION = 15;\n\n/**\n * Carbon/Trinity effect resource reader for compiled shader metadata.\n */\nexport class HlslEffectRes\n{\n static globalEffectOptions = [];\n\n /**\n * Creates an empty effect resource ready to load a compiled `.sm_*` payload.\n */\n constructor()\n {\n this.m_data = new Uint8Array(0);\n this.m_version = 0;\n this.m_stringTable = new Uint8Array(0);\n this.m_stringTableSize = 0;\n this.m_offsets = [];\n this.m_offsetCount = 0;\n this.m_permutations = [];\n this.m_shaders = new Map();\n this.m_compilerVersion = null;\n this.m_compilerVersionBytes = null;\n this.m_hash = new Uint8Array(0);\n this.sourcePath = \"\";\n this.loadError = null;\n this.effectStateManager = new HlslEffectStateManager();\n }\n\n /**\n * Reads the effect header, string table, permutation axes, and body offsets.\n *\n * @param {ArrayBuffer|ArrayBufferView|Uint8Array} source Compiled effect bytes.\n * @param {object} [options] Load metadata and dependency overrides.\n * @param {string} [options.sourcePath] Source path used in reports.\n * @param {string} [options.source] Alternate source label.\n * @param {HlslEffectStateManager} [options.effectStateManager] Registry to receive decoded state.\n * @returns {boolean} True when the header was decoded successfully.\n */\n DoLoad(source, options = {})\n {\n this._reset();\n this.sourcePath = options.sourcePath || options.source || \"\";\n this.effectStateManager = options.effectStateManager || new HlslEffectStateManager();\n\n try\n {\n // Carbon owns a memcpy of the loaded resource. Keep the JS graph\n // equally isolated from later caller mutation.\n this.m_data = Uint8Array.from(asUint8Array(source));\n const stream = new HlslReader(this.m_data, { source: this.sourcePath || \"HlslEffectRes\" });\n this.m_version = stream.readUint32();\n\n if (this.m_version < MIN_SUPPORTED_EFFECT_VERSION || this.m_version > MAX_SUPPORTED_EFFECT_VERSION)\n {\n throw new Error(`Unsupported HlslEffectRes version ${this.m_version}; expected ${MIN_SUPPORTED_EFFECT_VERSION}..${MAX_SUPPORTED_EFFECT_VERSION}`);\n }\n\n if (this.m_version >= 15)\n {\n // The header slot is four bytes, not a u32:\n // `constexpr uint8_t ShaderCompilerVersion[4]` = {major, minor,\n // patch, tweak} (ShaderCompilerConfig.h.in:5), of which Carbon's\n // rebuild check compares only the first three\n // (ModifiedTime.cpp:77). A shipped v15 header reads `01 02 06 00`\n // — compiler 1.2.6.0, matching the ShaderCompiler project\n // version. As a u32 that is 0x00060201, which means nothing.\n //\n // `m_compilerVersionBytes` is the truthful reading and is what new\n // code should use. `m_compilerVersion` keeps the dword form because\n // it is republished as `source.compilerVersion` in the portable\n // reflection, where it is asserted to be an unsigned integer\n // (portableReflection.js:645) and covered by a package digest —\n // changing its shape changes package bytes, which belongs with the\n // format rewrite rather than here.\n const compilerVersionBytes = stream.readRaw(4);\n this.m_compilerVersionBytes = Array.from(compilerVersionBytes);\n this.m_compilerVersion = new DataView(\n compilerVersionBytes.buffer,\n compilerVersionBytes.byteOffset,\n 4\n ).getUint32(0, true);\n this.m_hash = stream.readRaw(32);\n }\n\n this.m_stringTableSize = stream.readUint32();\n if (this.m_stringTableSize > this.m_data.length || stream.offset + this.m_stringTableSize > this.m_data.length)\n {\n throw new Error(\"Invalid effect string table size\");\n }\n this.m_stringTable = this.m_data.subarray(stream.offset, stream.offset + this.m_stringTableSize);\n stream.skip(this.m_stringTableSize);\n stream.setStringTable(this.m_stringTable, this.m_stringTableSize);\n\n const permutationCount = stream.readUint8();\n for (let index = 0; index < permutationCount; index += 1)\n {\n const permutation = new HlslShaderPermutation();\n permutation.name = stream.readString();\n permutation.defaultOption = stream.readUint8();\n permutation.description = stream.readString();\n permutation.type = this.m_version > 5 ? stream.readUint8() : 0;\n\n const optionCount = stream.readUint8();\n for (let optionIndex = 0; optionIndex < optionCount; optionIndex += 1)\n {\n permutation.options.push(stream.readString());\n }\n this.m_permutations.push(permutation);\n }\n\n const headerSize = stream.readUint32();\n if (headerSize === 0)\n {\n throw new Error(\"Effect contains no compiled shader bodies\");\n }\n\n this.m_offsetCount = headerSize;\n for (let index = 0; index < headerSize; index += 1)\n {\n const record = {\n index: stream.readUint32(),\n offset: stream.readUint32(),\n size: stream.readUint32()\n };\n record.end = record.offset + record.size;\n if (record.end > this.m_data.length)\n {\n throw new Error(`Invalid effect body record ${index}`);\n }\n this.m_offsets.push(record);\n }\n\n return true;\n }\n catch (error)\n {\n this.loadError = error;\n this.m_shaders.clear();\n return false;\n }\n }\n\n /**\n * Mirrors Carbon's prepare hook by clearing cached shader bodies.\n *\n * @returns {boolean} True when preparation completed.\n */\n DoPrepare()\n {\n this.m_shaders.clear();\n return true;\n }\n\n /**\n * Resolves a permutation option set to a decoded `HlslShader`.\n *\n * @param {Array<HlslShaderOption|object>|Map<string, string>} [options] Local option choices.\n * @param {number|null} [count] Number of local option entries to consider.\n * @returns {HlslShader|null} Decoded shader or null when no matching body exists.\n */\n GetShader(options = [], count = null)\n {\n if (!this.IsGood())\n {\n return null;\n }\n\n const normalizedOptions = normalizeShaderOptions(options);\n const optionCount = Number.isInteger(count) ? Math.min(count, normalizedOptions.length) : normalizedOptions.length;\n let multiplier = 1;\n let index = 0;\n\n for (const permutation of this.m_permutations)\n {\n let value = permutation.defaultOption;\n const globalOption = HlslEffectRes.globalEffectOptions.find((entry) => entry.name === permutation.name);\n const localOption = normalizedOptions.slice(0, optionCount).find((entry) => entry.name === permutation.name);\n const selected = globalOption || localOption;\n\n if (selected)\n {\n const selectedIndex = permutation.options.findIndex((option) => option === selected.value);\n if (selectedIndex >= 0)\n {\n value = selectedIndex;\n }\n }\n\n index += value * multiplier;\n multiplier *= permutation.options.length || 1;\n }\n\n return this.GetShaderByIndex(index);\n }\n\n /**\n * Decodes the body at an exact permutation-table index without applying\n * global or local option overrides.\n *\n * @param {number} index Exact zero-based permutation-table index.\n * @returns {HlslShader|null} Decoded shader or null when the index/body is unavailable.\n */\n GetShaderByIndex(index)\n {\n if (!Number.isSafeInteger(index) || index < 0)\n {\n throw new TypeError(\"HlslEffectRes body index must be a non-negative safe integer\");\n }\n if (!this.IsGood())\n {\n return null;\n }\n if (this.m_shaders.has(index))\n {\n return this.m_shaders.get(index);\n }\n\n const offset = this.m_offsets[index];\n if (!offset)\n {\n return null;\n }\n\n const shader = new HlslShader();\n const buffer = this.m_data.subarray(offset.offset, offset.end);\n const ok = shader.GetEffect().Read(\n buffer,\n offset.size,\n this.m_version,\n this.m_stringTable,\n this.m_stringTableSize,\n this.sourcePath,\n { effectStateManager: this.effectStateManager }\n );\n if (!ok)\n {\n return null;\n }\n\n shader.ProcessEffect();\n this.m_shaders.set(index, shader);\n return shader;\n }\n\n /**\n * Reports whether the effect header has been loaded without error.\n *\n * @returns {boolean} True when this resource has usable effect data.\n */\n IsGood()\n {\n return !this.loadError && this.m_data.length > 0 && this.m_version >= MIN_SUPPORTED_EFFECT_VERSION;\n }\n\n /**\n * Reports whether byte memory usage is known for this resource.\n *\n * @returns {boolean} Always true for byte-backed JavaScript resources.\n */\n IsMemoryUsageKnown()\n {\n return true;\n }\n\n /**\n * Returns the byte size of the loaded effect payload.\n *\n * @returns {number} Loaded byte count.\n */\n GetMemoryUsage()\n {\n return this.m_data.length;\n }\n\n /**\n * Clears decoded shader body caches while keeping the loaded header data.\n */\n ReleaseResources()\n {\n this.m_shaders.clear();\n }\n\n /**\n * Returns JSON-safe permutation metadata for tooling and reports.\n *\n * @returns {object[]} Permutation descriptions.\n */\n GetPermutationDescription()\n {\n return this.m_permutations.map((permutation) => permutation.toJSON());\n }\n\n /**\n * Returns a JSON-safe summary of the loaded effect resource.\n *\n * @returns {object} Serializable effect resource summary.\n */\n toJSON()\n {\n return {\n version: this.m_version,\n compilerVersion: this.m_compilerVersion,\n compilerVersionBytes: this.m_compilerVersionBytes,\n sourcePath: this.sourcePath,\n stringTableSize: this.m_stringTableSize,\n offsetCount: this.m_offsetCount,\n permutations: this.m_permutations.map((entry) => entry.toJSON()),\n offsets: this.m_offsets.map((entry) => ({ ...entry })),\n loadError: this.loadError ? {\n name: this.loadError.name,\n message: this.loadError.message\n } : null\n };\n }\n\n /**\n * Resets loaded state before a new `DoLoad` attempt.\n *\n * @private\n */\n _reset()\n {\n this.m_data = new Uint8Array(0);\n this.m_version = 0;\n this.m_stringTable = new Uint8Array(0);\n this.m_stringTableSize = 0;\n this.m_offsets = [];\n this.m_offsetCount = 0;\n this.m_permutations = [];\n this.m_shaders = new Map();\n this.m_compilerVersion = null;\n this.m_compilerVersionBytes = null;\n this.m_hash = new Uint8Array(0);\n this.loadError = null;\n }\n}\n\n/**\n * Applies global shader option overrides used during permutation lookup.\n *\n * @param {Array<HlslShaderOption|object>|Map<string, string>} [changes] Option changes to merge.\n */\nexport function ModifyGlobalEffectOptions(changes = [])\n{\n for (const change of normalizeShaderOptions(changes))\n {\n const index = HlslEffectRes.globalEffectOptions.findIndex((entry) => entry.name === change.name);\n if (!change.value)\n {\n if (index >= 0) HlslEffectRes.globalEffectOptions.splice(index, 1);\n }\n else if (index >= 0)\n {\n HlslEffectRes.globalEffectOptions[index] = change;\n }\n else\n {\n HlslEffectRes.globalEffectOptions.push(change);\n }\n }\n}\n\n/**\n * Returns the current global shader option overrides.\n *\n * @returns {HlslShaderOption[]} Copy of global shader option overrides.\n */\nexport function GetGlobalEffectOptions()\n{\n return HlslEffectRes.globalEffectOptions.slice();\n}\n\n/**\n * Converts supported option input shapes to `HlslShaderOption` instances.\n *\n * @param {Array<HlslShaderOption|object>|Map<string, string>} options Option input.\n * @returns {HlslShaderOption[]} Normalized option list.\n */\nfunction normalizeShaderOptions(options)\n{\n if (options instanceof Map)\n {\n return Array.from(options.entries()).map(([ name, value ]) => new HlslShaderOption(name, value));\n }\n if (!Array.isArray(options))\n {\n return [];\n }\n return options.map((entry) =>\n {\n if (entry instanceof HlslShaderOption)\n {\n return entry;\n }\n return new HlslShaderOption(entry?.name || \"\", entry?.value || \"\");\n });\n}\n"],"names":["MIN_SUPPORTED_EFFECT_VERSION","MAX_SUPPORTED_EFFECT_VERSION","HlslEffectRes","globalEffectOptions","constructor","m_data","Uint8Array","m_version","m_stringTable","m_stringTableSize","m_offsets","m_offsetCount","m_permutations","m_shaders","Map","m_compilerVersion","m_compilerVersionBytes","m_hash","sourcePath","loadError","effectStateManager","HlslEffectStateManager","DoLoad","source","options","_reset","from","asUint8Array","stream","HlslReader","readUint32","Error","compilerVersionBytes","readRaw","Array","DataView","buffer","byteOffset","getUint32","length","offset","subarray","skip","setStringTable","permutationCount","readUint8","index","permutation","HlslShaderPermutation","name","readString","defaultOption","description","type","optionCount","optionIndex","push","headerSize","record","size","end","error","clear","DoPrepare","GetShader","count","IsGood","normalizedOptions","normalizeShaderOptions","Number","isInteger","Math","min","multiplier","value","globalOption","find","entry","localOption","slice","selected","selectedIndex","findIndex","option","GetShaderByIndex","isSafeInteger","TypeError","has","get","shader","HlslShader","ok","GetEffect","Read","ProcessEffect","set","IsMemoryUsageKnown","GetMemoryUsage","ReleaseResources","GetPermutationDescription","map","toJSON","version","compilerVersion","stringTableSize","offsetCount","permutations","offsets","message","entries","HlslShaderOption","isArray"],"mappings":";;;;;;;AAOA,MAAMA,4BAA4B,GAAG,CAAC;AACtC,MAAMC,4BAA4B,GAAG,EAAE;;AAEvC;AACA;AACA;AACO,MAAMC,aAAa,CAC1B;EACI,OAAOC,mBAAmB,GAAG,EAAE;;AAE/B;AACJ;AACA;AACIC,EAAAA,WAAWA,GACX;AACI,IAAA,IAAI,CAACC,MAAM,GAAG,IAAIC,UAAU,CAAC,CAAC,CAAC;IAC/B,IAAI,CAACC,SAAS,GAAG,CAAC;AAClB,IAAA,IAAI,CAACC,aAAa,GAAG,IAAIF,UAAU,CAAC,CAAC,CAAC;IACtC,IAAI,CAACG,iBAAiB,GAAG,CAAC;IAC1B,IAAI,CAACC,SAAS,GAAG,EAAE;IACnB,IAAI,CAACC,aAAa,GAAG,CAAC;IACtB,IAAI,CAACC,cAAc,GAAG,EAAE;AACxB,IAAA,IAAI,CAACC,SAAS,GAAG,IAAIC,GAAG,EAAE;IAC1B,IAAI,CAACC,iBAAiB,GAAG,IAAI;IAC7B,IAAI,CAACC,sBAAsB,GAAG,IAAI;AAClC,IAA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EAAE;IACnB,IAAI,CAACC,aAAa,GAAG,CAAC;IACtB,IAAI,CAACC,cAAc,GAAG,EAAE;AACxB,IAAA,IAAI,CAACC,SAAS,GAAG,IAAIC,GAAG,EAAE;IAC1B,IAAI,CAACC,iBAAiB,GAAG,IAAI;IAC7B,IAAI,CAACC,sBAAsB,GAAG,IAAI;AAClC,IAAA,IAAI,CAACC,MAAM,GAAG,IAAIX,UAAU,CAAC,CAAC,CAAC;IAC/B,IAAI,CAACa,SAAS,GAAG,IAAI;AACzB,EAAA;AACJ;;AAqCA;AACA;AACA;AACA;AACA;AACA;AACA,SAASiD,sBAAsBA,CAAC5C,OAAO,EACvC;EACI,IAAIA,OAAO,YAAYV,GAAG,EAC1B;IACI,OAAOoB,KAAK,CAACR,IAAI,CAACF,OAAO,CAACqF,OAAO,EAAE,CAAC,CAACT,GAAG,CAAC,CAAC,CAAEnD,IAAI,EAAEyB,KAAK,CAAE,KAAK,IAAIoC,gBAAgB,CAAC7D,IAAI,EAAEyB,KAAK,CAAC,CAAC;AACpG,EAAA;AACA,EAAA,IAAI,CAACxC,KAAK,CAAC6E,OAAO,CAACvF,OAAO,CAAC,EAC3B;AACI,IAAA,OAAO,EAAE;AACb,EAAA;AACA,EAAA,OAAOA,OAAO,CAAC4E,GAAG,CAAEvB,KAAK,IACzB;IACI,IAAIA,KAAK,YAAYiC,gBAAgB,EACrC;AACI,MAAA,OAAOjC,KAAK;AAChB,IAAA;AACA,IAAA,OAAO,IAAIiC,gBAAgB,CAACjC,KAAK,EAAE5B,IAAI,IAAI,EAAE,EAAE4B,KAAK,EAAEH,KAAK,IAAI,EAAE,CAAC;AACtE,EAAA,CAAC,CAAC;AACN;;;;"}
|
package/dist/formats/index.js
CHANGED
|
@@ -4,7 +4,7 @@ export { CjsCmfFormat } from './cmf/CjsCmfFormat.js';
|
|
|
4
4
|
export { CjsDdsFormat } from './dds/CjsDdsFormat.js';
|
|
5
5
|
export { CjsDxbcFormat } from './dxbc/CjsDxbcFormat.js';
|
|
6
6
|
export { CjsHlslFormat } from './hlsl/CjsHlslFormat.js';
|
|
7
|
-
import '
|
|
7
|
+
import '../format/CjsByteReader.js';
|
|
8
8
|
import '@carbonenginejs/runtime-utils/bytes';
|
|
9
9
|
import './hlsl/core/tr2/shader/HlslEffectResource.js';
|
|
10
10
|
export { CjsWebglFormat } from './webgl/CjsWebglFormat.js';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WebglReader } from './binary.js';
|
|
2
2
|
import { sha256Bytes } from '../../../../format/effect/sha256.js';
|
|
3
3
|
import { hydrateEffectReflectionForPermutation } from '../../../../format/effect/effectReflectionPackage.js';
|
|
4
|
+
import { asUint8Array } from '@carbonenginejs/runtime-utils/bytes';
|
|
4
5
|
|
|
5
6
|
const CEWG_MAGIC = "CEWG";
|
|
6
7
|
const CEWG_FORMAT = "CEWG";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CewgPackage.js","sources":["../../../../../../src/formats/webgl/core/cewg/CewgPackage.js"],"sourcesContent":["import { WebglReader, asUint8Array } from \"./binary.js\";\nimport { sha256Bytes } from \"../../../../format/effect/sha256.js\";\nimport {\n hydrateEffectReflectionForPermutation\n} from \"../../../../format/effect/effectReflectionPackage.js\";\n\nconst CEWG_MAGIC = \"CEWG\";\nconst CEWG_FORMAT = \"CEWG\";\nconst CEWG_VERSION = 1;\nconst textDecoder = new TextDecoder(\"utf-8\", { fatal: false });\nconst jsonTextDecoder = new TextDecoder(\"utf-8\", { fatal: true });\nconst validatedEffectReflectionPackages = new WeakSet();\n\n/**\n * Reader for CarbonEngineJS CEWG shader packages emitted by `hlsl2webgl`.\n */\nexport class CewgPackage\n{\n /**\n * Creates an empty package reader.\n */\n constructor()\n {\n this.version = 0;\n this.chunks = [];\n this.chunkMap = new Map();\n this.jsonCache = new Map();\n this.reflectionBlobIndex = null;\n this.readError = null;\n this.sourcePath = \"\";\n }\n\n /**\n * Reads a CEWG package from bytes.\n *\n * @param {ArrayBuffer|ArrayBufferView|Uint8Array} source CEWG binary bytes.\n * @param {object} [options] Read options.\n * @param {string} [options.sourcePath] Source path for diagnostics.\n * @returns {boolean} True when the package was decoded.\n */\n Read(source, options = {})\n {\n validatedEffectReflectionPackages.delete(this);\n this.version = 0;\n this.chunks = [];\n this.chunkMap = new Map();\n this.jsonCache = new Map();\n this.reflectionBlobIndex = null;\n this.readError = null;\n this.sourcePath = options.sourcePath || \"\";\n\n try\n {\n const bytes = asUint8Array(source);\n const stream = new WebglReader(bytes, { source: this.sourcePath || \"CEWG\" });\n const magic = decodeAscii(stream.readRaw(CEWG_MAGIC.length));\n if (magic !== CEWG_MAGIC)\n {\n throw new Error(`Invalid CEWG magic \"${magic}\"`);\n }\n\n this.version = stream.readUint32();\n if (this.version !== CEWG_VERSION)\n {\n throw new Error(`Unsupported CEWG version ${this.version}`);\n }\n\n const chunkCount = stream.readUint32();\n for (let index = 0; index < chunkCount; index += 1)\n {\n const tag = decodeAscii(stream.readRaw(4));\n validateChunkTag(tag);\n if (this.chunkMap.has(tag))\n {\n throw new Error(`CEWG package contains duplicate chunk tag ${tag}`);\n }\n const size = stream.readUint32();\n const offset = stream.offset;\n const chunkBytes = stream.readRaw(size);\n const chunk = {\n tag,\n size,\n offset,\n bytes: chunkBytes\n };\n this.chunks.push(chunk);\n this.chunkMap.set(tag, chunk);\n }\n\n if (stream.remaining !== 0)\n {\n throw new Error(`CEWG package has ${stream.remaining} trailing bytes`);\n }\n\n return true;\n }\n catch (error)\n {\n this.readError = error;\n this.chunks = [];\n this.chunkMap = new Map();\n this.jsonCache = new Map();\n this.reflectionBlobIndex = null;\n return false;\n }\n }\n\n /**\n * Reports whether the package decoded successfully.\n *\n * @returns {boolean} True when no read error is present.\n */\n IsGood()\n {\n return !this.readError && this.version === CEWG_VERSION;\n }\n\n /**\n * Gets a chunk by four-character tag.\n *\n * @param {string} tag Chunk tag.\n * @returns {{tag:string,size:number,offset:number,bytes:Uint8Array}|null} Chunk record.\n */\n GetChunk(tag)\n {\n return this.chunkMap.get(tag) || null;\n }\n\n /**\n * Decodes a text chunk.\n *\n * @param {string} tag Chunk tag.\n * @returns {string|null} Decoded text, or null when absent.\n */\n GetText(tag)\n {\n const chunk = this.GetChunk(tag);\n return chunk ? textDecoder.decode(chunk.bytes) : null;\n }\n\n /**\n * Decodes a JSON chunk.\n *\n * @param {string} tag Chunk tag.\n * @returns {object|null} Parsed JSON, or null when absent.\n */\n GetJson(tag)\n {\n return cloneJson(getCachedJson(this, tag));\n }\n\n /**\n * Gets translator summary metadata from the `INFO` chunk.\n *\n * @returns {object|null} Info JSON.\n */\n get info()\n {\n return this.GetJson(\"INFO\");\n }\n\n /**\n * Gets caller-provided Carbon metadata from the `META` chunk.\n *\n * @returns {object|null} Metadata JSON.\n */\n get metadata()\n {\n return this.GetJson(\"META\");\n }\n\n /**\n * Gets the complete source permutation graph when present.\n *\n * @returns {object|null} Parsed permutation graph.\n */\n get permutationGraph()\n {\n return this.GetJson(\"PGRF\");\n }\n\n /**\n * Gets complete source effect reflection when present.\n *\n * @returns {object|null} Parsed reflection document.\n */\n get reflection()\n {\n return this.GetJson(\"RFLX\");\n }\n\n /**\n * Gets the raw reflection blob store when present.\n *\n * @returns {Uint8Array|null} RBLB bytes.\n */\n get reflectionBlobBytes()\n {\n return this.GetChunk(\"RBLB\")?.bytes ?? null;\n }\n\n /**\n * Copies one reflected byte payload by blob key or exact reference.\n *\n * @param {string|object} value Blob key or exact RFLX byte-reference object.\n * @returns {Uint8Array|null} Owned payload bytes, or null when unavailable.\n */\n GetReflectionBlob(value)\n {\n const key = typeof value === \"string\" ? value : value?.blobKey;\n if (!this.reflectionBlobIndex)\n {\n this.reflectionBlobIndex = new Map(\n (getCachedJson(this, \"RFLX\")?.blobStore?.blobs ?? []).map((entry) => [\n entry.blobKey,\n entry\n ])\n );\n }\n const entry = this.reflectionBlobIndex.get(key);\n const bytes = this.reflectionBlobBytes;\n if (!entry || !bytes) return null;\n if (typeof value !== \"string\"\n && (!value\n || value.offset !== entry.offset\n || value.byteLength !== entry.byteLength\n || value.sha256 !== entry.sha256))\n {\n return null;\n }\n const end = entry.offset + entry.byteLength;\n if (!Number.isSafeInteger(entry.offset) || entry.offset < 0\n || !Number.isSafeInteger(entry.byteLength) || entry.byteLength < 0\n || end > bytes.byteLength\n || sha256Bytes(bytes.subarray(entry.offset, end)) !== entry.sha256)\n {\n return null;\n }\n return Uint8Array.from(bytes.subarray(entry.offset, end));\n }\n\n /**\n * Gets fully hydrated portable source reflection for one permutation.\n *\n * Every reflected byte field is returned as a fresh owned `Uint8Array`.\n *\n * @param {number} [permutationIndex] Exact PGRF permutation index.\n * @returns {object|null} Validated portable reflection, or null when absent.\n */\n GetPortableEffectReflection(permutationIndex)\n {\n if (!validatedEffectReflectionPackages.has(this)) return null;\n const reflection = getCachedJson(this, \"RFLX\");\n const permutationGraph = getCachedJson(this, \"PGRF\");\n if (!reflection || !permutationGraph) return null;\n const selectedIndex = permutationIndex\n ?? getCachedJson(this, \"INFO\")?.defaultPermutationIndex\n ?? 0;\n return hydrateEffectReflectionForPermutation(\n reflection,\n permutationGraph,\n selectedIndex,\n (reference) => this.GetReflectionBlob(reference)\n );\n }\n\n /**\n * Gets translated GLSL source from the `GLSL` chunk.\n *\n * @returns {string|null} GLSL source.\n */\n get glsl()\n {\n return this.GetText(\"GLSL\");\n }\n\n /**\n * Gets translated GLSL metadata when the `GLSL` chunk contains JSON.\n *\n * Whole-effect packages store a JSON stage set in this chunk; single-stage\n * packages store raw GLSL text and return null here.\n *\n * @returns {object|null} Parsed GLSL stage set, or null for raw source.\n */\n get glslJson()\n {\n try\n {\n return this.GetJson(\"GLSL\");\n }\n catch\n {\n return null;\n }\n }\n\n /**\n * Gets original DXBC bytes when present.\n *\n * @returns {Uint8Array|null} DXBC bytes.\n */\n get dxbc()\n {\n return this.GetChunk(\"DXBC\")?.bytes || null;\n }\n\n /**\n * Returns a JSON-safe package summary.\n *\n * @returns {object} Serializable summary.\n */\n toJSON()\n {\n return {\n format: CEWG_FORMAT,\n version: this.version,\n sourcePath: this.sourcePath,\n chunks: this.chunks.map((chunk) => ({\n tag: chunk.tag,\n size: chunk.size,\n offset: chunk.offset\n })),\n readError: this.readError ? {\n name: this.readError.name,\n message: this.readError.message\n } : null\n };\n }\n}\n\n/**\n * Marks one package as having passed the canonical v3 reflection envelope.\n *\n * This is intentionally an internal deep import rather than package-root API.\n *\n * @param {CewgPackage} pkg Validated package reader.\n * @returns {void}\n */\nexport function markEffectReflectionValidated(pkg)\n{\n validatedEffectReflectionPackages.add(pkg);\n}\n\n/**\n * Decode and cache one private JSON document.\n *\n * @param {CewgPackage} pkg Package reader.\n * @param {string} tag Chunk tag.\n * @returns {object|null} Private parsed JSON, or null when absent.\n */\nfunction getCachedJson(pkg, tag)\n{\n if (!pkg.jsonCache.has(tag))\n {\n const chunk = pkg.GetChunk(tag);\n pkg.jsonCache.set(\n tag,\n chunk ? JSON.parse(jsonTextDecoder.decode(chunk.bytes)) : null\n );\n }\n return pkg.jsonCache.get(tag);\n}\n\n/**\n * Copy JSON-compatible data without reparsing its source chunk.\n *\n * @param {any} value Cached JSON value.\n * @returns {any} Structurally independent JSON value.\n */\nfunction cloneJson(value)\n{\n if (Array.isArray(value)) return value.map(cloneJson);\n if (value && typeof value === \"object\")\n {\n return Object.fromEntries(Object.entries(value).map(([ key, entry ]) => [\n key,\n cloneJson(entry)\n ]));\n }\n return value;\n}\n\nfunction validateChunkTag(tag)\n{\n if (typeof tag !== \"string\"\n || tag.length !== 4\n || [ ...tag ].some((character) =>\n {\n const code = character.charCodeAt(0);\n return code < 0x21 || code > 0x7e;\n }))\n {\n throw new Error(`Invalid CEWG chunk tag ${JSON.stringify(tag)}`);\n }\n}\n\n/**\n * Decodes an ASCII four-character code.\n *\n * @param {Uint8Array} bytes Four-byte tag payload.\n * @returns {string} ASCII string.\n */\nfunction decodeAscii(bytes)\n{\n return String.fromCharCode(...bytes);\n}\n"],"names":["CEWG_MAGIC","CEWG_FORMAT","CEWG_VERSION","textDecoder","TextDecoder","fatal","jsonTextDecoder","validatedEffectReflectionPackages","WeakSet","CewgPackage","constructor","version","chunks","chunkMap","Map","jsonCache","reflectionBlobIndex","readError","sourcePath","Read","source","options","delete","bytes","asUint8Array","stream","WebglReader","magic","decodeAscii","readRaw","length","Error","readUint32","chunkCount","index","tag","validateChunkTag","has","size","offset","chunkBytes","chunk","push","set","remaining","error","IsGood","GetChunk","get","GetText","decode","GetJson","cloneJson","getCachedJson","info","metadata","permutationGraph","reflection","reflectionBlobBytes","GetReflectionBlob","value","key","blobKey","blobStore","blobs","map","entry","byteLength","sha256","end","Number","isSafeInteger","sha256Bytes","subarray","Uint8Array","from","GetPortableEffectReflection","permutationIndex","selectedIndex","defaultPermutationIndex","hydrateEffectReflectionForPermutation","reference","glsl","glslJson","dxbc","toJSON","format","name","message","markEffectReflectionValidated","pkg","add","JSON","parse","Array","isArray","Object","fromEntries","entries","some","character","code","charCodeAt","stringify","String","fromCharCode"],"mappings":";;;;AAMA,MAAMA,UAAU,GAAG,MAAM;AACzB,MAAMC,WAAW,GAAG,MAAM;AAC1B,MAAMC,YAAY,GAAG,CAAC;AACtB,MAAMC,WAAW,GAAG,IAAIC,WAAW,CAAC,OAAO,EAAE;AAAEC,EAAAA,KAAK,EAAE;AAAM,CAAC,CAAC;AAC9D,MAAMC,eAAe,GAAG,IAAIF,WAAW,CAAC,OAAO,EAAE;AAAEC,EAAAA,KAAK,EAAE;AAAK,CAAC,CAAC;AACjE,MAAME,iCAAiC,GAAG,IAAIC,OAAO,EAAE;;AAEvD;AACA;AACA;AACO,MAAMC,WAAW,CACxB;AACI;AACJ;AACA;AACIC,EAAAA,WAAWA,GACX;IACI,IAAI,CAACC,OAAO,GAAG,CAAC;IAChB,IAAI,CAACC,MAAM,GAAG,EAAE;AAChB,IAAA,IAAI,CAACC,QAAQ,GAAG,IAAIC,GAAG,EAAE;AACzB,IAAA,IAAI,CAACC,SAAS,GAAG,IAA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IAAItE,KAAK,CAAC,CAAA,uBAAA,EAA0B6D,IAAI,CAACW,SAAS,CAACpE,GAAG,CAAC,CAAA,CAAE,CAAC;AACpE,EAAA;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAASP,WAAWA,CAACL,KAAK,EAC1B;AACI,EAAA,OAAOiF,MAAM,CAACC,YAAY,CAAC,GAAGlF,KAAK,CAAC;AACxC;;;;"}
|
|
1
|
+
{"version":3,"file":"CewgPackage.js","sources":["../../../../../../src/formats/webgl/core/cewg/CewgPackage.js"],"sourcesContent":["import { WebglReader, asUint8Array } from \"./binary.js\";\nimport { sha256Bytes } from \"../../../../format/effect/sha256.js\";\nimport {\n hydrateEffectReflectionForPermutation\n} from \"../../../../format/effect/effectReflectionPackage.js\";\n\nconst CEWG_MAGIC = \"CEWG\";\nconst CEWG_FORMAT = \"CEWG\";\nconst CEWG_VERSION = 1;\nconst textDecoder = new TextDecoder(\"utf-8\", { fatal: false });\nconst jsonTextDecoder = new TextDecoder(\"utf-8\", { fatal: true });\nconst validatedEffectReflectionPackages = new WeakSet();\n\n/**\n * Reader for CarbonEngineJS CEWG shader packages emitted by `hlsl2webgl`.\n */\nexport class CewgPackage\n{\n /**\n * Creates an empty package reader.\n */\n constructor()\n {\n this.version = 0;\n this.chunks = [];\n this.chunkMap = new Map();\n this.jsonCache = new Map();\n this.reflectionBlobIndex = null;\n this.readError = null;\n this.sourcePath = \"\";\n }\n\n /**\n * Reads a CEWG package from bytes.\n *\n * @param {ArrayBuffer|ArrayBufferView|Uint8Array} source CEWG binary bytes.\n * @param {object} [options] Read options.\n * @param {string} [options.sourcePath] Source path for diagnostics.\n * @returns {boolean} True when the package was decoded.\n */\n Read(source, options = {})\n {\n validatedEffectReflectionPackages.delete(this);\n this.version = 0;\n this.chunks = [];\n this.chunkMap = new Map();\n this.jsonCache = new Map();\n this.reflectionBlobIndex = null;\n this.readError = null;\n this.sourcePath = options.sourcePath || \"\";\n\n try\n {\n const bytes = asUint8Array(source);\n const stream = new WebglReader(bytes, { source: this.sourcePath || \"CEWG\" });\n const magic = decodeAscii(stream.readRaw(CEWG_MAGIC.length));\n if (magic !== CEWG_MAGIC)\n {\n throw new Error(`Invalid CEWG magic \"${magic}\"`);\n }\n\n this.version = stream.readUint32();\n if (this.version !== CEWG_VERSION)\n {\n throw new Error(`Unsupported CEWG version ${this.version}`);\n }\n\n const chunkCount = stream.readUint32();\n for (let index = 0; index < chunkCount; index += 1)\n {\n const tag = decodeAscii(stream.readRaw(4));\n validateChunkTag(tag);\n if (this.chunkMap.has(tag))\n {\n throw new Error(`CEWG package contains duplicate chunk tag ${tag}`);\n }\n const size = stream.readUint32();\n const offset = stream.offset;\n const chunkBytes = stream.readRaw(size);\n const chunk = {\n tag,\n size,\n offset,\n bytes: chunkBytes\n };\n this.chunks.push(chunk);\n this.chunkMap.set(tag, chunk);\n }\n\n if (stream.remaining !== 0)\n {\n throw new Error(`CEWG package has ${stream.remaining} trailing bytes`);\n }\n\n return true;\n }\n catch (error)\n {\n this.readError = error;\n this.chunks = [];\n this.chunkMap = new Map();\n this.jsonCache = new Map();\n this.reflectionBlobIndex = null;\n return false;\n }\n }\n\n /**\n * Reports whether the package decoded successfully.\n *\n * @returns {boolean} True when no read error is present.\n */\n IsGood()\n {\n return !this.readError && this.version === CEWG_VERSION;\n }\n\n /**\n * Gets a chunk by four-character tag.\n *\n * @param {string} tag Chunk tag.\n * @returns {{tag:string,size:number,offset:number,bytes:Uint8Array}|null} Chunk record.\n */\n GetChunk(tag)\n {\n return this.chunkMap.get(tag) || null;\n }\n\n /**\n * Decodes a text chunk.\n *\n * @param {string} tag Chunk tag.\n * @returns {string|null} Decoded text, or null when absent.\n */\n GetText(tag)\n {\n const chunk = this.GetChunk(tag);\n return chunk ? textDecoder.decode(chunk.bytes) : null;\n }\n\n /**\n * Decodes a JSON chunk.\n *\n * @param {string} tag Chunk tag.\n * @returns {object|null} Parsed JSON, or null when absent.\n */\n GetJson(tag)\n {\n return cloneJson(getCachedJson(this, tag));\n }\n\n /**\n * Gets translator summary metadata from the `INFO` chunk.\n *\n * @returns {object|null} Info JSON.\n */\n get info()\n {\n return this.GetJson(\"INFO\");\n }\n\n /**\n * Gets caller-provided Carbon metadata from the `META` chunk.\n *\n * @returns {object|null} Metadata JSON.\n */\n get metadata()\n {\n return this.GetJson(\"META\");\n }\n\n /**\n * Gets the complete source permutation graph when present.\n *\n * @returns {object|null} Parsed permutation graph.\n */\n get permutationGraph()\n {\n return this.GetJson(\"PGRF\");\n }\n\n /**\n * Gets complete source effect reflection when present.\n *\n * @returns {object|null} Parsed reflection document.\n */\n get reflection()\n {\n return this.GetJson(\"RFLX\");\n }\n\n /**\n * Gets the raw reflection blob store when present.\n *\n * @returns {Uint8Array|null} RBLB bytes.\n */\n get reflectionBlobBytes()\n {\n return this.GetChunk(\"RBLB\")?.bytes ?? null;\n }\n\n /**\n * Copies one reflected byte payload by blob key or exact reference.\n *\n * @param {string|object} value Blob key or exact RFLX byte-reference object.\n * @returns {Uint8Array|null} Owned payload bytes, or null when unavailable.\n */\n GetReflectionBlob(value)\n {\n const key = typeof value === \"string\" ? value : value?.blobKey;\n if (!this.reflectionBlobIndex)\n {\n this.reflectionBlobIndex = new Map(\n (getCachedJson(this, \"RFLX\")?.blobStore?.blobs ?? []).map((entry) => [\n entry.blobKey,\n entry\n ])\n );\n }\n const entry = this.reflectionBlobIndex.get(key);\n const bytes = this.reflectionBlobBytes;\n if (!entry || !bytes) return null;\n if (typeof value !== \"string\"\n && (!value\n || value.offset !== entry.offset\n || value.byteLength !== entry.byteLength\n || value.sha256 !== entry.sha256))\n {\n return null;\n }\n const end = entry.offset + entry.byteLength;\n if (!Number.isSafeInteger(entry.offset) || entry.offset < 0\n || !Number.isSafeInteger(entry.byteLength) || entry.byteLength < 0\n || end > bytes.byteLength\n || sha256Bytes(bytes.subarray(entry.offset, end)) !== entry.sha256)\n {\n return null;\n }\n return Uint8Array.from(bytes.subarray(entry.offset, end));\n }\n\n /**\n * Gets fully hydrated portable source reflection for one permutation.\n *\n * Every reflected byte field is returned as a fresh owned `Uint8Array`.\n *\n * @param {number} [permutationIndex] Exact PGRF permutation index.\n * @returns {object|null} Validated portable reflection, or null when absent.\n */\n GetPortableEffectReflection(permutationIndex)\n {\n if (!validatedEffectReflectionPackages.has(this)) return null;\n const reflection = getCachedJson(this, \"RFLX\");\n const permutationGraph = getCachedJson(this, \"PGRF\");\n if (!reflection || !permutationGraph) return null;\n const selectedIndex = permutationIndex\n ?? getCachedJson(this, \"INFO\")?.defaultPermutationIndex\n ?? 0;\n return hydrateEffectReflectionForPermutation(\n reflection,\n permutationGraph,\n selectedIndex,\n (reference) => this.GetReflectionBlob(reference)\n );\n }\n\n /**\n * Gets translated GLSL source from the `GLSL` chunk.\n *\n * @returns {string|null} GLSL source.\n */\n get glsl()\n {\n return this.GetText(\"GLSL\");\n }\n\n /**\n * Gets translated GLSL metadata when the `GLSL` chunk contains JSON.\n *\n * Whole-effect packages store a JSON stage set in this chunk; single-stage\n * packages store raw GLSL text and return null here.\n *\n * @returns {object|null} Parsed GLSL stage set, or null for raw source.\n */\n get glslJson()\n {\n try\n {\n return this.GetJson(\"GLSL\");\n }\n catch\n {\n return null;\n }\n }\n\n /**\n * Gets original DXBC bytes when present.\n *\n * @returns {Uint8Array|null} DXBC bytes.\n */\n get dxbc()\n {\n return this.GetChunk(\"DXBC\")?.bytes || null;\n }\n\n /**\n * Returns a JSON-safe package summary.\n *\n * @returns {object} Serializable summary.\n */\n toJSON()\n {\n return {\n format: CEWG_FORMAT,\n version: this.version,\n sourcePath: this.sourcePath,\n chunks: this.chunks.map((chunk) => ({\n tag: chunk.tag,\n size: chunk.size,\n offset: chunk.offset\n })),\n readError: this.readError ? {\n name: this.readError.name,\n message: this.readError.message\n } : null\n };\n }\n}\n\n/**\n * Marks one package as having passed the canonical v3 reflection envelope.\n *\n * This is intentionally an internal deep import rather than package-root API.\n *\n * @param {CewgPackage} pkg Validated package reader.\n * @returns {void}\n */\nexport function markEffectReflectionValidated(pkg)\n{\n validatedEffectReflectionPackages.add(pkg);\n}\n\n/**\n * Decode and cache one private JSON document.\n *\n * @param {CewgPackage} pkg Package reader.\n * @param {string} tag Chunk tag.\n * @returns {object|null} Private parsed JSON, or null when absent.\n */\nfunction getCachedJson(pkg, tag)\n{\n if (!pkg.jsonCache.has(tag))\n {\n const chunk = pkg.GetChunk(tag);\n pkg.jsonCache.set(\n tag,\n chunk ? JSON.parse(jsonTextDecoder.decode(chunk.bytes)) : null\n );\n }\n return pkg.jsonCache.get(tag);\n}\n\n/**\n * Copy JSON-compatible data without reparsing its source chunk.\n *\n * @param {any} value Cached JSON value.\n * @returns {any} Structurally independent JSON value.\n */\nfunction cloneJson(value)\n{\n if (Array.isArray(value)) return value.map(cloneJson);\n if (value && typeof value === \"object\")\n {\n return Object.fromEntries(Object.entries(value).map(([ key, entry ]) => [\n key,\n cloneJson(entry)\n ]));\n }\n return value;\n}\n\nfunction validateChunkTag(tag)\n{\n if (typeof tag !== \"string\"\n || tag.length !== 4\n || [ ...tag ].some((character) =>\n {\n const code = character.charCodeAt(0);\n return code < 0x21 || code > 0x7e;\n }))\n {\n throw new Error(`Invalid CEWG chunk tag ${JSON.stringify(tag)}`);\n }\n}\n\n/**\n * Decodes an ASCII four-character code.\n *\n * @param {Uint8Array} bytes Four-byte tag payload.\n * @returns {string} ASCII string.\n */\nfunction decodeAscii(bytes)\n{\n return String.fromCharCode(...bytes);\n}\n"],"names":["CEWG_MAGIC","CEWG_FORMAT","CEWG_VERSION","textDecoder","TextDecoder","fatal","jsonTextDecoder","validatedEffectReflectionPackages","WeakSet","CewgPackage","constructor","version","chunks","chunkMap","Map","jsonCache","reflectionBlobIndex","readError","sourcePath","Read","source","options","delete","bytes","asUint8Array","stream","WebglReader","magic","decodeAscii","readRaw","length","Error","readUint32","chunkCount","index","tag","validateChunkTag","has","size","offset","chunkBytes","chunk","push","set","remaining","error","IsGood","GetChunk","get","GetText","decode","GetJson","cloneJson","getCachedJson","info","metadata","permutationGraph","reflection","reflectionBlobBytes","GetReflectionBlob","value","key","blobKey","blobStore","blobs","map","entry","byteLength","sha256","end","Number","isSafeInteger","sha256Bytes","subarray","Uint8Array","from","GetPortableEffectReflection","permutationIndex","selectedIndex","defaultPermutationIndex","hydrateEffectReflectionForPermutation","reference","glsl","glslJson","dxbc","toJSON","format","name","message","markEffectReflectionValidated","pkg","add","JSON","parse","Array","isArray","Object","fromEntries","entries","some","character","code","charCodeAt","stringify","String","fromCharCode"],"mappings":";;;;;AAMA,MAAMA,UAAU,GAAG,MAAM;AACzB,MAAMC,WAAW,GAAG,MAAM;AAC1B,MAAMC,YAAY,GAAG,CAAC;AACtB,MAAMC,WAAW,GAAG,IAAIC,WAAW,CAAC,OAAO,EAAE;AAAEC,EAAAA,KAAK,EAAE;AAAM,CAAC,CAAC;AAC9D,MAAMC,eAAe,GAAG,IAAIF,WAAW,CAAC,OAAO,EAAE;AAAEC,EAAAA,KAAK,EAAE;AAAK,CAAC,CAAC;AACjE,MAAME,iCAAiC,GAAG,IAAIC,OAAO,EAAE;;AAEvD;AACA;AACA;AACO,MAAMC,WAAW,CACxB;AACI;AACJ;AACA;AACIC,EAAAA,WAAWA,GACX;IACI,IAAI,CAACC,OAAO,GAAG,CAAC;IAChB,IAAI,CAACC,MAAM,GAAG,EAAE;AAChB,IAAA,IAAI,CAACC,QAAQ,GAAG,IAAIC,GAAG,EAAE;AACzB,IAAA,IAAI,CAACC,SAAS,GAAG,IAAID,GAAG,EAAE;IAC1B,IAAI,CAACE,mBAAmB,GAAG,IAAI;IAC/B,IAAI,CAACC,SAAS,GAAG,IAAI;IACrB,IAAI,CAACC,UAAU,GAAG,EAAE;AACxB,EAAA;;AAEA;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACIC,EAAAA,IAAIA,CAACC,MAAM,EAAEC,OAAO,GAAG,EAAE,EACzB;AACId,IAAAA,iCAAiC,CAACe,MAAM,CAAC,IAAI,CAAC;IAC9C,IAAI,C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} from '../../../../format/CjsByteReader.js';
|
|
1
2
|
import { WebglReadError } from '../errors.js';
|
|
3
|
+
export { asUint8Array } from '@carbonenginejs/runtime-utils/bytes';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
|
-
*
|
|
6
|
+
* Little-endian binary reader for the CEWG package container.
|
|
5
7
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
+
* The implementation is `CjsByteReader` in `src/format/`; this subclass only
|
|
9
|
+
* supplies the error class and message this format reports. The CEWG container
|
|
10
|
+
* has no string table, so only the raw-byte and `uint32` reads are exercised —
|
|
11
|
+
* but they are now the shared ones rather than a third copy.
|
|
8
12
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
if (value instanceof ArrayBuffer) {
|
|
14
|
-
return new Uint8Array(value);
|
|
15
|
-
}
|
|
16
|
-
if (ArrayBuffer.isView(value)) {
|
|
17
|
-
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
18
|
-
}
|
|
19
|
-
throw new TypeError("Expected an ArrayBuffer or Uint8Array");
|
|
13
|
+
class WebglReader extends CjsByteReader {
|
|
14
|
+
static ReadError = WebglReadError;
|
|
15
|
+
static endOfDataMessage = "Unexpected end of CEWG package data";
|
|
20
16
|
}
|
|
21
17
|
|
|
22
|
-
|
|
23
|
-
* Minimal little-endian binary reader for the flat CEWG chunk container.
|
|
24
|
-
*
|
|
25
|
-
* Trimmed from Carbon's compiled-effect `WebglReader` (see the sibling
|
|
26
|
-
* `formats/dxbc` and `formats/hlsl` vendored copies): the CEWG format has no
|
|
27
|
-
* string table, so only raw-byte and uint32
|
|
28
|
-
* reads plus offset/remaining tracking are implemented here.
|
|
29
|
-
*/
|
|
30
|
-
class WebglReader {
|
|
31
|
-
/**
|
|
32
|
-
* Creates a reader over a byte payload.
|
|
33
|
-
*
|
|
34
|
-
* @param {ArrayBuffer|ArrayBufferView|Uint8Array} bytes Source payload.
|
|
35
|
-
* @param {object} [options] Reader bounds and metadata.
|
|
36
|
-
* @param {number} [options.offset] Initial byte offset.
|
|
37
|
-
* @param {number} [options.end] Exclusive end offset.
|
|
38
|
-
* @param {string} [options.source] Source name used in error details.
|
|
39
|
-
*/
|
|
40
|
-
constructor(bytes, options = {}) {
|
|
41
|
-
this.bytes = asUint8Array(bytes);
|
|
42
|
-
this.view = new DataView(this.bytes.buffer, this.bytes.byteOffset, this.bytes.byteLength);
|
|
43
|
-
this.offset = Number(options.offset) || 0;
|
|
44
|
-
this.end = Number.isInteger(options.end) ? options.end : this.bytes.length;
|
|
45
|
-
this.source = options.source || "memory";
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Returns the unread byte count inside the configured reader bounds.
|
|
50
|
-
*
|
|
51
|
-
* @returns {number} Remaining bytes.
|
|
52
|
-
*/
|
|
53
|
-
get remaining() {
|
|
54
|
-
return this.end - this.offset;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Reads a byte range from the payload.
|
|
59
|
-
*
|
|
60
|
-
* @param {number} size Byte count to read.
|
|
61
|
-
* @returns {Uint8Array} View over the read bytes.
|
|
62
|
-
*/
|
|
63
|
-
readRaw(size) {
|
|
64
|
-
this._require(size);
|
|
65
|
-
const start = this.offset;
|
|
66
|
-
this.offset += size;
|
|
67
|
-
return this.bytes.subarray(start, start + size);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Reads a little-endian unsigned 32-bit integer.
|
|
72
|
-
*
|
|
73
|
-
* @returns {number} Integer value.
|
|
74
|
-
*/
|
|
75
|
-
readUint32() {
|
|
76
|
-
this._require(4);
|
|
77
|
-
const value = this.view.getUint32(this.offset, true);
|
|
78
|
-
this.offset += 4;
|
|
79
|
-
return value;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Ensures the requested read fits inside the configured payload bounds.
|
|
84
|
-
*
|
|
85
|
-
* @param {number} size Requested byte count.
|
|
86
|
-
* @private
|
|
87
|
-
*/
|
|
88
|
-
_require(size) {
|
|
89
|
-
if (!Number.isInteger(size) || size < 0 || this.offset + size > this.end) {
|
|
90
|
-
throw new WebglReadError("Unexpected end of CEWG package data", {
|
|
91
|
-
source: this.source,
|
|
92
|
-
offset: this.offset,
|
|
93
|
-
requested: size,
|
|
94
|
-
end: this.end
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export { WebglReader, asUint8Array };
|
|
18
|
+
export { WebglReader };
|
|
101
19
|
//# sourceMappingURL=binary.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binary.js","sources":["../../../../../../src/formats/webgl/core/cewg/binary.js"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"binary.js","sources":["../../../../../../src/formats/webgl/core/cewg/binary.js"],"sourcesContent":["import { CjsByteReader } from \"../../../../format/CjsByteReader.js\";\nimport { WebglReadError } from \"../errors.js\";\n\nexport { asUint8Array } from \"@carbonenginejs/runtime-utils/bytes\";\n\n/**\n * Little-endian binary reader for the CEWG package container.\n *\n * The implementation is `CjsByteReader` in `src/format/`; this subclass only\n * supplies the error class and message this format reports. The CEWG container\n * has no string table, so only the raw-byte and `uint32` reads are exercised —\n * but they are now the shared ones rather than a third copy.\n */\nexport class WebglReader extends CjsByteReader\n{\n static ReadError = WebglReadError;\n\n static endOfDataMessage = \"Unexpected end of CEWG package data\";\n}\n\nexport default WebglReader;\n"],"names":["WebglReader","CjsByteReader","ReadError","WebglReadError","endOfDataMessage"],"mappings":";;;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,WAAW,SAASC,aAAa,CAC9C;EACI,OAAOC,SAAS,GAAGC,cAAc;EAEjC,OAAOC,gBAAgB,GAAG,qCAAqC;AACnE;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EFFECT_INFO_VERSION } from './effectPackageValidation.js';
|
|
2
2
|
import { CjsHlslFormat } from '../../hlsl/CjsHlslFormat.js';
|
|
3
3
|
import { HlslRenderContextEnum, hlslShaderStageName } from '../../hlsl/core/tr2/HlslRenderContextEnum.js';
|
|
4
|
-
import '
|
|
4
|
+
import '../../../format/CjsByteReader.js';
|
|
5
5
|
import '@carbonenginejs/runtime-utils/bytes';
|
|
6
6
|
import '../../hlsl/core/tr2/shader/HlslEffectResource.js';
|
|
7
7
|
import { HlslEffectBindingManifest } from '../../hlsl/core/tr2/shader/HlslEffectBindingManifest.js';
|