Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
PublicPrecompile.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2022 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
9
26
27namespace {
28
29using namespace skgpu::graphite;
30
31void compile(const RendererProvider* rendererProvider,
32 ResourceProvider* resourceProvider,
33 const KeyContext& keyContext,
34 UniquePaintParamsID uniqueID,
35 DrawTypeFlags drawTypes,
36 SkSpan<const RenderPassDesc> renderPassDescs,
37 bool withPrimitiveBlender,
38 Coverage coverage) {
39 for (const Renderer* r : rendererProvider->renderers()) {
40 if (!(r->drawTypes() & drawTypes)) {
41 continue;
42 }
43
44 if (r->emitsPrimitiveColor() != withPrimitiveBlender) {
45 // UniqueIDs are explicitly built either w/ or w/o primitiveBlending so must
46 // match what the Renderer requires
47 continue;
48 }
49
50 if (r->coverage() != coverage) {
51 // For now, UniqueIDs are explicitly built with a specific type of coverage so must
52 // match what the Renderer requires
53 continue;
54 }
55
56 for (auto&& s : r->steps()) {
57 SkASSERT(!s->performsShading() || s->emitsPrimitiveColor() == withPrimitiveBlender);
58
59 UniquePaintParamsID paintID = s->performsShading() ? uniqueID
61 GraphicsPipelineDesc pipelineDesc(s, paintID);
62
63 for (const RenderPassDesc& renderPassDesc : renderPassDescs) {
64 sk_sp<GraphicsPipeline> pipeline = resourceProvider->findOrCreateGraphicsPipeline(
65 keyContext.rtEffectDict(),
66 pipelineDesc,
67 renderPassDesc);
68 if (!pipeline) {
69 SKGPU_LOG_W("Failed to create GraphicsPipeline in precompile!");
70 return;
71 }
72 }
73 }
74 }
75}
76
77} // anonymous namespace
78
79namespace skgpu::graphite {
80
81bool Precompile(Context* context,
83 const GraphicsPipelineDesc& pipelineDesc,
84 const RenderPassDesc& renderPassDesc) {
85 ResourceProvider* resourceProvider = context->priv().resourceProvider();
86
87 sk_sp<GraphicsPipeline> pipeline = resourceProvider->findOrCreateGraphicsPipeline(
88 rteDict,
89 pipelineDesc,
90 renderPassDesc);
91 if (!pipeline) {
92 SKGPU_LOG_W("Failed to create GraphicsPipeline in precompile!");
93 return false;
94 }
95
96 return true;
97}
98
99void Precompile(Context* context, const PaintOptions& options, DrawTypeFlags drawTypes) {
100
102 const Caps* caps = context->priv().caps();
103
104 auto rtEffectDict = std::make_unique<RuntimeEffectDictionary>();
105
107 KeyContext keyContext(
108 caps, dict, rtEffectDict.get(), ci, /* dstTexture= */ nullptr, /* dstOffset= */ {0, 0});
109
112 context, options, keyContext,
113 static_cast<DrawTypeFlags>(drawTypes & ~DrawTypeFlags::kDrawVertices),
114 /* withPrimitiveBlender= */ false,
115 coverage);
116 }
117
118 if (drawTypes & DrawTypeFlags::kDrawVertices) {
120 // drawVertices w/ colors use a primitiveBlender while those w/o don't
121 for (bool withPrimitiveBlender : { true, false }) {
122 PrecompileCombinations(context, options, keyContext,
124 withPrimitiveBlender,
125 coverage);
126 }
127 }
128 }
129}
130
132 const PaintOptions& options,
133 const KeyContext& keyContext,
134 DrawTypeFlags drawTypes,
135 bool withPrimitiveBlender,
136 Coverage coverage) {
137 // Since the precompilation path's uniforms aren't used and don't change the key,
138 // the exact layout doesn't matter
140
141 const Caps* caps = keyContext.caps();
142 SkColorType destCT = keyContext.dstColorInfo().colorType();
143 // TODO: we need iterate over a broader set of TextureInfos here. Perhaps, allow the client
144 // to pass in colorType, mipmapping and protection.
146 Mipmapped::kNo,
147 Protected::kNo,
148 Renderable::kYes);
149
150 Swizzle writeSwizzle = caps->getWriteSwizzle(destCT, info);
151 // Note: at least on Metal, the LoadOp, StoreOp and clearColor fields don't influence the
152 // actual RenderPassDescKey.
153 // TODO: if all of the Renderers associated w/ the requested drawTypes require MSAA we
154 // do not need to generate the combinations w/ the non-MSAA RenderPassDescs.
155 const RenderPassDesc renderPassDescs[] = {
157 info,
161 /* clearColor= */ { .0f, .0f, .0f, .0f },
162 /* requiresMSAA= */ true,
163 writeSwizzle),
165 info,
169 /* clearColor= */ { .0f, .0f, .0f, .0f },
170 /* requiresMSAA= */ true,
171 writeSwizzle),
173 info,
177 /* clearColor= */ { .0f, .0f, .0f, .0f },
178 /* requiresMSAA= */ false,
179 writeSwizzle),
181 info,
185 /* clearColor= */ { .0f, .0f, .0f, .0f },
186 /* requiresMSAA= */ false,
187 writeSwizzle),
188 };
189
190 options.priv().buildCombinations(
191 keyContext,
192 &gatherer,
193 drawTypes,
194 withPrimitiveBlender,
195 coverage,
196 [context, &keyContext, &renderPassDescs](UniquePaintParamsID uniqueID,
197 DrawTypeFlags drawTypes,
198 bool withPrimitiveBlender,
199 Coverage coverage) {
200 compile(context->priv().rendererProvider(),
201 context->priv().resourceProvider(),
202 keyContext,
203 uniqueID,
204 drawTypes,
205 renderPassDescs,
206 withPrimitiveBlender,
207 coverage);
208 });
209}
210
211} // namespace skgpu::graphite
const char * options
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
#define SKGPU_LOG_W(fmt,...)
Definition Log.h:40
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
#define SkASSERT(cond)
Definition SkAssert.h:116
SkColorType
Definition SkColorType.h:19
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
SkColorType colorType() const
skgpu::Swizzle getWriteSwizzle(SkColorType, const TextureInfo &) const
Definition Caps.cpp:141
virtual TextureInfo getDefaultSampledTextureInfo(SkColorType, Mipmapped mipmapped, Protected, Renderable) const =0
const RendererProvider * rendererProvider() const
Definition ContextPriv.h:46
const Caps * caps() const
Definition ContextPriv.h:32
ResourceProvider * resourceProvider() const
Definition ContextPriv.h:49
const ShaderCodeDictionary * shaderCodeDictionary() const
Definition ContextPriv.h:34
RuntimeEffectDictionary * rtEffectDict() const
Definition KeyContext.h:63
const SkColorInfo & dstColorInfo() const
Definition KeyContext.h:65
const Caps * caps() const
Definition KeyContext.h:57
sk_sp< GraphicsPipeline > findOrCreateGraphicsPipeline(const RuntimeEffectDictionary *, const GraphicsPipelineDesc &, const RenderPassDesc &)
static UniquePaintParamsID InvalidID()
struct MyStruct s
bool Precompile(Context *context, RuntimeEffectDictionary *rteDict, const GraphicsPipelineDesc &pipelineDesc, const RenderPassDesc &renderPassDesc)
void PrecompileCombinations(Context *context, const PaintOptions &options, const KeyContext &keyContext, DrawTypeFlags drawTypes, bool withPrimitiveBlender, Coverage coverage)
static RenderPassDesc Make(const Caps *caps, const TextureInfo &targetInfo, LoadOp loadOp, StoreOp storeOp, SkEnumBitMask< DepthStencilFlags > depthStencilFlags, const std::array< float, 4 > &clearColor, bool requiresMSAA, Swizzle writeSwizzle)