Benchmark
This commit is contained in:
@@ -17,6 +17,9 @@ export class GpuTimer {
|
||||
// ms per frame by label, averaged over the last window
|
||||
results = new Map<string, number>();
|
||||
total = 0;
|
||||
// every timed frame's total, while something reads them, like the benchmark. a frame goes to the array that was
|
||||
// here when it was submitted, however late its time comes back
|
||||
samples: number[] | undefined;
|
||||
|
||||
#device: GPUDevice;
|
||||
#query_set: GPUQuerySet | undefined;
|
||||
@@ -82,16 +85,20 @@ export class GpuTimer {
|
||||
this.#free.push(buffer);
|
||||
return;
|
||||
}
|
||||
const samples = this.samples;
|
||||
buffer.mapAsync(GPUMapMode.READ, 0, labels.length * 16).then(() => {
|
||||
const times = new BigUint64Array(buffer.getMappedRange(0, labels.length * 16));
|
||||
const frame = new Map<string, number>();
|
||||
let total = 0;
|
||||
labels.forEach((label, i) => {
|
||||
const ms = Math.max(0, Number(times[i * 2 + 1] - times[i * 2])) / 1e6;
|
||||
frame.set(label, (frame.get(label) ?? 0) + ms);
|
||||
total += ms;
|
||||
});
|
||||
buffer.unmap();
|
||||
this.#free.push(buffer);
|
||||
this.#add_frame(frame);
|
||||
samples?.push(total);
|
||||
}).catch(() => {
|
||||
// the device was lost, nothing to time anymore
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user