Flutter Engine
The Flutter Engine
GrMtlResourceProvider.h
Go to the documentation of this file.
1/*
2 * Copyright 2018 Google Inc.
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 GrMtlResourceProvider_DEFINED
9#define GrMtlResourceProvider_DEFINED
10
12#include "src/base/SkSpinlock.h"
13#include "src/core/SkChecksum.h"
14#include "src/core/SkLRUCache.h"
22
23#import <Metal/Metal.h>
24
25class GrMtlGpu;
27
29public:
31
33 const GrProgramDesc&,const GrProgramInfo&,
35 bool precompileShader(const SkData& key, const SkData& data);
36
37 // Finds or creates a compatible MTLDepthStencilState based on the GrStencilSettings.
40
41 // Finds or creates a compatible MTLSamplerState based on the GrSamplerState.
43
44 const GrMtlRenderPipeline* findOrCreateMSAALoadPipeline(MTLPixelFormat colorFormat,
45 int sampleCount,
46 MTLPixelFormat stencilFormat);
47
48 // Destroy any cached resources. To be called before releasing the MtlDevice.
49 void destroyResources();
50
51#if defined(GR_TEST_UTILS)
52 void resetShaderCacheForTesting() const { fPipelineStateCache->release(); }
53#endif
54
55private:
56#ifdef SK_DEBUG
57#define GR_PIPELINE_STATE_CACHE_STATS
58#endif
59
60 class PipelineStateCache : public GrThreadSafePipelineBuilder {
61 public:
62 PipelineStateCache(GrMtlGpu* gpu);
63 ~PipelineStateCache() override;
64
65 void release();
66 GrMtlPipelineState* refPipelineState(const GrProgramDesc&, const GrProgramInfo&,
68 bool precompileShader(const SkData& key, const SkData& data);
69
70 private:
71 GrMtlPipelineState* onRefPipelineState(const GrProgramDesc&, const GrProgramInfo&,
73
74 struct Entry;
75
76 struct DescHash {
77 uint32_t operator()(const GrProgramDesc& desc) const {
78 return SkChecksum::Hash32(desc.asKey(), desc.keyLength());
79 }
80 };
81
83
84 GrMtlGpu* fGpu;
85 };
86
87 GrMtlGpu* fGpu;
88
89 // Cache of GrMtlPipelineStates
90 std::unique_ptr<PipelineStateCache> fPipelineStateCache;
91
94
95 struct MSAALoadPipelineEntry {
97 MTLPixelFormat fColorFormat;
98 int fSampleCount;
99 MTLPixelFormat fStencilFormat;
100 };
101 id<MTLLibrary> fMSAALoadLibrary;
103};
104
105#endif
GrSurfaceOrigin
Definition: GrTypes.h:147
const GrMtlRenderPipeline * findOrCreateMSAALoadPipeline(MTLPixelFormat colorFormat, int sampleCount, MTLPixelFormat stencilFormat)
GrMtlPipelineState * findOrCreateCompatiblePipelineState(const GrProgramDesc &, const GrProgramInfo &, GrThreadSafePipelineBuilder::Stats::ProgramCacheResult *stat=nullptr)
bool precompileShader(const SkData &key, const SkData &data)
GrMtlDepthStencil * findOrCreateCompatibleDepthStencilState(const GrStencilSettings &, GrSurfaceOrigin)
GrMtlResourceProvider(GrMtlGpu *gpu)
GrMtlSampler * findOrCreateCompatibleSampler(GrSamplerState)
Definition: SkData.h:25
uint32_t Hash32(const void *data, size_t bytes, uint32_t seed)
Definition: SkChecksum.cpp:113
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63