Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion impeller/compiler/reflector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ std::vector<Reflector::BindPrototype> Reflector::ReflectBindPrototypes(
.argument_name = "texture",
});
proto.args.push_back(BindPrototypeArgument{
.type_name = "std::shared_ptr<const Sampler>",
.type_name = "const std::unique_ptr<const Sampler>&",
.argument_name = "sampler",
});
}
Expand Down
2 changes: 1 addition & 1 deletion impeller/core/resource_binder.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct ResourceBinder {
const SampledImageSlot& slot,
const ShaderMetadata& metadata,
std::shared_ptr<const Texture> texture,
std::shared_ptr<const Sampler> sampler) = 0;
const std::unique_ptr<const Sampler>& sampler) = 0;
};

} // namespace impeller
Expand Down
4 changes: 1 addition & 3 deletions impeller/core/sampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class Sampler {
public:
virtual ~Sampler();

virtual bool IsValid() const = 0;

const SamplerDescriptor& GetDescriptor() const;

protected:
Expand All @@ -32,7 +30,7 @@ class Sampler {
};

using SamplerMap = std::unordered_map<SamplerDescriptor,
std::shared_ptr<const Sampler>,
std::unique_ptr<const Sampler>,
ComparableHash<SamplerDescriptor>,
ComparableEqual<SamplerDescriptor>>;

Expand Down
5 changes: 3 additions & 2 deletions impeller/entity/contents/atlas_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,9 @@ bool AtlasContents::Render(const ContentContext& renderer,
dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
}
auto dst_sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler(
dst_sampler_descriptor);
const std::unique_ptr<const Sampler>& dst_sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
dst_sampler_descriptor);
FS::BindTextureSamplerDst(pass, texture_, dst_sampler);
frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();

Expand Down
25 changes: 15 additions & 10 deletions impeller/entity/contents/filters/blend_filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ static std::optional<Entity> AdvancedBlend(
dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
}
auto dst_sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler(
dst_sampler_descriptor);
const std::unique_ptr<const Sampler>& dst_sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
dst_sampler_descriptor);
FS::BindTextureSamplerDst(pass, dst_snapshot->texture, dst_sampler);
frame_info.dst_y_coord_scale = dst_snapshot->texture->GetYCoordScale();
blend_info.dst_input_alpha =
Expand All @@ -201,8 +202,9 @@ static std::optional<Entity> AdvancedBlend(
src_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
src_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
}
auto src_sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler(
src_sampler_descriptor);
const std::unique_ptr<const Sampler>& src_sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
src_sampler_descriptor);
blend_info.color_factor = 0;
blend_info.src_input_alpha = src_snapshot->opacity;
FS::BindTextureSamplerSrc(pass, src_snapshot->texture, src_sampler);
Expand Down Expand Up @@ -351,8 +353,9 @@ std::optional<Entity> BlendFilterContents::CreateForegroundAdvancedBlend(
dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
}
auto dst_sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler(
dst_sampler_descriptor);
const std::unique_ptr<const Sampler>& dst_sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
dst_sampler_descriptor);
FS::BindTextureSamplerDst(pass, dst_snapshot->texture, dst_sampler);
frame_info.dst_y_coord_scale = dst_snapshot->texture->GetYCoordScale();
blend_info.dst_input_alpha =
Expand Down Expand Up @@ -473,8 +476,9 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(
dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
}
auto dst_sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler(
dst_sampler_descriptor);
const std::unique_ptr<const Sampler>& dst_sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
dst_sampler_descriptor);
FS::BindTextureSamplerDst(pass, dst_snapshot->texture, dst_sampler);
frame_info.texture_sampler_y_coord_scale =
dst_snapshot->texture->GetYCoordScale();
Expand Down Expand Up @@ -570,8 +574,9 @@ static std::optional<Entity> PipelineBlend(
return false;
}

auto sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler(
input->sampler_descriptor);
const std::unique_ptr<const Sampler>& sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
input->sampler_descriptor);
FS::BindTextureSamplerSrc(pass, input->texture, sampler);

auto size = input->texture->GetSize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ std::optional<Entity> BorderMaskBlurFilterContents::RenderFilter(
FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));

auto sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
const std::unique_ptr<const Sampler>& sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
FS::BindTextureSampler(pass, input_snapshot->texture, sampler);

return pass.Draw().ok();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ std::optional<Entity> ColorMatrixFilterContents::RenderFilter(
absorb_opacity == ColorFilterContents::AbsorbOpacity::kYes
? input_snapshot->opacity
: 1.0f;
auto sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
const std::unique_ptr<const Sampler>& sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
FS::BindInputTexture(pass, input_snapshot->texture, sampler);
FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ std::optional<Entity> SrgbToLinearFilterContents::RenderFilter(
? input_snapshot->opacity
: 1.0f;

auto sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
const std::unique_ptr<const Sampler>& sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
FS::BindInputTexture(pass, input_snapshot->texture, sampler);
FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ std::optional<Entity> YUVToRGBFilterContents::RenderFilter(
break;
}

auto sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
const std::unique_ptr<const Sampler>& sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
FS::BindYTexture(pass, y_input_snapshot->texture, sampler);
FS::BindUvTexture(pass, uv_input_snapshot->texture, sampler);

Expand Down
5 changes: 3 additions & 2 deletions impeller/entity/contents/framebuffer_blend_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ bool FramebufferBlendContents::Render(const ContentContext& renderer,
src_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
src_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
}
auto src_sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler(
src_sampler_descriptor);
const std::unique_ptr<const Sampler>& src_sampler =
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
src_sampler_descriptor);
FS::BindTextureSamplerSrc(pass, src_snapshot->texture, src_sampler);

frame_info.mvp = pass.GetOrthographicTransform() * src_snapshot->transform;
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/runtime_effect_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
FML_DCHECK(sampler_index < texture_inputs_.size());
auto& input = texture_inputs_[sampler_index];

auto sampler =
const std::unique_ptr<const Sampler>& sampler =
context->GetSamplerLibrary()->GetSampler(input.sampler_descriptor);

SampledImageSlot image_slot;
Expand Down
13 changes: 7 additions & 6 deletions impeller/entity/contents/test/recording_render_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ bool RecordingRenderPass::BindResource(
}

// |RenderPass|
bool RecordingRenderPass::BindResource(ShaderStage stage,
DescriptorType type,
const SampledImageSlot& slot,
const ShaderMetadata& metadata,
std::shared_ptr<const Texture> texture,
std::shared_ptr<const Sampler> sampler) {
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) {
pending_.BindResource(stage, type, slot, metadata, texture, sampler);
return delegate_->BindResource(stage, type, slot, metadata, texture, sampler);
}
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/test/recording_render_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class RecordingRenderPass : public RenderPass {
const SampledImageSlot& slot,
const ShaderMetadata& metadata,
std::shared_ptr<const Texture> texture,
std::shared_ptr<const Sampler> sampler) override;
const std::unique_ptr<const Sampler>& sampler) override;

// |RenderPass|
void OnSetLabel(std::string label) override;
Expand Down
11 changes: 7 additions & 4 deletions impeller/playground/imgui/imgui_impl_impeller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@
#include "impeller/renderer/render_pass.h"

struct ImGui_ImplImpeller_Data {
explicit ImGui_ImplImpeller_Data(
const std::unique_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;
std::shared_ptr<const impeller::Sampler> sampler;
const std::unique_ptr<const impeller::Sampler>& sampler;
};

static ImGui_ImplImpeller_Data* ImGui_ImplImpeller_GetBackendData() {
Expand All @@ -56,7 +60,8 @@ bool ImGui_ImplImpeller_Init(
"Already initialized a renderer backend!");

// Setup backend capabilities flags
auto* bd = new ImGui_ImplImpeller_Data();
auto* bd =
new ImGui_ImplImpeller_Data(context->GetSamplerLibrary()->GetSampler({}));
io.BackendRendererUserData = reinterpret_cast<void*>(bd);
io.BackendRendererName = "imgui_impl_impeller";
io.BackendFlags |=
Expand Down Expand Up @@ -105,8 +110,6 @@ bool ImGui_ImplImpeller_Init(
bd->pipeline =
context->GetPipelineLibrary()->GetPipeline(std::move(desc)).Get();
IM_ASSERT(bd->pipeline != nullptr && "Could not create ImGui pipeline.");

bd->sampler = context->GetSamplerLibrary()->GetSampler({});
IM_ASSERT(bd->pipeline != nullptr && "Could not create ImGui sampler.");
}

Expand Down
10 changes: 0 additions & 10 deletions impeller/renderer/backend/gles/sampler_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include "impeller/renderer/backend/gles/sampler_gles.h"

#include <iostream>

#include "impeller/base/validation.h"
#include "impeller/core/formats.h"
#include "impeller/renderer/backend/gles/formats_gles.h"
Expand All @@ -18,10 +16,6 @@ SamplerGLES::SamplerGLES(SamplerDescriptor desc) : Sampler(std::move(desc)) {}

SamplerGLES::~SamplerGLES() = default;

bool SamplerGLES::IsValid() const {
return true;
}

static GLint ToParam(MinMagFilter minmag_filter,
std::optional<MipFilter> mip_filter = std::nullopt) {
if (!mip_filter.has_value()) {
Expand Down Expand Up @@ -74,10 +68,6 @@ static GLint ToAddressMode(SamplerAddressMode mode,

bool SamplerGLES::ConfigureBoundTexture(const TextureGLES& texture,
const ProcTableGLES& gl) const {
if (!IsValid()) {
return false;
}

if (texture.NeedsMipmapGeneration()) {
VALIDATION_LOG
<< "Texture mip count is > 1, but the mipmap has not been generated. "
Expand Down
3 changes: 0 additions & 3 deletions impeller/renderer/backend/gles/sampler_gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ class SamplerGLES final : public Sampler,

explicit SamplerGLES(SamplerDescriptor desc);

// |Sampler|
bool IsValid() const override;

SamplerGLES(const SamplerGLES&) = delete;

SamplerGLES& operator=(const SamplerGLES&) = delete;
Expand Down
10 changes: 6 additions & 4 deletions impeller/renderer/backend/gles/sampler_library_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

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) {}
Expand All @@ -19,23 +21,23 @@ SamplerLibraryGLES::SamplerLibraryGLES(bool supports_decal_sampler_address_mode)
SamplerLibraryGLES::~SamplerLibraryGLES() = default;

// |SamplerLibrary|
std::shared_ptr<const Sampler> SamplerLibraryGLES::GetSampler(
const std::unique_ptr<const Sampler>& SamplerLibraryGLES::GetSampler(
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 nullptr;
return kNullSampler;
}

auto found = samplers_.find(descriptor);
if (found != samplers_.end()) {
return found->second;
}
return samplers_[descriptor] =
std::shared_ptr<SamplerGLES>(new SamplerGLES(descriptor));
return (samplers_[descriptor] =
std::unique_ptr<SamplerGLES>(new SamplerGLES(descriptor)));
}

} // namespace impeller
3 changes: 2 additions & 1 deletion impeller/renderer/backend/gles/sampler_library_gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_SAMPLER_LIBRARY_GLES_H_
#define FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_SAMPLER_LIBRARY_GLES_H_

#include "impeller/core/sampler.h"
#include "impeller/core/sampler_descriptor.h"
#include "impeller/renderer/sampler_library.h"

Expand All @@ -24,7 +25,7 @@ class SamplerLibraryGLES final : public SamplerLibrary {
SamplerLibraryGLES();

// |SamplerLibrary|
std::shared_ptr<const Sampler> GetSampler(
const std::unique_ptr<const Sampler>& GetSampler(
SamplerDescriptor descriptor) override;

bool supports_decal_sampler_address_mode_ = false;
Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/metal/compute_pass_mtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ComputePassMTL final : public ComputePass {
const SampledImageSlot& slot,
const ShaderMetadata& metadata,
std::shared_ptr<const Texture> texture,
std::shared_ptr<const Sampler> sampler) override;
const std::unique_ptr<const Sampler>& sampler) override;

// |ComputePass|
bool EncodeCommands() const override;
Expand Down
15 changes: 8 additions & 7 deletions impeller/renderer/backend/metal/compute_pass_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@
}

// |ComputePass|
bool ComputePassMTL::BindResource(ShaderStage stage,
DescriptorType type,
const SampledImageSlot& slot,
const ShaderMetadata& metadata,
std::shared_ptr<const Texture> texture,
std::shared_ptr<const Sampler> sampler) {
if (!sampler->IsValid() || !texture->IsValid()) {
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) {
if (!sampler || !texture->IsValid()) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/metal/render_pass_mtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class RenderPassMTL final : public RenderPass {
const SampledImageSlot& slot,
const ShaderMetadata& metadata,
std::shared_ptr<const Texture> texture,
std::shared_ptr<const Sampler> sampler) override;
const std::unique_ptr<const Sampler>& sampler) override;

RenderPassMTL(const RenderPassMTL&) = delete;

Expand Down
Loading