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::ops::Deref;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
use crate::error::FilterChainError;
|
||||||
use windows::Win32::Graphics::Direct3D12::{
|
use windows::Win32::Graphics::Direct3D12::{
|
||||||
ID3D12DescriptorHeap, ID3D12Device, D3D12_CPU_DESCRIPTOR_HANDLE, D3D12_DESCRIPTOR_HEAP_DESC,
|
ID3D12DescriptorHeap, ID3D12Device, D3D12_CPU_DESCRIPTOR_HANDLE, D3D12_DESCRIPTOR_HEAP_DESC,
|
||||||
D3D12_DESCRIPTOR_HEAP_FLAG_NONE, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE,
|
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_DESCRIPTOR_HEAP_TYPE_RTV, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER,
|
||||||
D3D12_GPU_DESCRIPTOR_HANDLE,
|
D3D12_GPU_DESCRIPTOR_HANDLE,
|
||||||
};
|
};
|
||||||
use crate::error::FilterChainError;
|
|
||||||
|
|
||||||
#[const_trait]
|
#[const_trait]
|
||||||
pub trait D3D12HeapType {
|
pub trait D3D12HeapType {
|
||||||
|
|
|
@ -2,6 +2,7 @@ use crate::buffer::{D3D12Buffer, D3D12ConstantBuffer};
|
||||||
use crate::descriptor_heap::{
|
use crate::descriptor_heap::{
|
||||||
CpuStagingHeap, D3D12DescriptorHeap, RenderTargetHeap, ResourceWorkHeap,
|
CpuStagingHeap, D3D12DescriptorHeap, RenderTargetHeap, ResourceWorkHeap,
|
||||||
};
|
};
|
||||||
|
use crate::error::FilterChainError;
|
||||||
use crate::filter_pass::FilterPass;
|
use crate::filter_pass::FilterPass;
|
||||||
use crate::framebuffer::OwnedImage;
|
use crate::framebuffer::OwnedImage;
|
||||||
use crate::graphics_pipeline::{D3D12GraphicsPipeline, D3D12RootSignature};
|
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::Graphics::Dxgi::Common::DXGI_FORMAT_UNKNOWN;
|
||||||
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::error::FilterChainError;
|
|
||||||
|
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
type DxilShaderPassMeta = ShaderPassArtifact<impl CompileReflectShader<DXIL, GlslangCompilation> + Send>;
|
type DxilShaderPassMeta =
|
||||||
type HlslShaderPassMeta = ShaderPassArtifact<impl CompileReflectShader<HLSL, GlslangCompilation> + Send>;
|
ShaderPassArtifact<impl CompileReflectShader<DXIL, GlslangCompilation> + Send>;
|
||||||
|
type HlslShaderPassMeta =
|
||||||
|
ShaderPassArtifact<impl CompileReflectShader<HLSL, GlslangCompilation> + Send>;
|
||||||
|
|
||||||
pub struct FilterMutable {
|
pub struct FilterMutable {
|
||||||
pub(crate) passes_enabled: usize,
|
pub(crate) passes_enabled: usize,
|
||||||
|
@ -113,11 +115,10 @@ impl FilterChainD3D12 {
|
||||||
|
|
||||||
let shader_copy = preset.shaders.clone();
|
let shader_copy = preset.shaders.clone();
|
||||||
|
|
||||||
let (passes, semantics) =
|
let (passes, semantics) = DXIL::compile_preset_passes::<
|
||||||
DXIL::compile_preset_passes::<GlslangCompilation, FilterChainError>(
|
GlslangCompilation,
|
||||||
preset.shaders,
|
FilterChainError,
|
||||||
&preset.textures,
|
>(preset.shaders, &preset.textures)?;
|
||||||
)?;
|
|
||||||
|
|
||||||
let (hlsl_passes, _) = HLSL::compile_preset_passes::<GlslangCompilation, FilterChainError>(
|
let (hlsl_passes, _) = HLSL::compile_preset_passes::<GlslangCompilation, FilterChainError>(
|
||||||
shader_copy,
|
shader_copy,
|
||||||
|
@ -361,10 +362,8 @@ impl FilterChainD3D12 {
|
||||||
let filters: Vec<error::Result<_>> = passes.into_par_iter()
|
let filters: Vec<error::Result<_>> = passes.into_par_iter()
|
||||||
.zip(hlsl_passes)
|
.zip(hlsl_passes)
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(
|
.map(|(index, ((config, source, mut dxil),
|
||||||
index,
|
(_, _, mut hlsl)))| {
|
||||||
((config, source, mut dxil),
|
|
||||||
(_, _, mut hlsl)), )|{
|
|
||||||
let validator: IDxcValidator = unsafe { DxcCreateInstance(&CLSID_DxcValidator)? };
|
let validator: IDxcValidator = unsafe { DxcCreateInstance(&CLSID_DxcValidator)? };
|
||||||
let library: IDxcUtils = unsafe { DxcCreateInstance(&CLSID_DxcLibrary)? };
|
let library: IDxcUtils = unsafe { DxcCreateInstance(&CLSID_DxcLibrary)? };
|
||||||
let compiler: IDxcCompiler = unsafe { DxcCreateInstance(&CLSID_DxcCompiler)? };
|
let compiler: IDxcCompiler = unsafe { DxcCreateInstance(&CLSID_DxcCompiler)? };
|
||||||
|
@ -383,10 +382,7 @@ impl FilterChainD3D12 {
|
||||||
source.format
|
source.format
|
||||||
} else {
|
} else {
|
||||||
ImageFormat::R8G8B8A8Unorm
|
ImageFormat::R8G8B8A8Unorm
|
||||||
}
|
}.into();
|
||||||
.into();
|
|
||||||
|
|
||||||
eprintln!("building pipeline for pass {index:?}");
|
|
||||||
|
|
||||||
/// incredibly cursed.
|
/// incredibly cursed.
|
||||||
let (reflection, graphics_pipeline) = if !force_hlsl &&
|
let (reflection, graphics_pipeline) = if !force_hlsl &&
|
||||||
|
@ -401,7 +397,6 @@ 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,
|
||||||
|
@ -451,18 +446,27 @@ impl FilterChainD3D12 {
|
||||||
let filters: error::Result<Vec<_>> = filters.into_iter().collect();
|
let filters: error::Result<Vec<_>> = filters.into_iter().collect();
|
||||||
let filters = filters?;
|
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(work_heaps)
|
||||||
.zip(sampler_work_heaps)
|
.zip(sampler_work_heaps)
|
||||||
.map(|(((reflection,
|
.map(
|
||||||
|
|(
|
||||||
|
(
|
||||||
|
(
|
||||||
|
reflection,
|
||||||
uniform_bindings,
|
uniform_bindings,
|
||||||
uniform_storage,
|
uniform_storage,
|
||||||
push_cbuffer,
|
push_cbuffer,
|
||||||
ubo_cbuffer,
|
ubo_cbuffer,
|
||||||
pipeline,
|
pipeline,
|
||||||
config,
|
config,
|
||||||
source), mut texture_heap), mut sampler_heap)| {
|
source,
|
||||||
|
),
|
||||||
|
mut texture_heap,
|
||||||
|
),
|
||||||
|
mut sampler_heap,
|
||||||
|
)| {
|
||||||
let texture_heap = texture_heap.alloc_range()?;
|
let texture_heap = texture_heap.alloc_range()?;
|
||||||
let sampler_heap = sampler_heap.alloc_range()?;
|
let sampler_heap = sampler_heap.alloc_range()?;
|
||||||
Ok(FilterPass {
|
Ok(FilterPass {
|
||||||
|
@ -477,7 +481,8 @@ impl FilterChainD3D12 {
|
||||||
sampler_heap,
|
sampler_heap,
|
||||||
source,
|
source,
|
||||||
})
|
})
|
||||||
})
|
},
|
||||||
|
)
|
||||||
.collect();
|
.collect();
|
||||||
let filters: error::Result<Vec<_>> = filters.into_iter().collect();
|
let filters: error::Result<Vec<_>> = filters.into_iter().collect();
|
||||||
let filters = filters?;
|
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::quad_render::DrawQuad;
|
||||||
use crate::{error, util};
|
use crate::{error, util};
|
||||||
use librashader_reflect::back::cross::CrossHlslContext;
|
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,
|
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 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 struct D3D12GraphicsPipeline {
|
||||||
pub(crate) handle: ID3D12PipelineState,
|
pub(crate) handle: ID3D12PipelineState,
|
||||||
|
@ -216,10 +216,14 @@ impl D3D12GraphicsPipeline {
|
||||||
render_format: DXGI_FORMAT,
|
render_format: DXGI_FORMAT,
|
||||||
) -> error::Result<D3D12GraphicsPipeline> {
|
) -> error::Result<D3D12GraphicsPipeline> {
|
||||||
if shader_assembly.vertex.requires_runtime_data() {
|
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() {
|
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 vertex_dxil = util::dxc_validate_shader(library, validator, &shader_assembly.vertex)?;
|
||||||
let fragment_dxil =
|
let fragment_dxil =
|
||||||
|
|
|
@ -195,18 +195,6 @@ pub fn dxc_compile_shader(
|
||||||
&include,
|
&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()?;
|
let result = result.GetResult()?;
|
||||||
Ok(result)
|
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 { library.CreateBlob(source.as_ptr().cast(), source.len() as u32, DXC_CP(0))? };
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let result = validator
|
let _result = validator.Validate(&blob, DxcValidatorFlags_InPlaceEdit)?;
|
||||||
.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}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(IDxcBlob::from(blob))
|
Ok(IDxcBlob::from(blob))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue