[Impeller] migrate texture fill shaders to half precision. (flutter/engine#40735)
[Impeller] migrate texture fill shaders to half precision.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#define TEXTURE_GLSL_
|
||||
|
||||
#include <impeller/branching.glsl>
|
||||
#include <impeller/types.glsl>
|
||||
|
||||
/// Sample from a texture.
|
||||
///
|
||||
@@ -92,6 +93,26 @@ vec4 IPSampleWithTileMode(sampler2D tex,
|
||||
return texture(tex, coords);
|
||||
}
|
||||
|
||||
const float16_t kTileModeDecalHf = 3.0hf;
|
||||
|
||||
/// Sample a texture, emulating a specific tile mode.
|
||||
///
|
||||
/// This is useful for Impeller graphics backend that don't have native support
|
||||
/// for Decal.
|
||||
f16vec4 IPHalfSampleWithTileMode(f16sampler2D tex,
|
||||
f16vec2 coords,
|
||||
float16_t x_tile_mode,
|
||||
float16_t y_tile_mode) {
|
||||
if (x_tile_mode == kTileModeDecalHf &&
|
||||
(coords.x < 0.0hf || coords.x >= 1.0hf) ||
|
||||
y_tile_mode == kTileModeDecalHf &&
|
||||
(coords.y < 0.0hf || coords.y >= 1.0hf)) {
|
||||
return f16vec4(0.0hf);
|
||||
}
|
||||
|
||||
return texture(tex, coords);
|
||||
}
|
||||
|
||||
/// Sample a texture, emulating a specific tile mode.
|
||||
///
|
||||
/// This is useful for Impeller graphics backend that don't have native support
|
||||
|
||||
@@ -11,6 +11,8 @@ impeller_shaders("entity_shaders") {
|
||||
vulkan_language_version = 130
|
||||
}
|
||||
|
||||
use_half_textures = true
|
||||
|
||||
shaders = [
|
||||
"shaders/blending/advanced_blend.vert",
|
||||
"shaders/blending/advanced_blend_color.frag",
|
||||
|
||||
@@ -4,18 +4,18 @@
|
||||
|
||||
#include <impeller/types.glsl>
|
||||
|
||||
uniform sampler2D texture_sampler;
|
||||
uniform f16sampler2D texture_sampler;
|
||||
|
||||
uniform FragInfo {
|
||||
float alpha;
|
||||
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() {
|
||||
vec4 sampled = texture(texture_sampler, v_texture_coords);
|
||||
f16vec4 sampled = texture(texture_sampler, v_texture_coords);
|
||||
frag_color = sampled * frag_info.alpha;
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ frame_info;
|
||||
in vec2 position;
|
||||
in vec2 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);
|
||||
v_texture_coords =
|
||||
IPRemapCoords(texture_coords, frame_info.texture_sampler_y_coord_scale);
|
||||
v_texture_coords = f16vec2(
|
||||
IPRemapCoords(texture_coords, frame_info.texture_sampler_y_coord_scale));
|
||||
}
|
||||
|
||||
@@ -5,24 +5,25 @@
|
||||
#include <impeller/texture.glsl>
|
||||
#include <impeller/types.glsl>
|
||||
|
||||
uniform sampler2D texture_sampler;
|
||||
uniform f16sampler2D texture_sampler;
|
||||
|
||||
uniform FragInfo {
|
||||
float x_tile_mode;
|
||||
float y_tile_mode;
|
||||
float alpha;
|
||||
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 = IPSampleWithTileMode(texture_sampler, // sampler
|
||||
v_texture_coords, // texture coordinates
|
||||
frag_info.x_tile_mode, // x tile mode
|
||||
frag_info.y_tile_mode // y tile mode
|
||||
) *
|
||||
frag_info.alpha;
|
||||
frag_color =
|
||||
IPHalfSampleWithTileMode(texture_sampler, // sampler
|
||||
v_texture_coords, // texture coordinates
|
||||
frag_info.x_tile_mode, // x tile mode
|
||||
frag_info.y_tile_mode // y tile mode
|
||||
) *
|
||||
frag_info.alpha;
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ frame_info;
|
||||
in vec2 position;
|
||||
in vec2 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);
|
||||
v_texture_coords =
|
||||
IPRemapCoords(texture_coords, frame_info.texture_sampler_y_coord_scale);
|
||||
v_texture_coords = f16vec2(
|
||||
IPRemapCoords(texture_coords, frame_info.texture_sampler_y_coord_scale));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user