Skip to content

Commit

Permalink
feature: Timestamp queries (#3636)
Browse files Browse the repository at this point in the history
Co-authored-by: Andreas Reich <r_andreas2@web.de>
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
Co-authored-by: Connor Fitzgerald <connor@modyfi.io>
  • Loading branch information
4 people authored Aug 2, 2023
1 parent 494ae1a commit 3305e88
Show file tree
Hide file tree
Showing 64 changed files with 1,260 additions and 62 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,15 @@ Some texture format names have changed to get back in line with the spec.

By @cwfitzgerald in [#3671](https://github.com/gfx-rs/wgpu/pull/3671).

#### Pass timestamp queries

Addition of `TimestampWrites` to compute and render passes to allow profiling.
This brings us in line with the spec.

Added new example to demonstrate the various kinds of timestamps.

By @FL33TW00D & @wumpf in [#3636](https://github.com/gfx-rs/wgpu/pull/3636).

#### Misc Breaking Changes

- Change type of `mip_level_count` and `array_layer_count` (members of `TextureViewDescriptor` and `ImageSubresourceRange`) from `Option<NonZeroU32>` to `Option<u32>`. By @teoxoy in [#3445](https://github.com/gfx-rs/wgpu/pull/3445)
Expand Down
18 changes: 18 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions deno_webgpu/command_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ pub fn op_webgpu_command_encoder_begin_render_pass(
label: label.map(Cow::from),
color_attachments: Cow::from(color_attachments),
depth_stencil_attachment: processed_depth_stencil_attachment.as_ref(),
timestamp_writes: None,
occlusion_query_set: occlusion_query_set_resource,
};

Expand All @@ -207,6 +208,7 @@ pub fn op_webgpu_command_encoder_begin_compute_pass(

let descriptor = wgpu_core::command::ComputePassDescriptor {
label: label.map(Cow::from),
timestamp_writes: None,
};

let compute_pass =
Expand Down
4 changes: 3 additions & 1 deletion deno_webgpu/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ impl From<DeviceError> for WebGpuError {
match err {
DeviceError::Lost => WebGpuError::Lost,
DeviceError::OutOfMemory => WebGpuError::OutOfMemory,
DeviceError::Invalid => WebGpuError::Validation(fmt_err(&err)),
DeviceError::ResourceCreationFailed | DeviceError::Invalid => {
WebGpuError::Validation(fmt_err(&err))
}
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions examples/boids/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ impl wgpu_example::framework::Example for Example {
label: None,
color_attachments: &color_attachments,
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
};

Expand All @@ -293,8 +294,10 @@ impl wgpu_example::framework::Example for Example {
command_encoder.push_debug_group("compute boid movement");
{
// compute pass
let mut cpass =
command_encoder.begin_compute_pass(&wgpu::ComputePassDescriptor { label: None });
let mut cpass = command_encoder.begin_compute_pass(&wgpu::ComputePassDescriptor {
label: None,
timestamp_writes: None,
});
cpass.set_pipeline(&self.compute_pipeline);
cpass.set_bind_group(0, &self.particle_bind_groups[self.frame_num % 2], &[]);
cpass.dispatch_workgroups(self.work_group_count, 1, 1);
Expand Down
1 change: 1 addition & 0 deletions examples/bunnymark/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ impl wgpu_example::framework::Example for Example {
},
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
});
rpass.set_pipeline(&self.pipeline);
Expand Down
1 change: 1 addition & 0 deletions examples/capture/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ async fn create_red_image_with_dimensions(
},
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
});

Expand Down
2 changes: 2 additions & 0 deletions examples/conservative-raster/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ impl wgpu_example::framework::Example for Example {
},
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
});

Expand All @@ -293,6 +294,7 @@ impl wgpu_example::framework::Example for Example {
},
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
});

Expand Down
1 change: 1 addition & 0 deletions examples/cube/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ impl wgpu_example::framework::Example for Example {
},
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
});
rpass.push_debug_group("Prepare data for draw.");
Expand Down
5 changes: 4 additions & 1 deletion examples/hello-compute/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ async fn execute_gpu_inner(
let mut encoder =
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
{
let mut cpass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor { label: None });
let mut cpass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor {
label: None,
timestamp_writes: None,
});
cpass.set_pipeline(&compute_pipeline);
cpass.set_bind_group(0, &bind_group, &[]);
cpass.insert_debug_marker("compute collatz iterations");
Expand Down
4 changes: 4 additions & 0 deletions examples/hello-compute/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fn test_compute_1() {
TestParameters::default()
.downlevel_flags(wgpu::DownlevelFlags::COMPUTE_SHADERS)
.limits(wgpu::Limits::downlevel_defaults())
.features(wgpu::Features::TIMESTAMP_QUERY)
.specific_failure(None, None, Some("V3D"), true),
|ctx| {
let input = &[1, 2, 3, 4];
Expand All @@ -33,6 +34,7 @@ fn test_compute_2() {
TestParameters::default()
.downlevel_flags(wgpu::DownlevelFlags::COMPUTE_SHADERS)
.limits(wgpu::Limits::downlevel_defaults())
.features(wgpu::Features::TIMESTAMP_QUERY)
.specific_failure(None, None, Some("V3D"), true),
|ctx| {
let input = &[5, 23, 10, 9];
Expand All @@ -54,6 +56,7 @@ fn test_compute_overflow() {
TestParameters::default()
.downlevel_flags(wgpu::DownlevelFlags::COMPUTE_SHADERS)
.limits(wgpu::Limits::downlevel_defaults())
.features(wgpu::Features::TIMESTAMP_QUERY)
.specific_failure(None, None, Some("V3D"), true),
|ctx| {
let input = &[77031, 837799, 8400511, 63728127];
Expand All @@ -74,6 +77,7 @@ fn test_multithreaded_compute() {
TestParameters::default()
.downlevel_flags(wgpu::DownlevelFlags::COMPUTE_SHADERS)
.limits(wgpu::Limits::downlevel_defaults())
.features(wgpu::Features::TIMESTAMP_QUERY)
.specific_failure(None, None, Some("V3D"), true)
// https://github.com/gfx-rs/wgpu/issues/3944
.specific_failure(
Expand Down
1 change: 1 addition & 0 deletions examples/hello-triangle/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
},
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
});
rpass.set_pipeline(&render_pipeline);
Expand Down
1 change: 1 addition & 0 deletions examples/hello-windows/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ async fn run(event_loop: EventLoop<()>, viewports: Vec<(Window, wgpu::Color)>) {
},
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
});
}
Expand Down
2 changes: 2 additions & 0 deletions examples/mipmap/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ impl Example {
},
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
});
if let Some(ref query_sets) = query_sets {
Expand Down Expand Up @@ -493,6 +494,7 @@ impl wgpu_example::framework::Example for Example {
},
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
});
rpass.set_pipeline(&self.draw_pipeline);
Expand Down
1 change: 1 addition & 0 deletions examples/msaa-line/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ impl wgpu_example::framework::Example for Example {
label: None,
color_attachments: &[Some(rpass_color_attachment)],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
})
.execute_bundles(iter::once(&self.bundle));
Expand Down
2 changes: 2 additions & 0 deletions examples/shadow/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,7 @@ impl wgpu_example::framework::Example for Example {
}),
stencil_ops: None,
}),
timestamp_writes: None,
occlusion_query_set: None,
});
pass.set_pipeline(&self.shadow_pass.pipeline);
Expand Down Expand Up @@ -820,6 +821,7 @@ impl wgpu_example::framework::Example for Example {
}),
stencil_ops: None,
}),
timestamp_writes: None,
occlusion_query_set: None,
});
pass.set_pipeline(&self.forward_pass.pipeline);
Expand Down
1 change: 1 addition & 0 deletions examples/skybox/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ impl wgpu_example::framework::Example for Skybox {
}),
stencil_ops: None,
}),
timestamp_writes: None,
occlusion_query_set: None,
});

Expand Down
1 change: 1 addition & 0 deletions examples/stencil-triangles/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ impl wgpu_example::framework::Example for Triangles {
store: true,
}),
}),
timestamp_writes: None,
occlusion_query_set: None,
});

Expand Down
1 change: 1 addition & 0 deletions examples/texture-arrays/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ impl wgpu_example::framework::Example for Example {
},
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
});

Expand Down
30 changes: 30 additions & 0 deletions examples/timestamp-queries/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "wgpu-timestamp-queries-example"
version.workspace = true
license.workspace = true
edition.workspace = true
description = "wgpu timestamp query example"
publish = false

[[bin]]
name = "timestamp-queries"
path = "src/main.rs"

[dependencies]
bytemuck.workspace = true
env_logger.workspace = true
futures-intrusive.workspace = true
pollster.workspace = true
wgpu.workspace = true
winit.workspace = true

[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook.workspace = true
console_log.workspace = true
log.workspace = true
wasm-bindgen-futures.workspace = true

[dev-dependencies]
wasm-bindgen-test.workspace = true
wgpu-test.workspace = true

9 changes: 9 additions & 0 deletions examples/timestamp-queries/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# timestamp-queries

This example shows various ways of querying time when supported.

## To Run

```
cargo run --bin timestamp-queries
```
Loading

0 comments on commit 3305e88

Please sign in to comment.