[Impeller] Uniquely label offscreen resources (flutter/engine#39987)

[Impeller] Uniquely label offscreen resources
This commit is contained in:
Brandon DeRosier
2023-03-01 13:59:51 -08:00
committed by GitHub
parent 713de45bb4
commit ef4d01a9ea
11 changed files with 28 additions and 28 deletions

View File

@@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include <sstream> #include <sstream>
#include "impeller/base/strings.h"
#include "impeller/entity/entity.h" #include "impeller/entity/entity.h"
#include "impeller/renderer/command_buffer.h" #include "impeller/renderer/command_buffer.h"
#include "impeller/renderer/formats.h" #include "impeller/renderer/formats.h"
@@ -308,6 +309,7 @@ bool ContentContext::IsValid() const {
} }
std::shared_ptr<Texture> ContentContext::MakeSubpass( std::shared_ptr<Texture> ContentContext::MakeSubpass(
const std::string& label,
ISize texture_size, ISize texture_size,
const SubpassCallback& subpass_callback, const SubpassCallback& subpass_callback,
bool msaa_enabled) const { bool msaa_enabled) const {
@@ -317,11 +319,11 @@ std::shared_ptr<Texture> ContentContext::MakeSubpass(
if (context->GetDeviceCapabilities().SupportsOffscreenMSAA() && if (context->GetDeviceCapabilities().SupportsOffscreenMSAA() &&
msaa_enabled) { msaa_enabled) {
subpass_target = RenderTarget::CreateOffscreenMSAA( subpass_target = RenderTarget::CreateOffscreenMSAA(
*context, texture_size, "Contents Offscreen MSAA", *context, texture_size, SPrintF("%s Offscreen", label.c_str()),
RenderTarget::kDefaultColorAttachmentConfigMSAA, std::nullopt); RenderTarget::kDefaultColorAttachmentConfigMSAA, std::nullopt);
} else { } else {
subpass_target = RenderTarget::CreateOffscreen( subpass_target = RenderTarget::CreateOffscreen(
*context, texture_size, "Contents Offscreen", *context, texture_size, SPrintF("%s Offscreen", label.c_str()),
RenderTarget::kDefaultColorAttachmentConfig, std::nullopt); RenderTarget::kDefaultColorAttachmentConfig, std::nullopt);
} }
auto subpass_texture = subpass_target.GetRenderTargetTexture(); auto subpass_texture = subpass_target.GetRenderTargetTexture();
@@ -330,7 +332,7 @@ std::shared_ptr<Texture> ContentContext::MakeSubpass(
} }
auto sub_command_buffer = context->CreateCommandBuffer(); auto sub_command_buffer = context->CreateCommandBuffer();
sub_command_buffer->SetLabel("Offscreen Contents Command Buffer"); sub_command_buffer->SetLabel(SPrintF("%s CommandBuffer", label.c_str()));
if (!sub_command_buffer) { if (!sub_command_buffer) {
return nullptr; return nullptr;
} }
@@ -339,7 +341,7 @@ std::shared_ptr<Texture> ContentContext::MakeSubpass(
if (!sub_renderpass) { if (!sub_renderpass) {
return nullptr; return nullptr;
} }
sub_renderpass->SetLabel("OffscreenContentsPass"); sub_renderpass->SetLabel(SPrintF("%s RenderPass", label.c_str()));
if (!subpass_callback(*this, *sub_renderpass)) { if (!subpass_callback(*this, *sub_renderpass)) {
return nullptr; return nullptr;

View File

@@ -603,7 +603,8 @@ class ContentContext {
/// @brief Creates a new texture of size `texture_size` and calls /// @brief Creates a new texture of size `texture_size` and calls
/// `subpass_callback` with a `RenderPass` for drawing to the texture. /// `subpass_callback` with a `RenderPass` for drawing to the texture.
std::shared_ptr<Texture> MakeSubpass(ISize texture_size, std::shared_ptr<Texture> MakeSubpass(const std::string& label,
ISize texture_size,
const SubpassCallback& subpass_callback, const SubpassCallback& subpass_callback,
bool msaa_enabled = true) const; bool msaa_enabled = true) const;

View File

@@ -6,6 +6,7 @@
#include <optional> #include <optional>
#include "fml/logging.h" #include "fml/logging.h"
#include "impeller/base/strings.h"
#include "impeller/entity/contents/content_context.h" #include "impeller/entity/contents/content_context.h"
#include "impeller/entity/contents/texture_contents.h" #include "impeller/entity/contents/texture_contents.h"
#include "impeller/renderer/command_buffer.h" #include "impeller/renderer/command_buffer.h"
@@ -82,7 +83,7 @@ std::optional<Snapshot> Contents::RenderToSnapshot(
} }
auto texture = renderer.MakeSubpass( auto texture = renderer.MakeSubpass(
ISize::Ceil(coverage->size), "Snapshot", ISize::Ceil(coverage->size),
[&contents = *this, &entity, &coverage](const ContentContext& renderer, [&contents = *this, &entity, &coverage](const ContentContext& renderer,
RenderPass& pass) -> bool { RenderPass& pass) -> bool {
Entity sub_entity; Entity sub_entity;

View File

@@ -150,11 +150,11 @@ static std::optional<Entity> AdvancedBlend(
return true; return true;
}; };
auto out_texture = renderer.MakeSubpass(ISize(coverage.size), callback); auto out_texture = renderer.MakeSubpass("Advanced Blend Filter",
ISize(coverage.size), callback);
if (!out_texture) { if (!out_texture) {
return std::nullopt; return std::nullopt;
} }
out_texture->SetLabel("Advanced Blend Filter Texture");
return Contents::EntityFromSnapshot( return Contents::EntityFromSnapshot(
Snapshot{.texture = out_texture, Snapshot{.texture = out_texture,
@@ -274,11 +274,11 @@ static std::optional<Entity> PipelineBlend(
return true; return true;
}; };
auto out_texture = renderer.MakeSubpass(ISize(coverage.size), callback); auto out_texture = renderer.MakeSubpass("Pipeline Blend Filter",
ISize(coverage.size), callback);
if (!out_texture) { if (!out_texture) {
return std::nullopt; return std::nullopt;
} }
out_texture->SetLabel("Pipeline Blend Filter Texture");
return Contents::EntityFromSnapshot( return Contents::EntityFromSnapshot(
Snapshot{.texture = out_texture, Snapshot{.texture = out_texture,

View File

@@ -122,11 +122,11 @@ std::optional<Entity> BorderMaskBlurFilterContents::RenderFilter(
return pass.AddCommand(std::move(cmd)); return pass.AddCommand(std::move(cmd));
}; };
auto out_texture = renderer.MakeSubpass(ISize(coverage.size), callback); auto out_texture = renderer.MakeSubpass("Border Mask Blur Filter",
ISize(coverage.size), callback);
if (!out_texture) { if (!out_texture) {
return std::nullopt; return std::nullopt;
} }
out_texture->SetLabel("BorderMaskBlurFilter Texture");
return Contents::EntityFromSnapshot( return Contents::EntityFromSnapshot(
Snapshot{.texture = out_texture, Snapshot{.texture = out_texture,

View File

@@ -97,12 +97,11 @@ std::optional<Entity> ColorMatrixFilterContents::RenderFilter(
return pass.AddCommand(std::move(cmd)); return pass.AddCommand(std::move(cmd));
}; };
auto out_texture = auto out_texture = renderer.MakeSubpass(
renderer.MakeSubpass(input_snapshot->texture->GetSize(), callback); "Color Matrix Filter", input_snapshot->texture->GetSize(), callback);
if (!out_texture) { if (!out_texture) {
return std::nullopt; return std::nullopt;
} }
out_texture->SetLabel("ColorMatrixFilter Texture");
return Contents::EntityFromSnapshot( return Contents::EntityFromSnapshot(
Snapshot{.texture = out_texture, Snapshot{.texture = out_texture,

View File

@@ -276,12 +276,12 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(
Vector2 scaled_size = pass_texture_rect.size * scale; Vector2 scaled_size = pass_texture_rect.size * scale;
ISize floored_size = ISize(scaled_size.x, scaled_size.y); ISize floored_size = ISize(scaled_size.x, scaled_size.y);
auto out_texture = renderer.MakeSubpass(floored_size, callback); auto out_texture = renderer.MakeSubpass("Directional Gaussian Blur Filter",
floored_size, callback);
if (!out_texture) { if (!out_texture) {
return std::nullopt; return std::nullopt;
} }
out_texture->SetLabel("DirectionalGaussianBlurFilter Texture");
SamplerDescriptor sampler_desc; SamplerDescriptor sampler_desc;
sampler_desc.min_filter = MinMagFilter::kLinear; sampler_desc.min_filter = MinMagFilter::kLinear;

View File

@@ -74,12 +74,11 @@ std::optional<Entity> LinearToSrgbFilterContents::RenderFilter(
return pass.AddCommand(std::move(cmd)); return pass.AddCommand(std::move(cmd));
}; };
auto out_texture = auto out_texture = renderer.MakeSubpass(
renderer.MakeSubpass(input_snapshot->texture->GetSize(), callback); "Linear to sRGB Filter", input_snapshot->texture->GetSize(), callback);
if (!out_texture) { if (!out_texture) {
return std::nullopt; return std::nullopt;
} }
out_texture->SetLabel("LinearToSrgb Texture");
return Contents::EntityFromSnapshot( return Contents::EntityFromSnapshot(
Snapshot{.texture = out_texture, Snapshot{.texture = out_texture,

View File

@@ -132,11 +132,11 @@ std::optional<Entity> DirectionalMorphologyFilterContents::RenderFilter(
return pass.AddCommand(cmd); return pass.AddCommand(cmd);
}; };
auto out_texture = renderer.MakeSubpass(ISize(coverage.size), callback); auto out_texture = renderer.MakeSubpass("Directional Morphology Filter",
ISize(coverage.size), callback);
if (!out_texture) { if (!out_texture) {
return std::nullopt; return std::nullopt;
} }
out_texture->SetLabel("DirectionalMorphologyFilter Texture");
SamplerDescriptor sampler_desc; SamplerDescriptor sampler_desc;
sampler_desc.min_filter = MinMagFilter::kLinear; sampler_desc.min_filter = MinMagFilter::kLinear;

View File

@@ -74,12 +74,11 @@ std::optional<Entity> SrgbToLinearFilterContents::RenderFilter(
return pass.AddCommand(std::move(cmd)); return pass.AddCommand(std::move(cmd));
}; };
auto out_texture = auto out_texture = renderer.MakeSubpass(
renderer.MakeSubpass(input_snapshot->texture->GetSize(), callback); "sRGB to Linear Filter", input_snapshot->texture->GetSize(), callback);
if (!out_texture) { if (!out_texture) {
return std::nullopt; return std::nullopt;
} }
out_texture->SetLabel("SrgbToLinear Texture");
return Contents::EntityFromSnapshot( return Contents::EntityFromSnapshot(
Snapshot{.texture = out_texture, Snapshot{.texture = out_texture,

View File

@@ -111,12 +111,11 @@ std::optional<Entity> YUVToRGBFilterContents::RenderFilter(
return pass.AddCommand(std::move(cmd)); return pass.AddCommand(std::move(cmd));
}; };
auto out_texture = auto out_texture = renderer.MakeSubpass(
renderer.MakeSubpass(y_input_snapshot->texture->GetSize(), callback); "YUV to RGB Filter", y_input_snapshot->texture->GetSize(), callback);
if (!out_texture) { if (!out_texture) {
return std::nullopt; return std::nullopt;
} }
out_texture->SetLabel("YUVToRGB Texture");
return Contents::EntityFromSnapshot(Snapshot{.texture = out_texture}, return Contents::EntityFromSnapshot(Snapshot{.texture = out_texture},
entity.GetBlendMode(), entity.GetBlendMode(),