Debian Codegraph @

src/gpu/graphite/GraphicsPipeline.cpp

raw
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
21 GraphicsPipeline::GraphicsPipeline(const SharedContext* sharedContext,
22 const PipelineInfo& pipelineInfo,
23 std::string_view label)
24 : Resource(sharedContext,
25 Ownership::kOwned,
26 /*gpuMemorySize=*/0)
27 , fPipelineInfo(pipelineInfo) {
28 this->setLabel(label);
29 }
30
31 GraphicsPipeline::~GraphicsPipeline() {
32 #if defined(SK_PIPELINE_LIFETIME_LOGGING)
33 static const char* kNames[2] = { "DeletionN", "DeletionP" };
34 TRACE_EVENT_INSTANT2("skia.gpu",
35 TRACE_STR_STATIC(kNames[this->fromPrecompile()]),
36 TRACE_EVENT_SCOPE_THREAD,
37 "key", this->getPipelineInfo().fUniqueKeyHash,
38 "compilationID", this->getPipelineInfo().fCompilationID);
39 #endif
40 }
41
42 GraphicsPipeline::PipelineInfo::PipelineInfo(
43 const ShaderInfo& shaderInfo,
44 SkEnumBitMask<PipelineCreationFlags> pipelineCreationFlags,
45 uint32_t uniqueKeyHash,
46 uint32_t compilationID)
47 : fDstReadStrategy(shaderInfo.dstReadStrategy())
48 , fNumFragTexturesAndSamplers(shaderInfo.numFragmentTexturesAndSamplers())
49 , fHasCombinedUniforms(shaderInfo.hasCombinedUniforms())
50 , fHasGradientBuffer(shaderInfo.hasGradientBuffer())
51 , fUniqueKeyHash(uniqueKeyHash)
52 , fCompilationID(compilationID)
53 , fFromPrecompile(pipelineCreationFlags & PipelineCreationFlags::kForPrecompilation) {
54 #if defined(GPU_TEST_UTILS)
55 fSkSLVertexShader = SkShaderUtils::PrettyPrint(shaderInfo.vertexSkSL());
56 fSkSLFragmentShader = SkShaderUtils::PrettyPrint(shaderInfo.fragmentSkSL());
57 #endif
58 }
59
60 #if defined(GPU_TEST_UTILS)
61 SkString GraphicsPipelineDesc::toString(const Caps* caps, ShaderCodeDictionary* dict) const {
62 SkString tmp;
63
64 tmp.append(RenderStep::RenderStepName(fRenderStepID));
65 tmp.append(" - ");
66
67 PaintParamsKey key = dict->lookup(fPaintID);
68
69 tmp.append(key.toString(caps, dict));
70
71 return tmp;
72 }
73 #endif
74
75 } // namespace skgpu::graphite