d3d12: use dxc to compile mipmap shader
removes fxc dependency completely. Also slim down windows-rs features where only needed for testing.
This commit is contained in:
parent
29a1fa05d8
commit
abadfb3ee1
|
@ -27,6 +27,19 @@ array-concat = "0.5.2"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies.windows]
|
[target.'cfg(windows)'.dependencies.windows]
|
||||||
version = "0.44.0"
|
version = "0.44.0"
|
||||||
|
features = [
|
||||||
|
"Win32_Foundation",
|
||||||
|
"Win32_Graphics_Dxgi_Common",
|
||||||
|
"Win32_Graphics_Direct3D",
|
||||||
|
"Win32_Graphics_Direct3D11",
|
||||||
|
"Win32_Graphics_Direct3D_Fxc",
|
||||||
|
"Win32_System_Threading",
|
||||||
|
"Win32_System_WindowsProgramming",
|
||||||
|
"Win32_Security",
|
||||||
|
]
|
||||||
|
|
||||||
|
[target.'cfg(windows)'.dev-dependencies.windows]
|
||||||
|
version = "0.44.0"
|
||||||
features = [
|
features = [
|
||||||
"Win32_Foundation",
|
"Win32_Foundation",
|
||||||
"Win32_Graphics_Dxgi_Common",
|
"Win32_Graphics_Dxgi_Common",
|
||||||
|
|
|
@ -30,7 +30,6 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::options::FilterChainOptionsD3D11;
|
use crate::options::FilterChainOptionsD3D11;
|
||||||
use librashader_runtime::image::{Image, UVDirection};
|
use librashader_runtime::image::{Image, UVDirection};
|
||||||
use std::env;
|
|
||||||
|
|
||||||
// "../test/slang-shaders/scalefx/scalefx-9x.slangp",
|
// "../test/slang-shaders/scalefx/scalefx-9x.slangp",
|
||||||
// "../test/slang-shaders/bezel/koko-aio/monitor-bloom.slangp",
|
// "../test/slang-shaders/bezel/koko-aio/monitor-bloom.slangp",
|
||||||
|
@ -48,7 +47,7 @@ mod tests {
|
||||||
const IMAGE_PATH: &str = "../triangle.png";
|
const IMAGE_PATH: &str = "../triangle.png";
|
||||||
#[test]
|
#[test]
|
||||||
fn triangle_d3d11_args() {
|
fn triangle_d3d11_args() {
|
||||||
let mut args = env::args();
|
let mut args = std::env::args();
|
||||||
let _ = args.next();
|
let _ = args.next();
|
||||||
let _ = args.next();
|
let _ = args.next();
|
||||||
let filter = args.next();
|
let filter = args.next();
|
||||||
|
|
|
@ -32,6 +32,18 @@ rayon = "1.6.1"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies.windows]
|
[target.'cfg(windows)'.dependencies.windows]
|
||||||
version = "0.44.0"
|
version = "0.44.0"
|
||||||
|
features = [
|
||||||
|
"Win32_Foundation",
|
||||||
|
"Win32_Graphics_Dxgi_Common",
|
||||||
|
"Win32_Graphics_Direct3D",
|
||||||
|
"Win32_Graphics_Direct3D12",
|
||||||
|
"Win32_Graphics_Direct3D_Dxc",
|
||||||
|
"Win32_System_Threading",
|
||||||
|
"Win32_System_WindowsProgramming",
|
||||||
|
"Win32_Security",
|
||||||
|
]
|
||||||
|
|
||||||
|
[target.'cfg(windows)'.dev-dependencies.windows]
|
||||||
features = [
|
features = [
|
||||||
"Win32_Foundation",
|
"Win32_Foundation",
|
||||||
"Win32_Graphics_Dxgi_Common",
|
"Win32_Graphics_Dxgi_Common",
|
||||||
|
@ -43,8 +55,10 @@ features = [
|
||||||
"Win32_Security",
|
"Win32_Security",
|
||||||
"Win32_System_LibraryLoader",
|
"Win32_System_LibraryLoader",
|
||||||
"Win32_System_Threading",
|
"Win32_System_Threading",
|
||||||
"Win32_System_WindowsProgramming",
|
|
||||||
"Win32_UI_WindowsAndMessaging",
|
"Win32_UI_WindowsAndMessaging",
|
||||||
|
"Win32_System_Threading",
|
||||||
|
"Win32_System_WindowsProgramming",
|
||||||
]
|
]
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
gfx-maths = "0.2.8"
|
gfx-maths = "0.2.8"
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use widestring::u16cstr;
|
||||||
use crate::error::assume_d3d12_init;
|
use crate::error::assume_d3d12_init;
|
||||||
use crate::error::FilterChainError::Direct3DOperationError;
|
use crate::error::FilterChainError::Direct3DOperationError;
|
||||||
use crate::quad_render::DrawQuad;
|
use crate::quad_render::DrawQuad;
|
||||||
|
@ -5,7 +6,6 @@ use crate::{error, util};
|
||||||
use librashader_reflect::back::cross::CrossHlslContext;
|
use librashader_reflect::back::cross::CrossHlslContext;
|
||||||
use librashader_reflect::back::dxil::DxilObject;
|
use librashader_reflect::back::dxil::DxilObject;
|
||||||
use librashader_reflect::back::ShaderCompilerOutput;
|
use librashader_reflect::back::ShaderCompilerOutput;
|
||||||
use librashader_reflect::reflect::semantics::BindingStage;
|
|
||||||
use windows::Win32::Foundation::BOOL;
|
use windows::Win32::Foundation::BOOL;
|
||||||
use windows::Win32::Graphics::Direct3D::Dxc::{
|
use windows::Win32::Graphics::Direct3D::Dxc::{
|
||||||
CLSID_DxcLibrary, DxcCreateInstance, IDxcBlob, IDxcCompiler, IDxcUtils, IDxcValidator, DXC_CP,
|
CLSID_DxcLibrary, DxcCreateInstance, IDxcBlob, IDxcCompiler, IDxcUtils, IDxcValidator, DXC_CP,
|
||||||
|
@ -308,12 +308,12 @@ impl D3D12GraphicsPipeline {
|
||||||
render_format: DXGI_FORMAT,
|
render_format: DXGI_FORMAT,
|
||||||
) -> error::Result<D3D12GraphicsPipeline> {
|
) -> error::Result<D3D12GraphicsPipeline> {
|
||||||
let vertex_dxil =
|
let vertex_dxil =
|
||||||
util::dxc_compile_shader(library, dxc, &shader_assembly.vertex, BindingStage::VERTEX)?;
|
util::dxc_compile_shader(library, dxc, &shader_assembly.vertex, u16cstr!("vs_6_0"))?;
|
||||||
let fragment_dxil = util::dxc_compile_shader(
|
let fragment_dxil = util::dxc_compile_shader(
|
||||||
library,
|
library,
|
||||||
dxc,
|
dxc,
|
||||||
&shader_assembly.fragment,
|
&shader_assembly.fragment,
|
||||||
BindingStage::FRAGMENT,
|
u16cstr!("ps_6_0")
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Self::new_from_blobs(
|
Self::new_from_blobs(
|
||||||
|
|
|
@ -36,7 +36,7 @@ mod tests {
|
||||||
// "../test/slang-shaders/crt/crt-lottes.slangp",
|
// "../test/slang-shaders/crt/crt-lottes.slangp",
|
||||||
// "../test/basic.slangp",
|
// "../test/basic.slangp",
|
||||||
// "../test/slang-shaders/handheld/console-border/gbc-lcd-grid-v2.slangp",
|
// "../test/slang-shaders/handheld/console-border/gbc-lcd-grid-v2.slangp",
|
||||||
"../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV-GLASS.slangp",
|
"../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp",
|
||||||
// "../test/slang-shaders/test/feedback.slangp",
|
// "../test/slang-shaders/test/feedback.slangp",
|
||||||
// "../test/slang-shaders/test/history.slangp",
|
// "../test/slang-shaders/test/history.slangp",
|
||||||
// "../test/slang-shaders/crt/crt-royale.slangp",
|
// "../test/slang-shaders/crt/crt-royale.slangp",
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
use crate::descriptor_heap::{D3D12DescriptorHeap, D3D12DescriptorHeapSlot, ResourceWorkHeap};
|
use crate::descriptor_heap::{D3D12DescriptorHeap, D3D12DescriptorHeapSlot, ResourceWorkHeap};
|
||||||
use crate::util::fxc_compile_shader;
|
use crate::util::dxc_compile_shader;
|
||||||
use crate::{error, util};
|
use crate::{error, util};
|
||||||
use bytemuck::{Pod, Zeroable};
|
use bytemuck::{Pod, Zeroable};
|
||||||
use librashader_common::Size;
|
use librashader_common::Size;
|
||||||
use librashader_runtime::scaling::MipmapSize;
|
use librashader_runtime::scaling::MipmapSize;
|
||||||
use std::mem::ManuallyDrop;
|
use std::mem::ManuallyDrop;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
use widestring::u16cstr;
|
||||||
use windows::Win32::Graphics::Direct3D12::{
|
use windows::Win32::Graphics::Direct3D12::{
|
||||||
ID3D12DescriptorHeap, ID3D12Device, ID3D12GraphicsCommandList, ID3D12PipelineState,
|
ID3D12DescriptorHeap, ID3D12Device, ID3D12GraphicsCommandList, ID3D12PipelineState,
|
||||||
ID3D12Resource, ID3D12RootSignature, D3D12_COMPUTE_PIPELINE_STATE_DESC,
|
ID3D12Resource, ID3D12RootSignature, D3D12_COMPUTE_PIPELINE_STATE_DESC,
|
||||||
|
@ -16,6 +17,7 @@ use windows::Win32::Graphics::Direct3D12::{
|
||||||
D3D12_SRV_DIMENSION_TEXTURE2D, D3D12_TEX2D_SRV, D3D12_TEX2D_UAV, D3D12_UAV_DIMENSION_TEXTURE2D,
|
D3D12_SRV_DIMENSION_TEXTURE2D, D3D12_TEX2D_SRV, D3D12_TEX2D_UAV, D3D12_UAV_DIMENSION_TEXTURE2D,
|
||||||
D3D12_UNORDERED_ACCESS_VIEW_DESC, D3D12_UNORDERED_ACCESS_VIEW_DESC_0,
|
D3D12_UNORDERED_ACCESS_VIEW_DESC, D3D12_UNORDERED_ACCESS_VIEW_DESC_0,
|
||||||
};
|
};
|
||||||
|
use windows::Win32::Graphics::Direct3D::Dxc::{CLSID_DxcCompiler, CLSID_DxcLibrary, DxcCreateInstance};
|
||||||
use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT;
|
use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT;
|
||||||
|
|
||||||
static GENERATE_MIPS_SRC: &[u8] = b"
|
static GENERATE_MIPS_SRC: &[u8] = b"
|
||||||
|
@ -124,7 +126,10 @@ impl<'a> MipmapGenContext<'a> {
|
||||||
impl D3D12MipmapGen {
|
impl D3D12MipmapGen {
|
||||||
pub fn new(device: &ID3D12Device, own_heaps: bool) -> error::Result<D3D12MipmapGen> {
|
pub fn new(device: &ID3D12Device, own_heaps: bool) -> error::Result<D3D12MipmapGen> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let blob = fxc_compile_shader(GENERATE_MIPS_SRC, b"main\0", b"cs_5_1\0")?;
|
let library = DxcCreateInstance(&CLSID_DxcLibrary)?;
|
||||||
|
let compiler = DxcCreateInstance(&CLSID_DxcCompiler)?;
|
||||||
|
|
||||||
|
let blob = dxc_compile_shader(&library, &compiler, GENERATE_MIPS_SRC, u16cstr!("cs_6_0"))?;
|
||||||
let blob =
|
let blob =
|
||||||
std::slice::from_raw_parts(blob.GetBufferPointer().cast(), blob.GetBufferSize());
|
std::slice::from_raw_parts(blob.GetBufferPointer().cast(), blob.GetBufferSize());
|
||||||
let root_signature: ID3D12RootSignature = device.CreateRootSignature(0, blob)?;
|
let root_signature: ID3D12RootSignature = device.CreateRootSignature(0, blob)?;
|
||||||
|
|
|
@ -1,19 +1,15 @@
|
||||||
use crate::error;
|
use crate::error;
|
||||||
use crate::error::assume_d3d12_init;
|
use crate::error::assume_d3d12_init;
|
||||||
use librashader_reflect::reflect::semantics::BindingStage;
|
|
||||||
|
|
||||||
use std::mem::ManuallyDrop;
|
use std::mem::ManuallyDrop;
|
||||||
use std::u64;
|
use std::u64;
|
||||||
use widestring::u16cstr;
|
use widestring::{u16cstr, U16CStr};
|
||||||
use windows::core::{PCSTR, PCWSTR};
|
use windows::core::PCWSTR;
|
||||||
use windows::Win32::Graphics::Direct3D::Dxc::{
|
use windows::Win32::Graphics::Direct3D::Dxc::{
|
||||||
DxcValidatorFlags_InPlaceEdit, IDxcBlob, IDxcCompiler, IDxcUtils, IDxcValidator, DXC_CP,
|
DxcValidatorFlags_InPlaceEdit, IDxcBlob, IDxcCompiler, IDxcUtils, IDxcValidator, DXC_CP,
|
||||||
DXC_CP_UTF8,
|
DXC_CP_UTF8,
|
||||||
};
|
};
|
||||||
use windows::Win32::Graphics::Direct3D::Fxc::{
|
|
||||||
D3DCompile, D3DCOMPILE_DEBUG, D3DCOMPILE_OPTIMIZATION_LEVEL3, D3DCOMPILE_SKIP_OPTIMIZATION,
|
|
||||||
};
|
|
||||||
use windows::Win32::Graphics::Direct3D::ID3DBlob;
|
|
||||||
use windows::Win32::Graphics::Direct3D12::{
|
use windows::Win32::Graphics::Direct3D12::{
|
||||||
ID3D12Device, ID3D12GraphicsCommandList, ID3D12Resource, D3D12_FEATURE_DATA_FORMAT_SUPPORT,
|
ID3D12Device, ID3D12GraphicsCommandList, ID3D12Resource, D3D12_FEATURE_DATA_FORMAT_SUPPORT,
|
||||||
D3D12_FEATURE_FORMAT_SUPPORT, D3D12_MEMCPY_DEST, D3D12_PLACED_SUBRESOURCE_FOOTPRINT,
|
D3D12_FEATURE_FORMAT_SUPPORT, D3D12_MEMCPY_DEST, D3D12_PLACED_SUBRESOURCE_FOOTPRINT,
|
||||||
|
@ -132,54 +128,22 @@ pub fn d3d12_get_closest_format(
|
||||||
DXGI_FORMAT_UNKNOWN
|
DXGI_FORMAT_UNKNOWN
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fxc_compile_shader(source: &[u8], entry: &[u8], version: &[u8]) -> error::Result<ID3DBlob> {
|
|
||||||
unsafe {
|
|
||||||
let mut blob = None;
|
|
||||||
D3DCompile(
|
|
||||||
source.as_ptr().cast(),
|
|
||||||
source.len(),
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
PCSTR(entry.as_ptr()),
|
|
||||||
PCSTR(version.as_ptr()),
|
|
||||||
if cfg!(feature = "debug-shader") {
|
|
||||||
D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION
|
|
||||||
} else {
|
|
||||||
D3DCOMPILE_OPTIMIZATION_LEVEL3
|
|
||||||
},
|
|
||||||
0,
|
|
||||||
&mut blob,
|
|
||||||
None,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
assume_d3d12_init!(blob, "D3DCompile");
|
|
||||||
Ok(blob)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn dxc_compile_shader(
|
pub fn dxc_compile_shader(
|
||||||
library: &IDxcUtils,
|
library: &IDxcUtils,
|
||||||
compiler: &IDxcCompiler,
|
compiler: &IDxcCompiler,
|
||||||
source: &String,
|
source: impl AsRef<[u8]>,
|
||||||
profile: BindingStage,
|
profile: &U16CStr,
|
||||||
) -> error::Result<IDxcBlob> {
|
) -> error::Result<IDxcBlob> {
|
||||||
let include = unsafe { library.CreateDefaultIncludeHandler()? };
|
let include = unsafe { library.CreateDefaultIncludeHandler()? };
|
||||||
|
let source = source.as_ref();
|
||||||
let blob = unsafe {
|
let blob = unsafe {
|
||||||
library.CreateBlobFromPinned(
|
library.CreateBlobFromPinned(
|
||||||
source.as_ptr().cast(),
|
source.as_ptr().cast(),
|
||||||
source.as_bytes().len() as u32,
|
source.len() as u32,
|
||||||
DXC_CP_UTF8,
|
DXC_CP_UTF8,
|
||||||
)?
|
)?
|
||||||
};
|
};
|
||||||
|
|
||||||
let profile = if profile == BindingStage::FRAGMENT {
|
|
||||||
u16cstr!("ps_6_0")
|
|
||||||
} else {
|
|
||||||
u16cstr!("vs_6_0")
|
|
||||||
};
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let result = compiler.Compile(
|
let result = compiler.Compile(
|
||||||
&blob,
|
&blob,
|
||||||
|
|
Loading…
Reference in a new issue