Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions impeller/entity/entity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@

#include "impeller/entity/entity.h"

#include <algorithm>
#include <optional>

#include "impeller/base/validation.h"
#include "impeller/entity/contents/content_context.h"
#include "impeller/entity/contents/filters/filter_contents.h"
#include "impeller/entity/contents/texture_contents.h"
#include "impeller/entity/entity_pass.h"
#include "impeller/geometry/color.h"
#include "impeller/geometry/vector.h"
#include "impeller/renderer/render_pass.h"

namespace impeller {
Expand Down
16 changes: 5 additions & 11 deletions impeller/entity/entity_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ static EntityPassTarget CreateRenderTarget(ContentContext& renderer,
}

return EntityPassTarget(
target, renderer.GetDeviceCapabilities().SupportsReadFromResolve(),
renderer.GetDeviceCapabilities().SupportsImplicitResolvingMSAA());
target, renderer.GetDeviceCapabilities().SupportsImplicitResolvingMSAA());
}

uint32_t EntityPass::GetTotalPassReads(ContentContext& renderer) const {
Expand Down Expand Up @@ -333,16 +332,11 @@ bool EntityPass::Render(ContentContext& renderer,
.coverage = Rect::MakeSize(root_render_target.GetRenderTargetSize()),
.clip_depth = 0}};

bool supports_onscreen_backdrop_reads =
renderer.GetDeviceCapabilities().SupportsReadFromOnscreenTexture() &&
// If the backend doesn't have `SupportsReadFromResolve`, we need to flip
// between two textures when restoring a previous MSAA pass.
renderer.GetDeviceCapabilities().SupportsReadFromResolve();
bool reads_from_onscreen_backdrop = GetTotalPassReads(renderer) > 0;
// In this branch path, we need to render everything to an offscreen texture
// and then blit the results onto the onscreen texture. If using this branch,
// there's no need to set up a stencil attachment on the root render target.
if (!supports_onscreen_backdrop_reads && reads_from_onscreen_backdrop) {
if (reads_from_onscreen_backdrop) {
auto offscreen_target =
CreateRenderTarget(renderer, root_render_target.GetRenderTargetSize(),
GetClearColor(render_target.GetRenderTargetSize()));
Expand Down Expand Up @@ -459,7 +453,6 @@ bool EntityPass::Render(ContentContext& renderer,

EntityPassTarget pass_target(
root_render_target,
renderer.GetDeviceCapabilities().SupportsReadFromResolve(),
renderer.GetDeviceCapabilities().SupportsImplicitResolvingMSAA());

return OnRender( //
Expand Down Expand Up @@ -844,8 +837,9 @@ bool EntityPass::OnRender(
TRACE_EVENT0("impeller", "EntityPass::OnRender");

auto context = renderer.GetContext();
InlinePassContext pass_context(
context, pass_target, GetTotalPassReads(renderer), collapsed_parent_pass);
InlinePassContext pass_context(context, renderer.GetRenderTargetCache(),
pass_target, GetTotalPassReads(renderer),
collapsed_parent_pass);
if (!pass_context.IsValid()) {
VALIDATION_LOG << SPrintF("Pass context invalid (Depth=%d)", pass_depth);
return false;
Expand Down
17 changes: 4 additions & 13 deletions impeller/entity/entity_pass_target.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
#include "impeller/base/validation.h"
#include "impeller/core/formats.h"
#include "impeller/core/texture.h"
#include "impeller/renderer/render_target.h"

namespace impeller {

EntityPassTarget::EntityPassTarget(const RenderTarget& render_target,
bool supports_read_from_resolve,
bool supports_implicit_msaa)
: target_(render_target),
supports_read_from_resolve_(supports_read_from_resolve),
supports_implicit_msaa_(supports_implicit_msaa) {}
: target_(render_target), supports_implicit_msaa_(supports_implicit_msaa) {}

std::shared_ptr<Texture> EntityPassTarget::Flip(Allocator& allocator) {
std::shared_ptr<Texture> EntityPassTarget::Flip(
RenderTargetAllocator& allocator) {
auto color0 = target_.GetColorAttachments().find(0)->second;
if (!color0.resolve_texture) {
VALIDATION_LOG << "EntityPassTarget Flip should never be called for a "
Expand All @@ -28,14 +27,6 @@ std::shared_ptr<Texture> EntityPassTarget::Flip(Allocator& allocator) {
return color0.texture;
}

if (supports_read_from_resolve_) {
// Just return the current resolve texture, which is safe to read in the
// next render pass that'll resolve to `target_`.
//
// Note that this can only be done when MSAA is being used.
return color0.resolve_texture;
}

if (!secondary_color_texture_) {
// The second texture is allocated lazily to avoid unused allocations.
TextureDescriptor new_descriptor =
Expand Down
8 changes: 3 additions & 5 deletions impeller/entity/entity_pass_target.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ class InlinePassContext;

class EntityPassTarget {
public:
explicit EntityPassTarget(const RenderTarget& render_target,
bool supports_read_from_resolve,
bool supports_implicit_msaa);
EntityPassTarget(const RenderTarget& render_target,
bool supports_implicit_msaa);

/// @brief Flips the backdrop and returns a readable texture that can be
/// bound/sampled to restore the previous pass.
Expand All @@ -24,7 +23,7 @@ class EntityPassTarget {
/// result of `GetRenderTarget` is guaranteed to be able to read the
/// previous pass's backdrop texture (which is returned by this
/// method).
std::shared_ptr<Texture> Flip(Allocator& allocator);
std::shared_ptr<Texture> Flip(RenderTargetAllocator& allocator);

const RenderTarget& GetRenderTarget() const;

Expand All @@ -34,7 +33,6 @@ class EntityPassTarget {
RenderTarget target_;
std::shared_ptr<Texture> secondary_color_texture_;

bool supports_read_from_resolve_;
bool supports_implicit_msaa_;

friend InlinePassContext;
Expand Down
10 changes: 4 additions & 6 deletions impeller/entity/entity_pass_target_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ TEST_P(EntityPassTargetTest, SwapWithMSAATexture) {
*content_context->GetContext(),
*GetContentContext()->GetRenderTargetCache(), {100, 100});

auto entity_pass_target = EntityPassTarget(render_target, false, false);
auto entity_pass_target = EntityPassTarget(render_target, false);

auto color0 = entity_pass_target.GetRenderTarget()
.GetColorAttachments()
Expand All @@ -37,8 +37,7 @@ TEST_P(EntityPassTargetTest, SwapWithMSAATexture) {
auto msaa_tex = color0.texture;
auto resolve_tex = color0.resolve_texture;

entity_pass_target.Flip(
*content_context->GetContext()->GetResourceAllocator());
entity_pass_target.Flip(*content_context->GetRenderTargetCache());

color0 = entity_pass_target.GetRenderTarget()
.GetColorAttachments()
Expand Down Expand Up @@ -86,7 +85,7 @@ TEST_P(EntityPassTargetTest, SwapWithMSAAImplicitResolve) {
render_target.SetStencilAttachment(std::nullopt);
}

auto entity_pass_target = EntityPassTarget(render_target, false, true);
auto entity_pass_target = EntityPassTarget(render_target, true);

auto color0 = entity_pass_target.GetRenderTarget()
.GetColorAttachments()
Expand All @@ -97,8 +96,7 @@ TEST_P(EntityPassTargetTest, SwapWithMSAAImplicitResolve) {

ASSERT_EQ(msaa_tex, resolve_tex);

entity_pass_target.Flip(
*content_context->GetContext()->GetResourceAllocator());
entity_pass_target.Flip(*content_context->GetRenderTargetCache());

color0 = entity_pass_target.GetRenderTarget()
.GetColorAttachments()
Expand Down
11 changes: 5 additions & 6 deletions impeller/entity/inline_pass_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@

#include "impeller/base/validation.h"
#include "impeller/core/formats.h"
#include "impeller/core/texture_descriptor.h"
#include "impeller/entity/entity_pass_target.h"
#include "impeller/renderer/command_buffer.h"

namespace impeller {

InlinePassContext::InlinePassContext(
std::shared_ptr<Context> context,
std::shared_ptr<RenderTargetAllocator> allocator,
EntityPassTarget& pass_target,
uint32_t pass_texture_reads,
std::optional<RenderPassResult> collapsed_parent_pass)
: context_(std::move(context)),
allocator_(std::move(allocator)),
pass_target_(pass_target),
is_collapsed_(collapsed_parent_pass.has_value()) {
if (collapsed_parent_pass.has_value()) {
Expand Down Expand Up @@ -106,8 +107,7 @@ InlinePassContext::RenderPassResult InlinePassContext::GetRenderPass(
.find(0)
->second.resolve_texture != nullptr;
if (pass_count_ > 0 && is_msaa) {
result.backdrop_texture =
pass_target_.Flip(*context_->GetResourceAllocator());
result.backdrop_texture = pass_target_.Flip(*allocator_);
if (!result.backdrop_texture) {
VALIDATION_LOG << "Could not flip the EntityPass render target.";
}
Expand Down Expand Up @@ -156,9 +156,8 @@ InlinePassContext::RenderPassResult InlinePassContext::GetRenderPass(

result.pass = pass_;

if (!context_->GetCapabilities()->SupportsReadFromResolve() &&
result.backdrop_texture ==
result.pass->GetRenderTarget().GetRenderTargetTexture()) {
if (result.backdrop_texture ==
result.pass->GetRenderTarget().GetRenderTargetTexture()) {
VALIDATION_LOG << "EntityPass backdrop restore configuration is not valid "
"for the current graphics backend.";
}
Expand Down
2 changes: 2 additions & 0 deletions impeller/entity/inline_pass_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class InlinePassContext {

InlinePassContext(
std::shared_ptr<Context> context,
std::shared_ptr<RenderTargetAllocator> allocator,
EntityPassTarget& pass_target,
uint32_t pass_texture_reads,
std::optional<RenderPassResult> collapsed_parent_pass = std::nullopt);
Expand All @@ -38,6 +39,7 @@ class InlinePassContext {

private:
std::shared_ptr<Context> context_;
std::shared_ptr<RenderTargetAllocator> allocator_;
EntityPassTarget& pass_target_;
std::shared_ptr<CommandBuffer> command_buffer_;
std::shared_ptr<RenderPass> pass_;
Expand Down
4 changes: 0 additions & 4 deletions impeller/renderer/backend/gles/capabilities_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,6 @@ bool CapabilitiesGLES::SupportsReadFromOnscreenTexture() const {
return false;
}

bool CapabilitiesGLES::SupportsReadFromResolve() const {
return false;
}

bool CapabilitiesGLES::SupportsDecalSamplerAddressMode() const {
return supports_decal_sampler_address_mode_;
}
Expand Down
3 changes: 0 additions & 3 deletions impeller/renderer/backend/gles/capabilities_gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ class CapabilitiesGLES final
// |Capabilities|
bool SupportsReadFromOnscreenTexture() const override;

// |Capabilities|
bool SupportsReadFromResolve() const override;

// |Capabilities|
bool SupportsDecalSamplerAddressMode() const override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ TEST(CapabilitiesGLES, CanInitializeWithDefaults) {
EXPECT_FALSE(capabilities->SupportsCompute());
EXPECT_FALSE(capabilities->SupportsComputeSubgroups());
EXPECT_FALSE(capabilities->SupportsReadFromOnscreenTexture());
EXPECT_FALSE(capabilities->SupportsReadFromResolve());
EXPECT_FALSE(capabilities->SupportsDecalSamplerAddressMode());
EXPECT_FALSE(capabilities->SupportsDeviceTransientTextures());

Expand Down
1 change: 0 additions & 1 deletion impeller/renderer/backend/metal/context_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ static bool DeviceSupportsComputeSubgroups(id<MTLDevice> device) {
.SetDefaultDepthStencilFormat(PixelFormat::kD32FloatS8UInt)
.SetSupportsCompute(true)
.SetSupportsComputeSubgroups(DeviceSupportsComputeSubgroups(device))
.SetSupportsReadFromResolve(true)
.SetSupportsReadFromOnscreenTexture(true)
.SetSupportsDeviceTransientTextures(true)
.Build();
Expand Down
7 changes: 0 additions & 7 deletions impeller/renderer/backend/vulkan/capabilities_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include "impeller/renderer/backend/vulkan/capabilities_vk.h"

#include <algorithm>

#include "impeller/base/validation.h"
#include "impeller/core/formats.h"
#include "impeller/renderer/backend/vulkan/vk.h"
Expand Down Expand Up @@ -446,11 +444,6 @@ bool CapabilitiesVK::SupportsComputeSubgroups() const {
return supports_compute_subgroups_;
}

// |Capabilities|
bool CapabilitiesVK::SupportsReadFromResolve() const {
return false;
}

// |Capabilities|
bool CapabilitiesVK::SupportsReadFromOnscreenTexture() const {
return false;
Expand Down
4 changes: 0 additions & 4 deletions impeller/renderer/backend/vulkan/capabilities_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <string>
#include <vector>

#include "flutter/fml/macros.h"
#include "impeller/base/backend_cast.h"
#include "impeller/renderer/backend/vulkan/vk.h"
#include "impeller/renderer/capabilities.h"
Expand Down Expand Up @@ -82,9 +81,6 @@ class CapabilitiesVK final : public Capabilities,
// |Capabilities|
bool SupportsComputeSubgroups() const override;

// |Capabilities|
bool SupportsReadFromResolve() const override;

// |Capabilities|
bool SupportsReadFromOnscreenTexture() const override;

Expand Down
15 changes: 0 additions & 15 deletions impeller/renderer/capabilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ class StandardCapabilities final : public Capabilities {
return supports_read_from_onscreen_texture_;
}

// |Capabilities|
bool SupportsReadFromResolve() const override {
return supports_read_from_resolve_;
}

// |Capabilities|
bool SupportsDecalSamplerAddressMode() const override {
return supports_decal_sampler_address_mode_;
Expand Down Expand Up @@ -92,7 +87,6 @@ class StandardCapabilities final : public Capabilities {
bool supports_compute,
bool supports_compute_subgroups,
bool supports_read_from_onscreen_texture,
bool supports_read_from_resolve,
bool supports_decal_sampler_address_mode,
bool supports_device_transient_textures,
PixelFormat default_color_format,
Expand All @@ -107,7 +101,6 @@ class StandardCapabilities final : public Capabilities {
supports_compute_subgroups_(supports_compute_subgroups),
supports_read_from_onscreen_texture_(
supports_read_from_onscreen_texture),
supports_read_from_resolve_(supports_read_from_resolve),
supports_decal_sampler_address_mode_(
supports_decal_sampler_address_mode),
supports_device_transient_textures_(supports_device_transient_textures),
Expand All @@ -125,7 +118,6 @@ class StandardCapabilities final : public Capabilities {
bool supports_compute_ = false;
bool supports_compute_subgroups_ = false;
bool supports_read_from_onscreen_texture_ = false;
bool supports_read_from_resolve_ = false;
bool supports_decal_sampler_address_mode_ = false;
bool supports_device_transient_textures_ = false;
PixelFormat default_color_format_ = PixelFormat::kUnknown;
Expand Down Expand Up @@ -186,12 +178,6 @@ CapabilitiesBuilder& CapabilitiesBuilder::SetSupportsReadFromOnscreenTexture(
return *this;
}

CapabilitiesBuilder& CapabilitiesBuilder::SetSupportsReadFromResolve(
bool read_from_resolve) {
supports_read_from_resolve_ = read_from_resolve;
return *this;
}

CapabilitiesBuilder& CapabilitiesBuilder::SetDefaultColorFormat(
PixelFormat value) {
default_color_format_ = value;
Expand Down Expand Up @@ -232,7 +218,6 @@ std::unique_ptr<Capabilities> CapabilitiesBuilder::Build() {
supports_compute_, //
supports_compute_subgroups_, //
supports_read_from_onscreen_texture_, //
supports_read_from_resolve_, //
supports_decal_sampler_address_mode_, //
supports_device_transient_textures_, //
default_color_format_.value_or(PixelFormat::kUnknown), //
Expand Down
16 changes: 0 additions & 16 deletions impeller/renderer/capabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,6 @@ class Capabilities {
/// texture for shader reading.
virtual bool SupportsReadFromOnscreenTexture() const = 0;

/// @brief Whether the context backend supports binding the current
/// `RenderPass` attachments. This is supported if the backend can
/// guarantee that attachment textures will not be mutated until the
/// render pass has fully completed.
///
/// This is possible because many mobile graphics cards track
/// `RenderPass` attachment state in intermediary tile memory prior to
/// Storing the pass in the heap allocated attachments on DRAM.
/// Metal's hazard tracking and Vulkan's barriers are granular enough
/// to allow for safely accessing attachment textures prior to storage
/// in the same `RenderPass`.
virtual bool SupportsReadFromResolve() const = 0;

/// @brief Whether the context backend supports `SamplerAddressMode::Decal`.
virtual bool SupportsDecalSamplerAddressMode() const = 0;

Expand Down Expand Up @@ -138,8 +125,6 @@ class CapabilitiesBuilder {

CapabilitiesBuilder& SetSupportsReadFromOnscreenTexture(bool value);

CapabilitiesBuilder& SetSupportsReadFromResolve(bool value);

CapabilitiesBuilder& SetDefaultColorFormat(PixelFormat value);

CapabilitiesBuilder& SetDefaultStencilFormat(PixelFormat value);
Expand All @@ -161,7 +146,6 @@ class CapabilitiesBuilder {
bool supports_compute_ = false;
bool supports_compute_subgroups_ = false;
bool supports_read_from_onscreen_texture_ = false;
bool supports_read_from_resolve_ = false;
bool supports_decal_sampler_address_mode_ = false;
bool supports_device_transient_textures_ = false;
std::optional<PixelFormat> default_color_format_ = std::nullopt;
Expand Down
Loading