Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrD3DResourceProvider.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 GrD3DResourceProvider_DEFINED
9#define GrD3DResourceProvider_DEFINED
10
13#include "src/core/SkChecksum.h"
14#include "src/core/SkLRUCache.h"
15#include "src/core/SkTHash.h"
24
25#include <memory>
26
29class GrD3DGpu;
32class GrSamplerState;
33
35public:
37
38 void destroyResources();
39
40 std::unique_ptr<GrD3DDirectCommandList> findOrCreateDirectCommandList();
41
42 void recycleDirectCommandList(std::unique_ptr<GrD3DDirectCommandList>);
43
45 int numUAVs = 0);
46
48 unsigned int slot);
49
50 GrD3DDescriptorHeap::CPUHandle createRenderTargetView(ID3D12Resource* textureResource);
52
53 GrD3DDescriptorHeap::CPUHandle createDepthStencilView(ID3D12Resource* textureResource);
55
56 GrD3DDescriptorHeap::CPUHandle createConstantBufferView(ID3D12Resource* bufferResource,
57 size_t offset,
58 size_t size);
60 unsigned int mostDetailedMip = 0,
61 unsigned int mipLevels = -1);
63 unsigned int mipSlice);
65
66 D3D12_CPU_DESCRIPTOR_HANDLE findOrCreateCompatibleSampler(const GrSamplerState& params);
67
69 const std::vector<D3D12_CPU_DESCRIPTOR_HANDLE>& shaderViews);
71 const std::vector<D3D12_CPU_DESCRIPTOR_HANDLE>& samplers);
73 return &fDescriptorTableManager;
74 }
75
77 const GrProgramInfo&);
78
80
81 D3D12_GPU_VIRTUAL_ADDRESS uploadConstantData(void* data, size_t size);
82 void prepForSubmit();
83
84 void markPipelineStateUniformsDirty() { fPipelineStateCache->markPipelineStateUniformsDirty(); }
85
86#if defined(GR_TEST_UTILS)
87 void resetShaderCacheForTesting() const { fPipelineStateCache->release(); }
88#endif
89
90private:
91#ifdef SK_DEBUG
92#define GR_PIPELINE_STATE_CACHE_STATS
93#endif
94
95 class PipelineStateCache : public ::SkNoncopyable {
96 public:
97 PipelineStateCache(GrD3DGpu* gpu);
98 ~PipelineStateCache();
99
100 void release();
101 GrD3DPipelineState* refPipelineState(GrD3DRenderTarget*, const GrProgramInfo&);
102
103 void markPipelineStateUniformsDirty();
104
105 private:
106 struct Entry;
107
108 struct DescHash {
109 uint32_t operator()(const GrProgramDesc& desc) const {
110 return SkChecksum::Hash32(desc.asKey(), desc.keyLength());
111 }
112 };
113
115
116 GrD3DGpu* fGpu;
117
118#ifdef GR_PIPELINE_STATE_CACHE_STATS
119 int fTotalRequests;
120 int fCacheMisses;
121#endif
122 };
123
124 class DescriptorTableCache : public ::SkNoncopyable {
125 public:
126 DescriptorTableCache(GrD3DGpu* gpu) : fGpu(gpu), fMap(64) {
127 // Initialize the array we pass into CopyDescriptors for ranges.
128 // At the moment any descriptor we pass into CopyDescriptors is only itself,
129 // not the beginning of a range, so each range size is always 1.
130 for (int i = 0; i < kRangeSizesCount; ++i) {
131 fRangeSizes[i] = 1;
132 }
133 }
134 ~DescriptorTableCache() = default;
135
136 void release();
137 typedef std::function<sk_sp<GrD3DDescriptorTable>(GrD3DGpu*, unsigned int)> CreateFunc;
138 sk_sp<GrD3DDescriptorTable> findOrCreateDescTable(
139 const std::vector<D3D12_CPU_DESCRIPTOR_HANDLE>&, CreateFunc);
140
141 private:
142 GrD3DGpu* fGpu;
143
144 typedef std::vector<D3D12_CPU_DESCRIPTOR_HANDLE> DescTableKey;
145 typedef sk_sp<GrD3DDescriptorTable> DescTableValue;
146 struct DescTableHash {
147 uint32_t operator()(DescTableKey key) const {
148 return SkChecksum::Hash32(key.data(),
149 key.size() * sizeof(D3D12_CPU_DESCRIPTOR_HANDLE));
150 }
151 };
153 inline static constexpr int kRangeSizesCount = 8;
154 unsigned int fRangeSizes[kRangeSizesCount];
155 };
156
157 GrD3DGpu* fGpu;
158
162
163 GrD3DCpuDescriptorManager fCpuDescriptorManager;
164 GrD3DDescriptorTableManager fDescriptorTableManager;
165
166 std::unique_ptr<PipelineStateCache> fPipelineStateCache;
167 sk_sp<GrD3DPipeline> fMipmapPipeline;
168
170
171 DescriptorTableCache fShaderResourceDescriptorTableCache;
172 DescriptorTableCache fSamplerDescriptorTableCache;
173};
174
175#endif
void recycleDirectCommandList(std::unique_ptr< GrD3DDirectCommandList >)
GrD3DDescriptorHeap::CPUHandle createUnorderedAccessView(ID3D12Resource *resource, unsigned int mipSlice)
void recycleShaderView(const GrD3DDescriptorHeap::CPUHandle &)
GrD3DDescriptorHeap::CPUHandle createDepthStencilView(ID3D12Resource *textureResource)
sk_sp< GrD3DCommandSignature > findOrCreateCommandSignature(GrD3DCommandSignature::ForIndexed, unsigned int slot)
GrD3DDescriptorHeap::CPUHandle createShaderResourceView(ID3D12Resource *resource, unsigned int mostDetailedMip=0, unsigned int mipLevels=-1)
D3D12_GPU_VIRTUAL_ADDRESS uploadConstantData(void *data, size_t size)
sk_sp< GrD3DDescriptorTable > findOrCreateShaderViewTable(const std::vector< D3D12_CPU_DESCRIPTOR_HANDLE > &shaderViews)
GrD3DDescriptorHeap::CPUHandle createRenderTargetView(ID3D12Resource *textureResource)
D3D12_CPU_DESCRIPTOR_HANDLE findOrCreateCompatibleSampler(const GrSamplerState &params)
GrD3DDescriptorHeap::CPUHandle createConstantBufferView(ID3D12Resource *bufferResource, size_t offset, size_t size)
void recycleRenderTargetView(const GrD3DDescriptorHeap::CPUHandle &)
sk_sp< GrD3DPipeline > findOrCreateMipmapPipeline()
std::unique_ptr< GrD3DDirectCommandList > findOrCreateDirectCommandList()
sk_sp< GrD3DDescriptorTable > findOrCreateSamplerTable(const std::vector< D3D12_CPU_DESCRIPTOR_HANDLE > &samplers)
GrD3DDescriptorTableManager * descriptorTableMgr()
void recycleDepthStencilView(const GrD3DDescriptorHeap::CPUHandle &)
GrD3DPipelineState * findOrCreateCompatiblePipelineState(GrD3DRenderTarget *, const GrProgramInfo &)
sk_sp< GrD3DRootSignature > findOrCreateRootSignature(int numTextureSamplers, int numUAVs=0)
const EmbeddedViewParams * params
uint32_t Hash32(const void *data, size_t bytes, uint32_t seed)
Point offset