From a64d0b0a96e6d2fe01e03ace8d121ddf866c9382 Mon Sep 17 00:00:00 2001 From: chyyran Date: Wed, 30 Nov 2022 19:10:04 -0500 Subject: [PATCH] d3d11: export runtime in root lib --- librashader-common/Cargo.toml | 3 +- librashader-common/src/d3d11.rs | 81 +--------------------------- librashader-common/src/dxgi.rs | 80 +++++++++++++++++++++++++++ librashader-common/src/lib.rs | 3 ++ librashader-runtime-d3d11/src/lib.rs | 4 ++ librashader/Cargo.toml | 3 +- 6 files changed, 92 insertions(+), 82 deletions(-) create mode 100644 librashader-common/src/dxgi.rs diff --git a/librashader-common/Cargo.toml b/librashader-common/Cargo.toml index 2f70cfb..9c0e220 100644 --- a/librashader-common/Cargo.toml +++ b/librashader-common/Cargo.toml @@ -8,7 +8,8 @@ edition = "2021" [features] default = [] opengl = ["gl"] -d3d11 = ["windows"] +d3d11 = ["windows", "dxgi"] +dxgi = ["windows"] [dependencies] gl = { version = "0.14.0", optional = true } diff --git a/librashader-common/src/d3d11.rs b/librashader-common/src/d3d11.rs index 17b6d02..483fee7 100644 --- a/librashader-common/src/d3d11.rs +++ b/librashader-common/src/d3d11.rs @@ -1,84 +1,5 @@ -use crate::{FilterMode, ImageFormat, WrapMode}; +use crate::{FilterMode, WrapMode}; use windows::Win32::Graphics::Direct3D11; -use windows::Win32::Graphics::Dxgi::Common as dxgi; -use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT; - -impl From for dxgi::DXGI_FORMAT { - fn from(format: ImageFormat) -> Self { - match format { - ImageFormat::Unknown => dxgi::DXGI_FORMAT_UNKNOWN, - ImageFormat::R8Unorm => dxgi::DXGI_FORMAT_R8_UNORM, - ImageFormat::R8Uint => dxgi::DXGI_FORMAT_R8_UINT, - ImageFormat::R8Sint => dxgi::DXGI_FORMAT_R8_SINT, - ImageFormat::R8G8Unorm => dxgi::DXGI_FORMAT_R8G8_UNORM, - ImageFormat::R8G8Uint => dxgi::DXGI_FORMAT_R8G8_UINT, - ImageFormat::R8G8Sint => dxgi::DXGI_FORMAT_R8G8_SINT, - ImageFormat::R8G8B8A8Unorm => dxgi::DXGI_FORMAT_R8G8B8A8_UNORM, - ImageFormat::R8G8B8A8Uint => dxgi::DXGI_FORMAT_R8G8B8A8_UINT, - ImageFormat::R8G8B8A8Sint => dxgi::DXGI_FORMAT_R8G8B8A8_SINT, - ImageFormat::R8G8B8A8Srgb => dxgi::DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, - ImageFormat::A2B10G10R10UnormPack32 => dxgi::DXGI_FORMAT_R10G10B10A2_UNORM, - ImageFormat::A2B10G10R10UintPack32 => dxgi::DXGI_FORMAT_R10G10B10A2_UINT, - ImageFormat::R16Uint => dxgi::DXGI_FORMAT_R16_UINT, - ImageFormat::R16Sint => dxgi::DXGI_FORMAT_R16_SINT, - ImageFormat::R16Sfloat => dxgi::DXGI_FORMAT_R16_FLOAT, - ImageFormat::R16G16Uint => dxgi::DXGI_FORMAT_R16G16_UINT, - ImageFormat::R16G16Sint => dxgi::DXGI_FORMAT_R16G16_SINT, - ImageFormat::R16G16Sfloat => dxgi::DXGI_FORMAT_R16G16_FLOAT, - ImageFormat::R16G16B16A16Uint => dxgi::DXGI_FORMAT_R16G16B16A16_UINT, - ImageFormat::R16G16B16A16Sint => dxgi::DXGI_FORMAT_R16G16B16A16_SINT, - ImageFormat::R16G16B16A16Sfloat => dxgi::DXGI_FORMAT_R16G16B16A16_FLOAT, - ImageFormat::R32Uint => dxgi::DXGI_FORMAT_R32_UINT, - ImageFormat::R32Sint => dxgi::DXGI_FORMAT_R32_SINT, - ImageFormat::R32Sfloat => dxgi::DXGI_FORMAT_R32_FLOAT, - ImageFormat::R32G32Uint => dxgi::DXGI_FORMAT_R32G32_UINT, - ImageFormat::R32G32Sint => dxgi::DXGI_FORMAT_R32G32_SINT, - ImageFormat::R32G32Sfloat => dxgi::DXGI_FORMAT_R32G32_FLOAT, - ImageFormat::R32G32B32A32Uint => dxgi::DXGI_FORMAT_R32G32B32A32_UINT, - ImageFormat::R32G32B32A32Sint => dxgi::DXGI_FORMAT_R32G32B32A32_SINT, - ImageFormat::R32G32B32A32Sfloat => dxgi::DXGI_FORMAT_R32G32B32A32_FLOAT, - } - } -} - -impl From for ImageFormat { - fn from(format: DXGI_FORMAT) -> Self { - match format { - dxgi::DXGI_FORMAT_UNKNOWN => ImageFormat::Unknown, - dxgi::DXGI_FORMAT_R8_UNORM => ImageFormat::R8Unorm, - dxgi::DXGI_FORMAT_R8_UINT => ImageFormat::R8Uint, - dxgi::DXGI_FORMAT_R8_SINT => ImageFormat::R8Sint, - dxgi::DXGI_FORMAT_R8G8_UNORM => ImageFormat::R8G8Unorm, - dxgi::DXGI_FORMAT_R8G8_UINT => ImageFormat::R8G8Uint, - dxgi::DXGI_FORMAT_R8G8_SINT => ImageFormat::R8G8Sint, - dxgi::DXGI_FORMAT_R8G8B8A8_UNORM => ImageFormat::R8G8B8A8Unorm, - dxgi::DXGI_FORMAT_R8G8B8A8_UINT => ImageFormat::R8G8B8A8Uint, - dxgi::DXGI_FORMAT_R8G8B8A8_SINT => ImageFormat::R8G8B8A8Sint, - dxgi::DXGI_FORMAT_R8G8B8A8_UNORM_SRGB => ImageFormat::R8G8B8A8Srgb, - dxgi::DXGI_FORMAT_R10G10B10A2_UNORM => ImageFormat::A2B10G10R10UnormPack32, - dxgi::DXGI_FORMAT_R10G10B10A2_UINT => ImageFormat::A2B10G10R10UintPack32, - dxgi::DXGI_FORMAT_R16_UINT => ImageFormat::R16Uint, - dxgi::DXGI_FORMAT_R16_SINT => ImageFormat::R16Sint, - dxgi::DXGI_FORMAT_R16_FLOAT => ImageFormat::R16Sfloat, - dxgi::DXGI_FORMAT_R16G16_UINT => ImageFormat::R16G16Uint, - dxgi::DXGI_FORMAT_R16G16_SINT => ImageFormat::R16G16Sint, - dxgi::DXGI_FORMAT_R16G16_FLOAT => ImageFormat::R16G16Sfloat, - dxgi::DXGI_FORMAT_R16G16B16A16_UINT => ImageFormat::R16G16B16A16Uint, - dxgi::DXGI_FORMAT_R16G16B16A16_SINT => ImageFormat::R16G16B16A16Sint, - dxgi::DXGI_FORMAT_R16G16B16A16_FLOAT => ImageFormat::R16G16B16A16Sfloat, - dxgi::DXGI_FORMAT_R32_UINT => ImageFormat::R32Uint, - dxgi::DXGI_FORMAT_R32_SINT => ImageFormat::R32Sint, - dxgi::DXGI_FORMAT_R32_FLOAT => ImageFormat::R32Sfloat, - dxgi::DXGI_FORMAT_R32G32_UINT => ImageFormat::R32G32Uint, - dxgi::DXGI_FORMAT_R32G32_SINT => ImageFormat::R32G32Sint, - dxgi::DXGI_FORMAT_R32G32_FLOAT => ImageFormat::R32G32Sfloat, - dxgi::DXGI_FORMAT_R32G32B32A32_UINT => ImageFormat::R32G32B32A32Uint, - dxgi::DXGI_FORMAT_R32G32B32A32_SINT => ImageFormat::R32G32B32A32Sint, - dxgi::DXGI_FORMAT_R32G32B32A32_FLOAT => ImageFormat::R32G32B32A32Sfloat, - _ => ImageFormat::Unknown, - } - } -} impl From for Direct3D11::D3D11_TEXTURE_ADDRESS_MODE { fn from(value: WrapMode) -> Self { diff --git a/librashader-common/src/dxgi.rs b/librashader-common/src/dxgi.rs new file mode 100644 index 0000000..1d5b096 --- /dev/null +++ b/librashader-common/src/dxgi.rs @@ -0,0 +1,80 @@ +use windows::Win32::Graphics::Dxgi::Common as dxgi; +use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT; +use crate::ImageFormat; + +impl From for dxgi::DXGI_FORMAT { + fn from(format: ImageFormat) -> Self { + match format { + ImageFormat::Unknown => dxgi::DXGI_FORMAT_UNKNOWN, + ImageFormat::R8Unorm => dxgi::DXGI_FORMAT_R8_UNORM, + ImageFormat::R8Uint => dxgi::DXGI_FORMAT_R8_UINT, + ImageFormat::R8Sint => dxgi::DXGI_FORMAT_R8_SINT, + ImageFormat::R8G8Unorm => dxgi::DXGI_FORMAT_R8G8_UNORM, + ImageFormat::R8G8Uint => dxgi::DXGI_FORMAT_R8G8_UINT, + ImageFormat::R8G8Sint => dxgi::DXGI_FORMAT_R8G8_SINT, + ImageFormat::R8G8B8A8Unorm => dxgi::DXGI_FORMAT_R8G8B8A8_UNORM, + ImageFormat::R8G8B8A8Uint => dxgi::DXGI_FORMAT_R8G8B8A8_UINT, + ImageFormat::R8G8B8A8Sint => dxgi::DXGI_FORMAT_R8G8B8A8_SINT, + ImageFormat::R8G8B8A8Srgb => dxgi::DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, + ImageFormat::A2B10G10R10UnormPack32 => dxgi::DXGI_FORMAT_R10G10B10A2_UNORM, + ImageFormat::A2B10G10R10UintPack32 => dxgi::DXGI_FORMAT_R10G10B10A2_UINT, + ImageFormat::R16Uint => dxgi::DXGI_FORMAT_R16_UINT, + ImageFormat::R16Sint => dxgi::DXGI_FORMAT_R16_SINT, + ImageFormat::R16Sfloat => dxgi::DXGI_FORMAT_R16_FLOAT, + ImageFormat::R16G16Uint => dxgi::DXGI_FORMAT_R16G16_UINT, + ImageFormat::R16G16Sint => dxgi::DXGI_FORMAT_R16G16_SINT, + ImageFormat::R16G16Sfloat => dxgi::DXGI_FORMAT_R16G16_FLOAT, + ImageFormat::R16G16B16A16Uint => dxgi::DXGI_FORMAT_R16G16B16A16_UINT, + ImageFormat::R16G16B16A16Sint => dxgi::DXGI_FORMAT_R16G16B16A16_SINT, + ImageFormat::R16G16B16A16Sfloat => dxgi::DXGI_FORMAT_R16G16B16A16_FLOAT, + ImageFormat::R32Uint => dxgi::DXGI_FORMAT_R32_UINT, + ImageFormat::R32Sint => dxgi::DXGI_FORMAT_R32_SINT, + ImageFormat::R32Sfloat => dxgi::DXGI_FORMAT_R32_FLOAT, + ImageFormat::R32G32Uint => dxgi::DXGI_FORMAT_R32G32_UINT, + ImageFormat::R32G32Sint => dxgi::DXGI_FORMAT_R32G32_SINT, + ImageFormat::R32G32Sfloat => dxgi::DXGI_FORMAT_R32G32_FLOAT, + ImageFormat::R32G32B32A32Uint => dxgi::DXGI_FORMAT_R32G32B32A32_UINT, + ImageFormat::R32G32B32A32Sint => dxgi::DXGI_FORMAT_R32G32B32A32_SINT, + ImageFormat::R32G32B32A32Sfloat => dxgi::DXGI_FORMAT_R32G32B32A32_FLOAT, + } + } +} + +impl From for ImageFormat { + fn from(format: DXGI_FORMAT) -> Self { + match format { + dxgi::DXGI_FORMAT_UNKNOWN => ImageFormat::Unknown, + dxgi::DXGI_FORMAT_R8_UNORM => ImageFormat::R8Unorm, + dxgi::DXGI_FORMAT_R8_UINT => ImageFormat::R8Uint, + dxgi::DXGI_FORMAT_R8_SINT => ImageFormat::R8Sint, + dxgi::DXGI_FORMAT_R8G8_UNORM => ImageFormat::R8G8Unorm, + dxgi::DXGI_FORMAT_R8G8_UINT => ImageFormat::R8G8Uint, + dxgi::DXGI_FORMAT_R8G8_SINT => ImageFormat::R8G8Sint, + dxgi::DXGI_FORMAT_R8G8B8A8_UNORM => ImageFormat::R8G8B8A8Unorm, + dxgi::DXGI_FORMAT_R8G8B8A8_UINT => ImageFormat::R8G8B8A8Uint, + dxgi::DXGI_FORMAT_R8G8B8A8_SINT => ImageFormat::R8G8B8A8Sint, + dxgi::DXGI_FORMAT_R8G8B8A8_UNORM_SRGB => ImageFormat::R8G8B8A8Srgb, + dxgi::DXGI_FORMAT_R10G10B10A2_UNORM => ImageFormat::A2B10G10R10UnormPack32, + dxgi::DXGI_FORMAT_R10G10B10A2_UINT => ImageFormat::A2B10G10R10UintPack32, + dxgi::DXGI_FORMAT_R16_UINT => ImageFormat::R16Uint, + dxgi::DXGI_FORMAT_R16_SINT => ImageFormat::R16Sint, + dxgi::DXGI_FORMAT_R16_FLOAT => ImageFormat::R16Sfloat, + dxgi::DXGI_FORMAT_R16G16_UINT => ImageFormat::R16G16Uint, + dxgi::DXGI_FORMAT_R16G16_SINT => ImageFormat::R16G16Sint, + dxgi::DXGI_FORMAT_R16G16_FLOAT => ImageFormat::R16G16Sfloat, + dxgi::DXGI_FORMAT_R16G16B16A16_UINT => ImageFormat::R16G16B16A16Uint, + dxgi::DXGI_FORMAT_R16G16B16A16_SINT => ImageFormat::R16G16B16A16Sint, + dxgi::DXGI_FORMAT_R16G16B16A16_FLOAT => ImageFormat::R16G16B16A16Sfloat, + dxgi::DXGI_FORMAT_R32_UINT => ImageFormat::R32Uint, + dxgi::DXGI_FORMAT_R32_SINT => ImageFormat::R32Sint, + dxgi::DXGI_FORMAT_R32_FLOAT => ImageFormat::R32Sfloat, + dxgi::DXGI_FORMAT_R32G32_UINT => ImageFormat::R32G32Uint, + dxgi::DXGI_FORMAT_R32G32_SINT => ImageFormat::R32G32Sint, + dxgi::DXGI_FORMAT_R32G32_FLOAT => ImageFormat::R32G32Sfloat, + dxgi::DXGI_FORMAT_R32G32B32A32_UINT => ImageFormat::R32G32B32A32Uint, + dxgi::DXGI_FORMAT_R32G32B32A32_SINT => ImageFormat::R32G32B32A32Sint, + dxgi::DXGI_FORMAT_R32G32B32A32_FLOAT => ImageFormat::R32G32B32A32Sfloat, + _ => ImageFormat::Unknown, + } + } +} \ No newline at end of file diff --git a/librashader-common/src/lib.rs b/librashader-common/src/lib.rs index 734706b..b99386d 100644 --- a/librashader-common/src/lib.rs +++ b/librashader-common/src/lib.rs @@ -6,6 +6,9 @@ pub mod gl; pub mod image; pub mod runtime; +#[cfg(feature = "dxgi")] +pub mod dxgi; + use num_traits::AsPrimitive; use std::convert::Infallible; use std::str::FromStr; diff --git a/librashader-runtime-d3d11/src/lib.rs b/librashader-runtime-d3d11/src/lib.rs index 0d7c96f..0b2e92a 100644 --- a/librashader-runtime-d3d11/src/lib.rs +++ b/librashader-runtime-d3d11/src/lib.rs @@ -16,6 +16,10 @@ mod texture; mod util; mod viewport; +pub use filter_chain::FilterChain; +pub use viewport::Viewport; +pub use texture::DxImageView; + #[cfg(test)] mod tests { diff --git a/librashader/Cargo.toml b/librashader/Cargo.toml index 9e9e681..35b5afc 100644 --- a/librashader/Cargo.toml +++ b/librashader/Cargo.toml @@ -14,4 +14,5 @@ librashader-runtime-gl = { path = "../librashader-runtime-gl" } [features] -gl = [ "librashader-common/opengl" ] \ No newline at end of file +gl = [ "librashader-common/opengl" ] +d3d11 = [ "librashader-common/d3d11" ] \ No newline at end of file