ultra-text 1.0.2 → 1.0.3

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 (206) hide show
  1. package/README.md +193 -115
  2. package/dist/assets/{cpuSdf.worker--X1Qpmdp.js → cpuSdf.worker-Dy4P5_TI.js} +98 -43
  3. package/dist/assets/cpuSdf.worker-Dy4P5_TI.js.map +1 -0
  4. package/dist/assets/traceOutline.worker-B5uVKmR4.js +1725 -0
  5. package/dist/assets/traceOutline.worker-B5uVKmR4.js.map +1 -0
  6. package/dist/atlas/appendAtlas.js +35 -11
  7. package/dist/atlas/appendAtlas.js.map +1 -1
  8. package/dist/atlas/buildAtlas.js +1 -1
  9. package/dist/atlas/buildAtlas.js.map +1 -1
  10. package/dist/atlas/colorGlyphs.d.ts +0 -10
  11. package/dist/atlas/colorGlyphs.js +97 -155
  12. package/dist/atlas/colorGlyphs.js.map +1 -1
  13. package/dist/atlas/colorTexture.d.ts +1 -0
  14. package/dist/atlas/colorTexture.js +64 -0
  15. package/dist/atlas/colorTexture.js.map +1 -0
  16. package/dist/atlas/cpuAtlas.js +8 -3
  17. package/dist/atlas/cpuAtlas.js.map +1 -1
  18. package/dist/atlas/cpuSdf.d.ts +1 -1
  19. package/dist/atlas/cpuSdf.js +97 -42
  20. package/dist/atlas/cpuSdf.js.map +1 -1
  21. package/dist/atlas/cpuWorker.d.ts +10 -4
  22. package/dist/atlas/cpuWorker.js +99 -49
  23. package/dist/atlas/cpuWorker.js.map +1 -1
  24. package/dist/atlas/gpuAtlas.js +133 -56
  25. package/dist/atlas/gpuAtlas.js.map +1 -1
  26. package/dist/atlas/gpuCommon.d.ts +140 -18
  27. package/dist/atlas/gpuCommon.js +726 -104
  28. package/dist/atlas/gpuCommon.js.map +1 -1
  29. package/dist/atlas/jfaWgsl.d.ts +1 -1
  30. package/dist/atlas/jfaWgsl.js +232 -61
  31. package/dist/atlas/jfaWgsl.js.map +1 -1
  32. package/dist/atlas/rasterize.d.ts +22 -0
  33. package/dist/atlas/rasterize.js +237 -111
  34. package/dist/atlas/rasterize.js.map +1 -1
  35. package/dist/atlas/vanillaCore.js +156 -103
  36. package/dist/atlas/vanillaCore.js.map +1 -1
  37. package/dist/atlas/vanillaCpuAtlas.js +37 -52
  38. package/dist/atlas/vanillaCpuAtlas.js.map +1 -1
  39. package/dist/atlas/vanillaExtras.js +91 -90
  40. package/dist/atlas/vanillaExtras.js.map +1 -1
  41. package/dist/atlas/vanillaGpuHelpers.d.ts +70 -7
  42. package/dist/atlas/vanillaGpuHelpers.js +262 -27
  43. package/dist/atlas/vanillaGpuHelpers.js.map +1 -1
  44. package/dist/dom/DomSdf.js +85 -79
  45. package/dist/dom/DomSdf.js.map +1 -1
  46. package/dist/dom/DomSlug.js +23 -18
  47. package/dist/dom/DomSlug.js.map +1 -1
  48. package/dist/dom/Text.d.ts +4 -1
  49. package/dist/dom/Text.js +5 -1
  50. package/dist/dom/Text.js.map +1 -1
  51. package/dist/dom/browserShaping.js +31 -14
  52. package/dist/dom/browserShaping.js.map +1 -1
  53. package/dist/dom/clusters.js +13 -2
  54. package/dist/dom/clusters.js.map +1 -1
  55. package/dist/dom/cssEffects.d.ts +4 -0
  56. package/dist/dom/cssEffects.js +72 -0
  57. package/dist/dom/cssEffects.js.map +1 -0
  58. package/dist/dom/domAnalytic.d.ts +1 -2
  59. package/dist/dom/domAnalytic.js +1 -1
  60. package/dist/dom/domAnalytic.js.map +1 -1
  61. package/dist/dom/fontCanvas.d.ts +16 -0
  62. package/dist/dom/fontCanvas.js +4 -4
  63. package/dist/dom/fontCanvas.js.map +1 -1
  64. package/dist/dom/layoutSignature.js +28 -12
  65. package/dist/dom/layoutSignature.js.map +1 -1
  66. package/dist/dom/markup.d.ts +10 -0
  67. package/dist/dom/markup.js +16 -1
  68. package/dist/dom/markup.js.map +1 -1
  69. package/dist/dom/pretextLayout.js +27 -19
  70. package/dist/dom/pretextLayout.js.map +1 -1
  71. package/dist/dom/snapshot.d.ts +4 -0
  72. package/dist/dom/snapshot.js +747 -505
  73. package/dist/dom/snapshot.js.map +1 -1
  74. package/dist/dom/snapshotsEqual.d.ts +7 -0
  75. package/dist/dom/snapshotsEqual.js +68 -0
  76. package/dist/dom/snapshotsEqual.js.map +1 -0
  77. package/dist/dom/svgCapture.js +30 -27
  78. package/dist/dom/svgCapture.js.map +1 -1
  79. package/dist/dom/textTransform.d.ts +13 -1
  80. package/dist/dom/textTransform.js +31 -13
  81. package/dist/dom/textTransform.js.map +1 -1
  82. package/dist/dom/tone.js +15 -8
  83. package/dist/dom/tone.js.map +1 -1
  84. package/dist/slug/SlugMaterial.d.ts +6 -0
  85. package/dist/slug/SlugMaterial.js +48 -20
  86. package/dist/slug/SlugMaterial.js.map +1 -1
  87. package/dist/slug/cff.d.ts +5 -0
  88. package/dist/slug/cff.js +780 -0
  89. package/dist/slug/cff.js.map +1 -0
  90. package/dist/slug/coverage.d.ts +3 -3
  91. package/dist/slug/coverage.js +283 -101
  92. package/dist/slug/coverage.js.map +1 -1
  93. package/dist/slug/preprocessCore.d.ts +1 -1
  94. package/dist/slug/preprocessCore.js +100 -80
  95. package/dist/slug/preprocessCore.js.map +1 -1
  96. package/dist/slug/runtime.js +32 -39
  97. package/dist/slug/runtime.js.map +1 -1
  98. package/dist/slug/standaloneRuntime.js +47 -37
  99. package/dist/slug/standaloneRuntime.js.map +1 -1
  100. package/dist/slug/truetype.d.ts +14 -6
  101. package/dist/slug/truetype.js +190 -62
  102. package/dist/slug/truetype.js.map +1 -1
  103. package/dist/slug/vanillaCore.d.ts +74 -4
  104. package/dist/slug/vanillaCore.js +226 -217
  105. package/dist/slug/vanillaCore.js.map +1 -1
  106. package/dist/slug-vanilla.d.ts +1 -1
  107. package/dist/slug-vanilla.js +5 -4
  108. package/dist/slug.d.ts +1 -1
  109. package/dist/slug.js +3 -3
  110. package/dist/text/GlyphTextMaterial.d.ts +5 -0
  111. package/dist/text/GlyphTextMaterial.js +11 -7
  112. package/dist/text/GlyphTextMaterial.js.map +1 -1
  113. package/dist/text/RectMaterial.js +6 -10
  114. package/dist/text/RectMaterial.js.map +1 -1
  115. package/dist/text/SdfTextMaterial.d.ts +9 -3
  116. package/dist/text/SdfTextMaterial.js +122 -37
  117. package/dist/text/SdfTextMaterial.js.map +1 -1
  118. package/dist/text/decorations.d.ts +7 -2
  119. package/dist/text/decorations.js +187 -96
  120. package/dist/text/decorations.js.map +1 -1
  121. package/dist/text/geometryUtils.d.ts +5 -0
  122. package/dist/text/geometryUtils.js +63 -9
  123. package/dist/text/geometryUtils.js.map +1 -1
  124. package/dist/text/glyphGeometry.d.ts +1 -1
  125. package/dist/text/glyphGeometry.js +281 -200
  126. package/dist/text/glyphGeometry.js.map +1 -1
  127. package/dist/text/rectGeometry.js +46 -42
  128. package/dist/text/rectGeometry.js.map +1 -1
  129. package/dist/text/reflow.d.ts +5 -0
  130. package/dist/text/reflow.js +127 -68
  131. package/dist/text/reflow.js.map +1 -1
  132. package/dist/text/snap.d.ts +15 -1
  133. package/dist/text/snap.js +1 -1
  134. package/dist/text/snap.js.map +1 -1
  135. package/dist/text/tone.js +2 -2
  136. package/dist/text/tone.js.map +1 -1
  137. package/dist/types.d.ts +23 -7
  138. package/dist/vanilla.js +1 -1
  139. package/dist/windfoil/WindfoilCompositeMaterial.d.ts +1 -1
  140. package/dist/windfoil/WindfoilCompositeMaterial.js +10 -3
  141. package/dist/windfoil/WindfoilCompositeMaterial.js.map +1 -1
  142. package/dist/windfoil/WindfoilMaterial.d.ts +12 -5
  143. package/dist/windfoil/WindfoilMaterial.js +71 -8
  144. package/dist/windfoil/WindfoilMaterial.js.map +1 -1
  145. package/dist/windfoil/compositeGeometry.js +12 -5
  146. package/dist/windfoil/compositeGeometry.js.map +1 -1
  147. package/dist/windfoil/coverage.d.ts +10 -2
  148. package/dist/windfoil/coverage.js +147 -59
  149. package/dist/windfoil/coverage.js.map +1 -1
  150. package/dist/windfoil/geometry.d.ts +15 -0
  151. package/dist/windfoil/geometry.js +154 -64
  152. package/dist/windfoil/geometry.js.map +1 -1
  153. package/dist/windfoil/layerGrid.js +8 -8
  154. package/dist/windfoil/layerGrid.js.map +1 -1
  155. package/dist/windfoil/mixed.js +13 -4
  156. package/dist/windfoil/mixed.js.map +1 -1
  157. package/dist/windfoil/preprocess.js +2 -2
  158. package/dist/windfoil/preprocessCore.d.ts +1 -0
  159. package/dist/windfoil/preprocessCore.js +63 -36
  160. package/dist/windfoil/preprocessCore.js.map +1 -1
  161. package/dist/windfoil/requests.d.ts +1 -1
  162. package/dist/windfoil/requests.js +11 -4
  163. package/dist/windfoil/requests.js.map +1 -1
  164. package/dist/windfoil/resolveOutline.d.ts +9 -0
  165. package/dist/windfoil/resolveOutline.js +20 -0
  166. package/dist/windfoil/resolveOutline.js.map +1 -0
  167. package/dist/windfoil/runtime.d.ts +1 -0
  168. package/dist/windfoil/runtime.js +8 -24
  169. package/dist/windfoil/runtime.js.map +1 -1
  170. package/dist/windfoil/shapeGeometry.js +80 -34
  171. package/dist/windfoil/shapeGeometry.js.map +1 -1
  172. package/dist/windfoil/sizeSwitch.d.ts +1 -1
  173. package/dist/windfoil/sizeSwitch.js +13 -8
  174. package/dist/windfoil/sizeSwitch.js.map +1 -1
  175. package/dist/windfoil/storage.d.ts +23 -9
  176. package/dist/windfoil/storage.js +49 -30
  177. package/dist/windfoil/storage.js.map +1 -1
  178. package/dist/windfoil/svg/curves.d.ts +20 -0
  179. package/dist/windfoil/svg/curves.js +145 -42
  180. package/dist/windfoil/svg/curves.js.map +1 -1
  181. package/dist/windfoil/svg/document.js +10 -1
  182. package/dist/windfoil/svg/document.js.map +1 -1
  183. package/dist/windfoil/svg/pathConverter.js +66 -50
  184. package/dist/windfoil/svg/pathConverter.js.map +1 -1
  185. package/dist/windfoil/svg/pathData.d.ts +9 -0
  186. package/dist/windfoil/svg/pathData.js +142 -109
  187. package/dist/windfoil/svg/pathData.js.map +1 -1
  188. package/dist/windfoil/svg/winding.js +34 -10
  189. package/dist/windfoil/svg/winding.js.map +1 -1
  190. package/dist/windfoil/trace/contours.js +120 -50
  191. package/dist/windfoil/trace/contours.js.map +1 -1
  192. package/dist/windfoil/trace/fit.js +578 -224
  193. package/dist/windfoil/trace/fit.js.map +1 -1
  194. package/dist/windfoil/trace/traceOutline.worker.d.ts +24 -0
  195. package/dist/windfoil/trace/traceWorker.d.ts +13 -0
  196. package/dist/windfoil/trace/traceWorker.js +192 -0
  197. package/dist/windfoil/trace/traceWorker.js.map +1 -0
  198. package/dist/windfoil/tracedOutlines.d.ts +2 -0
  199. package/dist/windfoil/tracedOutlines.js +335 -70
  200. package/dist/windfoil/tracedOutlines.js.map +1 -1
  201. package/package.json +48 -29
  202. package/skills/ultra-text/SKILL.md +9 -10
  203. package/skills/ultra-text/references/frameworks.md +46 -2
  204. package/skills/ultra-text/references/three-tsl.md +26 -24
  205. package/skills/ultra-text/references/vanilla-webgpu.md +3 -1
  206. package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +0 -1
@@ -1,4 +1,5 @@
1
- import { MIP_WGSL } from "./jfaWgsl.js";
1
+ import { MIP_SPD_WGSL, MIP_WGSL } from "./jfaWgsl.js";
2
+ import { encodeGpuColorBleed } from "./gpuCommon.js";
2
3
  // src/atlas/vanillaGpuHelpers.ts
3
4
  function resolveGpuDevice(source) {
4
5
  if (!source || typeof source !== "object") return null;
@@ -26,12 +27,31 @@ var vanillaMipPipelines = /* @__PURE__ */ new WeakMap();
26
27
  function getDeviceMipPipeline(device, format) {
27
28
  let cached = vanillaMipPipelines.get(device);
28
29
  if (!cached) {
30
+ let groupLayout = null;
31
+ let pipelineLayout = "auto";
32
+ if (typeof device.createBindGroupLayout === "function" && typeof device.createPipelineLayout === "function") {
33
+ groupLayout = device.createBindGroupLayout({ entries: [{
34
+ binding: 0,
35
+ visibility: 2,
36
+ texture: {
37
+ sampleType: "float",
38
+ viewDimension: "2d"
39
+ }
40
+ }, {
41
+ binding: 1,
42
+ visibility: 2,
43
+ sampler: { type: "filtering" }
44
+ }] });
45
+ pipelineLayout = device.createPipelineLayout({ bindGroupLayouts: [groupLayout] });
46
+ }
29
47
  cached = {
30
48
  module: device.createShaderModule({ code: MIP_WGSL }),
31
49
  sampler: device.createSampler({
32
50
  minFilter: "linear",
33
51
  magFilter: "linear"
34
- })
52
+ }),
53
+ groupLayout,
54
+ pipelineLayout
35
55
  };
36
56
  vanillaMipPipelines.set(device, cached);
37
57
  }
@@ -39,7 +59,7 @@ function getDeviceMipPipeline(device, format) {
39
59
  let pipeline = cached[key];
40
60
  if (!pipeline) {
41
61
  pipeline = device.createRenderPipeline({
42
- layout: "auto",
62
+ layout: cached.pipelineLayout,
43
63
  vertex: {
44
64
  module: cached.module,
45
65
  entryPoint: "mipVert"
@@ -54,26 +74,30 @@ function getDeviceMipPipeline(device, format) {
54
74
  }
55
75
  return {
56
76
  pipeline,
57
- sampler: cached.sampler
77
+ sampler: cached.sampler,
78
+ layout: cached.groupLayout ?? pipeline.getBindGroupLayout(0)
58
79
  };
59
80
  }
60
- function encodeMipmapChain(device, encoder, texture, mipLevelCount, pipeline, sampler) {
81
+ function encodeMipmapChain(device, encoder, texture, mipLevelCount, pipeline, sampler, layout = pipeline.getBindGroupLayout(0)) {
82
+ if (mipLevelCount <= 1) return;
61
83
  const view = (baseMipLevel) => texture.createView({
62
84
  baseMipLevel,
63
85
  mipLevelCount: 1
64
86
  });
87
+ let source = view(0);
65
88
  for (let level = 1; level < mipLevelCount; level++) {
89
+ const target = view(level);
66
90
  const pass = encoder.beginRenderPass({ colorAttachments: [{
67
- view: view(level),
91
+ view: target,
68
92
  loadOp: "clear",
69
93
  storeOp: "store"
70
94
  }] });
71
95
  pass.setPipeline(pipeline);
72
96
  pass.setBindGroup(0, device.createBindGroup({
73
- layout: pipeline.getBindGroupLayout(0),
97
+ layout,
74
98
  entries: [{
75
99
  binding: 0,
76
- resource: view(level - 1)
100
+ resource: source
77
101
  }, {
78
102
  binding: 1,
79
103
  resource: sampler
@@ -81,30 +105,241 @@ function encodeMipmapChain(device, encoder, texture, mipLevelCount, pipeline, sa
81
105
  }));
82
106
  pass.draw(3);
83
107
  pass.end();
108
+ source = target;
84
109
  }
85
110
  }
86
- function createGpuColorLayer(device, width, band, mipmaps) {
87
- const textures = texUsageOf();
88
- const mipLevelCount = mipCount(width, band.height, mipmaps);
89
- const gpuTexture = device.createTexture({
90
- size: [width, band.height],
111
+ var vanillaSpdPipelines = /* @__PURE__ */ new WeakMap();
112
+ function canUseSpdMips(device, directStore, workgroupDim) {
113
+ const texUsage = texUsageOf();
114
+ return directStore && workgroupDim === 16 && typeof texUsage.STORAGE_BINDING === "number" && texUsage.STORAGE_BINDING > 0 && (device.limits?.maxStorageTexturesPerShaderStage ?? 4) >= 4;
115
+ }
116
+ function buildSpdDummy(device) {
117
+ const texUsage = texUsageOf();
118
+ const dummyTexture = device.createTexture({
119
+ label: "ultra-text spd-scratch",
120
+ size: [8, 8],
121
+ mipLevelCount: 4,
122
+ format: "r8unorm",
123
+ usage: texUsage.TEXTURE_BINDING | (texUsage.STORAGE_BINDING ?? 0)
124
+ });
125
+ return {
126
+ dummyTexture,
127
+ dummyViews: [
128
+ 0,
129
+ 1,
130
+ 2,
131
+ 3
132
+ ].map((baseMipLevel) => dummyTexture.createView({
133
+ baseMipLevel,
134
+ mipLevelCount: 1
135
+ }))
136
+ };
137
+ }
138
+ async function getDeviceSpdMipPipeline(device) {
139
+ const existing = vanillaSpdPipelines.get(device);
140
+ if (existing?.pipeline) return {
141
+ pipeline: existing.pipeline,
142
+ layout: existing.groupLayout ?? existing.pipeline.getBindGroupLayout(0),
143
+ dummyViews: existing.dummyViews
144
+ };
145
+ if (existing?.promise) {
146
+ const resolved = await existing.promise;
147
+ return {
148
+ pipeline: resolved.pipeline,
149
+ layout: resolved.groupLayout ?? resolved.pipeline.getBindGroupLayout(0),
150
+ dummyViews: resolved.dummyViews
151
+ };
152
+ }
153
+ let groupLayout = null;
154
+ let pipelineLayout = "auto";
155
+ if (typeof device.createBindGroupLayout === "function" && typeof device.createPipelineLayout === "function") {
156
+ const storageEntry = (binding) => ({
157
+ binding,
158
+ visibility: 4,
159
+ storageTexture: {
160
+ format: "r8unorm",
161
+ access: "write-only",
162
+ viewDimension: "2d"
163
+ }
164
+ });
165
+ groupLayout = device.createBindGroupLayout({ entries: [
166
+ {
167
+ binding: 0,
168
+ visibility: 4,
169
+ buffer: {
170
+ type: "uniform",
171
+ minBindingSize: 16
172
+ }
173
+ },
174
+ {
175
+ binding: 1,
176
+ visibility: 4,
177
+ texture: {
178
+ sampleType: "unfilterable-float",
179
+ viewDimension: "2d"
180
+ }
181
+ },
182
+ storageEntry(2),
183
+ storageEntry(3),
184
+ storageEntry(4),
185
+ storageEntry(5)
186
+ ] });
187
+ pipelineLayout = device.createPipelineLayout({ bindGroupLayouts: [groupLayout] });
188
+ }
189
+ const module = device.createShaderModule({ code: MIP_SPD_WGSL });
190
+ const { dummyTexture, dummyViews } = buildSpdDummy(device);
191
+ const desc = {
192
+ label: "ultra-text spd-mips",
193
+ layout: pipelineLayout,
194
+ compute: {
195
+ module,
196
+ entryPoint: "mipSpdMain"
197
+ }
198
+ };
199
+ const pipeline = device.createComputePipeline(desc);
200
+ vanillaSpdPipelines.set(device, {
201
+ pipeline,
202
+ groupLayout,
203
+ dummyViews,
204
+ dummyTexture
205
+ });
206
+ return Promise.resolve({
207
+ pipeline,
208
+ layout: groupLayout ?? pipeline.getBindGroupLayout(0),
209
+ dummyViews
210
+ });
211
+ }
212
+ function encodeSpdMipmapChain(device, encoder, texture, width, height, mipLevelCount, spd, pool) {
213
+ if (mipLevelCount < 2) return;
214
+ const bufUsage = bufUsageOf();
215
+ const view = (baseMipLevel) => texture.createView({
216
+ baseMipLevel,
217
+ mipLevelCount: 1
218
+ });
219
+ const pass = encoder.beginComputePass();
220
+ pass.setPipeline(spd.pipeline);
221
+ const uniform = /* @__PURE__ */ new Uint32Array(4);
222
+ let srcW = width;
223
+ let srcH = height;
224
+ let k = 1;
225
+ while (k < mipLevelCount) {
226
+ let count = 0;
227
+ if (srcW >= 2 && srcH >= 2 && ((srcW | srcH) & 1) === 0) {
228
+ count = 1;
229
+ let pw = srcW >> 1;
230
+ let ph = srcH >> 1;
231
+ while (count < 4 && k + count < mipLevelCount && pw >= 2 && ph >= 2 && ((pw | ph) & 1) === 0) {
232
+ count++;
233
+ pw >>= 1;
234
+ ph >>= 1;
235
+ }
236
+ }
237
+ const dstW = Math.max(1, srcW >> 1);
238
+ const dstH = Math.max(1, srcH >> 1);
239
+ uniform[0] = srcW;
240
+ uniform[1] = srcH;
241
+ uniform[2] = count;
242
+ uniform[3] = 0;
243
+ const slot = pool.ringAlloc(16, bufUsage.UNIFORM | bufUsage.COPY_DST);
244
+ device.queue.writeBuffer(slot.buffer, slot.offset, uniform);
245
+ const dstCount = count === 0 ? 1 : count;
246
+ const dstViews = [
247
+ 0,
248
+ 1,
249
+ 2,
250
+ 3
251
+ ].map((i) => i < dstCount ? view(k + i) : spd.dummyViews[i]);
252
+ pass.setBindGroup(0, device.createBindGroup({
253
+ layout: spd.layout,
254
+ entries: [
255
+ {
256
+ binding: 0,
257
+ resource: {
258
+ buffer: slot.buffer,
259
+ offset: slot.offset,
260
+ size: 16
261
+ }
262
+ },
263
+ {
264
+ binding: 1,
265
+ resource: view(k - 1)
266
+ },
267
+ {
268
+ binding: 2,
269
+ resource: dstViews[0]
270
+ },
271
+ {
272
+ binding: 3,
273
+ resource: dstViews[1]
274
+ },
275
+ {
276
+ binding: 4,
277
+ resource: dstViews[2]
278
+ },
279
+ {
280
+ binding: 5,
281
+ resource: dstViews[3]
282
+ }
283
+ ]
284
+ }));
285
+ pass.dispatchWorkgroups(Math.ceil(dstW / 16), Math.ceil(dstH / 16));
286
+ const steps = count === 0 ? 1 : count;
287
+ for (let s = 0; s < steps; s++) {
288
+ srcW = Math.max(1, srcW >> 1);
289
+ srcH = Math.max(1, srcH >> 1);
290
+ }
291
+ k += steps;
292
+ }
293
+ pass.end();
294
+ }
295
+ /** Upload a complete atlas texture, transferring ownership only after its mip chain is submitted. */
296
+ function uploadAtlasTexture(device, width, height, data, format, mipmaps) {
297
+ const usage = texUsageOf();
298
+ const mipLevelCount = mipCount(width, height, mipmaps);
299
+ const texture = device.createTexture({
300
+ size: [width, height],
91
301
  mipLevelCount,
92
- format: "rgba8unorm-srgb",
93
- usage: textures.TEXTURE_BINDING | textures.COPY_DST | textures.COPY_SRC | (mipLevelCount > 1 ? textures.RENDER_ATTACHMENT : 0)
302
+ format,
303
+ usage: usage.TEXTURE_BINDING | usage.COPY_DST | usage.COPY_SRC | (mipLevelCount > 1 ? usage.RENDER_ATTACHMENT : 0)
94
304
  });
95
- device.queue.writeTexture({
96
- texture: gpuTexture,
97
- mipLevel: 0
98
- }, band.data, {
99
- offset: 0,
100
- bytesPerRow: width * 4,
101
- rowsPerImage: band.height
102
- }, [width, band.height]);
305
+ try {
306
+ device.queue.writeTexture({
307
+ texture,
308
+ mipLevel: 0
309
+ }, data, {
310
+ offset: 0,
311
+ bytesPerRow: format === "r8unorm" ? width : width * 4,
312
+ rowsPerImage: height
313
+ }, [width, height]);
314
+ if (mipLevelCount > 1) {
315
+ const mip = getDeviceMipPipeline(device, format);
316
+ const encoder = device.createCommandEncoder();
317
+ encodeMipmapChain(device, encoder, texture, mipLevelCount, mip.pipeline, mip.sampler, mip.layout);
318
+ device.queue.submit([encoder.finish()]);
319
+ }
320
+ return texture;
321
+ } catch (error) {
322
+ texture.destroy();
323
+ throw error;
324
+ }
325
+ }
326
+ function createGpuColorLayer(device, width, { data, height, top }, mipmaps) {
327
+ return {
328
+ data,
329
+ width,
330
+ height,
331
+ top,
332
+ gpuTexture: uploadAtlasTexture(device, width, height, data, "rgba8unorm-srgb", mipmaps)
333
+ };
334
+ }
335
+ function encodeVanillaGpuColorLayer(device, encoder, width, band, bleed, mipmaps, pool, transient) {
336
+ const mipLevelCount = mipCount(width, band.height, mipmaps);
337
+ const { texture, transient: bleedTransient } = encodeGpuColorBleed(device, encoder, bleed, mipLevelCount, pool);
338
+ transient.push(...bleedTransient);
339
+ const gpuTexture = texture;
103
340
  if (mipLevelCount > 1) {
104
341
  const mip = getDeviceMipPipeline(device, "rgba8unorm-srgb");
105
- const encoder = device.createCommandEncoder();
106
- encodeMipmapChain(device, encoder, gpuTexture, mipLevelCount, mip.pipeline, mip.sampler);
107
- device.queue.submit([encoder.finish()]);
342
+ encodeMipmapChain(device, encoder, gpuTexture, mipLevelCount, mip.pipeline, mip.sampler, mip.layout);
108
343
  }
109
344
  return {
110
345
  data: band.data,
@@ -114,6 +349,6 @@ function createGpuColorLayer(device, width, band, mipmaps) {
114
349
  height: band.height
115
350
  };
116
351
  }
117
- export { DEFAULT_BUF_USAGE, DEFAULT_TEX_USAGE, bufUsageOf, createGpuColorLayer, encodeMipmapChain, getDeviceMipPipeline, mipCount, resolveGpuDevice, texUsageOf, vanillaMipPipelines };
352
+ export { DEFAULT_BUF_USAGE, DEFAULT_TEX_USAGE, bufUsageOf, canUseSpdMips, createGpuColorLayer, encodeMipmapChain, encodeSpdMipmapChain, encodeVanillaGpuColorLayer, getDeviceMipPipeline, getDeviceSpdMipPipeline, mipCount, resolveGpuDevice, texUsageOf, uploadAtlasTexture, vanillaMipPipelines, vanillaSpdPipelines };
118
353
 
119
354
  //# sourceMappingURL=vanillaGpuHelpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"vanillaGpuHelpers.js","names":[],"sources":["../../src/atlas/vanillaGpuHelpers.ts"],"sourcesContent":["import type { SdfAtlasMode } from '../types.js'\nimport { MIP_WGSL } from './jfaWgsl.js'\nimport type { GlyphSlot, RasterColorBand } from '../types.js'\n\n/** Structural WebGPU texture handle returned by GPU atlas builds. */\nexport interface VanillaGpuTexture {\n readonly label?: string\n readonly width?: number\n readonly height?: number\n readonly format?: string\n readonly mipLevelCount?: number\n createView(descriptor?: { baseMipLevel?: number; mipLevelCount?: number }): unknown\n destroy(): void\n}\n\n/** Structural WebGPU device interface so callers need neither Three.js nor `@webgpu/types`. */\nexport interface VanillaGpuDevice {\n readonly features?: { has(name: string): boolean }\n readonly limits?: {\n readonly maxStorageBufferBindingSize: number\n readonly maxBufferSize: number\n readonly maxComputeInvocationsPerWorkgroup?: number\n readonly maxComputeWorkgroupSizeX?: number\n readonly maxComputeWorkgroupSizeY?: number\n readonly maxStorageBuffersPerShaderStage?: number\n readonly maxStorageBuffersInFragmentStage?: number\n readonly maxTextureDimension2D?: number\n }\n createTexture(descriptor: {\n label?: string\n size: readonly [number, number] | [number, number]\n mipLevelCount?: number\n format: string\n usage: number\n }): VanillaGpuTexture\n createBuffer(descriptor: {\n label?: string\n size: number\n usage: number\n mappedAtCreation?: boolean\n }): { destroy(): void }\n createSampler(descriptor?: {\n label?: string\n minFilter?: 'nearest' | 'linear'\n magFilter?: 'nearest' | 'linear'\n }): unknown\n createShaderModule(descriptor: { label?: string; code: string }): unknown\n createComputePipeline(descriptor: {\n label?: string\n layout: 'auto'\n compute: { module: unknown; entryPoint: string }\n }): { getBindGroupLayout(index: number): unknown }\n createRenderPipeline(descriptor: {\n label?: string\n layout: 'auto'\n vertex: { module: unknown; entryPoint: string }\n fragment: { module: unknown; entryPoint: string; targets: readonly { format: string }[] }\n primitive?: { topology?: string }\n }): { getBindGroupLayout(index: number): unknown }\n createBindGroup(descriptor: {\n layout: unknown\n entries: readonly { binding: number; resource: unknown }[]\n }): unknown\n createCommandEncoder(descriptor?: { label?: string }): {\n copyTextureToBuffer(\n source: { texture: VanillaGpuTexture },\n destination: { buffer: { destroy(): void }; bytesPerRow: number; rowsPerImage: number },\n size: readonly [number, number] | [number, number],\n ): void\n beginComputePass(descriptor?: { label?: string }): {\n setPipeline(pipeline: unknown): void\n setBindGroup(index: number, bindGroup: unknown): void\n dispatchWorkgroups(x: number, y?: number, z?: number): void\n end(): void\n }\n beginRenderPass(descriptor: {\n label?: string\n colorAttachments: readonly {\n view: unknown\n loadOp: 'clear' | 'load'\n storeOp: 'store' | 'discard'\n clearValue?: { r: number; g: number; b: number; a: number }\n }[]\n }): {\n setPipeline(pipeline: unknown): void\n setBindGroup(index: number, bindGroup: unknown): void\n draw(vertexCount: number): void\n end(): void\n }\n finish(): unknown\n }\n readonly queue: {\n copyExternalImageToTexture(\n source: { source: HTMLCanvasElement; flipY?: boolean },\n destination: { texture: VanillaGpuTexture; premultipliedAlpha?: boolean },\n size: readonly [number, number] | [number, number],\n ): void\n writeBuffer(\n buffer: { destroy(): void },\n bufferOffset: number,\n data: ArrayBufferView,\n dataOffset?: number,\n size?: number,\n ): void\n writeTexture(\n destination: { texture: VanillaGpuTexture; mipLevel?: number },\n data: ArrayBufferView,\n dataLayout: { offset?: number; bytesPerRow: number; rowsPerImage?: number },\n size: readonly [number, number] | [number, number],\n ): void\n submit(commandBuffers: readonly unknown[]): void\n }\n pushErrorScope?(filter: 'validation' | 'out-of-memory' | 'internal'): void\n popErrorScope?(): Promise<{ readonly message?: string } | null>\n}\n\n/** A WebGPU `GPUDevice`, an engine renderer holding `{ device }`, or `null`/`undefined` for CPU mode. */\nexport type VanillaGpuDeviceSource =\n VanillaGpuDevice | { readonly device?: VanillaGpuDevice | null | undefined } | null | undefined\n\n/** Companion colour layer owned and disposed by its `VanillaSdfAtlas`. */\nexport interface VanillaSdfColorLayer {\n readonly data: Uint8Array\n readonly gpuTexture?: VanillaGpuTexture | undefined\n readonly width: number\n readonly top: number\n readonly height: number\n}\n\n/** Engine-agnostic SDF atlas with CPU bytes and/or an adopted WebGPU `GPUTexture`. */\nexport interface VanillaSdfAtlas {\n /** Single-channel SDF bytes (`width * height`), present when built on CPU. */\n readonly data?: Uint8Array | undefined\n /** WebGPU `r8unorm` texture (`TEXTURE_BINDING | COPY_SRC`), present when built on GPU. */\n readonly gpuTexture?: VanillaGpuTexture | undefined\n readonly colorLayer?: VanillaSdfColorLayer | undefined\n readonly shapeTop?: number | undefined\n readonly width: number\n readonly height: number\n readonly pxRange: number\n readonly bakeSize: number\n readonly glyphs: ReadonlyMap<string, GlyphSlot>\n readonly mode: Exclude<SdfAtlasMode, 'auto'>\n /** Requested mipmap flag. */\n readonly mipmaps: boolean\n /** Requested anisotropy level. */\n readonly anisotropy: number\n dispose(): void\n}\n\nexport function resolveGpuDevice(source: VanillaGpuDeviceSource): VanillaGpuDevice | null {\n if (!source || typeof source !== 'object') return null\n if ('createTexture' in source && typeof source.createTexture === 'function') return source\n if ('device' in source && source.device && typeof source.device.createTexture === 'function') {\n return source.device\n }\n return null\n}\n\nexport const DEFAULT_BUF_USAGE = { COPY_SRC: 4, COPY_DST: 8, UNIFORM: 64, STORAGE: 128 }\nexport const DEFAULT_TEX_USAGE: {\n COPY_SRC: number\n COPY_DST: number\n TEXTURE_BINDING: number\n STORAGE_BINDING?: number\n RENDER_ATTACHMENT: number\n} = { COPY_SRC: 1, COPY_DST: 2, TEXTURE_BINDING: 4, STORAGE_BINDING: 8, RENDER_ATTACHMENT: 16 }\n\ninterface UsageGlobals {\n GPUBufferUsage?: typeof DEFAULT_BUF_USAGE\n GPUTextureUsage?: typeof DEFAULT_TEX_USAGE\n}\n\nexport const texUsageOf = () => (globalThis as UsageGlobals).GPUTextureUsage ?? DEFAULT_TEX_USAGE\nexport const bufUsageOf = () => (globalThis as UsageGlobals).GPUBufferUsage ?? DEFAULT_BUF_USAGE\nexport const mipCount = (w: number, h: number, mipmaps: boolean): number =>\n mipmaps ? Math.floor(Math.log2(Math.max(w, h))) + 1 : 1\n\ninterface CachedMipPipelines {\n readonly module: unknown\n readonly sampler: unknown\n r8?: ReturnType<VanillaGpuDevice['createRenderPipeline']>\n rgba?: ReturnType<VanillaGpuDevice['createRenderPipeline']>\n}\n\nexport const vanillaMipPipelines = new WeakMap<VanillaGpuDevice, CachedMipPipelines>()\n\nexport function getDeviceMipPipeline(\n device: VanillaGpuDevice,\n format: 'r8unorm' | 'rgba8unorm-srgb',\n): {\n readonly pipeline: ReturnType<VanillaGpuDevice['createRenderPipeline']>\n readonly sampler: unknown\n} {\n let cached = vanillaMipPipelines.get(device)\n if (!cached) {\n cached = {\n module: device.createShaderModule({ code: MIP_WGSL }),\n sampler: device.createSampler({ minFilter: 'linear', magFilter: 'linear' }),\n }\n vanillaMipPipelines.set(device, cached)\n }\n const key = format === 'r8unorm' ? 'r8' : 'rgba'\n let pipeline = cached[key]\n if (!pipeline) {\n pipeline = device.createRenderPipeline({\n layout: 'auto',\n vertex: { module: cached.module, entryPoint: 'mipVert' },\n fragment: { module: cached.module, entryPoint: 'mipFrag', targets: [{ format }] },\n })\n cached[key] = pipeline\n }\n return { pipeline, sampler: cached.sampler }\n}\n\nexport function encodeMipmapChain(\n device: VanillaGpuDevice,\n encoder: ReturnType<VanillaGpuDevice['createCommandEncoder']>,\n texture: VanillaGpuTexture,\n mipLevelCount: number,\n pipeline: ReturnType<VanillaGpuDevice['createRenderPipeline']>,\n sampler: unknown,\n): void {\n const view = (baseMipLevel: number) => texture.createView({ baseMipLevel, mipLevelCount: 1 })\n for (let level = 1; level < mipLevelCount; level++) {\n const pass = encoder.beginRenderPass({\n colorAttachments: [{ view: view(level), loadOp: 'clear', storeOp: 'store' }],\n })\n pass.setPipeline(pipeline)\n pass.setBindGroup(\n 0,\n device.createBindGroup({\n layout: pipeline.getBindGroupLayout(0),\n entries: [\n { binding: 0, resource: view(level - 1) },\n { binding: 1, resource: sampler },\n ],\n }),\n )\n pass.draw(3)\n pass.end()\n }\n}\n\nexport function createGpuColorLayer(\n device: VanillaGpuDevice,\n width: number,\n band: RasterColorBand,\n mipmaps: boolean,\n): VanillaSdfColorLayer {\n const textures = texUsageOf()\n const mipLevelCount = mipCount(width, band.height, mipmaps)\n const gpuTexture = device.createTexture({\n size: [width, band.height],\n mipLevelCount,\n format: 'rgba8unorm-srgb',\n usage:\n textures.TEXTURE_BINDING |\n textures.COPY_DST |\n textures.COPY_SRC |\n (mipLevelCount > 1 ? textures.RENDER_ATTACHMENT : 0),\n })\n device.queue.writeTexture(\n { texture: gpuTexture, mipLevel: 0 },\n band.data,\n { offset: 0, bytesPerRow: width * 4, rowsPerImage: band.height },\n [width, band.height],\n )\n if (mipLevelCount > 1) {\n const mip = getDeviceMipPipeline(device, 'rgba8unorm-srgb')\n const encoder = device.createCommandEncoder()\n encodeMipmapChain(device, encoder, gpuTexture, mipLevelCount, mip.pipeline, mip.sampler)\n device.queue.submit([encoder.finish()])\n }\n return {\n data: band.data,\n gpuTexture,\n width,\n top: band.top,\n height: band.height,\n }\n}\n"],"mappings":";;AAsJA,SAAgB,iBAAiB,QAAyD;CACxF,IAAI,CAAC,UAAU,OAAO,WAAW,UAAU,OAAO;CAClD,IAAI,mBAAmB,UAAU,OAAO,OAAO,kBAAkB,YAAY,OAAO;CACpF,IAAI,YAAY,UAAU,OAAO,UAAU,OAAO,OAAO,OAAO,kBAAkB,YAChF,OAAO,OAAO;CAEhB,OAAO;AACT;AAEA,IAAa,oBAAoB;CAAE,UAAU;CAAG,UAAU;CAAG,SAAS;CAAI,SAAS;AAAI;AACvF,IAAa,oBAMT;CAAE,UAAU;CAAG,UAAU;CAAG,iBAAiB;CAAG,iBAAiB;CAAG,mBAAmB;AAAG;AAO9F,IAAa,mBAAoB,WAA4B,mBAAmB;AAChF,IAAa,mBAAoB,WAA4B,kBAAkB;AAC/E,IAAa,YAAY,GAAW,GAAW,YAC7C,UAAU,KAAK,MAAM,KAAK,KAAK,KAAK,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,IAAI;AASxD,IAAa,sCAAsB,IAAI,QAA8C;AAErF,SAAgB,qBACd,QACA,QAIA;CACA,IAAI,SAAS,oBAAoB,IAAI,MAAM;CAC3C,IAAI,CAAC,QAAQ;EACX,SAAS;GACP,QAAQ,OAAO,mBAAmB,EAAE,MAAM,SAAS,CAAC;GACpD,SAAS,OAAO,cAAc;IAAE,WAAW;IAAU,WAAW;GAAS,CAAC;EAC5E;EACA,oBAAoB,IAAI,QAAQ,MAAM;CACxC;CACA,MAAM,MAAM,WAAW,YAAY,OAAO;CAC1C,IAAI,WAAW,OAAO;CACtB,IAAI,CAAC,UAAU;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;CAAO,GAC/D,CAAC,OAAO,KAAK,MAAM,CACrB;CACA,IAAI,gBAAgB,GAAG;EACrB,MAAM,MAAM,qBAAqB,QAAQ,iBAAiB;EAC1D,MAAM,UAAU,OAAO,qBAAqB;EAC5C,kBAAkB,QAAQ,SAAS,YAAY,eAAe,IAAI,UAAU,IAAI,OAAO;EACvF,OAAO,MAAM,OAAO,CAAC,QAAQ,OAAO,CAAC,CAAC;CACxC;CACA,OAAO;EACL,MAAM,KAAK;EACX;EACA;EACA,KAAK,KAAK;EACV,QAAQ,KAAK;CACf;AACF"}
1
+ {"version":3,"file":"vanillaGpuHelpers.js","names":[],"sources":["../../src/atlas/vanillaGpuHelpers.ts"],"sourcesContent":["import type { GlyphSlot, RasterColorBand, SdfAtlasMode } from '../types.js'\nimport { encodeGpuColorBleed, type AtlasGpuPool, type DeferredColorBleed } from './gpuCommon.js'\nimport { MIP_SPD_WGSL, MIP_WGSL } from './jfaWgsl.js'\n\n/** Structural WebGPU texture handle returned by GPU atlas builds. */\nexport interface VanillaGpuTexture {\n readonly label?: string\n readonly width?: number\n readonly height?: number\n readonly format?: string\n readonly mipLevelCount?: number\n createView(descriptor?: { baseMipLevel?: number; mipLevelCount?: number }): unknown\n destroy(): void\n}\n\n/** Structural WebGPU device interface so callers need neither Three.js nor `@webgpu/types`. */\nexport interface VanillaGpuDevice {\n readonly features?: { has(name: string): boolean }\n readonly limits?: {\n readonly maxStorageBufferBindingSize: number\n readonly maxBufferSize: number\n readonly maxComputeInvocationsPerWorkgroup?: number\n readonly maxComputeWorkgroupSizeX?: number\n readonly maxComputeWorkgroupSizeY?: number\n readonly maxStorageBuffersPerShaderStage?: number\n readonly maxStorageBuffersInFragmentStage?: number\n readonly maxStorageTexturesPerShaderStage?: number\n readonly maxTextureDimension2D?: number\n readonly minUniformBufferOffsetAlignment?: number\n }\n createTexture(descriptor: {\n label?: string\n size: readonly [number, number] | [number, number]\n mipLevelCount?: number\n format: string\n usage: number\n }): VanillaGpuTexture\n createBuffer(descriptor: {\n label?: string\n size: number\n usage: number\n mappedAtCreation?: boolean\n }): { destroy(): void }\n createSampler(descriptor?: {\n label?: string\n minFilter?: 'nearest' | 'linear'\n magFilter?: 'nearest' | 'linear'\n }): unknown\n createShaderModule(descriptor: { label?: string; code: string }): unknown\n createBindGroupLayout?(descriptor: object): unknown\n createPipelineLayout?(descriptor: { bindGroupLayouts: unknown[] }): unknown\n createComputePipeline(descriptor: {\n label?: string\n layout: unknown\n compute: { module: unknown; entryPoint: string }\n }): { getBindGroupLayout(index: number): unknown }\n readonly createComputePipelineAsync?: (descriptor: {\n label?: string\n layout: unknown\n compute: { module: unknown; entryPoint: string }\n }) => Promise<{ getBindGroupLayout(index: number): unknown }>\n createRenderPipeline(descriptor: {\n label?: string\n layout: unknown\n vertex: { module: unknown; entryPoint: string }\n fragment: { module: unknown; entryPoint: string; targets: readonly { format: string }[] }\n primitive?: { topology?: string }\n }): { getBindGroupLayout(index: number): unknown }\n readonly createRenderPipelineAsync?: (descriptor: {\n label?: string\n layout: unknown\n vertex: { module: unknown; entryPoint: string }\n fragment: { module: unknown; entryPoint: string; targets: readonly { format: string }[] }\n primitive?: { topology?: string }\n }) => Promise<{ getBindGroupLayout(index: number): unknown }>\n createBindGroup(descriptor: {\n layout: unknown\n entries: readonly { binding: number; resource: unknown }[]\n }): unknown\n createCommandEncoder(descriptor?: { label?: string }): {\n copyTextureToBuffer(\n source: { texture: VanillaGpuTexture },\n destination: { buffer: { destroy(): void }; bytesPerRow: number; rowsPerImage: number },\n size: readonly [number, number] | [number, number],\n ): void\n beginComputePass(descriptor?: { label?: string }): {\n setPipeline(pipeline: unknown): void\n setBindGroup(index: number, bindGroup: unknown): void\n dispatchWorkgroups(x: number, y?: number, z?: number): void\n end(): void\n }\n beginRenderPass(descriptor: {\n label?: string\n colorAttachments: readonly {\n view: unknown\n loadOp: 'clear' | 'load'\n storeOp: 'store' | 'discard'\n clearValue?: { r: number; g: number; b: number; a: number }\n }[]\n }): {\n setPipeline(pipeline: unknown): void\n setBindGroup(index: number, bindGroup: unknown): void\n draw(vertexCount: number): void\n end(): void\n }\n finish(): unknown\n }\n readonly queue: {\n copyExternalImageToTexture(\n source: { source: HTMLCanvasElement; flipY?: boolean },\n destination: { texture: VanillaGpuTexture; premultipliedAlpha?: boolean },\n size: readonly [number, number] | [number, number],\n ): void\n writeBuffer(\n buffer: { destroy(): void },\n bufferOffset: number,\n data: BufferSource | ArrayBufferView,\n dataOffset?: number,\n size?: number,\n ): void\n writeTexture(\n destination: { texture: VanillaGpuTexture; mipLevel?: number },\n data: ArrayBufferView,\n dataLayout: { offset?: number; bytesPerRow: number; rowsPerImage?: number },\n size: readonly [number, number] | [number, number],\n ): void\n submit(commandBuffers: readonly unknown[]): void\n }\n pushErrorScope?(filter: 'validation' | 'out-of-memory' | 'internal'): void\n popErrorScope?(): Promise<{ readonly message?: string } | null>\n}\n\n/** A WebGPU `GPUDevice`, an engine renderer holding `{ device }`, or `null`/`undefined` for CPU mode. */\nexport type VanillaGpuDeviceSource =\n VanillaGpuDevice | { readonly device?: VanillaGpuDevice | null | undefined } | null | undefined\n\n/** Companion colour layer owned and disposed by its `VanillaSdfAtlas`. */\nexport interface VanillaSdfColorLayer {\n readonly data: Uint8Array\n readonly gpuTexture?: VanillaGpuTexture | undefined\n readonly width: number\n readonly top: number\n readonly height: number\n}\n\n/** Engine-agnostic SDF atlas with CPU bytes and/or an adopted WebGPU `GPUTexture`. */\nexport interface VanillaSdfAtlas {\n /** Single-channel SDF bytes (`width * height`), present when built on CPU. */\n readonly data?: Uint8Array | undefined\n /** WebGPU `r8unorm` texture (`TEXTURE_BINDING | COPY_SRC`), present when built on GPU. */\n readonly gpuTexture?: VanillaGpuTexture | undefined\n readonly colorLayer?: VanillaSdfColorLayer | undefined\n readonly shapeTop?: number | undefined\n readonly width: number\n readonly height: number\n readonly pxRange: number\n readonly bakeSize: number\n readonly glyphs: ReadonlyMap<string, GlyphSlot>\n readonly mode: Exclude<SdfAtlasMode, 'auto'>\n /** Requested mipmap flag. */\n readonly mipmaps: boolean\n /** Requested anisotropy level. */\n readonly anisotropy: number\n dispose(): void\n}\n\nexport function resolveGpuDevice(source: VanillaGpuDeviceSource): VanillaGpuDevice | null {\n if (!source || typeof source !== 'object') return null\n if ('createTexture' in source && typeof source.createTexture === 'function') return source\n if ('device' in source && source.device && typeof source.device.createTexture === 'function') {\n return source.device\n }\n return null\n}\n\nexport const DEFAULT_BUF_USAGE = { COPY_SRC: 4, COPY_DST: 8, UNIFORM: 64, STORAGE: 128 }\nexport const DEFAULT_TEX_USAGE: {\n COPY_SRC: number\n COPY_DST: number\n TEXTURE_BINDING: number\n STORAGE_BINDING?: number\n RENDER_ATTACHMENT: number\n} = { COPY_SRC: 1, COPY_DST: 2, TEXTURE_BINDING: 4, STORAGE_BINDING: 8, RENDER_ATTACHMENT: 16 }\n\ninterface UsageGlobals {\n GPUBufferUsage?: typeof DEFAULT_BUF_USAGE\n GPUTextureUsage?: typeof DEFAULT_TEX_USAGE\n}\n\nexport const texUsageOf = () => (globalThis as UsageGlobals).GPUTextureUsage ?? DEFAULT_TEX_USAGE\nexport const bufUsageOf = () => (globalThis as UsageGlobals).GPUBufferUsage ?? DEFAULT_BUF_USAGE\nexport const mipCount = (w: number, h: number, mipmaps: boolean): number =>\n mipmaps ? Math.floor(Math.log2(Math.max(w, h))) + 1 : 1\n\ninterface CachedMipPipelines {\n readonly module: unknown\n readonly sampler: unknown\n readonly groupLayout: unknown\n readonly pipelineLayout: unknown\n r8?: ReturnType<VanillaGpuDevice['createRenderPipeline']>\n rgba?: ReturnType<VanillaGpuDevice['createRenderPipeline']>\n}\n\nexport const vanillaMipPipelines = new WeakMap<VanillaGpuDevice, CachedMipPipelines>()\n\nexport function getDeviceMipPipeline(\n device: VanillaGpuDevice,\n format: 'r8unorm' | 'rgba8unorm-srgb',\n): {\n readonly pipeline: ReturnType<VanillaGpuDevice['createRenderPipeline']>\n readonly sampler: unknown\n readonly layout: unknown\n} {\n let cached = vanillaMipPipelines.get(device)\n if (!cached) {\n let groupLayout: unknown = null\n let pipelineLayout: unknown = 'auto'\n if (\n typeof device.createBindGroupLayout === 'function' &&\n typeof device.createPipelineLayout === 'function'\n ) {\n groupLayout = device.createBindGroupLayout({\n entries: [\n { binding: 0, visibility: 2, texture: { sampleType: 'float', viewDimension: '2d' } },\n { binding: 1, visibility: 2, sampler: { type: 'filtering' } },\n ],\n })\n pipelineLayout = device.createPipelineLayout({ bindGroupLayouts: [groupLayout] })\n }\n cached = {\n module: device.createShaderModule({ code: MIP_WGSL }),\n sampler: device.createSampler({ minFilter: 'linear', magFilter: 'linear' }),\n groupLayout,\n pipelineLayout,\n }\n vanillaMipPipelines.set(device, cached)\n }\n const key = format === 'r8unorm' ? 'r8' : 'rgba'\n let pipeline = cached[key]\n if (!pipeline) {\n pipeline = device.createRenderPipeline({\n layout: cached.pipelineLayout,\n vertex: { module: cached.module, entryPoint: 'mipVert' },\n fragment: { module: cached.module, entryPoint: 'mipFrag', targets: [{ format }] },\n })\n cached[key] = pipeline\n }\n return {\n pipeline,\n sampler: cached.sampler,\n layout: cached.groupLayout ?? pipeline.getBindGroupLayout(0),\n }\n}\n\nexport function encodeMipmapChain(\n device: VanillaGpuDevice,\n encoder: ReturnType<VanillaGpuDevice['createCommandEncoder']>,\n texture: VanillaGpuTexture,\n mipLevelCount: number,\n pipeline: ReturnType<VanillaGpuDevice['createRenderPipeline']>,\n sampler: unknown,\n layout: unknown = pipeline.getBindGroupLayout(0),\n): void {\n if (mipLevelCount <= 1) return\n const view = (baseMipLevel: number) => texture.createView({ baseMipLevel, mipLevelCount: 1 })\n let source = view(0)\n for (let level = 1; level < mipLevelCount; level++) {\n const target = view(level)\n const pass = encoder.beginRenderPass({\n colorAttachments: [{ view: target, loadOp: 'clear', storeOp: 'store' }],\n })\n pass.setPipeline(pipeline)\n pass.setBindGroup(\n 0,\n device.createBindGroup({\n layout,\n entries: [\n { binding: 0, resource: source },\n { binding: 1, resource: sampler },\n ],\n }),\n )\n pass.draw(3)\n pass.end()\n source = target\n }\n}\n\ninterface CachedSpdMipPipeline {\n readonly pipeline?: ReturnType<VanillaGpuDevice['createComputePipeline']>\n readonly promise?: Promise<CachedSpdMipPipeline>\n readonly groupLayout: unknown\n readonly dummyViews: readonly unknown[]\n readonly dummyTexture: VanillaGpuTexture\n}\n\nexport const vanillaSpdPipelines = new WeakMap<VanillaGpuDevice, CachedSpdMipPipeline>()\n\nexport function canUseSpdMips(\n device: VanillaGpuDevice,\n directStore: boolean,\n workgroupDim: 8 | 16,\n): boolean {\n const texUsage = texUsageOf()\n return (\n directStore &&\n workgroupDim === 16 &&\n typeof texUsage.STORAGE_BINDING === 'number' &&\n texUsage.STORAGE_BINDING > 0 &&\n (device.limits?.maxStorageTexturesPerShaderStage ?? 4) >= 4\n )\n}\n\nfunction buildSpdDummy(device: VanillaGpuDevice): {\n dummyTexture: VanillaGpuTexture\n dummyViews: unknown[]\n} {\n const texUsage = texUsageOf()\n const dummyTexture = device.createTexture({\n label: 'ultra-text spd-scratch',\n size: [8, 8],\n mipLevelCount: 4,\n format: 'r8unorm',\n usage: texUsage.TEXTURE_BINDING | (texUsage.STORAGE_BINDING ?? 0),\n })\n const dummyViews = [0, 1, 2, 3].map((baseMipLevel) =>\n dummyTexture.createView({ baseMipLevel, mipLevelCount: 1 }),\n )\n return { dummyTexture, dummyViews }\n}\n\nexport async function getDeviceSpdMipPipeline(device: VanillaGpuDevice): Promise<{\n readonly pipeline: ReturnType<VanillaGpuDevice['createComputePipeline']>\n readonly layout: unknown\n readonly dummyViews: readonly unknown[]\n}> {\n const existing = vanillaSpdPipelines.get(device)\n if (existing?.pipeline) {\n return {\n pipeline: existing.pipeline,\n layout: existing.groupLayout ?? existing.pipeline.getBindGroupLayout(0),\n dummyViews: existing.dummyViews,\n }\n }\n if (existing?.promise) {\n const resolved = await existing.promise\n return {\n pipeline: resolved.pipeline!,\n layout: resolved.groupLayout ?? resolved.pipeline!.getBindGroupLayout(0),\n dummyViews: resolved.dummyViews,\n }\n }\n\n let groupLayout: unknown = null\n let pipelineLayout: unknown = 'auto'\n if (\n typeof device.createBindGroupLayout === 'function' &&\n typeof device.createPipelineLayout === 'function'\n ) {\n const storageEntry = (binding: number) => ({\n binding,\n visibility: 4,\n storageTexture: { format: 'r8unorm', access: 'write-only', viewDimension: '2d' },\n })\n groupLayout = device.createBindGroupLayout({\n entries: [\n { binding: 0, visibility: 4, buffer: { type: 'uniform', minBindingSize: 16 } },\n {\n binding: 1,\n visibility: 4,\n texture: { sampleType: 'unfilterable-float', viewDimension: '2d' },\n },\n storageEntry(2),\n storageEntry(3),\n storageEntry(4),\n storageEntry(5),\n ],\n })\n pipelineLayout = device.createPipelineLayout({ bindGroupLayouts: [groupLayout] })\n }\n const module = device.createShaderModule({ code: MIP_SPD_WGSL })\n const { dummyTexture, dummyViews } = buildSpdDummy(device)\n const desc = {\n label: 'ultra-text spd-mips',\n layout: pipelineLayout,\n compute: { module, entryPoint: 'mipSpdMain' },\n }\n const pipeline = device.createComputePipeline(desc)\n vanillaSpdPipelines.set(device, { pipeline, groupLayout, dummyViews, dummyTexture })\n return Promise.resolve({\n pipeline,\n layout: groupLayout ?? pipeline.getBindGroupLayout(0),\n dummyViews,\n })\n}\n\nexport function encodeSpdMipmapChain(\n device: VanillaGpuDevice,\n encoder: ReturnType<VanillaGpuDevice['createCommandEncoder']>,\n texture: VanillaGpuTexture,\n width: number,\n height: number,\n mipLevelCount: number,\n spd: {\n readonly pipeline: ReturnType<VanillaGpuDevice['createComputePipeline']>\n readonly layout: unknown\n readonly dummyViews: readonly unknown[]\n },\n pool: AtlasGpuPool,\n): void {\n if (mipLevelCount < 2) return\n const bufUsage = bufUsageOf()\n const view = (baseMipLevel: number) => texture.createView({ baseMipLevel, mipLevelCount: 1 })\n const pass = encoder.beginComputePass()\n pass.setPipeline(spd.pipeline)\n const uniform = new Uint32Array(4)\n\n let srcW = width\n let srcH = height\n let k = 1\n while (k < mipLevelCount) {\n let count = 0\n if (srcW >= 2 && srcH >= 2 && ((srcW | srcH) & 1) === 0) {\n count = 1\n let pw = srcW >> 1\n let ph = srcH >> 1\n while (\n count < 4 &&\n k + count < mipLevelCount &&\n pw >= 2 &&\n ph >= 2 &&\n ((pw | ph) & 1) === 0\n ) {\n count++\n pw >>= 1\n ph >>= 1\n }\n }\n const dstW = Math.max(1, srcW >> 1)\n const dstH = Math.max(1, srcH >> 1)\n uniform[0] = srcW\n uniform[1] = srcH\n uniform[2] = count\n uniform[3] = 0\n const slot = pool.ringAlloc(16, bufUsage.UNIFORM | bufUsage.COPY_DST)\n device.queue.writeBuffer(slot.buffer, slot.offset, uniform)\n const dstCount = count === 0 ? 1 : count\n const dstViews = [0, 1, 2, 3].map((i) => (i < dstCount ? view(k + i) : spd.dummyViews[i]!))\n pass.setBindGroup(\n 0,\n device.createBindGroup({\n layout: spd.layout,\n entries: [\n { binding: 0, resource: { buffer: slot.buffer, offset: slot.offset, size: 16 } },\n { binding: 1, resource: view(k - 1) },\n { binding: 2, resource: dstViews[0]! },\n { binding: 3, resource: dstViews[1]! },\n { binding: 4, resource: dstViews[2]! },\n { binding: 5, resource: dstViews[3]! },\n ],\n }),\n )\n pass.dispatchWorkgroups(Math.ceil(dstW / 16), Math.ceil(dstH / 16))\n const steps = count === 0 ? 1 : count\n for (let s = 0; s < steps; s++) {\n srcW = Math.max(1, srcW >> 1)\n srcH = Math.max(1, srcH >> 1)\n }\n k += steps\n }\n pass.end()\n}\n\n/** Upload a complete atlas texture, transferring ownership only after its mip chain is submitted. */\nexport function uploadAtlasTexture(\n device: VanillaGpuDevice,\n width: number,\n height: number,\n data: Uint8Array,\n format: 'r8unorm' | 'rgba8unorm-srgb',\n mipmaps: boolean,\n): VanillaGpuTexture {\n const usage = texUsageOf()\n const mipLevelCount = mipCount(width, height, mipmaps)\n const texture = device.createTexture({\n size: [width, height],\n mipLevelCount,\n format,\n usage:\n usage.TEXTURE_BINDING |\n usage.COPY_DST |\n usage.COPY_SRC |\n (mipLevelCount > 1 ? usage.RENDER_ATTACHMENT : 0),\n })\n try {\n device.queue.writeTexture(\n { texture, mipLevel: 0 },\n data,\n { offset: 0, bytesPerRow: format === 'r8unorm' ? width : width * 4, rowsPerImage: height },\n [width, height],\n )\n if (mipLevelCount > 1) {\n const mip = getDeviceMipPipeline(device, format)\n const encoder = device.createCommandEncoder()\n encodeMipmapChain(\n device,\n encoder,\n texture,\n mipLevelCount,\n mip.pipeline,\n mip.sampler,\n mip.layout,\n )\n device.queue.submit([encoder.finish()])\n }\n return texture\n } catch (error) {\n texture.destroy()\n throw error\n }\n}\n\nexport function createGpuColorLayer(\n device: VanillaGpuDevice,\n width: number,\n { data, height, top }: RasterColorBand,\n mipmaps: boolean,\n): VanillaSdfColorLayer {\n return {\n data,\n width,\n height,\n top,\n gpuTexture: uploadAtlasTexture(device, width, height, data, 'rgba8unorm-srgb', mipmaps),\n }\n}\n\nexport function encodeVanillaGpuColorLayer(\n device: VanillaGpuDevice,\n encoder: ReturnType<VanillaGpuDevice['createCommandEncoder']>,\n width: number,\n band: RasterColorBand,\n bleed: DeferredColorBleed,\n mipmaps: boolean,\n pool: AtlasGpuPool,\n transient: { destroy(): void }[],\n): VanillaSdfColorLayer {\n const mipLevelCount = mipCount(width, band.height, mipmaps)\n const { texture, transient: bleedTransient } = encodeGpuColorBleed(\n device,\n encoder,\n bleed,\n mipLevelCount,\n pool,\n )\n transient.push(...bleedTransient)\n const gpuTexture = texture as VanillaGpuTexture\n if (mipLevelCount > 1) {\n const mip = getDeviceMipPipeline(device, 'rgba8unorm-srgb')\n encodeMipmapChain(\n device,\n encoder,\n gpuTexture,\n mipLevelCount,\n mip.pipeline,\n mip.sampler,\n mip.layout,\n )\n }\n return {\n data: band.data,\n gpuTexture,\n width,\n top: band.top,\n height: band.height,\n }\n}\n"],"mappings":";;;AAsKA,SAAgB,iBAAiB,QAAyD;CACxF,IAAI,CAAC,UAAU,OAAO,WAAW,UAAU,OAAO;CAClD,IAAI,m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