@graphty/webgpu-graph-algorithms 0.0.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/README.md +344 -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,390 @@
1
+ /**
2
+ * The WGSL composer (spec 3.5; contract 3.9, 4.2): ONE declaration per module (`WgslModuleSpec`) generates
3
+ * everything the host and the shader must agree on -- the `@group / @binding` block, the `override` lines, the
4
+ * struct texts, the explicit bind-group layouts and the bind() record keys -- by string concatenation in the fixed
5
+ * order of contract 4.2. Every disagreement that would otherwise be a GPUPipelineError on the first device that
6
+ * creates the variant is a compose-time `E_SHADER_COMPILE { stage: "compose" }` on every device.
7
+ *
8
+ * PLAN DECISION: this file imports `workgroupSizeFor` from `../device/caps.js` (one copy of the WG rule) and
9
+ * `ShaderStage` from `../device/webgpu-constants.js` (spec 2.1 rule 1: the core never reads the `GPUShaderStage`
10
+ * global at module top level); `../constants.js` is not imported because every constant the composer emits reaches
11
+ * it through `./prelude.js`. The layer rule (contract 2.4: device < context < memory < kernel) allows both edges.
12
+ */
13
+ import { workgroupSizeFor } from "../device/caps.js";
14
+ import { ShaderStage } from "../device/webgpu-constants.js";
15
+ import { WebGpuGraphError } from "../errors.js";
16
+ import { PRELUDE_WGSL, REDUCE_HELPER_NAMES, REDUCE_HELPERS_SUBGROUP_WGSL, REDUCE_HELPERS_WORKGROUP_WGSL, WGSL_RESERVED_WORDS, wgslF32Literal, } from "./prelude.js";
17
+ /** The names the prelude declares as overrides; spec.overrides may set them without an OverrideDecl. */
18
+ export const STANDARD_OVERRIDES = ["WG", "USE_PERM", "HAS_WEIGHTS", "SUBGROUP_MIN", "SUBGROUP_MAX"];
19
+ /** The type of each standard override (the prelude's declarations). */
20
+ const STANDARD_OVERRIDE_TYPES = Object.freeze({
21
+ WG: "u32",
22
+ USE_PERM: "bool",
23
+ HAS_WEIGHTS: "bool",
24
+ SUBGROUP_MIN: "u32",
25
+ SUBGROUP_MAX: "u32",
26
+ });
27
+ /** The only feature a body may need (spec 3.5). */
28
+ const KNOWN_NEEDS = Object.freeze(["subgroups"]);
29
+ /** The smallest legal subgroup size; the scratch of 4.3 is sized by the MINIMUM size. */
30
+ const SUBGROUP_FLOOR = 4;
31
+ /** Builtin WGSL element types a binding may name without a struct declaration. */
32
+ const BUILTIN_TYPES = new Set([
33
+ "u32",
34
+ "i32",
35
+ "f32",
36
+ "f16",
37
+ "bool",
38
+ "vec2f",
39
+ "vec3f",
40
+ "vec4f",
41
+ "vec2u",
42
+ "vec3u",
43
+ "vec4u",
44
+ "vec2i",
45
+ "vec3i",
46
+ "vec4i",
47
+ "vec2h",
48
+ "vec3h",
49
+ "vec4h",
50
+ ]);
51
+ const TEMPLATED_BUILTIN = /^(vec[234]|mat[234]x[234]|atomic|array)</;
52
+ const IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
53
+ /** The `var<...>` form of each binding kind (contract 4.2). */
54
+ const ADDRESS_SPACE = Object.freeze({
55
+ storage: "var<storage, read_write>",
56
+ "storage-ro": "var<storage, read>",
57
+ uniform: "var<uniform>",
58
+ });
59
+ /** The reserved words as a set (the frozen list stays the public form). */
60
+ const RESERVED = new Set(WGSL_RESERVED_WORDS);
61
+ const MARKER = /\/\/@@([A-Za-z0-9_]+)@@/;
62
+ const IDENTIFIER_TOKENS = /(?<![A-Za-z0-9_])[A-Za-z_][A-Za-z0-9_]*/g;
63
+ const COMPUTE_ATTRIBUTE = /@compute\b/g;
64
+ const ENTRY_FN = /\bfn\s+([A-Za-z_][A-Za-z0-9_]*)/;
65
+ /**
66
+ * The compose-time error of contract 3.9.
67
+ * @param id - the module id
68
+ * @param slot - what failed (`override:<key>`, `snippet:<key>`, `marker:<name>`, `body:<text>`, `binding:<name>`, `type:<name>`, `needs:<feature>`, `helper:<name>`, `reserved:<word>`, `entry`)
69
+ * @param message - the human-readable reason
70
+ * @returns the error (thrown by the caller)
71
+ */
72
+ function composeError(id, slot, message) {
73
+ return new WebGpuGraphError("E_SHADER_COMPILE", `${id}: ${message}`, { id, stage: "compose", slot });
74
+ }
75
+ /**
76
+ * Removes block and line comments so a word inside a comment is never taken for an identifier.
77
+ * @param text - WGSL text
78
+ * @returns the text without comments
79
+ */
80
+ function stripComments(text) {
81
+ return text.replace(/\/\*[\s\S]*?\*\//g, " ").replace(/\/\/[^\n]*/g, "");
82
+ }
83
+ /**
84
+ * The struct a binding's element type names, or null for a builtin type.
85
+ * @param wgslType - the binding's type text ("array<u32>", "array<Fa2Partial>", "Fa2State")
86
+ * @returns the struct name or null
87
+ */
88
+ function structNameOf(wgslType) {
89
+ const trimmed = wgslType.trim();
90
+ const inner = trimmed.startsWith("array<")
91
+ ? trimmed.slice("array<".length).replace(/\s*(,[^>]*)?>\s*$/, "")
92
+ : trimmed;
93
+ if (BUILTIN_TYPES.has(inner) || TEMPLATED_BUILTIN.test(inner)) {
94
+ return null;
95
+ }
96
+ return inner;
97
+ }
98
+ /**
99
+ * Checks that an override value matches its declared type.
100
+ * PLAN DECISION: a value of the wrong type (a number for a bool, a bool / negative / fractional for a u32) is a
101
+ * compose-time `E_SHADER_COMPILE { slot: "override:<name>" }` instead of a GPUPipelineError on the first device.
102
+ * @param id - the module id
103
+ * @param name - the override name
104
+ * @param type - the declared type
105
+ * @param value - the value
106
+ */
107
+ function assertOverrideValue(id, name, type, value) {
108
+ const ok = type === "bool"
109
+ ? typeof value === "boolean"
110
+ : typeof value === "number" &&
111
+ Number.isFinite(value) &&
112
+ (type === "f32" || (Number.isInteger(value) && value >= 0));
113
+ if (!ok) {
114
+ throw composeError(id, `override:${name}`, `override ${name} (${type}) cannot take the value ${String(value)}`);
115
+ }
116
+ }
117
+ /**
118
+ * The WGSL literal of an override default (u32 literals carry the `u` suffix, f32 literals a decimal point, bools true / false).
119
+ * @param decl - the override
120
+ * @returns the literal text
121
+ */
122
+ function overrideLiteral(decl) {
123
+ if (decl.type === "bool") {
124
+ return decl.default ? "true" : "false";
125
+ }
126
+ const value = decl.default;
127
+ return decl.type === "u32" ? `${value}u` : wgslF32Literal(value);
128
+ }
129
+ /**
130
+ * The `var<...>` declaration of one binding (contract 4.2).
131
+ * @param decl - the binding
132
+ * @returns the declaration line
133
+ */
134
+ function bindingLine(decl) {
135
+ const space = ADDRESS_SPACE[decl.kind];
136
+ return `@group(${decl.group}) @binding(${decl.binding}) ${space} ${decl.name}: ${decl.wgslType};`;
137
+ }
138
+ /**
139
+ * The entry-point name of a body, or null when the body does not carry exactly one `@compute` attribute followed by `fn <name>`.
140
+ * @param body - the kernel body
141
+ * @returns the name or null
142
+ */
143
+ function findEntryPoint(body) {
144
+ const stripped = stripComments(body);
145
+ const matches = [...stripped.matchAll(COMPUTE_ATTRIBUTE)];
146
+ if (matches.length !== 1 || matches[0].index === undefined) {
147
+ return null;
148
+ }
149
+ const fn = ENTRY_FN.exec(stripped.slice(matches[0].index));
150
+ return fn === null ? null : fn[1];
151
+ }
152
+ /**
153
+ * The entry-point name of a body: the identifier after `fn` on the line following `@compute` (every body has exactly one entry point).
154
+ * PLAN DECISION: a body without exactly one `@compute` entry point is `E_SHADER_COMPILE { stage: "compose", slot: "entry" }`.
155
+ * @param body - the kernel body
156
+ * @returns the entry-point function name
157
+ */
158
+ export function entryPointOf(body) {
159
+ const name = findEntryPoint(body);
160
+ if (name === null) {
161
+ throw new WebGpuGraphError("E_SHADER_COMPILE", "a body must carry exactly one @compute attribute followed by `fn <name>`", {
162
+ id: null,
163
+ stage: "compose",
164
+ slot: "entry",
165
+ });
166
+ }
167
+ return name;
168
+ }
169
+ /**
170
+ * The bind-group-layout descriptors derived from spec.bindings: one per group 0..maxGroup (empty groups get an empty entry list); uniform decls carry hasDynamicOffset true (spec 5.1).
171
+ * PLAN DECISION: a uniform decl whose struct is one of `spec.uniforms` also carries `minBindingSize = block.byteLength`,
172
+ * so a wrong-size uniform binding fails at createBindGroup (synchronously, with the bind group's label in the message)
173
+ * instead of at the first dispatch (verified on Dawn 0.4.0: without it the error names only the pipeline).
174
+ * @param spec - the module
175
+ * @returns the descriptors in group order
176
+ */
177
+ export function bindGroupLayoutDescriptors(spec) {
178
+ const maxGroup = spec.bindings.reduce((acc, b) => Math.max(acc, b.group), -1);
179
+ const blocks = new Map(spec.uniforms.map((block) => [block.name, block]));
180
+ const descriptors = [];
181
+ for (let group = 0; group <= maxGroup; group++) {
182
+ const entries = spec.bindings
183
+ .filter((b) => b.group === group)
184
+ .sort((a, b) => a.binding - b.binding)
185
+ .map((b) => {
186
+ if (b.kind === "uniform") {
187
+ const block = blocks.get(b.wgslType);
188
+ const buffer = { type: "uniform", hasDynamicOffset: true };
189
+ if (block !== undefined) {
190
+ buffer.minBindingSize = block.byteLength;
191
+ }
192
+ return { binding: b.binding, visibility: ShaderStage.COMPUTE, buffer };
193
+ }
194
+ return {
195
+ binding: b.binding,
196
+ visibility: ShaderStage.COMPUTE,
197
+ buffer: { type: b.kind === "storage" ? "storage" : "read-only-storage" },
198
+ };
199
+ });
200
+ descriptors.push({ entries });
201
+ }
202
+ return descriptors;
203
+ }
204
+ /**
205
+ * The names of the bindings of one group in binding order.
206
+ * @param spec - the module
207
+ * @param group - the group index
208
+ * @returns the names
209
+ */
210
+ export function bindingNames(spec, group) {
211
+ return spec.bindings
212
+ .filter((b) => b.group === group)
213
+ .sort((a, b) => a.binding - b.binding)
214
+ .map((b) => b.name);
215
+ }
216
+ /**
217
+ * Validates `spec.needs`, `spec.overrideDecls`, `spec.overrides` and `spec.bindings` (contract 3.9's compose-time checks).
218
+ * PLAN DECISION: an `overrideDecls` entry that redeclares a standard override, repeats a name or names a reserved
219
+ * word is `E_SHADER_COMPILE { slot: "override:<name>" }` (otherwise a duplicate-declaration error on the first device).
220
+ * @param spec - the module
221
+ */
222
+ function validateDeclarations(spec) {
223
+ const { id } = spec;
224
+ for (const need of spec.needs) {
225
+ if (!KNOWN_NEEDS.includes(need)) {
226
+ throw composeError(id, `needs:${need}`, `unknown feature "${need}" in needs`);
227
+ }
228
+ }
229
+ const declared = new Map();
230
+ for (const decl of spec.overrideDecls) {
231
+ if (!IDENTIFIER.test(decl.name) || RESERVED.has(decl.name)) {
232
+ throw composeError(id, `override:${decl.name}`, `override name "${decl.name}" is not a usable identifier`);
233
+ }
234
+ if (STANDARD_OVERRIDES.includes(decl.name) || declared.has(decl.name)) {
235
+ throw composeError(id, `override:${decl.name}`, `override "${decl.name}" is declared twice (the prelude declares the standard ones)`);
236
+ }
237
+ assertOverrideValue(id, decl.name, decl.type, decl.default);
238
+ declared.set(decl.name, decl.type);
239
+ }
240
+ for (const [key, value] of Object.entries(spec.overrides)) {
241
+ const standard = STANDARD_OVERRIDE_TYPES[key];
242
+ const type = standard ?? declared.get(key);
243
+ if (type === undefined) {
244
+ throw composeError(id, `override:${key}`, `override "${key}" is neither a standard override nor declared in overrideDecls`);
245
+ }
246
+ assertOverrideValue(id, key, type, value);
247
+ }
248
+ const slots = new Set();
249
+ const names = new Set();
250
+ const blocks = new Set(spec.uniforms.map((block) => block.name));
251
+ for (const b of spec.bindings) {
252
+ if (!IDENTIFIER.test(b.name) || RESERVED.has(b.name)) {
253
+ throw composeError(id, `binding:${b.name}`, `binding name "${b.name}" is not a usable identifier`);
254
+ }
255
+ const slot = `${b.group}.${b.binding}`;
256
+ if (slots.has(slot)) {
257
+ throw composeError(id, `binding:${b.name}`, `two bindings share group ${b.group} binding ${b.binding}`);
258
+ }
259
+ if (names.has(b.name)) {
260
+ throw composeError(id, `binding:${b.name}`, `two bindings share the name "${b.name}"`);
261
+ }
262
+ slots.add(slot);
263
+ names.add(b.name);
264
+ const struct = structNameOf(b.wgslType);
265
+ if (struct !== null && !blocks.has(struct)) {
266
+ throw composeError(id, `type:${struct}`, `binding "${b.name}" names struct "${struct}" but no block in spec.uniforms declares it`);
267
+ }
268
+ }
269
+ }
270
+ /**
271
+ * Substitutes the snippets into the body (every `//@@NAME@@` marker replaced by `spec.snippets[NAME]`) and checks the markers.
272
+ * @param spec - the module
273
+ * @returns the substituted body
274
+ */
275
+ function substituteSnippets(spec) {
276
+ const { id } = spec;
277
+ let { body } = spec;
278
+ for (const [key, snippet] of Object.entries(spec.snippets ?? {})) {
279
+ const marker = `//@@${key}@@`;
280
+ if (!body.includes(marker)) {
281
+ throw composeError(id, `snippet:${key}`, `snippet "${key}" has no ${marker} marker in the body`);
282
+ }
283
+ body = body.split(marker).join(snippet);
284
+ }
285
+ const left = MARKER.exec(body);
286
+ if (left !== null) {
287
+ throw composeError(id, `marker:${left[1]}`, `marker //@@${left[1]}@@ is not filled by any snippet`);
288
+ }
289
+ return body;
290
+ }
291
+ /**
292
+ * The textual checks on the substituted body: no `@group(`, no `override `, no reserved identifier, no helper call without `needs`.
293
+ * PLAN DECISION: a body calling a `wg_reduce_*` helper without `needs: ["subgroups"]` is
294
+ * `E_SHADER_COMPILE { slot: "helper:<name>" }` (otherwise an unresolved identifier on the first device).
295
+ * @param spec - the module
296
+ * @param body - the substituted body
297
+ */
298
+ function validateBody(spec, body) {
299
+ const { id } = spec;
300
+ for (const forbidden of ["@group(", "override "]) {
301
+ if (body.includes(forbidden)) {
302
+ throw composeError(id, `body:${forbidden}`, `a body must not contain "${forbidden}" (the composer emits those lines)`);
303
+ }
304
+ }
305
+ const stripped = stripComments(body);
306
+ const helpers = REDUCE_HELPER_NAMES;
307
+ for (const match of stripped.matchAll(IDENTIFIER_TOKENS)) {
308
+ const word = match[0];
309
+ if (RESERVED.has(word)) {
310
+ throw composeError(id, `reserved:${word}`, `"${word}" is a WGSL reserved word (spec 16.2) and cannot be an identifier`);
311
+ }
312
+ if (helpers.includes(word) && !spec.needs.includes("subgroups")) {
313
+ throw composeError(id, `helper:${word}`, `the body calls ${word} but spec.needs does not list "subgroups"`);
314
+ }
315
+ }
316
+ }
317
+ /**
318
+ * String concatenation of spec 3.5: prelude (constants, standard overrides, helpers), module overrides, struct texts, the bind declarations, then the body with snippets substituted (4.2 gives the exact emitted format).
319
+ * @param spec - the module
320
+ * @param caps - the device capabilities (WG, the subgroup sizes and the feature set)
321
+ * @returns the composed module
322
+ */
323
+ export function composeWgsl(spec, caps) {
324
+ validateDeclarations(spec);
325
+ const entryPoint = findEntryPoint(spec.body);
326
+ if (entryPoint === null) {
327
+ throw composeError(spec.id, "entry", "a body must carry exactly one @compute attribute followed by `fn <name>`");
328
+ }
329
+ const body = substituteSnippets(spec);
330
+ validateBody(spec, body);
331
+ const wantsHelpers = spec.needs.includes("subgroups");
332
+ const subgroups = wantsHelpers && caps.features.has("subgroups");
333
+ const overrides = { ...spec.overrides };
334
+ if (overrides.WG === undefined) {
335
+ overrides.WG = workgroupSizeFor(caps);
336
+ }
337
+ if (subgroups) {
338
+ overrides.SUBGROUP_MAX = caps.subgroupMaxSize;
339
+ overrides.SUBGROUP_MIN = Math.max(SUBGROUP_FLOOR, caps.subgroupMinSize);
340
+ }
341
+ const parts = [];
342
+ if (subgroups) {
343
+ parts.push("enable subgroups;");
344
+ }
345
+ parts.push(PRELUDE_WGSL);
346
+ for (const decl of spec.overrideDecls) {
347
+ parts.push(`override ${decl.name}: ${decl.type} = ${overrideLiteral(decl)};`);
348
+ }
349
+ for (const block of spec.uniforms) {
350
+ parts.push(block.wgsl);
351
+ }
352
+ if (wantsHelpers) {
353
+ parts.push(subgroups ? REDUCE_HELPERS_SUBGROUP_WGSL : REDUCE_HELPERS_WORKGROUP_WGSL);
354
+ }
355
+ for (const decl of spec.bindings) {
356
+ parts.push(bindingLine(decl));
357
+ }
358
+ const head = parts.join("\n");
359
+ const code = `${head}\n${body}`;
360
+ return Object.freeze({
361
+ id: spec.id,
362
+ code,
363
+ bodyLine: head.split("\n").length + 1,
364
+ overrides: Object.freeze(overrides),
365
+ constants: Object.freeze(referencedOverrides(code, overrides)),
366
+ entryPoint,
367
+ subgroups,
368
+ });
369
+ }
370
+ /**
371
+ * The overrides whose names occur in the code outside comments and outside their own `override` declaration lines
372
+ * (the constants a pipeline may carry on every backend, see ComposedModule.constants).
373
+ * @param code - the composed module text
374
+ * @param overrides - the effective override values
375
+ * @returns the referenced subset, in the same order
376
+ */
377
+ function referencedOverrides(code, overrides) {
378
+ const stripped = code
379
+ .replace(/\/\*[\s\S]*?\*\//g, " ")
380
+ .replace(/\/\/[^\n]*/g, " ")
381
+ .replace(/^\s*override\s+\w+\s*:[^\n]*$/gm, " ");
382
+ const referenced = {};
383
+ for (const [name, value] of Object.entries(overrides)) {
384
+ if (new RegExp(`\\b${name}\\b`).test(stripped)) {
385
+ referenced[name] = value;
386
+ }
387
+ }
388
+ return referenced;
389
+ }
390
+ //# sourceMappingURL=wgsl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wgsl.js","sourceRoot":"","sources":["../../../src/kernel/wgsl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,EACH,YAAY,EACZ,mBAAmB,EACnB,4BAA4B,EAC5B,6BAA6B,EAC7B,mBAAmB,EACnB,cAAc,GACjB,MAAM,cAAc,CAAC;AA4BtB,wGAAwG;AACxG,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,CAAU,CAAC;AAkB7G,uEAAuE;AACvE,MAAM,uBAAuB,GACzB,MAAM,CAAC,MAAM,CAAC;IACV,EAAE,EAAE,KAAK;IACT,QAAQ,EAAE,MAAM;IAChB,WAAW,E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D,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACpD,IAAI,IAAI,MAAM,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC7C,UAAU,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QAC7B,CAAC;IACL,CAAC;IACD,OAAO,UAAU,CAAC;AACtB,CAAC"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * THE kernel registry (spec 3.5; contract 3.10): every WGSL module the package compiles, keyed by id, with the
3
+ * binding table, the override declarations, the generated uniform / storage blocks and the feature needs from
4
+ * which src/kernel/wgsl.ts emits the bind declarations and src/kernel/pipeline-cache.ts derives the explicit
5
+ * bind-group layouts. A variant cannot exist without an entry here: the compile tests, the bind-group-budget
6
+ * test and PipelineCache.warm() iterate this table. P1-T4 lands degree, reduce, fill, fa2-repulsion-exact (K3)
7
+ * and fa2-speed-finalize (K4) together with every generated block of contract 3.10.2; P2-T2 lands
8
+ * segmented-reduce; P3-T2 adds fa2-stats-finalize (K1), fa2-attraction (K2), fa2-integrate (K5) and
9
+ * fa2-to-scene. This file is the only importer of src/wgsl/** (spec 3.2; test/layers.test.ts).
10
+ */
11
+ import { UniformBlock } from "./kernel/struct-block.js";
12
+ import { type BindingDecl, type OverrideDecl, type WgslModuleSpec } from "./kernel/wgsl.js";
13
+ import { type CoreBinding } from "./memory/residency.js";
14
+ import { type Binding } from "./types/memory.js";
15
+ /** Every module id of P1-P3 (P4+ ids are appended, never renamed). */
16
+ export type KernelId = "degree" | "reduce" | "fill" | "segmented-reduce" | "fa2-stats-finalize" | "fa2-attraction" | "fa2-repulsion-exact" | "fa2-speed-finalize" | "fa2-integrate" | "fa2-to-scene";
17
+ /** One registry entry: everything of a WgslModuleSpec except the per-variant overrides and snippets. */
18
+ export interface KernelEntry {
19
+ readonly id: KernelId;
20
+ readonly body: string;
21
+ readonly entryPoint: string;
22
+ readonly bindings: readonly BindingDecl[];
23
+ readonly overrideDecls: readonly OverrideDecl[];
24
+ readonly uniforms: readonly UniformBlock[];
25
+ /** ["subgroups"] when the body calls a reduction helper (the twin axis), else []. */
26
+ readonly needs: readonly "subgroups"[];
27
+ /** The snippet marker names the body carries (segmented-reduce: ["VALUE"]). */
28
+ readonly snippetSlots: readonly string[];
29
+ /** The phase the entry landed in (documentation and the compile-matrix filter). */
30
+ readonly phase: "P1" | "P2" | "P3";
31
+ }
32
+ /** `RangeParams` (uniform, 32 B): rows `[start, end)` @0 / @4 of the dispatch, the bound arc window `[arcBase, arcEnd)` @8 / @12 (0 and arcCount when not windowed), `accumulate` @16 (1 combines into `out[i]` instead of overwriting: the P4 windowed loop), `n` @20 (the node count that bounds neighbour indices), `pad0` @24, `pad1` @28. */
33
+ export declare const RANGE_PARAMS: UniformBlock;
34
+ /** `ReduceParams` (uniform, 16 B): `count` @0 elements of the level, `outOffset` @4 (the element index the level writes at), `level` @8, `pad0` @12. */
35
+ export declare const REDUCE_PARAMS: UniformBlock;
36
+ /** `FillParams` (uniform, 16 B): `count` @0 words, `value` @4, `mode` @8 (0 = the constant `value`, 1 = iota `i + value`), `pad0` @12. */
37
+ export declare const FILL_PARAMS: UniformBlock;
38
+ /** `Fa2Params` (uniform, 96 B; spec 7.3): the per-iteration ForceAtlas2 parameters -- `n` @0, `dim` @4, `flags` @8 (bit 0 = FA2_FLAG_FIRST), `tierStart` @12, `tierEnd` @16, `iterationIndex` @20, `seed` @24, `nearMax` @28, `scalingRatio` @32, `gravity` @36, `jitterTolerance` @40, `scale` @44, `center` @48 (xyz, w 0), `settleThreshold` @64, `extentFactor` @68, `gridMax` @72, `levels` @76, `pad` @80 (reserved for the P4 GridSpec). */
39
+ export declare const FA2_PARAMS: UniformBlock;
40
+ /** `Fa2State` (storage, padded to STATE_HEADER_BYTES = 256; spec 7.3): the device-resident controller state the finalize kernels write and the host reads back for stats -- `speed` @0, `speedEfficiency` @4, `swing` @8, `traction` @12, `centroid` @16, `rmsRadius` @32, `radius` @36, `meanDisplacement` @40, `iteration` @44, `min` @48, `max` @64, `gridMin` @80 (P4), `eps` @96 (P4), `settledCount` @100, `outsideGrid` @104 (P4), `maxCellOccupancy` @108 (P4), `reserved0` .. `reserved8` @112 .. @240. */
41
+ export declare const FA2_STATE: UniformBlock;
42
+ /** `Fa2Trace` (storage record, 32 B; spec 7.3): one per-iteration trace record -- `swing` @0, `traction` @4, `speed` @8, `speedEfficiency` @12 (written by K4), `meanDisplacement` @16, `settledCount` @20, `iteration` @24 (written by K1), `pad0` @28; the trace region is `array<Fa2Trace>` at byte offset STATE_HEADER_BYTES of the state buffer. */
43
+ export declare const FA2_TRACE: UniformBlock;
44
+ /** `Fa2Partial` (storage record, 64 B; spec 7.3): one per-workgroup partial -- `sum` @0 (xyz = sum of positions, w = sum of |p - centroid|^2), `min` @16, `max` @32 (w = max of |p - centroid|^2, the exact layoutRadius source), written by K5; `swingTraction` @48 (written by K3's epilogue); `dispFree` @56 (x = sum |dp| over free rows, y = the free count as an f32 <= 256, written by K5). */
45
+ export declare const FA2_PARTIAL: UniformBlock;
46
+ /** THE registry (spec 3.5): every entry, keyed by id. */
47
+ export declare const KERNELS: Readonly<Record<KernelId, KernelEntry>>;
48
+ /**
49
+ * A WgslModuleSpec for a variant: the entry plus the overrides / snippets given; unknown override names are
50
+ * rejected at compose time. A body override installed by setKernelBodyOverride is used instead of the entry's
51
+ * body.
52
+ * @param id - the module id
53
+ * @param overrides - the override values of this variant (the five standard names and the entry's overrideDecls)
54
+ * @param snippets - the texts substituted at the body's `//@@NAME@@` markers
55
+ * @returns the spec the PipelineCache compiles
56
+ */
57
+ export declare function kernelSpec(id: KernelId, overrides?: Readonly<Record<string, number | boolean>>, snippets?: Readonly<Record<string, string>>): WgslModuleSpec;
58
+ /**
59
+ * The group-0 graph bindings of a core with the dummy rules applied (spec 3.5, 4.1): colIdx <- rowPtr when null,
60
+ * weights <- colIdx ?? rowPtr when null, perm <- rowPtr when null. `weights` is the binding to use in the weights
61
+ * slot: omitted -> core.weights (degree, segmented-reduce); a layout passes its RESOLVED weights
62
+ * (ModelResources.weights, 3.13), null meaning "attract with 1.0" even on a weighted snapshot.
63
+ * @param core - the resident core arrays of a snapshot
64
+ * @param perm - the degreeOrder row permutation, or null (rowPtr is bound as the dummy)
65
+ * @param weights - the weights binding to use; undefined takes the core's, null binds the colIdx dummy
66
+ * @returns the four bindings in slot order
67
+ */
68
+ export declare function graphBindings(core: CoreBinding, perm: Binding | null, weights?: Binding | null): Readonly<Record<"rowPtr" | "colIdx" | "weights" | "perm", Binding>>;
69
+ /**
70
+ * The override values graphBindings implies: USE_PERM = perm !== null, HAS_WEIGHTS = (weights === undefined ?
71
+ * core.weights : weights) !== null.
72
+ * @param core - the resident core arrays of a snapshot
73
+ * @param perm - the row permutation binding, or null
74
+ * @param weights - the weights binding to use; undefined takes the core's, null means "unweighted"
75
+ * @returns the two standard override values of the variant
76
+ */
77
+ export declare function graphOverrides(core: CoreBinding, perm: Binding | null, weights?: Binding | null): Readonly<{
78
+ USE_PERM: boolean;
79
+ HAS_WEIGHTS: boolean;
80
+ }>;
81
+ //# sourceMappingURL=kernels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kernels.d.ts","sourceRoot":"","sources":["../../src/kernels.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC5F,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAYjD,sEAAsE;AACtE,MAAM,MAAM,QAAQ,GACd,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,kBAAkB,GAClB,oBAAoB,G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