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 dstReadRequirement()43 DstReadRequirement dstReadRequirement() const { return fPipelineInfo.fDstReadReq; } 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 56 DstReadRequirement fDstReadReq = DstReadRequirement::kNone; 57 int fNumFragTexturesAndSamplers = 0; 58 bool fHasPaintUniforms = false; 59 bool fHasStepUniforms = false; 60 bool fHasGradientBuffer = false; 61 62 // In test-enabled builds, we preserve the generated shader code to display in the viewer 63 // slide UI. This is not quite enough information to fully recreate the pipeline, as the 64 // RenderPassDesc used to make the pipeline is not preserved. 65 #if defined(GPU_TEST_UTILS) 66 std::string fLabel; 67 68 std::string fSkSLVertexShader; 69 std::string fSkSLFragmentShader; 70 std::string fNativeVertexShader; 71 std::string fNativeFragmentShader; 72 #endif 73 #if SK_HISTOGRAMS_ENABLED 74 bool fFromPrecompile = false; 75 #endif 76 }; 77 78 #if defined(GPU_TEST_UTILS) getPipelineInfo()79 const PipelineInfo& getPipelineInfo() const { 80 return fPipelineInfo; 81 } 82 #endif 83 #if SK_HISTOGRAMS_ENABLED fromPrecompile()84 bool fromPrecompile() const { return fPipelineInfo.fFromPrecompile; } 85 #endif 86 87 protected: 88 GraphicsPipeline(const SharedContext*, const PipelineInfo&); 89 90 private: 91 PipelineInfo fPipelineInfo; 92 }; 93 94 } // namespace skgpu::graphite 95 96 #endif // skgpu_graphite_GraphicsPipeline_DEFINED 97