• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/Renderer.h"
13 #include "src/gpu/graphite/ShaderInfo.h"
14 #include "src/utils/SkShaderUtils.h"
15 
16 namespace skgpu::graphite {
17 
GraphicsPipeline(const SharedContext * sharedContext,const PipelineInfo & pipelineInfo)18 GraphicsPipeline::GraphicsPipeline(const SharedContext* sharedContext,
19                                    const PipelineInfo& pipelineInfo)
20         : Resource(sharedContext,
21                    Ownership::kOwned,
22                    skgpu::Budgeted::kYes,
23                    /*gpuMemorySize=*/0)
24         , fPipelineInfo(pipelineInfo) {}
25 
~GraphicsPipeline()26 GraphicsPipeline::~GraphicsPipeline() {
27 #if defined(SK_PIPELINE_LIFETIME_LOGGING)
28     static const char* kNames[2] = { "DeletionN", "DeletionP" };
29     TRACE_EVENT_INSTANT2("skia.gpu",
30                          TRACE_STR_STATIC(kNames[this->fromPrecompile()]),
31                          TRACE_EVENT_SCOPE_THREAD,
32                          "key", this->getPipelineInfo().fUniqueKeyHash,
33                          "compilationID", this->getPipelineInfo().fCompilationID);
34 #endif
35 }
36 
PipelineInfo(const ShaderInfo & shaderInfo,SkEnumBitMask<PipelineCreationFlags> pipelineCreationFlags,uint32_t uniqueKeyHash,uint32_t compilationID)37 GraphicsPipeline::PipelineInfo::PipelineInfo(
38             const ShaderInfo& shaderInfo,
39             SkEnumBitMask<PipelineCreationFlags> pipelineCreationFlags,
40             uint32_t uniqueKeyHash,
41             uint32_t compilationID)
42         : fDstReadReq(shaderInfo.dstReadRequirement())
43         , fNumFragTexturesAndSamplers(shaderInfo.numFragmentTexturesAndSamplers())
44         , fHasPaintUniforms(shaderInfo.hasPaintUniforms())
45         , fHasStepUniforms(shaderInfo.hasStepUniforms())
46         , fHasGradientBuffer(shaderInfo.hasGradientBuffer())
47         , fUniqueKeyHash(uniqueKeyHash)
48         , fCompilationID(compilationID)
49         , fFromPrecompile(pipelineCreationFlags & PipelineCreationFlags::kForPrecompilation) {
50 #if defined(GPU_TEST_UTILS)
51     fSkSLVertexShader = SkShaderUtils::PrettyPrint(shaderInfo.vertexSkSL());
52     fSkSLFragmentShader = SkShaderUtils::PrettyPrint(shaderInfo.fragmentSkSL());
53     fLabel = shaderInfo.fsLabel();
54 #endif
55 }
56 
57 }  // namespace skgpu::graphite
58