yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie Hermaszewskaformatf65d756bf

master
1.4 KiB58 linesraw
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(
14    ID3D12Device* device,
15    int size,
16    D3D12_DESCRIPTOR_HEAP_TYPE type,
17    D3D12_DESCRIPTOR_HEAP_FLAGS flags)
18{
19    m_device = device;
20
21    D3D12_DESCRIPTOR_HEAP_DESC srvHeapDesc = {};
22    srvHeapDesc.NumDescriptors = size;
23    srvHeapDesc.Flags = flags;
24    srvHeapDesc.Type = type;
25    SLANG_RETURN_ON_FAIL(
26        device->CreateDescriptorHeap(&srvHeapDesc, IID_PPV_ARGS(m_heap.writeRef())));
27
28    m_descriptorSize = device->GetDescriptorHandleIncrementSize(type);
29    m_totalSize = size;
30    m_heapFlags = flags;
31
32    return SLANG_OK;
33}
34
35Result D3D12DescriptorHeap::init(
36    ID3D12Device* device,
37    const D3D12_CPU_DESCRIPTOR_HANDLE* handles,
38    int numHandles,
39    D3D12_DESCRIPTOR_HEAP_TYPE type,
40    D3D12_DESCRIPTOR_HEAP_FLAGS flags)
41{
42    SLANG_RETURN_ON_FAIL(init(device, numHandles, type, flags));
43    D3D12_CPU_DESCRIPTOR_HANDLE dst = m_heap->GetCPUDescriptorHandleForHeapStart();
44
45    // Copy them all
46    for (int i = 0; i < numHandles; i++, dst.ptr += m_descriptorSize)
47    {
48        D3D12_CPU_DESCRIPTOR_HANDLE src = handles[i];
49        if (src.ptr != 0)
50        {
51            device->CopyDescriptorsSimple(1, dst, src, type);
52        }
53    }
54
55    return SLANG_OK;
56}
57
58} // namespace gfx