Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
GrD3DResourceProvider Class Reference

#include <GrD3DResourceProvider.h>

Public Member Functions

 GrD3DResourceProvider (GrD3DGpu *)
 
void destroyResources ()
 
std::unique_ptr< GrD3DDirectCommandListfindOrCreateDirectCommandList ()
 
void recycleDirectCommandList (std::unique_ptr< GrD3DDirectCommandList >)
 
sk_sp< GrD3DRootSignaturefindOrCreateRootSignature (int numTextureSamplers, int numUAVs=0)
 
sk_sp< GrD3DCommandSignaturefindOrCreateCommandSignature (GrD3DCommandSignature::ForIndexed, unsigned int slot)
 
GrD3DDescriptorHeap::CPUHandle createRenderTargetView (ID3D12Resource *textureResource)
 
void recycleRenderTargetView (const GrD3DDescriptorHeap::CPUHandle &)
 
GrD3DDescriptorHeap::CPUHandle createDepthStencilView (ID3D12Resource *textureResource)
 
void recycleDepthStencilView (const GrD3DDescriptorHeap::CPUHandle &)
 
GrD3DDescriptorHeap::CPUHandle createConstantBufferView (ID3D12Resource *bufferResource, size_t offset, size_t size)
 
GrD3DDescriptorHeap::CPUHandle createShaderResourceView (ID3D12Resource *resource, unsigned int mostDetailedMip=0, unsigned int mipLevels=-1)
 
GrD3DDescriptorHeap::CPUHandle createUnorderedAccessView (ID3D12Resource *resource, unsigned int mipSlice)
 
void recycleShaderView (const GrD3DDescriptorHeap::CPUHandle &)
 
D3D12_CPU_DESCRIPTOR_HANDLE findOrCreateCompatibleSampler (const GrSamplerState &params)
 
sk_sp< GrD3DDescriptorTablefindOrCreateShaderViewTable (const std::vector< D3D12_CPU_DESCRIPTOR_HANDLE > &shaderViews)
 
sk_sp< GrD3DDescriptorTablefindOrCreateSamplerTable (const std::vector< D3D12_CPU_DESCRIPTOR_HANDLE > &samplers)
 
GrD3DDescriptorTableManagerdescriptorTableMgr ()
 
GrD3DPipelineStatefindOrCreateCompatiblePipelineState (GrD3DRenderTarget *, const GrProgramInfo &)
 
sk_sp< GrD3DPipelinefindOrCreateMipmapPipeline ()
 
D3D12_GPU_VIRTUAL_ADDRESS uploadConstantData (void *data, size_t size)
 
void prepForSubmit ()
 
void markPipelineStateUniformsDirty ()
 

Detailed Description

Definition at line 34 of file GrD3DResourceProvider.h.

Constructor & Destructor Documentation

◆ GrD3DResourceProvider()

GrD3DResourceProvider::GrD3DResourceProvider ( GrD3DGpu gpu)

Definition at line 20 of file GrD3DResourceProvider.cpp.

21 : fGpu(gpu)
22 , fCpuDescriptorManager(gpu)
23 , fDescriptorTableManager(gpu)
24 , fPipelineStateCache(new PipelineStateCache(gpu))
25 , fShaderResourceDescriptorTableCache(gpu)
26 , fSamplerDescriptorTableCache(gpu) {
27}

Member Function Documentation

◆ createConstantBufferView()

GrD3DDescriptorHeap::CPUHandle GrD3DResourceProvider::createConstantBufferView ( ID3D12Resource *  bufferResource,
size_t  offset,
size_t  size 
)

Definition at line 103 of file GrD3DResourceProvider.cpp.

104 {
105 return fCpuDescriptorManager.createConstantBufferView(fGpu, bufferResource, offset, size);
106}
GrD3DDescriptorHeap::CPUHandle createConstantBufferView(GrD3DGpu *, ID3D12Resource *bufferResource, size_t offset, size_t size)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
SeparatedVector2 offset

◆ createDepthStencilView()

GrD3DDescriptorHeap::CPUHandle GrD3DResourceProvider::createDepthStencilView ( ID3D12Resource *  textureResource)

Definition at line 93 of file GrD3DResourceProvider.cpp.

94 {
95 return fCpuDescriptorManager.createDepthStencilView(fGpu, textureResource);
96}
GrD3DDescriptorHeap::CPUHandle createDepthStencilView(GrD3DGpu *, ID3D12Resource *textureResource)

◆ createRenderTargetView()

GrD3DDescriptorHeap::CPUHandle GrD3DResourceProvider::createRenderTargetView ( ID3D12Resource *  textureResource)

Definition at line 83 of file GrD3DResourceProvider.cpp.

84 {
85 return fCpuDescriptorManager.createRenderTargetView(fGpu, textureResource);
86}
GrD3DDescriptorHeap::CPUHandle createRenderTargetView(GrD3DGpu *, ID3D12Resource *textureResource)

◆ createShaderResourceView()

GrD3DDescriptorHeap::CPUHandle GrD3DResourceProvider::createShaderResourceView ( ID3D12Resource *  resource,
unsigned int  mostDetailedMip = 0,
unsigned int  mipLevels = -1 
)

Definition at line 108 of file GrD3DResourceProvider.cpp.

109 {
110 return fCpuDescriptorManager.createShaderResourceView(fGpu, resource, highestMip, mipLevels);
111}
static SkString resource(SkPDFResourceType type, int index)
GrD3DDescriptorHeap::CPUHandle createShaderResourceView(GrD3DGpu *, ID3D12Resource *resource, unsigned int mostDetailedMip, unsigned int mipLevels)

◆ createUnorderedAccessView()

GrD3DDescriptorHeap::CPUHandle GrD3DResourceProvider::createUnorderedAccessView ( ID3D12Resource *  resource,
unsigned int  mipSlice 
)

Definition at line 113 of file GrD3DResourceProvider.cpp.

114 {
115 return fCpuDescriptorManager.createUnorderedAccessView(fGpu, resource, mipSlice);
116}
GrD3DDescriptorHeap::CPUHandle createUnorderedAccessView(GrD3DGpu *, ID3D12Resource *resource, unsigned int mipSlice)

◆ descriptorTableMgr()

GrD3DDescriptorTableManager * GrD3DResourceProvider::descriptorTableMgr ( )
inline

Definition at line 72 of file GrD3DResourceProvider.h.

72 {
73 return &fDescriptorTableManager;
74 }

◆ destroyResources()

void GrD3DResourceProvider::destroyResources ( )

Definition at line 29 of file GrD3DResourceProvider.cpp.

29 {
30 fSamplers.reset();
31
32 fPipelineStateCache->release();
33}

◆ findOrCreateCommandSignature()

sk_sp< GrD3DCommandSignature > GrD3DResourceProvider::findOrCreateCommandSignature ( GrD3DCommandSignature::ForIndexed  indexed,
unsigned int  slot 
)

Definition at line 67 of file GrD3DResourceProvider.cpp.

68 {
69 for (int i = 0; i < fCommandSignatures.size(); ++i) {
70 if (fCommandSignatures[i]->isCompatible(indexed, slot)) {
71 return fCommandSignatures[i];
72 }
73 }
74
75 auto commandSig = GrD3DCommandSignature::Make(fGpu, indexed, slot);
76 if (!commandSig) {
77 return nullptr;
78 }
79 fCommandSignatures.push_back(commandSig);
80 return commandSig;
81}
static sk_sp< GrD3DCommandSignature > Make(GrD3DGpu *gpu, ForIndexed indexed, unsigned int slot)
int size() const
Definition: SkTArray.h:421

◆ findOrCreateCompatiblePipelineState()

GrD3DPipelineState * GrD3DResourceProvider::findOrCreateCompatiblePipelineState ( GrD3DRenderTarget rt,
const GrProgramInfo info 
)

Definition at line 201 of file GrD3DResourceProvider.cpp.

202 {
203 return fPipelineStateCache->refPipelineState(rt, info);
204}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213

◆ findOrCreateCompatibleSampler()

D3D12_CPU_DESCRIPTOR_HANDLE GrD3DResourceProvider::findOrCreateCompatibleSampler ( const GrSamplerState params)

Definition at line 160 of file GrD3DResourceProvider.cpp.

161 {
162 // In D3D anisotropic filtering uses the same field (D3D12_SAMPLER_DESC::Filter) as min/mag/mip
163 // settings and so is not orthogonal to them.
164 uint32_t key = params.asKey(/*anisoIsOrthogonal=*/false);
165 D3D12_CPU_DESCRIPTOR_HANDLE* samplerPtr = fSamplers.find(key);
166 if (samplerPtr) {
167 return *samplerPtr;
168 }
169
170 D3D12_FILTER filter = d3d_filter(params);
171 // We disable MIP filtering using maxLOD. Otherwise, we want the max LOD to be unbounded.
172 float maxLOD =
174 D3D12_TEXTURE_ADDRESS_MODE addressModeU = wrap_mode_to_d3d_address_mode(params.wrapModeX());
175 D3D12_TEXTURE_ADDRESS_MODE addressModeV = wrap_mode_to_d3d_address_mode(params.wrapModeY());
176 unsigned int maxAnisotropy = params.maxAniso();
177 D3D12_CPU_DESCRIPTOR_HANDLE sampler =
178 fCpuDescriptorManager.createSampler(
179 fGpu, filter, maxLOD, maxAnisotropy, addressModeU, addressModeV).fHandle;
180 fSamplers.set(key, sampler);
181 return sampler;
182}
static D3D12_FILTER d3d_filter(GrSamplerState sampler)
static D3D12_TEXTURE_ADDRESS_MODE wrap_mode_to_d3d_address_mode(GrSamplerState::WrapMode wrapMode)
GrD3DDescriptorHeap::CPUHandle createSampler(GrD3DGpu *, D3D12_FILTER filter, float maxLOD, unsigned int maxAnisotropy, D3D12_TEXTURE_ADDRESS_MODE addressModeU, D3D12_TEXTURE_ADDRESS_MODE addressModeV)
V * find(const K &key) const
Definition: SkTHash.h:494
V * set(K key, V val)
Definition: SkTHash.h:487
const EmbeddedViewParams * params
static float max(float r, float g, float b)
Definition: hsl.cpp:49
D3D12_CPU_DESCRIPTOR_HANDLE fHandle

◆ findOrCreateDirectCommandList()

std::unique_ptr< GrD3DDirectCommandList > GrD3DResourceProvider::findOrCreateDirectCommandList ( )

Definition at line 35 of file GrD3DResourceProvider.cpp.

35 {
36 if (fAvailableDirectCommandLists.size()) {
37 std::unique_ptr<GrD3DDirectCommandList> list =
38 std::move(fAvailableDirectCommandLists.back());
39 fAvailableDirectCommandLists.pop_back();
40 return list;
41 }
43}
static std::unique_ptr< GrD3DDirectCommandList > Make(GrD3DGpu *gpu)

◆ findOrCreateMipmapPipeline()

sk_sp< GrD3DPipeline > GrD3DResourceProvider::findOrCreateMipmapPipeline ( )

Definition at line 206 of file GrD3DResourceProvider.cpp.

206 {
207 if (!fMipmapPipeline) {
208 // Note: filtering for non-even widths and heights samples at the 0.25 and 0.75
209 // locations and averages the result. As the initial samples are bilerped this is
210 // approximately a triangle filter. We should look into doing a better kernel but
211 // this should hold us for now.
212 const char* shader =
213 "SamplerState textureSampler : register(s0, space1);\n"
214 "Texture2D<float4> inputTexture : register(t1, space1);\n"
215 "RWTexture2D<float4> outUAV : register(u2, space1);\n"
216 "\n"
217 "cbuffer UniformBuffer : register(b0, space0) {\n"
218 " float2 inverseDims;\n"
219 " uint mipLevel;\n"
220 " uint sampleMode;\n"
221 "}\n"
222 "\n"
223 "[numthreads(8, 8, 1)]\n"
224 "void main(uint groupIndex : SV_GroupIndex, uint3 threadID : SV_DispatchThreadID) {\n"
225 " float2 uv = inverseDims * (threadID.xy + 0.5);\n"
226 " float4 mipVal;\n"
227 " switch (sampleMode) {\n"
228 " case 0: {\n"
229 " mipVal = inputTexture.SampleLevel(textureSampler, uv, mipLevel);\n"
230 " break;\n"
231 " }\n"
232 " case 1: {\n"
233 " float2 uvdiff = inverseDims * 0.25;\n"
234 " mipVal = inputTexture.SampleLevel(textureSampler, uv-uvdiff, mipLevel);\n"
235 " mipVal += inputTexture.SampleLevel(textureSampler, uv+uvdiff, mipLevel);\n"
236 " uvdiff.y = -uvdiff.y;\n"
237 " mipVal += inputTexture.SampleLevel(textureSampler, uv-uvdiff, mipLevel);\n"
238 " mipVal += inputTexture.SampleLevel(textureSampler, uv+uvdiff, mipLevel);\n"
239 " mipVal *= 0.25;\n"
240 " break;\n"
241 " }\n"
242 " case 2: {\n"
243 " float2 uvdiff = float2(inverseDims.x * 0.25, 0);\n"
244 " mipVal = inputTexture.SampleLevel(textureSampler, uv-uvdiff, mipLevel);\n"
245 " mipVal += inputTexture.SampleLevel(textureSampler, uv+uvdiff, mipLevel);\n"
246 " mipVal *= 0.5;\n"
247 " break;\n"
248 " }\n"
249 " case 3: {\n"
250 " float2 uvdiff = float2(0, inverseDims.y * 0.25);\n"
251 " mipVal = inputTexture.SampleLevel(textureSampler, uv-uvdiff, mipLevel);\n"
252 " mipVal += inputTexture.SampleLevel(textureSampler, uv+uvdiff, mipLevel);\n"
253 " mipVal *= 0.5;\n"
254 " break;\n"
255 " }\n"
256 " }\n"
257 "\n"
258 " outUAV[threadID.xy] = mipVal;\n"
259 "}\n";
260
262
263 fMipmapPipeline =
265 }
266
267 return fMipmapPipeline;
268}
static sk_sp< GrD3DPipeline > MakeComputePipeline(GrD3DGpu *, GrD3DRootSignature *, const char *shader)
sk_sp< GrD3DRootSignature > findOrCreateRootSignature(int numTextureSamplers, int numUAVs=0)
T * get() const
Definition: SkRefCnt.h:303

◆ findOrCreateRootSignature()

sk_sp< GrD3DRootSignature > GrD3DResourceProvider::findOrCreateRootSignature ( int  numTextureSamplers,
int  numUAVs = 0 
)

Definition at line 51 of file GrD3DResourceProvider.cpp.

52 {
53 for (int i = 0; i < fRootSignatures.size(); ++i) {
54 if (fRootSignatures[i]->isCompatible(numTextureSamplers, numUAVs)) {
55 return fRootSignatures[i];
56 }
57 }
58
59 auto rootSig = GrD3DRootSignature::Make(fGpu, numTextureSamplers, numUAVs);
60 if (!rootSig) {
61 return nullptr;
62 }
63 fRootSignatures.push_back(rootSig);
64 return rootSig;
65}
static sk_sp< GrD3DRootSignature > Make(GrD3DGpu *gpu, int numTextureSamplers, int numUAVs)

◆ findOrCreateSamplerTable()

sk_sp< GrD3DDescriptorTable > GrD3DResourceProvider::findOrCreateSamplerTable ( const std::vector< D3D12_CPU_DESCRIPTOR_HANDLE > &  samplers)

Definition at line 193 of file GrD3DResourceProvider.cpp.

194 {
195 auto createFunc = [this](GrD3DGpu* gpu, unsigned int numDesc) {
196 return this->fDescriptorTableManager.createSamplerTable(gpu, numDesc);
197 };
198 return fShaderResourceDescriptorTableCache.findOrCreateDescTable(samplers, createFunc);
199}
sk_sp< GrD3DDescriptorTable > createSamplerTable(GrD3DGpu *, unsigned int count)

◆ findOrCreateShaderViewTable()

sk_sp< GrD3DDescriptorTable > GrD3DResourceProvider::findOrCreateShaderViewTable ( const std::vector< D3D12_CPU_DESCRIPTOR_HANDLE > &  shaderViews)

Definition at line 184 of file GrD3DResourceProvider.cpp.

185 {
186
187 auto createFunc = [this](GrD3DGpu* gpu, unsigned int numDesc) {
188 return this->fDescriptorTableManager.createShaderViewTable(gpu, numDesc);
189 };
190 return fShaderResourceDescriptorTableCache.findOrCreateDescTable(shaderViews, createFunc);
191}
sk_sp< GrD3DDescriptorTable > createShaderViewTable(GrD3DGpu *, unsigned int count)

◆ markPipelineStateUniformsDirty()

void GrD3DResourceProvider::markPipelineStateUniformsDirty ( )
inline

Definition at line 84 of file GrD3DResourceProvider.h.

84{ fPipelineStateCache->markPipelineStateUniformsDirty(); }

◆ prepForSubmit()

void GrD3DResourceProvider::prepForSubmit ( )

Definition at line 286 of file GrD3DResourceProvider.cpp.

286 {
287 fDescriptorTableManager.prepForSubmit(fGpu);
288 // Any heap memory used for these will be returned when the command buffer finishes,
289 // so we have to invalidate all entries.
290 fShaderResourceDescriptorTableCache.release();
291 fSamplerDescriptorTableCache.release();
292}

◆ recycleDepthStencilView()

void GrD3DResourceProvider::recycleDepthStencilView ( const GrD3DDescriptorHeap::CPUHandle dsvDescriptor)

Definition at line 98 of file GrD3DResourceProvider.cpp.

99 {
100 fCpuDescriptorManager.recycleDepthStencilView(dsvDescriptor);
101}
void recycleDepthStencilView(const GrD3DDescriptorHeap::CPUHandle &)

◆ recycleDirectCommandList()

void GrD3DResourceProvider::recycleDirectCommandList ( std::unique_ptr< GrD3DDirectCommandList commandList)

Definition at line 45 of file GrD3DResourceProvider.cpp.

46 {
47 commandList->reset();
48 fAvailableDirectCommandLists.push_back(std::move(commandList));
49}

◆ recycleRenderTargetView()

void GrD3DResourceProvider::recycleRenderTargetView ( const GrD3DDescriptorHeap::CPUHandle rtvDescriptor)

Definition at line 88 of file GrD3DResourceProvider.cpp.

89 {
90 fCpuDescriptorManager.recycleRenderTargetView(rtvDescriptor);
91}
void recycleRenderTargetView(const GrD3DDescriptorHeap::CPUHandle &)

◆ recycleShaderView()

void GrD3DResourceProvider::recycleShaderView ( const GrD3DDescriptorHeap::CPUHandle view)

Definition at line 118 of file GrD3DResourceProvider.cpp.

119 {
120 fCpuDescriptorManager.recycleShaderView(view);
121}
void recycleShaderView(const GrD3DDescriptorHeap::CPUHandle &)

◆ uploadConstantData()

D3D12_GPU_VIRTUAL_ADDRESS GrD3DResourceProvider::uploadConstantData ( void *  data,
size_t  size 
)

Definition at line 270 of file GrD3DResourceProvider.cpp.

270 {
271 // constant size has to be aligned to 256
272 constexpr int kConstantAlignment = 256;
273
274 // upload the data
275 size_t paddedSize = SkAlignTo(size, kConstantAlignment);
276 GrRingBuffer::Slice slice = fGpu->uniformsRingBuffer()->suballocate(paddedSize);
277 char* destPtr = static_cast<char*>(slice.fBuffer->map()) + slice.fOffset;
278 memcpy(destPtr, data, size);
279
280 // create the associated constant buffer view descriptor
281 GrD3DBuffer* d3dBuffer = static_cast<GrD3DBuffer*>(slice.fBuffer);
282 D3D12_GPU_VIRTUAL_ADDRESS gpuAddress = d3dBuffer->d3dResource()->GetGPUVirtualAddress();
283 return gpuAddress + slice.fOffset;
284}
constexpr int kConstantAlignment
Definition: GrD3DGpu.cpp:77
static constexpr size_t SkAlignTo(size_t x, size_t alignment)
Definition: SkAlign.h:33
ID3D12Resource * d3dResource() const
Definition: GrD3DBuffer.h:24
GrRingBuffer * uniformsRingBuffer() override
Definition: GrD3DGpu.h:53
void * map()
Definition: GrGpuBuffer.cpp:28
Slice suballocate(size_t size)
GrGpuBuffer * fBuffer
Definition: GrRingBuffer.h:40
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

The documentation for this class was generated from the following files: