Skip to main content

Module gpu_profiling

Module gpu_profiling 

Source
Expand description

GPU profiling via wgpu-profiler with puffin visualization.

When the gpu-profiling feature is enabled, this module provides a GpuFrameProfiler that wraps wgpu_profiler::GpuProfiler and automatically reports GPU timing data to puffin.

When the feature is disabled, all types and methods become zero-cost no-ops.

§Automatic Integration

The recommended usage is to attach the profiler to a RenderableWindow:

// At init:
let ctx = GraphicsContext::new_owned_with_descriptor(
    GraphicsContextDescriptor::new()
        .request_capability::<GpuFrameProfiler>()
).await?;
let profiler = Arc::new(GpuFrameProfiler::new(&ctx)?);
window.set_gpu_profiler(profiler);

// Each frame — GPU profiling is fully automatic:
let mut frame = window.begin_drawing();
frame.clear_and_render(RenderTarget::Surface, Color::BLACK, |pass| {
    // GPU scope "main_pass" is automatically active
});
frame.finish(); // auto: resolve_queries -> submit -> end_frame

§Manual Scoping

For custom GPU scopes outside of render passes:

frame.with_gpu_scope("upload_data", |encoder| {
    encoder.copy_buffer_to_buffer(&src, 0, &dst, 0, size);
});

Structs§

GpuFrameProfiler
No-op GPU frame profiler (gpu-profiling feature disabled).
GpuFrameProfilerError
Placeholder error type when gpu-profiling is disabled.