[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:
parent
ad317842d3
commit
fda902f593
@ -1390,7 +1390,7 @@ std::vector<Reflector::BindPrototype> Reflector::ReflectBindPrototypes(
|
||||
.argument_name = "texture",
|
||||
});
|
||||
proto.args.push_back(BindPrototypeArgument{
|
||||
.type_name = "const std::unique_ptr<const Sampler>&",
|
||||
.type_name = "raw_ptr<const Sampler>",
|
||||
.argument_name = "sampler",
|
||||
});
|
||||
}
|
||||
|
@ -412,7 +412,7 @@ struct Viewport {
|
||||
/// @brief Describes how the texture should be sampled when the texture
|
||||
/// is being shrunk (minified) or expanded (magnified) to fit to
|
||||
/// the sample point.
|
||||
enum class MinMagFilter {
|
||||
enum class MinMagFilter : uint8_t {
|
||||
/// Select nearest to the sample point. Most widely supported.
|
||||
kNearest,
|
||||
|
||||
@ -422,7 +422,7 @@ enum class MinMagFilter {
|
||||
};
|
||||
|
||||
/// @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.
|
||||
///
|
||||
/// All samples are read from level 0.
|
||||
@ -438,7 +438,7 @@ enum class MipFilter {
|
||||
kLinear,
|
||||
};
|
||||
|
||||
enum class SamplerAddressMode {
|
||||
enum class SamplerAddressMode : uint8_t {
|
||||
kClampToEdge,
|
||||
kRepeat,
|
||||
kMirror,
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "impeller/core/buffer_view.h"
|
||||
#include "impeller/core/formats.h"
|
||||
#include "impeller/core/raw_ptr.h"
|
||||
#include "impeller/core/sampler.h"
|
||||
#include "impeller/core/shader_types.h"
|
||||
#include "impeller/core/texture.h"
|
||||
@ -34,7 +35,7 @@ struct ResourceBinder {
|
||||
const SampledImageSlot& slot,
|
||||
const ShaderMetadata* metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
const std::unique_ptr<const Sampler>& sampler) = 0;
|
||||
raw_ptr<const Sampler>) = 0;
|
||||
};
|
||||
|
||||
} // namespace impeller
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
Sampler::Sampler(SamplerDescriptor desc) : desc_(std::move(desc)) {}
|
||||
Sampler::Sampler(const SamplerDescriptor& desc) : desc_(desc) {}
|
||||
|
||||
Sampler::~Sampler() = default;
|
||||
|
||||
|
@ -5,9 +5,6 @@
|
||||
#ifndef 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"
|
||||
|
||||
namespace impeller {
|
||||
@ -21,7 +18,7 @@ class Sampler {
|
||||
protected:
|
||||
SamplerDescriptor desc_;
|
||||
|
||||
explicit Sampler(SamplerDescriptor desc);
|
||||
explicit Sampler(const SamplerDescriptor& desc);
|
||||
|
||||
private:
|
||||
Sampler(const Sampler&) = delete;
|
||||
@ -29,11 +26,6 @@ class Sampler {
|
||||
Sampler& operator=(const Sampler&) = delete;
|
||||
};
|
||||
|
||||
using SamplerMap = std::unordered_map<SamplerDescriptor,
|
||||
std::unique_ptr<const Sampler>,
|
||||
ComparableHash<SamplerDescriptor>,
|
||||
ComparableEqual<SamplerDescriptor>>;
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
#endif // FLUTTER_IMPELLER_CORE_SAMPLER_H_
|
||||
|
@ -5,14 +5,13 @@
|
||||
#ifndef FLUTTER_IMPELLER_CORE_SAMPLER_DESCRIPTOR_H_
|
||||
#define FLUTTER_IMPELLER_CORE_SAMPLER_DESCRIPTOR_H_
|
||||
|
||||
#include "impeller/base/comparable.h"
|
||||
#include "impeller/core/formats.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
class Context;
|
||||
|
||||
struct SamplerDescriptor final : public Comparable<SamplerDescriptor> {
|
||||
struct SamplerDescriptor final {
|
||||
MinMagFilter min_filter = MinMagFilter::kNearest;
|
||||
MinMagFilter mag_filter = MinMagFilter::kNearest;
|
||||
MipFilter mip_filter = MipFilter::kNearest;
|
||||
@ -30,20 +29,17 @@ struct SamplerDescriptor final : public Comparable<SamplerDescriptor> {
|
||||
MinMagFilter mag_filter,
|
||||
MipFilter mip_filter);
|
||||
|
||||
// Comparable<SamplerDescriptor>
|
||||
std::size_t GetHash() const override {
|
||||
return fml::HashCombine(min_filter, mag_filter, mip_filter,
|
||||
width_address_mode, height_address_mode,
|
||||
depth_address_mode);
|
||||
}
|
||||
static uint64_t ToKey(const SamplerDescriptor& d) {
|
||||
static_assert(sizeof(MinMagFilter) == 1);
|
||||
static_assert(sizeof(MipFilter) == 1);
|
||||
static_assert(sizeof(SamplerAddressMode) == 1);
|
||||
|
||||
// Comparable<SamplerDescriptor>
|
||||
bool IsEqual(const SamplerDescriptor& o) const override {
|
||||
return min_filter == o.min_filter && mag_filter == o.mag_filter &&
|
||||
mip_filter == o.mip_filter &&
|
||||
width_address_mode == o.width_address_mode &&
|
||||
height_address_mode == o.height_address_mode &&
|
||||
depth_address_mode == o.depth_address_mode;
|
||||
return static_cast<uint64_t>(d.min_filter) << 0 |
|
||||
static_cast<uint64_t>(d.mag_filter) << 8 |
|
||||
static_cast<uint64_t>(d.mip_filter) << 16 |
|
||||
static_cast<uint64_t>(d.width_address_mode) << 24 |
|
||||
static_cast<uint64_t>(d.height_address_mode) << 32 |
|
||||
static_cast<uint64_t>(d.depth_address_mode) << 40;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -658,7 +658,7 @@ void Canvas::DrawPoints(const Point points[],
|
||||
void Canvas::DrawImage(const std::shared_ptr<Texture>& image,
|
||||
Point offset,
|
||||
const Paint& paint,
|
||||
SamplerDescriptor sampler) {
|
||||
const SamplerDescriptor& sampler) {
|
||||
if (!image) {
|
||||
return;
|
||||
}
|
||||
@ -666,14 +666,14 @@ void Canvas::DrawImage(const std::shared_ptr<Texture>& image,
|
||||
const auto source = Rect::MakeSize(image->GetSize());
|
||||
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,
|
||||
Rect source,
|
||||
Rect dest,
|
||||
const Paint& paint,
|
||||
SamplerDescriptor sampler,
|
||||
const SamplerDescriptor& sampler,
|
||||
SourceRectConstraint src_rect_constraint) {
|
||||
if (!image || source.IsEmpty() || dest.IsEmpty()) {
|
||||
return;
|
||||
@ -704,7 +704,7 @@ void Canvas::DrawImageRect(const std::shared_ptr<Texture>& image,
|
||||
texture_contents->SetSourceRect(*clipped_source);
|
||||
texture_contents->SetStrictSourceRect(src_rect_constraint ==
|
||||
SourceRectConstraint::kStrict);
|
||||
texture_contents->SetSamplerDescriptor(std::move(sampler));
|
||||
texture_contents->SetSamplerDescriptor(sampler);
|
||||
texture_contents->SetOpacity(paint.color.alpha);
|
||||
texture_contents->SetDeferApplyingOpacity(paint.HasColorFilter());
|
||||
|
||||
|
@ -209,14 +209,14 @@ class Canvas {
|
||||
void DrawImage(const std::shared_ptr<Texture>& image,
|
||||
Point offset,
|
||||
const Paint& paint,
|
||||
SamplerDescriptor sampler = {});
|
||||
const SamplerDescriptor& sampler = {});
|
||||
|
||||
void DrawImageRect(
|
||||
const std::shared_ptr<Texture>& image,
|
||||
Rect source,
|
||||
Rect dest,
|
||||
const Paint& paint,
|
||||
SamplerDescriptor sampler = {},
|
||||
const SamplerDescriptor& sampler = {},
|
||||
SourceRectConstraint src_rect_constraint = SourceRectConstraint::kFast);
|
||||
|
||||
void DrawTextFrame(const std::shared_ptr<TextFrame>& text_frame,
|
||||
|
@ -47,7 +47,7 @@ bool AtlasContents::Render(const ContentContext& renderer,
|
||||
dst_sampler_descriptor.width_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(
|
||||
dst_sampler_descriptor);
|
||||
|
||||
@ -58,7 +58,7 @@ bool AtlasContents::Render(const ContentContext& renderer,
|
||||
|
||||
auto dst_sampler_descriptor = geometry_->GetSamplerDescriptor();
|
||||
|
||||
const std::unique_ptr<const Sampler>& dst_sampler =
|
||||
raw_ptr<const Sampler> dst_sampler =
|
||||
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
|
||||
dst_sampler_descriptor);
|
||||
|
||||
|
@ -204,7 +204,7 @@ static std::optional<Entity> AdvancedBlend(
|
||||
dst_sampler_descriptor.width_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(
|
||||
dst_sampler_descriptor);
|
||||
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.height_address_mode = SamplerAddressMode::kDecal;
|
||||
}
|
||||
const std::unique_ptr<const Sampler>& src_sampler =
|
||||
raw_ptr<const Sampler> src_sampler =
|
||||
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
|
||||
src_sampler_descriptor);
|
||||
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.height_address_mode = SamplerAddressMode::kDecal;
|
||||
}
|
||||
const std::unique_ptr<const Sampler>& dst_sampler =
|
||||
raw_ptr<const Sampler> dst_sampler =
|
||||
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
|
||||
dst_sampler_descriptor);
|
||||
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.height_address_mode = SamplerAddressMode::kDecal;
|
||||
}
|
||||
const std::unique_ptr<const Sampler>& dst_sampler =
|
||||
raw_ptr<const Sampler> dst_sampler =
|
||||
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
|
||||
dst_sampler_descriptor);
|
||||
FS::BindTextureSamplerDst(pass, dst_snapshot->texture, dst_sampler);
|
||||
@ -577,7 +577,7 @@ static std::optional<Entity> PipelineBlend(
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::unique_ptr<const Sampler>& sampler =
|
||||
raw_ptr<const Sampler> sampler =
|
||||
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
|
||||
input->sampler_descriptor);
|
||||
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.height_address_mode = SamplerAddressMode::kDecal;
|
||||
}
|
||||
const std::unique_ptr<const Sampler>& src_sampler =
|
||||
raw_ptr<const Sampler> src_sampler =
|
||||
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
|
||||
src_sampler_descriptor);
|
||||
FS::BindTextureSamplerSrc(pass, src_texture, src_sampler);
|
||||
|
@ -122,7 +122,7 @@ std::optional<Entity> BorderMaskBlurFilterContents::RenderFilter(
|
||||
FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_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({});
|
||||
FS::BindTextureSampler(pass, input_snapshot->texture, sampler);
|
||||
|
||||
|
@ -96,7 +96,7 @@ std::optional<Entity> ColorMatrixFilterContents::RenderFilter(
|
||||
absorb_opacity == ColorFilterContents::AbsorbOpacity::kYes
|
||||
? input_snapshot->opacity
|
||||
: 1.0f;
|
||||
const std::unique_ptr<const Sampler>& sampler =
|
||||
raw_ptr<const Sampler> sampler =
|
||||
renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
|
||||
FS::BindInputTexture(pass, input_snapshot->texture, sampler);
|
||||
FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
|
||||
|
@ -20,8 +20,8 @@ void MatrixFilterContents::SetRenderingMode(
|
||||
FilterContents::SetRenderingMode(rendering_mode);
|
||||
}
|
||||
|
||||
void MatrixFilterContents::SetSamplerDescriptor(SamplerDescriptor desc) {
|
||||
sampler_descriptor_ = std::move(desc);
|
||||
void MatrixFilterContents::SetSamplerDescriptor(const SamplerDescriptor& desc) {
|
||||
sampler_descriptor_ = desc;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
@ -21,7 +21,7 @@ class MatrixFilterContents final : public FilterContents {
|
||||
// |FilterContents|
|
||||
void SetRenderingMode(Entity::RenderingMode rendering_mode) override;
|
||||
|
||||
void SetSamplerDescriptor(SamplerDescriptor desc);
|
||||
void SetSamplerDescriptor(const SamplerDescriptor& desc);
|
||||
|
||||
// |FilterContents|
|
||||
std::optional<Rect> GetFilterCoverage(
|
||||
|
@ -77,7 +77,7 @@ std::optional<Entity> SrgbToLinearFilterContents::RenderFilter(
|
||||
? input_snapshot->opacity
|
||||
: 1.0f;
|
||||
|
||||
const std::unique_ptr<const Sampler>& sampler =
|
||||
raw_ptr<const Sampler> sampler =
|
||||
renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
|
||||
FS::BindInputTexture(pass, input_snapshot->texture, sampler);
|
||||
FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
|
||||
|
@ -111,7 +111,7 @@ std::optional<Entity> YUVToRGBFilterContents::RenderFilter(
|
||||
break;
|
||||
}
|
||||
|
||||
const std::unique_ptr<const Sampler>& sampler =
|
||||
raw_ptr<const Sampler> sampler =
|
||||
renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
|
||||
FS::BindYTexture(pass, y_input_snapshot->texture, sampler);
|
||||
FS::BindUvTexture(pass, uv_input_snapshot->texture, sampler);
|
||||
|
@ -128,7 +128,7 @@ bool FramebufferBlendContents::Render(const ContentContext& renderer,
|
||||
src_sampler_descriptor.width_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(
|
||||
src_sampler_descriptor);
|
||||
FS::BindTextureSamplerSrc(pass, src_snapshot->texture, src_sampler);
|
||||
|
@ -301,7 +301,7 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
|
||||
FML_DCHECK(sampler_index < texture_inputs_.size());
|
||||
auto& input = texture_inputs_[sampler_index];
|
||||
|
||||
const std::unique_ptr<const Sampler>& sampler =
|
||||
raw_ptr<const Sampler> sampler =
|
||||
context->GetSamplerLibrary()->GetSampler(
|
||||
input.sampler_descriptor);
|
||||
|
||||
|
@ -135,7 +135,7 @@ bool RecordingRenderPass::BindDynamicResource(
|
||||
const SampledImageSlot& slot,
|
||||
std::unique_ptr<ShaderMetadata> metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
const std::unique_ptr<const Sampler>& sampler) {
|
||||
raw_ptr<const Sampler> sampler) {
|
||||
if (delegate_) {
|
||||
return delegate_->BindDynamicResource(
|
||||
stage, type, slot, std::move(metadata), texture, sampler);
|
||||
@ -143,13 +143,12 @@ bool RecordingRenderPass::BindDynamicResource(
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RecordingRenderPass::BindResource(
|
||||
ShaderStage stage,
|
||||
DescriptorType type,
|
||||
const SampledImageSlot& slot,
|
||||
const ShaderMetadata* metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
const std::unique_ptr<const Sampler>& sampler) {
|
||||
bool RecordingRenderPass::BindResource(ShaderStage stage,
|
||||
DescriptorType type,
|
||||
const SampledImageSlot& slot,
|
||||
const ShaderMetadata* metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
raw_ptr<const Sampler> sampler) {
|
||||
if (delegate_) {
|
||||
return delegate_->BindResource(stage, type, slot, metadata, texture,
|
||||
sampler);
|
||||
|
@ -56,7 +56,7 @@ class RecordingRenderPass : public RenderPass {
|
||||
const SampledImageSlot& slot,
|
||||
const ShaderMetadata* metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
const std::unique_ptr<const Sampler>& sampler) override;
|
||||
raw_ptr<const Sampler> sampler) override;
|
||||
|
||||
// |RenderPass|
|
||||
bool BindDynamicResource(ShaderStage stage,
|
||||
@ -66,13 +66,12 @@ class RecordingRenderPass : public RenderPass {
|
||||
BufferView view) override;
|
||||
|
||||
// |RenderPass|
|
||||
bool BindDynamicResource(
|
||||
ShaderStage stage,
|
||||
DescriptorType type,
|
||||
const SampledImageSlot& slot,
|
||||
std::unique_ptr<ShaderMetadata> metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
const std::unique_ptr<const Sampler>& sampler) override;
|
||||
bool BindDynamicResource(ShaderStage stage,
|
||||
DescriptorType type,
|
||||
const SampledImageSlot& slot,
|
||||
std::unique_ptr<ShaderMetadata> metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
raw_ptr<const Sampler> sampler) override;
|
||||
|
||||
// |RenderPass|
|
||||
void OnSetLabel(std::string_view label) override;
|
||||
|
@ -240,8 +240,8 @@ bool TextureContents::GetStrictSourceRect() const {
|
||||
return strict_source_rect_enabled_;
|
||||
}
|
||||
|
||||
void TextureContents::SetSamplerDescriptor(SamplerDescriptor desc) {
|
||||
sampler_descriptor_ = std::move(desc);
|
||||
void TextureContents::SetSamplerDescriptor(const SamplerDescriptor& desc) {
|
||||
sampler_descriptor_ = desc;
|
||||
}
|
||||
|
||||
const SamplerDescriptor& TextureContents::GetSamplerDescriptor() const {
|
||||
|
@ -33,7 +33,7 @@ class TextureContents final : public Contents {
|
||||
|
||||
std::shared_ptr<Texture> GetTexture() const;
|
||||
|
||||
void SetSamplerDescriptor(SamplerDescriptor desc);
|
||||
void SetSamplerDescriptor(const SamplerDescriptor& desc);
|
||||
|
||||
const SamplerDescriptor& GetSamplerDescriptor() const;
|
||||
|
||||
|
@ -47,8 +47,8 @@ void TiledTextureContents::SetTileModes(Entity::TileMode x_tile_mode,
|
||||
y_tile_mode_ = y_tile_mode;
|
||||
}
|
||||
|
||||
void TiledTextureContents::SetSamplerDescriptor(SamplerDescriptor desc) {
|
||||
sampler_descriptor_ = std::move(desc);
|
||||
void TiledTextureContents::SetSamplerDescriptor(const SamplerDescriptor& desc) {
|
||||
sampler_descriptor_ = desc;
|
||||
}
|
||||
|
||||
void TiledTextureContents::SetColorFilter(ColorFilterProc color_filter) {
|
||||
|
@ -37,7 +37,7 @@ class TiledTextureContents final : public ColorSourceContents {
|
||||
|
||||
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
|
||||
/// @param color_filter
|
||||
|
@ -70,8 +70,8 @@ std::optional<Rect> VerticesSimpleBlendContents::GetCoverage(
|
||||
}
|
||||
|
||||
void VerticesSimpleBlendContents::SetSamplerDescriptor(
|
||||
SamplerDescriptor descriptor) {
|
||||
descriptor_ = std::move(descriptor);
|
||||
const SamplerDescriptor& descriptor) {
|
||||
descriptor_ = descriptor;
|
||||
}
|
||||
|
||||
void VerticesSimpleBlendContents::SetTileMode(Entity::TileMode tile_mode_x,
|
||||
@ -126,7 +126,7 @@ bool VerticesSimpleBlendContents::Render(const ContentContext& renderer,
|
||||
TileModeToAddressMode(tile_mode_y_, renderer.GetDeviceCapabilities())
|
||||
.value_or(SamplerAddressMode::kClampToEdge);
|
||||
|
||||
const std::unique_ptr<const Sampler>& dst_sampler =
|
||||
raw_ptr<const Sampler> dst_sampler =
|
||||
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
|
||||
dst_sampler_descriptor);
|
||||
|
||||
|
@ -36,7 +36,7 @@ class VerticesSimpleBlendContents final : public Contents {
|
||||
|
||||
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);
|
||||
|
||||
|
@ -38,13 +38,13 @@
|
||||
|
||||
struct 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) {}
|
||||
|
||||
std::shared_ptr<impeller::Context> context;
|
||||
std::shared_ptr<impeller::Texture> font_texture;
|
||||
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() {
|
||||
|
@ -486,7 +486,7 @@ std::optional<size_t> BufferBindingsGLES::BindTextures(
|
||||
/// If there is a sampler for the texture at the same index, configure the
|
||||
/// 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)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
@ -5,7 +5,6 @@
|
||||
#ifndef 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 "flutter/third_party/abseil-cpp/absl/container/flat_hash_map.h"
|
||||
|
@ -6,13 +6,14 @@
|
||||
|
||||
#include "impeller/base/validation.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/proc_table_gles.h"
|
||||
#include "impeller/renderer/backend/gles/texture_gles.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
SamplerGLES::SamplerGLES(SamplerDescriptor desc) : Sampler(std::move(desc)) {}
|
||||
SamplerGLES::SamplerGLES(const SamplerDescriptor& desc) : Sampler(desc) {}
|
||||
|
||||
SamplerGLES::~SamplerGLES() = default;
|
||||
|
||||
@ -81,7 +82,7 @@ bool SamplerGLES::ConfigureBoundTexture(const TextureGLES& texture,
|
||||
if (!target.has_value()) {
|
||||
return false;
|
||||
}
|
||||
const auto& desc = GetDescriptor();
|
||||
const SamplerDescriptor& desc = GetDescriptor();
|
||||
|
||||
GLint mag_filter = ToParam(desc.mag_filter);
|
||||
|
||||
|
@ -25,7 +25,7 @@ class SamplerGLES final : public Sampler,
|
||||
private:
|
||||
friend class SamplerLibraryGLES;
|
||||
|
||||
explicit SamplerGLES(SamplerDescriptor desc);
|
||||
explicit SamplerGLES(const SamplerDescriptor&);
|
||||
|
||||
SamplerGLES(const SamplerGLES&) = delete;
|
||||
|
||||
|
@ -7,12 +7,11 @@
|
||||
#include "impeller/base/config.h"
|
||||
#include "impeller/base/validation.h"
|
||||
#include "impeller/core/formats.h"
|
||||
#include "impeller/core/sampler_descriptor.h"
|
||||
#include "impeller/renderer/backend/gles/sampler_gles.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
static const std::unique_ptr<const Sampler> kNullSampler = nullptr;
|
||||
|
||||
SamplerLibraryGLES::SamplerLibraryGLES(bool 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;
|
||||
|
||||
// |SamplerLibrary|
|
||||
const std::unique_ptr<const Sampler>& SamplerLibraryGLES::GetSampler(
|
||||
SamplerDescriptor descriptor) {
|
||||
raw_ptr<const Sampler> SamplerLibraryGLES::GetSampler(
|
||||
const SamplerDescriptor& descriptor) {
|
||||
if (!supports_decal_sampler_address_mode_ &&
|
||||
(descriptor.width_address_mode == SamplerAddressMode::kDecal ||
|
||||
descriptor.height_address_mode == SamplerAddressMode::kDecal ||
|
||||
descriptor.depth_address_mode == SamplerAddressMode::kDecal)) {
|
||||
VALIDATION_LOG << "SamplerAddressMode::kDecal is not supported by the "
|
||||
"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);
|
||||
if (found != samplers_.end()) {
|
||||
return found->second;
|
||||
}
|
||||
return (samplers_[descriptor] =
|
||||
std::unique_ptr<SamplerGLES>(new SamplerGLES(descriptor)));
|
||||
auto sampler = std::unique_ptr<SamplerGLES>(new SamplerGLES(descriptor));
|
||||
samplers_.push_back(std::make_pair(p_key, std::move(sampler)));
|
||||
|
||||
return raw_ptr(samplers_.back().second);
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "impeller/core/sampler.h"
|
||||
#include "impeller/core/sampler_descriptor.h"
|
||||
#include "impeller/renderer/backend/gles/sampler_gles.h"
|
||||
#include "impeller/renderer/sampler_library.h"
|
||||
|
||||
namespace impeller {
|
||||
@ -20,13 +21,13 @@ class SamplerLibraryGLES final : public SamplerLibrary {
|
||||
private:
|
||||
friend class ContextGLES;
|
||||
|
||||
SamplerMap samplers_;
|
||||
std::vector<std::pair<uint64_t, std::shared_ptr<const Sampler>>> samplers_;
|
||||
|
||||
SamplerLibraryGLES();
|
||||
|
||||
// |SamplerLibrary|
|
||||
const std::unique_ptr<const Sampler>& GetSampler(
|
||||
SamplerDescriptor descriptor) override;
|
||||
raw_ptr<const Sampler> GetSampler(
|
||||
const SamplerDescriptor& descriptor) override;
|
||||
|
||||
bool supports_decal_sampler_address_mode_ = false;
|
||||
|
||||
|
@ -60,7 +60,7 @@ class ComputePassMTL final : public ComputePass {
|
||||
const SampledImageSlot& slot,
|
||||
const ShaderMetadata* metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
const std::unique_ptr<const Sampler>& sampler) override;
|
||||
raw_ptr<const Sampler> sampler) override;
|
||||
|
||||
// |ComputePass|
|
||||
bool EncodeCommands() const override;
|
||||
|
@ -105,13 +105,12 @@ bool ComputePassMTL::BindResource(ShaderStage stage,
|
||||
}
|
||||
|
||||
// |ComputePass|
|
||||
bool ComputePassMTL::BindResource(
|
||||
ShaderStage stage,
|
||||
DescriptorType type,
|
||||
const SampledImageSlot& slot,
|
||||
const ShaderMetadata* metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
const std::unique_ptr<const Sampler>& sampler) {
|
||||
bool ComputePassMTL::BindResource(ShaderStage stage,
|
||||
DescriptorType type,
|
||||
const SampledImageSlot& slot,
|
||||
const ShaderMetadata* metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
raw_ptr<const Sampler> sampler) {
|
||||
if (!sampler || !texture->IsValid()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ class RenderPassMTL final : public RenderPass {
|
||||
const SampledImageSlot& slot,
|
||||
const ShaderMetadata* metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
const std::unique_ptr<const Sampler>& sampler) override;
|
||||
raw_ptr<const Sampler> sampler) override;
|
||||
|
||||
// |RenderPass|
|
||||
bool BindDynamicResource(ShaderStage stage,
|
||||
@ -114,13 +114,12 @@ class RenderPassMTL final : public RenderPass {
|
||||
BufferView view) override;
|
||||
|
||||
// |RenderPass|
|
||||
bool BindDynamicResource(
|
||||
ShaderStage stage,
|
||||
DescriptorType type,
|
||||
const SampledImageSlot& slot,
|
||||
std::unique_ptr<ShaderMetadata> metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
const std::unique_ptr<const Sampler>& sampler) override;
|
||||
bool BindDynamicResource(ShaderStage stage,
|
||||
DescriptorType type,
|
||||
const SampledImageSlot& slot,
|
||||
std::unique_ptr<ShaderMetadata> metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
raw_ptr<const Sampler> sampler) override;
|
||||
|
||||
RenderPassMTL(const RenderPassMTL&) = delete;
|
||||
|
||||
|
@ -210,7 +210,7 @@ static bool Bind(PassBindingsCacheMTL& pass,
|
||||
static bool Bind(PassBindingsCacheMTL& pass,
|
||||
ShaderStage stage,
|
||||
size_t bind_index,
|
||||
const std::unique_ptr<const Sampler>& sampler,
|
||||
raw_ptr<const Sampler> sampler,
|
||||
const Texture& texture) {
|
||||
if (!sampler || !texture.IsValid()) {
|
||||
return false;
|
||||
@ -400,13 +400,12 @@ bool RenderPassMTL::BindDynamicResource(
|
||||
}
|
||||
|
||||
// |RenderPass|
|
||||
bool RenderPassMTL::BindResource(
|
||||
ShaderStage stage,
|
||||
DescriptorType type,
|
||||
const SampledImageSlot& slot,
|
||||
const ShaderMetadata* metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
const std::unique_ptr<const Sampler>& sampler) {
|
||||
bool RenderPassMTL::BindResource(ShaderStage stage,
|
||||
DescriptorType type,
|
||||
const SampledImageSlot& slot,
|
||||
const ShaderMetadata* metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
raw_ptr<const Sampler> sampler) {
|
||||
if (!texture) {
|
||||
return false;
|
||||
}
|
||||
@ -419,7 +418,7 @@ bool RenderPassMTL::BindDynamicResource(
|
||||
const SampledImageSlot& slot,
|
||||
std::unique_ptr<ShaderMetadata> metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
const std::unique_ptr<const Sampler>& sampler) {
|
||||
raw_ptr<const Sampler> sampler) {
|
||||
if (!texture) {
|
||||
return false;
|
||||
}
|
||||
|
@ -27,13 +27,13 @@ class SamplerLibraryMTL final
|
||||
friend class ContextMTL;
|
||||
|
||||
id<MTLDevice> device_ = nullptr;
|
||||
SamplerMap samplers_;
|
||||
std::vector<std::pair<uint64_t, std::shared_ptr<const Sampler>>> samplers_;
|
||||
|
||||
explicit SamplerLibraryMTL(id<MTLDevice> device);
|
||||
|
||||
// |SamplerLibrary|
|
||||
const std::unique_ptr<const Sampler>& GetSampler(
|
||||
SamplerDescriptor descriptor) override;
|
||||
raw_ptr<const Sampler> GetSampler(
|
||||
const SamplerDescriptor& descriptor) override;
|
||||
|
||||
SamplerLibraryMTL(const SamplerLibraryMTL&) = delete;
|
||||
|
||||
|
@ -13,16 +13,16 @@ SamplerLibraryMTL::SamplerLibraryMTL(id<MTLDevice> device) : device_(device) {}
|
||||
|
||||
SamplerLibraryMTL::~SamplerLibraryMTL() = default;
|
||||
|
||||
static const std::unique_ptr<const Sampler> kNullSampler = nullptr;
|
||||
|
||||
const std::unique_ptr<const Sampler>& SamplerLibraryMTL::GetSampler(
|
||||
SamplerDescriptor descriptor) {
|
||||
auto found = samplers_.find(descriptor);
|
||||
if (found != samplers_.end()) {
|
||||
return found->second;
|
||||
raw_ptr<const Sampler> SamplerLibraryMTL::GetSampler(
|
||||
const SamplerDescriptor& descriptor) {
|
||||
uint64_t p_key = SamplerDescriptor::ToKey(descriptor);
|
||||
for (const auto& [key, value] : samplers_) {
|
||||
if (key == p_key) {
|
||||
return raw_ptr(value);
|
||||
}
|
||||
}
|
||||
if (!device_) {
|
||||
return kNullSampler;
|
||||
return raw_ptr<const Sampler>(nullptr);
|
||||
}
|
||||
auto desc = [[MTLSamplerDescriptor alloc] init];
|
||||
desc.minFilter = ToMTLSamplerMinMagFilter(descriptor.min_filter);
|
||||
@ -42,12 +42,13 @@ const std::unique_ptr<const Sampler>& SamplerLibraryMTL::GetSampler(
|
||||
|
||||
auto mtl_sampler = [device_ newSamplerStateWithDescriptor:desc];
|
||||
if (!mtl_sampler) {
|
||||
return kNullSampler;
|
||||
return raw_ptr<const Sampler>(nullptr);
|
||||
;
|
||||
}
|
||||
auto sampler =
|
||||
std::unique_ptr<SamplerMTL>(new SamplerMTL(descriptor, mtl_sampler));
|
||||
|
||||
return (samplers_[descriptor] = std::move(sampler));
|
||||
std::shared_ptr<SamplerMTL>(new SamplerMTL(descriptor, mtl_sampler));
|
||||
samplers_.push_back(std::make_pair(p_key, std::move(sampler)));
|
||||
return raw_ptr(samplers_.back().second);
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
@ -29,7 +29,7 @@ class SamplerMTL final : public Sampler,
|
||||
|
||||
id<MTLSamplerState> state_ = nullptr;
|
||||
|
||||
SamplerMTL(SamplerDescriptor desc, id<MTLSamplerState> state);
|
||||
SamplerMTL(const SamplerDescriptor& desc, id<MTLSamplerState> state);
|
||||
|
||||
SamplerMTL(const SamplerMTL&) = delete;
|
||||
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
SamplerMTL::SamplerMTL(SamplerDescriptor desc, id<MTLSamplerState> state)
|
||||
: Sampler(std::move(desc)), state_(state) {
|
||||
SamplerMTL::SamplerMTL(const SamplerDescriptor& desc, id<MTLSamplerState> state)
|
||||
: Sampler(desc), state_(state) {
|
||||
FML_DCHECK(state_);
|
||||
}
|
||||
|
||||
|
@ -140,13 +140,12 @@ bool ComputePassVK::BindResource(ShaderStage stage,
|
||||
}
|
||||
|
||||
// |ResourceBinder|
|
||||
bool ComputePassVK::BindResource(
|
||||
ShaderStage stage,
|
||||
DescriptorType type,
|
||||
const SampledImageSlot& slot,
|
||||
const ShaderMetadata* metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
const std::unique_ptr<const Sampler>& sampler) {
|
||||
bool ComputePassVK::BindResource(ShaderStage stage,
|
||||
DescriptorType type,
|
||||
const SampledImageSlot& slot,
|
||||
const ShaderMetadata* metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
raw_ptr<const Sampler> sampler) {
|
||||
if (bound_image_offset_ >= kMaxBindings) {
|
||||
return false;
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ class ComputePassVK final : public ComputePass {
|
||||
const SampledImageSlot& slot,
|
||||
const ShaderMetadata* metadata,
|
||||
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);
|
||||
};
|
||||
|
@ -601,13 +601,12 @@ bool RenderPassVK::BindResource(size_t binding,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderPassVK::BindDynamicResource(
|
||||
ShaderStage stage,
|
||||
DescriptorType type,
|
||||
const SampledImageSlot& slot,
|
||||
std::unique_ptr<ShaderMetadata> metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
const std::unique_ptr<const Sampler>& sampler) {
|
||||
bool RenderPassVK::BindDynamicResource(ShaderStage stage,
|
||||
DescriptorType type,
|
||||
const SampledImageSlot& slot,
|
||||
std::unique_ptr<ShaderMetadata> metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
raw_ptr<const Sampler> sampler) {
|
||||
return BindResource(stage, type, slot, nullptr, texture, sampler);
|
||||
}
|
||||
|
||||
@ -616,7 +615,7 @@ bool RenderPassVK::BindResource(ShaderStage stage,
|
||||
const SampledImageSlot& slot,
|
||||
const ShaderMetadata* metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
const std::unique_ptr<const Sampler>& sampler) {
|
||||
raw_ptr<const Sampler> sampler) {
|
||||
if (bound_buffer_offset_ >= kMaxBindings) {
|
||||
return false;
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ class RenderPassVK final : public RenderPass {
|
||||
const SampledImageSlot& slot,
|
||||
const ShaderMetadata* metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
const std::unique_ptr<const Sampler>& sampler) override;
|
||||
raw_ptr<const Sampler> sampler) override;
|
||||
|
||||
// |RenderPass|
|
||||
bool BindDynamicResource(ShaderStage stage,
|
||||
@ -114,13 +114,12 @@ class RenderPassVK final : public RenderPass {
|
||||
BufferView view) override;
|
||||
|
||||
// |RenderPass|
|
||||
bool BindDynamicResource(
|
||||
ShaderStage stage,
|
||||
DescriptorType type,
|
||||
const SampledImageSlot& slot,
|
||||
std::unique_ptr<ShaderMetadata> metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
const std::unique_ptr<const Sampler>& sampler) override;
|
||||
bool BindDynamicResource(ShaderStage stage,
|
||||
DescriptorType type,
|
||||
const SampledImageSlot& slot,
|
||||
std::unique_ptr<ShaderMetadata> metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
raw_ptr<const Sampler> sampler) override;
|
||||
|
||||
bool BindResource(size_t binding, DescriptorType type, BufferView view);
|
||||
|
||||
|
@ -4,8 +4,6 @@
|
||||
|
||||
#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"
|
||||
|
||||
namespace impeller {
|
||||
@ -16,20 +14,21 @@ SamplerLibraryVK::SamplerLibraryVK(
|
||||
|
||||
SamplerLibraryVK::~SamplerLibraryVK() = default;
|
||||
|
||||
static const std::unique_ptr<const Sampler> kNullSampler = nullptr;
|
||||
|
||||
const std::unique_ptr<const Sampler>& SamplerLibraryVK::GetSampler(
|
||||
SamplerDescriptor desc) {
|
||||
auto found = samplers_.find(desc);
|
||||
if (found != samplers_.end()) {
|
||||
return found->second;
|
||||
raw_ptr<const Sampler> SamplerLibraryVK::GetSampler(
|
||||
const SamplerDescriptor& desc) {
|
||||
uint64_t p_key = SamplerDescriptor::ToKey(desc);
|
||||
for (const auto& [key, value] : samplers_) {
|
||||
if (key == p_key) {
|
||||
return raw_ptr(value);
|
||||
}
|
||||
}
|
||||
auto device_holder = device_holder_.lock();
|
||||
if (!device_holder || !device_holder->GetDevice()) {
|
||||
return kNullSampler;
|
||||
return raw_ptr<const Sampler>(nullptr);
|
||||
}
|
||||
return (samplers_[desc] =
|
||||
std::make_unique<SamplerVK>(device_holder->GetDevice(), desc));
|
||||
samplers_.push_back(std::make_pair(
|
||||
p_key, std::make_shared<SamplerVK>(device_holder->GetDevice(), desc)));
|
||||
return raw_ptr(samplers_.back().second);
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
@ -6,6 +6,7 @@
|
||||
#define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SAMPLER_LIBRARY_VK_H_
|
||||
|
||||
#include "impeller/base/backend_cast.h"
|
||||
#include "impeller/core/sampler.h"
|
||||
#include "impeller/core/sampler_descriptor.h"
|
||||
#include "impeller/renderer/backend/vulkan/device_holder_vk.h"
|
||||
#include "impeller/renderer/sampler_library.h"
|
||||
@ -23,13 +24,13 @@ class SamplerLibraryVK final
|
||||
friend class ContextVK;
|
||||
|
||||
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);
|
||||
|
||||
// |SamplerLibrary|
|
||||
const std::unique_ptr<const Sampler>& GetSampler(
|
||||
SamplerDescriptor descriptor) override;
|
||||
raw_ptr<const Sampler> GetSampler(
|
||||
const SamplerDescriptor& descriptor) override;
|
||||
|
||||
SamplerLibraryVK(const SamplerLibraryVK&) = delete;
|
||||
|
||||
|
@ -99,9 +99,9 @@ static vk::UniqueSampler CreateSampler(
|
||||
}
|
||||
|
||||
SamplerVK::SamplerVK(const vk::Device& device,
|
||||
SamplerDescriptor desc,
|
||||
const SamplerDescriptor& desc,
|
||||
std::shared_ptr<YUVConversionVK> yuv_conversion)
|
||||
: Sampler(std::move(desc)),
|
||||
: Sampler(desc),
|
||||
device_(device),
|
||||
sampler_(MakeSharedVK<vk::Sampler>(
|
||||
CreateSampler(device, desc_, yuv_conversion))),
|
||||
|
@ -18,7 +18,7 @@ class YUVConversionVK;
|
||||
class SamplerVK final : public Sampler, public BackendCast<SamplerVK, Sampler> {
|
||||
public:
|
||||
SamplerVK(const vk::Device& device,
|
||||
SamplerDescriptor desc,
|
||||
const SamplerDescriptor&,
|
||||
std::shared_ptr<YUVConversionVK> yuv_conversion = {});
|
||||
|
||||
// |Sampler|
|
||||
|
@ -227,7 +227,7 @@ std::shared_ptr<SamplerVK> TextureVK::GetImmutableSamplerVariant(
|
||||
if (!source_) {
|
||||
return nullptr;
|
||||
}
|
||||
auto conversion = source_->GetYUVConversion();
|
||||
std::shared_ptr<YUVConversionVK> conversion = source_->GetYUVConversion();
|
||||
if (!conversion) {
|
||||
// Most textures don't need a sampler conversion and will go down this path.
|
||||
// Only needed for YUV sampling from external textures.
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "flutter/fml/hash_combine.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/sampler_vk.h"
|
||||
|
||||
@ -107,12 +108,13 @@ ImmutableSamplerKeyVK::ImmutableSamplerKeyVK(const SamplerVK& sampler)
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
std::size_t ImmutableSamplerKeyVK::GetHash() const {
|
||||
return fml::HashCombine(sampler.GetHash(),
|
||||
return fml::HashCombine(SamplerDescriptor::ToKey(sampler),
|
||||
YUVConversionDescriptorVKHash{}(yuv_conversion));
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ struct TextureAndSampler {
|
||||
SampledImageSlot slot;
|
||||
ShaderStage stage;
|
||||
TextureResource texture;
|
||||
const std::unique_ptr<const Sampler>* sampler;
|
||||
raw_ptr<const Sampler> sampler;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
@ -237,7 +237,7 @@ bool RenderPass::BindResource(ShaderStage stage,
|
||||
const SampledImageSlot& slot,
|
||||
const ShaderMetadata* metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
const std::unique_ptr<const Sampler>& sampler) {
|
||||
raw_ptr<const Sampler> sampler) {
|
||||
if (!sampler) {
|
||||
return false;
|
||||
}
|
||||
@ -263,13 +263,12 @@ bool RenderPass::BindDynamicResource(ShaderStage stage,
|
||||
return BindBuffer(stage, slot, std::move(resouce));
|
||||
}
|
||||
|
||||
bool RenderPass::BindDynamicResource(
|
||||
ShaderStage stage,
|
||||
DescriptorType type,
|
||||
const SampledImageSlot& slot,
|
||||
std::unique_ptr<ShaderMetadata> metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
const std::unique_ptr<const Sampler>& sampler) {
|
||||
bool RenderPass::BindDynamicResource(ShaderStage stage,
|
||||
DescriptorType type,
|
||||
const SampledImageSlot& slot,
|
||||
std::unique_ptr<ShaderMetadata> metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
raw_ptr<const Sampler> sampler) {
|
||||
if (!sampler) {
|
||||
return false;
|
||||
}
|
||||
@ -296,11 +295,11 @@ bool RenderPass::BindBuffer(ShaderStage stage,
|
||||
bool RenderPass::BindTexture(ShaderStage stage,
|
||||
const SampledImageSlot& slot,
|
||||
TextureResource resource,
|
||||
const std::unique_ptr<const Sampler>& sampler) {
|
||||
raw_ptr<const Sampler> sampler) {
|
||||
TextureAndSampler data = TextureAndSampler{
|
||||
.stage = stage,
|
||||
.texture = std::move(resource),
|
||||
.sampler = &sampler,
|
||||
.sampler = sampler,
|
||||
};
|
||||
|
||||
if (!bound_textures_start_.has_value()) {
|
||||
|
@ -179,22 +179,20 @@ class RenderPass : public ResourceBinder {
|
||||
BufferView view) override;
|
||||
|
||||
// |ResourceBinder|
|
||||
virtual bool BindResource(
|
||||
ShaderStage stage,
|
||||
DescriptorType type,
|
||||
const SampledImageSlot& slot,
|
||||
const ShaderMetadata* metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
const std::unique_ptr<const Sampler>& sampler) override;
|
||||
virtual bool BindResource(ShaderStage stage,
|
||||
DescriptorType type,
|
||||
const SampledImageSlot& slot,
|
||||
const ShaderMetadata* metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
raw_ptr<const Sampler>) override;
|
||||
|
||||
/// @brief Bind with dynamically generated shader metadata.
|
||||
virtual bool BindDynamicResource(
|
||||
ShaderStage stage,
|
||||
DescriptorType type,
|
||||
const SampledImageSlot& slot,
|
||||
std::unique_ptr<ShaderMetadata> metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
const std::unique_ptr<const Sampler>& sampler);
|
||||
virtual bool BindDynamicResource(ShaderStage stage,
|
||||
DescriptorType type,
|
||||
const SampledImageSlot& slot,
|
||||
std::unique_ptr<ShaderMetadata> metadata,
|
||||
std::shared_ptr<const Texture> texture,
|
||||
raw_ptr<const Sampler>);
|
||||
|
||||
/// @brief Bind with dynamically generated shader metadata.
|
||||
virtual bool BindDynamicResource(ShaderStage stage,
|
||||
@ -289,7 +287,7 @@ class RenderPass : public ResourceBinder {
|
||||
bool BindTexture(ShaderStage stage,
|
||||
const SampledImageSlot& slot,
|
||||
TextureResource resource,
|
||||
const std::unique_ptr<const Sampler>& sampler);
|
||||
raw_ptr<const Sampler>);
|
||||
|
||||
Command pending_;
|
||||
std::optional<size_t> bound_buffers_start_ = std::nullopt;
|
||||
|
@ -75,8 +75,7 @@ TEST_P(RendererTest, CanCreateBoxPrimitive) {
|
||||
auto bridge = CreateTextureForFixture("bay_bridge.jpg");
|
||||
auto boston = CreateTextureForFixture("boston.jpg");
|
||||
ASSERT_TRUE(bridge && boston);
|
||||
const std::unique_ptr<const Sampler>& sampler =
|
||||
context->GetSamplerLibrary()->GetSampler({});
|
||||
raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
|
||||
ASSERT_TRUE(sampler);
|
||||
|
||||
auto host_buffer = HostBuffer::Create(context->GetResourceAllocator(),
|
||||
@ -238,8 +237,7 @@ TEST_P(RendererTest, CanRenderPerspectiveCube) {
|
||||
auto device_buffer = context->GetResourceAllocator()->CreateBufferWithCopy(
|
||||
reinterpret_cast<uint8_t*>(&cube), sizeof(cube));
|
||||
|
||||
const std::unique_ptr<const Sampler>& sampler =
|
||||
context->GetSamplerLibrary()->GetSampler({});
|
||||
raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
|
||||
ASSERT_TRUE(sampler);
|
||||
|
||||
Vector3 euler_angles;
|
||||
@ -320,8 +318,7 @@ TEST_P(RendererTest, CanRenderMultiplePrimitives) {
|
||||
auto bridge = CreateTextureForFixture("bay_bridge.jpg");
|
||||
auto boston = CreateTextureForFixture("boston.jpg");
|
||||
ASSERT_TRUE(bridge && boston);
|
||||
const std::unique_ptr<const Sampler>& sampler =
|
||||
context->GetSamplerLibrary()->GetSampler({});
|
||||
raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
|
||||
ASSERT_TRUE(sampler);
|
||||
|
||||
auto host_buffer = HostBuffer::Create(context->GetResourceAllocator(),
|
||||
@ -398,8 +395,7 @@ TEST_P(RendererTest, CanRenderToTexture) {
|
||||
auto bridge = CreateTextureForFixture("bay_bridge.jpg");
|
||||
auto boston = CreateTextureForFixture("boston.jpg");
|
||||
ASSERT_TRUE(bridge && boston);
|
||||
const std::unique_ptr<const Sampler>& sampler =
|
||||
context->GetSamplerLibrary()->GetSampler({});
|
||||
raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
|
||||
ASSERT_TRUE(sampler);
|
||||
|
||||
std::shared_ptr<RenderPass> r2t_pass;
|
||||
@ -553,8 +549,7 @@ TEST_P(RendererTest, CanBlitTextureToTexture) {
|
||||
auto bridge = CreateTextureForFixture("bay_bridge.jpg");
|
||||
auto boston = CreateTextureForFixture("boston.jpg");
|
||||
ASSERT_TRUE(bridge && boston);
|
||||
const std::unique_ptr<const Sampler>& sampler =
|
||||
context->GetSamplerLibrary()->GetSampler({});
|
||||
raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
|
||||
ASSERT_TRUE(sampler);
|
||||
|
||||
// Vertex buffer.
|
||||
@ -619,7 +614,7 @@ TEST_P(RendererTest, CanBlitTextureToTexture) {
|
||||
frag_info.lod = 0;
|
||||
FS::BindFragInfo(*pass, host_buffer->EmplaceUniform(frag_info));
|
||||
|
||||
auto& sampler = context->GetSamplerLibrary()->GetSampler({});
|
||||
auto sampler = context->GetSamplerLibrary()->GetSampler({});
|
||||
FS::BindTex(*pass, texture, sampler);
|
||||
|
||||
pass->Draw();
|
||||
@ -656,8 +651,7 @@ TEST_P(RendererTest, CanBlitTextureToBuffer) {
|
||||
auto bridge = CreateTextureForFixture("bay_bridge.jpg");
|
||||
auto boston = CreateTextureForFixture("boston.jpg");
|
||||
ASSERT_TRUE(bridge && boston);
|
||||
const std::unique_ptr<const Sampler>& sampler =
|
||||
context->GetSamplerLibrary()->GetSampler({});
|
||||
raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
|
||||
ASSERT_TRUE(sampler);
|
||||
|
||||
TextureDescriptor texture_desc;
|
||||
@ -742,7 +736,7 @@ TEST_P(RendererTest, CanBlitTextureToBuffer) {
|
||||
frag_info.lod = 0;
|
||||
FS::BindFragInfo(*pass, host_buffer->EmplaceUniform(frag_info));
|
||||
|
||||
const std::unique_ptr<const Sampler>& sampler =
|
||||
raw_ptr<const Sampler> sampler =
|
||||
context->GetSamplerLibrary()->GetSampler({});
|
||||
auto buffer_view = DeviceBuffer::AsBufferView(device_buffer);
|
||||
auto texture =
|
||||
@ -872,7 +866,7 @@ TEST_P(RendererTest, CanGenerateMipmaps) {
|
||||
SamplerDescriptor sampler_desc;
|
||||
sampler_desc.mip_filter = mip_filters[selected_mip_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);
|
||||
FS::BindTex(*pass, boston, sampler);
|
||||
|
||||
@ -908,14 +902,14 @@ TEST_P(RendererTest, TheImpeller) {
|
||||
SamplerDescriptor noise_sampler_desc;
|
||||
noise_sampler_desc.width_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);
|
||||
|
||||
auto cube_map = CreateTextureCubeForFixture(
|
||||
{"table_mountain_px.png", "table_mountain_nx.png",
|
||||
"table_mountain_py.png", "table_mountain_ny.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({});
|
||||
auto host_buffer = HostBuffer::Create(context->GetResourceAllocator(),
|
||||
context->GetIdleWaiter());
|
||||
@ -1244,8 +1238,7 @@ TEST_P(RendererTest, StencilMask) {
|
||||
auto bridge = CreateTextureForFixture("bay_bridge.jpg");
|
||||
auto boston = CreateTextureForFixture("boston.jpg");
|
||||
ASSERT_TRUE(bridge && boston);
|
||||
const std::unique_ptr<const Sampler>& sampler =
|
||||
context->GetSamplerLibrary()->GetSampler({});
|
||||
raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
|
||||
ASSERT_TRUE(sampler);
|
||||
|
||||
static bool mirror = false;
|
||||
@ -1621,8 +1614,7 @@ TEST_P(RendererTest, BindingNullTexturesDoesNotCrash) {
|
||||
using FS = BoxFadeFragmentShader;
|
||||
|
||||
auto context = GetContext();
|
||||
const std::unique_ptr<const Sampler>& sampler =
|
||||
context->GetSamplerLibrary()->GetSampler({});
|
||||
raw_ptr<const Sampler> sampler = context->GetSamplerLibrary()->GetSampler({});
|
||||
auto command_buffer = context->CreateCommandBuffer();
|
||||
|
||||
RenderTargetAllocator allocator(context->GetResourceAllocator());
|
||||
|
@ -5,6 +5,7 @@
|
||||
#ifndef 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_descriptor.h"
|
||||
|
||||
@ -23,8 +24,8 @@ class SamplerLibrary {
|
||||
/// The sampler library implementations must cache this sampler object
|
||||
/// and guarantee that the reference will continue to be valid
|
||||
/// throughout the lifetime of the Impeller context.
|
||||
virtual const std::unique_ptr<const Sampler>& GetSampler(
|
||||
SamplerDescriptor descriptor) = 0;
|
||||
virtual raw_ptr<const Sampler> GetSampler(
|
||||
const SamplerDescriptor& descriptor) = 0;
|
||||
|
||||
protected:
|
||||
SamplerLibrary();
|
||||
|
@ -244,9 +244,9 @@ class MockCommandQueue : public CommandQueue {
|
||||
|
||||
class MockSamplerLibrary : public SamplerLibrary {
|
||||
public:
|
||||
MOCK_METHOD(const std::unique_ptr<const Sampler>&,
|
||||
MOCK_METHOD(raw_ptr<const Sampler>,
|
||||
GetSampler,
|
||||
(SamplerDescriptor descriptor),
|
||||
(const SamplerDescriptor& descriptor),
|
||||
(override));
|
||||
};
|
||||
|
||||
|
@ -192,7 +192,7 @@ bool RenderPass::Draw() {
|
||||
texture.slot,
|
||||
std::make_unique<impeller::ShaderMetadata>(
|
||||
*texture.texture.GetMetadata()),
|
||||
texture.texture.resource, *texture.sampler);
|
||||
texture.texture.resource, texture.sampler);
|
||||
}
|
||||
for (const auto& [_, buffer] : fragment_uniform_bindings) {
|
||||
render_pass_->BindDynamicResource(
|
||||
@ -207,7 +207,7 @@ bool RenderPass::Draw() {
|
||||
impeller::DescriptorType::kSampledImage, texture.slot,
|
||||
std::make_unique<impeller::ShaderMetadata>(
|
||||
*texture.texture.GetMetadata()),
|
||||
texture.texture.resource, *texture.sampler);
|
||||
texture.texture.resource, texture.sampler);
|
||||
}
|
||||
|
||||
render_pass_->SetVertexBuffer(vertex_buffer);
|
||||
@ -466,7 +466,7 @@ bool InternalFlutterGpu_RenderPass_BindTexture(
|
||||
flutter::gpu::ToImpellerSamplerAddressMode(width_address_mode);
|
||||
sampler_desc.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);
|
||||
|
||||
flutter::gpu::RenderPass::TextureUniformMap* uniform_map = nullptr;
|
||||
@ -486,7 +486,7 @@ bool InternalFlutterGpu_RenderPass_BindTexture(
|
||||
impeller::TextureAndSampler{
|
||||
.slot = texture_binding->slot,
|
||||
.texture = {&texture_binding->metadata, texture->GetTexture()},
|
||||
.sampler = &sampler,
|
||||
.sampler = sampler,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user