diff --git a/impeller/compiler/shader_lib/impeller/blending.glsl b/impeller/compiler/shader_lib/impeller/blending.glsl index f92e6bc4ab9a0..8c6207cdd4a35 100644 --- a/impeller/compiler/shader_lib/impeller/blending.glsl +++ b/impeller/compiler/shader_lib/impeller/blending.glsl @@ -7,46 +7,48 @@ #include #include +#include //------------------------------------------------------------------------------ /// 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) { + if (mn < 0.0hf) { color = lum + (((color - lum) * lum) / (lum - mn + 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 + 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.0hf); } //------------------------------------------------------------------------------ @@ -58,134 +60,136 @@ 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; + color.r = 0.0hf; } if (dst.g < kEhCloseEnough) { - color.g = 0; + color.g = 0.0hf; } if (dst.b < kEhCloseEnough) { - color.b = 0; + color.b = 0.0hf; } - if (1 - src.r < kEhCloseEnough) { - color.r = 1; + if (1.0hf - src.r < kEhCloseEnough) { + color.r = 1.0hf; } - if (1 - src.g < kEhCloseEnough) { - color.g = 1; + if (1.0hf - src.g < kEhCloseEnough) { + color.g = 1.0hf; } - if (1 - src.b < kEhCloseEnough) { - color.b = 1; + if (1.0hf - src.b < kEhCloseEnough) { + color.b = 1.0hf; } 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 < kEhCloseEnough) { + color.r = 1.0hf; } - if (1 - dst.g < kEhCloseEnough) { - color.g = 1; + if (1.0hf - dst.g < kEhCloseEnough) { + color.g = 1.0hf; } - if (1 - dst.b < kEhCloseEnough) { - color.b = 1; + if (1.0hf - dst.b < kEhCloseEnough) { + color.b = 1.0hf; } if (src.r < kEhCloseEnough) { - color.r = 0; + color.r = 0.0hf; } if (src.g < kEhCloseEnough) { - color.g = 0; + color.g = 0.0hf; } if (src.b < kEhCloseEnough) { - color.b = 0; + color.b = 0.0hf; } 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, // - sqrt(dst), // - dst, // - 0.25); + f16vec3 D = + IPVec3ChooseCutoff(((16.0hf * dst - 12.0hf) * dst + 4.0hf) * dst, // + sqrt(dst), // + dst, // + 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..7eebb9db1c484 100644 --- a/impeller/compiler/shader_lib/impeller/branching.glsl +++ b/impeller/compiler/shader_lib/impeller/branching.glsl @@ -11,42 +11,45 @@ /// 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 < kEhCloseEnough, // + diff.g < kEhCloseEnough, // + diff.b < 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..6b2c729f66c9a 100644 --- a/impeller/compiler/shader_lib/impeller/color.glsl +++ b/impeller/compiler/shader_lib/impeller/color.glsl @@ -6,24 +6,25 @@ #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..76daf0d6264e3 100644 --- a/impeller/compiler/shader_lib/impeller/gaussian.glsl +++ b/impeller/compiler/shader_lib/impeller/gaussian.glsl @@ -6,49 +6,51 @@ #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) / (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 * (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 * (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..7a5bc70430dde 100644 --- a/impeller/compiler/shader_lib/impeller/gradient.glsl +++ b/impeller/compiler/shader_lib/impeller/gradient.glsl @@ -6,19 +6,20 @@ #define GRADIENT_GLSL_ #include +#include /// Compute the indexes and mix coefficient used to mix colors for an /// arbitrarily sized color gradient. /// /// 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 d478a3a268cca..c0d2299328248 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. @@ -24,38 +25,34 @@ vec4 IPSample(sampler2D texture_sampler, vec2 coords, float y_coord_scale) { /// 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] -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); +/// 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 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 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) { +float16_t IPFloatTile(float16_t t, float16_t tile_mode) { if (tile_mode == kTileModeClamp) { - t = clamp(t, 0.0, 1.0); + t = clamp(t, 0.0hf, 1.0hf); } else if (tile_mode == kTileModeRepeat) { t = fract(t); } else if (tile_mode == kTileModeMirror) { - float t1 = t - 1; - float t2 = t1 - 2 * floor(t1 * 0.5) - 1; + float16_t t1 = t - 1.0hf; + float16_t t2 = t1 - 2.0hf * floor(t1 * 0.5hf) - 1.0hf; t = abs(t2); } return t; @@ -64,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)); } @@ -73,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), @@ -91,10 +88,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); } @@ -102,17 +99,16 @@ 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); +/// 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), @@ -123,15 +119,13 @@ 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) { - return IPSampleLinearWithTileMode(tex, coords, y_coord_scale, half_texel, - tile_mode, tile_mode); +/// 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/types.glsl b/impeller/compiler/shader_lib/impeller/types.glsl index d896c5e60659a..52a6cb408016f 100644 --- a/impeller/compiler/shader_lib/impeller/types.glsl +++ b/impeller/compiler/shader_lib/impeller/types.glsl @@ -5,9 +5,31 @@ #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 + +#extension GL_AMD_gpu_shader_half_float : enable + +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/shaders/atlas_fill.frag b/impeller/entity/shaders/atlas_fill.frag index e211971ca1bb9..c0be7749b1538 100644 --- a/impeller/entity/shaders/atlas_fill.frag +++ b/impeller/entity/shaders/atlas_fill.frag @@ -3,25 +3,26 @@ // 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, - frag_info.texture_sampler_y_coord_scale); - if (frag_info.has_vertex_color == 1.0) { + f16vec4 sampled = IPSample(texture_sampler, v_texture_coords, + 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 { 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 a2b1650f904a2..4b310b7c8be47 100644 --- a/impeller/entity/shaders/blending/advanced_blend.glsl +++ b/impeller/entity/shaders/blending/advanced_blend.glsl @@ -5,26 +5,27 @@ #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 @@ -32,18 +33,17 @@ void main() { ) * blend_info.dst_input_alpha; - vec4 dst = IPUnpremultiply(dst_sample); - vec4 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 - )); + 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 + )); - 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..439a3598c9282 100644 --- a/impeller/entity/shaders/blending/advanced_blend_color.frag +++ b/impeller/entity/shaders/blending/advanced_blend_color.frag @@ -3,8 +3,9 @@ // 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..80b747f6c3439 100644 --- a/impeller/entity/shaders/blending/advanced_blend_colorburn.frag +++ b/impeller/entity/shaders/blending/advanced_blend_colorburn.frag @@ -3,8 +3,9 @@ // 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..c6356530bbe96 100644 --- a/impeller/entity/shaders/blending/advanced_blend_colordodge.frag +++ b/impeller/entity/shaders/blending/advanced_blend_colordodge.frag @@ -3,8 +3,9 @@ // 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..95c8802433bed 100644 --- a/impeller/entity/shaders/blending/advanced_blend_darken.frag +++ b/impeller/entity/shaders/blending/advanced_blend_darken.frag @@ -3,8 +3,9 @@ // 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..1ccea9890e17f 100644 --- a/impeller/entity/shaders/blending/advanced_blend_difference.frag +++ b/impeller/entity/shaders/blending/advanced_blend_difference.frag @@ -3,8 +3,9 @@ // 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..2f613ec10939e 100644 --- a/impeller/entity/shaders/blending/advanced_blend_exclusion.frag +++ b/impeller/entity/shaders/blending/advanced_blend_exclusion.frag @@ -3,8 +3,9 @@ // 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..7a5d77cd380e2 100644 --- a/impeller/entity/shaders/blending/advanced_blend_hardlight.frag +++ b/impeller/entity/shaders/blending/advanced_blend_hardlight.frag @@ -3,8 +3,9 @@ // 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..2fee599fd42f9 100644 --- a/impeller/entity/shaders/blending/advanced_blend_hue.frag +++ b/impeller/entity/shaders/blending/advanced_blend_hue.frag @@ -3,8 +3,9 @@ // 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..c10ea8f0d40d2 100644 --- a/impeller/entity/shaders/blending/advanced_blend_lighten.frag +++ b/impeller/entity/shaders/blending/advanced_blend_lighten.frag @@ -3,8 +3,9 @@ // 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..082a69ce70b08 100644 --- a/impeller/entity/shaders/blending/advanced_blend_luminosity.frag +++ b/impeller/entity/shaders/blending/advanced_blend_luminosity.frag @@ -3,8 +3,9 @@ // 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..4034a42a3f24c 100644 --- a/impeller/entity/shaders/blending/advanced_blend_multiply.frag +++ b/impeller/entity/shaders/blending/advanced_blend_multiply.frag @@ -3,8 +3,9 @@ // 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..520e356433999 100644 --- a/impeller/entity/shaders/blending/advanced_blend_overlay.frag +++ b/impeller/entity/shaders/blending/advanced_blend_overlay.frag @@ -3,8 +3,9 @@ // 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..abd9cba668d77 100644 --- a/impeller/entity/shaders/blending/advanced_blend_saturation.frag +++ b/impeller/entity/shaders/blending/advanced_blend_saturation.frag @@ -3,8 +3,9 @@ // 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..5d429d86768c8 100644 --- a/impeller/entity/shaders/blending/advanced_blend_screen.frag +++ b/impeller/entity/shaders/blending/advanced_blend_screen.frag @@ -3,8 +3,9 @@ // 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..2fa7182060f43 100644 --- a/impeller/entity/shaders/blending/advanced_blend_softlight.frag +++ b/impeller/entity/shaders/blending/advanced_blend_softlight.frag @@ -3,8 +3,9 @@ // 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 468a9bb67f7ce..c2d8d9bc8083c 100644 --- a/impeller/entity/shaders/blending/blend.frag +++ b/impeller/entity/shaders/blending/blend.frag @@ -3,18 +3,19 @@ // 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 36bea41e390d8..7e6fbe48db6c3 100644 --- a/impeller/entity/shaders/blending/blend.vert +++ b/impeller/entity/shaders/blending/blend.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 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 85da0df8cdb76..281839465e433 100644 --- a/impeller/entity/shaders/border_mask_blur.frag +++ b/impeller/entity/shaders/border_mask_blur.frag @@ -4,6 +4,7 @@ #include #include +#include // Constant time mask blur for image borders. // @@ -17,38 +18,39 @@ 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); + 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() { - vec4 image_color = IPSample(texture_sampler, v_texture_coords, - frag_info.texture_sampler_y_coord_scale); - float 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 = + f16vec4 image_color = IPSample(texture_sampler, v_texture_coords, + 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); + 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 c021a93604b28..97ec550d56a74 100644 --- a/impeller/entity/shaders/color_matrix_color_filter.frag +++ b/impeller/entity/shaders/color_matrix_color_filter.frag @@ -4,6 +4,7 @@ #include #include +#include // A color filter that transforms colors through a 4x5 color matrix. // @@ -30,27 +31,28 @@ 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, - frag_info.texture_sampler_y_coord_scale) * - frag_info.input_alpha; + 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(frag_info.color_m * color + frag_info.color_v, 0.0, 1.0); + color = clamp(f16mat4(frag_info.color_m) * color + frag_info.color_v, 0.0hf, + 1.0hf); // 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 29b0128258658..27b8ecedbf216 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; } diff --git a/impeller/entity/shaders/gaussian_blur.frag b/impeller/entity/shaders/gaussian_blur.frag index 06bd0f389ff47..b47f253abeb61 100644 --- a/impeller/entity/shaders/gaussian_blur.frag +++ b/impeller/entity/shaders/gaussian_blur.frag @@ -16,44 +16,45 @@ #include #include #include +#include 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,17 @@ 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 4c9175bd9b16a..42024eb547998 100644 --- a/impeller/entity/shaders/glyph_atlas.frag +++ b/impeller/entity/shaders/glyph_atlas.frag @@ -2,30 +2,33 @@ // 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_position; -in vec2 v_source_position; -in vec2 v_source_glyph_size; -in float v_has_color; +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 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); + 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(glyph_atlas_sampler, v_unit_position * uv_size + offset).aaaa * - frag_info.text_color; + frag_color = f16vec4(texture(glyph_atlas_sampler, + v_unit_vertex * scale_perspective + offset) + .aaaa) * + frag_info.text_color; } } diff --git a/impeller/entity/shaders/glyph_atlas.vert b/impeller/entity/shaders/glyph_atlas.vert index 365fc72b13b1e..b16271d86d49e 100644 --- a/impeller/entity/shaders/glyph_atlas.vert +++ b/impeller/entity/shaders/glyph_atlas.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 + #include uniform FrameInfo { @@ -9,17 +11,17 @@ uniform FrameInfo { } frame_info; -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; +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 vec2 v_unit_position; -out vec2 v_source_position; -out vec2 v_source_glyph_size; -out float v_has_color; +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( @@ -28,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/glyph_atlas_sdf.vert b/impeller/entity/shaders/glyph_atlas_sdf.vert index cfbb2d353e7c6..abc537415bf34 100644 --- a/impeller/entity/shaders/glyph_atlas_sdf.vert +++ b/impeller/entity/shaders/glyph_atlas_sdf.vert @@ -3,6 +3,7 @@ // found in the LICENSE file. #include +#include uniform FrameInfo { mat4 mvp; diff --git a/impeller/entity/shaders/gradient_fill.vert b/impeller/entity/shaders/gradient_fill.vert index 86f4d1e228694..824f496ea8c22 100644 --- a/impeller/entity/shaders/gradient_fill.vert +++ b/impeller/entity/shaders/gradient_fill.vert @@ -3,6 +3,7 @@ // found in the LICENSE file. #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 0986cfa750018..d2edc915141bf 100644 --- a/impeller/entity/shaders/linear_gradient_fill.frag +++ b/impeller/entity/shaders/linear_gradient_fill.frag @@ -3,32 +3,33 @@ // 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(v_position - gradient_info.start_point, - gradient_info.end_point - gradient_info.start_point); - float t = dot / (len * len); + 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); frag_color = IPSampleLinearWithTileMode( - texture_sampler, vec2(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 = - 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 21041d7938550..ab512ad731d49 100644 --- a/impeller/entity/shaders/linear_gradient_ssbo_fill.frag +++ b/impeller/entity/shaders/linear_gradient_ssbo_fill.frag @@ -4,40 +4,41 @@ #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(v_position - gradient_info.start_point, - gradient_info.end_point - gradient_info.start_point); - float t = dot / (len * len); + 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); - 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 0b2a68da12368..b982b61794808 100644 --- a/impeller/entity/shaders/linear_to_srgb_filter.frag +++ b/impeller/entity/shaders/linear_to_srgb_filter.frag @@ -4,6 +4,7 @@ #include #include +#include // A color filter that applies the sRGB gamma curve to the color. // @@ -12,25 +13,25 @@ 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, - frag_info.texture_sampler_y_coord_scale) * - frag_info.input_alpha; + 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 29b0128258658..c3439ca5d4b92 100644 --- a/impeller/entity/shaders/linear_to_srgb_filter.vert +++ b/impeller/entity/shaders/linear_to_srgb_filter.vert @@ -2,13 +2,15 @@ // 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 27fa447baeb63..49458bc8a37ce 100644 --- a/impeller/entity/shaders/morphology_filter.frag +++ b/impeller/entity/shaders/morphology_filter.frag @@ -4,32 +4,34 @@ #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 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 0b21229bcc05a..919bde994bd05 100644 --- a/impeller/entity/shaders/position.vert +++ b/impeller/entity/shaders/position.vert @@ -3,16 +3,17 @@ // 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 6b4ef7f642079..59731fd2ab43f 100644 --- a/impeller/entity/shaders/position_color.vert +++ b/impeller/entity/shaders/position_color.vert @@ -3,6 +3,7 @@ // found in the LICENSE file. #include +#include uniform VertInfo { mat4 mvp; @@ -10,9 +11,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 f60ec0dd6453c..e49949a801277 100644 --- a/impeller/entity/shaders/position_uv.vert +++ b/impeller/entity/shaders/position_uv.vert @@ -3,6 +3,7 @@ // found in the LICENSE file. #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 3414e8edc648c..a970d4c367720 100644 --- a/impeller/entity/shaders/radial_gradient_fill.frag +++ b/impeller/entity/shaders/radial_gradient_fill.frag @@ -3,30 +3,31 @@ // 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), + texture_sampler, 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 9b129f661fae9..6370dc3c8aa67 100644 --- a/impeller/entity/shaders/radial_gradient_ssbo_fill.frag +++ b/impeller/entity/shaders/radial_gradient_ssbo_fill.frag @@ -4,38 +4,39 @@ #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..32b550e5836b6 100644 --- a/impeller/entity/shaders/rrect_blur.frag +++ b/impeller/entity/shaders/rrect_blur.frag @@ -3,60 +3,63 @@ // 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 - - space * space)); + 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 +70,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 10a3cba4654db..54256a89c955a 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; } 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 9e4f90e900900..a2f567142c1c9 100644 --- a/impeller/entity/shaders/srgb_to_linear_filter.frag +++ b/impeller/entity/shaders/srgb_to_linear_filter.frag @@ -4,6 +4,7 @@ #include #include +#include // Creates a color filter that applies the inverse of the sRGB gamma curve // to the RGB channels. @@ -11,25 +12,25 @@ 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, - frag_info.texture_sampler_y_coord_scale) * - frag_info.input_alpha; + 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 29b0128258658..27b8ecedbf216 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; } diff --git a/impeller/entity/shaders/sweep_gradient_fill.frag b/impeller/entity/shaders/sweep_gradient_fill.frag index 30cc3ec8a35dd..2b71073a696e5 100644 --- a/impeller/entity/shaders/sweep_gradient_fill.frag +++ b/impeller/entity/shaders/sweep_gradient_fill.frag @@ -4,34 +4,35 @@ #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), + texture_sampler, 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/sweep_gradient_ssbo_fill.frag b/impeller/entity/shaders/sweep_gradient_ssbo_fill.frag index 226a483c815bc..cf1f8dd953ac5 100644 --- a/impeller/entity/shaders/sweep_gradient_ssbo_fill.frag +++ b/impeller/entity/shaders/sweep_gradient_ssbo_fill.frag @@ -5,41 +5,42 @@ #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/texture_fill.frag b/impeller/entity/shaders/texture_fill.frag index 913cc7e1e8a70..0e7cec6e6ea65 100644 --- a/impeller/entity/shaders/texture_fill.frag +++ b/impeller/entity/shaders/texture_fill.frag @@ -3,21 +3,22 @@ // 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, - frag_info.texture_sampler_y_coord_scale); + 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 459742b768f80..a4a33ece00c44 100644 --- a/impeller/entity/shaders/tiled_texture_fill.frag +++ b/impeller/entity/shaders/tiled_texture_fill.frag @@ -3,20 +3,21 @@ // 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..dabcdf780bf54 100644 --- a/impeller/entity/shaders/tiled_texture_fill.vert +++ b/impeller/entity/shaders/tiled_texture_fill.vert @@ -3,6 +3,7 @@ // found in the LICENSE file. #include +#include uniform VertInfo { mat4 mvp; 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 73e416ce5b7ef..db9554fd407db 100644 --- a/impeller/entity/shaders/yuv_to_rgb_filter.frag +++ b/impeller/entity/shaders/yuv_to_rgb_filter.frag @@ -4,37 +4,38 @@ #include #include +#include uniform sampler2D y_texture; 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; + .x; 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); + .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 29b0128258658..27b8ecedbf216 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; }