d3d12: try to do desc heaps

This commit is contained in:
chyyran 2023-01-21 15:34:13 -05:00 committed by Ronny Chan
parent 0ceb70d799
commit 92c9836985
4 changed files with 118 additions and 0 deletions

View file

@ -0,0 +1,52 @@
use std::ptr::NonNull;
use windows::Win32::Graphics::Direct3D12::{D3D12_CPU_DESCRIPTOR_HANDLE, D3D12_DESCRIPTOR_HEAP_DESC, D3D12_GPU_DESCRIPTOR_HANDLE, ID3D12DescriptorHeap, ID3D12Device};
use crate::error;
pub struct D3D12DescriptorHeap {
heap: ID3D12DescriptorHeap,
desc: D3D12_DESCRIPTOR_HEAP_DESC,
cpu_handle: D3D12_CPU_DESCRIPTOR_HANDLE,
gpu_handle: D3D12_GPU_DESCRIPTOR_HANDLE,
alignment: u32,
map: Box<[bool]>,
start: usize
}
impl D3D12DescriptorHeap {
pub fn new(device: &ID3D12Device, desc: D3D12_DESCRIPTOR_HEAP_DESC) -> error::Result<D3D12DescriptorHeap> {
unsafe {
let heap: ID3D12DescriptorHeap = device.CreateDescriptorHeap(&desc)?;
let cpu_handle = heap.GetCPUDescriptorHandleForHeapStart();
let gpu_handle = heap.GetGPUDescriptorHandleForHeapStart();
let alignment = device.GetDescriptorHandleIncrementSize(desc.Type);
let mut map = Vec::new();
map.resize(desc.NumDescriptors as usize, false);
Ok(D3D12DescriptorHeap {
heap,
desc,
cpu_handle,
gpu_handle,
alignment,
map: Box::new([]),
start: 0,
})
}
}
pub fn allocate_slot(&mut self) -> error::Result<D3D12_CPU_DESCRIPTOR_HANDLE> {
let mut handle = D3D12_CPU_DESCRIPTOR_HANDLE { ptr: 0 };
for i in self.start..self.desc.NumDescriptors as usize {
if !self.map[i] {
self.map[i] = true;
handle.ptr = self.cpu_handle.ptr + (i * self.alignment) as u64;
self.start = i + 1;
return Ok(handle);
}
}
todo!("error need to fail");
}
}

View file

@ -0,0 +1,3 @@
use std::error::Error;
pub type Result<T> = std::result::Result<T, Box<dyn Error>>;

View file

@ -0,0 +1,55 @@
use std::error::Error;
use std::path::Path;
use rustc_hash::FxHashMap;
use windows::Win32::Graphics::Direct3D12::ID3D12Device;
use librashader_presets::ShaderPreset;
use librashader_reflect::back::targets::HLSL;
use librashader_reflect::front::GlslangCompilation;
use librashader_reflect::reflect::presets::CompilePresetTarget;
use crate::error;
pub struct FilterChainD3D12 {
pub(crate) common: FilterCommon,
// pub(crate) passes: Vec<FilterPass>,
// pub(crate) output_framebuffers: Box<[OwnedFramebuffer]>,
// pub(crate) feedback_framebuffers: Box<[OwnedFramebuffer]>,
// pub(crate) history_framebuffers: VecDeque<OwnedFramebuffer>,
// pub(crate) draw_quad: DrawQuad,
}
pub(crate) struct FilterCommon {
pub(crate) d3d12: ID3D12Device,
// pub(crate) luts: FxHashMap<usize, LutTexture>,
// pub samplers: SamplerSet,
// pub output_textures: Box<[Option<InputTexture>]>,
// pub feedback_textures: Box<[Option<InputTexture>]>,
// pub history_textures: Box<[Option<InputTexture>]>,
// pub config: FilterMutable,
// pub disable_mipmaps: bool,
}
impl FilterChainD3D12 {
/// Load the shader preset at the given path into a filter chain.
pub fn load_from_path(
path: impl AsRef<Path>,
options: Option<&()>,
) -> error::Result<FilterChainD3D12> {
// load passes from preset
let preset = ShaderPreset::try_parse(path)?;
Self::load_from_preset(preset, options)
}
/// Load a filter chain from a pre-parsed `ShaderPreset`.
pub fn load_from_preset(
preset: ShaderPreset,
options: Option<&()>,
) -> error::Result<FilterChainD3D12> {
let (passes, semantics) = HLSL::compile_preset_passes::<
GlslangCompilation,
Box<dyn Error>,
>(preset.shaders, &preset.textures)?;
todo!()
}
}

View file

@ -0,0 +1,8 @@
use rustc_hash::FxHashMap;
use windows::Win32::Graphics::Direct3D12::D3D12_GPU_DESCRIPTOR_HANDLE;
use librashader_common::{FilterMode, WrapMode};
pub struct SamplerSet {
samplers: FxHashMap<(WrapMode, FilterMode), D3D12_GPU_DESCRIPTOR_HANDLE>,
heap: D3D12Descriptor_heap
}