[Impeller] Bias towards sampling from lower mip levels (flutter/engine#42386)

Resolves https://github.com/flutter/flutter/issues/127174.

Sets the same mip bias as Skia uses. Biases towards sampling from lower
(larger) mip levels -- the tradeoff is a slightly higher cache miss rate
in exchange for sharper/less blurry bilinear min-filtered images.

This makes scaled down images render identically between Impeller and
Skia.
This commit is contained in:
Brandon DeRosier
2023-05-30 08:44:48 -07:00
committed by GitHub
parent 979e3c25fd
commit d8c494c3d8
19 changed files with 276 additions and 258 deletions

View File

@@ -1090,6 +1090,7 @@ ORIGIN: ../../../flutter/impeller/compiler/shader_lib/impeller/blending.glsl + .
ORIGIN: ../../../flutter/impeller/compiler/shader_lib/impeller/branching.glsl + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/compiler/shader_lib/impeller/color.glsl + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/compiler/shader_lib/impeller/constants.glsl + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/compiler/shader_lib/impeller/conversions.glsl + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/compiler/shader_lib/impeller/gaussian.glsl + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/compiler/shader_lib/impeller/gradient.glsl + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/compiler/shader_lib/impeller/path.glsl + ../../../flutter/LICENSE
@@ -3747,6 +3748,7 @@ FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/blending.glsl
FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/branching.glsl
FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/color.glsl
FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/constants.glsl
FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/conversions.glsl
FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/gaussian.glsl
FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/gradient.glsl
FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/path.glsl

View File

@@ -8,6 +8,7 @@ copy("impeller") {
"branching.glsl",
"color.glsl",
"constants.glsl",
"conversions.glsl",
"gaussian.glsl",
"gradient.glsl",
"path.glsl",

View File

@@ -24,4 +24,8 @@ const float kHalfSqrtTwo = 0.70710678118;
// sqrt(3)
const float kSqrtThree = 1.73205080757;
const float kDefaultMipBias = -0.475;
const float kDefaultMipBiasHalf = -0.475hf;
#endif

View File

@@ -0,0 +1,15 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONVERSIONS_GLSL_
#define CONVERSIONS_GLSL_
vec2 IPRemapCoords(vec2 coords, float y_coord_scale) {
if (y_coord_scale < 0.0) {
coords.y = 1.0 - coords.y;
}
return coords;
}
#endif

View File

@@ -6,6 +6,7 @@
#define TEXTURE_GLSL_
#include <impeller/branching.glsl>
#include <impeller/conversions.glsl>
#include <impeller/types.glsl>
/// Sample from a texture.
@@ -14,17 +15,8 @@
/// for Impeller graphics backends that use a flipped framebuffer coordinate
/// space.
vec4 IPSample(sampler2D texture_sampler, vec2 coords, float y_coord_scale) {
if (y_coord_scale < 0.0) {
coords.y = 1.0 - coords.y;
}
return texture(texture_sampler, coords);
}
vec2 IPRemapCoords(vec2 coords, float y_coord_scale) {
if (y_coord_scale < 0.0) {
coords.y = 1.0 - coords.y;
}
return coords;
return texture(texture_sampler, IPRemapCoords(coords, y_coord_scale),
kDefaultMipBias);
}
/// Sample from a texture.
@@ -90,7 +82,7 @@ vec4 IPSampleWithTileMode(sampler2D tex,
return vec4(0);
}
return texture(tex, coords);
return texture(tex, coords, kDefaultMipBias);
}
const float16_t kTileModeDecalHf = 3.0hf;
@@ -108,7 +100,7 @@ f16vec4 IPHalfSampleWithTileMode(f16sampler2D tex,
return f16vec4(0.0hf);
}
return texture(tex, coords);
return texture(tex, coords, kDefaultMipBiasHalf);
}
/// Sample a texture, emulating a specific tile mode.
@@ -138,7 +130,7 @@ vec4 IPSampleDecal(sampler2D texture_sampler, vec2 coords) {
any(greaterThanEqual(coords, vec2(1)))) {
return vec4(0);
}
return texture(texture_sampler, coords);
return texture(texture_sampler, coords, kDefaultMipBias);
}
/// Sample a texture with decal tile mode.
@@ -147,7 +139,7 @@ f16vec4 IPHalfSampleDecal(f16sampler2D texture_sampler, vec2 coords) {
any(greaterThanEqual(coords, vec2(1)))) {
return f16vec4(0.0);
}
return texture(texture_sampler, coords);
return texture(texture_sampler, coords, kDefaultMipBiasHalf);
}
/// Sample a texture, emulating a specific tile mode.

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <impeller/texture.glsl>
#include <impeller/conversions.glsl>
#include <impeller/types.glsl>
uniform FrameInfo {

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <impeller/texture.glsl>
#include <impeller/conversions.glsl>
#include <impeller/types.glsl>
uniform FrameInfo {

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <impeller/texture.glsl>
#include <impeller/conversions.glsl>
#include <impeller/types.glsl>
uniform FrameInfo {

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <impeller/texture.glsl>
#include <impeller/conversions.glsl>
#include <impeller/types.glsl>
uniform FrameInfo {

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <impeller/texture.glsl>
#include <impeller/conversions.glsl>
#include <impeller/types.glsl>
uniform FrameInfo {

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <impeller/texture.glsl>
#include <impeller/conversions.glsl>
#include <impeller/types.glsl>
uniform FrameInfo {

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <impeller/texture.glsl>
#include <impeller/conversions.glsl>
#include <impeller/types.glsl>
uniform FrameInfo {

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <impeller/texture.glsl>
#include <impeller/conversions.glsl>
#include <impeller/types.glsl>
uniform FrameInfo {

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <impeller/texture.glsl>
#include <impeller/conversions.glsl>
#include <impeller/types.glsl>
uniform FrameInfo {

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <impeller/constants.glsl>
#include <impeller/types.glsl>
uniform f16sampler2D texture_sampler;
@@ -16,6 +17,7 @@ in highp vec2 v_texture_coords;
out f16vec4 frag_color;
void main() {
f16vec4 sampled = texture(texture_sampler, v_texture_coords);
f16vec4 sampled =
texture(texture_sampler, v_texture_coords, kDefaultMipBiasHalf);
frag_color = sampled * frag_info.alpha;
}

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <impeller/texture.glsl>
#include <impeller/conversions.glsl>
#include <impeller/types.glsl>
uniform FrameInfo {

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <impeller/texture.glsl>
#include <impeller/conversions.glsl>
#include <impeller/types.glsl>
uniform FrameInfo {

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <impeller/texture.glsl>
#include <impeller/conversions.glsl>
#include <impeller/types.glsl>
uniform FrameInfo {

File diff suppressed because it is too large Load Diff