Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(editor): show per-pass GPU times in the frame breakdown

esenginea8476ea01a5b
diff --git a/desktop/src/components/PerfRealmBridge.tsx b/desktop/src/components/PerfRealmBridge.tsx
index 2b8af701b..175b0d55e 100644
--- a/desktop/src/components/PerfRealmBridge.tsx
+++ b/desktop/src/components/PerfRealmBridge.tsx
@@ -25,7 +25,7 @@ export function PerfRealmBridge() {
const s = await PlayRealm.stats();
if (!alive) return;
cache = s
- ? { phaseMs: s.phases, systemMs: s.systems, drawCalls: s.drawCalls, triangles: s.triangles, sprites: s.sprites, entities: s.entities, gpuMs: s.gpuMs, cppScopes: s.cppScopes, cppCounters: s.cppCounters, wasmBytes: s.wasmBytes, vramBytes: s.vramBytes }
+ ? { phaseMs: s.phases, systemMs: s.systems, drawCalls: s.drawCalls, triangles: s.triangles, sprites: s.sprites, entities: s.entities, gpuMs: s.gpuMs, cppScopes: s.cppScopes, cppCounters: s.cppCounters, gpuScopes: s.gpuScopes, wasmBytes: s.wasmBytes, vramBytes: s.vramBytes }
: null;
};
void poll();
diff --git a/desktop/src/engine/EngineHost.ts b/desktop/src/engine/EngineHost.ts
index c0d194a9e..b4b7f98a9 100644
--- a/desktop/src/engine/EngineHost.ts
+++ b/desktop/src/engine/EngineHost.ts
@@ -119,6 +119,7 @@ class EngineHostImpl {
gpuMs: number;
cppScopes: Record<string, number>;
cppCounters: Record<string, number>;
+ gpuScopes: Record<string, number>;
wasmBytes: number;
vramBytes: number;
} | null {
@@ -137,6 +138,11 @@ class EngineHostImpl {
if (countersJson) {
try { cppCounters = JSON.parse(countersJson) as Record<string, number>; } catch { /* ignore */ }
}
+ let gpuScopes: Record<string, number> = {};
+ const gpuJson = m?.engine_getGpuScopes?.();
+ if (gpuJson) {
+ try { gpuScopes = JSON.parse(gpuJson) as Record<string, number>; } catch { /* ignore */ }
+ }
return {
phaseMs: phases ? Object.fromEntries(phases) : {},
systemMs: systems ? Object.fromEntries(systems) : {},
@@ -147,6 +153,7 @@ class EngineHostImpl {
gpuMs: m?.renderer_getGpuTimeMs?.() ?? -1,
cppScopes,
cppCounters,
+ gpuScopes,
wasmBytes: m?.HEAPU8?.byteLength ?? 0,
vramBytes: m?.renderer_getTextureBytes?.() ?? 0,
};
diff --git a/desktop/src/engine/PerfMonitor.ts b/desktop/src/engine/PerfMonitor.ts
index 715b93217..5dad7a901 100644
--- a/desktop/src/engine/PerfMonitor.ts
+++ b/desktop/src/engine/PerfMonitor.ts
@@ -51,6 +51,8 @@ export interface EngineFrame {
cppScopes: Record<string, number>;
/** Per-frame C++ named counters (culled, cache hits, …). */
cppCounters: Record<string, number>;
+ /** Per-frame per-pass GPU times (submit, postprocess), name → ms. */
+ gpuScopes: Record<string, number>;
/** Total wasm linear memory (bytes) — the engine's heap. */
wasmBytes: number;
/** Resident texture VRAM (bytes, estimate). */
@@ -70,6 +72,7 @@ export interface FrameSample {
editorPhases: Record<string, number>;
enginePhases: Record<string, number>;
cppScopes: Record<string, number>;
+ gpuScopes: Record<string, number>;
counters: Record<string, number>;
systems: Array<{ name: string; ms: number }>;
drawCalls: number;
@@ -328,11 +331,13 @@ class PerfMonitorImpl {
let engineFrameMs = 0;
let enginePhases: Record<string, number> = {};
let cppScopes: Record<string, number> = {};
+ let gpuScopes: Record<string, number> = {};
let engineCounters: Record<string, number> = {};
let systemsFrame: Array<{ name: string; ms: number }> = [];
if (ef) {
enginePhases = ef.phaseMs;
cppScopes = ef.cppScopes;
+ gpuScopes = ef.gpuScopes;
engineCounters = ef.cppCounters;
engineFrameMs = sumMs(enginePhases);
this.engineSum += engineFrameMs;
@@ -357,6 +362,7 @@ class PerfMonitorImpl {
editorPhases: { ...editorPhases },
enginePhases: { ...enginePhases },
cppScopes: { ...cppScopes },
+ gpuScopes: { ...gpuScopes },
counters: { ...engineCounters, ...editorCounters },
systems: systemsFrame,
drawCalls: this.counters.drawCalls,
diff --git a/desktop/src/engine/playProtocol.ts b/desktop/src/engine/playProtocol.ts
index df57f506a..ad876da13 100644
--- a/desktop/src/engine/playProtocol.ts
+++ b/desktop/src/engine/playProtocol.ts
@@ -67,6 +67,7 @@ export interface PlayStatsReply {
gpuMs: number;
cppScopes: Record<string, number>;
cppCounters: Record<string, number>;
+ gpuScopes: Record<string, number>;
wasmBytes: number;
vramBytes: number;
}
diff --git a/desktop/src/panels/ProfilerPanel.tsx b/desktop/src/panels/ProfilerPanel.tsx
index 0df06b456..6b8c74ede 100644
--- a/desktop/src/panels/ProfilerPanel.tsx
+++ b/desktop/src/panels/ProfilerPanel.tsx
@@ -202,6 +202,7 @@ export function ProfilerPanel() {
...Object.entries(pinned.editorPhases),
...Object.entries(pinned.enginePhases).map(([n, m]) => [`engine.${n}`, m] as [string, number]),
...Object.entries(pinned.cppScopes).map(([n, m]) => [`cpp.${n}`, m] as [string, number]),
+ ...Object.entries(pinned.gpuScopes).map(([n, m]) => [`gpu.${n}`, m] as [string, number]),
]
.filter(([, ms]) => ms >= 0.1)
.sort((a, b) => b[1] - a[1])
diff --git a/desktop/src/playHost.ts b/desktop/src/playHost.ts
index b9866da86..67adf94c5 100644
--- a/desktop/src/playHost.ts
+++ b/desktop/src/playHost.ts
@@ -347,6 +347,7 @@ window.addEventListener('message', (e: MessageEvent) => {
gpuMs: m?.renderer_getGpuTimeMs?.() ?? -1,
cppScopes: jsonMap(m?.engine_getCpuScopes?.()),
cppCounters: jsonMap(m?.engine_getCounters?.()),
+ gpuScopes: jsonMap(m?.engine_getGpuScopes?.()),
wasmBytes: m?.HEAPU8?.byteLength ?? 0,
vramBytes: m?.renderer_getTextureBytes?.() ?? 0,
},