1 /* 2 * Copyright 2024 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_RenderPassDesc_DEFINED 9 #define skgpu_graphite_RenderPassDesc_DEFINED 10 11 #include "include/core/SkString.h" 12 #include "include/gpu/graphite/TextureInfo.h" 13 #include "src/gpu/graphite/ResourceTypes.h" 14 15 #include "src/gpu/Swizzle.h" 16 17 #include <array> 18 19 namespace skgpu::graphite { 20 21 class Caps; 22 23 struct AttachmentDesc { 24 TextureInfo fTextureInfo; 25 LoadOp fLoadOp; 26 StoreOp fStoreOp; 27 28 bool operator==(const AttachmentDesc& other) const { 29 if (!fTextureInfo.isValid() && !other.fTextureInfo.isValid()) { 30 return true; 31 } 32 33 return fTextureInfo == other.fTextureInfo && 34 fLoadOp == other.fLoadOp && 35 fStoreOp == other.fStoreOp; 36 } 37 38 SkString toString() const; 39 }; 40 41 struct RenderPassDesc { 42 static RenderPassDesc Make(const Caps* caps, 43 const TextureInfo& targetInfo, 44 LoadOp loadOp, 45 StoreOp storeOp, 46 SkEnumBitMask<DepthStencilFlags> depthStencilFlags, 47 const std::array<float, 4>& clearColor, 48 bool requiresMSAA, 49 Swizzle writeSwizzle, 50 const DstReadStrategy targetReadStrategy); 51 52 bool operator==(const RenderPassDesc& other) const { 53 return (fSampleCount == other.fSampleCount && 54 fWriteSwizzle == other.fWriteSwizzle && 55 fClearDepth == other.fClearDepth && 56 fClearColor == other.fClearColor && 57 fColorAttachment == other.fColorAttachment && 58 fColorResolveAttachment == other.fColorResolveAttachment && 59 fDepthStencilAttachment == other.fDepthStencilAttachment && 60 fDstReadStrategyIfRequired == other.fDstReadStrategyIfRequired); 61 } 62 63 bool operator!=(const RenderPassDesc& other) const { 64 return !(*this == other); 65 } 66 67 AttachmentDesc fColorAttachment; 68 std::array<float, 4> fClearColor; 69 AttachmentDesc fColorResolveAttachment; 70 71 AttachmentDesc fDepthStencilAttachment; 72 float fClearDepth; 73 uint32_t fClearStencil; 74 75 Swizzle fWriteSwizzle; 76 77 // This samples count usually matches fColorAttachment & fDepthStencilAttachment's samples 78 // count. The only exceptional case is when multisampled render to single sampled is used. In 79 // that case, the fColorAttachment's samples count will be 1 and fSampleCount will be > 1. 80 uint32_t fSampleCount; 81 82 // Each shader/pipeline will need to independently determine whether a dst read is required. 83 // If so, it can consult RenderPassDesc's fDstReadStrategyIfRequired which is determined by 84 // the dst texture's information. 85 DstReadStrategy fDstReadStrategyIfRequired; 86 87 SkString toString() const; 88 // Only includes fixed state relevant to pipeline creation 89 SkString toPipelineLabel() const; 90 91 // TODO: 92 // * bounds (TBD whether exact bounds vs. granular) 93 // * input attachments 94 // * subpass makeup information 95 }; 96 97 } // namespace skgpu::graphite 98 99 #endif // skgpu_graphite_RenderPassDesc_DEFINED 100