ultra-text 1.0.1 → 1.0.2
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.
- package/README.md +224 -1002
- package/dist/assets/{cpuSdf.worker-xS57yQbP.js → cpuSdf.worker--X1Qpmdp.js} +136 -47
- package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +1 -0
- package/dist/atlas/appendAtlas.js +67 -25
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +3 -2
- package/dist/atlas/buildAtlas.js.map +1 -1
- package/dist/atlas/cpuAtlas.d.ts +4 -1
- package/dist/atlas/cpuAtlas.js +8 -6
- package/dist/atlas/cpuAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.js +152 -40
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.d.ts +5 -3
- package/dist/atlas/cpuWorker.js +119 -12
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.js +100 -276
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/gpuCommon.d.ts +135 -0
- package/dist/atlas/gpuCommon.js +223 -0
- package/dist/atlas/gpuCommon.js.map +1 -0
- package/dist/atlas/jfaWgsl.js +47 -241
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.js +103 -58
- package/dist/atlas/rasterize.js.map +1 -1
- package/dist/atlas/shapeRaster.js +2 -1
- package/dist/atlas/shapeRaster.js.map +1 -1
- package/dist/atlas/vanillaBounds.d.ts +64 -0
- package/dist/atlas/vanillaBounds.js +42 -0
- package/dist/atlas/vanillaBounds.js.map +1 -0
- package/dist/atlas/vanillaCore.d.ts +100 -0
- package/dist/atlas/vanillaCore.js +1012 -0
- package/dist/atlas/vanillaCore.js.map +1 -0
- package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
- package/dist/atlas/vanillaCpuAtlas.js +87 -0
- package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
- package/dist/atlas/vanillaExtras.d.ts +8 -0
- package/dist/atlas/vanillaExtras.js +166 -0
- package/dist/atlas/vanillaExtras.js.map +1 -0
- package/dist/atlas/vanillaGpuHelpers.d.ts +232 -0
- package/dist/atlas/vanillaGpuHelpers.js +119 -0
- package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
- package/dist/dom/DomSdf.js +224 -284
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.js +75 -151
- package/dist/dom/DomSlug.js.map +1 -1
- package/dist/dom/domAnalytic.d.ts +54 -0
- package/dist/dom/domAnalytic.js +282 -0
- package/dist/dom/domAnalytic.js.map +1 -0
- package/dist/dom/domExtras.d.ts +27 -0
- package/dist/dom/domExtras.js +137 -0
- package/dist/dom/domExtras.js.map +1 -0
- package/dist/dom/fontCanvas.js +27 -9
- package/dist/dom/fontCanvas.js.map +1 -1
- package/dist/dom/layoutSignature.js +150 -48
- package/dist/dom/layoutSignature.js.map +1 -1
- package/dist/dom/pretextLayout.js +55 -13
- package/dist/dom/pretextLayout.js.map +1 -1
- package/dist/dom/snapshot.js +369 -204
- package/dist/dom/snapshot.js.map +1 -1
- package/dist/dom/svgCapture.d.ts +8 -1
- package/dist/dom/svgCapture.js +75 -1
- package/dist/dom/svgCapture.js.map +1 -1
- package/dist/dom/tone.js +76 -36
- package/dist/dom/tone.js.map +1 -1
- package/dist/index.js +4 -3
- package/dist/slug/SlugMaterial.d.ts +11 -3
- package/dist/slug/SlugMaterial.js +54 -10
- package/dist/slug/SlugMaterial.js.map +1 -1
- package/dist/slug/coverage.d.ts +16 -12
- package/dist/slug/coverage.js +194 -221
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +5 -1
- package/dist/slug/preprocessCore.js +118 -87
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.d.ts +1 -0
- package/dist/slug/runtime.js +90 -44
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.d.ts +3 -2
- package/dist/slug/standaloneRuntime.js +75 -40
- package/dist/slug/standaloneRuntime.js.map +1 -1
- package/dist/slug/truetype.js +166 -193
- package/dist/slug/truetype.js.map +1 -1
- package/dist/slug/vanillaCore.d.ts +340 -0
- package/dist/slug/vanillaCore.js +1621 -0
- package/dist/slug/vanillaCore.js.map +1 -0
- package/dist/slug-vanilla.d.ts +13 -364
- package/dist/slug-vanilla.js +5 -1453
- package/dist/slug.d.ts +1 -1
- package/dist/slug.js +6 -6
- package/dist/text/GlyphTextMaterial.d.ts +1 -1
- package/dist/text/GlyphTextMaterial.js +5 -5
- package/dist/text/GlyphTextMaterial.js.map +1 -1
- package/dist/text/SdfTextMaterial.js +7 -5
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/text/decorations.js +36 -19
- package/dist/text/decorations.js.map +1 -1
- package/dist/text/geometry.d.ts +3 -22
- package/dist/text/geometryUtils.d.ts +11 -1
- package/dist/text/geometryUtils.js +22 -1
- package/dist/text/geometryUtils.js.map +1 -1
- package/dist/text/glyphGeometry.d.ts +9 -0
- package/dist/text/glyphGeometry.js +353 -0
- package/dist/text/glyphGeometry.js.map +1 -0
- package/dist/text/index.d.ts +2 -1
- package/dist/text/rectGeometry.d.ts +13 -0
- package/dist/text/rectGeometry.js +97 -0
- package/dist/text/rectGeometry.js.map +1 -0
- package/dist/text/reflow.d.ts +18 -1
- package/dist/text/reflow.js +108 -38
- package/dist/text/reflow.js.map +1 -1
- package/dist/text/snap.d.ts +1 -0
- package/dist/text/snap.js +26 -0
- package/dist/text/snap.js.map +1 -0
- package/dist/vanilla.d.ts +13 -363
- package/dist/vanilla.js +6 -1473
- package/dist/windfoil/geometry.d.ts +2 -2
- package/dist/windfoil/geometry.js +113 -40
- package/dist/windfoil/geometry.js.map +1 -1
- package/dist/windfoil/mixed.d.ts +1 -0
- package/dist/windfoil/mixed.js +44 -25
- package/dist/windfoil/mixed.js.map +1 -1
- package/dist/windfoil/preprocess.js +2 -2
- package/dist/windfoil/preprocessCore.d.ts +1 -0
- package/dist/windfoil/preprocessCore.js +9 -4
- package/dist/windfoil/preprocessCore.js.map +1 -1
- package/dist/windfoil/runtime.d.ts +3 -1
- package/dist/windfoil/runtime.js +62 -40
- package/dist/windfoil/runtime.js.map +1 -1
- package/dist/windfoil/storage.d.ts +60 -2
- package/dist/windfoil/storage.js +142 -6
- package/dist/windfoil/storage.js.map +1 -1
- package/dist/windfoil/trace/contours.d.ts +5 -0
- package/dist/windfoil/trace/contours.js +167 -43
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.d.ts +3 -1
- package/dist/windfoil/trace/fit.js +471 -175
- package/dist/windfoil/trace/fit.js.map +1 -1
- package/dist/windfoil/trace/outline.js +55 -30
- package/dist/windfoil/trace/outline.js.map +1 -1
- package/dist/windfoil/trace/types.d.ts +10 -0
- package/dist/windfoil/tracedOutlines.js +59 -34
- package/dist/windfoil/tracedOutlines.js.map +1 -1
- package/package.json +11 -11
- package/skills/ultra-text/references/three-tsl.md +2 -2
- package/skills/ultra-text/references/vanilla-webgpu.md +3 -2
- package/dist/assets/cpuSdf.worker-xS57yQbP.js.map +0 -1
- package/dist/slug-vanilla.js.map +0 -1
- package/dist/text/geometry.js +0 -348
- package/dist/text/geometry.js.map +0 -1
- package/dist/vanilla.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cpuWorker.js","names":["import.meta.
|
|
1
|
+
{"version":3,"file":"cpuWorker.js","names":["import.meta.ROLLDOWN_FILE_URL_WS0ejogqjneG5Vfqsm3kuQ"],"sources":["../../src/atlas/cpuWorker.ts"],"sourcesContent":["/** @internal Pre-spawned CPU SDF module worker overlapped with DOM capture and rasterization. */\nexport interface PreparedCpuWorker {\n readonly error: unknown\n take(): Worker | null\n dispose(): void\n}\n\nconst IDLE_TIMEOUT_MS = 10_000\n\ninterface PooledWorker {\n readonly worker: Worker\n readonly ctor: typeof Worker\n timer: ReturnType<typeof setTimeout> | null\n}\n\nlet warm: PooledWorker | null = null\n\nfunction clearWarm(terminate: boolean): void {\n const entry = warm\n if (!entry) return\n warm = null\n if (entry.timer !== null) {\n clearTimeout(entry.timer)\n entry.timer = null\n }\n entry.worker.onerror = null\n entry.worker.onmessage = null\n entry.worker.onmessageerror = null\n if (terminate) entry.worker.terminate()\n}\n\nfunction takeWarm(): Worker | null {\n const entry = warm\n if (!entry) return null\n if (typeof Worker === 'undefined' || entry.ctor !== Worker) {\n clearWarm(true)\n return null\n }\n clearWarm(false)\n return entry.worker\n}\n\nfunction releaseWarm(worker: Worker, ctor: typeof Worker): void {\n worker.onmessage = null\n worker.onmessageerror = null\n if (warm !== null || typeof Worker === 'undefined' || ctor !== Worker) {\n worker.onerror = null\n worker.terminate()\n return\n }\n const timer = setTimeout(() => {\n if (warm?.worker === worker) clearWarm(true)\n }, IDLE_TIMEOUT_MS)\n ;(timer as { unref?: () => void }).unref?.()\n const entry: PooledWorker = { worker, ctor, timer }\n worker.onerror = (event) => {\n event.preventDefault()\n if (warm?.worker === worker) clearWarm(true)\n }\n warm = entry\n}\n\n/** @internal Terminates any idle pooled CPU SDF worker. */\nexport function disposeCpuWorkerPool(): void {\n clearWarm(true)\n}\n\nfunction spawnWorker(): Worker {\n return new Worker(new URL('./cpuSdf.worker.js', import.meta.url), { type: 'module' })\n}\n\n/** @internal Starts or claims a warm CPU SDF worker early so load/compile overlaps DOM capture. */\nexport function prepareCpuWorker(): PreparedCpuWorker | null {\n if (typeof Worker === 'undefined') return null\n const pooled = takeWarm()\n try {\n const worker = pooled ?? spawnWorker()\n let closed = false\n let taken = false\n let earlyError: unknown\n worker.onerror = (event) => {\n event.preventDefault()\n earlyError = new Error(event.message || 'CPU SDF worker failed')\n }\n return {\n get error() {\n return earlyError\n },\n take() {\n if (closed || taken || earlyError !== undefined) return null\n taken = true\n return worker\n },\n dispose() {\n if (closed || taken) return\n closed = true\n worker.onerror = null\n worker.terminate()\n },\n }\n } catch {\n return null\n }\n}\n\n/**\n * Encodes an SDF atlas in a dedicated worker, keeping one warm idle-timed worker across\n * sequential bakes while spawning a separate worker when busy and terminating on error or abort.\n * The canvas's RGBA pixels are transferred, so the caller no longer owns them; the worker takes\n * their alpha.\n */\nexport function encodeInWorker(\n rgba: Uint8ClampedArray,\n width: number,\n height: number,\n pxRange: number,\n signal?: AbortSignal,\n prepared?: PreparedCpuWorker | null,\n): Promise<Uint8Array> {\n signal?.throwIfAborted()\n if (prepared?.error !== undefined) {\n const earlyError = prepared.error\n prepared.dispose()\n return Promise.reject(\n earlyError instanceof Error ? earlyError : new Error('CPU SDF worker failed'),\n )\n }\n const owned = prepared?.take() ?? null\n const ctor = typeof Worker !== 'undefined' ? Worker : null\n if (!ctor && !owned) return Promise.reject(new Error('Worker is unavailable'))\n const pooled = owned ?? takeWarm()\n return new Promise((resolve, reject) => {\n const workerCtor = ctor ?? (owned!.constructor as typeof Worker)\n const worker = pooled ?? spawnWorker()\n let settled = false\n const finish = (error?: unknown, result?: Uint8Array): void => {\n if (settled) return\n settled = true\n signal?.removeEventListener('abort', abort)\n if (result) {\n releaseWarm(worker, workerCtor)\n resolve(result)\n } else {\n worker.onmessage = null\n worker.onerror = null\n worker.onmessageerror = null\n worker.terminate()\n // AbortSignal.reason is caller-owned and can be any value.\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n reject(error)\n }\n }\n const abort = (): void => finish(signal?.reason)\n signal?.addEventListener('abort', abort, { once: true })\n worker.onmessage = (event: MessageEvent<unknown>) => {\n const result = event.data\n if (!(result instanceof Uint8Array) || result.length !== width * height) {\n finish(new Error('Invalid CPU SDF worker result'))\n } else finish(undefined, result)\n }\n worker.onerror = (event) => {\n event.preventDefault()\n finish(new Error(event.message || 'CPU SDF worker failed'))\n }\n worker.onmessageerror = () => finish(new Error('CPU SDF worker transfer failed'))\n try {\n worker.postMessage({ rgba, width, height, pxRange }, [rgba.buffer as ArrayBuffer])\n } catch (error) {\n finish(error)\n }\n })\n}\n"],"mappings":";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,UAAU;IAGjB,OAAO,KAAK;GACd;EACF;EACA,MAAM,cAAoB,OAAO,QAAQ,MAAM;EAC/C,QAAQ,iBAAiB,SAAS,OAAO,EAAE,MAAM,KAAK,CAAC;EACvD,OAAO,aAAa,UAAiC;GACnD,MAAM,SAAS,MAAM;GACrB,IAAI,EAAE,kBAAkB,eAAe,OAAO,WAAW,QAAQ,QAC/D,uBAAO,IAAI,MAAM,+BAA+B,CAAC;QAC5C,OAAO,KAAA,GAAW,MAAM;EACjC;EACA,OAAO,WAAW,UAAU;GAC1B,MAAM,eAAe;GACrB,OAAO,IAAI,MAAM,MAAM,WAAW,uBAAuB,CAAC;EAC5D;EACA,OAAO,uBAAuB,uBAAO,IAAI,MAAM,gCAAgC,CAAC;EAChF,IAAI;GACF,OAAO,YAAY;IAAE;IAAM;IAAO;IAAQ;GAAQ,GAAG,CAAC,KAAK,MAAqB,CAAC;EACnF,SAAS,OAAO;GACd,OAAO,KAAK;EACd;CACF,CAAC;AACH"}
|
package/dist/atlas/gpuAtlas.js
CHANGED
|
@@ -1,126 +1,60 @@
|
|
|
1
|
+
import { checkCommonAtlasLimits, encodeJfaWork, jfaSteps, openErrorScopes, prefersTiledJfa, selectWorkgroupDimension, supportsDirectStore } from "./gpuCommon.js";
|
|
1
2
|
import { buildJfaWgsl } from "./jfaWgsl.js";
|
|
2
3
|
import { ExternalTexture, LinearFilter, LinearMipmapLinearFilter, NoColorSpace, RedFormat, WebGPUBackend } from "three/webgpu";
|
|
3
4
|
// src/atlas/gpuAtlas.ts
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
function selectWorkgroupDimension(limits) {
|
|
16
|
-
const inv = limits?.maxComputeInvocationsPerWorkgroup ?? 256;
|
|
17
|
-
const wx = limits?.maxComputeWorkgroupSizeX ?? 256;
|
|
18
|
-
const wy = limits?.maxComputeWorkgroupSizeY ?? 256;
|
|
19
|
-
return inv >= CORE_WORKGROUP_DIMENSION ** 2 && wx >= CORE_WORKGROUP_DIMENSION && wy >= CORE_WORKGROUP_DIMENSION ? CORE_WORKGROUP_DIMENSION : MIN_WORKGROUP_DIMENSION;
|
|
20
|
-
}
|
|
21
|
-
function supportsDirectStore(device) {
|
|
22
|
-
const textures = globalThis.GPUTextureUsage;
|
|
23
|
-
return typeof textures?.STORAGE_BINDING === "number" && textures.STORAGE_BINDING > 0 && Boolean(device.features?.has("texture-formats-tier1"));
|
|
24
|
-
}
|
|
25
|
-
/** A texture-to-buffer copy aligns each row to 256 bytes; the raster keeps 4 bytes a texel. */
|
|
26
|
-
function rasterRowBytes(width) {
|
|
27
|
-
return Math.ceil(width / 64) * 256;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Past a device limit the passes are invalid, which WebGPU reports only asynchronously:
|
|
31
|
-
* checking first lets `auto` fall back without GPU work and `gpu` fail with a reason.
|
|
32
|
-
*/
|
|
33
|
-
function checkAtlasLimits(limits, width, height, maxStep, directStore) {
|
|
34
|
-
if (maxStep > 64) throw new RangeError("buildGpuSdfAtlas: pxRange exceeds fixed-point jump range; use atlasMode \"cpu\"");
|
|
35
|
-
if (!limits) return;
|
|
36
|
-
for (const [name, need] of KERNEL_NEEDS) {
|
|
37
|
-
const value = limits[name];
|
|
38
|
-
if (value !== void 0 && value < need) throw new RangeError(`buildGpuSdfAtlas: ${name}=${value}, needs ${need}; use atlasMode "cpu"`);
|
|
39
|
-
}
|
|
40
|
-
if (!directStore) {
|
|
41
|
-
const fragBuffers = limits.maxStorageBuffersInFragmentStage;
|
|
42
|
-
if (fragBuffers !== void 0 && fragBuffers < FRAGMENT_STORAGE_BUFFERS) throw new RangeError(`buildGpuSdfAtlas: maxStorageBuffersInFragmentStage=${fragBuffers}, needs ${FRAGMENT_STORAGE_BUFFERS}; use atlasMode "cpu"`);
|
|
43
|
-
}
|
|
44
|
-
const largest = limits.maxTextureDimension2D;
|
|
45
|
-
if (largest !== void 0 && Math.max(width, height) > largest) throw new RangeError(`buildGpuSdfAtlas: ${width}×${height} exceeds maxTextureDimension2D=${largest}; lower maxAtlasSize`);
|
|
46
|
-
const bytes = Math.max(width * height * SEED_BYTES_PER_TEXEL, rasterRowBytes(width) * height);
|
|
47
|
-
if (bytes > limits.maxStorageBufferBindingSize || bytes > limits.maxBufferSize) throw new RangeError(`buildGpuSdfAtlas: ${width}×${height} exceeds storage-buffer limits; use atlasMode "cpu" or lower maxAtlasSize`);
|
|
5
|
+
var devicePipelines = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
function asAtlasPipelines(workgroupDim, directStore, tiledStore, multi) {
|
|
7
|
+
return {
|
|
8
|
+
workgroupDim,
|
|
9
|
+
directStore,
|
|
10
|
+
seed: multi?.seed ?? null,
|
|
11
|
+
jump: multi?.jump ?? null,
|
|
12
|
+
jumpStore: multi?.jumpStore ?? null,
|
|
13
|
+
tiledStore,
|
|
14
|
+
resolve: multi?.resolve ?? null
|
|
15
|
+
};
|
|
48
16
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return error ? error.message ?? "unknown GPU error" : null;
|
|
63
|
-
}, (error) => String(error));
|
|
64
|
-
} };
|
|
17
|
+
function getDeviceCache(device, workgroupDim, directStore) {
|
|
18
|
+
const existing = devicePipelines.get(device);
|
|
19
|
+
if (existing?.workgroupDim === workgroupDim && existing.directStore === directStore) return existing;
|
|
20
|
+
const cache = {
|
|
21
|
+
workgroupDim,
|
|
22
|
+
directStore,
|
|
23
|
+
module: device.createShaderModule({
|
|
24
|
+
label: "ultra-text atlas",
|
|
25
|
+
code: buildJfaWgsl(workgroupDim, directStore)
|
|
26
|
+
})
|
|
27
|
+
};
|
|
28
|
+
devicePipelines.set(device, cache);
|
|
29
|
+
return cache;
|
|
65
30
|
}
|
|
66
|
-
function
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
for (; step >= 1; step >>= 1) steps.push(step);
|
|
72
|
-
return steps;
|
|
31
|
+
function cachedAtlasPipelines(device, workgroupDim, directStore, tiledOnly) {
|
|
32
|
+
const cache = devicePipelines.get(device);
|
|
33
|
+
if (cache?.workgroupDim !== workgroupDim || cache.directStore !== directStore) return void 0;
|
|
34
|
+
if (tiledOnly) return cache.tiledStore ? asAtlasPipelines(workgroupDim, directStore, cache.tiledStore) : void 0;
|
|
35
|
+
return cache.multi ? asAtlasPipelines(workgroupDim, directStore, null, cache.multi) : void 0;
|
|
73
36
|
}
|
|
74
|
-
var devicePipelines = /* @__PURE__ */ new WeakMap();
|
|
75
|
-
var devicePipelinePromises = /* @__PURE__ */ new WeakMap();
|
|
76
37
|
function supportsAsyncAtlasPipelines(device, directStore) {
|
|
77
38
|
return typeof device.createComputePipelineAsync === "function" && (directStore || typeof device.createRenderPipelineAsync === "function");
|
|
78
39
|
}
|
|
79
|
-
function
|
|
80
|
-
const cached =
|
|
81
|
-
if (cached
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
40
|
+
function buildAtlasPipelines(device, workgroupDim, directStore, tiledOnly, async) {
|
|
41
|
+
const cached = cachedAtlasPipelines(device, workgroupDim, directStore, tiledOnly);
|
|
42
|
+
if (cached) return async ? Promise.resolve(cached) : cached;
|
|
43
|
+
const existing = devicePipelines.get(device);
|
|
44
|
+
const sameConfig = existing?.workgroupDim === workgroupDim && existing.directStore === directStore;
|
|
45
|
+
if (async && sameConfig) {
|
|
46
|
+
const inFlight = tiledOnly ? existing.tiledPromise : existing.multiPromise;
|
|
47
|
+
if (inFlight) return inFlight;
|
|
48
|
+
}
|
|
49
|
+
const cache = getDeviceCache(device, workgroupDim, directStore);
|
|
50
|
+
const module = cache.module;
|
|
51
|
+
const computeSync = (entryPoint) => device.createComputePipeline({
|
|
87
52
|
layout: "auto",
|
|
88
53
|
compute: {
|
|
89
54
|
module,
|
|
90
55
|
entryPoint
|
|
91
56
|
}
|
|
92
57
|
});
|
|
93
|
-
const pipelines = {
|
|
94
|
-
workgroupDim,
|
|
95
|
-
directStore,
|
|
96
|
-
seed: compute("seedMain"),
|
|
97
|
-
jump: compute("jumpMain"),
|
|
98
|
-
jumpStore: directStore ? compute("jumpStoreMain") : null,
|
|
99
|
-
resolve: directStore ? null : device.createRenderPipeline({
|
|
100
|
-
layout: "auto",
|
|
101
|
-
vertex: {
|
|
102
|
-
module,
|
|
103
|
-
entryPoint: "fullscreenVert"
|
|
104
|
-
},
|
|
105
|
-
fragment: {
|
|
106
|
-
module,
|
|
107
|
-
entryPoint: "resolveFrag",
|
|
108
|
-
targets: [{ format: "r8unorm" }]
|
|
109
|
-
}
|
|
110
|
-
})
|
|
111
|
-
};
|
|
112
|
-
devicePipelines.set(device, pipelines);
|
|
113
|
-
return pipelines;
|
|
114
|
-
}
|
|
115
|
-
function atlasPipelinesAsync(device, workgroupDim, directStore) {
|
|
116
|
-
const cached = devicePipelines.get(device);
|
|
117
|
-
if (cached?.directStore === directStore && cached.workgroupDim === workgroupDim) return Promise.resolve(cached);
|
|
118
|
-
const inFlight = devicePipelinePromises.get(device);
|
|
119
|
-
if (inFlight?.directStore === directStore && inFlight.workgroupDim === workgroupDim) return inFlight.promise;
|
|
120
|
-
const module = device.createShaderModule({
|
|
121
|
-
label: "ultra-text atlas",
|
|
122
|
-
code: buildJfaWgsl(workgroupDim, directStore)
|
|
123
|
-
});
|
|
124
58
|
const computeAsync = (entryPoint) => device.createComputePipelineAsync({
|
|
125
59
|
layout: "auto",
|
|
126
60
|
compute: {
|
|
@@ -128,57 +62,69 @@ function atlasPipelinesAsync(device, workgroupDim, directStore) {
|
|
|
128
62
|
entryPoint
|
|
129
63
|
}
|
|
130
64
|
});
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
65
|
+
if (tiledOnly) {
|
|
66
|
+
const store = (tiledStore) => {
|
|
67
|
+
cache.tiledStore = tiledStore;
|
|
68
|
+
return asAtlasPipelines(workgroupDim, directStore, tiledStore);
|
|
69
|
+
};
|
|
70
|
+
if (!async) return store(computeSync("tiledStoreMain"));
|
|
71
|
+
const promise = computeAsync("tiledStoreMain").then((tiledStore) => store(tiledStore), (error) => {
|
|
72
|
+
if (cache.tiledPromise === promise) cache.tiledPromise = void 0;
|
|
73
|
+
throw error;
|
|
74
|
+
});
|
|
75
|
+
cache.tiledPromise = promise;
|
|
76
|
+
return promise;
|
|
77
|
+
}
|
|
78
|
+
const resolveDesc = {
|
|
79
|
+
layout: "auto",
|
|
80
|
+
vertex: {
|
|
81
|
+
module,
|
|
82
|
+
entryPoint: "fullscreenVert"
|
|
83
|
+
},
|
|
84
|
+
fragment: {
|
|
85
|
+
module,
|
|
86
|
+
entryPoint: "resolveFrag",
|
|
87
|
+
targets: [{ format: "r8unorm" }]
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const store = (seed, jump, jumpStore, resolve) => {
|
|
91
|
+
const multi = {
|
|
151
92
|
seed,
|
|
152
93
|
jump,
|
|
153
94
|
jumpStore,
|
|
154
95
|
resolve
|
|
155
96
|
};
|
|
156
|
-
|
|
157
|
-
return
|
|
158
|
-
}
|
|
159
|
-
|
|
97
|
+
cache.multi = multi;
|
|
98
|
+
return asAtlasPipelines(workgroupDim, directStore, null, multi);
|
|
99
|
+
};
|
|
100
|
+
if (!async) return store(computeSync("seedMain"), computeSync("jumpMain"), directStore ? computeSync("jumpStoreMain") : null, directStore ? null : device.createRenderPipeline(resolveDesc));
|
|
101
|
+
const promise = Promise.all([
|
|
102
|
+
computeAsync("seedMain"),
|
|
103
|
+
computeAsync("jumpMain"),
|
|
104
|
+
directStore ? computeAsync("jumpStoreMain") : Promise.resolve(null),
|
|
105
|
+
directStore ? Promise.resolve(null) : device.createRenderPipelineAsync(resolveDesc)
|
|
106
|
+
]).then(([seed, jump, jumpStore, resolve]) => store(seed, jump, jumpStore, resolve), (error) => {
|
|
107
|
+
if (cache.multiPromise === promise) cache.multiPromise = void 0;
|
|
160
108
|
throw error;
|
|
161
109
|
});
|
|
162
|
-
|
|
163
|
-
workgroupDim,
|
|
164
|
-
directStore,
|
|
165
|
-
promise
|
|
166
|
-
});
|
|
110
|
+
cache.multiPromise = promise;
|
|
167
111
|
return promise;
|
|
168
112
|
}
|
|
169
113
|
/**
|
|
170
114
|
* @internal Starts the native compile of the device's atlas passes ahead of its first atlas,
|
|
171
115
|
* while the caller reads the DOM.
|
|
172
116
|
*/
|
|
173
|
-
function prepareAtlasPasses(renderer) {
|
|
117
|
+
function prepareAtlasPasses(renderer, pxRange) {
|
|
174
118
|
const device = atlasDevice(renderer);
|
|
175
|
-
if (device?.createShaderModule
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
119
|
+
if (!device?.createShaderModule) return;
|
|
120
|
+
const directStore = supportsDirectStore(device.features);
|
|
121
|
+
const workgroupDim = selectWorkgroupDimension(device.limits);
|
|
122
|
+
const tiledOnly = prefersTiledJfa(directStore, pxRange);
|
|
123
|
+
const cached = devicePipelines.get(device);
|
|
124
|
+
if (cached?.workgroupDim === workgroupDim && cached.directStore === directStore && (tiledOnly ? cached.tiledStore || cached.tiledPromise : cached.multi || cached.multiPromise)) return;
|
|
125
|
+
if (supportsAsyncAtlasPipelines(device, directStore)) buildAtlasPipelines(device, workgroupDim, directStore, tiledOnly, true).catch(() => void 0);
|
|
126
|
+
else buildAtlasPipelines(device, workgroupDim, directStore, tiledOnly, false);
|
|
127
|
+
device.queue.submit([]);
|
|
182
128
|
}
|
|
183
129
|
/**
|
|
184
130
|
* @internal Regenerates the mips of an atlas texture from its level 0 with three's own mip
|
|
@@ -205,156 +151,35 @@ function atlasDevice(renderer) {
|
|
|
205
151
|
* `mipLevelCount` levels, all in one command buffer.
|
|
206
152
|
*/
|
|
207
153
|
async function encodeGpuSdf(device, raster, mipLevelCount, finish, onSubmitted) {
|
|
208
|
-
const { width, height, pxRange } = raster;
|
|
154
|
+
const { width, height, pxRange, canvas } = raster;
|
|
209
155
|
const { GPUBufferUsage: buffers, GPUTextureUsage: textures } = globalThis;
|
|
210
156
|
if (!device?.createCommandEncoder || !buffers || !textures) throw new Error("buildGpuSdfAtlas: device cannot run the atlas passes");
|
|
211
157
|
const steps = jfaSteps(pxRange);
|
|
212
|
-
const directStore = supportsDirectStore(device);
|
|
213
|
-
|
|
158
|
+
const directStore = supportsDirectStore(device.features);
|
|
159
|
+
checkCommonAtlasLimits("buildGpuSdfAtlas", device.limits, width, height, steps[0], directStore, "; use atlasMode \"cpu\"");
|
|
214
160
|
const workgroupDim = selectWorkgroupDimension(device.limits);
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
161
|
+
const tiledOnly = directStore && steps[0] === 4;
|
|
162
|
+
let prebuilt = cachedAtlasPipelines(device, workgroupDim, directStore, tiledOnly);
|
|
163
|
+
if (!prebuilt && supportsAsyncAtlasPipelines(device, directStore)) try {
|
|
164
|
+
prebuilt = await buildAtlasPipelines(device, workgroupDim, directStore, tiledOnly, true);
|
|
218
165
|
} catch (error) {
|
|
219
166
|
throw new Error(`buildGpuSdfAtlas: the device rejected the atlas passes: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
220
167
|
}
|
|
221
|
-
else if (!(prebuilt?.directStore === directStore && prebuilt.workgroupDim === workgroupDim)) prebuilt = void 0;
|
|
222
168
|
const transient = [];
|
|
223
169
|
let output;
|
|
224
170
|
try {
|
|
225
171
|
const scopes = openErrorScopes(device);
|
|
226
172
|
let reported;
|
|
227
173
|
try {
|
|
228
|
-
const pipelines = prebuilt ??
|
|
229
|
-
const rowBytes = rasterRowBytes(width);
|
|
230
|
-
const buffer = (size, usage) => {
|
|
231
|
-
const created = device.createBuffer({
|
|
232
|
-
size,
|
|
233
|
-
usage
|
|
234
|
-
});
|
|
235
|
-
transient.push(created);
|
|
236
|
-
return created;
|
|
237
|
-
};
|
|
238
|
-
const upload = device.createTexture({
|
|
239
|
-
size: [width, height],
|
|
240
|
-
format: "rgba8unorm",
|
|
241
|
-
usage: textures.COPY_SRC | textures.COPY_DST | textures.RENDER_ATTACHMENT
|
|
242
|
-
});
|
|
243
|
-
transient.push(upload);
|
|
244
|
-
const words = buffer(rowBytes * height, buffers.STORAGE | buffers.COPY_DST);
|
|
245
|
-
const seedBytes = width * height * SEED_BYTES_PER_TEXEL;
|
|
246
|
-
const seeds = [buffer(seedBytes, buffers.STORAGE), buffer(seedBytes, buffers.STORAGE)];
|
|
247
|
-
const params = buffer(steps.length * 256 + 16, buffers.UNIFORM | buffers.COPY_DST);
|
|
248
|
-
const values = new Int32Array(steps.length * 64 + 4);
|
|
249
|
-
const invPxRange = 1 / pxRange;
|
|
250
|
-
values.set([
|
|
251
|
-
width,
|
|
252
|
-
height,
|
|
253
|
-
rowBytes / 4
|
|
254
|
-
]);
|
|
255
|
-
new Float32Array(values.buffer, 12, 1)[0] = invPxRange;
|
|
256
|
-
steps.forEach((step, index) => {
|
|
257
|
-
const base = (index + 1) * 64;
|
|
258
|
-
values.set([
|
|
259
|
-
width,
|
|
260
|
-
height,
|
|
261
|
-
step
|
|
262
|
-
], base);
|
|
263
|
-
new Float32Array(values.buffer, base * 4 + 12, 1)[0] = invPxRange;
|
|
264
|
-
});
|
|
265
|
-
device.queue.writeBuffer(params, 0, values);
|
|
266
|
-
device.queue.copyExternalImageToTexture({
|
|
267
|
-
source: raster.canvas,
|
|
268
|
-
flipY: false
|
|
269
|
-
}, {
|
|
270
|
-
texture: upload,
|
|
271
|
-
premultipliedAlpha: false
|
|
272
|
-
}, [width, height]);
|
|
174
|
+
const pipelines = prebuilt ?? buildAtlasPipelines(device, workgroupDim, directStore, tiledOnly, false);
|
|
273
175
|
output = device.createTexture({
|
|
274
176
|
size: [width, height],
|
|
275
177
|
mipLevelCount,
|
|
276
178
|
format: "r8unorm",
|
|
277
179
|
usage: textures.RENDER_ATTACHMENT | textures.TEXTURE_BINDING | textures.COPY_SRC | textures.COPY_DST | (pipelines.directStore ? textures.STORAGE_BINDING ?? 0 : 0)
|
|
278
180
|
});
|
|
279
|
-
const bind = (pipeline, offset, ...storageBuffers) => device.createBindGroup({
|
|
280
|
-
layout: pipeline.getBindGroupLayout(0),
|
|
281
|
-
entries: [{
|
|
282
|
-
binding: 0,
|
|
283
|
-
resource: {
|
|
284
|
-
buffer: params,
|
|
285
|
-
offset,
|
|
286
|
-
size: 16
|
|
287
|
-
}
|
|
288
|
-
}, ...storageBuffers.map((resource, index) => ({
|
|
289
|
-
binding: index + 1,
|
|
290
|
-
resource: { buffer: resource }
|
|
291
|
-
}))]
|
|
292
|
-
});
|
|
293
181
|
const encoder = device.createCommandEncoder();
|
|
294
|
-
|
|
295
|
-
buffer: words,
|
|
296
|
-
bytesPerRow: rowBytes,
|
|
297
|
-
rowsPerImage: height
|
|
298
|
-
}, [width, height]);
|
|
299
|
-
const groupsX = Math.ceil(width / pipelines.workgroupDim);
|
|
300
|
-
const groupsY = Math.ceil(height / pipelines.workgroupDim);
|
|
301
|
-
const flood = encoder.beginComputePass();
|
|
302
|
-
flood.setPipeline(pipelines.seed);
|
|
303
|
-
flood.setBindGroup(0, bind(pipelines.seed, 0, words, seeds[0]));
|
|
304
|
-
flood.dispatchWorkgroups(groupsX, groupsY);
|
|
305
|
-
if (pipelines.directStore && pipelines.jumpStore) {
|
|
306
|
-
const midSteps = steps.length - 1;
|
|
307
|
-
if (midSteps > 0) {
|
|
308
|
-
flood.setPipeline(pipelines.jump);
|
|
309
|
-
for (let index = 0; index < midSteps; index++) {
|
|
310
|
-
const into = seeds[(index + 1) % 2];
|
|
311
|
-
flood.setBindGroup(0, bind(pipelines.jump, (index + 1) * 256, seeds[index % 2], into));
|
|
312
|
-
flood.dispatchWorkgroups(groupsX, groupsY);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
const finalView = output.createView({ mipLevelCount: 1 });
|
|
316
|
-
flood.setPipeline(pipelines.jumpStore);
|
|
317
|
-
flood.setBindGroup(0, device.createBindGroup({
|
|
318
|
-
layout: pipelines.jumpStore.getBindGroupLayout(0),
|
|
319
|
-
entries: [
|
|
320
|
-
{
|
|
321
|
-
binding: 0,
|
|
322
|
-
resource: {
|
|
323
|
-
buffer: params,
|
|
324
|
-
offset: steps.length * 256,
|
|
325
|
-
size: 16
|
|
326
|
-
}
|
|
327
|
-
},
|
|
328
|
-
{
|
|
329
|
-
binding: 1,
|
|
330
|
-
resource: { buffer: seeds[midSteps % 2] }
|
|
331
|
-
},
|
|
332
|
-
{
|
|
333
|
-
binding: 2,
|
|
334
|
-
resource: finalView
|
|
335
|
-
}
|
|
336
|
-
]
|
|
337
|
-
}));
|
|
338
|
-
flood.dispatchWorkgroups(groupsX, groupsY);
|
|
339
|
-
flood.end();
|
|
340
|
-
} else {
|
|
341
|
-
flood.setPipeline(pipelines.jump);
|
|
342
|
-
steps.forEach((_, index) => {
|
|
343
|
-
const into = seeds[(index + 1) % 2];
|
|
344
|
-
flood.setBindGroup(0, bind(pipelines.jump, (index + 1) * 256, seeds[index % 2], into));
|
|
345
|
-
flood.dispatchWorkgroups(groupsX, groupsY);
|
|
346
|
-
});
|
|
347
|
-
flood.end();
|
|
348
|
-
const resolve = encoder.beginRenderPass({ colorAttachments: [{
|
|
349
|
-
view: output.createView({ mipLevelCount: 1 }),
|
|
350
|
-
loadOp: "clear",
|
|
351
|
-
storeOp: "store"
|
|
352
|
-
}] });
|
|
353
|
-
resolve.setPipeline(pipelines.resolve);
|
|
354
|
-
resolve.setBindGroup(0, bind(pipelines.resolve, 0, seeds[steps.length % 2]));
|
|
355
|
-
resolve.draw(3);
|
|
356
|
-
resolve.end();
|
|
357
|
-
}
|
|
182
|
+
encodeJfaWork(device, encoder, pipelines, canvas, width, height, pxRange, steps, output, transient, buffers, textures);
|
|
358
183
|
finish?.(encoder, output);
|
|
359
184
|
device.queue.submit([encoder.finish()]);
|
|
360
185
|
} finally {
|
|
@@ -364,7 +189,6 @@ async function encodeGpuSdf(device, raster, mipLevelCount, finish, onSubmitted)
|
|
|
364
189
|
const rejection = await reported;
|
|
365
190
|
if (rejection !== null) {
|
|
366
191
|
devicePipelines.delete(device);
|
|
367
|
-
devicePipelinePromises.delete(device);
|
|
368
192
|
throw new Error(`buildGpuSdfAtlas: the device rejected the atlas passes: ${rejection}`);
|
|
369
193
|
}
|
|
370
194
|
const retained = output;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gpuAtlas.js","names":[],"sources":["../../src/atlas/gpuAtlas.ts"],"sourcesContent":["import {\n ExternalTexture,\n LinearFilter,\n LinearMipmapLinearFilter,\n NoColorSpace,\n RedFormat,\n WebGPUBackend,\n type Texture,\n type WebGPURenderer,\n} from 'three/webgpu'\n\nimport type { BuildSdfAtlasOptions, RasterAtlas, SdfAtlas } from '../types.js'\nimport { buildJfaWgsl } from './jfaWgsl.js'\nimport type { ShapeRows } from './rasterize.js'\n\n// Compatibility mode guarantees 128 invocations (8×8 = 64); core WebGPU devices provide >= 256\n// (16×16 = 256). Both visit neighbours in identical order and produce identical SDF bytes.\nconst MIN_WORKGROUP_DIMENSION = 8\nconst CORE_WORKGROUP_DIMENSION = 16\nconst SEED_BYTES_PER_TEXEL = 4\nconst COMPUTE_STORAGE_BUFFERS = 2\nconst FRAGMENT_STORAGE_BUFFERS = 1\n\ninterface AtlasDeviceLimits {\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\ntype AtlasErrorFilter = 'validation' | 'out-of-memory' | 'internal'\n\n/** @internal The WebGPU texture calls the atlas makes (no `@webgpu/types` needed). */\nexport interface AtlasGpuTexture {\n readonly mipLevelCount: number\n createView(descriptor?: { baseMipLevel?: number; mipLevelCount?: number }): unknown\n destroy(): void\n}\n\ninterface AtlasGpuBuffer {\n destroy(): void\n}\n\ninterface AtlasPipeline {\n getBindGroupLayout(index: number): unknown\n}\n\ninterface AtlasPass {\n setPipeline(pipeline: AtlasPipeline): void\n setBindGroup(index: number, bindGroup: unknown): void\n end(): void\n}\n\n/** @internal One command encoder of the atlas passes, which a patch adds its copies to. */\nexport interface AtlasEncoder {\n copyTextureToBuffer(\n source: { texture: AtlasGpuTexture },\n destination: { buffer: AtlasGpuBuffer; bytesPerRow: number; rowsPerImage: number },\n size: [number, number],\n ): void\n copyTextureToTexture(\n source: { texture: AtlasGpuTexture; origin: [number, number] },\n destination: { texture: AtlasGpuTexture; origin: [number, number] },\n size: [number, number],\n ): void\n beginComputePass(): AtlasPass & { dispatchWorkgroups(x: number, y: number): void }\n beginRenderPass(descriptor: {\n colorAttachments: { view: unknown; loadOp: 'clear'; storeOp: 'store' }[]\n }): AtlasPass & { draw(vertexCount: number): void }\n finish(): unknown\n}\n\n/** @internal The device calls of the atlas passes, called with the device as `this`. */\nexport interface AtlasDevice {\n readonly features?: { has(name: string): boolean }\n readonly limits?: AtlasDeviceLimits\n createTexture(descriptor: {\n size: [number, number]\n mipLevelCount?: number\n format: string\n usage: number\n }): AtlasGpuTexture\n createBuffer(descriptor: { size: number; usage: number }): AtlasGpuBuffer\n createShaderModule(descriptor: { label: string; code: string }): unknown\n createComputePipeline(descriptor: {\n layout: 'auto'\n compute: { module: unknown; entryPoint: string }\n }): AtlasPipeline\n readonly createComputePipelineAsync?: (descriptor: {\n layout: 'auto'\n compute: { module: unknown; entryPoint: string }\n }) => Promise<AtlasPipeline>\n createRenderPipeline(descriptor: {\n layout: 'auto'\n vertex: { module: unknown; entryPoint: string }\n fragment: { module: unknown; entryPoint: string; targets: { format: string }[] }\n }): AtlasPipeline\n readonly createRenderPipelineAsync?: (descriptor: {\n layout: 'auto'\n vertex: { module: unknown; entryPoint: string }\n fragment: { module: unknown; entryPoint: string; targets: { format: string }[] }\n }) => Promise<AtlasPipeline>\n createBindGroup(descriptor: {\n layout: unknown\n entries: { binding: number; resource: unknown }[]\n }): unknown\n createCommandEncoder(): AtlasEncoder\n readonly queue: {\n copyExternalImageToTexture(\n source: { source: HTMLCanvasElement; flipY: boolean },\n destination: { texture: AtlasGpuTexture; premultipliedAlpha: boolean },\n size: [number, number],\n ): void\n writeBuffer(buffer: AtlasGpuBuffer, offset: number, data: Int32Array): void\n submit(commandBuffers: unknown[]): void\n }\n readonly pushErrorScope?: (filter: AtlasErrorFilter) => void\n readonly popErrorScope?: () => Promise<{ readonly message?: string } | null>\n}\n\ninterface UsageFlags {\n GPUBufferUsage?: { STORAGE: number; UNIFORM: number; COPY_DST: number }\n GPUTextureUsage?: {\n COPY_SRC: number\n COPY_DST: number\n TEXTURE_BINDING: number\n STORAGE_BINDING?: number\n RENDER_ATTACHMENT: number\n }\n}\n\nconst KERNEL_NEEDS = [\n ['maxComputeInvocationsPerWorkgroup', MIN_WORKGROUP_DIMENSION ** 2],\n ['maxComputeWorkgroupSizeX', MIN_WORKGROUP_DIMENSION],\n ['maxComputeWorkgroupSizeY', MIN_WORKGROUP_DIMENSION],\n ['maxStorageBuffersPerShaderStage', COMPUTE_STORAGE_BUFFERS],\n] as const satisfies readonly (readonly [keyof AtlasDeviceLimits, number])[]\n\nfunction selectWorkgroupDimension(limits?: AtlasDeviceLimits): 8 | 16 {\n const inv = limits?.maxComputeInvocationsPerWorkgroup ?? 256\n const wx = limits?.maxComputeWorkgroupSizeX ?? 256\n const wy = limits?.maxComputeWorkgroupSizeY ?? 256\n return inv >= CORE_WORKGROUP_DIMENSION ** 2 &&\n wx >= CORE_WORKGROUP_DIMENSION &&\n wy >= CORE_WORKGROUP_DIMENSION\n ? CORE_WORKGROUP_DIMENSION\n : MIN_WORKGROUP_DIMENSION\n}\n\nfunction supportsDirectStore(device: AtlasDevice): boolean {\n const textures = (globalThis as UsageFlags).GPUTextureUsage\n return (\n typeof textures?.STORAGE_BINDING === 'number' &&\n textures.STORAGE_BINDING > 0 &&\n Boolean(device.features?.has('texture-formats-tier1'))\n )\n}\n\n/** A texture-to-buffer copy aligns each row to 256 bytes; the raster keeps 4 bytes a texel. */\nfunction rasterRowBytes(width: number): number {\n return Math.ceil(width / 64) * 256\n}\n\n/**\n * Past a device limit the passes are invalid, which WebGPU reports only asynchronously:\n * checking first lets `auto` fall back without GPU work and `gpu` fail with a reason.\n */\nfunction checkAtlasLimits(\n limits: AtlasDeviceLimits | undefined,\n width: number,\n height: number,\n maxStep: number,\n directStore: boolean,\n): void {\n if (maxStep > 64) {\n throw new RangeError(\n 'buildGpuSdfAtlas: pxRange exceeds fixed-point jump range; use atlasMode \"cpu\"',\n )\n }\n if (!limits) return\n for (const [name, need] of KERNEL_NEEDS) {\n const value = limits[name]\n if (value !== undefined && value < need) {\n throw new RangeError(`buildGpuSdfAtlas: ${name}=${value}, needs ${need}; use atlasMode \"cpu\"`)\n }\n }\n if (!directStore) {\n const fragBuffers = limits.maxStorageBuffersInFragmentStage\n if (fragBuffers !== undefined && fragBuffers < FRAGMENT_STORAGE_BUFFERS) {\n throw new RangeError(\n `buildGpuSdfAtlas: maxStorageBuffersInFragmentStage=${fragBuffers}, needs ${FRAGMENT_STORAGE_BUFFERS}; use atlasMode \"cpu\"`,\n )\n }\n }\n const largest = limits.maxTextureDimension2D\n if (largest !== undefined && Math.max(width, height) > largest) {\n throw new RangeError(\n `buildGpuSdfAtlas: ${width}×${height} exceeds maxTextureDimension2D=${largest}; lower maxAtlasSize`,\n )\n }\n // Each ping-pong seed buffer holds one packed u32 fixed-point relative seed (4 bytes) per texel.\n const bytes = Math.max(width * height * SEED_BYTES_PER_TEXEL, rasterRowBytes(width) * height)\n if (bytes > limits.maxStorageBufferBindingSize || bytes > limits.maxBufferSize) {\n throw new RangeError(\n `buildGpuSdfAtlas: ${width}×${height} exceeds storage-buffer limits; use atlasMode \"cpu\" or lower maxAtlasSize`,\n )\n }\n}\n\nconst ERROR_FILTERS: readonly AtlasErrorFilter[] = ['validation', 'out-of-memory', 'internal']\n\nfunction openErrorScopes(device: AtlasDevice): { close(): Promise<string | null> } {\n const push = device.pushErrorScope\n const pop = device.popErrorScope\n if (!push || !pop) {\n return { close: () => Promise.resolve(null) }\n }\n for (const filter of ERROR_FILTERS) push.call(device, filter)\n return {\n close() {\n return Promise.all(ERROR_FILTERS.map(() => pop.call(device))).then(\n (errors) => {\n const error = errors.find(Boolean)\n return error ? (error.message ?? 'unknown GPU error') : null\n },\n (error: unknown) => String(error),\n )\n },\n }\n}\n\nfunction jfaSteps(pxRange: number): number[] {\n const radius = Math.ceil(pxRange * 0.5) + 1\n let step = 1\n while (step * 2 - 1 < radius) step <<= 1\n const steps: number[] = []\n for (; step >= 1; step >>= 1) steps.push(step)\n return steps\n}\n\ninterface AtlasPipelines {\n readonly workgroupDim: 8 | 16\n readonly directStore: boolean\n readonly seed: AtlasPipeline\n readonly jump: AtlasPipeline\n readonly jumpStore: AtlasPipeline | null\n readonly resolve: AtlasPipeline | null\n}\n\nconst devicePipelines = new WeakMap<AtlasDevice, AtlasPipelines>()\nconst devicePipelinePromises = new WeakMap<\n AtlasDevice,\n {\n readonly workgroupDim: 8 | 16\n readonly directStore: boolean\n readonly promise: Promise<AtlasPipelines>\n }\n>()\n\nfunction supportsAsyncAtlasPipelines(device: AtlasDevice, directStore: boolean): boolean {\n return (\n typeof device.createComputePipelineAsync === 'function' &&\n (directStore || typeof device.createRenderPipelineAsync === 'function')\n )\n}\n\nfunction atlasPipelinesSync(\n device: AtlasDevice,\n workgroupDim: 8 | 16,\n directStore: boolean,\n): AtlasPipelines {\n const cached = devicePipelines.get(device)\n if (cached?.directStore === directStore && cached.workgroupDim === workgroupDim) {\n return cached\n }\n const module = device.createShaderModule({\n label: 'ultra-text atlas',\n code: buildJfaWgsl(workgroupDim, directStore),\n })\n const compute = (entryPoint: string): AtlasPipeline =>\n device.createComputePipeline({ layout: 'auto', compute: { module, entryPoint } })\n const pipelines: AtlasPipelines = {\n workgroupDim,\n directStore,\n seed: compute('seedMain'),\n jump: compute('jumpMain'),\n jumpStore: directStore ? compute('jumpStoreMain') : null,\n resolve: directStore\n ? null\n : device.createRenderPipeline({\n layout: 'auto',\n vertex: { module, entryPoint: 'fullscreenVert' },\n fragment: { module, entryPoint: 'resolveFrag', targets: [{ format: 'r8unorm' }] },\n }),\n }\n devicePipelines.set(device, pipelines)\n return pipelines\n}\n\nfunction atlasPipelinesAsync(\n device: AtlasDevice,\n workgroupDim: 8 | 16,\n directStore: boolean,\n): Promise<AtlasPipelines> {\n const cached = devicePipelines.get(device)\n if (cached?.directStore === directStore && cached.workgroupDim === workgroupDim) {\n return Promise.resolve(cached)\n }\n const inFlight = devicePipelinePromises.get(device)\n if (inFlight?.directStore === directStore && inFlight.workgroupDim === workgroupDim) {\n return inFlight.promise\n }\n const module = device.createShaderModule({\n label: 'ultra-text atlas',\n code: buildJfaWgsl(workgroupDim, directStore),\n })\n const computeAsync = (entryPoint: string): Promise<AtlasPipeline> =>\n device.createComputePipelineAsync!({ layout: 'auto', compute: { module, entryPoint } })\n const promise = Promise.all([\n computeAsync('seedMain'),\n computeAsync('jumpMain'),\n directStore ? computeAsync('jumpStoreMain') : Promise.resolve(null),\n directStore\n ? Promise.resolve(null)\n : device.createRenderPipelineAsync!({\n layout: 'auto',\n vertex: { module, entryPoint: 'fullscreenVert' },\n fragment: { module, entryPoint: 'resolveFrag', targets: [{ format: 'r8unorm' }] },\n }),\n ]).then(\n ([seed, jump, jumpStore, resolve]) => {\n const pipelines: AtlasPipelines = {\n workgroupDim,\n directStore,\n seed,\n jump,\n jumpStore,\n resolve,\n }\n devicePipelines.set(device, pipelines)\n return pipelines\n },\n (error: unknown) => {\n devicePipelinePromises.delete(device)\n throw error\n },\n )\n devicePipelinePromises.set(device, { workgroupDim, directStore, promise })\n return promise\n}\n\n/**\n * @internal Starts the native compile of the device's atlas passes ahead of its first atlas,\n * while the caller reads the DOM.\n */\nexport function prepareAtlasPasses(renderer: WebGPURenderer): void {\n const device = atlasDevice(renderer)\n if (\n device?.createShaderModule &&\n !devicePipelines.has(device) &&\n !devicePipelinePromises.has(device)\n ) {\n const directStore = supportsDirectStore(device)\n const workgroupDim = selectWorkgroupDimension(device.limits)\n if (supportsAsyncAtlasPipelines(device, directStore)) {\n void atlasPipelinesAsync(device, workgroupDim, directStore).catch(() => undefined)\n } else {\n atlasPipelinesSync(device, workgroupDim, directStore)\n }\n device.queue.submit([])\n }\n}\n\n/**\n * @internal Regenerates the mips of an atlas texture from its level 0 with three's own mip\n * pass, as three does for a render target, after the submissions that wrote it.\n */\nexport async function generateAtlasMips(renderer: WebGPURenderer, texture: Texture): Promise<void> {\n const scopes = openErrorScopes(atlasDevice(renderer)!)\n let reported: Promise<string | null>\n try {\n renderer.initTexture(texture)\n ;(renderer.backend as unknown as { generateMipmaps(texture: Texture): void }).generateMipmaps(\n texture,\n )\n } finally {\n reported = scopes.close()\n }\n const rejection = await reported\n if (rejection !== null) throw new Error(`buildGpuSdfAtlas: mip generation failed: ${rejection}`)\n}\n\n/** @internal The device behind a WebGPU-backend renderer, or `undefined`. */\nexport function atlasDevice(renderer: WebGPURenderer): AtlasDevice | undefined {\n return (renderer.backend as unknown as { device?: AtlasDevice }).device\n}\n\n/**\n * @internal Runs the atlas passes over `raster` into level 0 of a new r8unorm texture of\n * `mipLevelCount` levels, all in one command buffer.\n */\nexport async function encodeGpuSdf(\n device: AtlasDevice | undefined,\n raster: Pick<RasterAtlas, 'canvas' | 'width' | 'height' | 'pxRange'>,\n mipLevelCount: number,\n finish?: (encoder: AtlasEncoder, texture: AtlasGpuTexture) => void,\n onSubmitted?: (texture: AtlasGpuTexture) => void,\n): Promise<AtlasGpuTexture> {\n const { width, height, pxRange } = raster\n const { GPUBufferUsage: buffers, GPUTextureUsage: textures } = globalThis as UsageFlags\n if (!device?.createCommandEncoder || !buffers || !textures)\n throw new Error('buildGpuSdfAtlas: device cannot run the atlas passes')\n const steps = jfaSteps(pxRange)\n const directStore = supportsDirectStore(device)\n checkAtlasLimits(device.limits, width, height, steps[0]!, directStore)\n const workgroupDim = selectWorkgroupDimension(device.limits)\n let prebuilt: AtlasPipelines | undefined = devicePipelines.get(device)\n if (\n !(prebuilt?.directStore === directStore && prebuilt.workgroupDim === workgroupDim) &&\n supportsAsyncAtlasPipelines(device, directStore)\n ) {\n try {\n prebuilt = await atlasPipelinesAsync(device, workgroupDim, directStore)\n } catch (error: unknown) {\n throw new Error(\n `buildGpuSdfAtlas: the device rejected the atlas passes: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n )\n }\n } else if (!(prebuilt?.directStore === directStore && prebuilt.workgroupDim === workgroupDim)) {\n prebuilt = undefined\n }\n const transient: { destroy(): void }[] = []\n let output: AtlasGpuTexture | undefined\n try {\n const scopes = openErrorScopes(device)\n let reported: Promise<string | null>\n try {\n const pipelines = prebuilt ?? atlasPipelinesSync(device, workgroupDim, directStore)\n const rowBytes = rasterRowBytes(width)\n const buffer = (size: number, usage: number): AtlasGpuBuffer => {\n const created = device.createBuffer({ size, usage })\n transient.push(created)\n return created\n }\n const upload = device.createTexture({\n size: [width, height],\n format: 'rgba8unorm',\n usage: textures.COPY_SRC | textures.COPY_DST | textures.RENDER_ATTACHMENT,\n })\n transient.push(upload)\n const words = buffer(rowBytes * height, buffers.STORAGE | buffers.COPY_DST)\n const seedBytes = width * height * SEED_BYTES_PER_TEXEL\n const seeds = [buffer(seedBytes, buffers.STORAGE), buffer(seedBytes, buffers.STORAGE)]\n // Uniform slots 256 bytes apart: seed/resolve parameters at 0, then one per jump step.\n const params = buffer(steps.length * 256 + 16, buffers.UNIFORM | buffers.COPY_DST)\n const values = new Int32Array(steps.length * 64 + 4)\n const invPxRange = 1 / pxRange\n values.set([width, height, rowBytes / 4])\n new Float32Array(values.buffer, 12, 1)[0] = invPxRange\n steps.forEach((step, index) => {\n const base = (index + 1) * 64\n values.set([width, height, step], base)\n new Float32Array(values.buffer, base * 4 + 12, 1)[0] = invPxRange\n })\n device.queue.writeBuffer(params, 0, values)\n device.queue.copyExternalImageToTexture(\n { source: raster.canvas, flipY: false },\n { texture: upload, premultipliedAlpha: false },\n [width, height],\n )\n output = device.createTexture({\n size: [width, height],\n mipLevelCount,\n format: 'r8unorm',\n usage:\n textures.RENDER_ATTACHMENT |\n textures.TEXTURE_BINDING |\n textures.COPY_SRC |\n textures.COPY_DST |\n (pipelines.directStore ? (textures.STORAGE_BINDING ?? 0) : 0),\n })\n const bind = (\n pipeline: AtlasPipeline,\n offset: number,\n ...storageBuffers: AtlasGpuBuffer[]\n ): unknown =>\n device.createBindGroup({\n layout: pipeline.getBindGroupLayout(0),\n entries: [\n { binding: 0, resource: { buffer: params, offset, size: 16 } },\n ...storageBuffers.map((resource, index) => ({\n binding: index + 1,\n resource: { buffer: resource },\n })),\n ],\n })\n const encoder = device.createCommandEncoder()\n encoder.copyTextureToBuffer(\n { texture: upload },\n { buffer: words, bytesPerRow: rowBytes, rowsPerImage: height },\n [width, height],\n )\n const groupsX = Math.ceil(width / pipelines.workgroupDim)\n const groupsY = Math.ceil(height / pipelines.workgroupDim)\n const flood = encoder.beginComputePass()\n flood.setPipeline(pipelines.seed)\n flood.setBindGroup(0, bind(pipelines.seed, 0, words, seeds[0]!))\n flood.dispatchWorkgroups(groupsX, groupsY)\n if (pipelines.directStore && pipelines.jumpStore) {\n const midSteps = steps.length - 1\n if (midSteps > 0) {\n flood.setPipeline(pipelines.jump)\n for (let index = 0; index < midSteps; index++) {\n const into = seeds[(index + 1) % 2]!\n flood.setBindGroup(0, bind(pipelines.jump, (index + 1) * 256, seeds[index % 2]!, into))\n flood.dispatchWorkgroups(groupsX, groupsY)\n }\n }\n const finalView = output.createView({ mipLevelCount: 1 })\n flood.setPipeline(pipelines.jumpStore)\n flood.setBindGroup(\n 0,\n device.createBindGroup({\n layout: pipelines.jumpStore.getBindGroupLayout(0),\n entries: [\n { binding: 0, resource: { buffer: params, offset: steps.length * 256, size: 16 } },\n { binding: 1, resource: { buffer: seeds[midSteps % 2]! } },\n { binding: 2, resource: finalView },\n ],\n }),\n )\n flood.dispatchWorkgroups(groupsX, groupsY)\n flood.end()\n } else {\n flood.setPipeline(pipelines.jump)\n steps.forEach((_, index) => {\n const into = seeds[(index + 1) % 2]!\n flood.setBindGroup(0, bind(pipelines.jump, (index + 1) * 256, seeds[index % 2]!, into))\n flood.dispatchWorkgroups(groupsX, groupsY)\n })\n flood.end()\n const resolve = encoder.beginRenderPass({\n colorAttachments: [\n { view: output.createView({ mipLevelCount: 1 }), loadOp: 'clear', storeOp: 'store' },\n ],\n })\n resolve.setPipeline(pipelines.resolve!)\n resolve.setBindGroup(0, bind(pipelines.resolve!, 0, seeds[steps.length % 2]!))\n resolve.draw(3)\n resolve.end()\n }\n finish?.(encoder, output)\n device.queue.submit([encoder.finish()])\n } finally {\n reported = scopes.close()\n }\n onSubmitted?.(output)\n const rejection = await reported\n if (rejection !== null) {\n devicePipelines.delete(device)\n devicePipelinePromises.delete(device)\n throw new Error(`buildGpuSdfAtlas: the device rejected the atlas passes: ${rejection}`)\n }\n const retained = output\n output = undefined\n return retained\n } finally {\n for (const resource of transient) resource.destroy()\n output?.destroy()\n }\n}\n\n/**\n * Generates a compact R8 runtime SDF on the renderer's WebGPU device: boundary seeding and\n * 4-byte relative fixed-point jump flooding in compute passes, writing directly into `r8unorm`\n * when `'texture-formats-tier1'` is active on the device or resolving via a fullscreen render\n * pass on Core WebGPU 1.0 devices.\n */\nexport async function buildGpuSdfAtlas(\n renderer: WebGPURenderer,\n raster: RasterAtlas,\n options: Pick<BuildSdfAtlasOptions, 'mipmaps' | 'anisotropy'> = {},\n /** @internal */\n onProvisional?: (atlas: SdfAtlas) => void,\n): Promise<SdfAtlas> {\n await renderer.init()\n if (!(renderer.backend instanceof WebGPUBackend)) {\n throw new Error('buildGpuSdfAtlas: requires the WebGPU backend; use mode \"cpu\"')\n }\n const { width, height } = raster\n const mipmaps = options.mipmaps === true\n const levels = mipmaps ? Math.floor(Math.log2(Math.max(width, height))) + 1 : 1\n const { shapeTop } = raster as RasterAtlas & ShapeRows\n const maxAnisotropy = mipmaps ? renderer.getMaxAnisotropy() : 1\n const wrapAtlas = (gpuTexture: AtlasGpuTexture) => {\n const texture = new ExternalTexture(gpuTexture)\n let disposed = false\n let gpuDestroyed = false\n const dispose = (): void => {\n if (disposed) return\n disposed = true\n try {\n texture.dispose()\n } finally {\n if (!gpuDestroyed) {\n gpuDestroyed = true\n gpuTexture.destroy()\n }\n }\n }\n try {\n ;(texture as { image: unknown }).image = { width, height }\n texture.name = 'ultra-text SDF atlas'\n texture.format = RedFormat\n texture.colorSpace = NoColorSpace\n texture.generateMipmaps = mipmaps\n texture.minFilter = mipmaps ? LinearMipmapLinearFilter : LinearFilter\n texture.magFilter = LinearFilter\n texture.anisotropy = mipmaps\n ? Math.min(Math.max(1, options.anisotropy ?? 1), maxAnisotropy)\n : 1\n if (shapeTop !== undefined) texture.userData['ultraShapeTop'] = shapeTop\n } catch (error) {\n dispose()\n throw error\n }\n const atlas: SdfAtlas = {\n ...(shapeTop === undefined ? {} : { shapeTop }),\n texture,\n width,\n height,\n pxRange: raster.pxRange,\n bakeSize: raster.bakeSize,\n glyphs: raster.glyphs,\n mode: 'gpu',\n dispose,\n }\n return {\n atlas,\n markGpuDestroyed: () => {\n gpuDestroyed = true\n },\n }\n }\n\n if (onProvisional && !mipmaps) {\n let wrapped: ReturnType<typeof wrapAtlas> | undefined\n try {\n const gpuTexture = await encodeGpuSdf(\n atlasDevice(renderer),\n raster,\n levels,\n undefined,\n (candidate) => {\n wrapped = wrapAtlas(candidate)\n onProvisional(wrapped.atlas)\n },\n )\n return wrapped ? wrapped.atlas : wrapAtlas(gpuTexture).atlas\n } catch (error) {\n if (wrapped) {\n wrapped.markGpuDestroyed()\n wrapped.atlas.dispose()\n }\n throw error\n }\n }\n\n const gpuTexture = await encodeGpuSdf(atlasDevice(renderer), raster, levels)\n const { atlas } = wrapAtlas(gpuTexture)\n try {\n if (mipmaps) await generateAtlasMips(renderer, atlas.texture)\n } catch (error) {\n atlas.dispose()\n throw error\n }\n return atlas\n}\n"],"mappings":";;;AAiBA,IAAM,0BAA0B;AAChC,IAAM,2BAA2B;AACjC,IAAM,uBAAuB;AAC7B,IAAM,0BAA0B;AAChC,IAAM,2BAA2B;AAkHjC,IAAM,eAAe;CACnB,CAAC,qCAAqC,2BAA2B,CAAC;CAClE,CAAC,4BAA4B,uBAAuB;CACpD,CAAC,4BAA4B,uBAAuB;CACpD,CAAC,mCAAmC,uBAAuB;AAC7D;AAEA,SAAS,yBAAyB,QAAoC;CACpE,MAAM,MAAM,QAAQ,qCAAqC;CACzD,MAAM,KAAK,QAAQ,4BAA4B;CAC/C,MAAM,KAAK,QAAQ,4BAA4B;CAC/C,OAAO,OAAO,4BAA4B,KACxC,MAAM,4BACN,MAAM,2BACJ,2BACA;AACN;AAEA,SAAS,oBAAoB,QAA8B;CACzD,MAAM,WAAY,WAA0B;CAC5C,OACE,OAAO,UAAU,oBAAoB,YACrC,SAAS,kBAAkB,KAC3B,QAAQ,OAAO,UAAU,IAAI,uBAAuB,CAAC;AAEzD;;AAGA,SAAS,eAAe,OAAuB;CAC7C,OAAO,KAAK,KAAK,QAAQ,EAAE,IAAI;AACjC;;;;;AAMA,SAAS,iBACP,QACA,OACA,QACA,SACA,aACM;CACN,IAAI,UAAU,IACZ,MAAM,IAAI,WACR,iFACF;CAEF,IAAI,CAAC,QAAQ;CACb,KAAK,MAAM,CAAC,MAAM,SAAS,cAAc;EACvC,MAAM,Q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IACA;IACA,SAAS,OAAO;IAChB,UAAU,OAAO;IACjB,QAAQ,OAAO;IACf,MAAM;IACN;GAGA;GACA,wBAAwB;IACtB,eAAe;GACjB;EACF;CACF;CAEA,IAAI,iBAAiB,CAAC,SAAS;EAC7B,IAAI;EACJ,IAAI;GACF,MAAM,aAAa,MAAM,aACvB,YAAY,QAAQ,GACpB,QACA,QACA,KAAA,IACC,cAAc;IACb,UAAU,UAAU,SAAS;IAC7B,cAAc,QAAQ,KAAK;GAC7B,CACF;GACA,OAAO,UAAU,QAAQ,QAAQ,UAAU,UAAU,CAAC,CAAC;EACzD,SAAS,OAAO;GACd,IAAI,SAAS;IACX,QAAQ,iBAAiB;IACzB,QAAQ,MAAM,QAAQ;GACxB;GACA,MAAM;EACR;CACF;CAGA,MAAM,EAAE,UAAU,UAAU,MADH,aAAa,YAAY,QAAQ,GAAG,QAAQ,MAAM,CACrC;CACtC,IAAI;EACF,IAAI,SAAS,MAAM,kBAAkB,UAAU,MAAM,OAAO;CAC9D,SAAS,OAAO;EACd,MAAM,QAAQ;EACd,MAAM;CACR;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"gpuAtlas.js","names":["hasDirectStoreFeature"],"sources":["../../src/atlas/gpuAtlas.ts"],"sourcesContent":["import {\n ExternalTexture,\n LinearFilter,\n LinearMipmapLinearFilter,\n NoColorSpace,\n RedFormat,\n WebGPUBackend,\n type Texture,\n type WebGPURenderer,\n} from 'three/webgpu'\n\nimport type { BuildSdfAtlasOptions, RasterAtlas, SdfAtlas } from '../types.js'\nimport {\n checkCommonAtlasLimits,\n encodeJfaWork,\n jfaSteps,\n openErrorScopes,\n prefersTiledJfa,\n selectWorkgroupDimension,\n supportsDirectStore as hasDirectStoreFeature,\n type AtlasDeviceLimitsLike,\n type AtlasErrorFilter,\n type CommonJfaPipelines,\n type UsageGlobals,\n} from './gpuCommon.js'\nimport { buildJfaWgsl } from './jfaWgsl.js'\nimport type { ShapeRows } from './rasterize.js'\n\ntype AtlasDeviceLimits = AtlasDeviceLimitsLike & {\n readonly maxStorageBufferBindingSize: number\n readonly maxBufferSize: number\n}\n\n/** @internal The WebGPU texture calls the atlas makes (no `@webgpu/types` needed). */\nexport interface AtlasGpuTexture {\n readonly mipLevelCount: number\n createView(descriptor?: { baseMipLevel?: number; mipLevelCount?: number }): unknown\n destroy(): void\n}\n\ninterface AtlasGpuBuffer {\n destroy(): void\n}\n\ninterface AtlasPipeline {\n getBindGroupLayout(index: number): unknown\n}\n\ninterface AtlasPass {\n setPipeline(pipeline: AtlasPipeline): void\n setBindGroup(index: number, bindGroup: unknown): void\n end(): void\n}\n\n/** @internal One command encoder of the atlas passes, which a patch adds its copies to. */\nexport interface AtlasEncoder {\n copyTextureToBuffer(\n source: { texture: AtlasGpuTexture },\n destination: { buffer: AtlasGpuBuffer; bytesPerRow: number; rowsPerImage: number },\n size: [number, number],\n ): void\n copyTextureToTexture(\n source: { texture: AtlasGpuTexture; origin: [number, number] },\n destination: { texture: AtlasGpuTexture; origin: [number, number] },\n size: [number, number],\n ): void\n beginComputePass(): AtlasPass & { dispatchWorkgroups(x: number, y: number): void }\n beginRenderPass(descriptor: {\n colorAttachments: { view: unknown; loadOp: 'clear'; storeOp: 'store' }[]\n }): AtlasPass & { draw(vertexCount: number): void }\n finish(): unknown\n}\n\n/** @internal The device calls of the atlas passes, called with the device as `this`. */\nexport interface AtlasDevice {\n readonly features?: { has(name: string): boolean }\n readonly limits?: AtlasDeviceLimits\n createTexture(descriptor: {\n size: [number, number]\n mipLevelCount?: number\n format: string\n usage: number\n }): AtlasGpuTexture\n createBuffer(descriptor: { size: number; usage: number }): AtlasGpuBuffer\n createShaderModule(descriptor: { label: string; code: string }): unknown\n createComputePipeline(descriptor: {\n layout: 'auto'\n compute: { module: unknown; entryPoint: string }\n }): AtlasPipeline\n readonly createComputePipelineAsync?: (descriptor: {\n layout: 'auto'\n compute: { module: unknown; entryPoint: string }\n }) => Promise<AtlasPipeline>\n createRenderPipeline(descriptor: {\n layout: 'auto'\n vertex: { module: unknown; entryPoint: string }\n fragment: { module: unknown; entryPoint: string; targets: { format: string }[] }\n }): AtlasPipeline\n readonly createRenderPipelineAsync?: (descriptor: {\n layout: 'auto'\n vertex: { module: unknown; entryPoint: string }\n fragment: { module: unknown; entryPoint: string; targets: { format: string }[] }\n }) => Promise<AtlasPipeline>\n createBindGroup(descriptor: {\n layout: unknown\n entries: { binding: number; resource: unknown }[]\n }): unknown\n createCommandEncoder(): AtlasEncoder\n readonly queue: {\n copyExternalImageToTexture(\n source: { source: HTMLCanvasElement; flipY: boolean },\n destination: { texture: AtlasGpuTexture; premultipliedAlpha: boolean },\n size: [number, number],\n ): void\n writeBuffer(buffer: AtlasGpuBuffer, offset: number, data: Int32Array): void\n submit(commandBuffers: unknown[]): void\n }\n readonly pushErrorScope?: (filter: AtlasErrorFilter) => void\n readonly popErrorScope?: () => Promise<{ readonly message?: string } | null>\n}\n\ntype AtlasPipelines = CommonJfaPipelines<AtlasPipeline, AtlasPipeline>\n\ninterface MultiPassPipelines {\n readonly seed: AtlasPipeline\n readonly jump: AtlasPipeline\n readonly jumpStore: AtlasPipeline | null\n readonly resolve: AtlasPipeline | null\n}\n\ninterface DevicePipelineCache {\n readonly workgroupDim: 8 | 16\n readonly directStore: boolean\n readonly module: unknown\n tiledStore?: AtlasPipeline\n tiledPromise?: Promise<AtlasPipelines> | undefined\n multi?: MultiPassPipelines\n multiPromise?: Promise<AtlasPipelines> | undefined\n}\n\nconst devicePipelines = new WeakMap<AtlasDevice, DevicePipelineCache>()\n\nfunction asAtlasPipelines(\n workgroupDim: 8 | 16,\n directStore: boolean,\n tiledStore: AtlasPipeline | null,\n multi?: MultiPassPipelines,\n): AtlasPipelines {\n return {\n workgroupDim,\n directStore,\n seed: multi?.seed ?? null,\n jump: multi?.jump ?? null,\n jumpStore: multi?.jumpStore ?? null,\n tiledStore,\n resolve: multi?.resolve ?? null,\n }\n}\n\nfunction getDeviceCache(\n device: AtlasDevice,\n workgroupDim: 8 | 16,\n directStore: boolean,\n): DevicePipelineCache {\n const existing = devicePipelines.get(device)\n if (existing?.workgroupDim === workgroupDim && existing.directStore === directStore) {\n return existing\n }\n const cache: DevicePipelineCache = {\n workgroupDim,\n directStore,\n module: device.createShaderModule({\n label: 'ultra-text atlas',\n code: buildJfaWgsl(workgroupDim, directStore),\n }),\n }\n devicePipelines.set(device, cache)\n return cache\n}\n\nfunction cachedAtlasPipelines(\n device: AtlasDevice,\n workgroupDim: 8 | 16,\n directStore: boolean,\n tiledOnly: boolean,\n): AtlasPipelines | undefined {\n const cache = devicePipelines.get(device)\n if (cache?.workgroupDim !== workgroupDim || cache.directStore !== directStore) return undefined\n if (tiledOnly) {\n return cache.tiledStore\n ? asAtlasPipelines(workgroupDim, directStore, cache.tiledStore)\n : undefined\n }\n return cache.multi ? asAtlasPipelines(workgroupDim, directStore, null, cache.multi) : undefined\n}\n\nfunction supportsAsyncAtlasPipelines(device: AtlasDevice, directStore: boolean): boolean {\n return (\n typeof device.createComputePipelineAsync === 'function' &&\n (directStore || typeof device.createRenderPipelineAsync === 'function')\n )\n}\n\nfunction buildAtlasPipelines(\n device: AtlasDevice,\n workgroupDim: 8 | 16,\n directStore: boolean,\n tiledOnly: boolean,\n async: true,\n): Promise<AtlasPipelines>\nfunction buildAtlasPipelines(\n device: AtlasDevice,\n workgroupDim: 8 | 16,\n directStore: boolean,\n tiledOnly: boolean,\n async: false,\n): AtlasPipelines\nfunction buildAtlasPipelines(\n device: AtlasDevice,\n workgroupDim: 8 | 16,\n directStore: boolean,\n tiledOnly: boolean,\n async: boolean,\n): AtlasPipelines | Promise<AtlasPipelines> {\n const cached = cachedAtlasPipelines(device, workgroupDim, directStore, tiledOnly)\n if (cached) return async ? Promise.resolve(cached) : cached\n\n const existing = devicePipelines.get(device)\n const sameConfig = existing?.workgroupDim === workgroupDim && existing.directStore === directStore\n if (async && sameConfig) {\n const inFlight = tiledOnly ? existing.tiledPromise : existing.multiPromise\n if (inFlight) return inFlight\n }\n\n const cache = getDeviceCache(device, workgroupDim, directStore)\n const module = cache.module\n const computeSync = (entryPoint: string) =>\n device.createComputePipeline({ layout: 'auto', compute: { module, entryPoint } })\n const computeAsync = (entryPoint: string) =>\n device.createComputePipelineAsync!({ layout: 'auto', compute: { module, entryPoint } })\n\n if (tiledOnly) {\n const store = (tiledStore: AtlasPipeline): AtlasPipelines => {\n cache.tiledStore = tiledStore\n return asAtlasPipelines(workgroupDim, directStore, tiledStore)\n }\n if (!async) return store(computeSync('tiledStoreMain'))\n const promise = computeAsync('tiledStoreMain').then(\n (tiledStore) => store(tiledStore),\n (error: unknown) => {\n if (cache.tiledPromise === promise) cache.tiledPromise = undefined\n throw error\n },\n )\n cache.tiledPromise = promise\n return promise\n }\n\n const resolveDesc = {\n layout: 'auto' as const,\n vertex: { module, entryPoint: 'fullscreenVert' },\n fragment: { module, entryPoint: 'resolveFrag', targets: [{ format: 'r8unorm' }] },\n }\n const store = (\n seed: AtlasPipeline,\n jump: AtlasPipeline,\n jumpStore: AtlasPipeline | null,\n resolve: AtlasPipeline | null,\n ): AtlasPipelines => {\n const multi: MultiPassPipelines = { seed, jump, jumpStore, resolve }\n cache.multi = multi\n return asAtlasPipelines(workgroupDim, directStore, null, multi)\n }\n\n if (!async) {\n return store(\n computeSync('seedMain'),\n computeSync('jumpMain'),\n directStore ? computeSync('jumpStoreMain') : null,\n directStore ? null : device.createRenderPipeline(resolveDesc),\n )\n }\n\n const promise = Promise.all([\n computeAsync('seedMain'),\n computeAsync('jumpMain'),\n directStore ? computeAsync('jumpStoreMain') : Promise.resolve(null),\n directStore ? Promise.resolve(null) : device.createRenderPipelineAsync!(resolveDesc),\n ]).then(\n ([seed, jump, jumpStore, resolve]) => store(seed, jump, jumpStore, resolve),\n (error: unknown) => {\n if (cache.multiPromise === promise) cache.multiPromise = undefined\n throw error\n },\n )\n cache.multiPromise = promise\n return promise\n}\n\n/**\n * @internal Starts the native compile of the device's atlas passes ahead of its first atlas,\n * while the caller reads the DOM.\n */\nexport function prepareAtlasPasses(renderer: WebGPURenderer, pxRange?: number): void {\n const device = atlasDevice(renderer)\n if (!device?.createShaderModule) return\n const directStore = hasDirectStoreFeature(device.features)\n const workgroupDim = selectWorkgroupDimension(device.limits)\n const tiledOnly = prefersTiledJfa(directStore, pxRange)\n const cached = devicePipelines.get(device)\n const matches = cached?.workgroupDim === workgroupDim && cached.directStore === directStore\n if (\n matches &&\n (tiledOnly ? cached.tiledStore || cached.tiledPromise : cached.multi || cached.multiPromise)\n ) {\n return\n }\n if (supportsAsyncAtlasPipelines(device, directStore)) {\n void buildAtlasPipelines(device, workgroupDim, directStore, tiledOnly, true).catch(\n () => undefined,\n )\n } else {\n buildAtlasPipelines(device, workgroupDim, directStore, tiledOnly, false)\n }\n device.queue.submit([])\n}\n\n/**\n * @internal Regenerates the mips of an atlas texture from its level 0 with three's own mip\n * pass, as three does for a render target, after the submissions that wrote it.\n */\nexport async function generateAtlasMips(renderer: WebGPURenderer, texture: Texture): Promise<void> {\n const scopes = openErrorScopes(atlasDevice(renderer)!)\n let reported: Promise<string | null>\n try {\n renderer.initTexture(texture)\n ;(renderer.backend as unknown as { generateMipmaps(texture: Texture): void }).generateMipmaps(\n texture,\n )\n } finally {\n reported = scopes.close()\n }\n const rejection = await reported\n if (rejection !== null) throw new Error(`buildGpuSdfAtlas: mip generation failed: ${rejection}`)\n}\n\n/** @internal The device behind a WebGPU-backend renderer, or `undefined`. */\nexport function atlasDevice(renderer: WebGPURenderer): AtlasDevice | undefined {\n return (renderer.backend as unknown as { device?: AtlasDevice }).device\n}\n\n/**\n * @internal Runs the atlas passes over `raster` into level 0 of a new r8unorm texture of\n * `mipLevelCount` levels, all in one command buffer.\n */\nexport async function encodeGpuSdf(\n device: AtlasDevice | undefined,\n raster: Pick<RasterAtlas, 'canvas' | 'width' | 'height' | 'pxRange'>,\n mipLevelCount: number,\n finish?: (encoder: AtlasEncoder, texture: AtlasGpuTexture) => void,\n onSubmitted?: (texture: AtlasGpuTexture) => void,\n): Promise<AtlasGpuTexture> {\n const { width, height, pxRange, canvas } = raster\n const { GPUBufferUsage: buffers, GPUTextureUsage: textures } = globalThis as UsageGlobals\n if (!device?.createCommandEncoder || !buffers || !textures)\n throw new Error('buildGpuSdfAtlas: device cannot run the atlas passes')\n const steps = jfaSteps(pxRange)\n const directStore = hasDirectStoreFeature(device.features)\n checkCommonAtlasLimits(\n 'buildGpuSdfAtlas',\n device.limits,\n width,\n height,\n steps[0]!,\n directStore,\n '; use atlasMode \"cpu\"',\n )\n const workgroupDim = selectWorkgroupDimension(device.limits)\n const tiledOnly = directStore && steps[0] === 4\n let prebuilt = cachedAtlasPipelines(device, workgroupDim, directStore, tiledOnly)\n if (!prebuilt && supportsAsyncAtlasPipelines(device, directStore)) {\n try {\n prebuilt = await buildAtlasPipelines(device, workgroupDim, directStore, tiledOnly, true)\n } catch (error: unknown) {\n throw new Error(\n `buildGpuSdfAtlas: the device rejected the atlas passes: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n )\n }\n }\n const transient: { destroy(): void }[] = []\n let output: AtlasGpuTexture | undefined\n try {\n const scopes = openErrorScopes(device)\n let reported: Promise<string | null>\n try {\n const pipelines =\n prebuilt ?? buildAtlasPipelines(device, workgroupDim, directStore, tiledOnly, false)\n output = device.createTexture({\n size: [width, height],\n mipLevelCount,\n format: 'r8unorm',\n usage:\n textures.RENDER_ATTACHMENT |\n textures.TEXTURE_BINDING |\n textures.COPY_SRC |\n textures.COPY_DST |\n (pipelines.directStore ? (textures.STORAGE_BINDING ?? 0) : 0),\n })\n const encoder = device.createCommandEncoder()\n encodeJfaWork(\n device,\n encoder,\n pipelines,\n canvas,\n width,\n height,\n pxRange,\n steps,\n output,\n transient,\n buffers,\n textures,\n )\n finish?.(encoder, output)\n device.queue.submit([encoder.finish()])\n } finally {\n reported = scopes.close()\n }\n onSubmitted?.(output)\n const rejection = await reported\n if (rejection !== null) {\n devicePipelines.delete(device)\n throw new Error(`buildGpuSdfAtlas: the device rejected the atlas passes: ${rejection}`)\n }\n const retained = output\n output = undefined\n return retained\n } finally {\n for (const resource of transient) resource.destroy()\n output?.destroy()\n }\n}\n\n/**\n * Generates a compact R8 runtime SDF on the renderer's WebGPU device: boundary seeding and\n * 4-byte relative fixed-point jump flooding in compute passes, writing directly into `r8unorm`\n * when `'texture-formats-tier1'` is active on the device or resolving via a fullscreen render\n * pass on Core WebGPU 1.0 devices.\n */\nexport async function buildGpuSdfAtlas(\n renderer: WebGPURenderer,\n raster: RasterAtlas,\n options: Pick<BuildSdfAtlasOptions, 'mipmaps' | 'anisotropy'> = {},\n /** @internal */\n onProvisional?: (atlas: SdfAtlas) => void,\n): Promise<SdfAtlas> {\n await renderer.init()\n if (!(renderer.backend instanceof WebGPUBackend)) {\n throw new Error('buildGpuSdfAtlas: requires the WebGPU backend; use mode \"cpu\"')\n }\n const { width, height } = raster\n const mipmaps = options.mipmaps === true\n const levels = mipmaps ? Math.floor(Math.log2(Math.max(width, height))) + 1 : 1\n const { shapeTop } = raster as RasterAtlas & ShapeRows\n const maxAnisotropy = mipmaps ? renderer.getMaxAnisotropy() : 1\n const wrapAtlas = (gpuTexture: AtlasGpuTexture) => {\n const texture = new ExternalTexture(gpuTexture)\n let disposed = false\n let gpuDestroyed = false\n const dispose = (): void => {\n if (disposed) return\n disposed = true\n try {\n texture.dispose()\n } finally {\n if (!gpuDestroyed) {\n gpuDestroyed = true\n gpuTexture.destroy()\n }\n }\n }\n try {\n ;(texture as { image: unknown }).image = { width, height }\n texture.name = 'ultra-text SDF atlas'\n texture.format = RedFormat\n texture.colorSpace = NoColorSpace\n texture.generateMipmaps = mipmaps\n texture.minFilter = mipmaps ? LinearMipmapLinearFilter : LinearFilter\n texture.magFilter = LinearFilter\n texture.anisotropy = mipmaps\n ? Math.min(Math.max(1, options.anisotropy ?? 1), maxAnisotropy)\n : 1\n if (shapeTop !== undefined) texture.userData['ultraShapeTop'] = shapeTop\n } catch (error) {\n dispose()\n throw error\n }\n const atlas: SdfAtlas = {\n ...(shapeTop === undefined ? {} : { shapeTop }),\n texture,\n width,\n height,\n pxRange: raster.pxRange,\n bakeSize: raster.bakeSize,\n glyphs: raster.glyphs,\n mode: 'gpu',\n dispose,\n }\n return {\n atlas,\n markGpuDestroyed: () => {\n gpuDestroyed = true\n },\n }\n }\n\n if (onProvisional && !mipmaps) {\n let wrapped: ReturnType<typeof wrapAtlas> | undefined\n try {\n const gpuTexture = await encodeGpuSdf(\n atlasDevice(renderer),\n raster,\n levels,\n undefined,\n (candidate) => {\n wrapped = wrapAtlas(candidate)\n onProvisional(wrapped.atlas)\n },\n )\n return wrapped ? wrapped.atlas : wrapAtlas(gpuTexture).atlas\n } catch (error) {\n if (wrapped) {\n wrapped.markGpuDestroyed()\n wrapped.atlas.dispose()\n }\n throw error\n }\n }\n\n const gpuTexture = await encodeGpuSdf(atlasDevice(renderer), raster, levels)\n const { atlas } = wrapAtlas(gpuTexture)\n try {\n if (mipmaps) await generateAtlasMips(renderer, atlas.texture)\n } catch (error) {\n atlas.dispose()\n throw error\n }\n return atlas\n}\n"],"mappings":";;;;AA4IA,IAAM,kCAAkB,IAAI,QAA0C;AAEtE,SAAS,iBACP,cACA,aACA,YACA,OACgB;CAChB,OAAO;EACL;EACA;EACA,MAAM,OAAO,QAAQ;EACrB,MAAM,OAAO,QAAQ;EACrB,WAAW,OAAO,aAAa;EAC/B;EACA,SAAS,OAAO,WAAW;CAC7B;AACF;AAEA,SAAS,eACP,QACA,cACA,aACqB;CACrB,MAAM,WAAW,gBAAgB,IAAI,MAAM;CAC3C,IAAI,UAAU,iBAAiB,gBAAgB,SAAS,gBAAgB,aACtE,OAAO;CAET,MAAM,QAA6B;EACjC;EACA;EACA,QAAQ,OAAO,mBAAmB;GAChC,OAAO;GACP,MAAM,aAAa,cAAc,WAAW;EAC9C,CAAC;CACH;CACA,gBAAgB,IAAI,QAAQ,KAAK;CACjC,OAAO;AACT;AAEA,SAAS,qBACP,QACA,cACA,aACA,WAC4B;CAC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