Skip to main content

Module profiling

Module profiling 

Source
Expand description

GPU timestamp profiling using wgpu::Features::TIMESTAMP_QUERY.

Provides an opt-in GpuTimestampProfiler that records GPU-side timestamps around compute passes via a wgpu::QuerySet and reports per-pass timings in microseconds after resolution.

The profiler is graceful: GpuTimestampProfiler::try_new returns None whenever the adapter does not advertise the required features (wgpu::Features::TIMESTAMP_QUERY and wgpu::Features::TIMESTAMP_QUERY_INSIDE_ENCODERS — the latter is required to call wgpu::CommandEncoder::write_timestamp outside of a render/compute pass). Callers that do not enable these features when constructing the GpuContext will simply receive None and can fall back to wall-clock timing.

§Quick sketch

use oxigdal_gpu::{GpuContext, GpuTimestampProfiler};
let mut prof = match GpuTimestampProfiler::try_new(ctx, 16) {
    Some(p) => p,
    None => return Ok(()), // adapter lacks TIMESTAMP_QUERY support
};
let mut encoder = ctx.device().create_command_encoder(&Default::default());
if let Some(slot) = prof.begin_pass(&mut encoder, "blur") {
    // ... record compute work into `encoder` ...
    prof.end_pass(&mut encoder, slot);
}
ctx.queue().submit([encoder.finish()]);
for t in prof.resolve(ctx)? {
    println!("{} took {:.3} us", t.label, t.duration_us);
}

§Notes on wgpu features

Both features must be requested via GpuContextConfig::with_features before creating the GpuContext.

Structs§

GpuTimestampProfiler
Opt-in GPU timestamp profiler backed by a single wgpu::QuerySet.
PassTiming
Profiled timing for a single GPU pass.