Don't use transient stencil buffers for passes with advanced blends (flutter/engine#33413)

This commit is contained in:
Brandon DeRosier
2022-05-17 13:21:14 -07:00
committed by GitHub
parent 7df5e81ea8
commit 8a59c097b0
3 changed files with 44 additions and 17 deletions

View File

@@ -14,8 +14,10 @@
#include "impeller/entity/contents/filters/inputs/filter_input.h"
#include "impeller/entity/contents/texture_contents.h"
#include "impeller/geometry/path_builder.h"
#include "impeller/renderer/allocator.h"
#include "impeller/renderer/command.h"
#include "impeller/renderer/command_buffer.h"
#include "impeller/renderer/formats.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/texture.h"
@@ -133,7 +135,10 @@ bool EntityPass::Render(ContentContext& renderer,
RenderTarget render_target) const {
if (contains_advanced_blends_) {
auto offscreen_target = RenderTarget::CreateOffscreen(
*renderer.GetContext(), render_target.GetRenderTargetSize());
*renderer.GetContext(), render_target.GetRenderTargetSize(),
"EntityPass", //
StorageMode::kDevicePrivate, LoadAction::kClear, StoreAction::kStore,
StorageMode::kDevicePrivate, LoadAction::kClear, StoreAction::kStore);
if (!RenderInternal(renderer, offscreen_target, Point(), 0)) {
return false;
}
@@ -245,8 +250,20 @@ bool EntityPass::RenderInternal(ContentContext& renderer,
continue;
}
auto subpass_target = RenderTarget::CreateOffscreen(
*context, ISize::Ceil(subpass_coverage->size));
RenderTarget subpass_target;
if (subpass->contains_advanced_blends_) {
subpass_target = RenderTarget::CreateOffscreen(
*context, ISize::Ceil(subpass_coverage->size), "EntityPass",
StorageMode::kDevicePrivate, LoadAction::kClear,
StoreAction::kStore, StorageMode::kDevicePrivate,
LoadAction::kClear, StoreAction::kStore);
} else {
subpass_target = RenderTarget::CreateOffscreen(
*context, ISize::Ceil(subpass_coverage->size), "EntityPass",
StorageMode::kDevicePrivate, LoadAction::kClear,
StoreAction::kStore, StorageMode::kDeviceTransient,
LoadAction::kClear, StoreAction::kDontCare);
}
auto subpass_texture = subpass_target.GetRenderTargetTexture();

View File

@@ -177,7 +177,13 @@ const std::optional<StencilAttachment>& RenderTarget::GetStencilAttachment()
RenderTarget RenderTarget::CreateOffscreen(const Context& context,
ISize size,
std::string label) {
std::string label,
StorageMode color_storage_mode,
LoadAction color_load_action,
StoreAction color_store_action,
StorageMode stencil_storage_mode,
LoadAction stencil_load_action,
StoreAction stencil_store_action) {
if (size.IsEmpty()) {
return {};
}
@@ -196,10 +202,10 @@ RenderTarget RenderTarget::CreateOffscreen(const Context& context,
ColorAttachment color0;
color0.clear_color = Color::BlackTransparent();
color0.load_action = LoadAction::kClear;
color0.store_action = StoreAction::kStore;
color0.load_action = color_load_action;
color0.store_action = color_store_action;
color0.texture = context.GetPermanentsAllocator()->CreateTexture(
StorageMode::kDevicePrivate, color_tex0);
color_storage_mode, color_tex0);
if (!color0.texture) {
return {};
@@ -208,11 +214,11 @@ RenderTarget RenderTarget::CreateOffscreen(const Context& context,
color0.texture->SetLabel(SPrintF("%sColorTexture", label.c_str()));
StencilAttachment stencil0;
stencil0.load_action = LoadAction::kClear;
stencil0.store_action = StoreAction::kDontCare;
stencil0.load_action = stencil_load_action;
stencil0.store_action = stencil_store_action;
stencil0.clear_stencil = 0u;
stencil0.texture = context.GetPermanentsAllocator()->CreateTexture(
StorageMode::kDeviceTransient, stencil_tex0);
stencil_storage_mode, stencil_tex0);
if (!stencil0.texture) {
return {};

View File

@@ -10,6 +10,7 @@
#include "flutter/fml/macros.h"
#include "impeller/geometry/size.h"
#include "impeller/renderer/allocator.h"
#include "impeller/renderer/formats.h"
namespace impeller {
@@ -18,13 +19,16 @@ class Context;
class RenderTarget {
public:
static RenderTarget CreateOffscreen(const Context& context,
ISize size,
std::string label = "Offscreen");
static RenderTarget CreateMSAA(const Context& context,
std::shared_ptr<Texture> resolve_texture,
std::string label = "Offscreen");
static RenderTarget CreateOffscreen(
const Context& context,
ISize size,
std::string label = "Offscreen",
StorageMode color_storage_mode = StorageMode::kDevicePrivate,
LoadAction color_load_action = LoadAction::kClear,
StoreAction color_store_action = StoreAction::kStore,
StorageMode stencil_storage_mode = StorageMode::kDeviceTransient,
LoadAction stencil_load_action = LoadAction::kClear,
StoreAction stencil_store_action = StoreAction::kDontCare);
RenderTarget();