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
3 changes: 1 addition & 2 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ TEST_P(AiksTest, CanRenderTiledTexture) {
Entity::TileMode::kClamp, Entity::TileMode::kRepeat,
Entity::TileMode::kMirror, Entity::TileMode::kDecal};
const char* mip_filter_names[] = {"None", "Nearest", "Linear"};
const MipFilter mip_filters[] = {MipFilter::kNone, MipFilter::kNearest,
MipFilter::kLinear};
const MipFilter mip_filters[] = {MipFilter::kNearest, MipFilter::kLinear};
const char* min_mag_filter_names[] = {"Nearest", "Linear"};
const MinMagFilter min_mag_filters[] = {MinMagFilter::kNearest,
MinMagFilter::kLinear};
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/text_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static bool CommonRender(
sampler_desc.min_filter = MinMagFilter::kLinear;
sampler_desc.mag_filter = MinMagFilter::kLinear;
}
sampler_desc.mip_filter = MipFilter::kNone;
sampler_desc.mip_filter = MipFilter::kNearest;

typename FS::FragInfo frag_info;
frag_info.text_color = ToVector(color.Premultiply());
Expand Down
34 changes: 22 additions & 12 deletions impeller/renderer/backend/gles/sampler_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

#include "impeller/renderer/backend/gles/sampler_gles.h"
#include <iostream>

#include "impeller/renderer/backend/gles/formats_gles.h"
#include "impeller/renderer/backend/gles/proc_table_gles.h"
Expand All @@ -19,15 +20,19 @@ bool SamplerGLES::IsValid() const {
return true;
}

static GLint ToParam(MinMagFilter minmag_filter, MipFilter mip_filter) {
switch (mip_filter) {
case MipFilter::kNone:
Copy link
Member

@bdero bdero Mar 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think sampling with GL_[NEAREST|LINEAR]_MIPMAP_[NEAREST|LINEAR] will fail in GLES if the mip count is 1, and either GL_NEAREST or GL_LINEAR needs to be set when this is the case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please verify that this doesn't break the GLES playgrounds if landing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can retain this behavior for now without the enum variant. Make the mip_filter optional and treat nullopt as if it were none.

Copy link
Member

@bdero bdero Mar 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be addressed for the min filter. Right now, if a texture has a mip count of 1 (as all subpass and filter-created textures do), it will get a min filter that includes mipmap sampling. This will fail and sample with all zeros on some drivers:
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh yeah, got it

Copy link
Member

@bdero bdero Mar 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The capture above is Play/DisplayListTest.CanDrawBackdropFilter/OpenGLES, which was rendering nothing a couple of days ago on both M1 Mac and the Windows Nvidia driver prior to this fix: https://github.com/flutter/engine/pull/40425/files

switch (minmag_filter) {
case MinMagFilter::kNearest:
return GL_NEAREST;
case MinMagFilter::kLinear:
return GL_LINEAR;
}
static GLint ToParam(MinMagFilter minmag_filter,
std::optional<MipFilter> mip_filter = std::nullopt) {
if (!mip_filter.has_value()) {
switch (minmag_filter) {
case MinMagFilter::kNearest:
return GL_NEAREST;
case MinMagFilter::kLinear:
return GL_LINEAR;
}
FML_UNREACHABLE();
}

switch (mip_filter.value()) {
case MipFilter::kNearest:
switch (minmag_filter) {
case MinMagFilter::kNearest:
Expand Down Expand Up @@ -69,12 +74,17 @@ bool SamplerGLES::ConfigureBoundTexture(const TextureGLES& texture,
if (!target.has_value()) {
return false;
}

const auto& desc = GetDescriptor();

std::optional<MipFilter> mip_filter = std::nullopt;
if (texture.GetTextureDescriptor().mip_count > 1) {
mip_filter = desc.mip_filter;
}

gl.TexParameteri(target.value(), GL_TEXTURE_MIN_FILTER,
ToParam(desc.min_filter, desc.mip_filter));
ToParam(desc.min_filter, mip_filter));
gl.TexParameteri(target.value(), GL_TEXTURE_MAG_FILTER,
ToParam(desc.mag_filter, MipFilter::kNone));
ToParam(desc.mag_filter));
gl.TexParameteri(target.value(), GL_TEXTURE_WRAP_S,
ToAddressMode(desc.width_address_mode));
gl.TexParameteri(target.value(), GL_TEXTURE_WRAP_T,
Expand Down
2 changes: 0 additions & 2 deletions impeller/renderer/backend/metal/formats_mtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,6 @@ constexpr MTLSamplerMinMagFilter ToMTLSamplerMinMagFilter(MinMagFilter filter) {

constexpr MTLSamplerMipFilter ToMTLSamplerMipFilter(MipFilter filter) {
switch (filter) {
case MipFilter::kNone:
return MTLSamplerMipFilterNotMipmapped;
case MipFilter::kNearest:
return MTLSamplerMipFilterNearest;
case MipFilter::kLinear:
Expand Down
2 changes: 0 additions & 2 deletions impeller/renderer/backend/vulkan/formats_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,6 @@ constexpr vk::SamplerMipmapMode ToVKSamplerMipmapMode(MipFilter filter) {
return vk::SamplerMipmapMode::eNearest;
case MipFilter::kLinear:
return vk::SamplerMipmapMode::eLinear;
case MipFilter::kNone:
return vk::SamplerMipmapMode::eNearest;
}

FML_UNREACHABLE();
Expand Down
2 changes: 0 additions & 2 deletions impeller/renderer/formats.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,6 @@ enum class MinMagFilter {
};

enum class MipFilter {
/// Always sample from mip level 0. Other mip levels are ignored.
kNone,
/// Sample from the nearest mip level.
kNearest,
/// Sample from the two nearest mip levels and linearly interpolate between
Expand Down
7 changes: 3 additions & 4 deletions impeller/renderer/renderer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -724,15 +724,14 @@ TEST_P(RendererTest, CanGenerateMipmaps) {

bool first_frame = true;
Renderer::RenderCallback callback = [&](RenderTarget& render_target) {
const char* mip_filter_names[] = {"None", "Nearest", "Linear"};
const MipFilter mip_filters[] = {MipFilter::kNone, MipFilter::kNearest,
MipFilter::kLinear};
const char* mip_filter_names[] = {"Nearest", "Linear"};
const MipFilter mip_filters[] = {MipFilter::kNearest, MipFilter::kLinear};
const char* min_filter_names[] = {"Nearest", "Linear"};
const MinMagFilter min_filters[] = {MinMagFilter::kNearest,
MinMagFilter::kLinear};

// UI state.
static int selected_mip_filter = 2;
static int selected_mip_filter = 1;
static int selected_min_filter = 0;
static float lod = 4.5;

Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/sampler_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Context;
struct SamplerDescriptor final : public Comparable<SamplerDescriptor> {
MinMagFilter min_filter = MinMagFilter::kNearest;
MinMagFilter mag_filter = MinMagFilter::kNearest;
MipFilter mip_filter = MipFilter::kNone;
MipFilter mip_filter = MipFilter::kNearest;

SamplerAddressMode width_address_mode = SamplerAddressMode::kClampToEdge;
SamplerAddressMode height_address_mode = SamplerAddressMode::kClampToEdge;
Expand Down
2 changes: 1 addition & 1 deletion impeller/scene/geometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void SkinnedVertexBufferGeometry::BindToCommand(
SamplerDescriptor sampler_desc;
sampler_desc.min_filter = MinMagFilter::kNearest;
sampler_desc.mag_filter = MinMagFilter::kNearest;
sampler_desc.mip_filter = MipFilter::kNone;
sampler_desc.mip_filter = MipFilter::kNearest;
sampler_desc.width_address_mode = SamplerAddressMode::kRepeat;
sampler_desc.label = "NN Repeat";

Expand Down