Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 442d14a

Browse files
[Impeller] dont use half precision constants / Fixes for SPIRV tools roll (#52213)
See b/335381180 In an upcoming version of SPIRV tools, these constants are being flagged as invalid. Due to some combination of the macros + inlining we're ending up with multiple precision modifiers on the constants: ``` third_party/flutter_engine/impeller/entity/shaders/radial_gradient_fill.frag: GLSL to SPIRV failed; Compilation error. 0 error(s) and 1 warning(s). third_party/flutter_engine/impeller/entity/shaders/radial_gradient_fill.frag:14: warning: '' : all default precisions are highp; use precision statements to quiet warning, e.g.: third_party/flutter_engine/impeller/entity/shaders/radial_gradient_fill.frag: "precision mediump int; precision highp float;" shaderc: internal error: compilation succeeded but failed to optimize: ID '112' decorated with RelaxedPrecision multiple times is not allowed. %float_n0_474999994 = OpConstant %float -0.474999994 ``` We don't really benefit from half precision on these, since we're either using them for equality or can cheaply convert to half precision anyway.
1 parent 046207c commit 442d14a

File tree

6 files changed

+19
-21
lines changed

6 files changed

+19
-21
lines changed

impeller/compiler/shader_lib/impeller/constants.glsl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,5 @@ const float kSqrtThree = 1.73205080757;
2929
// which results in sharper looking images when mip sampling is enabled. This is
3030
// the same constant that Skia uses.
3131
const float kDefaultMipBias = -0.475;
32-
const float kDefaultMipBiasHalf = -0.475hf;
3332

3433
#endif

impeller/compiler/shader_lib/impeller/texture.glsl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,20 @@ vec4 IPSampleWithTileMode(sampler2D tex,
8282
return texture(tex, coords, kDefaultMipBias);
8383
}
8484

85-
const float16_t kTileModeDecalHf = 3.0hf;
86-
8785
/// Sample a texture, emulating a specific tile mode.
8886
///
8987
/// This is useful for Impeller graphics backend that don't have native support
9088
/// for Decal.
9189
f16vec4 IPHalfSampleWithTileMode(f16sampler2D tex,
9290
vec2 coords,
93-
float16_t x_tile_mode,
94-
float16_t y_tile_mode) {
95-
if (x_tile_mode == kTileModeDecalHf && (coords.x < 0.0 || coords.x >= 1.0) ||
96-
y_tile_mode == kTileModeDecalHf && (coords.y < 0.0 || coords.y >= 1.0)) {
91+
float x_tile_mode,
92+
float y_tile_mode) {
93+
if (x_tile_mode == kTileModeDecal && (coords.x < 0.0 || coords.x >= 1.0) ||
94+
y_tile_mode == kTileModeDecal && (coords.y < 0.0 || coords.y >= 1.0)) {
9795
return f16vec4(0.0hf);
9896
}
9997

100-
return texture(tex, coords, kDefaultMipBiasHalf);
98+
return texture(tex, coords, float16_t(kDefaultMipBias));
10199
}
102100

103101
/// Sample a texture, emulating a specific tile mode.
@@ -137,7 +135,7 @@ f16vec4 IPHalfSampleDecal(f16sampler2D texture_sampler, vec2 coords) {
137135
any(greaterThanEqual(coords, vec2(1)))) {
138136
return f16vec4(0.0);
139137
}
140-
return texture(texture_sampler, coords, kDefaultMipBiasHalf);
138+
return texture(texture_sampler, coords, float16_t(kDefaultMipBias));
141139
}
142140

143141
/// Sample a texture, emulating a specific tile mode.

impeller/entity/shaders/filters/morphology_filter.frag

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ layout(constant_id = 0) const float supports_decal = 1.0;
1212

1313
// These values must correspond to the order of the items in the
1414
// 'FilterContents::MorphType' enum class.
15-
const float16_t kMorphTypeDilate = 0.0hf;
16-
const float16_t kMorphTypeErode = 1.0hf;
15+
// const float kMorphTypeDilate = 0.0;
16+
// const float kMorphTypeErode = 1.0;
1717

1818
uniform f16sampler2D texture_sampler;
1919

2020
uniform FragInfo {
2121
f16vec2 uv_offset;
2222
float16_t radius;
23-
float16_t morph_type;
23+
float morph_type;
2424
float supports_decal_sampler_address_mode;
2525
}
2626
frag_info;
@@ -30,8 +30,9 @@ in highp vec2 v_texture_coords;
3030
out f16vec4 frag_color;
3131

3232
void main() {
33-
f16vec4 result =
34-
frag_info.morph_type == kMorphTypeDilate ? f16vec4(0.0) : f16vec4(1.0);
33+
f16vec4 result = frag_info.morph_type == /*kMorphTypeDilate*/ 0.0
34+
? f16vec4(0.0)
35+
: f16vec4(1.0);
3536
for (float16_t i = -frag_info.radius; i <= frag_info.radius; i++) {
3637
vec2 texture_coords = v_texture_coords + frag_info.uv_offset * i;
3738

@@ -42,7 +43,7 @@ void main() {
4243
color = IPHalfSampleDecal(texture_sampler, texture_coords);
4344
}
4445

45-
if (frag_info.morph_type == kMorphTypeDilate) {
46+
if (frag_info.morph_type == /*kMorphTypeDilate*/ 0.0) {
4647
result = max(color, result);
4748
} else {
4849
result = min(color, result);

impeller/entity/shaders/filters/yuv_to_rgb_filter.frag

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ uniform f16sampler2D uv_texture;
1313

1414
// These values must correspond to the order of the items in the
1515
// 'YUVColorSpace' enum class.
16-
const float16_t kBT601LimitedRange = 0.0hf;
17-
const float16_t kBT601FullRange = 1.0hf;
16+
// const float kBT601LimitedRange = 0.0;
17+
// const float kBT601FullRange = 1.0;
1818

1919
uniform FragInfo {
2020
mat4 matrix;
21-
float16_t yuv_color_space;
21+
float yuv_color_space;
2222
}
2323
frag_info;
2424

@@ -29,7 +29,7 @@ out f16vec4 frag_color;
2929
void main() {
3030
f16vec3 yuv;
3131
f16vec3 yuv_offset = f16vec3(0.0hf, 0.5hf, 0.5hf);
32-
if (frag_info.yuv_color_space == kBT601LimitedRange) {
32+
if (frag_info.yuv_color_space == /*kBT601LimitedRange*/ 0.0) {
3333
yuv_offset.x = 16.0hf / 255.0hf;
3434
}
3535

impeller/entity/shaders/texture_fill.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ out f16vec4 frag_color;
1616

1717
void main() {
1818
f16vec4 sampled =
19-
texture(texture_sampler, v_texture_coords, kDefaultMipBiasHalf);
19+
texture(texture_sampler, v_texture_coords, float16_t(kDefaultMipBias));
2020
frag_color = sampled * v_alpha;
2121
}

impeller/entity/shaders/texture_fill_strict_src.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ void main() {
2525
clamp(v_texture_coords.y, frag_info.source_rect.y,
2626
frag_info.source_rect.w));
2727
f16vec4 sampled =
28-
texture(texture_sampler, texture_coords, kDefaultMipBiasHalf);
28+
texture(texture_sampler, texture_coords, float16_t(kDefaultMipBias));
2929
frag_color = sampled * v_alpha;
3030
}

0 commit comments

Comments
 (0)