From f7a808161170a85ce387a5cbdfa76a78ccb23b98 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 21 Nov 2022 15:46:12 -0800 Subject: [PATCH 1/6] [Impeller] use explicit half types --- .../shader_lib/impeller/blending.glsl | 129 +++++++++--------- .../shader_lib/impeller/branching.glsl | 32 ++--- .../compiler/shader_lib/impeller/color.glsl | 13 +- .../shader_lib/impeller/constants.glsl | 10 +- .../shader_lib/impeller/gaussian.glsl | 35 ++--- .../shader_lib/impeller/gradient.glsl | 13 +- .../compiler/shader_lib/impeller/texture.glsl | 87 ++++++------ .../compiler/shader_lib/impeller/types.glsl | 21 +++ impeller/entity/BUILD.gn | 1 + impeller/entity/shaders/atlas_fill.frag | 17 +-- impeller/entity/shaders/atlas_fill.vert | 12 +- .../shaders/blending/advanced_blend.glsl | 30 ++-- .../shaders/blending/advanced_blend.vert | 10 +- .../blending/advanced_blend_color.frag | 3 +- .../blending/advanced_blend_colorburn.frag | 3 +- .../blending/advanced_blend_colordodge.frag | 3 +- .../blending/advanced_blend_darken.frag | 3 +- .../blending/advanced_blend_difference.frag | 3 +- .../blending/advanced_blend_exclusion.frag | 3 +- .../blending/advanced_blend_hardlight.frag | 3 +- .../shaders/blending/advanced_blend_hue.frag | 3 +- .../blending/advanced_blend_lighten.frag | 3 +- .../blending/advanced_blend_luminosity.frag | 3 +- .../blending/advanced_blend_multiply.frag | 3 +- .../blending/advanced_blend_overlay.frag | 3 +- .../blending/advanced_blend_saturation.frag | 3 +- .../blending/advanced_blend_screen.frag | 3 +- .../blending/advanced_blend_softlight.frag | 3 +- impeller/entity/shaders/blending/blend.frag | 9 +- impeller/entity/shaders/blending/blend.vert | 6 +- impeller/entity/shaders/border_mask_blur.frag | 37 ++--- impeller/entity/shaders/border_mask_blur.vert | 22 +-- .../shaders/color_matrix_color_filter.frag | 21 +-- .../shaders/color_matrix_color_filter.vert | 2 + impeller/entity/shaders/gaussian_blur.frag | 45 +++--- impeller/entity/shaders/gaussian_blur.vert | 10 +- impeller/entity/shaders/glyph_atlas.frag | 30 ++-- impeller/entity/shaders/glyph_atlas.vert | 21 +-- impeller/entity/shaders/glyph_atlas_sdf.vert | 1 + impeller/entity/shaders/gradient_fill.vert | 1 + .../entity/shaders/linear_gradient_fill.frag | 27 ++-- .../shaders/linear_gradient_ssbo_fill.frag | 31 +++-- .../entity/shaders/linear_to_srgb_filter.frag | 17 +-- .../entity/shaders/linear_to_srgb_filter.vert | 6 +- .../entity/shaders/morphology_filter.frag | 35 ++--- .../entity/shaders/morphology_filter.vert | 8 +- impeller/entity/shaders/position.vert | 7 +- impeller/entity/shaders/position_color.vert | 5 +- impeller/entity/shaders/position_uv.vert | 1 + .../entity/shaders/radial_gradient_fill.frag | 25 ++-- .../shaders/radial_gradient_ssbo_fill.frag | 29 ++-- impeller/entity/shaders/rrect_blur.frag | 57 ++++---- impeller/entity/shaders/rrect_blur.vert | 2 + impeller/entity/shaders/runtime_effect.vert | 1 + impeller/entity/shaders/solid_fill.frag | 2 + impeller/entity/shaders/solid_fill.vert | 2 + .../entity/shaders/srgb_to_linear_filter.frag | 19 +-- .../entity/shaders/srgb_to_linear_filter.vert | 2 + .../entity/shaders/sweep_gradient_fill.frag | 27 ++-- .../shaders/sweep_gradient_ssbo_fill.frag | 31 +++-- impeller/entity/shaders/test.frag | 19 +++ impeller/entity/shaders/texture_fill.frag | 9 +- impeller/entity/shaders/texture_fill.vert | 2 + .../entity/shaders/tiled_texture_fill.frag | 13 +- .../entity/shaders/tiled_texture_fill.vert | 1 + impeller/entity/shaders/vertices.frag | 2 + .../entity/shaders/yuv_to_rgb_filter.frag | 25 ++-- .../entity/shaders/yuv_to_rgb_filter.vert | 2 + 68 files changed, 594 insertions(+), 473 deletions(-) create mode 100644 impeller/entity/shaders/test.frag diff --git a/impeller/compiler/shader_lib/impeller/blending.glsl b/impeller/compiler/shader_lib/impeller/blending.glsl index f92e6bc4ab9a0..649d86d0b0e54 100644 --- a/impeller/compiler/shader_lib/impeller/blending.glsl +++ b/impeller/compiler/shader_lib/impeller/blending.glsl @@ -5,6 +5,7 @@ #ifndef BLENDING_GLSL_ #define BLENDING_GLSL_ +#include #include #include @@ -12,41 +13,41 @@ /// HSV utilities. /// -float IPLuminosity(vec3 color) { - return color.r * 0.3 + color.g * 0.59 + color.b * 0.11; +float16_t IPLuminosity(f16vec3 color) { + return color.r * 0.3hf + color.g * 0.59hf + color.b * 0.11hf; } /// Scales the color's luma by the amount necessary to place the color /// components in a 1-0 range. -vec3 IPClipColor(vec3 color) { - float lum = IPLuminosity(color); - float mn = min(min(color.r, color.g), color.b); - float mx = max(max(color.r, color.g), color.b); +f16vec3 IPClipColor(f16vec3 color) { + float16_t lum = IPLuminosity(color); + float16_t mn = min(min(color.r, color.g), color.b); + float16_t mx = max(max(color.r, color.g), color.b); // `lum - mn` and `mx - lum` will always be >= 0 in the following conditions, // so adding a tiny value is enough to make these divisions safe. - if (mn < 0) { - color = lum + (((color - lum) * lum) / (lum - mn + kEhCloseEnough)); + if (mn < 0.0hf) { + color = lum + (((color - lum) * lum) / (lum - mn + float16_t(kEhCloseEnough))); } - if (mx > 1) { - color = lum + (((color - lum) * (1 - lum)) / (mx - lum + kEhCloseEnough)); + if (mx > 1.0hf) { + color = lum + (((color - lum) * (1.0hf - lum)) / (mx - lum + float16_t(kEhCloseEnough))); } return color; } -vec3 IPSetLuminosity(vec3 color, float luminosity) { - float relative_lum = luminosity - IPLuminosity(color); +f16vec3 IPSetLuminosity(f16vec3 color, float16_t luminosity) { + float16_t relative_lum = luminosity - IPLuminosity(color); return IPClipColor(color + relative_lum); } -float IPSaturation(vec3 color) { +float16_t IPSaturation(f16vec3 color) { return max(max(color.r, color.g), color.b) - min(min(color.r, color.g), color.b); } -vec3 IPSetSaturation(vec3 color, float saturation) { - float mn = min(min(color.r, color.g), color.b); - float mx = max(max(color.r, color.g), color.b); - return (mn < mx) ? ((color - mn) * saturation) / (mx - mn) : vec3(0); +f16vec3 IPSetSaturation(f16vec3 color, float16_t saturation) { + float16_t mn = min(min(color.r, color.g), color.b); + float16_t mx = max(max(color.r, color.g), color.b); + return (mn < mx) ? ((color - mn) * saturation) / (mx - mn) : f16vec3(0); } //------------------------------------------------------------------------------ @@ -58,134 +59,134 @@ vec3 IPSetSaturation(vec3 color, float saturation) { /// applied to the destination using `SourceOver` alpha compositing. /// -vec3 IPBlendScreen(vec3 dst, vec3 src) { +f16vec3 IPBlendScreen(f16vec3 dst, f16vec3 src) { // https://www.w3.org/TR/compositing-1/#blendingscreen return dst + src - (dst * src); } -vec3 IPBlendHardLight(vec3 dst, vec3 src) { +f16vec3 IPBlendHardLight(f16vec3 dst, f16vec3 src) { // https://www.w3.org/TR/compositing-1/#blendinghardlight - return IPVec3Choose(dst * (2 * src), IPBlendScreen(dst, 2 * src - 1), src); + return IPVec3Choose(dst * (2.0hf * src), IPBlendScreen(dst, 2.0hf * src - 1.0hf), src); } -vec3 IPBlendOverlay(vec3 dst, vec3 src) { +f16vec3 IPBlendOverlay(f16vec3 dst, f16vec3 src) { // https://www.w3.org/TR/compositing-1/#blendingoverlay // HardLight, but with reversed parameters. return IPBlendHardLight(src, dst); } -vec3 IPBlendDarken(vec3 dst, vec3 src) { +f16vec3 IPBlendDarken(f16vec3 dst, f16vec3 src) { // https://www.w3.org/TR/compositing-1/#blendingdarken return min(dst, src); } -vec3 IPBlendLighten(vec3 dst, vec3 src) { +f16vec3 IPBlendLighten(f16vec3 dst, f16vec3 src) { // https://www.w3.org/TR/compositing-1/#blendinglighten return max(dst, src); } -vec3 IPBlendColorDodge(vec3 dst, vec3 src) { +f16vec3 IPBlendColorDodge(f16vec3 dst, f16vec3 src) { // https://www.w3.org/TR/compositing-1/#blendingcolordodge - vec3 color = min(vec3(1), dst / (1 - src)); + f16vec3 color = min(f16vec3(1.0hf), dst / (1.0hf - src)); - if (dst.r < kEhCloseEnough) { - color.r = 0; + if (dst.r < float16_t(kEhCloseEnough)) { + color.r = float16_t(0.); } - if (dst.g < kEhCloseEnough) { - color.g = 0; + if (dst.g < float16_t(kEhCloseEnough)) { + color.g = float16_t(0.); } - if (dst.b < kEhCloseEnough) { - color.b = 0; + if (dst.b < float16_t(kEhCloseEnough)) { + color.b = float16_t(0.); } - if (1 - src.r < kEhCloseEnough) { - color.r = 1; + if (1. - src.r < float16_t(kEhCloseEnough)) { + color.r = float16_t(1.); } - if (1 - src.g < kEhCloseEnough) { - color.g = 1; + if (1. - src.g < float16_t(kEhCloseEnough)) { + color.g = float16_t(1.); } - if (1 - src.b < kEhCloseEnough) { - color.b = 1; + if (1. - src.b < float16_t(kEhCloseEnough)) { + color.b = float16_t(1.); } return color; } -vec3 IPBlendColorBurn(vec3 dst, vec3 src) { +f16vec3 IPBlendColorBurn(f16vec3 dst, f16vec3 src) { // https://www.w3.org/TR/compositing-1/#blendingcolorburn - vec3 color = 1 - min(vec3(1), (1 - dst) / src); + f16vec3 color = 1.0hf - min(f16vec3(1.0hf), (1.0hf - dst) / src); - if (1 - dst.r < kEhCloseEnough) { - color.r = 1; + if (1.0hf - dst.r < float16_t(kEhCloseEnough)) { + color.r = 1.0hf; } - if (1 - dst.g < kEhCloseEnough) { - color.g = 1; + if (1.0hf - dst.g < float16_t(kEhCloseEnough)) { + color.g = float16_t(1.); } - if (1 - dst.b < kEhCloseEnough) { - color.b = 1; + if (1.0hf - dst.b < float16_t(kEhCloseEnough)) { + color.b = float16_t(.1); } - if (src.r < kEhCloseEnough) { - color.r = 0; + if (src.r < float16_t(kEhCloseEnough)) { + color.r = float16_t(0.); } - if (src.g < kEhCloseEnough) { - color.g = 0; + if (src.g < float16_t(kEhCloseEnough)) { + color.g = float16_t(0.); } - if (src.b < kEhCloseEnough) { - color.b = 0; + if (src.b < float16_t(kEhCloseEnough)) { + color.b = float16_t(0.); } return color; } -vec3 IPBlendSoftLight(vec3 dst, vec3 src) { +f16vec3 IPBlendSoftLight(f16vec3 dst, f16vec3 src) { // https://www.w3.org/TR/compositing-1/#blendingsoftlight - vec3 D = IPVec3ChooseCutoff(((16 * dst - 12) * dst + 4) * dst, // + f16vec3 D = IPVec3ChooseCutoff(((16.0hf * dst - 12.0hf) * dst + 4.0hf) * dst, // sqrt(dst), // dst, // - 0.25); + 0.25hf); - return IPVec3Choose(dst - (1 - 2 * src) * dst * (1 - dst), // - dst + (2 * src - 1) * (D - dst), // + return IPVec3Choose(dst - (1.0hf - 2.0hf * src) * dst * (1.0hf - dst), // + dst + (2.0hf * src - 1.0hf) * (D - dst), // src); } -vec3 IPBlendDifference(vec3 dst, vec3 src) { +f16vec3 IPBlendDifference(f16vec3 dst, f16vec3 src) { // https://www.w3.org/TR/compositing-1/#blendingdifference return abs(dst - src); } -vec3 IPBlendExclusion(vec3 dst, vec3 src) { +f16vec3 IPBlendExclusion(f16vec3 dst, f16vec3 src) { // https://www.w3.org/TR/compositing-1/#blendingexclusion - return dst + src - 2 * dst * src; + return dst + src - 2.0hf * dst * src; } -vec3 IPBlendMultiply(vec3 dst, vec3 src) { +f16vec3 IPBlendMultiply(f16vec3 dst, f16vec3 src) { // https://www.w3.org/TR/compositing-1/#blendingmultiply return dst * src; } -vec3 IPBlendHue(vec3 dst, vec3 src) { +f16vec3 IPBlendHue(f16vec3 dst, f16vec3 src) { // https://www.w3.org/TR/compositing-1/#blendinghue return IPSetLuminosity(IPSetSaturation(src, IPSaturation(dst)), IPLuminosity(dst)); } -vec3 IPBlendSaturation(vec3 dst, vec3 src) { +f16vec3 IPBlendSaturation(f16vec3 dst, f16vec3 src) { // https://www.w3.org/TR/compositing-1/#blendingsaturation return IPSetLuminosity(IPSetSaturation(dst, IPSaturation(src)), IPLuminosity(dst)); } -vec3 IPBlendColor(vec3 dst, vec3 src) { +f16vec3 IPBlendColor(f16vec3 dst, f16vec3 src) { // https://www.w3.org/TR/compositing-1/#blendingcolor return IPSetLuminosity(src, IPLuminosity(dst)); } -vec3 IPBlendLuminosity(vec3 dst, vec3 src) { +f16vec3 IPBlendLuminosity(f16vec3 dst, f16vec3 src) { // https://www.w3.org/TR/compositing-1/#blendingluminosity return IPSetLuminosity(dst, IPLuminosity(src)); } diff --git a/impeller/compiler/shader_lib/impeller/branching.glsl b/impeller/compiler/shader_lib/impeller/branching.glsl index bfa00b62dc5f1..93ac186a79ad0 100644 --- a/impeller/compiler/shader_lib/impeller/branching.glsl +++ b/impeller/compiler/shader_lib/impeller/branching.glsl @@ -5,48 +5,48 @@ #ifndef BRANCHING_GLSL_ #define BRANCHING_GLSL_ -#include #include +#include /// Perform an equality check for each vec3 component. /// /// Returns 1.0 if x == y, otherwise 0.0. -BoolV3 IPVec3IsEqual(vec3 x, float y) { - vec3 diff = abs(x - y); - return vec3(diff.r < kEhCloseEnough, // - diff.g < kEhCloseEnough, // - diff.b < kEhCloseEnough); +BoolV3 IPVec3IsEqual(f16vec3 x, float16_t y) { + f16vec3 diff = abs(x - y); + return f16vec3(diff.r < float16_t(kEhCloseEnough), // + diff.g < float16_t(kEhCloseEnough), // + diff.b < float16_t(kEhCloseEnough)); } /// Perform a branchless greater than check. /// /// Returns 1.0 if x > y, otherwise 0.0. -BoolF IPFloatIsGreaterThan(float x, float y) { - return max(sign(x - y), 0); +BoolF IPFloatIsGreaterThan(float16_t x, float16_t y) { + return max(sign(x - y), 0.0hf); } /// Perform a branchless greater than check for each vec3 component. /// /// Returns 1.0 if x > y, otherwise 0.0. -BoolV3 IPVec3IsGreaterThan(vec3 x, vec3 y) { - return max(sign(x - y), 0); +BoolV3 IPVec3IsGreaterThan(f16vec3 x, f16vec3 y) { + return max(sign(x - y), 0.0hf); } /// Perform a branchless less than check. /// /// Returns 1.0 if x < y, otherwise 0.0. -BoolF IPFloatIsLessThan(float x, float y) { - return max(sign(y - x), 0); +BoolF IPFloatIsLessThan(float16_t x, float16_t y) { + return max(sign(y - x), 0.0hf); } /// For each vec3 component, if value > cutoff, return b, otherwise return a. -vec3 IPVec3ChooseCutoff(vec3 a, vec3 b, vec3 value, float cutoff) { - return mix(a, b, IPVec3IsGreaterThan(value, vec3(cutoff))); +f16vec3 IPVec3ChooseCutoff(f16vec3 a, f16vec3 b, f16vec3 value, float16_t cutoff) { + return mix(a, b, IPVec3IsGreaterThan(value, f16vec3(cutoff))); } /// For each vec3 component, if value > 0.5, return b, otherwise return a. -vec3 IPVec3Choose(vec3 a, vec3 b, vec3 value) { - return IPVec3ChooseCutoff(a, b, value, 0.5); +f16vec3 IPVec3Choose(f16vec3 a, f16vec3 b, f16vec3 value) { + return IPVec3ChooseCutoff(a, b, value, 0.5hf); } #endif diff --git a/impeller/compiler/shader_lib/impeller/color.glsl b/impeller/compiler/shader_lib/impeller/color.glsl index 303b68e4c4570..088c0a0d661c4 100644 --- a/impeller/compiler/shader_lib/impeller/color.glsl +++ b/impeller/compiler/shader_lib/impeller/color.glsl @@ -5,25 +5,26 @@ #ifndef COLOR_GLSL_ #define COLOR_GLSL_ +#include #include /// Convert a premultiplied color (a color which has its color components /// multiplied with its alpha value) to an unpremultiplied color. /// /// Returns (0, 0, 0, 0) if the alpha component is 0. -vec4 IPUnpremultiply(vec4 color) { - if (color.a == 0) { - return vec4(0); +f16vec4 IPUnpremultiply(f16vec4 color) { + if (color.a == 0.0hf) { + return f16vec4(0.0hf); } - return vec4(color.rgb / color.a, color.a); + return f16vec4(color.rgb / color.a, color.a); } /// Convert an unpremultiplied color (a color which has its color components /// separated from its alpha value) to a premultiplied color. /// /// Returns (0, 0, 0, 0) if the alpha component is 0. -vec4 IPPremultiply(vec4 color) { - return vec4(color.rgb * color.a, color.a); +f16vec4 IPPremultiply(f16vec4 color) { + return f16vec4(color.rgb * color.a, color.a); } #endif diff --git a/impeller/compiler/shader_lib/impeller/constants.glsl b/impeller/compiler/shader_lib/impeller/constants.glsl index fe9367a926eae..5fa16ec8dcae4 100644 --- a/impeller/compiler/shader_lib/impeller/constants.glsl +++ b/impeller/compiler/shader_lib/impeller/constants.glsl @@ -5,15 +5,17 @@ #ifndef CONSTANTS_GLSL_ #define CONSTANTS_GLSL_ -const float kEhCloseEnough = 0.000001; +#include + +const float16_t kEhCloseEnough = 0.000001hf; // 1 / (2 * pi) -const float k1Over2Pi = 0.1591549430918; +const float16_t k1Over2Pi = 0.1591549430918hf; // sqrt(2 * pi) -const float kSqrtTwoPi = 2.50662827463; +const float16_t kSqrtTwoPi = 2.50662827463hf; // sqrt(2) / 2 == 1 / sqrt(2) -const float kHalfSqrtTwo = 0.70710678118; +const float16_t kHalfSqrtTwo = 0.70710678118hf; #endif diff --git a/impeller/compiler/shader_lib/impeller/gaussian.glsl b/impeller/compiler/shader_lib/impeller/gaussian.glsl index 7b8b4e438dea9..9aaa81d467675 100644 --- a/impeller/compiler/shader_lib/impeller/gaussian.glsl +++ b/impeller/compiler/shader_lib/impeller/gaussian.glsl @@ -5,50 +5,51 @@ #ifndef GAUSSIAN_GLSL_ #define GAUSSIAN_GLSL_ +#include #include /// Gaussian distribution function. -float IPGaussian(float x, float sigma) { - float variance = sigma * sigma; - return exp(-0.5 * x * x / variance) / (kSqrtTwoPi * sigma); +float16_t IPGaussian(float16_t x, float16_t sigma) { + float16_t variance = sigma * sigma; + return exp(-0.5hf * x * x / variance) / (float16_t(kSqrtTwoPi) * sigma); } /// Abramowitz and Stegun erf approximation. -float IPErf(float x) { - float a = abs(x); +float16_t IPErf(float16_t x) { + float16_t a = abs(x); // 0.278393*x + 0.230389*x^2 + 0.078108*x^4 + 1 - float b = (0.278393 + (0.230389 + 0.078108 * a * a) * a) * a + 1.0; - return sign(x) * (1 - 1 / (b * b * b * b)); + float16_t b = (0.278393hf + (0.230389hf + 0.078108hf * a * a) * a) * a + 1.0hf; + return sign(x) * (1.0hf - 1.0hf / (b * b * b * b)); } /// Vec2 variation for the Abramowitz and Stegun erf approximation. -vec2 IPVec2Erf(vec2 x) { - vec2 a = abs(x); +f16vec2 IPVec2Erf(f16vec2 x) { + f16vec2 a = abs(x); // 0.278393*x + 0.230389*x^2 + 0.078108*x^4 + 1 - vec2 b = (0.278393 + (0.230389 + 0.078108 * a * a) * a) * a + 1.0; - return sign(x) * (1 - 1 / (b * b * b * b)); + f16vec2 b = (0.278393hf + (0.230389hf + 0.078108hf * a * a) * a) * a + 1.0hf; + return sign(x) * (1.0hf - 1.0hf / (b * b * b * b)); } /// Indefinite integral of the Gaussian function (with constant range 0->1). -float IPGaussianIntegral(float x, float sigma) { +float16_t IPGaussianIntegral(float16_t x, float16_t sigma) { // ( 1 + erf( x * (sqrt(2) / (2 * sigma) ) ) / 2 // Because this sigmoid is always > 1, we remap it (n * 1.07 - 0.07) // so that it always fades to zero before it reaches the blur radius. - return 0.535 * IPErf(x * (kHalfSqrtTwo / sigma)) + 0.465; + return 0.535hf * IPErf(x * (float16_t(kHalfSqrtTwo) / sigma)) + 0.465hf; } /// Vec2 variation for the indefinite integral of the Gaussian function (with /// constant range 0->1). -vec2 IPVec2GaussianIntegral(vec2 x, float sigma) { +f16vec2 IPVec2GaussianIntegral(f16vec2 x, float16_t sigma) { // ( 1 + erf( x * (sqrt(2) / (2 * sigma) ) ) / 2 // Because this sigmoid is always > 1, we remap it (n * 1.07 - 0.07) // so that it always fades to zero before it reaches the blur radius. - return 0.535 * IPVec2Erf(x * (kHalfSqrtTwo / sigma)) + 0.465; + return 0.535hf * IPVec2Erf(x * (float16_t(kHalfSqrtTwo) / sigma)) + 0.465hf; } /// Simple logistic sigmoid with a domain of [-1, 1] and range of [0, 1]. -float IPSigmoid(float x) { - return 1.03731472073 / (1 + exp(-4 * x)) - 0.0186573603638; +float16_t IPSigmoid(float16_t x) { + return 1.03731472073hf / (1.0hf + exp(-4.0hf * x)) - 0.0186573603638hf; } #endif diff --git a/impeller/compiler/shader_lib/impeller/gradient.glsl b/impeller/compiler/shader_lib/impeller/gradient.glsl index 2c64edd35098b..c5ace9ecc9970 100644 --- a/impeller/compiler/shader_lib/impeller/gradient.glsl +++ b/impeller/compiler/shader_lib/impeller/gradient.glsl @@ -5,6 +5,7 @@ #ifndef GRADIENT_GLSL_ #define GRADIENT_GLSL_ +#include #include /// Compute the indexes and mix coefficient used to mix colors for an @@ -12,13 +13,13 @@ /// /// The returned values are the lower index, upper index, and mix /// coefficient. -vec3 IPComputeFixedGradientValues(float t, float colors_length) { - float rough_index = (colors_length - 1) * t; - float lower_index = floor(rough_index); - float upper_index = ceil(rough_index); - float scale = rough_index - lower_index; +f16vec3 IPComputeFixedGradientValues(float16_t t, float16_t colors_length) { + float16_t rough_index = (colors_length - 1.0hf) * t; + float16_t lower_index = floor(rough_index); + float16_t upper_index = ceil(rough_index); + float16_t scale = rough_index - lower_index; - return vec3(lower_index, upper_index, scale); + return f16vec3(lower_index, upper_index, scale); } #endif diff --git a/impeller/compiler/shader_lib/impeller/texture.glsl b/impeller/compiler/shader_lib/impeller/texture.glsl index 447bedc22158d..100e98dd67102 100644 --- a/impeller/compiler/shader_lib/impeller/texture.glsl +++ b/impeller/compiler/shader_lib/impeller/texture.glsl @@ -5,6 +5,7 @@ #ifndef TEXTURE_GLSL_ #define TEXTURE_GLSL_ +#include #include /// Sample from a texture. @@ -12,11 +13,11 @@ /// If `y_coord_scale` < 0.0, the Y coordinate is flipped. This is useful /// 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; +f16vec4 IPSample(sampler2D texture_sampler, f16vec2 coords, float16_t y_coord_scale) { + if (y_coord_scale < 0.0hf) { + coords.y = 1.0hf - coords.y; } - return texture(texture_sampler, coords); + return f16vec4(texture(texture_sampler, coords)); } /// Sample from a texture. @@ -25,9 +26,9 @@ vec4 IPSample(sampler2D texture_sampler, vec2 coords, float y_coord_scale) { /// for Impeller graphics backends that use a flipped framebuffer coordinate /// space. /// The range of `coods` will be mapped from [0, 1] to [half_texel, 1 - half_texel] -vec4 IPSampleLinear(sampler2D texture_sampler, vec2 coords, float y_coord_scale, vec2 half_texel) { - coords.x = mix(half_texel.x, 1 - half_texel.x, coords.x); - coords.y = mix(half_texel.y, 1 - half_texel.y, coords.y); +f16vec4 IPSampleLinear(sampler2D texture_sampler, f16vec2 coords, float16_t y_coord_scale, f16vec2 half_texel) { + coords.x = mix(half_texel.x, 1.0hf - half_texel.x, coords.x); + coords.y = mix(half_texel.y, 1.0hf - half_texel.y, coords.y); return IPSample(texture_sampler, coords, y_coord_scale); } @@ -38,20 +39,20 @@ const float kTileModeRepeat = 1; const float kTileModeMirror = 2; const float kTileModeDecal = 3; -/// Remap a float using a tiling mode. +/// Remap a float16_t using a tiling mode. /// /// When `tile_mode` is `kTileModeDecal`, no tiling is applied and `t` is /// returned. In all other cases, a value between 0 and 1 is returned by tiling /// `t`. /// When `t` is between [0 to 1), the original unchanged `t` is always returned. -float IPFloatTile(float t, float tile_mode) { - if (tile_mode == kTileModeClamp) { - t = clamp(t, 0.0, 1.0); - } else if (tile_mode == kTileModeRepeat) { +float16_t IPFloatTile(float16_t t, float16_t tile_mode) { + if (tile_mode == float16_t(kTileModeClamp)) { + t = clamp(t, 0.0hf, 1.0hf); + } else if (tile_mode == float16_t(kTileModeRepeat)) { t = fract(t); - } else if (tile_mode == kTileModeMirror) { - float t1 = t - 1; - float t2 = t1 - 2 * floor(t1 * 0.5) - 1; + } else if (tile_mode == float16_t(kTileModeMirror)) { + float16_t t1 = t - 1.0hf; + float16_t t2 = t1 - 2.0hf * floor(t1 * 0.5hf) - 1.0hf; t = abs(t2); } return t; @@ -60,8 +61,8 @@ float IPFloatTile(float t, float tile_mode) { /// Remap a vec2 using a tiling mode. /// /// Runs each component of the vec2 through `IPFloatTile`. -vec2 IPVec2Tile(vec2 coords, float x_tile_mode, float y_tile_mode) { - return vec2(IPFloatTile(coords.x, x_tile_mode), +f16vec2 IPVec2Tile(f16vec2 coords, float16_t x_tile_mode, float16_t y_tile_mode) { + return f16vec2(IPFloatTile(coords.x, x_tile_mode), IPFloatTile(coords.y, y_tile_mode)); } @@ -69,14 +70,14 @@ vec2 IPVec2Tile(vec2 coords, float x_tile_mode, float y_tile_mode) { /// /// This is useful for Impeller graphics backend that don't have native support /// for Decal. -vec4 IPSampleWithTileMode(sampler2D tex, - vec2 coords, - float y_coord_scale, - float x_tile_mode, - float y_tile_mode) { - if (x_tile_mode == kTileModeDecal && (coords.x < 0 || coords.x >= 1) || - y_tile_mode == kTileModeDecal && (coords.y < 0 || coords.y >= 1)) { - return vec4(0); +f16vec4 IPSampleWithTileMode(sampler2D tex, + f16vec2 coords, + float16_t y_coord_scale, + float16_t x_tile_mode, + float16_t y_tile_mode) { + if (x_tile_mode == kTileModeDecal && (coords.x < 0.hf || coords.x >= 1.hf) || + y_tile_mode == kTileModeDecal && (coords.y < 0.hf || coords.y >= 1.hf)) { + return f16vec4(0.0hf); } return IPSample(tex, IPVec2Tile(coords, x_tile_mode, y_tile_mode), y_coord_scale); @@ -86,10 +87,10 @@ vec4 IPSampleWithTileMode(sampler2D tex, /// /// This is useful for Impeller graphics backend that don't have native support /// for Decal. -vec4 IPSampleWithTileMode(sampler2D tex, - vec2 coords, - float y_coord_scale, - float tile_mode) { +f16vec4 IPSampleWithTileMode(sampler2D tex, + f16vec2 coords, + float16_t y_coord_scale, + float16_t tile_mode) { return IPSampleWithTileMode(tex, coords, y_coord_scale, tile_mode, tile_mode); } @@ -98,15 +99,15 @@ vec4 IPSampleWithTileMode(sampler2D tex, /// This is useful for Impeller graphics backend that don't have native support /// for Decal. /// The range of `coods` will be mapped from [0, 1] to [half_texel, 1 - half_texel] -vec4 IPSampleLinearWithTileMode(sampler2D tex, - vec2 coords, - float y_coord_scale, - vec2 half_texel, - float x_tile_mode, - float y_tile_mode) { - if (x_tile_mode == kTileModeDecal && (coords.x < 0 || coords.x >= 1) || - y_tile_mode == kTileModeDecal && (coords.y < 0 || coords.y >= 1)) { - return vec4(0); +f16vec4 IPSampleLinearWithTileMode(sampler2D tex, + f16vec2 coords, + float16_t y_coord_scale, + f16vec2 half_texel, + float16_t x_tile_mode, + float16_t y_tile_mode) { + if (x_tile_mode == float16_t(kTileModeDecal) && (coords.x < 0.0hf || coords.x >= 1.0hf) || + y_tile_mode == float16_t(kTileModeDecal) && (coords.y < 0.0hf || coords.y >= 1.0hf)) { + return f16vec4(0.0hf); } return IPSampleLinear(tex, IPVec2Tile(coords, x_tile_mode, y_tile_mode), y_coord_scale, half_texel); @@ -117,11 +118,11 @@ vec4 IPSampleLinearWithTileMode(sampler2D tex, /// This is useful for Impeller graphics backend that don't have native support /// for Decal. /// The range of `coods` will be mapped from [0, 1] to [half_texel, 1 - half_texel] -vec4 IPSampleLinearWithTileMode(sampler2D tex, - vec2 coords, - float y_coord_scale, - vec2 half_texel, - float tile_mode) { +f16vec4 IPSampleLinearWithTileMode(sampler2D tex, + f16vec2 coords, + float16_t y_coord_scale, + f16vec2 half_texel, + float16_t tile_mode) { return IPSampleLinearWithTileMode(tex, coords, y_coord_scale, half_texel, tile_mode, tile_mode); } diff --git a/impeller/compiler/shader_lib/impeller/types.glsl b/impeller/compiler/shader_lib/impeller/types.glsl index d896c5e60659a..4ee34daf03983 100644 --- a/impeller/compiler/shader_lib/impeller/types.glsl +++ b/impeller/compiler/shader_lib/impeller/types.glsl @@ -5,9 +5,30 @@ #ifndef TYPES_GLSL_ #define TYPES_GLSL_ +#ifdef IMPELLER_TARGET_METAL +#extension GL_AMD_gpu_shader_half_float: enable + +#define BoolF float16_t +#define BoolV2 f16vec2 +#define BoolV3 f16vec3 +#define BoolV4 f16vec4 + +#else + +precision mediump sampler2D; +precision mediump float; + +#define float16_t float +#define f16vec2 vec2 +#define f16vec3 vec3 +#define f16vec4 vec4 +#define f16mat4 mat4 #define BoolF float #define BoolV2 vec2 #define BoolV3 vec3 #define BoolV4 vec4 +#endif // IMPELLER_TARGET_METAL + + #endif diff --git a/impeller/entity/BUILD.gn b/impeller/entity/BUILD.gn index ecba665e6617a..216a3ec6fb983 100644 --- a/impeller/entity/BUILD.gn +++ b/impeller/entity/BUILD.gn @@ -8,6 +8,7 @@ impeller_shaders("entity_shaders") { name = "entity" shaders = [ + "shaders/test.frag", "shaders/atlas_fill.frag", "shaders/atlas_fill.vert", "shaders/blending/advanced_blend.vert", diff --git a/impeller/entity/shaders/atlas_fill.frag b/impeller/entity/shaders/atlas_fill.frag index e211971ca1bb9..fb7ace3f8cd9b 100644 --- a/impeller/entity/shaders/atlas_fill.frag +++ b/impeller/entity/shaders/atlas_fill.frag @@ -2,26 +2,27 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include uniform sampler2D texture_sampler; uniform FragInfo { - float texture_sampler_y_coord_scale; - float has_vertex_color; - float alpha; + float16_t texture_sampler_y_coord_scale; + float16_t has_vertex_color; + float16_t alpha; } frag_info; -in vec2 v_texture_coords; -in vec4 v_color; +in f16vec2 v_texture_coords; +in f16vec4 v_color; -out vec4 frag_color; +out f16vec4 frag_color; void main() { - vec4 sampled = IPSample(texture_sampler, v_texture_coords, + f16vec4 sampled = IPSample(texture_sampler, v_texture_coords, frag_info.texture_sampler_y_coord_scale); - if (frag_info.has_vertex_color == 1.0) { + if (frag_info.has_vertex_color == 1.0hf) { frag_color = sampled.aaaa * v_color * frag_info.alpha; } else { frag_color = sampled * frag_info.alpha; diff --git a/impeller/entity/shaders/atlas_fill.vert b/impeller/entity/shaders/atlas_fill.vert index 29d3c0a5be6e7..a2c2bfd3d574e 100644 --- a/impeller/entity/shaders/atlas_fill.vert +++ b/impeller/entity/shaders/atlas_fill.vert @@ -2,17 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include + uniform VertInfo { mat4 mvp; } vert_info; -in vec2 position; -in vec2 texture_coords; -in vec4 color; +in f16vec2 position; +in f16vec2 texture_coords; +in f16vec4 color; -out vec2 v_texture_coords; -out vec4 v_color; +out f16vec2 v_texture_coords; +out f16vec4 v_color; void main() { gl_Position = vert_info.mvp * vec4(position, 0.0, 1.0); diff --git a/impeller/entity/shaders/blending/advanced_blend.glsl b/impeller/entity/shaders/blending/advanced_blend.glsl index 6ff1d93ab6810..5c7ebab515e32 100644 --- a/impeller/entity/shaders/blending/advanced_blend.glsl +++ b/impeller/entity/shaders/blending/advanced_blend.glsl @@ -2,46 +2,46 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include #include #include uniform BlendInfo { - float dst_input_alpha; - float dst_y_coord_scale; - float src_y_coord_scale; - float color_factor; - vec4 color; // This color input is expected to be unpremultiplied. + float16_t dst_input_alpha; + float16_t dst_y_coord_scale; + float16_t src_y_coord_scale; + float16_t color_factor; + f16vec4 color; // This color input is expected to be unpremultiplied. } blend_info; uniform sampler2D texture_sampler_dst; uniform sampler2D texture_sampler_src; -in vec2 v_dst_texture_coords; -in vec2 v_src_texture_coords; +in f16vec2 v_dst_texture_coords; +in f16vec2 v_src_texture_coords; -out vec4 frag_color; +out f16vec4 frag_color; void main() { - vec4 dst_sample = + f16vec4 dst_sample = IPSampleWithTileMode(texture_sampler_dst, // sampler v_dst_texture_coords, // texture coordinates blend_info.dst_y_coord_scale, // y coordinate scale - kTileModeDecal // tile mode + float16_t(kTileModeDecal) // tile mode ) * blend_info.dst_input_alpha; - vec4 dst = IPUnpremultiply(dst_sample); - vec4 src = blend_info.color_factor > 0 + f16vec4 dst = IPUnpremultiply(dst_sample); + f16vec4 src = blend_info.color_factor > 0. ? blend_info.color : IPUnpremultiply(IPSampleWithTileMode( texture_sampler_src, // sampler v_src_texture_coords, // texture coordinates blend_info.src_y_coord_scale, // y coordinate scale - kTileModeDecal // tile mode + float16_t(kTileModeDecal) // tile mode )); - vec4 blended = vec4(Blend(dst.rgb, src.rgb), 1) * dst.a; + f16vec4 blended = f16vec4(Blend(dst.rgb, src.rgb), 1.0hf) * dst.a; frag_color = mix(dst_sample, blended, src.a); - //frag_color = dst_sample; } diff --git a/impeller/entity/shaders/blending/advanced_blend.vert b/impeller/entity/shaders/blending/advanced_blend.vert index 715dd3dead9fe..fe211a90fa592 100644 --- a/impeller/entity/shaders/blending/advanced_blend.vert +++ b/impeller/entity/shaders/blending/advanced_blend.vert @@ -2,17 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include + uniform FrameInfo { mat4 mvp; } frame_info; in vec2 vertices; -in vec2 dst_texture_coords; -in vec2 src_texture_coords; +in f16vec2 dst_texture_coords; +in f16vec2 src_texture_coords; -out vec2 v_dst_texture_coords; -out vec2 v_src_texture_coords; +out f16vec2 v_dst_texture_coords; +out f16vec2 v_src_texture_coords; void main() { gl_Position = frame_info.mvp * vec4(vertices, 0.0, 1.0); diff --git a/impeller/entity/shaders/blending/advanced_blend_color.frag b/impeller/entity/shaders/blending/advanced_blend_color.frag index 225bd3f098122..cfcb1b87d5aef 100644 --- a/impeller/entity/shaders/blending/advanced_blend_color.frag +++ b/impeller/entity/shaders/blending/advanced_blend_color.frag @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include -vec3 Blend(vec3 dst, vec3 src) { +f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendColor(dst, src); } diff --git a/impeller/entity/shaders/blending/advanced_blend_colorburn.frag b/impeller/entity/shaders/blending/advanced_blend_colorburn.frag index 95aac01645999..34d438c345e73 100644 --- a/impeller/entity/shaders/blending/advanced_blend_colorburn.frag +++ b/impeller/entity/shaders/blending/advanced_blend_colorburn.frag @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include -vec3 Blend(vec3 dst, vec3 src) { +f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendColorBurn(dst, src); } diff --git a/impeller/entity/shaders/blending/advanced_blend_colordodge.frag b/impeller/entity/shaders/blending/advanced_blend_colordodge.frag index f11fc5e68584d..ddb35bb4611e4 100644 --- a/impeller/entity/shaders/blending/advanced_blend_colordodge.frag +++ b/impeller/entity/shaders/blending/advanced_blend_colordodge.frag @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include -vec3 Blend(vec3 dst, vec3 src) { +f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendColorDodge(dst, src); } diff --git a/impeller/entity/shaders/blending/advanced_blend_darken.frag b/impeller/entity/shaders/blending/advanced_blend_darken.frag index 286b7ff2912e6..747b4223712a2 100644 --- a/impeller/entity/shaders/blending/advanced_blend_darken.frag +++ b/impeller/entity/shaders/blending/advanced_blend_darken.frag @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include -vec3 Blend(vec3 dst, vec3 src) { +f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendDarken(dst, src); } diff --git a/impeller/entity/shaders/blending/advanced_blend_difference.frag b/impeller/entity/shaders/blending/advanced_blend_difference.frag index 9d9320fdffd78..6b197899d3310 100644 --- a/impeller/entity/shaders/blending/advanced_blend_difference.frag +++ b/impeller/entity/shaders/blending/advanced_blend_difference.frag @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include -vec3 Blend(vec3 dst, vec3 src) { +f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendDifference(dst, src); } diff --git a/impeller/entity/shaders/blending/advanced_blend_exclusion.frag b/impeller/entity/shaders/blending/advanced_blend_exclusion.frag index 7c2f9f92996ca..28c0bbe5d908b 100644 --- a/impeller/entity/shaders/blending/advanced_blend_exclusion.frag +++ b/impeller/entity/shaders/blending/advanced_blend_exclusion.frag @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include -vec3 Blend(vec3 dst, vec3 src) { +f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendExclusion(dst, src); } diff --git a/impeller/entity/shaders/blending/advanced_blend_hardlight.frag b/impeller/entity/shaders/blending/advanced_blend_hardlight.frag index aa126dfdc7cc7..01f9c018aa2b5 100644 --- a/impeller/entity/shaders/blending/advanced_blend_hardlight.frag +++ b/impeller/entity/shaders/blending/advanced_blend_hardlight.frag @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include -vec3 Blend(vec3 dst, vec3 src) { +f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendHardLight(dst, src); } diff --git a/impeller/entity/shaders/blending/advanced_blend_hue.frag b/impeller/entity/shaders/blending/advanced_blend_hue.frag index c0355b4b00d34..24de234171be8 100644 --- a/impeller/entity/shaders/blending/advanced_blend_hue.frag +++ b/impeller/entity/shaders/blending/advanced_blend_hue.frag @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include -vec3 Blend(vec3 dst, vec3 src) { +f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendHue(dst, src); } diff --git a/impeller/entity/shaders/blending/advanced_blend_lighten.frag b/impeller/entity/shaders/blending/advanced_blend_lighten.frag index 32f2df082b4f5..0672168631b42 100644 --- a/impeller/entity/shaders/blending/advanced_blend_lighten.frag +++ b/impeller/entity/shaders/blending/advanced_blend_lighten.frag @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include -vec3 Blend(vec3 dst, vec3 src) { +f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendLighten(dst, src); } diff --git a/impeller/entity/shaders/blending/advanced_blend_luminosity.frag b/impeller/entity/shaders/blending/advanced_blend_luminosity.frag index 4ceae64493947..71eab1b831f86 100644 --- a/impeller/entity/shaders/blending/advanced_blend_luminosity.frag +++ b/impeller/entity/shaders/blending/advanced_blend_luminosity.frag @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include -vec3 Blend(vec3 dst, vec3 src) { +f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendLuminosity(dst, src); } diff --git a/impeller/entity/shaders/blending/advanced_blend_multiply.frag b/impeller/entity/shaders/blending/advanced_blend_multiply.frag index a2fd42b6c7d2e..04f98fedbd086 100644 --- a/impeller/entity/shaders/blending/advanced_blend_multiply.frag +++ b/impeller/entity/shaders/blending/advanced_blend_multiply.frag @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include -vec3 Blend(vec3 dst, vec3 src) { +f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendMultiply(dst, src); } diff --git a/impeller/entity/shaders/blending/advanced_blend_overlay.frag b/impeller/entity/shaders/blending/advanced_blend_overlay.frag index 0837b91d8bfbd..d96f1ca12ab4d 100644 --- a/impeller/entity/shaders/blending/advanced_blend_overlay.frag +++ b/impeller/entity/shaders/blending/advanced_blend_overlay.frag @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include -vec3 Blend(vec3 dst, vec3 src) { +f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendOverlay(dst, src); } diff --git a/impeller/entity/shaders/blending/advanced_blend_saturation.frag b/impeller/entity/shaders/blending/advanced_blend_saturation.frag index c3fd3bebc87d7..329ceb6340103 100644 --- a/impeller/entity/shaders/blending/advanced_blend_saturation.frag +++ b/impeller/entity/shaders/blending/advanced_blend_saturation.frag @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include -vec3 Blend(vec3 dst, vec3 src) { +f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendSaturation(dst, src); } diff --git a/impeller/entity/shaders/blending/advanced_blend_screen.frag b/impeller/entity/shaders/blending/advanced_blend_screen.frag index f65ab5db1d563..0dd33ef660747 100644 --- a/impeller/entity/shaders/blending/advanced_blend_screen.frag +++ b/impeller/entity/shaders/blending/advanced_blend_screen.frag @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include -vec3 Blend(vec3 dst, vec3 src) { +f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendScreen(dst, src); } diff --git a/impeller/entity/shaders/blending/advanced_blend_softlight.frag b/impeller/entity/shaders/blending/advanced_blend_softlight.frag index 3a504afbb99c6..a75850022e21c 100644 --- a/impeller/entity/shaders/blending/advanced_blend_softlight.frag +++ b/impeller/entity/shaders/blending/advanced_blend_softlight.frag @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include -vec3 Blend(vec3 dst, vec3 src) { +f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendSoftLight(dst, src); } diff --git a/impeller/entity/shaders/blending/blend.frag b/impeller/entity/shaders/blending/blend.frag index c3f89be765349..c21d0de2bd190 100644 --- a/impeller/entity/shaders/blending/blend.frag +++ b/impeller/entity/shaders/blending/blend.frag @@ -2,18 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include uniform sampler2D texture_sampler_src; uniform FragInfo { - float texture_sampler_y_coord_scale; - float input_alpha; + float16_t texture_sampler_y_coord_scale; + float16_t input_alpha; } frag_info; -in vec2 v_texture_coords; +in f16vec2 v_texture_coords; -out vec4 frag_color; +out f16vec4 frag_color; void main() { frag_color = IPSample(texture_sampler_src, v_texture_coords, diff --git a/impeller/entity/shaders/blending/blend.vert b/impeller/entity/shaders/blending/blend.vert index daa30f5650a3f..cbbd69ded6248 100644 --- a/impeller/entity/shaders/blending/blend.vert +++ b/impeller/entity/shaders/blending/blend.vert @@ -2,14 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include + uniform FrameInfo { mat4 mvp; } frame_info; in vec2 vertices; -in vec2 texture_coords; +in f16vec2 texture_coords; -out vec2 v_texture_coords; +out f16vec2 v_texture_coords; void main() { gl_Position = frame_info.mvp * vec4(vertices, 0.0, 1.0); diff --git a/impeller/entity/shaders/border_mask_blur.frag b/impeller/entity/shaders/border_mask_blur.frag index e9b56fa3cfe0a..865669c1d1712 100644 --- a/impeller/entity/shaders/border_mask_blur.frag +++ b/impeller/entity/shaders/border_mask_blur.frag @@ -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 #include #include @@ -17,37 +18,37 @@ uniform sampler2D texture_sampler; uniform FragInfo { - float texture_sampler_y_coord_scale; + float16_t texture_sampler_y_coord_scale; } frag_info; -in vec2 v_texture_coords; -in vec2 v_sigma_uv; -in float v_src_factor; -in float v_inner_blur_factor; -in float v_outer_blur_factor; +in f16vec2 v_texture_coords; +in f16vec2 v_sigma_uv; +in float16_t v_src_factor; +in float16_t v_inner_blur_factor; +in float16_t v_outer_blur_factor; -out vec4 frag_color; +out f16vec4 frag_color; -float BoxBlurMask(vec2 uv) { +float16_t BoxBlurMask(f16vec2 uv) { // LTRB return IPGaussianIntegral(uv.x, v_sigma_uv.x) * // IPGaussianIntegral(uv.y, v_sigma_uv.y) * // - IPGaussianIntegral(1 - uv.x, v_sigma_uv.x) * // - IPGaussianIntegral(1 - uv.y, v_sigma_uv.y); + IPGaussianIntegral(1.0hf - uv.x, v_sigma_uv.x) * // + IPGaussianIntegral(1.0hf - uv.y, v_sigma_uv.y); } void main() { - vec4 image_color = IPSample(texture_sampler, v_texture_coords, + f16vec4 image_color = IPSample(texture_sampler, v_texture_coords, frag_info.texture_sampler_y_coord_scale); - float blur_factor = BoxBlurMask(v_texture_coords); + float16_t blur_factor = BoxBlurMask(v_texture_coords); - float within_bounds = - float(v_texture_coords.x >= 0 && v_texture_coords.y >= 0 && - v_texture_coords.x < 1 && v_texture_coords.y < 1); - float inner_factor = + float16_t within_bounds = + float16_t(v_texture_coords.x >= 0.0hf && v_texture_coords.y >= 0.0hf && + v_texture_coords.x < 1.0hf && v_texture_coords.y < 1.0hf); + float16_t inner_factor = (v_inner_blur_factor * blur_factor + v_src_factor) * within_bounds; - float outer_factor = v_outer_blur_factor * blur_factor * (1 - within_bounds); + float16_t outer_factor = v_outer_blur_factor * blur_factor * (1.0hf - within_bounds); - float mask_factor = inner_factor + outer_factor; + float16_t mask_factor = inner_factor + outer_factor; frag_color = image_color * mask_factor; } diff --git a/impeller/entity/shaders/border_mask_blur.vert b/impeller/entity/shaders/border_mask_blur.vert index 3851a60aeb7fe..27270ecfaf04e 100644 --- a/impeller/entity/shaders/border_mask_blur.vert +++ b/impeller/entity/shaders/border_mask_blur.vert @@ -2,25 +2,27 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include + uniform FrameInfo { mat4 mvp; - vec2 sigma_uv; + f16vec2 sigma_uv; - float src_factor; - float inner_blur_factor; - float outer_blur_factor; + float16_t src_factor; + float16_t inner_blur_factor; + float16_t outer_blur_factor; } frame_info; in vec2 vertices; -in vec2 texture_coords; +in f16vec2 texture_coords; -out vec2 v_texture_coords; -out vec2 v_sigma_uv; -out float v_src_factor; -out float v_inner_blur_factor; -out float v_outer_blur_factor; +out f16vec2 v_texture_coords; +out f16vec2 v_sigma_uv; +out float16_t v_src_factor; +out float16_t v_inner_blur_factor; +out float16_t v_outer_blur_factor; void main() { gl_Position = frame_info.mvp * vec4(vertices, 0.0, 1.0); diff --git a/impeller/entity/shaders/color_matrix_color_filter.frag b/impeller/entity/shaders/color_matrix_color_filter.frag index 43aa4c8c93976..d94c6081ae370 100644 --- a/impeller/entity/shaders/color_matrix_color_filter.frag +++ b/impeller/entity/shaders/color_matrix_color_filter.frag @@ -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 #include #include @@ -28,27 +29,27 @@ uniform FragInfo { mat4 color_m; - vec4 color_v; - float texture_sampler_y_coord_scale; - float input_alpha; + f16vec4 color_v; + float16_t texture_sampler_y_coord_scale; + float16_t input_alpha; } frag_info; uniform sampler2D input_texture; -in vec2 v_position; -out vec4 frag_color; +in f16vec2 v_position; +out f16vec4 frag_color; void main() { - vec4 input_color = IPSample(input_texture, v_position, + f16vec4 input_color = IPSample(input_texture, v_position, frag_info.texture_sampler_y_coord_scale) * frag_info.input_alpha; // unpremultiply first, as filter inputs are premultiplied. - vec4 color = IPUnpremultiply(input_color); + f16vec4 color = IPUnpremultiply(input_color); + + color = clamp(f16mat4(frag_info.color_m) * color + frag_info.color_v, 0.0hf, 1.0hf); - color = clamp(frag_info.color_m * color + frag_info.color_v, 0.0, 1.0); - // premultiply the outputs - frag_color = vec4(color.rgb * color.a, color.a); + frag_color = f16vec4(color.rgb * color.a, color.a); } diff --git a/impeller/entity/shaders/color_matrix_color_filter.vert b/impeller/entity/shaders/color_matrix_color_filter.vert index b741b2744ec60..774a7c7f39ea4 100644 --- a/impeller/entity/shaders/color_matrix_color_filter.vert +++ b/impeller/entity/shaders/color_matrix_color_filter.vert @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include + uniform FrameInfo { mat4 mvp; } frame_info; diff --git a/impeller/entity/shaders/gaussian_blur.frag b/impeller/entity/shaders/gaussian_blur.frag index 06bd0f389ff47..c48f1f61a9928 100644 --- a/impeller/entity/shaders/gaussian_blur.frag +++ b/impeller/entity/shaders/gaussian_blur.frag @@ -13,6 +13,7 @@ // reduced in the first pass by sampling the source textures with a mip // level of log2(min_radius). +#include #include #include #include @@ -21,39 +22,39 @@ uniform sampler2D texture_sampler; uniform sampler2D alpha_mask_sampler; uniform FragInfo { - float texture_sampler_y_coord_scale; - float alpha_mask_sampler_y_coord_scale; + float16_t texture_sampler_y_coord_scale; + float16_t alpha_mask_sampler_y_coord_scale; - vec2 texture_size; - vec2 blur_direction; + f16vec2 texture_size; + f16vec2 blur_direction; - float tile_mode; + float16_t tile_mode; // The blur sigma and radius have a linear relationship which is defined // host-side, but both are useful controls here. Sigma (pixels per standard // deviation) is used to define the gaussian function itself, whereas the // radius is used to limit how much of the function is integrated. - float blur_sigma; - float blur_radius; + float16_t blur_sigma; + float16_t blur_radius; - float src_factor; - float inner_blur_factor; - float outer_blur_factor; + float16_t src_factor; + float16_t inner_blur_factor; + float16_t outer_blur_factor; } frag_info; -in vec2 v_texture_coords; -in vec2 v_src_texture_coords; +in f16vec2 v_texture_coords; +in f16vec2 v_src_texture_coords; -out vec4 frag_color; +out f16vec4 frag_color; void main() { - vec4 total_color = vec4(0); - float gaussian_integral = 0; - vec2 blur_uv_offset = frag_info.blur_direction / frag_info.texture_size; + f16vec4 total_color = f16vec4(0.0hf); + float16_t gaussian_integral = 0.0hf; + f16vec2 blur_uv_offset = frag_info.blur_direction / frag_info.texture_size; - for (float i = -frag_info.blur_radius; i <= frag_info.blur_radius; i++) { - float gaussian = IPGaussian(i, frag_info.blur_sigma); + for (float16_t i = -frag_info.blur_radius; i <= frag_info.blur_radius; i++) { + float16_t gaussian = IPGaussian(i, frag_info.blur_sigma); gaussian_integral += gaussian; total_color += gaussian * @@ -65,16 +66,16 @@ void main() { ); } - vec4 blur_color = total_color / gaussian_integral; + f16vec4 blur_color = total_color / gaussian_integral; - vec4 src_color = IPSampleWithTileMode( + f16vec4 src_color = IPSampleWithTileMode( alpha_mask_sampler, // sampler v_src_texture_coords, // texture coordinates frag_info.alpha_mask_sampler_y_coord_scale, // y coordinate scale frag_info.tile_mode // tile mode ); - float blur_factor = frag_info.inner_blur_factor * float(src_color.a > 0) + - frag_info.outer_blur_factor * float(src_color.a == 0); + float16_t blur_factor = frag_info.inner_blur_factor * float16_t(src_color.a > 0.0hf) + + frag_info.outer_blur_factor * float16_t(src_color.a == 0.0hf); frag_color = blur_color * blur_factor + src_color * frag_info.src_factor; } diff --git a/impeller/entity/shaders/gaussian_blur.vert b/impeller/entity/shaders/gaussian_blur.vert index 0fd3595a2d267..13a62d06fa711 100644 --- a/impeller/entity/shaders/gaussian_blur.vert +++ b/impeller/entity/shaders/gaussian_blur.vert @@ -2,17 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include + uniform FrameInfo { mat4 mvp; } frame_info; in vec2 vertices; -in vec2 texture_coords; -in vec2 src_texture_coords; +in f16vec2 texture_coords; +in f16vec2 src_texture_coords; -out vec2 v_texture_coords; -out vec2 v_src_texture_coords; +out f16vec2 v_texture_coords; +out f16vec2 v_src_texture_coords; void main() { gl_Position = frame_info.mvp * vec4(vertices, 0.0, 1.0); diff --git a/impeller/entity/shaders/glyph_atlas.frag b/impeller/entity/shaders/glyph_atlas.frag index 6fa09ad2dde2f..5e4e895c7ce0d 100644 --- a/impeller/entity/shaders/glyph_atlas.frag +++ b/impeller/entity/shaders/glyph_atlas.frag @@ -2,32 +2,34 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include + uniform sampler2D glyph_atlas_sampler; uniform FragInfo { - vec2 atlas_size; - vec4 text_color; + f16vec2 atlas_size; + f16vec4 text_color; } frag_info; -in vec2 v_unit_vertex; -in vec2 v_atlas_position; -in vec2 v_atlas_glyph_size; -in float v_color_glyph; +in f16vec2 v_unit_vertex; +in f16vec2 v_atlas_position; +in f16vec2 v_atlas_glyph_size; +in float16_t v_color_glyph; -out vec4 frag_color; +out f16vec4 frag_color; void main() { - vec2 scale_perspective = v_atlas_glyph_size / frag_info.atlas_size; - vec2 offset = v_atlas_position / frag_info.atlas_size; - if (v_color_glyph == 1.0) { - frag_color = texture( + f16vec2 scale_perspective = v_atlas_glyph_size / frag_info.atlas_size; + f16vec2 offset = v_atlas_position / frag_info.atlas_size; + if (v_color_glyph == 1.0hf) { + frag_color = f16vec4(texture( glyph_atlas_sampler, v_unit_vertex * scale_perspective + offset - ); + )); } else { - frag_color = texture( + frag_color = f16vec4(texture( glyph_atlas_sampler, v_unit_vertex * scale_perspective + offset - ).aaaa * frag_info.text_color; + ).aaaa) * frag_info.text_color; } } diff --git a/impeller/entity/shaders/glyph_atlas.vert b/impeller/entity/shaders/glyph_atlas.vert index e332d67d3be7f..c5d73341be8b1 100644 --- a/impeller/entity/shaders/glyph_atlas.vert +++ b/impeller/entity/shaders/glyph_atlas.vert @@ -2,23 +2,24 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include uniform FrameInfo { mat4 mvp; } frame_info; -in vec2 unit_vertex; -in vec2 glyph_position; -in vec2 glyph_size; -in vec2 atlas_position; -in vec2 atlas_glyph_size; -in float color_glyph; +in f16vec2 unit_vertex; +in f16vec2 glyph_position; +in f16vec2 glyph_size; +in f16vec2 atlas_position; +in f16vec2 atlas_glyph_size; +in float16_t color_glyph; -out vec2 v_unit_vertex; -out vec2 v_atlas_position; -out vec2 v_atlas_glyph_size; -out float v_color_glyph; +out f16vec2 v_unit_vertex; +out f16vec2 v_atlas_position; +out f16vec2 v_atlas_glyph_size; +out float16_t v_color_glyph; void main() { gl_Position = IPPositionForGlyphPosition(frame_info.mvp, unit_vertex, glyph_position, glyph_size); diff --git a/impeller/entity/shaders/glyph_atlas_sdf.vert b/impeller/entity/shaders/glyph_atlas_sdf.vert index 830566304a123..e0b51a09774c8 100644 --- a/impeller/entity/shaders/glyph_atlas_sdf.vert +++ b/impeller/entity/shaders/glyph_atlas_sdf.vert @@ -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 #include uniform FrameInfo { diff --git a/impeller/entity/shaders/gradient_fill.vert b/impeller/entity/shaders/gradient_fill.vert index 4b793dbfa183d..fa0e7809ce6c1 100644 --- a/impeller/entity/shaders/gradient_fill.vert +++ b/impeller/entity/shaders/gradient_fill.vert @@ -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 #include uniform FrameInfo { diff --git a/impeller/entity/shaders/linear_gradient_fill.frag b/impeller/entity/shaders/linear_gradient_fill.frag index 577dd7dbb4741..572c97cc5ac73 100644 --- a/impeller/entity/shaders/linear_gradient_fill.frag +++ b/impeller/entity/shaders/linear_gradient_fill.frag @@ -2,35 +2,36 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include uniform sampler2D texture_sampler; uniform GradientInfo { - vec2 start_point; - vec2 end_point; - float tile_mode; - float texture_sampler_y_coord_scale; - float alpha; - vec2 half_texel; + f16vec2 start_point; + f16vec2 end_point; + float16_t tile_mode; + float16_t texture_sampler_y_coord_scale; + float16_t alpha; + f16vec2 half_texel; } gradient_info; -in vec2 v_position; +in f16vec2 v_position; -out vec4 frag_color; +out f16vec4 frag_color; void main() { - float len = length(gradient_info.end_point - gradient_info.start_point); - float dot = dot( + float16_t len = length(gradient_info.end_point - gradient_info.start_point); + float16_t dot = dot( v_position - gradient_info.start_point, gradient_info.end_point - gradient_info.start_point ); - float t = dot / (len * len); + float16_t t = dot / (len * len); frag_color = IPSampleLinearWithTileMode( texture_sampler, - vec2(t, 0.5), + f16vec2(t, 0.5hf), gradient_info.texture_sampler_y_coord_scale, gradient_info.half_texel, gradient_info.tile_mode); - frag_color = vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; + frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; } diff --git a/impeller/entity/shaders/linear_gradient_ssbo_fill.frag b/impeller/entity/shaders/linear_gradient_ssbo_fill.frag index e8cc761c9046b..5f62862df3c6b 100644 --- a/impeller/entity/shaders/linear_gradient_ssbo_fill.frag +++ b/impeller/entity/shaders/linear_gradient_ssbo_fill.frag @@ -2,40 +2,41 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include #include readonly buffer ColorData { - vec4 colors[]; + f16vec4 colors[]; } color_data; uniform GradientInfo { - vec2 start_point; - vec2 end_point; - float alpha; - float tile_mode; - float colors_length; + f16vec2 start_point; + f16vec2 end_point; + float16_t alpha; + float16_t tile_mode; + float16_t colors_length; } gradient_info; -in vec2 v_position; +in f16vec2 v_position; -out vec4 frag_color; +out f16vec4 frag_color; void main() { - float len = length(gradient_info.end_point - gradient_info.start_point); - float dot = dot( + float16_t len = length(gradient_info.end_point - gradient_info.start_point); + float16_t dot = dot( v_position - gradient_info.start_point, gradient_info.end_point - gradient_info.start_point ); - float t = dot / (len * len); + float16_t t = dot / (len * len); - if ((t < 0.0 || t > 1.0) && gradient_info.tile_mode == kTileModeDecal) { - frag_color = vec4(0); + if ((t < 0.0hf || t > 1.0hf) && gradient_info.tile_mode == kTileModeDecal) { + frag_color = f16vec4(0.0hf); return; } t = IPFloatTile(t, gradient_info.tile_mode); - vec3 values = IPComputeFixedGradientValues(t, gradient_info.colors_length); + f16vec3 values = IPComputeFixedGradientValues(t, gradient_info.colors_length); frag_color = mix(color_data.colors[int(values.x)], color_data.colors[int(values.y)], values.z); - frag_color = vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; + frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; } diff --git a/impeller/entity/shaders/linear_to_srgb_filter.frag b/impeller/entity/shaders/linear_to_srgb_filter.frag index e4fb50b1a2ead..2ec6396bd10cc 100644 --- a/impeller/entity/shaders/linear_to_srgb_filter.frag +++ b/impeller/entity/shaders/linear_to_srgb_filter.frag @@ -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 #include #include @@ -12,24 +13,24 @@ uniform sampler2D input_texture; uniform FragInfo { - float texture_sampler_y_coord_scale; - float input_alpha; + float16_t texture_sampler_y_coord_scale; + float16_t input_alpha; } frag_info; in vec2 v_position; -out vec4 frag_color; +out f16vec4 frag_color; void main() { - vec4 input_color = IPSample(input_texture, v_position, + f16vec4 input_color = IPSample(input_texture, f16vec2(v_position), frag_info.texture_sampler_y_coord_scale) * frag_info.input_alpha; - vec4 color = IPUnpremultiply(input_color); + f16vec4 color = IPUnpremultiply(input_color); for (int i = 0; i < 3; i++) { - if (color[i] <= 0.0031308) { - color[i] = (color[i]) * 12.92; + if (color[i] <= 0.0031308hf) { + color[i] = (color[i]) * 12.92hf; } else { - color[i] = 1.055 * pow(color[i], (1.0 / 2.4)) - 0.055; + color[i] = 1.055hf * pow(color[i], (1.0hf / 2.4hf)) - 0.055hf; } } diff --git a/impeller/entity/shaders/linear_to_srgb_filter.vert b/impeller/entity/shaders/linear_to_srgb_filter.vert index b741b2744ec60..6bbda03b036d1 100644 --- a/impeller/entity/shaders/linear_to_srgb_filter.vert +++ b/impeller/entity/shaders/linear_to_srgb_filter.vert @@ -2,12 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include + uniform FrameInfo { mat4 mvp; } frame_info; -in vec2 position; -out vec2 v_position; +in f16vec2 position; +out f16vec2 v_position; void main() { v_position = position; diff --git a/impeller/entity/shaders/morphology_filter.frag b/impeller/entity/shaders/morphology_filter.frag index 8d35ab13186a1..d98b6b0727b78 100644 --- a/impeller/entity/shaders/morphology_filter.frag +++ b/impeller/entity/shaders/morphology_filter.frag @@ -2,42 +2,43 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include #include // These values must correspond to the order of the items in the // 'FilterContents::MorphType' enum class. -const float kMorphTypeDilate = 0; -const float kMorphTypeErode = 1; - +const float16_t kMorphTypeDilate = 0.0hf; +const float16_t kMorphTypeErode = 1.0hf; + uniform sampler2D texture_sampler; uniform FragInfo { - float texture_sampler_y_coord_scale; - vec2 texture_size; - vec2 direction; - float radius; - float morph_type; + float16_t texture_sampler_y_coord_scale; + f16vec2 texture_size; + f16vec2 direction; + float16_t radius; + float16_t morph_type; } frag_info; -in vec2 v_texture_coords; -out vec4 frag_color; +in f16vec2 v_texture_coords; +out f16vec4 frag_color; void main() { - vec4 result = frag_info.morph_type == kMorphTypeDilate ? vec4(0) : vec4(1); - vec2 uv_offset = frag_info.direction / frag_info.texture_size; - for (float i = -frag_info.radius; i <= frag_info.radius; i++) { - vec2 texture_coords = v_texture_coords + uv_offset * i; - vec4 color; + f16vec4 result = frag_info.morph_type == kMorphTypeDilate ? f16vec4(0) : f16vec4(1); + f16vec2 uv_offset = frag_info.direction / frag_info.texture_size; + for (float16_t i = -frag_info.radius; i <= frag_info.radius; i++) { + f16vec2 texture_coords = v_texture_coords + uv_offset * i; + f16vec4 color; color = IPSampleWithTileMode( texture_sampler, // sampler texture_coords, // texture coordinates frag_info.texture_sampler_y_coord_scale, // y coordinate scale - kTileModeDecal // tile mode + float16_t(kTileModeDecal) // tile mode ); - if (frag_info.morph_type == kMorphTypeDilate) { + if (frag_info.morph_type == float16_t(kMorphTypeDilate)) { result = max(color, result); } else { result = min(color, result); diff --git a/impeller/entity/shaders/morphology_filter.vert b/impeller/entity/shaders/morphology_filter.vert index c76f3b8a57f48..057fedaec9fbd 100644 --- a/impeller/entity/shaders/morphology_filter.vert +++ b/impeller/entity/shaders/morphology_filter.vert @@ -2,15 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include + uniform FrameInfo { mat4 mvp; } frame_info; -in vec2 position; -in vec2 texture_coords; +in f16vec2 position; +in f16vec2 texture_coords; -out vec2 v_texture_coords; +out f16vec2 v_texture_coords; void main() { gl_Position = frame_info.mvp * vec4(position, 0.0, 1.0); diff --git a/impeller/entity/shaders/position.vert b/impeller/entity/shaders/position.vert index 949fe02afd3f7..b3249f0bae1f7 100644 --- a/impeller/entity/shaders/position.vert +++ b/impeller/entity/shaders/position.vert @@ -2,16 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include uniform VertInfo { mat4 mvp; - vec4 color; + f16vec4 color; } vert_info; -in vec2 position; +in f16vec2 position; -out vec4 v_color; +out f16vec4 v_color; void main() { gl_Position = vert_info.mvp * vec4(position, 0.0, 1.0); diff --git a/impeller/entity/shaders/position_color.vert b/impeller/entity/shaders/position_color.vert index fe62e61474b7b..e69bddfdbb937 100644 --- a/impeller/entity/shaders/position_color.vert +++ b/impeller/entity/shaders/position_color.vert @@ -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 #include uniform VertInfo { @@ -9,9 +10,9 @@ uniform VertInfo { } vert_info; in vec2 position; -in vec4 color; +in f16vec4 color; -out vec4 v_color; +out f16vec4 v_color; void main() { gl_Position = vert_info.mvp * vec4(position, 0.0, 1.0); diff --git a/impeller/entity/shaders/position_uv.vert b/impeller/entity/shaders/position_uv.vert index cb8850b795173..61aaed83a02cc 100644 --- a/impeller/entity/shaders/position_uv.vert +++ b/impeller/entity/shaders/position_uv.vert @@ -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 #include uniform VertInfo { diff --git a/impeller/entity/shaders/radial_gradient_fill.frag b/impeller/entity/shaders/radial_gradient_fill.frag index 31d3ae2463632..1cad23244e8f7 100644 --- a/impeller/entity/shaders/radial_gradient_fill.frag +++ b/impeller/entity/shaders/radial_gradient_fill.frag @@ -2,31 +2,32 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include uniform sampler2D texture_sampler; uniform GradientInfo { - vec2 center; - float radius; - float tile_mode; - float texture_sampler_y_coord_scale; - float alpha; - vec2 half_texel; + f16vec2 center; + float16_t radius; + float16_t tile_mode; + float16_t texture_sampler_y_coord_scale; + float16_t alpha; + f16vec2 half_texel; } gradient_info; -in vec2 v_position; +in f16vec2 v_position; -out vec4 frag_color; +out f16vec4 frag_color; void main() { - float len = length(v_position - gradient_info.center); - float t = len / gradient_info.radius; + float16_t len = length(v_position - gradient_info.center); + float16_t t = len / gradient_info.radius; frag_color = IPSampleLinearWithTileMode( texture_sampler, - vec2(t, 0.5), + f16vec2(t, 0.5hf), gradient_info.texture_sampler_y_coord_scale, gradient_info.half_texel, gradient_info.tile_mode); - frag_color = vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; + frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; } diff --git a/impeller/entity/shaders/radial_gradient_ssbo_fill.frag b/impeller/entity/shaders/radial_gradient_ssbo_fill.frag index b6ce052286102..c8bbf379f1654 100644 --- a/impeller/entity/shaders/radial_gradient_ssbo_fill.frag +++ b/impeller/entity/shaders/radial_gradient_ssbo_fill.frag @@ -2,36 +2,37 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include #include readonly buffer ColorData { - vec4 colors[]; + f16vec4 colors[]; } color_data; uniform GradientInfo { - vec2 center; - float radius; - float tile_mode; - float alpha; - float colors_length; + f16vec2 center; + float16_t radius; + float16_t tile_mode; + float16_t alpha; + float16_t colors_length; } gradient_info; -in vec2 v_position; +in f16vec2 v_position; -out vec4 frag_color; +out f16vec4 frag_color; void main() { - float len = length(v_position - gradient_info.center); - float t = len / gradient_info.radius; + float16_t len = length(v_position - gradient_info.center); + float16_t t = len / gradient_info.radius; - if ((t < 0.0 || t > 1.0) && gradient_info.tile_mode == kTileModeDecal) { - frag_color = vec4(0); + if ((t < 0.0hf || t > 1.0hf) && gradient_info.tile_mode == kTileModeDecal) { + frag_color = f16vec4(0.0hf); return; } t = IPFloatTile(t, gradient_info.tile_mode); - vec3 values = IPComputeFixedGradientValues(t, gradient_info.colors_length); + f16vec3 values = IPComputeFixedGradientValues(t, gradient_info.colors_length); frag_color = mix(color_data.colors[int(values.x)], color_data.colors[int(values.y)], values.z); - frag_color = vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; + frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; } diff --git a/impeller/entity/shaders/rrect_blur.frag b/impeller/entity/shaders/rrect_blur.frag index bc400d0354e06..c4800cc0fdf40 100644 --- a/impeller/entity/shaders/rrect_blur.frag +++ b/impeller/entity/shaders/rrect_blur.frag @@ -2,61 +2,62 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include uniform FragInfo { - vec4 color; - float blur_sigma; - vec2 rect_size; - float corner_radius; + f16vec4 color; + float16_t blur_sigma; + f16vec2 rect_size; + float16_t corner_radius; } frag_info; -in vec2 v_position; +in f16vec2 v_position; -out vec4 frag_color; +out f16vec4 frag_color; -const int kSampleCount = 5; +const float16_t kSampleCount = 5.0hf; -float RRectDistance(vec2 sample_position, vec2 half_size) { +float16_t RRectDistance(f16vec2 sample_position, f16vec2 half_size) { vec2 space = abs(sample_position) - half_size + frag_info.corner_radius; - return length(max(space, 0.0)) + min(max(space.x, space.y), 0.0) - + return float16_t(length(max(space, 0.0hf)) + min(max(space.x, space.y), 0.0hf)) - frag_info.corner_radius; } /// Closed form unidirectional rounded rect blur mask solution using the /// analytical Gaussian integral (with approximated erf). -float RRectShadowX(vec2 sample_position, vec2 half_size) { +float16_t RRectShadowX(f16vec2 sample_position, f16vec2 half_size) { // Compute the X direction distance field (not incorporating the Y distance) // for the rounded rect. - float space = - min(0, half_size.y - frag_info.corner_radius - abs(sample_position.y)); - float rrect_distance = + float16_t space = + min(0.0hf, half_size.y - frag_info.corner_radius - abs(sample_position.y)); + float16_t rrect_distance = half_size.x - frag_info.corner_radius + - sqrt(max(0, frag_info.corner_radius * frag_info.corner_radius - + sqrt(max(0.0hf, frag_info.corner_radius * frag_info.corner_radius - space * space)); // Map the linear distance field to the analytical Gaussian integral. - vec2 integral = IPVec2GaussianIntegral( - sample_position.x + vec2(-rrect_distance, rrect_distance), + f16vec2 integral = IPVec2GaussianIntegral( + sample_position.x + f16vec2(-rrect_distance, rrect_distance), frag_info.blur_sigma); return integral.y - integral.x; } -float RRectShadow(vec2 sample_position, vec2 half_size) { +float16_t RRectShadow(f16vec2 sample_position, f16vec2 half_size) { // Limit the sampling range to 3 standard deviations in the Y direction from // the kernel center to incorporate 99.7% of the color contribution. - float half_sampling_range = frag_info.blur_sigma * 3; + float16_t half_sampling_range = frag_info.blur_sigma * 3.0hf; - float begin_y = max(-half_sampling_range, sample_position.y - half_size.y); - float end_y = min(half_sampling_range, sample_position.y + half_size.y); - float interval = (end_y - begin_y) / kSampleCount; + float16_t begin_y = max(-half_sampling_range, sample_position.y - half_size.y); + float16_t end_y = min(half_sampling_range, sample_position.y + half_size.y); + float16_t interval = (end_y - begin_y) / kSampleCount; // Sample the X blur kSampleCount times, weighted by the Gaussian function. - float result = 0; - for (int sample_i = 0; sample_i < kSampleCount; sample_i++) { - float y = begin_y + interval * (sample_i + 0.5); - result += RRectShadowX(vec2(sample_position.x, sample_position.y - y), + float16_t result = 0.0hf; + for (float16_t sample_i = 0.0hf; sample_i < kSampleCount; sample_i++) { + float16_t y = begin_y + interval * (sample_i + 0.5hf); + result += RRectShadowX(f16vec2(sample_position.x, sample_position.y - y), half_size) * IPGaussian(y, frag_info.blur_sigma) * interval; } @@ -67,10 +68,10 @@ float RRectShadow(vec2 sample_position, vec2 half_size) { void main() { frag_color = frag_info.color; - vec2 half_size = frag_info.rect_size * 0.5; - vec2 sample_position = v_position - half_size; + f16vec2 half_size = frag_info.rect_size * 0.5hf; + f16vec2 sample_position = v_position - half_size; - if (frag_info.blur_sigma > 0) { + if (frag_info.blur_sigma > 0.0hf) { frag_color *= RRectShadow(sample_position, half_size); } else { frag_color *= -RRectDistance(sample_position, half_size); diff --git a/impeller/entity/shaders/rrect_blur.vert b/impeller/entity/shaders/rrect_blur.vert index 36711c6ede5e0..8ada4365f4138 100644 --- a/impeller/entity/shaders/rrect_blur.vert +++ b/impeller/entity/shaders/rrect_blur.vert @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include + uniform VertInfo { mat4 mvp; } diff --git a/impeller/entity/shaders/runtime_effect.vert b/impeller/entity/shaders/runtime_effect.vert index a29402d71e627..7bf8e2bd8e078 100644 --- a/impeller/entity/shaders/runtime_effect.vert +++ b/impeller/entity/shaders/runtime_effect.vert @@ -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 uniform VertInfo { mat4 mvp; } vert_info; diff --git a/impeller/entity/shaders/solid_fill.frag b/impeller/entity/shaders/solid_fill.frag index 5d9c83604dd68..28c7776da9e1d 100644 --- a/impeller/entity/shaders/solid_fill.frag +++ b/impeller/entity/shaders/solid_fill.frag @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include + uniform FragInfo { vec4 color; } diff --git a/impeller/entity/shaders/solid_fill.vert b/impeller/entity/shaders/solid_fill.vert index 8fdc5b1ea3f1e..3ced5986276c7 100644 --- a/impeller/entity/shaders/solid_fill.vert +++ b/impeller/entity/shaders/solid_fill.vert @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include + uniform VertInfo { mat4 mvp; } diff --git a/impeller/entity/shaders/srgb_to_linear_filter.frag b/impeller/entity/shaders/srgb_to_linear_filter.frag index 7c524fe80c291..c8840875b5f46 100644 --- a/impeller/entity/shaders/srgb_to_linear_filter.frag +++ b/impeller/entity/shaders/srgb_to_linear_filter.frag @@ -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 #include #include @@ -11,24 +12,24 @@ uniform sampler2D input_texture; uniform FragInfo { - float texture_sampler_y_coord_scale; - float input_alpha; + float16_t texture_sampler_y_coord_scale; + float16_t input_alpha; } frag_info; -in vec2 v_position; -out vec4 frag_color; +in f16vec2 v_position; +out f16vec4 frag_color; void main() { - vec4 input_color = IPSample(input_texture, v_position, + f16vec4 input_color = IPSample(input_texture, v_position, frag_info.texture_sampler_y_coord_scale) * frag_info.input_alpha; - vec4 color = IPUnpremultiply(input_color); + f16vec4 color = IPUnpremultiply(input_color); for (int i = 0; i < 3; i++) { - if (color[i] <= 0.04045) { - color[i] = color[i] / 12.92; + if (color[i] <= 0.04045hf) { + color[i] = color[i] / 12.92hf; } else { - color[i] = pow((color[i] + 0.055) / 1.055, 2.4); + color[i] = pow((color[i] + 0.055hf) / 1.055hf, 2.4hf); } } diff --git a/impeller/entity/shaders/srgb_to_linear_filter.vert b/impeller/entity/shaders/srgb_to_linear_filter.vert index b741b2744ec60..774a7c7f39ea4 100644 --- a/impeller/entity/shaders/srgb_to_linear_filter.vert +++ b/impeller/entity/shaders/srgb_to_linear_filter.vert @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include + uniform FrameInfo { mat4 mvp; } frame_info; diff --git a/impeller/entity/shaders/sweep_gradient_fill.frag b/impeller/entity/shaders/sweep_gradient_fill.frag index 2fe042dd2c8c2..fe0c57e8883a7 100644 --- a/impeller/entity/shaders/sweep_gradient_fill.frag +++ b/impeller/entity/shaders/sweep_gradient_fill.frag @@ -2,35 +2,36 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include #include uniform sampler2D texture_sampler; uniform GradientInfo { - vec2 center; - float bias; - float scale; - float tile_mode; - float texture_sampler_y_coord_scale; - float alpha; - vec2 half_texel; + f16vec2 center; + float16_t bias; + float16_t scale; + float16_t tile_mode; + float16_t texture_sampler_y_coord_scale; + float16_t alpha; + f16vec2 half_texel; } gradient_info; -in vec2 v_position; +in f16vec2 v_position; -out vec4 frag_color; +out f16vec4 frag_color; void main() { - vec2 coord = v_position - gradient_info.center; + f16vec2 coord = v_position - gradient_info.center; float angle = atan(-coord.y, -coord.x); - float t = (angle * k1Over2Pi + 0.5 + gradient_info.bias) * gradient_info.scale; + float16_t t = (float16_t(angle) * k1Over2Pi + 0.5hf + gradient_info.bias) * gradient_info.scale; frag_color = IPSampleLinearWithTileMode( texture_sampler, - vec2(t, 0.5), + f16vec2(t, 0.5), gradient_info.texture_sampler_y_coord_scale, gradient_info.half_texel, gradient_info.tile_mode); - frag_color = vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; + frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; } diff --git a/impeller/entity/shaders/sweep_gradient_ssbo_fill.frag b/impeller/entity/shaders/sweep_gradient_ssbo_fill.frag index 129f4aa95c467..6e284e0a63009 100644 --- a/impeller/entity/shaders/sweep_gradient_ssbo_fill.frag +++ b/impeller/entity/shaders/sweep_gradient_ssbo_fill.frag @@ -2,39 +2,40 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include #include #include readonly buffer ColorData { - vec4 colors[]; + f16vec4 colors[]; } color_data; uniform GradientInfo { - vec2 center; - float bias; - float scale; - float tile_mode; - float alpha; - float colors_length; + f16vec2 center; + float16_t bias; + float16_t scale; + float16_t tile_mode; + float16_t alpha; + float16_t colors_length; } gradient_info; -in vec2 v_position; +in f16vec2 v_position; -out vec4 frag_color; +out f16vec4 frag_color; void main() { - vec2 coord = v_position - gradient_info.center; + f16vec2 coord = v_position - gradient_info.center; float angle = atan(-coord.y, -coord.x); - float t = (angle * k1Over2Pi + 0.5 + gradient_info.bias) * gradient_info.scale; + float16_t t = (float16_t(angle) * k1Over2Pi + 0.5hf + gradient_info.bias) * gradient_info.scale; - if ((t < 0.0 || t > 1.0) && gradient_info.tile_mode == kTileModeDecal) { - frag_color = vec4(0); + if ((t < 0.0hf || t > 1.0hf) && gradient_info.tile_mode == kTileModeDecal) { + frag_color = f16vec4(0.0hf); return; } t = IPFloatTile(t, gradient_info.tile_mode); - vec3 values = IPComputeFixedGradientValues(t, gradient_info.colors_length); + f16vec3 values = IPComputeFixedGradientValues(t, gradient_info.colors_length); frag_color = mix(color_data.colors[int(values.x)], color_data.colors[int(values.y)], values.z); - frag_color = vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; + frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; } diff --git a/impeller/entity/shaders/test.frag b/impeller/entity/shaders/test.frag new file mode 100644 index 0000000000000..7b7b73346ad34 --- /dev/null +++ b/impeller/entity/shaders/test.frag @@ -0,0 +1,19 @@ +// 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. + +#include + +uniform sampler2D texture_sampler; + +uniform GradientInfo { + float16_t bias; +} gradient_info; + +in vec2 v_position; + +out vec4 frag_color; + +void main() { + frag_color = gradient_info.bias * vec4(1.0, 0.0, 0.0, 1.0); +} diff --git a/impeller/entity/shaders/texture_fill.frag b/impeller/entity/shaders/texture_fill.frag index 913cc7e1e8a70..f8444665f53d1 100644 --- a/impeller/entity/shaders/texture_fill.frag +++ b/impeller/entity/shaders/texture_fill.frag @@ -2,22 +2,23 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include uniform sampler2D texture_sampler; uniform FragInfo { - float texture_sampler_y_coord_scale; - float alpha; + float16_t texture_sampler_y_coord_scale; + float16_t alpha; } frag_info; -in vec2 v_texture_coords; +in f16vec2 v_texture_coords; out vec4 frag_color; void main() { - vec4 sampled = IPSample(texture_sampler, v_texture_coords, + f16vec4 sampled = IPSample(texture_sampler, v_texture_coords, frag_info.texture_sampler_y_coord_scale); frag_color = sampled * frag_info.alpha; } diff --git a/impeller/entity/shaders/texture_fill.vert b/impeller/entity/shaders/texture_fill.vert index c8abc9aaabbce..212f9e288f34f 100644 --- a/impeller/entity/shaders/texture_fill.vert +++ b/impeller/entity/shaders/texture_fill.vert @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include + uniform VertInfo { mat4 mvp; } diff --git a/impeller/entity/shaders/tiled_texture_fill.frag b/impeller/entity/shaders/tiled_texture_fill.frag index 9892643517043..b6e07bcd21b22 100644 --- a/impeller/entity/shaders/tiled_texture_fill.frag +++ b/impeller/entity/shaders/tiled_texture_fill.frag @@ -2,21 +2,22 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include uniform sampler2D texture_sampler; uniform FragInfo { - float texture_sampler_y_coord_scale; - float x_tile_mode; - float y_tile_mode; - float alpha; + float16_t texture_sampler_y_coord_scale; + float16_t x_tile_mode; + float16_t y_tile_mode; + float16_t alpha; } frag_info; -in vec2 v_texture_coords; +in f16vec2 v_texture_coords; -out vec4 frag_color; +out f16vec4 frag_color; void main() { frag_color = diff --git a/impeller/entity/shaders/tiled_texture_fill.vert b/impeller/entity/shaders/tiled_texture_fill.vert index db73769940067..0442a6384d096 100644 --- a/impeller/entity/shaders/tiled_texture_fill.vert +++ b/impeller/entity/shaders/tiled_texture_fill.vert @@ -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 #include uniform VertInfo { diff --git a/impeller/entity/shaders/vertices.frag b/impeller/entity/shaders/vertices.frag index ccad5b7d3e141..c42e809ecc14d 100644 --- a/impeller/entity/shaders/vertices.frag +++ b/impeller/entity/shaders/vertices.frag @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include + in vec4 v_color; out vec4 frag_color; diff --git a/impeller/entity/shaders/yuv_to_rgb_filter.frag b/impeller/entity/shaders/yuv_to_rgb_filter.frag index b734b486024ab..2e40738e94c0a 100644 --- a/impeller/entity/shaders/yuv_to_rgb_filter.frag +++ b/impeller/entity/shaders/yuv_to_rgb_filter.frag @@ -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 #include #include @@ -10,26 +11,26 @@ uniform sampler2D uv_texture; // These values must correspond to the order of the items in the // 'YUVColorSpace' enum class. -const float kBT601LimitedRange = 0; -const float kBT601FullRange = 1; +const float16_t kBT601LimitedRange = 0.0hf; +const float16_t kBT601FullRange = 1.0hf; uniform FragInfo { - float texture_sampler_y_coord_scale; + float16_t texture_sampler_y_coord_scale; + float16_t yuv_color_space; mat4 matrix; - float yuv_color_space; } frag_info; -in vec2 v_position; -out vec4 frag_color; +in f16vec2 v_position; +out f16vec4 frag_color; void main() { - vec3 yuv; - vec3 yuv_offset = vec3(0.0, 0.5, 0.5); + f16vec3 yuv; + f16vec3 yuv_offset = f16vec3(0.0hf, 0.5hf, 0.5hf); if (frag_info.yuv_color_space == kBT601LimitedRange) { - yuv_offset.x = 16.0 / 255.0; + yuv_offset.x = 16.0hf / 255.0hf; } - yuv.x = IPSample(y_texture, v_position, frag_info.texture_sampler_y_coord_scale).r; - yuv.yz = IPSample(uv_texture, v_position, frag_info.texture_sampler_y_coord_scale).rg; - frag_color = frag_info.matrix * vec4(yuv - yuv_offset, 1); + yuv.x = IPSample(y_texture, v_position, frag_info.texture_sampler_y_coord_scale).x; + yuv.yz = IPSample(uv_texture, v_position, frag_info.texture_sampler_y_coord_scale).xy; + frag_color = f16mat4(frag_info.matrix) * f16vec4(yuv - yuv_offset, 1.0hf); } diff --git a/impeller/entity/shaders/yuv_to_rgb_filter.vert b/impeller/entity/shaders/yuv_to_rgb_filter.vert index b741b2744ec60..774a7c7f39ea4 100644 --- a/impeller/entity/shaders/yuv_to_rgb_filter.vert +++ b/impeller/entity/shaders/yuv_to_rgb_filter.vert @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include + uniform FrameInfo { mat4 mvp; } frame_info; From e2fcede13c1908174cddae03cf4118a1a6335261 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 21 Nov 2022 15:53:43 -0800 Subject: [PATCH 2/6] remove extra conversions --- .../shader_lib/impeller/blending.glsl | 52 +++++++++---------- .../shader_lib/impeller/branching.glsl | 6 +-- .../shader_lib/impeller/gaussian.glsl | 6 +-- .../compiler/shader_lib/impeller/texture.glsl | 18 +++---- .../shaders/blending/advanced_blend.glsl | 4 +- .../entity/shaders/morphology_filter.frag | 4 +- 6 files changed, 45 insertions(+), 45 deletions(-) diff --git a/impeller/compiler/shader_lib/impeller/blending.glsl b/impeller/compiler/shader_lib/impeller/blending.glsl index 649d86d0b0e54..b7eb5ccaafe2a 100644 --- a/impeller/compiler/shader_lib/impeller/blending.glsl +++ b/impeller/compiler/shader_lib/impeller/blending.glsl @@ -26,10 +26,10 @@ f16vec3 IPClipColor(f16vec3 color) { // `lum - mn` and `mx - lum` will always be >= 0 in the following conditions, // so adding a tiny value is enough to make these divisions safe. if (mn < 0.0hf) { - color = lum + (((color - lum) * lum) / (lum - mn + float16_t(kEhCloseEnough))); + color = lum + (((color - lum) * lum) / (lum - mn + kEhCloseEnough)); } if (mx > 1.0hf) { - color = lum + (((color - lum) * (1.0hf - lum)) / (mx - lum + float16_t(kEhCloseEnough))); + color = lum + (((color - lum) * (1.0hf - lum)) / (mx - lum + kEhCloseEnough)); } return color; } @@ -47,7 +47,7 @@ float16_t IPSaturation(f16vec3 color) { f16vec3 IPSetSaturation(f16vec3 color, float16_t saturation) { float16_t mn = min(min(color.r, color.g), color.b); float16_t mx = max(max(color.r, color.g), color.b); - return (mn < mx) ? ((color - mn) * saturation) / (mx - mn) : f16vec3(0); + return (mn < mx) ? ((color - mn) * saturation) / (mx - mn) : f16vec3(0.0hf); } //------------------------------------------------------------------------------ @@ -90,24 +90,24 @@ f16vec3 IPBlendColorDodge(f16vec3 dst, f16vec3 src) { f16vec3 color = min(f16vec3(1.0hf), dst / (1.0hf - src)); - if (dst.r < float16_t(kEhCloseEnough)) { - color.r = float16_t(0.); + if (dst.r < kEhCloseEnough) { + color.r = 0.0hf; } - if (dst.g < float16_t(kEhCloseEnough)) { - color.g = float16_t(0.); + if (dst.g < kEhCloseEnough) { + color.g = 0.0hf; } - if (dst.b < float16_t(kEhCloseEnough)) { - color.b = float16_t(0.); + if (dst.b < kEhCloseEnough) { + color.b = 0.0hf; } - if (1. - src.r < float16_t(kEhCloseEnough)) { - color.r = float16_t(1.); + if (1.0hf - src.r < kEhCloseEnough) { + color.r = 1.0hf; } - if (1. - src.g < float16_t(kEhCloseEnough)) { - color.g = float16_t(1.); + if (1. - src.g < kEhCloseEnough) { + color.g = 1.0hf; } - if (1. - src.b < float16_t(kEhCloseEnough)) { - color.b = float16_t(1.); + if (1. - src.b < kEhCloseEnough) { + color.b = 1.0hf; } return color; @@ -118,24 +118,24 @@ f16vec3 IPBlendColorBurn(f16vec3 dst, f16vec3 src) { f16vec3 color = 1.0hf - min(f16vec3(1.0hf), (1.0hf - dst) / src); - if (1.0hf - dst.r < float16_t(kEhCloseEnough)) { + if (1.0hf - dst.r < kEhCloseEnough) { color.r = 1.0hf; } - if (1.0hf - dst.g < float16_t(kEhCloseEnough)) { - color.g = float16_t(1.); + if (1.0hf - dst.g < kEhCloseEnough) { + color.g = 1.0hf; } - if (1.0hf - dst.b < float16_t(kEhCloseEnough)) { - color.b = float16_t(.1); + if (1.0hf - dst.b < kEhCloseEnough) { + color.b = 0.1hf; } - if (src.r < float16_t(kEhCloseEnough)) { - color.r = float16_t(0.); + if (src.r < kEhCloseEnough) { + color.r = 0.0hf; } - if (src.g < float16_t(kEhCloseEnough)) { - color.g = float16_t(0.); + if (src.g < kEhCloseEnough) { + color.g = 0.0hf; } - if (src.b < float16_t(kEhCloseEnough)) { - color.b = float16_t(0.); + if (src.b < kEhCloseEnough) { + color.b = 0.0hf; } return color; diff --git a/impeller/compiler/shader_lib/impeller/branching.glsl b/impeller/compiler/shader_lib/impeller/branching.glsl index 93ac186a79ad0..5b9530f0f8c4b 100644 --- a/impeller/compiler/shader_lib/impeller/branching.glsl +++ b/impeller/compiler/shader_lib/impeller/branching.glsl @@ -13,9 +13,9 @@ /// Returns 1.0 if x == y, otherwise 0.0. BoolV3 IPVec3IsEqual(f16vec3 x, float16_t y) { f16vec3 diff = abs(x - y); - return f16vec3(diff.r < float16_t(kEhCloseEnough), // - diff.g < float16_t(kEhCloseEnough), // - diff.b < float16_t(kEhCloseEnough)); + return f16vec3(diff.r < kEhCloseEnough, // + diff.g < kEhCloseEnough, // + diff.b < kEhCloseEnough); } /// Perform a branchless greater than check. diff --git a/impeller/compiler/shader_lib/impeller/gaussian.glsl b/impeller/compiler/shader_lib/impeller/gaussian.glsl index 9aaa81d467675..2c5837e9c407f 100644 --- a/impeller/compiler/shader_lib/impeller/gaussian.glsl +++ b/impeller/compiler/shader_lib/impeller/gaussian.glsl @@ -11,7 +11,7 @@ /// Gaussian distribution function. float16_t IPGaussian(float16_t x, float16_t sigma) { float16_t variance = sigma * sigma; - return exp(-0.5hf * x * x / variance) / (float16_t(kSqrtTwoPi) * sigma); + return exp(-0.5hf * x * x / variance) / (kSqrtTwoPi * sigma); } /// Abramowitz and Stegun erf approximation. @@ -35,7 +35,7 @@ float16_t IPGaussianIntegral(float16_t x, float16_t sigma) { // ( 1 + erf( x * (sqrt(2) / (2 * sigma) ) ) / 2 // Because this sigmoid is always > 1, we remap it (n * 1.07 - 0.07) // so that it always fades to zero before it reaches the blur radius. - return 0.535hf * IPErf(x * (float16_t(kHalfSqrtTwo) / sigma)) + 0.465hf; + return 0.535hf * IPErf(x * (kHalfSqrtTwo / sigma)) + 0.465hf; } /// Vec2 variation for the indefinite integral of the Gaussian function (with @@ -44,7 +44,7 @@ f16vec2 IPVec2GaussianIntegral(f16vec2 x, float16_t sigma) { // ( 1 + erf( x * (sqrt(2) / (2 * sigma) ) ) / 2 // Because this sigmoid is always > 1, we remap it (n * 1.07 - 0.07) // so that it always fades to zero before it reaches the blur radius. - return 0.535hf * IPVec2Erf(x * (float16_t(kHalfSqrtTwo) / sigma)) + 0.465hf; + return 0.535hf * IPVec2Erf(x * (kHalfSqrtTwo / sigma)) + 0.465hf; } /// Simple logistic sigmoid with a domain of [-1, 1] and range of [0, 1]. diff --git a/impeller/compiler/shader_lib/impeller/texture.glsl b/impeller/compiler/shader_lib/impeller/texture.glsl index 100e98dd67102..631f668f7f6e4 100644 --- a/impeller/compiler/shader_lib/impeller/texture.glsl +++ b/impeller/compiler/shader_lib/impeller/texture.glsl @@ -34,10 +34,10 @@ f16vec4 IPSampleLinear(sampler2D texture_sampler, f16vec2 coords, float16_t y_co // These values must correspond to the order of the items in the // 'Entity::TileMode' enum class. -const float kTileModeClamp = 0; -const float kTileModeRepeat = 1; -const float kTileModeMirror = 2; -const float kTileModeDecal = 3; +const float16_t kTileModeClamp = 0.0hf; +const float16_t kTileModeRepeat = 1.0hf; +const float16_t kTileModeMirror = 2.0hf; +const float16_t kTileModeDecal = 3.0hf; /// Remap a float16_t using a tiling mode. /// @@ -46,11 +46,11 @@ const float kTileModeDecal = 3; /// `t`. /// When `t` is between [0 to 1), the original unchanged `t` is always returned. float16_t IPFloatTile(float16_t t, float16_t tile_mode) { - if (tile_mode == float16_t(kTileModeClamp)) { + if (tile_mode == kTileModeClamp) { t = clamp(t, 0.0hf, 1.0hf); - } else if (tile_mode == float16_t(kTileModeRepeat)) { + } else if (tile_mode == kTileModeRepeat) { t = fract(t); - } else if (tile_mode == float16_t(kTileModeMirror)) { + } else if (tile_mode == kTileModeMirror) { float16_t t1 = t - 1.0hf; float16_t t2 = t1 - 2.0hf * floor(t1 * 0.5hf) - 1.0hf; t = abs(t2); @@ -105,8 +105,8 @@ f16vec4 IPSampleLinearWithTileMode(sampler2D tex, f16vec2 half_texel, float16_t x_tile_mode, float16_t y_tile_mode) { - if (x_tile_mode == float16_t(kTileModeDecal) && (coords.x < 0.0hf || coords.x >= 1.0hf) || - y_tile_mode == float16_t(kTileModeDecal) && (coords.y < 0.0hf || coords.y >= 1.0hf)) { + if (x_tile_mode == kTileModeDecal && (coords.x < 0.0hf || coords.x >= 1.0hf) || + y_tile_mode == kTileModeDecal && (coords.y < 0.0hf || coords.y >= 1.0hf)) { return f16vec4(0.0hf); } diff --git a/impeller/entity/shaders/blending/advanced_blend.glsl b/impeller/entity/shaders/blending/advanced_blend.glsl index 5c7ebab515e32..f87323518409e 100644 --- a/impeller/entity/shaders/blending/advanced_blend.glsl +++ b/impeller/entity/shaders/blending/advanced_blend.glsl @@ -28,7 +28,7 @@ void main() { IPSampleWithTileMode(texture_sampler_dst, // sampler v_dst_texture_coords, // texture coordinates blend_info.dst_y_coord_scale, // y coordinate scale - float16_t(kTileModeDecal) // tile mode + kTileModeDecal // tile mode ) * blend_info.dst_input_alpha; f16vec4 dst = IPUnpremultiply(dst_sample); @@ -38,7 +38,7 @@ void main() { texture_sampler_src, // sampler v_src_texture_coords, // texture coordinates blend_info.src_y_coord_scale, // y coordinate scale - float16_t(kTileModeDecal) // tile mode + kTileModeDecal // tile mode )); f16vec4 blended = f16vec4(Blend(dst.rgb, src.rgb), 1.0hf) * dst.a; diff --git a/impeller/entity/shaders/morphology_filter.frag b/impeller/entity/shaders/morphology_filter.frag index d98b6b0727b78..b104bd4326c9b 100644 --- a/impeller/entity/shaders/morphology_filter.frag +++ b/impeller/entity/shaders/morphology_filter.frag @@ -36,9 +36,9 @@ void main() { texture_sampler, // sampler texture_coords, // texture coordinates frag_info.texture_sampler_y_coord_scale, // y coordinate scale - float16_t(kTileModeDecal) // tile mode + kTileModeDecal // tile mode ); - if (frag_info.morph_type == float16_t(kMorphTypeDilate)) { + if (frag_info.morph_type == kMorphTypeDilate) { result = max(color, result); } else { result = min(color, result); From c27b602b904e86335369280763dbf42ff78f20bb Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 21 Nov 2022 15:55:29 -0800 Subject: [PATCH 3/6] format --- .../shader_lib/impeller/blending.glsl | 19 ++- .../shader_lib/impeller/branching.glsl | 11 +- .../compiler/shader_lib/impeller/color.glsl | 2 +- .../shader_lib/impeller/gaussian.glsl | 5 +- .../shader_lib/impeller/gradient.glsl | 2 +- .../compiler/shader_lib/impeller/texture.glsl | 16 +- .../shader_lib/impeller/texture.glsl.orig | 131 ++++++++++++++++ .../shader_lib/impeller/texture.glsl.rej | 148 ++++++++++++++++++ .../compiler/shader_lib/impeller/types.glsl | 5 +- impeller/entity/shaders/atlas_fill.frag | 4 +- .../shaders/blending/advanced_blend.glsl | 19 +-- .../blending/advanced_blend_color.frag | 2 +- .../blending/advanced_blend_colorburn.frag | 2 +- .../blending/advanced_blend_colordodge.frag | 2 +- .../blending/advanced_blend_darken.frag | 2 +- .../blending/advanced_blend_difference.frag | 2 +- .../blending/advanced_blend_exclusion.frag | 2 +- .../blending/advanced_blend_hardlight.frag | 2 +- .../shaders/blending/advanced_blend_hue.frag | 2 +- .../blending/advanced_blend_lighten.frag | 2 +- .../blending/advanced_blend_luminosity.frag | 2 +- .../blending/advanced_blend_multiply.frag | 2 +- .../blending/advanced_blend_overlay.frag | 2 +- .../blending/advanced_blend_saturation.frag | 2 +- .../blending/advanced_blend_screen.frag | 2 +- .../blending/advanced_blend_softlight.frag | 2 +- impeller/entity/shaders/blending/blend.frag | 5 +- impeller/entity/shaders/border_mask_blur.frag | 16 +- .../shaders/color_matrix_color_filter.frag | 12 +- impeller/entity/shaders/gaussian_blur.frag | 7 +- impeller/entity/shaders/glyph_atlas.frag | 17 +- impeller/entity/shaders/glyph_atlas.vert | 2 +- impeller/entity/shaders/glyph_atlas_sdf.vert | 2 +- impeller/entity/shaders/gradient_fill.vert | 2 +- .../entity/shaders/linear_gradient_fill.frag | 22 ++- .../shaders/linear_gradient_ssbo_fill.frag | 20 +-- .../entity/shaders/linear_to_srgb_filter.frag | 9 +- .../entity/shaders/morphology_filter.frag | 18 +-- impeller/entity/shaders/position.vert | 5 +- impeller/entity/shaders/position_color.vert | 2 +- impeller/entity/shaders/position_uv.vert | 2 +- .../entity/shaders/radial_gradient_fill.frag | 16 +- .../shaders/radial_gradient_ssbo_fill.frag | 14 +- impeller/entity/shaders/rrect_blur.frag | 14 +- .../entity/shaders/srgb_to_linear_filter.frag | 9 +- .../entity/shaders/sweep_gradient_fill.frag | 19 +-- .../shaders/sweep_gradient_ssbo_fill.frag | 17 +- impeller/entity/shaders/test.frag | 3 +- impeller/entity/shaders/texture_fill.frag | 4 +- .../entity/shaders/tiled_texture_fill.frag | 2 +- .../entity/shaders/tiled_texture_fill.vert | 2 +- .../entity/shaders/yuv_to_rgb_filter.frag | 13 +- 52 files changed, 479 insertions(+), 167 deletions(-) create mode 100644 impeller/compiler/shader_lib/impeller/texture.glsl.orig create mode 100644 impeller/compiler/shader_lib/impeller/texture.glsl.rej diff --git a/impeller/compiler/shader_lib/impeller/blending.glsl b/impeller/compiler/shader_lib/impeller/blending.glsl index b7eb5ccaafe2a..834cd8d1e7344 100644 --- a/impeller/compiler/shader_lib/impeller/blending.glsl +++ b/impeller/compiler/shader_lib/impeller/blending.glsl @@ -5,9 +5,9 @@ #ifndef BLENDING_GLSL_ #define BLENDING_GLSL_ -#include #include #include +#include //------------------------------------------------------------------------------ /// HSV utilities. @@ -29,7 +29,8 @@ f16vec3 IPClipColor(f16vec3 color) { color = lum + (((color - lum) * lum) / (lum - mn + kEhCloseEnough)); } if (mx > 1.0hf) { - color = lum + (((color - lum) * (1.0hf - lum)) / (mx - lum + kEhCloseEnough)); + color = + lum + (((color - lum) * (1.0hf - lum)) / (mx - lum + kEhCloseEnough)); } return color; } @@ -66,7 +67,8 @@ f16vec3 IPBlendScreen(f16vec3 dst, f16vec3 src) { f16vec3 IPBlendHardLight(f16vec3 dst, f16vec3 src) { // https://www.w3.org/TR/compositing-1/#blendinghardlight - return IPVec3Choose(dst * (2.0hf * src), IPBlendScreen(dst, 2.0hf * src - 1.0hf), src); + return IPVec3Choose(dst * (2.0hf * src), + IPBlendScreen(dst, 2.0hf * src - 1.0hf), src); } f16vec3 IPBlendOverlay(f16vec3 dst, f16vec3 src) { @@ -144,13 +146,14 @@ f16vec3 IPBlendColorBurn(f16vec3 dst, f16vec3 src) { f16vec3 IPBlendSoftLight(f16vec3 dst, f16vec3 src) { // https://www.w3.org/TR/compositing-1/#blendingsoftlight - f16vec3 D = IPVec3ChooseCutoff(((16.0hf * dst - 12.0hf) * dst + 4.0hf) * dst, // - sqrt(dst), // - dst, // - 0.25hf); + f16vec3 D = + IPVec3ChooseCutoff(((16.0hf * dst - 12.0hf) * dst + 4.0hf) * dst, // + sqrt(dst), // + dst, // + 0.25hf); return IPVec3Choose(dst - (1.0hf - 2.0hf * src) * dst * (1.0hf - dst), // - dst + (2.0hf * src - 1.0hf) * (D - dst), // + dst + (2.0hf * src - 1.0hf) * (D - dst), // src); } diff --git a/impeller/compiler/shader_lib/impeller/branching.glsl b/impeller/compiler/shader_lib/impeller/branching.glsl index 5b9530f0f8c4b..7eebb9db1c484 100644 --- a/impeller/compiler/shader_lib/impeller/branching.glsl +++ b/impeller/compiler/shader_lib/impeller/branching.glsl @@ -5,8 +5,8 @@ #ifndef BRANCHING_GLSL_ #define BRANCHING_GLSL_ -#include #include +#include /// Perform an equality check for each vec3 component. /// @@ -14,8 +14,8 @@ BoolV3 IPVec3IsEqual(f16vec3 x, float16_t y) { f16vec3 diff = abs(x - y); return f16vec3(diff.r < kEhCloseEnough, // - diff.g < kEhCloseEnough, // - diff.b < kEhCloseEnough); + diff.g < kEhCloseEnough, // + diff.b < kEhCloseEnough); } /// Perform a branchless greater than check. @@ -40,7 +40,10 @@ BoolF IPFloatIsLessThan(float16_t x, float16_t y) { } /// For each vec3 component, if value > cutoff, return b, otherwise return a. -f16vec3 IPVec3ChooseCutoff(f16vec3 a, f16vec3 b, f16vec3 value, float16_t cutoff) { +f16vec3 IPVec3ChooseCutoff(f16vec3 a, + f16vec3 b, + f16vec3 value, + float16_t cutoff) { return mix(a, b, IPVec3IsGreaterThan(value, f16vec3(cutoff))); } diff --git a/impeller/compiler/shader_lib/impeller/color.glsl b/impeller/compiler/shader_lib/impeller/color.glsl index 088c0a0d661c4..6b2c729f66c9a 100644 --- a/impeller/compiler/shader_lib/impeller/color.glsl +++ b/impeller/compiler/shader_lib/impeller/color.glsl @@ -5,8 +5,8 @@ #ifndef COLOR_GLSL_ #define COLOR_GLSL_ -#include #include +#include /// Convert a premultiplied color (a color which has its color components /// multiplied with its alpha value) to an unpremultiplied color. diff --git a/impeller/compiler/shader_lib/impeller/gaussian.glsl b/impeller/compiler/shader_lib/impeller/gaussian.glsl index 2c5837e9c407f..76daf0d6264e3 100644 --- a/impeller/compiler/shader_lib/impeller/gaussian.glsl +++ b/impeller/compiler/shader_lib/impeller/gaussian.glsl @@ -5,8 +5,8 @@ #ifndef GAUSSIAN_GLSL_ #define GAUSSIAN_GLSL_ -#include #include +#include /// Gaussian distribution function. float16_t IPGaussian(float16_t x, float16_t sigma) { @@ -18,7 +18,8 @@ float16_t IPGaussian(float16_t x, float16_t sigma) { float16_t IPErf(float16_t x) { float16_t a = abs(x); // 0.278393*x + 0.230389*x^2 + 0.078108*x^4 + 1 - float16_t b = (0.278393hf + (0.230389hf + 0.078108hf * a * a) * a) * a + 1.0hf; + float16_t b = + (0.278393hf + (0.230389hf + 0.078108hf * a * a) * a) * a + 1.0hf; return sign(x) * (1.0hf - 1.0hf / (b * b * b * b)); } diff --git a/impeller/compiler/shader_lib/impeller/gradient.glsl b/impeller/compiler/shader_lib/impeller/gradient.glsl index c5ace9ecc9970..7a5bc70430dde 100644 --- a/impeller/compiler/shader_lib/impeller/gradient.glsl +++ b/impeller/compiler/shader_lib/impeller/gradient.glsl @@ -5,8 +5,8 @@ #ifndef GRADIENT_GLSL_ #define GRADIENT_GLSL_ -#include #include +#include /// Compute the indexes and mix coefficient used to mix colors for an /// arbitrarily sized color gradient. diff --git a/impeller/compiler/shader_lib/impeller/texture.glsl b/impeller/compiler/shader_lib/impeller/texture.glsl index 6cfe681f7a565..c0d2299328248 100644 --- a/impeller/compiler/shader_lib/impeller/texture.glsl +++ b/impeller/compiler/shader_lib/impeller/texture.glsl @@ -50,7 +50,7 @@ float16_t IPFloatTile(float16_t t, float16_t tile_mode) { t = clamp(t, 0.0hf, 1.0hf); } else if (tile_mode == kTileModeRepeat) { t = fract(t); - } else if (tile_mode == kTileModeMirror) { + } else if (tile_mode == kTileModeMirror) { float16_t t1 = t - 1.0hf; float16_t t2 = t1 - 2.0hf * floor(t1 * 0.5hf) - 1.0hf; t = abs(t2); @@ -71,10 +71,10 @@ f16vec2 IPVec2Tile(f16vec2 coords, float16_t x_tile_mode, float16_t y_tile_mode) /// This is useful for Impeller graphics backend that don't have native support /// for Decal. f16vec4 IPSampleWithTileMode(sampler2D tex, - f16vec2 coords, - float16_t y_coord_scale, - float16_t x_tile_mode, - float16_t y_tile_mode) { + f16vec2 coords, + float16_t y_coord_scale, + float16_t x_tile_mode, + float16_t y_tile_mode) { if (x_tile_mode == kTileModeDecal && (coords.x < 0.hf || coords.x >= 1.hf) || y_tile_mode == kTileModeDecal && (coords.y < 0.hf || coords.y >= 1.hf)) { return f16vec4(0.0hf); @@ -89,9 +89,9 @@ f16vec4 IPSampleWithTileMode(sampler2D tex, /// This is useful for Impeller graphics backend that don't have native support /// for Decal. f16vec4 IPSampleWithTileMode(sampler2D tex, - f16vec2 coords, - float16_t y_coord_scale, - float16_t tile_mode) { + f16vec2 coords, + float16_t y_coord_scale, + float16_t tile_mode) { return IPSampleWithTileMode(tex, coords, y_coord_scale, tile_mode, tile_mode); } diff --git a/impeller/compiler/shader_lib/impeller/texture.glsl.orig b/impeller/compiler/shader_lib/impeller/texture.glsl.orig new file mode 100644 index 0000000000000..6cfe681f7a565 --- /dev/null +++ b/impeller/compiler/shader_lib/impeller/texture.glsl.orig @@ -0,0 +1,131 @@ +// 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 TEXTURE_GLSL_ +#define TEXTURE_GLSL_ + +#include +#include + +/// Sample from a texture. +/// +/// If `y_coord_scale` < 0.0, the Y coordinate is flipped. This is useful +/// for Impeller graphics backends that use a flipped framebuffer coordinate +/// space. +f16vec4 IPSample(sampler2D texture_sampler, f16vec2 coords, float16_t y_coord_scale) { + if (y_coord_scale < 0.0hf) { + coords.y = 1.0hf - coords.y; + } + return f16vec4(texture(texture_sampler, coords)); +} + +/// Sample from a texture. +/// +/// If `y_coord_scale` < 0.0, the Y coordinate is flipped. This is useful +/// for Impeller graphics backends that use a flipped framebuffer coordinate +/// space. +/// The range of `coods` will be mapped from [0, 1] to [half_texel, 1 - half_texel] +f16vec4 IPSampleLinear(sampler2D texture_sampler, f16vec2 coords, float16_t y_coord_scale, f16vec2 half_texel) { + coords.x = mix(half_texel.x, 1.0hf - half_texel.x, coords.x); + coords.y = mix(half_texel.y, 1.0hf - half_texel.y, coords.y); + return IPSample(texture_sampler, coords, y_coord_scale); +} + +// These values must correspond to the order of the items in the +// 'Entity::TileMode' enum class. +const float16_t kTileModeClamp = 0.0hf; +const float16_t kTileModeRepeat = 1.0hf; +const float16_t kTileModeMirror = 2.0hf; +const float16_t kTileModeDecal = 3.0hf; + +/// Remap a float16_t using a tiling mode. +/// +/// When `tile_mode` is `kTileModeDecal`, no tiling is applied and `t` is +/// returned. In all other cases, a value between 0 and 1 is returned by tiling +/// `t`. +/// When `t` is between [0 to 1), the original unchanged `t` is always returned. +float16_t IPFloatTile(float16_t t, float16_t tile_mode) { + if (tile_mode == kTileModeClamp) { + t = clamp(t, 0.0hf, 1.0hf); + } else if (tile_mode == kTileModeRepeat) { + t = fract(t); + } else if (tile_mode == kTileModeMirror) { + float16_t t1 = t - 1.0hf; + float16_t t2 = t1 - 2.0hf * floor(t1 * 0.5hf) - 1.0hf; + t = abs(t2); + } + return t; +} + +/// Remap a vec2 using a tiling mode. +/// +/// Runs each component of the vec2 through `IPFloatTile`. +f16vec2 IPVec2Tile(f16vec2 coords, float16_t x_tile_mode, float16_t y_tile_mode) { + return f16vec2(IPFloatTile(coords.x, x_tile_mode), + IPFloatTile(coords.y, y_tile_mode)); +} + +/// Sample a texture, emulating a specific tile mode. +/// +/// This is useful for Impeller graphics backend that don't have native support +/// for Decal. +f16vec4 IPSampleWithTileMode(sampler2D tex, + f16vec2 coords, + float16_t y_coord_scale, + float16_t x_tile_mode, + float16_t y_tile_mode) { + if (x_tile_mode == kTileModeDecal && (coords.x < 0.hf || coords.x >= 1.hf) || + y_tile_mode == kTileModeDecal && (coords.y < 0.hf || coords.y >= 1.hf)) { + return f16vec4(0.0hf); + } + + return IPSample(tex, IPVec2Tile(coords, x_tile_mode, y_tile_mode), + y_coord_scale); +} + +/// Sample a texture, emulating a specific tile mode. +/// +/// This is useful for Impeller graphics backend that don't have native support +/// for Decal. +f16vec4 IPSampleWithTileMode(sampler2D tex, + f16vec2 coords, + float16_t y_coord_scale, + float16_t tile_mode) { + return IPSampleWithTileMode(tex, coords, y_coord_scale, tile_mode, tile_mode); +} + +/// Sample a texture, emulating a specific tile mode. +/// +/// This is useful for Impeller graphics backend that don't have native support +/// for Decal. +/// The range of `coods` will be mapped from [0, 1] to [half_texel, 1 - half_texel] +f16vec4 IPSampleLinearWithTileMode(sampler2D tex, + f16vec2 coords, + float16_t y_coord_scale, + f16vec2 half_texel, + float16_t x_tile_mode, + float16_t y_tile_mode) { + if (x_tile_mode == kTileModeDecal && (coords.x < 0.0hf || coords.x >= 1.0hf) || + y_tile_mode == kTileModeDecal && (coords.y < 0.0hf || coords.y >= 1.0hf)) { + return f16vec4(0.0hf); + } + + return IPSampleLinear(tex, IPVec2Tile(coords, x_tile_mode, y_tile_mode), + y_coord_scale, half_texel); +} + +/// Sample a texture, emulating a specific tile mode. +/// +/// This is useful for Impeller graphics backend that don't have native support +/// for Decal. +/// The range of `coods` will be mapped from [0, 1] to [half_texel, 1 - half_texel] +f16vec4 IPSampleLinearWithTileMode(sampler2D tex, + f16vec2 coords, + float16_t y_coord_scale, + f16vec2 half_texel, + float16_t tile_mode) { + return IPSampleLinearWithTileMode(tex, coords, y_coord_scale, half_texel, tile_mode, tile_mode); +} + +#endif diff --git a/impeller/compiler/shader_lib/impeller/texture.glsl.rej b/impeller/compiler/shader_lib/impeller/texture.glsl.rej new file mode 100644 index 0000000000000..c59fffbf3eddc --- /dev/null +++ b/impeller/compiler/shader_lib/impeller/texture.glsl.rej @@ -0,0 +1,148 @@ +*************** +*** 5,19 **** + #ifndef TEXTURE_GLSL_ + #define TEXTURE_GLSL_ + +- #include + #include + + /// Sample from a texture. + /// + /// If < 0.0, the Y coordinate is flipped. This is useful + /// for Impeller graphics backends that use a flipped framebuffer coordinate + /// space. +- f16vec4 IPSample(sampler2D texture_sampler, f16vec2 coords, float16_t y_coord_scale) { + if (y_coord_scale < 0.0hf) { + coords.y = 1.0hf - coords.y; + } +--- 5,21 ---- + #ifndef TEXTURE_GLSL_ + #define TEXTURE_GLSL_ + + #include ++ #include + + /// Sample from a texture. + /// + /// If < 0.0, the Y coordinate is flipped. This is useful + /// for Impeller graphics backends that use a flipped framebuffer coordinate + /// space. ++ f16vec4 IPSample(sampler2D texture_sampler, ++ f16vec2 coords, ++ float16_t y_coord_scale) { + if (y_coord_scale < 0.0hf) { + coords.y = 1.0hf - coords.y; + } +*************** +*** 25,32 **** + /// If < 0.0, the Y coordinate is flipped. This is useful + /// for Impeller graphics backends that use a flipped framebuffer coordinate + /// space. +- /// The range of will be mapped from [0, 1] to [half_texel, 1 - half_texel] +- f16vec4 IPSampleLinear(sampler2D texture_sampler, f16vec2 coords, float16_t y_coord_scale, f16vec2 half_texel) { + coords.x = mix(half_texel.x, 1.0hf - half_texel.x, coords.x); + coords.y = mix(half_texel.y, 1.0hf - half_texel.y, coords.y); + return IPSample(texture_sampler, coords, y_coord_scale); +--- 27,38 ---- + /// If < 0.0, the Y coordinate is flipped. This is useful + /// for Impeller graphics backends that use a flipped framebuffer coordinate + /// space. ++ /// The range of will be mapped from [0, 1] to [half_texel, 1 - ++ /// half_texel] ++ f16vec4 IPSampleLinear(sampler2D texture_sampler, ++ f16vec2 coords, ++ float16_t y_coord_scale, ++ f16vec2 half_texel) { + coords.x = mix(half_texel.x, 1.0hf - half_texel.x, coords.x); + coords.y = mix(half_texel.y, 1.0hf - half_texel.y, coords.y); + return IPSample(texture_sampler, coords, y_coord_scale); +*************** +*** 61,69 **** + /// Remap a vec2 using a tiling mode. + /// + /// Runs each component of the vec2 through . +- f16vec2 IPVec2Tile(f16vec2 coords, float16_t x_tile_mode, float16_t y_tile_mode) { + return f16vec2(IPFloatTile(coords.x, x_tile_mode), +- IPFloatTile(coords.y, y_tile_mode)); + } + + /// Sample a texture, emulating a specific tile mode. +--- 67,77 ---- + /// Remap a vec2 using a tiling mode. + /// + /// Runs each component of the vec2 through . ++ f16vec2 IPVec2Tile(f16vec2 coords, ++ float16_t x_tile_mode, ++ float16_t y_tile_mode) { + return f16vec2(IPFloatTile(coords.x, x_tile_mode), ++ IPFloatTile(coords.y, y_tile_mode)); + } + + /// Sample a texture, emulating a specific tile mode. +*************** +*** 99,113 **** + /// + /// This is useful for Impeller graphics backend that don't have native support + /// for Decal. +- /// The range of will be mapped from [0, 1] to [half_texel, 1 - half_texel] + f16vec4 IPSampleLinearWithTileMode(sampler2D tex, +- f16vec2 coords, +- float16_t y_coord_scale, +- f16vec2 half_texel, +- float16_t x_tile_mode, +- float16_t y_tile_mode) { +- if (x_tile_mode == kTileModeDecal && (coords.x < 0.0hf || coords.x >= 1.0hf) || +- y_tile_mode == kTileModeDecal && (coords.y < 0.0hf || coords.y >= 1.0hf)) { + return f16vec4(0.0hf); + } + +--- 107,124 ---- + /// + /// This is useful for Impeller graphics backend that don't have native support + /// for Decal. ++ /// The range of will be mapped from [0, 1] to [half_texel, 1 - ++ /// half_texel] + f16vec4 IPSampleLinearWithTileMode(sampler2D tex, ++ f16vec2 coords, ++ float16_t y_coord_scale, ++ f16vec2 half_texel, ++ float16_t x_tile_mode, ++ float16_t y_tile_mode) { ++ if (x_tile_mode == kTileModeDecal && ++ (coords.x < 0.0hf || coords.x >= 1.0hf) || ++ y_tile_mode == kTileModeDecal && ++ (coords.y < 0.0hf || coords.y >= 1.0hf)) { + return f16vec4(0.0hf); + } + +*************** +*** 119,131 **** + /// + /// This is useful for Impeller graphics backend that don't have native support + /// for Decal. +- /// The range of will be mapped from [0, 1] to [half_texel, 1 - half_texel] + f16vec4 IPSampleLinearWithTileMode(sampler2D tex, + f16vec2 coords, + float16_t y_coord_scale, + f16vec2 half_texel, + float16_t tile_mode) { +- return IPSampleLinearWithTileMode(tex, coords, y_coord_scale, half_texel, tile_mode, tile_mode); + } + + #endif +--- 130,144 ---- + /// + /// This is useful for Impeller graphics backend that don't have native support + /// for Decal. ++ /// The range of will be mapped from [0, 1] to [half_texel, 1 - ++ /// half_texel] + f16vec4 IPSampleLinearWithTileMode(sampler2D tex, + f16vec2 coords, + float16_t y_coord_scale, + f16vec2 half_texel, + float16_t tile_mode) { ++ return IPSampleLinearWithTileMode(tex, coords, y_coord_scale, half_texel, ++ tile_mode, tile_mode); + } + + #endif diff --git a/impeller/compiler/shader_lib/impeller/types.glsl b/impeller/compiler/shader_lib/impeller/types.glsl index 4ee34daf03983..c61a4ac11d159 100644 --- a/impeller/compiler/shader_lib/impeller/types.glsl +++ b/impeller/compiler/shader_lib/impeller/types.glsl @@ -6,7 +6,7 @@ #define TYPES_GLSL_ #ifdef IMPELLER_TARGET_METAL -#extension GL_AMD_gpu_shader_half_float: enable +#extension GL_AMD_gpu_shader_half_float : enable #define BoolF float16_t #define BoolV2 f16vec2 @@ -28,7 +28,6 @@ precision mediump float; #define BoolV3 vec3 #define BoolV4 vec4 -#endif // IMPELLER_TARGET_METAL - +#endif // IMPELLER_TARGET_METAL #endif diff --git a/impeller/entity/shaders/atlas_fill.frag b/impeller/entity/shaders/atlas_fill.frag index fb7ace3f8cd9b..c0be7749b1538 100644 --- a/impeller/entity/shaders/atlas_fill.frag +++ b/impeller/entity/shaders/atlas_fill.frag @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include uniform sampler2D texture_sampler; @@ -21,7 +21,7 @@ out f16vec4 frag_color; void main() { f16vec4 sampled = IPSample(texture_sampler, v_texture_coords, - frag_info.texture_sampler_y_coord_scale); + frag_info.texture_sampler_y_coord_scale); if (frag_info.has_vertex_color == 1.0hf) { frag_color = sampled.aaaa * v_color * frag_info.alpha; } else { diff --git a/impeller/entity/shaders/blending/advanced_blend.glsl b/impeller/entity/shaders/blending/advanced_blend.glsl index a1633e67e0a76..60065bc6ae6b5 100644 --- a/impeller/entity/shaders/blending/advanced_blend.glsl +++ b/impeller/entity/shaders/blending/advanced_blend.glsl @@ -2,10 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include #include #include +#include uniform BlendInfo { <<<<<<< HEAD @@ -14,7 +14,8 @@ uniform BlendInfo { float16_t src_y_coord_scale; float16_t color_factor; f16vec4 color; // This color input is expected to be unpremultiplied. -} blend_info; +} +blend_info; ======= float dst_input_alpha; float dst_y_coord_scale; @@ -44,13 +45,13 @@ void main() { f16vec4 dst = IPUnpremultiply(dst_sample); f16vec4 src = blend_info.color_factor > 0. - ? blend_info.color - : IPUnpremultiply(IPSampleWithTileMode( - texture_sampler_src, // sampler - v_src_texture_coords, // texture coordinates - blend_info.src_y_coord_scale, // y coordinate scale - kTileModeDecal // tile mode - )); + ? blend_info.color + : IPUnpremultiply(IPSampleWithTileMode( + texture_sampler_src, // sampler + v_src_texture_coords, // texture coordinates + blend_info.src_y_coord_scale, // y coordinate scale + kTileModeDecal // tile mode + )); f16vec4 blended = f16vec4(Blend(dst.rgb, src.rgb), 1.0hf) * dst.a; diff --git a/impeller/entity/shaders/blending/advanced_blend_color.frag b/impeller/entity/shaders/blending/advanced_blend_color.frag index cfcb1b87d5aef..439a3598c9282 100644 --- a/impeller/entity/shaders/blending/advanced_blend_color.frag +++ b/impeller/entity/shaders/blending/advanced_blend_color.frag @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendColor(dst, src); diff --git a/impeller/entity/shaders/blending/advanced_blend_colorburn.frag b/impeller/entity/shaders/blending/advanced_blend_colorburn.frag index 34d438c345e73..80b747f6c3439 100644 --- a/impeller/entity/shaders/blending/advanced_blend_colorburn.frag +++ b/impeller/entity/shaders/blending/advanced_blend_colorburn.frag @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendColorBurn(dst, src); diff --git a/impeller/entity/shaders/blending/advanced_blend_colordodge.frag b/impeller/entity/shaders/blending/advanced_blend_colordodge.frag index ddb35bb4611e4..c6356530bbe96 100644 --- a/impeller/entity/shaders/blending/advanced_blend_colordodge.frag +++ b/impeller/entity/shaders/blending/advanced_blend_colordodge.frag @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendColorDodge(dst, src); diff --git a/impeller/entity/shaders/blending/advanced_blend_darken.frag b/impeller/entity/shaders/blending/advanced_blend_darken.frag index 747b4223712a2..95c8802433bed 100644 --- a/impeller/entity/shaders/blending/advanced_blend_darken.frag +++ b/impeller/entity/shaders/blending/advanced_blend_darken.frag @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendDarken(dst, src); diff --git a/impeller/entity/shaders/blending/advanced_blend_difference.frag b/impeller/entity/shaders/blending/advanced_blend_difference.frag index 6b197899d3310..1ccea9890e17f 100644 --- a/impeller/entity/shaders/blending/advanced_blend_difference.frag +++ b/impeller/entity/shaders/blending/advanced_blend_difference.frag @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendDifference(dst, src); diff --git a/impeller/entity/shaders/blending/advanced_blend_exclusion.frag b/impeller/entity/shaders/blending/advanced_blend_exclusion.frag index 28c0bbe5d908b..2f613ec10939e 100644 --- a/impeller/entity/shaders/blending/advanced_blend_exclusion.frag +++ b/impeller/entity/shaders/blending/advanced_blend_exclusion.frag @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendExclusion(dst, src); diff --git a/impeller/entity/shaders/blending/advanced_blend_hardlight.frag b/impeller/entity/shaders/blending/advanced_blend_hardlight.frag index 01f9c018aa2b5..7a5d77cd380e2 100644 --- a/impeller/entity/shaders/blending/advanced_blend_hardlight.frag +++ b/impeller/entity/shaders/blending/advanced_blend_hardlight.frag @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendHardLight(dst, src); diff --git a/impeller/entity/shaders/blending/advanced_blend_hue.frag b/impeller/entity/shaders/blending/advanced_blend_hue.frag index 24de234171be8..2fee599fd42f9 100644 --- a/impeller/entity/shaders/blending/advanced_blend_hue.frag +++ b/impeller/entity/shaders/blending/advanced_blend_hue.frag @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendHue(dst, src); diff --git a/impeller/entity/shaders/blending/advanced_blend_lighten.frag b/impeller/entity/shaders/blending/advanced_blend_lighten.frag index 0672168631b42..c10ea8f0d40d2 100644 --- a/impeller/entity/shaders/blending/advanced_blend_lighten.frag +++ b/impeller/entity/shaders/blending/advanced_blend_lighten.frag @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendLighten(dst, src); diff --git a/impeller/entity/shaders/blending/advanced_blend_luminosity.frag b/impeller/entity/shaders/blending/advanced_blend_luminosity.frag index 71eab1b831f86..082a69ce70b08 100644 --- a/impeller/entity/shaders/blending/advanced_blend_luminosity.frag +++ b/impeller/entity/shaders/blending/advanced_blend_luminosity.frag @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendLuminosity(dst, src); diff --git a/impeller/entity/shaders/blending/advanced_blend_multiply.frag b/impeller/entity/shaders/blending/advanced_blend_multiply.frag index 04f98fedbd086..4034a42a3f24c 100644 --- a/impeller/entity/shaders/blending/advanced_blend_multiply.frag +++ b/impeller/entity/shaders/blending/advanced_blend_multiply.frag @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendMultiply(dst, src); diff --git a/impeller/entity/shaders/blending/advanced_blend_overlay.frag b/impeller/entity/shaders/blending/advanced_blend_overlay.frag index d96f1ca12ab4d..520e356433999 100644 --- a/impeller/entity/shaders/blending/advanced_blend_overlay.frag +++ b/impeller/entity/shaders/blending/advanced_blend_overlay.frag @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendOverlay(dst, src); diff --git a/impeller/entity/shaders/blending/advanced_blend_saturation.frag b/impeller/entity/shaders/blending/advanced_blend_saturation.frag index 329ceb6340103..abd9cba668d77 100644 --- a/impeller/entity/shaders/blending/advanced_blend_saturation.frag +++ b/impeller/entity/shaders/blending/advanced_blend_saturation.frag @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendSaturation(dst, src); diff --git a/impeller/entity/shaders/blending/advanced_blend_screen.frag b/impeller/entity/shaders/blending/advanced_blend_screen.frag index 0dd33ef660747..5d429d86768c8 100644 --- a/impeller/entity/shaders/blending/advanced_blend_screen.frag +++ b/impeller/entity/shaders/blending/advanced_blend_screen.frag @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendScreen(dst, src); diff --git a/impeller/entity/shaders/blending/advanced_blend_softlight.frag b/impeller/entity/shaders/blending/advanced_blend_softlight.frag index a75850022e21c..2fa7182060f43 100644 --- a/impeller/entity/shaders/blending/advanced_blend_softlight.frag +++ b/impeller/entity/shaders/blending/advanced_blend_softlight.frag @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include f16vec3 Blend(f16vec3 dst, f16vec3 src) { return IPBlendSoftLight(dst, src); diff --git a/impeller/entity/shaders/blending/blend.frag b/impeller/entity/shaders/blending/blend.frag index 7d5ecffe5760b..111f001d19080 100644 --- a/impeller/entity/shaders/blending/blend.frag +++ b/impeller/entity/shaders/blending/blend.frag @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include uniform sampler2D texture_sampler_src; @@ -11,7 +11,8 @@ uniform FragInfo { <<<<<<< HEAD float16_t texture_sampler_y_coord_scale; float16_t input_alpha; -} frag_info; +} +frag_info; ======= float texture_sampler_y_coord_scale; float input_alpha; diff --git a/impeller/entity/shaders/border_mask_blur.frag b/impeller/entity/shaders/border_mask_blur.frag index 8d7fb2f619c1a..a55adad5f44b0 100644 --- a/impeller/entity/shaders/border_mask_blur.frag +++ b/impeller/entity/shaders/border_mask_blur.frag @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include #include +#include // Constant time mask blur for image borders. // @@ -20,7 +20,8 @@ uniform sampler2D texture_sampler; uniform FragInfo { <<<<<<< HEAD float16_t texture_sampler_y_coord_scale; -} frag_info; +} +frag_info; ======= float texture_sampler_y_coord_scale; } @@ -37,23 +38,24 @@ out f16vec4 frag_color; float16_t BoxBlurMask(f16vec2 uv) { // LTRB - return IPGaussianIntegral(uv.x, v_sigma_uv.x) * // - IPGaussianIntegral(uv.y, v_sigma_uv.y) * // + return IPGaussianIntegral(uv.x, v_sigma_uv.x) * // + IPGaussianIntegral(uv.y, v_sigma_uv.y) * // IPGaussianIntegral(1.0hf - uv.x, v_sigma_uv.x) * // IPGaussianIntegral(1.0hf - uv.y, v_sigma_uv.y); } void main() { f16vec4 image_color = IPSample(texture_sampler, v_texture_coords, - frag_info.texture_sampler_y_coord_scale); + frag_info.texture_sampler_y_coord_scale); float16_t blur_factor = BoxBlurMask(v_texture_coords); float16_t within_bounds = float16_t(v_texture_coords.x >= 0.0hf && v_texture_coords.y >= 0.0hf && - v_texture_coords.x < 1.0hf && v_texture_coords.y < 1.0hf); + v_texture_coords.x < 1.0hf && v_texture_coords.y < 1.0hf); float16_t inner_factor = (v_inner_blur_factor * blur_factor + v_src_factor) * within_bounds; - float16_t outer_factor = v_outer_blur_factor * blur_factor * (1.0hf - within_bounds); + float16_t outer_factor = + v_outer_blur_factor * blur_factor * (1.0hf - within_bounds); float16_t mask_factor = inner_factor + outer_factor; frag_color = image_color * mask_factor; diff --git a/impeller/entity/shaders/color_matrix_color_filter.frag b/impeller/entity/shaders/color_matrix_color_filter.frag index a08ff57a68037..fc04f8afaca7c 100644 --- a/impeller/entity/shaders/color_matrix_color_filter.frag +++ b/impeller/entity/shaders/color_matrix_color_filter.frag @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include #include +#include // A color filter that transforms colors through a 4x5 color matrix. // @@ -35,7 +35,8 @@ uniform FragInfo { f16vec4 color_v; float16_t texture_sampler_y_coord_scale; float16_t input_alpha; -} frag_info; +} +frag_info; ======= vec4 color_v; float texture_sampler_y_coord_scale; @@ -51,13 +52,14 @@ out f16vec4 frag_color; void main() { f16vec4 input_color = IPSample(input_texture, v_position, - frag_info.texture_sampler_y_coord_scale) * - frag_info.input_alpha; + frag_info.texture_sampler_y_coord_scale) * + frag_info.input_alpha; // unpremultiply first, as filter inputs are premultiplied. f16vec4 color = IPUnpremultiply(input_color); - color = clamp(f16mat4(frag_info.color_m) * color + frag_info.color_v, 0.0hf, 1.0hf); + color = clamp(f16mat4(frag_info.color_m) * color + frag_info.color_v, 0.0hf, + 1.0hf); <<<<<<< HEAD ======= diff --git a/impeller/entity/shaders/gaussian_blur.frag b/impeller/entity/shaders/gaussian_blur.frag index c48f1f61a9928..b47f253abeb61 100644 --- a/impeller/entity/shaders/gaussian_blur.frag +++ b/impeller/entity/shaders/gaussian_blur.frag @@ -13,10 +13,10 @@ // reduced in the first pass by sampling the source textures with a mip // level of log2(min_radius). -#include #include #include #include +#include uniform sampler2D texture_sampler; uniform sampler2D alpha_mask_sampler; @@ -74,8 +74,9 @@ void main() { frag_info.alpha_mask_sampler_y_coord_scale, // y coordinate scale frag_info.tile_mode // tile mode ); - float16_t blur_factor = frag_info.inner_blur_factor * float16_t(src_color.a > 0.0hf) + - frag_info.outer_blur_factor * float16_t(src_color.a == 0.0hf); + float16_t blur_factor = + frag_info.inner_blur_factor * float16_t(src_color.a > 0.0hf) + + frag_info.outer_blur_factor * float16_t(src_color.a == 0.0hf); frag_color = blur_color * blur_factor + src_color * frag_info.src_factor; } diff --git a/impeller/entity/shaders/glyph_atlas.frag b/impeller/entity/shaders/glyph_atlas.frag index d2498a03a45cd..152995279826b 100644 --- a/impeller/entity/shaders/glyph_atlas.frag +++ b/impeller/entity/shaders/glyph_atlas.frag @@ -10,7 +10,8 @@ uniform FragInfo { <<<<<<< HEAD f16vec2 atlas_size; f16vec4 text_color; -} frag_info; +} +frag_info; in f16vec2 v_unit_vertex; in f16vec2 v_atlas_position; @@ -35,15 +36,13 @@ void main() { f16vec2 scale_perspective = v_atlas_glyph_size / frag_info.atlas_size; f16vec2 offset = v_atlas_position / frag_info.atlas_size; if (v_color_glyph == 1.0hf) { - frag_color = f16vec4(texture( - glyph_atlas_sampler, - v_unit_vertex * scale_perspective + offset - )); + frag_color = f16vec4(texture(glyph_atlas_sampler, + v_unit_vertex * scale_perspective + offset)); } else { - frag_color = f16vec4(texture( - glyph_atlas_sampler, - v_unit_vertex * scale_perspective + offset - ).aaaa) * frag_info.text_color; + frag_color = f16vec4(texture(glyph_atlas_sampler, + v_unit_vertex * scale_perspective + offset) + .aaaa) * + frag_info.text_color; ======= vec2 uv_size = v_source_glyph_size / frag_info.atlas_size; vec2 offset = v_source_position / frag_info.atlas_size; diff --git a/impeller/entity/shaders/glyph_atlas.vert b/impeller/entity/shaders/glyph_atlas.vert index ec261885a510f..9542361f3ba38 100644 --- a/impeller/entity/shaders/glyph_atlas.vert +++ b/impeller/entity/shaders/glyph_atlas.vert @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include uniform FrameInfo { mat4 mvp; diff --git a/impeller/entity/shaders/glyph_atlas_sdf.vert b/impeller/entity/shaders/glyph_atlas_sdf.vert index 0ea5ce2e5674d..abc537415bf34 100644 --- a/impeller/entity/shaders/glyph_atlas_sdf.vert +++ b/impeller/entity/shaders/glyph_atlas_sdf.vert @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include uniform FrameInfo { mat4 mvp; diff --git a/impeller/entity/shaders/gradient_fill.vert b/impeller/entity/shaders/gradient_fill.vert index 7f6fd938c6c8a..824f496ea8c22 100644 --- a/impeller/entity/shaders/gradient_fill.vert +++ b/impeller/entity/shaders/gradient_fill.vert @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include uniform FrameInfo { mat4 mvp; diff --git a/impeller/entity/shaders/linear_gradient_fill.frag b/impeller/entity/shaders/linear_gradient_fill.frag index 8ab5632267481..a4292924a3020 100644 --- a/impeller/entity/shaders/linear_gradient_fill.frag +++ b/impeller/entity/shaders/linear_gradient_fill.frag @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include uniform sampler2D texture_sampler; @@ -15,7 +15,8 @@ uniform GradientInfo { float16_t texture_sampler_y_coord_scale; float16_t alpha; f16vec2 half_texel; -} gradient_info; +} +gradient_info; ======= vec2 start_point; vec2 end_point; @@ -34,18 +35,15 @@ out f16vec4 frag_color; void main() { <<<<<<< HEAD float16_t len = length(gradient_info.end_point - gradient_info.start_point); - float16_t dot = dot( - v_position - gradient_info.start_point, - gradient_info.end_point - gradient_info.start_point - ); + float16_t dot = dot(v_position - gradient_info.start_point, + gradient_info.end_point - gradient_info.start_point); float16_t t = dot / (len * len); frag_color = IPSampleLinearWithTileMode( - texture_sampler, - f16vec2(t, 0.5hf), - gradient_info.texture_sampler_y_coord_scale, - gradient_info.half_texel, - gradient_info.tile_mode); - frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; + texture_sampler, f16vec2(t, 0.5hf), + gradient_info.texture_sampler_y_coord_scale, gradient_info.half_texel, + gradient_info.tile_mode); + frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * + gradient_info.alpha; ======= float len = length(gradient_info.end_point - gradient_info.start_point); float dot = dot(v_position - gradient_info.start_point, diff --git a/impeller/entity/shaders/linear_gradient_ssbo_fill.frag b/impeller/entity/shaders/linear_gradient_ssbo_fill.frag index 24c72b2aa7e38..cf649641de2b1 100644 --- a/impeller/entity/shaders/linear_gradient_ssbo_fill.frag +++ b/impeller/entity/shaders/linear_gradient_ssbo_fill.frag @@ -2,14 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include #include +#include readonly buffer ColorData { <<<<<<< HEAD f16vec4 colors[]; -} color_data; +} +color_data; uniform GradientInfo { f16vec2 start_point; @@ -17,7 +18,8 @@ uniform GradientInfo { float16_t alpha; float16_t tile_mode; float16_t colors_length; -} gradient_info; +} +gradient_info; ======= vec4 colors[]; } @@ -40,10 +42,8 @@ out f16vec4 frag_color; void main() { <<<<<<< HEAD float16_t len = length(gradient_info.end_point - gradient_info.start_point); - float16_t dot = dot( - v_position - gradient_info.start_point, - gradient_info.end_point - gradient_info.start_point - ); + float16_t dot = dot(v_position - gradient_info.start_point, + gradient_info.end_point - gradient_info.start_point); float16_t t = dot / (len * len); ======= float len = length(gradient_info.end_point - gradient_info.start_point); @@ -60,8 +60,10 @@ void main() { f16vec3 values = IPComputeFixedGradientValues(t, gradient_info.colors_length); <<<<<<< HEAD - frag_color = mix(color_data.colors[int(values.x)], color_data.colors[int(values.y)], values.z); - frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; + frag_color = mix(color_data.colors[int(values.x)], + color_data.colors[int(values.y)], values.z); + frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * + gradient_info.alpha; ======= frag_color = mix(color_data.colors[int(values.x)], color_data.colors[int(values.y)], values.z); diff --git a/impeller/entity/shaders/linear_to_srgb_filter.frag b/impeller/entity/shaders/linear_to_srgb_filter.frag index 69ee2b03dee20..8dbf02bb006c9 100644 --- a/impeller/entity/shaders/linear_to_srgb_filter.frag +++ b/impeller/entity/shaders/linear_to_srgb_filter.frag @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include #include +#include // A color filter that applies the sRGB gamma curve to the color. // @@ -16,7 +16,8 @@ uniform FragInfo { <<<<<<< HEAD float16_t texture_sampler_y_coord_scale; float16_t input_alpha; -} frag_info; +} +frag_info; ======= float texture_sampler_y_coord_scale; float input_alpha; @@ -29,8 +30,8 @@ out f16vec4 frag_color; void main() { f16vec4 input_color = IPSample(input_texture, f16vec2(v_position), - frag_info.texture_sampler_y_coord_scale) * - frag_info.input_alpha; + frag_info.texture_sampler_y_coord_scale) * + frag_info.input_alpha; f16vec4 color = IPUnpremultiply(input_color); for (int i = 0; i < 3; i++) { diff --git a/impeller/entity/shaders/morphology_filter.frag b/impeller/entity/shaders/morphology_filter.frag index 98eea49da69a0..44b452df3dbb7 100644 --- a/impeller/entity/shaders/morphology_filter.frag +++ b/impeller/entity/shaders/morphology_filter.frag @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include #include +#include // These values must correspond to the order of the items in the // 'FilterContents::MorphType' enum class. @@ -32,18 +32,18 @@ out f16vec4 frag_color; void main() { <<<<<<< HEAD - f16vec4 result = frag_info.morph_type == kMorphTypeDilate ? f16vec4(0) : f16vec4(1); + f16vec4 result = + frag_info.morph_type == kMorphTypeDilate ? f16vec4(0) : f16vec4(1); f16vec2 uv_offset = frag_info.direction / frag_info.texture_size; for (float16_t i = -frag_info.radius; i <= frag_info.radius; i++) { f16vec2 texture_coords = v_texture_coords + uv_offset * i; f16vec4 color; - color = - IPSampleWithTileMode( - texture_sampler, // sampler - texture_coords, // texture coordinates - frag_info.texture_sampler_y_coord_scale, // y coordinate scale - kTileModeDecal // tile mode - ); + color = IPSampleWithTileMode( + texture_sampler, // sampler + texture_coords, // texture coordinates + frag_info.texture_sampler_y_coord_scale, // y coordinate scale + kTileModeDecal // tile mode + ); ======= vec4 result = frag_info.morph_type == kMorphTypeDilate ? vec4(0) : vec4(1); vec2 uv_offset = frag_info.direction / frag_info.texture_size; diff --git a/impeller/entity/shaders/position.vert b/impeller/entity/shaders/position.vert index 4d7183c306803..486a908e5bfd8 100644 --- a/impeller/entity/shaders/position.vert +++ b/impeller/entity/shaders/position.vert @@ -2,14 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include uniform VertInfo { mat4 mvp; <<<<<<< HEAD f16vec4 color; -} vert_info; +} +vert_info; ======= vec4 color; } diff --git a/impeller/entity/shaders/position_color.vert b/impeller/entity/shaders/position_color.vert index fc5dc8d1d3f08..59731fd2ab43f 100644 --- a/impeller/entity/shaders/position_color.vert +++ b/impeller/entity/shaders/position_color.vert @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include uniform VertInfo { mat4 mvp; diff --git a/impeller/entity/shaders/position_uv.vert b/impeller/entity/shaders/position_uv.vert index 7866829437ae8..e49949a801277 100644 --- a/impeller/entity/shaders/position_uv.vert +++ b/impeller/entity/shaders/position_uv.vert @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include uniform VertInfo { mat4 mvp; diff --git a/impeller/entity/shaders/radial_gradient_fill.frag b/impeller/entity/shaders/radial_gradient_fill.frag index 39b05acbb8adc..7fc483ced71d0 100644 --- a/impeller/entity/shaders/radial_gradient_fill.frag +++ b/impeller/entity/shaders/radial_gradient_fill.frag @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include uniform sampler2D texture_sampler; @@ -15,7 +15,8 @@ uniform GradientInfo { float16_t texture_sampler_y_coord_scale; float16_t alpha; f16vec2 half_texel; -} gradient_info; +} +gradient_info; ======= vec2 center; float radius; @@ -36,12 +37,11 @@ void main() { float16_t t = len / gradient_info.radius; frag_color = IPSampleLinearWithTileMode( <<<<<<< HEAD - texture_sampler, - f16vec2(t, 0.5hf), - gradient_info.texture_sampler_y_coord_scale, - gradient_info.half_texel, - gradient_info.tile_mode); - frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; + texture_sampler, f16vec2(t, 0.5hf), + gradient_info.texture_sampler_y_coord_scale, gradient_info.half_texel, + gradient_info.tile_mode); + frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * + gradient_info.alpha; ======= texture_sampler, vec2(t, 0.5), gradient_info.texture_sampler_y_coord_scale, gradient_info.half_texel, diff --git a/impeller/entity/shaders/radial_gradient_ssbo_fill.frag b/impeller/entity/shaders/radial_gradient_ssbo_fill.frag index 5be932b353aca..d49a3c2e2d814 100644 --- a/impeller/entity/shaders/radial_gradient_ssbo_fill.frag +++ b/impeller/entity/shaders/radial_gradient_ssbo_fill.frag @@ -2,14 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include #include +#include readonly buffer ColorData { <<<<<<< HEAD f16vec4 colors[]; -} color_data; +} +color_data; uniform GradientInfo { f16vec2 center; @@ -17,7 +18,8 @@ uniform GradientInfo { float16_t tile_mode; float16_t alpha; float16_t colors_length; -} gradient_info; +} +gradient_info; ======= vec4 colors[]; } @@ -49,8 +51,10 @@ void main() { f16vec3 values = IPComputeFixedGradientValues(t, gradient_info.colors_length); <<<<<<< HEAD - frag_color = mix(color_data.colors[int(values.x)], color_data.colors[int(values.y)], values.z); - frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; + frag_color = mix(color_data.colors[int(values.x)], + color_data.colors[int(values.y)], values.z); + frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * + gradient_info.alpha; ======= frag_color = mix(color_data.colors[int(values.x)], color_data.colors[int(values.y)], values.z); diff --git a/impeller/entity/shaders/rrect_blur.frag b/impeller/entity/shaders/rrect_blur.frag index c4800cc0fdf40..32b550e5836b6 100644 --- a/impeller/entity/shaders/rrect_blur.frag +++ b/impeller/entity/shaders/rrect_blur.frag @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include uniform FragInfo { f16vec4 color; @@ -21,7 +21,8 @@ const float16_t kSampleCount = 5.0hf; float16_t RRectDistance(f16vec2 sample_position, f16vec2 half_size) { vec2 space = abs(sample_position) - half_size + frag_info.corner_radius; - return float16_t(length(max(space, 0.0hf)) + min(max(space.x, space.y), 0.0hf)) - + return float16_t(length(max(space, 0.0hf)) + + min(max(space.x, space.y), 0.0hf)) - frag_info.corner_radius; } @@ -30,12 +31,12 @@ float16_t RRectDistance(f16vec2 sample_position, f16vec2 half_size) { float16_t RRectShadowX(f16vec2 sample_position, f16vec2 half_size) { // Compute the X direction distance field (not incorporating the Y distance) // for the rounded rect. - float16_t space = - min(0.0hf, half_size.y - frag_info.corner_radius - abs(sample_position.y)); + float16_t space = min( + 0.0hf, half_size.y - frag_info.corner_radius - abs(sample_position.y)); float16_t rrect_distance = half_size.x - frag_info.corner_radius + sqrt(max(0.0hf, frag_info.corner_radius * frag_info.corner_radius - - space * space)); + space * space)); // Map the linear distance field to the analytical Gaussian integral. f16vec2 integral = IPVec2GaussianIntegral( @@ -49,7 +50,8 @@ float16_t RRectShadow(f16vec2 sample_position, f16vec2 half_size) { // the kernel center to incorporate 99.7% of the color contribution. float16_t half_sampling_range = frag_info.blur_sigma * 3.0hf; - float16_t begin_y = max(-half_sampling_range, sample_position.y - half_size.y); + float16_t begin_y = + max(-half_sampling_range, sample_position.y - half_size.y); float16_t end_y = min(half_sampling_range, sample_position.y + half_size.y); float16_t interval = (end_y - begin_y) / kSampleCount; diff --git a/impeller/entity/shaders/srgb_to_linear_filter.frag b/impeller/entity/shaders/srgb_to_linear_filter.frag index b79cda95c3214..7de9dda13f607 100644 --- a/impeller/entity/shaders/srgb_to_linear_filter.frag +++ b/impeller/entity/shaders/srgb_to_linear_filter.frag @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include #include +#include // Creates a color filter that applies the inverse of the sRGB gamma curve // to the RGB channels. @@ -15,7 +15,8 @@ uniform FragInfo { <<<<<<< HEAD float16_t texture_sampler_y_coord_scale; float16_t input_alpha; -} frag_info; +} +frag_info; ======= float texture_sampler_y_coord_scale; float input_alpha; @@ -28,8 +29,8 @@ out f16vec4 frag_color; void main() { f16vec4 input_color = IPSample(input_texture, v_position, - frag_info.texture_sampler_y_coord_scale) * - frag_info.input_alpha; + frag_info.texture_sampler_y_coord_scale) * + frag_info.input_alpha; f16vec4 color = IPUnpremultiply(input_color); for (int i = 0; i < 3; i++) { diff --git a/impeller/entity/shaders/sweep_gradient_fill.frag b/impeller/entity/shaders/sweep_gradient_fill.frag index ec1edf7093a4a..a420683e989fd 100644 --- a/impeller/entity/shaders/sweep_gradient_fill.frag +++ b/impeller/entity/shaders/sweep_gradient_fill.frag @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include #include +#include uniform sampler2D texture_sampler; @@ -17,7 +17,8 @@ uniform GradientInfo { float16_t texture_sampler_y_coord_scale; float16_t alpha; f16vec2 half_texel; -} gradient_info; +} +gradient_info; ======= vec2 center; float bias; @@ -39,14 +40,14 @@ void main() { float angle = atan(-coord.y, -coord.x); <<<<<<< HEAD - float16_t t = (float16_t(angle) * k1Over2Pi + 0.5hf + gradient_info.bias) * gradient_info.scale; + float16_t t = (float16_t(angle) * k1Over2Pi + 0.5hf + gradient_info.bias) * + gradient_info.scale; frag_color = IPSampleLinearWithTileMode( - texture_sampler, - f16vec2(t, 0.5), - gradient_info.texture_sampler_y_coord_scale, - gradient_info.half_texel, - gradient_info.tile_mode); - frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; + texture_sampler, f16vec2(t, 0.5), + gradient_info.texture_sampler_y_coord_scale, gradient_info.half_texel, + gradient_info.tile_mode); + frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * + gradient_info.alpha; ======= float t = (angle * k1Over2Pi + 0.5 + gradient_info.bias) * gradient_info.scale; diff --git a/impeller/entity/shaders/sweep_gradient_ssbo_fill.frag b/impeller/entity/shaders/sweep_gradient_ssbo_fill.frag index baf51007cc2c4..2b484f3c24a24 100644 --- a/impeller/entity/shaders/sweep_gradient_ssbo_fill.frag +++ b/impeller/entity/shaders/sweep_gradient_ssbo_fill.frag @@ -2,15 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include #include #include +#include readonly buffer ColorData { <<<<<<< HEAD f16vec4 colors[]; -} color_data; +} +color_data; uniform GradientInfo { f16vec2 center; @@ -19,7 +20,8 @@ uniform GradientInfo { float16_t tile_mode; float16_t alpha; float16_t colors_length; -} gradient_info; +} +gradient_info; ======= vec4 colors[]; } @@ -44,7 +46,8 @@ void main() { f16vec2 coord = v_position - gradient_info.center; float angle = atan(-coord.y, -coord.x); <<<<<<< HEAD - float16_t t = (float16_t(angle) * k1Over2Pi + 0.5hf + gradient_info.bias) * gradient_info.scale; + float16_t t = (float16_t(angle) * k1Over2Pi + 0.5hf + gradient_info.bias) * + gradient_info.scale; ======= float t = (angle * k1Over2Pi + 0.5 + gradient_info.bias) * gradient_info.scale; @@ -58,8 +61,10 @@ void main() { f16vec3 values = IPComputeFixedGradientValues(t, gradient_info.colors_length); <<<<<<< HEAD - frag_color = mix(color_data.colors[int(values.x)], color_data.colors[int(values.y)], values.z); - frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; + frag_color = mix(color_data.colors[int(values.x)], + color_data.colors[int(values.y)], values.z); + frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * + gradient_info.alpha; ======= frag_color = mix(color_data.colors[int(values.x)], color_data.colors[int(values.y)], values.z); diff --git a/impeller/entity/shaders/test.frag b/impeller/entity/shaders/test.frag index 7b7b73346ad34..eadd477b3c1d0 100644 --- a/impeller/entity/shaders/test.frag +++ b/impeller/entity/shaders/test.frag @@ -8,7 +8,8 @@ uniform sampler2D texture_sampler; uniform GradientInfo { float16_t bias; -} gradient_info; +} +gradient_info; in vec2 v_position; diff --git a/impeller/entity/shaders/texture_fill.frag b/impeller/entity/shaders/texture_fill.frag index f8444665f53d1..0e7cec6e6ea65 100644 --- a/impeller/entity/shaders/texture_fill.frag +++ b/impeller/entity/shaders/texture_fill.frag @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include uniform sampler2D texture_sampler; @@ -19,6 +19,6 @@ out vec4 frag_color; void main() { f16vec4 sampled = IPSample(texture_sampler, v_texture_coords, - frag_info.texture_sampler_y_coord_scale); + frag_info.texture_sampler_y_coord_scale); frag_color = sampled * frag_info.alpha; } diff --git a/impeller/entity/shaders/tiled_texture_fill.frag b/impeller/entity/shaders/tiled_texture_fill.frag index 90a947e58f8ce..a4a33ece00c44 100644 --- a/impeller/entity/shaders/tiled_texture_fill.frag +++ b/impeller/entity/shaders/tiled_texture_fill.frag @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include uniform sampler2D texture_sampler; diff --git a/impeller/entity/shaders/tiled_texture_fill.vert b/impeller/entity/shaders/tiled_texture_fill.vert index 0442a6384d096..dabcdf780bf54 100644 --- a/impeller/entity/shaders/tiled_texture_fill.vert +++ b/impeller/entity/shaders/tiled_texture_fill.vert @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include uniform VertInfo { mat4 mvp; diff --git a/impeller/entity/shaders/yuv_to_rgb_filter.frag b/impeller/entity/shaders/yuv_to_rgb_filter.frag index 702b18148ab70..1319517e2ed4f 100644 --- a/impeller/entity/shaders/yuv_to_rgb_filter.frag +++ b/impeller/entity/shaders/yuv_to_rgb_filter.frag @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include #include +#include uniform sampler2D y_texture; uniform sampler2D uv_texture; @@ -19,7 +19,8 @@ uniform FragInfo { float16_t yuv_color_space; mat4 matrix; <<<<<<< HEAD -} frag_info; +} +frag_info; ======= float yuv_color_space; } @@ -37,8 +38,12 @@ void main() { } <<<<<<< HEAD - yuv.x = IPSample(y_texture, v_position, frag_info.texture_sampler_y_coord_scale).x; - yuv.yz = IPSample(uv_texture, v_position, frag_info.texture_sampler_y_coord_scale).xy; + yuv.x = + IPSample(y_texture, v_position, frag_info.texture_sampler_y_coord_scale) + .x; + yuv.yz = + IPSample(uv_texture, v_position, frag_info.texture_sampler_y_coord_scale) + .xy; frag_color = f16mat4(frag_info.matrix) * f16vec4(yuv - yuv_offset, 1.0hf); ======= yuv.x = From 56df059758ad30f0b4050718e8f252981e2e4c76 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 21 Nov 2022 16:03:40 -0800 Subject: [PATCH 4/6] ++ --- .../shaders/blending/advanced_blend.glsl | 14 ------- impeller/entity/shaders/blending/blend.frag | 7 ---- impeller/entity/shaders/border_mask_blur.frag | 6 --- .../shaders/color_matrix_color_filter.frag | 13 ------- impeller/entity/shaders/glyph_atlas.frag | 24 ------------ impeller/entity/shaders/glyph_atlas.vert | 39 +++++++------------ .../entity/shaders/linear_gradient_fill.frag | 24 ------------ .../shaders/linear_gradient_ssbo_fill.frag | 29 -------------- .../entity/shaders/linear_to_srgb_filter.frag | 7 ---- .../entity/shaders/morphology_filter.frag | 19 --------- impeller/entity/shaders/position.vert | 6 --- .../entity/shaders/radial_gradient_fill.frag | 19 --------- .../shaders/radial_gradient_ssbo_fill.frag | 22 ----------- .../entity/shaders/srgb_to_linear_filter.frag | 7 ---- .../entity/shaders/sweep_gradient_fill.frag | 25 +----------- .../shaders/sweep_gradient_ssbo_fill.frag | 28 ------------- .../entity/shaders/yuv_to_rgb_filter.frag | 16 -------- 17 files changed, 14 insertions(+), 291 deletions(-) diff --git a/impeller/entity/shaders/blending/advanced_blend.glsl b/impeller/entity/shaders/blending/advanced_blend.glsl index 60065bc6ae6b5..4b310b7c8be47 100644 --- a/impeller/entity/shaders/blending/advanced_blend.glsl +++ b/impeller/entity/shaders/blending/advanced_blend.glsl @@ -8,7 +8,6 @@ #include uniform BlendInfo { -<<<<<<< HEAD float16_t dst_input_alpha; float16_t dst_y_coord_scale; float16_t src_y_coord_scale; @@ -16,15 +15,6 @@ uniform BlendInfo { f16vec4 color; // This color input is expected to be unpremultiplied. } blend_info; -======= - float dst_input_alpha; - float dst_y_coord_scale; - float src_y_coord_scale; - float color_factor; - vec4 color; // This color input is expected to be unpremultiplied. -} -blend_info; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 uniform sampler2D texture_sampler_dst; uniform sampler2D texture_sampler_src; @@ -56,8 +46,4 @@ void main() { f16vec4 blended = f16vec4(Blend(dst.rgb, src.rgb), 1.0hf) * dst.a; frag_color = mix(dst_sample, blended, src.a); -<<<<<<< HEAD -======= - // frag_color = dst_sample; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 } diff --git a/impeller/entity/shaders/blending/blend.frag b/impeller/entity/shaders/blending/blend.frag index 111f001d19080..c2d8d9bc8083c 100644 --- a/impeller/entity/shaders/blending/blend.frag +++ b/impeller/entity/shaders/blending/blend.frag @@ -8,17 +8,10 @@ uniform sampler2D texture_sampler_src; uniform FragInfo { -<<<<<<< HEAD float16_t texture_sampler_y_coord_scale; float16_t input_alpha; } frag_info; -======= - float texture_sampler_y_coord_scale; - float input_alpha; -} -frag_info; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 in f16vec2 v_texture_coords; diff --git a/impeller/entity/shaders/border_mask_blur.frag b/impeller/entity/shaders/border_mask_blur.frag index a55adad5f44b0..281839465e433 100644 --- a/impeller/entity/shaders/border_mask_blur.frag +++ b/impeller/entity/shaders/border_mask_blur.frag @@ -18,15 +18,9 @@ uniform sampler2D texture_sampler; uniform FragInfo { -<<<<<<< HEAD float16_t texture_sampler_y_coord_scale; } frag_info; -======= - float texture_sampler_y_coord_scale; -} -frag_info; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 in f16vec2 v_texture_coords; in f16vec2 v_sigma_uv; diff --git a/impeller/entity/shaders/color_matrix_color_filter.frag b/impeller/entity/shaders/color_matrix_color_filter.frag index fc04f8afaca7c..97ec550d56a74 100644 --- a/impeller/entity/shaders/color_matrix_color_filter.frag +++ b/impeller/entity/shaders/color_matrix_color_filter.frag @@ -31,19 +31,11 @@ uniform FragInfo { mat4 color_m; -<<<<<<< HEAD f16vec4 color_v; float16_t texture_sampler_y_coord_scale; float16_t input_alpha; } frag_info; -======= - vec4 color_v; - float texture_sampler_y_coord_scale; - float input_alpha; -} -frag_info; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 uniform sampler2D input_texture; @@ -61,11 +53,6 @@ void main() { color = clamp(f16mat4(frag_info.color_m) * color + frag_info.color_v, 0.0hf, 1.0hf); -<<<<<<< HEAD -======= - color = clamp(frag_info.color_m * color + frag_info.color_v, 0.0, 1.0); - ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 // premultiply the outputs frag_color = f16vec4(color.rgb * color.a, color.a); } diff --git a/impeller/entity/shaders/glyph_atlas.frag b/impeller/entity/shaders/glyph_atlas.frag index 152995279826b..42024eb547998 100644 --- a/impeller/entity/shaders/glyph_atlas.frag +++ b/impeller/entity/shaders/glyph_atlas.frag @@ -7,7 +7,6 @@ uniform sampler2D glyph_atlas_sampler; uniform FragInfo { -<<<<<<< HEAD f16vec2 atlas_size; f16vec4 text_color; } @@ -17,22 +16,10 @@ in f16vec2 v_unit_vertex; in f16vec2 v_atlas_position; in f16vec2 v_atlas_glyph_size; in float16_t v_color_glyph; -======= - vec2 atlas_size; - vec4 text_color; -} -frag_info; - -in vec2 v_unit_position; -in vec2 v_source_position; -in vec2 v_source_glyph_size; -in float v_has_color; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 out f16vec4 frag_color; void main() { -<<<<<<< HEAD f16vec2 scale_perspective = v_atlas_glyph_size / frag_info.atlas_size; f16vec2 offset = v_atlas_position / frag_info.atlas_size; if (v_color_glyph == 1.0hf) { @@ -43,16 +30,5 @@ void main() { v_unit_vertex * scale_perspective + offset) .aaaa) * frag_info.text_color; -======= - vec2 uv_size = v_source_glyph_size / frag_info.atlas_size; - vec2 offset = v_source_position / frag_info.atlas_size; - if (v_has_color == 1.0) { - frag_color = - texture(glyph_atlas_sampler, v_unit_position * uv_size + offset); - } else { - frag_color = - texture(glyph_atlas_sampler, v_unit_position * uv_size + offset).aaaa * - frag_info.text_color; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 } } diff --git a/impeller/entity/shaders/glyph_atlas.vert b/impeller/entity/shaders/glyph_atlas.vert index 9542361f3ba38..b16271d86d49e 100644 --- a/impeller/entity/shaders/glyph_atlas.vert +++ b/impeller/entity/shaders/glyph_atlas.vert @@ -2,39 +2,26 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include + uniform FrameInfo { mat4 mvp; } frame_info; -<<<<<<< HEAD -in f16vec2 unit_vertex; -in f16vec2 glyph_position; -in f16vec2 glyph_size; -in f16vec2 atlas_position; -in f16vec2 atlas_glyph_size; -in float16_t color_glyph; +in f16vec2 unit_position; +in f16vec2 destination_position; +in f16vec2 destination_size; +in f16vec2 source_position; +in f16vec2 source_glyph_size; +in float16_t has_color; -out f16vec2 v_unit_vertex; -out f16vec2 v_atlas_position; -out f16vec2 v_atlas_glyph_size; -out float16_t v_color_glyph; -======= -in vec2 unit_position; -in vec2 destination_position; -in vec2 destination_size; -in vec2 source_position; -in vec2 source_glyph_size; -in float has_color; - -out vec2 v_unit_position; -out vec2 v_source_position; -out vec2 v_source_glyph_size; -out float v_has_color; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 +out f16vec2 v_unit_position; +out f16vec2 v_source_position; +out f16vec2 v_source_glyph_size; +out float16_t v_has_color; void main() { gl_Position = IPPositionForGlyphPosition( @@ -43,4 +30,4 @@ void main() { v_source_position = source_position; v_source_glyph_size = source_glyph_size; v_has_color = has_color; -} +} \ No newline at end of file diff --git a/impeller/entity/shaders/linear_gradient_fill.frag b/impeller/entity/shaders/linear_gradient_fill.frag index a4292924a3020..d2edc915141bf 100644 --- a/impeller/entity/shaders/linear_gradient_fill.frag +++ b/impeller/entity/shaders/linear_gradient_fill.frag @@ -8,7 +8,6 @@ uniform sampler2D texture_sampler; uniform GradientInfo { -<<<<<<< HEAD f16vec2 start_point; f16vec2 end_point; float16_t tile_mode; @@ -17,23 +16,12 @@ uniform GradientInfo { f16vec2 half_texel; } gradient_info; -======= - vec2 start_point; - vec2 end_point; - float tile_mode; - float texture_sampler_y_coord_scale; - float alpha; - vec2 half_texel; -} -gradient_info; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 in f16vec2 v_position; out f16vec4 frag_color; void main() { -<<<<<<< HEAD float16_t len = length(gradient_info.end_point - gradient_info.start_point); float16_t dot = dot(v_position - gradient_info.start_point, gradient_info.end_point - gradient_info.start_point); @@ -44,16 +32,4 @@ void main() { gradient_info.tile_mode); frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; -======= - float len = length(gradient_info.end_point - gradient_info.start_point); - float dot = dot(v_position - gradient_info.start_point, - gradient_info.end_point - gradient_info.start_point); - float t = dot / (len * len); - frag_color = IPSampleLinearWithTileMode( - texture_sampler, vec2(t, 0.5), - gradient_info.texture_sampler_y_coord_scale, gradient_info.half_texel, - gradient_info.tile_mode); - frag_color = - vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 } diff --git a/impeller/entity/shaders/linear_gradient_ssbo_fill.frag b/impeller/entity/shaders/linear_gradient_ssbo_fill.frag index cf649641de2b1..ab512ad731d49 100644 --- a/impeller/entity/shaders/linear_gradient_ssbo_fill.frag +++ b/impeller/entity/shaders/linear_gradient_ssbo_fill.frag @@ -7,7 +7,6 @@ #include readonly buffer ColorData { -<<<<<<< HEAD f16vec4 colors[]; } color_data; @@ -20,37 +19,16 @@ uniform GradientInfo { float16_t colors_length; } gradient_info; -======= - vec4 colors[]; -} -color_data; - -uniform GradientInfo { - vec2 start_point; - vec2 end_point; - float alpha; - float tile_mode; - float colors_length; -} -gradient_info; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 in f16vec2 v_position; out f16vec4 frag_color; void main() { -<<<<<<< HEAD float16_t len = length(gradient_info.end_point - gradient_info.start_point); float16_t dot = dot(v_position - gradient_info.start_point, gradient_info.end_point - gradient_info.start_point); float16_t t = dot / (len * len); -======= - float len = length(gradient_info.end_point - gradient_info.start_point); - float dot = dot(v_position - gradient_info.start_point, - gradient_info.end_point - gradient_info.start_point); - float t = dot / (len * len); ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 if ((t < 0.0hf || t > 1.0hf) && gradient_info.tile_mode == kTileModeDecal) { frag_color = f16vec4(0.0hf); @@ -59,15 +37,8 @@ void main() { t = IPFloatTile(t, gradient_info.tile_mode); f16vec3 values = IPComputeFixedGradientValues(t, gradient_info.colors_length); -<<<<<<< HEAD frag_color = mix(color_data.colors[int(values.x)], color_data.colors[int(values.y)], values.z); frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; -======= - frag_color = mix(color_data.colors[int(values.x)], - color_data.colors[int(values.y)], values.z); - frag_color = - vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 } diff --git a/impeller/entity/shaders/linear_to_srgb_filter.frag b/impeller/entity/shaders/linear_to_srgb_filter.frag index 8dbf02bb006c9..b982b61794808 100644 --- a/impeller/entity/shaders/linear_to_srgb_filter.frag +++ b/impeller/entity/shaders/linear_to_srgb_filter.frag @@ -13,17 +13,10 @@ uniform sampler2D input_texture; uniform FragInfo { -<<<<<<< HEAD float16_t texture_sampler_y_coord_scale; float16_t input_alpha; } frag_info; -======= - float texture_sampler_y_coord_scale; - float input_alpha; -} -frag_info; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 in vec2 v_position; out f16vec4 frag_color; diff --git a/impeller/entity/shaders/morphology_filter.frag b/impeller/entity/shaders/morphology_filter.frag index 44b452df3dbb7..49458bc8a37ce 100644 --- a/impeller/entity/shaders/morphology_filter.frag +++ b/impeller/entity/shaders/morphology_filter.frag @@ -8,13 +8,8 @@ // These values must correspond to the order of the items in the // 'FilterContents::MorphType' enum class. -<<<<<<< HEAD const float16_t kMorphTypeDilate = 0.0hf; const float16_t kMorphTypeErode = 1.0hf; -======= -const float kMorphTypeDilate = 0; -const float kMorphTypeErode = 1; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 uniform sampler2D texture_sampler; @@ -31,7 +26,6 @@ in f16vec2 v_texture_coords; out f16vec4 frag_color; void main() { -<<<<<<< HEAD f16vec4 result = frag_info.morph_type == kMorphTypeDilate ? f16vec4(0) : f16vec4(1); f16vec2 uv_offset = frag_info.direction / frag_info.texture_size; @@ -44,19 +38,6 @@ void main() { frag_info.texture_sampler_y_coord_scale, // y coordinate scale kTileModeDecal // tile mode ); -======= - vec4 result = frag_info.morph_type == kMorphTypeDilate ? vec4(0) : vec4(1); - vec2 uv_offset = frag_info.direction / frag_info.texture_size; - for (float i = -frag_info.radius; i <= frag_info.radius; i++) { - vec2 texture_coords = v_texture_coords + uv_offset * i; - vec4 color; - color = IPSampleWithTileMode( - texture_sampler, // sampler - texture_coords, // texture coordinates - frag_info.texture_sampler_y_coord_scale, // y coordinate scale - kTileModeDecal // tile mode - ); ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 if (frag_info.morph_type == kMorphTypeDilate) { result = max(color, result); } else { diff --git a/impeller/entity/shaders/position.vert b/impeller/entity/shaders/position.vert index 486a908e5bfd8..919bde994bd05 100644 --- a/impeller/entity/shaders/position.vert +++ b/impeller/entity/shaders/position.vert @@ -7,15 +7,9 @@ uniform VertInfo { mat4 mvp; -<<<<<<< HEAD f16vec4 color; } vert_info; -======= - vec4 color; -} -vert_info; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 in f16vec2 position; diff --git a/impeller/entity/shaders/radial_gradient_fill.frag b/impeller/entity/shaders/radial_gradient_fill.frag index 7fc483ced71d0..a970d4c367720 100644 --- a/impeller/entity/shaders/radial_gradient_fill.frag +++ b/impeller/entity/shaders/radial_gradient_fill.frag @@ -8,7 +8,6 @@ uniform sampler2D texture_sampler; uniform GradientInfo { -<<<<<<< HEAD f16vec2 center; float16_t radius; float16_t tile_mode; @@ -17,16 +16,6 @@ uniform GradientInfo { f16vec2 half_texel; } gradient_info; -======= - vec2 center; - float radius; - float tile_mode; - float texture_sampler_y_coord_scale; - float alpha; - vec2 half_texel; -} -gradient_info; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 in f16vec2 v_position; @@ -36,17 +25,9 @@ void main() { float16_t len = length(v_position - gradient_info.center); float16_t t = len / gradient_info.radius; frag_color = IPSampleLinearWithTileMode( -<<<<<<< HEAD texture_sampler, f16vec2(t, 0.5hf), gradient_info.texture_sampler_y_coord_scale, gradient_info.half_texel, gradient_info.tile_mode); frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; -======= - texture_sampler, vec2(t, 0.5), - gradient_info.texture_sampler_y_coord_scale, gradient_info.half_texel, - gradient_info.tile_mode); - frag_color = - vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 } diff --git a/impeller/entity/shaders/radial_gradient_ssbo_fill.frag b/impeller/entity/shaders/radial_gradient_ssbo_fill.frag index d49a3c2e2d814..6370dc3c8aa67 100644 --- a/impeller/entity/shaders/radial_gradient_ssbo_fill.frag +++ b/impeller/entity/shaders/radial_gradient_ssbo_fill.frag @@ -7,7 +7,6 @@ #include readonly buffer ColorData { -<<<<<<< HEAD f16vec4 colors[]; } color_data; @@ -20,20 +19,6 @@ uniform GradientInfo { float16_t colors_length; } gradient_info; -======= - vec4 colors[]; -} -color_data; - -uniform GradientInfo { - vec2 center; - float radius; - float tile_mode; - float alpha; - float colors_length; -} -gradient_info; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 in f16vec2 v_position; @@ -50,15 +35,8 @@ void main() { t = IPFloatTile(t, gradient_info.tile_mode); f16vec3 values = IPComputeFixedGradientValues(t, gradient_info.colors_length); -<<<<<<< HEAD frag_color = mix(color_data.colors[int(values.x)], color_data.colors[int(values.y)], values.z); frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; -======= - frag_color = mix(color_data.colors[int(values.x)], - color_data.colors[int(values.y)], values.z); - frag_color = - vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 } diff --git a/impeller/entity/shaders/srgb_to_linear_filter.frag b/impeller/entity/shaders/srgb_to_linear_filter.frag index 7de9dda13f607..a2f567142c1c9 100644 --- a/impeller/entity/shaders/srgb_to_linear_filter.frag +++ b/impeller/entity/shaders/srgb_to_linear_filter.frag @@ -12,17 +12,10 @@ uniform sampler2D input_texture; uniform FragInfo { -<<<<<<< HEAD float16_t texture_sampler_y_coord_scale; float16_t input_alpha; } frag_info; -======= - float texture_sampler_y_coord_scale; - float input_alpha; -} -frag_info; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 in f16vec2 v_position; out f16vec4 frag_color; diff --git a/impeller/entity/shaders/sweep_gradient_fill.frag b/impeller/entity/shaders/sweep_gradient_fill.frag index a420683e989fd..2b71073a696e5 100644 --- a/impeller/entity/shaders/sweep_gradient_fill.frag +++ b/impeller/entity/shaders/sweep_gradient_fill.frag @@ -9,7 +9,6 @@ uniform sampler2D texture_sampler; uniform GradientInfo { -<<<<<<< HEAD f16vec2 center; float16_t bias; float16_t scale; @@ -19,17 +18,6 @@ uniform GradientInfo { f16vec2 half_texel; } gradient_info; -======= - vec2 center; - float bias; - float scale; - float tile_mode; - float texture_sampler_y_coord_scale; - float alpha; - vec2 half_texel; -} -gradient_info; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 in f16vec2 v_position; @@ -39,23 +27,12 @@ void main() { f16vec2 coord = v_position - gradient_info.center; float angle = atan(-coord.y, -coord.x); -<<<<<<< HEAD float16_t t = (float16_t(angle) * k1Over2Pi + 0.5hf + gradient_info.bias) * gradient_info.scale; frag_color = IPSampleLinearWithTileMode( - texture_sampler, f16vec2(t, 0.5), + texture_sampler, f16vec2(t, 0.5hf), gradient_info.texture_sampler_y_coord_scale, gradient_info.half_texel, gradient_info.tile_mode); frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; -======= - float t = - (angle * k1Over2Pi + 0.5 + gradient_info.bias) * gradient_info.scale; - frag_color = IPSampleLinearWithTileMode( - texture_sampler, vec2(t, 0.5), - gradient_info.texture_sampler_y_coord_scale, gradient_info.half_texel, - gradient_info.tile_mode); - frag_color = - vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 } diff --git a/impeller/entity/shaders/sweep_gradient_ssbo_fill.frag b/impeller/entity/shaders/sweep_gradient_ssbo_fill.frag index 2b484f3c24a24..cf1f8dd953ac5 100644 --- a/impeller/entity/shaders/sweep_gradient_ssbo_fill.frag +++ b/impeller/entity/shaders/sweep_gradient_ssbo_fill.frag @@ -8,7 +8,6 @@ #include readonly buffer ColorData { -<<<<<<< HEAD f16vec4 colors[]; } color_data; @@ -22,21 +21,6 @@ uniform GradientInfo { float16_t colors_length; } gradient_info; -======= - vec4 colors[]; -} -color_data; - -uniform GradientInfo { - vec2 center; - float bias; - float scale; - float tile_mode; - float alpha; - float colors_length; -} -gradient_info; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 in f16vec2 v_position; @@ -45,13 +29,8 @@ out f16vec4 frag_color; void main() { f16vec2 coord = v_position - gradient_info.center; float angle = atan(-coord.y, -coord.x); -<<<<<<< HEAD float16_t t = (float16_t(angle) * k1Over2Pi + 0.5hf + gradient_info.bias) * gradient_info.scale; -======= - float t = - (angle * k1Over2Pi + 0.5 + gradient_info.bias) * gradient_info.scale; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 if ((t < 0.0hf || t > 1.0hf) && gradient_info.tile_mode == kTileModeDecal) { frag_color = f16vec4(0.0hf); @@ -60,15 +39,8 @@ void main() { t = IPFloatTile(t, gradient_info.tile_mode); f16vec3 values = IPComputeFixedGradientValues(t, gradient_info.colors_length); -<<<<<<< HEAD frag_color = mix(color_data.colors[int(values.x)], color_data.colors[int(values.y)], values.z); frag_color = f16vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; -======= - frag_color = mix(color_data.colors[int(values.x)], - color_data.colors[int(values.y)], values.z); - frag_color = - vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 } diff --git a/impeller/entity/shaders/yuv_to_rgb_filter.frag b/impeller/entity/shaders/yuv_to_rgb_filter.frag index 1319517e2ed4f..db9554fd407db 100644 --- a/impeller/entity/shaders/yuv_to_rgb_filter.frag +++ b/impeller/entity/shaders/yuv_to_rgb_filter.frag @@ -18,14 +18,8 @@ uniform FragInfo { float16_t texture_sampler_y_coord_scale; float16_t yuv_color_space; mat4 matrix; -<<<<<<< HEAD } frag_info; -======= - float yuv_color_space; -} -frag_info; ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 in f16vec2 v_position; out f16vec4 frag_color; @@ -37,7 +31,6 @@ void main() { yuv_offset.x = 16.0hf / 255.0hf; } -<<<<<<< HEAD yuv.x = IPSample(y_texture, v_position, frag_info.texture_sampler_y_coord_scale) .x; @@ -45,13 +38,4 @@ void main() { IPSample(uv_texture, v_position, frag_info.texture_sampler_y_coord_scale) .xy; frag_color = f16mat4(frag_info.matrix) * f16vec4(yuv - yuv_offset, 1.0hf); -======= - yuv.x = - IPSample(y_texture, v_position, frag_info.texture_sampler_y_coord_scale) - .r; - yuv.yz = - IPSample(uv_texture, v_position, frag_info.texture_sampler_y_coord_scale) - .rg; - frag_color = frag_info.matrix * vec4(yuv - yuv_offset, 1); ->>>>>>> ddf6a20b86578f147ee7da023f3f08ecb4256d07 } From 5f9f270f5583c186ee76a835b3b8ad380fb3c198 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 21 Nov 2022 16:08:18 -0800 Subject: [PATCH 5/6] ++ --- impeller/compiler/shader_lib/impeller/blending.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/impeller/compiler/shader_lib/impeller/blending.glsl b/impeller/compiler/shader_lib/impeller/blending.glsl index 834cd8d1e7344..8c6207cdd4a35 100644 --- a/impeller/compiler/shader_lib/impeller/blending.glsl +++ b/impeller/compiler/shader_lib/impeller/blending.glsl @@ -105,10 +105,10 @@ f16vec3 IPBlendColorDodge(f16vec3 dst, f16vec3 src) { if (1.0hf - src.r < kEhCloseEnough) { color.r = 1.0hf; } - if (1. - src.g < kEhCloseEnough) { + if (1.0hf - src.g < kEhCloseEnough) { color.g = 1.0hf; } - if (1. - src.b < kEhCloseEnough) { + if (1.0hf - src.b < kEhCloseEnough) { color.b = 1.0hf; } @@ -127,7 +127,7 @@ f16vec3 IPBlendColorBurn(f16vec3 dst, f16vec3 src) { color.g = 1.0hf; } if (1.0hf - dst.b < kEhCloseEnough) { - color.b = 0.1hf; + color.b = 1.0hf; } if (src.r < kEhCloseEnough) { From 7901465e60aabb6ffcb5f36d0297d173de2aa0e0 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 21 Nov 2022 16:31:56 -0800 Subject: [PATCH 6/6] fix android --- .../shader_lib/impeller/texture.glsl.orig | 131 ---------------- .../shader_lib/impeller/texture.glsl.rej | 148 ------------------ .../compiler/shader_lib/impeller/types.glsl | 2 + impeller/entity/BUILD.gn | 1 - impeller/entity/shaders/test.frag | 20 --- 5 files changed, 2 insertions(+), 300 deletions(-) delete mode 100644 impeller/compiler/shader_lib/impeller/texture.glsl.orig delete mode 100644 impeller/compiler/shader_lib/impeller/texture.glsl.rej delete mode 100644 impeller/entity/shaders/test.frag diff --git a/impeller/compiler/shader_lib/impeller/texture.glsl.orig b/impeller/compiler/shader_lib/impeller/texture.glsl.orig deleted file mode 100644 index 6cfe681f7a565..0000000000000 --- a/impeller/compiler/shader_lib/impeller/texture.glsl.orig +++ /dev/null @@ -1,131 +0,0 @@ -// 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 TEXTURE_GLSL_ -#define TEXTURE_GLSL_ - -#include -#include - -/// Sample from a texture. -/// -/// If `y_coord_scale` < 0.0, the Y coordinate is flipped. This is useful -/// for Impeller graphics backends that use a flipped framebuffer coordinate -/// space. -f16vec4 IPSample(sampler2D texture_sampler, f16vec2 coords, float16_t y_coord_scale) { - if (y_coord_scale < 0.0hf) { - coords.y = 1.0hf - coords.y; - } - return f16vec4(texture(texture_sampler, coords)); -} - -/// Sample from a texture. -/// -/// If `y_coord_scale` < 0.0, the Y coordinate is flipped. This is useful -/// for Impeller graphics backends that use a flipped framebuffer coordinate -/// space. -/// The range of `coods` will be mapped from [0, 1] to [half_texel, 1 - half_texel] -f16vec4 IPSampleLinear(sampler2D texture_sampler, f16vec2 coords, float16_t y_coord_scale, f16vec2 half_texel) { - coords.x = mix(half_texel.x, 1.0hf - half_texel.x, coords.x); - coords.y = mix(half_texel.y, 1.0hf - half_texel.y, coords.y); - return IPSample(texture_sampler, coords, y_coord_scale); -} - -// These values must correspond to the order of the items in the -// 'Entity::TileMode' enum class. -const float16_t kTileModeClamp = 0.0hf; -const float16_t kTileModeRepeat = 1.0hf; -const float16_t kTileModeMirror = 2.0hf; -const float16_t kTileModeDecal = 3.0hf; - -/// Remap a float16_t using a tiling mode. -/// -/// When `tile_mode` is `kTileModeDecal`, no tiling is applied and `t` is -/// returned. In all other cases, a value between 0 and 1 is returned by tiling -/// `t`. -/// When `t` is between [0 to 1), the original unchanged `t` is always returned. -float16_t IPFloatTile(float16_t t, float16_t tile_mode) { - if (tile_mode == kTileModeClamp) { - t = clamp(t, 0.0hf, 1.0hf); - } else if (tile_mode == kTileModeRepeat) { - t = fract(t); - } else if (tile_mode == kTileModeMirror) { - float16_t t1 = t - 1.0hf; - float16_t t2 = t1 - 2.0hf * floor(t1 * 0.5hf) - 1.0hf; - t = abs(t2); - } - return t; -} - -/// Remap a vec2 using a tiling mode. -/// -/// Runs each component of the vec2 through `IPFloatTile`. -f16vec2 IPVec2Tile(f16vec2 coords, float16_t x_tile_mode, float16_t y_tile_mode) { - return f16vec2(IPFloatTile(coords.x, x_tile_mode), - IPFloatTile(coords.y, y_tile_mode)); -} - -/// Sample a texture, emulating a specific tile mode. -/// -/// This is useful for Impeller graphics backend that don't have native support -/// for Decal. -f16vec4 IPSampleWithTileMode(sampler2D tex, - f16vec2 coords, - float16_t y_coord_scale, - float16_t x_tile_mode, - float16_t y_tile_mode) { - if (x_tile_mode == kTileModeDecal && (coords.x < 0.hf || coords.x >= 1.hf) || - y_tile_mode == kTileModeDecal && (coords.y < 0.hf || coords.y >= 1.hf)) { - return f16vec4(0.0hf); - } - - return IPSample(tex, IPVec2Tile(coords, x_tile_mode, y_tile_mode), - y_coord_scale); -} - -/// Sample a texture, emulating a specific tile mode. -/// -/// This is useful for Impeller graphics backend that don't have native support -/// for Decal. -f16vec4 IPSampleWithTileMode(sampler2D tex, - f16vec2 coords, - float16_t y_coord_scale, - float16_t tile_mode) { - return IPSampleWithTileMode(tex, coords, y_coord_scale, tile_mode, tile_mode); -} - -/// Sample a texture, emulating a specific tile mode. -/// -/// This is useful for Impeller graphics backend that don't have native support -/// for Decal. -/// The range of `coods` will be mapped from [0, 1] to [half_texel, 1 - half_texel] -f16vec4 IPSampleLinearWithTileMode(sampler2D tex, - f16vec2 coords, - float16_t y_coord_scale, - f16vec2 half_texel, - float16_t x_tile_mode, - float16_t y_tile_mode) { - if (x_tile_mode == kTileModeDecal && (coords.x < 0.0hf || coords.x >= 1.0hf) || - y_tile_mode == kTileModeDecal && (coords.y < 0.0hf || coords.y >= 1.0hf)) { - return f16vec4(0.0hf); - } - - return IPSampleLinear(tex, IPVec2Tile(coords, x_tile_mode, y_tile_mode), - y_coord_scale, half_texel); -} - -/// Sample a texture, emulating a specific tile mode. -/// -/// This is useful for Impeller graphics backend that don't have native support -/// for Decal. -/// The range of `coods` will be mapped from [0, 1] to [half_texel, 1 - half_texel] -f16vec4 IPSampleLinearWithTileMode(sampler2D tex, - f16vec2 coords, - float16_t y_coord_scale, - f16vec2 half_texel, - float16_t tile_mode) { - return IPSampleLinearWithTileMode(tex, coords, y_coord_scale, half_texel, tile_mode, tile_mode); -} - -#endif diff --git a/impeller/compiler/shader_lib/impeller/texture.glsl.rej b/impeller/compiler/shader_lib/impeller/texture.glsl.rej deleted file mode 100644 index c59fffbf3eddc..0000000000000 --- a/impeller/compiler/shader_lib/impeller/texture.glsl.rej +++ /dev/null @@ -1,148 +0,0 @@ -*************** -*** 5,19 **** - #ifndef TEXTURE_GLSL_ - #define TEXTURE_GLSL_ - -- #include - #include - - /// Sample from a texture. - /// - /// If < 0.0, the Y coordinate is flipped. This is useful - /// for Impeller graphics backends that use a flipped framebuffer coordinate - /// space. -- f16vec4 IPSample(sampler2D texture_sampler, f16vec2 coords, float16_t y_coord_scale) { - if (y_coord_scale < 0.0hf) { - coords.y = 1.0hf - coords.y; - } ---- 5,21 ---- - #ifndef TEXTURE_GLSL_ - #define TEXTURE_GLSL_ - - #include -+ #include - - /// Sample from a texture. - /// - /// If < 0.0, the Y coordinate is flipped. This is useful - /// for Impeller graphics backends that use a flipped framebuffer coordinate - /// space. -+ f16vec4 IPSample(sampler2D texture_sampler, -+ f16vec2 coords, -+ float16_t y_coord_scale) { - if (y_coord_scale < 0.0hf) { - coords.y = 1.0hf - coords.y; - } -*************** -*** 25,32 **** - /// If < 0.0, the Y coordinate is flipped. This is useful - /// for Impeller graphics backends that use a flipped framebuffer coordinate - /// space. -- /// The range of will be mapped from [0, 1] to [half_texel, 1 - half_texel] -- f16vec4 IPSampleLinear(sampler2D texture_sampler, f16vec2 coords, float16_t y_coord_scale, f16vec2 half_texel) { - coords.x = mix(half_texel.x, 1.0hf - half_texel.x, coords.x); - coords.y = mix(half_texel.y, 1.0hf - half_texel.y, coords.y); - return IPSample(texture_sampler, coords, y_coord_scale); ---- 27,38 ---- - /// If < 0.0, the Y coordinate is flipped. This is useful - /// for Impeller graphics backends that use a flipped framebuffer coordinate - /// space. -+ /// The range of will be mapped from [0, 1] to [half_texel, 1 - -+ /// half_texel] -+ f16vec4 IPSampleLinear(sampler2D texture_sampler, -+ f16vec2 coords, -+ float16_t y_coord_scale, -+ f16vec2 half_texel) { - coords.x = mix(half_texel.x, 1.0hf - half_texel.x, coords.x); - coords.y = mix(half_texel.y, 1.0hf - half_texel.y, coords.y); - return IPSample(texture_sampler, coords, y_coord_scale); -*************** -*** 61,69 **** - /// Remap a vec2 using a tiling mode. - /// - /// Runs each component of the vec2 through . -- f16vec2 IPVec2Tile(f16vec2 coords, float16_t x_tile_mode, float16_t y_tile_mode) { - return f16vec2(IPFloatTile(coords.x, x_tile_mode), -- IPFloatTile(coords.y, y_tile_mode)); - } - - /// Sample a texture, emulating a specific tile mode. ---- 67,77 ---- - /// Remap a vec2 using a tiling mode. - /// - /// Runs each component of the vec2 through . -+ f16vec2 IPVec2Tile(f16vec2 coords, -+ float16_t x_tile_mode, -+ float16_t y_tile_mode) { - return f16vec2(IPFloatTile(coords.x, x_tile_mode), -+ IPFloatTile(coords.y, y_tile_mode)); - } - - /// Sample a texture, emulating a specific tile mode. -*************** -*** 99,113 **** - /// - /// This is useful for Impeller graphics backend that don't have native support - /// for Decal. -- /// The range of will be mapped from [0, 1] to [half_texel, 1 - half_texel] - f16vec4 IPSampleLinearWithTileMode(sampler2D tex, -- f16vec2 coords, -- float16_t y_coord_scale, -- f16vec2 half_texel, -- float16_t x_tile_mode, -- float16_t y_tile_mode) { -- if (x_tile_mode == kTileModeDecal && (coords.x < 0.0hf || coords.x >= 1.0hf) || -- y_tile_mode == kTileModeDecal && (coords.y < 0.0hf || coords.y >= 1.0hf)) { - return f16vec4(0.0hf); - } - ---- 107,124 ---- - /// - /// This is useful for Impeller graphics backend that don't have native support - /// for Decal. -+ /// The range of will be mapped from [0, 1] to [half_texel, 1 - -+ /// half_texel] - f16vec4 IPSampleLinearWithTileMode(sampler2D tex, -+ f16vec2 coords, -+ float16_t y_coord_scale, -+ f16vec2 half_texel, -+ float16_t x_tile_mode, -+ float16_t y_tile_mode) { -+ if (x_tile_mode == kTileModeDecal && -+ (coords.x < 0.0hf || coords.x >= 1.0hf) || -+ y_tile_mode == kTileModeDecal && -+ (coords.y < 0.0hf || coords.y >= 1.0hf)) { - return f16vec4(0.0hf); - } - -*************** -*** 119,131 **** - /// - /// This is useful for Impeller graphics backend that don't have native support - /// for Decal. -- /// The range of will be mapped from [0, 1] to [half_texel, 1 - half_texel] - f16vec4 IPSampleLinearWithTileMode(sampler2D tex, - f16vec2 coords, - float16_t y_coord_scale, - f16vec2 half_texel, - float16_t tile_mode) { -- return IPSampleLinearWithTileMode(tex, coords, y_coord_scale, half_texel, tile_mode, tile_mode); - } - - #endif ---- 130,144 ---- - /// - /// This is useful for Impeller graphics backend that don't have native support - /// for Decal. -+ /// The range of will be mapped from [0, 1] to [half_texel, 1 - -+ /// half_texel] - f16vec4 IPSampleLinearWithTileMode(sampler2D tex, - f16vec2 coords, - float16_t y_coord_scale, - f16vec2 half_texel, - float16_t tile_mode) { -+ return IPSampleLinearWithTileMode(tex, coords, y_coord_scale, half_texel, -+ tile_mode, tile_mode); - } - - #endif diff --git a/impeller/compiler/shader_lib/impeller/types.glsl b/impeller/compiler/shader_lib/impeller/types.glsl index c61a4ac11d159..52a6cb408016f 100644 --- a/impeller/compiler/shader_lib/impeller/types.glsl +++ b/impeller/compiler/shader_lib/impeller/types.glsl @@ -15,6 +15,8 @@ #else +#extension GL_AMD_gpu_shader_half_float : enable + precision mediump sampler2D; precision mediump float; diff --git a/impeller/entity/BUILD.gn b/impeller/entity/BUILD.gn index 216a3ec6fb983..ecba665e6617a 100644 --- a/impeller/entity/BUILD.gn +++ b/impeller/entity/BUILD.gn @@ -8,7 +8,6 @@ impeller_shaders("entity_shaders") { name = "entity" shaders = [ - "shaders/test.frag", "shaders/atlas_fill.frag", "shaders/atlas_fill.vert", "shaders/blending/advanced_blend.vert", diff --git a/impeller/entity/shaders/test.frag b/impeller/entity/shaders/test.frag deleted file mode 100644 index eadd477b3c1d0..0000000000000 --- a/impeller/entity/shaders/test.frag +++ /dev/null @@ -1,20 +0,0 @@ -// 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. - -#include - -uniform sampler2D texture_sampler; - -uniform GradientInfo { - float16_t bias; -} -gradient_info; - -in vec2 v_position; - -out vec4 frag_color; - -void main() { - frag_color = gradient_info.bias * vec4(1.0, 0.0, 0.0, 1.0); -}