gpu_telemetry 0.1.0

High-level GPU telemetry background logger
Documentation
use std::time::Duration;

use crate::{errors::{Error, ErrorKind}, monitor::telemetry::GpuSample};

#[cfg(target_os = "windows")]
mod windows;

#[cfg(any(target_os = "windows", target_os = "linux"))]
mod vulkan;

pub trait GpuTelemetry: Sized {
    fn new(adapter: usize) -> Result<Self, Error>;

    fn wait_at_most(&self, interval: Duration) -> Result<(), Error>;

    fn query(&self) -> Result<GpuSample, Error>;
}

#[cfg(target_os = "windows")]
pub use windows::DxGpuQuery;

#[cfg(any(target_os = "windows", target_os = "linux"))]
pub use vulkan::VulkanGpuQuery;

pub struct NopQuery {}

impl GpuTelemetry for NopQuery {
    fn new(_adapter: usize) -> Result<Self, Error> {
        Ok(Self {})
    }

    fn query(&self) -> Result<GpuSample, Error> {
        Err(Error {
            msg: "using nop backend",
            kind: ErrorKind::UnsupportedFeature,
        })
    }

    fn wait_at_most(&self, _interval: Duration) -> Result<(), Error> {
        Err(Error {
            msg: "using nop backend",
            kind: ErrorKind::UnsupportedFeature,
        })
    }
}