Jonah Williams 01c2363b16 [Impeller] Cache render target texture allocations across frames. (flutter/engine#44527)
When allocating a non-host visible texture for a render target, the allocator will hold onto a reference to this texture descriptor. On the immediate next frame, this texture is made available to replace requested allocations for new render target textures. if this texture is not used, then at the end of the next frame it is discarded.

This removes the vast majority of allocations in most flutter gallery and wonderous. This does not attempt to use different sized textures for the cache.

There are two caveats noted in the PR contents.

Fixes https://github.com/flutter/flutter/issues/131515
2023-08-16 00:25:08 +00:00

46 lines
1.1 KiB
C++

// 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 "impeller/renderer/render_target.h"
namespace impeller {
/// @brief An implementation of the [RenderTargetAllocator] that caches all
/// allocated texture data for one frame.
///
/// Any textures unused after a frame are immediately discarded.
class RenderTargetCache : public RenderTargetAllocator {
public:
explicit RenderTargetCache(std::shared_ptr<Allocator> allocator);
~RenderTargetCache() = default;
// |RenderTargetAllocator|
void Start() override;
// |RenderTargetAllocator|
void End() override;
// |RenderTargetAllocator|
std::shared_ptr<Texture> CreateTexture(
const TextureDescriptor& desc) override;
// visible for testing.
size_t CachedTextureCount() const;
private:
struct TextureData {
bool used_this_frame;
std::shared_ptr<Texture> texture;
};
std::vector<TextureData> texture_data_;
FML_DISALLOW_COPY_AND_ASSIGN(RenderTargetCache);
};
} // namespace impeller