Debian Codegraph @

src/gpu/ganesh/d3d/GrD3DCpuDescriptorManager.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 GrD3DCpuDescriptorManager_DEFINED
9 #define GrD3DCpuDescriptorManager_DEFINED
10
11 #include "src/gpu/ganesh/d3d/GrD3DDescriptorHeap.h"
12 #include <vector>
13
14 class GrD3DGpu;
15
16 class GrD3DCpuDescriptorManager {
17 public:
18 GrD3DCpuDescriptorManager(GrD3DGpu*);
19
20 GrD3DDescriptorHeap::CPUHandle createRenderTargetView(GrD3DGpu*,
21 ID3D12Resource* textureResource);
22 void recycleRenderTargetView(const GrD3DDescriptorHeap::CPUHandle&);
23
24 GrD3DDescriptorHeap::CPUHandle createDepthStencilView(GrD3DGpu*,
25 ID3D12Resource* textureResource);
26 void recycleDepthStencilView(const GrD3DDescriptorHeap::CPUHandle&);
27
28 GrD3DDescriptorHeap::CPUHandle createConstantBufferView(GrD3DGpu*,
29 ID3D12Resource* bufferResource,
30 size_t offset,
31 size_t size);
32 GrD3DDescriptorHeap::CPUHandle createShaderResourceView(GrD3DGpu*,
33 ID3D12Resource* resource,
34 unsigned int mostDetailedMip,
35 unsigned int mipLevels);
36 GrD3DDescriptorHeap::CPUHandle createUnorderedAccessView(GrD3DGpu*,
37 ID3D12Resource* resource,
38 unsigned int mipSlice);
39 void recycleShaderView(const GrD3DDescriptorHeap::CPUHandle&);
40
41 GrD3DDescriptorHeap::CPUHandle createSampler(GrD3DGpu*,
42 D3D12_FILTER filter,
43 float maxLOD,
44 unsigned int maxAnisotropy,
45 D3D12_TEXTURE_ADDRESS_MODE addressModeU,
46 D3D12_TEXTURE_ADDRESS_MODE addressModeV);
47 void recycleSampler(const GrD3DDescriptorHeap::CPUHandle&);
48
49 private:
50 class Heap {
51 public:
52 static std::unique_ptr<Heap> Make(GrD3DGpu* gpu, D3D12_DESCRIPTOR_HEAP_TYPE type,
53 unsigned int numDescriptors);
54
55 GrD3DDescriptorHeap::CPUHandle allocateCPUHandle();
56 void freeCPUHandle(const GrD3DDescriptorHeap::CPUHandle&);
57 bool ownsHandle(const GrD3DDescriptorHeap::CPUHandle& handle) {
58 return handle.fHeapID == fHeap->uniqueID();
59 }
60
61 bool canAllocate() { return fFreeCount > 0; }
62
63 private:
64 Heap(std::unique_ptr<GrD3DDescriptorHeap>& heap, unsigned int numDescriptors)
65 : fHeap(std::move(heap))
66 , fFreeBlocks(numDescriptors)
67 , fFreeCount(numDescriptors) {
68 for (unsigned int i = 0; i < numDescriptors; ++i) {
69 fFreeBlocks.set(i);
70 }
71 }
72
73 std::unique_ptr<GrD3DDescriptorHeap> fHeap;
74 SkBitSet fFreeBlocks;
75 unsigned int fFreeCount;
76 };
77
78 class HeapPool {
79 public:
80 HeapPool(GrD3DGpu*, D3D12_DESCRIPTOR_HEAP_TYPE);
81
82 GrD3DDescriptorHeap::CPUHandle allocateHandle(GrD3DGpu*);
83 void releaseHandle(const GrD3DDescriptorHeap::CPUHandle&);
84
85 private:
86 std::vector<std::unique_ptr<Heap>> fDescriptorHeaps;
87 int fMaxAvailableDescriptors;
88 D3D12_DESCRIPTOR_HEAP_TYPE fHeapType;
89 };
90
91 HeapPool fRTVDescriptorPool;
92 HeapPool fDSVDescriptorPool;
93 HeapPool fShaderViewDescriptorPool;
94 HeapPool fSamplerDescriptorPool;
95 };
96
97 #endif