mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-07 01:56:04 +00:00
feat(engine): open drawElement fast capture to Windows hardware GPU
Widen the default-on drawElement clamp from darwin-only to darwin|win32 (still requiring a non-software-GPU browser). The darwin restriction was a validation envelope, not an architectural limit — the CanvasDrawElement Chrome flag ships on every platform, and every safety layer that made the macOS default-on release (v0.7.38) survivable is platform-neutral: compile-time gates, the SwiftShader init gate, per-render worker-encode self-verification with screenshot fallback, and the blank guard. Worst case on an unvalidated D3D11 backend is the same as on Metal: verify catches a bad frame and the render re-runs on the screenshot baseline. Why now: 30-day telemetry shows ~206k non-CI hardware-GPU Windows renders (~78% of the win32 fleet, 18k installs) held on the slow screenshot path by the clamp — the second-largest perf population after macOS, carrying ~1,550 capture-hours/month in the DE-eligible >=700-frame band alone at a measured ~2x speedup opportunity. Instrumentation for the new cohort: drawElement session init now records the raw WebGL UNMASKED_RENDERER_WEBGL string (detectSwiftShader generalized to detectGpuBackend — same single evaluate, the string was previously read and discarded) and threads it session -> CapturePerfSummary -> RenderPerfSummary -> render_complete as `gpu_renderer`. drawElement damage proved compositor-backend-specific throughout the macOS rollout, so D3D11-cohort failures must cluster by ANGLE backend + GPU vendor (NVIDIA/AMD/Intel), not just `os`. The two DE clamp branches are extracted into a pure, unit-tested `resolveDefaultDrawElement` (platform + GPU mode + worker-encode + explicit opt-in), which also drops resolveConfig's cyclomatic complexity. The win32 streaming-encode compound tests collapse onto one shared helper. Linux stays excluded: that fleet is headless/Docker SwiftShader, where DE has no speedup and known rendering defects. Kill switches unchanged: PRODUCER_EXPERIMENTAL_FAST_CAPTURE=false, --experimental-fast-capture=false. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
3c857d768b
commit
cb30157ebb
@@ -1,34 +1,49 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { Page } from "puppeteer-core";
|
||||
import { detectSwiftShader, resolveDrawElementCaptureMode } from "./drawElementService.js";
|
||||
import {
|
||||
detectGpuBackend,
|
||||
detectSwiftShader,
|
||||
resolveDrawElementCaptureMode,
|
||||
} from "./drawElementService.js";
|
||||
|
||||
// ── detectSwiftShader ──────────────────────────────────────────────────────────
|
||||
// ── detectGpuBackend / detectSwiftShader ───────────────────────────────────────
|
||||
|
||||
describe("detectSwiftShader", () => {
|
||||
describe("detectGpuBackend", () => {
|
||||
function makePage(evaluateResult: unknown): Page {
|
||||
return {
|
||||
evaluate: vi.fn().mockResolvedValue(evaluateResult),
|
||||
} as unknown as Page;
|
||||
}
|
||||
|
||||
it("returns true when renderer includes 'swiftshader'", async () => {
|
||||
const page = makePage(true);
|
||||
it("carries the raw renderer string alongside the SwiftShader verdict", async () => {
|
||||
const page = makePage({
|
||||
isSwiftShader: false,
|
||||
renderer: "ANGLE (NVIDIA, D3D11 vs_5_0 ps_5_0, D3D11)",
|
||||
});
|
||||
expect(await detectGpuBackend(page)).toEqual({
|
||||
isSwiftShader: false,
|
||||
renderer: "ANGLE (NVIDIA, D3D11 vs_5_0 ps_5_0, D3D11)",
|
||||
});
|
||||
});
|
||||
|
||||
it("reports null renderer when WebGL is unavailable", async () => {
|
||||
const page = makePage({ isSwiftShader: false, renderer: null });
|
||||
expect(await detectGpuBackend(page)).toEqual({ isSwiftShader: false, renderer: null });
|
||||
});
|
||||
|
||||
it("detectSwiftShader wrapper returns true when renderer is SwiftShader", async () => {
|
||||
const page = makePage({ isSwiftShader: true, renderer: "Google SwiftShader" });
|
||||
expect(await detectSwiftShader(page)).toBe(true);
|
||||
});
|
||||
|
||||
it("returns false for a standard GPU renderer string", async () => {
|
||||
const page = makePage(false);
|
||||
expect(await detectSwiftShader(page)).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false when WebGL is unavailable", async () => {
|
||||
const page = makePage(false);
|
||||
it("detectSwiftShader wrapper returns false for a hardware renderer", async () => {
|
||||
const page = makePage({ isSwiftShader: false, renderer: "ANGLE (Apple, ANGLE Metal)" });
|
||||
expect(await detectSwiftShader(page)).toBe(false);
|
||||
});
|
||||
|
||||
it("passes a function to page.evaluate", async () => {
|
||||
const page = makePage(false);
|
||||
await detectSwiftShader(page);
|
||||
const page = makePage({ isSwiftShader: false, renderer: null });
|
||||
await detectGpuBackend(page);
|
||||
expect(page.evaluate).toHaveBeenCalledWith(expect.any(Function));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -105,27 +105,50 @@ export function instrumentAcceleratedCanvases(): void {
|
||||
};
|
||||
}
|
||||
|
||||
export interface GpuBackendInfo {
|
||||
/** SwiftShader (software rasterizer) — e.g. Docker headless-shell. */
|
||||
isSwiftShader: boolean;
|
||||
/**
|
||||
* Raw UNMASKED_RENDERER_WEBGL string (e.g. "ANGLE (Apple, ANGLE Metal
|
||||
* Renderer: Apple M4 Pro, ...)", "ANGLE (NVIDIA, D3D11 ...)"), or null when
|
||||
* WebGL / the debug extension is unavailable. Carried to render telemetry:
|
||||
* drawElement failure modes proved compositor-backend-specific during the
|
||||
* macOS rollout, so the win32/D3D11 cohort needs damage clusters
|
||||
* attributable to a GPU vendor + ANGLE backend, not just `os`.
|
||||
*/
|
||||
renderer: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect whether the page is running on SwiftShader (software rasterizer).
|
||||
* Detect the page's WebGL backend: SwiftShader vs a real GPU, plus the raw
|
||||
* renderer string for telemetry.
|
||||
*
|
||||
* Returns true inside Docker headless-shell with --use-angle=swiftshader.
|
||||
* Returns false on macOS / Linux with a real GPU.
|
||||
* Call once after window.__hf is ready; cache result on session.
|
||||
* `isSwiftShader` is true inside Docker headless-shell with
|
||||
* --use-angle=swiftshader. Call once after window.__hf is ready; cache the
|
||||
* result on the session.
|
||||
*/
|
||||
export async function detectSwiftShader(page: Page): Promise<boolean> {
|
||||
return page.evaluate(() => {
|
||||
export async function detectGpuBackend(page: Page): Promise<GpuBackendInfo> {
|
||||
return page.evaluate((): GpuBackendInfo => {
|
||||
const canvas = document.createElement("canvas");
|
||||
const gl =
|
||||
canvas.getContext("webgl") ||
|
||||
(canvas.getContext("experimental-webgl") as WebGLRenderingContext | null);
|
||||
if (!gl) return false;
|
||||
if (!gl) return { isSwiftShader: false, renderer: null };
|
||||
const ext = gl.getExtension("WEBGL_debug_renderer_info");
|
||||
if (!ext) return false;
|
||||
if (!ext) return { isSwiftShader: false, renderer: null };
|
||||
const renderer = gl.getParameter(ext.UNMASKED_RENDERER_WEBGL) as string;
|
||||
return renderer.toLowerCase().includes("swiftshader");
|
||||
return { isSwiftShader: renderer.toLowerCase().includes("swiftshader"), renderer };
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Back-compat wrapper over {@link detectGpuBackend} for callers that only
|
||||
* need the SwiftShader boolean.
|
||||
*/
|
||||
export async function detectSwiftShader(page: Page): Promise<boolean> {
|
||||
return (await detectGpuBackend(page)).isSwiftShader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject a `<canvas layoutsubtree>` around the composition root.
|
||||
*
|
||||
|
||||
@@ -34,7 +34,7 @@ import {
|
||||
shouldDefaultCaptureBeyondViewport,
|
||||
} from "./screenshotService.js";
|
||||
import {
|
||||
detectSwiftShader,
|
||||
detectGpuBackend,
|
||||
injectDrawElementCanvas,
|
||||
captureDrawElementFrame,
|
||||
resolveDrawElementCaptureMode,
|
||||
@@ -146,6 +146,13 @@ export interface CaptureSession {
|
||||
config?: Partial<EngineConfig>;
|
||||
/** True if running on SwiftShader (detected at init). Undefined before init. */
|
||||
isSwiftShader?: boolean;
|
||||
/**
|
||||
* Raw WebGL UNMASKED_RENDERER_WEBGL string, captured alongside the
|
||||
* SwiftShader probe at DE session init (e.g. "ANGLE (NVIDIA, D3D11 ...)").
|
||||
* Surfaces in CapturePerfSummary → render telemetry so backend-specific
|
||||
* drawElement damage (Metal vs D3D11 vs GL) clusters attributably.
|
||||
*/
|
||||
gpuRenderer?: string;
|
||||
/** drawElementImage canvas was injected and is ready for capture. */
|
||||
drawElementReady?: boolean;
|
||||
/**
|
||||
@@ -704,7 +711,9 @@ async function initDrawElementOrTransparentBackground(
|
||||
);
|
||||
}
|
||||
if (useDrawElement) {
|
||||
session.isSwiftShader = await detectSwiftShader(page);
|
||||
const gpuBackend = await detectGpuBackend(page);
|
||||
session.isSwiftShader = gpuBackend.isSwiftShader;
|
||||
session.gpuRenderer = gpuBackend.renderer ?? undefined;
|
||||
const transparent = session.options.format === "png";
|
||||
async function routeToFallback(): Promise<void> {
|
||||
session.captureMode = session.launchCaptureMode;
|
||||
@@ -3784,6 +3793,7 @@ export function getCapturePerfSummary(session: CaptureSession): CapturePerfSumma
|
||||
beginFrameNoDamage: session.beginFrameNoDamageCount,
|
||||
beginFrameHasDamage: session.beginFrameHasDamageCount,
|
||||
captureMode: session.captureMode,
|
||||
gpuRenderer: session.gpuRenderer,
|
||||
deGateReason: session.deGateReason,
|
||||
deFallbackTrigger: session.deFallbackTrigger,
|
||||
deWorkerEncode: session.workerEncodeEnabled ?? false,
|
||||
|
||||
Reference in New Issue
Block a user