The native WebGPU adapter rejects or misinterprets standard inputs used by a TypeGPU consumer: GPU flag globals are absent, omitted entry points become "main", and buffer source ranges are ignored. This fills those gaps and adds native texture readback and reusable render-bundle recording/execution.
System
The changes stay at the JavaScript WebGPU adapter boundary. Helpers normalize buffer ranges, texture extents, and callback ABI selection; Dawn records and executes bundles through the existing native FFI exports. The diagram's adapter-to-Dawn boundary also carries bundle commands. Electrobun gains no TypeGPU or Glyph dependency.
Change
| Element | Change | Why |
|---|---|---|
| Upload and pipeline inputs | Install GPU flag globals; honor writeBuffer ranges and tuple extents; preserve omitted entry points for Dawn inference. | Accept standard consumer inputs without app-side patches. |
| Mapping and completion | Expose mapState, use const read mappings, correct callback userdata positions, and add copyTextureToBuffer. | Retrieve native GPU results and settle the intended callback. |
| Render bundles | Add createRenderBundleEncoder, binding commands, direct/indexed/indirect draws, debug markers, finish, and nonempty executeBundles. | Record once and replay compatible draw commands across render passes. |
| Native handle ownership | Finalize abandoned encoders/bundles; unregister on explicit release or finish; release encoders even when finish fails. | Standard consumers get automatic cleanup, with optional deterministic release(). |
| FFI declarations | Correct the four bundle string-call signatures and their generator for indirect Windows x64 versus two-word ARM64/SysV arguments. | Pass labels and debug strings by the native WGPUStringView ABI. |
Blast radius
Measured against origin/main: 12 files, with three direct import dependents outside the diff: entries/webgpu.ts, the main SDK entry, and Warren's built-in renderer. Existing upload arguments remain valid. Omitted entry points now reach Dawn's inference path; shaders with multiple eligible entry points must name one.
Verify
- From
package:node node_modules/typescript/bin/tsc --noEmit: passed. - Pinned Hutch Bun runner, eight focused test files: 24 passed, 0 failed. The isolated bundle fixture checks descriptor layout, dynamic-offset packing/slicing, ordered replay, all four draw commands, and explicit/finalizer cleanup. Exact command below.
- macOS ARM64, actual Cottontail 0.7.2 and packaged Electrobun 2.0.4 Dawn: TypeGPU 0.12.8 records direct, indexed, indirect, and indexed-indirect bundles. Each is reused across two submissions; all eight readbacks contain the expected 16 red pixels. Includes nonzero index-buffer offset, empty execution followed by real bundles, and debug groups/markers.
- Real C→Cottontail callback fixture on macOS ARM64; cross-target clang output distinguishes Windows ARM64 aggregate registers from Windows x64 indirection. The ABI helper covers six platform/architecture combinations.
- Repeat native consumer validation on Windows and Linux, including map/queue completion callbacks.
Risks
- Bundle replay resets pipeline/bind-group/vertex/index bindings, even for an empty iterable. Subsequent direct draws must rebind state; the docs call this out.
- Garbage collection has nondeterministic timing. Applications that recreate recordings frequently can use
release()for prompt native cleanup. - Windows x64 string arguments are indirect; ARM64/SysV use two words. Native Windows/Linux execution remains unchecked.
- The adapter retains its pre-existing
@ts-nocheck; the range, extent, and ABI helpers are independently typechecked.
Evidence
The native bundle probe at bc0554061140a3e0b8347a45c9b36c15fdc8e1dd verified eight submissions and 128 exact RGBA pixels across the four draw paths. The independent adversarial re-review found no remaining P1/P2 blockers after the ownership and ABI changes.
The earlier combined prototype also exercised Glyph text updates/clipping/removal and queue completion. That historical evidence is separate from the current branch's bundle/readback check above.
Unknowns
- Windows/Linux native execution, MSAA/depth bundle rendering, and full WebGPU conformance remain unverified. The standalone TypeGPU native probe is local; the committed isolated fixture uses mocked FFI calls.
- TypeGPU's experimental immediate variables still require feature/limit negotiation that this adapter does not expose. The docs state that existing limitation; this PR adds ordinary render-bundle commands.
- Existing reports #542, #543, and #544 describe the global flags, map state, and entry-point gaps. They are referenced without auto-closing them.
Agent context
You are reviewing blackboardsh/electrobun PR #585: https://github.com/blackboardsh/electrobun/pull/585.
Problem and plan: complete the native adapter inputs, readback paths, and ordinary render-bundle recording/replay used by an external TypeGPU consumer.
Task: review the change against these measured facts and the platform limitations above.
Facts were collected at the commits below; check each against source before relying on it.
{
"base": "c54c0c14876455d43a25af0f9cd41a4b14e21854",
"head": "bc0554061140a3e0b8347a45c9b36c15fdc8e1dd",
"summary": {
"filesChanged": 12,
"insertions": 707,
"deletions": 28,
"byKind": {
"docs": 1,
"source": 7,
"test": 4
},
"elementsChanged": 2,
"directDependents": 3,
"exportedSignatureChanges": 3
},
"caveats": [
"dependents are files whose imports resolve to a changed file; calls through dependency injection, reflection, string paths or generated code are not seen",
"edge status (added/removed) compares only the imports of files in this diff against base, resolved against the head file list",
"transitive dependents are followed 3 import hops; a file that imports a re-exporting module counts even when it uses other names from it",
"no CODEOWNERS file; owners are empty"
]
}
Architecture: package and docs are directory fallbacks, not a saved system architecture map. The existing diagram still describes the unchanged adapter-to-native relationship; it predates the additional bundle commands.
Commands run
From package: node node_modules/typescript/bin/tsc --noEmit
HUTCH_HOME=/absolute/agent-deck/.tools/hutch HUTCH_BINARY=/absolute/agent-deck/.tools/hutch/bin/hutch node scripts/run-bun-test.js src/sdks/main/webgpuRenderBundle.test.ts src/sdks/main/webgpuBufferSource.test.ts src/sdks/main/webgpuExtent.test.ts src/sdks/main/webgpuCallback.test.ts src/sdks/main/webgpuRenderPass.test.ts src/sdks/main/webgpuContextKey.test.ts src/sdks/main/webgpuContextRegistry.test.ts src/sdks/main/webgpuPresentationState.test.ts
24 pass; 0 fail. The child fixture contains additional node:assert contract checks.
Native TypeGPU 0.12.8/unplugin-typegpu 0.12.6/esbuild 0.28.2 probe; Cottontail 0.7.2, Electrobun 2.0.4 native runtime; adapter head named above.
Four bundle recordings, each replayed twice: all eight 4x4 GPU readbacks equal red RGBA pixels.
Window/core imports were substituted with an offscreen shim forwarding device/readback operations to the packaged native WGPUBridge functions. No window presentation check or runtime rebuild claimed.
Earlier native callback fixture and cross-target ABI check remain applicable; no callback code changed in this commit.
Full impact facts, lossless gzip+base64
Decoded SHA-256: fe99d2724e68de373efc326afa96a351f6f2298bc833861a7d497250656dacf5
Decode base64 then gunzip to obtain JSON.
BEGIN_GZIP_BASE64_FACTS
H4sIAAAAAAAC/+1d7VPbutL/3r9Ck09hBgIJ4aVwTzu8tZfn0NIHeso8QxlGsZVEB9vylWRCTi//+yPJb3JshyRNYmPSDyWWLXn129VqtV6tfr0DoMaMPrJh
7QA01+VlBzIkLmrGTtvYMprt/b3d9s6O2d6GrR3Y3eq+N8x2E7Y7zTZqNfd32jVV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YbUoS9w1OScdzNh4w
N/raZ8lob9O4Z9QeOz83ARdI6ulVODL6DrFIbygfuPIYBwaVs0ZOF+J8Whm7SWzo4C7Scy/IkHa11WkvznLGxKzksRxlpyrEG6e2MnYUHQnlYPgbsrYyBXAU
tHFglQmk1rIhoqInG12LGA8bAzG00jjlPlACiVo+WoTwNER1WbyWhYztEiexp3+KfvdwVpeby+6yIKPvddKdbozeqFSv2QO2LJbR69Ebi+z1sjttEiOjy8nS
BfZ3P6vDL3W3OXt3HddO9zZRuEjmtpfN3ZRVFHY5bS4trttt7TzJKZj8Apd3x41kdZhQhlynbiyw25m9Xii3ObJl5g+U0fGMW4vsemtvgX2P7Wezh8Zsohtr
GpM8e3CgNtNPrornlaxgcqpTYzcieacYkpP68wUaW8XQmLE+fAntoiUhh+SMoVw0pfnrhdIOs/RMQFKiXLTM5tCYP7Z2i6Eza3IpWAtEc4RcqVJoaInDatL7
pOW3MKLp5/bdBJvkx7tRZ3MezuIye9lhHu4KD2omNsb7O9Cx04sn39t4f7pBTkLP1m0yMYiBkYakNB0s9IT5MC4jAwdR/Rn4iKDm49KmdgApAsoEAIM+YQgE
++JBwGjACYAg4I968BAYAkQGeJ8Sr9cHEVlDgJ2/kUqhsy6qd63wd3CGpAt5nwFCQQ8J8oSsmkBuG1cUOIQDFsf8K7MC+GIJ6sqxt0mRLQTRXAOyx6KOaEom
e+L9mGbSDbqCHVGOGTBxtwtgD8pjgdXBv+thv8yoWDbQR9DvHLBw5PHQMheAUcCIZZGBaGQ7eDfoE5cdCqRUI7wPeUQUFK/c8DMZSRRsYnriEZXXgAEkhpYA
XvyHOfCY7JSghwLlIQVycIPIuKs5BJxcnp5d3nw9u7oOeOGzWhElNABXX7fv3j2/+3+HLfij5uIAAA==
END_GZIP_BASE64_FACTSRefs #542 Refs #543 Refs #544
Activity
5Implemented native render-bundle creation, recording, finish, and nonempty execution. Direct, indexed, indirect, and indexed-indirect TypeGPU recordings each passed two native macOS ARM64 submissions/readbacks. Added automatic native-handle finalization plus optional deterministic release, corrected bundle string-call FFI declarations and their generator, and documented binding resets and the existing immediate-variable limitation. Package typecheck and 24 focused tests pass; adversarial re-review found no remaining P1/P2 blockers. Windows/Linux native validation remains pending.
Addressed adversarial review: callback ABI selection now distinguishes Windows x64 from Windows ARM64, with six architecture cases and a real macOS ARM64 C→Cottontail callback check. Empty executeBundles calls are supported for TypeGPU pass detection; all nonempty inputs now throw NotSupportedError because bundle encoding is not implemented. 25 focused tests and package typecheck pass; native Windows/Linux checks remain pending.