Jim Van Verth | 7359165 | 2020-05-08 12:50:38 -0400 | [diff] [blame] | 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 GrD3DAttachmentViewManager_DEFINED |
| 9 | #define GrD3DAttachmentViewManager_DEFINED |
| 10 | |
| 11 | #include "src/gpu/d3d/GrD3DDescriptorHeap.h" |
| 12 | |
| 13 | class GrD3DGpu; |
| 14 | |
| 15 | class GrD3DAttachmentViewManager { |
| 16 | public: |
| 17 | GrD3DAttachmentViewManager(GrD3DGpu*); |
| 18 | |
| 19 | D3D12_CPU_DESCRIPTOR_HANDLE createRenderTargetView(GrD3DGpu*, ID3D12Resource* textureResource); |
| 20 | void recycleRenderTargetView(D3D12_CPU_DESCRIPTOR_HANDLE*); |
| 21 | |
| 22 | D3D12_CPU_DESCRIPTOR_HANDLE createDepthStencilView(GrD3DGpu*, ID3D12Resource* textureResource); |
| 23 | void recycleDepthStencilView(D3D12_CPU_DESCRIPTOR_HANDLE*); |
| 24 | |
| 25 | private: |
| 26 | class Heap { |
| 27 | public: |
| 28 | static std::unique_ptr<Heap> Make(GrD3DGpu* gpu, D3D12_DESCRIPTOR_HEAP_TYPE type, |
| 29 | unsigned int numDescriptors); |
| 30 | |
| 31 | D3D12_CPU_DESCRIPTOR_HANDLE allocateCPUHandle(); |
| 32 | bool freeCPUHandle(D3D12_CPU_DESCRIPTOR_HANDLE*); |
| 33 | |
| 34 | bool canAllocate() { return fFreeCount > 0; } |
| 35 | |
| 36 | private: |
| 37 | Heap(std::unique_ptr<GrD3DDescriptorHeap>& heap, unsigned int numDescriptors) |
| 38 | : fHeap(std::move(heap)) |
| 39 | , fFreeBlocks(numDescriptors) |
| 40 | , fFreeCount(numDescriptors) { |
| 41 | for (unsigned int i = 0; i < numDescriptors; ++i) { |
| 42 | fFreeBlocks.set(i); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | std::unique_ptr<GrD3DDescriptorHeap> fHeap; |
| 47 | SkBitSet fFreeBlocks; |
| 48 | unsigned int fFreeCount; |
| 49 | }; |
| 50 | |
| 51 | class HeapPool { |
| 52 | public: |
| 53 | HeapPool(GrD3DGpu*, D3D12_DESCRIPTOR_HEAP_TYPE); |
| 54 | |
| 55 | D3D12_CPU_DESCRIPTOR_HANDLE allocateHandle(GrD3DGpu*); |
| 56 | void releaseHandle(D3D12_CPU_DESCRIPTOR_HANDLE*); |
| 57 | |
| 58 | private: |
| 59 | std::vector<std::unique_ptr<Heap>> fDescriptorHeaps; |
| 60 | int fMaxAvailableDescriptors; |
| 61 | D3D12_DESCRIPTOR_HEAP_TYPE fHeapType; |
| 62 | }; |
| 63 | |
| 64 | HeapPool fRTVDescriptorPool; |
| 65 | HeapPool fDSVDescriptorPool; |
| 66 | }; |
| 67 | |
| 68 | #endif |