Flutter Engine
The Flutter Engine
RenderPassDesc.cpp
Go to the documentation of this file.
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
9
11
12namespace skgpu::graphite {
13
14namespace {
15
16const char* to_str(LoadOp op) {
17 switch (op) {
18 case LoadOp::kLoad: return "load";
19 case LoadOp::kClear: return "clear";
20 case LoadOp::kDiscard: return "discard";
21 }
22
24}
25
26const char* to_str(StoreOp op) {
27 switch (op) {
28 case StoreOp::kStore: return "store";
29 case StoreOp::kDiscard: return "discard";
30 }
31
33}
34
35} // anonymous namespace
36
38 const TextureInfo& targetInfo,
39 LoadOp loadOp,
40 StoreOp storeOp,
41 SkEnumBitMask<DepthStencilFlags> depthStencilFlags,
42 const std::array<float, 4>& clearColor,
43 bool requiresMSAA,
44 Swizzle writeSwizzle) {
46 desc.fWriteSwizzle = writeSwizzle;
47 desc.fSampleCount = 1;
48 // It doesn't make sense to have a storeOp for our main target not be store. Why are we doing
49 // this DrawPass then
50 SkASSERT(storeOp == StoreOp::kStore);
51 if (requiresMSAA) {
53 desc.fColorAttachment.fTextureInfo = targetInfo;
54 desc.fColorAttachment.fLoadOp = loadOp;
55 desc.fColorAttachment.fStoreOp = storeOp;
56 desc.fSampleCount = caps->defaultMSAASamplesCount();
57 } else {
58 // TODO: If the resolve texture isn't readable, the MSAA color attachment will need to
59 // be persistently associated with the framebuffer, in which case it's not discardable.
60 auto msaaTextureInfo = caps->getDefaultMSAATextureInfo(targetInfo, Discardable::kYes);
61 if (msaaTextureInfo.isValid()) {
62 desc.fColorAttachment.fTextureInfo = msaaTextureInfo;
63 if (loadOp != LoadOp::kClear) {
64 desc.fColorAttachment.fLoadOp = LoadOp::kDiscard;
65 } else {
66 desc.fColorAttachment.fLoadOp = LoadOp::kClear;
67 }
68 desc.fColorAttachment.fStoreOp = StoreOp::kDiscard;
69
70 desc.fColorResolveAttachment.fTextureInfo = targetInfo;
71 if (loadOp != LoadOp::kLoad) {
72 desc.fColorResolveAttachment.fLoadOp = LoadOp::kDiscard;
73 } else {
74 desc.fColorResolveAttachment.fLoadOp = LoadOp::kLoad;
75 }
76 desc.fColorResolveAttachment.fStoreOp = storeOp;
77
78 desc.fSampleCount = msaaTextureInfo.numSamples();
79 } else {
80 // fall back to single sampled
81 desc.fColorAttachment.fTextureInfo = targetInfo;
82 desc.fColorAttachment.fLoadOp = loadOp;
83 desc.fColorAttachment.fStoreOp = storeOp;
84 }
85 }
86 } else {
87 desc.fColorAttachment.fTextureInfo = targetInfo;
88 desc.fColorAttachment.fLoadOp = loadOp;
89 desc.fColorAttachment.fStoreOp = storeOp;
90 }
91 desc.fClearColor = clearColor;
92
93 if (depthStencilFlags != DepthStencilFlags::kNone) {
94 desc.fDepthStencilAttachment.fTextureInfo = caps->getDefaultDepthStencilTextureInfo(
95 depthStencilFlags, desc.fSampleCount, targetInfo.isProtected());
96 // Always clear the depth and stencil to 0 at the start of a DrawPass, but discard at the
97 // end since their contents do not affect the next frame.
98 desc.fDepthStencilAttachment.fLoadOp = LoadOp::kClear;
99 desc.fClearDepth = 0.f;
100 desc.fClearStencil = 0;
101 desc.fDepthStencilAttachment.fStoreOp = StoreOp::kDiscard;
102 }
103
104 return desc;
105}
106
108 return SkStringPrintf("RP(color: %s, resolve: %s, ds: %s, samples: %u, swizzle: %s, "
109 "clear: c(%f,%f,%f,%f), d(%f), s(0x%02x))",
118}
119
121 // This intentionally only includes the fixed state that impacts pipeline compilation.
122 // We include the load op of the color attachment when there is a resolve attachment because
123 // the load may trigger a different renderpass description.
124 const char* colorLoadStr = "";
127 colorLoadStr = " w/ msaa load";
128 }
129 // TODO: Remove `fSampleCount` in label when the Dawn backend manages its MSAA color attachments
130 // directly instead of relying on msaaRenderToSingleSampledSupport().
131 return SkStringPrintf("RP(color: %s%s, resolve: %s, ds: %s, samples: %u, swizzle: %s)",
133 colorLoadStr,
138}
139
141 if (fTextureInfo.isValid()) {
142 return SkStringPrintf("info: %s loadOp: %s storeOp: %s",
146 } else {
147 return SkString("invalid attachment");
148 }
149}
150
151} // namespace skgpu::graphite
#define SkUNREACHABLE
Definition: SkAssert.h:135
#define SkASSERT(cond)
Definition: SkAssert.h:116
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
const char * c_str() const
Definition: SkString.h:133
SkString asString() const
Definition: Swizzle.cpp:46
virtual TextureInfo getDefaultDepthStencilTextureInfo(SkEnumBitMask< DepthStencilFlags >, uint32_t sampleCount, Protected) const =0
virtual TextureInfo getDefaultMSAATextureInfo(const TextureInfo &singleSampledInfo, Discardable discardable) const =0
int defaultMSAASamplesCount() const
Definition: Caps.h:142
bool msaaRenderToSingleSampledSupport() const
Definition: Caps.h:254
SkString toRPAttachmentString() const
Protected isProtected() const
Definition: TextureInfo.h:80
static std::string to_str(const SharedContext *ctx, const GraphicsPipelineDesc &gpDesc, const RenderPassDesc &rpDesc)
AttachmentDesc fDepthStencilAttachment
AttachmentDesc fColorResolveAttachment
std::array< float, 4 > fClearColor
static RenderPassDesc Make(const Caps *caps, const TextureInfo &targetInfo, LoadOp loadOp, StoreOp storeOp, SkEnumBitMask< DepthStencilFlags > depthStencilFlags, const std::array< float, 4 > &clearColor, bool requiresMSAA, Swizzle writeSwizzle)