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
53 changes: 53 additions & 0 deletions src/lib/exporter/modernFrameRenderer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,59 @@ function createRenderer() {
}

describe("ModernFrameRenderer Pixi lifecycle", () => {
it("defaults to webgl before webgpu when no explicit backend is requested", async () => {
pixiApplicationInstancesMock.length = 0;
pixiInitializationErrorsMock.length = 0;
vi.stubGlobal("navigator", { gpu: {} });

try {
const renderer = createRenderer() as unknown as {
config: { preferredRenderBackend?: "webgl" | "webgpu" };
createPixiApplication: (
canvas: HTMLCanvasElement,
) => Promise<{ backend: "webgl" | "webgpu" }>;
};
delete renderer.config.preferredRenderBackend;

await expect(
renderer.createPixiApplication({} as HTMLCanvasElement),
).resolves.toMatchObject({
backend: "webgl",
});

expect(pixiApplicationInstancesMock).toHaveLength(1);
} finally {
vi.unstubAllGlobals();
}
});

it("falls back to webgpu when webgl initialization fails and no backend was requested", async () => {
pixiApplicationInstancesMock.length = 0;
pixiInitializationErrorsMock.length = 0;
pixiInitializationErrorsMock.push(new Error("WebGL initialization failed"), undefined);
vi.stubGlobal("navigator", { gpu: {} });

try {
const renderer = createRenderer() as unknown as {
config: { preferredRenderBackend?: "webgl" | "webgpu" };
createPixiApplication: (
canvas: HTMLCanvasElement,
) => Promise<{ backend: "webgl" | "webgpu" }>;
};
delete renderer.config.preferredRenderBackend;

await expect(
renderer.createPixiApplication({} as HTMLCanvasElement),
).resolves.toMatchObject({
backend: "webgpu",
});

expect(pixiApplicationInstancesMock).toHaveLength(2);
} finally {
vi.unstubAllGlobals();
}
});

it("continues to the next backend when failed-init cleanup would throw", async () => {
pixiApplicationInstancesMock.length = 0;
pixiInitializationErrorsMock.length = 0;
Expand Down
12 changes: 4 additions & 8 deletions src/lib/exporter/modernFrameRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import { buildTemporalSamplePlanUs, getTemporalMotionBlurConfig } from "./tempor

const TEMPORAL_ZOOM_MOTION_BLUR_ENABLED = false;

import { getDefaultLightningRenderBackend } from "./backendPolicy";
import type { ExportRenderBackend } from "./types";

Comment on lines 101 to 105
interface FrameRenderConfig {
Expand Down Expand Up @@ -639,15 +640,10 @@ export class FrameRenderer {
powerPreference: "high-performance" as const,
};

const preferredRenderBackend = this.config.preferredRenderBackend;
const preferredRenderBackend =
this.config.preferredRenderBackend ?? getDefaultLightningRenderBackend();
const backendOrder: ExportRenderBackend[] =
preferredRenderBackend === "webgl"
? ["webgl", "webgpu"]
: preferredRenderBackend === "webgpu"
? ["webgpu", "webgl"]
: typeof navigator !== "undefined" && "gpu" in navigator
? ["webgpu", "webgl"]
: ["webgl"];
preferredRenderBackend === "webgpu" ? ["webgpu", "webgl"] : ["webgl", "webgpu"];
Comment on lines +643 to +646
const failures: PixiRendererAttempt[] = [];

for (const backend of backendOrder) {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/exporter/modernVideoExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
} from "@/lib/wallpapers";
import { AudioProcessor, isAacAudioEncodingSupported } from "./audioEncoder";
import {
getDefaultLightningRenderBackend,
normalizeLightningRuntimePlatform,
shouldPreferNativeAutoBackend,
shouldPreferNativeStaticLayoutBeforeBreeze,
Expand Down Expand Up @@ -588,7 +589,8 @@ export class ModernVideoExporter {
this.renderer = new ModernFrameRenderer({
width: this.config.width,
height: this.config.height,
preferredRenderBackend: undefined,
preferredRenderBackend:
this.config.preferredRenderBackend ?? getDefaultLightningRenderBackend(),
wallpaper: this.config.wallpaper,
zoomRegions: this.config.zoomRegions,
showShadow: this.config.showShadow,
Expand Down