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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(render): the mode that actually stops the display from pacing a frame
esenginef2cabc911c71
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f9f8b241c..57f26a64c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -105,6 +105,27 @@ published separately; it ships inside the editor.to stop a list and its checks drifting apart; it cannot be a second place theversion is written.+- **A benched frame on Metal was the panel's, not the engine's.** The native+ host asks the swapchain to stop waiting for the display before it times+ anything, and the mode it picked was Mailbox — which every macOS surface+ advertises, and which Dawn's Metal backend leaves display-synced:+ `SwapChainMTL.mm` clears `displaySyncEnabled` for Immediate ALONE. So the+ request succeeded and changed nothing.++ Nothing said so, because a throttled frame reads as a frame that cost the+ refresh interval. Every span came back at 16.6 ms whatever was in the scene —+ 200 entities or 2,000, one draw or none — and the interpreted and compiled+ builds of the AOT benchmark read 1.00x apart, which the gate reported as a+ compiled system falling back to the interpreter. What settled it was the+ process's own clocks: 6.25 s of wall for 0.69 s of CPU, so the frame was+ WAITING for 89% of itself.++ Immediate is preferred over Mailbox now, and the order is load-bearing rather+ than a taste: tearing is exactly what a measurement is buying. The same frame+ reads 3.03 ms, and the AOT ratio 9.3x. The configure step also says which mode+ it was actually granted, because a fallback here makes a number wrong rather+ than absent.+- **Three release criteria could not pass on a Mac, and one of them blamed theengine for it.** `verify-aot-native` and the native frame bench both locatedthe app they had just exported by searching it for "a file with no extension".diff --git a/src/esengine/renderer/webgpu/WebGPUDevice.cpp b/src/esengine/renderer/webgpu/WebGPUDevice.cppindex 60440a0e8..cc4cb29c9 100644--- a/src/esengine/renderer/webgpu/WebGPUDevice.cpp+++ b/src/esengine/renderer/webgpu/WebGPUDevice.cpp@@ -393,9 +393,14 @@ bool WebGPUDevice::surfaceBytesAreBGRA() const {/*** The fastest present mode this surface actually advertises.*- * Mailbox first: it drops finished frames rather than blocking the CPU, and does- * not tear. Immediate tears, which a measurement does not care about. Fifo is the- * fallback, and then the caller's frame is throttled.+ * Immediate FIRST, and the order is load-bearing rather than a preference: this+ * mode exists so a frame can be timed, and Dawn's Metal backend clears+ * `displaySyncEnabled` for Immediate ALONE (`SwapChainMTL.mm`). A surface that+ * offers both hands back a Mailbox that is still vsynced, so the bench reads the+ * panel — measured here as every span pinned to 16.6 ms while the process sat+ * blocked for 89% of its wall clock. Tearing is what the caller is buying.+ *+ * Fifo is the fallback, and then the caller's frame is throttled.*/WGPUPresentMode WebGPUDevice::pickUncappedPresentMode() const {#if !defined(__EMSCRIPTEN__)@@ -404,11 +409,11 @@ WGPUPresentMode WebGPUDevice::pickUncappedPresentMode() const {if (wgpuSurfaceGetCapabilities(surface_, adapter_, &caps) == WGPUStatus_Success) {WGPUPresentMode chosen = WGPUPresentMode_Fifo;for (size_t i = 0; i < caps.presentModeCount; ++i) {- if (caps.presentModes[i] == WGPUPresentMode_Mailbox) {- chosen = WGPUPresentMode_Mailbox;+ if (caps.presentModes[i] == WGPUPresentMode_Immediate) {+ chosen = WGPUPresentMode_Immediate;break;}- if (caps.presentModes[i] == WGPUPresentMode_Immediate) chosen = WGPUPresentMode_Immediate;+ if (caps.presentModes[i] == WGPUPresentMode_Mailbox) chosen = WGPUPresentMode_Mailbox;}wgpuSurfaceCapabilitiesFreeMembers(caps);return chosen;@@ -465,6 +470,15 @@ bool WebGPUDevice::configureSwapchain(u32 width, u32 height) {// game should want. setPresentUncapped asks for a measurable frame instead —// see its comment for why a vsynced one cannot be measured.cfg.presentMode = present_uncapped_ ? pickUncappedPresentMode() : WGPUPresentMode_Fifo;+ // Said out loud, because a fallback here makes a measurement WRONG rather than+ // absent: a frame that was throttled reads as the refresh interval, and the+ // bench consuming it cannot tell that from a frame that cost that much.+ if (present_uncapped_) {+ ES_LOG_WARN("WebGPUDevice: uncapped present asked for, surface gave {}",+ cfg.presentMode == WGPUPresentMode_Immediate ? "Immediate"+ : cfg.presentMode == WGPUPresentMode_Mailbox ? "Mailbox — still vsynced on Metal"+ : "Fifo — the frame IS the refresh interval");+ }wgpuSurfaceConfigure(surface_, &cfg);surface_width_ = width;surface_height_ = height;