ultra-text 1.0.0 → 1.0.1
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 +168 -85
- package/THIRD_PARTY_NOTICES.md +3 -0
- package/dist/assets/{cpuSdf.worker-Du9o8q4p.js → cpuSdf.worker-xS57yQbP.js} +13 -11
- package/dist/assets/cpuSdf.worker-xS57yQbP.js.map +1 -0
- package/dist/atlas/appendAtlas.js +2 -1
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +3 -14
- package/dist/atlas/buildAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.js +12 -10
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.js +1 -1
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.d.ts +7 -6
- package/dist/atlas/gpuAtlas.js +280 -145
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/jfaWgsl.js +201 -73
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.d.ts +2 -0
- package/dist/atlas/rasterize.js +2 -87
- package/dist/atlas/rasterize.js.map +1 -1
- package/dist/dom/DomSdf.js +66 -15
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.d.ts +26 -0
- package/dist/dom/DomSlug.js +640 -0
- package/dist/dom/DomSlug.js.map +1 -0
- package/dist/dom/SlugText.d.ts +18 -0
- package/dist/dom/SlugText.js +94 -0
- package/dist/dom/SlugText.js.map +1 -0
- package/dist/dom/Text.js +4 -67
- package/dist/dom/Text.js.map +1 -1
- package/dist/dom/fontCanvas.d.ts +2 -0
- package/dist/dom/fontCanvas.js +101 -0
- package/dist/dom/fontCanvas.js.map +1 -0
- package/dist/dom/layoutSignature.js +29 -2
- package/dist/dom/layoutSignature.js.map +1 -1
- package/dist/dom/snapshot.js +251 -96
- package/dist/dom/snapshot.js.map +1 -1
- package/dist/dom/textHost.d.ts +11 -0
- package/dist/dom/textHost.js +68 -0
- package/dist/dom/textHost.js.map +1 -0
- package/dist/slug/SlugMaterial.d.ts +3 -2
- package/dist/slug/SlugMaterial.js +28 -2
- package/dist/slug/SlugMaterial.js.map +1 -1
- package/dist/slug/coverage.d.ts +1 -1
- package/dist/slug/coverage.js +1 -1
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +1 -2
- package/dist/slug/preprocessCore.js +39 -16
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.js +6 -4
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.d.ts +39 -0
- package/dist/slug/standaloneRuntime.js +140 -0
- package/dist/slug/standaloneRuntime.js.map +1 -0
- package/dist/slug/truetype.d.ts +22 -0
- package/dist/slug/truetype.js +494 -0
- package/dist/slug/truetype.js.map +1 -0
- package/dist/slug-vanilla.d.ts +364 -0
- package/dist/slug-vanilla.js +1461 -0
- package/dist/slug-vanilla.js.map +1 -0
- package/dist/slug.d.ts +21 -0
- package/dist/slug.js +19 -0
- package/dist/text/GlyphTextMaterial.d.ts +11 -11
- package/dist/text/GlyphTextMaterial.js +98 -29
- package/dist/text/GlyphTextMaterial.js.map +1 -1
- package/dist/text/SdfTextMaterial.d.ts +5 -4
- package/dist/text/SdfTextMaterial.js +22 -4
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/types.d.ts +63 -14
- package/dist/vanilla.d.ts +3 -0
- package/dist/vanilla.js +132 -59
- package/dist/vanilla.js.map +1 -1
- package/dist/windfoil/WindfoilMaterial.d.ts +2 -1
- package/dist/windfoil/WindfoilMaterial.js +8 -1
- package/dist/windfoil/WindfoilMaterial.js.map +1 -1
- package/dist/windfoil/abortable.d.ts +2 -0
- package/dist/windfoil/abortable.js +26 -0
- package/dist/windfoil/abortable.js.map +1 -0
- package/dist/windfoil/color.js +2 -1
- package/dist/windfoil/color.js.map +1 -1
- package/dist/windfoil/coverage.d.ts +3 -20
- package/dist/windfoil/coverage.js +7 -20
- package/dist/windfoil/coverage.js.map +1 -1
- package/dist/windfoil/emoji.js +1 -1
- package/dist/windfoil/emoji.js.map +1 -1
- package/dist/windfoil/emojiMetrics.js +1 -1
- package/dist/windfoil/emojiMetrics.js.map +1 -1
- package/dist/windfoil/geometry.js +100 -33
- package/dist/windfoil/geometry.js.map +1 -1
- package/dist/windfoil/layerGrid.js +14 -10
- package/dist/windfoil/layerGrid.js.map +1 -1
- package/dist/windfoil/layerNormalization.d.ts +1 -1
- package/dist/windfoil/layerNormalization.js +1 -1
- package/dist/windfoil/layerNormalization.js.map +1 -1
- package/dist/windfoil/outlineValidation.d.ts +86 -0
- package/dist/windfoil/outlineValidation.js +65 -0
- package/dist/windfoil/outlineValidation.js.map +1 -0
- package/dist/windfoil/preprocess.js +3 -2
- package/dist/windfoil/preprocess.js.map +1 -1
- package/dist/windfoil/preprocessCore.d.ts +4 -85
- package/dist/windfoil/preprocessCore.js +210 -206
- package/dist/windfoil/preprocessCore.js.map +1 -1
- package/dist/windfoil/requests.js +1 -1
- package/dist/windfoil/requests.js.map +1 -1
- package/dist/windfoil/runtime.d.ts +2 -1
- package/dist/windfoil/runtime.js +3 -2
- package/dist/windfoil/runtime.js.map +1 -1
- package/dist/windfoil/shapeResources.js +2 -1
- package/dist/windfoil/shapeResources.js.map +1 -1
- package/dist/windfoil/shapes.js +1 -1
- package/dist/windfoil/skirt.d.ts +22 -0
- package/dist/windfoil/skirt.js +20 -0
- package/dist/windfoil/skirt.js.map +1 -0
- package/dist/windfoil/storage.d.ts +2 -2
- package/dist/windfoil/storage.js +1 -22
- package/dist/windfoil/storage.js.map +1 -1
- package/dist/windfoil/trace/contours.d.ts +0 -5
- package/dist/windfoil/trace/contours.js +81 -114
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.d.ts +0 -6
- package/dist/windfoil/trace/fit.js +304 -308
- package/dist/windfoil/trace/fit.js.map +1 -1
- package/dist/windfoil/trace/outline.js +10 -10
- package/dist/windfoil/trace/outline.js.map +1 -1
- package/dist/windfoil/trace/types.d.ts +5 -3
- package/dist/windfoil/tracedOutlines.d.ts +37 -1
- package/dist/windfoil/tracedOutlines.js +172 -33
- package/dist/windfoil/tracedOutlines.js.map +1 -1
- package/package.json +57 -8
- package/skills/ultra-text/SKILL.md +114 -0
- package/skills/ultra-text/references/frameworks.md +43 -0
- package/skills/ultra-text/references/three-tsl.md +78 -0
- package/skills/ultra-text/references/vanilla-webgpu.md +95 -0
- package/dist/assets/cpuSdf.worker-Du9o8q4p.js.map +0 -1
package/dist/vanilla.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isColorCandidate
|
|
1
|
+
import { MIP_WGSL, buildJfaWgsl } from "./atlas/jfaWgsl.js";
|
|
2
|
+
import { isColorCandidate } from "./dom/fontCanvas.js";
|
|
3
|
+
import { rasterizeGlyphAtlas } from "./atlas/rasterize.js";
|
|
3
4
|
import { backdropCurve, resolveDomTextTone, resolveTextTone, srgbEncode, toneCoverage, toneLightness } from "./dom/tone.js";
|
|
4
5
|
import { reflowSnapshot, snapGlyph } from "./text/reflow.js";
|
|
5
6
|
import { collectDomSnapshot } from "./dom/snapshot.js";
|
|
@@ -28,26 +29,43 @@ function jfaSteps(pxRange) {
|
|
|
28
29
|
}
|
|
29
30
|
return steps;
|
|
30
31
|
}
|
|
31
|
-
var
|
|
32
|
+
var MIN_WORKGROUP_DIMENSION = 8;
|
|
33
|
+
var CORE_WORKGROUP_DIMENSION = 16;
|
|
34
|
+
var SEED_BYTES_PER_TEXEL = 4;
|
|
32
35
|
var ERROR_FILTERS = [
|
|
33
36
|
"validation",
|
|
34
37
|
"out-of-memory",
|
|
35
38
|
"internal"
|
|
36
39
|
];
|
|
37
|
-
function
|
|
40
|
+
function selectVanillaWorkgroupDimension(limits) {
|
|
41
|
+
const inv = limits?.maxComputeInvocationsPerWorkgroup ?? 256;
|
|
42
|
+
const wx = limits?.maxComputeWorkgroupSizeX ?? 256;
|
|
43
|
+
const wy = limits?.maxComputeWorkgroupSizeY ?? 256;
|
|
44
|
+
return inv >= CORE_WORKGROUP_DIMENSION ** 2 && wx >= CORE_WORKGROUP_DIMENSION && wy >= CORE_WORKGROUP_DIMENSION ? CORE_WORKGROUP_DIMENSION : MIN_WORKGROUP_DIMENSION;
|
|
45
|
+
}
|
|
46
|
+
function supportsVanillaDirectStore(device) {
|
|
47
|
+
const textures = texUsageOf();
|
|
48
|
+
return typeof textures.STORAGE_BINDING === "number" && textures.STORAGE_BINDING > 0 && Boolean(device.features?.has("texture-formats-tier1"));
|
|
49
|
+
}
|
|
50
|
+
function checkVanillaAtlasLimits(limits, width, height, maxStep, directStore) {
|
|
51
|
+
if (maxStep > 64) throw new RangeError("buildVanillaGpuSdfAtlas: pxRange exceeds fixed-point jump range");
|
|
52
|
+
if (!limits) return;
|
|
38
53
|
for (const [name, need] of [
|
|
39
|
-
["maxComputeInvocationsPerWorkgroup",
|
|
40
|
-
["maxComputeWorkgroupSizeX",
|
|
41
|
-
["maxComputeWorkgroupSizeY",
|
|
42
|
-
["maxStorageBuffersPerShaderStage", 2]
|
|
43
|
-
["maxStorageBuffersInFragmentStage", 1]
|
|
54
|
+
["maxComputeInvocationsPerWorkgroup", MIN_WORKGROUP_DIMENSION ** 2],
|
|
55
|
+
["maxComputeWorkgroupSizeX", MIN_WORKGROUP_DIMENSION],
|
|
56
|
+
["maxComputeWorkgroupSizeY", MIN_WORKGROUP_DIMENSION],
|
|
57
|
+
["maxStorageBuffersPerShaderStage", 2]
|
|
44
58
|
]) {
|
|
45
59
|
const value = limits[name];
|
|
46
60
|
if (typeof value === "number" && value < need) throw new RangeError(`buildVanillaGpuSdfAtlas: ${name}=${value}, needs ${need}`);
|
|
47
61
|
}
|
|
62
|
+
if (!directStore) {
|
|
63
|
+
const fragBuffers = limits.maxStorageBuffersInFragmentStage;
|
|
64
|
+
if (typeof fragBuffers === "number" && fragBuffers < 1) throw new RangeError(`buildVanillaGpuSdfAtlas: maxStorageBuffersInFragmentStage=${fragBuffers}, needs 1`);
|
|
65
|
+
}
|
|
48
66
|
const largest = limits.maxTextureDimension2D;
|
|
49
67
|
if (typeof largest === "number" && Math.max(width, height) > largest) throw new RangeError(`buildVanillaGpuSdfAtlas: ${width}×${height} exceeds maxTextureDimension2D=${largest}`);
|
|
50
|
-
const bytes = Math.max(width * height *
|
|
68
|
+
const bytes = Math.max(width * height * SEED_BYTES_PER_TEXEL, rasterRowBytes(width) * height);
|
|
51
69
|
if (bytes > limits.maxStorageBufferBindingSize || bytes > limits.maxBufferSize) throw new RangeError(`buildVanillaGpuSdfAtlas: ${width}×${height} exceeds storage-buffer limits`);
|
|
52
70
|
}
|
|
53
71
|
function openVanillaErrorScopes(device) {
|
|
@@ -63,9 +81,11 @@ function openVanillaErrorScopes(device) {
|
|
|
63
81
|
}
|
|
64
82
|
var devicePipelines = /* @__PURE__ */ new WeakMap();
|
|
65
83
|
function getDevicePipelines(device) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
84
|
+
const directStore = supportsVanillaDirectStore(device);
|
|
85
|
+
const workgroupDim = selectVanillaWorkgroupDimension(device.limits);
|
|
86
|
+
const cached = devicePipelines.get(device);
|
|
87
|
+
if (cached?.directStore === directStore && cached.workgroupDim === workgroupDim) return cached;
|
|
88
|
+
const module = device.createShaderModule({ code: buildJfaWgsl(workgroupDim, directStore) + MIP_WGSL });
|
|
69
89
|
const compute = (entryPoint) => device.createComputePipeline({
|
|
70
90
|
layout: "auto",
|
|
71
91
|
compute: {
|
|
@@ -85,19 +105,22 @@ function getDevicePipelines(device) {
|
|
|
85
105
|
targets: [{ format }]
|
|
86
106
|
}
|
|
87
107
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
108
|
+
const next = {
|
|
109
|
+
workgroupDim,
|
|
110
|
+
directStore,
|
|
111
|
+
seed: compute("seedMain"),
|
|
112
|
+
jump: compute("jumpMain"),
|
|
113
|
+
jumpStore: directStore ? compute("jumpStoreMain") : null,
|
|
114
|
+
resolve: directStore ? null : render("fullscreenVert", "resolveFrag", "r8unorm"),
|
|
115
|
+
mipR8: render("mipVert", "mipFrag", "r8unorm"),
|
|
116
|
+
mipRgba: render("mipVert", "mipFrag", "rgba8unorm-srgb"),
|
|
117
|
+
sampler: device.createSampler({
|
|
95
118
|
minFilter: "linear",
|
|
96
119
|
magFilter: "linear"
|
|
97
120
|
})
|
|
98
|
-
|
|
99
|
-
devicePipelines.set(device,
|
|
100
|
-
return
|
|
121
|
+
};
|
|
122
|
+
devicePipelines.set(device, next);
|
|
123
|
+
return next;
|
|
101
124
|
}
|
|
102
125
|
function encodeMipmapChain(device, encoder, texture, mipLevelCount, pipeline, sampler) {
|
|
103
126
|
const view = (baseMipLevel) => texture.createView({
|
|
@@ -135,6 +158,7 @@ var DEFAULT_TEX_USAGE = {
|
|
|
135
158
|
COPY_SRC: 1,
|
|
136
159
|
COPY_DST: 2,
|
|
137
160
|
TEXTURE_BINDING: 4,
|
|
161
|
+
STORAGE_BINDING: 8,
|
|
138
162
|
RENDER_ATTACHMENT: 16
|
|
139
163
|
};
|
|
140
164
|
var texUsageOf = () => globalThis.GPUTextureUsage ?? DEFAULT_TEX_USAGE;
|
|
@@ -160,7 +184,7 @@ function createGpuColorLayer(device, width, band, mipmaps) {
|
|
|
160
184
|
if (mipLevelCount > 1) {
|
|
161
185
|
const pipelines = getDevicePipelines(device);
|
|
162
186
|
const encoder = device.createCommandEncoder();
|
|
163
|
-
encodeMipmapChain(device, encoder, gpuTexture, mipLevelCount, pipelines
|
|
187
|
+
encodeMipmapChain(device, encoder, gpuTexture, mipLevelCount, pipelines.mipRgba, pipelines.sampler);
|
|
164
188
|
device.queue.submit([encoder.finish()]);
|
|
165
189
|
}
|
|
166
190
|
return {
|
|
@@ -174,12 +198,13 @@ function createGpuColorLayer(device, width, band, mipmaps) {
|
|
|
174
198
|
async function buildVanillaGpuSdfAtlas(device, raster, options = {}) {
|
|
175
199
|
options.signal?.throwIfAborted();
|
|
176
200
|
const { width, height } = raster;
|
|
177
|
-
|
|
201
|
+
const steps = jfaSteps(raster.pxRange);
|
|
202
|
+
const directStore = supportsVanillaDirectStore(device);
|
|
203
|
+
checkVanillaAtlasLimits(device.limits, width, height, steps[0], directStore);
|
|
178
204
|
const bufUsage = bufUsageOf();
|
|
179
205
|
const texUsage = texUsageOf();
|
|
180
206
|
const scopes = openVanillaErrorScopes(device);
|
|
181
207
|
const bytesPerRow = rasterRowBytes(width);
|
|
182
|
-
const steps = jfaSteps(raster.pxRange);
|
|
183
208
|
const mipmaps = options.mipmaps === true;
|
|
184
209
|
const mipLevelCount = mipCount(width, height, mipmaps);
|
|
185
210
|
let rasterTexture;
|
|
@@ -202,22 +227,27 @@ async function buildVanillaGpuSdfAtlas(device, raster, options = {}) {
|
|
|
202
227
|
usage: texUsage.COPY_SRC | texUsage.COPY_DST | texUsage.RENDER_ATTACHMENT
|
|
203
228
|
});
|
|
204
229
|
const rasterBuffer = makeBuf(bytesPerRow * height, bufUsage.STORAGE | bufUsage.COPY_DST);
|
|
205
|
-
const seedBytes = width * height *
|
|
230
|
+
const seedBytes = width * height * SEED_BYTES_PER_TEXEL;
|
|
206
231
|
const seedA = makeBuf(seedBytes, bufUsage.STORAGE);
|
|
207
232
|
const seedB = makeBuf(seedBytes, bufUsage.STORAGE);
|
|
208
233
|
const paramsBuffer = makeBuf(steps.length * 256 + 16, bufUsage.UNIFORM | bufUsage.COPY_DST);
|
|
209
234
|
const paramsInts = new Int32Array(steps.length * 64 + 4);
|
|
235
|
+
const invPxRange = 1 / raster.pxRange;
|
|
210
236
|
paramsInts.set([
|
|
211
237
|
width,
|
|
212
238
|
height,
|
|
213
239
|
bytesPerRow / 4
|
|
214
240
|
]);
|
|
215
|
-
new Float32Array(paramsInts.buffer, 12, 1)[0] =
|
|
216
|
-
steps.forEach((step, i) =>
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
241
|
+
new Float32Array(paramsInts.buffer, 12, 1)[0] = invPxRange;
|
|
242
|
+
steps.forEach((step, i) => {
|
|
243
|
+
const base = (i + 1) * 64;
|
|
244
|
+
paramsInts.set([
|
|
245
|
+
width,
|
|
246
|
+
height,
|
|
247
|
+
step
|
|
248
|
+
], base);
|
|
249
|
+
new Float32Array(paramsInts.buffer, base * 4 + 12, 1)[0] = invPxRange;
|
|
250
|
+
});
|
|
221
251
|
device.queue.writeBuffer(paramsBuffer, 0, paramsInts);
|
|
222
252
|
device.queue.copyExternalImageToTexture({
|
|
223
253
|
source: raster.canvas,
|
|
@@ -230,7 +260,7 @@ async function buildVanillaGpuSdfAtlas(device, raster, options = {}) {
|
|
|
230
260
|
size: [width, height],
|
|
231
261
|
mipLevelCount,
|
|
232
262
|
format: "r8unorm",
|
|
233
|
-
usage: texUsage.RENDER_ATTACHMENT | texUsage.TEXTURE_BINDING | texUsage.COPY_SRC
|
|
263
|
+
usage: texUsage.RENDER_ATTACHMENT | texUsage.TEXTURE_BINDING | texUsage.COPY_SRC | (pipelines.directStore ? texUsage.STORAGE_BINDING ?? 0 : 0)
|
|
234
264
|
});
|
|
235
265
|
const encoder = device.createCommandEncoder();
|
|
236
266
|
encoder.copyTextureToBuffer({ texture: rasterTexture }, {
|
|
@@ -238,8 +268,8 @@ async function buildVanillaGpuSdfAtlas(device, raster, options = {}) {
|
|
|
238
268
|
bytesPerRow,
|
|
239
269
|
rowsPerImage: height
|
|
240
270
|
}, [width, height]);
|
|
241
|
-
const groupsX = Math.ceil(width /
|
|
242
|
-
const groupsY = Math.ceil(height /
|
|
271
|
+
const groupsX = Math.ceil(width / pipelines.workgroupDim);
|
|
272
|
+
const groupsY = Math.ceil(height / pipelines.workgroupDim);
|
|
243
273
|
const bind = (pipeline, offset, ...bufs) => device.createBindGroup({
|
|
244
274
|
layout: pipeline.getBindGroupLayout(0),
|
|
245
275
|
entries: [{
|
|
@@ -255,33 +285,75 @@ async function buildVanillaGpuSdfAtlas(device, raster, options = {}) {
|
|
|
255
285
|
}))]
|
|
256
286
|
});
|
|
257
287
|
const computePass = encoder.beginComputePass();
|
|
258
|
-
computePass.setPipeline(pipelines
|
|
259
|
-
computePass.setBindGroup(0, bind(pipelines
|
|
288
|
+
computePass.setPipeline(pipelines.seed);
|
|
289
|
+
computePass.setBindGroup(0, bind(pipelines.seed, 0, rasterBuffer, seedA));
|
|
260
290
|
computePass.dispatchWorkgroups(groupsX, groupsY);
|
|
261
291
|
let currentIn = seedA;
|
|
262
292
|
let currentOut = seedB;
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
293
|
+
if (pipelines.directStore && pipelines.jumpStore) {
|
|
294
|
+
const midSteps = steps.length - 1;
|
|
295
|
+
if (midSteps > 0) {
|
|
296
|
+
computePass.setPipeline(pipelines.jump);
|
|
297
|
+
for (let i = 0; i < midSteps; i++) {
|
|
298
|
+
computePass.setBindGroup(0, bind(pipelines.jump, (i + 1) * 256, currentIn, currentOut));
|
|
299
|
+
computePass.dispatchWorkgroups(groupsX, groupsY);
|
|
300
|
+
const prev = currentIn;
|
|
301
|
+
currentIn = currentOut;
|
|
302
|
+
currentOut = prev;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
const level0View = outputTexture.createView({
|
|
274
306
|
baseMipLevel: 0,
|
|
275
307
|
mipLevelCount: 1
|
|
276
|
-
})
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
308
|
+
});
|
|
309
|
+
computePass.setPipeline(pipelines.jumpStore);
|
|
310
|
+
computePass.setBindGroup(0, device.createBindGroup({
|
|
311
|
+
layout: pipelines.jumpStore.getBindGroupLayout(0),
|
|
312
|
+
entries: [
|
|
313
|
+
{
|
|
314
|
+
binding: 0,
|
|
315
|
+
resource: {
|
|
316
|
+
buffer: paramsBuffer,
|
|
317
|
+
offset: steps.length * 256,
|
|
318
|
+
size: 16
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
binding: 1,
|
|
323
|
+
resource: { buffer: currentIn }
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
binding: 2,
|
|
327
|
+
resource: level0View
|
|
328
|
+
}
|
|
329
|
+
]
|
|
330
|
+
}));
|
|
331
|
+
computePass.dispatchWorkgroups(groupsX, groupsY);
|
|
332
|
+
computePass.end();
|
|
333
|
+
} else {
|
|
334
|
+
computePass.setPipeline(pipelines.jump);
|
|
335
|
+
for (let i = 0; i < steps.length; i++) {
|
|
336
|
+
computePass.setBindGroup(0, bind(pipelines.jump, (i + 1) * 256, currentIn, currentOut));
|
|
337
|
+
computePass.dispatchWorkgroups(groupsX, groupsY);
|
|
338
|
+
const prev = currentIn;
|
|
339
|
+
currentIn = currentOut;
|
|
340
|
+
currentOut = prev;
|
|
341
|
+
}
|
|
342
|
+
computePass.end();
|
|
343
|
+
const resolvePass = encoder.beginRenderPass({ colorAttachments: [{
|
|
344
|
+
view: outputTexture.createView({
|
|
345
|
+
baseMipLevel: 0,
|
|
346
|
+
mipLevelCount: 1
|
|
347
|
+
}),
|
|
348
|
+
loadOp: "clear",
|
|
349
|
+
storeOp: "store"
|
|
350
|
+
}] });
|
|
351
|
+
resolvePass.setPipeline(pipelines.resolve);
|
|
352
|
+
resolvePass.setBindGroup(0, bind(pipelines.resolve, 0, currentIn));
|
|
353
|
+
resolvePass.draw(3);
|
|
354
|
+
resolvePass.end();
|
|
355
|
+
}
|
|
356
|
+
if (mipLevelCount > 1) encodeMipmapChain(device, encoder, outputTexture, mipLevelCount, pipelines.mipR8, pipelines.sampler);
|
|
285
357
|
device.queue.submit([encoder.finish()]);
|
|
286
358
|
} catch (error) {
|
|
287
359
|
scopes.close();
|
|
@@ -294,6 +366,7 @@ async function buildVanillaGpuSdfAtlas(device, raster, options = {}) {
|
|
|
294
366
|
const rejection = await scopes.close();
|
|
295
367
|
for (const b of transient) b.destroy();
|
|
296
368
|
if (rejection !== null) {
|
|
369
|
+
devicePipelines.delete(device);
|
|
297
370
|
outputTexture.destroy();
|
|
298
371
|
throw new Error(`buildVanillaGpuSdfAtlas: the device rejected the atlas passes: ${rejection}`);
|
|
299
372
|
}
|
|
@@ -369,7 +442,7 @@ async function buildVanillaCpuSdfAtlas(raster, options = {}) {
|
|
|
369
442
|
if (mipLevelCount > 1) {
|
|
370
443
|
const pipelines = getDevicePipelines(device);
|
|
371
444
|
const encoder = device.createCommandEncoder();
|
|
372
|
-
encodeMipmapChain(device, encoder, gpuTexture, mipLevelCount, pipelines
|
|
445
|
+
encodeMipmapChain(device, encoder, gpuTexture, mipLevelCount, pipelines.mipR8, pipelines.sampler);
|
|
373
446
|
device.queue.submit([encoder.finish()]);
|
|
374
447
|
}
|
|
375
448
|
if (raster.colorBand) colorLayer = createGpuColorLayer(device, raster.width, raster.colorBand, mipmaps);
|