Skip to content

Commit

Permalink
use correct timing-helper.js
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed May 28, 2024
1 parent e1c8fc5 commit fdcea4f
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 131 deletions.
20 changes: 20 additions & 0 deletions webgpu/resources/js/rolling-average.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// See https://webgpufundamentals.org/webgpu/lessons/webgpu-timing.html
export default class RollingAverage {
#total = 0;
#samples = [];
#cursor = 0;
#numSamples;
constructor(numSamples = 30) {
this.#numSamples = numSamples;
}
addSample(v) {
if (!Number.isNaN(v) && Number.isFinite(v)) {
this.#total += v - (this.#samples[this.#cursor] || 0);
this.#samples[this.#cursor] = v;
this.#cursor = (this.#cursor + 1) % this.#numSamples;
}
}
get() {
return this.#total / this.#samples.length;
}
}
1 change: 1 addition & 0 deletions webgpu/resources/js/timing-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ function assert(cond, msg = '') {
}
}

// See https://webgpufundamentals.org/webgpu/lessons/webgpu-timing.html
export default class TimingHelper {
#canTimestamp;
#device;
Expand Down
121 changes: 0 additions & 121 deletions webgpu/timing-helper.js

This file was deleted.

5 changes: 4 additions & 1 deletion webgpu/webgpu-optimization-all.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
<script type="module">
import GUI from '../3rdparty/muigui-0.x.module.js';
import {mat4, mat3, vec3} from '../3rdparty/wgpu-matrix.module.js';
import {RollingAverage, TimingHelper} from './timing-helper.js';
// see https://webgpufundamentals.org/webgpu/lessons/webgpu-timing.html
import TimingHelper from './resources/js/timing-helper.js';
// see https://webgpufundamentals.org/webgpu/lessons/webgpu-timing.html
import RollingAverage from './resources/js/rolling-average.js';

const fpsAverage = new RollingAverage();
const jsAverage = new RollingAverage();
Expand Down
5 changes: 4 additions & 1 deletion webgpu/webgpu-optimization-none.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
<script type="module">
import GUI from '../3rdparty/muigui-0.x.module.js';
import {mat4, mat3, vec3} from '../3rdparty/wgpu-matrix.module.js';
import {RollingAverage, TimingHelper} from './timing-helper.js';
// see https://webgpufundamentals.org/webgpu/lessons/webgpu-timing.html
import TimingHelper from './resources/js/timing-helper.js';
// see https://webgpufundamentals.org/webgpu/lessons/webgpu-timing.html
import RollingAverage from './resources/js/rolling-average.js';

const fpsAverage = new RollingAverage();
const jsAverage = new RollingAverage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
<script type="module">
import GUI from '../3rdparty/muigui-0.x.module.js';
import {mat4, mat3, vec3} from '../3rdparty/wgpu-matrix.module.js';
import {RollingAverage, TimingHelper} from './timing-helper.js';
// see https://webgpufundamentals.org/webgpu/lessons/webgpu-timing.html
import TimingHelper from './resources/js/timing-helper.js';
// see https://webgpufundamentals.org/webgpu/lessons/webgpu-timing.html
import RollingAverage from './resources/js/rolling-average.js';

const fpsAverage = new RollingAverage();
const jsAverage = new RollingAverage();
Expand Down
5 changes: 4 additions & 1 deletion webgpu/webgpu-optimization-step4-material-uniforms.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
<script type="module">
import GUI from '../3rdparty/muigui-0.x.module.js';
import {mat4, mat3, vec3} from '../3rdparty/wgpu-matrix.module.js';
import {RollingAverage, TimingHelper} from './timing-helper.js';
// see https://webgpufundamentals.org/webgpu/lessons/webgpu-timing.html
import TimingHelper from './resources/js/timing-helper.js';
// see https://webgpufundamentals.org/webgpu/lessons/webgpu-timing.html
import RollingAverage from './resources/js/rolling-average.js';

const fpsAverage = new RollingAverage();
const jsAverage = new RollingAverage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
<script type="module">
import GUI from '../3rdparty/muigui-0.x.module.js';
import {mat4, mat3, vec3} from '../3rdparty/wgpu-matrix.module.js';
import {RollingAverage, TimingHelper} from './timing-helper.js';
// see https://webgpufundamentals.org/webgpu/lessons/webgpu-timing.html
import TimingHelper from './resources/js/timing-helper.js';
// see https://webgpufundamentals.org/webgpu/lessons/webgpu-timing.html
import RollingAverage from './resources/js/rolling-average.js';

const fpsAverage = new RollingAverage();
const jsAverage = new RollingAverage();
Expand Down
5 changes: 4 additions & 1 deletion webgpu/webgpu-optimization-step5-use-buffer-offsets.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
<script type="module">
import GUI from '../3rdparty/muigui-0.x.module.js';
import {mat4, mat3, vec3} from '../3rdparty/wgpu-matrix.module.js';
import {RollingAverage, TimingHelper} from './timing-helper.js';
// see https://webgpufundamentals.org/webgpu/lessons/webgpu-timing.html
import TimingHelper from './resources/js/timing-helper.js';
// see https://webgpufundamentals.org/webgpu/lessons/webgpu-timing.html
import RollingAverage from './resources/js/rolling-average.js';

const fpsAverage = new RollingAverage();
const jsAverage = new RollingAverage();
Expand Down
5 changes: 4 additions & 1 deletion webgpu/webgpu-optimization-step6-use-mapped-buffers.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
<script type="module">
import GUI from '../3rdparty/muigui-0.x.module.js';
import {mat4, mat3, vec3} from '../3rdparty/wgpu-matrix.module.js';
import {RollingAverage, TimingHelper} from './timing-helper.js';
// see https://webgpufundamentals.org/webgpu/lessons/webgpu-timing.html
import TimingHelper from './resources/js/timing-helper.js';
// see https://webgpufundamentals.org/webgpu/lessons/webgpu-timing.html
import RollingAverage from './resources/js/rolling-average.js';

const fpsAverage = new RollingAverage();
const jsAverage = new RollingAverage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
<script type="module">
import GUI from '../3rdparty/muigui-0.x.module.js';
import {mat4, mat3, vec3} from '../3rdparty/wgpu-matrix.module.js';
import {RollingAverage, TimingHelper} from './timing-helper.js';
// see https://webgpufundamentals.org/webgpu/lessons/webgpu-timing.html
import TimingHelper from './resources/js/timing-helper.js';
// see https://webgpufundamentals.org/webgpu/lessons/webgpu-timing.html
import RollingAverage from './resources/js/rolling-average.js';

const fpsAverage = new RollingAverage();
const jsAverage = new RollingAverage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
<script type="module">
import GUI from '../3rdparty/muigui-0.x.module.js';
import {mat4, mat3, vec3} from '../3rdparty/wgpu-matrix.module.js';
import {RollingAverage, TimingHelper} from './timing-helper.js';
// see https://webgpufundamentals.org/webgpu/lessons/webgpu-timing.html
import TimingHelper from './resources/js/timing-helper.js';
// see https://webgpufundamentals.org/webgpu/lessons/webgpu-timing.html
import RollingAverage from './resources/js/rolling-average.js';

const fpsAverage = new RollingAverage();
const jsAverage = new RollingAverage();
Expand Down
5 changes: 4 additions & 1 deletion webgpu/webgpu-optimization-step7-double-buffer.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
<script type="module">
import GUI from '../3rdparty/muigui-0.x.module.js';
import {mat4, mat3, vec3} from '../3rdparty/wgpu-matrix.module.js';
import {RollingAverage, TimingHelper} from './timing-helper.js';
// see https://webgpufundamentals.org/webgpu/lessons/webgpu-timing.html
import TimingHelper from './resources/js/timing-helper.js';
// see https://webgpufundamentals.org/webgpu/lessons/webgpu-timing.html
import RollingAverage from './resources/js/rolling-average.js';

const fpsAverage = new RollingAverage();
const jsAverage = new RollingAverage();
Expand Down

0 comments on commit fdcea4f

Please sign in to comment.