d3d12: try to do desc heaps
This commit is contained in:
parent
92c9836985
commit
4dc34fceb2
|
@ -1,7 +1,12 @@
|
|||
use std::ptr::NonNull;
|
||||
use std::sync::Arc;
|
||||
use windows::Win32::Graphics::Direct3D12::{D3D12_CPU_DESCRIPTOR_HANDLE, D3D12_DESCRIPTOR_HEAP_DESC, D3D12_GPU_DESCRIPTOR_HANDLE, ID3D12DescriptorHeap, ID3D12Device};
|
||||
use crate::error;
|
||||
|
||||
pub struct D3D12DescriptorHeapSlot {
|
||||
cpu_handle: D3D12_CPU_DESCRIPTOR_HANDLE,
|
||||
heap: Arc<D3D12DescriptorHeap>
|
||||
}
|
||||
|
||||
pub struct D3D12DescriptorHeap {
|
||||
heap: ID3D12DescriptorHeap,
|
||||
desc: D3D12_DESCRIPTOR_HEAP_DESC,
|
||||
|
@ -13,7 +18,7 @@ pub struct D3D12DescriptorHeap {
|
|||
}
|
||||
|
||||
impl D3D12DescriptorHeap {
|
||||
pub fn new(device: &ID3D12Device, desc: D3D12_DESCRIPTOR_HEAP_DESC) -> error::Result<D3D12DescriptorHeap> {
|
||||
pub fn new(device: &ID3D12Device, desc: D3D12_DESCRIPTOR_HEAP_DESC) -> error::Result<Arc<D3D12DescriptorHeap>> {
|
||||
unsafe {
|
||||
let heap: ID3D12DescriptorHeap = device.CreateDescriptorHeap(&desc)?;
|
||||
let cpu_handle = heap.GetCPUDescriptorHandleForHeapStart();
|
||||
|
@ -22,7 +27,7 @@ impl D3D12DescriptorHeap {
|
|||
let mut map = Vec::new();
|
||||
map.resize(desc.NumDescriptors as usize, false);
|
||||
|
||||
Ok(D3D12DescriptorHeap {
|
||||
Ok(Arc::new(D3D12DescriptorHeap {
|
||||
heap,
|
||||
desc,
|
||||
cpu_handle,
|
||||
|
@ -30,11 +35,29 @@ impl D3D12DescriptorHeap {
|
|||
alignment,
|
||||
map: Box::new([]),
|
||||
start: 0,
|
||||
})
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn allocate_slot(&mut self) -> error::Result<D3D12_CPU_DESCRIPTOR_HANDLE> {
|
||||
pub fn allocate_slot(self: &Arc<D3D12DescriptorHeap>) -> error::Result<D3D12DescriptorHeapSlot> {
|
||||
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(D3D12DescriptorHeapSlot {
|
||||
cpu_handle: handle,
|
||||
heap: Arc::clone(self),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
todo!("error need to fail");
|
||||
}
|
||||
|
||||
pub fn free_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 {
|
||||
|
@ -49,4 +72,6 @@ impl D3D12DescriptorHeap {
|
|||
todo!("error need to fail");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop
|
|
@ -4,5 +4,4 @@ use librashader_common::{FilterMode, WrapMode};
|
|||
|
||||
pub struct SamplerSet {
|
||||
samplers: FxHashMap<(WrapMode, FilterMode), D3D12_GPU_DESCRIPTOR_HANDLE>,
|
||||
heap: D3D12Descriptor_heap
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue