gled-core 2.33.0

The engine of gled without a user interface: inputs, timing, rendering, Art-Net/DMX output and storage
Documentation
//! GPU profiling of the output device, with the `profiling` feature.

use once_cell::sync::Lazy;
use parking_lot::{Mutex, MutexGuard};
use std::sync::OnceLock;

static WGPU_PROFILER: OnceLock<Mutex<wgpu_profiler::GpuProfiler>> = OnceLock::new();

/// GPU timings for the puffin viewer, fed by the render thread.
pub static PUFFIN_GPU_PROFILER: Lazy<Mutex<puffin::GlobalProfiler>> =
    Lazy::new(|| Mutex::new(puffin::GlobalProfiler::default()));

/// Create the GPU profiler for the output device. Called once by the render thread.
pub fn init_wgpu_profiler(device: &wgpu::Device) {
    match wgpu_profiler::GpuProfiler::new(device, wgpu_profiler::GpuProfilerSettings::default()) {
        Ok(profiler) => {
            if WGPU_PROFILER.set(Mutex::new(profiler)).is_err() {
                tracing::warn!("WGPU profiler was already initialized");
            }
        }
        Err(err) => tracing::error!("Could not create the WGPU profiler: {err}"),
    }
}

/// The output device's profiler.
///
/// # Panics
/// Before the render thread started, which creates it.
#[allow(clippy::expect_used)]
pub fn wgpu_profiler() -> MutexGuard<'static, wgpu_profiler::GpuProfiler> {
    WGPU_PROFILER
        .get()
        .expect("WGPU profiler is initialized when the render thread starts")
        .lock()
}