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 #ifndef skgpu_graphite_GraphicsPipeline_DEFINED 9 #define skgpu_graphite_GraphicsPipeline_DEFINED 10 11 #include "src/gpu/graphite/Caps.h" 12 #include "src/gpu/graphite/Resource.h" 13 #include "src/gpu/graphite/UniquePaintParamsID.h" 14 15 namespace skgpu::graphite { 16 17 class ShaderInfo; 18 class RenderStep; 19 20 enum class PipelineCreationFlags : uint8_t { 21 kNone = 0b000, 22 // For Dawn, this flag overrides the DawnCaps::fUseAsyncPipelineCreation 23 // parameter and forces Synchronous Pipeline creation. 24 kForPrecompilation = 0b001, 25 }; 26 27 /** 28 * GraphicsPipeline corresponds to a backend specific pipeline used for rendering (vs. compute), 29 * e.g. MTLRenderPipelineState (Metal), 30 * CreateRenderPipeline (Dawn), 31 * CreateGraphicsPipelineState (D3D12), 32 * or VkGraphicsPipelineCreateInfo (Vulkan). 33 * 34 * A GraphicsPipeline is created from the combination of a GraphicsPipelineDesc (representing draw 35 * specific configuration) and a RenderPassDesc (representing the target of the draw). 36 */ 37 class GraphicsPipeline : public Resource { 38 public: 39 ~GraphicsPipeline() override; 40 getResourceType()41 const char* getResourceType() const override { return "Graphics Pipeline"; } 42 dstReadStrategy()43 DstReadStrategy dstReadStrategy() const { return fPipelineInfo.fDstReadStrategy; } 44 numFragTexturesAndSamplers()45 int numFragTexturesAndSamplers() const { return fPipelineInfo.fNumFragTexturesAndSamplers; } hasPaintUniforms()46 bool hasPaintUniforms() const { return fPipelineInfo.fHasPaintUniforms; } hasStepUniforms()47 bool hasStepUniforms() const { return fPipelineInfo.fHasStepUniforms; } hasGradientBuffer()48 bool hasGradientBuffer() const { return fPipelineInfo.fHasGradientBuffer; } 49 50 struct PipelineInfo { 51 PipelineInfo() = default; 52 53 // NOTE: Subclasses must manually fill in native shader code in GPU_TEST_UTILS builds. 54 PipelineInfo(const ShaderInfo&, SkEnumBitMask<PipelineCreationFlags>, 55 uint32_t uniqueKeyHash, uint32_t compilationID); 56 57 DstReadStrategy fDstReadStrategy = DstReadStrategy::kNoneRequired; 58 int fNumFragTexturesAndSamplers = 0; 59 bool fHasPaintUniforms = false; 60 bool fHasStepUniforms = false; 61 bool fHasGradientBuffer = false; 62 63 // In test-enabled builds, we preserve the generated shader code to display in the viewer 64 // slide UI. This is not quite enough information to fully recreate the pipeline, as the 65 // RenderPassDesc used to make the pipeline is not preserved. 66 #if defined(GPU_TEST_UTILS) 67 std::string fLabel; 68 69 std::string fSkSLVertexShader; 70 std::string fSkSLFragmentShader; 71 std::string fNativeVertexShader; 72 std::string fNativeFragmentShader; 73 #endif 74 const uint32_t fUniqueKeyHash = 0; 75 // The compilation ID is used to distinguish between different compilations/instantiations 76 // of the same unique key. If, for example, two versions were created due to threading. 77 const uint32_t fCompilationID = 0; 78 const bool fFromPrecompile = false; 79 bool fWasUsed = false; 80 }; 81 getPipelineInfo()82 const PipelineInfo& getPipelineInfo() const { 83 return fPipelineInfo; 84 } fromPrecompile()85 bool fromPrecompile() const { return fPipelineInfo.fFromPrecompile; } 86 markUsed()87 void markUsed() { fPipelineInfo.fWasUsed = true; } wasUsed()88 bool wasUsed() const { return fPipelineInfo.fWasUsed; } 89 90 protected: 91 GraphicsPipeline(const SharedContext*, const PipelineInfo&); 92 93 private: 94 PipelineInfo fPipelineInfo; 95 }; 96 97 } // namespace skgpu::graphite 98 99 #endif // skgpu_graphite_GraphicsPipeline_DEFINED 100