Revert "[Impeller] Add render target builder." (flutter/engine#36368)

This commit is contained in:
Dan Field
2022-09-22 22:12:36 -07:00
committed by GitHub
parent 96cc60c5af
commit 6f088565b0
9 changed files with 206 additions and 327 deletions

View File

@@ -905,8 +905,6 @@ FILE: ../../../flutter/impeller/renderer/render_pass.cc
FILE: ../../../flutter/impeller/renderer/render_pass.h
FILE: ../../../flutter/impeller/renderer/render_target.cc
FILE: ../../../flutter/impeller/renderer/render_target.h
FILE: ../../../flutter/impeller/renderer/render_target_builder.cc
FILE: ../../../flutter/impeller/renderer/render_target_builder.h
FILE: ../../../flutter/impeller/renderer/renderer.cc
FILE: ../../../flutter/impeller/renderer/renderer.h
FILE: ../../../flutter/impeller/renderer/renderer_unittests.cc

View File

@@ -10,7 +10,6 @@
#include "impeller/base/validation.h"
#include "impeller/entity/entity.h"
#include "impeller/renderer/render_target.h"
#include "impeller/renderer/render_target_builder.h"
#include "impeller/renderer/snapshot.h"
namespace impeller {
@@ -53,10 +52,7 @@ std::shared_ptr<Texture> Picture::RenderToTexture(
// This texture isn't host visible, but we might want to add host visible
// features to Image someday.
auto target = RenderTargetBuilder()
.SetSize(size)
.SetRenderTargetType(RenderTargetType::kOffscreen)
.Build(*context.GetContext());
auto target = RenderTarget::CreateOffscreen(*context.GetContext(), size);
if (!target.IsValid()) {
VALIDATION_LOG << "Could not create valid RenderTarget.";
return nullptr;

View File

@@ -11,7 +11,6 @@
#include "impeller/renderer/formats.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/render_target.h"
#include "impeller/renderer/render_target_builder.h"
namespace impeller {
@@ -246,15 +245,12 @@ std::shared_ptr<Texture> ContentContext::MakeSubpass(
SubpassCallback subpass_callback) const {
auto context = GetContext();
RenderTargetType render_target_type = context->SupportsOffscreenMSAA()
? RenderTargetType::kOffscreenMSAA
: RenderTargetType::kOffscreen;
RenderTarget subpass_target = RenderTargetBuilder()
.SetSize(texture_size)
.SetRenderTargetType(render_target_type)
.Build(*context);
RenderTarget subpass_target;
if (context->SupportsOffscreenMSAA()) {
subpass_target = RenderTarget::CreateOffscreenMSAA(*context, texture_size);
} else {
subpass_target = RenderTarget::CreateOffscreen(*context, texture_size);
}
auto subpass_texture = subpass_target.GetRenderTargetTexture();
if (!subpass_texture) {
return nullptr;

View File

@@ -23,7 +23,6 @@
#include "impeller/renderer/command_buffer.h"
#include "impeller/renderer/formats.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/render_target_builder.h"
#include "impeller/renderer/texture.h"
namespace impeller {
@@ -153,27 +152,34 @@ static RenderTarget CreateRenderTarget(ContentContext& renderer,
/// What's important is the `StorageMode` of the textures, which cannot be
/// changed for the lifetime of the textures.
RenderTargetBuilder builder;
builder.SetSize(size)
.SetLabel("EntityPass")
.SetColorResolveStorageMode(StorageMode::kDevicePrivate)
.SetColorLoadAction(LoadAction::kDontCare)
.SetStencilStorageMode(readable ? StorageMode::kDevicePrivate
: StorageMode::kDeviceTransient)
.SetStencilLoadAction(LoadAction::kDontCare)
.SetStencilStoreAction(StoreAction::kDontCare);
if (context->SupportsOffscreenMSAA()) {
builder.SetRenderTargetType(RenderTargetType::kOffscreenMSAA)
.SetColorStoreAction(StoreAction::kMultisampleResolve)
.SetColorStorageMode(StorageMode::kDeviceTransient);
} else {
builder.SetRenderTargetType(RenderTargetType::kOffscreen)
.SetColorStorageMode(StorageMode::kDevicePrivate)
.SetColorStoreAction(StoreAction::kDontCare);
return RenderTarget::CreateOffscreenMSAA(
*context, // context
size, // size
"EntityPass", // label
StorageMode::kDeviceTransient, // color_storage_mode
StorageMode::kDevicePrivate, // color_resolve_storage_mode
LoadAction::kDontCare, // color_load_action
StoreAction::kMultisampleResolve, // color_store_action
readable ? StorageMode::kDevicePrivate
: StorageMode::kDeviceTransient, // stencil_storage_mode
LoadAction::kDontCare, // stencil_load_action
StoreAction::kDontCare // stencil_store_action
);
}
return builder.Build(*context);
return RenderTarget::CreateOffscreen(
*context, // context
size, // size
"EntityPass", // label
StorageMode::kDevicePrivate, // color_storage_mode
LoadAction::kDontCare, // color_load_action
StoreAction::kDontCare, // color_store_action
readable ? StorageMode::kDevicePrivate
: StorageMode::kDeviceTransient, // stencil_storage_mode
LoadAction::kDontCare, // stencil_load_action
StoreAction::kDontCare // stencil_store_action
);
}
bool EntityPass::Render(ContentContext& renderer,

View File

@@ -55,8 +55,6 @@ impeller_component("renderer") {
"render_pass.h",
"render_target.cc",
"render_target.h",
"render_target_builder.cc",
"render_target_builder.h",
"renderer.cc",
"renderer.h",
"sampler.cc",

View File

@@ -176,4 +176,155 @@ const std::optional<StencilAttachment>& RenderTarget::GetStencilAttachment()
return stencil_;
}
RenderTarget RenderTarget::CreateOffscreen(const Context& context,
ISize size,
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 {};
}
TextureDescriptor color_tex0;
color_tex0.storage_mode = color_storage_mode;
color_tex0.format = PixelFormat::kDefaultColor;
color_tex0.size = size;
color_tex0.usage = static_cast<uint64_t>(TextureUsage::kRenderTarget) |
static_cast<uint64_t>(TextureUsage::kShaderRead);
TextureDescriptor stencil_tex0;
stencil_tex0.storage_mode = stencil_storage_mode;
stencil_tex0.format = PixelFormat::kDefaultStencil;
stencil_tex0.size = size;
stencil_tex0.usage =
static_cast<TextureUsageMask>(TextureUsage::kRenderTarget);
ColorAttachment color0;
color0.clear_color = Color::BlackTransparent();
color0.load_action = color_load_action;
color0.store_action = color_store_action;
color0.texture = context.GetResourceAllocator()->CreateTexture(color_tex0);
if (!color0.texture) {
return {};
}
color0.texture->SetLabel(SPrintF("%s Color Texture", label.c_str()));
StencilAttachment stencil0;
stencil0.load_action = stencil_load_action;
stencil0.store_action = stencil_store_action;
stencil0.clear_stencil = 0u;
stencil0.texture =
context.GetResourceAllocator()->CreateTexture(stencil_tex0);
if (!stencil0.texture) {
return {};
}
stencil0.texture->SetLabel(SPrintF("%s Stencil Texture", label.c_str()));
RenderTarget target;
target.SetColorAttachment(std::move(color0), 0u);
target.SetStencilAttachment(std::move(stencil0));
return target;
}
RenderTarget RenderTarget::CreateOffscreenMSAA(
const Context& context,
ISize size,
std::string label,
StorageMode color_storage_mode,
StorageMode color_resolve_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 {};
}
// Create MSAA color texture.
TextureDescriptor color0_tex_desc;
color0_tex_desc.storage_mode = color_storage_mode;
color0_tex_desc.type = TextureType::kTexture2DMultisample;
color0_tex_desc.sample_count = SampleCount::kCount4;
color0_tex_desc.format = PixelFormat::kDefaultColor;
color0_tex_desc.size = size;
color0_tex_desc.usage = static_cast<uint64_t>(TextureUsage::kRenderTarget);
auto color0_msaa_tex =
context.GetResourceAllocator()->CreateTexture(color0_tex_desc);
if (!color0_msaa_tex) {
VALIDATION_LOG << "Could not create multisample color texture.";
return {};
}
color0_msaa_tex->SetLabel(
SPrintF("%s Color Texture (Multisample)", label.c_str()));
// Create color resolve texture.
TextureDescriptor color0_resolve_tex_desc;
color0_resolve_tex_desc.storage_mode = color_resolve_storage_mode;
color0_resolve_tex_desc.format = PixelFormat::kDefaultColor;
color0_resolve_tex_desc.size = size;
color0_resolve_tex_desc.usage =
static_cast<uint64_t>(TextureUsage::kRenderTarget) |
static_cast<uint64_t>(TextureUsage::kShaderRead);
auto color0_resolve_tex =
context.GetResourceAllocator()->CreateTexture(color0_resolve_tex_desc);
if (!color0_resolve_tex) {
VALIDATION_LOG << "Could not create color texture.";
return {};
}
color0_resolve_tex->SetLabel(SPrintF("%s Color Texture", label.c_str()));
// Color attachment.
ColorAttachment color0;
color0.clear_color = Color::BlackTransparent();
color0.load_action = color_load_action;
color0.store_action = color_store_action;
color0.texture = color0_msaa_tex;
color0.resolve_texture = color0_resolve_tex;
// Create MSAA stencil texture.
TextureDescriptor stencil_tex0;
stencil_tex0.storage_mode = stencil_storage_mode;
stencil_tex0.type = TextureType::kTexture2DMultisample;
stencil_tex0.sample_count = SampleCount::kCount4;
stencil_tex0.format = PixelFormat::kDefaultStencil;
stencil_tex0.size = size;
stencil_tex0.usage =
static_cast<TextureUsageMask>(TextureUsage::kRenderTarget);
StencilAttachment stencil0;
stencil0.load_action = stencil_load_action;
stencil0.store_action = stencil_store_action;
stencil0.clear_stencil = 0u;
stencil0.texture =
context.GetResourceAllocator()->CreateTexture(stencil_tex0);
if (!stencil0.texture) {
return {};
}
stencil0.texture->SetLabel(SPrintF("%s Stencil Texture", label.c_str()));
RenderTarget target;
target.SetColorAttachment(std::move(color0), 0u);
target.SetStencilAttachment(std::move(stencil0));
return target;
}
} // namespace impeller

View File

@@ -19,6 +19,29 @@ class Context;
class RenderTarget {
public:
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);
static RenderTarget CreateOffscreenMSAA(
const Context& context,
ISize size,
std::string label = "Offscreen MSAA",
StorageMode color_storage_mode = StorageMode::kDeviceTransient,
StorageMode color_resolve_storage_mode = StorageMode::kDevicePrivate,
LoadAction color_load_action = LoadAction::kClear,
StoreAction color_store_action = StoreAction::kMultisampleResolve,
StorageMode stencil_storage_mode = StorageMode::kDeviceTransient,
LoadAction stencil_load_action = LoadAction::kClear,
StoreAction stencil_store_action = StoreAction::kDontCare);
RenderTarget();
~RenderTarget();

View File

@@ -1,217 +0,0 @@
#include "impeller/renderer/render_target_builder.h"
#include "impeller/base/strings.h"
#include "impeller/base/validation.h"
#include "impeller/renderer/allocator.h"
#include "impeller/renderer/context.h"
#include "impeller/renderer/texture.h"
namespace impeller {
RenderTargetBuilder::RenderTargetBuilder() = default;
RenderTargetBuilder::~RenderTargetBuilder() = default;
RenderTarget RenderTargetBuilder::Build(const Context& context) const {
if (render_target_type_ == RenderTargetType::kOffscreen) {
return CreateOffscreen(context);
} else if (render_target_type_ == RenderTargetType::kOffscreenMSAA) {
return CreateOffscreenMSAA(context);
} else {
return {};
}
}
RenderTarget RenderTargetBuilder::CreateOffscreen(
const Context& context) const {
if (size_.IsEmpty()) {
return {};
}
TextureDescriptor color_tex0;
color_tex0.storage_mode = color_storage_mode_;
color_tex0.format = PixelFormat::kDefaultColor;
color_tex0.size = size_;
color_tex0.usage = static_cast<uint64_t>(TextureUsage::kRenderTarget) |
static_cast<uint64_t>(TextureUsage::kShaderRead);
TextureDescriptor stencil_tex0;
stencil_tex0.storage_mode = stencil_storage_mode_;
stencil_tex0.format = PixelFormat::kDefaultStencil;
stencil_tex0.size = size_;
stencil_tex0.usage =
static_cast<TextureUsageMask>(TextureUsage::kRenderTarget);
ColorAttachment color0;
color0.clear_color = Color::BlackTransparent();
color0.load_action = color_load_action_;
color0.store_action = color_store_action_;
color0.texture = context.GetResourceAllocator()->CreateTexture(color_tex0);
if (!color0.texture) {
return {};
}
color0.texture->SetLabel(SPrintF("%s Color Texture", label_.c_str()));
StencilAttachment stencil0;
stencil0.load_action = stencil_load_action_;
stencil0.store_action = stencil_store_action_;
stencil0.clear_stencil = 0u;
stencil0.texture =
context.GetResourceAllocator()->CreateTexture(stencil_tex0);
if (!stencil0.texture) {
return {};
}
stencil0.texture->SetLabel(SPrintF("%s Stencil Texture", label_.c_str()));
RenderTarget target;
target.SetColorAttachment(std::move(color0), 0u);
target.SetStencilAttachment(std::move(stencil0));
return target;
}
RenderTarget RenderTargetBuilder::CreateOffscreenMSAA(
const Context& context) const {
if (size_.IsEmpty()) {
return {};
}
// Create MSAA color texture.
TextureDescriptor color0_tex_desc;
color0_tex_desc.storage_mode = color_storage_mode_;
color0_tex_desc.type = TextureType::kTexture2DMultisample;
color0_tex_desc.sample_count = SampleCount::kCount4;
color0_tex_desc.format = PixelFormat::kDefaultColor;
color0_tex_desc.size = size_;
color0_tex_desc.usage = static_cast<uint64_t>(TextureUsage::kRenderTarget);
auto color0_msaa_tex =
context.GetResourceAllocator()->CreateTexture(color0_tex_desc);
if (!color0_msaa_tex) {
VALIDATION_LOG << "Could not create multisample color texture.";
return {};
}
color0_msaa_tex->SetLabel(
SPrintF("%s Color Texture (Multisample)", label_.c_str()));
// Create color resolve texture.
TextureDescriptor color0_resolve_tex_desc;
color0_resolve_tex_desc.storage_mode = color_resolve_storage_mode_;
color0_resolve_tex_desc.format = PixelFormat::kDefaultColor;
color0_resolve_tex_desc.size = size_;
color0_resolve_tex_desc.usage =
static_cast<uint64_t>(TextureUsage::kRenderTarget) |
static_cast<uint64_t>(TextureUsage::kShaderRead);
auto color0_resolve_tex =
context.GetResourceAllocator()->CreateTexture(color0_resolve_tex_desc);
if (!color0_resolve_tex) {
VALIDATION_LOG << "Could not create color texture.";
return {};
}
color0_resolve_tex->SetLabel(SPrintF("%s Color Texture", label_.c_str()));
// Color attachment.
ColorAttachment color0;
color0.clear_color = Color::BlackTransparent();
color0.load_action = color_load_action_;
color0.store_action = color_store_action_;
color0.texture = color0_msaa_tex;
color0.resolve_texture = color0_resolve_tex;
// Create MSAA stencil texture.
TextureDescriptor stencil_tex0;
stencil_tex0.storage_mode = stencil_storage_mode_;
stencil_tex0.type = TextureType::kTexture2DMultisample;
stencil_tex0.sample_count = SampleCount::kCount4;
stencil_tex0.format = PixelFormat::kDefaultStencil;
stencil_tex0.size = size_;
stencil_tex0.usage =
static_cast<TextureUsageMask>(TextureUsage::kRenderTarget);
StencilAttachment stencil0;
stencil0.load_action = stencil_load_action_;
stencil0.store_action = stencil_store_action_;
stencil0.clear_stencil = 0u;
stencil0.texture =
context.GetResourceAllocator()->CreateTexture(stencil_tex0);
if (!stencil0.texture) {
return {};
}
stencil0.texture->SetLabel(SPrintF("%s Stencil Texture", label_.c_str()));
RenderTarget target;
target.SetColorAttachment(std::move(color0), 0u);
target.SetStencilAttachment(std::move(stencil0));
return target;
}
RenderTargetBuilder& RenderTargetBuilder::SetSize(ISize size) {
size_ = size;
return *this;
}
RenderTargetBuilder& RenderTargetBuilder::SetLabel(std::string label) {
label_ = label;
return *this;
}
RenderTargetBuilder& RenderTargetBuilder::SetColorStorageMode(
StorageMode mode) {
color_storage_mode_ = mode;
return *this;
}
RenderTargetBuilder& RenderTargetBuilder::SetColorLoadAction(
LoadAction action) {
color_load_action_ = action;
return *this;
}
RenderTargetBuilder& RenderTargetBuilder::SetColorStoreAction(
StoreAction action) {
color_store_action_ = action;
return *this;
}
RenderTargetBuilder& RenderTargetBuilder::SetStencilStorageMode(
StorageMode mode) {
stencil_storage_mode_ = mode;
return *this;
}
RenderTargetBuilder& RenderTargetBuilder::SetStencilLoadAction(
LoadAction action) {
stencil_load_action_ = action;
return *this;
}
RenderTargetBuilder& RenderTargetBuilder::SetStencilStoreAction(
StoreAction action) {
stencil_store_action_ = action;
return *this;
}
RenderTargetBuilder& RenderTargetBuilder::SetColorResolveStorageMode(
StorageMode mode) {
color_resolve_storage_mode_ = mode;
return *this;
}
RenderTargetBuilder& RenderTargetBuilder::SetRenderTargetType(
RenderTargetType type) {
render_target_type_ = type;
return *this;
}
} // namespace impeller

View File

@@ -1,72 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#pragma once
#include <functional>
#include <map>
#include <optional>
#include "context.h"
#include "flutter/fml/macros.h"
#include "impeller/geometry/size.h"
#include "impeller/renderer/allocator.h"
#include "impeller/renderer/formats.h"
#include "render_target.h"
namespace impeller {
enum class RenderTargetType { kOffscreen, kOffscreenMSAA, kUnknown };
class RenderTargetBuilder {
public:
RenderTargetBuilder();
~RenderTargetBuilder();
RenderTargetBuilder& SetSize(ISize size);
RenderTargetBuilder& SetLabel(std::string label);
RenderTargetBuilder& SetColorStorageMode(StorageMode mode);
RenderTargetBuilder& SetColorLoadAction(LoadAction action);
RenderTargetBuilder& SetColorStoreAction(StoreAction action);
RenderTargetBuilder& SetStencilStorageMode(StorageMode mode);
RenderTargetBuilder& SetStencilLoadAction(LoadAction action);
RenderTargetBuilder& SetStencilStoreAction(StoreAction action);
RenderTargetBuilder& SetColorResolveStorageMode(StorageMode mode);
RenderTargetBuilder& SetRenderTargetType(RenderTargetType type);
RenderTarget Build(const Context& context) const;
private:
ISize size_;
std::string label_;
StorageMode color_storage_mode_ = StorageMode::kDeviceTransient;
LoadAction color_load_action_ = LoadAction::kDontCare;
StoreAction color_store_action_ = StoreAction::kDontCare;
StorageMode stencil_storage_mode_ = StorageMode::kDeviceTransient;
LoadAction stencil_load_action_ = LoadAction::kDontCare;
StoreAction stencil_store_action_ = StoreAction::kDontCare;
StorageMode color_resolve_storage_mode_ = StorageMode::kDeviceTransient;
RenderTargetType render_target_type_ = RenderTargetType::kUnknown;
RenderTarget CreateOffscreen(const Context& context) const;
RenderTarget CreateOffscreenMSAA(const Context& context) const;
FML_DISALLOW_COPY_AND_ASSIGN(RenderTargetBuilder);
};
} // namespace impeller