From 227cae640508131f1b6bc0d6b1e4ac49e9a7a9ce Mon Sep 17 00:00:00 2001 From: chyyran Date: Sun, 5 Feb 2023 20:05:22 -0500 Subject: [PATCH] fmt: clean up d3d12 --- .../src/descriptor_heap.rs | 2 +- librashader-runtime-d3d12/src/filter_chain.rs | 89 ++++++++++--------- .../src/graphics_pipeline.rs | 12 ++- librashader-runtime-d3d12/src/util.rs | 27 +----- 4 files changed, 57 insertions(+), 73 deletions(-) diff --git a/librashader-runtime-d3d12/src/descriptor_heap.rs b/librashader-runtime-d3d12/src/descriptor_heap.rs index 3eca04e..720b3ae 100644 --- a/librashader-runtime-d3d12/src/descriptor_heap.rs +++ b/librashader-runtime-d3d12/src/descriptor_heap.rs @@ -4,6 +4,7 @@ use std::marker::PhantomData; use std::ops::Deref; use std::rc::Rc; +use crate::error::FilterChainError; use windows::Win32::Graphics::Direct3D12::{ ID3D12DescriptorHeap, ID3D12Device, D3D12_CPU_DESCRIPTOR_HANDLE, D3D12_DESCRIPTOR_HEAP_DESC, D3D12_DESCRIPTOR_HEAP_FLAG_NONE, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE, @@ -11,7 +12,6 @@ use windows::Win32::Graphics::Direct3D12::{ D3D12_DESCRIPTOR_HEAP_TYPE_RTV, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, D3D12_GPU_DESCRIPTOR_HANDLE, }; -use crate::error::FilterChainError; #[const_trait] pub trait D3D12HeapType { diff --git a/librashader-runtime-d3d12/src/filter_chain.rs b/librashader-runtime-d3d12/src/filter_chain.rs index b4a9702..a2c9d3c 100644 --- a/librashader-runtime-d3d12/src/filter_chain.rs +++ b/librashader-runtime-d3d12/src/filter_chain.rs @@ -2,6 +2,7 @@ use crate::buffer::{D3D12Buffer, D3D12ConstantBuffer}; use crate::descriptor_heap::{ CpuStagingHeap, D3D12DescriptorHeap, RenderTargetHeap, ResourceWorkHeap, }; +use crate::error::FilterChainError; use crate::filter_pass::FilterPass; use crate::framebuffer::OwnedImage; use crate::graphics_pipeline::{D3D12GraphicsPipeline, D3D12RootSignature}; @@ -47,11 +48,12 @@ use windows::Win32::Graphics::Direct3D12::{ use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_UNKNOWN; use windows::Win32::System::Threading::{CreateEventA, ResetEvent, WaitForSingleObject}; use windows::Win32::System::WindowsProgramming::INFINITE; -use crate::error::FilterChainError; use rayon::prelude::*; -type DxilShaderPassMeta = ShaderPassArtifact + Send>; -type HlslShaderPassMeta = ShaderPassArtifact + Send>; +type DxilShaderPassMeta = + ShaderPassArtifact + Send>; +type HlslShaderPassMeta = + ShaderPassArtifact + Send>; pub struct FilterMutable { pub(crate) passes_enabled: usize, @@ -113,11 +115,10 @@ impl FilterChainD3D12 { let shader_copy = preset.shaders.clone(); - let (passes, semantics) = - DXIL::compile_preset_passes::( - preset.shaders, - &preset.textures, - )?; + let (passes, semantics) = DXIL::compile_preset_passes::< + GlslangCompilation, + FilterChainError, + >(preset.shaders, &preset.textures)?; let (hlsl_passes, _) = HLSL::compile_preset_passes::( shader_copy, @@ -361,10 +362,8 @@ impl FilterChainD3D12 { let filters: Vec> = passes.into_par_iter() .zip(hlsl_passes) .enumerate() - .map(|( - index, - ((config, source, mut dxil), - (_, _, mut hlsl)), )|{ + .map(|(index, ((config, source, mut dxil), + (_, _, mut hlsl)))| { let validator: IDxcValidator = unsafe { DxcCreateInstance(&CLSID_DxcValidator)? }; let library: IDxcUtils = unsafe { DxcCreateInstance(&CLSID_DxcLibrary)? }; let compiler: IDxcCompiler = unsafe { DxcCreateInstance(&CLSID_DxcCompiler)? }; @@ -383,10 +382,7 @@ impl FilterChainD3D12 { source.format } else { ImageFormat::R8G8B8A8Unorm - } - .into(); - - eprintln!("building pipeline for pass {index:?}"); + }.into(); /// incredibly cursed. let (reflection, graphics_pipeline) = if !force_hlsl && @@ -401,7 +397,6 @@ impl FilterChainD3D12 { ) { (dxil_reflection, graphics_pipeline) } else { - eprintln!("falling back to hlsl for {index:?}"); let graphics_pipeline = D3D12GraphicsPipeline::new_from_hlsl( device, &library, @@ -451,33 +446,43 @@ impl FilterChainD3D12 { let filters: error::Result> = filters.into_iter().collect(); let filters = filters?; - let filters: Vec> = filters.into_iter() + let filters: Vec> = filters + .into_iter() .zip(work_heaps) .zip(sampler_work_heaps) - .map(|(((reflection, - uniform_bindings, - uniform_storage, - push_cbuffer, - ubo_cbuffer, - pipeline, - config, - source), mut texture_heap), mut sampler_heap)| { - - let texture_heap = texture_heap.alloc_range()?; - let sampler_heap = sampler_heap.alloc_range()?; - Ok(FilterPass { - reflection, - uniform_bindings, - uniform_storage, - push_cbuffer, - ubo_cbuffer, - pipeline, - config, - texture_heap, - sampler_heap, - source, - }) - }) + .map( + |( + ( + ( + reflection, + uniform_bindings, + uniform_storage, + push_cbuffer, + ubo_cbuffer, + pipeline, + config, + source, + ), + mut texture_heap, + ), + mut sampler_heap, + )| { + let texture_heap = texture_heap.alloc_range()?; + let sampler_heap = sampler_heap.alloc_range()?; + Ok(FilterPass { + reflection, + uniform_bindings, + uniform_storage, + push_cbuffer, + ubo_cbuffer, + pipeline, + config, + texture_heap, + sampler_heap, + source, + }) + }, + ) .collect(); let filters: error::Result> = filters.into_iter().collect(); let filters = filters?; diff --git a/librashader-runtime-d3d12/src/graphics_pipeline.rs b/librashader-runtime-d3d12/src/graphics_pipeline.rs index 65223d0..ba9092c 100644 --- a/librashader-runtime-d3d12/src/graphics_pipeline.rs +++ b/librashader-runtime-d3d12/src/graphics_pipeline.rs @@ -1,3 +1,5 @@ +use crate::error::assume_d3d12_init; +use crate::error::FilterChainError::Direct3DOperationError; use crate::quad_render::DrawQuad; use crate::{error, util}; use librashader_reflect::back::cross::CrossHlslContext; @@ -20,8 +22,6 @@ use windows::Win32::Graphics::Direct3D12::{ D3D12_SHADER_VISIBILITY_ALL, D3D12_SHADER_VISIBILITY_PIXEL, D3D_ROOT_SIGNATURE_VERSION_1, }; use windows::Win32::Graphics::Dxgi::Common::{DXGI_FORMAT, DXGI_FORMAT_UNKNOWN, DXGI_SAMPLE_DESC}; -use crate::error::assume_d3d12_init; -use crate::error::FilterChainError::Direct3DOperationError; pub struct D3D12GraphicsPipeline { pub(crate) handle: ID3D12PipelineState, @@ -216,10 +216,14 @@ impl D3D12GraphicsPipeline { render_format: DXGI_FORMAT, ) -> error::Result { if shader_assembly.vertex.requires_runtime_data() { - return Err(Direct3DOperationError("Compiled DXIL Vertex shader needs unexpected runtime data")) + return Err(Direct3DOperationError( + "Compiled DXIL Vertex shader needs unexpected runtime data", + )); } if shader_assembly.fragment.requires_runtime_data() { - return Err(Direct3DOperationError("Compiled DXIL fragment shader needs unexpected runtime data")) + return Err(Direct3DOperationError( + "Compiled DXIL fragment shader needs unexpected runtime data", + )); } let vertex_dxil = util::dxc_validate_shader(library, validator, &shader_assembly.vertex)?; let fragment_dxil = diff --git a/librashader-runtime-d3d12/src/util.rs b/librashader-runtime-d3d12/src/util.rs index 8746f3d..3f27261 100644 --- a/librashader-runtime-d3d12/src/util.rs +++ b/librashader-runtime-d3d12/src/util.rs @@ -195,18 +195,6 @@ pub fn dxc_compile_shader( &include, )?; - if let Ok(buf) = result.GetErrorBuffer() { - unsafe { - let buf: IDxcBlobUtf8 = buf.cast()?; - let buf = - std::slice::from_raw_parts(buf.GetBufferPointer().cast(), buf.GetBufferSize()); - let str = std::str::from_utf8_unchecked(buf); - if !str.is_empty() { - eprintln!("{str}"); - } - } - } - let result = result.GetResult()?; Ok(result) } @@ -224,20 +212,7 @@ pub fn dxc_validate_shader( unsafe { library.CreateBlob(source.as_ptr().cast(), source.len() as u32, DXC_CP(0))? }; unsafe { - let result = validator - .Validate(&blob, DxcValidatorFlags_InPlaceEdit)?; - - if let Ok(buf) = result.GetErrorBuffer() { - unsafe { - let buf: IDxcBlobUtf8 = buf.cast()?; - let buf = - std::slice::from_raw_parts(buf.GetBufferPointer().cast(), buf.GetBufferSize()); - let str = std::str::from_utf8_unchecked(buf); - if !str.is_empty() { - eprintln!("{str}"); - } - } - } + let _result = validator.Validate(&blob, DxcValidatorFlags_InPlaceEdit)?; Ok(IDxcBlob::from(blob)) } }