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_DrawPass_DEFINED 9 #define skgpu_graphite_DrawPass_DEFINED 10 11 #include "include/core/SkColor.h" 12 #include "include/core/SkRect.h" 13 #include "include/core/SkRefCnt.h" 14 #include "include/private/base/SkTArray.h" 15 #include "src/base/SkEnumBitMask.h" 16 #include "src/gpu/graphite/DrawCommands.h" 17 #include "src/gpu/graphite/DrawTypes.h" 18 #include "src/gpu/graphite/GraphicsPipelineDesc.h" 19 #include "src/gpu/graphite/ResourceTypes.h" 20 #include "src/gpu/graphite/TextureProxy.h" 21 22 #include <memory> 23 24 struct SkImageInfo; 25 26 namespace skgpu::graphite { 27 28 class BoundsManager; 29 class CommandBuffer; 30 class DrawList; 31 class GraphicsPipeline; 32 class Recorder; 33 struct RenderPassDesc; 34 class ResourceProvider; 35 class RuntimeEffectDictionary; 36 class Sampler; 37 class TextureDataBlock; 38 class Texture; 39 enum class UniformSlot; 40 41 /** 42 * DrawPass is analogous to a subpass, storing the drawing operations in the order they are stored 43 * in the eventual command buffer, as well as the surface proxy the operations are intended for. 44 * DrawPasses are grouped into a RenderPassTask for execution within a single render pass if the 45 * subpasses are compatible with each other. 46 * 47 * Unlike DrawList, DrawPasses are immutable and represent as closely as possible what will be 48 * stored in the command buffer while being flexible as to how the pass is incorporated. Depending 49 * on the backend, it may even be able to write accumulated vertex and uniform data directly to 50 * mapped GPU memory, although that is the extent of the CPU->GPU work they perform before they are 51 * executed by a RenderPassTask. 52 */ 53 class DrawPass { 54 public: 55 ~DrawPass(); 56 57 // Create a DrawPass that renders the DrawList into `target` with the given load/store ops and 58 // clear color. 59 static std::unique_ptr<DrawPass> Make(Recorder*, 60 std::unique_ptr<DrawList>, 61 sk_sp<TextureProxy> target, 62 const SkImageInfo& targetInfo, 63 std::pair<LoadOp, StoreOp>, 64 std::array<float, 4> clearColor); 65 66 // Defined relative to the top-left corner of the surface the DrawPass renders to, and is 67 // contained within its dimensions. bounds()68 const SkIRect& bounds() const { return fBounds; } target()69 TextureProxy* target() const { return fTarget.get(); } ops()70 std::pair<LoadOp, StoreOp> ops() const { return fOps; } clearColor()71 std::array<float, 4> clearColor() const { return fClearColor; } 72 requiresDstTexture()73 bool requiresDstTexture() const { return false; } requiresMSAA()74 bool requiresMSAA() const { return fRequiresMSAA; } 75 depthStencilFlags()76 SkEnumBitMask<DepthStencilFlags> depthStencilFlags() const { return fDepthStencilFlags; } 77 vertexBufferSize()78 size_t vertexBufferSize() const { return 0; } uniformBufferSize()79 size_t uniformBufferSize() const { return 0; } 80 81 // Instantiate and prepare any resources used by the DrawPass that require the Recorder's 82 // ResourceProvider. This includes things likes GraphicsPipelines, sampled Textures, Samplers, 83 // etc. 84 bool prepareResources(ResourceProvider*, 85 const RuntimeEffectDictionary*, 86 const RenderPassDesc&); 87 commands()88 DrawPassCommands::List::Iter commands() const { 89 return fCommandList.commands(); 90 } 91 getPipeline(size_t index)92 const GraphicsPipeline* getPipeline(size_t index) const { 93 return fFullPipelines[index].get(); 94 } 95 const Texture* getTexture(size_t index) const; 96 const Sampler* getSampler(size_t index) const; 97 sampledTextures()98 skia_private::TArray<sk_sp<TextureProxy>> sampledTextures() const { return fSampledTextures; } 99 100 void addResourceRefs(CommandBuffer*) const; 101 102 private: 103 class SortKey; 104 105 DrawPass(sk_sp<TextureProxy> target, 106 std::pair<LoadOp, StoreOp> ops, 107 std::array<float, 4> clearColor); 108 109 DrawPassCommands::List fCommandList; 110 111 sk_sp<TextureProxy> fTarget; 112 SkIRect fBounds; 113 114 std::pair<LoadOp, StoreOp> fOps; 115 std::array<float, 4> fClearColor; 116 117 SkEnumBitMask<DepthStencilFlags> fDepthStencilFlags = DepthStencilFlags::kNone; 118 bool fRequiresMSAA = false; 119 120 // The pipelines are referenced by index in BindGraphicsPipeline, but that will index into a 121 // an array of actual GraphicsPipelines. 122 skia_private::TArray<GraphicsPipelineDesc> fPipelineDescs; 123 skia_private::TArray<SamplerDesc> fSamplerDescs; 124 125 // These resources all get instantiated during prepareResources. 126 skia_private::TArray<sk_sp<GraphicsPipeline>> fFullPipelines; 127 skia_private::TArray<sk_sp<TextureProxy>> fSampledTextures; 128 skia_private::TArray<sk_sp<Sampler>> fSamplers; 129 }; 130 131 } // namespace skgpu::graphite 132 133 #endif // skgpu_graphite_DrawPass_DEFINED 134