ultra-text 1.0.1 → 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.
- package/README.md +339 -1039
- package/dist/assets/cpuSdf.worker-Dy4P5_TI.js +466 -0
- package/dist/assets/cpuSdf.worker-Dy4P5_TI.js.map +1 -0
- package/dist/assets/traceOutline.worker-B5uVKmR4.js +1725 -0
- package/dist/assets/traceOutline.worker-B5uVKmR4.js.map +1 -0
- package/dist/atlas/appendAtlas.js +97 -31
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +4 -3
- package/dist/atlas/buildAtlas.js.map +1 -1
- package/dist/atlas/colorGlyphs.d.ts +0 -10
- package/dist/atlas/colorGlyphs.js +97 -155
- package/dist/atlas/colorGlyphs.js.map +1 -1
- package/dist/atlas/colorTexture.d.ts +1 -0
- package/dist/atlas/colorTexture.js +64 -0
- package/dist/atlas/colorTexture.js.map +1 -0
- package/dist/atlas/cpuAtlas.d.ts +4 -1
- package/dist/atlas/cpuAtlas.js +14 -7
- package/dist/atlas/cpuAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.d.ts +1 -1
- package/dist/atlas/cpuSdf.js +235 -68
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.d.ts +11 -3
- package/dist/atlas/cpuWorker.js +179 -22
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.js +188 -287
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/gpuCommon.d.ts +257 -0
- package/dist/atlas/gpuCommon.js +845 -0
- package/dist/atlas/gpuCommon.js.map +1 -0
- package/dist/atlas/jfaWgsl.d.ts +1 -1
- package/dist/atlas/jfaWgsl.js +226 -249
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.d.ts +22 -0
- package/dist/atlas/rasterize.js +329 -158
- 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 +1065 -0
- package/dist/atlas/vanillaCore.js.map +1 -0
- package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
- package/dist/atlas/vanillaCpuAtlas.js +72 -0
- package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
- package/dist/atlas/vanillaExtras.d.ts +8 -0
- package/dist/atlas/vanillaExtras.js +167 -0
- package/dist/atlas/vanillaExtras.js.map +1 -0
- package/dist/atlas/vanillaGpuHelpers.d.ts +295 -0
- package/dist/atlas/vanillaGpuHelpers.js +354 -0
- package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
- package/dist/dom/DomSdf.js +243 -297
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.js +94 -165
- package/dist/dom/DomSlug.js.map +1 -1
- package/dist/dom/Text.d.ts +4 -1
- package/dist/dom/Text.js +5 -1
- package/dist/dom/Text.js.map +1 -1
- package/dist/dom/browserShaping.js +31 -14
- package/dist/dom/browserShaping.js.map +1 -1
- package/dist/dom/clusters.js +13 -2
- package/dist/dom/clusters.js.map +1 -1
- package/dist/dom/cssEffects.d.ts +4 -0
- package/dist/dom/cssEffects.js +72 -0
- package/dist/dom/cssEffects.js.map +1 -0
- package/dist/dom/domAnalytic.d.ts +53 -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.d.ts +16 -0
- package/dist/dom/fontCanvas.js +31 -13
- package/dist/dom/fontCanvas.js.map +1 -1
- package/dist/dom/layoutSignature.js +175 -57
- package/dist/dom/layoutSignature.js.map +1 -1
- package/dist/dom/markup.d.ts +10 -0
- package/dist/dom/markup.js +16 -1
- package/dist/dom/markup.js.map +1 -1
- package/dist/dom/pretextLayout.js +78 -28
- package/dist/dom/pretextLayout.js.map +1 -1
- package/dist/dom/snapshot.d.ts +4 -0
- package/dist/dom/snapshot.js +891 -484
- package/dist/dom/snapshot.js.map +1 -1
- package/dist/dom/snapshotsEqual.d.ts +7 -0
- package/dist/dom/snapshotsEqual.js +68 -0
- package/dist/dom/snapshotsEqual.js.map +1 -0
- package/dist/dom/svgCapture.d.ts +8 -1
- package/dist/dom/svgCapture.js +105 -28
- package/dist/dom/svgCapture.js.map +1 -1
- package/dist/dom/textTransform.d.ts +13 -1
- package/dist/dom/textTransform.js +31 -13
- package/dist/dom/textTransform.js.map +1 -1
- package/dist/dom/tone.js +91 -44
- package/dist/dom/tone.js.map +1 -1
- package/dist/index.js +4 -3
- package/dist/slug/SlugMaterial.d.ts +17 -3
- package/dist/slug/SlugMaterial.js +98 -26
- package/dist/slug/SlugMaterial.js.map +1 -1
- package/dist/slug/cff.d.ts +5 -0
- package/dist/slug/cff.js +780 -0
- package/dist/slug/cff.js.map +1 -0
- package/dist/slug/coverage.d.ts +19 -15
- package/dist/slug/coverage.js +380 -225
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +6 -2
- package/dist/slug/preprocessCore.js +199 -148
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.d.ts +1 -0
- package/dist/slug/runtime.js +113 -74
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.d.ts +3 -2
- package/dist/slug/standaloneRuntime.js +112 -67
- package/dist/slug/standaloneRuntime.js.map +1 -1
- package/dist/slug/truetype.d.ts +14 -6
- package/dist/slug/truetype.js +356 -255
- package/dist/slug/truetype.js.map +1 -1
- package/dist/slug/vanillaCore.d.ts +410 -0
- package/dist/slug/vanillaCore.js +1630 -0
- package/dist/slug/vanillaCore.js.map +1 -0
- package/dist/slug-vanilla.d.ts +13 -364
- package/dist/slug-vanilla.js +7 -1454
- package/dist/slug.d.ts +2 -2
- package/dist/slug.js +7 -7
- package/dist/text/GlyphTextMaterial.d.ts +6 -1
- package/dist/text/GlyphTextMaterial.js +16 -12
- package/dist/text/GlyphTextMaterial.js.map +1 -1
- package/dist/text/RectMaterial.js +6 -10
- package/dist/text/RectMaterial.js.map +1 -1
- package/dist/text/SdfTextMaterial.d.ts +9 -3
- package/dist/text/SdfTextMaterial.js +125 -38
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/text/decorations.d.ts +7 -2
- package/dist/text/decorations.js +187 -79
- package/dist/text/decorations.js.map +1 -1
- package/dist/text/geometry.d.ts +3 -22
- package/dist/text/geometryUtils.d.ts +16 -1
- package/dist/text/geometryUtils.js +83 -8
- package/dist/text/geometryUtils.js.map +1 -1
- package/dist/text/glyphGeometry.d.ts +9 -0
- package/dist/text/glyphGeometry.js +434 -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 +101 -0
- package/dist/text/rectGeometry.js.map +1 -0
- package/dist/text/reflow.d.ts +23 -1
- package/dist/text/reflow.js +223 -94
- package/dist/text/reflow.js.map +1 -1
- package/dist/text/snap.d.ts +15 -0
- package/dist/text/snap.js +26 -0
- package/dist/text/snap.js.map +1 -0
- package/dist/text/tone.js +2 -2
- package/dist/text/tone.js.map +1 -1
- package/dist/types.d.ts +23 -7
- package/dist/vanilla.d.ts +13 -363
- package/dist/vanilla.js +7 -1474
- package/dist/windfoil/WindfoilCompositeMaterial.d.ts +1 -1
- package/dist/windfoil/WindfoilCompositeMaterial.js +10 -3
- package/dist/windfoil/WindfoilCompositeMaterial.js.map +1 -1
- package/dist/windfoil/WindfoilMaterial.d.ts +12 -5
- package/dist/windfoil/WindfoilMaterial.js +71 -8
- package/dist/windfoil/WindfoilMaterial.js.map +1 -1
- package/dist/windfoil/compositeGeometry.js +12 -5
- package/dist/windfoil/compositeGeometry.js.map +1 -1
- package/dist/windfoil/coverage.d.ts +10 -2
- package/dist/windfoil/coverage.js +147 -59
- package/dist/windfoil/coverage.js.map +1 -1
- package/dist/windfoil/geometry.d.ts +17 -2
- package/dist/windfoil/geometry.js +220 -57
- package/dist/windfoil/geometry.js.map +1 -1
- package/dist/windfoil/layerGrid.js +8 -8
- package/dist/windfoil/layerGrid.js.map +1 -1
- package/dist/windfoil/mixed.d.ts +1 -0
- package/dist/windfoil/mixed.js +57 -29
- package/dist/windfoil/mixed.js.map +1 -1
- package/dist/windfoil/preprocess.js +2 -2
- package/dist/windfoil/preprocessCore.d.ts +2 -0
- package/dist/windfoil/preprocessCore.js +69 -37
- package/dist/windfoil/preprocessCore.js.map +1 -1
- package/dist/windfoil/requests.d.ts +1 -1
- package/dist/windfoil/requests.js +11 -4
- package/dist/windfoil/requests.js.map +1 -1
- package/dist/windfoil/resolveOutline.d.ts +9 -0
- package/dist/windfoil/resolveOutline.js +20 -0
- package/dist/windfoil/resolveOutline.js.map +1 -0
- package/dist/windfoil/runtime.d.ts +4 -1
- package/dist/windfoil/runtime.js +69 -63
- package/dist/windfoil/runtime.js.map +1 -1
- package/dist/windfoil/shapeGeometry.js +80 -34
- package/dist/windfoil/shapeGeometry.js.map +1 -1
- package/dist/windfoil/sizeSwitch.d.ts +1 -1
- package/dist/windfoil/sizeSwitch.js +13 -8
- package/dist/windfoil/sizeSwitch.js.map +1 -1
- package/dist/windfoil/storage.d.ts +78 -6
- package/dist/windfoil/storage.js +166 -11
- package/dist/windfoil/storage.js.map +1 -1
- package/dist/windfoil/svg/curves.d.ts +20 -0
- package/dist/windfoil/svg/curves.js +145 -42
- package/dist/windfoil/svg/curves.js.map +1 -1
- package/dist/windfoil/svg/document.js +10 -1
- package/dist/windfoil/svg/document.js.map +1 -1
- package/dist/windfoil/svg/pathConverter.js +66 -50
- package/dist/windfoil/svg/pathConverter.js.map +1 -1
- package/dist/windfoil/svg/pathData.d.ts +9 -0
- package/dist/windfoil/svg/pathData.js +142 -109
- package/dist/windfoil/svg/pathData.js.map +1 -1
- package/dist/windfoil/svg/winding.js +34 -10
- package/dist/windfoil/svg/winding.js.map +1 -1
- package/dist/windfoil/trace/contours.d.ts +5 -0
- package/dist/windfoil/trace/contours.js +256 -62
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.d.ts +3 -1
- package/dist/windfoil/trace/fit.js +915 -265
- 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/traceOutline.worker.d.ts +24 -0
- package/dist/windfoil/trace/traceWorker.d.ts +13 -0
- package/dist/windfoil/trace/traceWorker.js +192 -0
- package/dist/windfoil/trace/traceWorker.js.map +1 -0
- package/dist/windfoil/trace/types.d.ts +10 -0
- package/dist/windfoil/tracedOutlines.d.ts +2 -0
- package/dist/windfoil/tracedOutlines.js +393 -103
- package/dist/windfoil/tracedOutlines.js.map +1 -1
- package/package.json +48 -29
- package/skills/ultra-text/SKILL.md +9 -10
- package/skills/ultra-text/references/frameworks.md +46 -2
- package/skills/ultra-text/references/three-tsl.md +27 -25
- package/skills/ultra-text/references/vanilla-webgpu.md +5 -2
- package/dist/assets/cpuSdf.worker-xS57yQbP.js +0 -322
- 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
package/dist/atlas/gpuAtlas.js
CHANGED
|
@@ -1,184 +1,168 @@
|
|
|
1
1
|
import { buildJfaWgsl } from "./jfaWgsl.js";
|
|
2
|
+
import { checkCommonAtlasLimits, edtRadius, encodeGpuColorBleed, encodeJfaWork, getDeviceGpuPool, getJfaLayouts, openErrorScopes, peekDeferredColorBleed, putReadyGpuColorTexture, selectAtlasMode, selectWorkgroupDimension, storageBufferFits, supportsDirectStore, takeDeferredColorBleed, takeReadyGpuColorTexture } from "./gpuCommon.js";
|
|
3
|
+
import { encodeMipmapChain, getDeviceMipPipeline, mipCount } from "./vanillaGpuHelpers.js";
|
|
2
4
|
import { ExternalTexture, LinearFilter, LinearMipmapLinearFilter, NoColorSpace, RedFormat, WebGPUBackend } from "three/webgpu";
|
|
3
5
|
// src/atlas/gpuAtlas.ts
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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"));
|
|
6
|
+
var devicePipelines = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
function asAtlasPipelines(workgroupDim, directStore, layouts, tiledStore, tiledStoreWide, multi, sep12) {
|
|
8
|
+
return {
|
|
9
|
+
workgroupDim,
|
|
10
|
+
directStore,
|
|
11
|
+
layouts,
|
|
12
|
+
sepHoriz: multi?.sepHoriz ?? null,
|
|
13
|
+
sepVertStore: multi?.sepVertStore ?? null,
|
|
14
|
+
sepHorizPx12: sep12?.sepHorizPx12 ?? null,
|
|
15
|
+
sepVertPx12: sep12?.sepVertPx12 ?? null,
|
|
16
|
+
tiledStore,
|
|
17
|
+
tiledStoreWide,
|
|
18
|
+
resolve: multi?.resolve ?? null
|
|
19
|
+
};
|
|
24
20
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return Math.ceil(width / 64) * 256;
|
|
21
|
+
function atlasModeFor(directStore, pxRange, limits, width = 0, height = 0) {
|
|
22
|
+
return selectAtlasMode(directStore, pxRange, limits, width, height);
|
|
28
23
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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`);
|
|
48
|
-
}
|
|
49
|
-
var ERROR_FILTERS = [
|
|
50
|
-
"validation",
|
|
51
|
-
"out-of-memory",
|
|
52
|
-
"internal"
|
|
53
|
-
];
|
|
54
|
-
function openErrorScopes(device) {
|
|
55
|
-
const push = device.pushErrorScope;
|
|
56
|
-
const pop = device.popErrorScope;
|
|
57
|
-
if (!push || !pop) return { close: () => Promise.resolve(null) };
|
|
58
|
-
for (const filter of ERROR_FILTERS) push.call(device, filter);
|
|
59
|
-
return { close() {
|
|
60
|
-
return Promise.all(ERROR_FILTERS.map(() => pop.call(device))).then((errors) => {
|
|
61
|
-
const error = errors.find(Boolean);
|
|
62
|
-
return error ? error.message ?? "unknown GPU error" : null;
|
|
63
|
-
}, (error) => String(error));
|
|
64
|
-
} };
|
|
24
|
+
function getDeviceCache(device, workgroupDim, directStore, needWideTiled = false) {
|
|
25
|
+
const existing = devicePipelines.get(device);
|
|
26
|
+
if (existing?.workgroupDim === workgroupDim && existing.directStore === directStore && (!needWideTiled || existing.includeWideTiled)) return existing;
|
|
27
|
+
const includeWideTiled = needWideTiled || !storageBufferFits(device.limits, 4096, 4096);
|
|
28
|
+
const cache = {
|
|
29
|
+
workgroupDim,
|
|
30
|
+
directStore,
|
|
31
|
+
includeWideTiled,
|
|
32
|
+
layouts: getJfaLayouts(device),
|
|
33
|
+
module: device.createShaderModule({
|
|
34
|
+
label: "ultra-text atlas",
|
|
35
|
+
code: buildJfaWgsl(workgroupDim, directStore, true, includeWideTiled)
|
|
36
|
+
})
|
|
37
|
+
};
|
|
38
|
+
devicePipelines.set(device, cache);
|
|
39
|
+
return cache;
|
|
65
40
|
}
|
|
66
|
-
function
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return
|
|
41
|
+
function cachedAtlasPipelines(device, workgroupDim, directStore, mode) {
|
|
42
|
+
const cache = devicePipelines.get(device);
|
|
43
|
+
if (cache?.workgroupDim !== workgroupDim || cache.directStore !== directStore) return void 0;
|
|
44
|
+
if (mode === "sep12") return cache.sep12 ? asAtlasPipelines(workgroupDim, directStore, cache.layouts, null, null, void 0, cache.sep12) : void 0;
|
|
45
|
+
if (mode === "tiled12") return cache.tiledStore ? asAtlasPipelines(workgroupDim, directStore, cache.layouts, cache.tiledStore, null) : void 0;
|
|
46
|
+
if (mode === "tiled32") return cache.tiledWide ? asAtlasPipelines(workgroupDim, directStore, cache.layouts, null, cache.tiledWide) : void 0;
|
|
47
|
+
return cache.multi ? asAtlasPipelines(workgroupDim, directStore, cache.layouts, null, null, cache.multi) : void 0;
|
|
73
48
|
}
|
|
74
|
-
var devicePipelines = /* @__PURE__ */ new WeakMap();
|
|
75
|
-
var devicePipelinePromises = /* @__PURE__ */ new WeakMap();
|
|
76
49
|
function supportsAsyncAtlasPipelines(device, directStore) {
|
|
77
50
|
return typeof device.createComputePipelineAsync === "function" && (directStore || typeof device.createRenderPipelineAsync === "function");
|
|
78
51
|
}
|
|
79
|
-
function
|
|
80
|
-
const cached =
|
|
81
|
-
if (cached
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
52
|
+
function buildAtlasPipelines(device, workgroupDim, directStore, mode, async) {
|
|
53
|
+
const cached = cachedAtlasPipelines(device, workgroupDim, directStore, mode);
|
|
54
|
+
if (cached) return async ? Promise.resolve(cached) : cached;
|
|
55
|
+
const existing = devicePipelines.get(device);
|
|
56
|
+
const sameConfig = existing?.workgroupDim === workgroupDim && existing.directStore === directStore;
|
|
57
|
+
if (async && sameConfig) {
|
|
58
|
+
const inFlight = mode === "sep12" ? existing.sep12Promise : mode === "tiled12" ? existing.tiledPromise : mode === "tiled32" ? existing.tiledWidePromise : existing.multiPromise;
|
|
59
|
+
if (inFlight) return inFlight;
|
|
60
|
+
}
|
|
61
|
+
const cache = getDeviceCache(device, workgroupDim, directStore, mode === "tiled32");
|
|
62
|
+
const { module, layouts } = cache;
|
|
63
|
+
const computeSync = (entryPoint, layout) => device.createComputePipeline({
|
|
64
|
+
layout,
|
|
88
65
|
compute: {
|
|
89
66
|
module,
|
|
90
67
|
entryPoint
|
|
91
68
|
}
|
|
92
69
|
});
|
|
93
|
-
const
|
|
94
|
-
|
|
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
|
-
const computeAsync = (entryPoint) => device.createComputePipelineAsync({
|
|
125
|
-
layout: "auto",
|
|
70
|
+
const computeAsync = (entryPoint, layout) => device.createComputePipelineAsync({
|
|
71
|
+
layout,
|
|
126
72
|
compute: {
|
|
127
73
|
module,
|
|
128
74
|
entryPoint
|
|
129
75
|
}
|
|
130
76
|
});
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
77
|
+
if (mode === "sep12") {
|
|
78
|
+
const hLayout = layouts ? layouts.sepHorizPipeline : "auto";
|
|
79
|
+
const vLayout = layouts ? layouts.sepVertStorePipeline : "auto";
|
|
80
|
+
const storeSep12 = (sepHorizPx12, sepVertPx12) => {
|
|
81
|
+
const sep12 = {
|
|
82
|
+
sepHorizPx12,
|
|
83
|
+
sepVertPx12
|
|
84
|
+
};
|
|
85
|
+
cache.sep12 = sep12;
|
|
86
|
+
return asAtlasPipelines(workgroupDim, directStore, layouts, null, null, void 0, sep12);
|
|
87
|
+
};
|
|
88
|
+
if (!async) return storeSep12(computeSync("sepHorizPx12", hLayout), computeSync("sepVertPx12", vLayout));
|
|
89
|
+
const promise = Promise.all([computeAsync("sepHorizPx12", hLayout), computeAsync("sepVertPx12", vLayout)]).then(([h, v]) => storeSep12(h, v), (error) => {
|
|
90
|
+
if (cache.sep12Promise === promise) cache.sep12Promise = void 0;
|
|
91
|
+
throw error;
|
|
92
|
+
});
|
|
93
|
+
cache.sep12Promise = promise;
|
|
94
|
+
return promise;
|
|
95
|
+
}
|
|
96
|
+
if (mode === "tiled12" || mode === "tiled32") {
|
|
97
|
+
const isWide = mode === "tiled32";
|
|
98
|
+
const entryPoint = isWide ? "tiledStoreWideMain" : "tiledStoreMain";
|
|
99
|
+
const layout = layouts ? layouts.tiledPipeline : "auto";
|
|
100
|
+
const store = (pipeline) => {
|
|
101
|
+
if (isWide) cache.tiledWide = pipeline;
|
|
102
|
+
else cache.tiledStore = pipeline;
|
|
103
|
+
return asAtlasPipelines(workgroupDim, directStore, layouts, isWide ? null : pipeline, isWide ? pipeline : null);
|
|
104
|
+
};
|
|
105
|
+
if (!async) return store(computeSync(entryPoint, layout));
|
|
106
|
+
const promise = computeAsync(entryPoint, layout).then((pipeline) => store(pipeline), (error) => {
|
|
107
|
+
if (isWide) {
|
|
108
|
+
if (cache.tiledWidePromise === promise) cache.tiledWidePromise = void 0;
|
|
109
|
+
} else if (cache.tiledPromise === promise) cache.tiledPromise = void 0;
|
|
110
|
+
throw error;
|
|
111
|
+
});
|
|
112
|
+
if (isWide) cache.tiledWidePromise = promise;
|
|
113
|
+
else cache.tiledPromise = promise;
|
|
114
|
+
return promise;
|
|
115
|
+
}
|
|
116
|
+
const resolveDesc = {
|
|
117
|
+
layout: layouts ? layouts.resolvePipeline : "auto",
|
|
118
|
+
vertex: {
|
|
119
|
+
module,
|
|
120
|
+
entryPoint: "fullscreenVert"
|
|
121
|
+
},
|
|
122
|
+
fragment: {
|
|
123
|
+
module,
|
|
124
|
+
entryPoint: "resolveFrag",
|
|
125
|
+
targets: [{ format: "r8unorm" }]
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const store = (sepHoriz, sepVertStore, resolve) => {
|
|
129
|
+
const multi = {
|
|
130
|
+
sepHoriz,
|
|
131
|
+
sepVertStore,
|
|
154
132
|
resolve
|
|
155
133
|
};
|
|
156
|
-
|
|
157
|
-
return
|
|
158
|
-
}
|
|
159
|
-
|
|
134
|
+
cache.multi = multi;
|
|
135
|
+
return asAtlasPipelines(workgroupDim, directStore, layouts, null, null, multi);
|
|
136
|
+
};
|
|
137
|
+
const horizLayout = layouts ? layouts.sepHorizPipeline : "auto";
|
|
138
|
+
const vertLayout = directStore && layouts ? layouts.sepVertStorePipeline : "auto";
|
|
139
|
+
if (!async) return store(computeSync("sepHorizMain", horizLayout), directStore ? computeSync("sepVertStoreMain", vertLayout) : null, directStore ? null : device.createRenderPipeline(resolveDesc));
|
|
140
|
+
const promise = Promise.all([
|
|
141
|
+
computeAsync("sepHorizMain", horizLayout),
|
|
142
|
+
directStore ? computeAsync("sepVertStoreMain", vertLayout) : Promise.resolve(null),
|
|
143
|
+
directStore ? Promise.resolve(null) : device.createRenderPipelineAsync(resolveDesc)
|
|
144
|
+
]).then(([sepHoriz, sepVertStore, resolve]) => store(sepHoriz, sepVertStore, resolve), (error) => {
|
|
145
|
+
if (cache.multiPromise === promise) cache.multiPromise = void 0;
|
|
160
146
|
throw error;
|
|
161
147
|
});
|
|
162
|
-
|
|
163
|
-
workgroupDim,
|
|
164
|
-
directStore,
|
|
165
|
-
promise
|
|
166
|
-
});
|
|
148
|
+
cache.multiPromise = promise;
|
|
167
149
|
return promise;
|
|
168
150
|
}
|
|
169
151
|
/**
|
|
170
152
|
* @internal Starts the native compile of the device's atlas passes ahead of its first atlas,
|
|
171
153
|
* while the caller reads the DOM.
|
|
172
154
|
*/
|
|
173
|
-
function prepareAtlasPasses(renderer) {
|
|
155
|
+
function prepareAtlasPasses(renderer, pxRange) {
|
|
174
156
|
const device = atlasDevice(renderer);
|
|
175
|
-
if (device?.createShaderModule
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
157
|
+
if (!device?.createShaderModule) return;
|
|
158
|
+
const directStore = supportsDirectStore(device.features);
|
|
159
|
+
const workgroupDim = selectWorkgroupDimension(device.limits);
|
|
160
|
+
const mode = atlasModeFor(directStore, pxRange);
|
|
161
|
+
const cached = devicePipelines.get(device);
|
|
162
|
+
if (cached?.workgroupDim === workgroupDim && cached.directStore === directStore && (mode === "sep12" ? cached.sep12 || cached.sep12Promise : mode === "tiled12" ? cached.tiledStore || cached.tiledPromise : mode === "tiled32" ? cached.tiledWide || cached.tiledWidePromise : cached.multi || cached.multiPromise)) return;
|
|
163
|
+
if (supportsAsyncAtlasPipelines(device, directStore)) buildAtlasPipelines(device, workgroupDim, directStore, mode, true).catch(() => void 0);
|
|
164
|
+
else buildAtlasPipelines(device, workgroupDim, directStore, mode, false);
|
|
165
|
+
device.queue.submit([]);
|
|
182
166
|
}
|
|
183
167
|
/**
|
|
184
168
|
* @internal Regenerates the mips of an atlas texture from its level 0 with three's own mip
|
|
@@ -204,159 +188,46 @@ function atlasDevice(renderer) {
|
|
|
204
188
|
* @internal Runs the atlas passes over `raster` into level 0 of a new r8unorm texture of
|
|
205
189
|
* `mipLevelCount` levels, all in one command buffer.
|
|
206
190
|
*/
|
|
207
|
-
async function encodeGpuSdf(device, raster, mipLevelCount, finish, onSubmitted) {
|
|
208
|
-
const { width, height, pxRange } = raster;
|
|
191
|
+
async function encodeGpuSdf(device, raster, mipLevelCount, finish, onSubmitted, extraTransient) {
|
|
192
|
+
const { width, height, pxRange, canvas } = raster;
|
|
209
193
|
const { GPUBufferUsage: buffers, GPUTextureUsage: textures } = globalThis;
|
|
210
194
|
if (!device?.createCommandEncoder || !buffers || !textures) throw new Error("buildGpuSdfAtlas: device cannot run the atlas passes");
|
|
211
|
-
const
|
|
212
|
-
const directStore = supportsDirectStore(device);
|
|
213
|
-
|
|
195
|
+
const radius = edtRadius(pxRange);
|
|
196
|
+
const directStore = supportsDirectStore(device.features);
|
|
197
|
+
const mode = atlasModeFor(directStore, pxRange, device.limits, width, height);
|
|
198
|
+
checkCommonAtlasLimits("buildGpuSdfAtlas", device.limits, width, height, radius, directStore, "; use atlasMode \"cpu\"", mode);
|
|
214
199
|
const workgroupDim = selectWorkgroupDimension(device.limits);
|
|
215
|
-
let prebuilt =
|
|
216
|
-
|
|
217
|
-
|
|
200
|
+
let prebuilt = cachedAtlasPipelines(device, workgroupDim, directStore, mode);
|
|
201
|
+
const cachedEntry = devicePipelines.get(device);
|
|
202
|
+
const inFlight = !prebuilt && cachedEntry?.workgroupDim === workgroupDim && cachedEntry.directStore === directStore ? mode === "sep12" ? cachedEntry.sep12Promise : mode === "tiled12" ? cachedEntry.tiledPromise : mode === "tiled32" ? cachedEntry.tiledWidePromise : cachedEntry.multiPromise : void 0;
|
|
203
|
+
if (inFlight) try {
|
|
204
|
+
prebuilt = await inFlight;
|
|
218
205
|
} catch (error) {
|
|
219
206
|
throw new Error(`buildGpuSdfAtlas: the device rejected the atlas passes: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
220
207
|
}
|
|
221
|
-
|
|
208
|
+
const pool = getDeviceGpuPool(device);
|
|
209
|
+
const retainPool = pool.beginBuild();
|
|
222
210
|
const transient = [];
|
|
223
211
|
let output;
|
|
212
|
+
let resolvedOk = false;
|
|
213
|
+
let buildEnded = false;
|
|
224
214
|
try {
|
|
225
215
|
const scopes = openErrorScopes(device);
|
|
226
216
|
let reported;
|
|
227
217
|
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]);
|
|
218
|
+
const pipelines = prebuilt ?? buildAtlasPipelines(device, workgroupDim, directStore, mode, false);
|
|
273
219
|
output = device.createTexture({
|
|
274
220
|
size: [width, height],
|
|
275
221
|
mipLevelCount,
|
|
276
222
|
format: "r8unorm",
|
|
277
223
|
usage: textures.RENDER_ATTACHMENT | textures.TEXTURE_BINDING | textures.COPY_SRC | textures.COPY_DST | (pipelines.directStore ? textures.STORAGE_BINDING ?? 0 : 0)
|
|
278
224
|
});
|
|
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
225
|
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
|
-
}
|
|
226
|
+
encodeJfaWork(device, encoder, pipelines, canvas, width, height, pxRange, radius, output, transient, buffers, textures, pool);
|
|
358
227
|
finish?.(encoder, output);
|
|
228
|
+
if (extraTransient?.length) transient.push(...extraTransient);
|
|
359
229
|
device.queue.submit([encoder.finish()]);
|
|
230
|
+
pool.resetRing();
|
|
360
231
|
} finally {
|
|
361
232
|
reported = scopes.close();
|
|
362
233
|
}
|
|
@@ -364,14 +235,17 @@ async function encodeGpuSdf(device, raster, mipLevelCount, finish, onSubmitted)
|
|
|
364
235
|
const rejection = await reported;
|
|
365
236
|
if (rejection !== null) {
|
|
366
237
|
devicePipelines.delete(device);
|
|
367
|
-
devicePipelinePromises.delete(device);
|
|
368
238
|
throw new Error(`buildGpuSdfAtlas: the device rejected the atlas passes: ${rejection}`);
|
|
369
239
|
}
|
|
240
|
+
resolvedOk = true;
|
|
241
|
+
buildEnded = true;
|
|
242
|
+
pool.endBuild(transient, retainPool, false);
|
|
243
|
+
transient.length = 0;
|
|
370
244
|
const retained = output;
|
|
371
245
|
output = void 0;
|
|
372
246
|
return retained;
|
|
373
247
|
} finally {
|
|
374
|
-
|
|
248
|
+
if (!resolvedOk && !buildEnded) pool.endBuild(transient, false, true);
|
|
375
249
|
output?.destroy();
|
|
376
250
|
}
|
|
377
251
|
}
|
|
@@ -439,10 +313,12 @@ async function buildGpuSdfAtlas(renderer, raster, options = {}, onProvisional) {
|
|
|
439
313
|
}
|
|
440
314
|
};
|
|
441
315
|
};
|
|
442
|
-
|
|
316
|
+
const device = atlasDevice(renderer);
|
|
317
|
+
const bleed = raster.colorBand && device ? peekDeferredColorBleed(raster.colorBand.data) : void 0;
|
|
318
|
+
if (onProvisional && !mipmaps && !bleed) {
|
|
443
319
|
let wrapped;
|
|
444
320
|
try {
|
|
445
|
-
const gpuTexture = await encodeGpuSdf(
|
|
321
|
+
const gpuTexture = await encodeGpuSdf(device, raster, levels, void 0, (candidate) => {
|
|
446
322
|
wrapped = wrapAtlas(candidate);
|
|
447
323
|
onProvisional(wrapped.atlas);
|
|
448
324
|
});
|
|
@@ -455,10 +331,35 @@ async function buildGpuSdfAtlas(renderer, raster, options = {}, onProvisional) {
|
|
|
455
331
|
throw error;
|
|
456
332
|
}
|
|
457
333
|
}
|
|
458
|
-
const
|
|
334
|
+
const extraTransient = [];
|
|
335
|
+
let colorGpuTex;
|
|
336
|
+
const encodeBleed = (encoder) => {
|
|
337
|
+
if (!bleed || !device) return;
|
|
338
|
+
const colorMips = mipCount(width, bleed.height, mipmaps);
|
|
339
|
+
const res = encodeGpuColorBleed(device, encoder, bleed, colorMips, getDeviceGpuPool(device));
|
|
340
|
+
colorGpuTex = res.texture;
|
|
341
|
+
extraTransient.push(...res.transient);
|
|
342
|
+
if (colorMips > 1) {
|
|
343
|
+
const mip = getDeviceMipPipeline(device, "rgba8unorm-srgb");
|
|
344
|
+
encodeMipmapChain(device, encoder, colorGpuTex, colorMips, mip.pipeline, mip.sampler, mip.layout);
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
let gpuTexture;
|
|
348
|
+
try {
|
|
349
|
+
gpuTexture = await encodeGpuSdf(device, raster, levels, bleed ? encodeBleed : void 0, void 0, extraTransient);
|
|
350
|
+
} catch (error) {
|
|
351
|
+
colorGpuTex?.destroy();
|
|
352
|
+
throw error;
|
|
353
|
+
}
|
|
354
|
+
if (colorGpuTex && raster.colorBand) {
|
|
355
|
+
takeDeferredColorBleed(raster.colorBand.data);
|
|
356
|
+
putReadyGpuColorTexture(raster.colorBand.data, colorGpuTex);
|
|
357
|
+
}
|
|
358
|
+
const { atlas } = wrapAtlas(gpuTexture);
|
|
459
359
|
try {
|
|
460
360
|
if (mipmaps) await generateAtlasMips(renderer, atlas.texture);
|
|
461
361
|
} catch (error) {
|
|
362
|
+
if (raster.colorBand) takeReadyGpuColorTexture(raster.colorBand.data)?.destroy();
|
|
462
363
|
atlas.dispose();
|
|
463
364
|
throw error;
|
|
464
365
|
}
|