Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions impeller/entity/contents/content_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ void ContentContextOptions::ApplyToPipelineDescriptor(
}
desc.SetColorAttachmentDescriptor(0u, color0);

if (!has_stencil_attachment) {
desc.SetStencilPixelFormat(impeller::PixelFormat::kUnknown);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have a ClearStencilAttachments, ClearDepthAttachments and ClearColorAttachment(size_t index) helpers on the descriptor.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

desc.SetStencilAttachmentDescriptors(std::nullopt);
}

if (desc.GetFrontStencilAttachmentDescriptor().has_value()) {
StencilAttachmentDescriptor stencil =
desc.GetFrontStencilAttachmentDescriptor().value();
Expand Down
7 changes: 5 additions & 2 deletions impeller/entity/contents/content_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,13 @@ struct ContentContextOptions {
CompareFunction stencil_compare = CompareFunction::kEqual;
StencilOperation stencil_operation = StencilOperation::kKeep;
PrimitiveType primitive_type = PrimitiveType::kTriangle;
bool has_stencil_attachment = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine (especially for non-TBDR archs), but we should be careful when adding more options to this struct as that open up another dimension along which PSO variants can be created (albeit with the same shaders). I'm somewhat uncomfortable we need to do this today already but we already have the prototypes and they are created concurrently. So it works out.

Perhaps we should add a comment to this struct explaining the consequences of adding fields here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added a docstring explaining that complicated Flutter apps could easily be expected to form hundreds of PSOs in total, but should never reach the order of e.g. 10s of thousands.

BTW, we'll need another param to set the color attachment pixel format for wide gamut (I suspect this is the major mismatch issue that @gaaclarke has been running into).


struct Hash {
constexpr std::size_t operator()(const ContentContextOptions& o) const {
return fml::HashCombine(o.sample_count, o.blend_mode, o.stencil_compare,
o.stencil_operation, o.primitive_type);
o.stencil_operation, o.primitive_type,
o.has_stencil_attachment);
}
};

Expand All @@ -200,7 +202,8 @@ struct ContentContextOptions {
lhs.blend_mode == rhs.blend_mode &&
lhs.stencil_compare == rhs.stencil_compare &&
lhs.stencil_operation == rhs.stencil_operation &&
lhs.primitive_type == rhs.primitive_type;
lhs.primitive_type == rhs.primitive_type &&
lhs.has_stencil_attachment == rhs.has_stencil_attachment;
}
};

Expand Down
4 changes: 4 additions & 0 deletions impeller/entity/contents/contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ namespace impeller {
ContentContextOptions OptionsFromPass(const RenderPass& pass) {
ContentContextOptions opts;
opts.sample_count = pass.GetRenderTarget().GetSampleCount();
opts.has_stencil_attachment =
pass.GetRenderTarget().GetStencilAttachment().has_value();
return opts;
}

ContentContextOptions OptionsFromPassAndEntity(const RenderPass& pass,
const Entity& entity) {
ContentContextOptions opts;
opts.sample_count = pass.GetRenderTarget().GetSampleCount();
opts.has_stencil_attachment =
pass.GetRenderTarget().GetStencilAttachment().has_value();
opts.blend_mode = entity.GetBlendMode();
return opts;
}
Expand Down
24 changes: 14 additions & 10 deletions impeller/entity/contents/scene_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,20 @@ bool SceneContents::Render(const ContentContext& renderer,
}

RenderTarget subpass_target = RenderTarget::CreateOffscreenMSAA(
*renderer.GetContext(), // context
ISize(coverage.value().size), // size
"SceneContents", // label
StorageMode::kDeviceTransient, // color_storage_mode
StorageMode::kDevicePrivate, // color_resolve_storage_mode
LoadAction::kClear, // color_load_action
StoreAction::kMultisampleResolve, // color_store_action
StorageMode::kDeviceTransient, // stencil_storage_mode
LoadAction::kDontCare, // stencil_load_action
StoreAction::kDontCare // stencil_store_action
*renderer.GetContext(), // context
ISize(coverage.value().size), // size
"SceneContents", // label
RenderTarget::AttachmentConfigMSAA{
.storage_mode = StorageMode::kDeviceTransient,
.resolve_storage_mode = StorageMode::kDevicePrivate,
.load_action = LoadAction::kClear,
.store_action = StoreAction::kMultisampleResolve,
}, // color_attachment_config
RenderTarget::AttachmentConfig{
.storage_mode = StorageMode::kDeviceTransient,
.load_action = LoadAction::kDontCare,
.store_action = StoreAction::kDontCare,
} // stencil_attachment_config
);
if (!subpass_target.IsValid()) {
return false;
Expand Down
50 changes: 29 additions & 21 deletions impeller/entity/entity_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,31 +155,39 @@ static RenderTarget CreateRenderTarget(ContentContext& renderer,

if (context->SupportsOffscreenMSAA()) {
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
*context, // context
size, // size
"EntityPass", // label
RenderTarget::AttachmentConfigMSAA{
.storage_mode = StorageMode::kDeviceTransient,
.resolve_storage_mode = StorageMode::kDevicePrivate,
.load_action = LoadAction::kDontCare,
.store_action = StoreAction::kMultisampleResolve,
}, // color_attachment_config
RenderTarget::AttachmentConfig{
.storage_mode = readable ? StorageMode::kDevicePrivate
: StorageMode::kDeviceTransient,
.load_action = LoadAction::kDontCare,
.store_action = StoreAction::kDontCare,
} // stencil_attachment_config
);
}

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
*context, // context
size, // size
"EntityPass", // label
RenderTarget::AttachmentConfig{
.storage_mode = StorageMode::kDevicePrivate,
.load_action = LoadAction::kDontCare,
.store_action = StoreAction::kDontCare,
}, // color_attachment_config
RenderTarget::AttachmentConfig{
.storage_mode = readable ? StorageMode::kDevicePrivate
: StorageMode::kDeviceTransient,
.load_action = LoadAction::kDontCare,
.store_action = StoreAction::kDontCare,
} // stencil_attachment_config
);
}

Expand Down
139 changes: 69 additions & 70 deletions impeller/renderer/render_target.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,84 +183,80 @@ const std::optional<StencilAttachment>& RenderTarget::GetStencilAttachment()
return stencil_;
}

RenderTarget RenderTarget::CreateOffscreen(const Context& context,
ISize size,
const 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) {
RenderTarget RenderTarget::CreateOffscreen(
const Context& context,
ISize size,
const std::string& label,
AttachmentConfig color_attachment_config,
std::optional<AttachmentConfig> stencil_attachment_config) {
if (size.IsEmpty()) {
return {};
}

RenderTarget target;

TextureDescriptor color_tex0;
color_tex0.storage_mode = color_storage_mode;
color_tex0.storage_mode = color_attachment_config.storage_mode;
color_tex0.format = context.GetColorAttachmentPixelFormat();
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.load_action = color_attachment_config.load_action;
color0.store_action = color_attachment_config.store_action;
color0.texture = context.GetResourceAllocator()->CreateTexture(color_tex0);

if (!color0.texture) {
return {};
}

color0.texture->SetLabel(SPrintF("%s Color Texture", label.c_str()));
target.SetColorAttachment(color0, 0u);

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 {};
if (stencil_attachment_config.has_value()) {
TextureDescriptor stencil_tex0;
stencil_tex0.storage_mode = stencil_attachment_config->storage_mode;
stencil_tex0.format = PixelFormat::kDefaultStencil;
stencil_tex0.size = size;
stencil_tex0.usage =
static_cast<TextureUsageMask>(TextureUsage::kRenderTarget);

StencilAttachment stencil0;
stencil0.load_action = stencil_attachment_config->load_action;
stencil0.store_action = stencil_attachment_config->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()));
target.SetStencilAttachment(std::move(stencil0));
} else {
target.SetStencilAttachment(std::nullopt);
}

stencil0.texture->SetLabel(SPrintF("%s Stencil Texture", label.c_str()));

RenderTarget target;
target.SetColorAttachment(color0, 0u);
target.SetStencilAttachment(std::move(stencil0));

return target;
}

RenderTarget RenderTarget::CreateOffscreenMSAA(
const Context& context,
ISize size,
const 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) {
AttachmentConfigMSAA color_attachment_config,
std::optional<AttachmentConfig> stencil_attachment_config) {
if (size.IsEmpty()) {
return {};
}

RenderTarget target;

// Create MSAA color texture.

TextureDescriptor color0_tex_desc;
color0_tex_desc.storage_mode = color_storage_mode;
color0_tex_desc.storage_mode = color_attachment_config.storage_mode;
color0_tex_desc.type = TextureType::kTexture2DMultisample;
color0_tex_desc.sample_count = SampleCount::kCount4;
color0_tex_desc.format = context.GetColorAttachmentPixelFormat();
Expand All @@ -279,7 +275,8 @@ RenderTarget RenderTarget::CreateOffscreenMSAA(
// Create color resolve texture.

TextureDescriptor color0_resolve_tex_desc;
color0_resolve_tex_desc.storage_mode = color_resolve_storage_mode;
color0_resolve_tex_desc.storage_mode =
color_attachment_config.resolve_storage_mode;
color0_resolve_tex_desc.format = context.GetColorAttachmentPixelFormat();
color0_resolve_tex_desc.size = size;
color0_resolve_tex_desc.usage =
Expand All @@ -298,39 +295,41 @@ RenderTarget RenderTarget::CreateOffscreenMSAA(

ColorAttachment color0;
color0.clear_color = Color::BlackTransparent();
color0.load_action = color_load_action;
color0.store_action = color_store_action;
color0.load_action = color_attachment_config.load_action;
color0.store_action = color_attachment_config.store_action;
color0.texture = color0_msaa_tex;
color0.resolve_texture = color0_resolve_tex;

target.SetColorAttachment(color0, 0u);

// 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 {};
if (stencil_attachment_config.has_value()) {
TextureDescriptor stencil_tex0;
stencil_tex0.storage_mode = stencil_attachment_config->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_attachment_config->load_action;
stencil0.store_action = stencil_attachment_config->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()));
target.SetStencilAttachment(std::move(stencil0));
} else {
target.SetStencilAttachment(std::nullopt);
}

stencil0.texture->SetLabel(SPrintF("%s Stencil Texture", label.c_str()));

RenderTarget target;
target.SetColorAttachment(color0, 0u);
target.SetStencilAttachment(std::move(stencil0));

return target;
}

Expand Down
Loading