@carbonenginejs/runtime 0.1.0-alpha.6 → 0.1.0-alpha.7

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.

Potentially problematic release.


This version of @carbonenginejs/runtime might be problematic. Click here for more details.

Files changed (92) hide show
  1. package/dist/global/consts/effectPaths.js +4 -1
  2. package/dist/global/consts/effectPaths.js.map +1 -1
  3. package/dist/global/consts/index.js +1 -1
  4. package/dist/global/index.js +1 -1
  5. package/dist/index.js +3 -3
  6. package/dist/resource/format/carbonEffect/carbonEffectBackendBlock.js +19 -2
  7. package/dist/resource/format/carbonEffect/carbonEffectBackendBlock.js.map +1 -1
  8. package/dist/resource/format/index.js +1 -1
  9. package/dist/resource/formats/hlsl/core/carbonTypedViews.js +121 -65
  10. package/dist/resource/formats/hlsl/core/carbonTypedViews.js.map +1 -1
  11. package/dist/resource/formats/webgl/core/glsl/DxbcGlslEmitter.js +10 -7
  12. package/dist/resource/formats/webgl/core/glsl/DxbcGlslEmitter.js.map +1 -1
  13. package/dist/resource/formats/webgpu/core/effectBackendBodySet.js +3 -1
  14. package/dist/resource/formats/webgpu/core/effectBackendBodySet.js.map +1 -1
  15. package/dist/resource/formats/webgpu/core/packageEffect.js +5 -0
  16. package/dist/resource/formats/webgpu/core/packageEffect.js.map +1 -1
  17. package/dist/resource/formats/webgpu/core/wgsl/emitWgsl.js +20 -0
  18. package/dist/resource/formats/webgpu/core/wgsl/emitWgsl.js.map +1 -1
  19. package/dist/resource/formats/webgpu/core/wgsl/emulatedAddressing.js +93 -4
  20. package/dist/resource/formats/webgpu/core/wgsl/emulatedAddressing.js.map +1 -1
  21. package/dist/resource/formats/webgpu/core/wgsl/lowerBindingLayout.js +74 -64
  22. package/dist/resource/formats/webgpu/core/wgsl/lowerBindingLayout.js.map +1 -1
  23. package/dist/resource/formats/webgpu/core/wgsl/lowerFragmentProgram.js +16 -7
  24. package/dist/resource/formats/webgpu/core/wgsl/lowerFragmentProgram.js.map +1 -1
  25. package/dist/resource/formats/webgpu/core/wgsl/wgslTypedViews.js +69 -27
  26. package/dist/resource/formats/webgpu/core/wgsl/wgslTypedViews.js.map +1 -1
  27. package/dist/resource/geometry/registerGeometryResources.js +10 -1
  28. package/dist/resource/geometry/registerGeometryResources.js.map +1 -1
  29. package/dist/sof/EveSOFDNA.js +4 -2
  30. package/dist/sof/EveSOFDNA.js.map +1 -1
  31. package/dist/sof/EveSOFDataMgr.js +83 -69
  32. package/dist/sof/EveSOFDataMgr.js.map +1 -1
  33. package/dist/trinity/core/Tr2Denoiser.js +6 -1
  34. package/dist/trinity/core/Tr2Denoiser.js.map +1 -1
  35. package/dist/trinity/core/Tr2ShadowMap.js +7 -2
  36. package/dist/trinity/core/Tr2ShadowMap.js.map +1 -1
  37. package/dist/trinity/core/context/Tr2RenderContext.js +43 -0
  38. package/dist/trinity/core/context/Tr2RenderContext.js.map +1 -1
  39. package/dist/trinity/core/device/Tr2GpuStructuredBuffer.js +134 -0
  40. package/dist/trinity/core/device/Tr2GpuStructuredBuffer.js.map +1 -0
  41. package/dist/trinity/core/index.js +1 -0
  42. package/dist/trinity/core/index.js.map +1 -1
  43. package/dist/trinity/core/lighting/Tr2LightManager.js +410 -124
  44. package/dist/trinity/core/lighting/Tr2LightManager.js.map +1 -1
  45. package/dist/trinity/eve/effect/lensflare/EveLensflare.js +303 -312
  46. package/dist/trinity/eve/effect/lensflare/EveLensflare.js.map +1 -1
  47. package/dist/trinity/eve/effect/lensflare/EveOccluder.js +117 -0
  48. package/dist/trinity/eve/effect/lensflare/EveOccluder.js.map +1 -0
  49. package/dist/trinity/eve/index.js +1 -0
  50. package/dist/trinity/eve/index.js.map +1 -1
  51. package/dist/trinity/eve/scene/EveSpaceScene.js +286 -6
  52. package/dist/trinity/eve/scene/EveSpaceScene.js.map +1 -1
  53. package/dist/trinity/eve/scene/EveSpaceSceneRenderDriver.js +212 -32
  54. package/dist/trinity/eve/scene/EveSpaceSceneRenderDriver.js.map +1 -1
  55. package/dist/trinity/generated/eve/effect/index.js +0 -1
  56. package/dist/trinity/generated/eve/effect/index.js.map +1 -1
  57. package/dist/trinity/generated/eve/index.js +0 -1
  58. package/dist/trinity/generated/eve/index.js.map +1 -1
  59. package/dist/trinity/generated/index.js +0 -2
  60. package/dist/trinity/generated/index.js.map +1 -1
  61. package/dist/trinity/generated/trinityCore/index.js +0 -1
  62. package/dist/trinity/generated/trinityCore/index.js.map +1 -1
  63. package/dist/trinity/index.js +2 -2
  64. package/dist/trinity/postProcess/Tr2PostProcessRenderer.js +4 -1
  65. package/dist/trinity/postProcess/Tr2PostProcessRenderer.js.map +1 -1
  66. package/dist/trinity/postProcess/Tr2SSAO.js +282 -21
  67. package/dist/trinity/postProcess/Tr2SSAO.js.map +1 -1
  68. package/dist/trinity/shader/parameter/Tr2RuntimeTextureParameter.js +71 -53
  69. package/dist/trinity/shader/parameter/Tr2RuntimeTextureParameter.js.map +1 -1
  70. package/dist/trinityal/webgpu/CjsWebgpuRenderContextAL.js +81 -18
  71. package/dist/trinityal/webgpu/CjsWebgpuRenderContextAL.js.map +1 -1
  72. package/dist/trinityal/webgpu/CjsWebgpuResourceSetAL.js +46 -4
  73. package/dist/trinityal/webgpu/CjsWebgpuResourceSetAL.js.map +1 -1
  74. package/dist/trinityal/webgpu/CjsWebgpuShaderAL.js +32 -1
  75. package/dist/trinityal/webgpu/CjsWebgpuShaderAL.js.map +1 -1
  76. package/dist/trinityal/webgpu/CjsWebgpuShaderProgramAL.js +27 -0
  77. package/dist/trinityal/webgpu/CjsWebgpuShaderProgramAL.js.map +1 -1
  78. package/dist/trinityal/webgpu/CjsWebgpuTextureAL.js +29 -4
  79. package/dist/trinityal/webgpu/CjsWebgpuTextureAL.js.map +1 -1
  80. package/dist/trinityal/webgpu/core/CjsWebgpuPsoDescription.js +32 -2
  81. package/dist/trinityal/webgpu/core/CjsWebgpuPsoDescription.js.map +1 -1
  82. package/dist/trinityal/webgpu/core/CjsWebgpuUtils.js +57 -5
  83. package/dist/trinityal/webgpu/core/CjsWebgpuUtils.js.map +1 -1
  84. package/dist/trinityal/webgpu/core/CjsWebgpuWorkQueue.js +111 -5
  85. package/dist/trinityal/webgpu/core/CjsWebgpuWorkQueue.js.map +1 -1
  86. package/docs/trinity/reference/classes/generated.md +20 -20
  87. package/docs/trinity/reference/classes/post-process.md +1 -1
  88. package/package.json +1 -1
  89. package/dist/trinity/generated/eve/effect/EveOccluder.js +0 -38
  90. package/dist/trinity/generated/eve/effect/EveOccluder.js.map +0 -1
  91. package/dist/trinity/generated/trinityCore/Tr2GpuStructuredBuffer.js +0 -48
  92. package/dist/trinity/generated/trinityCore/Tr2GpuStructuredBuffer.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"CjsWebgpuRenderContextAL.js","sources":["../../../../src/trinityal/webgpu/CjsWebgpuRenderContextAL.js"],"sourcesContent":["// Source: trinity/trinityal/metal/Tr2RenderContextMetal.h\n// Source: trinity/trinityal/metal/Tr2RenderContextMetal.mm\n// Source: trinity/trinityal/stub/Tr2RenderContextStub.h\n//\n// The WebGPU backend behind Carbon's abstraction layer.\n//\n// WHAT THIS REPLACED. `Tr2RenderContext` used to RECORD what Trinity asked for\n// into an intent list, which `framePlan.js` partitioned and `frameExecutor.js`\n// encoded. That mechanism had no Carbon counterpart - Carbon gives the same job\n// to the abstraction layer, and a backend is simply called - and it is now\n// deleted, along with all three of those files (runtime `1e881dec`).\n//\n// THE DIVISION OF LABOUR IS CARBON'S. `Tr2RenderContextAL` (metal) holds the\n// bound state and validates; `MetalWorkQueue` owns the command buffer and the\n// encoder lifetime. `DrawIndexedInstanced` there checks its index buffer,\n// converts a primitive count to a vertex count, then calls the work queue,\n// whose draw opens a render encoder if none is current\n// (`Tr2RenderContextMetal.mm:414-436`, `MetalWorkQueue.mm:2922-2945`). This\n// keeps that split, so `CjsWebgpuWorkQueue` is the only thing that knows when a\n// pass begins.\n//\n// DEVICE-FREE, AS CARBON'S STUB IS. Every verb here is argument validation,\n// state, and delegation - none of it needs a GPU, and Carbon ships a whole\n// backend (`TrinityAL_stub`) on that basis. The device arrives when the work\n// queue's recorded transitions are applied to a real command encoder.\n//\n// SCOPE. The verbs `Tr2RenderContext` forwards to a backend: the geometry and\n// draw path Carbon's `SubmitGeometry` touches (`Tr2RenderContext.cpp:83-103`),\n// the render-target and depth-stencil families with their per-slot stacks, the\n// viewport, clear, compute and present. That is what installing this backend\n// requires, because the context prefers the AL per verb and a missing one is a\n// crash rather than a fallback.\n//\n// NOT HERE YET: texture creation, copies and mip generation. Absent rather than\n// faked. Buffer creation IS here (`CreateBuffer`), because a Trinity class that\n// fills a buffer per frame cannot pick its own backend.\n//\n// WHAT CARBON'S METAL BACKEND HAS THAT THIS DOES NOT, AND WHY.\n//\n// The parity check compares this file against the donors it cites, which\n// includes all of metal - so Metal-only members are reported against a backend\n// that has no reason to carry them. These are decisions, not a queue:\n//\n// - `BeginParallelEncoding`/`EndParallelEncoding`/`ForkContext` spread batch\n// encoding across threads. There is one thread here, and `Tr2RenderContext`\n// already records the same omission for the same reason.\n// - `BufferRewritten` notifies the context that a buffer allocation was RENAMED\n// under it. WebGPU cannot rename: `queue.writeBuffer` is ordered on the queue,\n// which gives the guarantee renaming buys without renaming, and\n// `CjsWebgpuBufferAL`'s head comment argues that at length.\n// - `CheckDrawResources` does not validate, which the first version of this\n// note claimed. Carbon BINDS dummy resources into unfilled slots and installs\n// the vertex descriptor, on every draw (`Tr2RenderContextMetal.mm:524-541`).\n// WebGPU has the same requirement and will reject a draw with an unfilled\n// binding, so the browser is not doing this for us - it is the thing that\n// rejects us. WE DO IT, under Metal's other name: `EmitRenderEncoderState`\n// resolves the pipeline, fills unbound slots with dummies and binds the\n// layout, inside every draw verb. A NAME divergence, not an absence. (Until\n// 2026-09-10 this note said the divergence held \"because the dispatcher fills\n// bindings before the draw reaches here\"; there is no dispatcher.)\n// - `ReleaseLater` defers destruction until the GPU has finished reading. A\n// `GPUBuffer` stays alive as long as a submitted command references it, so\n// the deferral has nothing to defer.\n// - `UseConstantBuffer` is Metal-only and makes a constant buffer resident on\n// the COMPUTE encoder (`:1658-1673`); its only callers build the ray-tracing\n// shader table. No compute dispatches here and there is no ray tracing, so\n// there is nothing to make resident. (This note used to lump it with\n// `UploadConstants` and claim \"there is no arena\", which stopped being true\n// the day the arena landed. `UploadConstants` IS ported, above.)\n// - `GetMetalContext` and `GetMetalWorkQueue` are Metal's native escape\n// hatches. Ours are `GetWebgpu` and `GetWorkQueue` - Carbon names these per\n// backend too, so a WebGPU spelling is the faithful thing, not a divergence.\n\nimport { CjsSchema, impl } from \"#schema\";\nimport { Tr2ResourceSetAL } from \"../Tr2ResourceSetAL/Tr2ResourceSetAL.js\";\nimport { PixelFormat, ShaderType, Topology, Tr2LoadAction, Tr2StoreAction, UpscalingResult, UpscalingSetting, UpscalingTechnique } from \"#consts/render-context\";\nimport { Tr2ColorAttachment, Tr2ConstantUsageAL, Tr2DepthAttachment, Tr2VertexLayoutALStub, resolveBindingPlan, ALResult, Failed, Tr2DrawUPHelper } from \"#trinityal\";\nimport { CjsWebgpuWorkQueue, EncoderType } from \"./core/CjsWebgpuWorkQueue.js\";\nimport { CjsWebgpuMipGenerator } from \"./core/CjsWebgpuMipGenerator.js\";\nimport { CjsWebgpuBufferAL } from \"./CjsWebgpuBufferAL.js\";\nimport { CjsWebgpuConstantBufferAL } from \"./CjsWebgpuConstantBufferAL.js\";\nimport { CjsWebgpuSamplerStateAL } from \"./CjsWebgpuSamplerStateAL.js\";\nimport { CjsWebgpuResourceSetAL } from \"./CjsWebgpuResourceSetAL.js\";\nimport { CjsWebgpuTextureAL } from \"./CjsWebgpuTextureAL.js\";\nimport { CjsWebgpuConstantArena } from \"./core/CjsWebgpuConstantArena.js\";\nimport { CjsWebgpuUtils } from \"./core/CjsWebgpuUtils.js\";\nimport { CanonicalKey } from \"./core/CjsWebgpuPipelineCache.js\";\nimport { TOPOLOGIES } from \"./core/topology.js\";\nimport { SamplerDescriptionKey } from \"../Tr2HalHelperStructures/Tr2SamplerDescription.js\";\nimport { CjsWebgpuCapsAL } from \"./CjsWebgpuCapsAL.js\";\nimport { CjsWebgpuPsoDescription } from \"./core/CjsWebgpuPsoDescription.js\";\nimport { CjsWebgpuShaderAL, WEBGPU_ENTRY_POINT } from \"./CjsWebgpuShaderAL.js\";\nimport { CjsWebgpuShaderProgramAL } from \"./CjsWebgpuShaderProgramAL.js\";\nimport { WebgpuVertexBufferLayout } from \"./core/vertexFormat.js\";\n\n/** WebGPU's index format for a Carbon index stride, or null for one it lacks. */\nconst INDEX_FORMAT = Object.freeze({ 2: \"uint16\", 4: \"uint32\" });\n\n/** Bind groups kept before the cache is dropped and rebuilt. */\nconst MAX_CACHED_BIND_GROUPS = 1024;\n\n/**\n * The `GPUBuffer` behind a bound stream, or null.\n *\n * A stream is whatever Trinity bound: a `Tr2BufferAL` answers; anything else\n * does not, and the draw refuses. Trinity realizes a mesh batch's geometry\n * descriptor into suballocated buffers before binding it\n * (`RealizeBatchGeometry`, called from `Tr2RenderContext.SubmitGeometry`).\n */\nfunction DeviceBufferOf(bound)\n{\n return bound && typeof bound.GetDeviceBuffer === \"function\" ? bound.GetDeviceBuffer() : null;\n}\n\n\n/**\n * A clear colour as a `GPUColor`. `Tr2ColorAttachment.clearColor` is Carbon's\n * packed ARGB word (`Color_inline.h:15-22`); Trinity's clears also pass a\n * four-float colour, which is taken as r, g, b, a.\n */\nfunction gpuColor(value)\n{\n if (typeof value === \"number\")\n {\n return {\n r: ((value >>> 16) & 0xff) / 255,\n g: ((value >>> 8) & 0xff) / 255,\n b: (value & 0xff) / 255,\n a: ((value >>> 24) & 0xff) / 255\n };\n }\n\n if (value && value.length >= 4) return { r: value[0], g: value[1], b: value[2], a: value[3] };\n\n return value ?? { r: 0, g: 0, b: 0, a: 0 };\n}\n\n\nfunction fail(message)\n{\n const error = new Error(`CjsWebgpuRenderContextAL: ${message}`);\n error.code = \"CJS_WEBGPU_AL_INVALID\";\n throw error;\n}\n\n\n/**\n * How many vertices a primitive count describes, per topology.\n *\n * CARBON'S DRAW VERBS TAKE PRIMITIVES AND ITS BACKENDS DRAW VERTICES, so every\n * one of them converts (`Tr2RenderContextMetal.mm:424`, `ComputeVertexCount`).\n * The conversion depends on the bound topology, which is why the AL holds it.\n */\nconst VERTICES_PER_PRIMITIVE = Object.freeze({\n [Topology.TOP_TRIANGLES]: count => count * 3,\n [Topology.TOP_TRIANGLE_STRIP]: count => count + 2,\n [Topology.TOP_TRIANGLE_FAN]: count => count + 2,\n [Topology.TOP_LINES]: count => count * 2,\n [Topology.TOP_LINE_STRIP]: count => count + 1,\n [Topology.TOP_POINTS]: count => count\n});\n\n\n/** Carbon's `MAX_RENDER_TARGET`; the bound-target array is fixed width. */\nconst MAX_RENDER_TARGET = 8;\n\n/**\n * The dummy vertex element's format for a missing input, by the input's\n * declared Tr2ShaderPipelineInputAL::Type (FLOAT 0, INT 1, UINT 2; the string\n * form is vertexLayoutMatch's FALLBACK_INPUT_TYPE): Metal's Char4 / UChar4 /\n * Float4 (Tr2VertexLayoutALMetal.mm:147-156).\n */\nconst DUMMY_VERTEX_FORMAT = Object.freeze({\n 0: \"float32x4\",\n 1: \"sint8x4\",\n 2: \"uint8x4\",\n FLOAT: \"float32x4\",\n INT: \"sint8x4\",\n UINT: \"uint8x4\"\n});\n\n\n/**\n * The Carbon pixel format behind each format a canvas can be configured with.\n *\n * SHORT ON PURPOSE. `GPUCanvasContext.configure` accepts only `bgra8unorm`,\n * `rgba8unorm` and their sRGB view formats, so this is the whole domain rather\n * than a partial table someone should extend later.\n */\nconst CANVAS_PIXEL_FORMAT = Object.freeze({\n \"bgra8unorm\": PixelFormat.PIXEL_FORMAT_B8G8R8A8_UNORM,\n \"bgra8unorm-srgb\": PixelFormat.PIXEL_FORMAT_B8G8R8A8_UNORM_SRGB,\n \"rgba8unorm\": PixelFormat.PIXEL_FORMAT_R8G8B8A8_UNORM,\n \"rgba8unorm-srgb\": PixelFormat.PIXEL_FORMAT_R8G8B8A8_UNORM_SRGB\n});\n\n\n/**\n * The primary render context, Carbon's process-wide one.\n *\n * A MODULE-LEVEL BINDING, matching the stub, because Carbon's is a static on\n * the class and a JavaScript static field would be per-subclass. There is one\n * primary context per process in Carbon and there is one here.\n */\nlet primaryRenderContext = null;\n\n\n/**\n * How many constant-buffer registers a stage has.\n *\n * Carbon's Metal backend fixes this at 20 (`METAL_CONST_BUFFER_COUNT`,\n * `MetalWorkQueue.h:39`) and rejects anything past it. Kept at Carbon's number\n * rather than a WebGPU limit: this bounds the REGISTER INDEX an effect declares,\n * which the shader compiler already fixed, not the bind-group slot count.\n */\nconst CONSTANT_BUFFER_REGISTERS = 20;\n\n\n/** WebGPU behind the abstraction layer, holding a work queue as Metal does. */\nexport class CjsWebgpuRenderContextAL\n{\n /**\n * The shader stages this backend runs, a bit per stage: `SHADER_TYPE_MASK`,\n * which `SHADER_TYPE_EXISTS` tests (`Tr2RenderContextEnum.h:413`). Vertex,\n * pixel and compute, as Metal's (`Tr2RenderContextMetal.h:190-191`).\n */\n static SHADER_TYPE_MASK = (1 << ShaderType.VERTEX_SHADER) | (1 << ShaderType.PIXEL_SHADER) | (1 << ShaderType.COMPUTE_SHADER);\n\n /** m_workQueue */\n _workQueue = new CjsWebgpuWorkQueue();\n\n /** m_isValid */\n _isValid = false;\n\n /** m_metalPrimitiveInfo - the topology following draws use. */\n _topology = Topology.TOP_TRIANGLES;\n\n /** m_metalIndexBuffer */\n _indexBuffer = null;\n\n _indexStride = 0;\n\n /** Vertex streams by slot, as SetStreamSource fills them. */\n _streams = [];\n\n /** m_vertexLayout */\n _vertexLayout = null;\n\n /** m_shaderProgram */\n _shaderProgram = null;\n\n /** m_resourceSet */\n _resourceSet = null;\n\n // Carbon's m_psoDescription half that exists so far: the authored setup and\n // the overrides it must be projected through, plus m_dirtyPso. The rest of\n // the description - shader program, vertex layout, topology, target formats -\n // is already held by the fields above and around; assembling and caching it\n // is the next piece of the immediate-draw route.\n\n _renderStateSetup = null;\n\n _renderStateOverrides = null;\n\n /** m_dirtyPso */\n _pipelineDirty = true;\n\n /**\n * m_drawUPHelper, DX12's name for it; DX11 calls the same thing m_drawUP.\n *\n * Owned rather than shared, as every backend owns its own: the ring's slots\n * are only safe because one context advances one cursor.\n */\n _drawUP = new Tr2DrawUPHelper();\n\n /**\n * m_psoDescription. Carbon's setters accumulate into one of these and mark it\n * dirty; every draw entry then calls `SetAllState`, which resolves a pipeline\n * from a cache keyed on the description's hash and binds it\n * (`Tr2RenderContextDx12.cpp:763-806`, `:810-880`).\n *\n * The class was written for this and wired to nothing until 2026-09-09. It is\n * filled here so the description is always current; RESOLVING it is the next\n * step, and needs the bound program to carry its effect package.\n */\n _psoDescription = new CjsWebgpuPsoDescription();\n\n /** m_boundRenderTarget[MAX_RENDER_TARGET] */\n _boundRenderTargets = new Array(MAX_RENDER_TARGET).fill(null);\n\n /** m_stackRT[MAX_RENDER_TARGET] - one stack per slot, as Carbon has. */\n _renderTargetStacks = Array.from({ length: MAX_RENDER_TARGET }, () => []);\n\n _depthStencil = null;\n\n _depthStencilStack = [];\n\n _viewport = null;\n\n /** Everything the work queue reported, for a caller that encodes it. */\n _transitions = [];\n\n // THE DEVICE HALF, AND WHY IT IS OPTIONAL. Composed, this backend draws:\n // `BeginScene` opens a command encoder, the work queue turns it into real\n // render passes, the draw verbs resolve a pipeline and bind groups from the\n // bound state and record into the live pass, and `EndScene` submits.\n // Uncomposed it validates verbs and records transitions - the stub backend\n // Carbon ships, and the thing every headless test relies on.\n //\n // IT IS HANDED VERBS, NEVER A BATCH. Until 2026-09-10 it also declared\n // `RenderBatches`, a Trinity method, and needed a resolver and a dispatcher\n // to turn the batches it was handed into bindings - the inversion this lane\n // was opened to undo. Trinity's own walk (`Tr2RenderContext.RenderBatchesInOrder`)\n // now calls the same verbs Carbon's does.\n\n _webgpu = null;\n\n _renderTarget = null;\n\n /**\n * The backend's translation tables, `MetalContext::m_utils` (`MetalContext.h:34`),\n * reached as Metal reaches its own: `context.m_utils.GetGPUTextureFormat(...)`.\n */\n m_utils = new CjsWebgpuUtils();\n\n /** The frame's command encoder, between BeginScene and EndScene. */\n _commandEncoder = null;\n\n /** The acquired swap-chain frame, valid only within one scene. */\n _frame = null;\n\n /**\n * @param {object} [composition] The device half; omit for the stub backend.\n * @param {object} [composition.webgpu] A `CjsWebgpuDevice`.\n * @param {object} [composition.renderTarget] A `CjsWebgpuRenderTarget`.\n */\n constructor({ webgpu = null, renderTarget = null } = {})\n {\n if (webgpu && !renderTarget)\n {\n fail(\"a composed backend needs a render target as well as a device\");\n }\n\n this._webgpu = webgpu;\n this._renderTarget = renderTarget;\n\n // The description starts in step with the state it describes. Carbon's\n // struct is constructed with the same defaults its context has, so a\n // description read before any setter runs describes what is actually bound\n // rather than an empty pipeline.\n this._psoDescription.topology = this._topology;\n }\n\n /** Whether this backend can actually draw. @returns {boolean} */\n IsComposed()\n {\n return this._webgpu !== null;\n }\n\n /**\n * The device this context draws through.\n *\n * Carbon's buffer and texture AL types take a `Tr2PrimaryRenderContextAL&` in\n * `Create` and reach the device through it (`Tr2BufferAL.h:47`), so the\n * context being the way to the device is Carbon's shape, not a shortcut.\n *\n * @returns {object|null} The `CjsWebgpuDevice`, or null before composition.\n */\n GetWebgpu()\n {\n return this._webgpu;\n }\n\n /**\n * Creates a device-backed buffer, this backend's kind of `Tr2BufferAL`.\n *\n * The stub context answers the same call with a `Tr2BufferALStub`, which is\n * how a Trinity class gets the right buffer for the running backend without\n * importing either - see the note on the stub's `CreateBuffer`.\n *\n * @param {object} description A `Tr2BufferDescriptionAL`.\n * @param {ArrayBufferView|null} [initialData] Initial contents, if any.\n * @returns {object|null} The created buffer, or null when Create refused.\n */\n CreateBuffer(description, initialData = null)\n {\n const buffer = new CjsWebgpuBufferAL();\n\n if (Failed(buffer.Create(description, initialData, this))) return null;\n\n return buffer;\n }\n\n /**\n * Creates a vertex layout, this backend's kind of `Tr2VertexLayoutAL`.\n *\n * IT HOLDS THE DEFINITION AND NOTHING DEVICE-SIDE, and that is not a stub\n * standing in for real work. WebGPU has no input-layout object: the vertex\n * buffer layouts are part of the render pipeline descriptor and are fixed at\n * pipeline creation, so a layout here can only be the definition a pipeline\n * will later be built from. That is why `Tr2VertexLayoutALStub` is the right\n * shape for this backend too rather than a placeholder for a WebGPU one.\n *\n * @param {object[]|object} definition The vertex element list or definition.\n * @returns {object|null} The created layout, or null when Create refused.\n */\n CreateVertexLayout(definition)\n {\n const layout = new Tr2VertexLayoutALStub();\n\n if (Failed(layout.Create(definition, this))) return null;\n\n return layout;\n }\n\n /**\n * Creates a constant buffer, this backend's kind of `Tr2ConstantBufferAL`.\n *\n * See the stub's note: with no size this returns an empty buffer for a\n * Trinity caller to `Create` later, as Carbon default-constructs its member.\n *\n * @param {number} [size] Bytes; zero returns an empty, invalid buffer.\n * @param {number} [usage] A `Tr2ConstantUsageAL`.\n * @param {ArrayBufferView|null} [initialData] Initial contents, if any.\n * @returns {object|null} The buffer, or null when a sized Create refused.\n */\n CreateConstantBuffer(size = 0, usage = Tr2ConstantUsageAL.REUSABLE, initialData = null)\n {\n const buffer = new CjsWebgpuConstantBufferAL();\n\n if (size > 0 && Failed(buffer.Create(size, usage, initialData, this))) return null;\n\n return buffer;\n }\n\n /**\n * Carbon's `Tr2SamplerStateALFactory` (`Tr2SamplerStateAL.h:41-43`), keyed on\n * the description: equal descriptions are one state.\n */\n _samplerStates = new Map();\n\n /**\n * The sampler state for a description, this backend's kind of\n * `Tr2SamplerStateAL`, created once per distinct description.\n *\n * Carbon's `Tr2SamplerStateAL::Create` IS this lookup\n * (`Tr2SamplerStateAL.cpp:25-28`): the primary context owns the factory and\n * hands back the shared object, which is why a resource set can compare\n * sampler states by identity.\n *\n * @param {object} description A `Tr2SamplerDescription`, either spelling.\n * @returns {object|null} The shared state, or null when Create refused.\n */\n CreateSamplerState(description)\n {\n const key = SamplerDescriptionKey(description);\n\n if (key === null) return null;\n\n const existing = this._samplerStates.get(key);\n\n if (existing) return existing;\n\n const state = new CjsWebgpuSamplerStateAL();\n\n if (Failed(state.Create(description, this))) return null;\n\n this._samplerStates.set(key, state);\n\n return state;\n }\n\n /**\n * Compiles one shader stage into a `GPUShaderModule`.\n *\n * THE FIRST CONSTRUCTION OF THESE CLASSES. `CjsWebgpuShaderAL` and\n * `CjsWebgpuShaderProgramAL` were written for the immediate-draw route and\n * nothing built one, because the state manager had no way to ask a backend\n * for a shader. This is that way.\n *\n * @param {number} stageType A Carbon `ShaderType`.\n * @param {ArrayBufferView|string} bytecode WGSL source, as this backend's\n * bytecode; see the head comment on `CjsWebgpuShaderAL`.\n * @param {object|null} signature The reflected signature.\n * @param {string} [shaderPath] A debug label.\n * @returns {object|null} The created shader, or null when Create refused.\n */\n CreateShader(stageType, bytecode, signature, shaderPath = \"\")\n {\n const shader = new CjsWebgpuShaderAL();\n\n if (Failed(shader.Create(stageType, bytecode, signature, shaderPath, this))) return null;\n\n return shader;\n }\n\n /**\n * Links compiled stages into a program.\n *\n * @param {object[]} shaders The stages to link.\n * @returns {object|null} The created program, or null when Create refused.\n */\n CreateShaderProgram(shaders)\n {\n const program = new CjsWebgpuShaderProgramAL();\n\n if (Failed(program.Create(shaders, this))) return null;\n\n return program;\n }\n\n /**\n * How many batches this backend has encoded since it was created.\n *\n * A HARNESS NEEDS THIS AND A FRAME DOES NOT, which is why it counts batches\n * rather than reporting them: \"did anything draw\" is the question a test asks\n * when the alternative is trusting an empty canvas. Carbon answers it with\n * `CCP_STATS_INC( batchCount )` for the same reason.\n *\n * @returns {number} Batches encoded.\n */\n GetDrawnBatchCount()\n {\n return this._drawnBatchCount;\n }\n\n _drawnBatchCount = 0;\n\n /**\n * The work queue this backend records through.\n *\n * @returns {CjsWebgpuWorkQueue} The queue.\n */\n GetWorkQueue()\n {\n return this._workQueue;\n }\n\n /** m_caps, built once against whatever device this backend was composed with. */\n _caps = null;\n\n /**\n * What this backend can do.\n *\n * Carbon returns a reference to a member (`Tr2RenderContextMetal.mm:855-858`),\n * so the object is stable across calls; built lazily here because the device\n * is a constructor argument and the caps read its limits.\n *\n * @returns {CjsWebgpuCapsAL} The capabilities.\n */\n GetCaps()\n {\n this._caps ??= new CjsWebgpuCapsAL(this._webgpu);\n\n return this._caps;\n }\n\n /**\n * m_frameNumber. Carbon's Metal backend keeps this on the context behind it\n * (`Tr2RenderContextMetal.mm:1686-1694`); there is no such object here, so it\n * lives on the backend, exactly as the stub keeps it.\n */\n _frameNumber = 0;\n\n /**\n * The frame being recorded now.\n *\n * @returns {number} One past the last frame submitted.\n */\n GetRecordingFrameNumber()\n {\n return this._frameNumber + 1;\n }\n\n /**\n * The last frame handed to the device.\n *\n * SUBMISSION, NOT COMPLETION. `GPUQueue.submit` returns without waiting, and\n * the only handle on actual completion is `onSubmittedWorkDone`, a promise -\n * so a truthful \"rendered\" count would lag by an unbounded amount and could\n * not be read synchronously. This counts submitted frames, and a ring buffer\n * fencing against it is therefore protected by submission order rather than\n * by GPU completion.\n *\n * @returns {number} Frames submitted.\n */\n GetRenderedFrameNumber()\n {\n return this._frameNumber;\n }\n\n /**\n * Everything the work queue has reported since the last drain.\n *\n * @returns {object[]} Transitions and draws, in order.\n */\n DrainTransitions()\n {\n const transitions = this._transitions;\n\n this._transitions = [];\n\n return transitions;\n }\n\n /**\n * Creates the device. Carbon gates every resource create on this.\n *\n * @returns {boolean} True.\n */\n CreateDevice()\n {\n this._isValid = true;\n\n return true;\n }\n\n /** @returns {boolean} Whether a device exists. */\n IsValid()\n {\n return this._isValid;\n }\n\n /**\n * Opens the frame's command buffer.\n *\n * @returns {boolean} True.\n */\n BeginScene()\n {\n if (!this._isValid) fail(\"BeginScene before CreateDevice\");\n\n if (this._webgpu)\n {\n // THE FRAME IS ACQUIRED LAZILY, AT THE FIRST PASS, AND NOT HERE. A canvas\n // texture is valid only within one synchronous turn: awaiting anything -\n // and preparation awaits - lets the browser swap the surface and destroy\n // it underneath. Acquiring in BeginScene therefore encoded into a dead\n // texture, and the only symptom was a submit warning and a blank canvas\n // while the draw itself reported success.\n this._frame = null;\n this._commandEncoder = this._webgpu.GetDevice().createCommandEncoder({ label: \"CjsWebgpuRenderContextAL\" });\n this._workQueue.SetCommandEncoder(this._commandEncoder, attachments => this._Descriptor(attachments));\n }\n\n this._Record(this._workQueue.BeginFrame());\n\n // The constant arena starts the frame empty (`MetalContext.mm:473`); the\n // previous frame's regions were consumed at its submit.\n this._constantArena?.Reset();\n\n // Carbon's BeginScene is exactly these two calls\n // (`Tr2RenderContextMetal.mm:860-864`). The reset is what stops a frame\n // inheriting the previous frame's bound targets.\n this.ResetRenderTargets();\n\n return true;\n }\n\n /**\n * The render-pass descriptor for a set of folded attachments.\n *\n * `attachments` IS NULL FOR AN UNHINTED PASS, which is most of them: Carbon\n * applies load and store actions only when a hint is pending and otherwise\n * leaves the backend's own defaults alone. Ours are the render target's.\n */\n _Descriptor(attachments)\n {\n if (!this._IsCanvasPass()) return this._TextureDescriptor(attachments);\n\n // First pass of the scene acquires; later passes share the one view.\n this._frame ??= this._renderTarget.AcquireFrame();\n\n const clear = attachments?.colors?.[0];\n\n return this._renderTarget.CreateRenderPassDescriptor(this._frame, {\n label: `pass ${this._workQueue.GetPassCount()}`,\n clearColor: clear?.loadOp === \"clear\" ? clear.clearValue : undefined,\n clearDepth: attachments?.depth?.loadOp === \"clear\" ? attachments.depth.clearValue : undefined\n });\n }\n\n /**\n * The render-pass descriptor when textures are bound: every bound colour\n * slot and the bound depth stencil, as Metal's pass descriptor holds the\n * textures `SetRenderAttachments` and `SetDepthAttachment` put there\n * (`MetalWorkQueue.mm:2000-2096`). Unhinted attachments LOAD and STORE, the\n * backend default the canvas path also keeps. The hint's colours are the\n * bound slots in order, which is how `Clear` builds them.\n */\n _TextureDescriptor(attachments)\n {\n const bound = this._workQueue.GetAttachments();\n const hinted = attachments?.colors ?? [];\n let next = 0;\n\n const colorAttachments = bound.colors.map(color =>\n {\n if (!color) return null;\n\n const hint = hinted[next++] ?? null;\n const clear = hint?.loadOp === \"clear\";\n\n return {\n view: color.texture.GetDeviceRenderTargetView(color.slice),\n loadOp: clear ? \"clear\" : \"load\",\n storeOp: hint?.storeOp ?? \"store\",\n ...(clear ? { clearValue: gpuColor(hint.clearValue) } : {})\n };\n });\n\n while (colorAttachments.length && !colorAttachments[colorAttachments.length - 1]) colorAttachments.pop();\n\n const descriptor = { label: `pass ${this._workQueue.GetPassCount()}`, colorAttachments };\n const depth = bound.depth?.texture ?? null;\n\n if (depth)\n {\n const hint = attachments?.depth ?? null;\n const clear = hint?.loadOp === \"clear\";\n const stencil = depth.GetDeviceFormat().includes(\"stencil\");\n\n descriptor.depthStencilAttachment = {\n view: depth.GetDeviceRenderTargetView(0),\n depthLoadOp: clear ? \"clear\" : \"load\",\n depthStoreOp: hint?.storeOp ?? \"store\",\n ...(clear ? { depthClearValue: hint.clearValue } : {}),\n ...(stencil\n ? { stencilLoadOp: clear ? \"clear\" : \"load\", stencilStoreOp: \"store\", ...(clear ? { stencilClearValue: 0 } : {}) }\n : {})\n };\n }\n\n return descriptor;\n }\n\n /**\n * Closes the frame's last pass and submits the command buffer.\n *\n * SYNCHRONOUS, AS CARBON'S IS. The first version awaited the dispatcher's\n * preparation here, because the backend had been handed batches it still had\n * to turn into pipelines. It is handed verbs now, every draw resolved inside\n * the verb that issued it, and there is nothing left to wait for: `finish()`\n * and `queue.submit()` are synchronous calls. A caller that awaits this\n * still may; awaiting a non-promise costs nothing.\n *\n * @returns {boolean} Whether the scene ended cleanly.\n */\n EndScene()\n {\n this._Record(this._workQueue.EndFrame());\n\n // UNBINDS WHAT THE FRAME BOUND, AS CARBON DOES\n // (`Tr2RenderContextMetal.mm:869-873`): vertex layout, resource set and\n // shader program go back to empty and the draw check is forced on. Without\n // it the next frame inherits the last frame's program and declaration, and\n // the early-return in `SetShaderProgram` then SKIPS the rebind because the\n // incoming program compares equal to the stale one - so the first draw of a\n // frame runs against state nobody in that frame asked for. Same shape as\n // the render-target inheritance `ResetRenderTargets` fixes at BeginScene.\n //\n // The pipeline description's program reference goes with it, because the\n // description and the field are two halves of one binding: leaving it set\n // while the field is null would resolve a pipeline for a program the\n // context does not consider bound. `_pipelineDirty` is this backend's\n // `m_needsDrawResourceCheck` - nothing is assumed resolved across frames.\n this._vertexLayout = null;\n this._resourceSet = null;\n this._shaderProgram = null;\n this._psoDescription.shaderProgram = null;\n this._pipelineDirty = true;\n\n this._frameNumber += 1;\n\n if (this._commandEncoder)\n {\n // EndFrame has already closed the last pass, so finishing here is safe.\n this._webgpu.Submit([ this._commandEncoder.finish() ]);\n this._workQueue.SetCommandEncoder(null);\n this._commandEncoder = null;\n this._frame = null;\n }\n\n return true;\n }\n\n\n /**\n * Declares what the next render pass does with its attachments.\n *\n * Carbon's two overloads differ only in how many colour attachments they\n * carry, so they collapse into one variadic list. The depth attachment is\n * always last.\n *\n * @param {...object} attachments `Tr2ColorAttachment`s then a `Tr2DepthAttachment`.\n */\n RenderPassHint(...attachments)\n {\n const depth = attachments.length ? attachments[attachments.length - 1] : null;\n const colors = attachments.slice(0, -1);\n\n this._workQueue.RenderPassHint(colors, depth);\n }\n\n /** Ends the declared pass, so following work opens a new one. */\n EndRenderPassHint()\n {\n this._Record(this._workQueue.EndRenderPassHint());\n }\n\n /**\n * Binds a colour target at one slot.\n *\n * RESETS THE VIEWPORT TO THE NEW TARGET, which Carbon does here in the\n * backend (`Tr2RenderContextMetal.mm:762-766`) whenever slot zero changes.\n * Leaving it alone is the defect where a 2048 shadow pass leaves the viewport\n * at 2048 for the rest of the frame.\n *\n * @param {number} slot The slot.\n * @param {object|null} renderTarget A `Tr2TextureAL`, or null to detach.\n * @param {number} [slice] The array slice or cube face.\n * @returns {boolean} True.\n */\n SetRenderTarget(slot, renderTarget, slice = 0)\n {\n if (slot >= MAX_RENDER_TARGET) return false;\n\n this._Record(this._workQueue.SetRenderAttachments(renderTarget ?? null, slot, slice));\n\n // The attachment formats are part of the pipeline; DX12 dirties its PSO\n // here too (`Tr2RenderContextDx12.cpp:456`).\n if (this._boundRenderTargets[slot] !== (renderTarget ?? null)) this._pipelineDirty = true;\n\n this._boundRenderTargets[slot] = renderTarget ?? null;\n\n const primary = this._boundRenderTargets[0];\n\n if (slot === 0 && primary)\n {\n this.SetViewport({ x: 0, y: 0, width: primary.GetWidth(), height: primary.GetHeight() });\n }\n\n return true;\n }\n\n /**\n * The target bound at one slot.\n *\n * @param {number} [slot] The slot.\n * @returns {object|null} The target.\n */\n GetRenderTarget(slot = 0)\n {\n return this._boundRenderTargets[slot] ?? null;\n }\n\n /**\n * Saves the target bound at one slot.\n *\n * ONE STACK PER SLOT, as Carbon has (`m_stackRT[MAX_RENDER_TARGET]`). A single\n * shared stack pops the most recent push whatever its slot, so pushing slot 0\n * then slot 1 and popping slot 0 restores the wrong surface.\n *\n * @param {number} [slot] The slot.\n * @returns {boolean} True.\n */\n PushRenderTarget(slot = 0)\n {\n if (slot >= MAX_RENDER_TARGET) return false;\n\n this._renderTargetStacks[slot].push(this._boundRenderTargets[slot] ?? null);\n\n return true;\n }\n\n /**\n * Restores the target saved for one slot.\n *\n * @param {number} [slot] The slot.\n * @returns {boolean} Whether anything was saved.\n */\n PopRenderTarget(slot = 0)\n {\n const stack = this._renderTargetStacks[slot];\n\n if (!stack?.length) return false;\n\n this.SetRenderTarget(slot, stack.pop());\n\n return true;\n }\n\n /**\n * Depth of one slot's stack.\n *\n * @param {number} [slot] The slot.\n * @returns {number} The depth.\n */\n GetStackSizeRT(slot = 0)\n {\n return this._renderTargetStacks[slot]?.length ?? 0;\n }\n\n /**\n * Binds the depth-stencil target.\n *\n * @param {object|null} depthStencil A `Tr2TextureAL`, or null to detach.\n * @returns {boolean} True.\n */\n SetDepthStencil(depthStencil)\n {\n const previous = this._depthStencil;\n\n this._Record(this._workQueue.SetDepthAttachment(depthStencil ?? null));\n\n // Unbinding ends the pass that wrote the depth, so a sampled depth\n // texture's float shadow is refreshed here (CjsWebgpuTextureAL._depthShadow).\n if (previous && previous !== (depthStencil ?? null)) this._Record(this._workQueue.CopyDepthShadow(previous));\n\n if (this._depthStencil !== (depthStencil ?? null)) this._pipelineDirty = true;\n\n this._depthStencil = depthStencil ?? null;\n\n return true;\n }\n\n /** @returns {object|null} The bound depth-stencil target. */\n GetDepthStencil()\n {\n return this._depthStencil;\n }\n\n /** Saves the bound depth-stencil target. @returns {boolean} True. */\n PushDepthStencil()\n {\n this._depthStencilStack.push(this._depthStencil);\n\n return true;\n }\n\n /** Restores the saved depth-stencil target. @returns {boolean} Whether one was saved. */\n PopDepthStencil()\n {\n if (!this._depthStencilStack.length) return false;\n\n this.SetDepthStencil(this._depthStencilStack.pop());\n\n return true;\n }\n\n /** @returns {number} Depth of the depth-stencil stack. */\n GetStackSizeDS()\n {\n return this._depthStencilStack.length;\n }\n\n /**\n * The size of the target at one slot.\n *\n * @param {number} [slot] The slot.\n * @returns {object} `{ result, width, height }`.\n */\n GetRenderTargetSize(slot = 0)\n {\n const target = this._boundRenderTargets[slot];\n\n if (!target) return { result: ALResult.E_INVALIDCALL, width: 0, height: 0 };\n\n return { result: ALResult.S_OK, width: target.GetWidth(), height: target.GetHeight() };\n }\n\n /**\n * Sets the viewport following draws use.\n *\n * @param {object} viewport `{ x, y, width, height }`.\n * @returns {boolean} True.\n */\n SetViewport(viewport)\n {\n this._viewport = viewport ? { ...viewport } : null;\n\n return true;\n }\n\n /** @returns {object|null} The current viewport. */\n GetViewport()\n {\n return this._viewport ? { ...this._viewport } : null;\n }\n\n /**\n * Clears the bound attachments.\n *\n * A CLEAR IS A LOAD OPERATION, not a command. WebGPU has no mid-pass clear,\n * so this ends the current pass and declares the next one's load actions -\n * which is the same thing `RenderPassHint` does, arrived at from the other\n * direction. Carbon's Metal backend folds a clear the same way.\n *\n * CARBON'S FLAGS AND SLOT (`Tr2RenderContextMetal.mm:297-351`): the colour\n * clear names ONE slot, and depth is cleared only when asked. Every other\n * attached colour slot loads, so clearing the velocity target at slot 1\n * leaves slot 0 alone. `clearColor`/`clearDepth`/`clearStencil` are\n * CLEARFLAGS_TARGET/ZBUFFER/STENCIL; a call naming none of them clears the\n * target and depth, which is what every caller without flags meant. As in\n * Metal, a cleared target or depth that is not bound is E_INVALIDCALL.\n *\n * @param {object} [options] `{ color, depth, stencil, clearColor, clearDepth, clearStencil, slot }`.\n * @returns {boolean} Whether the clear was declared.\n */\n Clear(options = {})\n {\n const flagged = \"clearColor\" in options || \"clearDepth\" in options || \"clearStencil\" in options;\n const clearTarget = flagged ? !!options.clearColor : true;\n const clearDepth = flagged ? !!(options.clearDepth || options.clearStencil) : true;\n const slot = options.slot ?? 0;\n const attachments = this._workQueue.GetAttachments();\n\n if (clearTarget && !attachments.colors[slot]) return false;\n if (flagged && clearDepth && !attachments.depth) return false;\n\n const colors = [];\n\n attachments.colors.forEach((attachment, index) =>\n {\n if (!attachment) return;\n colors.push(clearTarget && index === slot\n ? new Tr2ColorAttachment(Tr2LoadAction.CLEAR, Tr2StoreAction.STORE, options.color ?? 0)\n : new Tr2ColorAttachment(Tr2LoadAction.LOAD, Tr2StoreAction.STORE));\n });\n\n const depth = attachments.depth\n ? (clearDepth\n ? new Tr2DepthAttachment(Tr2LoadAction.CLEAR, Tr2StoreAction.STORE, Number(options.depth ?? 1))\n : new Tr2DepthAttachment(Tr2LoadAction.LOAD, Tr2StoreAction.STORE))\n : null;\n\n this._workQueue.RenderPassHint(colors, depth);\n\n return true;\n }\n\n /**\n * Dispatches the bound compute program.\n *\n * Carbon's AL verb (`Tr2RenderContextDx11.h:151`); Metal's is the compute\n * encoder's `DispatchThreadgroups`. The program, its resource set and its\n * constants are whatever `Tr2Renderer.runComputeShader` bound for the pass.\n * WebGPU needs a `GPUComputePipeline`, made once per program here, where a\n * D3D context binds the compute shader directly.\n *\n * @param {number} x Thread groups along x.\n * @param {number} y Thread groups along y.\n * @param {number} z Thread groups along z.\n * @returns {boolean} Whether the dispatch was encoded.\n */\n RunComputeShader(x, y, z)\n {\n if (!this._webgpu) return false;\n\n const program = this._shaderProgram;\n const module = program && typeof program.GetModuleFor === \"function\"\n ? program.GetModuleFor(ShaderType.COMPUTE_SHADER)\n : null;\n\n if (!module) return this._RefusePipeline(\"a compute program\");\n\n let pipeline = this._computePipelines.get(program) ?? null;\n\n if (!pipeline)\n {\n pipeline = this._webgpu.GetDevice().createComputePipeline({\n label: `Tr2RenderContextAL compute ${program.GetIdentity()}`,\n layout: program.GetPipelineLayout(),\n compute: { module, entryPoint: WEBGPU_ENTRY_POINT }\n });\n this._computePipelines.set(program, pipeline);\n }\n\n if (!this._EmitBindGroups()) return false;\n\n this._workQueue.SetComputePipeline(pipeline);\n this._Record(this._workQueue.DispatchThreadgroups(x, y, z));\n\n return true;\n }\n\n /** Compute pipelines by program; a program's compute pipeline has no other state. */\n _computePipelines = new WeakMap();\n\n /** The mip generator textures on this context use, made on first ask. */\n _mipGenerator = null;\n\n /**\n * The mip generator, standing in for the blit encoder's `generateMipmaps`\n * that Metal's work queue calls (see CjsWebgpuMipGenerator).\n *\n * @returns {CjsWebgpuMipGenerator} The generator.\n */\n GetMipGenerator()\n {\n this._mipGenerator ??= new CjsWebgpuMipGenerator(this._webgpu.GetDevice());\n return this._mipGenerator;\n }\n\n /**\n * Runs a compute dispatch whose group counts are read from a buffer.\n *\n * REFUSES; see `RunComputeShader`. This validated the buffer and then set the\n * compute encoder type, which is not a dispatch - the same false success, with\n * an argument check in front of it that made it look like more.\n *\n * Carbon's stub refuses too (`stub/Tr2RenderContextStub.h:175-178`).\n *\n * @param {object} _effect The compute effect to run.\n * @param {object} _indirectionBuffer A buffer holding the group counts.\n * @param {number} [_offsetForArgs] Byte offset to them.\n * @returns {boolean} False; nothing is dispatched.\n */\n RunComputeShaderIndirect(_effect, _indirectionBuffer, _offsetForArgs = 0)\n {\n return false;\n }\n\n /**\n * Clears an unordered-access resource.\n *\n * A BUFFER CLEARED TO ZERO is encoded: Metal's `ClearUav` hands it to\n * `MetalWorkQueue::ClearBuffer` (`Tr2RenderContextMetal.mm:237-257`), whose\n * zero fast path is a blit fill (`MetalWorkQueue.mm:1216-1225`), and WebGPU's\n * `clearBuffer` is that fill. A float zero is the same bits, so it takes the\n * same path; negative zero does not.\n *\n * EVERYTHING ELSE REFUSES RATHER THAN PRETENDS: a non-zero value needs\n * Metal's clear compute shader, and a texture needs `ClearTexture`, neither\n * of which exists here. Reporting success would leave a caller reading stale\n * contents it believes are cleared, which a compute pass cannot detect.\n * Carbon's stub refuses the same way (`Tr2RenderContextALStub.ClearUav`).\n *\n * @param {object} resource The buffer or texture to clear.\n * @param {number[]} value The clear value, four components.\n * @param {boolean} [_clearWithFloat] Whether the value is float or integer.\n * @returns {boolean} Whether the clear was encoded.\n */\n ClearUav(resource, value, _clearWithFloat = false)\n {\n const buffer = DeviceBufferOf(resource);\n\n if (!buffer) return false;\n\n for (let index = 0; index < 4; index += 1)\n {\n if (!Object.is(Number(value?.[index] ?? 0), 0)) return false;\n }\n\n this._Record(this._workQueue.ClearBuffer(buffer));\n\n return true;\n }\n\n /**\n * Presents the frame (`Tr2RenderContextMetal.mm:879-886`): the swap chain\n * presents and the render targets reset. It does NOT end the scene. Carbon's\n * TriDevice::HandleRenderTick presents the previous frame, which EndScene\n * already submitted, before Render opens the next. This called EndScene, so\n * a Present during an open frame closed it underneath its owner.\n *\n * The browser presents a configured canvas after the submission that drew\n * into its current texture, so the swap-chain half has nothing to do.\n *\n * @returns {boolean} True.\n */\n Present()\n {\n return this.ResetRenderTargets();\n }\n\n /**\n * Sets the primitive topology following draws use.\n *\n * @param {number} topology A `Topology` value.\n * @returns {boolean} Whether the AL knows it.\n */\n SetTopology(topology)\n {\n if (topology >= Topology.TOP_MAX_TOPOLOGY || !VERTICES_PER_PRIMITIVE[topology]) return false;\n\n this._topology = topology;\n this._psoDescription.topology = topology;\n this._pipelineDirty = true;\n\n return true;\n }\n\n /**\n * Binds the vertex declaration.\n *\n * @param {object} layout A `Tr2VertexLayoutAL`.\n * @returns {boolean} True.\n */\n SetVertexLayout(layout)\n {\n if (this._vertexLayout === layout) return true;\n\n // DIRTIES THE PIPELINE, AS DX12'S DOES (`Tr2RenderContextDx12.cpp:321`).\n // The descriptor itself is built at the draw, not here: Metal's\n // SetVertexLayout only stores the layout (`Tr2RenderContextMetal.mm:894`)\n // and CheckDrawResources matches it against the BOUND PROGRAM's inputs at\n // draw time (`:524-541`), because the same declaration yields a different\n // descriptor under a shader that reads a different subset of it.\n this._vertexLayout = layout;\n this._pipelineDirty = true;\n\n return true;\n }\n\n /**\n * Binds one vertex stream.\n *\n * @param {number} stream The slot.\n * @param {object} buffer A `Tr2BufferAL`.\n * @param {number} offset Byte offset.\n * @param {number} stride Bytes per vertex.\n * @returns {boolean} True.\n */\n SetStreamSource(stream, buffer, offset, stride)\n {\n // The stride is part of the pipeline on WebGPU - `arrayStride` lives in the\n // vertex buffer layout - exactly as it is on Metal, where each active\n // stream's stride feeds the vertex-descriptor hash\n // (`MetalWorkQueue.mm:1512-1531`). The buffer itself is not.\n if (this._streams[stream]?.stride !== stride) this._pipelineDirty = true;\n\n this._streams[stream] = { buffer, offset, stride };\n\n return true;\n }\n\n /**\n * Binds the index buffer.\n *\n * @param {object} buffer A `Tr2BufferAL`.\n * @param {number} [stride] Bytes per index.\n * @returns {boolean} True.\n */\n SetIndices(buffer, stride = 0)\n {\n this._indexBuffer = buffer;\n this._indexStride = stride;\n\n return true;\n }\n\n /**\n * Binds the shader program following draws run.\n *\n * @param {object} shaderProgram A `Tr2ShaderProgramAL`.\n * @returns {boolean} True.\n */\n SetShaderProgram(shaderProgram)\n {\n if (this._shaderProgram === shaderProgram) return true;\n\n this._shaderProgram = shaderProgram;\n this._psoDescription.shaderProgram = shaderProgram;\n this._pipelineDirty = true;\n\n return true;\n }\n\n /**\n * Takes the render-state setup a pass authored, with the state manager's\n * overrides applied.\n *\n * Carbon's backends receive a resolved state-PAIR list here and set each pair\n * on the device (`Tr2EffectStateManager.cpp:753`). WebGPU has no per-state\n * setter - state is folded into a pipeline at creation - so the setup is held\n * and projected when a pipeline is resolved, which is also why the projection\n * needs the depth format only this backend knows.\n *\n * THE PROJECTION IS NOT DONE HERE. `Tr2RenderStateSetup.GetWebgpuRecipe`\n * already does it and the batch resolver already uses it; a second translator\n * would be the mistake this whole lane exists to undo. This stores the inputs\n * and marks the pipeline dirty, as Carbon's setters do.\n *\n * @param {object} setup A `Tr2RenderStateSetup`.\n * @param {object} [overrides] The state manager's render-state overrides.\n * @returns {boolean} Whether a setup was supplied.\n */\n SetRenderStates(setup, overrides = null)\n {\n if (!setup) return false;\n\n // Carbon's setters compare before dirtying, so a redundant apply costs\n // nothing (Tr2RenderContextDx12.cpp:315-338). The overrides are compared BY\n // VALUE: the state manager hands a fresh copy each apply, and comparing\n // references made every apply dirty the pipeline.\n if (this._renderStateSetup === setup && CanonicalKey(this._renderStateOverrides) === CanonicalKey(overrides)) return true;\n\n this._renderStateSetup = setup;\n this._renderStateOverrides = overrides;\n this._psoDescription.renderStateSetup = setup;\n this._psoDescription.renderStateOverrides = overrides;\n this._pipelineDirty = true;\n\n return true;\n }\n\n /**\n * m_renderStates - single states set by name rather than through a setup.\n *\n * A DIFFERENT AXIS FROM `overrides`, which is a flags object the PSO\n * description reads (`core/psoDescription.js:113-114`). These are Carbon's\n * raw `RenderState` values, which `TriStepSetRenderState` sets one at a time.\n */\n _renderStates = new Map();\n\n /**\n * Sets one render state.\n *\n * Carbon's Metal backend stores the value and applies it when the pipeline is\n * assembled, and says so in a comment above the method: \"we'll remove the\n * actual setting here and just store the values in some state and we'll do a\n * wholesale setting of state in some combined function just before we draw\"\n * (`Tr2RenderContextMetal.mm:925-928`). This stores.\n *\n * THE PSO RESOLVER DOES NOT READ THESE YET. `GetWebgpuRecipe` projects the\n * setup and the flags, and nothing consumes the single-state map, so a state\n * set this way is recorded and not yet honoured. Recorded rather than dropped,\n * because the resolver is where the projection belongs and adding a second\n * translator here is the mistake this file already carries a warning about.\n *\n * @param {number} state A `RenderState` value.\n * @param {number} value The value to set.\n * @returns {boolean} True.\n */\n SetRenderState(state, value)\n {\n const key = state >>> 0;\n\n if (this._renderStates.get(key) === (value >>> 0)) return true;\n\n this._renderStates.set(key, value >>> 0);\n this._pipelineDirty = true;\n\n return true;\n }\n\n /** The setup, overrides and single states a pipeline should be resolved from. */\n GetRenderStateInputs()\n {\n return {\n setup: this._renderStateSetup,\n overrides: this._renderStateOverrides,\n states: this._renderStates\n };\n }\n\n /** Whether the pipeline description changed since it was last resolved. */\n IsPipelineDirty()\n {\n return this._pipelineDirty;\n }\n\n /**\n * The pipeline description the setters have accumulated.\n *\n * Carbon's `m_psoDescription`, and `GetMissing()` on it answers the question\n * `GetPipelineState` answers by returning null: what this state does not yet\n * name. Reading it does not resolve anything.\n *\n * @returns {CjsWebgpuPsoDescription} The live description.\n */\n GetPsoDescription()\n {\n this._RefreshAttachmentFormats();\n\n return this._psoDescription;\n }\n\n /** The pipeline the last resolve produced, or null. */\n _pipeline = null;\n\n /**\n * Resolved pipelines by description key.\n *\n * Carbon keeps this on the DEVICE (`m_ownerDevice->m_pipelineStates`,\n * `Tr2PrimaryRenderContextDx12.h:319`; Metal's `GetCachedRenderPipelineState`)\n * so every context shares one. It lives here until `CjsWebgpuDevice` offers a\n * synchronous cache - its `CjsWebgpuPipelineCache` resolves asynchronously,\n * and a draw verb cannot await. Cleared with the device resources.\n */\n _pipelines = new Map();\n\n /**\n * Why the last `EmitRenderEncoderState` refused, or null when it did not.\n *\n * Carbon asserts at these points; a JS frame must not die at a draw, so the\n * reason is kept where a harness can read it instead.\n */\n m_pipelineFailure = null;\n\n /**\n * Resolves and binds the pipeline the bound state describes.\n *\n * METAL'S `EmitRenderPipelineState` (`MetalWorkQueue.mm:1595-1747`) AND\n * DX12'S `SetAllState` (`Tr2RenderContextDx12.cpp:810-878`): called from\n * inside every draw verb, keyed on the description's hash, creating on a miss\n * and otherwise reusing, and clearing the dirty flag once resolved\n * (`:870`). Pipeline creation is SYNCHRONOUS here as it is there -\n * `createRenderPipeline` returns immediately, and the first-use stall it can\n * carry is the same one `newRenderPipelineStateWithDescriptor` carries.\n *\n * The vertex half of the description is built here rather than by\n * `SetVertexLayout`, because it depends on three bound things at once: the\n * declaration, the program whose inputs select from it, and the stream\n * strides (`Tr2RenderContextMetal.mm:524-541`, `MetalWorkQueue.mm:1842-1863`).\n *\n * Uncomposed, there is no device and nothing to resolve; the verbs record as\n * the stub's do.\n *\n * @returns {boolean} Whether a pipeline is bound for the next draw.\n */\n EmitRenderPipelineState()\n {\n if (!this._webgpu) return true;\n\n if (!this._pipelineDirty && this._pipeline)\n {\n this._workQueue.SetRenderPipeline(this._pipeline);\n\n return true;\n }\n\n const description = this.GetPsoDescription();\n const program = description.shaderProgram;\n\n if (!program || typeof program.GetPipelineLayout !== \"function\")\n {\n return this._RefusePipeline(\"a program this backend linked\");\n }\n\n const vertexBufferLayouts = this.BuildVertexBufferLayouts();\n\n if (typeof vertexBufferLayouts === \"string\") return this._RefusePipeline(vertexBufferLayouts);\n\n description.vertexBufferLayouts = vertexBufferLayouts;\n\n const missing = description.GetMissing();\n\n if (missing) return this._RefusePipeline(missing);\n\n if (!program.GetModuleFor(ShaderType.VERTEX_SHADER)) return this._RefusePipeline(\"a vertex stage\");\n\n // An indexed strip needs its index format baked into the pipeline\n // (`primitive.stripIndexFormat`), so the bound index stride is part of the\n // identity for strips and nothing else.\n const topology = TOPOLOGIES[this._topology];\n const stripIndexFormat = topology && topology.endsWith(\"-strip\") ? INDEX_FORMAT[this._indexStride] ?? null : null;\n let key;\n let recipe;\n\n // `GetWebgpuRecipe` refuses a state it cannot project - a non-solid fill,\n // depth state against no depth attachment - by THROWING. A draw verb is not\n // where a frame may die, so the refusal becomes this verb's reason.\n try\n {\n key = `${description.GetKey()}|strip:${stripIndexFormat ?? \"-\"}`;\n recipe = description.BuildRecipe();\n }\n catch (error)\n {\n return this._RefusePipeline(`a projectable state: ${error.message}`);\n }\n\n if (stripIndexFormat) recipe.primitive = { ...recipe.primitive, stripIndexFormat };\n\n let pipeline = this._pipelines.get(key) ?? null;\n const created = pipeline === null;\n\n if (created)\n {\n pipeline = this._CreateRenderPipeline(program, recipe);\n this._pipelines.set(key, pipeline);\n }\n\n this._pipeline = pipeline;\n this._pipelineDirty = false;\n this.m_pipelineFailure = null;\n this._Record([ { type: \"pipeline\", key, created } ]);\n this._workQueue.SetRenderPipeline(pipeline);\n\n return true;\n }\n\n /**\n * Binds everything a draw needs on the encoder: pipeline, then buffers.\n *\n * Metal's `EmitRenderEncoderState` (`MetalWorkQueue.mm:1750-1890`), which\n * the draw verbs call first and skip the draw when it fails. Bindings are\n * deferred to here rather than set in `SetStreamSource`, as Metal defers\n * them (`:2570-2598` stores, `:2613-2690` binds).\n *\n * WHAT IT CANNOT HONOUR, IT REFUSES. A pipeline or bind group that cannot be\n * resolved, or a stream or index buffer that is not a device buffer, would\n * be a validation error on the GPU, so the draw is refused here and says why.\n *\n * @param {boolean} indexed Whether the draw reads the bound index buffer.\n * @returns {boolean} Whether the encoder is ready to draw.\n */\n EmitRenderEncoderState(indexed)\n {\n if (!this._webgpu) return true;\n\n // A reason describes THIS attempt; one left from an earlier refusal would\n // outlive the draw that succeeded after it.\n this.m_pipelineFailure = null;\n\n if (!this.EmitRenderPipelineState()) return false;\n\n if (!this._EmitBindGroups()) return false;\n\n const layouts = this._psoDescription.vertexBufferLayouts;\n\n for (let slot = 0; slot < layouts.length; slot += 1)\n {\n if (!layouts[slot]) continue;\n\n if (slot === this._dummyVertexStream)\n {\n this._workQueue.SetVertexBuffer(slot, this._DummyVertexBuffer(), 0);\n continue;\n }\n\n const stream = this._streams[slot];\n const buffer = DeviceBufferOf(stream?.buffer);\n\n if (!buffer) return this._RefusePipeline(`a device buffer on vertex stream ${slot}`);\n\n this._workQueue.SetVertexBuffer(slot, buffer, stream.offset ?? 0);\n }\n\n if (indexed)\n {\n const format = INDEX_FORMAT[this._indexStride] ?? null;\n const buffer = DeviceBufferOf(this._indexBuffer);\n\n if (!format) return this._RefusePipeline(`an index format for a ${this._indexStride}-byte stride`);\n if (!buffer) return this._RefusePipeline(\"a device buffer for the indices\");\n\n this._workQueue.SetIndexBuffer(buffer, format, 0);\n }\n\n return true;\n }\n\n /**\n * The vertex buffer layouts the bound declaration, program and strides\n * describe, one per stream slot.\n *\n * Metal's `Tr2VertexLayoutAL::SetVertexLayout` (`Tr2VertexLayoutALMetal.mm:205-245`):\n * match the program's pipeline inputs against the declaration's items, and\n * stamp each active stream's stride. An input the declaration lacks gets no\n * attribute - Metal points it at a dummy stream - and a stream no input\n * reads gets no layout.\n *\n * @returns {Array<object|null>|string} The layouts by slot, or what is\n * missing when they cannot be built.\n */\n BuildVertexBufferLayouts()\n {\n const layout = this._vertexLayout;\n\n if (!layout) return [];\n\n const elements = layout.GetDefinition() ?? [];\n const inputs = this._shaderProgram.GetInputs();\n const plan = resolveBindingPlan(elements, inputs);\n const byStream = new Map();\n\n // AN INPUT THE DECLARATION LACKS IS A REFUSAL, NOT A HOLE. WebGPU requires\n // every vertex-stage `@location` to be fed, and `createRenderPipeline`\n // with a missing one yields an invalid pipeline WITHOUT throwing - which\n // would then be cached. Metal feeds such an input from a constant-step\n // dummy stream (`Tr2VertexLayoutALMetal.mm:155-159`); until that is\n // ported, the draw says which input it cannot feed.\n const missing = plan.entries.filter(entry => !entry.element);\n\n this._dummyVertexStream = null;\n\n for (const entry of plan.entries)\n {\n if (!entry.element) continue;\n\n const stream = entry.element.stream ?? 0;\n\n if (!byStream.has(stream)) byStream.set(stream, []);\n byStream.get(stream).push(entry);\n }\n\n const layouts = new Array(byStream.size ? Math.max(...byStream.keys()) + 1 : 0).fill(null);\n\n for (const [ stream, entries ] of byStream)\n {\n const stride = this._streams[stream]?.stride;\n\n if (!stride) return `a stride for vertex stream ${stream}`;\n\n try\n {\n layouts[stream] = WebgpuVertexBufferLayout(stride, entries);\n }\n catch (error)\n {\n return `a vertex format for stream ${stream}: ${error.message}`;\n }\n }\n\n // AN INPUT THE DECLARATION LACKS READS A CONSTANT DUMMY STREAM, as Metal's\n // does (Tr2VertexLayoutALMetal.mm:145-165): every missing input at offset\n // 0 of one stream that does not step, in a format from the input's\n // declared type - INT char4, UINT uchar4, anything else float4. WebGPU\n // spells \"does not step\" as arrayStride 0, and requires every vertex-stage\n // location to be fed, so leaving the hole is an invalid pipeline. The\n // stream takes the first slot after the mesh's own.\n if (missing.length)\n {\n this._dummyVertexStream = layouts.length;\n layouts.push({\n arrayStride: 0,\n stepMode: \"vertex\",\n attributes: missing\n .map(entry => ({ shaderLocation: entry.registerIndex, offset: 0, format: DUMMY_VERTEX_FORMAT[entry.fallbackType] ?? \"float32x4\" }))\n .sort((a, b) => a.shaderLocation - b.shaderLocation)\n });\n }\n\n return layouts;\n }\n\n /** The slot of the constant dummy vertex stream this layout added, or null. */\n _dummyVertexStream = null;\n\n /**\n * Metal's dummy vertex buffer (the METAL_VERTEX_STREAM_DUMMY stream): 16\n * zero bytes, the widest dummy element, read by every missing input.\n * WebGPU zero-fills a new buffer.\n */\n _DummyVertexBuffer()\n {\n const usage = this._webgpu.GetBufferUsage();\n\n this._dummies.vertexBuffer ??= this._webgpu.GetDevice().createBuffer({\n label: \"Tr2RenderContextAL dummy vertex stream\",\n size: 16,\n usage: usage.VERTEX | usage.COPY_DST\n });\n\n return this._dummies.vertexBuffer;\n }\n\n /**\n * Bind groups by `program | group | resource set | constant buffers`.\n *\n * DX12's descriptor tables live on the CONTEXT, per back buffer\n * (`Tr2RenderContextDx12.h:269`), and are committed at `SetAllState`\n * (`:875`); Metal binds per stage inside `EmitRenderEncoderState`\n * (`MetalWorkQueue.mm:2613-2690`). A WebGPU bind group is an immutable object\n * made of both the set's entries and the bound constant buffers, so it is\n * made here, at the draw, and kept by the identities that produced it.\n */\n _bindGroups = new Map();\n\n /**\n * Builds or reuses one bind group per program group and names them for the\n * draw.\n *\n * The program's uniform slots read the constant buffers `SetConstants` bound\n * at that stage and register - Carbon's parallel road for CBs - uploading\n * each buffer's shadow if it changed, which is where Carbon's token is\n * consumed. Every other slot reads the resource set; with no set bound, or a\n * set made for another program, the slots take dummies, which is Metal's\n * `SetDummyResources` (`Tr2RenderContextMetal.mm:527-530`).\n *\n * @returns {boolean} Whether every group could be built.\n */\n _EmitBindGroups()\n {\n const program = this._shaderProgram;\n const layouts = program.GetBindGroupLayouts();\n\n if (!layouts.length) return true;\n\n const set = this._resourceSet?.m_resourceSet.implementation;\n const entries = set && set.IsValid() && set.GetProgram() === program ? set.GetEntries() : null;\n const setId = entries ? set.m_id : 0;\n const bindings = program.GetBindings();\n const device = this._webgpu.GetDevice();\n\n for (let group = 0; group < layouts.length; group += 1)\n {\n const keyParts = [ program.GetIdentity(), group, setId ];\n const resolved = [];\n const dynamicOffsets = [];\n\n for (const binding of bindings)\n {\n if (binding.group !== group) continue;\n\n let resource;\n\n if (binding.buffer && binding.buffer.type === \"uniform\")\n {\n // METAL'S `SetConstants` + `UploadConstants` (`MetalWorkQueue.mm:2396-2439`):\n // the shadow is copied into the frame's arena if its token is stale,\n // and the bind is the PAGE with the region's offset as a dynamic\n // offset - `setVertexBufferOffset:` (`:2656-2659`). The bind group\n // therefore keys on the page and not on the buffer: two objects\n // drawn through one program share one bind group and differ only in\n // their offsets, which is the whole economy of the arena.\n const size = binding.buffer.minBindingSize ?? 16;\n const constantBuffer = this._ConstantBufferFor(binding);\n\n if (constantBuffer)\n {\n const region = this.UploadConstants(constantBuffer, size);\n\n resource = { buffer: this._Arena().GetPage(region.page), offset: 0, size };\n dynamicOffsets.push(region.offset);\n keyParts.push(`p${region.page}`);\n }\n else\n {\n // DX12 substitutes a null CB for an unbound root CBV\n // (`DescriptorStateCacheDx12.cpp:234-242`).\n resource = { buffer: this.GetNullBuffer(size, \"UNIFORM\"), offset: 0, size };\n dynamicOffsets.push(0);\n keyParts.push(\"null\");\n }\n }\n else\n {\n resource = entries ? entries.get(`${group}:${binding.binding}`) ?? null : null;\n resource ??= this._DummyFor(binding);\n }\n\n resolved.push({ binding: binding.binding, resource });\n }\n\n const key = keyParts.join(\"|\");\n let bindGroup = this._bindGroups.get(key) ?? null;\n\n if (!bindGroup)\n {\n // Identities are monotonic, so a key never comes back once its set or\n // buffer is gone; without a bound the map grows with every rebuild.\n // DX12's descriptor cache is per back buffer and rebuilt each frame\n // (`Tr2RenderContextDx12.h:269`); dropping everything and rebuilding\n // what the next draws need is the same cost profile.\n if (this._bindGroups.size >= MAX_CACHED_BIND_GROUPS) this._bindGroups.clear();\n\n bindGroup = device.createBindGroup({\n label: `Tr2RenderContextAL ${program.GetIdentity()} group${group}`,\n layout: layouts[group],\n entries: resolved\n });\n this._bindGroups.set(key, bindGroup);\n }\n\n this._workQueue.SetBindGroup(group, bindGroup, dynamicOffsets);\n }\n\n return true;\n }\n\n /** Carbon's `ConstantBufferAllocator`, owned by the context (`MetalContext.h:104`). */\n _constantArena = null;\n\n /** The frame's constant arena, made on first use. */\n _Arena()\n {\n this._constantArena ??= new CjsWebgpuConstantArena(this._webgpu);\n\n return this._constantArena;\n }\n\n /**\n * Copies constants into this frame's arena and says where they landed.\n *\n * CARBON'S TWO OVERLOADS, in one method as JavaScript spells them\n * (`Tr2RenderContextMetal.mm:679-697`, `Tr2RenderContextDx12.cpp:538-548`):\n *\n * - given BYTES, a fresh region every call - Carbon constructs a zeroed\n * token each time, so nothing is reused;\n * - given a `Tr2ConstantBufferAL`, the buffer's OWN token, so a buffer bound\n * twice in a frame without a Lock between keeps one region. Carbon reaches\n * straight into the impl for it (`buffer.m_buffer->m_token`), which is why\n * ours is public.\n *\n * Carbon returns a `uint64_t` packing Metal's page and offset together; the\n * region object is that pair unpacked, which is what a bind group needs.\n *\n * @param {object|ArrayBufferView} source A constant buffer, or the bytes.\n * @param {number} [size] Bytes the binding demands at least.\n * @returns {{page: number, offset: number, size: number}|null} The region,\n * or null when there is nothing to upload - Carbon's `return 0`.\n */\n UploadConstants(source, size = 0)\n {\n if (!this._webgpu || !source) return null;\n\n const arena = this._Arena();\n\n if (ArrayBuffer.isView(source)) return arena.Allocate(source, Math.max(size, source.byteLength));\n\n if (!(source instanceof CjsWebgpuConstantBufferAL) || !source.IsValid()) return null;\n\n const token = source.m_token;\n const wanted = Math.max(size, source.m_shadowCopy.length);\n\n // Metal's `UploadConstants` (`MetalWorkQueue.mm:2426-2439`): a token from\n // this frame is left alone. The size test is ours - a layout may demand\n // more than an earlier binding reserved, and a short region is a\n // validation error rather than a wrong picture.\n if (token.frame !== this.GetRecordingFrameNumber() || token.size < wanted)\n {\n const region = arena.Allocate(source.m_shadowCopy, wanted);\n\n token.frame = this.GetRecordingFrameNumber();\n token.page = region.page;\n token.offset = region.offset;\n token.size = region.size;\n }\n\n return token;\n }\n\n /**\n * NOT PORTED, and Metal-only in Carbon. `UseConstantBuffer` makes a constant\n * buffer resident on the COMPUTE encoder (`useResource:`,\n * `Tr2RenderContextMetal.mm:1658-1673`) and its only callers build the\n * ray-tracing shader table (`Tr2RtShaderTableALMetal.mm:61-68`). DX12 has no\n * such method. This backend dispatches no compute and has no ray tracing, so\n * there is nothing to make resident.\n */\n\n /** The constant buffer `SetConstants` bound for a uniform binding, by any visible stage. */\n _ConstantBufferFor(binding)\n {\n for (const [ bit, stage ] of [ [ 1, ShaderType.VERTEX_SHADER ], [ 2, ShaderType.PIXEL_SHADER ], [ 4, ShaderType.COMPUTE_SHADER ] ])\n {\n if ((binding.visibility & bit) === 0) continue;\n\n const buffer = this._constantBuffers.get(stage * CONSTANT_BUFFER_REGISTERS + binding.registerIndex) ?? null;\n\n // A buffer of another backend's kind - a stub made before this backend\n // was installed - has no shadow this arena can upload; it is skipped and\n // the slot takes the null buffer, which is DX12's answer to an unbound\n // CBV. Asked by TYPE, which is the question: Carbon has one constant\n // buffer class per compiled backend and cannot be handed another's.\n if (buffer instanceof CjsWebgpuConstantBufferAL && buffer.IsValid()) return buffer;\n }\n\n return null;\n }\n\n /** Metal's dummy for a slot no set filled. */\n _DummyFor(binding)\n {\n if (binding.sampler) return this.GetDummySampler();\n if (binding.texture) return this.GetDummyTexture(binding.texture.viewDimension ?? \"2d\");\n if (binding.storageTexture) return this.GetDummyStorageTexture(binding.storageTexture.format, binding.storageTexture.viewDimension);\n\n return { buffer: this.GetNullBuffer(binding.buffer?.minBindingSize ?? 16, \"STORAGE\") };\n }\n\n /** The dummies, created once each: `MetalContext::m_dummyTexture[]`, `m_dummySampler`. */\n _dummies = { textures: new Map(), storageTextures: new Map(), sampler: null, buffers: new Map(), vertexBuffer: null };\n\n /**\n * A 1x1 texture view of the given dimension, for a slot nothing filled.\n *\n * `MetalContext::GetDummyTexture( MTLTextureType )` (`MetalContext.mm:306-320`):\n * one per texture type, because a sampler of the wrong dimension is a\n * validation error rather than a black texel.\n *\n * @param {string} [viewDimension] A `GPUTextureViewDimension`.\n * @returns {object} A `GPUTextureView`.\n */\n GetDummyTexture(viewDimension = \"2d\")\n {\n const existing = this._dummies.textures.get(viewDimension);\n\n if (existing) return existing;\n\n const usage = this._webgpu.GetTextureUsage();\n const layers = viewDimension === \"cube\" ? 6 : 1;\n const texture = this._webgpu.GetDevice().createTexture({\n label: `Tr2RenderContextAL dummy ${viewDimension}`,\n size: { width: 1, height: 1, depthOrArrayLayers: layers },\n dimension: viewDimension === \"3d\" ? \"3d\" : \"2d\",\n format: \"rgba8unorm\",\n usage: usage.TEXTURE_BINDING | usage.COPY_DST\n });\n const view = texture.createView({ dimension: viewDimension });\n\n this._dummies.textures.set(viewDimension, view);\n\n return view;\n }\n\n /**\n * A 1x1 storage view for a UAV slot nothing filled.\n *\n * D3D binds a null UAV and drops its writes; WebGPU has no null binding and\n * checks the view's format against the layout, so the stand-in is one per\n * format and dimension, written to and never read.\n *\n * @param {string} format The binding's `storageTexture.format`.\n * @param {string} viewDimension The binding's `storageTexture.viewDimension`.\n * @returns {object} A `GPUTextureView`.\n */\n GetDummyStorageTexture(format, viewDimension)\n {\n const key = `${format}:${viewDimension}`;\n const existing = this._dummies.storageTextures.get(key);\n\n if (existing) return existing;\n\n const usage = this._webgpu.GetTextureUsage();\n const texture = this._webgpu.GetDevice().createTexture({\n label: `Tr2RenderContextAL dummy storage ${key}`,\n size: { width: 1, height: 1, depthOrArrayLayers: 1 },\n dimension: viewDimension === \"3d\" ? \"3d\" : \"2d\",\n format,\n usage: usage.STORAGE_BINDING\n });\n const view = texture.createView({ dimension: viewDimension });\n\n this._dummies.storageTextures.set(key, view);\n return view;\n }\n\n /** `MetalContext::GetDummySampler()`: a default sampler for a slot nothing filled. */\n GetDummySampler()\n {\n this._dummies.sampler ??= this._webgpu.GetDevice().createSampler({ label: \"Tr2RenderContextAL dummy sampler\" });\n\n return this._dummies.sampler;\n }\n\n /**\n * A zeroed buffer of at least `size` bytes for a slot nothing filled.\n *\n * DX12's null CB / null SRV substitution, one per size and usage.\n *\n * @param {number} size Bytes the layout demands.\n * @param {\"UNIFORM\"|\"STORAGE\"} usageName The usage flag's name.\n * @returns {object} A `GPUBuffer`.\n */\n GetNullBuffer(size, usageName)\n {\n const aligned = Math.max(16, Math.ceil(size / 16) * 16);\n const key = `${usageName}:${aligned}`;\n const existing = this._dummies.buffers.get(key);\n\n if (existing) return existing;\n\n const usage = this._webgpu.GetBufferUsage();\n const buffer = this._webgpu.GetDevice().createBuffer({\n label: `Tr2RenderContextAL null ${usageName.toLowerCase()} ${aligned}`,\n size: aligned,\n usage: usage[usageName] | usage.COPY_DST\n });\n\n this._dummies.buffers.set(key, buffer);\n\n return buffer;\n }\n\n /**\n * Creates a texture, this backend's kind of `Tr2TextureAL`.\n *\n * @param {object} desc A `Tr2BitmapDimensions`.\n * @param {object} options `{ gpuUsage, cpuUsage, msaa, initialData }`.\n * @returns {object|null} The texture, or null when Create refused.\n */\n CreateTexture(desc, options)\n {\n const texture = new CjsWebgpuTextureAL();\n\n if (Failed(texture.Create(desc, options ?? {}, this))) return null;\n\n return texture;\n }\n\n /**\n * Creates a resource set, this backend's kind of `Tr2ResourceSetAL`.\n *\n * @param {object} description A `Tr2ResourceSetDescriptionAL`.\n * @param {object} program The `CjsWebgpuShaderProgramAL` it binds against.\n * @returns {object|null} The set, or null when Create refused.\n */\n @impl.custom\n @impl.reason(\"JavaScript chooses the AL implementation through this context factory instead of a compile-time platform include. The private allocation branch preserves the native Create result.\")\n CreateResourceSet(description, program, implementationOnly = false)\n {\n // JS platform selection for the public facade; the allocation branch\n // returns the native status code without collapsing it to null.\n if (implementationOnly)\n {\n const implementation = new CjsWebgpuResourceSetAL();\n const result = implementation.Create(description, program, this);\n if (Failed(result)) implementation.Destroy();\n return { result, implementation };\n }\n const resourceSet = new Tr2ResourceSetAL();\n if (Failed(resourceSet.Create(description, program, this))) return null;\n return resourceSet;\n }\n\n /** Records why a draw cannot proceed and says no. */\n _RefusePipeline(reason)\n {\n this.m_pipelineFailure = reason;\n\n return false;\n }\n\n /**\n * Creates the `GPURenderPipeline` a program and recipe describe.\n *\n * A program without a pixel stage is a depth-only pipeline, which WebGPU\n * spells by omitting `fragment` - Carbon's shadow passes are exactly this.\n */\n _CreateRenderPipeline(program, recipe)\n {\n const fragmentModule = program.GetModuleFor(ShaderType.PIXEL_SHADER);\n const descriptor = {\n label: `Tr2RenderContextAL ${program.GetIdentity()}`,\n layout: program.GetPipelineLayout(),\n vertex: {\n module: program.GetModuleFor(ShaderType.VERTEX_SHADER),\n entryPoint: WEBGPU_ENTRY_POINT,\n buffers: recipe.vertex.buffers\n },\n primitive: recipe.primitive,\n ...(recipe.depthStencil ? { depthStencil: recipe.depthStencil } : {}),\n ...(recipe.multisample ? { multisample: recipe.multisample } : {}),\n ...(fragmentModule\n ? { fragment: { module: fragmentModule, entryPoint: WEBGPU_ENTRY_POINT, targets: recipe.fragment.targets } }\n : {})\n };\n\n return this._webgpu.GetDevice().createRenderPipeline(descriptor);\n }\n\n /**\n * Copies the bound attachments' formats onto the description.\n *\n * Deferred to the read rather than done in `SetRenderTarget`, because the\n * canvas format is only known once the target is configured and a target can\n * be bound before that. Carbon has no equivalent hop: a DX12 render-target\n * format is written straight into the description by `SetRenderState`\n * (`Tr2RenderContextDx12.cpp:453`), because a D3D texture knows its format\n * from creation.\n */\n _RefreshAttachmentFormats()\n {\n // THE DESCRIPTION DESCRIBES THE PASS `_Descriptor` OPENS, as Metal's\n // pipeline key reads the formats off the pass descriptor's own textures\n // (`MetalWorkQueue.mm:1681-1698`). With the canvas at slot zero the pass is\n // the canvas's, depth included; otherwise it is the bound textures and the\n // bound depth stencil, each in the format it was CREATED in. A texture's\n // `GetFormat` is Carbon's PixelFormat number, not a GPUTextureFormat, and a\n // UAV texture may have been created in a substitute (`GetDeviceFormat`).\n if (this._IsCanvasPass())\n {\n if (!this._renderTarget)\n {\n this._psoDescription.colorFormats = [];\n this._psoDescription.depthFormat = null;\n this._psoDescription.sampleCount = 1;\n return;\n }\n\n this._psoDescription.colorFormats = [ this._renderTarget.GetFormat() ];\n this._psoDescription.depthFormat = this._renderTarget.GetDepthFormat();\n this._psoDescription.sampleCount = this._renderTarget.GetSampleCount();\n return;\n }\n\n const formats = this._boundRenderTargets.map(target => (target ? target.GetDeviceFormat() : null));\n\n while (formats.length && !formats[formats.length - 1]) formats.pop();\n\n this._psoDescription.colorFormats = formats;\n this._psoDescription.depthFormat = this._depthStencil ? this._depthStencil.GetDeviceFormat() : null;\n this._psoDescription.sampleCount = 1;\n }\n\n /**\n * Whether the next pass is the canvas's: the canvas render target at slot\n * zero, or nothing bound at all (the canvas stays the pass of last resort,\n * as it was before textures could be targets).\n */\n _IsCanvasPass()\n {\n const primary = this._boundRenderTargets[0] ?? null;\n\n if (primary) return primary === this._renderTarget;\n\n return !this._depthStencil && !this._boundRenderTargets.some(Boolean);\n }\n\n /**\n * Binds a prepared set of textures, samplers and buffers.\n *\n * @param {object} resourceSet A `Tr2ResourceSetAL`.\n * @returns {boolean} True.\n */\n @impl.adapted\n @impl.reason(\"A copied public wrapper retains the shared ownership record while this context binds the WebGPU implementation.\")\n SetResourceSet(resourceSet)\n {\n this._resourceSet = resourceSet ? new Tr2ResourceSetAL({ copy: resourceSet }) : null;\n\n return true;\n }\n\n /**\n * m_constantBuffers[stage][register], as Metal keeps them.\n *\n * A Map keyed by `stage * CONSTANT_BUFFER_REGISTERS + register` rather than a\n * fixed two-dimensional array, because the register count is a device limit\n * here and not a compile-time constant.\n */\n _constantBuffers = new Map();\n\n /**\n * Binds a constant buffer to one shader stage at one register.\n *\n * Carbon rejects a register past the backend's constant-buffer count and\n * otherwise hands the buffer to itself to bind\n * (`Tr2RenderContextMetal.mm:664-677`). The bound state is what the resolver\n * reads when it assembles a draw.\n *\n * @param {object} buffer A `Tr2ConstantBufferAL`.\n * @param {number} constantType A `ShaderType`.\n * @param {number} registerIndex The constant-buffer register.\n * @param {number} [_maxRegisterCount] Carbon's optional bound.\n * @returns {boolean} Whether the AL accepted it.\n */\n SetConstants(buffer, constantType, registerIndex, _maxRegisterCount = 0)\n {\n if (registerIndex < 0 || registerIndex >= CONSTANT_BUFFER_REGISTERS) return false;\n if (constantType < 0 || constantType >= ShaderType.SHADER_TYPE_COUNT) return false;\n\n this._constantBuffers.set(constantType * CONSTANT_BUFFER_REGISTERS + registerIndex, buffer ?? null);\n\n return true;\n }\n\n /**\n * The constant buffer bound to one stage and register.\n *\n * @param {number} constantType A `ShaderType`.\n * @param {number} registerIndex The constant-buffer register.\n * @returns {object|null} The buffer, or null when nothing is bound.\n */\n GetConstants(constantType, registerIndex)\n {\n return this._constantBuffers.get(constantType * CONSTANT_BUFFER_REGISTERS + registerIndex) ?? null;\n }\n\n // ---------------------------------------------------------------------------\n // THE REST OF CARBON'S RENDER-CONTEXT SURFACE.\n //\n // Nothing in Trinity calls these yet - the nine it does call are above - but a\n // backend is only interchangeable if the whole surface answers, and the\n // governing test for this layer is \"swap the backend; nothing in Trinity\n // changes\". Each one either does what WebGPU can do or reports what the stub\n // reports, and says which.\n\n /**\n * Where a debug group was pushed, so its pop reaches the same encoder.\n *\n * WEBGPU REQUIRES THE PAIR TO BALANCE WITHIN ONE ENCODER. A group pushed on\n * the command encoder and popped after a render pass opened would be a\n * validation error, not a mislabelled capture - so the push records its\n * target and the pop uses it rather than asking again.\n */\n _markerStack = [];\n\n /** The encoder debug markers should go to: the open pass, else the frame. */\n _MarkerTarget()\n {\n return this._workQueue.GetRenderPass() ?? this._commandEncoder;\n }\n\n /**\n * Inserts a one-off marker into the capture.\n *\n * Real, unlike the stub's empty body: `insertDebugMarker` is what a WebGPU\n * capture tool shows, and this is the only reason Carbon's markers exist.\n *\n * @param {string} marker The label.\n */\n AddGpuMarker(marker)\n {\n const target = this._MarkerTarget();\n\n if (target) target.insertDebugMarker(String(marker));\n }\n\n /**\n * Opens a named debug group.\n *\n * @param {string} marker The label.\n */\n PushGpuMarker(marker)\n {\n const target = this._MarkerTarget();\n\n this._markerStack.push(target);\n\n if (target) target.pushDebugGroup(String(marker));\n }\n\n /** Closes the innermost debug group, on the encoder that opened it. */\n PopGpuMarker()\n {\n const target = this._markerStack.pop();\n\n if (target) target.popDebugGroup();\n }\n\n /**\n * Marks a point in the frame for a profiler.\n *\n * @param {string} frameEvent The event name.\n */\n MarkFrameEvent(frameEvent)\n {\n this.AddGpuMarker(frameEvent);\n }\n\n /**\n * Tears the device down, dropping every piece of bound state.\n *\n * @returns {boolean} True.\n */\n Destroy()\n {\n this._boundRenderTargets.fill(null);\n this._depthStencil = null;\n for (const stack of this._renderTargetStacks) stack.length = 0;\n this._depthStencilStack.length = 0;\n this._constantBuffers.clear();\n this._renderStates.clear();\n this._markerStack.length = 0;\n this._commandEncoder = null;\n this._frame = null;\n this._ReleasePipelines();\n this._samplerStates.clear();\n this._constantArena?.Destroy();\n this._constantArena = null;\n // Carbon's backends destroy the helper with the context too (DX12's\n // destructor runs `Tr2DrawUPHelper::Destroy`), and its scratch buffers are\n // real device buffers that must not outlive the device they came from.\n this._drawUP.Destroy();\n // Bound state goes too; the description describes nothing bound.\n this._streams = [];\n this._vertexLayout = null;\n this._shaderProgram = null;\n this._psoDescription.shaderProgram = null;\n this._resourceSet = null;\n this._indexBuffer = null;\n this._indexStride = 0;\n this._isValid = false;\n\n return true;\n }\n\n /**\n * Binds the default back buffer at slot zero and clears every other slot.\n *\n * Carbon calls this from `BeginScene` (`Tr2RenderContextMetal.mm:860-864`),\n * which is why a frame there never inherits the previous frame's targets.\n * This backend did not, so bound targets survived across frames and the first\n * pass of a frame drew into whatever the last pass of the previous one had\n * left bound - the same shape as the 2048 shadow-map defect one layer up.\n *\n * @returns {boolean} True.\n */\n ResetRenderTargets()\n {\n this.SetDepthStencil(null);\n this.SetRenderTarget(0, this._renderTarget);\n\n for (let slot = 1; slot < MAX_RENDER_TARGET; slot++) this.SetRenderTarget(slot, null);\n\n return true;\n }\n\n /**\n * Marks this context as the process-wide primary one.\n *\n * Carbon's Metal version also constructs the device-side context and the\n * default back buffer (`Tr2RenderContextMetal.mm:114-124`); ours receive both\n * through the constructor, so what remains is the registration.\n *\n * @returns {boolean} True.\n */\n SetAsPrimary()\n {\n CjsWebgpuRenderContextAL.SetPrimaryRenderContext(this);\n\n return true;\n }\n\n /**\n * The present parameters last applied.\n *\n * CARBON'S MISSPELLING IS KEPT (`Tr2RenderContextMetal.h:230`). It is the\n * name on the abstraction-layer contract, and a backend that spells it\n * correctly is a backend the contract cannot reach.\n *\n * @returns {object|null} The parameters, or null before any were set.\n */\n GetPresentParamaters()\n {\n return this._presentParameters;\n }\n\n /** m_presentParameters */\n _presentParameters = null;\n\n /**\n * Releases what a device reset would invalidate, keeping the context alive.\n *\n * @returns {boolean} True.\n */\n ReleaseDeviceResources()\n {\n this._boundRenderTargets.fill(null);\n this._frame = null;\n this._ReleasePipelines();\n\n return true;\n }\n\n /** Drops every resolved pipeline; the next draw resolves afresh. */\n _ReleasePipelines()\n {\n this._pipelines.clear();\n this._pipeline = null;\n this._pipelineDirty = true;\n this._bindGroups.clear();\n this._dummies = { textures: new Map(), sampler: null, buffers: new Map() };\n // The sampler factory is NOT cleared here: Carbon's lives for the primary\n // context's lifetime, and every seeded pass description still holds the\n // states it handed out - clearing it made an equal description create a\n // second state and report a change it had not made.\n }\n\n /**\n * The back buffer this context presents into.\n *\n * The render target IS this backend's back buffer: it answers `GetWidth` and\n * `GetHeight` exactly as a `Tr2TextureAL` does, which is why it can be bound\n * at slot zero without an adapter.\n *\n * @returns {object|null} The render target, or null before composition.\n */\n GetDefaultBackBuffer()\n {\n return this._renderTarget;\n }\n\n /**\n * The back buffer's pixel format, as a Carbon `PixelFormat`.\n *\n * @returns {number} The format, or `PIXEL_FORMAT_UNKNOWN` before composition\n * or for a canvas format outside the four the spec allows.\n */\n GetBackBufferFormat()\n {\n if (!this._renderTarget) return PixelFormat.PIXEL_FORMAT_UNKNOWN;\n\n return CANVAS_PIXEL_FORMAT[this._renderTarget.GetFormat()] ?? PixelFormat.PIXEL_FORMAT_UNKNOWN;\n }\n\n /**\n * Applies present parameters by resizing the presentation surface.\n *\n * The stub CREATES a back buffer at the requested size; here the canvas\n * already exists and is reconfigured instead, which is the same act against a\n * surface the page owns rather than one the backend allocates.\n *\n * @param {object} presentParameters Carbon's `Tr2PresentParametersAL`.\n * @returns {number} An `ALResult` value.\n */\n SetPresentParameters(presentParameters)\n {\n if (!presentParameters || !presentParameters.mode) return ALResult.E_INVALIDARG;\n if (!this._renderTarget) return ALResult.E_INVALIDCALL;\n\n const { width, height } = presentParameters.mode;\n\n this._renderTarget.Configure({ width, height });\n this._presentParameters = presentParameters;\n\n return ALResult.S_OK;\n }\n\n /**\n * Whether textures can be reached without a binding.\n *\n * @returns {boolean} False. WebGPU has no bindless path at all: every\n * resource is reached through a bind group.\n */\n SupportsBindlessTextures()\n {\n return false;\n }\n\n /**\n * How much video memory the adapter has.\n *\n * @returns {number} Zero, as the stub reports. WebGPU deliberately exposes no\n * memory size - it is a fingerprinting surface - so this is not a gap that\n * a later browser fills in.\n */\n GetTotalVideoMemory()\n {\n return 0;\n }\n\n /** m_readOnlyDepth - Metal keeps this and folds it into ZWRITEENABLE. */\n _readOnlyDepth = false;\n\n /**\n * Whether depth is bound read-only.\n *\n * @returns {boolean} The flag.\n */\n GetReadOnlyDepth()\n {\n return this._readOnlyDepth;\n }\n\n /**\n * Binds depth read-only, so it can be sampled while still testing.\n *\n * STORED, NOT YET APPLIED. WebGPU expresses this as `depthReadOnly` on the\n * render-pass descriptor, which `_Descriptor` builds; wiring it there is a\n * pass-descriptor change rather than a state one, and the flag has to exist\n * before it can be read.\n *\n * @param {boolean} enable Whether depth is read-only.\n */\n SetReadOnlyDepth(enable)\n {\n this._readOnlyDepth = !!enable;\n }\n\n /**\n * Copies a byte range between two buffers.\n *\n * Real when a frame is open: `copyBufferToBuffer` is a command-encoder verb,\n * so it needs the encoder `BeginScene` created and nothing else.\n *\n * @param {object} destination The destination `Tr2BufferAL`.\n * @param {number} destinationOffset Byte offset into it.\n * @param {object} source The source `Tr2BufferAL`.\n * @param {number} sourceOffset Byte offset into it.\n * @param {number} size Bytes to copy.\n * @returns {boolean} Whether the copy was encoded.\n */\n CopySubBuffer(destination, destinationOffset, source, sourceOffset, size)\n {\n if (!this._commandEncoder) return false;\n if (!destination || !source || !destination.IsValid() || !source.IsValid()) return false;\n if (size <= 0) return false;\n\n this._commandEncoder.copyBufferToBuffer(\n source.GetDeviceBuffer(),\n sourceOffset,\n destination.GetDeviceBuffer(),\n destinationOffset,\n size\n );\n\n return true;\n }\n\n /**\n * Draws indirectly, reading the draw arguments from a buffer.\n *\n * REFUSES, as the stub does. WebGPU has `drawIndirect`, but the work queue\n * owns every draw and has no indirect verb; adding one here would put a\n * second draw path beside the queue's, which is the split this backend is\n * built around.\n *\n * @returns {boolean} False.\n */\n DrawInstancedIndirect()\n {\n return false;\n }\n\n /**\n * Draws indexed indirectly.\n *\n * @returns {boolean} False; see `DrawInstancedIndirect`.\n */\n DrawIndexedInstancedIndirect()\n {\n return false;\n }\n\n /**\n * Declares that a batch of resources is about to be used.\n *\n * @param {object} _destination Where they are used.\n * @param {number} _usage How they are used.\n * @param {object[]} _resources The resources.\n * @returns {boolean} True. This is a residency and barrier hint for backends\n * that place their own memory; WebGPU tracks both itself, so honouring it\n * is nothing rather than unimplemented.\n */\n UseResources(_destination, _usage, _resources)\n {\n return true;\n }\n\n /**\n * Declares a ray-tracing acceleration structure in use.\n *\n * @param {object} _tlas The top-level structure.\n * @returns {boolean} True, as the stub reports.\n */\n UseAccelerationStructure(_tlas)\n {\n return true;\n }\n\n /**\n * Dispatches rays.\n *\n * @returns {boolean} False; WebGPU has no ray-tracing pipeline.\n */\n DispatchRays()\n {\n return false;\n }\n\n /**\n * Whether the device recorded a GPU state marker after a fault.\n *\n * @returns {boolean} False; WebGPU surfaces device loss as a promise and a\n * reason string, with no marker or breadcrumb to read.\n */\n GetGpuStateMarker()\n {\n return false;\n }\n\n /**\n * The resource a GPU page fault named.\n *\n * @returns {boolean} False; see `GetGpuStateMarker`.\n */\n GetGpuPageFaultResource()\n {\n return false;\n }\n\n // THE UPSCALING FAMILY. Every answer is the stub's, and the stub's are\n // Carbon's: the family is live only in the DX backends. WebGPU has no\n // upscaler to reach, so these are complete rather than pending.\n\n /**\n * Enables upscaling.\n *\n * @returns {number} `UpscalingResult.OK` - Carbon's stub succeeds WITHOUT\n * creating anything, so a caller that then asks for a context gets null.\n * That pairing is Carbon's and both halves are kept.\n */\n EnableUpscaling()\n {\n return UpscalingResult.OK;\n }\n\n /**\n * An existing upscaling context.\n *\n * @returns {null} Null; none is kept.\n */\n GetUpscalingContext()\n {\n return null;\n }\n\n /**\n * Creates an upscaling context.\n *\n * @returns {null} Null; none is created.\n */\n CreateUpscalingContext()\n {\n return null;\n }\n\n /** Destroys an upscaling context; there are none. */\n DeleteUpscalingContext()\n {\n }\n\n /**\n * What an upscaling context is doing.\n *\n * @returns {object} A default `UpscalingInfo`; two of its values are not zero.\n */\n GetUpscalingInfo()\n {\n return {\n displayWidth: 0,\n displayHeight: 0,\n renderWidth: 0,\n renderHeight: 0,\n technique: UpscalingTechnique.NONE,\n setting: UpscalingSetting.NATIVE,\n frameGeneration: false,\n temporal: false,\n hasSharpening: false,\n upscalingAmount: 1,\n jitterX: 0,\n jitterY: 0,\n mipLevelBias: 0\n };\n }\n\n /**\n * The techniques an adapter supports.\n *\n * @returns {Array} Empty.\n */\n GetSupportedUpscalingTechniques()\n {\n return [];\n }\n\n /**\n * The upscaling currently set up.\n *\n * @returns {object} \"No upscaling\", in the four fields Carbon fills.\n */\n GetUpscalingSetup()\n {\n return {\n technique: UpscalingTechnique.NONE,\n setting: UpscalingSetting.NATIVE,\n frameGeneration: false,\n temporal: false\n };\n }\n\n // THE PRIMARY RENDER CONTEXT. Carbon keeps one per process as a static and\n // reaches it from resource creation; these are the same three accessors the\n // stub carries, over the same module-level binding.\n\n /**\n * Records the primary render context.\n *\n * @param {object} renderContext The context to make primary.\n */\n static SetPrimaryRenderContext(renderContext)\n {\n primaryRenderContext = renderContext;\n }\n\n /**\n * The primary render context, which must exist.\n *\n * @returns {object} The primary context.\n */\n static GetPrimaryRenderContext()\n {\n if (primaryRenderContext === null) fail(\"there is no primary render context\");\n\n return primaryRenderContext;\n }\n\n /**\n * The primary render context, or null.\n *\n * @returns {object|null} The primary context.\n */\n static GetPrimaryRenderContextPointer()\n {\n return primaryRenderContext;\n }\n\n /**\n * Draws the bound geometry, indexed.\n *\n * REFUSES WITHOUT AN INDEX BUFFER, as Metal does - `E_INVALIDARG` at\n * `Tr2RenderContextMetal.mm:419-422`. An indexed draw with nothing to index\n * is a caller error a backend can catch without a device.\n *\n * @param {number} indexCountPerInstance Indices each instance reads.\n * @param {number} instanceCount Instances to draw.\n * @param {number} startIndexLocation First index.\n * @param {number} baseVertexLocation Value added to every index.\n * @param {number} startInstanceLocation First instance id.\n * @returns {boolean} Whether the draw was recorded.\n */\n DrawIndexedInstanced(\n indexCountPerInstance,\n instanceCount,\n startIndexLocation = 0,\n baseVertexLocation = 0,\n startInstanceLocation = 0\n )\n {\n if (!this._indexBuffer) return false;\n if (!this._shaderProgram) return false;\n\n // Metal (`MetalWorkQueue.mm:2922-2944`): `GetRenderEncoder()` FIRST, then\n // `if( EmitRenderEncoderState() ) { [renderEncoder drawIndexed...] }`. The\n // pass opens whether or not the draw can proceed. DX12 is\n // `CR_RETURN_HR( SetAllState() )` at the top of the verb.\n this._Record(this._workQueue.GetRenderEncoder());\n\n if (!this.EmitRenderEncoderState(true)) return false;\n\n this._Record(this._workQueue.DrawIndexedPrimitives(\n indexCountPerInstance,\n instanceCount,\n startIndexLocation,\n baseVertexLocation,\n startInstanceLocation\n ));\n this._drawnBatchCount += 1;\n\n return true;\n }\n\n /**\n * Draws the bound geometry, non-indexed.\n *\n * @param {number} vertexCountPerInstance Vertices each instance reads.\n * @param {number} instanceCount Instances to draw.\n * @param {number} startVertexLocation First vertex.\n * @param {number} startInstanceLocation First instance id.\n * @returns {boolean} Whether the draw was recorded.\n */\n DrawInstanced(vertexCountPerInstance, instanceCount, startVertexLocation = 0, startInstanceLocation = 0)\n {\n if (!this._shaderProgram) return false;\n\n this._Record(this._workQueue.GetRenderEncoder());\n\n if (!this.EmitRenderEncoderState(false)) return false;\n\n this._Record(this._workQueue.DrawPrimitives(\n vertexCountPerInstance,\n instanceCount,\n startVertexLocation,\n startInstanceLocation\n ));\n this._drawnBatchCount += 1;\n\n return true;\n }\n\n /**\n * Draws a primitive COUNT, converting it to vertices first.\n *\n * @param {number} numVertices Vertices the index range spans.\n * @param {number} startIndex First index.\n * @param {number} primitiveCount Primitives to draw.\n * @param {number} [minimumIndex] Lowest index present.\n * @returns {boolean} Whether the draw was recorded.\n */\n DrawIndexedPrimitive(numVertices, startIndex, primitiveCount, minimumIndex = 0)\n {\n return this.DrawIndexedInstanced(this.ComputeVertexCount(primitiveCount), 1, startIndex, minimumIndex, 0);\n }\n\n /**\n * Draws a primitive count, non-indexed.\n *\n * @param {number} startVertex First vertex.\n * @param {number} primitiveCount Primitives to draw.\n * @returns {boolean} Whether the draw was recorded.\n */\n DrawPrimitive(startVertex, primitiveCount)\n {\n return this.DrawInstanced(this.ComputeVertexCount(primitiveCount), 1, startVertex, 0);\n }\n\n /**\n * Draws non-indexed straight from caller memory, with no buffer bound.\n *\n * Carbon does not draw this itself either: every backend hands it to\n * `Tr2DrawUPHelper` (Metal at `Tr2RenderContextMetal.mm:558-571`, DX12 at\n * `Tr2RenderContextDx12.cpp:1219-1224`), which stages the caller's vertices\n * into a ring of scratch buffers and issues an ordinary draw. WebGPU cannot\n * read caller memory either - every vertex must reach a `GPUBuffer` first -\n * so the helper IS the implementation rather than a detail of it, and the\n * port is shared rather than written again here.\n *\n * @param {number} primitiveCount Primitives to draw.\n * @param {ArrayBufferView} vertexStreamZeroData The vertices.\n * @param {number} vertexStreamZeroStride Bytes per vertex.\n * @returns {boolean} Whether the draw was encoded.\n */\n DrawPrimitiveUP(primitiveCount, vertexStreamZeroData, vertexStreamZeroStride)\n {\n return !Failed(this._drawUP.DrawPrimitiveUP(\n this._topology,\n primitiveCount,\n vertexStreamZeroData,\n vertexStreamZeroStride,\n this\n ));\n }\n\n /**\n * Draws indexed straight from caller memory.\n *\n * The same helper, staging indices as well as vertices. Carbon has an\n * overload per index width; the width is read off the array here instead.\n *\n * @param {number} numVertices Vertices the index data spans.\n * @param {number} primitiveCount Primitives to draw.\n * @param {Uint16Array|Uint32Array} indexData The indices.\n * @param {ArrayBufferView} vertexStreamZeroData The vertices.\n * @param {number} vertexStreamZeroStride Bytes per vertex.\n * @returns {boolean} Whether the draw was encoded.\n */\n DrawIndexedPrimitiveUP(numVertices, primitiveCount, indexData, vertexStreamZeroData, vertexStreamZeroStride)\n {\n return !Failed(this._drawUP.DrawIndexedPrimitiveUP(\n this._topology,\n numVertices,\n primitiveCount,\n indexData,\n vertexStreamZeroData,\n vertexStreamZeroStride,\n this\n ));\n }\n\n /**\n * How many vertices a primitive count describes at the bound topology.\n *\n * @param {number} primitiveCount Primitives.\n * @returns {number} Vertices.\n */\n ComputeVertexCount(primitiveCount)\n {\n return VERTICES_PER_PRIMITIVE[this._topology](primitiveCount);\n }\n\n /**\n * What a following draw would bind, for a caller that must encode it.\n *\n * @returns {object} A copy of the bound state.\n */\n GetBoundState()\n {\n return {\n topology: this._topology,\n indexBuffer: this._indexBuffer,\n indexStride: this._indexStride,\n streams: this._streams.map(stream => (stream ? { ...stream } : stream)),\n vertexLayout: this._vertexLayout,\n shaderProgram: this._shaderProgram,\n resourceSet: this._resourceSet\n };\n }\n\n /**\n * Keeps the work queue's reported encoder transitions for the tests to read.\n *\n * @param {object[]} [events] The events, if any were reported.\n */\n _Record(events)\n {\n if (events?.length) this._transitions.push(...events);\n }\n}\n\n// DECLARED AS A CALL, NOT A DECORATOR, for the reason recorded in\n// Tr2BitmapDimensions.js: the layer is imported straight from source by its\n// tests and raw Node cannot parse decorator syntax.\n//\n// The donor is NAMED rather than left to be derived from this class's name.\n// Carbon calls every backend's class the same thing and carries the backend in\n// the FILE name, because only one backend compiles at a time; we ship them\n// together, so the backend moves onto the class name. That divergence is the\n// author's to declare, never a checker's to guess.\nCjsSchema.define(CjsWebgpuRenderContextAL, { className: \"CjsWebgpuRenderContextAL\", carbon: \"Tr2RenderContextAL\" });\n"],"names":["INDEX_FORMAT","Object","freeze","MAX_CACHED_BIND_GROUPS","DeviceBufferOf","bound","GetDeviceBuffer","gpuColor","value","r","g","b","a","length","fail","message","error","Error","code","VERTICES_PER_PRIMITIVE","Topology","TOP_TRIANGLES","count","TOP_TRIANGLE_STRIP","TOP_TRIANGLE_FAN","TOP_LINES","TOP_LINE_STRIP","TOP_POINTS","MAX_RENDER_TARGET","DUMMY_VERTEX_FORMAT","FLOAT","INT","UINT","CANVAS_PIXEL_FORMAT","PixelFormat","PIXEL_FORMAT_B8G8R8A8_UNORM","PIXEL_FORMAT_B8G8R8A8_UNORM_SRGB","PIXEL_FORMAT_R8G8B8A8_UNORM","PIXEL_FORMAT_R8G8B8A8_UNORM_SRGB","primaryRenderContext","CONSTANT_BUFFER_REGISTERS","CjsWebgpuRenderContextAL","_initProto","_applyDecs","impl","custom","reason","adapted","e","SHADER_TYPE_MASK","ShaderType","VERTEX_SHADER","PIXEL_SHADER","COMPUTE_SHADER","_workQueue","CjsWebgpuWorkQueue","_isValid","_topology","_indexBuffer","_indexStride","_streams","_vertexLayout","_shaderProgram","_resourceSet","_renderStateSetup","_renderStateOverrides","_pipelineDirty","_drawUP","Tr2DrawUPHelper","_psoDescription","CjsWebgpuPsoDescription","_boundRenderTargets","Array","fill","_renderTargetStacks","from","_depthStencil","_depthStencilStack","_viewport","_transitions","_webgpu","_renderTarget","m_utils","CjsWebgpuUtils","_commandEncoder","_frame","constructor","webgpu","renderTarget","topology","IsComposed","GetWebgpu","CreateBuffer","description","initialData","buffer","CjsWebgpuBufferAL","Failed","Create","CreateVertexLayout","definition","layout","Tr2VertexLayoutALStub","CreateConstantBuffer","size","usage","Tr2ConstantUsageAL","REUSABLE","CjsWebgpuConstantBufferAL","_samplerStates","Map","CreateSamplerState","key","SamplerDescriptionKey","existing","get","state","CjsWebgpuSamplerStateAL","set","CreateShader","stageType","bytecode","signature","shaderPath","shader","CjsWebgpuShaderAL","CreateShaderProgram","shaders","program","CjsWebgpuShaderProgramAL","GetDrawnBatchCount","_drawnBatchCount","GetWorkQueue","_caps","GetCaps","CjsWebgpuCapsAL","_frameNumber","GetRecordingFrameNumber","GetRenderedFrameNumber","DrainTransitions","transitions","CreateDevice","IsValid","BeginScene","GetDevice","createCommandEncoder","label","SetCommandEncoder","attachments","_Descriptor","_Record","BeginFrame","_constantArena","Reset","ResetRenderTargets","_IsCanvasPass","_TextureDescriptor","AcquireFrame","clear","colors","CreateRenderPassDescriptor","GetPassCount","clearColor","loadOp","clearValue","undefined","clearDepth","depth","GetAttachments","hinted","next","colorAttachments","map","color","hint","view","texture","GetDeviceRenderTargetView","slice","storeOp","pop","descriptor","stencil","GetDeviceFormat","includes","depthStencilAttachment","depthLoadOp","depthStoreOp","depthClearValue","stencilLoadOp","stencilStoreOp","stencilClearValue","EndScene","EndFrame","shaderProgram","Submit","finish","RenderPassHint","EndRenderPassHint","SetRenderTarget","slot","SetRenderAttachments","primary","SetViewport","x","y","width","GetWidth","height","GetHeight","GetRenderTarget","PushRenderTarget","push","PopRenderTarget","stack","GetStackSizeRT","SetDepthStencil","depthStencil","previous","SetDepthAttachment","CopyDepthShadow","GetDepthStencil","PushDepthStencil","PopDepthStencil","GetStackSizeDS","GetRenderTargetSize","target","result","ALResult","E_INVALIDCALL","S_OK","viewport","GetViewport","Clear","options","flagged","clearTarget","clearStencil","forEach","attachment","index","Tr2ColorAttachment","Tr2LoadAction","CLEAR","Tr2StoreAction","STORE","LOAD","Tr2DepthAttachment","Number","RunComputeShader","z","module","GetModuleFor","_RefusePipeline","pipeline","_computePipelines","createComputePipeline","GetIdentity","GetPipelineLayout","compute","entryPoint","WEBGPU_ENTRY_POINT","_EmitBindGroups","SetComputePipeline","DispatchThreadgroups","WeakMap","_mipGenerator","GetMipGenerator","CjsWebgpuMipGenerator","RunComputeShaderIndirect","_effect","_indirectionBuffer","_offsetForArgs","ClearUav","resource","_clearWithFloat","is","ClearBuffer","Present","SetTopology","TOP_MAX_TOPOLOGY","SetVertexLayout","SetStreamSource","stream","offset","stride","SetIndices","SetShaderProgram","SetRenderStates","setup","overrides","CanonicalKey","renderStateSetup","renderStateOverrides","_renderStates","SetRenderState","GetRenderStateInputs","states","IsPipelineDirty","GetPsoDescription","_RefreshAttachmentFormats","_pipeline","_pipelines","m_pipelineFailure","EmitRenderPipelineState","SetRenderPipeline","vertexBufferLayouts","BuildVertexBufferLayouts","missing","GetMissing","TOPOLOGIES","stripIndexFormat","endsWith","recipe","GetKey","BuildRecipe","primitive","created","_CreateRenderPipeline","type","EmitRenderEncoderState","indexed","layouts","_dummyVertexStream","SetVertexBuffer","_DummyVertexBuffer","format","SetIndexBuffer","elements","GetDefinition","inputs","GetInputs","plan","resolveBindingPlan","byStream","entries","filter","entry","element","has","Math","max","keys","WebgpuVertexBufferLayout","arrayStride","stepMode","attributes","shaderLocation","registerIndex","fallbackType","sort","GetBufferUsage","_dummies","vertexBuffer","createBuffer","VERTEX","COPY_DST","_bindGroups","GetBindGroupLayouts","m_resourceSet","implementation","GetProgram","GetEntries","setId","m_id","bindings","GetBindings","device","group","keyParts","resolved","dynamicOffsets","binding","minBindingSize","constantBuffer","_ConstantBufferFor","region","UploadConstants","_Arena","GetPage","page","GetNullBuffer","_DummyFor","join","bindGroup","createBindGroup","SetBindGroup","CjsWebgpuConstantArena","source","arena","ArrayBuffer","isView","Allocate","byteLength","token","m_token","wanted","m_shadowCopy","frame","bit","stage","visibility","_constantBuffers","sampler","GetDummySampler","GetDummyTexture","viewDimension","storageTexture","GetDummyStorageTexture","textures","storageTextures","buffers","GetTextureUsage","layers","createTexture","depthOrArrayLayers","dimension","TEXTURE_BINDING","createView","STORAGE_BINDING","createSampler","usageName","aligned","ceil","toLowerCase","CreateTexture","desc","CjsWebgpuTextureAL","CreateResourceSet","implementationOnly","CjsWebgpuResourceSetAL","Destroy","resourceSet","Tr2ResourceSetAL","fragmentModule","vertex","multisample","fragment","targets","createRenderPipeline","colorFormats","depthFormat","sampleCount","GetFormat","GetDepthFormat","GetSampleCount","formats","some","Boolean","SetResourceSet","copy","SetConstants","constantType","_maxRegisterCount","SHADER_TYPE_COUNT","GetConstants","_markerStack","_MarkerTarget","GetRenderPass","AddGpuMarker","marker","insertDebugMarker","String","PushGpuMarker","pushDebugGroup","PopGpuMarker","popDebugGroup","MarkFrameEvent","frameEvent","_ReleasePipelines","SetAsPrimary","SetPrimaryRenderContext","GetPresentParamaters","_presentParameters","ReleaseDeviceResources","GetDefaultBackBuffer","GetBackBufferFormat","PIXEL_FORMAT_UNKNOWN","SetPresentParameters","presentParameters","mode","E_INVALIDARG","Configure","SupportsBindlessTextures","GetTotalVideoMemory","_readOnlyDepth","GetReadOnlyDepth","SetReadOnlyDepth","enable","CopySubBuffer","destination","destinationOffset","sourceOffset","copyBufferToBuffer","DrawInstancedIndirect","DrawIndexedInstancedIndirect","UseResources","_destination","_usage","_resources","UseAccelerationStructure","_tlas","DispatchRays","GetGpuStateMarker","GetGpuPageFaultResource","EnableUpscaling","UpscalingResult","OK","GetUpscalingContext","CreateUpscalingContext","DeleteUpscalingContext","GetUpscalingInfo","displayWidth","displayHeight","renderWidth","renderHeight","technique","UpscalingTechnique","NONE","setting","UpscalingSetting","NATIVE","frameGeneration","temporal","hasSharpening","upscalingAmount","jitterX","jitterY","mipLevelBias","GetSupportedUpscalingTechniques","GetUpscalingSetup","renderContext","GetPrimaryRenderContext","GetPrimaryRenderContextPointer","DrawIndexedInstanced","indexCountPerInstance","instanceCount","startIndexLocation","baseVertexLocation","startInstanceLocation","GetRenderEncoder","DrawIndexedPrimitives","DrawInstanced","vertexCountPerInstance","startVertexLocation","DrawPrimitives","DrawIndexedPrimitive","numVertices","startIndex","primitiveCount","minimumIndex","ComputeVertexCount","DrawPrimitive","startVertex","DrawPrimitiveUP","vertexStreamZeroData","vertexStreamZeroStride","DrawIndexedPrimitiveUP","indexData","GetBoundState","indexBuffer","indexStride","streams","vertexLayout","events","CjsSchema","define","className","carbon"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA+FA;AACA,MAAMA,YAAY,GAAGC,MAAM,CAACC,MAAM,CAAC;AAAE,EAAA,CAAC,EAAE,QAAQ;AAAE,EAAA,CAAC,EAAE;AAAS,CAAC,CAAC;;AAEhE;AACA,MAAMC,sBAAsB,GAAG,IAAI;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,cAAcA,CAACC,KAAK,EAC7B;AACE,EAAA,OAAOA,KAAK,IAAI,OAAOA,KAAK,CAACC,eAAe,KAAK,UAAU,GAAGD,KAAK,CAACC,eAAe,EAAE,GAAG,IAAI;AAC9F;;AAGA;AACA;AACA;AACA;AACA;AACA,SAASC,QAAQA,CAACC,KAAK,EACvB;AACE,EAAA,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAC7B;IACE,OAAO;MACLC,CAAC,EAAE,CAAED,KAAK,KAAK,EAAE,GAAI,IAAI,IAAI,GAAG;MAChCE,CAAC,EAAE,CAAEF,KAAK,KAAK,CAAC,GAAI,IAAI,IAAI,GAAG;AAC/BG,MAAAA,CAAC,EAAE,CAACH,KAAK,GAAG,IAAI,IAAI,GAAG;AACvBI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S;MACxBuf,WAAW,EAAE,IAAI,CAACtf,YAAY;MAC9Buf,WAAW,EAAE,IAAI,CAACtf,YAAY;MAC9Buf,OAAO,EAAE,IAAI,CAACtf,QAAQ,CAACgH,GAAG,CAAC+G,MAAM,IAAKA,MAAM,GAAG;QAAE,GAAGA;OAAQ,GAAGA,MAAO,CAAC;MACvEwR,YAAY,EAAE,IAAI,CAACtf,aAAa;MAChCqI,aAAa,EAAE,IAAI,CAACpI,cAAc;MAClCkX,WAAW,EAAE,IAAI,CAACjX;KACnB;AACH,EAAA;;AAEA;AACF;AACA;AACA;AACA;EACEuF,OAAOA,CAAC8Z,MAAM,EACd;AACE,IAAA,IAAIA,MAAM,EAAEviB,MAAM,EAAE,IAAI,CAACkE,YAAY,CAACqI,IAAI,CAAC,GAAGgW,MAAM,CAAC;AACvD,EAAA;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACAC,SAAS,CAACC,MAAM,CAAC7gB,wBAAwB,EAAE;AAAE8gB,EAAAA,SAAS,EAAE,0BAA0B;AAAEC,EAAAA,MAAM,EAAE;AAAqB,CAAC,CAAC;;;;"}
1
+ {"version":3,"file":"CjsWebgpuRenderContextAL.js","sources":["../../../../src/trinityal/webgpu/CjsWebgpuRenderContextAL.js"],"sourcesContent":["// Source: trinity/trinityal/metal/Tr2RenderContextMetal.h\n// Source: trinity/trinityal/metal/Tr2RenderContextMetal.mm\n// Source: trinity/trinityal/stub/Tr2RenderContextStub.h\n//\n// The WebGPU backend behind Carbon's abstraction layer.\n//\n// WHAT THIS REPLACED. `Tr2RenderContext` used to RECORD what Trinity asked for\n// into an intent list, which `framePlan.js` partitioned and `frameExecutor.js`\n// encoded. That mechanism had no Carbon counterpart - Carbon gives the same job\n// to the abstraction layer, and a backend is simply called - and it is now\n// deleted, along with all three of those files (runtime `1e881dec`).\n//\n// THE DIVISION OF LABOUR IS CARBON'S. `Tr2RenderContextAL` (metal) holds the\n// bound state and validates; `MetalWorkQueue` owns the command buffer and the\n// encoder lifetime. `DrawIndexedInstanced` there checks its index buffer,\n// converts a primitive count to a vertex count, then calls the work queue,\n// whose draw opens a render encoder if none is current\n// (`Tr2RenderContextMetal.mm:414-436`, `MetalWorkQueue.mm:2922-2945`). This\n// keeps that split, so `CjsWebgpuWorkQueue` is the only thing that knows when a\n// pass begins.\n//\n// DEVICE-FREE, AS CARBON'S STUB IS. Every verb here is argument validation,\n// state, and delegation - none of it needs a GPU, and Carbon ships a whole\n// backend (`TrinityAL_stub`) on that basis. The device arrives when the work\n// queue's recorded transitions are applied to a real command encoder.\n//\n// SCOPE. The verbs `Tr2RenderContext` forwards to a backend: the geometry and\n// draw path Carbon's `SubmitGeometry` touches (`Tr2RenderContext.cpp:83-103`),\n// the render-target and depth-stencil families with their per-slot stacks, the\n// viewport, clear, compute and present. That is what installing this backend\n// requires, because the context prefers the AL per verb and a missing one is a\n// crash rather than a fallback.\n//\n// NOT HERE YET: texture creation, copies and mip generation. Absent rather than\n// faked. Buffer creation IS here (`CreateBuffer`), because a Trinity class that\n// fills a buffer per frame cannot pick its own backend.\n//\n// WHAT CARBON'S METAL BACKEND HAS THAT THIS DOES NOT, AND WHY.\n//\n// The parity check compares this file against the donors it cites, which\n// includes all of metal - so Metal-only members are reported against a backend\n// that has no reason to carry them. These are decisions, not a queue:\n//\n// - `BeginParallelEncoding`/`EndParallelEncoding`/`ForkContext` spread batch\n// encoding across threads. There is one thread here, and `Tr2RenderContext`\n// already records the same omission for the same reason.\n// - `BufferRewritten` notifies the context that a buffer allocation was RENAMED\n// under it. WebGPU cannot rename: `queue.writeBuffer` is ordered on the queue,\n// which gives the guarantee renaming buys without renaming, and\n// `CjsWebgpuBufferAL`'s head comment argues that at length.\n// - `CheckDrawResources` does not validate, which the first version of this\n// note claimed. Carbon BINDS dummy resources into unfilled slots and installs\n// the vertex descriptor, on every draw (`Tr2RenderContextMetal.mm:524-541`).\n// WebGPU has the same requirement and will reject a draw with an unfilled\n// binding, so the browser is not doing this for us - it is the thing that\n// rejects us. WE DO IT, under Metal's other name: `EmitRenderEncoderState`\n// resolves the pipeline, fills unbound slots with dummies and binds the\n// layout, inside every draw verb. A NAME divergence, not an absence. (Until\n// 2026-09-10 this note said the divergence held \"because the dispatcher fills\n// bindings before the draw reaches here\"; there is no dispatcher.)\n// - `ReleaseLater` defers destruction until the GPU has finished reading. A\n// `GPUBuffer` stays alive as long as a submitted command references it, so\n// the deferral has nothing to defer.\n// - `UseConstantBuffer` is Metal-only and makes a constant buffer resident on\n// the COMPUTE encoder (`:1658-1673`); its only callers build the ray-tracing\n// shader table. No compute dispatches here and there is no ray tracing, so\n// there is nothing to make resident. (This note used to lump it with\n// `UploadConstants` and claim \"there is no arena\", which stopped being true\n// the day the arena landed. `UploadConstants` IS ported, above.)\n// - `GetMetalContext` and `GetMetalWorkQueue` are Metal's native escape\n// hatches. Ours are `GetWebgpu` and `GetWorkQueue` - Carbon names these per\n// backend too, so a WebGPU spelling is the faithful thing, not a divergence.\n\nimport { CjsSchema, impl } from \"#schema\";\nimport { Tr2ResourceSetAL } from \"../Tr2ResourceSetAL/Tr2ResourceSetAL.js\";\nimport { PixelFormat, RenderState, ShaderType, Topology, Tr2LoadAction, Tr2StoreAction, UpscalingResult, UpscalingSetting, UpscalingTechnique } from \"#consts/render-context\";\nimport { Tr2ColorAttachment, Tr2ConstantUsageAL, Tr2DepthAttachment, Tr2VertexLayoutALStub, resolveBindingPlan, ALResult, Failed, Tr2DrawUPHelper } from \"#trinityal\";\nimport { CjsWebgpuWorkQueue, EncoderType } from \"./core/CjsWebgpuWorkQueue.js\";\nimport { CjsWebgpuMipGenerator } from \"./core/CjsWebgpuMipGenerator.js\";\nimport { CjsWebgpuBufferAL } from \"./CjsWebgpuBufferAL.js\";\nimport { CjsWebgpuConstantBufferAL } from \"./CjsWebgpuConstantBufferAL.js\";\nimport { CARBON_BACKEND_ADDRESS_MODES_SYMBOL } from \"#resource/format\";\nimport { CjsWebgpuSamplerStateAL } from \"./CjsWebgpuSamplerStateAL.js\";\nimport { CjsWebgpuResourceSetAL } from \"./CjsWebgpuResourceSetAL.js\";\nimport { CjsWebgpuTextureAL } from \"./CjsWebgpuTextureAL.js\";\nimport { CjsWebgpuConstantArena } from \"./core/CjsWebgpuConstantArena.js\";\nimport { CjsWebgpuUtils } from \"./core/CjsWebgpuUtils.js\";\nimport { CanonicalKey } from \"./core/CjsWebgpuPipelineCache.js\";\nimport { TOPOLOGIES } from \"./core/topology.js\";\nimport { SamplerDescriptionKey } from \"../Tr2HalHelperStructures/Tr2SamplerDescription.js\";\nimport { CjsWebgpuCapsAL } from \"./CjsWebgpuCapsAL.js\";\nimport { CjsWebgpuPsoDescription } from \"./core/CjsWebgpuPsoDescription.js\";\nimport { CjsWebgpuShaderAL, WEBGPU_ENTRY_POINT } from \"./CjsWebgpuShaderAL.js\";\nimport { CjsWebgpuShaderProgramAL } from \"./CjsWebgpuShaderProgramAL.js\";\nimport { WebgpuVertexBufferLayout } from \"./core/vertexFormat.js\";\n\n/** WebGPU's index format for a Carbon index stride, or null for one it lacks. */\nconst INDEX_FORMAT = Object.freeze({ 2: \"uint16\", 4: \"uint32\" });\n\n/** Bind groups kept before the cache is dropped and rebuilt. */\nconst MAX_CACHED_BIND_GROUPS = 1024;\n\n/**\n * The `GPUBuffer` behind a bound stream, or null.\n *\n * A stream is whatever Trinity bound: a `Tr2BufferAL` answers; anything else\n * does not, and the draw refuses. Trinity realizes a mesh batch's geometry\n * descriptor into suballocated buffers before binding it\n * (`RealizeBatchGeometry`, called from `Tr2RenderContext.SubmitGeometry`).\n */\nfunction DeviceBufferOf(bound)\n{\n return bound && typeof bound.GetDeviceBuffer === \"function\" ? bound.GetDeviceBuffer() : null;\n}\n\n\n/**\n * A clear colour as a `GPUColor`. `Tr2ColorAttachment.clearColor` is Carbon's\n * packed ARGB word (`Color_inline.h:15-22`); Trinity's clears also pass a\n * four-float colour, which is taken as r, g, b, a.\n */\nfunction gpuColor(value)\n{\n if (typeof value === \"number\")\n {\n return {\n r: ((value >>> 16) & 0xff) / 255,\n g: ((value >>> 8) & 0xff) / 255,\n b: (value & 0xff) / 255,\n a: ((value >>> 24) & 0xff) / 255\n };\n }\n\n if (value && value.length >= 4) return { r: value[0], g: value[1], b: value[2], a: value[3] };\n\n return value ?? { r: 0, g: 0, b: 0, a: 0 };\n}\n\n\nfunction fail(message)\n{\n const error = new Error(`CjsWebgpuRenderContextAL: ${message}`);\n error.code = \"CJS_WEBGPU_AL_INVALID\";\n throw error;\n}\n\n\n/**\n * How many vertices a primitive count describes, per topology.\n *\n * CARBON'S DRAW VERBS TAKE PRIMITIVES AND ITS BACKENDS DRAW VERTICES, so every\n * one of them converts (`Tr2RenderContextMetal.mm:424`, `ComputeVertexCount`).\n * The conversion depends on the bound topology, which is why the AL holds it.\n */\nconst VERTICES_PER_PRIMITIVE = Object.freeze({\n [Topology.TOP_TRIANGLES]: count => count * 3,\n [Topology.TOP_TRIANGLE_STRIP]: count => count + 2,\n [Topology.TOP_TRIANGLE_FAN]: count => count + 2,\n [Topology.TOP_LINES]: count => count * 2,\n [Topology.TOP_LINE_STRIP]: count => count + 1,\n [Topology.TOP_POINTS]: count => count\n});\n\n\n/** Carbon's `MAX_RENDER_TARGET`; the bound-target array is fixed width. */\nconst MAX_RENDER_TARGET = 8;\n\n/**\n * The dummy vertex element's format for a missing input, by the input's\n * declared Tr2ShaderPipelineInputAL::Type (FLOAT 0, INT 1, UINT 2; the string\n * form is vertexLayoutMatch's FALLBACK_INPUT_TYPE): Metal's Char4 / UChar4 /\n * Float4 (Tr2VertexLayoutALMetal.mm:147-156).\n */\nconst DUMMY_VERTEX_FORMAT = Object.freeze({\n 0: \"float32x4\",\n 1: \"sint8x4\",\n 2: \"uint8x4\",\n FLOAT: \"float32x4\",\n INT: \"sint8x4\",\n UINT: \"uint8x4\"\n});\n\n\n/**\n * The Carbon pixel format behind each format a canvas can be configured with.\n *\n * SHORT ON PURPOSE. `GPUCanvasContext.configure` accepts only `bgra8unorm`,\n * `rgba8unorm` and their sRGB view formats, so this is the whole domain rather\n * than a partial table someone should extend later.\n */\nconst CANVAS_PIXEL_FORMAT = Object.freeze({\n \"bgra8unorm\": PixelFormat.PIXEL_FORMAT_B8G8R8A8_UNORM,\n \"bgra8unorm-srgb\": PixelFormat.PIXEL_FORMAT_B8G8R8A8_UNORM_SRGB,\n \"rgba8unorm\": PixelFormat.PIXEL_FORMAT_R8G8B8A8_UNORM,\n \"rgba8unorm-srgb\": PixelFormat.PIXEL_FORMAT_R8G8B8A8_UNORM_SRGB\n});\n\n\n/**\n * The primary render context, Carbon's process-wide one.\n *\n * A MODULE-LEVEL BINDING, matching the stub, because Carbon's is a static on\n * the class and a JavaScript static field would be per-subclass. There is one\n * primary context per process in Carbon and there is one here.\n */\nlet primaryRenderContext = null;\n\n\n/**\n * How many constant-buffer registers a stage has.\n *\n * Carbon's Metal backend fixes this at 20 (`METAL_CONST_BUFFER_COUNT`,\n * `MetalWorkQueue.h:39`) and rejects anything past it. Kept at Carbon's number\n * rather than a WebGPU limit: this bounds the REGISTER INDEX an effect declares,\n * which the shader compiler already fixed, not the bind-group slot count.\n */\nconst CONSTANT_BUFFER_REGISTERS = 20;\n\n\n/** WebGPU behind the abstraction layer, holding a work queue as Metal does. */\nexport class CjsWebgpuRenderContextAL\n{\n /**\n * The shader stages this backend runs, a bit per stage: `SHADER_TYPE_MASK`,\n * which `SHADER_TYPE_EXISTS` tests (`Tr2RenderContextEnum.h:413`). Vertex,\n * pixel and compute, as Metal's (`Tr2RenderContextMetal.h:190-191`).\n */\n static SHADER_TYPE_MASK = (1 << ShaderType.VERTEX_SHADER) | (1 << ShaderType.PIXEL_SHADER) | (1 << ShaderType.COMPUTE_SHADER);\n\n /** m_workQueue */\n _workQueue = new CjsWebgpuWorkQueue();\n\n /** m_isValid */\n _isValid = false;\n\n /** m_metalPrimitiveInfo - the topology following draws use. */\n _topology = Topology.TOP_TRIANGLES;\n\n /** m_metalIndexBuffer */\n _indexBuffer = null;\n\n _indexStride = 0;\n\n /** Vertex streams by slot, as SetStreamSource fills them. */\n _streams = [];\n\n /** m_vertexLayout */\n _vertexLayout = null;\n\n /** m_shaderProgram */\n _shaderProgram = null;\n\n /** m_resourceSet */\n _resourceSet = null;\n\n // Carbon's m_psoDescription half that exists so far: the authored setup and\n // the overrides it must be projected through, plus m_dirtyPso. The rest of\n // the description - shader program, vertex layout, topology, target formats -\n // is already held by the fields above and around; assembling and caching it\n // is the next piece of the immediate-draw route.\n\n _renderStateSetup = null;\n\n _renderStateOverrides = null;\n\n /** m_dirtyPso */\n _pipelineDirty = true;\n\n /**\n * m_drawUPHelper, DX12's name for it; DX11 calls the same thing m_drawUP.\n *\n * Owned rather than shared, as every backend owns its own: the ring's slots\n * are only safe because one context advances one cursor.\n */\n _drawUP = new Tr2DrawUPHelper();\n\n /**\n * m_psoDescription. Carbon's setters accumulate into one of these and mark it\n * dirty; every draw entry then calls `SetAllState`, which resolves a pipeline\n * from a cache keyed on the description's hash and binds it\n * (`Tr2RenderContextDx12.cpp:763-806`, `:810-880`).\n *\n * The class was written for this and wired to nothing until 2026-09-09. It is\n * filled here so the description is always current; RESOLVING it is the next\n * step, and needs the bound program to carry its effect package.\n */\n _psoDescription = new CjsWebgpuPsoDescription();\n\n /** m_boundRenderTarget[MAX_RENDER_TARGET] */\n _boundRenderTargets = new Array(MAX_RENDER_TARGET).fill(null);\n\n /** m_stackRT[MAX_RENDER_TARGET] - one stack per slot, as Carbon has. */\n _renderTargetStacks = Array.from({ length: MAX_RENDER_TARGET }, () => []);\n\n _depthStencil = null;\n\n _depthStencilStack = [];\n\n _viewport = null;\n\n /** Everything the work queue reported, for a caller that encodes it. */\n _transitions = [];\n\n // THE DEVICE HALF, AND WHY IT IS OPTIONAL. Composed, this backend draws:\n // `BeginScene` opens a command encoder, the work queue turns it into real\n // render passes, the draw verbs resolve a pipeline and bind groups from the\n // bound state and record into the live pass, and `EndScene` submits.\n // Uncomposed it validates verbs and records transitions - the stub backend\n // Carbon ships, and the thing every headless test relies on.\n //\n // IT IS HANDED VERBS, NEVER A BATCH. Until 2026-09-10 it also declared\n // `RenderBatches`, a Trinity method, and needed a resolver and a dispatcher\n // to turn the batches it was handed into bindings - the inversion this lane\n // was opened to undo. Trinity's own walk (`Tr2RenderContext.RenderBatchesInOrder`)\n // now calls the same verbs Carbon's does.\n\n _webgpu = null;\n\n _renderTarget = null;\n\n /**\n * The backend's translation tables, `MetalContext::m_utils` (`MetalContext.h:34`),\n * reached as Metal reaches its own: `context.m_utils.GetGPUTextureFormat(...)`.\n */\n m_utils = new CjsWebgpuUtils();\n\n /** The frame's command encoder, between BeginScene and EndScene. */\n _commandEncoder = null;\n\n /** The acquired swap-chain frame, valid only within one scene. */\n _frame = null;\n\n /**\n * @param {object} [composition] The device half; omit for the stub backend.\n * @param {object} [composition.webgpu] A `CjsWebgpuDevice`.\n * @param {object} [composition.renderTarget] A `CjsWebgpuRenderTarget`.\n */\n constructor({ webgpu = null, renderTarget = null } = {})\n {\n if (webgpu && !renderTarget)\n {\n fail(\"a composed backend needs a render target as well as a device\");\n }\n\n this._webgpu = webgpu;\n this._renderTarget = renderTarget;\n\n // The description starts in step with the state it describes. Carbon's\n // struct is constructed with the same defaults its context has, so a\n // description read before any setter runs describes what is actually bound\n // rather than an empty pipeline.\n this._psoDescription.topology = this._topology;\n }\n\n /** Whether this backend can actually draw. @returns {boolean} */\n IsComposed()\n {\n return this._webgpu !== null;\n }\n\n /**\n * The device this context draws through.\n *\n * Carbon's buffer and texture AL types take a `Tr2PrimaryRenderContextAL&` in\n * `Create` and reach the device through it (`Tr2BufferAL.h:47`), so the\n * context being the way to the device is Carbon's shape, not a shortcut.\n *\n * @returns {object|null} The `CjsWebgpuDevice`, or null before composition.\n */\n GetWebgpu()\n {\n return this._webgpu;\n }\n\n /**\n * Creates a device-backed buffer, this backend's kind of `Tr2BufferAL`.\n *\n * The stub context answers the same call with a `Tr2BufferALStub`, which is\n * how a Trinity class gets the right buffer for the running backend without\n * importing either - see the note on the stub's `CreateBuffer`.\n *\n * @param {object} description A `Tr2BufferDescriptionAL`.\n * @param {ArrayBufferView|null} [initialData] Initial contents, if any.\n * @returns {object|null} The created buffer, or null when Create refused.\n */\n CreateBuffer(description, initialData = null)\n {\n const buffer = new CjsWebgpuBufferAL();\n\n if (Failed(buffer.Create(description, initialData, this))) return null;\n\n return buffer;\n }\n\n /**\n * Creates a vertex layout, this backend's kind of `Tr2VertexLayoutAL`.\n *\n * IT HOLDS THE DEFINITION AND NOTHING DEVICE-SIDE, and that is not a stub\n * standing in for real work. WebGPU has no input-layout object: the vertex\n * buffer layouts are part of the render pipeline descriptor and are fixed at\n * pipeline creation, so a layout here can only be the definition a pipeline\n * will later be built from. That is why `Tr2VertexLayoutALStub` is the right\n * shape for this backend too rather than a placeholder for a WebGPU one.\n *\n * @param {object[]|object} definition The vertex element list or definition.\n * @returns {object|null} The created layout, or null when Create refused.\n */\n CreateVertexLayout(definition)\n {\n const layout = new Tr2VertexLayoutALStub();\n\n if (Failed(layout.Create(definition, this))) return null;\n\n return layout;\n }\n\n /**\n * Creates a constant buffer, this backend's kind of `Tr2ConstantBufferAL`.\n *\n * See the stub's note: with no size this returns an empty buffer for a\n * Trinity caller to `Create` later, as Carbon default-constructs its member.\n *\n * @param {number} [size] Bytes; zero returns an empty, invalid buffer.\n * @param {number} [usage] A `Tr2ConstantUsageAL`.\n * @param {ArrayBufferView|null} [initialData] Initial contents, if any.\n * @returns {object|null} The buffer, or null when a sized Create refused.\n */\n CreateConstantBuffer(size = 0, usage = Tr2ConstantUsageAL.REUSABLE, initialData = null)\n {\n const buffer = new CjsWebgpuConstantBufferAL();\n\n if (size > 0 && Failed(buffer.Create(size, usage, initialData, this))) return null;\n\n return buffer;\n }\n\n /**\n * Carbon's `Tr2SamplerStateALFactory` (`Tr2SamplerStateAL.h:41-43`), keyed on\n * the description: equal descriptions are one state.\n */\n _samplerStates = new Map();\n\n /**\n * The sampler state for a description, this backend's kind of\n * `Tr2SamplerStateAL`, created once per distinct description.\n *\n * Carbon's `Tr2SamplerStateAL::Create` IS this lookup\n * (`Tr2SamplerStateAL.cpp:25-28`): the primary context owns the factory and\n * hands back the shared object, which is why a resource set can compare\n * sampler states by identity.\n *\n * @param {object} description A `Tr2SamplerDescription`, either spelling.\n * @returns {object|null} The shared state, or null when Create refused.\n */\n CreateSamplerState(description)\n {\n const key = SamplerDescriptionKey(description);\n\n if (key === null) return null;\n\n const existing = this._samplerStates.get(key);\n\n if (existing) return existing;\n\n const state = new CjsWebgpuSamplerStateAL();\n\n if (Failed(state.Create(description, this))) return null;\n\n this._samplerStates.set(key, state);\n\n return state;\n }\n\n /**\n * Compiles one shader stage into a `GPUShaderModule`.\n *\n * THE FIRST CONSTRUCTION OF THESE CLASSES. `CjsWebgpuShaderAL` and\n * `CjsWebgpuShaderProgramAL` were written for the immediate-draw route and\n * nothing built one, because the state manager had no way to ask a backend\n * for a shader. This is that way.\n *\n * @param {number} stageType A Carbon `ShaderType`.\n * @param {ArrayBufferView|string} bytecode WGSL source, as this backend's\n * bytecode; see the head comment on `CjsWebgpuShaderAL`.\n * @param {object|null} signature The reflected signature.\n * @param {string} [shaderPath] A debug label.\n * @returns {object|null} The created shader, or null when Create refused.\n */\n CreateShader(stageType, bytecode, signature, shaderPath = \"\")\n {\n const shader = new CjsWebgpuShaderAL();\n\n if (Failed(shader.Create(stageType, bytecode, signature, shaderPath, this))) return null;\n\n return shader;\n }\n\n /**\n * Links compiled stages into a program.\n *\n * @param {object[]} shaders The stages to link.\n * @returns {object|null} The created program, or null when Create refused.\n */\n CreateShaderProgram(shaders)\n {\n const program = new CjsWebgpuShaderProgramAL();\n\n if (Failed(program.Create(shaders, this))) return null;\n\n return program;\n }\n\n /**\n * How many batches this backend has encoded since it was created.\n *\n * A HARNESS NEEDS THIS AND A FRAME DOES NOT, which is why it counts batches\n * rather than reporting them: \"did anything draw\" is the question a test asks\n * when the alternative is trusting an empty canvas. Carbon answers it with\n * `CCP_STATS_INC( batchCount )` for the same reason.\n *\n * @returns {number} Batches encoded.\n */\n GetDrawnBatchCount()\n {\n return this._drawnBatchCount;\n }\n\n _drawnBatchCount = 0;\n\n /**\n * The work queue this backend records through.\n *\n * @returns {CjsWebgpuWorkQueue} The queue.\n */\n GetWorkQueue()\n {\n return this._workQueue;\n }\n\n /** m_caps, built once against whatever device this backend was composed with. */\n _caps = null;\n\n /**\n * What this backend can do.\n *\n * Carbon returns a reference to a member (`Tr2RenderContextMetal.mm:855-858`),\n * so the object is stable across calls; built lazily here because the device\n * is a constructor argument and the caps read its limits.\n *\n * @returns {CjsWebgpuCapsAL} The capabilities.\n */\n GetCaps()\n {\n this._caps ??= new CjsWebgpuCapsAL(this._webgpu);\n\n return this._caps;\n }\n\n /**\n * m_frameNumber. Carbon's Metal backend keeps this on the context behind it\n * (`Tr2RenderContextMetal.mm:1686-1694`); there is no such object here, so it\n * lives on the backend, exactly as the stub keeps it.\n */\n _frameNumber = 0;\n\n /**\n * The frame being recorded now.\n *\n * @returns {number} One past the last frame submitted.\n */\n GetRecordingFrameNumber()\n {\n return this._frameNumber + 1;\n }\n\n /**\n * The last frame handed to the device.\n *\n * SUBMISSION, NOT COMPLETION. `GPUQueue.submit` returns without waiting, and\n * the only handle on actual completion is `onSubmittedWorkDone`, a promise -\n * so a truthful \"rendered\" count would lag by an unbounded amount and could\n * not be read synchronously. This counts submitted frames, and a ring buffer\n * fencing against it is therefore protected by submission order rather than\n * by GPU completion.\n *\n * @returns {number} Frames submitted.\n */\n GetRenderedFrameNumber()\n {\n return this._frameNumber;\n }\n\n /**\n * Everything the work queue has reported since the last drain.\n *\n * @returns {object[]} Transitions and draws, in order.\n */\n DrainTransitions()\n {\n const transitions = this._transitions;\n\n this._transitions = [];\n\n return transitions;\n }\n\n /**\n * Creates the device. Carbon gates every resource create on this.\n *\n * @returns {boolean} True.\n */\n CreateDevice()\n {\n this._isValid = true;\n\n return true;\n }\n\n /** @returns {boolean} Whether a device exists. */\n IsValid()\n {\n return this._isValid;\n }\n\n /**\n * Opens the frame's command buffer.\n *\n * @returns {boolean} True.\n */\n BeginScene()\n {\n if (!this._isValid) fail(\"BeginScene before CreateDevice\");\n\n if (this._webgpu)\n {\n // THE FRAME IS ACQUIRED LAZILY, AT THE FIRST PASS, AND NOT HERE. A canvas\n // texture is valid only within one synchronous turn: awaiting anything -\n // and preparation awaits - lets the browser swap the surface and destroy\n // it underneath. Acquiring in BeginScene therefore encoded into a dead\n // texture, and the only symptom was a submit warning and a blank canvas\n // while the draw itself reported success.\n this._frame = null;\n this._commandEncoder = this._webgpu.GetDevice().createCommandEncoder({ label: \"CjsWebgpuRenderContextAL\" });\n this._workQueue.SetCommandEncoder(this._commandEncoder, attachments => this._Descriptor(attachments));\n }\n\n this._Record(this._workQueue.BeginFrame());\n\n // The constant arena starts the frame empty (`MetalContext.mm:473`); the\n // previous frame's regions were consumed at its submit.\n this._constantArena?.Reset();\n\n // Carbon's BeginScene is exactly these two calls\n // (`Tr2RenderContextMetal.mm:860-864`). The reset is what stops a frame\n // inheriting the previous frame's bound targets.\n this.ResetRenderTargets();\n\n return true;\n }\n\n /**\n * The render-pass descriptor for a set of folded attachments.\n *\n * `attachments` IS NULL FOR AN UNHINTED PASS, which is most of them: Carbon\n * applies load and store actions only when a hint is pending and otherwise\n * leaves the backend's own defaults alone. Ours are the render target's.\n */\n _Descriptor(attachments)\n {\n if (!this._IsCanvasPass()) return this._TextureDescriptor(attachments);\n\n // First pass of the scene acquires; later passes share the one view.\n this._frame ??= this._renderTarget.AcquireFrame();\n\n const clear = attachments?.colors?.[0];\n\n return this._renderTarget.CreateRenderPassDescriptor(this._frame, {\n label: `pass ${this._workQueue.GetPassCount()}`,\n clearColor: clear?.loadOp === \"clear\" ? clear.clearValue : undefined,\n clearDepth: attachments?.depth?.loadOp === \"clear\" ? attachments.depth.clearValue : undefined\n });\n }\n\n /**\n * The render-pass descriptor when textures are bound: every bound colour\n * slot and the bound depth stencil, as Metal's pass descriptor holds the\n * textures `SetRenderAttachments` and `SetDepthAttachment` put there\n * (`MetalWorkQueue.mm:2000-2096`). Unhinted attachments LOAD and STORE, the\n * backend default the canvas path also keeps. The hint's colours are the\n * bound slots in order, which is how `Clear` builds them.\n */\n _TextureDescriptor(attachments)\n {\n const bound = this._workQueue.GetAttachments();\n const hinted = attachments?.colors ?? [];\n let next = 0;\n\n const colorAttachments = bound.colors.map(color =>\n {\n if (!color) return null;\n\n const hint = hinted[next++] ?? null;\n const clear = hint?.loadOp === \"clear\";\n\n return {\n view: color.texture.GetDeviceRenderTargetView(color.slice),\n loadOp: clear ? \"clear\" : \"load\",\n storeOp: hint?.storeOp ?? \"store\",\n ...(clear ? { clearValue: gpuColor(hint.clearValue) } : {})\n };\n });\n\n while (colorAttachments.length && !colorAttachments[colorAttachments.length - 1]) colorAttachments.pop();\n\n const descriptor = { label: `pass ${this._workQueue.GetPassCount()}`, colorAttachments };\n const depth = bound.depth?.texture ?? null;\n\n if (depth)\n {\n const hint = attachments?.depth ?? null;\n const clear = hint?.loadOp === \"clear\";\n const stencil = depth.GetDeviceFormat().includes(\"stencil\");\n\n descriptor.depthStencilAttachment = {\n view: depth.GetDeviceRenderTargetView(0),\n depthLoadOp: clear ? \"clear\" : \"load\",\n depthStoreOp: hint?.storeOp ?? \"store\",\n ...(clear ? { depthClearValue: hint.clearValue } : {}),\n ...(stencil\n ? { stencilLoadOp: clear ? \"clear\" : \"load\", stencilStoreOp: \"store\", ...(clear ? { stencilClearValue: 0 } : {}) }\n : {})\n };\n }\n\n return descriptor;\n }\n\n /**\n * Closes the frame's last pass and submits the command buffer.\n *\n * SYNCHRONOUS, AS CARBON'S IS. The first version awaited the dispatcher's\n * preparation here, because the backend had been handed batches it still had\n * to turn into pipelines. It is handed verbs now, every draw resolved inside\n * the verb that issued it, and there is nothing left to wait for: `finish()`\n * and `queue.submit()` are synchronous calls. A caller that awaits this\n * still may; awaiting a non-promise costs nothing.\n *\n * @returns {boolean} Whether the scene ended cleanly.\n */\n EndScene()\n {\n this._Record(this._workQueue.EndFrame());\n\n // UNBINDS WHAT THE FRAME BOUND, AS CARBON DOES\n // (`Tr2RenderContextMetal.mm:869-873`): vertex layout, resource set and\n // shader program go back to empty and the draw check is forced on. Without\n // it the next frame inherits the last frame's program and declaration, and\n // the early-return in `SetShaderProgram` then SKIPS the rebind because the\n // incoming program compares equal to the stale one - so the first draw of a\n // frame runs against state nobody in that frame asked for. Same shape as\n // the render-target inheritance `ResetRenderTargets` fixes at BeginScene.\n //\n // The pipeline description's program reference goes with it, because the\n // description and the field are two halves of one binding: leaving it set\n // while the field is null would resolve a pipeline for a program the\n // context does not consider bound. `_pipelineDirty` is this backend's\n // `m_needsDrawResourceCheck` - nothing is assumed resolved across frames.\n this._vertexLayout = null;\n this._resourceSet = null;\n this._shaderProgram = null;\n this._psoDescription.shaderProgram = null;\n this._pipelineDirty = true;\n\n this._frameNumber += 1;\n\n if (this._commandEncoder)\n {\n // EndFrame has already closed the last pass, so finishing here is safe.\n this._webgpu.Submit([ this._commandEncoder.finish() ]);\n this._workQueue.SetCommandEncoder(null);\n this._commandEncoder = null;\n this._frame = null;\n }\n\n return true;\n }\n\n\n /**\n * Declares what the next render pass does with its attachments.\n *\n * Carbon's two overloads differ only in how many colour attachments they\n * carry, so they collapse into one variadic list. The depth attachment is\n * always last.\n *\n * @param {...object} attachments `Tr2ColorAttachment`s then a `Tr2DepthAttachment`.\n */\n RenderPassHint(...attachments)\n {\n const depth = attachments.length ? attachments[attachments.length - 1] : null;\n const colors = attachments.slice(0, -1);\n\n this._workQueue.RenderPassHint(colors, depth);\n }\n\n /** Ends the declared pass, so following work opens a new one. */\n EndRenderPassHint()\n {\n this._Record(this._workQueue.EndRenderPassHint());\n }\n\n /**\n * Binds a colour target at one slot.\n *\n * RESETS THE VIEWPORT TO THE NEW TARGET, which Carbon does here in the\n * backend (`Tr2RenderContextMetal.mm:762-766`) whenever slot zero changes.\n * Leaving it alone is the defect where a 2048 shadow pass leaves the viewport\n * at 2048 for the rest of the frame.\n *\n * @param {number} slot The slot.\n * @param {object|null} renderTarget A `Tr2TextureAL`, or null to detach.\n * @param {number} [slice] The array slice or cube face.\n * @returns {boolean} True.\n */\n SetRenderTarget(slot, renderTarget, slice = 0)\n {\n if (slot >= MAX_RENDER_TARGET) return false;\n\n this._Record(this._workQueue.SetRenderAttachments(renderTarget ?? null, slot, slice));\n\n // The attachment formats are part of the pipeline; DX12 dirties its PSO\n // here too (`Tr2RenderContextDx12.cpp:456`).\n if (this._boundRenderTargets[slot] !== (renderTarget ?? null)) this._pipelineDirty = true;\n\n this._boundRenderTargets[slot] = renderTarget ?? null;\n\n const primary = this._boundRenderTargets[0];\n\n if (slot === 0 && primary)\n {\n this.SetViewport({ x: 0, y: 0, width: primary.GetWidth(), height: primary.GetHeight() });\n }\n\n return true;\n }\n\n /**\n * The target bound at one slot.\n *\n * @param {number} [slot] The slot.\n * @returns {object|null} The target.\n */\n GetRenderTarget(slot = 0)\n {\n return this._boundRenderTargets[slot] ?? null;\n }\n\n /**\n * Saves the target bound at one slot.\n *\n * ONE STACK PER SLOT, as Carbon has (`m_stackRT[MAX_RENDER_TARGET]`). A single\n * shared stack pops the most recent push whatever its slot, so pushing slot 0\n * then slot 1 and popping slot 0 restores the wrong surface.\n *\n * @param {number} [slot] The slot.\n * @returns {boolean} True.\n */\n PushRenderTarget(slot = 0)\n {\n if (slot >= MAX_RENDER_TARGET) return false;\n\n this._renderTargetStacks[slot].push(this._boundRenderTargets[slot] ?? null);\n\n return true;\n }\n\n /**\n * Restores the target saved for one slot.\n *\n * @param {number} [slot] The slot.\n * @returns {boolean} Whether anything was saved.\n */\n PopRenderTarget(slot = 0)\n {\n const stack = this._renderTargetStacks[slot];\n\n if (!stack?.length) return false;\n\n this.SetRenderTarget(slot, stack.pop());\n\n return true;\n }\n\n /**\n * Depth of one slot's stack.\n *\n * @param {number} [slot] The slot.\n * @returns {number} The depth.\n */\n GetStackSizeRT(slot = 0)\n {\n return this._renderTargetStacks[slot]?.length ?? 0;\n }\n\n /**\n * Binds the depth-stencil target.\n *\n * @param {object|null} depthStencil A `Tr2TextureAL`, or null to detach.\n * @returns {boolean} True.\n */\n SetDepthStencil(depthStencil)\n {\n const previous = this._depthStencil;\n\n this._Record(this._workQueue.SetDepthAttachment(depthStencil ?? null));\n\n // Unbinding ends the pass that wrote the depth, so a sampled depth\n // texture's float shadow is refreshed here (CjsWebgpuTextureAL._depthShadow).\n if (previous && previous !== (depthStencil ?? null)) this._Record(this._workQueue.CopyDepthShadow(previous));\n\n if (this._depthStencil !== (depthStencil ?? null)) this._pipelineDirty = true;\n\n this._depthStencil = depthStencil ?? null;\n\n return true;\n }\n\n /** @returns {object|null} The bound depth-stencil target. */\n GetDepthStencil()\n {\n return this._depthStencil;\n }\n\n /** Saves the bound depth-stencil target. @returns {boolean} True. */\n PushDepthStencil()\n {\n this._depthStencilStack.push(this._depthStencil);\n\n return true;\n }\n\n /** Restores the saved depth-stencil target. @returns {boolean} Whether one was saved. */\n PopDepthStencil()\n {\n if (!this._depthStencilStack.length) return false;\n\n this.SetDepthStencil(this._depthStencilStack.pop());\n\n return true;\n }\n\n /** @returns {number} Depth of the depth-stencil stack. */\n GetStackSizeDS()\n {\n return this._depthStencilStack.length;\n }\n\n /**\n * The size of the target at one slot.\n *\n * @param {number} [slot] The slot.\n * @returns {object} `{ result, width, height }`.\n */\n GetRenderTargetSize(slot = 0)\n {\n const target = this._boundRenderTargets[slot];\n\n if (!target) return { result: ALResult.E_INVALIDCALL, width: 0, height: 0 };\n\n return { result: ALResult.S_OK, width: target.GetWidth(), height: target.GetHeight() };\n }\n\n /**\n * Sets the viewport following draws use.\n *\n * @param {object} viewport `{ x, y, width, height }`.\n * @returns {boolean} True.\n */\n SetViewport(viewport)\n {\n this._viewport = viewport ? { ...viewport } : null;\n\n // Metal hands every viewport to its work queue (`Tr2RenderContextMetal.mm:1180-1186`).\n // A viewport without depth bounds has Tr2Viewport's defaults, 0 and 1.\n if (viewport) this._workQueue.SetViewport(viewport.x, viewport.y, viewport.width, viewport.height, viewport.minZ ?? 0, viewport.maxZ ?? 1);\n\n return true;\n }\n\n /** @returns {object|null} The current viewport. */\n GetViewport()\n {\n return this._viewport ? { ...this._viewport } : null;\n }\n\n /**\n * Clears the bound attachments.\n *\n * A CLEAR IS A LOAD OPERATION, not a command. WebGPU has no mid-pass clear,\n * so this ends the current pass and makes the clear the next one's load\n * actions, ON THE ATTACHMENTS BOUND NOW: Metal's `ClearAttachment`\n * (`MetalWorkQueue.mm:2845-2881`). Binding other targets first runs the\n * clear in a pass of its own, so it never lands on them; a pending hint\n * wins, and the clear is ignored.\n *\n * CARBON'S FLAGS AND SLOT (`Tr2RenderContextMetal.mm:297-351`): the colour\n * clear names ONE slot, and depth is cleared only when asked. Every other\n * attached colour slot loads, so clearing the velocity target at slot 1\n * leaves slot 0 alone. `clearColor`/`clearDepth`/`clearStencil` are\n * CLEARFLAGS_TARGET/ZBUFFER/STENCIL; a call naming none of them clears the\n * target and depth, which is what every caller without flags meant. As in\n * Metal, a cleared target or depth that is not bound is E_INVALIDCALL.\n *\n * @param {object} [options] `{ color, depth, stencil, clearColor, clearDepth, clearStencil, slot }`.\n * @returns {boolean} Whether the clear was declared.\n */\n Clear(options = {})\n {\n const flagged = \"clearColor\" in options || \"clearDepth\" in options || \"clearStencil\" in options;\n const clearTarget = flagged ? !!options.clearColor : true;\n const clearDepth = flagged ? !!(options.clearDepth || options.clearStencil) : true;\n const slot = options.slot ?? 0;\n const attachments = this._workQueue.GetAttachments();\n\n if (clearTarget && !attachments.colors[slot]) return false;\n if (flagged && clearDepth && !attachments.depth) return false;\n\n const colors = [];\n\n attachments.colors.forEach((attachment, index) =>\n {\n if (!attachment) return;\n colors.push(clearTarget && index === slot\n ? new Tr2ColorAttachment(Tr2LoadAction.CLEAR, Tr2StoreAction.STORE, options.color ?? 0)\n : new Tr2ColorAttachment(Tr2LoadAction.LOAD, Tr2StoreAction.STORE));\n });\n\n const depth = attachments.depth\n ? (clearDepth\n ? new Tr2DepthAttachment(Tr2LoadAction.CLEAR, Tr2StoreAction.STORE, Number(options.depth ?? 1))\n : new Tr2DepthAttachment(Tr2LoadAction.LOAD, Tr2StoreAction.STORE))\n : null;\n\n this._Record(this._workQueue.ClearAttachment(colors, depth));\n\n return true;\n }\n\n /**\n * Dispatches the bound compute program.\n *\n * Carbon's AL verb (`Tr2RenderContextDx11.h:151`); Metal's is the compute\n * encoder's `DispatchThreadgroups`. The program, its resource set and its\n * constants are whatever `Tr2Renderer.runComputeShader` bound for the pass.\n * WebGPU needs a `GPUComputePipeline`, made once per program here, where a\n * D3D context binds the compute shader directly.\n *\n * @param {number} x Thread groups along x.\n * @param {number} y Thread groups along y.\n * @param {number} z Thread groups along z.\n * @returns {boolean} Whether the dispatch was encoded.\n */\n RunComputeShader(x, y, z)\n {\n if (!this._webgpu) return false;\n\n const program = this._shaderProgram;\n const module = program && typeof program.GetModuleFor === \"function\"\n ? program.GetModuleFor(ShaderType.COMPUTE_SHADER)\n : null;\n\n if (!module) return this._RefusePipeline(\"a compute program\");\n\n let pipeline = this._computePipelines.get(program) ?? null;\n\n if (!pipeline)\n {\n pipeline = this._webgpu.GetDevice().createComputePipeline({\n label: `Tr2RenderContextAL compute ${program.GetIdentity()}`,\n layout: program.GetPipelineLayout(),\n compute: { module, entryPoint: WEBGPU_ENTRY_POINT }\n });\n this._computePipelines.set(program, pipeline);\n }\n\n if (!this._EmitBindGroups()) return false;\n\n this._workQueue.SetComputePipeline(pipeline);\n this._Record(this._workQueue.DispatchThreadgroups(x, y, z));\n\n return true;\n }\n\n /** Compute pipelines by program; a program's compute pipeline has no other state. */\n _computePipelines = new WeakMap();\n\n /** The mip generator textures on this context use, made on first ask. */\n _mipGenerator = null;\n\n /**\n * The mip generator, standing in for the blit encoder's `generateMipmaps`\n * that Metal's work queue calls (see CjsWebgpuMipGenerator).\n *\n * @returns {CjsWebgpuMipGenerator} The generator.\n */\n GetMipGenerator()\n {\n this._mipGenerator ??= new CjsWebgpuMipGenerator(this._webgpu.GetDevice());\n return this._mipGenerator;\n }\n\n /**\n * Runs a compute dispatch whose group counts are read from a buffer.\n *\n * REFUSES; see `RunComputeShader`. This validated the buffer and then set the\n * compute encoder type, which is not a dispatch - the same false success, with\n * an argument check in front of it that made it look like more.\n *\n * Carbon's stub refuses too (`stub/Tr2RenderContextStub.h:175-178`).\n *\n * @param {object} _effect The compute effect to run.\n * @param {object} _indirectionBuffer A buffer holding the group counts.\n * @param {number} [_offsetForArgs] Byte offset to them.\n * @returns {boolean} False; nothing is dispatched.\n */\n RunComputeShaderIndirect(_effect, _indirectionBuffer, _offsetForArgs = 0)\n {\n return false;\n }\n\n /**\n * Clears an unordered-access resource.\n *\n * A BUFFER CLEARED TO ZERO is encoded: Metal's `ClearUav` hands it to\n * `MetalWorkQueue::ClearBuffer` (`Tr2RenderContextMetal.mm:237-257`), whose\n * zero fast path is a blit fill (`MetalWorkQueue.mm:1216-1225`), and WebGPU's\n * `clearBuffer` is that fill. A float zero is the same bits, so it takes the\n * same path; negative zero does not.\n *\n * EVERYTHING ELSE REFUSES RATHER THAN PRETENDS: a non-zero value needs\n * Metal's clear compute shader, and a texture needs `ClearTexture`, neither\n * of which exists here. Reporting success would leave a caller reading stale\n * contents it believes are cleared, which a compute pass cannot detect.\n * Carbon's stub refuses the same way (`Tr2RenderContextALStub.ClearUav`).\n *\n * @param {object} resource The buffer or texture to clear.\n * @param {number[]} value The clear value, four components.\n * @param {boolean} [_clearWithFloat] Whether the value is float or integer.\n * @returns {boolean} Whether the clear was encoded.\n */\n ClearUav(resource, value, _clearWithFloat = false)\n {\n const buffer = DeviceBufferOf(resource);\n\n if (!buffer) return false;\n\n for (let index = 0; index < 4; index += 1)\n {\n if (!Object.is(Number(value?.[index] ?? 0), 0)) return false;\n }\n\n this._Record(this._workQueue.ClearBuffer(buffer));\n\n return true;\n }\n\n /**\n * Presents the frame (`Tr2RenderContextMetal.mm:879-886`): the swap chain\n * presents and the render targets reset. It does NOT end the scene. Carbon's\n * TriDevice::HandleRenderTick presents the previous frame, which EndScene\n * already submitted, before Render opens the next. This called EndScene, so\n * a Present during an open frame closed it underneath its owner.\n *\n * The browser presents a configured canvas after the submission that drew\n * into its current texture, so the swap-chain half has nothing to do.\n *\n * @returns {boolean} True.\n */\n Present()\n {\n return this.ResetRenderTargets();\n }\n\n /**\n * Sets the primitive topology following draws use.\n *\n * @param {number} topology A `Topology` value.\n * @returns {boolean} Whether the AL knows it.\n */\n SetTopology(topology)\n {\n if (topology >= Topology.TOP_MAX_TOPOLOGY || !VERTICES_PER_PRIMITIVE[topology]) return false;\n\n this._topology = topology;\n this._psoDescription.topology = topology;\n this._pipelineDirty = true;\n\n return true;\n }\n\n /**\n * Binds the vertex declaration.\n *\n * @param {object} layout A `Tr2VertexLayoutAL`.\n * @returns {boolean} True.\n */\n SetVertexLayout(layout)\n {\n if (this._vertexLayout === layout) return true;\n\n // DIRTIES THE PIPELINE, AS DX12'S DOES (`Tr2RenderContextDx12.cpp:321`).\n // The descriptor itself is built at the draw, not here: Metal's\n // SetVertexLayout only stores the layout (`Tr2RenderContextMetal.mm:894`)\n // and CheckDrawResources matches it against the BOUND PROGRAM's inputs at\n // draw time (`:524-541`), because the same declaration yields a different\n // descriptor under a shader that reads a different subset of it.\n this._vertexLayout = layout;\n this._pipelineDirty = true;\n\n return true;\n }\n\n /**\n * Binds one vertex stream.\n *\n * @param {number} stream The slot.\n * @param {object} buffer A `Tr2BufferAL`.\n * @param {number} offset Byte offset.\n * @param {number} stride Bytes per vertex.\n * @returns {boolean} True.\n */\n SetStreamSource(stream, buffer, offset, stride)\n {\n // The stride is part of the pipeline on WebGPU - `arrayStride` lives in the\n // vertex buffer layout - exactly as it is on Metal, where each active\n // stream's stride feeds the vertex-descriptor hash\n // (`MetalWorkQueue.mm:1512-1531`). The buffer itself is not.\n if (this._streams[stream]?.stride !== stride) this._pipelineDirty = true;\n\n this._streams[stream] = { buffer, offset, stride };\n\n return true;\n }\n\n /**\n * Binds the index buffer.\n *\n * @param {object} buffer A `Tr2BufferAL`.\n * @param {number} [stride] Bytes per index.\n * @returns {boolean} True.\n */\n SetIndices(buffer, stride = 0)\n {\n this._indexBuffer = buffer;\n this._indexStride = stride;\n\n return true;\n }\n\n /**\n * Binds the shader program following draws run.\n *\n * @param {object} shaderProgram A `Tr2ShaderProgramAL`.\n * @returns {boolean} True.\n */\n SetShaderProgram(shaderProgram)\n {\n if (this._shaderProgram === shaderProgram) return true;\n\n this._shaderProgram = shaderProgram;\n this._psoDescription.shaderProgram = shaderProgram;\n this._pipelineDirty = true;\n\n return true;\n }\n\n /**\n * Takes the render-state setup a pass authored, with the state manager's\n * overrides applied.\n *\n * Carbon's backends receive a resolved state-PAIR list here and set each pair\n * on the device (`Tr2EffectStateManager.cpp:753`). WebGPU has no per-state\n * setter - state is folded into a pipeline at creation - so the setup is held\n * and projected when a pipeline is resolved, which is also why the projection\n * needs the depth format only this backend knows.\n *\n * THE PROJECTION IS NOT DONE HERE. `Tr2RenderStateSetup.GetWebgpuRecipe`\n * already does it and the batch resolver already uses it; a second translator\n * would be the mistake this whole lane exists to undo. This stores the inputs\n * and marks the pipeline dirty, as Carbon's setters do.\n *\n * @param {object} setup A `Tr2RenderStateSetup`.\n * @param {object} [overrides] The state manager's render-state overrides.\n * @returns {boolean} Whether a setup was supplied.\n */\n SetRenderStates(setup, overrides = null)\n {\n if (!setup) return false;\n\n // Carbon's setters compare before dirtying, so a redundant apply costs\n // nothing (Tr2RenderContextDx12.cpp:315-338). The overrides are compared BY\n // VALUE: the state manager hands a fresh copy each apply, and comparing\n // references made every apply dirty the pipeline.\n if (this._renderStateSetup === setup && CanonicalKey(this._renderStateOverrides) === CanonicalKey(overrides)) return true;\n\n this._renderStateSetup = setup;\n this._renderStateOverrides = overrides;\n this._psoDescription.renderStateSetup = setup;\n this._psoDescription.renderStateOverrides = overrides;\n this._pipelineDirty = true;\n\n return true;\n }\n\n /**\n * m_renderStates - single states set by name rather than through a setup.\n *\n * A DIFFERENT AXIS FROM `overrides`, which is a flags object the PSO\n * description reads (`core/psoDescription.js:113-114`). These are Carbon's\n * raw `RenderState` values, which `TriStepSetRenderState` sets one at a time.\n */\n _renderStates = new Map();\n\n /**\n * Sets one render state.\n *\n * Carbon's Metal backend stores the value and applies it when the pipeline is\n * assembled, and says so in a comment above the method: \"we'll remove the\n * actual setting here and just store the values in some state and we'll do a\n * wholesale setting of state in some combined function just before we draw\"\n * (`Tr2RenderContextMetal.mm:925-928`). This stores.\n *\n * THE PSO RESOLVER DOES NOT READ THESE YET. `GetWebgpuRecipe` projects the\n * setup and the flags, and nothing consumes the single-state map, so a state\n * set this way is recorded and not yet honoured. Recorded rather than dropped,\n * because the resolver is where the projection belongs and adding a second\n * translator here is the mistake this file already carries a warning about.\n *\n * @param {number} state A `RenderState` value.\n * @param {number} value The value to set.\n * @returns {boolean} True.\n */\n SetRenderState(state, value)\n {\n const key = state >>> 0;\n\n if (this._renderStates.get(key) === (value >>> 0)) return true;\n\n this._renderStates.set(key, value >>> 0);\n this._pipelineDirty = true;\n\n // Depth clip is honoured where the device can: the shadow cascades draw\n // with it off, so a caster in front of the light's near plane still\n // writes depth. Without depth-clip-control it stays on.\n if (key === RenderState.RS_DEPTH_CLIP_ENABLE)\n {\n this._psoDescription.unclippedDepth = value === 0 && this._webgpu.GetDevice().features.has(\"depth-clip-control\");\n }\n\n return true;\n }\n\n /** The setup, overrides and single states a pipeline should be resolved from. */\n GetRenderStateInputs()\n {\n return {\n setup: this._renderStateSetup,\n overrides: this._renderStateOverrides,\n states: this._renderStates\n };\n }\n\n /** Whether the pipeline description changed since it was last resolved. */\n IsPipelineDirty()\n {\n return this._pipelineDirty;\n }\n\n /**\n * The pipeline description the setters have accumulated.\n *\n * Carbon's `m_psoDescription`, and `GetMissing()` on it answers the question\n * `GetPipelineState` answers by returning null: what this state does not yet\n * name. Reading it does not resolve anything.\n *\n * @returns {CjsWebgpuPsoDescription} The live description.\n */\n GetPsoDescription()\n {\n this._RefreshAttachmentFormats();\n\n return this._psoDescription;\n }\n\n /** The pipeline the last resolve produced, or null. */\n _pipeline = null;\n\n /**\n * Resolved pipelines by description key.\n *\n * Carbon keeps this on the DEVICE (`m_ownerDevice->m_pipelineStates`,\n * `Tr2PrimaryRenderContextDx12.h:319`; Metal's `GetCachedRenderPipelineState`)\n * so every context shares one. It lives here until `CjsWebgpuDevice` offers a\n * synchronous cache - its `CjsWebgpuPipelineCache` resolves asynchronously,\n * and a draw verb cannot await. Cleared with the device resources.\n */\n _pipelines = new Map();\n\n /**\n * Why the last `EmitRenderEncoderState` refused, or null when it did not.\n *\n * Carbon asserts at these points; a JS frame must not die at a draw, so the\n * reason is kept where a harness can read it instead.\n */\n m_pipelineFailure = null;\n\n /**\n * Resolves and binds the pipeline the bound state describes.\n *\n * METAL'S `EmitRenderPipelineState` (`MetalWorkQueue.mm:1595-1747`) AND\n * DX12'S `SetAllState` (`Tr2RenderContextDx12.cpp:810-878`): called from\n * inside every draw verb, keyed on the description's hash, creating on a miss\n * and otherwise reusing, and clearing the dirty flag once resolved\n * (`:870`). Pipeline creation is SYNCHRONOUS here as it is there -\n * `createRenderPipeline` returns immediately, and the first-use stall it can\n * carry is the same one `newRenderPipelineStateWithDescriptor` carries.\n *\n * The vertex half of the description is built here rather than by\n * `SetVertexLayout`, because it depends on three bound things at once: the\n * declaration, the program whose inputs select from it, and the stream\n * strides (`Tr2RenderContextMetal.mm:524-541`, `MetalWorkQueue.mm:1842-1863`).\n *\n * Uncomposed, there is no device and nothing to resolve; the verbs record as\n * the stub's do.\n *\n * @returns {boolean} Whether a pipeline is bound for the next draw.\n */\n EmitRenderPipelineState()\n {\n if (!this._webgpu) return true;\n\n if (!this._pipelineDirty && this._pipeline)\n {\n this._workQueue.SetRenderPipeline(this._pipeline);\n\n return true;\n }\n\n const description = this.GetPsoDescription();\n const program = description.shaderProgram;\n\n if (!program || typeof program.GetPipelineLayout !== \"function\")\n {\n return this._RefusePipeline(\"a program this backend linked\");\n }\n\n const vertexBufferLayouts = this.BuildVertexBufferLayouts();\n\n if (typeof vertexBufferLayouts === \"string\") return this._RefusePipeline(vertexBufferLayouts);\n\n description.vertexBufferLayouts = vertexBufferLayouts;\n\n const missing = description.GetMissing();\n\n if (missing) return this._RefusePipeline(missing);\n\n if (!program.GetModuleFor(ShaderType.VERTEX_SHADER)) return this._RefusePipeline(\"a vertex stage\");\n\n // An indexed strip needs its index format baked into the pipeline\n // (`primitive.stripIndexFormat`), so the bound index stride is part of the\n // identity for strips and nothing else.\n const topology = TOPOLOGIES[this._topology];\n const stripIndexFormat = topology && topology.endsWith(\"-strip\") ? INDEX_FORMAT[this._indexStride] ?? null : null;\n let key;\n let recipe;\n\n // `GetWebgpuRecipe` refuses a state it cannot project - a non-solid fill,\n // depth state against no depth attachment - by THROWING. A draw verb is not\n // where a frame may die, so the refusal becomes this verb's reason.\n try\n {\n key = `${description.GetKey()}|strip:${stripIndexFormat ?? \"-\"}`;\n recipe = description.BuildRecipe();\n }\n catch (error)\n {\n return this._RefusePipeline(`a projectable state: ${error.message}`);\n }\n\n if (stripIndexFormat) recipe.primitive = { ...recipe.primitive, stripIndexFormat };\n\n let pipeline = this._pipelines.get(key) ?? null;\n const created = pipeline === null;\n\n if (created)\n {\n pipeline = this._CreateRenderPipeline(program, recipe);\n this._pipelines.set(key, pipeline);\n }\n\n this._pipeline = pipeline;\n this._pipelineDirty = false;\n this.m_pipelineFailure = null;\n this._Record([ { type: \"pipeline\", key, created } ]);\n this._workQueue.SetRenderPipeline(pipeline);\n\n return true;\n }\n\n /**\n * Binds everything a draw needs on the encoder: pipeline, then buffers.\n *\n * Metal's `EmitRenderEncoderState` (`MetalWorkQueue.mm:1750-1890`), which\n * the draw verbs call first and skip the draw when it fails. Bindings are\n * deferred to here rather than set in `SetStreamSource`, as Metal defers\n * them (`:2570-2598` stores, `:2613-2690` binds).\n *\n * WHAT IT CANNOT HONOUR, IT REFUSES. A pipeline or bind group that cannot be\n * resolved, or a stream or index buffer that is not a device buffer, would\n * be a validation error on the GPU, so the draw is refused here and says why.\n *\n * @param {boolean} indexed Whether the draw reads the bound index buffer.\n * @returns {boolean} Whether the encoder is ready to draw.\n */\n EmitRenderEncoderState(indexed)\n {\n if (!this._webgpu) return true;\n\n // A reason describes THIS attempt; one left from an earlier refusal would\n // outlive the draw that succeeded after it.\n this.m_pipelineFailure = null;\n\n if (!this.EmitRenderPipelineState()) return false;\n\n if (!this._EmitBindGroups()) return false;\n\n const layouts = this._psoDescription.vertexBufferLayouts;\n\n for (let slot = 0; slot < layouts.length; slot += 1)\n {\n if (!layouts[slot]) continue;\n\n if (slot === this._dummyVertexStream)\n {\n this._workQueue.SetVertexBuffer(slot, this._DummyVertexBuffer(), 0);\n continue;\n }\n\n const stream = this._streams[slot];\n const buffer = DeviceBufferOf(stream?.buffer);\n\n if (!buffer) return this._RefusePipeline(`a device buffer on vertex stream ${slot}`);\n\n this._workQueue.SetVertexBuffer(slot, buffer, stream.offset ?? 0);\n }\n\n if (indexed)\n {\n const format = INDEX_FORMAT[this._indexStride] ?? null;\n const buffer = DeviceBufferOf(this._indexBuffer);\n\n if (!format) return this._RefusePipeline(`an index format for a ${this._indexStride}-byte stride`);\n if (!buffer) return this._RefusePipeline(\"a device buffer for the indices\");\n\n this._workQueue.SetIndexBuffer(buffer, format, 0);\n }\n\n return true;\n }\n\n /**\n * The vertex buffer layouts the bound declaration, program and strides\n * describe, one per stream slot.\n *\n * Metal's `Tr2VertexLayoutAL::SetVertexLayout` (`Tr2VertexLayoutALMetal.mm:205-245`):\n * match the program's pipeline inputs against the declaration's items, and\n * stamp each active stream's stride. An input the declaration lacks gets no\n * attribute - Metal points it at a dummy stream - and a stream no input\n * reads gets no layout.\n *\n * @returns {Array<object|null>|string} The layouts by slot, or what is\n * missing when they cannot be built.\n */\n BuildVertexBufferLayouts()\n {\n const layout = this._vertexLayout;\n\n if (!layout) return [];\n\n const elements = layout.GetDefinition() ?? [];\n const inputs = this._shaderProgram.GetInputs();\n const plan = resolveBindingPlan(elements, inputs);\n const byStream = new Map();\n\n // AN INPUT THE DECLARATION LACKS IS A REFUSAL, NOT A HOLE. WebGPU requires\n // every vertex-stage `@location` to be fed, and `createRenderPipeline`\n // with a missing one yields an invalid pipeline WITHOUT throwing - which\n // would then be cached. Metal feeds such an input from a constant-step\n // dummy stream (`Tr2VertexLayoutALMetal.mm:155-159`); until that is\n // ported, the draw says which input it cannot feed.\n const missing = plan.entries.filter(entry => !entry.element);\n\n this._dummyVertexStream = null;\n\n for (const entry of plan.entries)\n {\n if (!entry.element) continue;\n\n const stream = entry.element.stream ?? 0;\n\n if (!byStream.has(stream)) byStream.set(stream, []);\n byStream.get(stream).push(entry);\n }\n\n const layouts = new Array(byStream.size ? Math.max(...byStream.keys()) + 1 : 0).fill(null);\n\n for (const [ stream, entries ] of byStream)\n {\n const stride = this._streams[stream]?.stride;\n\n if (!stride) return `a stride for vertex stream ${stream}`;\n\n try\n {\n layouts[stream] = WebgpuVertexBufferLayout(stride, entries);\n }\n catch (error)\n {\n return `a vertex format for stream ${stream}: ${error.message}`;\n }\n }\n\n // AN INPUT THE DECLARATION LACKS READS A CONSTANT DUMMY STREAM, as Metal's\n // does (Tr2VertexLayoutALMetal.mm:145-165): every missing input at offset\n // 0 of one stream that does not step, in a format from the input's\n // declared type - INT char4, UINT uchar4, anything else float4. WebGPU\n // spells \"does not step\" as arrayStride 0, and requires every vertex-stage\n // location to be fed, so leaving the hole is an invalid pipeline. The\n // stream takes the first slot after the mesh's own.\n if (missing.length)\n {\n this._dummyVertexStream = layouts.length;\n layouts.push({\n arrayStride: 0,\n stepMode: \"vertex\",\n attributes: missing\n .map(entry => ({ shaderLocation: entry.registerIndex, offset: 0, format: DUMMY_VERTEX_FORMAT[entry.fallbackType] ?? \"float32x4\" }))\n .sort((a, b) => a.shaderLocation - b.shaderLocation)\n });\n }\n\n return layouts;\n }\n\n /** The slot of the constant dummy vertex stream this layout added, or null. */\n _dummyVertexStream = null;\n\n /**\n * Metal's dummy vertex buffer (the METAL_VERTEX_STREAM_DUMMY stream): 16\n * zero bytes, the widest dummy element, read by every missing input.\n * WebGPU zero-fills a new buffer.\n */\n _DummyVertexBuffer()\n {\n const usage = this._webgpu.GetBufferUsage();\n\n this._dummies.vertexBuffer ??= this._webgpu.GetDevice().createBuffer({\n label: \"Tr2RenderContextAL dummy vertex stream\",\n size: 16,\n usage: usage.VERTEX | usage.COPY_DST\n });\n\n return this._dummies.vertexBuffer;\n }\n\n /**\n * Bind groups by `program | group | resource set | constant buffers`.\n *\n * DX12's descriptor tables live on the CONTEXT, per back buffer\n * (`Tr2RenderContextDx12.h:269`), and are committed at `SetAllState`\n * (`:875`); Metal binds per stage inside `EmitRenderEncoderState`\n * (`MetalWorkQueue.mm:2613-2690`). A WebGPU bind group is an immutable object\n * made of both the set's entries and the bound constant buffers, so it is\n * made here, at the draw, and kept by the identities that produced it.\n */\n _bindGroups = new Map();\n\n /**\n * Builds or reuses one bind group per program group and names them for the\n * draw.\n *\n * The program's uniform slots read the constant buffers `SetConstants` bound\n * at that stage and register - Carbon's parallel road for CBs - uploading\n * each buffer's shadow if it changed, which is where Carbon's token is\n * consumed. Every other slot reads the resource set; with no set bound, or a\n * set made for another program, the slots take dummies, which is Metal's\n * `SetDummyResources` (`Tr2RenderContextMetal.mm:527-530`).\n *\n * @returns {boolean} Whether every group could be built.\n */\n _EmitBindGroups()\n {\n const program = this._shaderProgram;\n const layouts = program.GetBindGroupLayouts();\n\n if (!layouts.length) return true;\n\n const set = this._resourceSet?.m_resourceSet.implementation;\n const entries = set && set.IsValid() && set.GetProgram() === program ? set.GetEntries() : null;\n const setId = entries ? set.m_id : 0;\n const bindings = program.GetBindings();\n const device = this._webgpu.GetDevice();\n\n for (let group = 0; group < layouts.length; group += 1)\n {\n const keyParts = [ program.GetIdentity(), group, setId ];\n const resolved = [];\n const dynamicOffsets = [];\n // Each storage dummy in the group its own (GetDummyStorageTexture).\n let storageDummies = 0;\n\n for (const binding of bindings)\n {\n if (binding.group !== group) continue;\n\n let resource;\n\n if (binding.buffer && binding.buffer.type === \"uniform\")\n {\n // METAL'S `SetConstants` + `UploadConstants` (`MetalWorkQueue.mm:2396-2439`):\n // the shadow is copied into the frame's arena if its token is stale,\n // and the bind is the PAGE with the region's offset as a dynamic\n // offset - `setVertexBufferOffset:` (`:2656-2659`). The bind group\n // therefore keys on the page and not on the buffer: two objects\n // drawn through one program share one bind group and differ only in\n // their offsets, which is the whole economy of the arena.\n const size = binding.buffer.minBindingSize ?? 16;\n const constantBuffer = binding.generatedSymbol === CARBON_BACKEND_ADDRESS_MODES_SYMBOL\n ? this._AddressModesBuffer(entries ? set : null, size)\n : this._ConstantBufferFor(binding);\n\n if (constantBuffer)\n {\n const region = this.UploadConstants(constantBuffer, size);\n\n resource = { buffer: this._Arena().GetPage(region.page), offset: 0, size };\n dynamicOffsets.push(region.offset);\n keyParts.push(`p${region.page}`);\n }\n else\n {\n // DX12 substitutes a null CB for an unbound root CBV\n // (`DescriptorStateCacheDx12.cpp:234-242`).\n resource = { buffer: this.GetNullBuffer(size, \"UNIFORM\"), offset: 0, size };\n dynamicOffsets.push(0);\n keyParts.push(\"null\");\n }\n }\n else\n {\n resource = entries ? entries.get(`${group}:${binding.binding}`) ?? null : null;\n resource ??= this._DummyFor(binding, binding.storageTexture ? storageDummies++ : 0);\n }\n\n resolved.push({ binding: binding.binding, resource });\n }\n\n const key = keyParts.join(\"|\");\n let bindGroup = this._bindGroups.get(key) ?? null;\n\n if (!bindGroup)\n {\n // Identities are monotonic, so a key never comes back once its set or\n // buffer is gone; without a bound the map grows with every rebuild.\n // DX12's descriptor cache is per back buffer and rebuilt each frame\n // (`Tr2RenderContextDx12.h:269`); dropping everything and rebuilding\n // what the next draws need is the same cost profile.\n if (this._bindGroups.size >= MAX_CACHED_BIND_GROUPS) this._bindGroups.clear();\n\n bindGroup = device.createBindGroup({\n label: `Tr2RenderContextAL ${program.GetIdentity()} group${group}`,\n layout: layouts[group],\n entries: resolved\n });\n this._bindGroups.set(key, bindGroup);\n }\n\n this._workQueue.SetBindGroup(group, bindGroup, dynamicOffsets);\n }\n\n return true;\n }\n\n /** Carbon's `ConstantBufferAllocator`, owned by the context (`MetalContext.h:104`). */\n _constantArena = null;\n\n /** The frame's constant arena, made on first use. */\n _Arena()\n {\n this._constantArena ??= new CjsWebgpuConstantArena(this._webgpu);\n\n return this._constantArena;\n }\n\n /**\n * Copies constants into this frame's arena and says where they landed.\n *\n * CARBON'S TWO OVERLOADS, in one method as JavaScript spells them\n * (`Tr2RenderContextMetal.mm:679-697`, `Tr2RenderContextDx12.cpp:538-548`):\n *\n * - given BYTES, a fresh region every call - Carbon constructs a zeroed\n * token each time, so nothing is reused;\n * - given a `Tr2ConstantBufferAL`, the buffer's OWN token, so a buffer bound\n * twice in a frame without a Lock between keeps one region. Carbon reaches\n * straight into the impl for it (`buffer.m_buffer->m_token`), which is why\n * ours is public.\n *\n * Carbon returns a `uint64_t` packing Metal's page and offset together; the\n * region object is that pair unpacked, which is what a bind group needs.\n *\n * @param {object|ArrayBufferView} source A constant buffer, or the bytes.\n * @param {number} [size] Bytes the binding demands at least.\n * @returns {{page: number, offset: number, size: number}|null} The region,\n * or null when there is nothing to upload - Carbon's `return 0`.\n */\n UploadConstants(source, size = 0)\n {\n if (!this._webgpu || !source) return null;\n\n const arena = this._Arena();\n\n if (ArrayBuffer.isView(source)) return arena.Allocate(source, Math.max(size, source.byteLength));\n\n if (!(source instanceof CjsWebgpuConstantBufferAL) || !source.IsValid()) return null;\n\n const token = source.m_token;\n const wanted = Math.max(size, source.m_shadowCopy.length);\n\n // Metal's `UploadConstants` (`MetalWorkQueue.mm:2426-2439`): a token from\n // this frame is left alone. The size test is ours - a layout may demand\n // more than an earlier binding reserved, and a short region is a\n // validation error rather than a wrong picture.\n if (token.frame !== this.GetRecordingFrameNumber() || token.size < wanted)\n {\n const region = arena.Allocate(source.m_shadowCopy, wanted);\n\n token.frame = this.GetRecordingFrameNumber();\n token.page = region.page;\n token.offset = region.offset;\n token.size = region.size;\n }\n\n return token;\n }\n\n /**\n * NOT PORTED, and Metal-only in Carbon. `UseConstantBuffer` makes a constant\n * buffer resident on the COMPUTE encoder (`useResource:`,\n * `Tr2RenderContextMetal.mm:1658-1673`) and its only callers build the\n * ray-tracing shader table (`Tr2RtShaderTableALMetal.mm:61-68`). DX12 has no\n * such method. This backend dispatches no compute and has no ray tracing, so\n * there is nothing to make resident.\n */\n\n /** The constant buffer `SetConstants` bound for a uniform binding, by any visible stage. */\n _ConstantBufferFor(binding)\n {\n for (const [ bit, stage ] of [ [ 1, ShaderType.VERTEX_SHADER ], [ 2, ShaderType.PIXEL_SHADER ], [ 4, ShaderType.COMPUTE_SHADER ] ])\n {\n if ((binding.visibility & bit) === 0) continue;\n\n const buffer = this._constantBuffers.get(stage * CONSTANT_BUFFER_REGISTERS + binding.registerIndex) ?? null;\n\n // A buffer of another backend's kind - a stub made before this backend\n // was installed - has no shadow this arena can upload; it is skipped and\n // the slot takes the null buffer, which is DX12's answer to an unbound\n // CBV. Asked by TYPE, which is the question: Carbon has one constant\n // buffer class per compiled backend and cannot be handed another's.\n if (buffer instanceof CjsWebgpuConstantBufferAL && buffer.IsValid()) return buffer;\n }\n\n return null;\n }\n\n /**\n * The emulated-addressing modes buffer: WebGPU has no border or mirror-once\n * address mode, so a translated shader tests them from this buffer\n * (`emulatedAddressing.js`). It is the backend's own, not the effect's, and\n * is filled here, per draw, from the sampler states the resource set binds,\n * so an override that rebinds a sampler is what the shader reads.\n *\n * @param {object|null} set The draw's `CjsWebgpuResourceSetAL`, or null.\n * @param {number} size The binding's size in bytes, a vec4 per sampler register.\n * @returns {object} The constant buffer, filled.\n */\n _AddressModesBuffer(set, size)\n {\n if (!this._addressModes?.IsValid() || this._addressModes.GetSize() < size)\n {\n this._addressModes = new CjsWebgpuConstantBufferAL();\n this._addressModes.Create(size, Tr2ConstantUsageAL.REUSABLE, null, this);\n }\n\n const { data } = this._addressModes.Lock(this);\n const modes = set ? set.GetAddressModes(size / 16) : new Float32Array(size / 4);\n\n data.fill(0);\n data.set(new Uint8Array(modes.buffer, modes.byteOffset, modes.byteLength));\n this._addressModes.Unlock(this);\n\n return this._addressModes;\n }\n\n /** The emulated-addressing modes buffer, made on first need. */\n _addressModes = null;\n\n /** Metal's dummy for a slot no set filled; `storageIndex` picks a storage dummy of its own. */\n _DummyFor(binding, storageIndex = 0)\n {\n if (binding.sampler) return this.GetDummySampler();\n if (binding.texture) return this.GetDummyTexture(binding.texture.viewDimension ?? \"2d\");\n if (binding.storageTexture) return this.GetDummyStorageTexture(binding.storageTexture.format, binding.storageTexture.viewDimension, storageIndex);\n\n return { buffer: this.GetNullBuffer(binding.buffer?.minBindingSize ?? 16, \"STORAGE\") };\n }\n\n /** The dummies, created once each: `MetalContext::m_dummyTexture[]`, `m_dummySampler`. */\n _dummies = { textures: new Map(), storageTextures: new Map(), sampler: null, buffers: new Map(), vertexBuffer: null };\n\n /**\n * A 1x1 texture view of the given dimension, for a slot nothing filled.\n *\n * `MetalContext::GetDummyTexture( MTLTextureType )` (`MetalContext.mm:306-320`):\n * one per texture type, because a sampler of the wrong dimension is a\n * validation error rather than a black texel.\n *\n * @param {string} [viewDimension] A `GPUTextureViewDimension`.\n * @returns {object} A `GPUTextureView`.\n */\n GetDummyTexture(viewDimension = \"2d\")\n {\n const existing = this._dummies.textures.get(viewDimension);\n\n if (existing) return existing;\n\n const usage = this._webgpu.GetTextureUsage();\n const layers = viewDimension === \"cube\" ? 6 : 1;\n const texture = this._webgpu.GetDevice().createTexture({\n label: `Tr2RenderContextAL dummy ${viewDimension}`,\n size: { width: 1, height: 1, depthOrArrayLayers: layers },\n dimension: viewDimension === \"3d\" ? \"3d\" : \"2d\",\n format: \"rgba8unorm\",\n usage: usage.TEXTURE_BINDING | usage.COPY_DST\n });\n const view = texture.createView({ dimension: viewDimension });\n\n this._dummies.textures.set(viewDimension, view);\n\n return view;\n }\n\n /**\n * A 1x1 storage view for a UAV slot nothing filled.\n *\n * D3D binds a null UAV and drops its writes; WebGPU has no null binding and\n * checks the view's format against the layout, so the stand-in is one per\n * format and dimension, written to and never read. And one per `index`:\n * WebGPU refuses two writable bindings of one texture in a dispatch, so a\n * set needing several asks for distinct ones.\n *\n * @param {string} format The binding's `storageTexture.format`.\n * @param {string} viewDimension The binding's `storageTexture.viewDimension`.\n * @param {number} [index] Which of that kind, for a set needing several.\n * @returns {object} A `GPUTextureView`.\n */\n GetDummyStorageTexture(format, viewDimension, index = 0)\n {\n const key = `${format}:${viewDimension}:${index}`;\n const existing = this._dummies.storageTextures.get(key);\n\n if (existing) return existing;\n\n const usage = this._webgpu.GetTextureUsage();\n const texture = this._webgpu.GetDevice().createTexture({\n label: `Tr2RenderContextAL dummy storage ${key}`,\n size: { width: 1, height: 1, depthOrArrayLayers: 1 },\n dimension: viewDimension === \"3d\" ? \"3d\" : \"2d\",\n format,\n usage: usage.STORAGE_BINDING\n });\n const view = texture.createView({ dimension: viewDimension });\n\n this._dummies.storageTextures.set(key, view);\n return view;\n }\n\n /** `MetalContext::GetDummySampler()`: a default sampler for a slot nothing filled. */\n GetDummySampler()\n {\n this._dummies.sampler ??= this._webgpu.GetDevice().createSampler({ label: \"Tr2RenderContextAL dummy sampler\" });\n\n return this._dummies.sampler;\n }\n\n /**\n * A zeroed buffer of at least `size` bytes for a slot nothing filled.\n *\n * DX12's null CB / null SRV substitution, one per size and usage.\n *\n * @param {number} size Bytes the layout demands.\n * @param {\"UNIFORM\"|\"STORAGE\"} usageName The usage flag's name.\n * @returns {object} A `GPUBuffer`.\n */\n GetNullBuffer(size, usageName)\n {\n const aligned = Math.max(16, Math.ceil(size / 16) * 16);\n const key = `${usageName}:${aligned}`;\n const existing = this._dummies.buffers.get(key);\n\n if (existing) return existing;\n\n const usage = this._webgpu.GetBufferUsage();\n const buffer = this._webgpu.GetDevice().createBuffer({\n label: `Tr2RenderContextAL null ${usageName.toLowerCase()} ${aligned}`,\n size: aligned,\n usage: usage[usageName] | usage.COPY_DST\n });\n\n this._dummies.buffers.set(key, buffer);\n\n return buffer;\n }\n\n /**\n * Creates a texture, this backend's kind of `Tr2TextureAL`.\n *\n * @param {object} desc A `Tr2BitmapDimensions`.\n * @param {object} options `{ gpuUsage, cpuUsage, msaa, initialData }`.\n * @returns {object|null} The texture, or null when Create refused.\n */\n CreateTexture(desc, options)\n {\n const texture = new CjsWebgpuTextureAL();\n\n if (Failed(texture.Create(desc, options ?? {}, this))) return null;\n\n return texture;\n }\n\n /**\n * Creates a resource set, this backend's kind of `Tr2ResourceSetAL`.\n *\n * @param {object} description A `Tr2ResourceSetDescriptionAL`.\n * @param {object} program The `CjsWebgpuShaderProgramAL` it binds against.\n * @returns {object|null} The set, or null when Create refused.\n */\n @impl.custom\n @impl.reason(\"JavaScript chooses the AL implementation through this context factory instead of a compile-time platform include. The private allocation branch preserves the native Create result.\")\n CreateResourceSet(description, program, implementationOnly = false)\n {\n // JS platform selection for the public facade; the allocation branch\n // returns the native status code without collapsing it to null.\n if (implementationOnly)\n {\n const implementation = new CjsWebgpuResourceSetAL();\n const result = implementation.Create(description, program, this);\n if (Failed(result)) implementation.Destroy();\n return { result, implementation };\n }\n const resourceSet = new Tr2ResourceSetAL();\n if (Failed(resourceSet.Create(description, program, this))) return null;\n return resourceSet;\n }\n\n /** Records why a draw cannot proceed and says no. */\n _RefusePipeline(reason)\n {\n this.m_pipelineFailure = reason;\n\n return false;\n }\n\n /**\n * Creates the `GPURenderPipeline` a program and recipe describe.\n *\n * A program without a pixel stage is a depth-only pipeline, which WebGPU\n * spells by omitting `fragment` - Carbon's shadow passes are exactly this.\n */\n _CreateRenderPipeline(program, recipe)\n {\n const fragmentModule = program.GetModuleFor(ShaderType.PIXEL_SHADER);\n const descriptor = {\n label: `Tr2RenderContextAL ${program.GetIdentity()}`,\n layout: program.GetPipelineLayout(),\n vertex: {\n module: program.GetModuleFor(ShaderType.VERTEX_SHADER),\n entryPoint: WEBGPU_ENTRY_POINT,\n buffers: recipe.vertex.buffers\n },\n primitive: recipe.primitive,\n ...(recipe.depthStencil ? { depthStencil: recipe.depthStencil } : {}),\n ...(recipe.multisample ? { multisample: recipe.multisample } : {}),\n ...(fragmentModule\n ? {\n fragment: {\n module: fragmentModule,\n entryPoint: WEBGPU_ENTRY_POINT,\n targets: recipe.fragment.targets,\n ...(recipe.fragment.constants ? { constants: recipe.fragment.constants } : {})\n }\n }\n : {})\n };\n\n return this._webgpu.GetDevice().createRenderPipeline(descriptor);\n }\n\n /**\n * Copies the bound attachments' formats onto the description.\n *\n * Deferred to the read rather than done in `SetRenderTarget`, because the\n * canvas format is only known once the target is configured and a target can\n * be bound before that. Carbon has no equivalent hop: a DX12 render-target\n * format is written straight into the description by `SetRenderState`\n * (`Tr2RenderContextDx12.cpp:453`), because a D3D texture knows its format\n * from creation.\n */\n _RefreshAttachmentFormats()\n {\n // THE DESCRIPTION DESCRIBES THE PASS `_Descriptor` OPENS, as Metal's\n // pipeline key reads the formats off the pass descriptor's own textures\n // (`MetalWorkQueue.mm:1681-1698`). With the canvas at slot zero the pass is\n // the canvas's, depth included; otherwise it is the bound textures and the\n // bound depth stencil, each in the format it was CREATED in. A texture's\n // `GetFormat` is Carbon's PixelFormat number, not a GPUTextureFormat, and a\n // UAV texture may have been created in a substitute (`GetDeviceFormat`).\n if (this._IsCanvasPass())\n {\n if (!this._renderTarget)\n {\n this._psoDescription.colorFormats = [];\n this._psoDescription.unormTargets = [];\n this._psoDescription.depthFormat = null;\n this._psoDescription.sampleCount = 1;\n return;\n }\n\n this._psoDescription.colorFormats = [ this._renderTarget.GetFormat() ];\n this._psoDescription.unormTargets = [];\n this._psoDescription.depthFormat = this._renderTarget.GetDepthFormat();\n this._psoDescription.sampleCount = this._renderTarget.GetSampleCount();\n return;\n }\n\n const formats = this._boundRenderTargets.map(target => (target ? target.GetDeviceFormat() : null));\n\n while (formats.length && !formats[formats.length - 1]) formats.pop();\n\n this._psoDescription.colorFormats = formats;\n this._psoDescription.unormTargets = this._boundRenderTargets.map(target => Boolean(target && target.IsUnormSubstitute()));\n this._psoDescription.depthFormat = this._depthStencil ? this._depthStencil.GetDeviceFormat() : null;\n this._psoDescription.sampleCount = 1;\n }\n\n /**\n * Whether the next pass is the canvas's: the canvas render target at slot\n * zero, or nothing bound at all (the canvas stays the pass of last resort,\n * as it was before textures could be targets).\n */\n _IsCanvasPass()\n {\n const primary = this._boundRenderTargets[0] ?? null;\n\n if (primary) return primary === this._renderTarget;\n\n return !this._depthStencil && !this._boundRenderTargets.some(Boolean);\n }\n\n /**\n * Binds a prepared set of textures, samplers and buffers.\n *\n * @param {object} resourceSet A `Tr2ResourceSetAL`.\n * @returns {boolean} True.\n */\n @impl.adapted\n @impl.reason(\"A copied public wrapper retains the shared ownership record while this context binds the WebGPU implementation.\")\n SetResourceSet(resourceSet)\n {\n this._resourceSet = resourceSet ? new Tr2ResourceSetAL({ copy: resourceSet }) : null;\n\n return true;\n }\n\n /**\n * m_constantBuffers[stage][register], as Metal keeps them.\n *\n * A Map keyed by `stage * CONSTANT_BUFFER_REGISTERS + register` rather than a\n * fixed two-dimensional array, because the register count is a device limit\n * here and not a compile-time constant.\n */\n _constantBuffers = new Map();\n\n /**\n * Binds a constant buffer to one shader stage at one register.\n *\n * Carbon rejects a register past the backend's constant-buffer count and\n * otherwise hands the buffer to itself to bind\n * (`Tr2RenderContextMetal.mm:664-677`). The bound state is what the resolver\n * reads when it assembles a draw.\n *\n * @param {object} buffer A `Tr2ConstantBufferAL`.\n * @param {number} constantType A `ShaderType`.\n * @param {number} registerIndex The constant-buffer register.\n * @param {number} [_maxRegisterCount] Carbon's optional bound.\n * @returns {boolean} Whether the AL accepted it.\n */\n SetConstants(buffer, constantType, registerIndex, _maxRegisterCount = 0)\n {\n if (registerIndex < 0 || registerIndex >= CONSTANT_BUFFER_REGISTERS) return false;\n if (constantType < 0 || constantType >= ShaderType.SHADER_TYPE_COUNT) return false;\n\n this._constantBuffers.set(constantType * CONSTANT_BUFFER_REGISTERS + registerIndex, buffer ?? null);\n\n return true;\n }\n\n /**\n * The constant buffer bound to one stage and register.\n *\n * @param {number} constantType A `ShaderType`.\n * @param {number} registerIndex The constant-buffer register.\n * @returns {object|null} The buffer, or null when nothing is bound.\n */\n GetConstants(constantType, registerIndex)\n {\n return this._constantBuffers.get(constantType * CONSTANT_BUFFER_REGISTERS + registerIndex) ?? null;\n }\n\n // ---------------------------------------------------------------------------\n // THE REST OF CARBON'S RENDER-CONTEXT SURFACE.\n //\n // Nothing in Trinity calls these yet - the nine it does call are above - but a\n // backend is only interchangeable if the whole surface answers, and the\n // governing test for this layer is \"swap the backend; nothing in Trinity\n // changes\". Each one either does what WebGPU can do or reports what the stub\n // reports, and says which.\n\n /**\n * Where a debug group was pushed, so its pop reaches the same encoder.\n *\n * WEBGPU REQUIRES THE PAIR TO BALANCE WITHIN ONE ENCODER. A group pushed on\n * the command encoder and popped after a render pass opened would be a\n * validation error, not a mislabelled capture - so the push records its\n * target and the pop uses it rather than asking again.\n */\n _markerStack = [];\n\n /** The encoder debug markers should go to: the open pass, else the frame. */\n _MarkerTarget()\n {\n return this._workQueue.GetRenderPass() ?? this._commandEncoder;\n }\n\n /**\n * Inserts a one-off marker into the capture.\n *\n * Real, unlike the stub's empty body: `insertDebugMarker` is what a WebGPU\n * capture tool shows, and this is the only reason Carbon's markers exist.\n *\n * @param {string} marker The label.\n */\n AddGpuMarker(marker)\n {\n const target = this._MarkerTarget();\n\n if (target) target.insertDebugMarker(String(marker));\n }\n\n /**\n * Opens a named debug group.\n *\n * @param {string} marker The label.\n */\n PushGpuMarker(marker)\n {\n const target = this._MarkerTarget();\n\n this._markerStack.push(target);\n\n if (target) target.pushDebugGroup(String(marker));\n }\n\n /** Closes the innermost debug group, on the encoder that opened it. */\n PopGpuMarker()\n {\n const target = this._markerStack.pop();\n\n if (target) target.popDebugGroup();\n }\n\n /**\n * Marks a point in the frame for a profiler.\n *\n * @param {string} frameEvent The event name.\n */\n MarkFrameEvent(frameEvent)\n {\n this.AddGpuMarker(frameEvent);\n }\n\n /**\n * Tears the device down, dropping every piece of bound state.\n *\n * @returns {boolean} True.\n */\n Destroy()\n {\n this._boundRenderTargets.fill(null);\n this._depthStencil = null;\n for (const stack of this._renderTargetStacks) stack.length = 0;\n this._depthStencilStack.length = 0;\n this._constantBuffers.clear();\n this._renderStates.clear();\n this._markerStack.length = 0;\n this._commandEncoder = null;\n this._frame = null;\n this._ReleasePipelines();\n this._samplerStates.clear();\n this._constantArena?.Destroy();\n this._constantArena = null;\n // Carbon's backends destroy the helper with the context too (DX12's\n // destructor runs `Tr2DrawUPHelper::Destroy`), and its scratch buffers are\n // real device buffers that must not outlive the device they came from.\n this._drawUP.Destroy();\n // Bound state goes too; the description describes nothing bound.\n this._streams = [];\n this._vertexLayout = null;\n this._shaderProgram = null;\n this._psoDescription.shaderProgram = null;\n this._resourceSet = null;\n this._indexBuffer = null;\n this._indexStride = 0;\n this._isValid = false;\n\n return true;\n }\n\n /**\n * Binds the default back buffer at slot zero and clears every other slot.\n *\n * Carbon calls this from `BeginScene` (`Tr2RenderContextMetal.mm:860-864`),\n * which is why a frame there never inherits the previous frame's targets.\n * This backend did not, so bound targets survived across frames and the first\n * pass of a frame drew into whatever the last pass of the previous one had\n * left bound - the same shape as the 2048 shadow-map defect one layer up.\n *\n * @returns {boolean} True.\n */\n ResetRenderTargets()\n {\n this.SetDepthStencil(null);\n this.SetRenderTarget(0, this._renderTarget);\n\n for (let slot = 1; slot < MAX_RENDER_TARGET; slot++) this.SetRenderTarget(slot, null);\n\n return true;\n }\n\n /**\n * Marks this context as the process-wide primary one.\n *\n * Carbon's Metal version also constructs the device-side context and the\n * default back buffer (`Tr2RenderContextMetal.mm:114-124`); ours receive both\n * through the constructor, so what remains is the registration.\n *\n * @returns {boolean} True.\n */\n SetAsPrimary()\n {\n CjsWebgpuRenderContextAL.SetPrimaryRenderContext(this);\n\n return true;\n }\n\n /**\n * The present parameters last applied.\n *\n * CARBON'S MISSPELLING IS KEPT (`Tr2RenderContextMetal.h:230`). It is the\n * name on the abstraction-layer contract, and a backend that spells it\n * correctly is a backend the contract cannot reach.\n *\n * @returns {object|null} The parameters, or null before any were set.\n */\n GetPresentParamaters()\n {\n return this._presentParameters;\n }\n\n /** m_presentParameters */\n _presentParameters = null;\n\n /**\n * Releases what a device reset would invalidate, keeping the context alive.\n *\n * @returns {boolean} True.\n */\n ReleaseDeviceResources()\n {\n this._boundRenderTargets.fill(null);\n this._frame = null;\n this._ReleasePipelines();\n\n return true;\n }\n\n /** Drops every resolved pipeline; the next draw resolves afresh. */\n _ReleasePipelines()\n {\n this._pipelines.clear();\n this._pipeline = null;\n this._pipelineDirty = true;\n this._bindGroups.clear();\n this._dummies = { textures: new Map(), sampler: null, buffers: new Map() };\n // The sampler factory is NOT cleared here: Carbon's lives for the primary\n // context's lifetime, and every seeded pass description still holds the\n // states it handed out - clearing it made an equal description create a\n // second state and report a change it had not made.\n }\n\n /**\n * The back buffer this context presents into.\n *\n * The render target IS this backend's back buffer: it answers `GetWidth` and\n * `GetHeight` exactly as a `Tr2TextureAL` does, which is why it can be bound\n * at slot zero without an adapter.\n *\n * @returns {object|null} The render target, or null before composition.\n */\n GetDefaultBackBuffer()\n {\n return this._renderTarget;\n }\n\n /**\n * The back buffer's pixel format, as a Carbon `PixelFormat`.\n *\n * @returns {number} The format, or `PIXEL_FORMAT_UNKNOWN` before composition\n * or for a canvas format outside the four the spec allows.\n */\n GetBackBufferFormat()\n {\n if (!this._renderTarget) return PixelFormat.PIXEL_FORMAT_UNKNOWN;\n\n return CANVAS_PIXEL_FORMAT[this._renderTarget.GetFormat()] ?? PixelFormat.PIXEL_FORMAT_UNKNOWN;\n }\n\n /**\n * Applies present parameters by resizing the presentation surface.\n *\n * The stub CREATES a back buffer at the requested size; here the canvas\n * already exists and is reconfigured instead, which is the same act against a\n * surface the page owns rather than one the backend allocates.\n *\n * @param {object} presentParameters Carbon's `Tr2PresentParametersAL`.\n * @returns {number} An `ALResult` value.\n */\n SetPresentParameters(presentParameters)\n {\n if (!presentParameters || !presentParameters.mode) return ALResult.E_INVALIDARG;\n if (!this._renderTarget) return ALResult.E_INVALIDCALL;\n\n const { width, height } = presentParameters.mode;\n\n this._renderTarget.Configure({ width, height });\n this._presentParameters = presentParameters;\n\n return ALResult.S_OK;\n }\n\n /**\n * Whether textures can be reached without a binding.\n *\n * @returns {boolean} False. WebGPU has no bindless path at all: every\n * resource is reached through a bind group.\n */\n SupportsBindlessTextures()\n {\n return false;\n }\n\n /**\n * How much video memory the adapter has.\n *\n * @returns {number} Zero, as the stub reports. WebGPU deliberately exposes no\n * memory size - it is a fingerprinting surface - so this is not a gap that\n * a later browser fills in.\n */\n GetTotalVideoMemory()\n {\n return 0;\n }\n\n /** m_readOnlyDepth - Metal keeps this and folds it into ZWRITEENABLE. */\n _readOnlyDepth = false;\n\n /**\n * Whether depth is bound read-only.\n *\n * @returns {boolean} The flag.\n */\n GetReadOnlyDepth()\n {\n return this._readOnlyDepth;\n }\n\n /**\n * Binds depth read-only, so it can be sampled while still testing.\n *\n * TURNING IT ON REFRESHES THE BOUND DEPTH'S FLOAT SHADOW. Carbon enables it\n * exactly where a pass is about to read the depth it has written with the\n * depth still bound: SSAO, the light lists, the lens-flare queries\n * (EveSpaceSceneRenderDriver.cpp:365, 543, 589). Shaders here read the\n * r32float shadow (`CjsWebgpuTextureAL._depthShadow`), which otherwise\n * refreshes only when the depth is unbound (`SetDepthStencil`), so without\n * this they read the previous frame's depth. The copy ends the open pass.\n *\n * The flag itself is STORED, NOT YET APPLIED. WebGPU expresses it as\n * `depthReadOnly` on the render-pass descriptor, which `_Descriptor`\n * builds; wiring it there is a pass-descriptor change rather than a state\n * one, and the flag has to exist before it can be read.\n *\n * @param {boolean} enable Whether depth is read-only.\n */\n SetReadOnlyDepth(enable)\n {\n if (enable && !this._readOnlyDepth && this._depthStencil) this._Record(this._workQueue.CopyDepthShadow(this._depthStencil));\n\n this._readOnlyDepth = !!enable;\n }\n\n /**\n * Copies a byte range between two buffers.\n *\n * Real when a frame is open: `copyBufferToBuffer` is a command-encoder verb,\n * so it needs the encoder `BeginScene` created and nothing else.\n *\n * @param {object} destination The destination `Tr2BufferAL`.\n * @param {number} destinationOffset Byte offset into it.\n * @param {object} source The source `Tr2BufferAL`.\n * @param {number} sourceOffset Byte offset into it.\n * @param {number} size Bytes to copy.\n * @returns {boolean} Whether the copy was encoded.\n */\n CopySubBuffer(destination, destinationOffset, source, sourceOffset, size)\n {\n if (!this._commandEncoder) return false;\n if (!destination || !source || !destination.IsValid() || !source.IsValid()) return false;\n if (size <= 0) return false;\n\n this._commandEncoder.copyBufferToBuffer(\n source.GetDeviceBuffer(),\n sourceOffset,\n destination.GetDeviceBuffer(),\n destinationOffset,\n size\n );\n\n return true;\n }\n\n /**\n * Draws indirectly, reading the draw arguments from a buffer.\n *\n * REFUSES, as the stub does. WebGPU has `drawIndirect`, but the work queue\n * owns every draw and has no indirect verb; adding one here would put a\n * second draw path beside the queue's, which is the split this backend is\n * built around.\n *\n * @returns {boolean} False.\n */\n DrawInstancedIndirect()\n {\n return false;\n }\n\n /**\n * Draws indexed indirectly.\n *\n * @returns {boolean} False; see `DrawInstancedIndirect`.\n */\n DrawIndexedInstancedIndirect()\n {\n return false;\n }\n\n /**\n * Declares that a batch of resources is about to be used.\n *\n * @param {object} _destination Where they are used.\n * @param {number} _usage How they are used.\n * @param {object[]} _resources The resources.\n * @returns {boolean} True. This is a residency and barrier hint for backends\n * that place their own memory; WebGPU tracks both itself, so honouring it\n * is nothing rather than unimplemented.\n */\n UseResources(_destination, _usage, _resources)\n {\n return true;\n }\n\n /**\n * Declares a ray-tracing acceleration structure in use.\n *\n * @param {object} _tlas The top-level structure.\n * @returns {boolean} True, as the stub reports.\n */\n UseAccelerationStructure(_tlas)\n {\n return true;\n }\n\n /**\n * Dispatches rays.\n *\n * @returns {boolean} False; WebGPU has no ray-tracing pipeline.\n */\n DispatchRays()\n {\n return false;\n }\n\n /**\n * Whether the device recorded a GPU state marker after a fault.\n *\n * @returns {boolean} False; WebGPU surfaces device loss as a promise and a\n * reason string, with no marker or breadcrumb to read.\n */\n GetGpuStateMarker()\n {\n return false;\n }\n\n /**\n * The resource a GPU page fault named.\n *\n * @returns {boolean} False; see `GetGpuStateMarker`.\n */\n GetGpuPageFaultResource()\n {\n return false;\n }\n\n // THE UPSCALING FAMILY. Every answer is the stub's, and the stub's are\n // Carbon's: the family is live only in the DX backends. WebGPU has no\n // upscaler to reach, so these are complete rather than pending.\n\n /**\n * Enables upscaling.\n *\n * @returns {number} `UpscalingResult.OK` - Carbon's stub succeeds WITHOUT\n * creating anything, so a caller that then asks for a context gets null.\n * That pairing is Carbon's and both halves are kept.\n */\n EnableUpscaling()\n {\n return UpscalingResult.OK;\n }\n\n /**\n * An existing upscaling context.\n *\n * @returns {null} Null; none is kept.\n */\n GetUpscalingContext()\n {\n return null;\n }\n\n /**\n * Creates an upscaling context.\n *\n * @returns {null} Null; none is created.\n */\n CreateUpscalingContext()\n {\n return null;\n }\n\n /** Destroys an upscaling context; there are none. */\n DeleteUpscalingContext()\n {\n }\n\n /**\n * What an upscaling context is doing.\n *\n * @returns {object} A default `UpscalingInfo`; two of its values are not zero.\n */\n GetUpscalingInfo()\n {\n return {\n displayWidth: 0,\n displayHeight: 0,\n renderWidth: 0,\n renderHeight: 0,\n technique: UpscalingTechnique.NONE,\n setting: UpscalingSetting.NATIVE,\n frameGeneration: false,\n temporal: false,\n hasSharpening: false,\n upscalingAmount: 1,\n jitterX: 0,\n jitterY: 0,\n mipLevelBias: 0\n };\n }\n\n /**\n * The techniques an adapter supports.\n *\n * @returns {Array} Empty.\n */\n GetSupportedUpscalingTechniques()\n {\n return [];\n }\n\n /**\n * The upscaling currently set up.\n *\n * @returns {object} \"No upscaling\", in the four fields Carbon fills.\n */\n GetUpscalingSetup()\n {\n return {\n technique: UpscalingTechnique.NONE,\n setting: UpscalingSetting.NATIVE,\n frameGeneration: false,\n temporal: false\n };\n }\n\n // THE PRIMARY RENDER CONTEXT. Carbon keeps one per process as a static and\n // reaches it from resource creation; these are the same three accessors the\n // stub carries, over the same module-level binding.\n\n /**\n * Records the primary render context.\n *\n * @param {object} renderContext The context to make primary.\n */\n static SetPrimaryRenderContext(renderContext)\n {\n primaryRenderContext = renderContext;\n }\n\n /**\n * The primary render context, which must exist.\n *\n * @returns {object} The primary context.\n */\n static GetPrimaryRenderContext()\n {\n if (primaryRenderContext === null) fail(\"there is no primary render context\");\n\n return primaryRenderContext;\n }\n\n /**\n * The primary render context, or null.\n *\n * @returns {object|null} The primary context.\n */\n static GetPrimaryRenderContextPointer()\n {\n return primaryRenderContext;\n }\n\n /**\n * Draws the bound geometry, indexed.\n *\n * REFUSES WITHOUT AN INDEX BUFFER, as Metal does - `E_INVALIDARG` at\n * `Tr2RenderContextMetal.mm:419-422`. An indexed draw with nothing to index\n * is a caller error a backend can catch without a device.\n *\n * @param {number} indexCountPerInstance Indices each instance reads.\n * @param {number} instanceCount Instances to draw.\n * @param {number} startIndexLocation First index.\n * @param {number} baseVertexLocation Value added to every index.\n * @param {number} startInstanceLocation First instance id.\n * @returns {boolean} Whether the draw was recorded.\n */\n DrawIndexedInstanced(\n indexCountPerInstance,\n instanceCount,\n startIndexLocation = 0,\n baseVertexLocation = 0,\n startInstanceLocation = 0\n )\n {\n if (!this._indexBuffer) return false;\n if (!this._shaderProgram) return false;\n\n // Metal (`MetalWorkQueue.mm:2922-2944`): `GetRenderEncoder()` FIRST, then\n // `if( EmitRenderEncoderState() ) { [renderEncoder drawIndexed...] }`. The\n // pass opens whether or not the draw can proceed. DX12 is\n // `CR_RETURN_HR( SetAllState() )` at the top of the verb.\n this._Record(this._workQueue.GetRenderEncoder());\n\n if (!this.EmitRenderEncoderState(true)) return false;\n\n this._Record(this._workQueue.DrawIndexedPrimitives(\n indexCountPerInstance,\n instanceCount,\n startIndexLocation,\n baseVertexLocation,\n startInstanceLocation\n ));\n this._drawnBatchCount += 1;\n\n return true;\n }\n\n /**\n * Draws the bound geometry, non-indexed.\n *\n * @param {number} vertexCountPerInstance Vertices each instance reads.\n * @param {number} instanceCount Instances to draw.\n * @param {number} startVertexLocation First vertex.\n * @param {number} startInstanceLocation First instance id.\n * @returns {boolean} Whether the draw was recorded.\n */\n DrawInstanced(vertexCountPerInstance, instanceCount, startVertexLocation = 0, startInstanceLocation = 0)\n {\n if (!this._shaderProgram) return false;\n\n this._Record(this._workQueue.GetRenderEncoder());\n\n if (!this.EmitRenderEncoderState(false)) return false;\n\n this._Record(this._workQueue.DrawPrimitives(\n vertexCountPerInstance,\n instanceCount,\n startVertexLocation,\n startInstanceLocation\n ));\n this._drawnBatchCount += 1;\n\n return true;\n }\n\n /**\n * Draws a primitive COUNT, converting it to vertices first.\n *\n * @param {number} numVertices Vertices the index range spans.\n * @param {number} startIndex First index.\n * @param {number} primitiveCount Primitives to draw.\n * @param {number} [minimumIndex] Lowest index present.\n * @returns {boolean} Whether the draw was recorded.\n */\n DrawIndexedPrimitive(numVertices, startIndex, primitiveCount, minimumIndex = 0)\n {\n return this.DrawIndexedInstanced(this.ComputeVertexCount(primitiveCount), 1, startIndex, minimumIndex, 0);\n }\n\n /**\n * Draws a primitive count, non-indexed.\n *\n * @param {number} startVertex First vertex.\n * @param {number} primitiveCount Primitives to draw.\n * @returns {boolean} Whether the draw was recorded.\n */\n DrawPrimitive(startVertex, primitiveCount)\n {\n return this.DrawInstanced(this.ComputeVertexCount(primitiveCount), 1, startVertex, 0);\n }\n\n /**\n * Draws non-indexed straight from caller memory, with no buffer bound.\n *\n * Carbon does not draw this itself either: every backend hands it to\n * `Tr2DrawUPHelper` (Metal at `Tr2RenderContextMetal.mm:558-571`, DX12 at\n * `Tr2RenderContextDx12.cpp:1219-1224`), which stages the caller's vertices\n * into a ring of scratch buffers and issues an ordinary draw. WebGPU cannot\n * read caller memory either - every vertex must reach a `GPUBuffer` first -\n * so the helper IS the implementation rather than a detail of it, and the\n * port is shared rather than written again here.\n *\n * @param {number} primitiveCount Primitives to draw.\n * @param {ArrayBufferView} vertexStreamZeroData The vertices.\n * @param {number} vertexStreamZeroStride Bytes per vertex.\n * @returns {boolean} Whether the draw was encoded.\n */\n DrawPrimitiveUP(primitiveCount, vertexStreamZeroData, vertexStreamZeroStride)\n {\n return !Failed(this._drawUP.DrawPrimitiveUP(\n this._topology,\n primitiveCount,\n vertexStreamZeroData,\n vertexStreamZeroStride,\n this\n ));\n }\n\n /**\n * Draws indexed straight from caller memory.\n *\n * The same helper, staging indices as well as vertices. Carbon has an\n * overload per index width; the width is read off the array here instead.\n *\n * @param {number} numVertices Vertices the index data spans.\n * @param {number} primitiveCount Primitives to draw.\n * @param {Uint16Array|Uint32Array} indexData The indices.\n * @param {ArrayBufferView} vertexStreamZeroData The vertices.\n * @param {number} vertexStreamZeroStride Bytes per vertex.\n * @returns {boolean} Whether the draw was encoded.\n */\n DrawIndexedPrimitiveUP(numVertices, primitiveCount, indexData, vertexStreamZeroData, vertexStreamZeroStride)\n {\n return !Failed(this._drawUP.DrawIndexedPrimitiveUP(\n this._topology,\n numVertices,\n primitiveCount,\n indexData,\n vertexStreamZeroData,\n vertexStreamZeroStride,\n this\n ));\n }\n\n /**\n * How many vertices a primitive count describes at the bound topology.\n *\n * @param {number} primitiveCount Primitives.\n * @returns {number} Vertices.\n */\n ComputeVertexCount(primitiveCount)\n {\n return VERTICES_PER_PRIMITIVE[this._topology](primitiveCount);\n }\n\n /**\n * What a following draw would bind, for a caller that must encode it.\n *\n * @returns {object} A copy of the bound state.\n */\n GetBoundState()\n {\n return {\n topology: this._topology,\n indexBuffer: this._indexBuffer,\n indexStride: this._indexStride,\n streams: this._streams.map(stream => (stream ? { ...stream } : stream)),\n vertexLayout: this._vertexLayout,\n shaderProgram: this._shaderProgram,\n resourceSet: this._resourceSet\n };\n }\n\n /**\n * Keeps the work queue's reported encoder transitions for the tests to read.\n *\n * @param {object[]} [events] The events, if any were reported.\n */\n _Record(events)\n {\n if (events?.length) this._transitions.push(...events);\n }\n}\n\n// DECLARED AS A CALL, NOT A DECORATOR, for the reason recorded in\n// Tr2BitmapDimensions.js: the layer is imported straight from source by its\n// tests and raw Node cannot parse decorator syntax.\n//\n// The donor is NAMED rather than left to be derived from this class's name.\n// Carbon calls every backend's class the same thing and carries the backend in\n// the FILE name, because only one backend compiles at a time; we ship them\n// together, so the backend moves onto the class name. That divergence is the\n// author's to declare, never a checker's to guess.\nCjsSchema.define(CjsWebgpuRenderContextAL, { className: \"CjsWebgpuRenderContextAL\", carbon: \"Tr2RenderContextAL\" });\n"],"names":["INDEX_FORMAT","Object","freeze","MAX_CACHED_BIND_GROUPS","DeviceBufferOf","bound","GetDeviceBuffer","gpuColor","value","r","g","b","a","length","fail","message","error","Error","code","VERTICES_PER_PRIMITIVE","Topology","TOP_TRIANGLES","count","TOP_TRIANGLE_STRIP","TOP_TRIANGLE_FAN","TOP_LINES","TOP_LINE_STRIP","TOP_POINTS","MAX_RENDER_TARGET","DUMMY_VERTEX_FORMAT","FLOAT","INT","UINT","CANVAS_PIXEL_FORMAT","PixelFormat","PIXEL_FORMAT_B8G8R8A8_UNORM","PIXEL_FORMAT_B8G8R8A8_UNORM_SRGB","PIXEL_FORMAT_R8G8B8A8_UNORM","PIXEL_FORMAT_R8G8B8A8_UNORM_SRGB","primaryRenderContext","CONSTANT_BUFFER_REGISTERS","CjsWebgpuRenderContextAL","_initProto","_applyDecs","impl","custom","reason","adapted","e","SHADER_TYPE_MASK","ShaderType","VERTEX_SHADER","PIXEL_SHADER","COMPUTE_SHADER","_workQueue","CjsWebgpuWorkQueue","_isValid","_topology","_indexBuffer","_indexStride","_streams","_vertexLayout","_shaderProgram","_resourceSet","_renderStateSetup","_renderStateOverrides","_pipelineDirty","_drawUP","Tr2DrawUPHelper","_psoDescription","CjsWebgpuPsoDescription","_boundRenderTargets","Array","fill","_renderTargetStacks","from","_depthStencil","_depthStencilStack","_viewport","_transitions","_webgpu","_renderTarget","m_utils","CjsWebgpuUtils","_commandEncoder","_frame","constructor","webgpu","renderTarget","topology","IsComposed","GetWebgpu","CreateBuffer","description","initialData","buffer","CjsWebgpuBufferAL","Failed","Create","CreateVertexLayout","definition","layout","Tr2VertexLayoutALStub","CreateConstantBuffer","size","usage","Tr2ConstantUsageAL","REUSABLE","CjsWebgpuConstantBufferAL","_samplerStates","Map","CreateSamplerState","key","SamplerDescriptionKey","existing","get","state","CjsWebgpuSamplerStateAL","set","CreateShader","stageType","bytecode","signature","shaderPath","shader","CjsWebgpuShaderAL","CreateShaderProgram","shaders","program","CjsWebgpuShaderProgramAL","GetDrawnBatchCount","_drawnBatchCount","GetWorkQueue","_caps","GetCaps","CjsWebgpuCapsAL","_frameNumber","GetRecordingFrameNumber","GetRenderedFrameNumber","DrainTransitions","transitions","CreateDevice","IsValid","BeginScene","GetDevice","createCommandEncoder","label","SetCommandEncoder","attachments","_Descriptor","_Record","BeginFrame","_constantArena","Reset","ResetRenderTargets","_IsCanvasPass","_TextureDescriptor","AcquireFrame","clear","colors","CreateRenderPassDescriptor","GetPassCount","clearColor","loadOp","clearValue","undefined","clearDepth","depth","GetAttachments","hinted","next","colorAttachments","map","color","hint","view","texture","GetDeviceRenderTargetView","slice","storeOp","pop","descriptor","stencil","GetDeviceFormat","includes","depthStencilAttachment","depthLoadOp","depthStoreOp","depthClearValue","stencilLoadOp","stencilStoreOp","stencilClearValue","EndScene","EndFrame","shaderProgram","Submit","finish","RenderPassHint","EndRenderPassHint","SetRenderTarget","slot","SetRenderAttachments","primary","SetViewport","x","y","width","GetWidth","height","GetHeight","GetRenderTarget","PushRenderTarget","push","PopRenderTarget","stack","GetStackSizeRT","SetDepthStencil","depthStencil","previous","SetDepthAttachment","CopyDepthShadow","GetDepthStencil","PushDepthStencil","PopDepthStencil","GetStackSizeDS","GetRenderTargetSize","target","result","ALResult","E_INVALIDCALL","S_OK","viewport","minZ","maxZ","GetViewport","Clear","options","flagged","clearTarget","clearStencil","forEach","attachment","index","Tr2ColorAttachment","Tr2LoadAction","CLEAR","Tr2StoreAction","STORE","LOAD","Tr2DepthAttachment","Number","ClearAttachment","RunComputeShader","z","module","GetModuleFor","_RefusePipeline","pipeline","_computePipelines","createComputePipeline","GetIdentity","GetPipelineLayout","compute","entryPoint","WEBGPU_ENTRY_POINT","_EmitBindGroups","SetComputePipeline","DispatchThreadgroups","WeakMap","_mipGenerator","GetMipGenerator","CjsWebgpuMipGenerator","RunComputeShaderIndirect","_effect","_indirectionBuffer","_offsetForArgs","ClearUav","resource","_clearWithFloat","is","ClearBuffer","Present","SetTopology","TOP_MAX_TOPOLOGY","SetVertexLayout","SetStreamSource","stream","offset","stride","SetIndices","SetShaderProgram","SetRenderStates","setup","overrides","CanonicalKey","renderStateSetup","renderStateOverrides","_renderStates","SetRenderState","RenderState","RS_DEPTH_CLIP_ENABLE","unclippedDepth","features","has","GetRenderStateInputs","states","IsPipelineDirty","GetPsoDescription","_RefreshAttachmentFormats","_pipeline","_pipelines","m_pipelineFailure","EmitRenderPipelineState","SetRenderPipeline","vertexBufferLayouts","BuildVertexBufferLayouts","missing","GetMissing","TOPOLOGIES","stripIndexFormat","endsWith","recipe","GetKey","BuildRecipe","primitive","created","_CreateRenderPipeline","type","EmitRenderEncoderState","indexed","layouts","_dummyVertexStream","SetVertexBuffer","_DummyVertexBuffer","format","SetIndexBuffer","elements","GetDefinition","inputs","GetInputs","plan","resolveBindingPlan","byStream","entries","filter","entry","element","Math","max","keys","WebgpuVertexBufferLayout","arrayStride","stepMode","attributes","shaderLocation","registerIndex","fallbackType","sort","GetBufferUsage","_dummies","vertexBuffer","createBuffer","VERTEX","COPY_DST","_bindGroups","GetBindGroupLayouts","m_resourceSet","implementation","GetProgram","GetEntries","setId","m_id","bindings","GetBindings","device","group","keyParts","resolved","dynamicOffsets","storageDummies","binding","minBindingSize","constantBuffer","generatedSymbol","CARBON_BACKEND_ADDRESS_MODES_SYMBOL","_AddressModesBuffer","_ConstantBufferFor","region","UploadConstants","_Arena","GetPage","page","GetNullBuffer","_DummyFor","storageTexture","join","bindGroup","createBindGroup","SetBindGroup","CjsWebgpuConstantArena","source","arena","ArrayBuffer","isView","Allocate","byteLength","token","m_token","wanted","m_shadowCopy","frame","bit","stage","visibility","_constantBuffers","_addressModes","GetSize","data","Lock","modes","GetAddressModes","Float32Array","Uint8Array","byteOffset","Unlock","storageIndex","sampler","GetDummySampler","GetDummyTexture","viewDimension","GetDummyStorageTexture","textures","storageTextures","buffers","GetTextureUsage","layers","createTexture","depthOrArrayLayers","dimension","TEXTURE_BINDING","createView","STORAGE_BINDING","createSampler","usageName","aligned","ceil","toLowerCase","CreateTexture","desc","CjsWebgpuTextureAL","CreateResourceSet","implementationOnly","CjsWebgpuResourceSetAL","Destroy","resourceSet","Tr2ResourceSetAL","fragmentModule","vertex","multisample","fragment","targets","constants","createRenderPipeline","colorFormats","unormTargets","depthFormat","sampleCount","GetFormat","GetDepthFormat","GetSampleCount","formats","Boolean","IsUnormSubstitute","some","SetResourceSet","copy","SetConstants","constantType","_maxRegisterCount","SHADER_TYPE_COUNT","GetConstants","_markerStack","_MarkerTarget","GetRenderPass","AddGpuMarker","marker","insertDebugMarker","String","PushGpuMarker","pushDebugGroup","PopGpuMarker","popDebugGroup","MarkFrameEvent","frameEvent","_ReleasePipelines","SetAsPrimary","SetPrimaryRenderContext","GetPresentParamaters","_presentParameters","ReleaseDeviceResources","GetDefaultBackBuffer","GetBackBufferFormat","PIXEL_FORMAT_UNKNOWN","SetPresentParameters","presentParameters","mode","E_INVALIDARG","Configure","SupportsBindlessTextures","GetTotalVideoMemory","_readOnlyDepth","GetReadOnlyDepth","SetReadOnlyDepth","enable","CopySubBuffer","destination","destinationOffset","sourceOffset","copyBufferToBuffer","DrawInstancedIndirect","DrawIndexedInstancedIndirect","UseResources","_destination","_usage","_resources","UseAccelerationStructure","_tlas","DispatchRays","GetGpuStateMarker","GetGpuPageFaultResource","EnableUpscaling","UpscalingResult","OK","GetUpscalingContext","CreateUpscalingContext","DeleteUpscalingContext","GetUpscalingInfo","displayWidth","displayHeight","renderWidth","renderHeight","technique","UpscalingTechnique","NONE","setting","UpscalingSetting","NATIVE","frameGeneration","temporal","hasSharpening","upscalingAmount","jitterX","jitterY","mipLevelBias","GetSupportedUpscalingTechniques","GetUpscalingSetup","renderContext","GetPrimaryRenderContext","GetPrimaryRenderContextPointer","DrawIndexedInstanced","indexCountPerInstance","instanceCount","startIndexLocation","baseVertexLocation","startInstanceLocation","GetRenderEncoder","DrawIndexedPrimitives","DrawInstanced","vertexCountPerInstance","startVertexLocation","DrawPrimitives","DrawIndexedPrimitive","numVertices","startIndex","primitiveCount","minimumIndex","ComputeVertexCount","DrawPrimitive","startVertex","DrawPrimitiveUP","vertexStreamZeroData","vertexStreamZeroStride","DrawIndexedPrimitiveUP","indexData","GetBoundState","indexBuffer","indexStride","streams","vertexLayout","events","CjsSchema","define","className","carbon"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAgGA;AACA,MAAMA,YAAY,GAAGC,MAAM,CAACC,MAAM,CAAC;AAAE,EAAA,CAAC,EAAE,QAAQ;AAAE,EAAA,CAAC,EAAE;AAAS,CAAC,CAAC;;AAEhE;AACA,MAAMC,sBAAsB,GAAG,IAAI;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,cAAcA,CAACC,KAAK,EAC7B;AACE,EAAA,OAAOA,KAAK,IAAI,OAAOA,KAAK,CAACC,eAAe,KAAK,UAAU,GAAGD,KAAK,CAACC,eAAe,EAAE,GAAG,IAAI;AAC9F;;AAGA;AACA;AACA;AACA;AACA;AACA,SAASC,QAAQA,CAACC,KAAK,EACvB;AACE,EAAA,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAC7B;IACE,OAAO;MACLC,CAAC,EAAE,CAAED,KAAK,KAAK,EAAE,GAAI,IAAI,IAAI,GAAG;MAChCE,CAAC,EAAE,CAAEF,KAAK,KAAK,CAAC,GAAI,IAAI,IAAI,GAAG;AAC/BG,MAAAA,CAAC,EAAE,CAACH,KAAK,GAAG,IAAI,IAAI,GAAG;AACvBI,MAAAA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