[Impeller] exploit perfect hash for SamplerDescriptor. (flutter/engine#57036)

There are only 3 or 4 sampler's active at any given time in a flutter app. rather than store them in a hashmap, just use a vector.
This commit is contained in:
Jonah Williams 2024-12-12 14:00:17 -08:00 committed by GitHub
parent ad317842d3
commit fda902f593
58 changed files with 221 additions and 243 deletions

View File

@ -1390,7 +1390,7 @@ std::vector<Reflector::BindPrototype> Reflector::ReflectBindPrototypes(
.argument_name = "texture", .argument_name = "texture",
}); });
proto.args.push_back(BindPrototypeArgument{ proto.args.push_back(BindPrototypeArgument{
.type_name = "const std::unique_ptr<const Sampler>&", .type_name = "raw_ptr<const Sampler>",
.argument_name = "sampler", .argument_name = "sampler",
}); });
} }

View File

@ -412,7 +412,7 @@ struct Viewport {
/// @brief Describes how the texture should be sampled when the texture /// @brief Describes how the texture should be sampled when the texture
/// is being shrunk (minified) or expanded (magnified) to fit to /// is being shrunk (minified) or expanded (magnified) to fit to
/// the sample point. /// the sample point.
enum class MinMagFilter { enum class MinMagFilter : uint8_t {
/// Select nearest to the sample point. Most widely supported. /// Select nearest to the sample point. Most widely supported.
kNearest, kNearest,
@ -422,7 +422,7 @@ enum class MinMagFilter {
}; };
/// @brief Options for selecting and filtering between mipmap levels. /// @brief Options for selecting and filtering between mipmap levels.
enum class MipFilter { enum class MipFilter : uint8_t {
/// @brief The texture is sampled as if it only had a single mipmap level. /// @brief The texture is sampled as if it only had a single mipmap level.
/// ///
/// All samples are read from level 0. /// All samples are read from level 0.
@ -438,7 +438,7 @@ enum class MipFilter {
kLinear, kLinear,
}; };
enum class SamplerAddressMode { enum class SamplerAddressMode : uint8_t {
kClampToEdge, kClampToEdge,
kRepeat, kRepeat,
kMirror, kMirror,

View File

@ -9,6 +9,7 @@
#include "impeller/core/buffer_view.h" #include "impeller/core/buffer_view.h"
#include "impeller/core/formats.h" #include "impeller/core/formats.h"
#include "impeller/core/raw_ptr.h"
#include "impeller/core/sampler.h" #include "impeller/core/sampler.h"
#include "impeller/core/shader_types.h" #include "impeller/core/shader_types.h"
#include "impeller/core/texture.h" #include "impeller/core/texture.h"
@ -34,7 +35,7 @@ struct ResourceBinder {
const SampledImageSlot& slot, const SampledImageSlot& slot,
const ShaderMetadata* metadata, const ShaderMetadata* metadata,
std::shared_ptr<const Texture> texture, std::shared_ptr<const Texture> texture,
const std::unique_ptr<const Sampler>& sampler) = 0; raw_ptr<const Sampler>) = 0;
}; };
} // namespace impeller } // namespace impeller

View File

@ -6,7 +6,7 @@
namespace impeller { namespace impeller {
Sampler::Sampler(SamplerDescriptor desc) : desc_(std::move(desc)) {} Sampler::Sampler(const SamplerDescriptor& desc) : desc_(desc) {}
Sampler::~Sampler() = default; Sampler::~Sampler() = default;

View File

@ -5,9 +5,6 @@
#ifndef FLUTTER_IMPELLER_CORE_SAMPLER_H_ #ifndef FLUTTER_IMPELLER_CORE_SAMPLER_H_
#define FLUTTER_IMPELLER_CORE_SAMPLER_H_ #define FLUTTER_IMPELLER_CORE_SAMPLER_H_
#include <unordered_map>
#include "impeller/base/comparable.h"
#include "impeller/core/sampler_descriptor.h" #include "impeller/core/sampler_descriptor.h"
namespace impeller { namespace impeller {
@ -21,7 +18,7 @@ class Sampler {
protected: protected:
SamplerDescriptor desc_; SamplerDescriptor desc_;
explicit Sampler(SamplerDescriptor desc); explicit Sampler(const SamplerDescriptor& desc);
private: private:
Sampler(const Sampler&) = delete; Sampler(const Sampler&) = delete;
@ -29,11 +26,6 @@ class Sampler {
Sampler& operator=(const Sampler&) = delete; Sampler& operator=(const Sampler&) = delete;
}; };
using SamplerMap = std::unordered_map<SamplerDescriptor,
std::unique_ptr<const Sampler>,
ComparableHash<SamplerDescriptor>,
ComparableEqual<SamplerDescriptor>>;
} // namespace impeller } // namespace impeller
#endif // FLUTTER_IMPELLER_CORE_SAMPLER_H_ #endif // FLUTTER_IMPELLER_CORE_SAMPLER_H_

View File

@ -5,14 +5,13 @@
#ifndef FLUTTER_IMPELLER_CORE_SAMPLER_DESCRIPTOR_H_ #ifndef FLUTTER_IMPELLER_CORE_SAMPLER_DESCRIPTOR_H_
#define FLUTTER_IMPELLER_CORE_SAMPLER_DESCRIPTOR_H_ #define FLUTTER_IMPELLER_CORE_SAMPLER_DESCRIPTOR_H_
#include "impeller/base/comparable.h"
#include "impeller/core/formats.h" #include "impeller/core/formats.h"
namespace impeller { namespace impeller {
class Context; class Context;
struct SamplerDescriptor final : public Comparable<SamplerDescriptor> { struct SamplerDescriptor final {
MinMagFilter min_filter = MinMagFilter::kNearest; MinMagFilter min_filter = MinMagFilter::kNearest;
MinMagFilter mag_filter = MinMagFilter::kNearest; MinMagFilter mag_filter = MinMagFilter::kNearest;
MipFilter mip_filter = MipFilter::kNearest; MipFilter mip_filter = MipFilter::kNearest;
@ -30,20 +29,17 @@ struct SamplerDescriptor final : public Comparable<SamplerDescriptor> {
MinMagFilter mag_filter, MinMagFilter mag_filter,
MipFilter mip_filter); MipFilter mip_filter);
// Comparable<SamplerDescriptor> static uint64_t ToKey(const SamplerDescriptor& d) {
std::size_t GetHash() const override { static_assert(sizeof(MinMagFilter) == 1);
return fml::HashCombine(min_filter, mag_filter, mip_filter, static_assert(sizeof(MipFilter) == 1);
width_address_mode, height_address_mode, static_assert(sizeof(SamplerAddressMode) == 1);
depth_address_mode);
}
// Comparable<SamplerDescriptor> return static_cast<uint64_t>(d.min_filter) << 0 |
bool IsEqual(const SamplerDescriptor& o) const override { static_cast<uint64_t>(d.mag_filter) << 8 |
return min_filter == o.min_filter && mag_filter == o.mag_filter && static_cast<uint64_t>(d.mip_filter) << 16 |
mip_filter == o.mip_filter && static_cast<uint64_t>(d.width_address_mode) << 24 |
width_address_mode == o.width_address_mode && static_cast<uint64_t>(d.height_address_mode) << 32 |
height_address_mode == o.height_address_mode && static_cast<uint64_t>(d.depth_address_mode) << 40;
depth_address_mode == o.depth_address_mode;
} }
}; };

View File

@ -658,7 +658,7 @@ void Canvas::DrawPoints(const Point points[],
void Canvas::DrawImage(const std::shared_ptr<Texture>& image, void Canvas::DrawImage(const std::shared_ptr<Texture>& image,
Point offset, Point offset,
const Paint& paint, const Paint& paint,
SamplerDescriptor sampler) { const SamplerDescriptor& sampler) {
if (!image) { if (!image) {
return; return;
} }
@ -666,14 +666,14 @@ void Canvas::DrawImage(const std::shared_ptr<Texture>& image,
const auto source = Rect::MakeSize(image->GetSize()); const auto source = Rect::MakeSize(image->GetSize());
const auto dest = source.Shift(offset); const auto dest = source.Shift(offset);
DrawImageRect(image, source, dest, paint, std::move(sampler)); DrawImageRect(image, source, dest, paint, sampler);
} }
void Canvas::DrawImageRect(const std::shared_ptr<Texture>& image, void Canvas::DrawImageRect(const std::shared_ptr<Texture>& image,
Rect source, Rect source,
Rect dest, Rect dest,
const Paint& paint, const Paint& paint,
SamplerDescriptor sampler, const SamplerDescriptor& sampler,
SourceRectConstraint src_rect_constraint) { SourceRectConstraint src_rect_constraint) {
if (!image || source.IsEmpty() || dest.IsEmpty()) { if (!image || source.IsEmpty() || dest.IsEmpty()) {
return; return;
@ -704,7 +704,7 @@ void Canvas::DrawImageRect(const std::shared_ptr<Texture>& image,
texture_contents->SetSourceRect(*clipped_source); texture_contents->SetSourceRect(*clipped_source);
texture_contents->SetStrictSourceRect(src_rect_constraint == texture_contents->SetStrictSourceRect(src_rect_constraint ==
SourceRectConstraint::kStrict); SourceRectConstraint::kStrict);
texture_contents->SetSamplerDescriptor(std::move(sampler)); texture_contents->SetSamplerDescriptor(sampler);
texture_contents->SetOpacity(paint.color.alpha); texture_contents->SetOpacity(paint.color.alpha);
texture_contents->SetDeferApplyingOpacity(paint.HasColorFilter()); texture_contents->SetDeferApplyingOpacity(paint.HasColorFilter());

View File

@ -209,14 +209,14 @@ class Canvas {
void DrawImage(const std::shared_ptr<Texture>& image, void DrawImage(const std::shared_ptr<Texture>& image,
Point offset, Point offset,
const Paint& paint, const Paint& paint,
SamplerDescriptor sampler = {}); const SamplerDescriptor& sampler = {});
void DrawImageRect( void DrawImageRect(
const std::shared_ptr<Texture>& image, const std::shared_ptr<Texture>& image,
Rect source, Rect source,
Rect dest, Rect dest,
const Paint& paint, const Paint& paint,
SamplerDescriptor sampler = {}, const SamplerDescriptor& sampler = {},
SourceRectConstraint src_rect_constraint = SourceRectConstraint::kFast); SourceRectConstraint src_rect_constraint = SourceRectConstraint::kFast);
void DrawTextFrame(const std::shared_ptr<TextFrame>& text_frame, void DrawTextFrame(const std::shared_ptr<TextFrame>& text_frame,

View File

@ -47,7 +47,7 @@ bool AtlasContents::Render(const ContentContext& renderer,
dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal; dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal; dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
} }
const std::unique_ptr<const Sampler>& dst_sampler = raw_ptr<const Sampler> dst_sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler( renderer.GetContext()->GetSamplerLibrary()->GetSampler(
dst_sampler_descriptor); dst_sampler_descriptor);
@ -58,7 +58,7 @@ bool AtlasContents::Render(const ContentContext& renderer,
auto dst_sampler_descriptor = geometry_->GetSamplerDescriptor(); auto dst_sampler_descriptor = geometry_->GetSamplerDescriptor();
const std::unique_ptr<const Sampler>& dst_sampler = raw_ptr<const Sampler> dst_sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler( renderer.GetContext()->GetSamplerLibrary()->GetSampler(
dst_sampler_descriptor); dst_sampler_descriptor);

View File

@ -204,7 +204,7 @@ static std::optional<Entity> AdvancedBlend(
dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal; dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal; dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
} }
const std::unique_ptr<const Sampler>& dst_sampler = raw_ptr<const Sampler> dst_sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler( renderer.GetContext()->GetSamplerLibrary()->GetSampler(
dst_sampler_descriptor); dst_sampler_descriptor);
FS::BindTextureSamplerDst(pass, dst_snapshot->texture, dst_sampler); FS::BindTextureSamplerDst(pass, dst_snapshot->texture, dst_sampler);
@ -227,7 +227,7 @@ static std::optional<Entity> AdvancedBlend(
src_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal; src_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
src_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal; src_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
} }
const std::unique_ptr<const Sampler>& src_sampler = raw_ptr<const Sampler> src_sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler( renderer.GetContext()->GetSamplerLibrary()->GetSampler(
src_sampler_descriptor); src_sampler_descriptor);
blend_info.color_factor = 0; blend_info.color_factor = 0;
@ -377,7 +377,7 @@ std::optional<Entity> BlendFilterContents::CreateForegroundAdvancedBlend(
dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal; dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal; dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
} }
const std::unique_ptr<const Sampler>& dst_sampler = raw_ptr<const Sampler> dst_sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler( renderer.GetContext()->GetSamplerLibrary()->GetSampler(
dst_sampler_descriptor); dst_sampler_descriptor);
FS::BindTextureSamplerDst(pass, dst_snapshot->texture, dst_sampler); FS::BindTextureSamplerDst(pass, dst_snapshot->texture, dst_sampler);
@ -484,7 +484,7 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(
dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal; dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal; dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
} }
const std::unique_ptr<const Sampler>& dst_sampler = raw_ptr<const Sampler> dst_sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler( renderer.GetContext()->GetSamplerLibrary()->GetSampler(
dst_sampler_descriptor); dst_sampler_descriptor);
FS::BindTextureSamplerDst(pass, dst_snapshot->texture, dst_sampler); FS::BindTextureSamplerDst(pass, dst_snapshot->texture, dst_sampler);
@ -577,7 +577,7 @@ static std::optional<Entity> PipelineBlend(
return false; return false;
} }
const std::unique_ptr<const Sampler>& sampler = raw_ptr<const Sampler> sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler( renderer.GetContext()->GetSamplerLibrary()->GetSampler(
input->sampler_descriptor); input->sampler_descriptor);
FS::BindTextureSampler(pass, input->texture, sampler); FS::BindTextureSampler(pass, input->texture, sampler);
@ -853,7 +853,7 @@ std::optional<Entity> BlendFilterContents::CreateFramebufferAdvancedBlend(
src_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal; src_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
src_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal; src_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
} }
const std::unique_ptr<const Sampler>& src_sampler = raw_ptr<const Sampler> src_sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler( renderer.GetContext()->GetSamplerLibrary()->GetSampler(
src_sampler_descriptor); src_sampler_descriptor);
FS::BindTextureSamplerSrc(pass, src_texture, src_sampler); FS::BindTextureSamplerSrc(pass, src_texture, src_sampler);

View File

@ -122,7 +122,7 @@ std::optional<Entity> BorderMaskBlurFilterContents::RenderFilter(
FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info)); FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info)); VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
const std::unique_ptr<const Sampler>& sampler = raw_ptr<const Sampler> sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler({}); renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
FS::BindTextureSampler(pass, input_snapshot->texture, sampler); FS::BindTextureSampler(pass, input_snapshot->texture, sampler);

View File

@ -96,7 +96,7 @@ std::optional<Entity> ColorMatrixFilterContents::RenderFilter(
absorb_opacity == ColorFilterContents::AbsorbOpacity::kYes absorb_opacity == ColorFilterContents::AbsorbOpacity::kYes
? input_snapshot->opacity ? input_snapshot->opacity
: 1.0f; : 1.0f;
const std::unique_ptr<const Sampler>& sampler = raw_ptr<const Sampler> sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler({}); renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
FS::BindInputTexture(pass, input_snapshot->texture, sampler); FS::BindInputTexture(pass, input_snapshot->texture, sampler);
FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info)); FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));

View File

@ -20,8 +20,8 @@ void MatrixFilterContents::SetRenderingMode(
FilterContents::SetRenderingMode(rendering_mode); FilterContents::SetRenderingMode(rendering_mode);
} }
void MatrixFilterContents::SetSamplerDescriptor(SamplerDescriptor desc) { void MatrixFilterContents::SetSamplerDescriptor(const SamplerDescriptor& desc) {
sampler_descriptor_ = std::move(desc); sampler_descriptor_ = desc;
} }
namespace { namespace {

View File

@ -21,7 +21,7 @@ class MatrixFilterContents final : public FilterContents {
// |FilterContents| // |FilterContents|
void SetRenderingMode(Entity::RenderingMode rendering_mode) override; void SetRenderingMode(Entity::RenderingMode rendering_mode) override;
void SetSamplerDescriptor(SamplerDescriptor desc); void SetSamplerDescriptor(const SamplerDescriptor& desc);
// |FilterContents| // |FilterContents|
std::optional<Rect> GetFilterCoverage( std::optional<Rect> GetFilterCoverage(

View File

@ -77,7 +77,7 @@ std::optional<Entity> SrgbToLinearFilterContents::RenderFilter(
? input_snapshot->opacity ? input_snapshot->opacity
: 1.0f; : 1.0f;
const std::unique_ptr<const Sampler>& sampler = raw_ptr<const Sampler> sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler({}); renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
FS::BindInputTexture(pass, input_snapshot->texture, sampler); FS::BindInputTexture(pass, input_snapshot->texture, sampler);
FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info)); FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));

View File

@ -111,7 +111,7 @@ std::optional<Entity> YUVToRGBFilterContents::RenderFilter(
break; break;
} }
const std::unique_ptr<const Sampler>& sampler = raw_ptr<const Sampler> sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler({}); renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
FS::BindYTexture(pass, y_input_snapshot->texture, sampler); FS::BindYTexture(pass, y_input_snapshot->texture, sampler);
FS::BindUvTexture(pass, uv_input_snapshot->texture, sampler); FS::BindUvTexture(pass, uv_input_snapshot->texture, sampler);

View File

@ -128,7 +128,7 @@ bool FramebufferBlendContents::Render(const ContentContext& renderer,
src_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal; src_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
src_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal; src_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
} }
const std::unique_ptr<const Sampler>& src_sampler = raw_ptr<const Sampler> src_sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler( renderer.GetContext()->GetSamplerLibrary()->GetSampler(
src_sampler_descriptor); src_sampler_descriptor);
FS::BindTextureSamplerSrc(pass, src_snapshot->texture, src_sampler); FS::BindTextureSamplerSrc(pass, src_snapshot->texture, src_sampler);

View File

@ -301,7 +301,7 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
FML_DCHECK(sampler_index < texture_inputs_.size()); FML_DCHECK(sampler_index < texture_inputs_.size());
auto& input = texture_inputs_[sampler_index]; auto& input = texture_inputs_[sampler_index];
const std::unique_ptr<const Sampler>& sampler = raw_ptr<const Sampler> sampler =
context->GetSamplerLibrary()->GetSampler( context->GetSamplerLibrary()->GetSampler(
input.sampler_descriptor); input.sampler_descriptor);

View File

@ -135,7 +135,7 @@ bool RecordingRenderPass::BindDynamicResource(
const SampledImageSlot& slot, const SampledImageSlot& slot,
std::unique_ptr<ShaderMetadata> metadata, std::unique_ptr<ShaderMetadata> metadata,
std::shared_ptr<const Texture> texture, std::shared_ptr<const Texture> texture,
const std::unique_ptr<const Sampler>& sampler) { raw_ptr<const Sampler> sampler) {
if (delegate_) { if (delegate_) {
return delegate_->BindDynamicResource( return delegate_->BindDynamicResource(
stage, type, slot, std::move(metadata), texture, sampler); stage, type, slot, std::move(metadata), texture, sampler);
@ -143,13 +143,12 @@ bool RecordingRenderPass::BindDynamicResource(
return true; return true;
} }
bool RecordingRenderPass::BindResource( bool RecordingRenderPass::BindResource(ShaderStage stage,
ShaderStage stage, DescriptorType type,
DescriptorType type, const SampledImageSlot& slot,
const SampledImageSlot& slot, const ShaderMetadata* metadata,
const ShaderMetadata* metadata, std::shared_ptr<const Texture> texture,
std::shared_ptr<const Texture> texture, raw_ptr<const Sampler> sampler) {
const std::unique_ptr<const Sampler>& sampler) {
if (delegate_) { if (delegate_) {
return delegate_->BindResource(stage, type, slot, metadata, texture, return delegate_->BindResource(stage, type, slot, metadata, texture,
sampler); sampler);

View File

@ -56,7 +56,7 @@ class RecordingRenderPass : public RenderPass {
const SampledImageSlot& slot, const SampledImageSlot& slot,
const ShaderMetadata* metadata, const ShaderMetadata* metadata,
std::shared_ptr<const Texture> texture, std::shared_ptr<const Texture> texture,
const std::unique_ptr<const Sampler>& sampler) override; raw_ptr<const Sampler> sampler) override;
// |RenderPass| // |RenderPass|
bool BindDynamicResource(ShaderStage stage, bool BindDynamicResource(ShaderStage stage,
@ -66,13 +66,12 @@ class RecordingRenderPass : public RenderPass {
BufferView view) override; BufferView view) override;
// |RenderPass| // |RenderPass|
bool BindDynamicResource( bool BindDynamicResource(ShaderStage stage,
ShaderStage stage, DescriptorType type,
DescriptorType type, const SampledImageSlot& slot,
const SampledImageSlot& slot, std::unique_ptr<ShaderMetadata> metadata,
std::unique_ptr<ShaderMetadata> metadata, std::shared_ptr<const Texture> texture,
std::shared_ptr<const Texture> texture, raw_ptr<const Sampler> sampler) override;
const std::unique_ptr<const Sampler>& sampler) override;
// |RenderPass| // |RenderPass|
void OnSetLabel(std::string_view label) override; void OnSetLabel(std::string_view label) override;

View File

@ -240,8 +240,8 @@ bool TextureContents::GetStrictSourceRect() const {
return strict_source_rect_enabled_; return strict_source_rect_enabled_;
} }
void TextureContents::SetSamplerDescriptor(SamplerDescriptor desc) { void TextureContents::SetSamplerDescriptor(const SamplerDescriptor& desc) {
sampler_descriptor_ = std::move(desc); sampler_descriptor_ = desc;
} }
const SamplerDescriptor& TextureContents::GetSamplerDescriptor() const { const SamplerDescriptor& TextureContents::GetSamplerDescriptor() const {

View File

@ -33,7 +33,7 @@ class TextureContents final : public Contents {
std::shared_ptr<Texture> GetTexture() const; std::shared_ptr<Texture> GetTexture() const;
void SetSamplerDescriptor(SamplerDescriptor desc); void SetSamplerDescriptor(const SamplerDescriptor& desc);
const SamplerDescriptor& GetSamplerDescriptor() const; const SamplerDescriptor& GetSamplerDescriptor() const;

View File

@ -47,8 +47,8 @@ void TiledTextureContents::SetTileModes(Entity::TileMode x_tile_mode,
y_tile_mode_ = y_tile_mode; y_tile_mode_ = y_tile_mode;
} }
void TiledTextureContents::SetSamplerDescriptor(SamplerDescriptor desc) { void TiledTextureContents::SetSamplerDescriptor(const SamplerDescriptor& desc) {
sampler_descriptor_ = std::move(desc); sampler_descriptor_ = desc;
} }
void TiledTextureContents::SetColorFilter(ColorFilterProc color_filter) { void TiledTextureContents::SetColorFilter(ColorFilterProc color_filter) {

View File

@ -37,7 +37,7 @@ class TiledTextureContents final : public ColorSourceContents {
void SetTileModes(Entity::TileMode x_tile_mode, Entity::TileMode y_tile_mode); void SetTileModes(Entity::TileMode x_tile_mode, Entity::TileMode y_tile_mode);
void SetSamplerDescriptor(SamplerDescriptor desc); void SetSamplerDescriptor(const SamplerDescriptor& desc);
/// @brief Set a color filter to apply directly to this tiled texture /// @brief Set a color filter to apply directly to this tiled texture
/// @param color_filter /// @param color_filter

View File

@ -70,8 +70,8 @@ std::optional<Rect> VerticesSimpleBlendContents::GetCoverage(
} }
void VerticesSimpleBlendContents::SetSamplerDescriptor( void VerticesSimpleBlendContents::SetSamplerDescriptor(
SamplerDescriptor descriptor) { const SamplerDescriptor& descriptor) {
descriptor_ = std::move(descriptor); descriptor_ = descriptor;
} }
void VerticesSimpleBlendContents::SetTileMode(Entity::TileMode tile_mode_x, void VerticesSimpleBlendContents::SetTileMode(Entity::TileMode tile_mode_x,
@ -126,7 +126,7 @@ bool VerticesSimpleBlendContents::Render(const ContentContext& renderer,
TileModeToAddressMode(tile_mode_y_, renderer.GetDeviceCapabilities()) TileModeToAddressMode(tile_mode_y_, renderer.GetDeviceCapabilities())
.value_or(SamplerAddressMode::kClampToEdge); .value_or(SamplerAddressMode::kClampToEdge);
const std::unique_ptr<const Sampler>& dst_sampler = raw_ptr<const Sampler> dst_sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler( renderer.GetContext()->GetSamplerLibrary()->GetSampler(
dst_sampler_descriptor); dst_sampler_descriptor);

View File

@ -36,7 +36,7 @@ class VerticesSimpleBlendContents final : public Contents {
void SetLazyTexture(const LazyTexture& lazy_texture); void SetLazyTexture(const LazyTexture& lazy_texture);
void SetSamplerDescriptor(SamplerDescriptor descriptor); void SetSamplerDescriptor(const SamplerDescriptor& descriptor);
void SetTileMode(Entity::TileMode tile_mode_x, Entity::TileMode tile_mode_y); void SetTileMode(Entity::TileMode tile_mode_x, Entity::TileMode tile_mode_y);

View File

@ -38,13 +38,13 @@
struct ImGui_ImplImpeller_Data { struct ImGui_ImplImpeller_Data {
explicit ImGui_ImplImpeller_Data( explicit ImGui_ImplImpeller_Data(
const std::unique_ptr<const impeller::Sampler>& p_sampler) impeller::raw_ptr<const impeller::Sampler> p_sampler)
: sampler(p_sampler) {} : sampler(p_sampler) {}
std::shared_ptr<impeller::Context> context; std::shared_ptr<impeller::Context> context;
std::shared_ptr<impeller::Texture> font_texture; std::shared_ptr<impeller::Texture> font_texture;
std::shared_ptr<impeller::Pipeline<impeller::PipelineDescriptor>> pipeline; std::shared_ptr<impeller::Pipeline<impeller::PipelineDescriptor>> pipeline;
const std::unique_ptr<const impeller::Sampler>& sampler; impeller::raw_ptr<const impeller::Sampler> sampler;
}; };
static ImGui_ImplImpeller_Data* ImGui_ImplImpeller_GetBackendData() { static ImGui_ImplImpeller_Data* ImGui_ImplImpeller_GetBackendData() {

View File

@ -486,7 +486,7 @@ std::optional<size_t> BufferBindingsGLES::BindTextures(
/// If there is a sampler for the texture at the same index, configure the /// If there is a sampler for the texture at the same index, configure the
/// bound texture using that sampler. /// bound texture using that sampler.
/// ///
const auto& sampler_gles = SamplerGLES::Cast(**data.sampler); const auto& sampler_gles = SamplerGLES::Cast(*data.sampler);
if (!sampler_gles.ConfigureBoundTexture(texture_gles, gl)) { if (!sampler_gles.ConfigureBoundTexture(texture_gles, gl)) {
return std::nullopt; return std::nullopt;
} }

View File

@ -5,7 +5,6 @@
#ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_BUFFER_BINDINGS_GLES_H_ #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_BUFFER_BINDINGS_GLES_H_
#define FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_BUFFER_BINDINGS_GLES_H_ #define FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_BUFFER_BINDINGS_GLES_H_
#include <unordered_map>
#include <vector> #include <vector>
#include "flutter/third_party/abseil-cpp/absl/container/flat_hash_map.h" #include "flutter/third_party/abseil-cpp/absl/container/flat_hash_map.h"

View File

@ -6,13 +6,14 @@
#include "impeller/base/validation.h" #include "impeller/base/validation.h"
#include "impeller/core/formats.h" #include "impeller/core/formats.h"
#include "impeller/core/sampler_descriptor.h"
#include "impeller/renderer/backend/gles/formats_gles.h" #include "impeller/renderer/backend/gles/formats_gles.h"
#include "impeller/renderer/backend/gles/proc_table_gles.h" #include "impeller/renderer/backend/gles/proc_table_gles.h"
#include "impeller/renderer/backend/gles/texture_gles.h" #include "impeller/renderer/backend/gles/texture_gles.h"
namespace impeller { namespace impeller {
SamplerGLES::SamplerGLES(SamplerDescriptor desc) : Sampler(std::move(desc)) {} SamplerGLES::SamplerGLES(const SamplerDescriptor& desc) : Sampler(desc) {}
SamplerGLES::~SamplerGLES() = default; SamplerGLES::~SamplerGLES() = default;
@ -81,7 +82,7 @@ bool SamplerGLES::ConfigureBoundTexture(const TextureGLES& texture,
if (!target.has_value()) { if (!target.has_value()) {
return false; return false;
} }
const auto& desc = GetDescriptor(); const SamplerDescriptor& desc = GetDescriptor();
GLint mag_filter = ToParam(desc.mag_filter); GLint mag_filter = ToParam(desc.mag_filter);

View File

@ -25,7 +25,7 @@ class SamplerGLES final : public Sampler,
private: private:
friend class SamplerLibraryGLES; friend class SamplerLibraryGLES;
explicit SamplerGLES(SamplerDescriptor desc); explicit SamplerGLES(const SamplerDescriptor&);
SamplerGLES(const SamplerGLES&) = delete; SamplerGLES(const SamplerGLES&) = delete;

View File

@ -7,12 +7,11 @@
#include "impeller/base/config.h" #include "impeller/base/config.h"
#include "impeller/base/validation.h" #include "impeller/base/validation.h"
#include "impeller/core/formats.h" #include "impeller/core/formats.h"
#include "impeller/core/sampler_descriptor.h"
#include "impeller/renderer/backend/gles/sampler_gles.h" #include "impeller/renderer/backend/gles/sampler_gles.h"
namespace impeller { namespace impeller {
static const std::unique_ptr<const Sampler> kNullSampler = nullptr;
SamplerLibraryGLES::SamplerLibraryGLES(bool supports_decal_sampler_address_mode) SamplerLibraryGLES::SamplerLibraryGLES(bool supports_decal_sampler_address_mode)
: supports_decal_sampler_address_mode_( : supports_decal_sampler_address_mode_(
supports_decal_sampler_address_mode) {} supports_decal_sampler_address_mode) {}
@ -21,23 +20,27 @@ SamplerLibraryGLES::SamplerLibraryGLES(bool supports_decal_sampler_address_mode)
SamplerLibraryGLES::~SamplerLibraryGLES() = default; SamplerLibraryGLES::~SamplerLibraryGLES() = default;
// |SamplerLibrary| // |SamplerLibrary|
const std::unique_ptr<const Sampler>& SamplerLibraryGLES::GetSampler( raw_ptr<const Sampler> SamplerLibraryGLES::GetSampler(
SamplerDescriptor descriptor) { const SamplerDescriptor& descriptor) {
if (!supports_decal_sampler_address_mode_ && if (!supports_decal_sampler_address_mode_ &&
(descriptor.width_address_mode == SamplerAddressMode::kDecal || (descriptor.width_address_mode == SamplerAddressMode::kDecal ||
descriptor.height_address_mode == SamplerAddressMode::kDecal || descriptor.height_address_mode == SamplerAddressMode::kDecal ||
descriptor.depth_address_mode == SamplerAddressMode::kDecal)) { descriptor.depth_address_mode == SamplerAddressMode::kDecal)) {
VALIDATION_LOG << "SamplerAddressMode::kDecal is not supported by the " VALIDATION_LOG << "SamplerAddressMode::kDecal is not supported by the "
"current OpenGLES backend."; "current OpenGLES backend.";
return kNullSampler; return raw_ptr<const Sampler>{nullptr};
}
uint64_t p_key = SamplerDescriptor::ToKey(descriptor);
for (const auto& [key, value] : samplers_) {
if (key == p_key) {
return raw_ptr(value);
}
} }
auto found = samplers_.find(descriptor); auto sampler = std::unique_ptr<SamplerGLES>(new SamplerGLES(descriptor));
if (found != samplers_.end()) { samplers_.push_back(std::make_pair(p_key, std::move(sampler)));
return found->second;
} return raw_ptr(samplers_.back().second);
return (samplers_[descriptor] =
std::unique_ptr<SamplerGLES>(new SamplerGLES(descriptor)));
} }
} // namespace impeller } // namespace impeller

View File

@ -7,6 +7,7 @@
#include "impeller/core/sampler.h" #include "impeller/core/sampler.h"
#include "impeller/core/sampler_descriptor.h" #include "impeller/core/sampler_descriptor.h"
#include "impeller/renderer/backend/gles/sampler_gles.h"
#include "impeller/renderer/sampler_library.h" #include "impeller/renderer/sampler_library.h"
namespace impeller { namespace impeller {
@ -20,13 +21,13 @@ class SamplerLibraryGLES final : public SamplerLibrary {
private: private:
friend class ContextGLES; friend class ContextGLES;
SamplerMap samplers_; std::vector<std::pair<uint64_t, std::shared_ptr<const Sampler>>> samplers_;
SamplerLibraryGLES(); SamplerLibraryGLES();
// |SamplerLibrary| // |SamplerLibrary|
const std::unique_ptr<const Sampler>& GetSampler( raw_ptr<const Sampler> GetSampler(
SamplerDescriptor descriptor) override; const SamplerDescriptor& descriptor) override;
bool supports_decal_sampler_address_mode_ = false; bool supports_decal_sampler_address_mode_ = false;

View File

@ -60,7 +60,7 @@ class ComputePassMTL final : public ComputePass {
const SampledImageSlot& slot, const SampledImageSlot& slot,
const ShaderMetadata* metadata, const ShaderMetadata* metadata,
std::shared_ptr<const Texture> texture, std::shared_ptr<const Texture> texture,
const std::unique_ptr<const Sampler>& sampler) override; raw_ptr<const Sampler> sampler) override;
// |ComputePass| // |ComputePass|
bool EncodeCommands() const override; bool EncodeCommands() const override;

View File

@ -105,13 +105,12 @@ bool ComputePassMTL::BindResource(ShaderStage stage,
} }
// |ComputePass| // |ComputePass|
bool ComputePassMTL::BindResource( bool ComputePassMTL::BindResource(ShaderStage stage,
ShaderStage stage, DescriptorType type,
DescriptorType type, const SampledImageSlot& slot,
const SampledImageSlot& slot, const ShaderMetadata* metadata,
const ShaderMetadata* metadata, std::shared_ptr<const Texture> texture,
std::shared_ptr<const Texture> texture, raw_ptr<const Sampler> sampler) {
const std::unique_ptr<const Sampler>& sampler) {
if (!sampler || !texture->IsValid()) { if (!sampler || !texture->IsValid()) {
return false; return false;
} }

View File

@ -104,7 +104,7 @@ class RenderPassMTL final : public RenderPass {
const SampledImageSlot& slot, const SampledImageSlot& slot,
const ShaderMetadata* metadata, const ShaderMetadata* metadata,
std::shared_ptr<const Texture> texture, std::shared_ptr<const Texture> texture,
const std::unique_ptr<const Sampler>& sampler) override; raw_ptr<const Sampler> sampler) override;
// |RenderPass| // |RenderPass|
bool BindDynamicResource(ShaderStage stage, bool BindDynamicResource(ShaderStage stage,
@ -114,13 +114,12 @@ class RenderPassMTL final : public RenderPass {
BufferView view) override; BufferView view) override;
// |RenderPass| // |RenderPass|
bool BindDynamicResource( bool BindDynamicResource(ShaderStage stage,
ShaderStage stage, DescriptorType type,
DescriptorType type, const SampledImageSlot& slot,
const SampledImageSlot& slot, std::unique_ptr<ShaderMetadata> metadata,
std::unique_ptr<ShaderMetadata> metadata, std::shared_ptr<const Texture> texture,
std::shared_ptr<const Texture> texture, raw_ptr<const Sampler> sampler) override;
const std::unique_ptr<const Sampler>& sampler) override;
RenderPassMTL(const RenderPassMTL&) = delete; RenderPassMTL(const RenderPassMTL&) = delete;

View File

@ -210,7 +210,7 @@ static bool Bind(PassBindingsCacheMTL& pass,
static bool Bind(PassBindingsCacheMTL& pass, static bool Bind(PassBindingsCacheMTL& pass,
ShaderStage stage, ShaderStage stage,
size_t bind_index, size_t bind_index,
const std::unique_ptr<const Sampler>& sampler, raw_ptr<const Sampler> sampler,
const Texture& texture) { const Texture& texture) {
if (!sampler || !texture.IsValid()) { if (!sampler || !texture.IsValid()) {
return false; return false;
@ -400,13 +400,12 @@ bool RenderPassMTL::BindDynamicResource(
} }
// |RenderPass| // |RenderPass|
bool RenderPassMTL::BindResource( bool RenderPassMTL::BindResource(ShaderStage stage,
ShaderStage stage, DescriptorType type,
DescriptorType type, const SampledImageSlot& slot,
const SampledImageSlot& slot, const ShaderMetadata* metadata,
const ShaderMetadata* metadata, std::shared_ptr<const Texture> texture,
std::shared_ptr<const Texture> texture, raw_ptr<const Sampler> sampler) {
const std::unique_ptr<const Sampler>& sampler) {
if (!texture) { if (!texture) {
return false; return false;
} }
@ -419,7 +418,7 @@ bool RenderPassMTL::BindDynamicResource(
const SampledImageSlot& slot, const SampledImageSlot& slot,
std::unique_ptr<ShaderMetadata> metadata, std::unique_ptr<ShaderMetadata> metadata,
std::shared_ptr<const Texture> texture, std::shared_ptr<const Texture> texture,
const std::unique_ptr<const Sampler>& sampler) { raw_ptr<const Sampler> sampler) {
if (!texture) { if (!texture) {
return false; return false;
} }

View File

@ -27,13 +27,13 @@ class SamplerLibraryMTL final
friend class ContextMTL; friend class ContextMTL;
id<MTLDevice> device_ = nullptr; id<MTLDevice> device_ = nullptr;
SamplerMap samplers_; std::vector<std::pair<uint64_t, std::shared_ptr<const Sampler>>> samplers_;
explicit SamplerLibraryMTL(id<MTLDevice> device); explicit SamplerLibraryMTL(id<MTLDevice> device);
// |SamplerLibrary| // |SamplerLibrary|
const std::unique_ptr<const Sampler>& GetSampler( raw_ptr<const Sampler> GetSampler(
SamplerDescriptor descriptor) override; const SamplerDescriptor& descriptor) override;
SamplerLibraryMTL(const SamplerLibraryMTL&) = delete; SamplerLibraryMTL(const SamplerLibraryMTL&) = delete;

View File

@ -13,16 +13,16 @@ SamplerLibraryMTL::SamplerLibraryMTL(id<MTLDevice> device) : device_(device) {}
SamplerLibraryMTL::~SamplerLibraryMTL() = default; SamplerLibraryMTL::~SamplerLibraryMTL() = default;
static const std::unique_ptr<const Sampler> kNullSampler = nullptr; raw_ptr<const Sampler> SamplerLibraryMTL::GetSampler(
const SamplerDescriptor& descriptor) {
const std::unique_ptr<const Sampler>& SamplerLibraryMTL::GetSampler( uint64_t p_key = SamplerDescriptor::ToKey(descriptor);
SamplerDescriptor descriptor) { for (const auto& [key, value] : samplers_) {
auto found = samplers_.find(descriptor); if (key == p_key) {
if (found != samplers_.end()) { return raw_ptr(value);
return found->second; }
} }
if (!device_) { if (!device_) {
return kNullSampler; return raw_ptr<const Sampler>(nullptr);
} }
auto desc = [[MTLSamplerDescriptor alloc] init]; auto desc = [[MTLSamplerDescriptor alloc] init];
desc.minFilter = ToMTLSamplerMinMagFilter(descriptor.min_filter); desc.minFilter = ToMTLSamplerMinMagFilter(descriptor.min_filter);
@ -42,12 +42,13 @@ const std::unique_ptr<const Sampler>& SamplerLibraryMTL::GetSampler(
auto mtl_sampler = [device_ newSamplerStateWithDescriptor:desc]; auto mtl_sampler = [device_ newSamplerStateWithDescriptor:desc];
if (!mtl_sampler) { if (!mtl_sampler) {
return kNullSampler; return raw_ptr<const Sampler>(nullptr);
;
} }
auto sampler = auto sampler =
std::unique_ptr<SamplerMTL>(new SamplerMTL(descriptor, mtl_sampler)); std::shared_ptr<SamplerMTL>(new SamplerMTL(descriptor, mtl_sampler));
samplers_.push_back(std::make_pair(p_key, std::move(sampler)));
return (samplers_[descriptor] = std::move(sampler)); return raw_ptr(samplers_.back().second);
} }
} // namespace impeller } // namespace impeller

View File

@ -29,7 +29,7 @@ class SamplerMTL final : public Sampler,
id<MTLSamplerState> state_ = nullptr; id<MTLSamplerState> state_ = nullptr;
SamplerMTL(SamplerDescriptor desc, id<MTLSamplerState> state); SamplerMTL(const SamplerDescriptor& desc, id<MTLSamplerState> state);
SamplerMTL(const SamplerMTL&) = delete; SamplerMTL(const SamplerMTL&) = delete;

View File

@ -6,8 +6,8 @@
namespace impeller { namespace impeller {
SamplerMTL::SamplerMTL(SamplerDescriptor desc, id<MTLSamplerState> state) SamplerMTL::SamplerMTL(const SamplerDescriptor& desc, id<MTLSamplerState> state)
: Sampler(std::move(desc)), state_(state) { : Sampler(desc), state_(state) {
FML_DCHECK(state_); FML_DCHECK(state_);
} }

View File

@ -140,13 +140,12 @@ bool ComputePassVK::BindResource(ShaderStage stage,
} }
// |ResourceBinder| // |ResourceBinder|
bool ComputePassVK::BindResource( bool ComputePassVK::BindResource(ShaderStage stage,
ShaderStage stage, DescriptorType type,
DescriptorType type, const SampledImageSlot& slot,
const SampledImageSlot& slot, const ShaderMetadata* metadata,
const ShaderMetadata* metadata, std::shared_ptr<const Texture> texture,
std::shared_ptr<const Texture> texture, raw_ptr<const Sampler> sampler) {
const std::unique_ptr<const Sampler>& sampler) {
if (bound_image_offset_ >= kMaxBindings) { if (bound_image_offset_ >= kMaxBindings) {
return false; return false;
} }

View File

@ -80,7 +80,7 @@ class ComputePassVK final : public ComputePass {
const SampledImageSlot& slot, const SampledImageSlot& slot,
const ShaderMetadata* metadata, const ShaderMetadata* metadata,
std::shared_ptr<const Texture> texture, std::shared_ptr<const Texture> texture,
const std::unique_ptr<const Sampler>& sampler) override; raw_ptr<const Sampler> sampler) override;
bool BindResource(size_t binding, DescriptorType type, BufferView view); bool BindResource(size_t binding, DescriptorType type, BufferView view);
}; };

View File

@ -601,13 +601,12 @@ bool RenderPassVK::BindResource(size_t binding,
return true; return true;
} }
bool RenderPassVK::BindDynamicResource( bool RenderPassVK::BindDynamicResource(ShaderStage stage,
ShaderStage stage, DescriptorType type,
DescriptorType type, const SampledImageSlot& slot,
const SampledImageSlot& slot, std::unique_ptr<ShaderMetadata> metadata,
std::unique_ptr<ShaderMetadata> metadata, std::shared_ptr<const Texture> texture,
std::shared_ptr<const Texture> texture, raw_ptr<const Sampler> sampler) {
const std::unique_ptr<const Sampler>& sampler) {
return BindResource(stage, type, slot, nullptr, texture, sampler); return BindResource(stage, type, slot, nullptr, texture, sampler);
} }
@ -616,7 +615,7 @@ bool RenderPassVK::BindResource(ShaderStage stage,
const SampledImageSlot& slot, const SampledImageSlot& slot,
const ShaderMetadata* metadata, const ShaderMetadata* metadata,
std::shared_ptr<const Texture> texture, std::shared_ptr<const Texture> texture,
const std::unique_ptr<const Sampler>& sampler) { raw_ptr<const Sampler> sampler) {
if (bound_buffer_offset_ >= kMaxBindings) { if (bound_buffer_offset_ >= kMaxBindings) {
return false; return false;
} }

View File

@ -104,7 +104,7 @@ class RenderPassVK final : public RenderPass {
const SampledImageSlot& slot, const SampledImageSlot& slot,
const ShaderMetadata* metadata, const ShaderMetadata* metadata,
std::shared_ptr<const Texture> texture, std::shared_ptr<const Texture> texture,
const std::unique_ptr<const Sampler>& sampler) override; raw_ptr<const Sampler> sampler) override;
// |RenderPass| // |RenderPass|
bool BindDynamicResource(ShaderStage stage, bool BindDynamicResource(ShaderStage stage,
@ -114,13 +114,12 @@ class RenderPassVK final : public RenderPass {
BufferView view) override; BufferView view) override;
// |RenderPass| // |RenderPass|
bool BindDynamicResource( bool BindDynamicResource(ShaderStage stage,
ShaderStage stage, DescriptorType type,
DescriptorType type, const SampledImageSlot& slot,
const SampledImageSlot& slot, std::unique_ptr<ShaderMetadata> metadata,
std::unique_ptr<ShaderMetadata> metadata, std::shared_ptr<const Texture> texture,
std::shared_ptr<const Texture> texture, raw_ptr<const Sampler> sampler) override;
const std::unique_ptr<const Sampler>& sampler) override;
bool BindResource(size_t binding, DescriptorType type, BufferView view); bool BindResource(size_t binding, DescriptorType type, BufferView view);

View File

@ -4,8 +4,6 @@
#include "impeller/renderer/backend/vulkan/sampler_library_vk.h" #include "impeller/renderer/backend/vulkan/sampler_library_vk.h"
#include "impeller/renderer/backend/vulkan/context_vk.h"
#include "impeller/renderer/backend/vulkan/formats_vk.h"
#include "impeller/renderer/backend/vulkan/sampler_vk.h" #include "impeller/renderer/backend/vulkan/sampler_vk.h"
namespace impeller { namespace impeller {
@ -16,20 +14,21 @@ SamplerLibraryVK::SamplerLibraryVK(
SamplerLibraryVK::~SamplerLibraryVK() = default; SamplerLibraryVK::~SamplerLibraryVK() = default;
static const std::unique_ptr<const Sampler> kNullSampler = nullptr; raw_ptr<const Sampler> SamplerLibraryVK::GetSampler(
const SamplerDescriptor& desc) {
const std::unique_ptr<const Sampler>& SamplerLibraryVK::GetSampler( uint64_t p_key = SamplerDescriptor::ToKey(desc);
SamplerDescriptor desc) { for (const auto& [key, value] : samplers_) {
auto found = samplers_.find(desc); if (key == p_key) {
if (found != samplers_.end()) { return raw_ptr(value);
return found->second; }
} }
auto device_holder = device_holder_.lock(); auto device_holder = device_holder_.lock();
if (!device_holder || !device_holder->GetDevice()) { if (!device_holder || !device_holder->GetDevice()) {
return kNullSampler; return raw_ptr<const Sampler>(nullptr);
} }
return (samplers_[desc] = samplers_.push_back(std::make_pair(
std::make_unique<SamplerVK>(device_holder->GetDevice(), desc)); p_key, std::make_shared<SamplerVK>(device_holder->GetDevice(), desc)));
return raw_ptr(samplers_.back().second);
} }
} // namespace impeller } // namespace impeller

View File

@ -6,6 +6,7 @@
#define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SAMPLER_LIBRARY_VK_H_ #define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SAMPLER_LIBRARY_VK_H_
#include "impeller/base/backend_cast.h" #include "impeller/base/backend_cast.h"
#include "impeller/core/sampler.h"
#include "impeller/core/sampler_descriptor.h" #include "impeller/core/sampler_descriptor.h"
#include "impeller/renderer/backend/vulkan/device_holder_vk.h" #include "impeller/renderer/backend/vulkan/device_holder_vk.h"
#include "impeller/renderer/sampler_library.h" #include "impeller/renderer/sampler_library.h"
@ -23,13 +24,13 @@ class SamplerLibraryVK final
friend class ContextVK; friend class ContextVK;
std::weak_ptr<DeviceHolderVK> device_holder_; std::weak_ptr<DeviceHolderVK> device_holder_;
SamplerMap samplers_; std::vector<std::pair<uint64_t, std::shared_ptr<const Sampler>>> samplers_;
explicit SamplerLibraryVK(const std::weak_ptr<DeviceHolderVK>& device_holder); explicit SamplerLibraryVK(const std::weak_ptr<DeviceHolderVK>& device_holder);
// |SamplerLibrary| // |SamplerLibrary|
const std::unique_ptr<const Sampler>& GetSampler( raw_ptr<const Sampler> GetSampler(
SamplerDescriptor descriptor) override; const SamplerDescriptor& descriptor) override;
SamplerLibraryVK(const SamplerLibraryVK&) = delete; SamplerLibraryVK(const SamplerLibraryVK&) = delete;

View File

@ -99,9 +99,9 @@ static vk::UniqueSampler CreateSampler(
} }
SamplerVK::SamplerVK(const vk::Device& device, SamplerVK::SamplerVK(const vk::Device& device,
SamplerDescriptor desc, const SamplerDescriptor& desc,
std::shared_ptr<YUVConversionVK> yuv_conversion) std::shared_ptr<YUVConversionVK> yuv_conversion)
: Sampler(std::move(desc)), : Sampler(desc),
device_(device), device_(device),
sampler_(MakeSharedVK<vk::Sampler>( sampler_(MakeSharedVK<vk::Sampler>(
CreateSampler(device, desc_, yuv_conversion))), CreateSampler(device, desc_, yuv_conversion))),

View File

@ -18,7 +18,7 @@ class YUVConversionVK;
class SamplerVK final : public Sampler, public BackendCast<SamplerVK, Sampler> { class SamplerVK final : public Sampler, public BackendCast<SamplerVK, Sampler> {
public: public:
SamplerVK(const vk::Device& device, SamplerVK(const vk::Device& device,
SamplerDescriptor desc, const SamplerDescriptor&,
std::shared_ptr<YUVConversionVK> yuv_conversion = {}); std::shared_ptr<YUVConversionVK> yuv_conversion = {});
// |Sampler| // |Sampler|

View File

@ -227,7 +227,7 @@ std::shared_ptr<SamplerVK> TextureVK::GetImmutableSamplerVariant(
if (!source_) { if (!source_) {
return nullptr; return nullptr;
} }
auto conversion = source_->GetYUVConversion(); std::shared_ptr<YUVConversionVK> conversion = source_->GetYUVConversion();
if (!conversion) { if (!conversion) {
// Most textures don't need a sampler conversion and will go down this path. // Most textures don't need a sampler conversion and will go down this path.
// Only needed for YUV sampling from external textures. // Only needed for YUV sampling from external textures.

View File

@ -6,6 +6,7 @@
#include "flutter/fml/hash_combine.h" #include "flutter/fml/hash_combine.h"
#include "impeller/base/validation.h" #include "impeller/base/validation.h"
#include "impeller/core/sampler_descriptor.h"
#include "impeller/renderer/backend/vulkan/device_holder_vk.h" #include "impeller/renderer/backend/vulkan/device_holder_vk.h"
#include "impeller/renderer/backend/vulkan/sampler_vk.h" #include "impeller/renderer/backend/vulkan/sampler_vk.h"
@ -107,12 +108,13 @@ ImmutableSamplerKeyVK::ImmutableSamplerKeyVK(const SamplerVK& sampler)
} }
bool ImmutableSamplerKeyVK::IsEqual(const ImmutableSamplerKeyVK& other) const { bool ImmutableSamplerKeyVK::IsEqual(const ImmutableSamplerKeyVK& other) const {
return sampler.IsEqual(other.sampler) && return SamplerDescriptor::ToKey(sampler) ==
SamplerDescriptor::ToKey(other.sampler) &&
YUVConversionDescriptorVKEqual{}(yuv_conversion, other.yuv_conversion); YUVConversionDescriptorVKEqual{}(yuv_conversion, other.yuv_conversion);
} }
std::size_t ImmutableSamplerKeyVK::GetHash() const { std::size_t ImmutableSamplerKeyVK::GetHash() const {
return fml::HashCombine(sampler.GetHash(), return fml::HashCombine(SamplerDescriptor::ToKey(sampler),
YUVConversionDescriptorVKHash{}(yuv_conversion)); YUVConversionDescriptorVKHash{}(yuv_conversion));
} }

View File

@ -59,7 +59,7 @@ struct TextureAndSampler {
SampledImageSlot slot; SampledImageSlot slot;
ShaderStage stage; ShaderStage stage;
TextureResource texture; TextureResource texture;
const std::unique_ptr<const Sampler>* sampler; raw_ptr<const Sampler> sampler;
}; };
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

View File

@ -237,7 +237,7 @@ bool RenderPass::BindResource(ShaderStage stage,
const SampledImageSlot& slot, const SampledImageSlot& slot,
const ShaderMetadata* metadata, const ShaderMetadata* metadata,
std::shared_ptr<const Texture> texture, std::shared_ptr<const Texture> texture,
const std::unique_ptr<const Sampler>& sampler) { raw_ptr<const Sampler> sampler) {
if (!sampler) { if (!sampler) {
return false; return false;
} }
@ -263,13 +263,12 @@ bool RenderPass::BindDynamicResource(ShaderStage stage,
return BindBuffer(stage, slot, std::move(resouce)); return BindBuffer(stage, slot, std::move(resouce));
} }
bool RenderPass::BindDynamicResource( bool RenderPass::BindDynamicResource(ShaderStage stage,
ShaderStage stage, DescriptorType type,
DescriptorType type, const SampledImageSlot& slot,
const SampledImageSlot& slot, std::unique_ptr<ShaderMetadata> metadata,
std::unique_ptr<ShaderMetadata> metadata, std::shared_ptr<const Texture> texture,
std::shared_ptr<const Texture> texture, raw_ptr<const Sampler> sampler) {
const std::unique_ptr<const Sampler>& sampler) {
if (!sampler) { if (!sampler) {
return false; return false;
} }
@ -296,11 +295,11 @@ bool RenderPass::BindBuffer(ShaderStage stage,
bool RenderPass::BindTexture(ShaderStage stage, bool RenderPass::BindTexture(ShaderStage stage,
const SampledImageSlot& slot, const SampledImageSlot& slot,
TextureResource resource, TextureResource resource,
const std::unique_ptr<const Sampler>& sampler) { raw_ptr<const Sampler> sampler) {
TextureAndSampler data = TextureAndSampler{ TextureAndSampler data = TextureAndSampler{
.stage = stage, .stage = stage,
.texture = std::move(resource), .texture = std::move(resource),
.sampler = &sampler, .sampler = sampler,
}; };
if (!bound_textures_start_.has_value()) { if (!bound_textures_start_.has_value()) {

View File

@ -179,22 +179,20 @@ class RenderPass : public ResourceBinder {
BufferView view) override; BufferView view) override;
// |ResourceBinder| // |ResourceBinder|
virtual bool BindResource( virtual bool BindResource(ShaderStage stage,
ShaderStage stage, DescriptorType type,
DescriptorType type, const SampledImageSlot& slot,
const SampledImageSlot& slot, const ShaderMetadata* metadata,
const ShaderMetadata* metadata, std::shared_ptr<const Texture> texture,
std::shared_ptr<const Texture> texture, raw_ptr<const Sampler>) override;
const std::unique_ptr<const Sampler>& sampler) override;
/// @brief Bind with dynamically generated shader metadata. /// @brief Bind with dynamically generated shader metadata.
virtual bool BindDynamicResource( virtual bool BindDynamicResource(ShaderStage stage,
ShaderStage stage, DescriptorType type,
DescriptorType type, const SampledImageSlot& slot,
const SampledImageSlot& slot, std::unique_ptr<ShaderMetadata> metadata,
std::unique_ptr<ShaderMetadata> metadata, std::shared_ptr<const Texture> texture,
std::shared_ptr<const Texture> texture, raw_ptr<const Sampler>);
const std::unique_ptr<const Sampler>& sampler);
/// @brief Bind with dynamically generated shader metadata. /// @brief Bind with dynamically generated shader metadata.
virtual bool BindDynamicResource(ShaderStage stage, virtual bool BindDynamicResource(ShaderStage stage,
@ -289,7 +287,7 @@ class RenderPass : public ResourceBinder {
bool BindTexture(ShaderStage stage, bool BindTexture(ShaderStage stage,
const SampledImageSlot& slot, const SampledImageSlot& slot,
TextureResource resource, TextureResource resource,
const std::unique_ptr<const Sampler>& sampler); raw_ptr<const Sampler>);
Command pending_; Command pending_;
std::optional<size_t> bound_buffers_start_ = std::nullopt; std::optional<size_t> bound_buffers_start_ = std::nullopt;

View File

@ -75,8 +75,7 @@ TEST_P(RendererTest, CanCreateBoxPrimitive) {
auto bridge = CreateTextureForFixture("bay_bridge.jpg"); auto bridge = CreateTextureForFixture("bay_bridge.jpg");
auto boston = CreateTextureForFixture("boston.jpg"); auto boston = CreateTextureForFixture("boston.jpg");
ASSERT_TRUE(bridge && boston); ASSERT_TRUE(bridge && boston);
const std::unique_ptr<const Sampler>& sampler = raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
context->GetSamplerLibrary()->GetSampler({});
ASSERT_TRUE(sampler); ASSERT_TRUE(sampler);
auto host_buffer = HostBuffer::Create(context->GetResourceAllocator(), auto host_buffer = HostBuffer::Create(context->GetResourceAllocator(),
@ -238,8 +237,7 @@ TEST_P(RendererTest, CanRenderPerspectiveCube) {
auto device_buffer = context->GetResourceAllocator()->CreateBufferWithCopy( auto device_buffer = context->GetResourceAllocator()->CreateBufferWithCopy(
reinterpret_cast<uint8_t*>(&cube), sizeof(cube)); reinterpret_cast<uint8_t*>(&cube), sizeof(cube));
const std::unique_ptr<const Sampler>& sampler = raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
context->GetSamplerLibrary()->GetSampler({});
ASSERT_TRUE(sampler); ASSERT_TRUE(sampler);
Vector3 euler_angles; Vector3 euler_angles;
@ -320,8 +318,7 @@ TEST_P(RendererTest, CanRenderMultiplePrimitives) {
auto bridge = CreateTextureForFixture("bay_bridge.jpg"); auto bridge = CreateTextureForFixture("bay_bridge.jpg");
auto boston = CreateTextureForFixture("boston.jpg"); auto boston = CreateTextureForFixture("boston.jpg");
ASSERT_TRUE(bridge && boston); ASSERT_TRUE(bridge && boston);
const std::unique_ptr<const Sampler>& sampler = raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
context->GetSamplerLibrary()->GetSampler({});
ASSERT_TRUE(sampler); ASSERT_TRUE(sampler);
auto host_buffer = HostBuffer::Create(context->GetResourceAllocator(), auto host_buffer = HostBuffer::Create(context->GetResourceAllocator(),
@ -398,8 +395,7 @@ TEST_P(RendererTest, CanRenderToTexture) {
auto bridge = CreateTextureForFixture("bay_bridge.jpg"); auto bridge = CreateTextureForFixture("bay_bridge.jpg");
auto boston = CreateTextureForFixture("boston.jpg"); auto boston = CreateTextureForFixture("boston.jpg");
ASSERT_TRUE(bridge && boston); ASSERT_TRUE(bridge && boston);
const std::unique_ptr<const Sampler>& sampler = raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
context->GetSamplerLibrary()->GetSampler({});
ASSERT_TRUE(sampler); ASSERT_TRUE(sampler);
std::shared_ptr<RenderPass> r2t_pass; std::shared_ptr<RenderPass> r2t_pass;
@ -553,8 +549,7 @@ TEST_P(RendererTest, CanBlitTextureToTexture) {
auto bridge = CreateTextureForFixture("bay_bridge.jpg"); auto bridge = CreateTextureForFixture("bay_bridge.jpg");
auto boston = CreateTextureForFixture("boston.jpg"); auto boston = CreateTextureForFixture("boston.jpg");
ASSERT_TRUE(bridge && boston); ASSERT_TRUE(bridge && boston);
const std::unique_ptr<const Sampler>& sampler = raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
context->GetSamplerLibrary()->GetSampler({});
ASSERT_TRUE(sampler); ASSERT_TRUE(sampler);
// Vertex buffer. // Vertex buffer.
@ -619,7 +614,7 @@ TEST_P(RendererTest, CanBlitTextureToTexture) {
frag_info.lod = 0; frag_info.lod = 0;
FS::BindFragInfo(*pass, host_buffer->EmplaceUniform(frag_info)); FS::BindFragInfo(*pass, host_buffer->EmplaceUniform(frag_info));
auto& sampler = context->GetSamplerLibrary()->GetSampler({}); auto sampler = context->GetSamplerLibrary()->GetSampler({});
FS::BindTex(*pass, texture, sampler); FS::BindTex(*pass, texture, sampler);
pass->Draw(); pass->Draw();
@ -656,8 +651,7 @@ TEST_P(RendererTest, CanBlitTextureToBuffer) {
auto bridge = CreateTextureForFixture("bay_bridge.jpg"); auto bridge = CreateTextureForFixture("bay_bridge.jpg");
auto boston = CreateTextureForFixture("boston.jpg"); auto boston = CreateTextureForFixture("boston.jpg");
ASSERT_TRUE(bridge && boston); ASSERT_TRUE(bridge && boston);
const std::unique_ptr<const Sampler>& sampler = raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
context->GetSamplerLibrary()->GetSampler({});
ASSERT_TRUE(sampler); ASSERT_TRUE(sampler);
TextureDescriptor texture_desc; TextureDescriptor texture_desc;
@ -742,7 +736,7 @@ TEST_P(RendererTest, CanBlitTextureToBuffer) {
frag_info.lod = 0; frag_info.lod = 0;
FS::BindFragInfo(*pass, host_buffer->EmplaceUniform(frag_info)); FS::BindFragInfo(*pass, host_buffer->EmplaceUniform(frag_info));
const std::unique_ptr<const Sampler>& sampler = raw_ptr<const Sampler> sampler =
context->GetSamplerLibrary()->GetSampler({}); context->GetSamplerLibrary()->GetSampler({});
auto buffer_view = DeviceBuffer::AsBufferView(device_buffer); auto buffer_view = DeviceBuffer::AsBufferView(device_buffer);
auto texture = auto texture =
@ -872,7 +866,7 @@ TEST_P(RendererTest, CanGenerateMipmaps) {
SamplerDescriptor sampler_desc; SamplerDescriptor sampler_desc;
sampler_desc.mip_filter = mip_filters[selected_mip_filter]; sampler_desc.mip_filter = mip_filters[selected_mip_filter];
sampler_desc.min_filter = min_filters[selected_min_filter]; sampler_desc.min_filter = min_filters[selected_min_filter];
const std::unique_ptr<const Sampler>& sampler = raw_ptr<const Sampler> sampler =
context->GetSamplerLibrary()->GetSampler(sampler_desc); context->GetSamplerLibrary()->GetSampler(sampler_desc);
FS::BindTex(*pass, boston, sampler); FS::BindTex(*pass, boston, sampler);
@ -908,14 +902,14 @@ TEST_P(RendererTest, TheImpeller) {
SamplerDescriptor noise_sampler_desc; SamplerDescriptor noise_sampler_desc;
noise_sampler_desc.width_address_mode = SamplerAddressMode::kRepeat; noise_sampler_desc.width_address_mode = SamplerAddressMode::kRepeat;
noise_sampler_desc.height_address_mode = SamplerAddressMode::kRepeat; noise_sampler_desc.height_address_mode = SamplerAddressMode::kRepeat;
const std::unique_ptr<const Sampler>& noise_sampler = raw_ptr<const Sampler> noise_sampler =
context->GetSamplerLibrary()->GetSampler(noise_sampler_desc); context->GetSamplerLibrary()->GetSampler(noise_sampler_desc);
auto cube_map = CreateTextureCubeForFixture( auto cube_map = CreateTextureCubeForFixture(
{"table_mountain_px.png", "table_mountain_nx.png", {"table_mountain_px.png", "table_mountain_nx.png",
"table_mountain_py.png", "table_mountain_ny.png", "table_mountain_py.png", "table_mountain_ny.png",
"table_mountain_pz.png", "table_mountain_nz.png"}); "table_mountain_pz.png", "table_mountain_nz.png"});
const std::unique_ptr<const Sampler>& cube_map_sampler = raw_ptr<const Sampler> cube_map_sampler =
context->GetSamplerLibrary()->GetSampler({}); context->GetSamplerLibrary()->GetSampler({});
auto host_buffer = HostBuffer::Create(context->GetResourceAllocator(), auto host_buffer = HostBuffer::Create(context->GetResourceAllocator(),
context->GetIdleWaiter()); context->GetIdleWaiter());
@ -1244,8 +1238,7 @@ TEST_P(RendererTest, StencilMask) {
auto bridge = CreateTextureForFixture("bay_bridge.jpg"); auto bridge = CreateTextureForFixture("bay_bridge.jpg");
auto boston = CreateTextureForFixture("boston.jpg"); auto boston = CreateTextureForFixture("boston.jpg");
ASSERT_TRUE(bridge && boston); ASSERT_TRUE(bridge && boston);
const std::unique_ptr<const Sampler>& sampler = raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
context->GetSamplerLibrary()->GetSampler({});
ASSERT_TRUE(sampler); ASSERT_TRUE(sampler);
static bool mirror = false; static bool mirror = false;
@ -1621,8 +1614,7 @@ TEST_P(RendererTest, BindingNullTexturesDoesNotCrash) {
using FS = BoxFadeFragmentShader; using FS = BoxFadeFragmentShader;
auto context = GetContext(); auto context = GetContext();
const std::unique_ptr<const Sampler>& sampler = raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
context->GetSamplerLibrary()->GetSampler({});
auto command_buffer = context->CreateCommandBuffer(); auto command_buffer = context->CreateCommandBuffer();
RenderTargetAllocator allocator(context->GetResourceAllocator()); RenderTargetAllocator allocator(context->GetResourceAllocator());

View File

@ -5,6 +5,7 @@
#ifndef FLUTTER_IMPELLER_RENDERER_SAMPLER_LIBRARY_H_ #ifndef FLUTTER_IMPELLER_RENDERER_SAMPLER_LIBRARY_H_
#define FLUTTER_IMPELLER_RENDERER_SAMPLER_LIBRARY_H_ #define FLUTTER_IMPELLER_RENDERER_SAMPLER_LIBRARY_H_
#include "impeller/core/raw_ptr.h"
#include "impeller/core/sampler.h" #include "impeller/core/sampler.h"
#include "impeller/core/sampler_descriptor.h" #include "impeller/core/sampler_descriptor.h"
@ -23,8 +24,8 @@ class SamplerLibrary {
/// The sampler library implementations must cache this sampler object /// The sampler library implementations must cache this sampler object
/// and guarantee that the reference will continue to be valid /// and guarantee that the reference will continue to be valid
/// throughout the lifetime of the Impeller context. /// throughout the lifetime of the Impeller context.
virtual const std::unique_ptr<const Sampler>& GetSampler( virtual raw_ptr<const Sampler> GetSampler(
SamplerDescriptor descriptor) = 0; const SamplerDescriptor& descriptor) = 0;
protected: protected:
SamplerLibrary(); SamplerLibrary();

View File

@ -244,9 +244,9 @@ class MockCommandQueue : public CommandQueue {
class MockSamplerLibrary : public SamplerLibrary { class MockSamplerLibrary : public SamplerLibrary {
public: public:
MOCK_METHOD(const std::unique_ptr<const Sampler>&, MOCK_METHOD(raw_ptr<const Sampler>,
GetSampler, GetSampler,
(SamplerDescriptor descriptor), (const SamplerDescriptor& descriptor),
(override)); (override));
}; };

View File

@ -192,7 +192,7 @@ bool RenderPass::Draw() {
texture.slot, texture.slot,
std::make_unique<impeller::ShaderMetadata>( std::make_unique<impeller::ShaderMetadata>(
*texture.texture.GetMetadata()), *texture.texture.GetMetadata()),
texture.texture.resource, *texture.sampler); texture.texture.resource, texture.sampler);
} }
for (const auto& [_, buffer] : fragment_uniform_bindings) { for (const auto& [_, buffer] : fragment_uniform_bindings) {
render_pass_->BindDynamicResource( render_pass_->BindDynamicResource(
@ -207,7 +207,7 @@ bool RenderPass::Draw() {
impeller::DescriptorType::kSampledImage, texture.slot, impeller::DescriptorType::kSampledImage, texture.slot,
std::make_unique<impeller::ShaderMetadata>( std::make_unique<impeller::ShaderMetadata>(
*texture.texture.GetMetadata()), *texture.texture.GetMetadata()),
texture.texture.resource, *texture.sampler); texture.texture.resource, texture.sampler);
} }
render_pass_->SetVertexBuffer(vertex_buffer); render_pass_->SetVertexBuffer(vertex_buffer);
@ -466,7 +466,7 @@ bool InternalFlutterGpu_RenderPass_BindTexture(
flutter::gpu::ToImpellerSamplerAddressMode(width_address_mode); flutter::gpu::ToImpellerSamplerAddressMode(width_address_mode);
sampler_desc.height_address_mode = sampler_desc.height_address_mode =
flutter::gpu::ToImpellerSamplerAddressMode(height_address_mode); flutter::gpu::ToImpellerSamplerAddressMode(height_address_mode);
const std::unique_ptr<const impeller::Sampler>& sampler = auto sampler =
wrapper->GetContext()->GetSamplerLibrary()->GetSampler(sampler_desc); wrapper->GetContext()->GetSamplerLibrary()->GetSampler(sampler_desc);
flutter::gpu::RenderPass::TextureUniformMap* uniform_map = nullptr; flutter::gpu::RenderPass::TextureUniformMap* uniform_map = nullptr;
@ -486,7 +486,7 @@ bool InternalFlutterGpu_RenderPass_BindTexture(
impeller::TextureAndSampler{ impeller::TextureAndSampler{
.slot = texture_binding->slot, .slot = texture_binding->slot,
.texture = {&texture_binding->metadata, texture->GetTexture()}, .texture = {&texture_binding->metadata, texture->GetTexture()},
.sampler = &sampler, .sampler = sampler,
}); });
return true; return true;
} }