Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
507 changes: 17 additions & 490 deletions apps/benchmarks/src/app.tsx

Large diffs are not rendered by default.

55 changes: 28 additions & 27 deletions apps/benchmarks/src/benchmark/raster-fixture-manifests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,34 +93,35 @@ describe('checked raster fixture manifests', () => {
}
});

it('authenticates every complete MTSDF font artifact and page total', async () => {
it('covers every complete MTSDF font fixture', () => {
expect(mtsdfManifest.artifacts.map(({ fontFixture }) => fontFixture)).toEqual(Object.keys(fixtureIdentities));
for (const artifact of mtsdfManifest.artifacts) {
const fixtureId = checkedFixtureId(artifact.fontFixture);
const identity = fixtureIdentities[fixtureId];
const compressed = await readFile(new URL(`rendering/${artifact.file}`, fixtureRoot));
expect(compressed.byteLength).toBe(artifact.compressed.bytes);
expect(sha256(compressed)).toBe(artifact.compressed.sha256);
const expanded = await authenticateGzipGlb(compressed);
expect(expanded.bytes).toBe(artifact.uncompressed.bytes);
expect(expanded.sha256).toBe(artifact.uncompressed.sha256);
const document = glbDocument(expanded.jsonPrefix, artifact.file);
await expectCompleteFont(document, identity, fixtureId);
const raster = objectProperty(
objectProperty(document, 'extensions', artifact.file),
'PMNDRS_font_distance_field',
artifact.file,
);
expect(integerProperty(raster, 'glyphCount', artifact.file)).toBe(identity.glyphCount);
expect(arrayProperty(raster, 'pages', artifact.file)).toHaveLength(artifact.raster.pages.length);
expect(sum(artifact.raster.pages.map(({ decodedGpuBytes }) => decodedGpuBytes))).toBe(
artifact.raster.decodedGpuBytes,
);
const textureArray = artifact.raster.runtimeTextureArray;
expect(exactBaseTextureArrayBytes(textureArray.width, textureArray.height, textureArray.layers, 4)).toBe(
textureArray.basePaddedGpuBytes,
);
}
});

it.each(mtsdfManifest.artifacts)('authenticates MTSDF artifact $fontFixture and its page total', async (artifact) => {
const fixtureId = checkedFixtureId(artifact.fontFixture);
const identity = fixtureIdentities[fixtureId];
const compressed = await readFile(new URL(`rendering/${artifact.file}`, fixtureRoot));
expect(compressed.byteLength).toBe(artifact.compressed.bytes);
expect(sha256(compressed)).toBe(artifact.compressed.sha256);
const expanded = await authenticateGzipGlb(compressed);
expect(expanded.bytes).toBe(artifact.uncompressed.bytes);
expect(expanded.sha256).toBe(artifact.uncompressed.sha256);
const document = glbDocument(expanded.jsonPrefix, artifact.file);
await expectCompleteFont(document, identity, fixtureId);
const raster = objectProperty(
objectProperty(document, 'extensions', artifact.file),
'PMNDRS_font_distance_field',
artifact.file,
);
expect(integerProperty(raster, 'glyphCount', artifact.file)).toBe(identity.glyphCount);
expect(arrayProperty(raster, 'pages', artifact.file)).toHaveLength(artifact.raster.pages.length);
expect(sum(artifact.raster.pages.map(({ decodedGpuBytes }) => decodedGpuBytes))).toBe(
artifact.raster.decodedGpuBytes,
);
const textureArray = artifact.raster.runtimeTextureArray;
expect(exactBaseTextureArrayBytes(textureArray.width, textureArray.height, textureArray.layers, 4)).toBe(
textureArray.basePaddedGpuBytes,
);
});
});

Expand Down
6 changes: 6 additions & 0 deletions apps/benchmarks/src/benchmark/target-boundary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@ describe('benchmark target boundaries', () => {
const registry = await readFile(new URL('./targets/registry.ts', import.meta.url), 'utf8');
const execution = await readFile(new URL('./execution.ts', import.meta.url), 'utf8');
const conformance = await readFile(new URL('./targets/conformance/index.ts', import.meta.url), 'utf8');
const mtsdfAdapter = await readFile(new URL('./targets/conformance/raster/mtsdf.ts', import.meta.url), 'utf8');
const slugAdapter = await readFile(new URL('./targets/conformance/raster/slug.ts', import.meta.url), 'utf8');

expect(registry).toContain("import('./product')");
expect(registry).toContain("import('./measurement/font-baker')");
expect(registry).toContain("import('./conformance')");
expect(execution).toContain('await loadRegisteredTarget(request.targetId)');
expect(conformance).toContain("import('./advanced-shaping')");
expect(conformance).not.toContain('renderer/advanced-shaping-conformance');
expect(conformance).not.toContain("import('../../../renderer/mtsdf-text')");
expect(conformance).not.toContain("import('../../../renderer/slug-text')");
expect(mtsdfAdapter).toContain("import('../../../../renderer/mtsdf-text')");
expect(slugAdapter).toContain("import('../../../../renderer/slug-text')");
const { createAdvancedShapingConformanceTarget } = await import('./targets/conformance/advanced-shaping');
expect(createAdvancedShapingConformanceTarget().id).toBe('advanced-shaping-conformance');
expect(await loadRegisteredTarget('missing')).toBeUndefined();
Expand Down
70 changes: 23 additions & 47 deletions apps/benchmarks/src/benchmark/targets/conformance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import type { BenchmarkInput, BenchmarkTarget, Capability } from '../../contract
import { selectableFontFixture } from '../../font-fixtures';
import { createShapingConformanceTargets } from './direct-runtime';
import { createFontLoaderWorkerConformanceTarget } from './font-loader-worker';
import { mtsdfRasterConformanceAdapter } from './raster/mtsdf';
import { slugRasterConformanceAdapter } from './raster/slug';
import { createRasterSamplingConformanceTarget, createRasterSourceOutlineConformanceTarget } from './raster/target';
import { createDeferredTarget, sha256 } from '../shared';

type Backend = 'webgpu' | 'webgl2';
Expand Down Expand Up @@ -35,21 +38,9 @@ function tslBaselineTarget(backend: Backend): BenchmarkTarget {
}

function samplingTarget(technique: Extract<Technique, 'mtsdf' | 'slug'>, backend: Backend): BenchmarkTarget {
return createDeferredTarget(
{
id: `${technique}-conformance-${backend}`,
label: `${technique === 'mtsdf' ? 'MTSDF' : 'Slug'} sampling conformance · ${backendLabel(backend)}`,
detail: 'GPU TSL candidate · independent scalar CPU reconstruction',
color: technique === 'slug' && backend === 'webgpu' ? 'green' : backendColor(backend),
capabilities: rasterCapabilities,
status: () => 'ready',
},
async () => {
if (technique === 'mtsdf')
return (await import('../../../renderer/mtsdf-text')).createMtsdfConformanceTarget(backend);
return (await import('../../../renderer/slug-text')).createSlugConformanceTarget(backend);
},
{ forwardsConfiguration: true },
return createRasterSamplingConformanceTarget(
technique === 'mtsdf' ? mtsdfRasterConformanceAdapter : slugRasterConformanceAdapter,
backend,
);
}

Expand All @@ -67,6 +58,12 @@ const advancedShapingTarget = () =>
);

function sourceOutlineFidelityTarget(technique: Technique, backend: Backend): BenchmarkTarget {
if (technique === 'mtsdf' || technique === 'slug') {
return createRasterSourceOutlineConformanceTarget(
technique === 'mtsdf' ? mtsdfRasterConformanceAdapter : slugRasterConformanceAdapter,
backend,
);
}
let configuredInput: BenchmarkInput = {};
return {
id: `source-outline-${technique}-${backend}`,
Expand All @@ -81,43 +78,22 @@ function sourceOutlineFidelityTarget(technique: Technique, backend: Backend): Be
load: async () => undefined,
run: async (input, _sampleIndex, controls, context) => {
const fontFixture = input.fontFixture ?? configuredInput.fontFixture ?? 'inter';
const capture =
technique === 'slug'
? await import('../../../renderer/slug-text').then(({ captureSlugSourceOutlineFidelity }) =>
captureSlugSourceOutlineFidelity({
backend,
dpr: controls.dpr,
fontFixture,
...(context?.renderer === undefined ? {} : { renderer: context.renderer }),
...(context?.signal === undefined ? {} : { signal: context.signal }),
}),
)
: technique === 'mtsdf'
? await import('../../../renderer/mtsdf-text').then(({ captureMtsdfSourceOutlineFidelity }) =>
captureMtsdfSourceOutlineFidelity({
backend,
dpr: controls.dpr,
fontFixture: selectableFontFixture(fontFixture),
...(context?.renderer === undefined ? {} : { renderer: context.renderer }),
...(context?.signal === undefined ? {} : { signal: context.signal }),
}),
)
: await import('../../../renderer/bitmap-text').then(({ captureBitmapSourceOutlineFidelity }) =>
captureBitmapSourceOutlineFidelity({
backend,
dpr: controls.dpr,
fontFixture: selectableFontFixture(fontFixture),
...(context?.renderer === undefined ? {} : { renderer: context.renderer }),
...(context?.signal === undefined ? {} : { signal: context.signal }),
}),
);
const capture = await import('../../../renderer/bitmap-text').then(({ captureBitmapSourceOutlineFidelity }) =>
captureBitmapSourceOutlineFidelity({
backend,
dpr: controls.dpr,
fontFixture: selectableFontFixture(fontFixture),
...(context?.renderer === undefined ? {} : { renderer: context.renderer }),
...(context?.signal === undefined ? {} : { signal: context.signal }),
}),
);
return {
bytes: capture.candidate.byteLength,
hash: await sha256(capture.candidate),
metrics: {
techniqueBitmap: technique === 'bitmap' ? 1 : 0,
techniqueMtsdf: technique === 'mtsdf' ? 1 : 0,
techniqueSlug: technique === 'slug' ? 1 : 0,
techniqueMtsdf: 0,
techniqueSlug: 0,
fixtureIsDotGothic: fontFixture === 'dot-gothic-16' ? 1 : 0,
backendWebGpu: backend === 'webgpu' ? 1 : 0,
backendWebGl2: backend === 'webgl2' ? 1 : 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { BenchmarkControls, BenchmarkExecutionContext, BenchmarkInput, TargetRunOutput } from '../../../contracts';

export type RasterConformanceBackend = 'webgpu' | 'webgl2';
export type RasterConformanceTechnique = 'mtsdf' | 'slug';

/** The subset of a source-outline capture the conformance target publishes. */
export interface RasterSourceOutlineCapture {
readonly candidate: Uint8Array;
readonly width: number;
readonly height: number;
readonly physicalPpem: number;
readonly meanAbsoluteError: number;
readonly maximumError: number;
readonly errorPixels: number;
readonly renderSubmitMs: number;
}

/**
* Backend-private resources stay in their renderer module. The target owns this
* session's warm load, capture, and disposal lifecycle without owning a renderer.
*/
export interface RasterConformanceSession {
load(input: BenchmarkInput, controls: BenchmarkControls, context?: BenchmarkExecutionContext): Promise<void>;
captureSampling(
input: BenchmarkInput,
sampleIndex: number,
controls: BenchmarkControls,
context?: BenchmarkExecutionContext,
): Promise<TargetRunOutput>;
captureSourceOutline(
input: BenchmarkInput,
controls: BenchmarkControls,
context?: BenchmarkExecutionContext,
): Promise<RasterSourceOutlineCapture>;
dispose(): Promise<void>;
}

export interface RasterConformanceAdapter {
readonly technique: RasterConformanceTechnique;
createSession(backend: RasterConformanceBackend): Promise<RasterConformanceSession>;
}
27 changes: 27 additions & 0 deletions apps/benchmarks/src/benchmark/targets/conformance/raster/mtsdf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { selectableFontFixture } from '../../../font-fixtures';
import type { RasterConformanceAdapter } from './contracts';

export const mtsdfRasterConformanceAdapter: RasterConformanceAdapter = {
technique: 'mtsdf',
async createSession(backend) {
const { captureMtsdfSourceOutlineFidelity, createMtsdfConformanceTarget } =
await import('../../../../renderer/mtsdf-text');
const target = createMtsdfConformanceTarget(backend);
return {
load: async (input, controls, context) => {
target.configure?.(input);
await target.load(controls, context);
},
captureSampling: (input, sampleIndex, controls, context) => target.run(input, sampleIndex, controls, context),
captureSourceOutline: async (input, controls, context) =>
captureMtsdfSourceOutlineFidelity({
backend,
dpr: controls.dpr,
fontFixture: selectableFontFixture(input.fontFixture ?? 'inter'),
...(context?.renderer === undefined ? {} : { renderer: context.renderer }),
...(context?.signal === undefined ? {} : { signal: context.signal }),
}),
dispose: () => target.dispose(),
};
},
};
26 changes: 26 additions & 0 deletions apps/benchmarks/src/benchmark/targets/conformance/raster/slug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { RasterConformanceAdapter } from './contracts';

export const slugRasterConformanceAdapter: RasterConformanceAdapter = {
technique: 'slug',
async createSession(backend) {
const { captureSlugSourceOutlineFidelity, createSlugConformanceTarget } =
await import('../../../../renderer/slug-text');
const target = createSlugConformanceTarget(backend);
return {
load: async (input, controls, context) => {
target.configure?.(input);
await target.load(controls, context);
},
captureSampling: (input, sampleIndex, controls, context) => target.run(input, sampleIndex, controls, context),
captureSourceOutline: async (input, controls, context) =>
captureSlugSourceOutlineFidelity({
backend,
dpr: controls.dpr,
fontFixture: input.fontFixture ?? 'inter',
...(context?.renderer === undefined ? {} : { renderer: context.renderer }),
...(context?.signal === undefined ? {} : { signal: context.signal }),
}),
dispose: () => target.dispose(),
};
},
};
Loading
Loading