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:
Amp
2026-09-18 11:52:09 +00:00
co-authored by heaust
parent bc957cf40d
commit eb8aa0e9dc
21 changed files with 762 additions and 174 deletions
+10 -10
View File
@@ -34,12 +34,20 @@ const fxNodeImports = {
},
};
const coreWorker = await build({
...browser,
entryPoints: [path.join(root, "core", "worker.js")],
external: ["./pkg/yawn_core.js"],
write: false,
});
const coreWorkerSource = coreWorker.outputFiles[0].text;
const workerFiles = new Map([
[
path.join(root, "core", "index.js"),
{
url: "./worker.js",
source: await fs.readFile(path.join(root, "core", "worker.js"), "utf8"),
source: coreWorkerSource,
},
],
[
@@ -113,15 +121,7 @@ await Promise.all([
entryPoints: [path.join(fxNodeSource, "worker", "fxnode.worker.ts")],
outfile: path.join(output, "fxnode-worker.js"),
}),
build({
bundle: false,
entryPoints: [path.join(root, "core", "worker.js")],
format: "esm",
legalComments: "none",
minify: true,
outfile: path.join(output, "worker.js"),
target: "es2022",
}),
fs.writeFile(path.join(output, "worker.js"), coreWorkerSource),
build({
...browser,
entryPoints: [
+15 -10
View File
@@ -224,6 +224,7 @@ async function openFile(file) {
scene = new Scene(canvas, {
arenaBytes: 384 * 1024 * 1024,
hdr: true,
directToCanvas: true,
clearColor: [0.025, 0.035, 0.045, 1],
});
await scene.ready;
@@ -266,16 +267,20 @@ async function openFile(file) {
);
await Promise.all([...lights.map((light) => light.ready), camera.ready]);
elements.renderValue.textContent = "— ms";
elements.renderTime.hidden = false;
const stopProfile = scene.core.onProfile((profile) => {
elements.renderValue.textContent = `${profile.milliseconds.toFixed(2)} ms`;
});
const profiling = await scene.core.setProfiler(true);
if (!profiling)
elements.renderTime.title =
"GPU timestamp queries are not supported by this adapter.";
else elements.renderTime.removeAttribute("title");
// Diagnostic A/B: omit queries and readback, not just the timing badge.
let stopProfile;
if (new URLSearchParams(location.search).get("profile") !== "off") {
elements.renderValue.textContent = "— ms";
elements.renderTime.hidden = false;
stopProfile = scene.core.onProfile((profile) => {
elements.renderValue.textContent = `${profile.milliseconds.toFixed(2)} ms`;
});
const profiling = await scene.core.setProfiler(true);
if (!profiling)
elements.renderTime.title =
"GPU timestamp queries are not supported by this adapter.";
else elements.renderTime.removeAttribute("title");
}
activeViewer = {
camera,