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