Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Change Log

## Unreleased
* fix issues with multiple calls to `GpuProfiler::resolve_queries` per frame, in [#79](https://github.com/Wumpf/wgpu-profiler/pull/79)

## 0.18.0
* update to wgpu 22.1.0, by @waywardmonkeys in [#75](https://github.com/Wumpf/wgpu-profiler/pull/75)
Expand Down
17 changes: 11 additions & 6 deletions src/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,23 +355,28 @@ impl GpuProfiler {

assert!(num_resolved_queries < num_used_queries);

// Resolve into offset 0 of the resolve buffer - this way we don't have to worry about
// the offset restrictions on resolve buffers (`wgpu::QUERY_RESOLVE_BUFFER_ALIGNMENT`)
// and we copy it anyways.
encoder.resolve_query_set(
&query_pool.query_set,
num_resolved_queries..num_used_queries,
&query_pool.resolve_buffer,
(num_resolved_queries * wgpu::QUERY_SIZE) as u64,
0,
);
query_pool
.num_resolved_queries
.store(num_used_queries, Ordering::Release);

// Copy the resolved queries into the read buffer, making sure
// that we don't override any of the results that are already there.
encoder.copy_buffer_to_buffer(
&query_pool.resolve_buffer,
0,
&query_pool.read_buffer,
0,
(num_resolved_queries * wgpu::QUERY_SIZE) as u64,
(num_used_queries * wgpu::QUERY_SIZE) as u64,
);

query_pool
.num_resolved_queries
.store(num_used_queries, Ordering::Release);
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/src/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod dropped_frame_handling;
mod errors;
mod interleaved_command_buffer;
mod multiple_resolves_per_frame;
mod nested_scopes;

pub fn create_device(
Expand Down
38 changes: 38 additions & 0 deletions tests/src/multiple_resolves_per_frame.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Regression test for bug described in https://github.com/Wumpf/wgpu-profiler/issues/79
#[test]
fn multiple_resolves_per_frame() {
let (_, device, queue) = super::create_device(
wgpu::Features::TIMESTAMP_QUERY.union(wgpu::Features::TIMESTAMP_QUERY_INSIDE_ENCODERS),
)
.unwrap();

let mut profiler =
wgpu_profiler::GpuProfiler::new(wgpu_profiler::GpuProfilerSettings::default()).unwrap();

{
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor::default());

// Resolve call per scope.
{
let _ = profiler.scope("testscope0", &mut encoder, &device);
}
profiler.resolve_queries(&mut encoder);
{
let _ = profiler.scope("testscope1", &mut encoder, &device);
}
profiler.resolve_queries(&mut encoder);

// And an extra resolve for good measure (this should be a no-op).
profiler.resolve_queries(&mut encoder);

profiler.end_frame().unwrap();
}

// Poll to explicitly trigger mapping callbacks.
device.poll(wgpu::Maintain::Wait);

// Frame should now be available.
assert!(profiler
.process_finished_frame(queue.get_timestamp_period())
.is_some());
}