mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-28 17:19:11 +01:00
[dxgi] lookup CreateDXGIFactory1 dynamically
This commit is contained in:
1 parent
839bb0260f
commit
6ebe618540
2 files changed
+26
-1
No files matched your search
@@ -13,6 +13,8 @@ use windows::{
|
||||
},
|
||||
};
|
||||
|
||||
use crate::dx12::DxgiLib;
|
||||
|
||||
/// The primary colors of a color space, in CIE 1931 xy:
|
||||
/// `[[red_x, red_y], [green_x, green_y], [blue_x, blue_y]]`.
|
||||
type Primaries = [[f32; 2]; 3];
|
||||
@@ -114,6 +116,7 @@ fn display_hdr_info_from_desc1(
|
||||
pub struct DxgiHdrSource {
|
||||
hwnd: HWND,
|
||||
factory: Mutex<Option<Dxgi::IDXGIFactory1>>,
|
||||
dxgi_lib: Option<DxgiLib>,
|
||||
}
|
||||
|
||||
// SAFETY: `HWND` and `IDXGIFactory1` are `!Send`/`!Sync` in windows-rs. The `HWND`
|
||||
@@ -131,6 +134,9 @@ impl DxgiHdrSource {
|
||||
Self {
|
||||
hwnd,
|
||||
factory: Mutex::new(None),
|
||||
dxgi_lib: DxgiLib::new()
|
||||
.inspect_err(|e| log::warn!("DxgiLib::new failed: {e}"))
|
||||
.ok(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +167,7 @@ impl DxgiHdrSource {
|
||||
if need_new {
|
||||
// SAFETY: `CreateDXGIFactory1` takes no caller pointers; the `windows`
|
||||
// binding fills the interface out-pointer itself.
|
||||
match unsafe { Dxgi::CreateDXGIFactory1() } {
|
||||
match self.dxgi_lib.as_ref()?.create_factory1() {
|
||||
Ok(new) => *factory = Some(new),
|
||||
Err(e) => {
|
||||
log::warn!("CreateDXGIFactory1 failed: {e}");
|
||||
|
||||
@@ -358,6 +358,25 @@ impl DxgiLib {
|
||||
result__.ok_or(crate::DeviceError::Unexpected).map(Some)
|
||||
}
|
||||
|
||||
/// Will error with crate::DeviceError::Unexpected if DXGI 1.1 is not available.
|
||||
pub fn create_factory1(&self) -> Result<Dxgi::IDXGIFactory1, crate::DeviceError> {
|
||||
// Calls windows::Win32::Graphics::Dxgi::CreateDXGIFactory1 on dxgi.dll
|
||||
type Fun = extern "system" fn(
|
||||
riid: *const windows_core::GUID,
|
||||
ppfactory: *mut *mut ffi::c_void,
|
||||
) -> windows_core::HRESULT;
|
||||
let func: libloading::Symbol<Fun> =
|
||||
unsafe { self.lib.get(c"CreateDXGIFactory1".to_bytes()) }?;
|
||||
|
||||
let mut result__ = None;
|
||||
|
||||
(func)(&Dxgi::IDXGIFactory1::IID, <*mut _>::cast(&mut result__))
|
||||
.ok()
|
||||
.into_device_result("create_factory1")?;
|
||||
|
||||
result__.ok_or(crate::DeviceError::Unexpected)
|
||||
}
|
||||
|
||||
/// Will error with crate::DeviceError::Unexpected if DXGI 1.4 is not available.
|
||||
pub fn create_factory4(
|
||||
&self,
|
||||
|
||||
Reference in new issue
Block a user