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

[Impeller] dont use half precision constants / Fixes for SPIRV tools roll #52213

Merged
merged 3 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion impeller/compiler/shader_lib/impeller/constants.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ const float kSqrtThree = 1.73205080757;
// which results in sharper looking images when mip sampling is enabled. This is
// the same constant that Skia uses.
const float kDefaultMipBias = -0.475;
const float kDefaultMipBiasHalf = -0.475hf;

#endif
14 changes: 6 additions & 8 deletions impeller/compiler/shader_lib/impeller/texture.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,20 @@ vec4 IPSampleWithTileMode(sampler2D tex,
return texture(tex, coords, kDefaultMipBias);
}

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,
vec2 coords,
float16_t x_tile_mode,
float16_t y_tile_mode) {
if (x_tile_mode == kTileModeDecalHf && (coords.x < 0.0 || coords.x >= 1.0) ||
y_tile_mode == kTileModeDecalHf && (coords.y < 0.0 || coords.y >= 1.0)) {
float x_tile_mode,
float y_tile_mode) {
if (x_tile_mode == kTileModeDecal && (coords.x < 0.0 || coords.x >= 1.0) ||
y_tile_mode == kTileModeDecal && (coords.y < 0.0 || coords.y >= 1.0)) {
return f16vec4(0.0hf);
}

return texture(tex, coords, kDefaultMipBiasHalf);
return texture(tex, coords, float16_t(kDefaultMipBias));
}

/// Sample a texture, emulating a specific tile mode.
Expand Down Expand Up @@ -137,7 +135,7 @@ f16vec4 IPHalfSampleDecal(f16sampler2D texture_sampler, vec2 coords) {
any(greaterThanEqual(coords, vec2(1)))) {
return f16vec4(0.0);
}
return texture(texture_sampler, coords, kDefaultMipBiasHalf);
return texture(texture_sampler, coords, float16_t(kDefaultMipBias));
}

/// Sample a texture, emulating a specific tile mode.
Expand Down
13 changes: 7 additions & 6 deletions impeller/entity/shaders/filters/morphology_filter.frag
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ layout(constant_id = 0) const float supports_decal = 1.0;

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

uniform f16sampler2D texture_sampler;

uniform FragInfo {
f16vec2 uv_offset;
float16_t radius;
float16_t morph_type;
float morph_type;
float supports_decal_sampler_address_mode;
}
frag_info;
Expand All @@ -30,8 +30,9 @@ in highp vec2 v_texture_coords;
out f16vec4 frag_color;

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

Expand All @@ -42,7 +43,7 @@ void main() {
color = IPHalfSampleDecal(texture_sampler, texture_coords);
}

if (frag_info.morph_type == kMorphTypeDilate) {
if (frag_info.morph_type == /*kMorphTypeDilate*/ 0.0) {
result = max(color, result);
} else {
result = min(color, result);
Expand Down
8 changes: 4 additions & 4 deletions impeller/entity/shaders/filters/yuv_to_rgb_filter.frag
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ uniform f16sampler2D uv_texture;

// These values must correspond to the order of the items in the
// 'YUVColorSpace' enum class.
const float16_t kBT601LimitedRange = 0.0hf;
const float16_t kBT601FullRange = 1.0hf;
// const float kBT601LimitedRange = 0.0;
// const float kBT601FullRange = 1.0;

uniform FragInfo {
mat4 matrix;
float16_t yuv_color_space;
float yuv_color_space;
}
frag_info;

Expand All @@ -29,7 +29,7 @@ out f16vec4 frag_color;
void main() {
f16vec3 yuv;
f16vec3 yuv_offset = f16vec3(0.0hf, 0.5hf, 0.5hf);
if (frag_info.yuv_color_space == kBT601LimitedRange) {
if (frag_info.yuv_color_space == /*kBT601LimitedRange*/ 0.0) {
yuv_offset.x = 16.0hf / 255.0hf;
}

Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/shaders/texture_fill.frag
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ out f16vec4 frag_color;

void main() {
f16vec4 sampled =
texture(texture_sampler, v_texture_coords, kDefaultMipBiasHalf);
texture(texture_sampler, v_texture_coords, float16_t(kDefaultMipBias));
frag_color = sampled * v_alpha;
}
2 changes: 1 addition & 1 deletion impeller/entity/shaders/texture_fill_strict_src.frag
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ void main() {
clamp(v_texture_coords.y, frag_info.source_rect.y,
frag_info.source_rect.w));
f16vec4 sampled =
texture(texture_sampler, texture_coords, kDefaultMipBiasHalf);
texture(texture_sampler, texture_coords, float16_t(kDefaultMipBias));
frag_color = sampled * v_alpha;
}