Optimize viewer shaders and camera controls; sample GPU profiles asynchronously
Amp-Thread-ID: https://ampcode.com/threads/T-01a0b382-1e79-712b-abd1-d29201c9bb5e Co-authored-by: Heaust Azure <heaust.azure@gmail.com>
This commit is contained in:
+5
-6
@@ -1,7 +1,8 @@
|
||||
import initWasm, { Core } from "./pkg/yawn_core.js";
|
||||
import { SharedProfile } from "./profile.js";
|
||||
|
||||
let core;
|
||||
let profileTimer;
|
||||
let profile;
|
||||
// While a relocation is staged, every request except its commit waits here.
|
||||
let awaitingCommit = false;
|
||||
const queue = [];
|
||||
@@ -15,6 +16,8 @@ async function handle(message) {
|
||||
if (core || !(message.canvas instanceof OffscreenCanvas)) fail("INIT");
|
||||
const wasm = await initWasm();
|
||||
core = new Core(message.arenaBytes);
|
||||
profile = new SharedProfile(message.profileBuffer);
|
||||
core.on_profile(json => profile.write(json));
|
||||
await core.initialize(message.canvas);
|
||||
const buffer = wasm.memory.buffer;
|
||||
if (!(buffer instanceof SharedArrayBuffer)) fail("WASM_MEMORY_NOT_SHARED");
|
||||
@@ -70,11 +73,7 @@ async function handle(message) {
|
||||
break;
|
||||
case "set-profiler":
|
||||
result = core.set_profiler(Boolean(message.enabled));
|
||||
clearInterval(profileTimer);
|
||||
profileTimer = result && message.enabled ? setInterval(() => {
|
||||
const stats = core.take_profile();
|
||||
if (stats) postMessage({ type: "profile", stats: JSON.parse(stats) });
|
||||
}, 250) : undefined;
|
||||
profile.clear();
|
||||
break;
|
||||
default:
|
||||
fail("MESSAGE");
|
||||
|
||||
Reference in New Issue
Block a user