Debian Codegraph @

src/gpu/ganesh/d3d/GrD3DDescriptorHeap.h

raw
1 /*
2 * Copyright 2020 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef GrD3DDescriptorHeap_DEFINED
9 #define GrD3DDescriptorHeap_DEFINED
10
11 #include "include/gpu/ganesh/d3d/GrD3DTypes.h"
12 #include "src/gpu/ganesh/GrManagedResource.h"
13 #include "src/utils/SkBitSet.h"
14
15 class GrD3DGpu;
16
17 class GrD3DDescriptorHeap {
18 public:
19 static std::unique_ptr<GrD3DDescriptorHeap> Make(GrD3DGpu* gpu, D3D12_DESCRIPTOR_HEAP_TYPE,
20 unsigned int numDescriptors,
21 D3D12_DESCRIPTOR_HEAP_FLAGS);
22
23 ~GrD3DDescriptorHeap() = default;
24
25 uint32_t uniqueID() const { return fUniqueID; }
26
27 struct CPUHandle {
28 D3D12_CPU_DESCRIPTOR_HANDLE fHandle;
29 uint32_t fHeapID;
30 };
31
32 struct GPUHandle {
33 D3D12_GPU_DESCRIPTOR_HANDLE fHandle;
34 uint32_t fHeapID;
35 };
36
37 CPUHandle getCPUHandle(unsigned int index); // write-only if shader-visible
38 GPUHandle getGPUHandle(unsigned int index);
39 ID3D12DescriptorHeap* descriptorHeap() const { return fHeap.get(); }
40 size_t handleIncrementSize() { return fHandleIncrementSize; }
41
42 size_t getIndex(const CPUHandle& handle) {
43 SkASSERT(handle.fHeapID == fUniqueID);
44 size_t index = (handle.fHandle.ptr - fCPUHeapStart.ptr) / fHandleIncrementSize;
45 SkASSERT(index < fHeap->GetDesc().NumDescriptors);
46 SkASSERT(handle.fHandle.ptr == fCPUHeapStart.ptr + index * fHandleIncrementSize);
47 return index;
48 }
49
50 size_t getIndex(const GPUHandle& handle) {
51 SkASSERT(handle.fHeapID == fUniqueID);
52 size_t index = (handle.fHandle.ptr - fCPUHeapStart.ptr) / fHandleIncrementSize;
53 SkASSERT(index < fHeap->GetDesc().NumDescriptors);
54 SkASSERT(handle.fHandle.ptr == fCPUHeapStart.ptr + index * fHandleIncrementSize);
55 return index;
56 }
57
58 protected:
59 GrD3DDescriptorHeap(const gr_cp<ID3D12DescriptorHeap>&, unsigned int handleIncrementSize);
60
61 static uint32_t GenID() {
62 static std::atomic<uint32_t> nextID{1};
63 uint32_t id;
64 do {
65 id = nextID++;
66 } while (id == SK_InvalidUniqueID);
67 return id;
68 }
69
70 gr_cp<ID3D12DescriptorHeap> fHeap;
71 size_t fHandleIncrementSize;
72 D3D12_CPU_DESCRIPTOR_HANDLE fCPUHeapStart;
73 D3D12_GPU_DESCRIPTOR_HANDLE fGPUHeapStart;
74 uint32_t fUniqueID;
75 };
76
77 #endif