From 6a1138f0dcf1d28dd65e310d75dc6e588e8641da Mon Sep 17 00:00:00 2001 From: chyyran Date: Sun, 5 Feb 2023 17:30:55 -0500 Subject: [PATCH] d3d12: allow force hlsl --- librashader-runtime-d3d12/src/filter_chain.rs | 16 +++++++++---- librashader-runtime-d3d12/src/lib.rs | 5 +++- librashader-runtime-d3d12/src/options.rs | 23 +++++++++++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 librashader-runtime-d3d12/src/options.rs diff --git a/librashader-runtime-d3d12/src/filter_chain.rs b/librashader-runtime-d3d12/src/filter_chain.rs index 2c52868..fdf6cec 100644 --- a/librashader-runtime-d3d12/src/filter_chain.rs +++ b/librashader-runtime-d3d12/src/filter_chain.rs @@ -46,6 +46,7 @@ use windows::Win32::Graphics::Direct3D12::{ }; use windows::Win32::System::Threading::{CreateEventA, ResetEvent, WaitForSingleObject}; use windows::Win32::System::WindowsProgramming::INFINITE; +use crate::options::FilterChainOptionsD3D12; type DxilShaderPassMeta = ShaderPassArtifact>; type HlslShaderPassMeta = ShaderPassArtifact>; @@ -89,7 +90,7 @@ impl FilterChainD3D12 { pub fn load_from_path( device: &ID3D12Device, path: impl AsRef, - options: Option<&()>, + options: Option<&FilterChainOptionsD3D12>, ) -> error::Result { // load passes from preset let preset = ShaderPreset::try_parse(path)?; @@ -100,7 +101,7 @@ impl FilterChainD3D12 { pub fn load_from_preset( device: &ID3D12Device, preset: ShaderPreset, - _options: Option<&()>, + options: Option<&FilterChainOptionsD3D12>, ) -> error::Result { let shader_count = preset.shaders.len(); let lut_count = preset.textures.len(); @@ -140,7 +141,8 @@ impl FilterChainD3D12 { let root_signature = D3D12RootSignature::new(device)?; let (texture_heap, sampler_heap, filters) = - FilterChainD3D12::init_passes(device, &root_signature, passes, hlsl_passes, &semantics) + FilterChainD3D12::init_passes(device, &root_signature, passes, hlsl_passes, &semantics, + options.map_or(false, |o| o.force_hlsl_pipeline)) .unwrap(); // initialize output framebuffers @@ -332,6 +334,7 @@ impl FilterChainD3D12 { passes: Vec, hlsl_passes: Vec, semantics: &ShaderSemantics, + force_hlsl: bool, ) -> error::Result<(ID3D12DescriptorHeap, ID3D12DescriptorHeap, Vec)> { let validator: IDxcValidator = unsafe { DxcCreateInstance(&CLSID_DxcValidator)? }; @@ -356,7 +359,8 @@ impl FilterChainD3D12 { for ( index, - ((((config, source, mut dxil), (_, _, mut hlsl)), mut texture_heap), mut sampler_heap), + ((((config, source, mut dxil), (_, _, mut hlsl)), + mut texture_heap), mut sampler_heap), ) in passes .into_iter() .zip(hlsl_passes) @@ -384,7 +388,8 @@ impl FilterChainD3D12 { eprintln!("building pipeline for pass {:?}", index); /// incredibly cursed. - let (reflection, graphics_pipeline) = if let Ok(graphics_pipeline) = + let (reflection, graphics_pipeline) = if !force_hlsl && + let Ok(graphics_pipeline) = D3D12GraphicsPipeline::new_from_dxil( device, &library, @@ -395,6 +400,7 @@ impl FilterChainD3D12 { ) { (dxil_reflection, graphics_pipeline) } else { + eprintln!("falling back to hlsl for {:?}", index); let graphics_pipeline = D3D12GraphicsPipeline::new_from_hlsl( device, &library, diff --git a/librashader-runtime-d3d12/src/lib.rs b/librashader-runtime-d3d12/src/lib.rs index 86f94e6..7f1edef 100644 --- a/librashader-runtime-d3d12/src/lib.rs +++ b/librashader-runtime-d3d12/src/lib.rs @@ -16,6 +16,7 @@ mod render_target; mod samplers; mod texture; mod util; +mod options; #[cfg(test)] mod tests { @@ -26,7 +27,9 @@ mod tests { fn triangle_d3d12() { let sample = hello_triangle::d3d12_hello_triangle::Sample::new( // "../test/slang-shaders/crt/crt-lottes.slangp", - "../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", + // "../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", + "../test/slang-shaders/crt/crt-royale.slangp", + &SampleCommandLine { use_warp_device: false, }, diff --git a/librashader-runtime-d3d12/src/options.rs b/librashader-runtime-d3d12/src/options.rs new file mode 100644 index 0000000..0a826d6 --- /dev/null +++ b/librashader-runtime-d3d12/src/options.rs @@ -0,0 +1,23 @@ +//! Direct3D12 shader runtime options. + +/// Options for each Direct3D11 shader frame. +#[repr(C)] +#[derive(Debug, Clone)] +pub struct FrameOptionsD3D12 { + /// Whether or not to clear the history buffers. + pub clear_history: bool, + /// The direction of the frame. 1 should be vertical. + pub frame_direction: i32, +} + +/// Options for Direct3D11 filter chain creation. +#[repr(C)] +#[derive(Debug, Clone)] +pub struct FilterChainOptionsD3D12 { + /// Force the HLSL shader pipeline. This may reduce shader compatibility + pub force_hlsl_pipeline: bool, + + /// Whether or not to explicitly disable mipmap + /// generation regardless of shader preset settings. + pub force_no_mipmaps: bool, +}