Benchmark
This commit is contained in:
@@ -8,6 +8,8 @@ import { profiler, type SectionStats } from "$/client/profiler.ts";
|
||||
import { canvas, gpu_timer, render_debug, render_stats } from "$/client/renderer/mod.ts";
|
||||
import { RENDER_LAYERS } from "$/common/everything_registry.ts";
|
||||
import { atlas_png } from "$/client/atlas.ts";
|
||||
import { RenderBenchmark } from "$/client/benchmark/benchmark.ts";
|
||||
import { format_report } from "$/client/benchmark/report.ts";
|
||||
|
||||
// how often the totals that go through every chunk are worked out again, so the overlay doesn't slow the frames it's
|
||||
// measuring
|
||||
@@ -17,6 +19,9 @@ const CHUNK_STATS_MS = 1000;
|
||||
export class DebugOverlay {
|
||||
#chunk_stats = { meshed: 0, bytes: 0 };
|
||||
#chunk_stats_time = -Infinity;
|
||||
// the last benchmark's, see client/benchmark/
|
||||
#benchmark_report: string | undefined;
|
||||
#benchmark_status = "";
|
||||
|
||||
render(client: Client) {
|
||||
this.#render_performance(client);
|
||||
@@ -54,6 +59,9 @@ export class DebugOverlay {
|
||||
|
||||
DebugUI.begin("Performance", 320, 10, 340, 600);
|
||||
const copy = DebugUI.button("Copy");
|
||||
if (DebugUI.button("Run the render benchmark")) this.#start_benchmark(client);
|
||||
if (this.#benchmark_report && DebugUI.button("Copy the benchmark's results")) this.#copy_benchmark();
|
||||
if (this.#benchmark_status) DebugUI.text(this.#benchmark_status);
|
||||
// what's shown, for the copy button
|
||||
const lines: string[] = [];
|
||||
const text = (line: string) => {
|
||||
@@ -104,10 +112,36 @@ export class DebugOverlay {
|
||||
if (copy) {
|
||||
const switches = { ...render_debug, ...level_renderer.draw };
|
||||
lines.push(Object.entries(switches).map(([key, on]) => ` ${key}: ${on}`).join("\n"));
|
||||
navigator.clipboard?.writeText(lines.join("\n")).catch(() => {});
|
||||
copy_text(lines.join("\n")).catch(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
#start_benchmark(client: Client) {
|
||||
try {
|
||||
client.benchmark = new RenderBenchmark(client.game_renderer, client.connection.mods, (result) => {
|
||||
client.benchmark = undefined;
|
||||
if (typeof result === "string") {
|
||||
this.#benchmark_status = result;
|
||||
return;
|
||||
}
|
||||
this.#benchmark_report = format_report(result);
|
||||
console.log(this.#benchmark_report);
|
||||
this.#copy_benchmark();
|
||||
});
|
||||
this.#benchmark_status = "";
|
||||
} catch (e) {
|
||||
this.#benchmark_status = e instanceof Error ? e.message : String(e);
|
||||
}
|
||||
}
|
||||
|
||||
// right after the benchmark, firefox and safari only let the page copy from a click
|
||||
#copy_benchmark() {
|
||||
copy_text(this.#benchmark_report!).then(
|
||||
() => this.#benchmark_status = "The benchmark's results are on the clipboard",
|
||||
() => this.#benchmark_status = "Click above to copy the benchmark's results",
|
||||
);
|
||||
}
|
||||
|
||||
// meshed chunks and what their meshes take on the gpu, once a second
|
||||
#count_chunks(client: Client) {
|
||||
const now = performance.now();
|
||||
@@ -146,3 +180,16 @@ export class DebugOverlay {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// pages that aren't https or localhost have no clipboard api, like a server on another computer, but the old way
|
||||
// still copies from a click
|
||||
function copy_text(text: string): Promise<void> {
|
||||
if (navigator.clipboard) return navigator.clipboard.writeText(text);
|
||||
const area = document.createElement("textarea");
|
||||
area.value = text;
|
||||
document.body.append(area);
|
||||
area.select();
|
||||
const copied = document.execCommand("copy");
|
||||
area.remove();
|
||||
return copied ? Promise.resolve() : Promise.reject(new Error("Couldn't copy"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user