| 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 "src/gpu/graphite/ResourceTypes.h" |
| 13 |
#include "src/gpu/graphite/TextureFormat.h" |
| 14 |
|
| 15 |
#include "src/gpu/Swizzle.h" |
| 16 |
|
| 17 |
#include <array> |
| 18 |
|
| 19 |
namespace skgpu::graphite { |
| 20 |
|
| 21 |
class Caps; |
| 22 |
class TextureInfo; |
| 23 |
|
| 24 |
struct AttachmentDesc { |
| 25 |
TextureFormat fFormat = TextureFormat::kUnsupported; |
| 26 |
LoadOp fLoadOp = LoadOp::kDiscard; |
| 27 |
StoreOp fStoreOp = StoreOp::kDiscard; |
| 28 |
SampleCount fSampleCount = SampleCount::k1; |
| 29 |
|
| 30 |
bool operator==(const AttachmentDesc& other) const { |
| 31 |
if (fFormat == TextureFormat::kUnsupported && |
| 32 |
other.fFormat == TextureFormat::kUnsupported) { |
| 33 |
return true; |
| 34 |
} |
| 35 |
|
| 36 |
return fFormat == other.fFormat && |
| 37 |
fLoadOp == other.fLoadOp && |
| 38 |
fStoreOp == other.fStoreOp && |
| 39 |
fSampleCount == other.fSampleCount; |
| 40 |
} |
| 41 |
bool operator!=(const AttachmentDesc& other) const { return !(*this == other); } |
| 42 |
|
| 43 |
bool isCompatible(const TextureInfo&) const; |
| 44 |
|
| 45 |
SkString toString() const; |
| 46 |
}; |
| 47 |
static_assert(sizeof(AttachmentDesc) == sizeof(uint32_t)); |
| 48 |
|
| 49 |
struct RenderPassDesc { |
| 50 |
static RenderPassDesc Make(const Caps* caps, |
| 51 |
const TextureInfo& targetInfo, |
| 52 |
LoadOp loadOp, |
| 53 |
StoreOp storeOp, |
| 54 |
SkEnumBitMask<DepthStencilFlags> depthStencilFlags, |
| 55 |
const std::array<float, 4>& clearColor, |
| 56 |
bool requiresMSAA, |
| 57 |
Swizzle writeSwizzle, |
| 58 |
const DstReadStrategy); |
| 59 |
|
| 60 |
bool operator==(const RenderPassDesc& other) const { |
| 61 |
return (fWriteSwizzle == other.fWriteSwizzle && |
| 62 |
fClearDepth == other.fClearDepth && |
| 63 |
fClearColor == other.fClearColor && |
| 64 |
fColorAttachment == other.fColorAttachment && |
| 65 |
fColorResolveAttachment == other.fColorResolveAttachment && |
| 66 |
fDepthStencilAttachment == other.fDepthStencilAttachment && |
| 67 |
fDstReadStrategy == other.fDstReadStrategy); |
| 68 |
} |
| 69 |
|
| 70 |
bool operator!=(const RenderPassDesc& other) const { |
| 71 |
return !(*this == other); |
| 72 |
} |
| 73 |
|
| 74 |
AttachmentDesc fColorAttachment; |
| 75 |
AttachmentDesc fColorResolveAttachment; |
| 76 |
AttachmentDesc fDepthStencilAttachment; |
| 77 |
|
| 78 |
// The write swizzle is applied in shader, so affects SkSL code generation, but is determined by |
| 79 |
// the desired SkColorType semantics and target TextureFormat combination of the render pass. |
| 80 |
Swizzle fWriteSwizzle; |
| 81 |
|
| 82 |
// The overall sample count of the render pass |
| 83 |
SampleCount fSampleCount; |
| 84 |
|
| 85 |
// The remaining fields are set on renderpasses, but don't change the structure of the pass. |
| 86 |
|
| 87 |
// Each renderpass determines what strategy to use for reading the dst texture. If no draws |
| 88 |
// within the renderpass require a dst read, this is set to be kNoneRequired. If any draw does |
| 89 |
// read from the dst, then each pipeline used by this RP independently determines if a dst read |
| 90 |
// is needed. When required, this strategy determines how to perform it. |
| 91 |
DstReadStrategy fDstReadStrategy; |
| 92 |
|
| 93 |
std::array<float, 4> fClearColor; |
| 94 |
float fClearDepth = 0.f; |
| 95 |
uint32_t fClearStencil = 0; |
| 96 |
|
| 97 |
SkString toString() const; |
| 98 |
// Only includes fixed state relevant to pipeline creation |
| 99 |
SkString toPipelineLabel() const; |
| 100 |
|
| 101 |
// TODO: |
| 102 |
// * bounds (TBD whether exact bounds vs. granular) |
| 103 |
// * input attachments |
| 104 |
// * subpass makeup information |
| 105 |
}; |
| 106 |
|
| 107 |
} // namespace skgpu::graphite |
| 108 |
|
| 109 |
#endif // skgpu_graphite_RenderPassDesc_DEFINED |