Skip to content

Commit

Permalink
Merge pull request #22 from WebGPU-Art/perf-now
Browse files Browse the repository at this point in the history
try performance.now() for stabler results
  • Loading branch information
NoEgAm authored Nov 25, 2024
2 parents 66e3358 + 425f907 commit 42be19d
Show file tree
Hide file tree
Showing 26 changed files with 146 additions and 144 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/upload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ jobs:
node-version: 20
cache: "yarn"

- uses: calcit-lang/[email protected]
with:
bundler: false
- uses: calcit-lang/[email protected]

- name: "compiles calcit to js"
run: caps --ci && cr -1 js
Expand Down
1 change: 1 addition & 0 deletions package.cirru → deps.cirru
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

{}
:calcit-version |0.9.6
:dependencies $ {}
|calcit-lang/lilac |main
|calcit-lang/memof |main
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"@webgpu/types": "^0.1.51",
"bottom-tip": "^0.1.5",
"query-string": "^9.1.1",
"typescript": "^5.6.3",
"typescript": "^5.7.2",
"vite": "^5.4.11"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/apps/attractor/aizawa.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export let loadRenderer = async (canvas: HTMLCanvasElement) => {
seedSize,
seedData: makeSeed(seedSize, 0),
getParams: (dt) => [
dt * 0.04, // deltaT
dt * 12, // deltaT
600.0, // scale
0.001, // width
0.99, // opacity
Expand Down
2 changes: 1 addition & 1 deletion src/apps/attractor/bouali.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn main(@builtin(global_invocation_id) GlobalInvocationID: vec3<u32>) {
return;
}

let ret = bouali(v_pos, params.delta_t * 0.01);
let ret = bouali(v_pos, params.delta_t * 1.);

// Write back
particles_b.particles[index].pos = ret.position;
Expand Down
2 changes: 1 addition & 1 deletion src/apps/attractor/burke-shaw.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export let loadRenderer = async (canvas: HTMLCanvasElement) => {
seedSize,
seedData: makeSeed(seedSize, 0),
getParams: (dt) => [
dt * 0.04, // deltaT
dt * 2, // deltaT
20.0, // scale
0.008, // width
0.99, // opacity
Expand Down
2 changes: 1 addition & 1 deletion src/apps/attractor/chen.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export let loadRenderer = async (canvas: HTMLCanvasElement) => {
seedSize,
seedData: makeSeed(seedSize, 0),
getParams: (dt) => [
dt * 0.04, // deltaT
dt * 2, // deltaT
20.0, // scale
0.008, // width
0.99, // opacity
Expand Down
2 changes: 1 addition & 1 deletion src/apps/attractor/dadras.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export let loadRenderer = async (canvas: HTMLCanvasElement) => {
seedSize,
seedData: makeSeed(seedSize, 0),
getParams: (dt) => [
dt * 0.04, // deltaT
dt * 0.4, // deltaT
20.0, // scale
0.008, // width
0.99, // opacity
Expand Down
2 changes: 1 addition & 1 deletion src/apps/attractor/den-tsucs.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export let loadRenderer = async (canvas: HTMLCanvasElement) => {
seedSize,
seedData: makeSeed(seedSize, 0),
getParams: (dt) => [
dt * 0.0003, // deltaT
dt * 0.1, // deltaT
20.0, // scale
0.008, // width
0.99, // opacity
Expand Down
2 changes: 1 addition & 1 deletion src/apps/attractor/dequanli.mts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export let loadRenderer = async (canvas: HTMLCanvasElement) => {
seedData: makeSeed(seedSize, 0),
getParams: (dt) => {
return [
dt * 0.04, // deltaT
dt * 4, // deltaT
20.0, // scale
0.008, // width
0.99, // opacity
Expand Down
2 changes: 1 addition & 1 deletion src/apps/attractor/fourwing.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export let loadRenderer = async (canvas: HTMLCanvasElement) => {
seedSize,
seedData: makeSeed(seedSize, 0),
getParams: (dt) => [
dt * 0.04, // deltaT
dt * 40, // deltaT
100.0, // scale
0.004, // width
0.99, // opacity
Expand Down
2 changes: 1 addition & 1 deletion src/apps/attractor/halvorsen.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export let loadRenderer = async (canvas: HTMLCanvasElement) => {
seedSize,
seedData: makeSeed(seedSize, 0),
getParams: (dt) => [
dt * 0.04, // deltaT
dt * 12, // deltaT
600.0, // scale
0.001, // width
0.99, // opacity
Expand Down
2 changes: 1 addition & 1 deletion src/apps/attractor/lorenz.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn main(@builtin(global_invocation_id) GlobalInvocationID: vec3<u32>) {
return;
}

let ret = lorenz(v_pos, params.delta_t * 0.0012 * (2. + 2. * rand(f32(index))));
let ret = lorenz(v_pos, params.delta_t * 0.12 * (2. + 2. * rand(f32(index))));
// let ret = four_wing(v_pos, params.delta_t * 0.01 * (20. + 2. * rand(f32(index))));
// let ret = aizawa(v_pos, params.delta_t * 0.001 * (12. + 4. * rand(f32(index))));

Expand Down
2 changes: 1 addition & 1 deletion src/apps/attractor/lorenz83.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export let loadRenderer = async (canvas: HTMLCanvasElement) => {
seedSize,
seedData: makeSeed(seedSize, 0),
getParams: (dt) => [
dt * 0.04, // deltaT
dt * 8, // deltaT
600.0, // scale
0.001, // width
0.99, // opacity
Expand Down
2 changes: 1 addition & 1 deletion src/apps/attractor/sprott.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export let loadRenderer = async (canvas: HTMLCanvasElement) => {
seedSize,
seedData: makeSeed(seedSize, 0),
getParams: (dt) => [
dt * 0.04, // deltaT
dt * 4, // deltaT
600.0, // scale
0.001, // width
0.99, // opacity
Expand Down
2 changes: 1 addition & 1 deletion src/apps/ball-spin.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export let loadRenderer = async (canvas: HTMLCanvasElement) => {
seedSize,
seedData: makeSeed(seedSize, 0),
getParams: (dt) => [
dt * 0.004, // deltaT
dt * 0.2, // deltaT
0.6, // height
0.2, // width
0.8, // opacity
Expand Down
2 changes: 1 addition & 1 deletion src/apps/bounce-trail.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export let loadRenderer = async (canvas: HTMLCanvasElement) => {
seedSize,
seedData: makeSeed(seedSize, 0),
getParams: (dt) => [
dt * 0.002, // deltaT
dt * 0.1, // deltaT
0.6, // height
0.2, // width
0.8, // opacity
Expand Down
2 changes: 1 addition & 1 deletion src/apps/bounce.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export let loadRenderer = async (canvas: HTMLCanvasElement) => {
seedSize,
seedData: makeSeed(seedSize, 0),
getParams: (dt) => [
dt * 0.004, // deltaT
dt * 0.1, // deltaT
0.6, // height
0.2, // width
0.8, // opacity
Expand Down
2 changes: 1 addition & 1 deletion src/apps/collision.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export let loadRenderer = async (canvas: HTMLCanvasElement) => {
seedSize,
seedData: makeSeed(seedSize, 0),
getParams: (dt) => [
dt * 0.004, // deltaT
dt * 0.4, // deltaT
0.6, // height
0.2, // width
0.8, // opacity
Expand Down
2 changes: 1 addition & 1 deletion src/apps/feday.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export let loadRenderer = async (canvas: HTMLCanvasElement) => {
seedSize,
seedData: makeSeed(seedSize, 0),
getParams: (dt) => [
dt * 0.004, // deltaT
dt * 0.1, // deltaT
0.6, // height
0.2, // width
0.8, // opacity
Expand Down
2 changes: 1 addition & 1 deletion src/apps/fireworks.mts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export let loadRenderer = async (canvas: HTMLCanvasElement) => {
seedSize,
seedData: makeSeed(seedSize, 0),
getParams: (dt) => [
dt * 0.004, // deltaT
dt * 4, // deltaT
0.6, // height
0.2, // width
0.8, // opacity
Expand Down
2 changes: 1 addition & 1 deletion src/apps/lamps.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export let loadRenderer = async (canvas: HTMLCanvasElement) => {
seedSize,
seedData: makeSeed(seedSize, 0),
getParams: (dt) => [
dt * 0.004, // deltaT
dt * 0.2, // deltaT
0.6, // height
0.2, // width
0.8, // opacity
Expand Down
2 changes: 1 addition & 1 deletion src/apps/orbit-spark.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export let loadRenderer = async (canvas: HTMLCanvasElement) => {
seedSize,
seedData: makeSeed(seedSize, 0),
getParams: (dt) => [
dt * 0.04, // deltaT
dt * 4, // deltaT
600.0, // scale
0.001, // width
0.99, // opacity
Expand Down
11 changes: 7 additions & 4 deletions src/render.mts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@ export let createRenderer = async (
seedSize
);

return async function render(t: number, skipComputing: boolean = false) {
return async function render(
loopTimes: number,
skipComputing: boolean = false
) {
let paramsData = computeOptions.getParams(ticker.ticked());

let paramBuffer = buildParamBuffer(paramsData);
Expand Down Expand Up @@ -295,7 +298,7 @@ export let createRenderer = async (
entries: uniformEntries,
})
);
computePassEncoder.setBindGroup(1, particleBindGroups[t % 2]);
computePassEncoder.setBindGroup(1, particleBindGroups[loopTimes % 2]);
computePassEncoder.dispatchWorkgroups(Math.ceil(numParticles / 64));
computePassEncoder.end();
}
Expand All @@ -309,7 +312,7 @@ export let createRenderer = async (

const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);
passEncoder.setPipeline(renderPipeline);
passEncoder.setVertexBuffer(0, particleBuffers[(t + 1) % 2]);
passEncoder.setVertexBuffer(0, particleBuffers[(loopTimes + 1) % 2]);
passEncoder.setVertexBuffer(1, buildSpriteVertexBuffer(vertexData));
passEncoder.setBindGroup(
0,
Expand All @@ -320,7 +323,7 @@ export let createRenderer = async (
entries: uniformEntries,
})
);
passEncoder.setBindGroup(1, mockedBindGroups[t % 2]); // mocked
passEncoder.setBindGroup(1, mockedBindGroups[loopTimes % 2]); // mocked

if (indexBuffer != null) {
passEncoder.setIndexBuffer(indexBuffer, "uint32");
Expand Down
4 changes: 2 additions & 2 deletions src/util.mts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ export class TimeTicker {
startedAt: number;

constructor() {
this.startedAt = Date.now();
this.startedAt = performance.now();
}

/** return in seconds */
ticked(): number {
let now = Date.now();
let now = performance.now();
let elapsed = now - this.startedAt;
this.startedAt = now;
return elapsed * 0.001;
Expand Down
Loading

0 comments on commit 42be19d

Please sign in to comment.