d3d12: allow force hlsl

This commit is contained in:
chyyran 2023-02-05 17:30:55 -05:00
parent 2d2ed22e9a
commit 6a1138f0dc
3 changed files with 38 additions and 6 deletions

View file

@ -46,6 +46,7 @@ use windows::Win32::Graphics::Direct3D12::{
}; };
use windows::Win32::System::Threading::{CreateEventA, ResetEvent, WaitForSingleObject}; use windows::Win32::System::Threading::{CreateEventA, ResetEvent, WaitForSingleObject};
use windows::Win32::System::WindowsProgramming::INFINITE; use windows::Win32::System::WindowsProgramming::INFINITE;
use crate::options::FilterChainOptionsD3D12;
type DxilShaderPassMeta = ShaderPassArtifact<impl CompileReflectShader<DXIL, GlslangCompilation>>; type DxilShaderPassMeta = ShaderPassArtifact<impl CompileReflectShader<DXIL, GlslangCompilation>>;
type HlslShaderPassMeta = ShaderPassArtifact<impl CompileReflectShader<HLSL, GlslangCompilation>>; type HlslShaderPassMeta = ShaderPassArtifact<impl CompileReflectShader<HLSL, GlslangCompilation>>;
@ -89,7 +90,7 @@ impl FilterChainD3D12 {
pub fn load_from_path( pub fn load_from_path(
device: &ID3D12Device, device: &ID3D12Device,
path: impl AsRef<Path>, path: impl AsRef<Path>,
options: Option<&()>, options: Option<&FilterChainOptionsD3D12>,
) -> error::Result<FilterChainD3D12> { ) -> error::Result<FilterChainD3D12> {
// load passes from preset // load passes from preset
let preset = ShaderPreset::try_parse(path)?; let preset = ShaderPreset::try_parse(path)?;
@ -100,7 +101,7 @@ impl FilterChainD3D12 {
pub fn load_from_preset( pub fn load_from_preset(
device: &ID3D12Device, device: &ID3D12Device,
preset: ShaderPreset, preset: ShaderPreset,
_options: Option<&()>, options: Option<&FilterChainOptionsD3D12>,
) -> error::Result<FilterChainD3D12> { ) -> error::Result<FilterChainD3D12> {
let shader_count = preset.shaders.len(); let shader_count = preset.shaders.len();
let lut_count = preset.textures.len(); let lut_count = preset.textures.len();
@ -140,7 +141,8 @@ impl FilterChainD3D12 {
let root_signature = D3D12RootSignature::new(device)?; let root_signature = D3D12RootSignature::new(device)?;
let (texture_heap, sampler_heap, filters) = 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(); .unwrap();
// initialize output framebuffers // initialize output framebuffers
@ -332,6 +334,7 @@ impl FilterChainD3D12 {
passes: Vec<DxilShaderPassMeta>, passes: Vec<DxilShaderPassMeta>,
hlsl_passes: Vec<HlslShaderPassMeta>, hlsl_passes: Vec<HlslShaderPassMeta>,
semantics: &ShaderSemantics, semantics: &ShaderSemantics,
force_hlsl: bool,
) -> error::Result<(ID3D12DescriptorHeap, ID3D12DescriptorHeap, Vec<FilterPass>)> { ) -> error::Result<(ID3D12DescriptorHeap, ID3D12DescriptorHeap, Vec<FilterPass>)> {
let validator: IDxcValidator = unsafe { DxcCreateInstance(&CLSID_DxcValidator)? }; let validator: IDxcValidator = unsafe { DxcCreateInstance(&CLSID_DxcValidator)? };
@ -356,7 +359,8 @@ impl FilterChainD3D12 {
for ( for (
index, 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 ) in passes
.into_iter() .into_iter()
.zip(hlsl_passes) .zip(hlsl_passes)
@ -384,7 +388,8 @@ impl FilterChainD3D12 {
eprintln!("building pipeline for pass {:?}", index); eprintln!("building pipeline for pass {:?}", index);
/// incredibly cursed. /// 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( D3D12GraphicsPipeline::new_from_dxil(
device, device,
&library, &library,
@ -395,6 +400,7 @@ impl FilterChainD3D12 {
) { ) {
(dxil_reflection, graphics_pipeline) (dxil_reflection, graphics_pipeline)
} else { } else {
eprintln!("falling back to hlsl for {:?}", index);
let graphics_pipeline = D3D12GraphicsPipeline::new_from_hlsl( let graphics_pipeline = D3D12GraphicsPipeline::new_from_hlsl(
device, device,
&library, &library,

View file

@ -16,6 +16,7 @@ mod render_target;
mod samplers; mod samplers;
mod texture; mod texture;
mod util; mod util;
mod options;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
@ -26,7 +27,9 @@ mod tests {
fn triangle_d3d12() { fn triangle_d3d12() {
let sample = hello_triangle::d3d12_hello_triangle::Sample::new( let sample = hello_triangle::d3d12_hello_triangle::Sample::new(
// "../test/slang-shaders/crt/crt-lottes.slangp", // "../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 { &SampleCommandLine {
use_warp_device: false, use_warp_device: false,
}, },

View file

@ -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,
}