@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,781 @@
|
|
|
1
|
+
import { CjsFormatReadError } from '../../../format/CjsFormatError.js';
|
|
2
|
+
import { HlslEffectConstant } from './tr2/shader/HlslEffectConstant.js';
|
|
3
|
+
import { HlslEffectParameterAnnotation } from './tr2/shader/HlslEffectParameterAnnotation.js';
|
|
4
|
+
import { HlslEffectResource } from './tr2/shader/HlslEffectResource.js';
|
|
5
|
+
import { HlslEffectStageInput } from './tr2/shader/HlslEffectStageInput.js';
|
|
6
|
+
import { HlslEffectStateManager } from './HlslEffectStateManager.js';
|
|
7
|
+
import { HlslEffectTechnique } from './tr2/shader/HlslEffectTechnique.js';
|
|
8
|
+
import { HlslPass } from './tr2/shader/HlslPass.js';
|
|
9
|
+
import { HlslRenderContextEnum, HlslUsageCodeNames } from './tr2/HlslRenderContextEnum.js';
|
|
10
|
+
import { HlslRenderStateSetup } from './HlslRenderStateSetup.js';
|
|
11
|
+
import { HlslResourceSetDescription } from './HlslResourceSetDescription.js';
|
|
12
|
+
import { HlslSamplerDescription } from './tr2/shader/HlslSamplerDescription.js';
|
|
13
|
+
import { HlslSamplerSetup } from './tr2/shader/HlslSamplerSetup.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Rebuilds the runtime effect-description shape from a Carbon record tree.
|
|
17
|
+
*
|
|
18
|
+
* This is a **shape adapter and nothing else**. It adds no semantics: its whole
|
|
19
|
+
* job is to turn the parsed container records into the object graph
|
|
20
|
+
* `HlslEffectBindingManifest.fromEffectDescription` already consumes, so that
|
|
21
|
+
* `buildEffectAnalysis` runs unchanged on a container-derived description. The
|
|
22
|
+
* derived view stays the same function it has always been rather than a
|
|
23
|
+
* reimplementation free to drift from it.
|
|
24
|
+
*
|
|
25
|
+
* ## Why this is not a field copy
|
|
26
|
+
*
|
|
27
|
+
* The wire shape and the runtime shape are genuinely different shapes, and every
|
|
28
|
+
* difference is a place a copying adapter produces something that reads as
|
|
29
|
+
* plausible and is wrong:
|
|
30
|
+
*
|
|
31
|
+
* | wire | runtime | conversion |
|
|
32
|
+
* |---|---|---|
|
|
33
|
+
* | `name: {offset, value}` | `name: "NormalMap"` | unwrap the arena string reference |
|
|
34
|
+
* | `count` | `arrayElements` | **renamed** — see `mapTextureRecord` |
|
|
35
|
+
* | `isSRGB: 0` | `isSRGB: false` | integer to boolean |
|
|
36
|
+
* | flat sampler fields | `{name, sampler: {...}}` | **re-nested** — see `mapSamplerRecord` |
|
|
37
|
+
* | UAV has no `isSRGB` | `isSRGB: false` | **synthesised** — see `mapUavRecord` |
|
|
38
|
+
* | `registerIndex` field | map key | consumed as the key, not a payload field |
|
|
39
|
+
*
|
|
40
|
+
* Three of those are silent when wrong. `arrayElements` is read at
|
|
41
|
+
* `packageHelpers.js:869` and a rename yields `undefined` there. `isSRGB` as `0`
|
|
42
|
+
* is *accidentally correct* — `0` is falsy, `1` is truthy — so it survives every
|
|
43
|
+
* behavioural test and only a structural diff sees it. A flat sampler puts all
|
|
44
|
+
* fourteen descriptor fields at the wrong depth at once.
|
|
45
|
+
*
|
|
46
|
+
* ## The tables are closed
|
|
47
|
+
*
|
|
48
|
+
* Every record is built through `mapClosed`, which walks the **source** keys and
|
|
49
|
+
* throws on any key with no rule. Nothing is spread and nothing is copied
|
|
50
|
+
* wholesale. That converts "did we enumerate every field?" — a question whose
|
|
51
|
+
* wrong answer shows up months later as `undefined` in the engine — into an error
|
|
52
|
+
* the first time the adapter meets a record it does not fully understand.
|
|
53
|
+
*
|
|
54
|
+
* This is deliberately redundant with the two-sided diff in
|
|
55
|
+
* `test/formats/webgpu/carbon-analysis-adapter.test.mjs`, and neither replaces the
|
|
56
|
+
* other. The table catches *the wire has something we do not handle*; the diff
|
|
57
|
+
* catches *our output differs from the reference*. A complete table can still map
|
|
58
|
+
* a field wrongly, and a passing diff on one fixture says nothing about a key that
|
|
59
|
+
* fixture never exercises.
|
|
60
|
+
*
|
|
61
|
+
* ## What is derived rather than stored
|
|
62
|
+
*
|
|
63
|
+
* `m_shader`, `pass.shaderProgram` and `pass.renderStates` are registration
|
|
64
|
+
* handles from `HlslEffectStateManager`, which are monotonic counters and
|
|
65
|
+
* therefore reproduce exactly when registration happens in the same order. That
|
|
66
|
+
* is why stages are walked in **wire array order** rather than by ascending
|
|
67
|
+
* stage type: the source reader registers them in the order the file lists them.
|
|
68
|
+
* `resourceSetDesc` and its `heapViews` are likewise rebuilt by running the same
|
|
69
|
+
* derivation the source reader runs, not carried on the wire.
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
/** Carbon annotation type for a string-valued annotation. */
|
|
73
|
+
const ANNOTATION_TYPE_STRING = HlslEffectParameterAnnotation.Type.STRING;
|
|
74
|
+
const rawView = new DataView(new ArrayBuffer(4));
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Unwraps an arena string reference to its text.
|
|
78
|
+
*
|
|
79
|
+
* @param {{offset:number, value:string}|null} reference Wire string reference.
|
|
80
|
+
* @returns {string} The referenced text.
|
|
81
|
+
*/
|
|
82
|
+
function text(reference) {
|
|
83
|
+
return typeof reference?.value === "string" ? reference.value : "";
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Converts a wire `u8` flag to the boolean the runtime shape carries.
|
|
88
|
+
*
|
|
89
|
+
* @param {number} value Wire flag.
|
|
90
|
+
* @returns {boolean} Boolean form.
|
|
91
|
+
*/
|
|
92
|
+
function flag(value) {
|
|
93
|
+
return Boolean(value);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Reads four wire bytes as the little-endian `u32` the runtime annotation holds.
|
|
98
|
+
*
|
|
99
|
+
* @param {Uint8Array|null} bytes Four raw bytes.
|
|
100
|
+
* @returns {number} Unsigned 32-bit value.
|
|
101
|
+
*/
|
|
102
|
+
function rawUint32(bytes) {
|
|
103
|
+
if (!bytes || bytes.length < 4) return 0;
|
|
104
|
+
rawView.setUint8(0, bytes[0]);
|
|
105
|
+
rawView.setUint8(1, bytes[1]);
|
|
106
|
+
rawView.setUint8(2, bytes[2]);
|
|
107
|
+
rawView.setUint8(3, bytes[3]);
|
|
108
|
+
return rawView.getUint32(0, true);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Reinterprets a `u32` bit pattern as the float it encodes.
|
|
113
|
+
*
|
|
114
|
+
* @param {number} bits Raw 32-bit pattern.
|
|
115
|
+
* @returns {number} The float those bits encode.
|
|
116
|
+
*/
|
|
117
|
+
function floatFromBits(bits) {
|
|
118
|
+
rawView.setUint32(0, bits >>> 0, true);
|
|
119
|
+
return rawView.getFloat32(0, true);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Builds an object from a record by walking the record's own keys against a
|
|
124
|
+
* closed rule table, throwing on any key the table does not name.
|
|
125
|
+
*
|
|
126
|
+
* Walking the **source** keys is the point. A table walked from its own entries
|
|
127
|
+
* would silently ignore a field the wire gained, which is exactly the failure
|
|
128
|
+
* this exists to make loud.
|
|
129
|
+
*
|
|
130
|
+
* @param {object} record Source wire record.
|
|
131
|
+
* @param {object} rules Rule table keyed by source field name.
|
|
132
|
+
* @param {object} target Object to populate.
|
|
133
|
+
* @param {string} what Record kind, for the error message.
|
|
134
|
+
* @returns {object} The populated target.
|
|
135
|
+
*/
|
|
136
|
+
function mapClosed(record, rules, target, what) {
|
|
137
|
+
for (const key of Object.keys(record)) {
|
|
138
|
+
const rule = rules[key];
|
|
139
|
+
if (!rule) {
|
|
140
|
+
throw new CjsFormatReadError(`Carbon ${what} record carries field "${key}" with no mapping rule`, {
|
|
141
|
+
record: what,
|
|
142
|
+
field: key
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
rule(target, record[key], record);
|
|
146
|
+
}
|
|
147
|
+
return target;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Consumes a field that is deliberately not part of the runtime payload. */
|
|
151
|
+
const consumed = () => {};
|
|
152
|
+
|
|
153
|
+
/** Texture record rules. `count` is Carbon's name for `arrayElements`. */
|
|
154
|
+
const TEXTURE_RULES = Object.freeze({
|
|
155
|
+
// Carried as the map key by the caller, not as a payload field.
|
|
156
|
+
registerIndex: consumed,
|
|
157
|
+
name: (target, value) => {
|
|
158
|
+
target.name = text(value);
|
|
159
|
+
},
|
|
160
|
+
type: (target, value) => {
|
|
161
|
+
target.type = value;
|
|
162
|
+
},
|
|
163
|
+
// RENAME: the wire calls this `count`; the runtime calls it `arrayElements`.
|
|
164
|
+
// Copying the field name yields `arrayElements: undefined`, read silently at
|
|
165
|
+
// `packageHelpers.js:869`.
|
|
166
|
+
count: (target, value) => {
|
|
167
|
+
target.arrayElements = value;
|
|
168
|
+
},
|
|
169
|
+
isSRGB: (target, value) => {
|
|
170
|
+
target.isSRGB = flag(value);
|
|
171
|
+
},
|
|
172
|
+
isAutoregister: (target, value) => {
|
|
173
|
+
target.isAutoregister = flag(value);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
/** UAV record rules. A UAV record has no `isSRGB`; it is synthesised. */
|
|
178
|
+
const UAV_RULES = Object.freeze({
|
|
179
|
+
registerIndex: consumed,
|
|
180
|
+
name: (target, value) => {
|
|
181
|
+
target.name = text(value);
|
|
182
|
+
},
|
|
183
|
+
type: (target, value) => {
|
|
184
|
+
target.type = value;
|
|
185
|
+
},
|
|
186
|
+
// RENAME: same as the texture record.
|
|
187
|
+
count: (target, value) => {
|
|
188
|
+
target.arrayElements = value;
|
|
189
|
+
},
|
|
190
|
+
isAutoregister: (target, value) => {
|
|
191
|
+
target.isAutoregister = flag(value);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
/** Sampler record rules. The wire record is flat; the runtime shape is nested. */
|
|
196
|
+
const SAMPLER_RULES = Object.freeze({
|
|
197
|
+
registerIndex: consumed,
|
|
198
|
+
// Handled after the walk: the name depends on `isDynamic`, which the walk
|
|
199
|
+
// may not have reached yet.
|
|
200
|
+
name: consumed,
|
|
201
|
+
isDynamic: (target, value) => {
|
|
202
|
+
target.sampler.isDynamic = flag(value);
|
|
203
|
+
},
|
|
204
|
+
comparison: (target, value) => {
|
|
205
|
+
target.sampler.comparison = flag(value);
|
|
206
|
+
},
|
|
207
|
+
minFilter: (target, value) => {
|
|
208
|
+
target.sampler.minFilter = value;
|
|
209
|
+
},
|
|
210
|
+
magFilter: (target, value) => {
|
|
211
|
+
target.sampler.magFilter = value;
|
|
212
|
+
},
|
|
213
|
+
mipFilter: (target, value) => {
|
|
214
|
+
target.sampler.mipFilter = value;
|
|
215
|
+
},
|
|
216
|
+
addressU: (target, value) => {
|
|
217
|
+
target.sampler.addressU = value;
|
|
218
|
+
},
|
|
219
|
+
addressV: (target, value) => {
|
|
220
|
+
target.sampler.addressV = value;
|
|
221
|
+
},
|
|
222
|
+
addressW: (target, value) => {
|
|
223
|
+
target.sampler.addressW = value;
|
|
224
|
+
},
|
|
225
|
+
mipLODBias: (target, value) => {
|
|
226
|
+
target.sampler.mipLODBias = value;
|
|
227
|
+
},
|
|
228
|
+
maxAnisotropy: (target, value) => {
|
|
229
|
+
target.sampler.maxAnisotropy = value;
|
|
230
|
+
},
|
|
231
|
+
comparisonFunc: (target, value) => {
|
|
232
|
+
target.sampler.comparisonFunc = value;
|
|
233
|
+
},
|
|
234
|
+
borderColor: (target, value) => {
|
|
235
|
+
target.sampler.borderColor = value.slice(0, 4);
|
|
236
|
+
},
|
|
237
|
+
minLOD: (target, value) => {
|
|
238
|
+
target.sampler.minLOD = value;
|
|
239
|
+
},
|
|
240
|
+
maxLOD: (target, value) => {
|
|
241
|
+
target.sampler.maxLOD = value;
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
/** Static sampler rules. `borderColor` is a one-byte enum here, not four floats. */
|
|
246
|
+
const STATIC_SAMPLER_RULES = Object.freeze({
|
|
247
|
+
registerIndex: (target, value) => {
|
|
248
|
+
target.registerIndex = value;
|
|
249
|
+
},
|
|
250
|
+
registerSpace: (target, value) => {
|
|
251
|
+
target.registerSpace = value;
|
|
252
|
+
},
|
|
253
|
+
comparison: (target, value) => {
|
|
254
|
+
target.sampler.comparison = flag(value);
|
|
255
|
+
},
|
|
256
|
+
minFilter: (target, value) => {
|
|
257
|
+
target.sampler.minFilter = value;
|
|
258
|
+
},
|
|
259
|
+
magFilter: (target, value) => {
|
|
260
|
+
target.sampler.magFilter = value;
|
|
261
|
+
},
|
|
262
|
+
mipFilter: (target, value) => {
|
|
263
|
+
target.sampler.mipFilter = value;
|
|
264
|
+
},
|
|
265
|
+
addressU: (target, value) => {
|
|
266
|
+
target.sampler.addressU = value;
|
|
267
|
+
},
|
|
268
|
+
addressV: (target, value) => {
|
|
269
|
+
target.sampler.addressV = value;
|
|
270
|
+
},
|
|
271
|
+
addressW: (target, value) => {
|
|
272
|
+
target.sampler.addressW = value;
|
|
273
|
+
},
|
|
274
|
+
mipLODBias: (target, value) => {
|
|
275
|
+
target.sampler.mipLODBias = value;
|
|
276
|
+
},
|
|
277
|
+
maxAnisotropy: (target, value) => {
|
|
278
|
+
target.sampler.maxAnisotropy = value;
|
|
279
|
+
},
|
|
280
|
+
comparisonFunc: (target, value) => {
|
|
281
|
+
target.sampler.comparisonFunc = value;
|
|
282
|
+
},
|
|
283
|
+
borderColor: (target, value) => {
|
|
284
|
+
target.sampler.borderColor = value;
|
|
285
|
+
},
|
|
286
|
+
minLOD: (target, value) => {
|
|
287
|
+
target.sampler.minLOD = value;
|
|
288
|
+
},
|
|
289
|
+
maxLOD: (target, value) => {
|
|
290
|
+
target.sampler.maxLOD = value;
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
/** Constant record rules. */
|
|
295
|
+
const CONSTANT_RULES = Object.freeze({
|
|
296
|
+
name: (target, value) => {
|
|
297
|
+
target.name = text(value);
|
|
298
|
+
},
|
|
299
|
+
offset: (target, value) => {
|
|
300
|
+
target.offset = value;
|
|
301
|
+
},
|
|
302
|
+
size: (target, value) => {
|
|
303
|
+
target.size = value;
|
|
304
|
+
},
|
|
305
|
+
type: (target, value) => {
|
|
306
|
+
target.type = value;
|
|
307
|
+
},
|
|
308
|
+
dimension: (target, value) => {
|
|
309
|
+
target.dimension = value;
|
|
310
|
+
},
|
|
311
|
+
elements: (target, value) => {
|
|
312
|
+
target.elements = value;
|
|
313
|
+
},
|
|
314
|
+
isSRGB: (target, value) => {
|
|
315
|
+
target.isSRGB = flag(value);
|
|
316
|
+
},
|
|
317
|
+
isAutoregister: (target, value) => {
|
|
318
|
+
target.isAutoregister = flag(value);
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
/** Register declaration rules. */
|
|
323
|
+
const REGISTER_RULES = Object.freeze({
|
|
324
|
+
registerType: (target, value) => {
|
|
325
|
+
target.registerType = value;
|
|
326
|
+
},
|
|
327
|
+
registerIndex: (target, value) => {
|
|
328
|
+
target.registerIndex = value;
|
|
329
|
+
},
|
|
330
|
+
// Carbon stores one field its reader calls `arrayCount` and its writer calls
|
|
331
|
+
// `registerCount`. The runtime shape carries both names, always equal — the
|
|
332
|
+
// producer refuses to write them when they disagree.
|
|
333
|
+
registerCount: (target, value) => {
|
|
334
|
+
target.registerCount = value;
|
|
335
|
+
target.arrayCount = value;
|
|
336
|
+
},
|
|
337
|
+
registerSpace: (target, value) => {
|
|
338
|
+
target.registerSpace = value;
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Pipeline input rules.
|
|
344
|
+
*
|
|
345
|
+
* `usageName` is derived from the `usage` byte rather than carried: it is a
|
|
346
|
+
* display name looked up from a table (`HlslEffectDescription.js:592`), exactly
|
|
347
|
+
* as Carbon derives it through `GetStringForUsageCode` (`EffectData.h:86`).
|
|
348
|
+
* Nothing goes on the wire for it.
|
|
349
|
+
*/
|
|
350
|
+
const PIPELINE_INPUT_RULES = Object.freeze({
|
|
351
|
+
usage: (target, value) => {
|
|
352
|
+
target.usage = value;
|
|
353
|
+
target.usageName = HlslUsageCodeNames[value] || `USAGE_${value}`;
|
|
354
|
+
},
|
|
355
|
+
registerIndex: (target, value) => {
|
|
356
|
+
target.registerIndex = value;
|
|
357
|
+
},
|
|
358
|
+
usageIndex: (target, value) => {
|
|
359
|
+
target.usageIndex = value;
|
|
360
|
+
},
|
|
361
|
+
usedMask: (target, value) => {
|
|
362
|
+
target.usedMask = value;
|
|
363
|
+
},
|
|
364
|
+
type: (target, value) => {
|
|
365
|
+
target.type = value;
|
|
366
|
+
},
|
|
367
|
+
dimension: (target, value) => {
|
|
368
|
+
target.dimension = value;
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
/** Annotation rules. */
|
|
373
|
+
const ANNOTATION_RULES = Object.freeze({
|
|
374
|
+
name: (target, value) => {
|
|
375
|
+
target.name = text(value);
|
|
376
|
+
},
|
|
377
|
+
type: (target, value) => {
|
|
378
|
+
target.type = value;
|
|
379
|
+
},
|
|
380
|
+
stringValue: (target, value) => {
|
|
381
|
+
if (value) target.stringValue = text(value);
|
|
382
|
+
},
|
|
383
|
+
// A non-string annotation value is four raw bytes: Carbon writes it through a
|
|
384
|
+
// float union and reads it through a different one, so the bytes are the only
|
|
385
|
+
// faithful form. The three typed views are derived from them exactly as the
|
|
386
|
+
// source reader derives them (`HlslEffectDescription.js:480-483`).
|
|
387
|
+
rawValue: (target, value, record) => {
|
|
388
|
+
if (record.type === ANNOTATION_TYPE_STRING) return;
|
|
389
|
+
const bits = rawUint32(value);
|
|
390
|
+
target.rawValue = bits;
|
|
391
|
+
target.boolValue = bits !== 0;
|
|
392
|
+
target.intValue = bits | 0;
|
|
393
|
+
target.floatValue = floatFromBits(bits);
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Maps one texture record onto its runtime resource object.
|
|
399
|
+
*
|
|
400
|
+
* @param {object} record Wire texture record.
|
|
401
|
+
* @returns {HlslEffectResource} Runtime resource.
|
|
402
|
+
*/
|
|
403
|
+
function mapTextureRecord(record) {
|
|
404
|
+
return mapClosed(record, TEXTURE_RULES, new HlslEffectResource(), "texture");
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Maps one UAV record onto its runtime resource object.
|
|
409
|
+
*
|
|
410
|
+
* A UAV record is one byte shorter than a texture record: it carries no
|
|
411
|
+
* `isSRGB`. Carbon's reader hardcodes it false (`Tr2EffectDescription.cpp:450`),
|
|
412
|
+
* and so does ours (`HlslEffectDescription.js:434`), so the runtime object's
|
|
413
|
+
* constructor default is restored explicitly rather than left to chance —
|
|
414
|
+
* `metadata.toJSON()` emits the key for a UAV even though the wire never carries
|
|
415
|
+
* it, because both kinds share `HlslEffectResource`.
|
|
416
|
+
*
|
|
417
|
+
* @param {object} record Wire UAV record.
|
|
418
|
+
* @returns {HlslEffectResource} Runtime resource.
|
|
419
|
+
*/
|
|
420
|
+
function mapUavRecord(record) {
|
|
421
|
+
const resource = mapClosed(record, UAV_RULES, new HlslEffectResource(), "uav");
|
|
422
|
+
resource.isSRGB = false;
|
|
423
|
+
return resource;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Maps one sampler record onto its runtime sampler setup.
|
|
428
|
+
*
|
|
429
|
+
* Two conversions beyond the flat-to-nested reshape:
|
|
430
|
+
*
|
|
431
|
+
* - Carbon nulls a sampler's name when it is not dynamic
|
|
432
|
+
* (`Tr2EffectDescription.cpp:430-433`, mirrored at
|
|
433
|
+
* `HlslEffectDescription.js:414-417`), so the wire's empty string must become
|
|
434
|
+
* `null` again. Like `isSRGB`, this is *accidentally correct* if left alone —
|
|
435
|
+
* `""` and `null` are both falsy, so `metadataName` and the heap-view lookup
|
|
436
|
+
* behave identically — and only a structural diff catches it.
|
|
437
|
+
* - `comparison` and `isDynamic` are `u8` on the wire and boolean at runtime.
|
|
438
|
+
*
|
|
439
|
+
* @param {object} record Wire sampler record.
|
|
440
|
+
* @returns {HlslSamplerSetup} Runtime sampler setup.
|
|
441
|
+
*/
|
|
442
|
+
function mapSamplerRecord(record) {
|
|
443
|
+
const setup = new HlslSamplerSetup();
|
|
444
|
+
setup.sampler = new HlslSamplerDescription();
|
|
445
|
+
mapClosed(record, SAMPLER_RULES, setup, "sampler");
|
|
446
|
+
setup.name = setup.sampler.isDynamic ? text(record.name) : null;
|
|
447
|
+
return setup;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Maps one static sampler record onto its runtime signature entry.
|
|
452
|
+
*
|
|
453
|
+
* The runtime shape keeps the `*Raw` companions non-enumerable, matching
|
|
454
|
+
* `readStaticSampler`, so a `cloneJson` of the descriptor sees the value form
|
|
455
|
+
* only.
|
|
456
|
+
*
|
|
457
|
+
* @param {object} record Wire static sampler record.
|
|
458
|
+
* @returns {object} Runtime static sampler entry.
|
|
459
|
+
*/
|
|
460
|
+
function mapStaticSamplerRecord(record) {
|
|
461
|
+
const entry = {
|
|
462
|
+
registerIndex: 0,
|
|
463
|
+
registerSpace: 0,
|
|
464
|
+
sampler: {
|
|
465
|
+
comparison: false,
|
|
466
|
+
minFilter: 0,
|
|
467
|
+
magFilter: 0,
|
|
468
|
+
mipFilter: 0,
|
|
469
|
+
addressU: 0,
|
|
470
|
+
addressV: 0,
|
|
471
|
+
addressW: 0,
|
|
472
|
+
mipLODBias: 0,
|
|
473
|
+
maxAnisotropy: 0,
|
|
474
|
+
comparisonFunc: 0,
|
|
475
|
+
borderColor: 0,
|
|
476
|
+
minLOD: 0,
|
|
477
|
+
maxLOD: 0
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
mapClosed(record, STATIC_SAMPLER_RULES, entry, "static sampler");
|
|
481
|
+
Object.defineProperties(entry.sampler, {
|
|
482
|
+
mipLODBiasRaw: {
|
|
483
|
+
value: 0,
|
|
484
|
+
writable: true
|
|
485
|
+
},
|
|
486
|
+
minLODRaw: {
|
|
487
|
+
value: 0,
|
|
488
|
+
writable: true
|
|
489
|
+
},
|
|
490
|
+
maxLODRaw: {
|
|
491
|
+
value: 0,
|
|
492
|
+
writable: true
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
return entry;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Maps one constant record onto its runtime constant object.
|
|
500
|
+
*
|
|
501
|
+
* @param {object} record Wire constant record.
|
|
502
|
+
* @returns {HlslEffectConstant} Runtime constant.
|
|
503
|
+
*/
|
|
504
|
+
function mapConstantRecord(record) {
|
|
505
|
+
return mapClosed(record, CONSTANT_RULES, new HlslEffectConstant(), "constant");
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Maps one annotation record onto its runtime annotation object.
|
|
510
|
+
*
|
|
511
|
+
* @param {object} record Wire annotation record.
|
|
512
|
+
* @returns {HlslEffectParameterAnnotation} Runtime annotation.
|
|
513
|
+
*/
|
|
514
|
+
function mapAnnotationRecord(record) {
|
|
515
|
+
return mapClosed(record, ANNOTATION_RULES, new HlslEffectParameterAnnotation(), "annotation");
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* Restores the `dynamic` flag the source reader derives per register.
|
|
520
|
+
*
|
|
521
|
+
* Reproduced rather than stored: it is a function of the register type, the
|
|
522
|
+
* stage type and the caller's per-frame start registers, none of which the
|
|
523
|
+
* container needs to carry (`HlslEffectDescription.js:750-765`).
|
|
524
|
+
*
|
|
525
|
+
* @param {object} register Runtime register declaration.
|
|
526
|
+
* @param {number} stageType Stage enum value.
|
|
527
|
+
* @param {object} context Adapter context carrying the per-frame registers.
|
|
528
|
+
* @returns {boolean} True when the register is dynamic.
|
|
529
|
+
*/
|
|
530
|
+
function isRegisterDynamic(register, stageType, context) {
|
|
531
|
+
if (register.registerType !== 0) return true;
|
|
532
|
+
if (stageType === HlslRenderContextEnum.VERTEX_SHADER && register.registerIndex === context.perFrameVSStartRegister) return false;
|
|
533
|
+
if (stageType === HlslRenderContextEnum.PIXEL_SHADER && register.registerIndex === context.perFramePSStartRegister) return false;
|
|
534
|
+
return true;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Populates one runtime stage input from a wire `StageData` block.
|
|
539
|
+
*
|
|
540
|
+
* @param {HlslEffectStageInput} input Destination stage input.
|
|
541
|
+
* @param {object} data Wire stage data.
|
|
542
|
+
* @param {number} stageType Stage enum value.
|
|
543
|
+
* @param {object} context Adapter context.
|
|
544
|
+
*/
|
|
545
|
+
function applyStageData(input, data, stageType, context) {
|
|
546
|
+
input.signature.registers = (data.registers ?? []).map(record => {
|
|
547
|
+
const register = mapClosed(record, REGISTER_RULES, {}, "register");
|
|
548
|
+
register.dynamic = isRegisterDynamic(register, stageType, context);
|
|
549
|
+
return register;
|
|
550
|
+
});
|
|
551
|
+
input.signature.samplers = (data.staticSamplers ?? []).map(mapStaticSamplerRecord);
|
|
552
|
+
input.constants = (data.constants ?? []).map(mapConstantRecord);
|
|
553
|
+
|
|
554
|
+
// The declared size is the unclamped one; the runtime clamps it to
|
|
555
|
+
// SHADER_CONSTANTS_MAX and slices the payload to match
|
|
556
|
+
// (`HlslEffectDescription.js:381-385`). `packMaterial` allocates an
|
|
557
|
+
// ArrayBuffer of exactly this size, so restoring the unclamped value would
|
|
558
|
+
// write past the layout the shader expects — on any effect above 4096 bytes
|
|
559
|
+
// of constants, which is precisely the size a small fixture never reaches.
|
|
560
|
+
const declaredSize = data.defaultValues?.size ?? 0;
|
|
561
|
+
input.sourceConstantValues = Uint8Array.from(data.defaultValues?.bytes ?? new Uint8Array(0));
|
|
562
|
+
input.m_constantValueSize = Math.min(declaredSize, HlslEffectStageInput.SHADER_CONSTANTS_MAX);
|
|
563
|
+
input.constantValues = input.sourceConstantValues.slice(0, input.m_constantValueSize);
|
|
564
|
+
input.resources = new Map((data.textures ?? []).map(record => [record.registerIndex, mapTextureRecord(record)]));
|
|
565
|
+
input.samplers = new Map((data.samplers ?? []).map(record => [record.registerIndex, mapSamplerRecord(record)]));
|
|
566
|
+
input.uavs = new Map((data.uavs ?? []).map(record => [record.registerIndex, mapUavRecord(record)]));
|
|
567
|
+
input.annotation = (data.annotations ?? []).map(mapAnnotationRecord);
|
|
568
|
+
|
|
569
|
+
// Runs last, because it needs the sampler map. See the function's own note
|
|
570
|
+
// for why it exists.
|
|
571
|
+
for (const constant of input.constants) patchSamplerHeapIndexConstant(input, constant);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* Grows the constant block to cover a sampler heap-index constant.
|
|
576
|
+
*
|
|
577
|
+
* Reproduces `HlslEffectDescription.js:773-791`, which the source reader applies
|
|
578
|
+
* to every constant once samplers are known: a `UINT`/dimension-1 constant whose
|
|
579
|
+
* name matches a sampler is a heap index, and the declared constant-value size
|
|
580
|
+
* can be smaller than the offset it sits at. The reader extends the block rather
|
|
581
|
+
* than reading out of bounds.
|
|
582
|
+
*
|
|
583
|
+
* **This is derived, not stored, and missing it is not cosmetic.** `packMaterial`
|
|
584
|
+
* allocates `new ArrayBuffer(constantValueSize)`, so an unpatched size
|
|
585
|
+
* under-allocates and the write runs past the end of the buffer the shader
|
|
586
|
+
* expects. It appears only on dx12 -- the whole dx11 corpus is unaffected --
|
|
587
|
+
* which is exactly why the analysis diff had to cover dx12 before this was
|
|
588
|
+
* trustworthy. On `quaddetailv5.sm_depth` the declared 608 becomes 620.
|
|
589
|
+
*
|
|
590
|
+
* @param {object} input Runtime stage input, with samplers already populated.
|
|
591
|
+
* @param {object} constant Runtime constant record.
|
|
592
|
+
*/
|
|
593
|
+
function patchSamplerHeapIndexConstant(input, constant) {
|
|
594
|
+
if (constant.type !== HlslEffectConstant.Type.UINT || constant.dimension !== 1) return;
|
|
595
|
+
for (const sampler of input.samplers.values()) {
|
|
596
|
+
if (sampler.name !== constant.name) continue;
|
|
597
|
+
const neededSize = constant.offset + constant.size;
|
|
598
|
+
if (neededSize > input.m_constantValueSize) {
|
|
599
|
+
const next = new Uint8Array(neededSize);
|
|
600
|
+
next.set(input.constantValues);
|
|
601
|
+
input.constantValues = next;
|
|
602
|
+
input.m_constantValueSize = neededSize;
|
|
603
|
+
}
|
|
604
|
+
break;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Rebuilds one runtime pass from a wire pass record.
|
|
610
|
+
*
|
|
611
|
+
* @param {object} record Wire pass record.
|
|
612
|
+
* @param {object} context Adapter context.
|
|
613
|
+
* @returns {HlslPass} Runtime pass.
|
|
614
|
+
*/
|
|
615
|
+
function buildPass(record, context) {
|
|
616
|
+
const pass = new HlslPass();
|
|
617
|
+
const shaderTypes = [];
|
|
618
|
+
const signatures = [];
|
|
619
|
+
const shaderHandles = [];
|
|
620
|
+
|
|
621
|
+
// Wire array order, not ascending stage type. The source reader registers
|
|
622
|
+
// shaders in the order the file lists its stages, and the state manager's
|
|
623
|
+
// handles are monotonic counters, so any other order reproduces the shape
|
|
624
|
+
// with the handles permuted.
|
|
625
|
+
for (const stage of record.stages ?? []) {
|
|
626
|
+
const stageType = stage.type;
|
|
627
|
+
const input = pass.stageInputs[stageType];
|
|
628
|
+
if (!input) {
|
|
629
|
+
throw new CjsFormatReadError(`Carbon stage record declares stage type ${stageType}, outside the runtime stage range`, {
|
|
630
|
+
stageType
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
if (input.m_exists) {
|
|
634
|
+
throw new CjsFormatReadError(`Carbon pass declares stage type ${stageType} twice; the later stage would clobber the earlier`, {
|
|
635
|
+
stageType
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
input.m_exists = true;
|
|
639
|
+
input.signature.threadGroupSize = {
|
|
640
|
+
x: stage.threadGroupSize[0],
|
|
641
|
+
y: stage.threadGroupSize[1],
|
|
642
|
+
z: stage.threadGroupSize[2]
|
|
643
|
+
};
|
|
644
|
+
input.signature.pipelineInputs = (stage.pipelineInputs ?? []).map(entry => mapClosed(entry, PIPELINE_INPUT_RULES, {}, "pipeline input"));
|
|
645
|
+
applyStageData(input, stage, stageType, context);
|
|
646
|
+
input.cjsShaderBytecode = context.bytecodeFor ? context.bytecodeFor(stage, stageType, pass) : null;
|
|
647
|
+
input.m_shader = context.effectStateManager.RegisterShader(stageType, input.cjsShaderBytecode, input.signature, context.effectName);
|
|
648
|
+
shaderHandles.push(input.m_shader);
|
|
649
|
+
shaderTypes.push(stageType);
|
|
650
|
+
signatures.push(input.signature);
|
|
651
|
+
pass.shaderTypeMask |= 1 << stageType;
|
|
652
|
+
}
|
|
653
|
+
pass.resourceSetDesc = new HlslResourceSetDescription(shaderTypes, signatures);
|
|
654
|
+
for (let stageType = 0; stageType < HlslRenderContextEnum.SHADER_TYPE_COUNT; stageType += 1) {
|
|
655
|
+
const input = pass.stageInputs[stageType];
|
|
656
|
+
if (!input?.m_exists) continue;
|
|
657
|
+
for (const [registerIndex, sampler] of input.samplers.entries()) {
|
|
658
|
+
pass.resourceSetDesc.SetSampler(stageType, registerIndex, sampler.sampler);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
pass.shaderProgram = context.effectStateManager.RegisterShaderProgram(shaderHandles, shaderHandles.length);
|
|
662
|
+
const states = new Map();
|
|
663
|
+
for (const entry of record.renderStates ?? []) {
|
|
664
|
+
if (states.has(entry.state)) {
|
|
665
|
+
throw new CjsFormatReadError(`Carbon pass declares render state ${entry.state} twice`, {
|
|
666
|
+
state: entry.state
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
states.set(entry.state, entry.value);
|
|
670
|
+
}
|
|
671
|
+
pass.cjsRenderStateSetup = new HlslRenderStateSetup(states);
|
|
672
|
+
pass.renderStates = context.effectStateManager.RegisterRenderStateSetup(pass.cjsRenderStateSetup);
|
|
673
|
+
return pass;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* Applies the `IsHeapView` annotations to the rebuilt resource-set descriptions.
|
|
678
|
+
*
|
|
679
|
+
* Derived exactly as the source reader derives it
|
|
680
|
+
* (`HlslEffectDescription.js:799-851`), over the annotations the container
|
|
681
|
+
* carries.
|
|
682
|
+
*
|
|
683
|
+
* @param {object} effectDescription Rebuilt effect description.
|
|
684
|
+
*/
|
|
685
|
+
function applyHeapViewAnnotations(effectDescription) {
|
|
686
|
+
const isHeapView = name => {
|
|
687
|
+
if (!name) return false;
|
|
688
|
+
const annotations = effectDescription.annotations.get(name) || [];
|
|
689
|
+
return annotations.some(annotation => annotation.name === "IsHeapView" && annotation.type === HlslEffectParameterAnnotation.Type.BOOL && annotation.boolValue);
|
|
690
|
+
};
|
|
691
|
+
for (const technique of effectDescription.techniques) {
|
|
692
|
+
for (const pass of technique.passes) {
|
|
693
|
+
for (let stageType = 0; stageType < pass.stageInputs.length; stageType += 1) {
|
|
694
|
+
const stage = pass.stageInputs[stageType];
|
|
695
|
+
if (!stage?.m_exists) continue;
|
|
696
|
+
for (const [registerIndex, resource] of stage.resources.entries()) {
|
|
697
|
+
if (isHeapView(resource.name)) pass.resourceSetDesc?.SetSrvHeapView(stageType, registerIndex);
|
|
698
|
+
}
|
|
699
|
+
for (const [registerIndex, resource] of stage.uavs.entries()) {
|
|
700
|
+
if (isHeapView(resource.name)) pass.resourceSetDesc?.SetUavHeapView(stageType, registerIndex);
|
|
701
|
+
}
|
|
702
|
+
for (const [registerIndex, sampler] of stage.samplers.entries()) {
|
|
703
|
+
if (isHeapView(sampler.name)) pass.resourceSetDesc?.SetSamplerHeapView(stageType, registerIndex);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
/**
|
|
711
|
+
* Rebuilds the runtime effect-description shape from a Carbon record tree.
|
|
712
|
+
*
|
|
713
|
+
* @param {object} description Parsed Carbon description record tree.
|
|
714
|
+
* @param {object} [options] Adapter options.
|
|
715
|
+
* @param {string} [options.effectName] Effect name or source path.
|
|
716
|
+
* @param {number} [options.version] Carbon effect-data version.
|
|
717
|
+
* @param {number} [options.perFrameVSStartRegister] Per-frame vertex start register.
|
|
718
|
+
* @param {number} [options.perFramePSStartRegister] Per-frame pixel start register.
|
|
719
|
+
* @param {Function} [options.bytecodeFor] Supplies `cjsShaderBytecode` per stage.
|
|
720
|
+
* @param {HlslEffectStateManager} [options.effectStateManager] Registry override.
|
|
721
|
+
* @returns {object} Runtime-shaped effect description.
|
|
722
|
+
*/
|
|
723
|
+
function runtimeDescriptionFromCarbon(description, options = {}) {
|
|
724
|
+
if (!description?.techniques) {
|
|
725
|
+
throw new CjsFormatReadError("Carbon description has no techniques", {});
|
|
726
|
+
}
|
|
727
|
+
const context = {
|
|
728
|
+
effectName: options.effectName ?? "",
|
|
729
|
+
effectStateManager: options.effectStateManager ?? new HlslEffectStateManager(),
|
|
730
|
+
bytecodeFor: options.bytecodeFor ?? null,
|
|
731
|
+
perFrameVSStartRegister: Number.isInteger(options.perFrameVSStartRegister) ? options.perFrameVSStartRegister : null,
|
|
732
|
+
perFramePSStartRegister: Number.isInteger(options.perFramePSStartRegister) ? options.perFramePSStartRegister : null
|
|
733
|
+
};
|
|
734
|
+
const effectDescription = {
|
|
735
|
+
effectName: context.effectName,
|
|
736
|
+
version: options.version ?? 15,
|
|
737
|
+
techniques: [],
|
|
738
|
+
annotations: new Map(),
|
|
739
|
+
effectStateManager: context.effectStateManager
|
|
740
|
+
};
|
|
741
|
+
for (const record of description.techniques) {
|
|
742
|
+
const technique = new HlslEffectTechnique();
|
|
743
|
+
technique.name = text(record.name);
|
|
744
|
+
// Raytracing libraries are carried on the wire and are deliberately NOT
|
|
745
|
+
// rebuilt here. `libraries` stays empty.
|
|
746
|
+
//
|
|
747
|
+
// This began as a throw, on the reasoning that a silent drop hides a
|
|
748
|
+
// whole missing section and that no shipped effect declared one. The
|
|
749
|
+
// first half still stands; the second half was wrong, and the way it was
|
|
750
|
+
// wrong is the useful part. The dx11 corpus has no libraries at all —
|
|
751
|
+
// 1611 files, zero — so the refusal never fired. **Every dx12 body of
|
|
752
|
+
// `unpacked_quadv5.sm_hi` carries one**: technique `RtShadow`, a
|
|
753
|
+
// `ClosestHit` export, DXR raytracing shadows that dx11 has no analogue
|
|
754
|
+
// for. All 288 distinct bodies. So the refusal blocked every dx12
|
|
755
|
+
// package for a section nothing downstream reads.
|
|
756
|
+
//
|
|
757
|
+
// Dropping them is safe for a *specific, checked* reason rather than a
|
|
758
|
+
// hopeful one: `buildEffectAnalysis` reaches libraries through no path.
|
|
759
|
+
// `buildPasses` walks `technique.passes`; `buildStages` walks
|
|
760
|
+
// `pass.stageInputs`; neither touches `technique.libraries`. The source
|
|
761
|
+
// reader's heap-view pass does visit libraries, but only to populate
|
|
762
|
+
// `library.globalResourceSetDesc`, which the manifest never reads.
|
|
763
|
+
//
|
|
764
|
+
// That claim is measured, not argued: the corpus analysis diff compares
|
|
765
|
+
// source-derived against container-derived analysis over dx12 as well as
|
|
766
|
+
// dx11, so every one of those library-bearing bodies is proof that the
|
|
767
|
+
// drop is invisible to this view. If the analysis ever grows a library
|
|
768
|
+
// section, that test goes red rather than this comment going stale.
|
|
769
|
+
technique.passes = (record.passes ?? []).map(pass => buildPass(pass, context));
|
|
770
|
+
for (const pass of technique.passes) technique.shaderTypeMask |= pass.shaderTypeMask;
|
|
771
|
+
effectDescription.techniques.push(technique);
|
|
772
|
+
}
|
|
773
|
+
for (const group of description.annotations ?? []) {
|
|
774
|
+
effectDescription.annotations.set(text(group.name), (group.annotations ?? []).map(mapAnnotationRecord));
|
|
775
|
+
}
|
|
776
|
+
applyHeapViewAnnotations(effectDescription);
|
|
777
|
+
return effectDescription;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
export { runtimeDescriptionFromCarbon };
|
|
781
|
+
//# sourceMappingURL=carbonDescriptionToRuntime.js.map
|