GPUTimer now respects timestamp period
This commit is contained in:
@@ -93,6 +93,7 @@ impl<'a> Renderer<'a> {
|
||||
// not exactly sure what this number should be,
|
||||
// doesn't affect performance much and depends on "normal" zoom
|
||||
let staging_belt = wgpu::util::StagingBelt::new(4096 * 4);
|
||||
let timer = GPUTimer::new(&device, queue.get_timestamp_period(), 1);
|
||||
|
||||
Self {
|
||||
camera: Camera::default(),
|
||||
@@ -101,7 +102,7 @@ impl<'a> Renderer<'a> {
|
||||
staging_belt,
|
||||
surface,
|
||||
encoder: Self::create_encoder(&device),
|
||||
timer: GPUTimer::new(&device, 1),
|
||||
timer,
|
||||
device,
|
||||
config,
|
||||
queue,
|
||||
|
||||
@@ -5,10 +5,11 @@ pub struct GPUTimer {
|
||||
map_buf: wgpu::Buffer,
|
||||
query_set: wgpu::QuerySet,
|
||||
timestamps: Vec<u64>,
|
||||
period: f32,
|
||||
}
|
||||
|
||||
impl GPUTimer {
|
||||
pub fn new(device: &wgpu::Device, count: u32) -> Self {
|
||||
pub fn new(device: &wgpu::Device, period: f32, count: u32) -> Self {
|
||||
let count = count * 2;
|
||||
let timestamp_set = device.create_query_set(&wgpu::QuerySetDescriptor {
|
||||
count,
|
||||
@@ -34,6 +35,7 @@ impl GPUTimer {
|
||||
resolve_buf: timestamp_resolve_buf,
|
||||
map_buf: timestamp_mapped_buf,
|
||||
timestamps: vec![0; count as usize],
|
||||
period,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +46,8 @@ impl GPUTimer {
|
||||
|
||||
pub fn duration(&self, i: u32) -> Duration {
|
||||
let i = i as usize * 2;
|
||||
Duration::from_nanos(self.timestamps[i + 1] - self.timestamps[i])
|
||||
let diff = self.timestamps[i + 1] - self.timestamps[i];
|
||||
Duration::from_nanos((diff as f32 * self.period) as u64)
|
||||
}
|
||||
|
||||
pub fn finish(&mut self, device: &wgpu::Device) {
|
||||
|
||||
Reference in New Issue
Block a user