| 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 |
|
| 8 |
#include "tools/graphite/UniqueKeyUtils.h" |
| 9 |
|
| 10 |
#include "src/gpu/ResourceKey.h" |
| 11 |
#include "src/gpu/graphite/Caps.h" |
| 12 |
#include "src/gpu/graphite/ContextPriv.h" |
| 13 |
#include "src/gpu/graphite/GraphicsPipelineDesc.h" |
| 14 |
#include "src/gpu/graphite/PrecompileContextPriv.h" |
| 15 |
#include "src/gpu/graphite/RenderPassDesc.h" |
| 16 |
#include "src/gpu/graphite/RendererProvider.h" |
| 17 |
|
| 18 |
using namespace skgpu::graphite; |
| 19 |
using namespace skgpu; |
| 20 |
|
| 21 |
|
| 22 |
namespace UniqueKeyUtils { |
| 23 |
|
| 24 |
void FetchUniqueKeys(PrecompileContext* precompileContext, |
| 25 |
std::vector<UniqueKey>* keys) { |
| 26 |
GlobalCache* globalCache = precompileContext->priv().globalCache(); |
| 27 |
|
| 28 |
keys->reserve(globalCache->numGraphicsPipelines()); |
| 29 |
globalCache->forEachGraphicsPipeline([keys](const UniqueKey& key, |
| 30 |
const GraphicsPipeline* pipeline) { |
| 31 |
keys->push_back(key); |
| 32 |
}); |
| 33 |
} |
| 34 |
|
| 35 |
#ifdef SK_DEBUG |
| 36 |
void DumpDescs(PrecompileContext* precompileContext, |
| 37 |
const GraphicsPipelineDesc& pipelineDesc, |
| 38 |
const RenderPassDesc& rpd) { |
| 39 |
const RendererProvider* rendererProvider = precompileContext->priv().rendererProvider(); |
| 40 |
const ShaderCodeDictionary* dict = precompileContext->priv().shaderCodeDictionary(); |
| 41 |
|
| 42 |
const RenderStep* rs = rendererProvider->lookup(pipelineDesc.renderStepID()); |
| 43 |
SkDebugf("GraphicsPipelineDesc: %u %s\n", pipelineDesc.paintParamsID().asUInt(), rs->name()); |
| 44 |
|
| 45 |
dict->dump(precompileContext->priv().caps(), pipelineDesc.paintParamsID()); |
| 46 |
|
| 47 |
SkDebugf("RenderPassDesc:\n"); |
| 48 |
SkDebugf(" colorAttach: %s\n", rpd.fColorAttachment.toString().c_str()); |
| 49 |
SkDebugf(" colorResolveAttach: %s\n", rpd.fColorResolveAttachment.toString().c_str()); |
| 50 |
SkDebugf(" depthStencilAttach: %s\n", rpd.fDepthStencilAttachment.toString().c_str()); |
| 51 |
SkDebugf(" clearColor: %.2f %.2f %.2f %.2f\n" |
| 52 |
" clearDepth: %.2f\n" |
| 53 |
" stencilClear: %u\n" |
| 54 |
" writeSwizzle: %s\n" |
| 55 |
" sampleCount: %u\n", |
| 56 |
rpd.fClearColor[0], rpd.fClearColor[1], rpd.fClearColor[2], rpd.fClearColor[3], |
| 57 |
rpd.fClearDepth, |
| 58 |
rpd.fClearStencil, |
| 59 |
rpd.fWriteSwizzle.asString().c_str(), |
| 60 |
(unsigned) rpd.fSampleCount); |
| 61 |
|
| 62 |
} |
| 63 |
#endif // SK_DEBUG |
| 64 |
|
| 65 |
bool ExtractKeyDescs(PrecompileContext* precompileContext, |
| 66 |
const UniqueKey& origKey, |
| 67 |
GraphicsPipelineDesc* pipelineDesc, |
| 68 |
RenderPassDesc* renderPassDesc) { |
| 69 |
const skgpu::graphite::Caps* caps = precompileContext->priv().caps(); |
| 70 |
const RendererProvider* rendererProvider = precompileContext->priv().rendererProvider(); |
| 71 |
|
| 72 |
bool extracted = caps->extractGraphicsDescs(origKey, pipelineDesc, renderPassDesc, |
| 73 |
rendererProvider); |
| 74 |
if (!extracted) { |
| 75 |
SkASSERT(0); |
| 76 |
return false; |
| 77 |
} |
| 78 |
|
| 79 |
#ifdef SK_DEBUG |
| 80 |
UniqueKey newKey = caps->makeGraphicsPipelineKey(*pipelineDesc, *renderPassDesc); |
| 81 |
if (origKey != newKey) { |
| 82 |
SkDebugf("------- The UniqueKey didn't round trip!\n"); |
| 83 |
origKey.dump("original key:"); |
| 84 |
newKey.dump("reassembled key:"); |
| 85 |
DumpDescs(precompileContext, *pipelineDesc, *renderPassDesc); |
| 86 |
SkDebugf("------------------------\n"); |
| 87 |
} |
| 88 |
SkASSERT(origKey == newKey); |
| 89 |
#endif |
| 90 |
|
| 91 |
return true; |
| 92 |
} |
| 93 |
|
| 94 |
} // namespace UniqueKeyUtils |