fmt: clean up d3d12
This commit is contained in:
parent
34b334fd7f
commit
227cae6405
4 changed files with 57 additions and 73 deletions
|
@ -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 {
|
||||
|
|
|
@ -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<impl CompileReflectShader<DXIL, GlslangCompilation> + Send>;
|
||||
type HlslShaderPassMeta = ShaderPassArtifact<impl CompileReflectShader<HLSL, GlslangCompilation> + Send>;
|
||||
type DxilShaderPassMeta =
|
||||
ShaderPassArtifact<impl CompileReflectShader<DXIL, GlslangCompilation> + Send>;
|
||||
type HlslShaderPassMeta =
|
||||
ShaderPassArtifact<impl CompileReflectShader<HLSL, GlslangCompilation> + 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::<GlslangCompilation, FilterChainError>(
|
||||
preset.shaders,
|
||||
&preset.textures,
|
||||
)?;
|
||||
let (passes, semantics) = DXIL::compile_preset_passes::<
|
||||
GlslangCompilation,
|
||||
FilterChainError,
|
||||
>(preset.shaders, &preset.textures)?;
|
||||
|
||||
let (hlsl_passes, _) = HLSL::compile_preset_passes::<GlslangCompilation, FilterChainError>(
|
||||
shader_copy,
|
||||
|
@ -361,10 +362,8 @@ impl FilterChainD3D12 {
|
|||
let filters: Vec<error::Result<_>> = 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<Vec<_>> = filters.into_iter().collect();
|
||||
let filters = filters?;
|
||||
|
||||
let filters: Vec<error::Result<FilterPass>> = filters.into_iter()
|
||||
let filters: Vec<error::Result<FilterPass>> = 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<Vec<_>> = filters.into_iter().collect();
|
||||
let filters = filters?;
|
||||
|
|
|
@ -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<D3D12GraphicsPipeline> {
|
||||
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 =
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue