@graphty/webgpu-graph-algorithms 0.0.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/README.md +378 -23
  2. package/dist/browser.d.ts +1 -0
  3. package/dist/browser.js +32 -0
  4. package/dist/browser.js.map +1 -0
  5. package/dist/chunks/context-E6iKaeuJ.js +3136 -0
  6. package/dist/chunks/context-E6iKaeuJ.js.map +1 -0
  7. package/dist/node.d.ts +1 -0
  8. package/dist/node.js +131 -0
  9. package/dist/node.js.map +1 -0
  10. package/dist/src/accelerator.d.ts +26 -0
  11. package/dist/src/accelerator.d.ts.map +1 -0
  12. package/dist/src/accelerator.js +101 -0
  13. package/dist/src/accelerator.js.map +1 -0
  14. package/dist/src/algorithms/degree.d.ts +35 -0
  15. package/dist/src/algorithms/degree.d.ts.map +1 -0
  16. package/dist/src/algorithms/degree.js +119 -0
  17. package/dist/src/algorithms/degree.js.map +1 -0
  18. package/dist/src/browser/index.d.ts +23 -0
  19. package/dist/src/browser/index.d.ts.map +1 -0
  20. package/dist/src/browser/index.js +48 -0
  21. package/dist/src/browser/index.js.map +1 -0
  22. package/dist/src/constants.d.ts +92 -0
  23. package/dist/src/constants.d.ts.map +1 -0
  24. package/dist/src/constants.js +92 -0
  25. package/dist/src/constants.js.map +1 -0
  26. package/dist/src/context.d.ts +84 -0
  27. package/dist/src/context.d.ts.map +1 -0
  28. package/dist/src/context.js +304 -0
  29. package/dist/src/context.js.map +1 -0
  30. package/dist/src/device/acquire.d.ts +57 -0
  31. package/dist/src/device/acquire.d.ts.map +1 -0
  32. package/dist/src/device/acquire.js +232 -0
  33. package/dist/src/device/acquire.js.map +1 -0
  34. package/dist/src/device/caps.d.ts +43 -0
  35. package/dist/src/device/caps.d.ts.map +1 -0
  36. package/dist/src/device/caps.js +104 -0
  37. package/dist/src/device/caps.js.map +1 -0
  38. package/dist/src/device/error-scope.d.ts +75 -0
  39. package/dist/src/device/error-scope.d.ts.map +1 -0
  40. package/dist/src/device/error-scope.js +152 -0
  41. package/dist/src/device/error-scope.js.map +1 -0
  42. package/dist/src/device/lost.d.ts +51 -0
  43. package/dist/src/device/lost.d.ts.map +1 -0
  44. package/dist/src/device/lost.js +130 -0
  45. package/dist/src/device/lost.js.map +1 -0
  46. package/dist/src/device/webgpu-constants.d.ts +31 -0
  47. package/dist/src/device/webgpu-constants.d.ts.map +1 -0
  48. package/dist/src/device/webgpu-constants.js +31 -0
  49. package/dist/src/device/webgpu-constants.js.map +1 -0
  50. package/dist/src/errors.d.ts +56 -0
  51. package/dist/src/errors.d.ts.map +1 -0
  52. package/dist/src/errors.js +57 -0
  53. package/dist/src/errors.js.map +1 -0
  54. package/dist/src/index.d.ts +29 -0
  55. package/dist/src/index.d.ts.map +1 -0
  56. package/dist/src/index.js +27 -0
  57. package/dist/src/index.js.map +1 -0
  58. package/dist/src/kernel/batch.d.ts +116 -0
  59. package/dist/src/kernel/batch.d.ts.map +1 -0
  60. package/dist/src/kernel/batch.js +335 -0
  61. package/dist/src/kernel/batch.js.map +1 -0
  62. package/dist/src/kernel/dispatch.d.ts +59 -0
  63. package/dist/src/kernel/dispatch.d.ts.map +1 -0
  64. package/dist/src/kernel/dispatch.js +139 -0
  65. package/dist/src/kernel/dispatch.js.map +1 -0
  66. package/dist/src/kernel/kernel.d.ts +84 -0
  67. package/dist/src/kernel/kernel.d.ts.map +1 -0
  68. package/dist/src/kernel/kernel.js +239 -0
  69. package/dist/src/kernel/kernel.js.map +1 -0
  70. package/dist/src/kernel/pipeline-cache.d.ts +90 -0
  71. package/dist/src/kernel/pipeline-cache.d.ts.map +1 -0
  72. package/dist/src/kernel/pipeline-cache.js +251 -0
  73. package/dist/src/kernel/pipeline-cache.js.map +1 -0
  74. package/dist/src/kernel/prelude.d.ts +35 -0
  75. package/dist/src/kernel/prelude.d.ts.map +1 -0
  76. package/dist/src/kernel/prelude.js +211 -0
  77. package/dist/src/kernel/prelude.js.map +1 -0
  78. package/dist/src/kernel/profiler.d.ts +64 -0
  79. package/dist/src/kernel/profiler.d.ts.map +1 -0
  80. package/dist/src/kernel/profiler.js +120 -0
  81. package/dist/src/kernel/profiler.js.map +1 -0
  82. package/dist/src/kernel/struct-block.d.ts +122 -0
  83. package/dist/src/kernel/struct-block.d.ts.map +1 -0
  84. package/dist/src/kernel/struct-block.js +353 -0
  85. package/dist/src/kernel/struct-block.js.map +1 -0
  86. package/dist/src/kernel/uniform-ring.d.ts +70 -0
  87. package/dist/src/kernel/uniform-ring.d.ts.map +1 -0
  88. package/dist/src/kernel/uniform-ring.js +146 -0
  89. package/dist/src/kernel/uniform-ring.js.map +1 -0
  90. package/dist/src/kernel/wgsl.d.ts +88 -0
  91. package/dist/src/kernel/wgsl.d.ts.map +1 -0
  92. package/dist/src/kernel/wgsl.js +390 -0
  93. package/dist/src/kernel/wgsl.js.map +1 -0
  94. package/dist/src/kernels.d.ts +81 -0
  95. package/dist/src/kernels.d.ts.map +1 -0
  96. package/dist/src/kernels.js +417 -0
  97. package/dist/src/kernels.js.map +1 -0
  98. package/dist/src/layouts/force-simulation.d.ts +498 -0
  99. package/dist/src/layouts/force-simulation.d.ts.map +1 -0
  100. package/dist/src/layouts/force-simulation.js +1650 -0
  101. package/dist/src/layouts/force-simulation.js.map +1 -0
  102. package/dist/src/layouts/forceatlas2.d.ts +210 -0
  103. package/dist/src/layouts/forceatlas2.d.ts.map +1 -0
  104. package/dist/src/layouts/forceatlas2.js +759 -0
  105. package/dist/src/layouts/forceatlas2.js.map +1 -0
  106. package/dist/src/layouts/inputs.d.ts +40 -0
  107. package/dist/src/layouts/inputs.d.ts.map +1 -0
  108. package/dist/src/layouts/inputs.js +185 -0
  109. package/dist/src/layouts/inputs.js.map +1 -0
  110. package/dist/src/layouts/repulsion-exact.d.ts +85 -0
  111. package/dist/src/layouts/repulsion-exact.d.ts.map +1 -0
  112. package/dist/src/layouts/repulsion-exact.js +134 -0
  113. package/dist/src/layouts/repulsion-exact.js.map +1 -0
  114. package/dist/src/layouts/seed.d.ts +56 -0
  115. package/dist/src/layouts/seed.d.ts.map +1 -0
  116. package/dist/src/layouts/seed.js +173 -0
  117. package/dist/src/layouts/seed.js.map +1 -0
  118. package/dist/src/memory/buffer-pool.d.ts +73 -0
  119. package/dist/src/memory/buffer-pool.d.ts.map +1 -0
  120. package/dist/src/memory/buffer-pool.js +170 -0
  121. package/dist/src/memory/buffer-pool.js.map +1 -0
  122. package/dist/src/memory/lease.d.ts +53 -0
  123. package/dist/src/memory/lease.d.ts.map +1 -0
  124. package/dist/src/memory/lease.js +85 -0
  125. package/dist/src/memory/lease.js.map +1 -0
  126. package/dist/src/memory/readback.d.ts +143 -0
  127. package/dist/src/memory/readback.d.ts.map +1 -0
  128. package/dist/src/memory/readback.js +375 -0
  129. package/dist/src/memory/readback.js.map +1 -0
  130. package/dist/src/memory/residency.d.ts +83 -0
  131. package/dist/src/memory/residency.d.ts.map +1 -0
  132. package/dist/src/memory/residency.js +573 -0
  133. package/dist/src/memory/residency.js.map +1 -0
  134. package/dist/src/memory/upload-plan.d.ts +101 -0
  135. package/dist/src/memory/upload-plan.d.ts.map +1 -0
  136. package/dist/src/memory/upload-plan.js +265 -0
  137. package/dist/src/memory/upload-plan.js.map +1 -0
  138. package/dist/src/node/index.d.ts +64 -0
  139. package/dist/src/node/index.d.ts.map +1 -0
  140. package/dist/src/node/index.js +183 -0
  141. package/dist/src/node/index.js.map +1 -0
  142. package/dist/src/primitives/reduce.d.ts +57 -0
  143. package/dist/src/primitives/reduce.d.ts.map +1 -0
  144. package/dist/src/primitives/reduce.js +161 -0
  145. package/dist/src/primitives/reduce.js.map +1 -0
  146. package/dist/src/primitives/segmented-reduce.d.ts +38 -0
  147. package/dist/src/primitives/segmented-reduce.d.ts.map +1 -0
  148. package/dist/src/primitives/segmented-reduce.js +211 -0
  149. package/dist/src/primitives/segmented-reduce.js.map +1 -0
  150. package/dist/src/types/accelerator.d.ts +209 -0
  151. package/dist/src/types/accelerator.d.ts.map +1 -0
  152. package/dist/src/types/accelerator.js +8 -0
  153. package/dist/src/types/accelerator.js.map +1 -0
  154. package/dist/src/types/context.d.ts +114 -0
  155. package/dist/src/types/context.d.ts.map +1 -0
  156. package/dist/src/types/context.js +7 -0
  157. package/dist/src/types/context.js.map +1 -0
  158. package/dist/src/types/layout.d.ts +95 -0
  159. package/dist/src/types/layout.d.ts.map +1 -0
  160. package/dist/src/types/layout.js +6 -0
  161. package/dist/src/types/layout.js.map +1 -0
  162. package/dist/src/types/memory.d.ts +22 -0
  163. package/dist/src/types/memory.d.ts.map +1 -0
  164. package/dist/src/types/memory.js +7 -0
  165. package/dist/src/types/memory.js.map +1 -0
  166. package/dist/src/types/options.d.ts +78 -0
  167. package/dist/src/types/options.d.ts.map +1 -0
  168. package/dist/src/types/options.js +7 -0
  169. package/dist/src/types/options.js.map +1 -0
  170. package/dist/src/types/run.d.ts +13 -0
  171. package/dist/src/types/run.d.ts.map +1 -0
  172. package/dist/src/types/run.js +6 -0
  173. package/dist/src/types/run.js.map +1 -0
  174. package/dist/src/wgsl/degree.wgsl.d.ts +10 -0
  175. package/dist/src/wgsl/degree.wgsl.d.ts.map +1 -0
  176. package/dist/src/wgsl/degree.wgsl.js +25 -0
  177. package/dist/src/wgsl/degree.wgsl.js.map +1 -0
  178. package/dist/src/wgsl/fa2-attraction.wgsl.d.ts +12 -0
  179. package/dist/src/wgsl/fa2-attraction.wgsl.d.ts.map +1 -0
  180. package/dist/src/wgsl/fa2-attraction.wgsl.js +37 -0
  181. package/dist/src/wgsl/fa2-attraction.wgsl.js.map +1 -0
  182. package/dist/src/wgsl/fa2-integrate.wgsl.d.ts +13 -0
  183. package/dist/src/wgsl/fa2-integrate.wgsl.d.ts.map +1 -0
  184. package/dist/src/wgsl/fa2-integrate.wgsl.js +69 -0
  185. package/dist/src/wgsl/fa2-integrate.wgsl.js.map +1 -0
  186. package/dist/src/wgsl/fa2-repulsion-exact.wgsl.d.ts +12 -0
  187. package/dist/src/wgsl/fa2-repulsion-exact.wgsl.d.ts.map +1 -0
  188. package/dist/src/wgsl/fa2-repulsion-exact.wgsl.js +79 -0
  189. package/dist/src/wgsl/fa2-repulsion-exact.wgsl.js.map +1 -0
  190. package/dist/src/wgsl/fa2-speed-finalize.wgsl.d.ts +15 -0
  191. package/dist/src/wgsl/fa2-speed-finalize.wgsl.d.ts.map +1 -0
  192. package/dist/src/wgsl/fa2-speed-finalize.wgsl.js +54 -0
  193. package/dist/src/wgsl/fa2-speed-finalize.wgsl.js.map +1 -0
  194. package/dist/src/wgsl/fa2-stats-finalize.wgsl.d.ts +14 -0
  195. package/dist/src/wgsl/fa2-stats-finalize.wgsl.d.ts.map +1 -0
  196. package/dist/src/wgsl/fa2-stats-finalize.wgsl.js +57 -0
  197. package/dist/src/wgsl/fa2-stats-finalize.wgsl.js.map +1 -0
  198. package/dist/src/wgsl/fa2-to-scene.wgsl.d.ts +11 -0
  199. package/dist/src/wgsl/fa2-to-scene.wgsl.d.ts.map +1 -0
  200. package/dist/src/wgsl/fa2-to-scene.wgsl.js +19 -0
  201. package/dist/src/wgsl/fa2-to-scene.wgsl.js.map +1 -0
  202. package/dist/src/wgsl/fill.wgsl.d.ts +7 -0
  203. package/dist/src/wgsl/fill.wgsl.d.ts.map +1 -0
  204. package/dist/src/wgsl/fill.wgsl.js +14 -0
  205. package/dist/src/wgsl/fill.wgsl.js.map +1 -0
  206. package/dist/src/wgsl/reduce.wgsl.d.ts +10 -0
  207. package/dist/src/wgsl/reduce.wgsl.d.ts.map +1 -0
  208. package/dist/src/wgsl/reduce.wgsl.js +63 -0
  209. package/dist/src/wgsl/reduce.wgsl.js.map +1 -0
  210. package/dist/src/wgsl/segmented-reduce.wgsl.d.ts +13 -0
  211. package/dist/src/wgsl/segmented-reduce.wgsl.d.ts.map +1 -0
  212. package/dist/src/wgsl/segmented-reduce.wgsl.js +35 -0
  213. package/dist/src/wgsl/segmented-reduce.wgsl.js.map +1 -0
  214. package/dist/tsconfig.build.tsbuildinfo +1 -0
  215. package/dist/webgpu-graph-algorithms.d.ts +1 -0
  216. package/dist/webgpu-graph-algorithms.js +4454 -0
  217. package/dist/webgpu-graph-algorithms.js.map +1 -0
  218. package/package.json +108 -17
  219. package/src/accelerator.ts +117 -0
  220. package/src/algorithms/degree.ts +142 -0
  221. package/src/browser/index.ts +57 -0
  222. package/src/constants.ts +116 -0
  223. package/src/context.ts +399 -0
  224. package/src/device/acquire.ts +256 -0
  225. package/src/device/caps.ts +122 -0
  226. package/src/device/error-scope.ts +171 -0
  227. package/src/device/lost.ts +142 -0
  228. package/src/device/webgpu-constants.ts +44 -0
  229. package/src/errors.ts +94 -0
  230. package/src/index.ts +102 -0
  231. package/src/kernel/batch.ts +427 -0
  232. package/src/kernel/dispatch.ts +162 -0
  233. package/src/kernel/kernel.ts +311 -0
  234. package/src/kernel/pipeline-cache.ts +288 -0
  235. package/src/kernel/prelude.ts +229 -0
  236. package/src/kernel/profiler.ts +148 -0
  237. package/src/kernel/struct-block.ts +439 -0
  238. package/src/kernel/uniform-ring.ts +184 -0
  239. package/src/kernel/wgsl.ts +490 -0
  240. package/src/kernels.ts +511 -0
  241. package/src/layouts/force-simulation.ts +2111 -0
  242. package/src/layouts/forceatlas2.ts +942 -0
  243. package/src/layouts/inputs.ts +252 -0
  244. package/src/layouts/repulsion-exact.ts +183 -0
  245. package/src/layouts/seed.ts +198 -0
  246. package/src/memory/buffer-pool.ts +204 -0
  247. package/src/memory/lease.ts +93 -0
  248. package/src/memory/readback.ts +429 -0
  249. package/src/memory/residency.ts +753 -0
  250. package/src/memory/upload-plan.ts +350 -0
  251. package/src/node/index.ts +230 -0
  252. package/src/primitives/reduce.ts +233 -0
  253. package/src/primitives/segmented-reduce.ts +270 -0
  254. package/src/types/accelerator.ts +236 -0
  255. package/src/types/context.ts +135 -0
  256. package/src/types/layout.ts +103 -0
  257. package/src/types/memory.ts +23 -0
  258. package/src/types/options.ts +84 -0
  259. package/src/types/run.ts +13 -0
  260. package/src/wgsl/degree.wgsl.ts +24 -0
  261. package/src/wgsl/fa2-attraction.wgsl.ts +37 -0
  262. package/src/wgsl/fa2-integrate.wgsl.ts +69 -0
  263. package/src/wgsl/fa2-repulsion-exact.wgsl.ts +78 -0
  264. package/src/wgsl/fa2-speed-finalize.wgsl.ts +53 -0
  265. package/src/wgsl/fa2-stats-finalize.wgsl.ts +57 -0
  266. package/src/wgsl/fa2-to-scene.wgsl.ts +19 -0
  267. package/src/wgsl/fill.wgsl.ts +13 -0
  268. package/src/wgsl/reduce.wgsl.ts +62 -0
  269. package/src/wgsl/segmented-reduce.wgsl.ts +35 -0
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Device acquisition (spec 2.2 steps 1-3, 2.6; contract 3.4): the adapter request, the software-adapter
3
+ * test, the adapter summary, the requiredLimits / requiredFeatures builders and the device request. Nothing
4
+ * above the device layer is constructed here (D26); src/context.ts sequences these calls. An adapter is
5
+ * consumed by its first requestDevice (WebGPU 3.5.1; Dawn-node rejects the second call with
6
+ * `OperationError: adapter is "consumed"`), so every device the package creates comes from a fresh adapter.
7
+ */
8
+ import type { AdapterInfoLike, AdapterSummary, LimitPolicy, RaisableLimit } from "../types/context.js";
9
+ /** The six raisable limits in the order create() requests them (spec 2.2). */
10
+ export declare const RAISABLE_LIMITS: readonly RaisableLimit[];
11
+ /**
12
+ * Software adapter test (spec 2.2 step 2): architecture "software" (Dawn llvmpipe) or "swiftshader", or
13
+ * isFallbackAdapter === true (Chromium); the ONE reader of these fields.
14
+ * @param info - the adapter info (structural, so tests can fake it)
15
+ * @returns true for a software adapter
16
+ */
17
+ export declare function isSoftwareAdapter(info: AdapterInfoLike): boolean;
18
+ /**
19
+ * The AdapterSummary of an adapter (info + features + limits); never requests a device.
20
+ * @param adapter - an adapter (unused or not; only its info, features and limits are read)
21
+ * @returns a frozen summary; `subgroupMinSize` / `subgroupMaxSize` are 0 when the info lacks them
22
+ */
23
+ export declare function summarizeAdapter(adapter: GPUAdapter): AdapterSummary;
24
+ /**
25
+ * Step 1 of create(): requestAdapter with the power preference; null -> E_NO_ADAPTER.
26
+ * @param gpu - navigator.gpu or the Dawn handle
27
+ * @param powerPreference - honoured by browsers, ignored by Dawn-node (spec 2.6)
28
+ * @returns an UNUSED adapter
29
+ */
30
+ export declare function requestAdapter(gpu: GPU, powerPreference: GPUPowerPreference): Promise<GPUAdapter>;
31
+ /**
32
+ * Step 3 of create(): the requiredLimits record for a policy, clamped to the adapter; an explicit value
33
+ * above the adapter -> E_NO_DEVICE { reason: "limit" } before any requestDevice call, so the failure is
34
+ * diagnosable.
35
+ * @param adapter - the adapter the device will come from
36
+ * @param policy - "default" (nothing), "raise" (every raisable limit at the adapter's value) or explicit values
37
+ * @returns the record to pass as requiredLimits
38
+ */
39
+ export declare function buildRequiredLimits(adapter: GPUAdapter, policy: LimitPolicy): Record<string, number>;
40
+ /**
41
+ * Step 3 of create(): the requiredFeatures list = required + (optional intersect adapter.features); a missing
42
+ * required feature -> E_NO_DEVICE { reason: "feature", requested: <name> }.
43
+ * @param adapter - the adapter the device will come from
44
+ * @param required - features the caller cannot do without
45
+ * @param optional - features requested only when the adapter has them
46
+ * @returns the deduplicated list, required first
47
+ */
48
+ export declare function buildRequiredFeatures(adapter: GPUAdapter, required: readonly GPUFeatureName[], optional: readonly GPUFeatureName[]): GPUFeatureName[];
49
+ /**
50
+ * Step 3 of create(): requestDevice; a rejection -> E_NO_DEVICE with the adapter summary ("consumed" when
51
+ * the adapter already created a device, detected by the OperationError message or a prior-use record).
52
+ * @param adapter - an UNUSED adapter
53
+ * @param descriptor - requiredLimits, requiredFeatures and the label
54
+ * @returns the device
55
+ */
56
+ export declare function requestDevice(adapter: GPUAdapter, descriptor: GPUDeviceDescriptor): Promise<GPUDevice>;
57
+ //# sourceMappingURL=acquire.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acquire.d.ts","sourceRoot":"","sources":["../../../src/device/acquire.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEvG,8EAA8E;AAC9E,eAAO,MAAM,eAAe,EAAE,SAAS,aAAa,EAOlD,CAAC;AA0DH;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAShE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,UAAU,GAAG,cAAc,CAqBpE;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,eAAe,EAAE,kBAAkB,GAAG,OAAO,CAAC,UAAU,CAAC,CAavG;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA2BpG;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACjC,OAAO,EAAE,UAAU,EACnB,QAAQ,EAAE,SAAS,cAAc,EAAE,EACnC,QAAQ,EAAE,SAAS,cAAc,EAAE,GACpC,cAAc,EAAE,CAoBlB;AAiBD;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,mBAAmB,GAAG,OAAO,CAAC,SAAS,CAAC,CAmB5G"}
@@ -0,0 +1,232 @@
1
+ /**
2
+ * Device acquisition (spec 2.2 steps 1-3, 2.6; contract 3.4): the adapter request, the software-adapter
3
+ * test, the adapter summary, the requiredLimits / requiredFeatures builders and the device request. Nothing
4
+ * above the device layer is constructed here (D26); src/context.ts sequences these calls. An adapter is
5
+ * consumed by its first requestDevice (WebGPU 3.5.1; Dawn-node rejects the second call with
6
+ * `OperationError: adapter is "consumed"`), so every device the package creates comes from a fresh adapter.
7
+ */
8
+ import { WebGpuGraphError } from "../errors.js";
9
+ /** The six raisable limits in the order create() requests them (spec 2.2). */
10
+ export const RAISABLE_LIMITS = Object.freeze([
11
+ "maxBufferSize",
12
+ "maxStorageBufferBindingSize",
13
+ "maxStorageBuffersPerShaderStage",
14
+ "maxComputeWorkgroupStorageSize",
15
+ "maxComputeInvocationsPerWorkgroup",
16
+ "maxComputeWorkgroupSizeX",
17
+ ]);
18
+ /**
19
+ * The WebGPU limit names summarizeAdapter reads (the GPUSupportedLimits members of @webgpu/types 0.1.72).
20
+ * A fixed list because Chromium exposes the limits as prototype getters (Object.keys is empty) and Dawn-node as an
21
+ * addon object; reading each name works identically on both, and a name the runtime lacks is simply absent.
22
+ */
23
+ const LIMIT_NAMES = [
24
+ "maxTextureDimension1D",
25
+ "maxTextureDimension2D",
26
+ "maxTextureDimension3D",
27
+ "maxTextureArrayLayers",
28
+ "maxBindGroups",
29
+ "maxBindGroupsPlusVertexBuffers",
30
+ "maxBindingsPerBindGroup",
31
+ "maxDynamicUniformBuffersPerPipelineLayout",
32
+ "maxDynamicStorageBuffersPerPipelineLayout",
33
+ "maxSampledTexturesPerShaderStage",
34
+ "maxSamplersPerShaderStage",
35
+ "maxStorageBuffersPerShaderStage",
36
+ "maxStorageBuffersInVertexStage",
37
+ "maxStorageBuffersInFragmentStage",
38
+ "maxStorageTexturesPerShaderStage",
39
+ "maxStorageTexturesInVertexStage",
40
+ "maxStorageTexturesInFragmentStage",
41
+ "maxUniformBuffersPerShaderStage",
42
+ "maxUniformBufferBindingSize",
43
+ "maxStorageBufferBindingSize",
44
+ "minUniformBufferOffsetAlignment",
45
+ "minStorageBufferOffsetAlignment",
46
+ "maxVertexBuffers",
47
+ "maxBufferSize",
48
+ "maxVertexAttributes",
49
+ "maxVertexBufferArrayStride",
50
+ "maxInterStageShaderVariables",
51
+ "maxColorAttachments",
52
+ "maxColorAttachmentBytesPerSample",
53
+ "maxComputeWorkgroupStorageSize",
54
+ "maxComputeInvocationsPerWorkgroup",
55
+ "maxComputeWorkgroupSizeX",
56
+ "maxComputeWorkgroupSizeY",
57
+ "maxComputeWorkgroupSizeZ",
58
+ "maxComputeWorkgroupsPerDimension",
59
+ "maxImmediateSize",
60
+ ];
61
+ /** Adapters that created a device through requestDevice(): a second create({ adapter }) fails without a round trip. */
62
+ const consumedAdapters = new WeakSet();
63
+ /**
64
+ * The message of a thrown value.
65
+ * @param err - what was caught
66
+ * @returns the Error message, or the value as a string
67
+ */
68
+ function messageOf(err) {
69
+ return err instanceof Error ? err.message : String(err);
70
+ }
71
+ /**
72
+ * Software adapter test (spec 2.2 step 2): architecture "software" (Dawn llvmpipe) or "swiftshader", or
73
+ * isFallbackAdapter === true (Chromium); the ONE reader of these fields.
74
+ * @param info - the adapter info (structural, so tests can fake it)
75
+ * @returns true for a software adapter
76
+ */
77
+ export function isSoftwareAdapter(info) {
78
+ // "software" = Dawn-node on llvmpipe, "swiftshader" = Chromium's fallback, "warp" = Dawn's D3D12 backend on
79
+ // Microsoft's WARP rasterizer (the Windows host lane: vendor "microsoft", isFallbackAdapter absent under Dawn-node).
80
+ return (info.architecture === "software" ||
81
+ info.architecture === "swiftshader" ||
82
+ info.architecture === "warp" ||
83
+ info.isFallbackAdapter === true);
84
+ }
85
+ /**
86
+ * The AdapterSummary of an adapter (info + features + limits); never requests a device.
87
+ * @param adapter - an adapter (unused or not; only its info, features and limits are read)
88
+ * @returns a frozen summary; `subgroupMinSize` / `subgroupMaxSize` are 0 when the info lacks them
89
+ */
90
+ export function summarizeAdapter(adapter) {
91
+ const { info } = adapter;
92
+ const source = adapter.limits;
93
+ const limits = {};
94
+ for (const name of LIMIT_NAMES) {
95
+ const value = source[name];
96
+ if (typeof value === "number") {
97
+ limits[name] = value;
98
+ }
99
+ }
100
+ return Object.freeze({
101
+ vendor: info.vendor,
102
+ architecture: info.architecture,
103
+ device: info.device,
104
+ description: info.description,
105
+ software: isSoftwareAdapter(info),
106
+ subgroupMinSize: info.subgroupMinSize ?? 0,
107
+ subgroupMaxSize: info.subgroupMaxSize ?? 0,
108
+ features: Object.freeze(Array.from(adapter.features).sort()),
109
+ limits: Object.freeze(limits),
110
+ });
111
+ }
112
+ /**
113
+ * Step 1 of create(): requestAdapter with the power preference; null -> E_NO_ADAPTER.
114
+ * @param gpu - navigator.gpu or the Dawn handle
115
+ * @param powerPreference - honoured by browsers, ignored by Dawn-node (spec 2.6)
116
+ * @returns an UNUSED adapter
117
+ */
118
+ export async function requestAdapter(gpu, powerPreference) {
119
+ let adapter;
120
+ try {
121
+ adapter = await gpu.requestAdapter({ powerPreference });
122
+ }
123
+ catch (err) {
124
+ const reason = `requestAdapter() threw: ${messageOf(err)}`;
125
+ throw new WebGpuGraphError("E_NO_ADAPTER", reason, { reason });
126
+ }
127
+ if (adapter === null) {
128
+ const reason = "requestAdapter() returned null: no usable WebGPU adapter";
129
+ throw new WebGpuGraphError("E_NO_ADAPTER", reason, { reason });
130
+ }
131
+ return adapter;
132
+ }
133
+ /**
134
+ * Step 3 of create(): the requiredLimits record for a policy, clamped to the adapter; an explicit value
135
+ * above the adapter -> E_NO_DEVICE { reason: "limit" } before any requestDevice call, so the failure is
136
+ * diagnosable.
137
+ * @param adapter - the adapter the device will come from
138
+ * @param policy - "default" (nothing), "raise" (every raisable limit at the adapter's value) or explicit values
139
+ * @returns the record to pass as requiredLimits
140
+ */
141
+ export function buildRequiredLimits(adapter, policy) {
142
+ const limits = {};
143
+ if (policy === "default") {
144
+ return limits;
145
+ }
146
+ if (policy === "raise") {
147
+ for (const name of RAISABLE_LIMITS) {
148
+ limits[name] = adapter.limits[name];
149
+ }
150
+ return limits;
151
+ }
152
+ for (const name of RAISABLE_LIMITS) {
153
+ const requested = policy[name];
154
+ if (requested === undefined) {
155
+ continue;
156
+ }
157
+ const available = adapter.limits[name];
158
+ if (requested > available) {
159
+ throw new WebGpuGraphError("E_NO_DEVICE", `requested ${name} = ${requested} exceeds the adapter's ${available}`, { reason: "limit", adapter: summarizeAdapter(adapter), limit: name, requested, available });
160
+ }
161
+ limits[name] = requested;
162
+ }
163
+ return limits;
164
+ }
165
+ /**
166
+ * Step 3 of create(): the requiredFeatures list = required + (optional intersect adapter.features); a missing
167
+ * required feature -> E_NO_DEVICE { reason: "feature", requested: <name> }.
168
+ * @param adapter - the adapter the device will come from
169
+ * @param required - features the caller cannot do without
170
+ * @param optional - features requested only when the adapter has them
171
+ * @returns the deduplicated list, required first
172
+ */
173
+ export function buildRequiredFeatures(adapter, required, optional) {
174
+ const features = [];
175
+ for (const feature of required) {
176
+ if (!adapter.features.has(feature)) {
177
+ throw new WebGpuGraphError("E_NO_DEVICE", `required feature "${feature}" is not supported by the adapter`, {
178
+ reason: "feature",
179
+ adapter: summarizeAdapter(adapter),
180
+ requested: feature,
181
+ });
182
+ }
183
+ if (!features.includes(feature)) {
184
+ features.push(feature);
185
+ }
186
+ }
187
+ for (const feature of optional) {
188
+ if (adapter.features.has(feature) && !features.includes(feature)) {
189
+ features.push(feature);
190
+ }
191
+ }
192
+ return features;
193
+ }
194
+ /**
195
+ * The E_NO_DEVICE of a consumed adapter; the runtime's text lives in the error message only (contract 3.1
196
+ * documents `details` as { reason, adapter, limit?, requested?, available? }).
197
+ * @param adapter - the adapter that already created a device
198
+ * @param message - the runtime's rejection message when there was a round trip
199
+ * @returns E_NO_DEVICE { reason: "consumed", adapter }
200
+ */
201
+ function consumedError(adapter, message) {
202
+ return new WebGpuGraphError("E_NO_DEVICE", `the adapter already created a device (an adapter is consumed by one requestDevice, spec 2.2 step 1): ${message}`, { reason: "consumed", adapter: summarizeAdapter(adapter) });
203
+ }
204
+ /**
205
+ * Step 3 of create(): requestDevice; a rejection -> E_NO_DEVICE with the adapter summary ("consumed" when
206
+ * the adapter already created a device, detected by the OperationError message or a prior-use record).
207
+ * @param adapter - an UNUSED adapter
208
+ * @param descriptor - requiredLimits, requiredFeatures and the label
209
+ * @returns the device
210
+ */
211
+ export async function requestDevice(adapter, descriptor) {
212
+ if (consumedAdapters.has(adapter)) {
213
+ throw consumedError(adapter, "recorded by this package");
214
+ }
215
+ let device;
216
+ try {
217
+ device = await adapter.requestDevice(descriptor);
218
+ }
219
+ catch (err) {
220
+ const message = messageOf(err);
221
+ if (/consumed|already been used/i.test(message)) {
222
+ throw consumedError(adapter, message);
223
+ }
224
+ throw new WebGpuGraphError("E_NO_DEVICE", `requestDevice() rejected: ${message}`, {
225
+ reason: "requestDevice",
226
+ adapter: summarizeAdapter(adapter),
227
+ });
228
+ }
229
+ consumedAdapters.add(adapter);
230
+ return device;
231
+ }
232
+ //# sourceMappingURL=acquire.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acquire.js","sourceRoot":"","sources":["../../../src/device/acquire.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGhD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,eAAe,GAA6B,MAAM,CAAC,MAAM,CAAC;IACnE,eAAe;IACf,6BAA6B;IAC7B,iCAAiC;IACjC,gCAAgC;IAChC,mCAAmC;IACnC,0BAA0B;CAC7B,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,WAAW,GAAsB;IACnC,uBAAuB;IACvB,uBAAuB;IACvB,uBAAuB;IACvB,uBAAuB;IACvB,eAAe;IACf,gCAAgC;IAChC,yBAAyB;IACzB,2CAA2C;IAC3C,2CAA2C;IAC3C,kCAAkC;IAClC,2BAA2B;IAC3B,iCAAiC;IACjC,gCAAgC;IAChC,kCAAkC;IAClC,kCAAkC;IAClC,iCAAiC;IACjC,mCAAmC;IACnC,iCAAiC;IACjC,6BAA6B;IAC7B,6BAA6B;IAC7B,iCAAiC;IACjC,iCAAiC;IACjC,kBAAkB;IAClB,eAAe;IACf,qBAAqB;IACrB,4BAA4B;IAC5B,8BAA8B;IAC9B,qBAAqB;IACrB,kCAAkC;IAClC,gCAAgC;IAChC,mCAAmC;IACnC,0BAA0B;IAC1B,0BAA0B;IAC1B,0BAA0B;IAC1B,kCAAkC;IAClC,kBAAkB;CACrB,CAAC;AAEF,uHAAuH;AACvH,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AC;IAC9B,OAAO,MAAM,CAAC;AAClB,CAAC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Capability capture (spec 2.2 step 4, 3.3, 5.1, 5.2; contract 3.4): the GpuCaps record of a DEVICE (its
3
+ * limits and features, never the adapter's), the zero-cost variant for an adopted device, the two planner
4
+ * facts asserted at create(), and the workgroup size a device runs.
5
+ */
6
+ import type { AdapterInfoLike, GpuCaps, PlanCaps } from "../types/context.js";
7
+ /**
8
+ * Step 4 of create(): the GpuCaps of a DEVICE (device.limits, never adapter.limits) with the adapter info
9
+ * and the runtime tag. The subgroup sizes are the adapter's only when the device has the "subgroups"
10
+ * feature, else 0 (spec 3.3).
11
+ * @param device - the device the caps describe
12
+ * @param info - the adapter's info (vendor, architecture, subgroup sizes)
13
+ * @param runtime - the tag the creating entry sets ("unknown" for consumers of the core)
14
+ * @param wgslFeatures - navigator.gpu.wgslLanguageFeatures or the Dawn equivalent (informational)
15
+ * @returns the capability record
16
+ */
17
+ export declare function captureCaps(device: GPUDevice, info: AdapterInfoLike, runtime: "browser" | "node" | "unknown", wgslFeatures: Iterable<string>): GpuCaps;
18
+ /**
19
+ * GpuContext.from(device, info?): caps from device.limits / device.features and the partial info given;
20
+ * software false and runtime "unknown" unless given; the subgroup sizes are honoured only when the device
21
+ * has the feature.
22
+ * @param device - the adopted device
23
+ * @param info - what the caller knows about the adapter, if anything
24
+ * @returns the capability record
25
+ */
26
+ export declare function capsFromDevice(device: GPUDevice, info: Partial<GpuCaps> | undefined): GpuCaps;
27
+ /**
28
+ * The workgroup size a device runs: min(WORKGROUP_SIZE, caps.limits.maxComputeInvocationsPerWorkgroup) rounded
29
+ * down to a power of two (spec 5.1; the formula of contract 3.2 / 3.4). maxComputeWorkgroupSizeX is not a term:
30
+ * every adapter supports its 256 default (WebGPU 3.6.2), so the result never exceeds it. Rounds down by doubling
31
+ * (no bitwise operator).
32
+ * @param caps - the capability record (a GpuCaps is a PlanCaps)
33
+ * @returns the workgroup size
34
+ */
35
+ export declare function workgroupSizeFor(caps: PlanCaps): number;
36
+ /**
37
+ * Asserts the two facts the planners bake in: maxComputeWorkgroupsPerDimension === MAX_WORKGROUPS_PER_DIM
38
+ * (the prelude's linear_id and plan1d / plan2d use the constant) and WG is a power of two >= 64 (spec 2.2,
39
+ * 5.2). The limit is never requested, so a device reports the spec default whatever its adapter says.
40
+ * @param caps - the capability record of the device
41
+ */
42
+ export declare function assertPlanLimits(caps: GpuCaps): void;
43
+ //# sourceMappingURL=caps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caps.d.ts","sourceRoot":"","sources":["../../../src/device/caps.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAG9E;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACvB,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,eAAe,EACrB,OAAO,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,EACvC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,GAC/B,OAAO,CAgBT;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,SAAS,GAAG,OAAO,CAgB7F;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAOvD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CA4BpD"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Capability capture (spec 2.2 step 4, 3.3, 5.1, 5.2; contract 3.4): the GpuCaps record of a DEVICE (its
3
+ * limits and features, never the adapter's), the zero-cost variant for an adopted device, the two planner
4
+ * facts asserted at create(), and the workgroup size a device runs.
5
+ */
6
+ import { MAX_WORKGROUPS_PER_DIM, WORKGROUP_SIZE } from "../constants.js";
7
+ import { WebGpuGraphError } from "../errors.js";
8
+ import { isSoftwareAdapter } from "./acquire.js";
9
+ /**
10
+ * Step 4 of create(): the GpuCaps of a DEVICE (device.limits, never adapter.limits) with the adapter info
11
+ * and the runtime tag. The subgroup sizes are the adapter's only when the device has the "subgroups"
12
+ * feature, else 0 (spec 3.3).
13
+ * @param device - the device the caps describe
14
+ * @param info - the adapter's info (vendor, architecture, subgroup sizes)
15
+ * @param runtime - the tag the creating entry sets ("unknown" for consumers of the core)
16
+ * @param wgslFeatures - navigator.gpu.wgslLanguageFeatures or the Dawn equivalent (informational)
17
+ * @returns the capability record
18
+ */
19
+ export function captureCaps(device, info, runtime, wgslFeatures) {
20
+ const features = new Set(device.features);
21
+ const subgroups = features.has("subgroups");
22
+ return {
23
+ limits: device.limits,
24
+ features,
25
+ wgslFeatures: new Set(wgslFeatures),
26
+ subgroupMinSize: subgroups ? (info.subgroupMinSize ?? 0) : 0,
27
+ subgroupMaxSize: subgroups ? (info.subgroupMaxSize ?? 0) : 0,
28
+ software: isSoftwareAdapter(info),
29
+ runtime,
30
+ vendor: info.vendor,
31
+ architecture: info.architecture,
32
+ device: info.device,
33
+ description: info.description,
34
+ };
35
+ }
36
+ /**
37
+ * GpuContext.from(device, info?): caps from device.limits / device.features and the partial info given;
38
+ * software false and runtime "unknown" unless given; the subgroup sizes are honoured only when the device
39
+ * has the feature.
40
+ * @param device - the adopted device
41
+ * @param info - what the caller knows about the adapter, if anything
42
+ * @returns the capability record
43
+ */
44
+ export function capsFromDevice(device, info) {
45
+ const features = new Set(device.features);
46
+ const subgroups = features.has("subgroups");
47
+ return {
48
+ limits: device.limits,
49
+ features,
50
+ wgslFeatures: info?.wgslFeatures ?? new Set(),
51
+ subgroupMinSize: subgroups ? (info?.subgroupMinSize ?? 0) : 0,
52
+ subgroupMaxSize: subgroups ? (info?.subgroupMaxSize ?? 0) : 0,
53
+ software: info?.software ?? false,
54
+ runtime: info?.runtime ?? "unknown",
55
+ vendor: info?.vendor ?? "",
56
+ architecture: info?.architecture ?? "",
57
+ device: info?.device ?? "",
58
+ description: info?.description ?? "",
59
+ };
60
+ }
61
+ /**
62
+ * The workgroup size a device runs: min(WORKGROUP_SIZE, caps.limits.maxComputeInvocationsPerWorkgroup) rounded
63
+ * down to a power of two (spec 5.1; the formula of contract 3.2 / 3.4). maxComputeWorkgroupSizeX is not a term:
64
+ * every adapter supports its 256 default (WebGPU 3.6.2), so the result never exceeds it. Rounds down by doubling
65
+ * (no bitwise operator).
66
+ * @param caps - the capability record (a GpuCaps is a PlanCaps)
67
+ * @returns the workgroup size
68
+ */
69
+ export function workgroupSizeFor(caps) {
70
+ const cap = Math.min(WORKGROUP_SIZE, caps.limits.maxComputeInvocationsPerWorkgroup);
71
+ let size = 1;
72
+ while (size * 2 <= cap) {
73
+ size *= 2;
74
+ }
75
+ return size;
76
+ }
77
+ /**
78
+ * Asserts the two facts the planners bake in: maxComputeWorkgroupsPerDimension === MAX_WORKGROUPS_PER_DIM
79
+ * (the prelude's linear_id and plan1d / plan2d use the constant) and WG is a power of two >= 64 (spec 2.2,
80
+ * 5.2). The limit is never requested, so a device reports the spec default whatever its adapter says.
81
+ * @param caps - the capability record of the device
82
+ */
83
+ export function assertPlanLimits(caps) {
84
+ const perDim = caps.limits.maxComputeWorkgroupsPerDimension;
85
+ if (perDim !== MAX_WORKGROUPS_PER_DIM) {
86
+ throw new WebGpuGraphError("E_NO_DEVICE", `maxComputeWorkgroupsPerDimension is ${perDim}; the dispatch planner and the WGSL prelude bake ${MAX_WORKGROUPS_PER_DIM}`, {
87
+ reason: "maxComputeWorkgroupsPerDimension",
88
+ adapter: null,
89
+ requested: MAX_WORKGROUPS_PER_DIM,
90
+ available: perDim,
91
+ });
92
+ }
93
+ const wg = workgroupSizeFor(caps);
94
+ if (wg < 64) {
95
+ throw new WebGpuGraphError("E_NO_DEVICE", `the device allows a workgroup of ${wg} invocations; the kernels need a power of two >= 64`, {
96
+ reason: "limit",
97
+ adapter: null,
98
+ limit: "maxComputeInvocationsPerWorkgroup",
99
+ requested: 64,
100
+ available: wg,
101
+ });
102
+ }
103
+ }
104
+ //# sourceMappingURL=caps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caps.js","sourceRoot":"","sources":["../../../src/device/caps.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD;;;;;;;;;GASG;AACH,MAAM,UAAU,WAAW,CACvB,MAAiB,EACjB,IAAqB,EACrB,OAAuC,EACvC,YAA8B;IAE9B,MAAM,QAAQ,GAAwB,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC/D,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC5C,OAAO;QACH,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,QAAQ;QACR,YAAY,EAAE,IAAI,GAAG,CAAC,YAAY,CAAC;QACnC,eAAe,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5D,eAAe,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5D,QAAQ,EAAE,iBAAiB,CAAC,IAAI,CAAC;QACjC,OAAO;QACP,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,WAAW,EAAE,IAAI,CAAC,WAAW;KAChC,CAAC;AACN,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,M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AC,MAAM,CAAC,gCAAgC,CAAC;IAC5D,IAAI,MAAM,KAAK,sBAAsB,EAAE,CAAC;QACpC,MAAM,IAAI,gBAAgB,CACtB,aAAa,EACb,uCAAuC,MAAM,oDAAoD,sBAAsB,EAAE,EACzH;YACI,MAAM,EAAE,kCAAkC;YAC1C,OAAO,EAAE,IAAI;YACb,SAAS,EAAE,sBAAsB;YACjC,SAAS,EAAE,MAAM;SACpB,CACJ,CAAC;IACN,CAAC;IACD,MAAM,EAAE,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC;QACV,MAAM,IAAI,gBAAgB,CACtB,aAAa,EACb,oCAAoC,EAAE,qDAAqD,EAC3F;YACI,MAAM,EAAE,OAAO;YACf,OAAO,EAAE,IAAI;YACb,KAAK,EAAE,mCAAmC;YAC1C,SAAS,EAAE,EAAE;YACb,SAAS,EAAE,EAAE;SAChB,CACJ,CAAC;IACN,CAAC;AACL,CAAC"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Error scopes (spec 5.7; contract 3.4): a validation scope that turns a captured GPUValidationError into
3
+ * E_VALIDATION { label, message }, the compilation-info formatter with body-relative line numbers, and the
4
+ * AllocationTracker that wraps large createBuffer calls in an out-of-memory scope and keeps the resident-byte
5
+ * bookkeeping the residency, the pool and the staging ring share (it is owned by the context).
6
+ */
7
+ /**
8
+ * Runs `fn` inside pushErrorScope("validation"); a captured error becomes E_VALIDATION { label, message }
9
+ * thrown from the returned promise (spec 5.7). An error `fn` itself throws is rethrown unchanged after the
10
+ * scope is popped, so the device's scope stack stays balanced.
11
+ * @param device - the device
12
+ * @param label - names the operation in the error (every object the package creates is labelled)
13
+ * @param fn - the work; may return a promise
14
+ * @returns the value of `fn`
15
+ */
16
+ export declare function withValidationScope<T>(device: GPUDevice, label: string, fn: () => Promise<T> | T): Promise<T>;
17
+ /**
18
+ * Formats GPUCompilationInfo messages with line numbers relative to the kernel BODY: `preludeLines` (the
19
+ * lines the composer emitted before the body) is subtracted, a message located inside those lines is
20
+ * reported as `prelude:<line>`, and a message without a location (lineNum 0) carries no position (spec 5.1).
21
+ * @param info - the compilation info of the shader module
22
+ * @param preludeLines - the number of emitted lines before the body's first line
23
+ * @returns one string per message: `<type> <line>:<column> <message>`
24
+ */
25
+ export declare function formatCompilationInfo(info: GPUCompilationInfo, preludeLines: number): string[];
26
+ /**
27
+ * Creates buffers, wrapping sizes >= OOM_SCOPE_THRESHOLD_BYTES in an "out-of-memory" scope whose pop is
28
+ * collected; `check()` surfaces the first OOM (spec 4.4, 5.7). Owned by the context, shared by the
29
+ * residency and the pool.
30
+ */
31
+ export declare class AllocationTracker {
32
+ private readonly device;
33
+ private readonly threshold;
34
+ private readonly live;
35
+ private residentBytes;
36
+ private pending;
37
+ private failure;
38
+ private serial;
39
+ /**
40
+ * Creates a tracker over one device.
41
+ * @param device - the device buffers are created on
42
+ * @param thresholdBytes - the byte size from which createBuffer runs inside an out-of-memory scope (default OOM_SCOPE_THRESHOLD_BYTES)
43
+ */
44
+ constructor(device: GPUDevice, thresholdBytes?: number);
45
+ /**
46
+ * createBuffer with the scope rule; every buffer is labelled (an unlabelled descriptor becomes `buffer-<n>`).
47
+ * @param descriptor - the buffer descriptor
48
+ * @returns the buffer
49
+ */
50
+ createBuffer(descriptor: GPUBufferDescriptor): GPUBuffer;
51
+ /**
52
+ * Destroys a buffer created here and decrements `resident`; a buffer the tracker does not know is destroyed
53
+ * without touching the bookkeeping, so destroying twice is harmless.
54
+ * @param buffer - the buffer to destroy
55
+ */
56
+ destroy(buffer: GPUBuffer): void;
57
+ /**
58
+ * Awaits every outstanding scope pop; the first OOM -> E_OUT_OF_MEMORY { requested, resident, label }; later
59
+ * calls after a failure throw the same error again until `reset()`.
60
+ */
61
+ check(): Promise<void>;
62
+ /** Forgets a recorded OOM after the caller released what it allocated. */
63
+ reset(): void;
64
+ /**
65
+ * Bytes of live buffers created through this tracker.
66
+ * @returns the resident byte count
67
+ */
68
+ get resident(): number;
69
+ /**
70
+ * Number of live buffers created through this tracker.
71
+ * @returns the live buffer count
72
+ */
73
+ get liveBuffers(): number;
74
+ }
75
+ //# sourceMappingURL=error-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-scope.d.ts","sourceRoot":"","sources":["../../../src/device/error-scope.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAcnH;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,EAAE,CAW9F;AAED;;;;GAIG;AACH,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;IACnC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAgC;IACrD,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,OAAO,CAAiC;IAChD,OAAO,CAAC,MAAM,CAAK;IAEnB;;;;OAIG;gBACS,MAAM,EAAE,SAAS,EAAE,cAAc,CAAC,EAAE,MAAM;IAKtD;;;;OAIG;IACH,YAAY,CAAC,UAAU,EAAE,mBAAmB,GAAG,SAAS;IAqCxD;;;;OAIG;IACH,OAAO,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI;IAShC;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAU5B,0EAA0E;IAC1E,KAAK,IAAI,IAAI;IAIb;;;OAGG;IACH,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED;;;OAGG;IACH,IAAI,WAAW,IAAI,MAAM,CAExB;CACJ"}