Flutter Engine
The Flutter Engine
GrD3DDescriptorHeap.h
Go to the documentation of this file.
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
13#include "src/utils/SkBitSet.h"
14
15class GrD3DGpu;
16
18public:
19 static std::unique_ptr<GrD3DDescriptorHeap> Make(GrD3DGpu* gpu, D3D12_DESCRIPTOR_HEAP_TYPE,
20 unsigned int numDescriptors,
21 D3D12_DESCRIPTOR_HEAP_FLAGS);
22
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(); }
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
58protected:
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
72 D3D12_CPU_DESCRIPTOR_HANDLE fCPUHeapStart;
73 D3D12_GPU_DESCRIPTOR_HANDLE fGPUHeapStart;
74 uint32_t fUniqueID;
75};
76
77#endif
#define SkASSERT(cond)
Definition: SkAssert.h:116
static constexpr uint32_t SK_InvalidUniqueID
Definition: SkTypes.h:196
D3D12_GPU_DESCRIPTOR_HANDLE fGPUHeapStart
~GrD3DDescriptorHeap()=default
static uint32_t GenID()
size_t getIndex(const GPUHandle &handle)
size_t getIndex(const CPUHandle &handle)
GPUHandle getGPUHandle(unsigned int index)
ID3D12DescriptorHeap * descriptorHeap() const
gr_cp< ID3D12DescriptorHeap > fHeap
CPUHandle getCPUHandle(unsigned int index)
uint32_t uniqueID() const
GrD3DDescriptorHeap(const gr_cp< ID3D12DescriptorHeap > &, unsigned int handleIncrementSize)
static std::unique_ptr< GrD3DDescriptorHeap > Make(GrD3DGpu *gpu, D3D12_DESCRIPTOR_HEAP_TYPE, unsigned int numDescriptors, D3D12_DESCRIPTOR_HEAP_FLAGS)
D3D12_CPU_DESCRIPTOR_HANDLE fCPUHeapStart
T * get() const
Definition: GrD3DTypes.h:108
D3D12_CPU_DESCRIPTOR_HANDLE fHandle
D3D12_GPU_DESCRIPTOR_HANDLE fHandle
const uintptr_t id