Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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) {
45 RenderPassDesc desc;
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 // This intentionally includes the fixed state that impacts pipeline compilation
109 return SkStringPrintf("RP(color: %s, resolve: %s, ds: %s, samples: %d, swizzle: %s)",
115}
116
117SkString AttachmentDesc::toString() const {
118 if (fTextureInfo.isValid()) {
119 return SkStringPrintf("info: %s loadOp: %s storeOp: %s",
123 } else {
124 return SkString("invalid attachment");
125 }
126}
127
128} // namespace skgpu::graphite
#define SkUNREACHABLE
Definition SkAssert.h:135
#define SkASSERT(cond)
Definition SkAssert.h:116
SK_API SkString static SkString SkStringPrintf()
Definition SkString.h:287
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:135
bool msaaRenderToSingleSampledSupport() const
Definition Caps.h:247
Protected isProtected() const
Definition TextureInfo.h:80
static std::string to_str(const SharedContext *ctx, const GraphicsPipelineDesc &gpDesc, const RenderPassDesc &rpDesc)
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)