1 /* 2 * Copyright 2022 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_DawnGraphicsPipeline_DEFINED 9 #define skgpu_graphite_DawnGraphicsPipeline_DEFINED 10 11 #include "include/core/SkRefCnt.h" 12 #include "include/core/SkSpan.h" 13 #include "include/ports/SkCFObject.h" 14 #include "src/gpu/graphite/DrawTypes.h" 15 #include "src/gpu/graphite/GraphicsPipeline.h" 16 17 #include "webgpu/webgpu_cpp.h" 18 19 class SkUniform; 20 21 namespace SkSL { 22 class Compiler; 23 } 24 namespace skgpu { 25 struct BlendInfo; 26 } 27 28 namespace skgpu::graphite { 29 30 class Attribute; 31 class Context; 32 class GraphicsPipelineDesc; 33 class DawnResourceProvider; 34 class DawnSharedContext; 35 struct DepthStencilSettings; 36 struct RenderPassDesc; 37 class RuntimeEffectDictionary; 38 39 class DawnGraphicsPipeline final : public GraphicsPipeline { 40 public: 41 inline static constexpr unsigned int kUniformBufferBindGroupIndex = 0; 42 inline static constexpr unsigned int kTextureBindGroupIndex = 1; 43 44 inline static constexpr unsigned int kIntrinsicUniformBufferIndex = 0; 45 inline static constexpr unsigned int kRenderStepUniformBufferIndex = 1; 46 inline static constexpr unsigned int kPaintUniformBufferIndex = 2; 47 inline static constexpr unsigned int kNumUniformBuffers = 3; 48 49 inline static constexpr unsigned int kVertexBufferIndex = 0; 50 inline static constexpr unsigned int kInstanceBufferIndex = 1; 51 inline static constexpr unsigned int kNumVertexBuffers = 2; 52 53 static sk_sp<DawnGraphicsPipeline> Make(const DawnSharedContext* sharedContext, 54 SkSL::Compiler* compiler, 55 const RuntimeEffectDictionary* runtimeDict, 56 const GraphicsPipelineDesc& pipelineDesc, 57 const RenderPassDesc& renderPassDesc); 58 ~DawnGraphicsPipeline()59 ~DawnGraphicsPipeline() override {} 60 stencilReferenceValue()61 uint32_t stencilReferenceValue() const { return fStencilReferenceValue; } primitiveType()62 PrimitiveType primitiveType() const { return fPrimitiveType; } hasStepUniforms()63 bool hasStepUniforms() const { return fHasStepUniforms; } hasFragment()64 bool hasFragment() const { return fHasFragment; } 65 const wgpu::RenderPipeline& dawnRenderPipeline() const; 66 67 private: DawnGraphicsPipeline(const skgpu::graphite::SharedContext * sharedContext,wgpu::RenderPipeline renderPipeline,PrimitiveType primitiveType,uint32_t refValue,bool hasStepUniforms,bool hasFragment)68 DawnGraphicsPipeline(const skgpu::graphite::SharedContext* sharedContext, 69 wgpu::RenderPipeline renderPipeline, 70 PrimitiveType primitiveType, 71 uint32_t refValue, 72 bool hasStepUniforms, 73 bool hasFragment) 74 : GraphicsPipeline(sharedContext) 75 , fRenderPipeline(std::move(renderPipeline)) 76 , fPrimitiveType(primitiveType) 77 , fStencilReferenceValue(refValue) 78 , fHasStepUniforms(hasStepUniforms) 79 , fHasFragment(hasFragment) {} 80 81 void freeGpuData() override; 82 83 wgpu::RenderPipeline fRenderPipeline; 84 const PrimitiveType fPrimitiveType; 85 const uint32_t fStencilReferenceValue; 86 const bool fHasStepUniforms; 87 const bool fHasFragment; 88 }; 89 90 } // namespace skgpu::graphite 91 92 #endif // skgpu_graphite_DawnGraphicsPipeline_DEFINED 93