12 uint32_t keep_alive_frame_count)
14 keep_alive_frame_count_(keep_alive_frame_count) {}
17 cache_disabled_count_ = 0;
18 for (
auto& td : render_target_data_) {
19 td.used_this_frame =
false;
24 cache_disabled_count_ = 0;
25 std::vector<RenderTargetData> retain;
27 for (RenderTargetData& td : render_target_data_) {
28 if (td.used_this_frame) {
30 }
else if (td.keep_alive_frame_count > 0) {
31 td.keep_alive_frame_count--;
35 render_target_data_.swap(retain);
39 cache_disabled_count_++;
42 bool RenderTargetCache::CacheEnabled()
const {
43 return cache_disabled_count_ == 0;
47 FML_DCHECK(cache_disabled_count_ > 0);
48 if (cache_disabled_count_ == 0) {
51 cache_disabled_count_--;
58 std::string_view label,
60 std::optional<RenderTarget::AttachmentConfig> stencil_attachment_config,
61 const std::shared_ptr<Texture>& existing_color_texture,
62 const std::shared_ptr<Texture>& existing_depth_stencil_texture) {
67 FML_DCHECK(existing_color_texture ==
nullptr &&
68 existing_depth_stencil_texture ==
nullptr);
71 .mip_count =
static_cast<size_t>(mip_count),
73 .has_depth_stencil = stencil_attachment_config.has_value(),
77 for (RenderTargetData& render_target_data : render_target_data_) {
79 if (!render_target_data.used_this_frame && other_config == config) {
80 render_target_data.used_this_frame =
true;
81 render_target_data.keep_alive_frame_count = keep_alive_frame_count_;
83 render_target_data.render_target.GetColorAttachment(0);
84 std::optional<DepthAttachment> depth =
85 render_target_data.render_target.GetDepthAttachment();
86 std::shared_ptr<Texture> depth_tex = depth ? depth->
texture :
nullptr;
88 context, size, mip_count, label, color_attachment_config,
89 stencil_attachment_config, color0.
texture, depth_tex);
94 context, size, mip_count, label, color_attachment_config,
95 stencil_attachment_config);
96 if (!created_target.
IsValid()) {
97 return created_target;
99 render_target_data_.push_back(RenderTargetData{
100 .used_this_frame =
true,
101 .keep_alive_frame_count = keep_alive_frame_count_,
103 .render_target = created_target
105 return created_target;
112 std::string_view label,
114 std::optional<RenderTarget::AttachmentConfig> stencil_attachment_config,
115 const std::shared_ptr<Texture>& existing_color_msaa_texture,
116 const std::shared_ptr<Texture>& existing_color_resolve_texture,
117 const std::shared_ptr<Texture>& existing_depth_stencil_texture) {
122 FML_DCHECK(existing_color_msaa_texture ==
nullptr &&
123 existing_color_resolve_texture ==
nullptr &&
124 existing_depth_stencil_texture ==
nullptr);
127 .mip_count =
static_cast<size_t>(mip_count),
129 .has_depth_stencil = stencil_attachment_config.has_value(),
131 if (CacheEnabled()) {
132 for (RenderTargetData& render_target_data : render_target_data_) {
134 if (!render_target_data.used_this_frame && other_config == config) {
135 render_target_data.used_this_frame =
true;
136 render_target_data.keep_alive_frame_count = keep_alive_frame_count_;
138 render_target_data.render_target.GetColorAttachment(0);
139 std::optional<DepthAttachment> depth =
140 render_target_data.render_target.GetDepthAttachment();
141 std::shared_ptr<Texture> depth_tex = depth ? depth->
texture :
nullptr;
143 context, size, mip_count, label, color_attachment_config,
150 context, size, mip_count, label, color_attachment_config,
151 stencil_attachment_config);
152 if (!created_target.
IsValid()) {
153 return created_target;
155 render_target_data_.push_back(RenderTargetData{
156 .used_this_frame =
true,
157 .keep_alive_frame_count = keep_alive_frame_count_,
159 .render_target = created_target
161 return created_target;
165 return render_target_data_.size();
To do anything rendering related with Impeller, you need a context.
a wrapper around the impeller [Allocator] instance that can be used to provide caching of allocated r...
virtual RenderTarget CreateOffscreenMSAA(const Context &context, ISize size, int mip_count, std::string_view label="Offscreen MSAA", RenderTarget::AttachmentConfigMSAA color_attachment_config=RenderTarget::kDefaultColorAttachmentConfigMSAA, std::optional< RenderTarget::AttachmentConfig > stencil_attachment_config=RenderTarget::kDefaultStencilAttachmentConfig, const std::shared_ptr< Texture > &existing_color_msaa_texture=nullptr, const std::shared_ptr< Texture > &existing_color_resolve_texture=nullptr, const std::shared_ptr< Texture > &existing_depth_stencil_texture=nullptr)
virtual RenderTarget CreateOffscreen(const Context &context, ISize size, int mip_count, std::string_view label="Offscreen", RenderTarget::AttachmentConfig color_attachment_config=RenderTarget::kDefaultColorAttachmentConfig, std::optional< RenderTarget::AttachmentConfig > stencil_attachment_config=RenderTarget::kDefaultStencilAttachmentConfig, const std::shared_ptr< Texture > &existing_color_texture=nullptr, const std::shared_ptr< Texture > &existing_depth_stencil_texture=nullptr)
RenderTarget CreateOffscreen(const Context &context, ISize size, int mip_count, std::string_view label="Offscreen", RenderTarget::AttachmentConfig color_attachment_config=RenderTarget::kDefaultColorAttachmentConfig, std::optional< RenderTarget::AttachmentConfig > stencil_attachment_config=RenderTarget::kDefaultStencilAttachmentConfig, const std::shared_ptr< Texture > &existing_color_texture=nullptr, const std::shared_ptr< Texture > &existing_depth_stencil_texture=nullptr) override
size_t CachedTextureCount() const
void DisableCache() override
Disable any caching until the next call to EnabledCache.
void EnableCache() override
Re-enable any caching if disabled.
RenderTargetCache(std::shared_ptr< Allocator > allocator, uint32_t keep_alive_frame_count=4)
void End() override
Mark the end of a frame workload.
void Start() override
Mark the beginning of a frame workload.
RenderTarget CreateOffscreenMSAA(const Context &context, ISize size, int mip_count, std::string_view label="Offscreen MSAA", RenderTarget::AttachmentConfigMSAA color_attachment_config=RenderTarget::kDefaultColorAttachmentConfigMSAA, std::optional< RenderTarget::AttachmentConfig > stencil_attachment_config=RenderTarget::kDefaultStencilAttachmentConfig, const std::shared_ptr< Texture > &existing_color_msaa_texture=nullptr, const std::shared_ptr< Texture > &existing_color_resolve_texture=nullptr, const std::shared_ptr< Texture > &existing_depth_stencil_texture=nullptr) override
std::shared_ptr< Texture > resolve_texture
std::shared_ptr< Texture > texture
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.