yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1 2#include "d3d12-descriptor-heap.h" 3 4namespace gfx 5{ 6using namespace Slang ; 7 8D3D12DescriptorHeap ::D3D12DescriptorHeap () 9 :m_totalSize (0 ),m_currentIndex (0 ),m_descriptorSize (0 ) 10{ 11} 12 13Result D3D12DescriptorHeap ::init ( 14ID3D12Device * device , 15int size , 16D3D12_DESCRIPTOR_HEAP_TYPE type , 17D3D12_DESCRIPTOR_HEAP_FLAGS flags ) 18{ 19m_device = device ; 20 21D3D12_DESCRIPTOR_HEAP_DESC srvHeapDesc = {}; 22srvHeapDesc .NumDescriptors = size ; 23srvHeapDesc .Flags = flags ; 24srvHeapDesc .Type = type ; 25SLANG_RETURN_ON_FAIL ( 26device -> CreateDescriptorHeap (& srvHeapDesc ,IID_PPV_ARGS (m_heap .writeRef ()))); 27 28m_descriptorSize = device -> GetDescriptorHandleIncrementSize (type ); 29m_totalSize = size ; 30m_heapFlags = flags ; 31 32return SLANG_OK ; 33} 34 35Result D3D12DescriptorHeap ::init ( 36ID3D12Device * device , 37const D3D12_CPU_DESCRIPTOR_HANDLE * handles , 38int numHandles , 39D3D12_DESCRIPTOR_HEAP_TYPE type , 40D3D12_DESCRIPTOR_HEAP_FLAGS flags ) 41{ 42SLANG_RETURN_ON_FAIL (init (device ,numHandles ,type ,flags )); 43D3D12_CPU_DESCRIPTOR_HANDLE dst = m_heap -> GetCPUDescriptorHandleForHeapStart (); 44 45// Copy them all 46for (int i = 0 ;i < numHandles ;i ++ ,dst .ptr += m_descriptorSize ) 47 { 48D3D12_CPU_DESCRIPTOR_HANDLE src = handles [i ]; 49if (src .ptr != 0 ) 50 { 51device -> CopyDescriptorsSimple (1 ,dst ,src ,type ); 52 } 53 } 54 55return SLANG_OK ; 56} 57 58}// namespace gfx