Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
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
4 changes: 2 additions & 2 deletions impeller/compiler/shader_lib/impeller/texture.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ f16vec4 IPHalfSampleWithTileMode(f16sampler2D tex,
return f16vec4(0.0hf);
}

return texture(tex, coords, kDefaultMipBiasHalf);
return f16vec4(texture(tex, coords, kDefaultMipBiasHalf));
}

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

/// Sample a texture, emulating a specific tile mode.
Expand Down
73 changes: 71 additions & 2 deletions impeller/compiler/shader_lib/impeller/types.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,95 @@

#extension GL_AMD_gpu_shader_half_float : enable
#extension GL_AMD_gpu_shader_half_float_fetch : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int8 : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int16 : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int32 : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int64 : enable
#extension GL_EXT_shader_explicit_arithmetic_types_float16 : enable
#extension GL_EXT_shader_explicit_arithmetic_types_float32 : enable
#extension GL_EXT_shader_explicit_arithmetic_types_float64 : enable

#ifdef IMPELLER_TARGET_OPENGLES
#define IMPELLER_MAYBE_FLAT
#else
#define IMPELLER_MAYBE_FLAT flat
#endif

#ifndef IMPELLER_TARGET_METAL_IOS
#if defined(IMPELLER_TARGET_OPENGLES) || defined(IMPELLER_TARGET_MOLTENVK)

// OpenGLES 2 targets GLSL ES 1.0, which doesn't support explicit arithmetic
// types on individual declarations. So for GLES, we provide macros for 16 bit
// types to keep writing cross API shaders easy.
//
// By default, OpenGLES sets the floating point precision to `highp` for vertex
// shaders and `mediump` for fragment shaders. Fragment shader samplers are set
// to `lowp` by default. Individual shaders may explicitly declare the
// precision for all declarations in the shader.
//
// For example:
// precision mediump sampler2D;
// precision mediump float;

precision mediump sampler2D;

#define float16_t float
#define float32_t float
#define float64_t float

#define f16vec2 vec2
#define f32vec2 vec2
#define f64vec2 vec2

#define f16vec3 vec3
#define f32vec3 vec3
#define f64vec3 vec3

#define f16vec4 vec4
#define f32vec4 vec4
#define f64vec4 vec4

#define f16mat4 mat4
#define f32mat4 mat4
#define f64mat4 mat4

#define f16sampler2D sampler2D
#define f32sampler2D sampler2D
#define f64sampler2D sampler2D

#define uint8_t uint
#define uint16_t uint
#define uint32_t uint
#define uint64_t uint

#define u8vec2 vec2
#define u16vec2 vec2
#define u32vec2 vec2
#define u64vec2 vec2

#define u8vec3 vec3
#define u16vec3 vec3
#define u32vec3 vec3
#define u64vec3 vec3

#endif // IMPELLER_TARGET_METAL
#define u8vec4 vec4
#define u16vec4 vec4
#define u32vec4 vec4
#define u64vec4 vec4

#define u8mat4 mat4
#define u16mat4 mat4
#define u32mat4 mat4
#define u64mat4 mat4

#elif defined(IMPELLER_TARGET_VULKAN)

precision mediump sampler2D;

// Vulkan does not support 16 bit floating point samplers.
// https://registry.khronos.org/vulkan/specs/1.1-extensions/html/vkspec.html#VUID-StandaloneSpirv-OpTypeImage-04656
#define f16sampler2D sampler2D

#endif

#define BoolF float
#define BoolV2 vec2
Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/shaders/blending/advanced_blend.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ out f16vec4 frag_color;
f16vec4 Sample(f16sampler2D texture_sampler, vec2 texture_coords) {
// gles 2.0 is the only backend without native decal support.
#ifdef IMPELLER_TARGET_OPENGLES
return IPSampleDecal(texture_sampler, texture_coords);
return IPHalfSampleDecal(texture_sampler, texture_coords);
#else
return texture(texture_sampler, texture_coords);
return f16vec4(texture(texture_sampler, texture_coords));
#endif
}

Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/shaders/blending/blend.frag
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ in vec2 v_texture_coords;
out f16vec4 frag_color;

void main() {
frag_color =
texture(texture_sampler_src, v_texture_coords) * frag_info.input_alpha;
frag_color = f16vec4(texture(texture_sampler_src, v_texture_coords)) *
frag_info.input_alpha;
}
8 changes: 4 additions & 4 deletions impeller/entity/shaders/blending/porter_duff_blend.frag
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ out f16vec4 frag_color;
f16vec4 Sample(f16sampler2D texture_sampler, vec2 texture_coords) {
// gles 2.0 is the only backend without native decal support.
#ifdef IMPELLER_TARGET_OPENGLES
return IPSampleDecal(texture_sampler, texture_coords);
return IPHalfSampleDecal(texture_sampler, texture_coords);
#else
return texture(texture_sampler, texture_coords);
return f16vec4(texture(texture_sampler, texture_coords));
#endif
}

void main() {
f16vec4 dst =
texture(texture_sampler_dst, v_texture_coords) * frag_info.input_alpha;
f16vec4 dst = f16vec4(texture(texture_sampler_dst, v_texture_coords)) *
frag_info.input_alpha;
f16vec4 src = frag_info.color;
frag_color =
src * (frag_info.src_coeff + dst.a * frag_info.src_coeff_dst_alpha) +
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/shaders/border_mask_blur.frag
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ float16_t BoxBlurMask(f16vec2 uv) {
}

void main() {
f16vec4 image_color = texture(texture_sampler, v_texture_coords);
f16vec4 image_color = f16vec4(texture(texture_sampler, v_texture_coords));
float16_t blur_factor = BoxBlurMask(f16vec2(v_texture_coords));

float16_t within_bounds =
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/shaders/color_matrix_color_filter.frag
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ out f16vec4 frag_color;

void main() {
f16vec4 input_color =
texture(input_texture, v_texture_coords) * frag_info.input_alpha;
f16vec4(texture(input_texture, v_texture_coords)) * frag_info.input_alpha;

// unpremultiply first, as filter inputs are premultiplied.
f16vec4 color = IPHalfUnpremultiply(input_color);
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/shaders/gaussian_blur/gaussian_blur.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ f16vec4 Sample(f16sampler2D tex, vec2 coords) {
#if ENABLE_DECAL_SPECIALIZATION
return IPHalfSampleDecal(tex, coords);
#else
return texture(tex, coords);
return f16vec4(texture(tex, coords));
#endif
}

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

void main() {
f16vec4 value = texture(glyph_atlas_sampler, v_uv);
f16vec4 value = f16vec4(texture(glyph_atlas_sampler, v_uv));
frag_color = value.aaaa * v_text_color;
}
2 changes: 1 addition & 1 deletion impeller/entity/shaders/glyph_atlas_color.frag
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ IMPELLER_MAYBE_FLAT in f16vec4 v_text_color;
out f16vec4 frag_color;

void main() {
f16vec4 value = texture(glyph_atlas_sampler, v_uv);
f16vec4 value = f16vec4(texture(glyph_atlas_sampler, v_uv));
frag_color = value * v_text_color.aaaa;
}
2 changes: 1 addition & 1 deletion impeller/entity/shaders/linear_to_srgb_filter.frag
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ out f16vec4 frag_color;

void main() {
f16vec4 input_color =
texture(input_texture, v_texture_coords) * frag_info.input_alpha;
f16vec4(texture(input_texture, v_texture_coords)) * frag_info.input_alpha;

f16vec4 color = IPHalfUnpremultiply(input_color);
for (int i = 0; i < 3; i++) {
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/shaders/morphology_filter.frag
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void main() {
#ifdef IMPELLER_TARGET_OPENGLES
f16vec4 color = IPHalfSampleDecal(texture_sampler, texture_coords);
#else
f16vec4 color = texture(texture_sampler, texture_coords);
f16vec4 color = f16vec4(texture(texture_sampler, texture_coords));
#endif

if (frag_info.morph_type == kMorphTypeDilate) {
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/shaders/srgb_to_linear_filter.frag
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ out f16vec4 frag_color;

void main() {
f16vec4 input_color =
texture(input_texture, v_texture_coords) * frag_info.input_alpha;
f16vec4(texture(input_texture, v_texture_coords)) * frag_info.input_alpha;

f16vec4 color = IPHalfUnpremultiply(input_color);
for (int i = 0; i < 3; i++) {
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);
f16vec4(texture(texture_sampler, v_texture_coords, kDefaultMipBiasHalf));
frag_color = sampled * v_alpha;
}
4 changes: 2 additions & 2 deletions impeller/entity/shaders/yuv_to_rgb_filter.frag
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void main() {
yuv_offset.x = 16.0hf / 255.0hf;
}

yuv.x = texture(y_texture, v_texture_coords).r;
yuv.yz = texture(uv_texture, v_texture_coords).rg;
yuv.x = float16_t(texture(y_texture, v_texture_coords).r);
yuv.yz = f16vec2(texture(uv_texture, v_texture_coords).rg);
frag_color = f16mat4(frag_info.matrix) * f16vec4(yuv - yuv_offset, 1.0hf);
}
8 changes: 4 additions & 4 deletions impeller/geometry/half.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "impeller/geometry/scalar.h"
#include "impeller/geometry/vector.h"

#ifdef FML_OS_WIN
#if defined(FML_OS_WIN)
using InternalHalf = uint16_t;
#else
using InternalHalf = _Float16;
Expand All @@ -24,10 +24,10 @@ namespace impeller {
/// @brief Convert a scalar to a half precision float.
///
/// See also: https://clang.llvm.org/docs/LanguageExtensions.html
/// This is not currently supported on Windows toolchains.
/// This is not currently supported on Windows on some Android toolchains.
inline constexpr InternalHalf ScalarToHalf(Scalar f) {
#ifdef FML_OS_WIN
return static_cast<InternalHalf>(0);
#if defined(FML_OS_WIN)
return static_cast<InternalHalf>(f);
#else
return static_cast<InternalHalf>(f);
#endif
Expand Down
8 changes: 8 additions & 0 deletions impeller/renderer/backend/vulkan/capabilities_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ CapabilitiesVK::GetEnabledInstanceExtensions() const {
}
}

// Vulkan 1.1 core extensions for 16 bit buffer access.
if (!HasExtension("VK_KHR_get_physical_device_properties2")) {
VALIDATION_LOG << "Instance does not support the "
"VK_KHR_get_physical_device_properties2 extension.";
return std::nullopt;
}
required.push_back("VK_KHR_get_physical_device_properties2");

return required;
}

Expand Down
5 changes: 4 additions & 1 deletion impeller/renderer/backend/vulkan/test/mock_vulkan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ VkResult vkEnumerateInstanceExtensionProperties(
uint32_t* pPropertyCount,
VkExtensionProperties* pProperties) {
if (!pProperties) {
*pPropertyCount = 2;
*pPropertyCount = 3;

} else {
strcpy(pProperties[0].extensionName, "VK_KHR_surface");
pProperties[0].specVersion = 0;
strcpy(pProperties[1].extensionName, "VK_MVK_macos_surface");
pProperties[1].specVersion = 0;
strcpy(pProperties[2].extensionName,
"VK_KHR_get_physical_device_properties2");
pProperties[2].specVersion = 0;
}
return VK_SUCCESS;
}
Expand Down
6 changes: 6 additions & 0 deletions impeller/tools/impeller.gni
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,12 @@ template("_impeller_shaders_vk") {
shader_target_flag = "--vulkan"

defines = [ "IMPELLER_TARGET_VULKAN" ]

# If we're compiling on a macOS host, then we're targeting MoltenVK which
# has additional constraints.
if (is_mac) {
defines += [ "IMPELLER_TARGET_MOLTENVK" ]
}
}

vk_shaders =
Expand Down