@carbonenginejs/runtime-resource 0.16.0 → 0.17.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 (34) 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 +100 -0
  6. package/dist/format/carbonEffect/backendEngineId.js.map +1 -0
  7. package/dist/format/carbonEffect/carbonEffectBackendBlock.js +23 -23
  8. package/dist/format/carbonEffect/carbonEffectBackendBlock.js.map +1 -1
  9. package/dist/format/index.js +1 -1
  10. package/dist/formats/png/core/helpers.js +27 -8
  11. package/dist/formats/png/core/helpers.js.map +1 -1
  12. package/dist/formats/webgl/core/effectPackage.js +141 -53
  13. package/dist/formats/webgl/core/effectPackage.js.map +1 -1
  14. package/dist/formats/webgl/core/glsl/DxbcGlslEmitter.js +799 -456
  15. package/dist/formats/webgl/core/glsl/DxbcGlslEmitter.js.map +1 -1
  16. package/dist/formats/webgl/core/glslBackendBlock.js +70 -27
  17. package/dist/formats/webgl/core/glslBackendBlock.js.map +1 -1
  18. package/dist/formats/webgl/core/helpers.js +53 -53
  19. package/dist/formats/webgl/core/helpers.js.map +1 -1
  20. package/dist/formats/webgl/core/readGlslEffectContainer.js +82 -67
  21. package/dist/formats/webgl/core/readGlslEffectContainer.js.map +1 -1
  22. package/dist/formats/webgpu/core/carbonWebgpu/CarbonWebgpuContainer.js +10 -1
  23. package/dist/formats/webgpu/core/carbonWebgpu/CarbonWebgpuContainer.js.map +1 -1
  24. package/dist/formats/wem/CjsWemFormat.js +121 -121
  25. package/dist/formats/wem/CjsWemFormat.js.map +1 -1
  26. package/dist/formats/wem/core/resolve.js +8 -8
  27. package/dist/formats/wem/core/resolve.js.map +1 -1
  28. package/dist/resource/shader/reflection/Tr2EffectStageInput.js +102 -60
  29. package/dist/resource/shader/reflection/Tr2EffectStageInput.js.map +1 -1
  30. package/docs/concepts/format-type-resolution.md +79 -0
  31. package/docs/formats/README.md +11 -0
  32. package/docs/formats/wwise.md +25 -0
  33. package/docs/roadmap.md +19 -0
  34. package/package.json +1 -1
@@ -2,6 +2,7 @@ import { CjsByteWriter } from '../../../format/CjsByteWriter.js';
2
2
  import { CjsByteReader } from '../../../format/CjsByteReader.js';
3
3
  import { CjsFormatReadError, CjsFormatWriteError } from '../../../format/CjsFormatError.js';
4
4
  import { readInlineString, readTransformSection, writeInlineString, writeTransformSection } from '../../../format/carbonEffect/carbonEffectResourceTransform.js';
5
+ import { readBackendEngineId, CARBON_BACKEND_ENGINE_ID } from '../../../format/carbonEffect/backendEngineId.js';
5
6
  import { DxbcComponentTypeNames } from '../../dxbc/core/signature.js';
6
7
  import { DxbcResourceDimensionNames } from '../../dxbc/core/decoder.js';
7
8
 
@@ -17,9 +18,10 @@ import { DxbcResourceDimensionNames } from '../../dxbc/core/decoder.js';
17
18
  * synthesised data textures and UBOs, the vertex attribute ABI, and the recipe
18
19
  * for running a compute shader as a fragment pass.
19
20
  *
20
- * Both codecs start at their own version 1, and that is safe: which one parses a
21
- * given block is decided by the resource path the file came from, the same way
22
- * the backend itself is chosen. Nothing has to sniff.
21
+ * Which one parses a given block is decided by the resource path the file came
22
+ * from, the same way the backend itself is chosen so nothing has to sniff.
23
+ * The leading engine identifier then confirms that decision rather than
24
+ * replacing it, and disagreement is a hard error.
23
25
  *
24
26
  * ## Why identifiers are on the wire
25
27
  *
@@ -51,8 +53,38 @@ import { DxbcResourceDimensionNames } from '../../dxbc/core/decoder.js';
51
53
  * container the transform is the single source of truth for what merged.
52
54
  */
53
55
 
54
- /** Current block version. Bump when a field is added; readers may skip unknown. */
55
- const GLSL_BACKEND_BLOCK_VERSION = 1;
56
+ /**
57
+ * ## This block identifies itself, and carries no version of its own
58
+ *
59
+ * The first byte is `CARBON_BACKEND_ENGINE_ID.webgl2`. Until it existed, this
60
+ * writer and the WebGPU one both led with a `1` meaning unrelated things, so a
61
+ * block could not say what it was and identification relied on the caller
62
+ * already knowing.
63
+ *
64
+ * **Carbon's container version is the only version.** An independent counter
65
+ * here would be a second versioning axis over the same bytes, and the two would
66
+ * have to be reasoned about together at every change — while describing a block
67
+ * that is only ever written and read by the same build, because every consumer
68
+ * calls `buildEffect` and then `read` on its result in-process.
69
+ *
70
+ * A shape change is therefore not a compatibility event, it is a rebuild. Stale
71
+ * artifacts are deleted and regenerated rather than parsed by an older path, and
72
+ * the trailing-byte check at the end of the read is what catches a mismatch: a
73
+ * record that does not land exactly on its declared size is a hard error, not a
74
+ * degraded read.
75
+ *
76
+ * This replaced a private version byte whose v1 wrote sampler registers only for
77
+ * comparison sampling and recovered `comparison` as "that list is non-empty".
78
+ * Carrying the texture-to-sampler pairing for ordinary textures under that
79
+ * encoding would have marked every one of them a shadow sampler, so the two are
80
+ * now independent fields — as they always were independent facts.
81
+ *
82
+ * Why the pairing is here at all: D3D pairs a texture with a sampler at each
83
+ * sample site, GLSL merges the two into one uniform, and Carbon's reflection
84
+ * relates them nowhere. A consumer without this field can only match `t#`
85
+ * against `s#` by number, which is coincidence — see
86
+ * `/docs/contracts/texture-sampler-pairing.md`.
87
+ */
56
88
 
57
89
  /**
58
90
  * Stage names, as a wire index.
@@ -210,6 +242,12 @@ function writeBindingBody(writer, binding) {
210
242
  const samplers = binding.comparison ? binding.samplerRegisterIndices ?? [] : [];
211
243
  writer.u8(samplers.length);
212
244
  for (const register of samplers) writer.u8(register);
245
+ // v2: comparison is its own fact, not "the list above is non-empty",
246
+ // so the pairing below can be written for ordinary textures too.
247
+ writer.u8(binding.comparison ? 1 : 0);
248
+ const paired = binding.pairedSamplerRegisters ?? [];
249
+ writer.u8(paired.length);
250
+ for (const register of paired) writer.u8(register);
213
251
  break;
214
252
  }
215
253
  case "bufferTexture":
@@ -266,7 +304,15 @@ function readBindingBody(reader, kind) {
266
304
  for (let index = 0; index < samplerCount; index += 1) {
267
305
  samplerRegisterIndices.push(reader.readUint8());
268
306
  }
269
- const comparison = samplerCount > 0;
307
+ // Comparison is its own fact rather than "the register list above is
308
+ // non-empty", which is what frees the pairing below to be written
309
+ // for ordinary textures too.
310
+ const comparison = reader.readUint8() === 1;
311
+ const pairedSamplerRegisters = [];
312
+ const pairedCount = reader.readUint8();
313
+ for (let index = 0; index < pairedCount; index += 1) {
314
+ pairedSamplerRegisters.push(reader.readUint8());
315
+ }
270
316
  const samplerType = comparison ? SHADOW_SAMPLER_TYPE_BY_DIMENSION[dimension] : SAMPLER_TYPE_BY_DIMENSION[dimension];
271
317
  if (!samplerType) {
272
318
  throw new CjsFormatReadError(`Resource dimension ${dimension} has no ${comparison ? "shadow " : ""}sampler type`, {
@@ -277,6 +323,9 @@ function readBindingBody(reader, kind) {
277
323
  return {
278
324
  samplerType,
279
325
  dimensionName: DxbcResourceDimensionNames[dimension] ?? `dimension_${dimension}`,
326
+ ...(pairedSamplerRegisters.length ? {
327
+ pairedSamplerRegisters
328
+ } : {}),
280
329
  ...(comparison ? {
281
330
  comparison: true,
282
331
  samplerRegisterIndices
@@ -415,7 +464,7 @@ function readComputeFragment(reader) {
415
464
  function writeGlslBackendBlock(block) {
416
465
  const stages = block.stages ?? {};
417
466
  const writer = new CjsByteWriter(256);
418
- writer.u8(GLSL_BACKEND_BLOCK_VERSION);
467
+ writer.u8(CARBON_BACKEND_ENGINE_ID.webgl2);
419
468
 
420
469
  // Canonical stage order, not object insertion order: two passes with the
421
470
  // same lowering must produce the same bytes so the arena dedupes them.
@@ -474,18 +523,13 @@ function readGlslBackendBlock(bytes, options = {}) {
474
523
  source: options.source ?? "glsl backend block"
475
524
  });
476
525
  const layoutKey = options.layoutKey ?? null;
477
- const version = reader.readUint8();
478
- if (version > GLSL_BACKEND_BLOCK_VERSION) {
479
- // Forward compatibility: an unknown block version means a newer writer
480
- // added fields. Report the pass as having no backend data rather than
481
- // misparsing it; the enclosing `{size, offset}` pair makes it skippable.
482
- return {
483
- version,
484
- unsupported: true,
485
- stages: {},
486
- transforms: []
487
- };
488
- }
526
+
527
+ // Identity, then straight into the payload: no version byte is read because
528
+ // none is written. Carbon's container version is the only version, and a
529
+ // block whose shape does not match this build fails on the trailing-byte
530
+ // check below - the fix for which is to rebuild the package, never to add a
531
+ // branch.
532
+ readBackendEngineId(reader, CARBON_BACKEND_ENGINE_ID.webgl2, options.source ?? "glsl backend block");
489
533
  const stages = {};
490
534
  const stageCount = reader.readUint8();
491
535
  for (let index = 0; index < stageCount; index += 1) {
@@ -528,19 +572,18 @@ function readGlslBackendBlock(bytes, options = {}) {
528
572
  }
529
573
  const transforms = readTransformSection(reader, layoutKey);
530
574
 
531
- // A sized record parsed at a known version must land exactly on its declared
532
- // end. Trailing bytes mean the writer knew fields this reader does not - the
533
- // same skew an unknown version reports, arriving without a version bump.
575
+ // A sized record must land exactly on its declared end. Trailing bytes mean
576
+ // the writer knew fields this reader does not, which without a version byte
577
+ // is the ONLY signal that a block came from a different build - so this is
578
+ // load-bearing rather than defensive, and it is why removing the version is
579
+ // safe. The fix is always to rebuild the package.
534
580
  if (reader.remaining !== 0) {
535
- throw new CjsFormatReadError(`GLSL backend block has ${reader.remaining} unparsed trailing byte(s) at version ${version}`, {
581
+ throw new CjsFormatReadError(`GLSL backend block has ${reader.remaining} unparsed trailing byte(s); rebuild the effect package`, {
536
582
  source: options.source ?? "glsl backend block",
537
- version,
538
583
  trailingBytes: reader.remaining
539
584
  });
540
585
  }
541
586
  return {
542
- version,
543
- unsupported: false,
544
587
  layoutKey,
545
588
  stages,
546
589
  transforms,
@@ -548,5 +591,5 @@ function readGlslBackendBlock(bytes, options = {}) {
548
591
  };
549
592
  }
550
593
 
551
- export { GLSL_BACKEND_BINDING_KIND, GLSL_BACKEND_BLOCK_VERSION, GLSL_BACKEND_CONSTANT_BUFFER_STYLE, GLSL_BACKEND_STAGE, GLSL_LOCAL_LIGHT_ROLE, readGlslBackendBlock, writeGlslBackendBlock };
594
+ export { GLSL_BACKEND_BINDING_KIND, GLSL_BACKEND_CONSTANT_BUFFER_STYLE, GLSL_BACKEND_STAGE, GLSL_LOCAL_LIGHT_ROLE, readGlslBackendBlock, writeGlslBackendBlock };
552
595
  //# sourceMappingURL=glslBackendBlock.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"glslBackendBlock.js","sources":["../../../../../src/formats/webgl/core/glslBackendBlock.js"],"sourcesContent":["import { CjsByteWriter } from \"../../../format/CjsByteWriter.js\";\nimport { CjsByteReader } from \"../../../format/CjsByteReader.js\";\nimport { CjsFormatReadError, CjsFormatWriteError } from \"../../../format/CjsFormatError.js\";\nimport {\n readInlineString,\n readTransformSection,\n writeInlineString,\n writeTransformSection\n} from \"../../../format/carbonEffect/carbonEffectResourceTransform.js\";\nimport { DxbcComponentTypeNames } from \"../../dxbc/core/signature.js\";\nimport { DxbcResourceDimensionNames } from \"../../dxbc/core/decoder.js\";\n\n/**\n * The WebGL 2 pass block: what the GLSL text declares but cannot say how to\n * build or bind.\n *\n * This is the GLSL counterpart of `carbonEffectBackendBlock.js`, occupying the\n * same one optional trailing block per pass, and it shares that file's\n * resource-transform section verbatim. Everything else differs, because the two\n * backends' lowering decisions are genuinely different documents: WebGPU records\n * bind-group topology, while WebGL 2 records sampler and uniform declarations,\n * synthesised data textures and UBOs, the vertex attribute ABI, and the recipe\n * for running a compute shader as a fragment pass.\n *\n * Both codecs start at their own version 1, and that is safe: which one parses a\n * given block is decided by the resource path the file came from, the same way\n * the backend itself is chosen. Nothing has to sniff.\n *\n * ## Why identifiers are on the wire\n *\n * `docs/contracts/constant-buffer-slots.md` establishes that a constant buffer's\n * register index is its meaning, and that identifiers are positional. That is\n * true of the *contract* but not sufficient to derive a name here: the pixel\n * stage remaps slot 0 to `cb7` (`DxbcGlslEmitter.js`, `pixelConstantBufferRemap`),\n * so an identifier is a function of register **and stage**, through a profile\n * table. A reader deriving names would be re-implementing the emitter's naming\n * policy, and a divergence would surface as a uniform that silently never binds\n * rather than as an error. The name is the actual link between this block and\n * the GLSL text, so it is stored and the text stays checkable against it.\n *\n * What is genuinely derived: the sampler type (a total function of the DXBC\n * resource dimension and whether comparison sampling is used) and the data\n * texture formats (constant per binding kind).\n *\n * ## What this block deliberately does not carry\n *\n * **Resource names.** The enclosing Carbon description already lists every\n * texture with its name and register, interned in the string table exactly as a\n * shipped Carbon file does. That is the name authority, and duplicating it here\n * would create two places to disagree.\n *\n * **Merge layer counts.** A merged detail-map array's layer count is the number\n * of inputs on its transform in the section below. The emitter also reports\n * `arrayLayerCount` and `mergedFrom` on the binding for standalone callers with\n * no container around them, and those are intentionally not stored: inside a\n * container the transform is the single source of truth for what merged.\n */\n\n/** Current block version. Bump when a field is added; readers may skip unknown. */\nexport const GLSL_BACKEND_BLOCK_VERSION = 1;\n\n/**\n * Stage names, as a wire index.\n *\n * These are the emitter's own names, which are Carbon's and D3D's: the pixel\n * stage is `pixel`, not `fragment`. The WebGPU block's visibility enum says\n * `fragment` because that is WGSL's word. Neither is translated into the other -\n * each block speaks its own backend's vocabulary, and the stage a record belongs\n * to is never inferred across the two.\n */\nexport const GLSL_BACKEND_STAGE = Object.freeze([ \"vertex\", \"pixel\", \"compute\" ]);\n\n/**\n * Binding kinds, ordered so the wire value is stable. These are the emitter's\n * own `binding.kind` values (`DxbcGlslEmitter.js`).\n */\nexport const GLSL_BACKEND_BINDING_KIND = Object.freeze([\n \"constantBuffer\",\n \"resource\",\n \"bufferTexture\",\n \"structuredTexture\",\n \"structuredUbo\",\n \"uavTexture\",\n \"dispatchUniform\"\n]);\n\n/** Constant-buffer declaration styles. */\nexport const GLSL_BACKEND_CONSTANT_BUFFER_STYLE = Object.freeze([ \"array\", \"std140\" ]);\n\n/** Sampler type per WebGL2-supported DXBC resource dimension. */\nconst SAMPLER_TYPE_BY_DIMENSION = Object.freeze({\n 2: \"sampler2D\",\n 3: \"sampler2D\",\n 5: \"sampler3D\",\n 6: \"samplerCube\",\n 8: \"sampler2DArray\"\n});\n\n/** Shadow-sampler type per WebGL2-supported DXBC resource dimension. */\nconst SHADOW_SAMPLER_TYPE_BY_DIMENSION = Object.freeze({\n 3: \"sampler2DShadow\",\n 6: \"samplerCubeShadow\",\n 8: \"sampler2DArrayShadow\"\n});\n\n/** Texel formats a synthesised data texture always uses, by binding kind. */\nconst DATA_TEXTURE_FORMAT = Object.freeze({\n bufferTexture: \"RGBA32F\",\n structuredTexture: \"RGBA32UI\"\n});\n\n/** Marks an absent optional `u8`. */\nconst ABSENT_U8 = 0xff;\n\n/**\n * Local-light lowering roles, as a wire index.\n *\n * Carbon puts local lights in two structured buffers plus a profile texture.\n * WebGL 2 has no structured buffers at all, so they have to be re-expressed —\n * this is a *storage* change, not a shading one, and without it the affected\n * shaders cannot bind their lights.\n *\n * The emitter still spells the role `cjsSemantic` on its binding records. That\n * name is not carried onto the wire: it names a defunct package format rather\n * than the thing it describes. Renaming it at the emitter is a separate change.\n */\nexport const GLSL_LOCAL_LIGHT_ROLE = Object.freeze([ \"packed-texture\", \"constant-buffer\" ]);\n\n/** Emitter `cjsSemantic` values, in the same order as the roles above. */\nconst EMITTER_LIGHT_SEMANTIC = Object.freeze([ \"packedLocalLights\", \"localLights\" ]);\n\n/**\n * Writes the optional local-light lowering record.\n *\n * Carries the source registers so a consumer can tie the synthesised resource\n * back to the Carbon resources it replaced, which is otherwise unrecoverable:\n * the shader no longer declares them.\n *\n * @param {CjsByteWriter} writer Target writer.\n * @param {object} binding Emitter binding record.\n */\nfunction writeLocalLightRecord(writer, binding)\n{\n const role = EMITTER_LIGHT_SEMANTIC.indexOf(binding.cjsSemantic);\n\n if (!binding.cjsSemantic)\n {\n writer.u8(0);\n return;\n }\n\n if (role < 0)\n {\n throw new CjsFormatWriteError(\n `Binding \"${binding.name}\" carries unknown local-light role \"${binding.cjsSemantic}\"`,\n { name: binding.name, semantic: binding.cjsSemantic }\n );\n }\n\n writer.u8(1);\n writer.u8(role);\n writer.u8(binding.lightIndexRegister);\n writer.u8(binding.lightDataRegister);\n // The profile array is optional: some permutations never sample it, and the\n // lowering replaces it with neutral attenuation when it is absent.\n writer.u8(binding.lightProfileRegister ?? ABSENT_U8);\n writer.u32(binding.dataTexelBase ?? 0);\n writer.u16(binding.capacityLights ?? 0);\n}\n\n/**\n * Reads the optional local-light lowering record.\n *\n * @param {CjsByteReader} reader Source reader.\n * @returns {object|null} Local-light fields, or null when the binding is ordinary.\n */\nfunction readLocalLightRecord(reader)\n{\n if (!reader.readUint8()) return null;\n\n const role = GLSL_LOCAL_LIGHT_ROLE[reader.readUint8()];\n const lightIndexRegister = reader.readUint8();\n const lightDataRegister = reader.readUint8();\n const profile = reader.readUint8();\n const dataTexelBase = reader.readUint32();\n const capacityLights = reader.readUint16();\n\n return {\n localLightRole: role,\n lightIndexRegister,\n lightDataRegister,\n lightProfileRegister: profile === ABSENT_U8 ? null : profile,\n ...(role === \"packed-texture\" ? { dataTexelBase } : {}),\n ...(role === \"constant-buffer\" ? { capacityLights } : {})\n };\n}\n\n/**\n * Writes one binding's kind-specific payload.\n *\n * @param {CjsByteWriter} writer Target writer.\n * @param {object} binding Emitter binding record.\n */\nfunction writeBindingBody(writer, binding)\n{\n switch (binding.kind)\n {\n case \"constantBuffer\": {\n const style = GLSL_BACKEND_CONSTANT_BUFFER_STYLE.indexOf(binding.style ?? \"array\");\n if (style < 0)\n {\n throw new CjsFormatWriteError(\n `Unknown constant-buffer style \"${binding.style}\"`, { style: binding.style }\n );\n }\n writer.u16(binding.sizeInVec4);\n writer.u8(style);\n writeLocalLightRecord(writer, binding);\n break;\n }\n case \"resource\": {\n const dimension = DxbcResourceDimensionNames.indexOf(binding.dimensionName);\n if (dimension < 0)\n {\n throw new CjsFormatWriteError(\n `Unknown resource dimension \"${binding.dimensionName}\"`,\n { dimensionName: binding.dimensionName }\n );\n }\n writer.u8(dimension);\n const samplers = binding.comparison ? binding.samplerRegisterIndices ?? [] : [];\n writer.u8(samplers.length);\n for (const register of samplers) writer.u8(register);\n break;\n }\n case \"bufferTexture\":\n writer.u16(binding.width);\n writeStringList(writer, binding.returnTypes);\n break;\n case \"structuredTexture\":\n writer.u32(binding.strideBytes ?? 0);\n writer.u16(binding.width);\n writeLocalLightRecord(writer, binding);\n break;\n case \"structuredUbo\":\n writer.u32(binding.strideBytes ?? 0);\n writer.u16(binding.capacityElements);\n break;\n case \"uavTexture\":\n writer.u8(binding.slice ?? ABSENT_U8);\n writer.u8(binding.location);\n writeStringList(writer, binding.returnTypes);\n break;\n case \"dispatchUniform\":\n break;\n default:\n throw new CjsFormatWriteError(`Unknown binding kind \"${binding.kind}\"`, {\n kind: binding.kind\n });\n }\n}\n\n/**\n * Reads one binding's kind-specific payload, restoring derived fields.\n *\n * @param {CjsByteReader} reader Source reader.\n * @param {string} kind Binding kind.\n * @returns {object} Kind-specific fields.\n */\nfunction readBindingBody(reader, kind)\n{\n switch (kind)\n {\n case \"constantBuffer\": {\n const sizeInVec4 = reader.readUint16();\n const style = GLSL_BACKEND_CONSTANT_BUFFER_STYLE[reader.readUint8()];\n return { sizeInVec4, style, ...(readLocalLightRecord(reader) ?? {}) };\n }\n case \"resource\": {\n const dimension = reader.readUint8();\n const samplerCount = reader.readUint8();\n const samplerRegisterIndices = [];\n for (let index = 0; index < samplerCount; index += 1)\n {\n samplerRegisterIndices.push(reader.readUint8());\n }\n const comparison = samplerCount > 0;\n const samplerType = comparison\n ? SHADOW_SAMPLER_TYPE_BY_DIMENSION[dimension]\n : SAMPLER_TYPE_BY_DIMENSION[dimension];\n\n if (!samplerType)\n {\n throw new CjsFormatReadError(\n `Resource dimension ${dimension} has no ${comparison ? \"shadow \" : \"\"}sampler type`,\n { dimension, comparison }\n );\n }\n\n return {\n samplerType,\n dimensionName: DxbcResourceDimensionNames[dimension] ?? `dimension_${dimension}`,\n ...(comparison ? { comparison: true, samplerRegisterIndices } : {})\n };\n }\n case \"bufferTexture\":\n return {\n format: DATA_TEXTURE_FORMAT.bufferTexture,\n width: reader.readUint16(),\n returnTypes: readStringList(reader)\n };\n case \"structuredTexture\": {\n const strideBytes = reader.readUint32();\n const width = reader.readUint16();\n return {\n strideBytes,\n format: DATA_TEXTURE_FORMAT.structuredTexture,\n width,\n ...(readLocalLightRecord(reader) ?? {})\n };\n }\n case \"structuredUbo\":\n return {\n strideBytes: reader.readUint32(),\n capacityElements: reader.readUint16()\n };\n case \"uavTexture\": {\n const slice = reader.readUint8();\n return {\n slice: slice === ABSENT_U8 ? null : slice,\n location: reader.readUint8(),\n returnTypes: readStringList(reader)\n };\n }\n case \"dispatchUniform\":\n return {};\n default:\n throw new CjsFormatReadError(`Unknown binding kind \"${kind}\"`, { kind });\n }\n}\n\n/**\n * Writes an optional count-prefixed string list.\n *\n * @param {CjsByteWriter} writer Target writer.\n * @param {string[]|null} values String list, or null.\n */\nfunction writeStringList(writer, values)\n{\n const list = Array.isArray(values) ? values : [];\n writer.u8(list.length);\n for (const value of list) writeInlineString(writer, value);\n}\n\n/**\n * Reads an optional count-prefixed string list.\n *\n * @param {CjsByteReader} reader Source reader.\n * @returns {string[]|null} String list, or null when empty.\n */\nfunction readStringList(reader)\n{\n const count = reader.readUint8();\n if (!count) return null;\n\n const values = [];\n for (let index = 0; index < count; index += 1) values.push(readInlineString(reader));\n return values;\n}\n\n/**\n * Writes the compute-as-fragment section.\n *\n * @param {CjsByteWriter} writer Target writer.\n * @param {object|null} computeFragment Compute-fragment contract, or null.\n */\nfunction writeComputeFragment(writer, computeFragment)\n{\n if (!computeFragment)\n {\n writer.u8(0);\n return;\n }\n\n writer.u8(1);\n const threadGroup = computeFragment.threadGroup;\n writer.u8(threadGroup ? 1 : 0);\n if (threadGroup) for (const extent of threadGroup) writer.u16(extent);\n writeInlineString(writer, computeFragment.dispatchOriginUniform ?? \"\");\n\n const outputs = computeFragment.uavOutputs ?? [];\n writer.u8(outputs.length);\n for (const output of outputs)\n {\n writer.u8(output.register);\n writer.u8(output.slice ?? ABSENT_U8);\n writer.u8(output.location);\n writeInlineString(writer, output.glslName);\n }\n}\n\n/**\n * Reads the compute-as-fragment section.\n *\n * @param {CjsByteReader} reader Source reader.\n * @returns {object|null} Compute-fragment contract, or null.\n */\nfunction readComputeFragment(reader)\n{\n if (!reader.readUint8()) return null;\n\n const threadGroup = reader.readUint8()\n ? [ reader.readUint16(), reader.readUint16(), reader.readUint16() ]\n : null;\n const dispatchOriginUniform = readInlineString(reader);\n\n const uavOutputs = [];\n const outputCount = reader.readUint8();\n for (let index = 0; index < outputCount; index += 1)\n {\n const register = reader.readUint8();\n const slice = reader.readUint8();\n uavOutputs.push({\n register,\n slice: slice === ABSENT_U8 ? null : slice,\n location: reader.readUint8(),\n glslName: readInlineString(reader)\n });\n }\n\n return {\n threadGroup,\n dispatchOriginUniform: dispatchOriginUniform === \"\" ? null : dispatchOriginUniform,\n uavOutputs\n };\n}\n\n/**\n * Serialises one pass's GLSL backend block.\n *\n * @param {object} block Block contents.\n * @param {object} [block.stages] Per-stage lowering data, keyed by stage name.\n * @param {object[]} [block.transforms] Resource transforms.\n * @returns {Uint8Array} Self-contained block bytes.\n */\nexport function writeGlslBackendBlock(block)\n{\n const stages = block.stages ?? {};\n const writer = new CjsByteWriter(256);\n\n writer.u8(GLSL_BACKEND_BLOCK_VERSION);\n\n // Canonical stage order, not object insertion order: two passes with the\n // same lowering must produce the same bytes so the arena dedupes them.\n const present = GLSL_BACKEND_STAGE.filter((name) => stages[name]);\n writer.u8(present.length);\n\n for (const stageName of present)\n {\n const stage = stages[stageName];\n writer.u8(GLSL_BACKEND_STAGE.indexOf(stageName));\n\n const bindings = stage.bindings ?? [];\n writer.u8(bindings.length);\n for (const binding of bindings)\n {\n const kind = GLSL_BACKEND_BINDING_KIND.indexOf(binding.kind);\n if (kind < 0)\n {\n throw new CjsFormatWriteError(`Unknown binding kind \"${binding.kind}\"`, {\n kind: binding.kind\n });\n }\n writer.u8(kind);\n writer.u8(binding.registerIndex ?? ABSENT_U8);\n writeInlineString(writer, binding.name);\n writeBindingBody(writer, binding);\n }\n\n const stageInputs = stage.stageInputs ?? [];\n writer.u8(stageInputs.length);\n for (const input of stageInputs)\n {\n const componentType = DxbcComponentTypeNames.indexOf(input.componentTypeName);\n if (componentType < 0)\n {\n throw new CjsFormatWriteError(\n `Unknown component type \"${input.componentTypeName}\"`,\n { componentTypeName: input.componentTypeName }\n );\n }\n writer.u8(input.register);\n writeInlineString(writer, input.name);\n writeInlineString(writer, input.semanticName);\n writer.u8(input.semanticIndex);\n writer.u8(componentType);\n writer.u8(input.mask);\n }\n\n writeComputeFragment(writer, stage.computeFragment ?? null);\n }\n\n writeTransformSection(writer, block.transforms ?? []);\n\n return writer.toBytes();\n}\n\n/**\n * Parses one pass's GLSL backend block, restoring every derived field.\n *\n * @param {ArrayBuffer|ArrayBufferView|Uint8Array} bytes Block bytes.\n * @param {object} [options] Read options.\n * @param {string} [options.layoutKey] Enclosing pass key, restored onto records.\n * @param {string} [options.source] Source name for error details.\n * @returns {object} Block contents with derived fields restored.\n */\nexport function readGlslBackendBlock(bytes, options = {})\n{\n const reader = new CjsByteReader(bytes, { source: options.source ?? \"glsl backend block\" });\n const layoutKey = options.layoutKey ?? null;\n\n const version = reader.readUint8();\n if (version > GLSL_BACKEND_BLOCK_VERSION)\n {\n // Forward compatibility: an unknown block version means a newer writer\n // added fields. Report the pass as having no backend data rather than\n // misparsing it; the enclosing `{size, offset}` pair makes it skippable.\n return { version, unsupported: true, stages: {}, transforms: [] };\n }\n\n const stages = {};\n const stageCount = reader.readUint8();\n\n for (let index = 0; index < stageCount; index += 1)\n {\n const stageName = GLSL_BACKEND_STAGE[reader.readUint8()];\n\n const bindings = [];\n const bindingCount = reader.readUint8();\n for (let bindingIndex = 0; bindingIndex < bindingCount; bindingIndex += 1)\n {\n const kind = GLSL_BACKEND_BINDING_KIND[reader.readUint8()];\n const registerIndex = reader.readUint8();\n const name = readInlineString(reader);\n bindings.push({\n kind,\n ...(registerIndex === ABSENT_U8 ? {} : { registerIndex }),\n name,\n ...readBindingBody(reader, kind)\n });\n }\n\n const stageInputs = [];\n const stageInputCount = reader.readUint8();\n for (let inputIndex = 0; inputIndex < stageInputCount; inputIndex += 1)\n {\n stageInputs.push({\n register: reader.readUint8(),\n name: readInlineString(reader),\n semanticName: readInlineString(reader),\n semanticIndex: reader.readUint8(),\n componentTypeName: DxbcComponentTypeNames[reader.readUint8()],\n mask: reader.readUint8()\n });\n }\n\n const computeFragment = readComputeFragment(reader);\n\n stages[stageName] = {\n bindings,\n stageInputs,\n ...(computeFragment ? { computeFragment } : {})\n };\n }\n\n const transforms = readTransformSection(reader, layoutKey);\n\n // A sized record parsed at a known version must land exactly on its declared\n // end. Trailing bytes mean the writer knew fields this reader does not - the\n // same skew an unknown version reports, arriving without a version bump.\n if (reader.remaining !== 0)\n {\n throw new CjsFormatReadError(\n `GLSL backend block has ${reader.remaining} unparsed trailing byte(s) at version ${version}`,\n {\n source: options.source ?? \"glsl backend block\",\n version,\n trailingBytes: reader.remaining\n }\n );\n }\n\n return { version, unsupported: false, layoutKey, stages, transforms, trailingBytes: 0 };\n}\n"],"names":["GLSL_BACKEND_BLOCK_VERSION","GLSL_BACKEND_STAGE","Object","freeze","GLSL_BACKEND_BINDING_KIND","GLSL_BACKEND_CONSTANT_BUFFER_STYLE","SAMPLER_TYPE_BY_DIMENSION","SHADOW_SAMPLER_TYPE_BY_DIMENSION","DATA_TEXTURE_FORMAT","bufferTexture","structuredTexture","ABSENT_U8","GLSL_LOCAL_LIGHT_ROLE","EMITTER_LIGHT_SEMANTIC","writeLocalLightRecord","writer","binding","role","indexOf","cjsSemantic","u8","CjsFormatWriteError","name","semantic","lightIndexRegister","lightDataRegister","lightProfileRegister","u32","dataTexelBase","u16","capacityLights","readLocalLightRecord","reader","readUint8","profile","readUint32","readUint16","localLightRole","writeBindingBody","kind","style","sizeInVec4","dimension","DxbcResourceDimensionNames","dimensionName","samplers","comparison","samplerRegisterIndices","length","register","width","writeStringList","returnTypes","strideBytes","capacityElements","slice","location","readBindingBody","samplerCount","index","push","samplerType","CjsFormatReadError","format","readStringList","values","list","Array","isArray","value","writeInlineString","count","readInlineString","writeComputeFragment","computeFragment","threadGroup","extent","dispatchOriginUniform","outputs","uavOutputs","output","glslName","readComputeFragment","outputCount","writeGlslBackendBlock","block","stages","CjsByteWriter","present","filter","stageName","stage","bindings","registerIndex","stageInputs","input","componentType","DxbcComponentTypeNames","componentTypeName","semanticName","semanticIndex","mask","writeTransformSection","transforms","toBytes","readGlslBackendBlock","bytes","options","CjsByteReader","source","layoutKey","version","unsupported","stageCount","bindingCount","bindingIndex","stageInputCount","inputIndex","readTransformSection","remaining","trailingBytes"],"mappings":";;;;;;;AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACO,MAAMA,0BAA0B,GAAG;;AAE1C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,kBAAkB,GAAGC,MAAM,CAACC,MAAM,CAAC,CAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAE;;AAEhF;AACA;AACA;AACA;AACO,MAAMC,yBAAyB,GAAGF,MAAM,CAACC,MAAM,CAAC,CACnD,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,iBAAiB,CACpB;;AAED;AACO,MAAME,kCAAkC,GAAGH,MAAM,CAACC,MAAM,CAAC,CAAE,OAAO,EAAE,QAAQ,CAAE;;AAErF;AACA,MAAMG,yBAAyB,GAAGJ,MAAM,CAACC,MAAM,CAAC;AAC5C,EAAA,CAAC,EAAE,WAAW;AACd,EAAA,CAAC,EAAE,WAAW;AACd,EAAA,CAAC,EAAE,WAAW;AACd,EAAA,CAAC,EAAE,aAAa;AAChB,EAAA,CAAC,EAAE;AACP,CAAC,C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6B,UAAU,GAAGe,oBAAoB,CAACtF,MAAM,EAAE8E,SAAS,CAAC;;AAE1D;AACA;AACA;AACA,EAAA,IAAI9E,MAAM,CAACuF,SAAS,KAAK,CAAC,EAC1B;IACI,MAAM,IAAIzD,kBAAkB,CACxB,CAAA,uBAAA,EAA0B9B,MAAM,CAACuF,SAAS,CAAA,sCAAA,EAAyCR,OAAO,CAAA,CAAE,EAC5F;AACIF,MAAAA,MAAM,EAAEF,OAAO,CAACE,MAAM,IAAI,oBAAoB;MAC9CE,OAAO;MACPS,aAAa,EAAExF,MAAM,CAACuF;AAC1B,KACJ,CAAC;AACL,EAAA;EAEA,OAAO;IAAER,OAAO;AAAEC,IAAAA,WAAW,EAAE,KAAK;IAAEF,SAAS;IAAExB,MAAM;IAAEiB,UAAU;AAAEiB,IAAAA,aAAa,EAAE;GAAG;AAC3F;;;;"}
1
+ {"version":3,"file":"glslBackendBlock.js","sources":["../../../../../src/formats/webgl/core/glslBackendBlock.js"],"sourcesContent":["import { CjsByteWriter } from \"../../../format/CjsByteWriter.js\";\nimport { CjsByteReader } from \"../../../format/CjsByteReader.js\";\nimport { CjsFormatReadError, CjsFormatWriteError } from \"../../../format/CjsFormatError.js\";\nimport {\n readInlineString,\n readTransformSection,\n writeInlineString,\n writeTransformSection\n} from \"../../../format/carbonEffect/carbonEffectResourceTransform.js\";\nimport {\n CARBON_BACKEND_ENGINE_ID,\n readBackendEngineId\n} from \"../../../format/carbonEffect/backendEngineId.js\";\nimport { DxbcComponentTypeNames } from \"../../dxbc/core/signature.js\";\nimport { DxbcResourceDimensionNames } from \"../../dxbc/core/decoder.js\";\n\n/**\n * The WebGL 2 pass block: what the GLSL text declares but cannot say how to\n * build or bind.\n *\n * This is the GLSL counterpart of `carbonEffectBackendBlock.js`, occupying the\n * same one optional trailing block per pass, and it shares that file's\n * resource-transform section verbatim. Everything else differs, because the two\n * backends' lowering decisions are genuinely different documents: WebGPU records\n * bind-group topology, while WebGL 2 records sampler and uniform declarations,\n * synthesised data textures and UBOs, the vertex attribute ABI, and the recipe\n * for running a compute shader as a fragment pass.\n *\n * Which one parses a given block is decided by the resource path the file came\n * from, the same way the backend itself is chosen — so nothing has to sniff.\n * The leading engine identifier then confirms that decision rather than\n * replacing it, and disagreement is a hard error.\n *\n * ## Why identifiers are on the wire\n *\n * `docs/contracts/constant-buffer-slots.md` establishes that a constant buffer's\n * register index is its meaning, and that identifiers are positional. That is\n * true of the *contract* but not sufficient to derive a name here: the pixel\n * stage remaps slot 0 to `cb7` (`DxbcGlslEmitter.js`, `pixelConstantBufferRemap`),\n * so an identifier is a function of register **and stage**, through a profile\n * table. A reader deriving names would be re-implementing the emitter's naming\n * policy, and a divergence would surface as a uniform that silently never binds\n * rather than as an error. The name is the actual link between this block and\n * the GLSL text, so it is stored and the text stays checkable against it.\n *\n * What is genuinely derived: the sampler type (a total function of the DXBC\n * resource dimension and whether comparison sampling is used) and the data\n * texture formats (constant per binding kind).\n *\n * ## What this block deliberately does not carry\n *\n * **Resource names.** The enclosing Carbon description already lists every\n * texture with its name and register, interned in the string table exactly as a\n * shipped Carbon file does. That is the name authority, and duplicating it here\n * would create two places to disagree.\n *\n * **Merge layer counts.** A merged detail-map array's layer count is the number\n * of inputs on its transform in the section below. The emitter also reports\n * `arrayLayerCount` and `mergedFrom` on the binding for standalone callers with\n * no container around them, and those are intentionally not stored: inside a\n * container the transform is the single source of truth for what merged.\n */\n\n/**\n * ## This block identifies itself, and carries no version of its own\n *\n * The first byte is `CARBON_BACKEND_ENGINE_ID.webgl2`. Until it existed, this\n * writer and the WebGPU one both led with a `1` meaning unrelated things, so a\n * block could not say what it was and identification relied on the caller\n * already knowing.\n *\n * **Carbon's container version is the only version.** An independent counter\n * here would be a second versioning axis over the same bytes, and the two would\n * have to be reasoned about together at every change — while describing a block\n * that is only ever written and read by the same build, because every consumer\n * calls `buildEffect` and then `read` on its result in-process.\n *\n * A shape change is therefore not a compatibility event, it is a rebuild. Stale\n * artifacts are deleted and regenerated rather than parsed by an older path, and\n * the trailing-byte check at the end of the read is what catches a mismatch: a\n * record that does not land exactly on its declared size is a hard error, not a\n * degraded read.\n *\n * This replaced a private version byte whose v1 wrote sampler registers only for\n * comparison sampling and recovered `comparison` as \"that list is non-empty\".\n * Carrying the texture-to-sampler pairing for ordinary textures under that\n * encoding would have marked every one of them a shadow sampler, so the two are\n * now independent fields — as they always were independent facts.\n *\n * Why the pairing is here at all: D3D pairs a texture with a sampler at each\n * sample site, GLSL merges the two into one uniform, and Carbon's reflection\n * relates them nowhere. A consumer without this field can only match `t#`\n * against `s#` by number, which is coincidence — see\n * `/docs/contracts/texture-sampler-pairing.md`.\n */\n\n/**\n * Stage names, as a wire index.\n *\n * These are the emitter's own names, which are Carbon's and D3D's: the pixel\n * stage is `pixel`, not `fragment`. The WebGPU block's visibility enum says\n * `fragment` because that is WGSL's word. Neither is translated into the other -\n * each block speaks its own backend's vocabulary, and the stage a record belongs\n * to is never inferred across the two.\n */\nexport const GLSL_BACKEND_STAGE = Object.freeze([ \"vertex\", \"pixel\", \"compute\" ]);\n\n/**\n * Binding kinds, ordered so the wire value is stable. These are the emitter's\n * own `binding.kind` values (`DxbcGlslEmitter.js`).\n */\nexport const GLSL_BACKEND_BINDING_KIND = Object.freeze([\n \"constantBuffer\",\n \"resource\",\n \"bufferTexture\",\n \"structuredTexture\",\n \"structuredUbo\",\n \"uavTexture\",\n \"dispatchUniform\"\n]);\n\n/** Constant-buffer declaration styles. */\nexport const GLSL_BACKEND_CONSTANT_BUFFER_STYLE = Object.freeze([ \"array\", \"std140\" ]);\n\n/** Sampler type per WebGL2-supported DXBC resource dimension. */\nconst SAMPLER_TYPE_BY_DIMENSION = Object.freeze({\n 2: \"sampler2D\",\n 3: \"sampler2D\",\n 5: \"sampler3D\",\n 6: \"samplerCube\",\n 8: \"sampler2DArray\"\n});\n\n/** Shadow-sampler type per WebGL2-supported DXBC resource dimension. */\nconst SHADOW_SAMPLER_TYPE_BY_DIMENSION = Object.freeze({\n 3: \"sampler2DShadow\",\n 6: \"samplerCubeShadow\",\n 8: \"sampler2DArrayShadow\"\n});\n\n/** Texel formats a synthesised data texture always uses, by binding kind. */\nconst DATA_TEXTURE_FORMAT = Object.freeze({\n bufferTexture: \"RGBA32F\",\n structuredTexture: \"RGBA32UI\"\n});\n\n/** Marks an absent optional `u8`. */\nconst ABSENT_U8 = 0xff;\n\n/**\n * Local-light lowering roles, as a wire index.\n *\n * Carbon puts local lights in two structured buffers plus a profile texture.\n * WebGL 2 has no structured buffers at all, so they have to be re-expressed —\n * this is a *storage* change, not a shading one, and without it the affected\n * shaders cannot bind their lights.\n *\n * The emitter still spells the role `cjsSemantic` on its binding records. That\n * name is not carried onto the wire: it names a defunct package format rather\n * than the thing it describes. Renaming it at the emitter is a separate change.\n */\nexport const GLSL_LOCAL_LIGHT_ROLE = Object.freeze([ \"packed-texture\", \"constant-buffer\" ]);\n\n/** Emitter `cjsSemantic` values, in the same order as the roles above. */\nconst EMITTER_LIGHT_SEMANTIC = Object.freeze([ \"packedLocalLights\", \"localLights\" ]);\n\n/**\n * Writes the optional local-light lowering record.\n *\n * Carries the source registers so a consumer can tie the synthesised resource\n * back to the Carbon resources it replaced, which is otherwise unrecoverable:\n * the shader no longer declares them.\n *\n * @param {CjsByteWriter} writer Target writer.\n * @param {object} binding Emitter binding record.\n */\nfunction writeLocalLightRecord(writer, binding)\n{\n const role = EMITTER_LIGHT_SEMANTIC.indexOf(binding.cjsSemantic);\n\n if (!binding.cjsSemantic)\n {\n writer.u8(0);\n return;\n }\n\n if (role < 0)\n {\n throw new CjsFormatWriteError(\n `Binding \"${binding.name}\" carries unknown local-light role \"${binding.cjsSemantic}\"`,\n { name: binding.name, semantic: binding.cjsSemantic }\n );\n }\n\n writer.u8(1);\n writer.u8(role);\n writer.u8(binding.lightIndexRegister);\n writer.u8(binding.lightDataRegister);\n // The profile array is optional: some permutations never sample it, and the\n // lowering replaces it with neutral attenuation when it is absent.\n writer.u8(binding.lightProfileRegister ?? ABSENT_U8);\n writer.u32(binding.dataTexelBase ?? 0);\n writer.u16(binding.capacityLights ?? 0);\n}\n\n/**\n * Reads the optional local-light lowering record.\n *\n * @param {CjsByteReader} reader Source reader.\n * @returns {object|null} Local-light fields, or null when the binding is ordinary.\n */\nfunction readLocalLightRecord(reader)\n{\n if (!reader.readUint8()) return null;\n\n const role = GLSL_LOCAL_LIGHT_ROLE[reader.readUint8()];\n const lightIndexRegister = reader.readUint8();\n const lightDataRegister = reader.readUint8();\n const profile = reader.readUint8();\n const dataTexelBase = reader.readUint32();\n const capacityLights = reader.readUint16();\n\n return {\n localLightRole: role,\n lightIndexRegister,\n lightDataRegister,\n lightProfileRegister: profile === ABSENT_U8 ? null : profile,\n ...(role === \"packed-texture\" ? { dataTexelBase } : {}),\n ...(role === \"constant-buffer\" ? { capacityLights } : {})\n };\n}\n\n/**\n * Writes one binding's kind-specific payload.\n *\n * @param {CjsByteWriter} writer Target writer.\n * @param {object} binding Emitter binding record.\n */\nfunction writeBindingBody(writer, binding)\n{\n switch (binding.kind)\n {\n case \"constantBuffer\": {\n const style = GLSL_BACKEND_CONSTANT_BUFFER_STYLE.indexOf(binding.style ?? \"array\");\n if (style < 0)\n {\n throw new CjsFormatWriteError(\n `Unknown constant-buffer style \"${binding.style}\"`, { style: binding.style }\n );\n }\n writer.u16(binding.sizeInVec4);\n writer.u8(style);\n writeLocalLightRecord(writer, binding);\n break;\n }\n case \"resource\": {\n const dimension = DxbcResourceDimensionNames.indexOf(binding.dimensionName);\n if (dimension < 0)\n {\n throw new CjsFormatWriteError(\n `Unknown resource dimension \"${binding.dimensionName}\"`,\n { dimensionName: binding.dimensionName }\n );\n }\n writer.u8(dimension);\n const samplers = binding.comparison ? binding.samplerRegisterIndices ?? [] : [];\n writer.u8(samplers.length);\n for (const register of samplers) writer.u8(register);\n // v2: comparison is its own fact, not \"the list above is non-empty\",\n // so the pairing below can be written for ordinary textures too.\n writer.u8(binding.comparison ? 1 : 0);\n const paired = binding.pairedSamplerRegisters ?? [];\n writer.u8(paired.length);\n for (const register of paired) writer.u8(register);\n break;\n }\n case \"bufferTexture\":\n writer.u16(binding.width);\n writeStringList(writer, binding.returnTypes);\n break;\n case \"structuredTexture\":\n writer.u32(binding.strideBytes ?? 0);\n writer.u16(binding.width);\n writeLocalLightRecord(writer, binding);\n break;\n case \"structuredUbo\":\n writer.u32(binding.strideBytes ?? 0);\n writer.u16(binding.capacityElements);\n break;\n case \"uavTexture\":\n writer.u8(binding.slice ?? ABSENT_U8);\n writer.u8(binding.location);\n writeStringList(writer, binding.returnTypes);\n break;\n case \"dispatchUniform\":\n break;\n default:\n throw new CjsFormatWriteError(`Unknown binding kind \"${binding.kind}\"`, {\n kind: binding.kind\n });\n }\n}\n\n/**\n * Reads one binding's kind-specific payload, restoring derived fields.\n *\n * @param {CjsByteReader} reader Source reader.\n * @param {string} kind Binding kind.\n * @returns {object} Kind-specific fields.\n */\nfunction readBindingBody(reader, kind)\n{\n switch (kind)\n {\n case \"constantBuffer\": {\n const sizeInVec4 = reader.readUint16();\n const style = GLSL_BACKEND_CONSTANT_BUFFER_STYLE[reader.readUint8()];\n return { sizeInVec4, style, ...(readLocalLightRecord(reader) ?? {}) };\n }\n case \"resource\": {\n const dimension = reader.readUint8();\n const samplerCount = reader.readUint8();\n const samplerRegisterIndices = [];\n for (let index = 0; index < samplerCount; index += 1)\n {\n samplerRegisterIndices.push(reader.readUint8());\n }\n // Comparison is its own fact rather than \"the register list above is\n // non-empty\", which is what frees the pairing below to be written\n // for ordinary textures too.\n const comparison = reader.readUint8() === 1;\n const pairedSamplerRegisters = [];\n const pairedCount = reader.readUint8();\n for (let index = 0; index < pairedCount; index += 1)\n {\n pairedSamplerRegisters.push(reader.readUint8());\n }\n const samplerType = comparison\n ? SHADOW_SAMPLER_TYPE_BY_DIMENSION[dimension]\n : SAMPLER_TYPE_BY_DIMENSION[dimension];\n\n if (!samplerType)\n {\n throw new CjsFormatReadError(\n `Resource dimension ${dimension} has no ${comparison ? \"shadow \" : \"\"}sampler type`,\n { dimension, comparison }\n );\n }\n\n return {\n samplerType,\n dimensionName: DxbcResourceDimensionNames[dimension] ?? `dimension_${dimension}`,\n ...(pairedSamplerRegisters.length ? { pairedSamplerRegisters } : {}),\n ...(comparison ? { comparison: true, samplerRegisterIndices } : {})\n };\n }\n case \"bufferTexture\":\n return {\n format: DATA_TEXTURE_FORMAT.bufferTexture,\n width: reader.readUint16(),\n returnTypes: readStringList(reader)\n };\n case \"structuredTexture\": {\n const strideBytes = reader.readUint32();\n const width = reader.readUint16();\n return {\n strideBytes,\n format: DATA_TEXTURE_FORMAT.structuredTexture,\n width,\n ...(readLocalLightRecord(reader) ?? {})\n };\n }\n case \"structuredUbo\":\n return {\n strideBytes: reader.readUint32(),\n capacityElements: reader.readUint16()\n };\n case \"uavTexture\": {\n const slice = reader.readUint8();\n return {\n slice: slice === ABSENT_U8 ? null : slice,\n location: reader.readUint8(),\n returnTypes: readStringList(reader)\n };\n }\n case \"dispatchUniform\":\n return {};\n default:\n throw new CjsFormatReadError(`Unknown binding kind \"${kind}\"`, { kind });\n }\n}\n\n/**\n * Writes an optional count-prefixed string list.\n *\n * @param {CjsByteWriter} writer Target writer.\n * @param {string[]|null} values String list, or null.\n */\nfunction writeStringList(writer, values)\n{\n const list = Array.isArray(values) ? values : [];\n writer.u8(list.length);\n for (const value of list) writeInlineString(writer, value);\n}\n\n/**\n * Reads an optional count-prefixed string list.\n *\n * @param {CjsByteReader} reader Source reader.\n * @returns {string[]|null} String list, or null when empty.\n */\nfunction readStringList(reader)\n{\n const count = reader.readUint8();\n if (!count) return null;\n\n const values = [];\n for (let index = 0; index < count; index += 1) values.push(readInlineString(reader));\n return values;\n}\n\n/**\n * Writes the compute-as-fragment section.\n *\n * @param {CjsByteWriter} writer Target writer.\n * @param {object|null} computeFragment Compute-fragment contract, or null.\n */\nfunction writeComputeFragment(writer, computeFragment)\n{\n if (!computeFragment)\n {\n writer.u8(0);\n return;\n }\n\n writer.u8(1);\n const threadGroup = computeFragment.threadGroup;\n writer.u8(threadGroup ? 1 : 0);\n if (threadGroup) for (const extent of threadGroup) writer.u16(extent);\n writeInlineString(writer, computeFragment.dispatchOriginUniform ?? \"\");\n\n const outputs = computeFragment.uavOutputs ?? [];\n writer.u8(outputs.length);\n for (const output of outputs)\n {\n writer.u8(output.register);\n writer.u8(output.slice ?? ABSENT_U8);\n writer.u8(output.location);\n writeInlineString(writer, output.glslName);\n }\n}\n\n/**\n * Reads the compute-as-fragment section.\n *\n * @param {CjsByteReader} reader Source reader.\n * @returns {object|null} Compute-fragment contract, or null.\n */\nfunction readComputeFragment(reader)\n{\n if (!reader.readUint8()) return null;\n\n const threadGroup = reader.readUint8()\n ? [ reader.readUint16(), reader.readUint16(), reader.readUint16() ]\n : null;\n const dispatchOriginUniform = readInlineString(reader);\n\n const uavOutputs = [];\n const outputCount = reader.readUint8();\n for (let index = 0; index < outputCount; index += 1)\n {\n const register = reader.readUint8();\n const slice = reader.readUint8();\n uavOutputs.push({\n register,\n slice: slice === ABSENT_U8 ? null : slice,\n location: reader.readUint8(),\n glslName: readInlineString(reader)\n });\n }\n\n return {\n threadGroup,\n dispatchOriginUniform: dispatchOriginUniform === \"\" ? null : dispatchOriginUniform,\n uavOutputs\n };\n}\n\n/**\n * Serialises one pass's GLSL backend block.\n *\n * @param {object} block Block contents.\n * @param {object} [block.stages] Per-stage lowering data, keyed by stage name.\n * @param {object[]} [block.transforms] Resource transforms.\n * @returns {Uint8Array} Self-contained block bytes.\n */\nexport function writeGlslBackendBlock(block)\n{\n const stages = block.stages ?? {};\n const writer = new CjsByteWriter(256);\n\n writer.u8(CARBON_BACKEND_ENGINE_ID.webgl2);\n\n // Canonical stage order, not object insertion order: two passes with the\n // same lowering must produce the same bytes so the arena dedupes them.\n const present = GLSL_BACKEND_STAGE.filter((name) => stages[name]);\n writer.u8(present.length);\n\n for (const stageName of present)\n {\n const stage = stages[stageName];\n writer.u8(GLSL_BACKEND_STAGE.indexOf(stageName));\n\n const bindings = stage.bindings ?? [];\n writer.u8(bindings.length);\n for (const binding of bindings)\n {\n const kind = GLSL_BACKEND_BINDING_KIND.indexOf(binding.kind);\n if (kind < 0)\n {\n throw new CjsFormatWriteError(`Unknown binding kind \"${binding.kind}\"`, {\n kind: binding.kind\n });\n }\n writer.u8(kind);\n writer.u8(binding.registerIndex ?? ABSENT_U8);\n writeInlineString(writer, binding.name);\n writeBindingBody(writer, binding);\n }\n\n const stageInputs = stage.stageInputs ?? [];\n writer.u8(stageInputs.length);\n for (const input of stageInputs)\n {\n const componentType = DxbcComponentTypeNames.indexOf(input.componentTypeName);\n if (componentType < 0)\n {\n throw new CjsFormatWriteError(\n `Unknown component type \"${input.componentTypeName}\"`,\n { componentTypeName: input.componentTypeName }\n );\n }\n writer.u8(input.register);\n writeInlineString(writer, input.name);\n writeInlineString(writer, input.semanticName);\n writer.u8(input.semanticIndex);\n writer.u8(componentType);\n writer.u8(input.mask);\n }\n\n writeComputeFragment(writer, stage.computeFragment ?? null);\n }\n\n writeTransformSection(writer, block.transforms ?? []);\n\n return writer.toBytes();\n}\n\n/**\n * Parses one pass's GLSL backend block, restoring every derived field.\n *\n * @param {ArrayBuffer|ArrayBufferView|Uint8Array} bytes Block bytes.\n * @param {object} [options] Read options.\n * @param {string} [options.layoutKey] Enclosing pass key, restored onto records.\n * @param {string} [options.source] Source name for error details.\n * @returns {object} Block contents with derived fields restored.\n */\nexport function readGlslBackendBlock(bytes, options = {})\n{\n const reader = new CjsByteReader(bytes, { source: options.source ?? \"glsl backend block\" });\n const layoutKey = options.layoutKey ?? null;\n\n // Identity, then straight into the payload: no version byte is read because\n // none is written. Carbon's container version is the only version, and a\n // block whose shape does not match this build fails on the trailing-byte\n // check below - the fix for which is to rebuild the package, never to add a\n // branch.\n readBackendEngineId(reader, CARBON_BACKEND_ENGINE_ID.webgl2, options.source ?? \"glsl backend block\");\n\n const stages = {};\n const stageCount = reader.readUint8();\n\n for (let index = 0; index < stageCount; index += 1)\n {\n const stageName = GLSL_BACKEND_STAGE[reader.readUint8()];\n\n const bindings = [];\n const bindingCount = reader.readUint8();\n for (let bindingIndex = 0; bindingIndex < bindingCount; bindingIndex += 1)\n {\n const kind = GLSL_BACKEND_BINDING_KIND[reader.readUint8()];\n const registerIndex = reader.readUint8();\n const name = readInlineString(reader);\n bindings.push({\n kind,\n ...(registerIndex === ABSENT_U8 ? {} : { registerIndex }),\n name,\n ...readBindingBody(reader, kind)\n });\n }\n\n const stageInputs = [];\n const stageInputCount = reader.readUint8();\n for (let inputIndex = 0; inputIndex < stageInputCount; inputIndex += 1)\n {\n stageInputs.push({\n register: reader.readUint8(),\n name: readInlineString(reader),\n semanticName: readInlineString(reader),\n semanticIndex: reader.readUint8(),\n componentTypeName: DxbcComponentTypeNames[reader.readUint8()],\n mask: reader.readUint8()\n });\n }\n\n const computeFragment = readComputeFragment(reader);\n\n stages[stageName] = {\n bindings,\n stageInputs,\n ...(computeFragment ? { computeFragment } : {})\n };\n }\n\n const transforms = readTransformSection(reader, layoutKey);\n\n // A sized record must land exactly on its declared end. Trailing bytes mean\n // the writer knew fields this reader does not, which without a version byte\n // is the ONLY signal that a block came from a different build - so this is\n // load-bearing rather than defensive, and it is why removing the version is\n // safe. The fix is always to rebuild the package.\n if (reader.remaining !== 0)\n {\n throw new CjsFormatReadError(\n `GLSL backend block has ${reader.remaining} unparsed trailing byte(s); rebuild the effect package`,\n {\n source: options.source ?? \"glsl backend block\",\n trailingBytes: reader.remaining\n }\n );\n }\n\n return { layoutKey, stages, transforms, trailingBytes: 0 };\n}\n"],"names":["GLSL_BACKEND_STAGE","Object","freeze","GLSL_BACKEND_BINDING_KIND","GLSL_BACKEND_CONSTANT_BUFFER_STYLE","SAMPLER_TYPE_BY_DIMENSION","SHADOW_SAMPLER_TYPE_BY_DIMENSION","DATA_TEXTURE_FORMAT","bufferTexture","structuredTexture","ABSENT_U8","GLSL_LOCAL_LIGHT_ROLE","EMITTER_LIGHT_SEMANTIC","writeLocalLightRecord","writer","binding","role","indexOf","cjsSemantic","u8","CjsFormatWriteError","name","semantic","lightIndexRegister","lightDataRegister","lightProfileRegister","u32","dataTexelBase","u16","capacityLights","readLocalLightRecord","reader","readUint8","profile","readUint32","readUint16","localLightRole","writeBindingBody","kind","style","sizeInVec4","dimension","DxbcResourceDimensionNames","dimensionName","samplers","comparison","samplerRegisterIndices","length","register","paired","pairedSamplerRegisters","width","writeStringList","returnTypes","strideBytes","capacityElements","slice","location","readBindingBody","samplerCount","index","push","pairedCount","samplerType","CjsFormatReadError","format","readStringList","values","list","Array","isArray","value","writeInlineString","count","readInlineString","writeComputeFragment","computeFragment","threadGroup","extent","dispatchOriginUniform","outputs","uavOutputs","output","glslName","readComputeFragment","outputCount","writeGlslBackendBlock","block","stages","CjsByteWriter","CARBON_BACKEND_ENGINE_ID","webgl2","present","filter","stageName","stage","bindings","registerIndex","stageInputs","input","componentType","DxbcComponentTypeNames","componentTypeName","semanticName","semanticIndex","mask","writeTransformSection","transforms","toBytes","readGlslBackendBlock","bytes","options","CjsByteReader","source","layoutKey","readBackendEngineId","stageCount","bindingCount","bindingIndex","stageInputCount","inputIndex","readTransformSection","remaining","trailingBytes"],"mappings":";;;;;;;;AAgBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,kBAAkB,GAAGC,MAAM,CAACC,MAAM,CAAC,CAAE,QAAQ,E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F,SAAS,KAAK,CAAC,EAC1B;IACI,MAAM,IAAI1D,kBAAkB,CACxB,CAAA,uBAAA,EAA0BjC,MAAM,CAAC2F,SAAS,wDAAwD,EAClG;AACIT,MAAAA,MAAM,EAAEF,OAAO,CAACE,MAAM,IAAI,oBAAoB;MAC9CU,aAAa,EAAE5F,MAAM,CAAC2F;AAC1B,KACJ,CAAC;AACL,EAAA;EAEA,OAAO;IAAER,SAAS;IAAE1B,MAAM;IAAEmB,UAAU;AAAEgB,IAAAA,aAAa,EAAE;GAAG;AAC9D;;;;"}
@@ -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,K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KAAK,CAACE,QAAQ,EAAE;AACtD,EAAA,IAAI1B,WAAW,CAACC,MAAM,CAACuB,KAAK,CAAC,EAAE,OAAOG,KAAK,CAACC,IAAI,CAACJ,KAAK,CAAC;AACvD,EAAA,IAAIG,KAAK,CAACE,OAAO,CAACL,KAAK,CAAC,EAAE,OAAOA,KAAK,CAACM,GAAG,CAACP,WAAW,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
+ {"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;AAC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