@carbonenginejs/runtime-resource 0.16.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/format/CjsFormat.js +84 -83
  2. package/dist/format/CjsFormat.js.map +1 -1
  3. package/dist/format/CjsResourceProbe.js +87 -86
  4. package/dist/format/CjsResourceProbe.js.map +1 -1
  5. package/dist/format/carbonEffect/backendEngineId.js +98 -0
  6. package/dist/format/carbonEffect/backendEngineId.js.map +1 -0
  7. package/dist/format/carbonEffect/carbonEffectBackendBlock.js +24 -23
  8. package/dist/format/carbonEffect/carbonEffectBackendBlock.js.map +1 -1
  9. package/dist/format/carbonEffect/carbonEffectResourceTransform.js +1 -1
  10. package/dist/format/carbonEffect/carbonEffectResourceTransform.js.map +1 -1
  11. package/dist/format/effect/effectPermutationGraph.js +46 -29
  12. package/dist/format/effect/effectPermutationGraph.js.map +1 -1
  13. package/dist/format/index.js +1 -1
  14. package/dist/formats/hlsl/core/detailMapFamily.js +1 -1
  15. package/dist/formats/hlsl/core/detailMapFamily.js.map +1 -1
  16. package/dist/formats/hlsl/core/localLightFamily.js +1 -1
  17. package/dist/formats/hlsl/core/localLightFamily.js.map +1 -1
  18. package/dist/formats/png/core/helpers.js +27 -8
  19. package/dist/formats/png/core/helpers.js.map +1 -1
  20. package/dist/formats/webgl/core/effectPackage.js +143 -56
  21. package/dist/formats/webgl/core/effectPackage.js.map +1 -1
  22. package/dist/formats/webgl/core/glsl/DxbcGlslEmitter.js +799 -456
  23. package/dist/formats/webgl/core/glsl/DxbcGlslEmitter.js.map +1 -1
  24. package/dist/formats/webgl/core/glslBackendBlock.js +74 -30
  25. package/dist/formats/webgl/core/glslBackendBlock.js.map +1 -1
  26. package/dist/formats/webgl/core/glslBackendBodySet.js +0 -1
  27. package/dist/formats/webgl/core/glslBackendBodySet.js.map +1 -1
  28. package/dist/formats/webgl/core/helpers.js +53 -53
  29. package/dist/formats/webgl/core/helpers.js.map +1 -1
  30. package/dist/formats/webgl/core/readGlslEffectContainer.js +82 -67
  31. package/dist/formats/webgl/core/readGlslEffectContainer.js.map +1 -1
  32. package/dist/formats/webgpu/CjsWebgpuFormat.js +161 -163
  33. package/dist/formats/webgpu/CjsWebgpuFormat.js.map +1 -1
  34. package/dist/formats/webgpu/core/carbonWebgpu/CarbonWebgpuContainer.js +10 -1
  35. package/dist/formats/webgpu/core/carbonWebgpu/CarbonWebgpuContainer.js.map +1 -1
  36. package/dist/formats/webgpu/core/effectBackendBodySet.js +21 -22
  37. package/dist/formats/webgpu/core/effectBackendBodySet.js.map +1 -1
  38. package/dist/formats/webgpu/core/helpers.js +111 -99
  39. package/dist/formats/webgpu/core/helpers.js.map +1 -1
  40. package/dist/formats/webgpu/core/packageEffect.js +30 -32
  41. package/dist/formats/webgpu/core/packageEffect.js.map +1 -1
  42. package/dist/formats/wem/CjsWemFormat.js +121 -121
  43. package/dist/formats/wem/CjsWemFormat.js.map +1 -1
  44. package/dist/formats/wem/core/resolve.js +8 -8
  45. package/dist/formats/wem/core/resolve.js.map +1 -1
  46. package/dist/resource/shader/reflection/Tr2EffectStageInput.js +102 -60
  47. package/dist/resource/shader/reflection/Tr2EffectStageInput.js.map +1 -1
  48. package/docs/concepts/format-type-resolution.md +79 -0
  49. package/docs/formats/README.md +11 -0
  50. package/docs/formats/webgpu/formats/carbon-webgpu.md +11 -4
  51. package/docs/formats/webgpu/reference/api.md +7 -6
  52. package/docs/formats/wwise.md +25 -0
  53. package/docs/roadmap.md +19 -0
  54. package/package.json +2 -2
@@ -2,14 +2,14 @@ import { DxbcGlslEmitter } from './glsl/DxbcGlslEmitter.js';
2
2
  import { applyPackedLightFixups } from './glsl/packedLightFixups.js';
3
3
  import { looksLikeCarbonEffectContainer } from '../../../format/carbonEffect/CjsCarbonEffectReader.js';
4
4
 
5
- /**
6
- * Internal glue for CjsWebglFormat.
7
- *
8
- * Keeps the public class file small: input/option normalization, DXBC-to-GLSL
9
- * emission, and JSON conversion live here. Reading an effect is
10
- * `readGlslEffectContainer` and summarising one is `inspectGlslEffectContainer`;
11
- * neither needs glue, so neither is wrapped here. The GLSL emitter lives under
12
- * src/formats/webgl/core/glsl.
5
+ /**
6
+ * Internal glue for CjsWebglFormat.
7
+ *
8
+ * Keeps the public class file small: input/option normalization, DXBC-to-GLSL
9
+ * emission, and JSON conversion live here. Reading an effect is
10
+ * `readGlslEffectContainer` and summarising one is `inspectGlslEffectContainer`;
11
+ * neither needs glue, so neither is wrapped here. The GLSL emitter lives under
12
+ * src/formats/webgl/core/glsl.
13
13
  */
14
14
 
15
15
  const OUTPUT_JSON = "json";
@@ -20,13 +20,13 @@ const DEFAULT_VALUES = Object.freeze({
20
20
  const VALID_EMITS = new Set([OUTPUT_JSON]);
21
21
  const OPTION_KEYS = new Set(["emit", "source"]);
22
22
 
23
- /**
24
- * Merge format values over a base set and validate them.
25
- *
26
- * @param {object} base Current values.
27
- * @param {object} [options] Values to merge in.
28
- * @param {string} [readerName] Reader name used in error messages.
29
- * @returns {object} A validated copy of the merged values.
23
+ /**
24
+ * Merge format values over a base set and validate them.
25
+ *
26
+ * @param {object} base Current values.
27
+ * @param {object} [options] Values to merge in.
28
+ * @param {string} [readerName] Reader name used in error messages.
29
+ * @returns {object} A validated copy of the merged values.
30
30
  */
31
31
  function normalizeValues(base, options = {}, readerName = "CjsWebglFormat") {
32
32
  if (!options || typeof options !== "object") {
@@ -53,11 +53,11 @@ function normalizeValues(base, options = {}, readerName = "CjsWebglFormat") {
53
53
  };
54
54
  }
55
55
 
56
- /**
57
- * Normalize caller input into a Uint8Array of package/DXBC bytes.
58
- *
59
- * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Candidate payload.
60
- * @returns {Uint8Array} The payload bytes.
56
+ /**
57
+ * Normalize caller input into a Uint8Array of package/DXBC bytes.
58
+ *
59
+ * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Candidate payload.
60
+ * @returns {Uint8Array} The payload bytes.
61
61
  */
62
62
  function toBytes(input) {
63
63
  if (input instanceof Uint8Array) return input;
@@ -66,15 +66,15 @@ function toBytes(input) {
66
66
  throw new TypeError("CjsWebglFormat: input must be effect container bytes (Uint8Array, Buffer, DataView or ArrayBuffer)");
67
67
  }
68
68
 
69
- /**
70
- * Reports whether a payload has the Carbon effect container shape.
71
- *
72
- * A shape check, not an identity check: our files are stock Carbon containers,
73
- * so nothing in the bytes distinguishes a WebGL one from a shipped
74
- * `effect.dx11`. Identity comes from the path the file was resolved through.
75
- *
76
- * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Candidate payload.
77
- * @returns {boolean} True when the payload has the container shape.
69
+ /**
70
+ * Reports whether a payload has the Carbon effect container shape.
71
+ *
72
+ * A shape check, not an identity check: our files are stock Carbon containers,
73
+ * so nothing in the bytes distinguishes a WebGL one from a shipped
74
+ * `effect.dx11`. Identity comes from the path the file was resolved through.
75
+ *
76
+ * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Candidate payload.
77
+ * @returns {boolean} True when the payload has the container shape.
78
78
  */
79
79
  function isWebglEffectContainer(input) {
80
80
  try {
@@ -83,24 +83,24 @@ function isWebglEffectContainer(input) {
83
83
  return false;
84
84
  }
85
85
  }
86
- const EMIT_GLSL_OPTION_KEYS = new Set(["constantBufferStyle", "pixelConstantBufferRemap", "samplerName", "vertexStructuredCapacity", "dataTextureWidth", "stubResourceRegisters", "neutralResourceRegisters", "detailMapArrayRegisters", "lightConstantBuffer", "lightPackedTexture", "pairVaryings", "source"]);
87
- const EMIT_GLSL_PROFILE_KEYS = new Set(["constantBufferStyle", "pixelConstantBufferRemap", "samplerName", "vertexStructuredCapacity", "dataTextureWidth", "stubResourceRegisters", "neutralResourceRegisters", "detailMapArrayRegisters", "lightConstantBuffer", "lightPackedTexture"]);
86
+ const EMIT_GLSL_OPTION_KEYS = new Set(["constantBufferStyle", "pixelConstantBufferRemap", "samplerName", "vertexStructuredCapacity", "dataTextureWidth", "stubResourceRegisters", "neutralResourceRegisters", "detailMapArrayRegisters", "lightConstantBuffer", "lightPackedTexture", "emulatedAddressing", "pairVaryings", "source"]);
87
+ const EMIT_GLSL_PROFILE_KEYS = new Set(["constantBufferStyle", "pixelConstantBufferRemap", "samplerName", "vertexStructuredCapacity", "dataTextureWidth", "stubResourceRegisters", "neutralResourceRegisters", "detailMapArrayRegisters", "lightConstantBuffer", "lightPackedTexture", "emulatedAddressing"]);
88
88
 
89
- /**
90
- * Translates one DXBC stage into GLSL ES 3.00 source, sharing one core path
91
- * between `CjsWebglFormat.emitGlsl` (static) and `EmitGlsl` (instance).
92
- *
93
- * `options` is a flat bag combining the emitter's ccpwgl-profile constructor
94
- * bits (`constantBufferStyle`, `pixelConstantBufferRemap`, `samplerName`,
95
- * `vertexStructuredCapacity`, `dataTextureWidth`) with its per-call Emit
96
- * options (`pairVaryings`, `source`); omitted keys keep the emitter's
97
- * existing defaults exactly.
98
- *
99
- * @param {ArrayBuffer|ArrayBufferView|Uint8Array} dxbcBytes DXBC container bytes.
100
- * @param {object} [options] Combined profile/emit options.
101
- * @returns {{source:string,stageName:string,inputs:object[],outputs:object[],bindings:object[],warnings:string[],computeFragment:(object|undefined)}}
102
- * GLSL text plus the IO contract the packaging layer records; compute
103
- * stages add the emitter's `computeFragment` host contract.
89
+ /**
90
+ * Translates one DXBC stage into GLSL ES 3.00 source, sharing one core path
91
+ * between `CjsWebglFormat.emitGlsl` (static) and `EmitGlsl` (instance).
92
+ *
93
+ * `options` is a flat bag combining the emitter's ccpwgl-profile constructor
94
+ * bits (`constantBufferStyle`, `pixelConstantBufferRemap`, `samplerName`,
95
+ * `vertexStructuredCapacity`, `dataTextureWidth`) with its per-call Emit
96
+ * options (`pairVaryings`, `source`); omitted keys keep the emitter's
97
+ * existing defaults exactly.
98
+ *
99
+ * @param {ArrayBuffer|ArrayBufferView|Uint8Array} dxbcBytes DXBC container bytes.
100
+ * @param {object} [options] Combined profile/emit options.
101
+ * @returns {{source:string,stageName:string,inputs:object[],outputs:object[],bindings:object[],warnings:string[],computeFragment:(object|undefined)}}
102
+ * GLSL text plus the IO contract the packaging layer records; compute
103
+ * stages add the emitter's `computeFragment` host contract.
104
104
  */
105
105
  function emitGlslWithOptions(dxbcBytes, options = {}) {
106
106
  if (!options || typeof options !== "object") {
@@ -134,13 +134,13 @@ function emitGlslWithOptions(dxbcBytes, options = {}) {
134
134
  };
135
135
  }
136
136
 
137
- /**
138
- * Deep-convert a value to plain JSON-compatible data. Typed arrays become
139
- * plain number arrays; Maps/Sets become objects/arrays; class instances
140
- * with toJSON are honoured.
141
- *
142
- * @param {any} value Value to convert.
143
- * @returns {any} Plain data.
137
+ /**
138
+ * Deep-convert a value to plain JSON-compatible data. Typed arrays become
139
+ * plain number arrays; Maps/Sets become objects/arrays; class instances
140
+ * with toJSON are honoured.
141
+ *
142
+ * @param {any} value Value to convert.
143
+ * @returns {any} Plain data.
144
144
  */
145
145
  function toJsonValue(value) {
146
146
  if (value === null || value === undefined) return value ?? null;
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sources":["../../../../../src/formats/webgl/core/helpers.js"],"sourcesContent":["/**\n * Internal glue for CjsWebglFormat.\n *\n * Keeps the public class file small: input/option normalization, DXBC-to-GLSL\n * emission, and JSON conversion live here. Reading an effect is\n * `readGlslEffectContainer` and summarising one is `inspectGlslEffectContainer`;\n * neither needs glue, so neither is wrapped here. The GLSL emitter lives under\n * src/formats/webgl/core/glsl.\n */\n\nimport { DxbcGlslEmitter } from \"./glsl/DxbcGlslEmitter.js\";\nimport { applyPackedLightFixups } from \"./glsl/packedLightFixups.js\";\nimport { WebglReadError } from \"./errors.js\";\nimport {\n looksLikeCarbonEffectContainer\n} from \"../../../format/carbonEffect/CjsCarbonEffectReader.js\";\n\nexport const OUTPUT_JSON = \"json\";\n\nexport const DEFAULT_VALUES = Object.freeze({\n emit: OUTPUT_JSON,\n source: \"memory\"\n});\n\nconst VALID_EMITS = new Set([ OUTPUT_JSON ]);\nconst OPTION_KEYS = new Set([ \"emit\", \"source\" ]);\n\n/**\n * Merge format values over a base set and validate them.\n *\n * @param {object} base Current values.\n * @param {object} [options] Values to merge in.\n * @param {string} [readerName] Reader name used in error messages.\n * @returns {object} A validated copy of the merged values.\n */\nexport function normalizeValues(base, options = {}, readerName = \"CjsWebglFormat\")\n{\n if (!options || typeof options !== \"object\")\n {\n throw new TypeError(`${readerName}: options must be an object`);\n }\n for (const key of Object.keys(options))\n {\n if (!OPTION_KEYS.has(key))\n {\n throw new TypeError(`${readerName}: unknown option ${JSON.stringify(key)}`);\n }\n }\n\n const values = { ...base, ...options };\n\n if (!VALID_EMITS.has(values.emit))\n {\n throw new TypeError(`${readerName}: emit must be \"${OUTPUT_JSON}\", got ${JSON.stringify(values.emit)}`);\n }\n if (typeof values.source !== \"string\" || !values.source)\n {\n values.source = DEFAULT_VALUES.source;\n }\n\n return {\n emit: values.emit,\n source: values.source\n };\n}\n\n/**\n * Normalize caller input into a Uint8Array of package/DXBC bytes.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Candidate payload.\n * @returns {Uint8Array} The payload bytes.\n */\nexport function toBytes(input)\n{\n if (input instanceof Uint8Array) return input;\n if (typeof ArrayBuffer !== \"undefined\" && input instanceof ArrayBuffer) return new Uint8Array(input);\n if (ArrayBuffer.isView(input)) return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);\n throw new TypeError(\"CjsWebglFormat: input must be effect container bytes (Uint8Array, Buffer, DataView or ArrayBuffer)\");\n}\n\n/**\n * Reports whether a payload has the Carbon effect container shape.\n *\n * A shape check, not an identity check: our files are stock Carbon containers,\n * so nothing in the bytes distinguishes a WebGL one from a shipped\n * `effect.dx11`. Identity comes from the path the file was resolved through.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Candidate payload.\n * @returns {boolean} True when the payload has the container shape.\n */\nexport function isWebglEffectContainer(input)\n{\n try\n {\n return looksLikeCarbonEffectContainer(toBytes(input));\n }\n catch\n {\n return false;\n }\n}\n\nconst EMIT_GLSL_OPTION_KEYS = new Set([\n \"constantBufferStyle\",\n \"pixelConstantBufferRemap\",\n \"samplerName\",\n \"vertexStructuredCapacity\",\n \"dataTextureWidth\",\n \"stubResourceRegisters\",\n \"neutralResourceRegisters\",\n \"detailMapArrayRegisters\",\n \"lightConstantBuffer\",\n \"lightPackedTexture\",\n \"pairVaryings\",\n \"source\"\n]);\n\nconst EMIT_GLSL_PROFILE_KEYS = new Set([\n \"constantBufferStyle\",\n \"pixelConstantBufferRemap\",\n \"samplerName\",\n \"vertexStructuredCapacity\",\n \"dataTextureWidth\",\n \"stubResourceRegisters\",\n \"neutralResourceRegisters\",\n \"detailMapArrayRegisters\",\n \"lightConstantBuffer\",\n \"lightPackedTexture\"\n]);\n\n/**\n * Translates one DXBC stage into GLSL ES 3.00 source, sharing one core path\n * between `CjsWebglFormat.emitGlsl` (static) and `EmitGlsl` (instance).\n *\n * `options` is a flat bag combining the emitter's ccpwgl-profile constructor\n * bits (`constantBufferStyle`, `pixelConstantBufferRemap`, `samplerName`,\n * `vertexStructuredCapacity`, `dataTextureWidth`) with its per-call Emit\n * options (`pairVaryings`, `source`); omitted keys keep the emitter's\n * existing defaults exactly.\n *\n * @param {ArrayBuffer|ArrayBufferView|Uint8Array} dxbcBytes DXBC container bytes.\n * @param {object} [options] Combined profile/emit options.\n * @returns {{source:string,stageName:string,inputs:object[],outputs:object[],bindings:object[],warnings:string[],computeFragment:(object|undefined)}}\n * GLSL text plus the IO contract the packaging layer records; compute\n * stages add the emitter's `computeFragment` host contract.\n */\nexport function emitGlslWithOptions(dxbcBytes, options = {})\n{\n if (!options || typeof options !== \"object\")\n {\n throw new TypeError(\"CjsWebglFormat: emitGlsl options must be an object\");\n }\n for (const key of Object.keys(options))\n {\n if (!EMIT_GLSL_OPTION_KEYS.has(key))\n {\n throw new TypeError(`CjsWebglFormat: unknown emitGlsl option ${JSON.stringify(key)}`);\n }\n }\n\n const profile = {};\n for (const key of EMIT_GLSL_PROFILE_KEYS)\n {\n if (Object.prototype.hasOwnProperty.call(options, key)) profile[key] = options[key];\n }\n\n const emitter = new DxbcGlslEmitter({ profile });\n const result = emitter.Emit(dxbcBytes, {\n source: options.source,\n pairVaryings: options.pairVaryings\n });\n\n // The packed local-light lowering leaves two idioms that must not reach a\n // driver: a flag mask round-tripped through a float, and an all-bits mask\n // stored as a float and then used for branch control, where 0xFFFFFFFF is a\n // NaN. Applied here rather than at a call site so every caller gets them.\n if (!options.lightPackedTexture) return result;\n\n return {\n ...result,\n source: applyPackedLightFixups(result.source, result.stageName)\n };\n}\n\n/**\n * Deep-convert a value to plain JSON-compatible data. Typed arrays become\n * plain number arrays; Maps/Sets become objects/arrays; class instances\n * with toJSON are honoured.\n *\n * @param {any} value Value to convert.\n * @returns {any} Plain data.\n */\nexport function toJsonValue(value)\n{\n if (value === null || value === undefined) return value ?? null;\n if (typeof value === \"number\" || typeof value === \"string\" || typeof value === \"boolean\") return value;\n if (typeof value === \"bigint\") return value.toString();\n if (ArrayBuffer.isView(value)) return Array.from(value);\n if (Array.isArray(value)) return value.map(toJsonValue);\n if (value instanceof Map)\n {\n const out = {};\n for (const [ key, entry ] of value) out[key] = toJsonValue(entry);\n return out;\n }\n if (value instanceof Set) return Array.from(value, toJsonValue);\n if (typeof value === \"object\")\n {\n if (typeof value.toJSON === \"function\") return toJsonValue(value.toJSON());\n const out = {};\n for (const key of Object.keys(value)) out[key] = toJsonValue(value[key]);\n return out;\n }\n return null;\n}\n\nexport { WebglReadError };\n"],"names":["OUTPUT_JSON","DEFAULT_VALUES","Object","freeze","emit","source","VALID_EMITS","Set","OPTION_KEYS","normalizeValues","base","options","readerName","TypeError","key","keys","has","JSON","stringify","values","toBytes","input","Uint8Array","ArrayBuffer","isView","buffer","byteOffset","byteLength","isWebglEffectContainer","looksLikeCarbonEffectContainer","EMIT_GLSL_OPTION_KEYS","EMIT_GLSL_PROFILE_KEYS","emitGlslWithOptions","dxbcBytes","profile","prototype","hasOwnProperty","call","emitter","DxbcGlslEmitter","result","Emit","pairVaryings","lightPackedTexture","applyPackedLightFixups","stageName","toJsonValue","value","undefined","toString","Array","from","isArray","map","Map","out","entry","toJSON"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASO,MAAMA,WAAW,GAAG;MAEdC,cAAc,GAAGC,MAAM,CAACC,MAAM,CAAC;AACxCC,EAAAA,IAAI,EAAEJ,WAAW;AACjBK,EAAAA,MAAM,EAAE;AACZ,CAAC;AAED,MAAMC,WAAW,GAAG,IAAIC,GAAG,CAAC,CAAEP,WAAW,CAAE,CAAC;AAC5C,MAAMQ,WAAW,GAAG,IAAID,GAAG,CAAC,CAAE,MAAM,EAAE,QAAQ,CAAE,CAAC;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,eAAeA,CAACC,IAAI,EAAEC,OAAO,GAAG,EAAE,EAAEC,UAAU,GAAG,gBAAgB,EACjF;AACI,EAAA,IAAI,CAACD,OAAO,IAAI,OAAOA,OAAO,KAAK,QAAQ,EAC3C;AACI,IAAA,MAAM,IAAIE,SAAS,CAAC,CAAA,EAAGD,UAAU,6BAA6B,CAAC;AACnE,EAAA;EACA,KAAK,MAAME,GAAG,IAAIZ,MAAM,CAACa,IAAI,CAACJ,OAAO,CAAC,EACtC;AACI,IAAA,IAAI,CAACH,WAAW,CAACQ,GAAG,CAACF,GAAG,CAAC,EACzB;AACI,MAAA,MAAM,IAAID,SAAS,CAAC,CAAA,EAAGD,UAAU,CAAA,iBAAA,EAAoBK,IAAI,CAACC,SAAS,CAACJ,GAAG,CAAC,EAAE,CAAC;AAC/E,IAAA;AACJ,EAAA;AAEA,EAAA,MAAMK,MAAM,GAAG;AAAE,IAAA,GAAGT,IAAI;IAAE,GAAGC;GAAS;EAEtC,IAAI,CAACL,WAAW,CAACU,GAAG,CAACG,MAAM,CAACf,IAAI,CAAC,EACjC;AACI,IAAA,MAAM,IAAIS,SAAS,CAAC,CAAA,EAAGD,UAAU,mBA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,OAAOC,KAAK,KAAK,QAAQ,EAC7B;AACI,IAAA,IAAI,OAAOA,KAAK,CAACU,MAAM,KAAK,UAAU,EAAE,OAAOX,WAAW,CAACC,KAAK,CAACU,MAAM,EAAE,CAAC;IAC1E,MAAMF,GAAG,GAAG,EAAE;IACd,KAAK,MAAMzC,GAAG,IAAIZ,MAAM,CAACa,IAAI,CAACgC,KAAK,CAAC,EAAEQ,GAAG,CAACzC,GAAG,CAAC,GAAGgC,WAAW,CAACC,KAAK,CAACjC,GAAG,CAAC,CAAC;AACxE,IAAA,OAAOyC,GAAG;AACd,EAAA;AACA,EAAA,OAAO,IAAI;AACf;;;;"}
1
+ {"version":3,"file":"helpers.js","sources":["../../../../../src/formats/webgl/core/helpers.js"],"sourcesContent":["/**\r\n * Internal glue for CjsWebglFormat.\r\n *\r\n * Keeps the public class file small: input/option normalization, DXBC-to-GLSL\r\n * emission, and JSON conversion live here. Reading an effect is\r\n * `readGlslEffectContainer` and summarising one is `inspectGlslEffectContainer`;\r\n * neither needs glue, so neither is wrapped here. The GLSL emitter lives under\r\n * src/formats/webgl/core/glsl.\r\n */\r\n\r\nimport { DxbcGlslEmitter } from \"./glsl/DxbcGlslEmitter.js\";\r\nimport { applyPackedLightFixups } from \"./glsl/packedLightFixups.js\";\r\nimport { WebglReadError } from \"./errors.js\";\r\nimport {\r\n looksLikeCarbonEffectContainer\r\n} from \"../../../format/carbonEffect/CjsCarbonEffectReader.js\";\r\n\r\nexport const OUTPUT_JSON = \"json\";\r\n\r\nexport const DEFAULT_VALUES = Object.freeze({\r\n emit: OUTPUT_JSON,\r\n source: \"memory\"\r\n});\r\n\r\nconst VALID_EMITS = new Set([ OUTPUT_JSON ]);\r\nconst OPTION_KEYS = new Set([ \"emit\", \"source\" ]);\r\n\r\n/**\r\n * Merge format values over a base set and validate them.\r\n *\r\n * @param {object} base Current values.\r\n * @param {object} [options] Values to merge in.\r\n * @param {string} [readerName] Reader name used in error messages.\r\n * @returns {object} A validated copy of the merged values.\r\n */\r\nexport function normalizeValues(base, options = {}, readerName = \"CjsWebglFormat\")\r\n{\r\n if (!options || typeof options !== \"object\")\r\n {\r\n throw new TypeError(`${readerName}: options must be an object`);\r\n }\r\n for (const key of Object.keys(options))\r\n {\r\n if (!OPTION_KEYS.has(key))\r\n {\r\n throw new TypeError(`${readerName}: unknown option ${JSON.stringify(key)}`);\r\n }\r\n }\r\n\r\n const values = { ...base, ...options };\r\n\r\n if (!VALID_EMITS.has(values.emit))\r\n {\r\n throw new TypeError(`${readerName}: emit must be \"${OUTPUT_JSON}\", got ${JSON.stringify(values.emit)}`);\r\n }\r\n if (typeof values.source !== \"string\" || !values.source)\r\n {\r\n values.source = DEFAULT_VALUES.source;\r\n }\r\n\r\n return {\r\n emit: values.emit,\r\n source: values.source\r\n };\r\n}\r\n\r\n/**\r\n * Normalize caller input into a Uint8Array of package/DXBC bytes.\r\n *\r\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Candidate payload.\r\n * @returns {Uint8Array} The payload bytes.\r\n */\r\nexport function toBytes(input)\r\n{\r\n if (input instanceof Uint8Array) return input;\r\n if (typeof ArrayBuffer !== \"undefined\" && input instanceof ArrayBuffer) return new Uint8Array(input);\r\n if (ArrayBuffer.isView(input)) return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);\r\n throw new TypeError(\"CjsWebglFormat: input must be effect container bytes (Uint8Array, Buffer, DataView or ArrayBuffer)\");\r\n}\r\n\r\n/**\r\n * Reports whether a payload has the Carbon effect container shape.\r\n *\r\n * A shape check, not an identity check: our files are stock Carbon containers,\r\n * so nothing in the bytes distinguishes a WebGL one from a shipped\r\n * `effect.dx11`. Identity comes from the path the file was resolved through.\r\n *\r\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Candidate payload.\r\n * @returns {boolean} True when the payload has the container shape.\r\n */\r\nexport function isWebglEffectContainer(input)\r\n{\r\n try\r\n {\r\n return looksLikeCarbonEffectContainer(toBytes(input));\r\n }\r\n catch\r\n {\r\n return false;\r\n }\r\n}\r\n\r\nconst EMIT_GLSL_OPTION_KEYS = new Set([\r\n \"constantBufferStyle\",\r\n \"pixelConstantBufferRemap\",\r\n \"samplerName\",\r\n \"vertexStructuredCapacity\",\r\n \"dataTextureWidth\",\r\n \"stubResourceRegisters\",\r\n \"neutralResourceRegisters\",\r\n \"detailMapArrayRegisters\",\r\n \"lightConstantBuffer\",\r\n \"lightPackedTexture\",\r\n \"emulatedAddressing\",\r\n \"pairVaryings\",\r\n \"source\"\r\n]);\r\n\r\nconst EMIT_GLSL_PROFILE_KEYS = new Set([\r\n \"constantBufferStyle\",\r\n \"pixelConstantBufferRemap\",\r\n \"samplerName\",\r\n \"vertexStructuredCapacity\",\r\n \"dataTextureWidth\",\r\n \"stubResourceRegisters\",\r\n \"neutralResourceRegisters\",\r\n \"detailMapArrayRegisters\",\r\n \"lightConstantBuffer\",\r\n \"lightPackedTexture\",\r\n \"emulatedAddressing\"\r\n]);\r\n\r\n/**\r\n * Translates one DXBC stage into GLSL ES 3.00 source, sharing one core path\r\n * between `CjsWebglFormat.emitGlsl` (static) and `EmitGlsl` (instance).\r\n *\r\n * `options` is a flat bag combining the emitter's ccpwgl-profile constructor\r\n * bits (`constantBufferStyle`, `pixelConstantBufferRemap`, `samplerName`,\r\n * `vertexStructuredCapacity`, `dataTextureWidth`) with its per-call Emit\r\n * options (`pairVaryings`, `source`); omitted keys keep the emitter's\r\n * existing defaults exactly.\r\n *\r\n * @param {ArrayBuffer|ArrayBufferView|Uint8Array} dxbcBytes DXBC container bytes.\r\n * @param {object} [options] Combined profile/emit options.\r\n * @returns {{source:string,stageName:string,inputs:object[],outputs:object[],bindings:object[],warnings:string[],computeFragment:(object|undefined)}}\r\n * GLSL text plus the IO contract the packaging layer records; compute\r\n * stages add the emitter's `computeFragment` host contract.\r\n */\r\nexport function emitGlslWithOptions(dxbcBytes, options = {})\r\n{\r\n if (!options || typeof options !== \"object\")\r\n {\r\n throw new TypeError(\"CjsWebglFormat: emitGlsl options must be an object\");\r\n }\r\n for (const key of Object.keys(options))\r\n {\r\n if (!EMIT_GLSL_OPTION_KEYS.has(key))\r\n {\r\n throw new TypeError(`CjsWebglFormat: unknown emitGlsl option ${JSON.stringify(key)}`);\r\n }\r\n }\r\n\r\n const profile = {};\r\n for (const key of EMIT_GLSL_PROFILE_KEYS)\r\n {\r\n if (Object.prototype.hasOwnProperty.call(options, key)) profile[key] = options[key];\r\n }\r\n\r\n const emitter = new DxbcGlslEmitter({ profile });\r\n const result = emitter.Emit(dxbcBytes, {\r\n source: options.source,\r\n pairVaryings: options.pairVaryings\r\n });\r\n\r\n // The packed local-light lowering leaves two idioms that must not reach a\r\n // driver: a flag mask round-tripped through a float, and an all-bits mask\r\n // stored as a float and then used for branch control, where 0xFFFFFFFF is a\r\n // NaN. Applied here rather than at a call site so every caller gets them.\r\n if (!options.lightPackedTexture) return result;\r\n\r\n return {\r\n ...result,\r\n source: applyPackedLightFixups(result.source, result.stageName)\r\n };\r\n}\r\n\r\n/**\r\n * Deep-convert a value to plain JSON-compatible data. Typed arrays become\r\n * plain number arrays; Maps/Sets become objects/arrays; class instances\r\n * with toJSON are honoured.\r\n *\r\n * @param {any} value Value to convert.\r\n * @returns {any} Plain data.\r\n */\r\nexport function toJsonValue(value)\r\n{\r\n if (value === null || value === undefined) return value ?? null;\r\n if (typeof value === \"number\" || typeof value === \"string\" || typeof value === \"boolean\") return value;\r\n if (typeof value === \"bigint\") return value.toString();\r\n if (ArrayBuffer.isView(value)) return Array.from(value);\r\n if (Array.isArray(value)) return value.map(toJsonValue);\r\n if (value instanceof Map)\r\n {\r\n const out = {};\r\n for (const [ key, entry ] of value) out[key] = toJsonValue(entry);\r\n return out;\r\n }\r\n if (value instanceof Set) return Array.from(value, toJsonValue);\r\n if (typeof value === \"object\")\r\n {\r\n if (typeof value.toJSON === \"function\") return toJsonValue(value.toJSON());\r\n const out = {};\r\n for (const key of Object.keys(value)) out[key] = toJsonValue(value[key]);\r\n return out;\r\n }\r\n return null;\r\n}\r\n\r\nexport { WebglReadError };\r\n"],"names":["OUTPUT_JSON","DEFAULT_VALUES","Object","freeze","emit","source","VALID_EMITS","Set","OPTION_KEYS","normalizeValues","base","options","readerName","TypeError","key","keys","has","JSON","stringify","values","toBytes","input","Uint8Array","ArrayBuffer","isView","buffer","byteOffset","byteLength","isWebglEffectContainer","looksLikeCarbonEffectContainer","EMIT_GLSL_OPTION_KEYS","EMIT_GLSL_PROFILE_KEYS","emitGlslWithOptions","dxbcBytes","profile","prototype","hasOwnProperty","call","emitter","DxbcGlslEmitter","result","Emit","pairVaryings","lightPackedTexture","applyPackedLightFixups","stageName","toJsonValue","value","undefined","toString","Array","from","isArray","map","Map","out","entry","toJSON"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASO,MAAMA,WAAW,GAAG;MAEdC,cAAc,GAAGC,MAAM,CAACC,MAAM,CAAC;AACxCC,EAAAA,IAAI,EAAEJ,WAAW;AACjBK,EAAAA,MAAM,EAAE;AACZ,CAAC;AAED,MAAMC,WAAW,GAAG,IAAIC,GAAG,CAAC,CAAEP,WAAW,CAAE,CAAC;AAC5C,MAAMQ,WAAW,GAAG,IAAID,GAAG,CAAC,CAAE,MAAM,EAAE,QAAQ,CAAE,CAAC;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,eAAeA,CAACC,IAAI,EAAEC,OAAO,GAAG,EAAE,EAAEC,UAAU,GAAG,gBAAgB,EACjF;AACI,EAAA,IAAI,CAACD,OAAO,IAAI,OAAOA,OAAO,KAAK,QAAQ,EAC3C;AACI,IAAA,MAAM,IAAIE,SAAS,CAAC,CAAA,EAAGD,UAAU,6BAA6B,CAAC;AACnE,EAAA;EACA,KAAK,MAAME,GAAG,IAAIZ,MAAM,CAACa,IAAI,CAACJ,OAAO,CAAC,EACtC;AACI,IAAA,IAAI,CAACH,WAAW,CAACQ,GAAG,CAACF,GAAG,CAAC,EACzB;AACI,MAAA,MAAM,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W,CAAC;EACvD,IAAIC,KAAK,YAAYO,GAAG,EACxB;IACI,MAAMC,GAAG,GAAG,EAAE;AACd,IAAA,KAAK,MAAM,CAAEzC,GAAG,EAAE0C,KAAK,CAAE,IAAIT,KAAK,EAAEQ,GAAG,CAACzC,GAAG,CAAC,GAAGgC,WAAW,CAACU,KAAK,CAAC;AACjE,IAAA,OAAOD,GAAG;AACd,EAAA;AACA,EAAA,IAAIR,KAAK,YAAYxC,GAAG,EAAE,OAAO2C,KAAK,CAACC,IAAI,CAACJ,KAAK,EAAED,WAAW,CAAC;AAC/D,EAAA,IAAI,OAAOC,KAAK,KAAK,QAAQ,EAC7B;AACI,IAAA,IAAI,OAAOA,KAAK,CAACU,MAAM,KAAK,UAAU,EAAE,OAAOX,WAAW,CAACC,KAAK,CAACU,MAAM,EAAE,CAAC;IAC1E,MAAMF,GAAG,GAAG,EAAE;IACd,KAAK,MAAMzC,GAAG,IAAIZ,MAAM,CAACa,IAAI,CAACgC,KAAK,CAAC,EAAEQ,GAAG,CAACzC,GAAG,CAAC,GAAGgC,WAAW,CAACC,KAAK,CAACjC,GAAG,CAAC,CAAC;AACxE,IAAA,OAAOyC,GAAG;AACd,EAAA;AACA,EAAA,OAAO,IAAI;AACf;;;;"}
@@ -1,62 +1,63 @@
1
1
  import { CjsCarbonEffectReader } from '../../../format/carbonEffect/CjsCarbonEffectReader.js';
2
2
  import { readGlslBackendBlock } from './glslBackendBlock.js';
3
+ import { peekBackendEngineId, CARBON_BACKEND_ENGINE_ID } from '../../../format/carbonEffect/backendEngineId.js';
3
4
  import { hlslShaderStageName } from '../../hlsl/core/tr2/HlslRenderContextEnum.js';
4
5
  import { runtimeDescriptionFromCarbon } from '../../hlsl/core/carbonDescriptionToRuntime.js';
5
6
  import { HlslEffectBindingManifest } from '../../hlsl/core/tr2/shader/HlslEffectBindingManifest.js';
6
7
 
7
- /**
8
- * Decodes a WebGL effect container into the stage/shader records the
9
- * completeness rules consume.
10
- *
11
- * This exists so the rules run from container bytes alone. The alternative was
12
- * to hand them the in-memory translation, which works inside `buildEffectPackage`
13
- * and nowhere else — the validator reads a finished file and has no translation
14
- * in scope. That would have cost the validator its completeness check while
15
- * still requiring a decoder to produce the programs it compiles in a browser, so
16
- * it was strictly more work for strictly less checking.
17
- *
18
- * The vocabulary is deliberately the one the rules already speak — `stages` with
19
- * pass coordinates, `shaders` with source and a translation verdict. The rules
20
- * are about the translation, not about how it was stored, so retargeting them
21
- * meant changing where the records come from and nothing about what they mean.
22
- *
23
- * **What the wire cannot tell you.** `buildCarbonEffectContainer` stores a body
24
- * the translator could not lower as its full pass tree with zero-length
25
- * programs; the *reason* it failed stays in the in-memory build result and is
26
- * never written. So a shader decoded from bytes reports `ok: false` with
27
- * "no program was stored" and nothing more specific. That is the honest answer:
28
- * a file on disk does not know why a translation failed months ago. Callers that
29
- * do know — `buildEffectPackage`, at build time — keep their specific
30
- * diagnostics by feeding the rules their own records instead.
8
+ /**
9
+ * Decodes a WebGL effect container into the stage/shader records the
10
+ * completeness rules consume.
11
+ *
12
+ * This exists so the rules run from container bytes alone. The alternative was
13
+ * to hand them the in-memory translation, which works inside `buildEffectPackage`
14
+ * and nowhere else — the validator reads a finished file and has no translation
15
+ * in scope. That would have cost the validator its completeness check while
16
+ * still requiring a decoder to produce the programs it compiles in a browser, so
17
+ * it was strictly more work for strictly less checking.
18
+ *
19
+ * The vocabulary is deliberately the one the rules already speak — `stages` with
20
+ * pass coordinates, `shaders` with source and a translation verdict. The rules
21
+ * are about the translation, not about how it was stored, so retargeting them
22
+ * meant changing where the records come from and nothing about what they mean.
23
+ *
24
+ * **What the wire cannot tell you.** `buildCarbonEffectContainer` stores a body
25
+ * the translator could not lower as its full pass tree with zero-length
26
+ * programs; the *reason* it failed stays in the in-memory build result and is
27
+ * never written. So a shader decoded from bytes reports `ok: false` with
28
+ * "no program was stored" and nothing more specific. That is the honest answer:
29
+ * a file on disk does not know why a translation failed months ago. Callers that
30
+ * do know — `buildEffectPackage`, at build time — keep their specific
31
+ * diagnostics by feeding the rules their own records instead.
31
32
  */
32
33
 
33
34
  /** The verdict a stage carrying no stored program gets. */
34
35
  const NO_PROGRAM_REASON = "no program was stored";
35
36
 
36
- /**
37
- * Derives the per-stage binding manifests for one body through the one
38
- * manifest builder the source path uses.
39
- *
40
- * This replaces a hand-built reshape of the wire records into the manifest
41
- * vocabulary. That copy had already diverged from the real manifest once —
42
- * `isAutoregister` was silently dropped, making every resource look
43
- * user-settable — which is the whole argument against a second producer: two
44
- * hand-maintained spellings of one reflection drift, and the drift is exactly
45
- * the kind of bug that draws, links and renders black without an error. The
46
- * record tree now flows through `runtimeDescriptionFromCarbon` — the
47
- * corpus-proven adapter the runtime read path uses — and
48
- * `HlslEffectBindingManifest`, so the container read and the build-time
49
- * package derive their manifests from the same code.
50
- *
51
- * No `bytecodeFor` is supplied: program text lives in the shader records this
52
- * reader emits, so the manifest's `shaderBytecode` stays null rather than
53
- * duplicating every program into the reflection.
54
- *
55
- * @param {object} description Decoded Carbon description record tree.
56
- * @param {number} version Container data version.
57
- * @param {string} source Source name for diagnostics.
58
- * @returns {Map<string, object>} Manifest stage records keyed by
59
- * `technique.passN.stageName`.
37
+ /**
38
+ * Derives the per-stage binding manifests for one body through the one
39
+ * manifest builder the source path uses.
40
+ *
41
+ * This replaces a hand-built reshape of the wire records into the manifest
42
+ * vocabulary. That copy had already diverged from the real manifest once —
43
+ * `isAutoregister` was silently dropped, making every resource look
44
+ * user-settable — which is the whole argument against a second producer: two
45
+ * hand-maintained spellings of one reflection drift, and the drift is exactly
46
+ * the kind of bug that draws, links and renders black without an error. The
47
+ * record tree now flows through `runtimeDescriptionFromCarbon` — the
48
+ * corpus-proven adapter the runtime read path uses — and
49
+ * `HlslEffectBindingManifest`, so the container read and the build-time
50
+ * package derive their manifests from the same code.
51
+ *
52
+ * No `bytecodeFor` is supplied: program text lives in the shader records this
53
+ * reader emits, so the manifest's `shaderBytecode` stays null rather than
54
+ * duplicating every program into the reflection.
55
+ *
56
+ * @param {object} description Decoded Carbon description record tree.
57
+ * @param {number} version Container data version.
58
+ * @param {string} source Source name for diagnostics.
59
+ * @returns {Map<string, object>} Manifest stage records keyed by
60
+ * `technique.passN.stageName`.
60
61
  */
61
62
  function bodyManifestStages(description, version, source) {
62
63
  const runtime = runtimeDescriptionFromCarbon(description, {
@@ -67,19 +68,33 @@ function bodyManifestStages(description, version, source) {
67
68
  return new Map(manifest.stages.map(stage => [`${stage.techniqueName}.pass${stage.passIndex}.${stage.stageName}`, stage]));
68
69
  }
69
70
 
70
- /**
71
- * Decodes one pass's backend block, tolerating a pass that has none.
72
- *
73
- * @param {object} pass Decoded pass record.
74
- * @param {string} passKey Enclosing pass key.
75
- * @param {string} source Source name for error details.
76
- * @returns {object} Per-stage backend data, keyed by stage name.
71
+ /**
72
+ * Decodes one pass's backend block, tolerating a pass that has none.
73
+ *
74
+ * @param {object} pass Decoded pass record.
75
+ * @param {string} passKey Enclosing pass key.
76
+ * @param {string} source Source name for error details.
77
+ * @returns {object} Per-stage backend data, keyed by stage name.
77
78
  */
78
79
  function backendStages(pass, passKey, source) {
79
80
  if (!pass.backendBlock?.size) return {
80
81
  stages: {},
81
82
  transforms: []
82
83
  };
84
+
85
+ // A block belonging to another backend is not an error here. The container
86
+ // is Carbon-shaped whatever it targets, and loading it must not depend on
87
+ // being able to use its programs - a dx11 container loads and simply cannot
88
+ // be executed by this library. Report no backend data and let prepare fail
89
+ // where the backend actually matters.
90
+ const engineId = peekBackendEngineId(pass.backendBlock.bytes);
91
+ if (engineId !== CARBON_BACKEND_ENGINE_ID.webgl2) {
92
+ return {
93
+ stages: {},
94
+ transforms: [],
95
+ foreignEngineId: engineId
96
+ };
97
+ }
83
98
  const block = readGlslBackendBlock(pass.backendBlock.bytes, {
84
99
  layoutKey: passKey,
85
100
  source
@@ -90,18 +105,18 @@ function backendStages(pass, passKey, source) {
90
105
  };
91
106
  }
92
107
 
93
- /**
94
- * Decodes container bytes into stage and shader records.
95
- *
96
- * Bodies are decoded once each rather than once per permutation row: rows alias
97
- * onto shared bodies, and a rule that saw the same body 4,096 times would report
98
- * 4,096 identical incomplete passes.
99
- *
100
- * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Container payload.
101
- * @param {object} [values] Read values.
102
- * @param {string} [values.source] Source name, for diagnostics.
103
- * @returns {{stages:object[], shaders:object[], recordCount:number, bodyCount:number}}
104
- * Stage graph in the completeness rules' vocabulary.
108
+ /**
109
+ * Decodes container bytes into stage and shader records.
110
+ *
111
+ * Bodies are decoded once each rather than once per permutation row: rows alias
112
+ * onto shared bodies, and a rule that saw the same body 4,096 times would report
113
+ * 4,096 identical incomplete passes.
114
+ *
115
+ * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Container payload.
116
+ * @param {object} [values] Read values.
117
+ * @param {string} [values.source] Source name, for diagnostics.
118
+ * @returns {{stages:object[], shaders:object[], recordCount:number, bodyCount:number}}
119
+ * Stage graph in the completeness rules' vocabulary.
105
120
  */
106
121
  function readGlslEffectContainer(input, values = {}) {
107
122
  const source = values.source ?? "memory";
@@ -1 +1 @@
1
- {"version":3,"file":"readGlslEffectContainer.js","sources":["../../../../../src/formats/webgl/core/readGlslEffectContainer.js"],"sourcesContent":["import { CjsCarbonEffectReader } from \"../../../format/carbonEffect/CjsCarbonEffectReader.js\";\r\nimport { readGlslBackendBlock } from \"./glslBackendBlock.js\";\r\nimport { hlslShaderStageName } from \"../../hlsl/core/tr2/HlslRenderContextEnum.js\";\r\nimport { runtimeDescriptionFromCarbon } from \"../../hlsl/core/carbonDescriptionToRuntime.js\";\r\nimport { HlslEffectBindingManifest } from \"../../hlsl/core/tr2/shader/HlslEffectBindingManifest.js\";\r\n\r\n/**\r\n * Decodes a WebGL effect container into the stage/shader records the\r\n * completeness rules consume.\r\n *\r\n * This exists so the rules run from container bytes alone. The alternative was\r\n * to hand them the in-memory translation, which works inside `buildEffectPackage`\r\n * and nowhere else — the validator reads a finished file and has no translation\r\n * in scope. That would have cost the validator its completeness check while\r\n * still requiring a decoder to produce the programs it compiles in a browser, so\r\n * it was strictly more work for strictly less checking.\r\n *\r\n * The vocabulary is deliberately the one the rules already speak — `stages` with\r\n * pass coordinates, `shaders` with source and a translation verdict. The rules\r\n * are about the translation, not about how it was stored, so retargeting them\r\n * meant changing where the records come from and nothing about what they mean.\r\n *\r\n * **What the wire cannot tell you.** `buildCarbonEffectContainer` stores a body\r\n * the translator could not lower as its full pass tree with zero-length\r\n * programs; the *reason* it failed stays in the in-memory build result and is\r\n * never written. So a shader decoded from bytes reports `ok: false` with\r\n * \"no program was stored\" and nothing more specific. That is the honest answer:\r\n * a file on disk does not know why a translation failed months ago. Callers that\r\n * do know — `buildEffectPackage`, at build time — keep their specific\r\n * diagnostics by feeding the rules their own records instead.\r\n */\r\n\r\n/** The verdict a stage carrying no stored program gets. */\r\nconst NO_PROGRAM_REASON = \"no program was stored\";\r\n\r\n/**\r\n * Derives the per-stage binding manifests for one body through the one\r\n * manifest builder the source path uses.\r\n *\r\n * This replaces a hand-built reshape of the wire records into the manifest\r\n * vocabulary. That copy had already diverged from the real manifest once —\r\n * `isAutoregister` was silently dropped, making every resource look\r\n * user-settable — which is the whole argument against a second producer: two\r\n * hand-maintained spellings of one reflection drift, and the drift is exactly\r\n * the kind of bug that draws, links and renders black without an error. The\r\n * record tree now flows through `runtimeDescriptionFromCarbon` — the\r\n * corpus-proven adapter the runtime read path uses — and\r\n * `HlslEffectBindingManifest`, so the container read and the build-time\r\n * package derive their manifests from the same code.\r\n *\r\n * No `bytecodeFor` is supplied: program text lives in the shader records this\r\n * reader emits, so the manifest's `shaderBytecode` stays null rather than\r\n * duplicating every program into the reflection.\r\n *\r\n * @param {object} description Decoded Carbon description record tree.\r\n * @param {number} version Container data version.\r\n * @param {string} source Source name for diagnostics.\r\n * @returns {Map<string, object>} Manifest stage records keyed by\r\n * `technique.passN.stageName`.\r\n */\r\nfunction bodyManifestStages(description, version, source)\r\n{\r\n const runtime = runtimeDescriptionFromCarbon(description, {\r\n effectName: source,\r\n version\r\n });\r\n const manifest = HlslEffectBindingManifest.fromEffectDescription(runtime).toJSON();\r\n return new Map(manifest.stages.map((stage) => [\r\n `${stage.techniqueName}.pass${stage.passIndex}.${stage.stageName}`,\r\n stage\r\n ]));\r\n}\r\n\r\n/**\r\n * Decodes one pass's backend block, tolerating a pass that has none.\r\n *\r\n * @param {object} pass Decoded pass record.\r\n * @param {string} passKey Enclosing pass key.\r\n * @param {string} source Source name for error details.\r\n * @returns {object} Per-stage backend data, keyed by stage name.\r\n */\r\nfunction backendStages(pass, passKey, source)\r\n{\r\n if (!pass.backendBlock?.size) return { stages: {}, transforms: [] };\r\n const block = readGlslBackendBlock(pass.backendBlock.bytes, { layoutKey: passKey, source });\r\n return { stages: block.stages ?? {}, transforms: block.transforms ?? [] };\r\n}\r\n\r\n/**\r\n * Decodes container bytes into stage and shader records.\r\n *\r\n * Bodies are decoded once each rather than once per permutation row: rows alias\r\n * onto shared bodies, and a rule that saw the same body 4,096 times would report\r\n * 4,096 identical incomplete passes.\r\n *\r\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Container payload.\r\n * @param {object} [values] Read values.\r\n * @param {string} [values.source] Source name, for diagnostics.\r\n * @returns {{stages:object[], shaders:object[], recordCount:number, bodyCount:number}}\r\n * Stage graph in the completeness rules' vocabulary.\r\n */\r\nexport function readGlslEffectContainer(input, values = {})\r\n{\r\n const source = values.source ?? \"memory\";\r\n const reader = new CjsCarbonEffectReader(input, { source });\r\n\r\n const stages = [];\r\n const shaders = [];\r\n const bodyKeyByOffset = new Map();\r\n\r\n // Every permutation index that resolves to each body.\r\n //\r\n // This is the bridge a caller actually needs, and the only one that is\r\n // sound. `bodyKey` here is this reader's own ordinal spelling; the\r\n // permutation graph mints `body${N}` for the same body, and the two are not\r\n // merely spelled differently — the graph dedupes by content (SHA-256 plus\r\n // byte equality) while this reader dedupes by source-record offset. Those\r\n // partitions coincide only because the container writer aliases\r\n // byte-identical bodies onto one offset, which is a property of the writer\r\n // rather than a contract.\r\n //\r\n // So a consumer must never map between the two by string surgery on either\r\n // spelling, and must not assume the two ordinal sequences agree. It holds a\r\n // permutation index; this gives it the body directly.\r\n const permutationIndicesByOffset = new Map();\r\n\r\n for (let index = 0; index < reader.records.length; index += 1)\r\n {\r\n const { offset } = reader.records[index];\r\n const seen = permutationIndicesByOffset.get(offset);\r\n if (seen) seen.push(index);\r\n else permutationIndicesByOffset.set(offset, [ index ]);\r\n }\r\n\r\n // Distinct program texts share one shader record, so `shaders` counts unique\r\n // translations the way the chunk package's shader table did. Empty stages are\r\n // deliberately *not* pooled: each keeps its own record so a report can name\r\n // every pass that is missing a program rather than one shared \"absent\".\r\n //\r\n // The pool key is the program text *and* the backend reflection that came\r\n // with it, not the text alone. A pooled record carries the bindings and\r\n // stage inputs of whichever stage was seen first, and\r\n // `validateShaderRuntimeContract` judges the emitted GLSL against them — so\r\n // pooling on text alone would let two stages with identical source but\r\n // different reflection be checked against the wrong metadata, silently. It\r\n // is unlikely that identical GLSL ever carries different reflection, which\r\n // is exactly why it would not be noticed.\r\n const shaderKeyByIdentity = new Map();\r\n\r\n for (let index = 0; index < reader.records.length; index += 1)\r\n {\r\n const { offset } = reader.records[index];\r\n if (bodyKeyByOffset.has(offset)) continue;\r\n\r\n const bodyKey = `body_${bodyKeyByOffset.size}`;\r\n bodyKeyByOffset.set(offset, bodyKey);\r\n\r\n const description = reader.readDescription(index, { backend: true });\r\n const manifestStages = bodyManifestStages(description, reader.version, source);\r\n\r\n for (const technique of description.techniques)\r\n {\r\n const techniqueName = technique.name.value;\r\n for (const [ passIndex, pass ] of technique.passes.entries())\r\n {\r\n const passKey = `${techniqueName}.pass${passIndex}`;\r\n const { stages: backend, transforms } = backendStages(\r\n pass,\r\n passKey,\r\n source\r\n );\r\n\r\n for (const stage of pass.stages)\r\n {\r\n const name = hlslShaderStageName(stage.type);\r\n const stageKey = `${bodyKey}.${passKey}.${name}`;\r\n const stageBackend = backend[name] ?? {};\r\n\r\n let shaderKey;\r\n if (stage.shaderData?.size)\r\n {\r\n const code = new TextDecoder().decode(stage.shaderData.bytes);\r\n const identity = `${JSON.stringify([\r\n stageBackend.bindings ?? [],\r\n stageBackend.stageInputs ?? [],\r\n stageBackend.computeFragment ?? null\r\n ])} ${code}`;\r\n const pooled = shaderKeyByIdentity.get(identity);\r\n if (pooled)\r\n {\r\n shaderKey = pooled;\r\n }\r\n else\r\n {\r\n shaderKey = `shader_${shaderKeyByIdentity.size}`;\r\n shaderKeyByIdentity.set(identity, shaderKey);\r\n shaders.push({\r\n key: shaderKey,\r\n stageName: name,\r\n source: code,\r\n hlsl2webgl: { ok: true },\r\n bindings: stageBackend.bindings ?? [],\r\n stageInputs: stageBackend.stageInputs ?? [],\r\n ...(stageBackend.computeFragment\r\n ? { computeFragment: stageBackend.computeFragment }\r\n : {})\r\n });\r\n }\r\n }\r\n else\r\n {\r\n shaderKey = `${stageKey}.absent`;\r\n shaders.push({\r\n key: shaderKey,\r\n stageName: name,\r\n source: \"\",\r\n hlsl2webgl: { ok: false, reason: NO_PROGRAM_REASON },\r\n bindings: stageBackend.bindings ?? [],\r\n stageInputs: stageBackend.stageInputs ?? []\r\n });\r\n }\r\n\r\n stages.push({\r\n key: stageKey,\r\n bodyKey,\r\n techniqueName,\r\n passIndex,\r\n stageName: name,\r\n stageType: stage.type,\r\n shaderKey,\r\n manifest: manifestStages.get(`${passKey}.${name}`) ?? null,\r\n // The pass's transforms, so a rule can ask whether a\r\n // description resource was merged away rather than lost.\r\n transforms\r\n });\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Ordered by first appearance, matching `bodyKey`'s ordinal.\r\n const bodies = [];\r\n for (const [ offset, key ] of bodyKeyByOffset)\r\n {\r\n bodies.push({\r\n key,\r\n permutationIndices: Object.freeze(permutationIndicesByOffset.get(offset) ?? [])\r\n });\r\n }\r\n\r\n return {\r\n stages,\r\n shaders,\r\n bodies,\r\n recordCount: reader.records.length,\r\n bodyCount: bodyKeyByOffset.size\r\n };\r\n}\r\n\r\nexport default readGlslEffectContainer;\r\n"],"names":["NO_PROGRAM_REASON","bodyManifestStages","description","version","source","runtime","runtimeDescriptionFromCarbon","effectName","manifest","HlslEffectBindingManifest","fromEffectDescription","toJSON","Map","stages","map","stage","techniqueName","passIndex","stageName","backendStages","pass","passKey","backendBlock","size","transforms","block","readGlslBackendBlock","bytes","layoutKey","readGlslEffectContainer","input","values","reader","CjsCarbonEffectReader","shaders","bodyKeyByOffset","permutationIndicesByOffset","index","records","length","offset","seen","get","push","set","shaderKeyByIdentity","has","bodyKey","readDescription","backend","manifestStages","technique","techniques","name","value","passes","entries","hlslShaderStageName","type","stageKey","stageBackend","shaderKey","shaderData","code","TextDecoder","decode","identity","JSON","stringify","bindings","stageInputs","computeFragment","pooled","key","hlsl2webgl","ok","reason","stageType","bodies","permutationIndices","Object","freeze","recordCount","bodyCount"],"mappings":";;;;;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,MAAMA,iBAAiB,GAAG,uBAAuB;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,kBAAkBA,CAACC,WAAW,EAAEC,OAAO,EAAEC,MAAM,EACxD;AACI,EAAA,MAAMC,OAAO,GAAGC,4BAA4B,CAACJ,WAAW,EAAE;AACtDK,IAAAA,UAAU,EAAEH,MAAM;AAClBD,IAAAA;AACJ,GAAC,CAAC;EACF,MAAMK,QAAQ,GAAGC,yBAAyB,CAACC,qBAAqB,CAACL,OAAO,CAAC,CAACM,MAAM,EAAE;AAClF,EAAA,OAAO,IAAIC,GAAG,CAACJ,QAAQ,CAACK,MAAM,CAACC,GAAG,CAAEC,KAAK,IAAK,CAC1C,CAAA,EAAGA,KAAK,CA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,SAAS,EAAE9D,KAAK,CAAC2C,IAAI;YACrBG,SAAS;AACTrD,YAAAA,QAAQ,EAAE0C,cAAc,CAACR,GAAG,CAAC,CAAA,EAAGrB,OAAO,CAAA,CAAA,EAAIgC,IAAI,CAAA,CAAE,CAAC,IAAI,IAAI;AAC1D;AACA;AACA7B,YAAAA;AACJ,WAAC,CAAC;AACN,QAAA;AACJ,MAAA;AACJ,IAAA;AACJ,EAAA;;AAEA;EACA,MAAMsD,MAAM,GAAG,EAAE;EACjB,KAAK,MAAM,CAAEtC,MAAM,EAAEiC,GAAG,CAAE,IAAItC,eAAe,EAC7C;IACI2C,MAAM,CAACnC,IAAI,CAAC;MACR8B,GAAG;AACHM,MAAAA,kBAAkB,EAAEC,MAAM,CAACC,MAAM,CAAC7C,0BAA0B,CAACM,GAAG,CAACF,MAAM,CAAC,IAAI,EAAE;AAClF,KAAC,CAAC;AACN,EAAA;EAEA,OAAO;IACH3B,MAAM;IACNqB,OAAO;IACP4C,MAAM;AACNI,IAAAA,WAAW,EAAElD,MAAM,CAACM,OAAO,CAACC,MAAM;IAClC4C,SAAS,EAAEhD,eAAe,CAACZ;GAC9B;AACL;;;;"}
1
+ {"version":3,"file":"readGlslEffectContainer.js","sources":["../../../../../src/formats/webgl/core/readGlslEffectContainer.js"],"sourcesContent":["import { CjsCarbonEffectReader } from \"../../../format/carbonEffect/CjsCarbonEffectReader.js\";\nimport { readGlslBackendBlock } from \"./glslBackendBlock.js\";\nimport {\n CARBON_BACKEND_ENGINE_ID,\n peekBackendEngineId\n} from \"../../../format/carbonEffect/backendEngineId.js\";\nimport { hlslShaderStageName } from \"../../hlsl/core/tr2/HlslRenderContextEnum.js\";\nimport { runtimeDescriptionFromCarbon } from \"../../hlsl/core/carbonDescriptionToRuntime.js\";\nimport { HlslEffectBindingManifest } from \"../../hlsl/core/tr2/shader/HlslEffectBindingManifest.js\";\n\n/**\n * Decodes a WebGL effect container into the stage/shader records the\n * completeness rules consume.\n *\n * This exists so the rules run from container bytes alone. The alternative was\n * to hand them the in-memory translation, which works inside `buildEffectPackage`\n * and nowhere else — the validator reads a finished file and has no translation\n * in scope. That would have cost the validator its completeness check while\n * still requiring a decoder to produce the programs it compiles in a browser, so\n * it was strictly more work for strictly less checking.\n *\n * The vocabulary is deliberately the one the rules already speak — `stages` with\n * pass coordinates, `shaders` with source and a translation verdict. The rules\n * are about the translation, not about how it was stored, so retargeting them\n * meant changing where the records come from and nothing about what they mean.\n *\n * **What the wire cannot tell you.** `buildCarbonEffectContainer` stores a body\n * the translator could not lower as its full pass tree with zero-length\n * programs; the *reason* it failed stays in the in-memory build result and is\n * never written. So a shader decoded from bytes reports `ok: false` with\n * \"no program was stored\" and nothing more specific. That is the honest answer:\n * a file on disk does not know why a translation failed months ago. Callers that\n * do know — `buildEffectPackage`, at build time — keep their specific\n * diagnostics by feeding the rules their own records instead.\n */\n\n/** The verdict a stage carrying no stored program gets. */\nconst NO_PROGRAM_REASON = \"no program was stored\";\n\n/**\n * Derives the per-stage binding manifests for one body through the one\n * manifest builder the source path uses.\n *\n * This replaces a hand-built reshape of the wire records into the manifest\n * vocabulary. That copy had already diverged from the real manifest once —\n * `isAutoregister` was silently dropped, making every resource look\n * user-settable — which is the whole argument against a second producer: two\n * hand-maintained spellings of one reflection drift, and the drift is exactly\n * the kind of bug that draws, links and renders black without an error. The\n * record tree now flows through `runtimeDescriptionFromCarbon` — the\n * corpus-proven adapter the runtime read path uses — and\n * `HlslEffectBindingManifest`, so the container read and the build-time\n * package derive their manifests from the same code.\n *\n * No `bytecodeFor` is supplied: program text lives in the shader records this\n * reader emits, so the manifest's `shaderBytecode` stays null rather than\n * duplicating every program into the reflection.\n *\n * @param {object} description Decoded Carbon description record tree.\n * @param {number} version Container data version.\n * @param {string} source Source name for diagnostics.\n * @returns {Map<string, object>} Manifest stage records keyed by\n * `technique.passN.stageName`.\n */\nfunction bodyManifestStages(description, version, source)\n{\n const runtime = runtimeDescriptionFromCarbon(description, {\n effectName: source,\n version\n });\n const manifest = HlslEffectBindingManifest.fromEffectDescription(runtime).toJSON();\n return new Map(manifest.stages.map((stage) => [\n `${stage.techniqueName}.pass${stage.passIndex}.${stage.stageName}`,\n stage\n ]));\n}\n\n/**\n * Decodes one pass's backend block, tolerating a pass that has none.\n *\n * @param {object} pass Decoded pass record.\n * @param {string} passKey Enclosing pass key.\n * @param {string} source Source name for error details.\n * @returns {object} Per-stage backend data, keyed by stage name.\n */\nfunction backendStages(pass, passKey, source)\n{\n if (!pass.backendBlock?.size) return { stages: {}, transforms: [] };\n\n // A block belonging to another backend is not an error here. The container\n // is Carbon-shaped whatever it targets, and loading it must not depend on\n // being able to use its programs - a dx11 container loads and simply cannot\n // be executed by this library. Report no backend data and let prepare fail\n // where the backend actually matters.\n const engineId = peekBackendEngineId(pass.backendBlock.bytes);\n if (engineId !== CARBON_BACKEND_ENGINE_ID.webgl2)\n {\n return { stages: {}, transforms: [], foreignEngineId: engineId };\n }\n\n const block = readGlslBackendBlock(pass.backendBlock.bytes, { layoutKey: passKey, source });\n return { stages: block.stages ?? {}, transforms: block.transforms ?? [] };\n}\n\n/**\n * Decodes container bytes into stage and shader records.\n *\n * Bodies are decoded once each rather than once per permutation row: rows alias\n * onto shared bodies, and a rule that saw the same body 4,096 times would report\n * 4,096 identical incomplete passes.\n *\n * @param {Uint8Array|ArrayBuffer|Buffer|DataView} input Container payload.\n * @param {object} [values] Read values.\n * @param {string} [values.source] Source name, for diagnostics.\n * @returns {{stages:object[], shaders:object[], recordCount:number, bodyCount:number}}\n * Stage graph in the completeness rules' vocabulary.\n */\nexport function readGlslEffectContainer(input, values = {})\n{\n const source = values.source ?? \"memory\";\n const reader = new CjsCarbonEffectReader(input, { source });\n\n const stages = [];\n const shaders = [];\n const bodyKeyByOffset = new Map();\n\n // Every permutation index that resolves to each body.\n //\n // This is the bridge a caller actually needs, and the only one that is\n // sound. `bodyKey` here is this reader's own ordinal spelling; the\n // permutation graph mints `body${N}` for the same body, and the two are not\n // merely spelled differently — the graph dedupes by content (SHA-256 plus\n // byte equality) while this reader dedupes by source-record offset. Those\n // partitions coincide only because the container writer aliases\n // byte-identical bodies onto one offset, which is a property of the writer\n // rather than a contract.\n //\n // So a consumer must never map between the two by string surgery on either\n // spelling, and must not assume the two ordinal sequences agree. It holds a\n // permutation index; this gives it the body directly.\n const permutationIndicesByOffset = new Map();\n\n for (let index = 0; index < reader.records.length; index += 1)\n {\n const { offset } = reader.records[index];\n const seen = permutationIndicesByOffset.get(offset);\n if (seen) seen.push(index);\n else permutationIndicesByOffset.set(offset, [ index ]);\n }\n\n // Distinct program texts share one shader record, so `shaders` counts unique\n // translations the way the chunk package's shader table did. Empty stages are\n // deliberately *not* pooled: each keeps its own record so a report can name\n // every pass that is missing a program rather than one shared \"absent\".\n //\n // The pool key is the program text *and* the backend reflection that came\n // with it, not the text alone. A pooled record carries the bindings and\n // stage inputs of whichever stage was seen first, and\n // `validateShaderRuntimeContract` judges the emitted GLSL against them — so\n // pooling on text alone would let two stages with identical source but\n // different reflection be checked against the wrong metadata, silently. It\n // is unlikely that identical GLSL ever carries different reflection, which\n // is exactly why it would not be noticed.\n const shaderKeyByIdentity = new Map();\n\n for (let index = 0; index < reader.records.length; index += 1)\n {\n const { offset } = reader.records[index];\n if (bodyKeyByOffset.has(offset)) continue;\n\n const bodyKey = `body_${bodyKeyByOffset.size}`;\n bodyKeyByOffset.set(offset, bodyKey);\n\n const description = reader.readDescription(index, { backend: true });\n const manifestStages = bodyManifestStages(description, reader.version, source);\n\n for (const technique of description.techniques)\n {\n const techniqueName = technique.name.value;\n for (const [ passIndex, pass ] of technique.passes.entries())\n {\n const passKey = `${techniqueName}.pass${passIndex}`;\n const { stages: backend, transforms } = backendStages(\n pass,\n passKey,\n source\n );\n\n for (const stage of pass.stages)\n {\n const name = hlslShaderStageName(stage.type);\n const stageKey = `${bodyKey}.${passKey}.${name}`;\n const stageBackend = backend[name] ?? {};\n\n let shaderKey;\n if (stage.shaderData?.size)\n {\n const code = new TextDecoder().decode(stage.shaderData.bytes);\n const identity = `${JSON.stringify([\n stageBackend.bindings ?? [],\n stageBackend.stageInputs ?? [],\n stageBackend.computeFragment ?? null\n ])} ${code}`;\n const pooled = shaderKeyByIdentity.get(identity);\n if (pooled)\n {\n shaderKey = pooled;\n }\n else\n {\n shaderKey = `shader_${shaderKeyByIdentity.size}`;\n shaderKeyByIdentity.set(identity, shaderKey);\n shaders.push({\n key: shaderKey,\n stageName: name,\n source: code,\n hlsl2webgl: { ok: true },\n bindings: stageBackend.bindings ?? [],\n stageInputs: stageBackend.stageInputs ?? [],\n ...(stageBackend.computeFragment\n ? { computeFragment: stageBackend.computeFragment }\n : {})\n });\n }\n }\n else\n {\n shaderKey = `${stageKey}.absent`;\n shaders.push({\n key: shaderKey,\n stageName: name,\n source: \"\",\n hlsl2webgl: { ok: false, reason: NO_PROGRAM_REASON },\n bindings: stageBackend.bindings ?? [],\n stageInputs: stageBackend.stageInputs ?? []\n });\n }\n\n stages.push({\n key: stageKey,\n bodyKey,\n techniqueName,\n passIndex,\n stageName: name,\n stageType: stage.type,\n shaderKey,\n manifest: manifestStages.get(`${passKey}.${name}`) ?? null,\n // The pass's transforms, so a rule can ask whether a\n // description resource was merged away rather than lost.\n transforms\n });\n }\n }\n }\n }\n\n // Ordered by first appearance, matching `bodyKey`'s ordinal.\n const bodies = [];\n for (const [ offset, key ] of bodyKeyByOffset)\n {\n bodies.push({\n key,\n permutationIndices: Object.freeze(permutationIndicesByOffset.get(offset) ?? [])\n });\n }\n\n return {\n stages,\n shaders,\n bodies,\n recordCount: reader.records.length,\n bodyCount: bodyKeyByOffset.size\n };\n}\n\nexport default readGlslEffectContainer;\n"],"names":["NO_PROGRAM_REASON","bodyManifestStages","description","version","source","runtime","runtimeDescriptionFromCarbon","effectName","manifest","HlslEffectBindingManifest","fromEffectDescription","toJSON","Map","stages","map","stage","techniqueName","passIndex","stageName","backendStages","pass","passKey","backendBlock","size","transforms","engineId","peekBackendEngineId","bytes","CARBON_BACKEND_ENGINE_ID","webgl2","foreignEngineId","block","readGlslBackendBlock","layoutKey","readGlslEffectContainer","input","values","reader","CjsCarbonEffectReader","shaders","bodyKeyByOffset","permutationIndicesByOffset","index","records","length","offset","seen","get","push","set","shaderKeyByIdentity","has","bodyKey","readDescription","backend","manifestStages","technique","techniques","name","value","passes","entries","hlslShaderStageName","type","stageKey","stageBackend","shaderKey","shaderData","code","TextDecoder","decode","identity","JSON","stringify","bindings","stageInputs","computeFragment","pooled","key","hlsl2webgl","ok","reason","stageType","bodies","permutationIndices","Object","freeze","recordCount","bodyCount"],"mappings":";;;;;;;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,MAAMA,iBAAiB,GAAG,uBAAuB;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,kBAAkBA,CAACC,WAAW,EAAEC,OAAO,EAAEC,MAAM,EACxD;AACI,EAAA,MAAMC,OAAO,GAAGC,4BAA4B,CAACJ,WAAW,EAAE;AACtDK,IAAAA,UAAU,EAAEH,MAAM;AAClBD,IAAAA;AACJ,GAAC,CAAC;EACF,MAAMK,QAAQ,GAAGC,yBAAyB,CAACC,qBAAqB,CAACL,OAAO,CAAC,CAACM,MAAM,EAAE;AAClF,EAAA,OAAO,IAAIC,GAAG,CAACJ,QAAQ,CAACK,MAAM,CAACC,GAAG,CAAEC,KAAK,IAAK,CAC1C,CAAA,EAAGA,KAAK,CAACC,aAAa,CAAA,KAAA,EAAQD,KAAK,CAACE,SAAS,CAAA,CAAA,EAAIF,KAAK,CAACG,SAAS,CAAA,CAAE,EAClEH,KAAK,CACR,CAAC,CAAC;AACP;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SA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