Flutter Engine
The Flutter Engine
UniqueKeyUtils.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2024 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
10#include "src/gpu/ResourceKey.h"
16
17using namespace skgpu::graphite;
18using namespace skgpu;
19
20
21namespace UniqueKeyUtils {
22
23void FetchUniqueKeys(GlobalCache* globalCache,
24 std::vector<UniqueKey>* keys) {
25 keys->reserve(globalCache->numGraphicsPipelines());
26 globalCache->forEachGraphicsPipeline([keys](const UniqueKey& key,
27 const GraphicsPipeline* pipeline) {
28 keys->push_back(key);
29 });
30}
31
32#ifdef SK_DEBUG
33void DumpDescs(const RendererProvider* rendererProvider,
34 const ShaderCodeDictionary* dict,
35 const GraphicsPipelineDesc& pipelineDesc,
36 const RenderPassDesc& rpd) {
37 const RenderStep* rs = rendererProvider->lookup(pipelineDesc.renderStepID());
38 SkDebugf("GraphicsPipelineDesc: %u %s\n", pipelineDesc.paintParamsID().asUInt(), rs->name());
39
40 dict->dump(pipelineDesc.paintParamsID());
41
42 SkDebugf("RenderPassDesc:\n");
43 SkDebugf(" colorAttach: %s\n", rpd.fColorAttachment.toString().c_str());
44 SkDebugf(" colorResolveAttach: %s\n", rpd.fColorResolveAttachment.toString().c_str());
45 SkDebugf(" depthStencilAttach: %s\n", rpd.fDepthStencilAttachment.toString().c_str());
46 SkDebugf(" clearColor: %.2f %.2f %.2f %.2f\n"
47 " clearDepth: %.2f\n"
48 " stencilClear: %u\n"
49 " writeSwizzle: %s\n"
50 " sampleCount: %u\n",
51 rpd.fClearColor[0], rpd.fClearColor[1], rpd.fClearColor[2], rpd.fClearColor[3],
52 rpd.fClearDepth,
53 rpd.fClearStencil,
55 rpd.fSampleCount);
56
57}
58#endif // SK_DEBUG
59
61 const UniqueKey& origKey,
62 GraphicsPipelineDesc* pipelineDesc,
63 RenderPassDesc* renderPassDesc) {
64 const Caps* caps = context->priv().caps();
65 const RendererProvider* rendererProvider = context->priv().rendererProvider();
66
67 bool extracted = caps->extractGraphicsDescs(origKey, pipelineDesc, renderPassDesc,
68 rendererProvider);
69 if (!extracted) {
70 SkASSERT(0);
71 return false;
72 }
73
74#ifdef SK_DEBUG
75 const ShaderCodeDictionary* dict = context->priv().shaderCodeDictionary();
76
77 UniqueKey newKey = caps->makeGraphicsPipelineKey(*pipelineDesc, *renderPassDesc);
78 if (origKey != newKey) {
79 SkDebugf("------- The UniqueKey didn't round trip!\n");
80 origKey.dump("original key:");
81 newKey.dump("reassembled key:");
82 DumpDescs(rendererProvider, dict, *pipelineDesc, *renderPassDesc);
83 SkDebugf("------------------------\n");
84 }
85 SkASSERT(origKey == newKey);
86#endif
87
88 return true;
89}
90
91} // namespace UniqueKeyUtils
#define SkASSERT(cond)
Definition: SkAssert.h:116
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
const char * c_str() const
Definition: SkString.h:133
SkString asString() const
Definition: Swizzle.cpp:46
virtual bool extractGraphicsDescs(const UniqueKey &, GraphicsPipelineDesc *, RenderPassDesc *, const RendererProvider *) const
Definition: Caps.h:129
virtual UniqueKey makeGraphicsPipelineKey(const GraphicsPipelineDesc &, const RenderPassDesc &) const =0
const RendererProvider * rendererProvider() const
Definition: ContextPriv.h:46
const Caps * caps() const
Definition: ContextPriv.h:32
const ShaderCodeDictionary * shaderCodeDictionary() const
Definition: ContextPriv.h:34
UniquePaintParamsID paintParamsID() const
const char * name() const
Definition: Renderer.h:116
const RenderStep * lookup(uint32_t uniqueID) const
void FetchUniqueKeys(GlobalCache *globalCache, std::vector< UniqueKey > *keys)
bool ExtractKeyDescs(Context *context, const UniqueKey &origKey, GraphicsPipelineDesc *pipelineDesc, RenderPassDesc *renderPassDesc)
Definition: GpuTools.h:21
AttachmentDesc fDepthStencilAttachment
AttachmentDesc fColorResolveAttachment
std::array< float, 4 > fClearColor