@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.
Files changed (170) hide show
  1. package/dist/CjsResMan.js +4 -4
  2. package/dist/CjsResMan.js.map +1 -1
  3. package/dist/_virtual/_rollupPluginBabelHelpers.js +1 -4
  4. package/dist/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
  5. package/dist/format/CjsByteReader.js +310 -0
  6. package/dist/format/CjsByteReader.js.map +1 -0
  7. package/dist/format/CjsByteWriter.js +242 -0
  8. package/dist/format/CjsByteWriter.js.map +1 -0
  9. package/dist/format/CjsFormatError.js +41 -0
  10. package/dist/format/CjsFormatError.js.map +1 -0
  11. package/dist/format/CjsStringTable.js +268 -0
  12. package/dist/format/CjsStringTable.js.map +1 -0
  13. package/dist/format/carbonEffect/CjsCarbonEffectReader.js +361 -0
  14. package/dist/format/carbonEffect/CjsCarbonEffectReader.js.map +1 -0
  15. package/dist/format/carbonEffect/CjsCarbonEffectWriter.js +373 -0
  16. package/dist/format/carbonEffect/CjsCarbonEffectWriter.js.map +1 -0
  17. package/dist/format/carbonEffect/carbonDescriptionFromPortable.js +372 -0
  18. package/dist/format/carbonEffect/carbonDescriptionFromPortable.js.map +1 -0
  19. package/dist/format/carbonEffect/carbonEffectBackendBlock.js +427 -0
  20. package/dist/format/carbonEffect/carbonEffectBackendBlock.js.map +1 -0
  21. package/dist/format/carbonEffect/carbonEffectRecords.js +955 -0
  22. package/dist/format/carbonEffect/carbonEffectRecords.js.map +1 -0
  23. package/dist/format/compareUtf8.js +36 -0
  24. package/dist/format/compareUtf8.js.map +1 -0
  25. package/dist/format/index.js +11 -0
  26. package/dist/format/index.js.map +1 -0
  27. package/dist/formats/bnk/CjsBnkFormat.js +10 -4
  28. package/dist/formats/bnk/CjsBnkFormat.js.map +1 -1
  29. package/dist/formats/bnk/core/eventAction.js +305 -0
  30. package/dist/formats/bnk/core/eventAction.js.map +1 -0
  31. package/dist/formats/bnk/core/helpers.js +11 -2
  32. package/dist/formats/bnk/core/helpers.js.map +1 -1
  33. package/dist/formats/bnk/core/nodeBase.js +532 -0
  34. package/dist/formats/bnk/core/nodeBase.js.map +1 -0
  35. package/dist/formats/bnk/core/sfxNodes.js +252 -152
  36. package/dist/formats/bnk/core/sfxNodes.js.map +1 -1
  37. package/dist/formats/hlsl/core/HlslReader.js +7 -257
  38. package/dist/formats/hlsl/core/HlslReader.js.map +1 -1
  39. package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js +781 -0
  40. package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js.map +1 -0
  41. package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js +21 -1
  42. package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js.map +1 -1
  43. package/dist/formats/index.js +1 -1
  44. package/dist/formats/webgl/core/cewg/CewgPackage.js +2 -1
  45. package/dist/formats/webgl/core/cewg/CewgPackage.js.map +1 -1
  46. package/dist/formats/webgl/core/cewg/binary.js +11 -93
  47. package/dist/formats/webgl/core/cewg/binary.js.map +1 -1
  48. package/dist/formats/webgl/core/effectPackage.js +1 -1
  49. package/dist/formats/webgpu/CjsWebgpuFormat.js +4 -23
  50. package/dist/formats/webgpu/CjsWebgpuFormat.js.map +1 -1
  51. package/dist/formats/webgpu/core/buildCarbonEffectContainer.js +197 -0
  52. package/dist/formats/webgpu/core/buildCarbonEffectContainer.js.map +1 -0
  53. package/dist/formats/webgpu/core/cewgpu/CewgpuContainer.js +368 -0
  54. package/dist/formats/webgpu/core/cewgpu/CewgpuContainer.js.map +1 -0
  55. package/dist/formats/webgpu/core/cewgpu/containerViews.js +355 -0
  56. package/dist/formats/webgpu/core/cewgpu/containerViews.js.map +1 -0
  57. package/dist/formats/webgpu/core/cewgpu/validateContainer.js +90 -0
  58. package/dist/formats/webgpu/core/cewgpu/validateContainer.js.map +1 -0
  59. package/dist/formats/webgpu/core/effectBackendBodySet.js +21 -20
  60. package/dist/formats/webgpu/core/effectBackendBodySet.js.map +1 -1
  61. package/dist/formats/webgpu/core/helpers.js +87 -92
  62. package/dist/formats/webgpu/core/helpers.js.map +1 -1
  63. package/dist/formats/webgpu/core/ir/analyzeRegisterValues.js +14 -13
  64. package/dist/formats/webgpu/core/ir/analyzeRegisterValues.js.map +1 -1
  65. package/dist/formats/webgpu/core/ir/inferValueTypes.js +10 -8
  66. package/dist/formats/webgpu/core/ir/inferValueTypes.js.map +1 -1
  67. package/dist/formats/webgpu/core/packageEffect.js +94 -9
  68. package/dist/formats/webgpu/core/packageEffect.js.map +1 -1
  69. package/dist/formats/webgpu/core/packageMetadata.js +10 -1
  70. package/dist/formats/webgpu/core/packageMetadata.js.map +1 -1
  71. package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js +17 -15
  72. package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js.map +1 -1
  73. package/dist/formats/webgpu/core/wgsl/buildWgslBindingPlan.js +13 -12
  74. package/dist/formats/webgpu/core/wgsl/buildWgslBindingPlan.js.map +1 -1
  75. package/dist/formats/webgpu/core/wgsl/buildWgslSet.js +9 -8
  76. package/dist/formats/webgpu/core/wgsl/buildWgslSet.js.map +1 -1
  77. package/dist/formats/webgpu/core/wgsl/lowerComputeProgram.js +23 -22
  78. package/dist/formats/webgpu/core/wgsl/lowerComputeProgram.js.map +1 -1
  79. package/dist/formats/webgpu/core/wgsl/selectionPlans.js +46 -44
  80. package/dist/formats/webgpu/core/wgsl/selectionPlans.js.map +1 -1
  81. package/dist/resource/CjsResource.js +700 -684
  82. package/dist/resource/CjsResource.js.map +1 -1
  83. package/dist/resource/Tr2LightProfileRes.js +18 -27
  84. package/dist/resource/Tr2LightProfileRes.js.map +1 -1
  85. package/dist/resource/audio/CjsAudioBufferRes.js +2 -2
  86. package/dist/resource/audio/CjsAudioBufferRes.js.map +1 -1
  87. package/dist/resource/audio/CjsAudioRes.js +2 -2
  88. package/dist/resource/audio/CjsAudioRes.js.map +1 -1
  89. package/dist/resource/geometry/TriGeometryRes.js +605 -586
  90. package/dist/resource/geometry/TriGeometryRes.js.map +1 -1
  91. package/dist/resource/geometry/granny/Tr2GrannyStateRes.js +21 -30
  92. package/dist/resource/geometry/granny/Tr2GrannyStateRes.js.map +1 -1
  93. package/dist/resource/geometry/granny/TriGrannyRes.js +21 -30
  94. package/dist/resource/geometry/granny/TriGrannyRes.js.map +1 -1
  95. package/dist/resource/shader/Tr2EffectRes.js +9 -7
  96. package/dist/resource/shader/Tr2EffectRes.js.map +1 -1
  97. package/dist/resource/shader/Tr2MaterialArea.js +5 -3
  98. package/dist/resource/shader/Tr2MaterialArea.js.map +1 -1
  99. package/dist/resource/shader/Tr2MaterialMesh.js +4 -2
  100. package/dist/resource/shader/Tr2MaterialMesh.js.map +1 -1
  101. package/dist/resource/shader/Tr2MaterialRes.js +5 -3
  102. package/dist/resource/shader/Tr2MaterialRes.js.map +1 -1
  103. package/dist/resource/shader/Tr2Shader.js +26 -21
  104. package/dist/resource/shader/Tr2Shader.js.map +1 -1
  105. package/dist/resource/shader/Tr2ShaderPermutation.js +8 -6
  106. package/dist/resource/shader/Tr2ShaderPermutation.js.map +1 -1
  107. package/dist/resource/shader/reflection/Tr2EffectDefine.js +5 -3
  108. package/dist/resource/shader/reflection/Tr2EffectDefine.js.map +1 -1
  109. package/dist/resource/shader/reflection/Tr2EffectDescription.js +5 -3
  110. package/dist/resource/shader/reflection/Tr2EffectDescription.js.map +1 -1
  111. package/dist/resource/shader/reflection/Tr2EffectLibrary.js +17 -15
  112. package/dist/resource/shader/reflection/Tr2EffectLibrary.js.map +1 -1
  113. package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js +11 -9
  114. package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js.map +1 -1
  115. package/dist/resource/shader/reflection/Tr2EffectResource.js +8 -6
  116. package/dist/resource/shader/reflection/Tr2EffectResource.js.map +1 -1
  117. package/dist/resource/shader/reflection/Tr2EffectStageInput.js +15 -13
  118. package/dist/resource/shader/reflection/Tr2EffectStageInput.js.map +1 -1
  119. package/dist/resource/shader/reflection/Tr2EffectTechnique.js +7 -5
  120. package/dist/resource/shader/reflection/Tr2EffectTechnique.js.map +1 -1
  121. package/dist/resource/shader/reflection/Tr2Pass.js +11 -9
  122. package/dist/resource/shader/reflection/Tr2Pass.js.map +1 -1
  123. package/dist/resource/shader/sampler/Tr2SamplerSetup.js +8 -6
  124. package/dist/resource/shader/sampler/Tr2SamplerSetup.js.map +1 -1
  125. package/dist/resource/texture/CjsTextureArrayRes.js +400 -411
  126. package/dist/resource/texture/CjsTextureArrayRes.js.map +1 -1
  127. package/dist/resource/texture/Tr2ImageRes.js +99 -95
  128. package/dist/resource/texture/Tr2ImageRes.js.map +1 -1
  129. package/dist/resource/texture/TriTextureRes.js +312 -273
  130. package/dist/resource/texture/TriTextureRes.js.map +1 -1
  131. package/docs/README.md +13 -1
  132. package/docs/architecture.md +3 -3
  133. package/docs/concepts/resource-lifecycle.md +9 -2
  134. package/docs/concepts/shader-resource-model.md +114 -0
  135. package/docs/concepts/writing-an-engine-adapter.md +115 -0
  136. package/docs/formats/README.md +24 -1
  137. package/docs/formats/carbon-effect-container.md +452 -0
  138. package/docs/formats/dxbc/reference/classes/README.md +5 -72
  139. package/docs/formats/hlsl/reference/api.md +5 -4
  140. package/docs/formats/hlsl/reference/classes/README.md +6 -11
  141. package/docs/formats/provenance.md +23 -13
  142. package/docs/formats/webgl/reference/classes/README.md +5 -92
  143. package/docs/formats/webgpu/README.md +19 -16
  144. package/docs/formats/webgpu/architecture.md +15 -12
  145. package/docs/formats/webgpu/formats/cewgpu.md +175 -438
  146. package/docs/formats/webgpu/guides/effect-packaging.md +132 -140
  147. package/docs/formats/webgpu/reference/api.md +131 -131
  148. package/docs/formats/webgpu/reference/classes/README.md +5 -62
  149. package/docs/formats/webgpu/reference/wgsl-compatibility.md +146 -45
  150. package/docs/formats/wwise.md +34 -8
  151. package/docs/reference/classes/core.md +80 -0
  152. package/docs/reference/classes/formats.md +18 -28
  153. package/docs/reference/events.md +25 -0
  154. package/docs/reference/motherlode-cache.md +22 -8
  155. package/docs/reference/workers.md +5 -5
  156. package/docs/roadmap.md +61 -41
  157. package/package.json +2 -1
  158. package/dist/formats/webgpu/core/cewgpu/CewgpuPackage.js +0 -415
  159. package/dist/formats/webgpu/core/cewgpu/CewgpuPackage.js.map +0 -1
  160. package/dist/formats/webgpu/core/cewgpu/CewgpuPackageBuilder.js +0 -100
  161. package/dist/formats/webgpu/core/cewgpu/CewgpuPackageBuilder.js.map +0 -1
  162. package/dist/formats/webgpu/core/cewgpu/binary.js +0 -93
  163. package/dist/formats/webgpu/core/cewgpu/binary.js.map +0 -1
  164. package/dist/formats/webgpu/core/cewgpu/tags.js +0 -17
  165. package/dist/formats/webgpu/core/cewgpu/tags.js.map +0 -1
  166. package/dist/formats/webgpu/core/effectPackageValidation.js +0 -1078
  167. package/dist/formats/webgpu/core/effectPackageValidation.js.map +0 -1
  168. package/docs/formats/hlsl/reference/classes/carbon-compatibility.md +0 -66
  169. package/docs/formats/hlsl/reference/classes/public-api.md +0 -26
  170. package/docs/formats/hlsl/reference/classes/tr2-effect-model.md +0 -150
@@ -1,383 +1,156 @@
1
- # CEWGPU package format
1
+ # CEWGPU effect container
2
2
 
3
3
  Status: Evolving
4
- Scope: `@carbonenginejs/runtime-resource/formats/webgpu` CEWGPU version 1
4
+ Scope: `@carbonenginejs/runtime-resource/formats/webgpu`
5
5
  Audience: Shader-tool authors and engine integrators
6
- Summary: Defines the flat CEWGPU v1 container, common chunks, and structured WGSL package records.
6
+ Summary: Defines the Carbon v15 record container used for WebGPU effects, its backend block, and its derived compatibility views.
7
7
 
8
8
  ## Purpose
9
9
 
10
- CEWGPU is a CarbonEngineJS-defined container for WebGPU shader analysis,
11
- emitted WGSL, and pass layout metadata. It is designed for deterministic
12
- offline construction and simple browser-side reading.
13
-
14
- ## Binary layout
15
-
16
- All integers are unsigned 32-bit little-endian values.
17
-
18
- | Field | Size | Meaning |
19
- | --- | ---: | --- |
20
- | Magic | 4 bytes | ASCII `CWGP`. |
21
- | Version | 4 bytes | Container version; the current reader accepts `1`. |
22
- | Chunk count | 4 bytes | Number of following chunks. |
23
- | Chunk tag | 4 bytes | ASCII four-character code. |
24
- | Chunk size | 4 bytes | Payload byte length. |
25
- | Chunk payload | Variable | Raw bytes, UTF-8 text, or UTF-8 JSON by chunk contract. |
26
-
27
- The tag, size, and payload fields repeat in declaration order. A reader rejects
28
- an unsupported version, truncated chunk, invalid magic, or trailing bytes.
29
-
30
- ## Common chunks
31
-
32
- | Tag | Payload | Purpose |
33
- | --- | --- | --- |
34
- | `INFO` | JSON | Format and translator information. |
35
- | `META` | JSON | Caller provenance and effect-selection metadata. |
36
- | `PGRF` | JSON | Complete source permutation topology and identity-only body records. |
37
- | `RFLX` | JSON | Complete portable reflection for every unique version-15 source body. |
38
- | `RBLB` | Raw bytes | Exact immutable byte payloads referenced by `RFLX`. |
39
- | `ANLS` | JSON or text | Compact selected-body diagnostic stage/binding data; not lossless effect reflection. |
40
- | `WGSL` | WGSL text or JSON | One raw module or a structured shader set with layouts. |
41
-
42
- Unknown four-character chunks remain readable as raw bytes. The package
43
- builder preserves the caller's chunk order. Chunk tags must be four printable
44
- ASCII characters, and duplicate tags are rejected by both builder and reader.
45
-
46
- ## Selected-effect envelope
47
-
48
- Generic CEWGPU containers may omit common chunks and may retain raw WGSL text.
49
- A package declaring `INFO.packageKind: "tr2-effect-webgpu"` has a stricter
50
- contract. The reader requires JSON `INFO`, `META`, `ANLS`, and `WGSL` chunks.
51
- Current producers also declare and emit `PGRF`; legacy INFO v1/v2 packages may
52
- omit it. Version-15 sources additionally declare and emit `RFLX` plus `RBLB`.
53
- INFO v3 makes the graph and reflection chunks one mandatory, indivisible unit.
54
- Legacy INFO v2 may omit reflection or carry selected-body RFLX v1. The reader
55
- validates current
56
- schema versions and reconciles
57
- translator/source/body identity, the complete source permutation topology,
58
- selected options, counts, pass/stage metadata, emitted shader and layout
59
- descriptors, explicit selection coverage, WGSL-set version features, and
60
- source/backend completeness flags. Declared effect layouts use unique bind
61
- groups contiguous from group zero and unique binding slots and physical
62
- identities.
63
-
64
- The binary container version and the `INFO` document version are independent.
65
- `BuildEffect` emits `INFO.formatVersion: 3` for version-15 input and version 2
66
- for versions 8-14. The reader retains legacy selected-effect INFO versions 1
67
- and 2 and rejects unknown INFO versions; generic packages remain outside this
68
- marker-gated schema.
69
-
70
- INFO versions 2 and 3 record `targetBackend: "webgpu"`, the producing backend package
71
- name/version, and the translator name/version. Its `sourceIdentity` contains
72
- the exact source byte length and a required lower-case SHA-256 digest. The
73
- builder computes that digest synchronously over the exact input byte view and
74
- rejects a conflicting caller-supplied digest. Optional MD5 is retained only as
75
- source-system provenance.
76
-
77
- The INFO v3 provenance subset uses the following keys. Package and translator
78
- versions use semantic-version syntax; the complete INFO document also includes
79
- source/output paths, selected backend-body mode, source/backend body coverage,
80
- completeness flags, and stage/layout counts.
81
-
82
- ```json
83
- {
84
- "format": "CEWGPU",
85
- "formatVersion": 3,
86
- "packageKind": "tr2-effect-webgpu",
87
- "targetBackend": "webgpu",
88
- "backendPackage": "@carbonenginejs/runtime-resource/formats/webgpu",
89
- "backendPackageVersion": "0.6.0",
90
- "translator": "dxbc-js-wgsl",
91
- "translatorVersion": "0.6.0",
92
- "permutationGraph": {
93
- "chunk": "PGRF",
94
- "format": "CJS_EFFECT_PERMUTATION_GRAPH",
95
- "formatVersion": 1,
96
- "sha256": "0000000000000000000000000000000000000000000000000000000000000000",
97
- "permutationCount": 1,
98
- "uniqueBodyCount": 1
99
- },
100
- "effectReflection": {
101
- "chunk": "RFLX",
102
- "format": "CJS_CEWGPU_EFFECT_REFLECTION",
103
- "formatVersion": 2,
104
- "blobChunk": "RBLB",
105
- "sha256": "0000000000000000000000000000000000000000000000000000000000000000",
106
- "coverage": "all-unique",
107
- "permutationCount": 6,
108
- "bodyCount": 2,
109
- "sourceProgramCount": 4,
110
- "blobCount": 6,
111
- "blobByteLength": 4096
112
- },
113
- "sourceBodyCoverage": "all-unique",
114
- "backendBodyCoverage": "selected",
115
- "bodyMode": "selected",
116
- "completeness": {
117
- "packageValid": true,
118
- "sourceComplete": true,
119
- "backendComplete": false,
120
- "runtimeComplete": false
121
- },
122
- "sourceIdentity": {
123
- "logicalPath": "res:/graphics/effect.dx11/example.sm_hi",
124
- "game": "Eve",
125
- "client": "tranquility",
126
- "build": "0000000",
127
- "byteLength": 1024,
128
- "md5": null,
129
- "sha256": "0000000000000000000000000000000000000000000000000000000000000000"
130
- }
131
- }
132
- ```
133
-
134
- The `INFO`, `META`, and `ANLS` source labels must agree.
135
- `INFO.sourceIdentity.logicalPath` is a separate canonical resource identity and
136
- may differ from that diagnostic label.
137
-
138
- The selected-effect validator also requires compact `ANLS` stages to omit raw
139
- byte arrays and retain null DXBC/IR fields. `BuildEffect` runs the same reader
140
- validation before returning `qualification.ok: true`.
141
-
142
- ## Source permutation graph
143
-
144
- `BuildEffect` emits `CJS_EFFECT_PERMUTATION_GRAPH` version 1 in `PGRF`.
145
- INFO v2/v3 points to the chunk and records its exact permutation and
146
- unique-body counts. INFO v3 also binds the exact PGRF chunk bytes with
147
- lower-case SHA-256. A pointer without the chunk, the chunk without a pointer,
148
- or disagreeing counts/digest fail closed. Older selected-effect INFO v1/v2
149
- packages without either remain readable.
150
-
151
- PGRF preserves:
152
-
153
- - ordered axes with index, exact name/options/default, description, and type;
154
- - one variant for every first-axis-least-significant mixed-radix permutation
155
- index;
156
- - the exact option-index tuple and source body record for every variant;
157
- - deterministic package-local body keys; and
158
- - the byte length and lower-case SHA-256 digest of every unique raw source body
159
- record.
160
-
161
- The complete version-1 document shape is:
162
-
163
- ```json
164
- {
165
- "format": "CJS_EFFECT_PERMUTATION_GRAPH",
166
- "formatVersion": 1,
167
- "coverage": {
168
- "permutations": "complete",
169
- "bodies": "identity-only",
170
- "reflection": "absent"
171
- },
172
- "axes": [
173
- {
174
- "index": 0,
175
- "name": "QUALITY",
176
- "options": [ "LOW", "HIGH" ],
177
- "defaultOption": 1,
178
- "description": "quality tier",
179
- "type": 0
180
- }
181
- ],
182
- "variants": [
183
- {
184
- "permutationIndex": 0,
185
- "optionIndices": [ 0 ],
186
- "bodyKey": "body0",
187
- "sourceRecord": { "offset": 256, "byteLength": 64 }
188
- },
189
- {
190
- "permutationIndex": 1,
191
- "optionIndices": [ 1 ],
192
- "bodyKey": "body0",
193
- "sourceRecord": { "offset": 256, "byteLength": 64 }
194
- }
195
- ],
196
- "bodies": [
197
- {
198
- "key": "body0",
199
- "byteLength": 64,
200
- "sha256": "0000000000000000000000000000000000000000000000000000000000000000"
201
- }
202
- ]
203
- }
204
- ```
205
-
206
- Axis and option counts plus `axes[].type` use the source format's unsigned
207
- 8-bit limits. Permutation indices, `bodies[].byteLength`, and source-record
208
- offset/length fields use unsigned 32-bit limits. A `sourceRecord.offset` is an
209
- absolute byte offset from the beginning of the exact compiled-effect input,
210
- and `offset + byteLength` must not exceed `INFO.sourceIdentity.byteLength`.
211
- Source ranges may be exact aliases or disjoint; partial overlaps fail closed.
212
- The synchronous browser-safe producer and reader add an implementation
213
- resource limit of 65,536 Cartesian permutations per effect; larger graphs fail
214
- explicitly before variant materialization.
215
-
216
- Raw body bytes are deduplicated with SHA-256 as a lookup accelerator and exact
217
- byte equality as the final identity check. A body entry therefore provides one
218
- package-local identity for a unique raw source-body byte sequence; the bytes
219
- themselves are not embedded, and duplicate body digests are invalid. Body keys
220
- are package-local because compiled body records refer to the enclosing
221
- effect's shared string table; they are not cross-package content identities.
222
-
223
- The graph's `coverage` declares `permutations: "complete"`,
224
- `bodies: "identity-only"`, and `reflection: "absent"`. It records
225
- builder-derived source topology that can be verified against the original
226
- compiled effect; a package reader can validate only the graph's schema and
227
- internal relationships because raw bodies are not embedded. It does not claim
228
- reflection or backend translation by itself; INFO v3 joins separate RFLX v2
229
- for complete source reflection. `META.bodyIndex` remains the
230
- selected permutation index; the matching PGRF variant supplies its body key.
231
- Stage filtering remains selected-body-local and does not change the graph.
232
-
233
- The package-kind marker is the opt-in discriminator: without it, a container is
234
- generic even when it happens to use the standard chunk tags. A consumer that
235
- expects an effect package must therefore require the marker as well as calling
236
- the reader.
237
-
238
- ## Complete source reflection
239
-
240
- For compiled-effect version 15, `BuildEffect` emits
241
- `CJS_CEWGPU_EFFECT_REFLECTION` version 2 in `RFLX` and one shared raw `RBLB`
242
- byte arena. INFO v3 points to both, binds the exact RFLX chunk with SHA-256,
243
- and records all-unique coverage plus permutation, body, source-program, blob,
244
- and byte counts. A missing pointer/chunk, a digest or count disagreement, or
245
- partial coverage fails closed. Versions 8-14 remain INFO v2 without RFLX/RBLB.
246
-
247
- RFLX v2 stores common source identity and a `bodies` array in exact PGRF body
248
- order. Each body records its PGRF `bodyKey`, first representative permutation
249
- index, byte length, SHA-256, and complete body-local
250
- `CJS_EFFECT_BODY_REFLECTION` version-1 effect graph. It preserves:
251
-
252
- - complete technique, pass, stage, and library topology;
253
- - render states, authored constants/resources/UAVs/samplers and annotations;
254
- - exact stage and library source programs;
255
- - exact immutable constant-default byte vectors;
256
- - signatures, registers, static samplers, pipeline inputs, and thread groups;
257
- - the opaque version-15 native source hash; and
258
- - source/body identities joined to INFO and PGRF.
259
-
260
- Every portable byte array is replaced by an exact reference containing
261
- `blobKey`, `offset`, `byteLength`, and lower-case SHA-256. One
262
- `RFLX.blobStore` lists canonical contiguous `blobN` records covering RBLB
263
- exactly. Identical payloads are deduplicated across every reflected body by
264
- digest plus exact byte equality; dangling, overlapping, corrupt, or
265
- unreferenced payloads are rejected.
266
-
267
- The reader reconstructs and validates one portable document for every unique
268
- body. It requires every PGRF body exactly once in PGRF order, with the first
269
- matching variant as representative. For selected-backend reconciliation it
270
- joins `META.bodyIndex` to `PGRF.variants[index].bodyKey`, then to the matching
271
- RFLX body and ANLS pass/stage identities.
272
-
273
- JSON reads expose RFLX references plus `reflectionBlobByteLength`. To consume
274
- the exact bytes, read with `emit: "raw"` and use
275
- `CewgpuPackage.GetReflectionBlob(referenceOrKey)`, which returns an owned copy.
276
- An object reference must exactly equal its inventory record; a string performs
277
- a package-local blob-key lookup. To consume one complete portable body, use
278
- `CewgpuPackage.GetPortableEffectReflection(permutationIndex)`. It selects the
279
- PGRF variant (defaulting to `META.bodyIndex`), joins its RFLX body, expands all
280
- references to fresh owned `Uint8Array` payloads, and reruns the
281
- `@carbonenginejs/runtime-resource/formats/hlsl/portable` validator.
282
-
283
- INFO v3 declares `sourceBodyCoverage: "all-unique"` and
284
- `completeness.sourceComplete: true`. This means complete portable source-effect
285
- semantics for that exact compiled input. It does not embed raw body records and
286
- is not an archival reconstruction of the original `.sm_*` bytes. The accessor
287
- returns a fresh, owned plain portable document. `runtime-resource`
288
- `Tr2EffectRes` consumes it to select and cache a canonical device-free
289
- `Tr2Shader`; renderer handles, resource-set descriptions, derived dynamic
290
- classifications, layouts, and programs remain engine-owned.
291
- PGRF
292
- correctly continues to describe its own body table as `identity-only` with
293
- `reflection: "absent"` because RFLX is a separate document.
294
-
295
- `bodyMode: "selected"` and `backendBodyCoverage: "selected"` describe ANLS and
296
- WGSL scope. `backendComplete` and `runtimeComplete` remain false.
297
-
298
- ## All-body backend graph (`WGSB`)
299
-
300
- `mode: "all"` (or the `allPermutations: true` compatibility request) additionally
301
- translates every unique source body and stores the result in a `WGSB`
302
- `CJS_WGSL_BODY_SET` chunk. It requires complete version-15 source reflection,
303
- because the unique-body inventory comes from RFLX/PGRF.
304
-
305
- The translation unit is one pass of one body: the binding plan, the
306
- resource-transform plan, and every stage's WGSL are derived together, so bodies
307
- whose pass carries byte-identical stage bytecode, semantic bindings, and render
308
- states share exactly one unit. `bodies[]` maps each `bodyKey` to
309
- `{passKey, unitKey}` references, and `passUnits[]` holds the shared translated
310
- programs, layouts, and transforms. Real Quad ship families collapse several
311
- hundred passes into a small fraction of that many units.
312
-
313
- A body that cannot be lowered is retained as
314
- `status: "unsupported"` with an explicit reason and no passes. Its complete
315
- source reflection remains in RFLX, so a partial backend never removes source
316
- truth; `coverage.bodies` and `INFO.backendBodyCoverage` then report `partial`
317
- instead of `all-unique`.
318
-
319
- `INFO.backendBodySet` binds the exact chunk digest and counts. Selected-mode
320
- packages must not carry the chunk, and an all-body package must contain one
321
- record for every unique permutation-graph body. All-body packages still emit
322
- `WGSL` for the selected body, and its programs are byte-identical to the
323
- corresponding shared translation units.
324
-
325
- Translating every body still does not make the package backend- or
326
- runtime-complete: `backendComplete` and `runtimeComplete` stay false until the
327
- engine parses these records, realizes their layouts and resource transforms,
328
- and passes an exact draw gate.
329
-
330
- Legacy INFO v2 may omit reflection or carry selected-body RFLX v1/RBLB. The
331
- current reader validates both forms. INFO v3 requires PGRF plus RFLX v2/RBLB;
332
- older readers do not accept this new schema.
333
-
334
- ## Analysis document
335
-
336
- The current analysis document records normalized data for one selected effect
337
- body:
338
-
339
- - selected permutation and effect body;
340
- - techniques, passes, and stage topology;
341
- - Carbon binding-manifest data;
342
- - per-stage bytecode summaries without raw byte arrays; and
343
- - null DXBC/IR fields reserved for return-only `AnalyzeEffect` diagnostics.
344
-
345
- Analysis is retained as provenance even when `BuildEffect` emits WGSL for only
346
- some complete selected passes. `ANLS` is not lossless source reflection. It
347
- omits exact constant-default bytes, complete nested reflection/libraries, and
348
- some typed annotations needed to hydrate a complete source effect resource.
349
- Those values live in RFLX/RBLB for version-15 input. Ordered axes and the total
350
- permutation-index-to-body mapping live in PGRF rather than ANLS.
351
-
352
- `AnalyzeEffect` uses transient selected-body bytecode to return DXBC and,
353
- when requested, shader-IR diagnostics. `BuildEffect` uses the same transient
354
- byte index for WGSL compilation but does not persist raw bytecode, decoded
355
- instructions, or compiler IR in `ANLS`.
356
-
357
- `BuildEffect` records `bodyMode` in `INFO` and `META`; for INFO v3 this is
358
- explicitly backend scope, and it stays `selected` unless all-body packaging was
359
- requested. Its returned qualification record uses
360
- `validator: "cewgpu-structural"` and reports `packageValid: true`. Version-15
361
- packages report `sourceComplete: true`, `backendComplete: false`, and
362
- `runtimeComplete: false`; versions 8-14 report all three completeness flags
363
- false. These flags prevent source preservation from being mistaken for
364
- all-body translation or runtime validation. The same booleans are embedded
365
- under `INFO.completeness`.
366
-
367
- `@carbonenginejs/runtime-resource/formats/hlsl` owns source parsing, selected-body resolution,
368
- unique-body enumeration, and the shared browser-safe portable reflection
369
- contract. `format-webgpu` validates the parsed header into PGRF, aggregates
370
- every unique version-15 body into RFLX/RBLB, owns transient byte indexing for
371
- diagnostics/translation, and owns selected backend programs, layouts, and
372
- transforms. Lossless reflection remains separate from compact ANLS
373
- diagnostics.
10
+ A `.cewgpu` file is a stock Carbon version-15 compiled-effect container whose
11
+ program slots carry WGSL instead of DXBC. It preserves every permutation row
12
+ and representable non-program description/reflection fields. Non-dynamic
13
+ sampler names are unrecoverable and stage order is canonicalized. Source-stage
14
+ programs are not stored: a translated slot contains WGSL and an untranslated slot is empty.
15
+ Each translated pass may also carry one WebGPU backend block containing
16
+ bind-group layouts and resource transforms.
17
+
18
+ There is no CEWGPU-specific magic, envelope, payload tag, or container version.
19
+ Backend identity comes from the resource path, such as `effect.webgpu/`, just
20
+ as Carbon selects `effect.dx11/`, `effect.dx12/`, or `effect.metal/`.
21
+ `isCewgpu(bytes)` is therefore only a Carbon-v15 shape check. It cannot prove
22
+ that arbitrary version-15 bytes contain WGSL.
23
+
24
+ ## Wire layout
25
+
26
+ The shared Carbon container contract is documented in
27
+ [Carbon compiled-effect container](../../carbon-effect-container.md). In
28
+ outline, the file contains:
29
+
30
+ - Carbon's version-15 header, compiler version, source-hash slot (zero-filled
31
+ by the current builder), string table, and permutation axes;
32
+ - one dense offset-table row for every permutation;
33
+ - one stored description tree for every distinct emitted body, with exact
34
+ emitted-description-byte aliases sharing that body; and
35
+ - one optional backend block after each pass's render states.
36
+
37
+ The Carbon region is backend-invariant. CEWGPU substitutes:
38
+
39
+ - UTF-8 WGSL in each translated stage's `shaderData`;
40
+ - the fixed entry point `main`, which is omitted from the wire because every
41
+ current lowerer must emit it; and
42
+ - a versioned backend block for bind-group layouts and resource transforms
43
+ that Carbon reflection cannot derive.
44
+
45
+ A stage with zero program bytes is reflection-only. This is how selected-mode
46
+ packages retain untranslated bodies and how unsupported Carbon stage types
47
+ remain represented without pretending WebGPU can execute them.
48
+
49
+ ## No stored chunks
50
+
51
+ The former flat CEWGPU format stored `INFO`, `META`, `PGRF`, `RFLX`, `RBLB`,
52
+ `ANLS`, `WGSL`, and `WGSB` chunks. The current wire stores none of them.
53
+
54
+ Equivalent read surfaces are derived from the one Carbon record tree:
55
+
56
+ | Former document | Current source of truth |
57
+ | --- | --- |
58
+ | `INFO` | Carbon version, compiler version, zero-filled rebuilt source hash, and counted records |
59
+ | `META` | The resolved permutation and the passes/stages that carry programs |
60
+ | `PGRF` | Carbon's permutation axes, dense offset table, and emitted-body aliases |
61
+ | `RFLX` / `RBLB` | Representable non-program description fields and exact arena-backed values |
62
+ | `ANLS` | A normalized analysis view rebuilt from one description |
63
+ | `WGSL` | Program text and layouts read from stage records and backend blocks |
64
+ | `WGSB` | A body-set view derived across distinct stored bodies |
65
+
66
+ `Read(..., { emit: "json" })` returns these compatibility views as plain data.
67
+ They are not independent stored documents and carry no cross-document digests.
68
+ `Read(..., { emit: "raw" })` returns the internal `CewgpuContainer` reader.
69
+ There is no `chunks` array and no generic `Build(chunks)` API.
70
+
71
+ ## Building
72
+
73
+ `BuildEffect` accepts version-15 compiled-effect bytes only. It parses the
74
+ complete input, resolves the requested permutation, lowers selected programs,
75
+ and writes a new Carbon v15 container. Full portable source reflection exists
76
+ in the in-memory build result; source-stage program bytes and the caller's
77
+ source hash are not retained in the emitted wire.
78
+
79
+ The returned build record is richer than the bytes. Its `info`, `metadata`,
80
+ `permutationGraph`, `reflection`, `analysis`, `wgsl`, `backendBodySet`, and
81
+ `qualification` fields are build-time evidence for callers. They must not be
82
+ interpreted as separate records stored in the container.
83
+
84
+ ### Selected mode
85
+
86
+ `mode: "selected"` is the default. The container still carries every
87
+ permutation row and representable non-program description fields, but only the
88
+ resolved body's requested complete passes carry translated WGSL. Other bodies
89
+ have zero-length program slots.
90
+
91
+ Selected mode narrows backend translation without reducing permutation
92
+ topology.
93
+
94
+ ### All mode
95
+
96
+ `mode: "all"` first lowers the resolved selection through the same initial gate
97
+ as selected mode; an unsupported resolved body therefore aborts the build.
98
+ After that precondition succeeds, the builder attempts every distinct body. A
99
+ later body that cannot be lowered remains in the container with its non-program
100
+ description fields and zero-length programs. The in-memory body-set view
101
+ records its specific failure; rereading the wire can report only that the body
102
+ carries no translated programs.
103
+
104
+ Translation units are pass-scoped because binding plans and resource
105
+ transforms are pass contracts. Arena deduplication shares identical emitted
106
+ program and backend blobs; the wire does not contain a separate unit table.
107
+
108
+ ## Reading and validation
109
+
110
+ The shared Carbon reader validates version, count caps, dense positional
111
+ offsets, arena bounds, and exact record ends. The WebGPU layer then checks each
112
+ distinct body and rejects any program-bearing stage outside vertex, pixel, and
113
+ compute. Geometry, hull, and domain reflection may remain only when the
114
+ corresponding program slot is empty.
115
+
116
+ Inspection reports:
117
+
118
+ - Carbon version and compiler-version bytes;
119
+ - permutation and distinct-body counts; and
120
+ - stage, shader, and layout counts for the resolved translation.
121
+
122
+ The JSON read shape contains `info`, `metadata`, `permutationGraph`,
123
+ `analysis`, `wgsl`, `backendBodySet`, and convenience `stages`, `shaders`, and
124
+ `layouts` arrays. `analysis`, `wgsl`, and `backendBodySet` are derived views.
125
+
126
+ ## Backend block
127
+
128
+ Each translated pass may reference one version-1 backend block from the Carbon
129
+ arena. The block carries:
130
+
131
+ - physical bind-group and binding slots;
132
+ - resource kind, stage visibility, register identity, generated symbol, and
133
+ optional structured-buffer or array-layer metadata; and
134
+ - resource-transform family, identifier, and ordered source inputs.
135
+
136
+ Strings inside the block are inline and length-prefixed. The block contains no
137
+ arena offsets, so its bytes remain independent of the arena's content sort and
138
+ can deduplicate safely. An unknown backend-block version is skipped instead of
139
+ being guessed.
140
+
141
+ Fields such as `identity`, `layoutKey`, transform output, and fixed layer
142
+ numbers are reconstructed from the block plus record position. Backend-block
143
+ version 1 stores visibility but not the original `scopeIdentity`; the reader
144
+ reconstructs `${identity}@${visibility[0]}`. A multi-stage shared binding
145
+ therefore rereads as stage-qualified rather than recovering its original bare
146
+ scope. Callers must not use the wire view to infer that original sharing
147
+ decision.
374
148
 
375
149
  ## Structured WGSL set
376
150
 
377
- `CJS_WGSL_SET` version 2 records contain emitted shader descriptors and
378
- optional pass-level `layouts`. A layout records the exact numeric bind group
379
- and binding slots already present in the WGSL source. A set remains version 2
380
- when its source resources map one-to-one to physical WebGPU bindings.
151
+ The derived `CJS_WGSL_SET` version-2 view contains shader descriptors and
152
+ pass-level layouts. A layout records the numeric bind group and binding slots
153
+ already present in the WGSL source.
381
154
 
382
155
  Each binding keeps:
383
156
 
@@ -387,66 +160,30 @@ Each binding keeps:
387
160
  - the buffer, texture, or sampler layout; and
388
161
  - its numeric group and binding.
389
162
 
390
- Version 2 treats resource tuples as stage-scoped unless the caller explicitly
391
- confirms one compatible shared identity. The builder rejects duplicate scopes,
392
- duplicate numeric slots, mixed shared and stage-scoped forms, incomplete
393
- visibility, and stage/layout conflicts. It never renumbers slots during WGSL
394
- set assembly.
163
+ Resource tuples are stage-scoped unless the caller explicitly proves one
164
+ compatible shared identity. The builder rejects duplicate scopes, duplicate
165
+ numeric slots, mixed shared and stage-scoped forms, incomplete visibility,
166
+ and stage/layout conflicts. It never renumbers slots during WGSL-set assembly.
395
167
 
396
- Version 1 binding plans remain accepted as legacy input. Ordinary new plans
168
+ Version-1 binding plans remain accepted as legacy input. Ordinary new plans
397
169
  and WGSL sets use version 2.
398
170
 
399
171
  ### Version 3 resource transforms
400
172
 
401
- A set becomes version 3 when the compiler proves that several logical source
402
- resources can be represented by one physical WebGPU resource. The top-level
403
- `resourceTransforms` array records the realization recipe; the matching
404
- physical layout binding carries its `transformId` and `arrayLayerCount`.
405
-
406
- The currently defined version-1 recipe has this shape:
407
-
408
- ```json
409
- {
410
- "id": "Main.pass0:detail-map-array:sampled-resource:0:16",
411
- "version": 1,
412
- "kind": "texture-2d-array",
413
- "layoutKey": "Main.pass0",
414
- "stage": "fragment",
415
- "inputs": [
416
- {
417
- "parameter": "Detail1Map",
418
- "layer": 0,
419
- "identity": "sampled-resource:0:16",
420
- "scopeIdentity": "sampled-resource:0:16@fragment"
421
- },
422
- {
423
- "parameter": "Detail2Map",
424
- "layer": 1,
425
- "identity": "sampled-resource:0:17",
426
- "scopeIdentity": "sampled-resource:0:17@fragment"
427
- }
428
- ],
429
- "output": {
430
- "name": "DetailMapArray",
431
- "identity": "sampled-resource:0:16",
432
- "scopeIdentity": "sampled-resource:0:16@fragment",
433
- "viewDimension": "2d-array",
434
- "layerCount": 2
435
- },
436
- "representation": "native-or-rgba8",
437
- "missingLayer": "reject"
438
- }
439
- ```
440
-
441
- Inputs are ordered by their exact fixed array layer. The output reuses layer
442
- zero's D3D identity; later logical inputs do not remain as physical bindings.
443
- The compiler emits every affected sample with that fixed integer layer.
444
-
445
- `native-or-rgba8` requires the consumer to realize one compatible
446
- `texture_2d_array` from the named source textures, either in a shared native
447
- representation or after decoding every layer to RGBA8. Dimensions, mip
448
- coverage, sample type, and texture format must be compatible with one WebGPU
449
- array view. `missingLayer: "reject"` forbids substituting a fallback layer.
173
+ A derived set becomes version 3 when the compiler proves that several logical
174
+ source resources can be represented by one physical WebGPU resource. Its
175
+ `resourceTransforms` array describes the realization recipe; the matching
176
+ physical layout binding carries `transformId` and `arrayLayerCount`.
177
+
178
+ The currently supported version-1 recipe is `kind: "texture-2d-array"`.
179
+ Inputs are ordered by fixed array layer. The output reuses layer zero's D3D
180
+ identity, and later logical inputs do not remain as physical bindings.
181
+
182
+ `representation: "native-or-rgba8"` requires the consumer to assemble one
183
+ compatible `texture_2d_array` from the named inputs, either in a shared native
184
+ format or after decoding every layer to RGBA8. Dimensions, mip coverage,
185
+ sample type, and texture format must agree. `missingLayer: "reject"` forbids a
186
+ fallback layer.
450
187
 
451
188
  The set builder fails closed unless every recipe:
452
189
 
@@ -456,24 +193,24 @@ The set builder fails closed unless every recipe:
456
193
  - matches the binding's identity, view dimension, and layer count; and
457
194
  - removes only the later input scopes from that recipe's owning pass.
458
195
 
459
- WGSL-set version 3 is currently a compiler/module contract. The committed
460
- `engine-webgpu` package reader accepts versions 1 and 2 and rejects version 3,
461
- so a runtime must add explicit recipe realization before it can consume these
462
- packages. Raw emitted modules may still be validated independently.
196
+ `engine-webgpu` accepts WGSL-set versions 1, 2, and 3 and realizes the
197
+ version-1 `texture-2d-array` recipe. Unsupported recipe kinds or versions fail
198
+ closed.
463
199
 
464
- ## Encoding values
200
+ ## Compatibility boundary
465
201
 
466
- `Build` accepts chunk payloads as strings, plain objects, typed bytes,
467
- `ArrayBuffer`, or other array-buffer views. Plain objects are serialized as
468
- UTF-8 JSON. Byte values are preserved without interpretation.
202
+ The JSON compatibility views exist so current consumers can cross the
203
+ container switchover without a second artifact. New code should treat the
204
+ Carbon record tree as the wire authority and should not rebuild assumptions
205
+ around the retired chunk names.
469
206
 
470
- `Read(..., { emit: "raw" })` exposes the internal package object and chunk byte
471
- views for zero-copy tooling. Treat those chunk views as immutable. Mutating
472
- them after JSON or reflection lookup is outside the reader contract; rebuild
473
- or reread a package instead.
207
+ The raw container's current reflection-to-`Tr2Shader` adapter and the engine's
208
+ body-program view remain integration boundaries under active repair. Their
209
+ existence does not change the wire contract described here.
474
210
 
475
211
  ## Related documentation
476
212
 
213
+ - [Carbon compiled-effect container](../../carbon-effect-container.md)
477
214
  - [Effect packaging guide](../guides/effect-packaging.md)
478
215
  - [Public API reference](../reference/api.md)
479
216
  - [WGSL compatibility](../reference/wgsl-compatibility.md)