@carbonenginejs/runtime-resource 0.11.1 → 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 (211) 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 +18 -2
  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/graph.js +3 -6
  32. package/dist/formats/bnk/core/graph.js.map +1 -1
  33. package/dist/formats/bnk/core/helpers.js +62 -11
  34. package/dist/formats/bnk/core/helpers.js.map +1 -1
  35. package/dist/formats/bnk/core/nodeBase.js +532 -0
  36. package/dist/formats/bnk/core/nodeBase.js.map +1 -0
  37. package/dist/formats/bnk/core/sfxNodes.js +632 -0
  38. package/dist/formats/bnk/core/sfxNodes.js.map +1 -0
  39. package/dist/formats/bnk/core/soundbanksInfo.js +59 -51
  40. package/dist/formats/bnk/core/soundbanksInfo.js.map +1 -1
  41. package/dist/formats/gr2/CjsGr2Format.js +256 -13
  42. package/dist/formats/gr2/CjsGr2Format.js.map +1 -1
  43. package/dist/formats/gr2/core/helpers.js +15 -15
  44. package/dist/formats/gr2/core/helpers.js.map +1 -1
  45. package/dist/formats/gr2/core/json.js +1 -1
  46. package/dist/formats/gr2/core/json.js.map +1 -1
  47. package/dist/formats/gr2/core/targets.js +1 -1
  48. package/dist/formats/gr2/core/targets.js.map +1 -1
  49. package/dist/formats/gr2/index.js +0 -1
  50. package/dist/formats/gr2/index.js.map +1 -1
  51. package/dist/formats/hlsl/core/HlslReader.js +7 -257
  52. package/dist/formats/hlsl/core/HlslReader.js.map +1 -1
  53. package/dist/formats/hlsl/core/analysis.js +1 -1
  54. package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js +781 -0
  55. package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js.map +1 -0
  56. package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js +21 -1
  57. package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js.map +1 -1
  58. package/dist/formats/hlsl/index.js +1 -0
  59. package/dist/formats/hlsl/index.js.map +1 -1
  60. package/dist/formats/index.js +3 -6
  61. package/dist/formats/index.js.map +1 -1
  62. package/dist/formats/webgl/core/cewg/CewgPackage.js +2 -1
  63. package/dist/formats/webgl/core/cewg/CewgPackage.js.map +1 -1
  64. package/dist/formats/webgl/core/cewg/binary.js +11 -93
  65. package/dist/formats/webgl/core/cewg/binary.js.map +1 -1
  66. package/dist/formats/webgl/core/effectPackage.js +4 -1
  67. package/dist/formats/webgl/core/effectPackage.js.map +1 -1
  68. package/dist/formats/webgl/core/errors.js +3 -3
  69. package/dist/formats/webgl/core/errors.js.map +1 -1
  70. package/dist/formats/webgpu/CjsWebgpuFormat.js +4 -23
  71. package/dist/formats/webgpu/CjsWebgpuFormat.js.map +1 -1
  72. package/dist/formats/webgpu/core/buildCarbonEffectContainer.js +197 -0
  73. package/dist/formats/webgpu/core/buildCarbonEffectContainer.js.map +1 -0
  74. package/dist/formats/webgpu/core/cewgpu/CewgpuContainer.js +368 -0
  75. package/dist/formats/webgpu/core/cewgpu/CewgpuContainer.js.map +1 -0
  76. package/dist/formats/webgpu/core/cewgpu/containerViews.js +355 -0
  77. package/dist/formats/webgpu/core/cewgpu/containerViews.js.map +1 -0
  78. package/dist/formats/webgpu/core/cewgpu/validateContainer.js +90 -0
  79. package/dist/formats/webgpu/core/cewgpu/validateContainer.js.map +1 -0
  80. package/dist/formats/webgpu/core/effectBackendBodySet.js +21 -20
  81. package/dist/formats/webgpu/core/effectBackendBodySet.js.map +1 -1
  82. package/dist/formats/webgpu/core/helpers.js +87 -92
  83. package/dist/formats/webgpu/core/helpers.js.map +1 -1
  84. package/dist/formats/webgpu/core/ir/analyzeRegisterValues.js +14 -13
  85. package/dist/formats/webgpu/core/ir/analyzeRegisterValues.js.map +1 -1
  86. package/dist/formats/webgpu/core/ir/inferValueTypes.js +10 -8
  87. package/dist/formats/webgpu/core/ir/inferValueTypes.js.map +1 -1
  88. package/dist/formats/webgpu/core/packageEffect.js +94 -9
  89. package/dist/formats/webgpu/core/packageEffect.js.map +1 -1
  90. package/dist/formats/webgpu/core/packageMetadata.js +10 -1
  91. package/dist/formats/webgpu/core/packageMetadata.js.map +1 -1
  92. package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js +17 -15
  93. package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js.map +1 -1
  94. package/dist/formats/webgpu/core/wgsl/buildWgslBindingPlan.js +13 -12
  95. package/dist/formats/webgpu/core/wgsl/buildWgslBindingPlan.js.map +1 -1
  96. package/dist/formats/webgpu/core/wgsl/buildWgslSet.js +9 -8
  97. package/dist/formats/webgpu/core/wgsl/buildWgslSet.js.map +1 -1
  98. package/dist/formats/webgpu/core/wgsl/lowerComputeProgram.js +23 -22
  99. package/dist/formats/webgpu/core/wgsl/lowerComputeProgram.js.map +1 -1
  100. package/dist/formats/webgpu/core/wgsl/selectionPlans.js +46 -44
  101. package/dist/formats/webgpu/core/wgsl/selectionPlans.js.map +1 -1
  102. package/dist/resource/CjsResource.js +700 -684
  103. package/dist/resource/CjsResource.js.map +1 -1
  104. package/dist/resource/Tr2LightProfileRes.js +18 -27
  105. package/dist/resource/Tr2LightProfileRes.js.map +1 -1
  106. package/dist/resource/audio/CjsAudioBufferRes.js +2 -2
  107. package/dist/resource/audio/CjsAudioBufferRes.js.map +1 -1
  108. package/dist/resource/audio/CjsAudioRes.js +2 -2
  109. package/dist/resource/audio/CjsAudioRes.js.map +1 -1
  110. package/dist/resource/geometry/TriGeometryRes.js +605 -586
  111. package/dist/resource/geometry/TriGeometryRes.js.map +1 -1
  112. package/dist/resource/geometry/granny/Tr2GrannyStateRes.js +21 -30
  113. package/dist/resource/geometry/granny/Tr2GrannyStateRes.js.map +1 -1
  114. package/dist/resource/geometry/granny/TriGrannyRes.js +21 -30
  115. package/dist/resource/geometry/granny/TriGrannyRes.js.map +1 -1
  116. package/dist/resource/shader/Tr2EffectRes.js +9 -7
  117. package/dist/resource/shader/Tr2EffectRes.js.map +1 -1
  118. package/dist/resource/shader/Tr2MaterialArea.js +5 -3
  119. package/dist/resource/shader/Tr2MaterialArea.js.map +1 -1
  120. package/dist/resource/shader/Tr2MaterialMesh.js +4 -2
  121. package/dist/resource/shader/Tr2MaterialMesh.js.map +1 -1
  122. package/dist/resource/shader/Tr2MaterialRes.js +5 -3
  123. package/dist/resource/shader/Tr2MaterialRes.js.map +1 -1
  124. package/dist/resource/shader/Tr2Shader.js +26 -21
  125. package/dist/resource/shader/Tr2Shader.js.map +1 -1
  126. package/dist/resource/shader/Tr2ShaderPermutation.js +8 -6
  127. package/dist/resource/shader/Tr2ShaderPermutation.js.map +1 -1
  128. package/dist/resource/shader/reflection/Tr2EffectDefine.js +5 -3
  129. package/dist/resource/shader/reflection/Tr2EffectDefine.js.map +1 -1
  130. package/dist/resource/shader/reflection/Tr2EffectDescription.js +5 -3
  131. package/dist/resource/shader/reflection/Tr2EffectDescription.js.map +1 -1
  132. package/dist/resource/shader/reflection/Tr2EffectLibrary.js +17 -15
  133. package/dist/resource/shader/reflection/Tr2EffectLibrary.js.map +1 -1
  134. package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js +11 -9
  135. package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js.map +1 -1
  136. package/dist/resource/shader/reflection/Tr2EffectResource.js +8 -6
  137. package/dist/resource/shader/reflection/Tr2EffectResource.js.map +1 -1
  138. package/dist/resource/shader/reflection/Tr2EffectStageInput.js +15 -13
  139. package/dist/resource/shader/reflection/Tr2EffectStageInput.js.map +1 -1
  140. package/dist/resource/shader/reflection/Tr2EffectTechnique.js +7 -5
  141. package/dist/resource/shader/reflection/Tr2EffectTechnique.js.map +1 -1
  142. package/dist/resource/shader/reflection/Tr2Pass.js +11 -9
  143. package/dist/resource/shader/reflection/Tr2Pass.js.map +1 -1
  144. package/dist/resource/shader/sampler/Tr2SamplerSetup.js +8 -6
  145. package/dist/resource/shader/sampler/Tr2SamplerSetup.js.map +1 -1
  146. package/dist/resource/texture/CjsTextureArrayRes.js +400 -411
  147. package/dist/resource/texture/CjsTextureArrayRes.js.map +1 -1
  148. package/dist/resource/texture/Tr2ImageRes.js +99 -95
  149. package/dist/resource/texture/Tr2ImageRes.js.map +1 -1
  150. package/dist/resource/texture/TriTextureRes.js +312 -273
  151. package/dist/resource/texture/TriTextureRes.js.map +1 -1
  152. package/docs/README.md +13 -1
  153. package/docs/architecture.md +3 -3
  154. package/docs/concepts/resource-lifecycle.md +9 -2
  155. package/docs/concepts/shader-resource-model.md +114 -0
  156. package/docs/concepts/writing-an-engine-adapter.md +115 -0
  157. package/docs/formats/README.md +24 -1
  158. package/docs/formats/carbon-effect-container.md +452 -0
  159. package/docs/formats/dxbc/README.md +68 -0
  160. package/docs/formats/dxbc/architecture.md +80 -0
  161. package/docs/formats/dxbc/reference/api.md +77 -0
  162. package/docs/formats/dxbc/reference/classes/README.md +9 -0
  163. package/docs/formats/dxbc/reference/decoded-output.md +122 -0
  164. package/docs/formats/gr2.md +3 -4
  165. package/docs/formats/hlsl/README.md +54 -0
  166. package/docs/formats/hlsl/architecture.md +67 -0
  167. package/docs/formats/hlsl/guides/hydrating-json-output.md +62 -0
  168. package/docs/formats/hlsl/guides/reading-effects.md +64 -0
  169. package/docs/formats/hlsl/reference/advanced-analysis.md +66 -0
  170. package/docs/formats/hlsl/reference/api.md +98 -0
  171. package/docs/formats/hlsl/reference/classes/README.md +11 -0
  172. package/docs/formats/hlsl/reference/json-graph.md +100 -0
  173. package/docs/formats/hlsl/reference/portable-reflection.md +141 -0
  174. package/docs/formats/provenance.md +32 -17
  175. package/docs/formats/webgl/README.md +57 -0
  176. package/docs/formats/webgl/architecture.md +70 -0
  177. package/docs/formats/webgl/carbon-constant-layouts.md +326 -0
  178. package/docs/formats/webgl/decl-io.md +1234 -0
  179. package/docs/formats/webgl/effect-reflection.md +127 -0
  180. package/docs/formats/webgl/memory-structured.md +871 -0
  181. package/docs/formats/webgl/reference/classes/README.md +9 -0
  182. package/docs/formats/webgl/texture-sample.md +964 -0
  183. package/docs/formats/webgpu/README.md +84 -0
  184. package/docs/formats/webgpu/architecture.md +96 -0
  185. package/docs/formats/webgpu/formats/cewgpu.md +216 -0
  186. package/docs/formats/webgpu/guides/effect-packaging.md +191 -0
  187. package/docs/formats/webgpu/reference/api.md +197 -0
  188. package/docs/formats/webgpu/reference/classes/README.md +9 -0
  189. package/docs/formats/webgpu/reference/wgsl-compatibility.md +1543 -0
  190. package/docs/formats/wwise.md +45 -4
  191. package/docs/reference/classes/core.md +80 -0
  192. package/docs/reference/classes/formats.md +24 -34
  193. package/docs/reference/events.md +25 -0
  194. package/docs/reference/motherlode-cache.md +22 -8
  195. package/docs/reference/workers.md +5 -5
  196. package/docs/roadmap.md +61 -41
  197. package/format-notices/bnk/NOTICE +5 -4
  198. package/format-notices/webgl/NOTICE +1 -1
  199. package/package.json +2 -1
  200. package/dist/formats/gr2/core/CjsFormatGr2.js +0 -273
  201. package/dist/formats/gr2/core/CjsFormatGr2.js.map +0 -1
  202. package/dist/formats/webgpu/core/cewgpu/CewgpuPackage.js +0 -415
  203. package/dist/formats/webgpu/core/cewgpu/CewgpuPackage.js.map +0 -1
  204. package/dist/formats/webgpu/core/cewgpu/CewgpuPackageBuilder.js +0 -100
  205. package/dist/formats/webgpu/core/cewgpu/CewgpuPackageBuilder.js.map +0 -1
  206. package/dist/formats/webgpu/core/cewgpu/binary.js +0 -93
  207. package/dist/formats/webgpu/core/cewgpu/binary.js.map +0 -1
  208. package/dist/formats/webgpu/core/cewgpu/tags.js +0 -17
  209. package/dist/formats/webgpu/core/cewgpu/tags.js.map +0 -1
  210. package/dist/formats/webgpu/core/effectPackageValidation.js +0 -1078
  211. package/dist/formats/webgpu/core/effectPackageValidation.js.map +0 -1
@@ -0,0 +1,84 @@
1
+ # WebGPU format documentation
2
+
3
+ Status: Evolving
4
+ Scope: `@carbonenginejs/runtime-resource/formats/webgpu`
5
+ Audience: Shader-tool authors, engine integrators, and maintainers
6
+ Summary: Explains the Carbon-record CEWGPU format, compiled-effect conversion API, and bounded DXBC-to-WGSL compiler.
7
+
8
+ ## Purpose
9
+
10
+ `@carbonenginejs/runtime-resource/formats/webgpu` reads and builds WebGPU
11
+ effect containers and converts supported compiled-effect stages into WGSL. It
12
+ owns effect analysis, DXBC-to-intermediate-representation lowering, WGSL
13
+ emission, pass-global binding planning, and the WebGPU backend block carried by
14
+ Carbon version-15 records.
15
+
16
+ Unsupported requested shader semantics fail explicitly instead of producing a
17
+ partially translated selected pass. `BuildEffect` preserves every permutation
18
+ row and representable non-program description/reflection fields in the Carbon
19
+ container. Non-dynamic sampler names are unrecoverable and stage order is
20
+ canonicalized. Source-stage DXBC is replaced by WGSL or an empty program slot.
21
+ Selected mode writes WGSL only for the resolved body's requested passes; all
22
+ mode attempts every distinct body after the resolved body passes the initial
23
+ translation gate. Backend and runtime completeness remain broader gates.
24
+
25
+ ## Use this package when
26
+
27
+ Use the WebGPU format subpath when you need to:
28
+
29
+ - inspect or build a `.cewgpu` package;
30
+ - analyze caller-supplied compiled effect bytes;
31
+ - lower supported DXBC vertex and fragment programs to WGSL;
32
+ - build one collision-free WebGPU binding layout across a complete pass; or
33
+ - translate selected or all distinct version-15 effect bodies while preserving
34
+ permutation topology and representable non-program reflection fields.
35
+
36
+ Use `@carbonenginejs/runtime-resource/formats/hlsl` directly for effect metadata without WGSL
37
+ conversion, and `@carbonenginejs/runtime-resource/formats/dxbc` directly for standalone DXBC
38
+ inspection. GPU device, shader-module, bind-group, and pipeline realization
39
+ belong in `@carbonenginejs/engine-webgpu`.
40
+
41
+ ## Where it fits
42
+
43
+ ```text
44
+ compiled effect bytes
45
+ |
46
+ +---- formats/hlsl ---- effect and binding metadata
47
+ |
48
+ +---- formats/dxbc ---- decoded shader programs
49
+ | |
50
+ +------------------------------+
51
+ |
52
+ v
53
+ formats/webgpu
54
+ analysis + WGSL + Carbon records
55
+ |
56
+ v
57
+ engine-webgpu
58
+ ```
59
+
60
+ The package is browser-safe at its public source boundary. Repository-only
61
+ commands may adapt filesystem input for development, but the core conversion
62
+ path accepts bytes and does not depend on Node filesystem APIs or native
63
+ executables.
64
+
65
+ ## Start here
66
+
67
+ ```js
68
+ import { CjsWebgpuFormat } from "@carbonenginejs/runtime-resource/formats/webgpu";
69
+
70
+ const summary = CjsWebgpuFormat.inspect(packageBytes);
71
+ const packageData = CjsWebgpuFormat.read(packageBytes);
72
+ ```
73
+
74
+ For compiled-effect conversion, continue with the
75
+ [effect packaging guide](guides/effect-packaging.md).
76
+
77
+ ## Documentation map
78
+
79
+ - [Architecture and boundaries](architecture.md)
80
+ - [Effect packaging guide](guides/effect-packaging.md)
81
+ - [Public API reference](reference/api.md)
82
+ - [CEWGPU package format](formats/cewgpu.md)
83
+ - [WGSL compatibility](reference/wgsl-compatibility.md)
84
+ - [Class-purpose catalog](reference/classes/README.md)
@@ -0,0 +1,96 @@
1
+ # Architecture and boundaries
2
+
3
+ Status: Evolving
4
+ Scope: `@carbonenginejs/runtime-resource/formats/webgpu`
5
+ Audience: Shader-tool authors, engine integrators, and maintainers
6
+ Summary: Defines the package's compiler, container, dependency, and engine boundaries.
7
+
8
+ ## Purpose
9
+
10
+ The WebGPU format subpath is the transformation and package layer between
11
+ compiled Carbon effects and WebGPU engine realization. It converts supported
12
+ shader programs into WGSL and writes Carbon version-15 effect records without
13
+ creating live GPU objects.
14
+
15
+ ## Dependency direction
16
+
17
+ ```text
18
+ @carbonenginejs/runtime-resource/formats/hlsl
19
+ |
20
+ +---- effect selection and binding metadata
21
+ |
22
+ v
23
+ @carbonenginejs/runtime-resource/formats/webgpu <---- @carbonenginejs/runtime-resource/formats/dxbc
24
+ | decoded DXBC
25
+ |
26
+ +---- CEWGPU bytes, analysis, WGSL, canonical layouts
27
+ |
28
+ v
29
+ @carbonenginejs/engine-webgpu
30
+ ```
31
+
32
+ Node build tools may call the public byte-oriented API, but the format package
33
+ does not import the toolchain. Dependency direction remains tools to formats,
34
+ then package data to the engine.
35
+
36
+ ## Owned responsibilities
37
+
38
+ - Reading, inspecting, and building Carbon-record CEWGPU containers.
39
+ - Resolving one compiled-effect permutation and complete pass.
40
+ - Preserving every source permutation row and representable non-program
41
+ description field; non-dynamic sampler names are unrecoverable and stage
42
+ order is canonicalized.
43
+ Stored-body identity is exact emitted-description-byte identity; it does not
44
+ promise to retain the source alias partition after programs are replaced.
45
+ - Writing WGSL to program slots and bind-group/transform data to the optional
46
+ per-pass backend block.
47
+ - Normalizing effect, stage, binding, and decoded DXBC analysis.
48
+ - Building validated shader intermediate representation and structured control
49
+ flow.
50
+ - Lowering the supported vertex and fragment profiles to WGSL.
51
+ - Allocating a pass-global binding plan with explicit stage scope.
52
+ - Assembling emitted shaders and layouts into a portable WGSL set.
53
+ - Rejecting unsupported or ambiguous semantics with explicit diagnostics.
54
+
55
+ ## Ownership elsewhere
56
+
57
+ - `@carbonenginejs/runtime-resource/formats/hlsl` owns compiled-effect parsing, permutation resolution,
58
+ unique-body enumeration, binding-manifest interpretation, and the shared
59
+ body-local portable reflection schema/validator.
60
+ - `@carbonenginejs/runtime-resource/formats/dxbc` owns DXBC container and instruction decoding.
61
+ - `@carbonenginejs/engine-webgpu` owns `GPUDevice`, shader-module compilation, bind groups,
62
+ pipelines, resource realization, device loss, and draw execution.
63
+ - Node tooling owns indexed input acquisition, filesystem adapters, caching,
64
+ build reports, and optional native comparison.
65
+ - `runtime-resource` owns effect-resource lifecycle, permutation selection,
66
+ canonical device-free `Tr2Shader` hydration, and shader caching.
67
+ - `runtime-trinity` owns authored effect/material facades, parameters, options,
68
+ sampler overrides, and scene references.
69
+
70
+ ## Browser and Node boundary
71
+
72
+ The public class accepts `ArrayBuffer`, typed-array, and compatible byte views.
73
+ Its source does not read files, inspect processes, or invoke native programs.
74
+ This allows applications to fetch or select bytes and build CEWGPU data in a
75
+ browser.
76
+
77
+ The repository's command-line scripts are development adapters over the same
78
+ public operations. They are not a second compiler contract.
79
+
80
+ ## Shader target
81
+
82
+ The general translation target is DX11 SM5.0 vertex and fragment bytecode.
83
+ The compiler also admits a finite, frozen set of exact bounded compute
84
+ profiles. DX12 SM5.1 input is useful for differential analysis where
85
+ supported, but DX12-only bindless resource ranges are not part of the current
86
+ translation target.
87
+
88
+ Geometry, hull, and domain stages, plus compute programs outside the admitted
89
+ profiles, are not emitted. The exact supported and adapted boundaries are
90
+ listed in [WGSL compatibility](reference/wgsl-compatibility.md).
91
+
92
+ ## Related documentation
93
+
94
+ - [Package documentation](README.md)
95
+ - [CEWGPU package format](formats/cewgpu.md)
96
+ - [Public API reference](reference/api.md)
@@ -0,0 +1,216 @@
1
+ # CEWGPU effect container
2
+
3
+ Status: Evolving
4
+ Scope: `@carbonenginejs/runtime-resource/formats/webgpu`
5
+ Audience: Shader-tool authors and engine integrators
6
+ Summary: Defines the Carbon v15 record container used for WebGPU effects, its backend block, and its derived compatibility views.
7
+
8
+ ## Purpose
9
+
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.
148
+
149
+ ## Structured WGSL set
150
+
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.
154
+
155
+ Each binding keeps:
156
+
157
+ - a D3D-derived base `identity`;
158
+ - a resource-resolution `scopeIdentity`;
159
+ - stage visibility;
160
+ - the buffer, texture, or sampler layout; and
161
+ - its numeric group and binding.
162
+
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.
167
+
168
+ Version-1 binding plans remain accepted as legacy input. Ordinary new plans
169
+ and WGSL sets use version 2.
170
+
171
+ ### Version 3 resource transforms
172
+
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.
187
+
188
+ The set builder fails closed unless every recipe:
189
+
190
+ - targets an emitted fragment stage in its own pass;
191
+ - links exactly one `texture_2d_array<f32>` physical binding;
192
+ - numbers distinct inputs contiguously from layer zero;
193
+ - matches the binding's identity, view dimension, and layer count; and
194
+ - removes only the later input scopes from that recipe's owning pass.
195
+
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.
199
+
200
+ ## Compatibility boundary
201
+
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.
206
+
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.
210
+
211
+ ## Related documentation
212
+
213
+ - [Carbon compiled-effect container](../../carbon-effect-container.md)
214
+ - [Effect packaging guide](../guides/effect-packaging.md)
215
+ - [Public API reference](../reference/api.md)
216
+ - [WGSL compatibility](../reference/wgsl-compatibility.md)
@@ -0,0 +1,191 @@
1
+ # Build a CEWGPU package from compiled effect bytes
2
+
3
+ Status: Evolving
4
+ Scope: `@carbonenginejs/runtime-resource/formats/webgpu`
5
+ Audience: Shader-tool authors and engine integrators
6
+ Summary: Shows how to translate version-15 compiled effects into Carbon-record CEWGPU bytes.
7
+
8
+ ## Purpose
9
+
10
+ Use `buildEffect` when a caller already has version-15 compiled-effect bytes
11
+ and needs a WebGPU-targeted effect container. The operation parses the complete
12
+ input, resolves a permutation, lowers supported DXBC, allocates pass-global
13
+ bindings, emits WGSL, writes a Carbon v15 container, and validates the result.
14
+
15
+ The method is byte-oriented and does not open files or resource paths.
16
+
17
+ ## Build selected passes
18
+
19
+ ```js
20
+ import { CjsWebgpuFormat } from "@carbonenginejs/runtime-resource/formats/webgpu";
21
+
22
+ const result = CjsWebgpuFormat.buildEffect(effectBytes, {
23
+ source: "res:/graphics/effect.dx11/example.sm_hi",
24
+ mode: "selected",
25
+ permutation: [
26
+ { name: "QUALITY", value: "HIGH" }
27
+ ],
28
+ selection: {
29
+ techniqueName: "Main",
30
+ passIndex: 0,
31
+ stageNames: [ "vertex", "pixel" ]
32
+ }
33
+ });
34
+
35
+ const packageBytes = result.bytes;
36
+ const emittedShaders = result.wgsl;
37
+ ```
38
+
39
+ `source` is a caller-owned diagnostic label. An optional `sourceIdentity`
40
+ records build provenance in the returned result; it does not change the wire
41
+ identity, which belongs to the resource path used to load the emitted bytes.
42
+ When `sourceIdentity.sha256` is supplied, the build checks it against the exact
43
+ input bytes.
44
+
45
+ ## What the bytes contain
46
+
47
+ The emitted bytes are a stock Carbon v15 effect container:
48
+
49
+ - every source permutation remains in the dense offset table;
50
+ - each distinct emitted description body is stored once, based on exact emitted
51
+ bytes rather than the source alias partition;
52
+ - representable non-program description/reflection fields remain in the Carbon
53
+ tree; non-dynamic sampler names are unrecoverable and stage order is
54
+ canonicalized;
55
+ - translated stage program slots contain UTF-8 WGSL;
56
+ - untranslated or unsupported stage program slots have zero length; and
57
+ - translated passes may carry a WebGPU backend block with bind-group layouts
58
+ and resource transforms.
59
+
60
+ Source-stage DXBC and the original source hash are not stored in CEWGPU bytes.
61
+ Full portable source reflection remains available only in the in-memory
62
+ `BuildEffect` result.
63
+
64
+ There are no stored `INFO`, `META`, `PGRF`, `RFLX`, `ANLS`, `WGSL`, or `WGSB`
65
+ chunks. The read API derives compatible JSON views from the Carbon records.
66
+
67
+ ## Translation modes
68
+
69
+ ### Selected
70
+
71
+ `mode: "selected"` is the default. It translates the resolved body's requested
72
+ complete passes. Every permutation row and representable non-program
73
+ description fields remain in the container, but untranslated program slots are
74
+ empty.
75
+
76
+ Selected mode does not discard permutations. It narrows backend translation.
77
+
78
+ ### All
79
+
80
+ `mode: "all"` first lowers the resolved selection; an unsupported resolved body
81
+ aborts the build. Once that precondition succeeds, later bodies that lower
82
+ successfully carry WGSL and backend blocks. A later body outside the compiler's
83
+ current boundary remains present with non-program description fields and empty
84
+ program slots. The in-memory body-set view records its reason; a reread can
85
+ report only that it carries no translated programs.
86
+
87
+ Passes, rather than individual stages, are the translation unit because a pass
88
+ owns one binding plan and resource-transform plan.
89
+
90
+ The compatibility option `allPermutations: true` selects all mode.
91
+ `allPermutations: false` selects the requested `mode` or the selected default.
92
+
93
+ ## Build result
94
+
95
+ The returned record contains build-time evidence in addition to `bytes`:
96
+
97
+ | Field | Purpose |
98
+ | --- | --- |
99
+ | `bytes` | Carbon v15 CEWGPU bytes. |
100
+ | `info` | Producer, source, translation-scope, and completeness evidence. |
101
+ | `metadata` | Resolved selection and caller provenance. |
102
+ | `permutationGraph` | Complete source permutation and body-alias view. |
103
+ | `reflection` | Complete portable source reflection used while building. |
104
+ | `reflectionBlobs` | Exact portable-reflection payload bytes. |
105
+ | `analysis` | Selected-body diagnostic analysis. |
106
+ | `wgsl` | Emitted shaders, layouts, and transforms. |
107
+ | `backendBodySet` | All-body translation result, or `null` in selected mode. |
108
+ | `inspection` | Summary obtained by rereading the emitted bytes. |
109
+ | `qualification` | Structural build outcome and translation counts. |
110
+
111
+ These fields are returned data. They are not separate documents stored beside
112
+ the Carbon records.
113
+
114
+ `qualification.packageValid` means the emitted container passed structural
115
+ validation. It is not prepared-pipeline or rendered evidence.
116
+ `backendComplete` and `runtimeComplete` remain false until the broader compiler,
117
+ resource-hydration, selection, and execution gates are satisfied.
118
+
119
+ ## Read the result
120
+
121
+ ```js
122
+ const summary = CjsWebgpuFormat.inspect(packageBytes, {
123
+ source: "res:/graphics/effect.webgpu/example.sm_hi"
124
+ });
125
+
126
+ const data = CjsWebgpuFormat.read(packageBytes, {
127
+ source: "res:/graphics/effect.webgpu/example.sm_hi"
128
+ });
129
+ ```
130
+
131
+ The JSON read derives `info`, `metadata`, `permutationGraph`, `analysis`,
132
+ `wgsl`, and `backendBodySet` views from the one record tree. It also exposes
133
+ convenience `stages`, `shaders`, and `layouts` arrays.
134
+
135
+ Raw reads return the internal container reader. That surface is useful for
136
+ current package integration but is not a second artifact and should not be
137
+ persisted as a replacement wire format.
138
+
139
+ ## Binding scope
140
+
141
+ A D3D resource tuple is stage-local unless authoritative metadata proves that
142
+ the vertex and fragment declarations name one compatible resource. Build one
143
+ binding plan from the complete stage set.
144
+
145
+ ```js
146
+ const plan = CjsWebgpuFormat.buildWgslBindingPlan(
147
+ [ vertexIr, fragmentIr ],
148
+ { sharedIdentities: [ "uniform-buffer:0:0" ] }
149
+ );
150
+ ```
151
+
152
+ Unshared identities receive separate `@vertex` or `@fragment`
153
+ `scopeIdentity` values and numeric slots. Shared identities retain one bare
154
+ scope with combined visibility.
155
+
156
+ ## Resource transforms
157
+
158
+ When semantic metadata proves that several logical textures may be represented
159
+ by one physical array texture, the derived WGSL set uses version 3 and carries
160
+ a `texture-2d-array` transform recipe.
161
+
162
+ The consumer must assemble the named layers, match size/mips/sample
163
+ type/format, and bind the resulting array through the transformed layout.
164
+ Missing layers fail closed. A version-3 document is not executable evidence by
165
+ itself.
166
+
167
+ ## Errors
168
+
169
+ Conversion fails explicitly when:
170
+
171
+ - the source is not a version-15 compiled effect;
172
+ - a permutation assertion is unknown or unresolved;
173
+ - the permutation table is sparse, misordered, out of bounds, or malformed;
174
+ - the technique, pass, or requested stage does not exist;
175
+ - the requested stage list is duplicated or incomplete;
176
+ - the selected shader uses unsupported semantics;
177
+ - resource declarations cannot form one unambiguous pass layout;
178
+ - a lowerer emits an entry point other than `main`; or
179
+ - the emitted Carbon records or backend block fail structural validation.
180
+
181
+ Unsupported selected programs abort selected-mode packaging and also abort the
182
+ initial selection gate in all mode. After that gate succeeds, an unsupported
183
+ later body remains represented with empty program slots and an explicit
184
+ in-memory derived status.
185
+
186
+ ## Related documentation
187
+
188
+ - [CEWGPU effect container](../formats/cewgpu.md)
189
+ - [Public API reference](../reference/api.md)
190
+ - [WGSL compatibility](../reference/wgsl-compatibility.md)
191
+ - [Carbon compiled-effect container](../../carbon-effect-container.md)