pub(crate) fn try_test_video() -> Option<String> {
let Ok(path) = std::env::var("MEDIA_PP_TEST_VIDEO") else {
eprintln!(
"skipping: set MEDIA_PP_TEST_VIDEO to a video file to run this test \
(no media is checked into this repository)"
);
return None;
};
if !std::path::Path::new(&path).is_file() {
eprintln!("skipping: MEDIA_PP_TEST_VIDEO=`{path}` is not a readable file");
return None;
}
eprintln!("using test video: {path}");
Some(path)
}
#[cfg(all(target_os = "windows", feature = "d3d11"))]
pub(crate) fn try_d3d11_device() -> Option<(
windows::Win32::Graphics::Direct3D11::ID3D11Device,
std::sync::Arc<std::sync::Mutex<windows::Win32::Graphics::Direct3D11::ID3D11DeviceContext>>,
)> {
use windows::Win32::Graphics::{
Direct3D::D3D_DRIVER_TYPE_HARDWARE,
Direct3D11::{D3D11_SDK_VERSION, D3D11CreateDevice},
};
let mut device = None;
let mut context = None;
let result = unsafe {
D3D11CreateDevice(
None,
D3D_DRIVER_TYPE_HARDWARE,
Default::default(),
Default::default(),
None,
D3D11_SDK_VERSION,
Some(&mut device),
None,
Some(&mut context),
)
};
if let Err(error) = result {
eprintln!("skipping: D3D11CreateDevice failed on this machine: {error}");
return None;
}
Some((
device.expect("D3D11CreateDevice succeeded without producing a device"),
std::sync::Arc::new(std::sync::Mutex::new(
context.expect("D3D11CreateDevice succeeded without producing a context"),
)),
))
}
#[cfg(all(target_os = "windows", feature = "d3d12"))]
pub(crate) fn try_d3d12_device() -> Option<windows::Win32::Graphics::Direct3D12::ID3D12Device> {
use windows::Win32::Graphics::{
Direct3D::D3D_FEATURE_LEVEL_11_0, Direct3D12::D3D12CreateDevice,
};
let mut device = None;
if let Err(error) = unsafe { D3D12CreateDevice(None, D3D_FEATURE_LEVEL_11_0, &mut device) } {
eprintln!("skipping: D3D12CreateDevice failed on this machine: {error}");
return None;
}
device
}
#[cfg(feature = "cuda")]
pub(crate) fn try_cuda_device() -> Option<(
crate::elements::CudaDevice,
std::sync::MutexGuard<'static, ()>,
)> {
static LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
let guard = LOCK.lock().unwrap_or_else(|poisoned| poisoned.into_inner());
match crate::elements::CudaDevice::new() {
Ok(device) => Some((device, guard)),
Err(error) => {
eprintln!("skipping: no usable CUDA device on this machine ({error})");
None
}
}
}