ultra-text 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +267 -962
- package/THIRD_PARTY_NOTICES.md +3 -0
- package/dist/assets/{cpuSdf.worker-Du9o8q4p.js → cpuSdf.worker--X1Qpmdp.js} +148 -57
- package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +1 -0
- package/dist/atlas/appendAtlas.js +69 -26
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +5 -15
- package/dist/atlas/buildAtlas.js.map +1 -1
- package/dist/atlas/cpuAtlas.d.ts +4 -1
- package/dist/atlas/cpuAtlas.js +8 -6
- package/dist/atlas/cpuAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.js +164 -50
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.d.ts +5 -3
- package/dist/atlas/cpuWorker.js +119 -12
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.d.ts +7 -6
- package/dist/atlas/gpuAtlas.js +206 -247
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/gpuCommon.d.ts +135 -0
- package/dist/atlas/gpuCommon.js +223 -0
- package/dist/atlas/gpuCommon.js.map +1 -0
- package/dist/atlas/jfaWgsl.js +59 -125
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.d.ts +2 -0
- package/dist/atlas/rasterize.js +104 -144
- package/dist/atlas/rasterize.js.map +1 -1
- package/dist/atlas/shapeRaster.js +2 -1
- package/dist/atlas/shapeRaster.js.map +1 -1
- package/dist/atlas/vanillaBounds.d.ts +64 -0
- package/dist/atlas/vanillaBounds.js +42 -0
- package/dist/atlas/vanillaBounds.js.map +1 -0
- package/dist/atlas/vanillaCore.d.ts +100 -0
- package/dist/atlas/vanillaCore.js +1012 -0
- package/dist/atlas/vanillaCore.js.map +1 -0
- package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
- package/dist/atlas/vanillaCpuAtlas.js +87 -0
- package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
- package/dist/atlas/vanillaExtras.d.ts +8 -0
- package/dist/atlas/vanillaExtras.js +166 -0
- package/dist/atlas/vanillaExtras.js.map +1 -0
- package/dist/atlas/vanillaGpuHelpers.d.ts +232 -0
- package/dist/atlas/vanillaGpuHelpers.js +119 -0
- package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
- package/dist/dom/DomSdf.js +263 -272
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.d.ts +26 -0
- package/dist/dom/DomSlug.js +564 -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/domAnalytic.d.ts +54 -0
- package/dist/dom/domAnalytic.js +282 -0
- package/dist/dom/domAnalytic.js.map +1 -0
- package/dist/dom/domExtras.d.ts +27 -0
- package/dist/dom/domExtras.js +137 -0
- package/dist/dom/domExtras.js.map +1 -0
- package/dist/dom/fontCanvas.d.ts +2 -0
- package/dist/dom/fontCanvas.js +119 -0
- package/dist/dom/fontCanvas.js.map +1 -0
- package/dist/dom/layoutSignature.js +156 -27
- package/dist/dom/layoutSignature.js.map +1 -1
- package/dist/dom/pretextLayout.js +55 -13
- package/dist/dom/pretextLayout.js.map +1 -1
- package/dist/dom/snapshot.js +563 -243
- package/dist/dom/snapshot.js.map +1 -1
- package/dist/dom/svgCapture.d.ts +8 -1
- package/dist/dom/svgCapture.js +75 -1
- package/dist/dom/svgCapture.js.map +1 -1
- package/dist/dom/textHost.d.ts +11 -0
- package/dist/dom/textHost.js +68 -0
- package/dist/dom/textHost.js.map +1 -0
- package/dist/dom/tone.js +76 -36
- package/dist/dom/tone.js.map +1 -1
- package/dist/index.js +4 -3
- package/dist/slug/SlugMaterial.d.ts +13 -4
- package/dist/slug/SlugMaterial.js +82 -12
- package/dist/slug/SlugMaterial.js.map +1 -1
- package/dist/slug/coverage.d.ts +17 -13
- package/dist/slug/coverage.js +195 -222
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +6 -3
- package/dist/slug/preprocessCore.js +149 -95
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.d.ts +1 -0
- package/dist/slug/runtime.js +94 -46
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.d.ts +40 -0
- package/dist/slug/standaloneRuntime.js +175 -0
- package/dist/slug/standaloneRuntime.js.map +1 -0
- package/dist/slug/truetype.d.ts +22 -0
- package/dist/slug/truetype.js +467 -0
- package/dist/slug/truetype.js.map +1 -0
- package/dist/slug/vanillaCore.d.ts +340 -0
- package/dist/slug/vanillaCore.js +1621 -0
- package/dist/slug/vanillaCore.js.map +1 -0
- package/dist/slug-vanilla.d.ts +13 -0
- package/dist/slug-vanilla.js +13 -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 +102 -33
- package/dist/text/GlyphTextMaterial.js.map +1 -1
- package/dist/text/SdfTextMaterial.d.ts +5 -4
- package/dist/text/SdfTextMaterial.js +29 -9
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/text/decorations.js +36 -19
- package/dist/text/decorations.js.map +1 -1
- package/dist/text/geometry.d.ts +3 -22
- package/dist/text/geometryUtils.d.ts +11 -1
- package/dist/text/geometryUtils.js +22 -1
- package/dist/text/geometryUtils.js.map +1 -1
- package/dist/text/glyphGeometry.d.ts +9 -0
- package/dist/text/glyphGeometry.js +353 -0
- package/dist/text/glyphGeometry.js.map +1 -0
- package/dist/text/index.d.ts +2 -1
- package/dist/text/rectGeometry.d.ts +13 -0
- package/dist/text/rectGeometry.js +97 -0
- package/dist/text/rectGeometry.js.map +1 -0
- package/dist/text/reflow.d.ts +18 -1
- package/dist/text/reflow.js +108 -38
- package/dist/text/reflow.js.map +1 -1
- package/dist/text/snap.d.ts +1 -0
- package/dist/text/snap.js +26 -0
- package/dist/text/snap.js.map +1 -0
- package/dist/types.d.ts +63 -14
- package/dist/vanilla.d.ts +13 -360
- package/dist/vanilla.js +8 -1402
- 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.d.ts +2 -2
- package/dist/windfoil/geometry.js +204 -64
- 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/mixed.d.ts +1 -0
- package/dist/windfoil/mixed.js +44 -25
- package/dist/windfoil/mixed.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 +5 -85
- package/dist/windfoil/preprocessCore.js +218 -209
- 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 +5 -2
- package/dist/windfoil/runtime.js +63 -40
- 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 +62 -4
- package/dist/windfoil/storage.js +143 -28
- package/dist/windfoil/storage.js.map +1 -1
- package/dist/windfoil/trace/contours.d.ts +3 -3
- package/dist/windfoil/trace/contours.js +228 -137
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.d.ts +3 -7
- package/dist/windfoil/trace/fit.js +668 -376
- package/dist/windfoil/trace/fit.js.map +1 -1
- package/dist/windfoil/trace/outline.js +60 -35
- package/dist/windfoil/trace/outline.js.map +1 -1
- package/dist/windfoil/trace/types.d.ts +15 -3
- package/dist/windfoil/tracedOutlines.d.ts +37 -1
- package/dist/windfoil/tracedOutlines.js +228 -64
- package/dist/windfoil/tracedOutlines.js.map +1 -1
- package/package.json +60 -11
- 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 +96 -0
- package/dist/assets/cpuSdf.worker-Du9o8q4p.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
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import type { SdfAtlasMode } from '../types.js';
|
|
2
|
+
import type { GlyphSlot, RasterColorBand } from '../types.js';
|
|
3
|
+
/** Structural WebGPU texture handle returned by GPU atlas builds. */
|
|
4
|
+
export interface VanillaGpuTexture {
|
|
5
|
+
readonly label?: string;
|
|
6
|
+
readonly width?: number;
|
|
7
|
+
readonly height?: number;
|
|
8
|
+
readonly format?: string;
|
|
9
|
+
readonly mipLevelCount?: number;
|
|
10
|
+
createView(descriptor?: {
|
|
11
|
+
baseMipLevel?: number;
|
|
12
|
+
mipLevelCount?: number;
|
|
13
|
+
}): unknown;
|
|
14
|
+
destroy(): void;
|
|
15
|
+
}
|
|
16
|
+
/** Structural WebGPU device interface so callers need neither Three.js nor `@webgpu/types`. */
|
|
17
|
+
export interface VanillaGpuDevice {
|
|
18
|
+
readonly features?: {
|
|
19
|
+
has(name: string): boolean;
|
|
20
|
+
};
|
|
21
|
+
readonly limits?: {
|
|
22
|
+
readonly maxStorageBufferBindingSize: number;
|
|
23
|
+
readonly maxBufferSize: number;
|
|
24
|
+
readonly maxComputeInvocationsPerWorkgroup?: number;
|
|
25
|
+
readonly maxComputeWorkgroupSizeX?: number;
|
|
26
|
+
readonly maxComputeWorkgroupSizeY?: number;
|
|
27
|
+
readonly maxStorageBuffersPerShaderStage?: number;
|
|
28
|
+
readonly maxStorageBuffersInFragmentStage?: number;
|
|
29
|
+
readonly maxTextureDimension2D?: number;
|
|
30
|
+
};
|
|
31
|
+
createTexture(descriptor: {
|
|
32
|
+
label?: string;
|
|
33
|
+
size: readonly [number, number] | [number, number];
|
|
34
|
+
mipLevelCount?: number;
|
|
35
|
+
format: string;
|
|
36
|
+
usage: number;
|
|
37
|
+
}): VanillaGpuTexture;
|
|
38
|
+
createBuffer(descriptor: {
|
|
39
|
+
label?: string;
|
|
40
|
+
size: number;
|
|
41
|
+
usage: number;
|
|
42
|
+
mappedAtCreation?: boolean;
|
|
43
|
+
}): {
|
|
44
|
+
destroy(): void;
|
|
45
|
+
};
|
|
46
|
+
createSampler(descriptor?: {
|
|
47
|
+
label?: string;
|
|
48
|
+
minFilter?: 'nearest' | 'linear';
|
|
49
|
+
magFilter?: 'nearest' | 'linear';
|
|
50
|
+
}): unknown;
|
|
51
|
+
createShaderModule(descriptor: {
|
|
52
|
+
label?: string;
|
|
53
|
+
code: string;
|
|
54
|
+
}): unknown;
|
|
55
|
+
createComputePipeline(descriptor: {
|
|
56
|
+
label?: string;
|
|
57
|
+
layout: 'auto';
|
|
58
|
+
compute: {
|
|
59
|
+
module: unknown;
|
|
60
|
+
entryPoint: string;
|
|
61
|
+
};
|
|
62
|
+
}): {
|
|
63
|
+
getBindGroupLayout(index: number): unknown;
|
|
64
|
+
};
|
|
65
|
+
createRenderPipeline(descriptor: {
|
|
66
|
+
label?: string;
|
|
67
|
+
layout: 'auto';
|
|
68
|
+
vertex: {
|
|
69
|
+
module: unknown;
|
|
70
|
+
entryPoint: string;
|
|
71
|
+
};
|
|
72
|
+
fragment: {
|
|
73
|
+
module: unknown;
|
|
74
|
+
entryPoint: string;
|
|
75
|
+
targets: readonly {
|
|
76
|
+
format: string;
|
|
77
|
+
}[];
|
|
78
|
+
};
|
|
79
|
+
primitive?: {
|
|
80
|
+
topology?: string;
|
|
81
|
+
};
|
|
82
|
+
}): {
|
|
83
|
+
getBindGroupLayout(index: number): unknown;
|
|
84
|
+
};
|
|
85
|
+
createBindGroup(descriptor: {
|
|
86
|
+
layout: unknown;
|
|
87
|
+
entries: readonly {
|
|
88
|
+
binding: number;
|
|
89
|
+
resource: unknown;
|
|
90
|
+
}[];
|
|
91
|
+
}): unknown;
|
|
92
|
+
createCommandEncoder(descriptor?: {
|
|
93
|
+
label?: string;
|
|
94
|
+
}): {
|
|
95
|
+
copyTextureToBuffer(source: {
|
|
96
|
+
texture: VanillaGpuTexture;
|
|
97
|
+
}, destination: {
|
|
98
|
+
buffer: {
|
|
99
|
+
destroy(): void;
|
|
100
|
+
};
|
|
101
|
+
bytesPerRow: number;
|
|
102
|
+
rowsPerImage: number;
|
|
103
|
+
}, size: readonly [number, number] | [number, number]): void;
|
|
104
|
+
beginComputePass(descriptor?: {
|
|
105
|
+
label?: string;
|
|
106
|
+
}): {
|
|
107
|
+
setPipeline(pipeline: unknown): void;
|
|
108
|
+
setBindGroup(index: number, bindGroup: unknown): void;
|
|
109
|
+
dispatchWorkgroups(x: number, y?: number, z?: number): void;
|
|
110
|
+
end(): void;
|
|
111
|
+
};
|
|
112
|
+
beginRenderPass(descriptor: {
|
|
113
|
+
label?: string;
|
|
114
|
+
colorAttachments: readonly {
|
|
115
|
+
view: unknown;
|
|
116
|
+
loadOp: 'clear' | 'load';
|
|
117
|
+
storeOp: 'store' | 'discard';
|
|
118
|
+
clearValue?: {
|
|
119
|
+
r: number;
|
|
120
|
+
g: number;
|
|
121
|
+
b: number;
|
|
122
|
+
a: number;
|
|
123
|
+
};
|
|
124
|
+
}[];
|
|
125
|
+
}): {
|
|
126
|
+
setPipeline(pipeline: unknown): void;
|
|
127
|
+
setBindGroup(index: number, bindGroup: unknown): void;
|
|
128
|
+
draw(vertexCount: number): void;
|
|
129
|
+
end(): void;
|
|
130
|
+
};
|
|
131
|
+
finish(): unknown;
|
|
132
|
+
};
|
|
133
|
+
readonly queue: {
|
|
134
|
+
copyExternalImageToTexture(source: {
|
|
135
|
+
source: HTMLCanvasElement;
|
|
136
|
+
flipY?: boolean;
|
|
137
|
+
}, destination: {
|
|
138
|
+
texture: VanillaGpuTexture;
|
|
139
|
+
premultipliedAlpha?: boolean;
|
|
140
|
+
}, size: readonly [number, number] | [number, number]): void;
|
|
141
|
+
writeBuffer(buffer: {
|
|
142
|
+
destroy(): void;
|
|
143
|
+
}, bufferOffset: number, data: ArrayBufferView, dataOffset?: number, size?: number): void;
|
|
144
|
+
writeTexture(destination: {
|
|
145
|
+
texture: VanillaGpuTexture;
|
|
146
|
+
mipLevel?: number;
|
|
147
|
+
}, data: ArrayBufferView, dataLayout: {
|
|
148
|
+
offset?: number;
|
|
149
|
+
bytesPerRow: number;
|
|
150
|
+
rowsPerImage?: number;
|
|
151
|
+
}, size: readonly [number, number] | [number, number]): void;
|
|
152
|
+
submit(commandBuffers: readonly unknown[]): void;
|
|
153
|
+
};
|
|
154
|
+
pushErrorScope?(filter: 'validation' | 'out-of-memory' | 'internal'): void;
|
|
155
|
+
popErrorScope?(): Promise<{
|
|
156
|
+
readonly message?: string;
|
|
157
|
+
} | null>;
|
|
158
|
+
}
|
|
159
|
+
/** A WebGPU `GPUDevice`, an engine renderer holding `{ device }`, or `null`/`undefined` for CPU mode. */
|
|
160
|
+
export type VanillaGpuDeviceSource = VanillaGpuDevice | {
|
|
161
|
+
readonly device?: VanillaGpuDevice | null | undefined;
|
|
162
|
+
} | null | undefined;
|
|
163
|
+
/** Companion colour layer owned and disposed by its `VanillaSdfAtlas`. */
|
|
164
|
+
export interface VanillaSdfColorLayer {
|
|
165
|
+
readonly data: Uint8Array;
|
|
166
|
+
readonly gpuTexture?: VanillaGpuTexture | undefined;
|
|
167
|
+
readonly width: number;
|
|
168
|
+
readonly top: number;
|
|
169
|
+
readonly height: number;
|
|
170
|
+
}
|
|
171
|
+
/** Engine-agnostic SDF atlas with CPU bytes and/or an adopted WebGPU `GPUTexture`. */
|
|
172
|
+
export interface VanillaSdfAtlas {
|
|
173
|
+
/** Single-channel SDF bytes (`width * height`), present when built on CPU. */
|
|
174
|
+
readonly data?: Uint8Array | undefined;
|
|
175
|
+
/** WebGPU `r8unorm` texture (`TEXTURE_BINDING | COPY_SRC`), present when built on GPU. */
|
|
176
|
+
readonly gpuTexture?: VanillaGpuTexture | undefined;
|
|
177
|
+
readonly colorLayer?: VanillaSdfColorLayer | undefined;
|
|
178
|
+
readonly shapeTop?: number | undefined;
|
|
179
|
+
readonly width: number;
|
|
180
|
+
readonly height: number;
|
|
181
|
+
readonly pxRange: number;
|
|
182
|
+
readonly bakeSize: number;
|
|
183
|
+
readonly glyphs: ReadonlyMap<string, GlyphSlot>;
|
|
184
|
+
readonly mode: Exclude<SdfAtlasMode, 'auto'>;
|
|
185
|
+
/** Requested mipmap flag. */
|
|
186
|
+
readonly mipmaps: boolean;
|
|
187
|
+
/** Requested anisotropy level. */
|
|
188
|
+
readonly anisotropy: number;
|
|
189
|
+
dispose(): void;
|
|
190
|
+
}
|
|
191
|
+
export declare function resolveGpuDevice(source: VanillaGpuDeviceSource): VanillaGpuDevice | null;
|
|
192
|
+
export declare const DEFAULT_BUF_USAGE: {
|
|
193
|
+
COPY_SRC: number;
|
|
194
|
+
COPY_DST: number;
|
|
195
|
+
UNIFORM: number;
|
|
196
|
+
STORAGE: number;
|
|
197
|
+
};
|
|
198
|
+
export declare const DEFAULT_TEX_USAGE: {
|
|
199
|
+
COPY_SRC: number;
|
|
200
|
+
COPY_DST: number;
|
|
201
|
+
TEXTURE_BINDING: number;
|
|
202
|
+
STORAGE_BINDING?: number;
|
|
203
|
+
RENDER_ATTACHMENT: number;
|
|
204
|
+
};
|
|
205
|
+
export declare const texUsageOf: () => {
|
|
206
|
+
COPY_SRC: number;
|
|
207
|
+
COPY_DST: number;
|
|
208
|
+
TEXTURE_BINDING: number;
|
|
209
|
+
STORAGE_BINDING?: number;
|
|
210
|
+
RENDER_ATTACHMENT: number;
|
|
211
|
+
};
|
|
212
|
+
export declare const bufUsageOf: () => {
|
|
213
|
+
COPY_SRC: number;
|
|
214
|
+
COPY_DST: number;
|
|
215
|
+
UNIFORM: number;
|
|
216
|
+
STORAGE: number;
|
|
217
|
+
};
|
|
218
|
+
export declare const mipCount: (w: number, h: number, mipmaps: boolean) => number;
|
|
219
|
+
interface CachedMipPipelines {
|
|
220
|
+
readonly module: unknown;
|
|
221
|
+
readonly sampler: unknown;
|
|
222
|
+
r8?: ReturnType<VanillaGpuDevice['createRenderPipeline']>;
|
|
223
|
+
rgba?: ReturnType<VanillaGpuDevice['createRenderPipeline']>;
|
|
224
|
+
}
|
|
225
|
+
export declare const vanillaMipPipelines: WeakMap<VanillaGpuDevice, CachedMipPipelines>;
|
|
226
|
+
export declare function getDeviceMipPipeline(device: VanillaGpuDevice, format: 'r8unorm' | 'rgba8unorm-srgb'): {
|
|
227
|
+
readonly pipeline: ReturnType<VanillaGpuDevice['createRenderPipeline']>;
|
|
228
|
+
readonly sampler: unknown;
|
|
229
|
+
};
|
|
230
|
+
export declare function encodeMipmapChain(device: VanillaGpuDevice, encoder: ReturnType<VanillaGpuDevice['createCommandEncoder']>, texture: VanillaGpuTexture, mipLevelCount: number, pipeline: ReturnType<VanillaGpuDevice['createRenderPipeline']>, sampler: unknown): void;
|
|
231
|
+
export declare function createGpuColorLayer(device: VanillaGpuDevice, width: number, band: RasterColorBand, mipmaps: boolean): VanillaSdfColorLayer;
|
|
232
|
+
export {};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { MIP_WGSL } from "./jfaWgsl.js";
|
|
2
|
+
// src/atlas/vanillaGpuHelpers.ts
|
|
3
|
+
function resolveGpuDevice(source) {
|
|
4
|
+
if (!source || typeof source !== "object") return null;
|
|
5
|
+
if ("createTexture" in source && typeof source.createTexture === "function") return source;
|
|
6
|
+
if ("device" in source && source.device && typeof source.device.createTexture === "function") return source.device;
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
var DEFAULT_BUF_USAGE = {
|
|
10
|
+
COPY_SRC: 4,
|
|
11
|
+
COPY_DST: 8,
|
|
12
|
+
UNIFORM: 64,
|
|
13
|
+
STORAGE: 128
|
|
14
|
+
};
|
|
15
|
+
var DEFAULT_TEX_USAGE = {
|
|
16
|
+
COPY_SRC: 1,
|
|
17
|
+
COPY_DST: 2,
|
|
18
|
+
TEXTURE_BINDING: 4,
|
|
19
|
+
STORAGE_BINDING: 8,
|
|
20
|
+
RENDER_ATTACHMENT: 16
|
|
21
|
+
};
|
|
22
|
+
var texUsageOf = () => globalThis.GPUTextureUsage ?? DEFAULT_TEX_USAGE;
|
|
23
|
+
var bufUsageOf = () => globalThis.GPUBufferUsage ?? DEFAULT_BUF_USAGE;
|
|
24
|
+
var mipCount = (w, h, mipmaps) => mipmaps ? Math.floor(Math.log2(Math.max(w, h))) + 1 : 1;
|
|
25
|
+
var vanillaMipPipelines = /* @__PURE__ */ new WeakMap();
|
|
26
|
+
function getDeviceMipPipeline(device, format) {
|
|
27
|
+
let cached = vanillaMipPipelines.get(device);
|
|
28
|
+
if (!cached) {
|
|
29
|
+
cached = {
|
|
30
|
+
module: device.createShaderModule({ code: MIP_WGSL }),
|
|
31
|
+
sampler: device.createSampler({
|
|
32
|
+
minFilter: "linear",
|
|
33
|
+
magFilter: "linear"
|
|
34
|
+
})
|
|
35
|
+
};
|
|
36
|
+
vanillaMipPipelines.set(device, cached);
|
|
37
|
+
}
|
|
38
|
+
const key = format === "r8unorm" ? "r8" : "rgba";
|
|
39
|
+
let pipeline = cached[key];
|
|
40
|
+
if (!pipeline) {
|
|
41
|
+
pipeline = device.createRenderPipeline({
|
|
42
|
+
layout: "auto",
|
|
43
|
+
vertex: {
|
|
44
|
+
module: cached.module,
|
|
45
|
+
entryPoint: "mipVert"
|
|
46
|
+
},
|
|
47
|
+
fragment: {
|
|
48
|
+
module: cached.module,
|
|
49
|
+
entryPoint: "mipFrag",
|
|
50
|
+
targets: [{ format }]
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
cached[key] = pipeline;
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
pipeline,
|
|
57
|
+
sampler: cached.sampler
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function encodeMipmapChain(device, encoder, texture, mipLevelCount, pipeline, sampler) {
|
|
61
|
+
const view = (baseMipLevel) => texture.createView({
|
|
62
|
+
baseMipLevel,
|
|
63
|
+
mipLevelCount: 1
|
|
64
|
+
});
|
|
65
|
+
for (let level = 1; level < mipLevelCount; level++) {
|
|
66
|
+
const pass = encoder.beginRenderPass({ colorAttachments: [{
|
|
67
|
+
view: view(level),
|
|
68
|
+
loadOp: "clear",
|
|
69
|
+
storeOp: "store"
|
|
70
|
+
}] });
|
|
71
|
+
pass.setPipeline(pipeline);
|
|
72
|
+
pass.setBindGroup(0, device.createBindGroup({
|
|
73
|
+
layout: pipeline.getBindGroupLayout(0),
|
|
74
|
+
entries: [{
|
|
75
|
+
binding: 0,
|
|
76
|
+
resource: view(level - 1)
|
|
77
|
+
}, {
|
|
78
|
+
binding: 1,
|
|
79
|
+
resource: sampler
|
|
80
|
+
}]
|
|
81
|
+
}));
|
|
82
|
+
pass.draw(3);
|
|
83
|
+
pass.end();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function createGpuColorLayer(device, width, band, mipmaps) {
|
|
87
|
+
const textures = texUsageOf();
|
|
88
|
+
const mipLevelCount = mipCount(width, band.height, mipmaps);
|
|
89
|
+
const gpuTexture = device.createTexture({
|
|
90
|
+
size: [width, band.height],
|
|
91
|
+
mipLevelCount,
|
|
92
|
+
format: "rgba8unorm-srgb",
|
|
93
|
+
usage: textures.TEXTURE_BINDING | textures.COPY_DST | textures.COPY_SRC | (mipLevelCount > 1 ? textures.RENDER_ATTACHMENT : 0)
|
|
94
|
+
});
|
|
95
|
+
device.queue.writeTexture({
|
|
96
|
+
texture: gpuTexture,
|
|
97
|
+
mipLevel: 0
|
|
98
|
+
}, band.data, {
|
|
99
|
+
offset: 0,
|
|
100
|
+
bytesPerRow: width * 4,
|
|
101
|
+
rowsPerImage: band.height
|
|
102
|
+
}, [width, band.height]);
|
|
103
|
+
if (mipLevelCount > 1) {
|
|
104
|
+
const mip = getDeviceMipPipeline(device, "rgba8unorm-srgb");
|
|
105
|
+
const encoder = device.createCommandEncoder();
|
|
106
|
+
encodeMipmapChain(device, encoder, gpuTexture, mipLevelCount, mip.pipeline, mip.sampler);
|
|
107
|
+
device.queue.submit([encoder.finish()]);
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
data: band.data,
|
|
111
|
+
gpuTexture,
|
|
112
|
+
width,
|
|
113
|
+
top: band.top,
|
|
114
|
+
height: band.height
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
export { DEFAULT_BUF_USAGE, DEFAULT_TEX_USAGE, bufUsageOf, createGpuColorLayer, encodeMipmapChain, getDeviceMipPipeline, mipCount, resolveGpuDevice, texUsageOf, vanillaMipPipelines };
|
|
118
|
+
|
|
119
|
+
//# sourceMappingURL=vanillaGpuHelpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vanillaGpuHelpers.js","names":[],"sources":["../../src/atlas/vanillaGpuHelpers.ts"],"sourcesContent":["import type { SdfAtlasMode } from '../types.js'\nimport { MIP_WGSL } from './jfaWgsl.js'\nimport type { GlyphSlot, RasterColorBand } from '../types.js'\n\n/** Structural WebGPU texture handle returned by GPU atlas builds. */\nexport interface VanillaGpuTexture {\n readonly label?: string\n readonly width?: number\n readonly height?: number\n readonly format?: string\n readonly mipLevelCount?: number\n createView(descriptor?: { baseMipLevel?: number; mipLevelCount?: number }): unknown\n destroy(): void\n}\n\n/** Structural WebGPU device interface so callers need neither Three.js nor `@webgpu/types`. */\nexport interface VanillaGpuDevice {\n readonly features?: { has(name: string): boolean }\n readonly limits?: {\n readonly maxStorageBufferBindingSize: number\n readonly maxBufferSize: number\n readonly maxComputeInvocationsPerWorkgroup?: number\n readonly maxComputeWorkgroupSizeX?: number\n readonly maxComputeWorkgroupSizeY?: number\n readonly maxStorageBuffersPerShaderStage?: number\n readonly maxStorageBuffersInFragmentStage?: number\n readonly maxTextureDimension2D?: number\n }\n createTexture(descriptor: {\n label?: string\n size: readonly [number, number] | [number, number]\n mipLevelCount?: number\n format: string\n usage: number\n }): VanillaGpuTexture\n createBuffer(descriptor: {\n label?: string\n size: number\n usage: number\n mappedAtCreation?: boolean\n }): { destroy(): void }\n createSampler(descriptor?: {\n label?: string\n minFilter?: 'nearest' | 'linear'\n magFilter?: 'nearest' | 'linear'\n }): unknown\n createShaderModule(descriptor: { label?: string; code: string }): unknown\n createComputePipeline(descriptor: {\n label?: string\n layout: 'auto'\n compute: { module: unknown; entryPoint: string }\n }): { getBindGroupLayout(index: number): unknown }\n createRenderPipeline(descriptor: {\n label?: string\n layout: 'auto'\n vertex: { module: unknown; entryPoint: string }\n fragment: { module: unknown; entryPoint: string; targets: readonly { format: string }[] }\n primitive?: { topology?: string }\n }): { getBindGroupLayout(index: number): unknown }\n createBindGroup(descriptor: {\n layout: unknown\n entries: readonly { binding: number; resource: unknown }[]\n }): unknown\n createCommandEncoder(descriptor?: { label?: string }): {\n copyTextureToBuffer(\n source: { texture: VanillaGpuTexture },\n destination: { buffer: { destroy(): void }; bytesPerRow: number; rowsPerImage: number },\n size: readonly [number, number] | [number, number],\n ): void\n beginComputePass(descriptor?: { label?: string }): {\n setPipeline(pipeline: unknown): void\n setBindGroup(index: number, bindGroup: unknown): void\n dispatchWorkgroups(x: number, y?: number, z?: number): void\n end(): void\n }\n beginRenderPass(descriptor: {\n label?: string\n colorAttachments: readonly {\n view: unknown\n loadOp: 'clear' | 'load'\n storeOp: 'store' | 'discard'\n clearValue?: { r: number; g: number; b: number; a: number }\n }[]\n }): {\n setPipeline(pipeline: unknown): void\n setBindGroup(index: number, bindGroup: unknown): void\n draw(vertexCount: number): void\n end(): void\n }\n finish(): unknown\n }\n readonly queue: {\n copyExternalImageToTexture(\n source: { source: HTMLCanvasElement; flipY?: boolean },\n destination: { texture: VanillaGpuTexture; premultipliedAlpha?: boolean },\n size: readonly [number, number] | [number, number],\n ): void\n writeBuffer(\n buffer: { destroy(): void },\n bufferOffset: number,\n data: ArrayBufferView,\n dataOffset?: number,\n size?: number,\n ): void\n writeTexture(\n destination: { texture: VanillaGpuTexture; mipLevel?: number },\n data: ArrayBufferView,\n dataLayout: { offset?: number; bytesPerRow: number; rowsPerImage?: number },\n size: readonly [number, number] | [number, number],\n ): void\n submit(commandBuffers: readonly unknown[]): void\n }\n pushErrorScope?(filter: 'validation' | 'out-of-memory' | 'internal'): void\n popErrorScope?(): Promise<{ readonly message?: string } | null>\n}\n\n/** A WebGPU `GPUDevice`, an engine renderer holding `{ device }`, or `null`/`undefined` for CPU mode. */\nexport type VanillaGpuDeviceSource =\n VanillaGpuDevice | { readonly device?: VanillaGpuDevice | null | undefined } | null | undefined\n\n/** Companion colour layer owned and disposed by its `VanillaSdfAtlas`. */\nexport interface VanillaSdfColorLayer {\n readonly data: Uint8Array\n readonly gpuTexture?: VanillaGpuTexture | undefined\n readonly width: number\n readonly top: number\n readonly height: number\n}\n\n/** Engine-agnostic SDF atlas with CPU bytes and/or an adopted WebGPU `GPUTexture`. */\nexport interface VanillaSdfAtlas {\n /** Single-channel SDF bytes (`width * height`), present when built on CPU. */\n readonly data?: Uint8Array | undefined\n /** WebGPU `r8unorm` texture (`TEXTURE_BINDING | COPY_SRC`), present when built on GPU. */\n readonly gpuTexture?: VanillaGpuTexture | undefined\n readonly colorLayer?: VanillaSdfColorLayer | undefined\n readonly shapeTop?: number | undefined\n readonly width: number\n readonly height: number\n readonly pxRange: number\n readonly bakeSize: number\n readonly glyphs: ReadonlyMap<string, GlyphSlot>\n readonly mode: Exclude<SdfAtlasMode, 'auto'>\n /** Requested mipmap flag. */\n readonly mipmaps: boolean\n /** Requested anisotropy level. */\n readonly anisotropy: number\n dispose(): void\n}\n\nexport function resolveGpuDevice(source: VanillaGpuDeviceSource): VanillaGpuDevice | null {\n if (!source || typeof source !== 'object') return null\n if ('createTexture' in source && typeof source.createTexture === 'function') return source\n if ('device' in source && source.device && typeof source.device.createTexture === 'function') {\n return source.device\n }\n return null\n}\n\nexport const DEFAULT_BUF_USAGE = { COPY_SRC: 4, COPY_DST: 8, UNIFORM: 64, STORAGE: 128 }\nexport const DEFAULT_TEX_USAGE: {\n COPY_SRC: number\n COPY_DST: number\n TEXTURE_BINDING: number\n STORAGE_BINDING?: number\n RENDER_ATTACHMENT: number\n} = { COPY_SRC: 1, COPY_DST: 2, TEXTURE_BINDING: 4, STORAGE_BINDING: 8, RENDER_ATTACHMENT: 16 }\n\ninterface UsageGlobals {\n GPUBufferUsage?: typeof DEFAULT_BUF_USAGE\n GPUTextureUsage?: typeof DEFAULT_TEX_USAGE\n}\n\nexport const texUsageOf = () => (globalThis as UsageGlobals).GPUTextureUsage ?? DEFAULT_TEX_USAGE\nexport const bufUsageOf = () => (globalThis as UsageGlobals).GPUBufferUsage ?? DEFAULT_BUF_USAGE\nexport const mipCount = (w: number, h: number, mipmaps: boolean): number =>\n mipmaps ? Math.floor(Math.log2(Math.max(w, h))) + 1 : 1\n\ninterface CachedMipPipelines {\n readonly module: unknown\n readonly sampler: unknown\n r8?: ReturnType<VanillaGpuDevice['createRenderPipeline']>\n rgba?: ReturnType<VanillaGpuDevice['createRenderPipeline']>\n}\n\nexport const vanillaMipPipelines = new WeakMap<VanillaGpuDevice, CachedMipPipelines>()\n\nexport function getDeviceMipPipeline(\n device: VanillaGpuDevice,\n format: 'r8unorm' | 'rgba8unorm-srgb',\n): {\n readonly pipeline: ReturnType<VanillaGpuDevice['createRenderPipeline']>\n readonly sampler: unknown\n} {\n let cached = vanillaMipPipelines.get(device)\n if (!cached) {\n cached = {\n module: device.createShaderModule({ code: MIP_WGSL }),\n sampler: device.createSampler({ minFilter: 'linear', magFilter: 'linear' }),\n }\n vanillaMipPipelines.set(device, cached)\n }\n const key = format === 'r8unorm' ? 'r8' : 'rgba'\n let pipeline = cached[key]\n if (!pipeline) {\n pipeline = device.createRenderPipeline({\n layout: 'auto',\n vertex: { module: cached.module, entryPoint: 'mipVert' },\n fragment: { module: cached.module, entryPoint: 'mipFrag', targets: [{ format }] },\n })\n cached[key] = pipeline\n }\n return { pipeline, sampler: cached.sampler }\n}\n\nexport function encodeMipmapChain(\n device: VanillaGpuDevice,\n encoder: ReturnType<VanillaGpuDevice['createCommandEncoder']>,\n texture: VanillaGpuTexture,\n mipLevelCount: number,\n pipeline: ReturnType<VanillaGpuDevice['createRenderPipeline']>,\n sampler: unknown,\n): void {\n const view = (baseMipLevel: number) => texture.createView({ baseMipLevel, mipLevelCount: 1 })\n for (let level = 1; level < mipLevelCount; level++) {\n const pass = encoder.beginRenderPass({\n colorAttachments: [{ view: view(level), loadOp: 'clear', storeOp: 'store' }],\n })\n pass.setPipeline(pipeline)\n pass.setBindGroup(\n 0,\n device.createBindGroup({\n layout: pipeline.getBindGroupLayout(0),\n entries: [\n { binding: 0, resource: view(level - 1) },\n { binding: 1, resource: sampler },\n ],\n }),\n )\n pass.draw(3)\n pass.end()\n }\n}\n\nexport function createGpuColorLayer(\n device: VanillaGpuDevice,\n width: number,\n band: RasterColorBand,\n mipmaps: boolean,\n): VanillaSdfColorLayer {\n const textures = texUsageOf()\n const mipLevelCount = mipCount(width, band.height, mipmaps)\n const gpuTexture = device.createTexture({\n size: [width, band.height],\n mipLevelCount,\n format: 'rgba8unorm-srgb',\n usage:\n textures.TEXTURE_BINDING |\n textures.COPY_DST |\n textures.COPY_SRC |\n (mipLevelCount > 1 ? textures.RENDER_ATTACHMENT : 0),\n })\n device.queue.writeTexture(\n { texture: gpuTexture, mipLevel: 0 },\n band.data,\n { offset: 0, bytesPerRow: width * 4, rowsPerImage: band.height },\n [width, band.height],\n )\n if (mipLevelCount > 1) {\n const mip = getDeviceMipPipeline(device, 'rgba8unorm-srgb')\n const encoder = device.createCommandEncoder()\n encodeMipmapChain(device, encoder, gpuTexture, mipLevelCount, mip.pipeline, mip.sampler)\n device.queue.submit([encoder.finish()])\n }\n return {\n data: band.data,\n gpuTexture,\n width,\n top: band.top,\n height: band.height,\n }\n}\n"],"mappings":"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"}
|