ultra-text 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +193 -115
- package/dist/assets/{cpuSdf.worker--X1Qpmdp.js → cpuSdf.worker-Dy4P5_TI.js} +98 -43
- 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 +35 -11
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +1 -1
- 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.js +8 -3
- package/dist/atlas/cpuAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.d.ts +1 -1
- package/dist/atlas/cpuSdf.js +97 -42
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.d.ts +10 -4
- package/dist/atlas/cpuWorker.js +99 -49
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.js +133 -56
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/gpuCommon.d.ts +140 -18
- package/dist/atlas/gpuCommon.js +726 -104
- package/dist/atlas/gpuCommon.js.map +1 -1
- package/dist/atlas/jfaWgsl.d.ts +1 -1
- package/dist/atlas/jfaWgsl.js +232 -61
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.d.ts +22 -0
- package/dist/atlas/rasterize.js +237 -111
- package/dist/atlas/rasterize.js.map +1 -1
- package/dist/atlas/vanillaCore.js +156 -103
- package/dist/atlas/vanillaCore.js.map +1 -1
- package/dist/atlas/vanillaCpuAtlas.js +37 -52
- package/dist/atlas/vanillaCpuAtlas.js.map +1 -1
- package/dist/atlas/vanillaExtras.js +91 -90
- package/dist/atlas/vanillaExtras.js.map +1 -1
- package/dist/atlas/vanillaGpuHelpers.d.ts +70 -7
- package/dist/atlas/vanillaGpuHelpers.js +262 -27
- package/dist/atlas/vanillaGpuHelpers.js.map +1 -1
- package/dist/dom/DomSdf.js +85 -79
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.js +23 -18
- 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 +1 -2
- package/dist/dom/domAnalytic.js +1 -1
- package/dist/dom/domAnalytic.js.map +1 -1
- package/dist/dom/fontCanvas.d.ts +16 -0
- package/dist/dom/fontCanvas.js +4 -4
- package/dist/dom/fontCanvas.js.map +1 -1
- package/dist/dom/layoutSignature.js +28 -12
- 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 +27 -19
- package/dist/dom/pretextLayout.js.map +1 -1
- package/dist/dom/snapshot.d.ts +4 -0
- package/dist/dom/snapshot.js +747 -505
- 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.js +30 -27
- 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 +15 -8
- package/dist/dom/tone.js.map +1 -1
- package/dist/slug/SlugMaterial.d.ts +6 -0
- package/dist/slug/SlugMaterial.js +48 -20
- 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 +3 -3
- package/dist/slug/coverage.js +283 -101
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +1 -1
- package/dist/slug/preprocessCore.js +100 -80
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.js +32 -39
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.js +47 -37
- package/dist/slug/standaloneRuntime.js.map +1 -1
- package/dist/slug/truetype.d.ts +14 -6
- package/dist/slug/truetype.js +190 -62
- package/dist/slug/truetype.js.map +1 -1
- package/dist/slug/vanillaCore.d.ts +74 -4
- package/dist/slug/vanillaCore.js +226 -217
- package/dist/slug/vanillaCore.js.map +1 -1
- package/dist/slug-vanilla.d.ts +1 -1
- package/dist/slug-vanilla.js +5 -4
- package/dist/slug.d.ts +1 -1
- package/dist/slug.js +3 -3
- package/dist/text/GlyphTextMaterial.d.ts +5 -0
- package/dist/text/GlyphTextMaterial.js +11 -7
- 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 +122 -37
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/text/decorations.d.ts +7 -2
- package/dist/text/decorations.js +187 -96
- package/dist/text/decorations.js.map +1 -1
- package/dist/text/geometryUtils.d.ts +5 -0
- package/dist/text/geometryUtils.js +63 -9
- package/dist/text/geometryUtils.js.map +1 -1
- package/dist/text/glyphGeometry.d.ts +1 -1
- package/dist/text/glyphGeometry.js +281 -200
- package/dist/text/glyphGeometry.js.map +1 -1
- package/dist/text/rectGeometry.js +46 -42
- package/dist/text/rectGeometry.js.map +1 -1
- package/dist/text/reflow.d.ts +5 -0
- package/dist/text/reflow.js +127 -68
- package/dist/text/reflow.js.map +1 -1
- package/dist/text/snap.d.ts +15 -1
- package/dist/text/snap.js +1 -1
- package/dist/text/snap.js.map +1 -1
- 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.js +1 -1
- 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 +15 -0
- package/dist/windfoil/geometry.js +154 -64
- 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.js +13 -4
- 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 +63 -36
- 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 +1 -0
- package/dist/windfoil/runtime.js +8 -24
- 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 +23 -9
- package/dist/windfoil/storage.js +49 -30
- 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.js +120 -50
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.js +578 -224
- package/dist/windfoil/trace/fit.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/tracedOutlines.d.ts +2 -0
- package/dist/windfoil/tracedOutlines.js +335 -70
- 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 +26 -24
- package/skills/ultra-text/references/vanilla-webgpu.md +3 -1
- package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +0 -1
package/dist/atlas/gpuCommon.js
CHANGED
|
@@ -1,16 +1,34 @@
|
|
|
1
|
+
import { COLOR_BLEED_WGSL } from "./jfaWgsl.js";
|
|
2
|
+
var TILED_MAX_TEXELS = 45e4;
|
|
1
3
|
var ERROR_FILTERS = [
|
|
2
4
|
"validation",
|
|
3
5
|
"out-of-memory",
|
|
4
6
|
"internal"
|
|
5
7
|
];
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
+
function storageBufferFits(limits, width, height) {
|
|
9
|
+
if (!limits || width <= 0 || height <= 0) return true;
|
|
10
|
+
const bytes = width * height * 4;
|
|
11
|
+
const storageStage = limits.maxStorageBuffersPerShaderStage;
|
|
12
|
+
if (storageStage !== void 0 && storageStage < 1) return false;
|
|
13
|
+
if (limits.maxStorageBufferBindingSize !== void 0 && bytes > limits.maxStorageBufferBindingSize) return false;
|
|
14
|
+
if (limits.maxBufferSize !== void 0 && bytes > limits.maxBufferSize) return false;
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
function selectAtlasMode(directStore, pxRange, limits, width = 0, height = 0) {
|
|
18
|
+
if (!directStore) return "multi";
|
|
19
|
+
const workgroupDim = selectWorkgroupDimension(limits);
|
|
20
|
+
if (pxRange === void 0 || pxRange <= 12) {
|
|
21
|
+
if (workgroupDim === 16 && width * height > 45e4 && storageBufferFits(limits, width, height)) return "sep12";
|
|
22
|
+
return "tiled12";
|
|
23
|
+
}
|
|
24
|
+
if (pxRange <= 32 && !storageBufferFits(limits, width, height)) return "tiled32";
|
|
25
|
+
return "multi";
|
|
8
26
|
}
|
|
9
27
|
var KERNEL_NEEDS = [
|
|
10
28
|
["maxComputeInvocationsPerWorkgroup", 64],
|
|
11
29
|
["maxComputeWorkgroupSizeX", 8],
|
|
12
30
|
["maxComputeWorkgroupSizeY", 8],
|
|
13
|
-
["maxStorageBuffersPerShaderStage",
|
|
31
|
+
["maxStorageBuffersPerShaderStage", 1]
|
|
14
32
|
];
|
|
15
33
|
function selectWorkgroupDimension(limits) {
|
|
16
34
|
const inv = limits?.maxComputeInvocationsPerWorkgroup ?? 256;
|
|
@@ -22,21 +40,15 @@ function supportsDirectStore(features) {
|
|
|
22
40
|
const textures = globalThis.GPUTextureUsage;
|
|
23
41
|
return typeof textures?.STORAGE_BINDING === "number" && textures.STORAGE_BINDING > 0 && Boolean(features?.has("texture-formats-tier1"));
|
|
24
42
|
}
|
|
25
|
-
function
|
|
26
|
-
return Math.ceil(
|
|
43
|
+
function edtRadius(pxRange) {
|
|
44
|
+
return Math.ceil(pxRange * .5) + 1;
|
|
27
45
|
}
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
let step = 1;
|
|
31
|
-
while (step * 2 - 1 < radius) step <<= 1;
|
|
32
|
-
const steps = [];
|
|
33
|
-
for (; step >= 1; step >>= 1) steps.push(step);
|
|
34
|
-
return steps;
|
|
35
|
-
}
|
|
36
|
-
function checkCommonAtlasLimits(caller, limits, width, height, maxStep, directStore, cpuHint = "") {
|
|
37
|
-
if (maxStep > 64) throw new RangeError(`${caller}: pxRange exceeds fixed-point jump range${cpuHint}`);
|
|
46
|
+
function checkCommonAtlasLimits(caller, limits, width, height, radius, directStore, cpuHint = "", mode) {
|
|
47
|
+
if (radius > 65) throw new RangeError(`${caller}: pxRange exceeds fixed-point jump range${cpuHint}`);
|
|
38
48
|
if (!limits) return;
|
|
39
|
-
|
|
49
|
+
const tiledOnly = mode !== void 0 ? mode === "tiled12" || mode === "tiled32" : directStore && radius <= 7;
|
|
50
|
+
const needs = tiledOnly ? KERNEL_NEEDS.slice(0, 3) : KERNEL_NEEDS;
|
|
51
|
+
for (const [name, need] of needs) {
|
|
40
52
|
const value = limits[name];
|
|
41
53
|
if (value !== void 0 && value < need) throw new RangeError(`${caller}: ${name}=${value}, needs ${need}${cpuHint}`);
|
|
42
54
|
}
|
|
@@ -46,7 +58,11 @@ function checkCommonAtlasLimits(caller, limits, width, height, maxStep, directSt
|
|
|
46
58
|
}
|
|
47
59
|
const largest = limits.maxTextureDimension2D;
|
|
48
60
|
if (largest !== void 0 && Math.max(width, height) > largest) throw new RangeError(`${caller}: ${width}×${height} exceeds maxTextureDimension2D=${largest}${cpuHint ? "; lower maxAtlasSize" : ""}`);
|
|
49
|
-
|
|
61
|
+
if (tiledOnly) {
|
|
62
|
+
if (limits.maxBufferSize !== void 0 && 16 > limits.maxBufferSize) throw new RangeError(`${caller}: ${width}×${height} exceeds storage-buffer limits${cpuHint ? `${cpuHint} or lower maxAtlasSize` : ""}`);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const bytes = width * height * 4;
|
|
50
66
|
if (limits.maxStorageBufferBindingSize !== void 0 && bytes > limits.maxStorageBufferBindingSize || limits.maxBufferSize !== void 0 && bytes > limits.maxBufferSize) throw new RangeError(`${caller}: ${width}×${height} exceeds storage-buffer limits${cpuHint ? `${cpuHint} or lower maxAtlasSize` : ""}`);
|
|
51
67
|
}
|
|
52
68
|
function openErrorScopes(device) {
|
|
@@ -61,46 +77,366 @@ function openErrorScopes(device) {
|
|
|
61
77
|
}, (error) => String(error));
|
|
62
78
|
} };
|
|
63
79
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
80
|
+
var POOL_MAX_PER_CLASS = 2;
|
|
81
|
+
var POOL_MAX_IDLE_BYTES = 100663296;
|
|
82
|
+
var POOL_IDLE_TRIM_MS = 5e3;
|
|
83
|
+
var POOL_RING_BYTES = 4096;
|
|
84
|
+
function poolSizeClass(size, maxBufferSize = Infinity) {
|
|
85
|
+
const need = Math.max(256, Math.ceil(size / 4) * 4);
|
|
86
|
+
const pow2 = 2 ** Math.ceil(Math.log2(need));
|
|
87
|
+
let b = pow2 <= maxBufferSize ? pow2 : need;
|
|
88
|
+
if (b >= 524288) b = size <= b * 11 / 16 ? b * 11 / 16 : size <= b * 3 / 4 ? b * 3 / 4 : b;
|
|
89
|
+
return b;
|
|
90
|
+
}
|
|
91
|
+
function createGpuPool(device, options = {}) {
|
|
92
|
+
const now = options.now ?? (() => performance.now());
|
|
93
|
+
const setTimer = options.setTimer ?? ((fn, ms) => setTimeout(fn, ms));
|
|
94
|
+
const clearTimer = options.clearTimer ?? ((id) => clearTimeout(id));
|
|
95
|
+
const maxBuf = device.limits?.maxBufferSize ?? Infinity;
|
|
96
|
+
const maxStorageBuf = device.limits?.maxStorageBufferBindingSize ?? maxBuf;
|
|
97
|
+
const maxDim = device.limits?.maxTextureDimension2D ?? Infinity;
|
|
98
|
+
const ringBytes = Math.min(POOL_RING_BYTES, maxBuf);
|
|
99
|
+
const align = Math.max(256, device.limits?.minUniformBufferOffsetAlignment ?? 256);
|
|
100
|
+
const idle = /* @__PURE__ */ new Map();
|
|
101
|
+
const meta = /* @__PURE__ */ new WeakMap();
|
|
102
|
+
const counters = {
|
|
103
|
+
liveBuffers: 0,
|
|
104
|
+
liveTextures: 0,
|
|
105
|
+
liveBytes: 0,
|
|
106
|
+
idleBytes: 0,
|
|
107
|
+
createdBuffers: 0,
|
|
108
|
+
createdTextures: 0,
|
|
109
|
+
reused: 0
|
|
110
|
+
};
|
|
111
|
+
let ringBuffers = [];
|
|
112
|
+
let ringIndex = 0;
|
|
113
|
+
let ringOffset = 0;
|
|
114
|
+
let timer = null;
|
|
115
|
+
let destroyed = false;
|
|
116
|
+
let builds = 0;
|
|
117
|
+
let activeBuilds = 0;
|
|
118
|
+
let warm = false;
|
|
119
|
+
let lastBuildTime = now();
|
|
120
|
+
const lend = (m, sign) => {
|
|
121
|
+
counters[`live${m.kind}`] += sign;
|
|
122
|
+
counters.liveBytes += sign * m.bytes;
|
|
123
|
+
};
|
|
124
|
+
const lendOut = (key, bytes, kind, make) => {
|
|
125
|
+
const list = idle.get(key);
|
|
126
|
+
const item = list?.pop();
|
|
127
|
+
let resource;
|
|
128
|
+
if (item) {
|
|
129
|
+
if (!list.length) idle.delete(key);
|
|
130
|
+
counters.idleBytes -= item.bytes;
|
|
131
|
+
counters.reused++;
|
|
132
|
+
resource = item.resource;
|
|
133
|
+
} else {
|
|
134
|
+
resource = make();
|
|
135
|
+
meta.set(resource, {
|
|
136
|
+
key,
|
|
137
|
+
bytes,
|
|
138
|
+
kind
|
|
139
|
+
});
|
|
140
|
+
counters[`created${kind}`]++;
|
|
141
|
+
}
|
|
142
|
+
lend(meta.get(resource), 1);
|
|
143
|
+
return resource;
|
|
144
|
+
};
|
|
145
|
+
const arm = () => {
|
|
146
|
+
if (timer !== null || destroyed || !idle.size && !warm && builds === 0) return;
|
|
147
|
+
const id = setTimer(() => {
|
|
148
|
+
timer = null;
|
|
149
|
+
trim(false);
|
|
150
|
+
}, POOL_IDLE_TRIM_MS);
|
|
151
|
+
if (id && typeof id.unref === "function") id.unref();
|
|
152
|
+
timer = id;
|
|
153
|
+
};
|
|
154
|
+
function discardRing() {
|
|
155
|
+
for (const b of ringBuffers) b.destroy();
|
|
156
|
+
ringBuffers = [];
|
|
157
|
+
ringIndex = 0;
|
|
158
|
+
ringOffset = 0;
|
|
159
|
+
}
|
|
160
|
+
function resetRing() {
|
|
161
|
+
ringIndex = 0;
|
|
162
|
+
ringOffset = 0;
|
|
163
|
+
}
|
|
164
|
+
function give(resource) {
|
|
165
|
+
if (!resource) return;
|
|
166
|
+
const m = meta.get(resource);
|
|
167
|
+
if (m) lend(m, -1);
|
|
168
|
+
const list = m ? idle.get(m.key) ?? [] : void 0;
|
|
169
|
+
if (!m || !list || destroyed || list.length >= POOL_MAX_PER_CLASS || counters.idleBytes + m.bytes > POOL_MAX_IDLE_BYTES) {
|
|
170
|
+
meta.delete(resource);
|
|
171
|
+
resource.destroy();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
list.push({
|
|
175
|
+
resource,
|
|
176
|
+
key: m.key,
|
|
177
|
+
bytes: m.bytes,
|
|
178
|
+
time: now()
|
|
70
179
|
});
|
|
71
|
-
|
|
72
|
-
|
|
180
|
+
idle.set(m.key, list);
|
|
181
|
+
counters.idleBytes += m.bytes;
|
|
182
|
+
arm();
|
|
183
|
+
}
|
|
184
|
+
function discard(resource) {
|
|
185
|
+
if (!resource) return;
|
|
186
|
+
const m = meta.get(resource);
|
|
187
|
+
if (m) {
|
|
188
|
+
lend(m, -1);
|
|
189
|
+
meta.delete(resource);
|
|
190
|
+
}
|
|
191
|
+
resource.destroy();
|
|
192
|
+
}
|
|
193
|
+
function trim(all = true) {
|
|
194
|
+
const t = now();
|
|
195
|
+
for (const [key, list] of idle) {
|
|
196
|
+
const keep = list.filter((item) => {
|
|
197
|
+
if (!all && t - item.time < 5e3) return true;
|
|
198
|
+
counters.idleBytes -= item.bytes;
|
|
199
|
+
item.resource.destroy();
|
|
200
|
+
return false;
|
|
201
|
+
});
|
|
202
|
+
if (keep.length) idle.set(key, keep);
|
|
203
|
+
else idle.delete(key);
|
|
204
|
+
}
|
|
205
|
+
if (counters.liveBuffers === 0 && counters.liveTextures === 0 && idle.size === 0 && (all || t - lastBuildTime >= 5e3)) {
|
|
206
|
+
discardRing();
|
|
207
|
+
warm = false;
|
|
208
|
+
builds = 0;
|
|
209
|
+
}
|
|
210
|
+
arm();
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
beginBuild() {
|
|
214
|
+
activeBuilds++;
|
|
215
|
+
lastBuildTime = now();
|
|
216
|
+
if (builds === 0 && !warm && idle.size === 0) {
|
|
217
|
+
builds = 1;
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
builds++;
|
|
221
|
+
warm = true;
|
|
222
|
+
return true;
|
|
223
|
+
},
|
|
224
|
+
endBuild(transient, retain, failed = false) {
|
|
225
|
+
activeBuilds = Math.max(0, activeBuilds - 1);
|
|
226
|
+
lastBuildTime = now();
|
|
227
|
+
if (failed || !retain) {
|
|
228
|
+
for (const resource of transient) discard(resource);
|
|
229
|
+
if (activeBuilds === 0 && (failed || !warm)) discardRing();
|
|
230
|
+
else resetRing();
|
|
231
|
+
} else {
|
|
232
|
+
for (const resource of transient) give(resource);
|
|
233
|
+
resetRing();
|
|
234
|
+
}
|
|
235
|
+
arm();
|
|
236
|
+
},
|
|
237
|
+
buffer(size, usage) {
|
|
238
|
+
const bufUsage = globalThis.GPUBufferUsage;
|
|
239
|
+
const limit = (bufUsage ? (usage & bufUsage.STORAGE) !== 0 : (usage & 128) !== 0) ? Math.min(maxBuf, maxStorageBuf) : maxBuf;
|
|
240
|
+
const bytes = warm || builds === 0 ? poolSizeClass(size, limit) : Math.max(256, Math.ceil(size / 4) * 4);
|
|
241
|
+
return lendOut(`b|${usage}|${bytes}`, bytes, "Buffers", () => device.createBuffer({
|
|
242
|
+
size: bytes,
|
|
243
|
+
usage
|
|
244
|
+
}));
|
|
245
|
+
},
|
|
246
|
+
uploadTexture(width, height, format, usage) {
|
|
247
|
+
const round = warm || builds === 0;
|
|
248
|
+
const w = round ? Math.min(maxDim, Math.ceil(width / 64) * 64) : Math.min(maxDim, width);
|
|
249
|
+
const h = round ? Math.min(maxDim, Math.ceil(height / 64) * 64) : Math.min(maxDim, height);
|
|
250
|
+
return lendOut(`t|${format}|${usage}|${w}|${h}`, w * h * 4, "Textures", () => device.createTexture({
|
|
251
|
+
size: [w, h],
|
|
252
|
+
format,
|
|
253
|
+
usage
|
|
254
|
+
}));
|
|
255
|
+
},
|
|
256
|
+
ringAlloc(bytes, usage) {
|
|
257
|
+
const aligned = Math.ceil(bytes / align) * align;
|
|
258
|
+
const size = aligned <= ringBytes || bytes > ringBytes ? aligned : Math.ceil(bytes / 4) * 4;
|
|
259
|
+
if (size > ringBytes) {
|
|
260
|
+
const buffer = device.createBuffer({
|
|
261
|
+
size,
|
|
262
|
+
usage
|
|
263
|
+
});
|
|
264
|
+
ringBuffers.push(buffer);
|
|
265
|
+
return {
|
|
266
|
+
buffer,
|
|
267
|
+
offset: 0
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
if (ringOffset + size > ringBytes) {
|
|
271
|
+
ringIndex++;
|
|
272
|
+
ringOffset = 0;
|
|
273
|
+
}
|
|
274
|
+
const buffer = ringBuffers[ringIndex] ??= device.createBuffer({
|
|
275
|
+
size: ringBytes,
|
|
276
|
+
usage
|
|
277
|
+
});
|
|
278
|
+
const offset = ringOffset;
|
|
279
|
+
ringOffset += size;
|
|
280
|
+
return {
|
|
281
|
+
buffer,
|
|
282
|
+
offset
|
|
283
|
+
};
|
|
284
|
+
},
|
|
285
|
+
resetRing,
|
|
286
|
+
discardRing,
|
|
287
|
+
give,
|
|
288
|
+
discard,
|
|
289
|
+
trim,
|
|
290
|
+
stats() {
|
|
291
|
+
let idleCount = 0;
|
|
292
|
+
for (const list of idle.values()) idleCount += list.length;
|
|
293
|
+
return {
|
|
294
|
+
...counters,
|
|
295
|
+
idle: idleCount,
|
|
296
|
+
live: counters.liveBuffers + counters.liveTextures
|
|
297
|
+
};
|
|
298
|
+
},
|
|
299
|
+
destroy() {
|
|
300
|
+
if (destroyed) return;
|
|
301
|
+
trim(true);
|
|
302
|
+
destroyed = true;
|
|
303
|
+
if (timer !== null) clearTimer(timer);
|
|
304
|
+
timer = null;
|
|
305
|
+
discardRing();
|
|
306
|
+
}
|
|
73
307
|
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
308
|
+
}
|
|
309
|
+
var devicePools = /* @__PURE__ */ new WeakMap();
|
|
310
|
+
var jfaLayouts = /* @__PURE__ */ new WeakMap();
|
|
311
|
+
function getDeviceGpuPool(device) {
|
|
312
|
+
let pool = devicePools.get(device);
|
|
313
|
+
if (!pool) devicePools.set(device, pool = createGpuPool(device));
|
|
314
|
+
return pool;
|
|
315
|
+
}
|
|
316
|
+
function getJfaLayouts(device) {
|
|
317
|
+
const cached = jfaLayouts.get(device);
|
|
318
|
+
if (cached) return cached;
|
|
319
|
+
if (typeof device.createBindGroupLayout !== "function" || typeof device.createPipelineLayout !== "function") return null;
|
|
320
|
+
const createBgl = device.createBindGroupLayout.bind(device);
|
|
321
|
+
const createPl = device.createPipelineLayout.bind(device);
|
|
322
|
+
const COMPUTE = 4;
|
|
323
|
+
const FRAGMENT = 2;
|
|
324
|
+
const uniform = (visibility) => ({
|
|
325
|
+
binding: 0,
|
|
326
|
+
visibility,
|
|
327
|
+
buffer: {
|
|
328
|
+
type: "uniform",
|
|
329
|
+
minBindingSize: 16
|
|
330
|
+
}
|
|
78
331
|
});
|
|
332
|
+
let tiledGroup;
|
|
333
|
+
let tiledPipeline;
|
|
334
|
+
let sepHorizGroup;
|
|
335
|
+
let sepHorizPipeline;
|
|
336
|
+
let sepVertStoreGroup;
|
|
337
|
+
let sepVertStorePipeline;
|
|
338
|
+
let resolveGroup;
|
|
339
|
+
let resolvePipeline;
|
|
340
|
+
const built = {
|
|
341
|
+
get tiledGroup() {
|
|
342
|
+
return tiledGroup ??= createBgl({ entries: [
|
|
343
|
+
uniform(COMPUTE),
|
|
344
|
+
{
|
|
345
|
+
binding: 1,
|
|
346
|
+
visibility: COMPUTE,
|
|
347
|
+
texture: {
|
|
348
|
+
sampleType: "unfilterable-float",
|
|
349
|
+
viewDimension: "2d"
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
binding: 2,
|
|
354
|
+
visibility: COMPUTE,
|
|
355
|
+
storageTexture: {
|
|
356
|
+
format: "r8unorm",
|
|
357
|
+
access: "write-only",
|
|
358
|
+
viewDimension: "2d"
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
] });
|
|
362
|
+
},
|
|
363
|
+
get tiledPipeline() {
|
|
364
|
+
return tiledPipeline ??= createPl({ bindGroupLayouts: [built.tiledGroup] });
|
|
365
|
+
},
|
|
366
|
+
get sepHorizGroup() {
|
|
367
|
+
return sepHorizGroup ??= createBgl({ entries: [
|
|
368
|
+
uniform(COMPUTE),
|
|
369
|
+
{
|
|
370
|
+
binding: 1,
|
|
371
|
+
visibility: COMPUTE,
|
|
372
|
+
texture: {
|
|
373
|
+
sampleType: "unfilterable-float",
|
|
374
|
+
viewDimension: "2d"
|
|
375
|
+
}
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
binding: 2,
|
|
379
|
+
visibility: COMPUTE,
|
|
380
|
+
buffer: { type: "storage" }
|
|
381
|
+
}
|
|
382
|
+
] });
|
|
383
|
+
},
|
|
384
|
+
get sepHorizPipeline() {
|
|
385
|
+
return sepHorizPipeline ??= createPl({ bindGroupLayouts: [built.sepHorizGroup] });
|
|
386
|
+
},
|
|
387
|
+
get sepVertStoreGroup() {
|
|
388
|
+
return sepVertStoreGroup ??= createBgl({ entries: [
|
|
389
|
+
uniform(COMPUTE),
|
|
390
|
+
{
|
|
391
|
+
binding: 1,
|
|
392
|
+
visibility: COMPUTE,
|
|
393
|
+
buffer: { type: "read-only-storage" }
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
binding: 2,
|
|
397
|
+
visibility: COMPUTE,
|
|
398
|
+
storageTexture: {
|
|
399
|
+
format: "r8unorm",
|
|
400
|
+
access: "write-only",
|
|
401
|
+
viewDimension: "2d"
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
] });
|
|
405
|
+
},
|
|
406
|
+
get sepVertStorePipeline() {
|
|
407
|
+
return sepVertStorePipeline ??= createPl({ bindGroupLayouts: [built.sepVertStoreGroup] });
|
|
408
|
+
},
|
|
409
|
+
get resolveGroup() {
|
|
410
|
+
return resolveGroup ??= createBgl({ entries: [uniform(FRAGMENT), {
|
|
411
|
+
binding: 1,
|
|
412
|
+
visibility: FRAGMENT,
|
|
413
|
+
buffer: { type: "read-only-storage" }
|
|
414
|
+
}] });
|
|
415
|
+
},
|
|
416
|
+
get resolvePipeline() {
|
|
417
|
+
return resolvePipeline ??= createPl({ bindGroupLayouts: [built.resolveGroup] });
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
jfaLayouts.set(device, built);
|
|
421
|
+
return built;
|
|
422
|
+
}
|
|
423
|
+
function encodeJfaWork(device, encoder, pipelines, canvas, width, height, pxRange, radius, output, transient, buffers, textures, pool = getDeviceGpuPool(device)) {
|
|
424
|
+
const upload = pool.uploadTexture(width, height, "rgba8unorm", textures.TEXTURE_BINDING | textures.COPY_DST | textures.RENDER_ATTACHMENT);
|
|
79
425
|
transient.push(upload);
|
|
426
|
+
const useSep12 = pipelines.directStore && radius <= 7 && Boolean(pipelines.sepHorizPx12) && Boolean(pipelines.sepVertPx12 ?? pipelines.sepVertStore);
|
|
427
|
+
const tiledStore = !useSep12 && pipelines.directStore && radius <= 17 ? (radius <= 7 ? pipelines.tiledStore : null) ?? pipelines.tiledStoreWide : null;
|
|
80
428
|
const seedBytes = width * height * 4;
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
const params = buffer(useTiled ? 16 : steps.length * 256 + 16, buffers.UNIFORM | buffers.COPY_DST);
|
|
86
|
-
const values = new Int32Array(useTiled ? 4 : steps.length * 64 + 4);
|
|
87
|
-
const invPxRange = 1 / pxRange;
|
|
429
|
+
const seed = tiledStore ? null : pool.buffer(seedBytes, buffers.STORAGE);
|
|
430
|
+
if (seed) transient.push(seed);
|
|
431
|
+
const paramsSlot = pool.ringAlloc(16, buffers.UNIFORM | buffers.COPY_DST);
|
|
432
|
+
const values = /* @__PURE__ */ new Int32Array(4);
|
|
88
433
|
values.set([
|
|
89
434
|
width,
|
|
90
435
|
height,
|
|
91
|
-
|
|
436
|
+
radius
|
|
92
437
|
]);
|
|
93
|
-
new Float32Array(values.buffer, 12, 1)[0] =
|
|
94
|
-
|
|
95
|
-
const base = (index + 1) * 64;
|
|
96
|
-
values.set([
|
|
97
|
-
width,
|
|
98
|
-
height,
|
|
99
|
-
step
|
|
100
|
-
], base);
|
|
101
|
-
new Float32Array(values.buffer, base * 4 + 12, 1)[0] = invPxRange;
|
|
102
|
-
});
|
|
103
|
-
device.queue.writeBuffer(params, 0, values);
|
|
438
|
+
new Float32Array(values.buffer, 12, 1)[0] = 1 / pxRange;
|
|
439
|
+
device.queue.writeBuffer(paramsSlot.buffer, paramsSlot.offset, values);
|
|
104
440
|
device.queue.copyExternalImageToTexture({
|
|
105
441
|
source: canvas,
|
|
106
442
|
flipY: false
|
|
@@ -108,25 +444,13 @@ function encodeJfaWork(device, encoder, pipelines, canvas, width, height, pxRang
|
|
|
108
444
|
texture: upload,
|
|
109
445
|
premultipliedAlpha: false
|
|
110
446
|
}, [width, height]);
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
entries: [{
|
|
119
|
-
binding: 0,
|
|
120
|
-
resource: {
|
|
121
|
-
buffer: params,
|
|
122
|
-
offset,
|
|
123
|
-
size: 16
|
|
124
|
-
}
|
|
125
|
-
}, ...storage.map((resource, index) => ({
|
|
126
|
-
binding: index + 1,
|
|
127
|
-
resource: { buffer: resource }
|
|
128
|
-
}))]
|
|
129
|
-
});
|
|
447
|
+
const uploadView = upload.createView();
|
|
448
|
+
const paramsBinding = {
|
|
449
|
+
buffer: paramsSlot.buffer,
|
|
450
|
+
offset: paramsSlot.offset,
|
|
451
|
+
size: 16
|
|
452
|
+
};
|
|
453
|
+
const layouts = pipelines.layouts ?? null;
|
|
130
454
|
const groupsX = Math.ceil(width / pipelines.workgroupDim);
|
|
131
455
|
const groupsY = Math.ceil(height / pipelines.workgroupDim);
|
|
132
456
|
const flood = encoder.beginComputePass();
|
|
@@ -134,19 +458,15 @@ function encodeJfaWork(device, encoder, pipelines, canvas, width, height, pxRang
|
|
|
134
458
|
const finalView = output.createView({ mipLevelCount: 1 });
|
|
135
459
|
flood.setPipeline(tiledStore);
|
|
136
460
|
flood.setBindGroup(0, device.createBindGroup({
|
|
137
|
-
layout: tiledStore.getBindGroupLayout(0),
|
|
461
|
+
layout: layouts ? layouts.tiledGroup : tiledStore.getBindGroupLayout(0),
|
|
138
462
|
entries: [
|
|
139
463
|
{
|
|
140
464
|
binding: 0,
|
|
141
|
-
resource:
|
|
142
|
-
buffer: params,
|
|
143
|
-
offset: 0,
|
|
144
|
-
size: 16
|
|
145
|
-
}
|
|
465
|
+
resource: paramsBinding
|
|
146
466
|
},
|
|
147
467
|
{
|
|
148
468
|
binding: 1,
|
|
149
|
-
resource:
|
|
469
|
+
resource: uploadView
|
|
150
470
|
},
|
|
151
471
|
{
|
|
152
472
|
binding: 2,
|
|
@@ -158,37 +478,48 @@ function encodeJfaWork(device, encoder, pipelines, canvas, width, height, pxRang
|
|
|
158
478
|
flood.end();
|
|
159
479
|
return upload;
|
|
160
480
|
}
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
flood.
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
481
|
+
const sepHoriz = useSep12 ? pipelines.sepHorizPx12 : pipelines.sepHoriz;
|
|
482
|
+
flood.setPipeline(sepHoriz);
|
|
483
|
+
flood.setBindGroup(0, device.createBindGroup({
|
|
484
|
+
layout: layouts ? layouts.sepHorizGroup : sepHoriz.getBindGroupLayout(0),
|
|
485
|
+
entries: [
|
|
486
|
+
{
|
|
487
|
+
binding: 0,
|
|
488
|
+
resource: paramsBinding
|
|
489
|
+
},
|
|
490
|
+
{
|
|
491
|
+
binding: 1,
|
|
492
|
+
resource: uploadView
|
|
493
|
+
},
|
|
494
|
+
{
|
|
495
|
+
binding: 2,
|
|
496
|
+
resource: {
|
|
497
|
+
buffer: seed,
|
|
498
|
+
offset: 0,
|
|
499
|
+
size: seedBytes
|
|
500
|
+
}
|
|
174
501
|
}
|
|
175
|
-
|
|
502
|
+
]
|
|
503
|
+
}));
|
|
504
|
+
flood.dispatchWorkgroups(Math.ceil(width / 64), useSep12 ? Math.ceil(height / 4) : height);
|
|
505
|
+
const sepVert = useSep12 ? pipelines.sepVertPx12 ?? pipelines.sepVertStore : pipelines.sepVertStore;
|
|
506
|
+
if (pipelines.directStore && sepVert) {
|
|
176
507
|
const finalView = output.createView({ mipLevelCount: 1 });
|
|
177
|
-
flood.setPipeline(
|
|
508
|
+
flood.setPipeline(sepVert);
|
|
178
509
|
flood.setBindGroup(0, device.createBindGroup({
|
|
179
|
-
layout:
|
|
510
|
+
layout: layouts ? layouts.sepVertStoreGroup : sepVert.getBindGroupLayout(0),
|
|
180
511
|
entries: [
|
|
181
512
|
{
|
|
182
513
|
binding: 0,
|
|
183
|
-
resource:
|
|
184
|
-
buffer: params,
|
|
185
|
-
offset: steps.length * 256,
|
|
186
|
-
size: 16
|
|
187
|
-
}
|
|
514
|
+
resource: paramsBinding
|
|
188
515
|
},
|
|
189
516
|
{
|
|
190
517
|
binding: 1,
|
|
191
|
-
resource: {
|
|
518
|
+
resource: {
|
|
519
|
+
buffer: seed,
|
|
520
|
+
offset: 0,
|
|
521
|
+
size: seedBytes
|
|
522
|
+
}
|
|
192
523
|
},
|
|
193
524
|
{
|
|
194
525
|
binding: 2,
|
|
@@ -199,12 +530,6 @@ function encodeJfaWork(device, encoder, pipelines, canvas, width, height, pxRang
|
|
|
199
530
|
flood.dispatchWorkgroups(groupsX, groupsY);
|
|
200
531
|
flood.end();
|
|
201
532
|
} else {
|
|
202
|
-
flood.setPipeline(jumpPipeline);
|
|
203
|
-
steps.forEach((_, index) => {
|
|
204
|
-
const into = seeds[(index + 1) % 2];
|
|
205
|
-
flood.setBindGroup(0, bind(jumpPipeline, (index + 1) * 256, seeds[index % 2], into));
|
|
206
|
-
flood.dispatchWorkgroups(groupsX, groupsY);
|
|
207
|
-
});
|
|
208
533
|
flood.end();
|
|
209
534
|
const resolve = encoder.beginRenderPass({ colorAttachments: [{
|
|
210
535
|
view: output.createView({ mipLevelCount: 1 }),
|
|
@@ -212,12 +537,309 @@ function encodeJfaWork(device, encoder, pipelines, canvas, width, height, pxRang
|
|
|
212
537
|
storeOp: "store"
|
|
213
538
|
}] });
|
|
214
539
|
resolve.setPipeline(pipelines.resolve);
|
|
215
|
-
resolve.setBindGroup(0,
|
|
540
|
+
resolve.setBindGroup(0, device.createBindGroup({
|
|
541
|
+
layout: layouts ? layouts.resolveGroup : pipelines.resolve.getBindGroupLayout(0),
|
|
542
|
+
entries: [{
|
|
543
|
+
binding: 0,
|
|
544
|
+
resource: paramsBinding
|
|
545
|
+
}, {
|
|
546
|
+
binding: 1,
|
|
547
|
+
resource: {
|
|
548
|
+
buffer: seed,
|
|
549
|
+
offset: 0,
|
|
550
|
+
size: seedBytes
|
|
551
|
+
}
|
|
552
|
+
}]
|
|
553
|
+
}));
|
|
216
554
|
resolve.draw(3);
|
|
217
555
|
resolve.end();
|
|
218
556
|
}
|
|
219
557
|
return upload;
|
|
220
558
|
}
|
|
221
|
-
|
|
559
|
+
var COLOR_BLEED_STATE_KEY = Symbol.for("ultra-text.gpuColorBleed");
|
|
560
|
+
function colorBleedState() {
|
|
561
|
+
const g = globalThis;
|
|
562
|
+
return g[COLOR_BLEED_STATE_KEY] ??= {
|
|
563
|
+
bleeds: /* @__PURE__ */ new WeakMap(),
|
|
564
|
+
ready: /* @__PURE__ */ new WeakMap()
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
function registerDeferredColorBleed(data, entry) {
|
|
568
|
+
colorBleedState().bleeds.set(data, entry);
|
|
569
|
+
}
|
|
570
|
+
function peekDeferredColorBleed(data) {
|
|
571
|
+
return colorBleedState().bleeds.get(data);
|
|
572
|
+
}
|
|
573
|
+
function takeDeferredColorBleed(data) {
|
|
574
|
+
const { bleeds } = colorBleedState();
|
|
575
|
+
const entry = bleeds.get(data);
|
|
576
|
+
if (entry) bleeds.delete(data);
|
|
577
|
+
return entry;
|
|
578
|
+
}
|
|
579
|
+
function flushDeferredColorBleed(data) {
|
|
580
|
+
takeDeferredColorBleed(data)?.applyCpu();
|
|
581
|
+
}
|
|
582
|
+
function putReadyGpuColorTexture(data, texture) {
|
|
583
|
+
colorBleedState().ready.set(data, texture);
|
|
584
|
+
}
|
|
585
|
+
function takeReadyGpuColorTexture(data) {
|
|
586
|
+
const { ready } = colorBleedState();
|
|
587
|
+
const tex = ready.get(data);
|
|
588
|
+
if (tex) ready.delete(data);
|
|
589
|
+
return tex;
|
|
590
|
+
}
|
|
591
|
+
var bleedPipelineCache = /* @__PURE__ */ new WeakMap();
|
|
592
|
+
function getBleedPipelines(device) {
|
|
593
|
+
const existing = bleedPipelineCache.get(device);
|
|
594
|
+
if (existing) return existing;
|
|
595
|
+
const module = device.createShaderModule({
|
|
596
|
+
label: "ultra-text color bleed",
|
|
597
|
+
code: COLOR_BLEED_WGSL
|
|
598
|
+
});
|
|
599
|
+
let classifyLayout = "auto";
|
|
600
|
+
let horizLayout = "auto";
|
|
601
|
+
let resolveLayout = "auto";
|
|
602
|
+
let classifyPipeLayout = "auto";
|
|
603
|
+
let horizPipeLayout = "auto";
|
|
604
|
+
let resolvePipeLayout = "auto";
|
|
605
|
+
if (typeof device.createBindGroupLayout === "function" && typeof device.createPipelineLayout === "function") {
|
|
606
|
+
const COMPUTE = 4;
|
|
607
|
+
const FRAGMENT = 2;
|
|
608
|
+
const u = (vis) => ({
|
|
609
|
+
binding: 0,
|
|
610
|
+
visibility: vis,
|
|
611
|
+
buffer: {
|
|
612
|
+
type: "uniform",
|
|
613
|
+
minBindingSize: 16
|
|
614
|
+
}
|
|
615
|
+
});
|
|
616
|
+
const tex = (binding) => ({
|
|
617
|
+
binding,
|
|
618
|
+
visibility: COMPUTE,
|
|
619
|
+
texture: {
|
|
620
|
+
sampleType: "unfilterable-float",
|
|
621
|
+
viewDimension: "2d"
|
|
622
|
+
}
|
|
623
|
+
});
|
|
624
|
+
classifyLayout = device.createBindGroupLayout({ entries: [
|
|
625
|
+
u(COMPUTE),
|
|
626
|
+
tex(1),
|
|
627
|
+
tex(2),
|
|
628
|
+
{
|
|
629
|
+
binding: 3,
|
|
630
|
+
visibility: COMPUTE,
|
|
631
|
+
buffer: { type: "storage" }
|
|
632
|
+
}
|
|
633
|
+
] });
|
|
634
|
+
classifyPipeLayout = device.createPipelineLayout({ bindGroupLayouts: [classifyLayout] });
|
|
635
|
+
horizLayout = device.createBindGroupLayout({ entries: [
|
|
636
|
+
u(COMPUTE),
|
|
637
|
+
{
|
|
638
|
+
binding: 3,
|
|
639
|
+
visibility: COMPUTE,
|
|
640
|
+
buffer: { type: "storage" }
|
|
641
|
+
},
|
|
642
|
+
{
|
|
643
|
+
binding: 4,
|
|
644
|
+
visibility: COMPUTE,
|
|
645
|
+
buffer: { type: "storage" }
|
|
646
|
+
}
|
|
647
|
+
] });
|
|
648
|
+
horizPipeLayout = device.createPipelineLayout({ bindGroupLayouts: [horizLayout] });
|
|
649
|
+
resolveLayout = device.createBindGroupLayout({ entries: [
|
|
650
|
+
u(FRAGMENT),
|
|
651
|
+
{
|
|
652
|
+
binding: 5,
|
|
653
|
+
visibility: FRAGMENT,
|
|
654
|
+
buffer: { type: "read-only-storage" }
|
|
655
|
+
},
|
|
656
|
+
{
|
|
657
|
+
binding: 6,
|
|
658
|
+
visibility: FRAGMENT,
|
|
659
|
+
buffer: { type: "read-only-storage" }
|
|
660
|
+
}
|
|
661
|
+
] });
|
|
662
|
+
resolvePipeLayout = device.createPipelineLayout({ bindGroupLayouts: [resolveLayout] });
|
|
663
|
+
}
|
|
664
|
+
const classify = device.createComputePipeline({
|
|
665
|
+
layout: classifyPipeLayout,
|
|
666
|
+
compute: {
|
|
667
|
+
module,
|
|
668
|
+
entryPoint: "classifyMain"
|
|
669
|
+
}
|
|
670
|
+
});
|
|
671
|
+
const horiz = device.createComputePipeline({
|
|
672
|
+
layout: horizPipeLayout,
|
|
673
|
+
compute: {
|
|
674
|
+
module,
|
|
675
|
+
entryPoint: "horizMain"
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
const resolve = device.createRenderPipeline({
|
|
679
|
+
layout: resolvePipeLayout,
|
|
680
|
+
vertex: {
|
|
681
|
+
module,
|
|
682
|
+
entryPoint: "bleedVert"
|
|
683
|
+
},
|
|
684
|
+
fragment: {
|
|
685
|
+
module,
|
|
686
|
+
entryPoint: "bleedResolveFrag",
|
|
687
|
+
targets: [{ format: "rgba8unorm-srgb" }]
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
const built = {
|
|
691
|
+
classify,
|
|
692
|
+
horiz,
|
|
693
|
+
resolve,
|
|
694
|
+
classifyLayout: classifyLayout === "auto" ? classify.getBindGroupLayout(0) : classifyLayout,
|
|
695
|
+
horizLayout: horizLayout === "auto" ? horiz.getBindGroupLayout(0) : horizLayout,
|
|
696
|
+
resolveLayout: resolveLayout === "auto" ? resolve.getBindGroupLayout(0) : resolveLayout
|
|
697
|
+
};
|
|
698
|
+
bleedPipelineCache.set(device, built);
|
|
699
|
+
return built;
|
|
700
|
+
}
|
|
701
|
+
function encodeGpuColorBleed(device, encoder, bleed, mipLevelCount, pool = getDeviceGpuPool(device)) {
|
|
702
|
+
const { width, height, pxRange, white, black } = bleed;
|
|
703
|
+
const globals = globalThis;
|
|
704
|
+
const bufUsage = globals.GPUBufferUsage ?? {
|
|
705
|
+
COPY_DST: 8,
|
|
706
|
+
UNIFORM: 64,
|
|
707
|
+
STORAGE: 128
|
|
708
|
+
};
|
|
709
|
+
const texUsage = globals.GPUTextureUsage ?? {
|
|
710
|
+
COPY_SRC: 1,
|
|
711
|
+
COPY_DST: 2,
|
|
712
|
+
TEXTURE_BINDING: 4,
|
|
713
|
+
RENDER_ATTACHMENT: 16
|
|
714
|
+
};
|
|
715
|
+
const transient = [];
|
|
716
|
+
const pipes = getBleedPipelines(device);
|
|
717
|
+
const wTex = pool.uploadTexture(width, height, "rgba8unorm", texUsage.TEXTURE_BINDING | texUsage.COPY_DST);
|
|
718
|
+
transient.push(wTex);
|
|
719
|
+
const bTex = pool.uploadTexture(width, height, "rgba8unorm", texUsage.TEXTURE_BINDING | texUsage.COPY_DST);
|
|
720
|
+
transient.push(bTex);
|
|
721
|
+
const bytes = width * height * 4;
|
|
722
|
+
const rawBuf = pool.buffer(bytes, bufUsage.STORAGE);
|
|
723
|
+
transient.push(rawBuf);
|
|
724
|
+
const hSeedBuf = pool.buffer(bytes, bufUsage.STORAGE);
|
|
725
|
+
transient.push(hSeedBuf);
|
|
726
|
+
const slot = pool.ringAlloc(16, bufUsage.UNIFORM | bufUsage.COPY_DST);
|
|
727
|
+
const radius = Math.max(pxRange * 2, 32);
|
|
728
|
+
device.queue.writeBuffer(slot.buffer, slot.offset, new Uint32Array([
|
|
729
|
+
width,
|
|
730
|
+
height,
|
|
731
|
+
radius,
|
|
732
|
+
0
|
|
733
|
+
]));
|
|
734
|
+
device.queue.writeTexture({ texture: wTex }, white, {
|
|
735
|
+
offset: 0,
|
|
736
|
+
bytesPerRow: width * 4,
|
|
737
|
+
rowsPerImage: height
|
|
738
|
+
}, [width, height]);
|
|
739
|
+
device.queue.writeTexture({ texture: bTex }, black, {
|
|
740
|
+
offset: 0,
|
|
741
|
+
bytesPerRow: width * 4,
|
|
742
|
+
rowsPerImage: height
|
|
743
|
+
}, [width, height]);
|
|
744
|
+
const texture = device.createTexture({
|
|
745
|
+
size: [width, height],
|
|
746
|
+
mipLevelCount,
|
|
747
|
+
format: "rgba8unorm-srgb",
|
|
748
|
+
usage: texUsage.TEXTURE_BINDING | texUsage.COPY_DST | texUsage.COPY_SRC | texUsage.RENDER_ATTACHMENT
|
|
749
|
+
});
|
|
750
|
+
const pBind = {
|
|
751
|
+
buffer: slot.buffer,
|
|
752
|
+
offset: slot.offset,
|
|
753
|
+
size: 16
|
|
754
|
+
};
|
|
755
|
+
const rawBind = {
|
|
756
|
+
buffer: rawBuf,
|
|
757
|
+
offset: 0,
|
|
758
|
+
size: bytes
|
|
759
|
+
};
|
|
760
|
+
const seedBind = {
|
|
761
|
+
buffer: hSeedBuf,
|
|
762
|
+
offset: 0,
|
|
763
|
+
size: bytes
|
|
764
|
+
};
|
|
765
|
+
const comp = encoder.beginComputePass();
|
|
766
|
+
const gx = Math.ceil(width / 64);
|
|
767
|
+
comp.setPipeline(pipes.classify);
|
|
768
|
+
comp.setBindGroup(0, device.createBindGroup({
|
|
769
|
+
layout: pipes.classifyLayout,
|
|
770
|
+
entries: [
|
|
771
|
+
{
|
|
772
|
+
binding: 0,
|
|
773
|
+
resource: pBind
|
|
774
|
+
},
|
|
775
|
+
{
|
|
776
|
+
binding: 1,
|
|
777
|
+
resource: wTex.createView()
|
|
778
|
+
},
|
|
779
|
+
{
|
|
780
|
+
binding: 2,
|
|
781
|
+
resource: bTex.createView()
|
|
782
|
+
},
|
|
783
|
+
{
|
|
784
|
+
binding: 3,
|
|
785
|
+
resource: rawBind
|
|
786
|
+
}
|
|
787
|
+
]
|
|
788
|
+
}));
|
|
789
|
+
comp.dispatchWorkgroups(gx, height);
|
|
790
|
+
comp.setPipeline(pipes.horiz);
|
|
791
|
+
comp.setBindGroup(0, device.createBindGroup({
|
|
792
|
+
layout: pipes.horizLayout,
|
|
793
|
+
entries: [
|
|
794
|
+
{
|
|
795
|
+
binding: 0,
|
|
796
|
+
resource: pBind
|
|
797
|
+
},
|
|
798
|
+
{
|
|
799
|
+
binding: 3,
|
|
800
|
+
resource: rawBind
|
|
801
|
+
},
|
|
802
|
+
{
|
|
803
|
+
binding: 4,
|
|
804
|
+
resource: seedBind
|
|
805
|
+
}
|
|
806
|
+
]
|
|
807
|
+
}));
|
|
808
|
+
comp.dispatchWorkgroups(gx, height);
|
|
809
|
+
comp.end();
|
|
810
|
+
const ren = encoder.beginRenderPass({ colorAttachments: [{
|
|
811
|
+
view: texture.createView({
|
|
812
|
+
baseMipLevel: 0,
|
|
813
|
+
mipLevelCount: 1
|
|
814
|
+
}),
|
|
815
|
+
loadOp: "clear",
|
|
816
|
+
storeOp: "store"
|
|
817
|
+
}] });
|
|
818
|
+
ren.setPipeline(pipes.resolve);
|
|
819
|
+
ren.setBindGroup(0, device.createBindGroup({
|
|
820
|
+
layout: pipes.resolveLayout,
|
|
821
|
+
entries: [
|
|
822
|
+
{
|
|
823
|
+
binding: 0,
|
|
824
|
+
resource: pBind
|
|
825
|
+
},
|
|
826
|
+
{
|
|
827
|
+
binding: 5,
|
|
828
|
+
resource: rawBind
|
|
829
|
+
},
|
|
830
|
+
{
|
|
831
|
+
binding: 6,
|
|
832
|
+
resource: seedBind
|
|
833
|
+
}
|
|
834
|
+
]
|
|
835
|
+
}));
|
|
836
|
+
ren.draw(3);
|
|
837
|
+
ren.end();
|
|
838
|
+
return {
|
|
839
|
+
texture,
|
|
840
|
+
transient
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
export { POOL_IDLE_TRIM_MS, POOL_RING_BYTES, TILED_MAX_TEXELS, checkCommonAtlasLimits, createGpuPool, edtRadius, encodeGpuColorBleed, encodeJfaWork, flushDeferredColorBleed, getDeviceGpuPool, getJfaLayouts, openErrorScopes, peekDeferredColorBleed, poolSizeClass, putReadyGpuColorTexture, registerDeferredColorBleed, selectAtlasMode, selectWorkgroupDimension, storageBufferFits, supportsDirectStore, takeDeferredColorBleed, takeReadyGpuColorTexture };
|
|
222
844
|
|
|
223
845
|
//# sourceMappingURL=gpuCommon.js.map
|