Skip to content

Commit 026dcd1

Browse files
chinmaygardednfield
authored andcommitted
Turn on full-screen 4xMSAA by default and additional render target validations.
1 parent ed8b78a commit 026dcd1

18 files changed

+310
-30
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@ TEST_F(AiksTest, CanRenderGroupOpacity) {
127127

128128
canvas.Restore();
129129

130+
// ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
131+
}
132+
133+
TEST_F(AiksTest, CanPerformFullScreenMSAA) {
134+
Canvas canvas;
135+
136+
Paint red;
137+
red.color = Color::Red();
138+
139+
canvas.DrawCircle({250, 250}, 125, red);
140+
130141
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
131142
}
132143

impeller/aiks/canvas.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ void Canvas::DrawPath(Path path, Paint paint) {
9191
GetCurrentPass().AddEntity(std::move(entity));
9292
}
9393

94+
void Canvas::DrawRect(Rect rect, Paint paint) {
95+
DrawPath(PathBuilder{}.AddRect(rect).CreatePath(), std::move(paint));
96+
}
97+
98+
void Canvas::DrawCircle(Point center, Scalar radius, Paint paint) {
99+
DrawPath(PathBuilder{}.AddCircle(center, radius).CreatePath(),
100+
std::move(paint));
101+
}
102+
94103
void Canvas::SaveLayer(Paint paint, std::optional<Rect> bounds) {
95104
GetCurrentPass().SetDelegate(
96105
std::make_unique<PaintPassDelegate>(std::move(paint)));
@@ -189,10 +198,6 @@ size_t Canvas::GetStencilDepth() const {
189198
return xformation_stack_.back().stencil_depth;
190199
}
191200

192-
void Canvas::DrawRect(Rect rect, Paint paint) {
193-
DrawPath(PathBuilder{}.AddRect(rect).CreatePath(), std::move(paint));
194-
}
195-
196201
void Canvas::Save(bool create_subpass) {
197202
auto entry = CanvasStackEntry{};
198203
if (create_subpass) {

impeller/aiks/canvas.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class Canvas {
5353

5454
void DrawRect(Rect rect, Paint paint);
5555

56+
void DrawCircle(Point center, Scalar radius, Paint paint);
57+
5658
void DrawImage(std::shared_ptr<Image> image, Point offset, Paint paint);
5759

5860
void DrawImageRect(std::shared_ptr<Image> image,

impeller/base/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ impeller_component("base") {
1212
"config.h",
1313
"strings.cc",
1414
"strings.h",
15+
"validation.cc",
16+
"validation.h",
1517
]
1618
}
1719

impeller/base/base.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
#pragma once
66

77
#include "impeller/base/strings.h"
8+
#include "impeller/base/validation.h"

impeller/base/validation.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "flutter/impeller/base/validation.h"
6+
7+
#include "flutter/fml/logging.h"
8+
9+
namespace impeller {
10+
11+
ValidationLog::ValidationLog() = default;
12+
13+
ValidationLog::~ValidationLog() {
14+
FML_LOG(ERROR) << stream_.str();
15+
ImpellerValidationBreak();
16+
}
17+
18+
std::ostream& ValidationLog::GetStream() {
19+
return stream_;
20+
}
21+
22+
void ImpellerValidationBreak() {
23+
// Nothing to do. Exists for the debugger.
24+
FML_LOG(ERROR) << "Break on " << __FUNCTION__
25+
<< " to inspect point of failure.";
26+
}
27+
28+
} // namespace impeller

impeller/base/validation.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#pragma once
6+
7+
#include <sstream>
8+
9+
#include "flutter/fml/macros.h"
10+
11+
namespace impeller {
12+
13+
class ValidationLog {
14+
public:
15+
ValidationLog();
16+
17+
~ValidationLog();
18+
19+
std::ostream& GetStream();
20+
21+
private:
22+
std::ostringstream stream_;
23+
24+
FML_DISALLOW_COPY_ASSIGN_AND_MOVE(ValidationLog);
25+
};
26+
27+
void ImpellerValidationBreak();
28+
29+
} // namespace impeller
30+
31+
#define VALIDATION_LOG ::impeller::ValidationLog{}.GetStream()

impeller/playground/playground.mm

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,44 @@ static void PlaygroundKeyCallback(GLFWwindow* window,
144144
return false;
145145
}
146146

147-
TextureDescriptor color0_tex;
148-
color0_tex.format = PixelFormat::kB8G8R8A8UNormInt;
149-
color0_tex.size = {
147+
TextureDescriptor msaa_tex_desc;
148+
msaa_tex_desc.type = TextureType::k2DMultisample;
149+
msaa_tex_desc.sample_count = SampleCount::kCount4;
150+
msaa_tex_desc.format = PixelFormat::kB8G8R8A8UNormInt;
151+
msaa_tex_desc.size = {
150152
static_cast<ISize::Type>(current_drawable.texture.width),
151153
static_cast<ISize::Type>(current_drawable.texture.height)};
152-
color0_tex.usage = static_cast<uint64_t>(TextureUsage::kRenderTarget);
154+
msaa_tex_desc.usage = static_cast<uint64_t>(TextureUsage::kRenderTarget);
155+
156+
auto msaa_tex =
157+
renderer_.GetContext()->GetPermanentsAllocator()->CreateTexture(
158+
StorageMode::kDeviceTransient, msaa_tex_desc);
159+
if (!msaa_tex) {
160+
FML_LOG(ERROR) << "Could not allocate MSAA resolve texture.";
161+
return false;
162+
}
163+
164+
msaa_tex->SetLabel("PlaygroundMainColor4xMSAA");
165+
166+
TextureDescriptor onscreen_tex_desc;
167+
onscreen_tex_desc.format = PixelFormat::kB8G8R8A8UNormInt;
168+
onscreen_tex_desc.size = msaa_tex_desc.size;
169+
onscreen_tex_desc.usage =
170+
static_cast<uint64_t>(TextureUsage::kRenderTarget);
153171

154172
ColorAttachment color0;
155-
color0.texture =
156-
std::make_shared<TextureMTL>(color0_tex, current_drawable.texture);
173+
color0.texture = msaa_tex;
157174
color0.clear_color = Color::DarkSlateGray();
158175
color0.load_action = LoadAction::kClear;
159-
color0.store_action = StoreAction::kStore;
176+
color0.store_action = StoreAction::kMultisampleResolve;
177+
color0.resolve_texture = std::make_shared<TextureMTL>(
178+
onscreen_tex_desc, current_drawable.texture);
160179

161180
TextureDescriptor stencil0_tex;
181+
stencil0_tex.type = TextureType::k2DMultisample;
182+
stencil0_tex.sample_count = SampleCount::kCount4;
162183
stencil0_tex.format = PixelFormat::kD32FloatS8UNormInt;
163-
stencil0_tex.size = color0_tex.size;
184+
stencil0_tex.size = msaa_tex_desc.size;
164185
stencil0_tex.usage =
165186
static_cast<TextureUsageMask>(TextureUsage::kRenderTarget);
166187
auto stencil_texture =

impeller/renderer/backend/metal/allocator_mtl.mm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ static MTLStorageMode ToMTLStorageMode(StorageMode mode) {
111111
}
112112

113113
auto mtl_texture_desc = ToMTLTextureDescriptor(desc);
114+
115+
if (!mtl_texture_desc) {
116+
FML_DLOG(ERROR) << "Texture descriptor was invalid.";
117+
return nullptr;
118+
}
119+
114120
mtl_texture_desc.storageMode = ToMTLStorageMode(mode);
115121
auto texture = [device_ newTextureWithDescriptor:mtl_texture_desc];
116122
if (!texture) {

impeller/renderer/backend/metal/formats_mtl.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ constexpr MTLStoreAction ToMTLStoreAction(StoreAction action) {
206206
return MTLStoreActionDontCare;
207207
case StoreAction::kStore:
208208
return MTLStoreActionStore;
209+
case StoreAction::kMultisampleResolve:
210+
return MTLStoreActionMultisampleResolve;
209211
}
210212
return MTLStoreActionDontCare;
211213
}
@@ -216,6 +218,8 @@ constexpr StoreAction FromMTLStoreAction(MTLStoreAction action) {
216218
return StoreAction::kDontCare;
217219
case MTLStoreActionStore:
218220
return StoreAction::kStore;
221+
case MTLStoreActionMultisampleResolve:
222+
return StoreAction::kMultisampleResolve;
219223
default:
220224
break;
221225
}
@@ -249,6 +253,16 @@ constexpr MTLClearColor ToMTLClearColor(const Color& color) {
249253
return MTLClearColorMake(color.red, color.green, color.blue, color.alpha);
250254
}
251255

256+
constexpr MTLTextureType ToMTLTextureType(TextureType type) {
257+
switch (type) {
258+
case TextureType::k2D:
259+
return MTLTextureType2D;
260+
case TextureType::k2DMultisample:
261+
return MTLTextureType2DMultisample;
262+
}
263+
return MTLTextureType2D;
264+
}
265+
252266
MTLRenderPipelineColorAttachmentDescriptor*
253267
ToMTLRenderPipelineColorAttachmentDescriptor(
254268
ColorAttachmentDescriptor descriptor);

0 commit comments

Comments
 (0)