1 /*
2 * Copyright 2021 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 "src/gpu/graphite/GraphicsPipeline.h"
9
10 #include "src/core/SkTraceEvent.h"
11 #include "src/gpu/graphite/ContextUtils.h"
12 #include "src/gpu/graphite/GraphicsPipelineDesc.h"
13 #include "src/gpu/graphite/PaintParamsKey.h"
14 #include "src/gpu/graphite/Renderer.h"
15 #include "src/gpu/graphite/ShaderCodeDictionary.h"
16 #include "src/gpu/graphite/ShaderInfo.h"
17 #include "src/utils/SkShaderUtils.h"
18
19 namespace skgpu::graphite {
20
GraphicsPipeline(const SharedContext * sharedContext,const PipelineInfo & pipelineInfo)21 GraphicsPipeline::GraphicsPipeline(const SharedContext* sharedContext,
22 const PipelineInfo& pipelineInfo)
23 : Resource(sharedContext,
24 Ownership::kOwned,
25 /*gpuMemorySize=*/0)
26 , fPipelineInfo(pipelineInfo) {}
27
~GraphicsPipeline()28 GraphicsPipeline::~GraphicsPipeline() {
29 #if defined(SK_PIPELINE_LIFETIME_LOGGING)
30 static const char* kNames[2] = { "DeletionN", "DeletionP" };
31 TRACE_EVENT_INSTANT2("skia.gpu",
32 TRACE_STR_STATIC(kNames[this->fromPrecompile()]),
33 TRACE_EVENT_SCOPE_THREAD,
34 "key", this->getPipelineInfo().fUniqueKeyHash,
35 "compilationID", this->getPipelineInfo().fCompilationID);
36 #endif
37 }
38
PipelineInfo(const ShaderInfo & shaderInfo,SkEnumBitMask<PipelineCreationFlags> pipelineCreationFlags,uint32_t uniqueKeyHash,uint32_t compilationID)39 GraphicsPipeline::PipelineInfo::PipelineInfo(
40 const ShaderInfo& shaderInfo,
41 SkEnumBitMask<PipelineCreationFlags> pipelineCreationFlags,
42 uint32_t uniqueKeyHash,
43 uint32_t compilationID)
44 : fDstReadStrategy(shaderInfo.dstReadStrategy())
45 , fNumFragTexturesAndSamplers(shaderInfo.numFragmentTexturesAndSamplers())
46 , fHasPaintUniforms(shaderInfo.hasPaintUniforms())
47 , fHasStepUniforms(shaderInfo.hasStepUniforms())
48 , fHasGradientBuffer(shaderInfo.hasGradientBuffer())
49 , fUniqueKeyHash(uniqueKeyHash)
50 , fCompilationID(compilationID)
51 , fFromPrecompile(pipelineCreationFlags & PipelineCreationFlags::kForPrecompilation) {
52 #if defined(GPU_TEST_UTILS)
53 fSkSLVertexShader = SkShaderUtils::PrettyPrint(shaderInfo.vertexSkSL());
54 fSkSLFragmentShader = SkShaderUtils::PrettyPrint(shaderInfo.fragmentSkSL());
55 fLabel = shaderInfo.fsLabel();
56 #endif
57 }
58
59 #if defined(GPU_TEST_UTILS)
toString(ShaderCodeDictionary * dict) const60 SkString GraphicsPipelineDesc::toString(ShaderCodeDictionary* dict) const {
61 SkString tmp;
62
63 tmp.append(RenderStep::RenderStepName(fRenderStepID));
64 tmp.append(" - ");
65
66 PaintParamsKey key = dict->lookup(fPaintID);
67
68 tmp.append(key.toString(dict, true));
69
70 return tmp;
71 }
72 #endif
73
74 } // namespace skgpu::graphite
75