Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 4 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
16 changes: 16 additions & 0 deletions impeller/compiler/compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,22 @@ Compiler::Compiler(const fml::Mapping& source_mapping,
switch (source_options.target_platform) {
case TargetPlatform::kMetalDesktop:
case TargetPlatform::kMetalIOS:
spirv_options.SetOptimizationLevel(
shaderc_optimization_level::shaderc_optimization_level_performance);
if (source_options.use_half_textures) {
spirv_options.SetTargetEnvironment(
shaderc_target_env::shaderc_target_env_opengl,
shaderc_env_version::shaderc_env_version_opengl_4_5);
spirv_options.SetTargetSpirv(
shaderc_spirv_version::shaderc_spirv_version_1_0);
} else {
spirv_options.SetTargetEnvironment(
shaderc_target_env::shaderc_target_env_vulkan,
shaderc_env_version::shaderc_env_version_vulkan_1_1);
spirv_options.SetTargetSpirv(
shaderc_spirv_version::shaderc_spirv_version_1_3);
}
break;
case TargetPlatform::kOpenGLES:
case TargetPlatform::kOpenGLDesktop:
spirv_options.SetOptimizationLevel(
Expand Down
1 change: 1 addition & 0 deletions impeller/compiler/impellerc_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ bool Main(const fml::CommandLine& command_line) {
options.json_format = switches.json_format;
options.gles_language_version = switches.gles_language_version;
options.metal_version = switches.metal_version;
options.use_half_textures = switches.use_half_textures;

Reflector::Options reflector_options;
reflector_options.target_platform = switches.target_platform;
Expand Down
4 changes: 4 additions & 0 deletions impeller/compiler/source_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ struct SourceOptions {
bool json_format = false;
std::string metal_version;

/// @brief Whether half-precision textures should be supported, requiring
/// opengl semantics. Only used on metal targets.
bool use_half_textures = false;

SourceOptions();

~SourceOptions();
Expand Down
7 changes: 4 additions & 3 deletions impeller/compiler/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ void Switches::PrintHelp(std::ostream& stream) {
stream << "[optional] --depfile=<depfile_path>" << std::endl;
stream << "[optional] --gles-language-verision=<number>" << std::endl;
stream << "[optional] --json" << std::endl;
stream << "[optional] --remap-samplers (force metal sampler index to match "
"declared order)"
stream << "[optional] --use-half-textures (force openGL semantics when "
"targeting metal)"
<< std::endl;
}

Expand Down Expand Up @@ -135,7 +135,8 @@ Switches::Switches(const fml::CommandLine& command_line)
metal_version(
command_line.GetOptionValueWithDefault("metal-version", "1.2")),
entry_point(
command_line.GetOptionValueWithDefault("entry-point", "main")) {
command_line.GetOptionValueWithDefault("entry-point", "main")),
use_half_textures(command_line.HasOption("use-half-textures")) {
auto language =
command_line.GetOptionValueWithDefault("source-language", "glsl");
std::transform(language.begin(), language.end(), language.begin(),
Expand Down
1 change: 1 addition & 0 deletions impeller/compiler/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct Switches {
uint32_t gles_language_version;
std::string metal_version;
std::string entry_point;
bool use_half_textures;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default initialize all members. This and (if you are in the mood for drive-by changes) the other members in the struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


Switches();

Expand Down
27 changes: 26 additions & 1 deletion impeller/tools/impeller.gni
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ template("impellerc") {
args += [ "--metal-version=$metal_version" ]
}

if (defined(invoker.use_half_textures) && invoker.use_half_textures) {
args += [ "--use-half-textures" ]
}

if (json) {
args += [ "--json" ]
}
Expand Down Expand Up @@ -403,6 +407,11 @@ template("_impeller_shaders_metal") {
metal_version = invoker.metal_version
}

use_half_textures = false
if (defined(invoker.use_half_textures) && invoker.use_half_textures) {
use_half_textures = invoker.use_half_textures
}

shaders_base_name = string_join("",
[
invoker.name,
Expand All @@ -413,6 +422,7 @@ template("_impeller_shaders_metal") {
shaders = invoker.shaders
metal_version = metal_version
sl_file_extension = "metal"
use_half_textures = use_half_textures
shader_target_flag = ""
defines = [ "IMPELLER_TARGET_METAL" ]
if (is_ios) {
Expand Down Expand Up @@ -666,12 +676,26 @@ template("_impeller_shaders_vk") {
#
# The SPIR-V version required by the shaders.
#
# @param[options] use_half_textures
#
# Whether the metal shader is using half-precision textures and requires
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be the default for Metal? Or is this because it interferes with the other features like framebuffer fetch? Perhaps we can detect that instead of tuning flags? Not sure. I bet this is fine too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It interferes with framebuffer fetch specifically. I think there is a way to make that work but I haven't found it yet. I was planning to handle this as a follow up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's not really a great way to detect it automatically, since we only really get the chance to inspect the shader after its in a SPIR-V ast and at that point the validation that rejects the f16sampler2d has already run.

# openGL semantics when compilig SPIR-V.
#
template("impeller_shaders") {
metal_version = "1.2"
if (defined(invoker.metal_version)) {
metal_version = invoker.metal_version
}
not_needed([ "metal_version" ])

use_half_textures = false
if (defined(invoker.use_half_textures) && invoker.use_half_textures) {
use_half_textures = true
}

not_needed([
"metal_version",
"use_half_textures",
])

enable_opengles = impeller_enable_opengles
if (defined(invoker.enable_opengles)) {
Expand All @@ -685,6 +709,7 @@ template("impeller_shaders") {
name = invoker.name
shaders = invoker.shaders
metal_version = metal_version
use_half_textures = use_half_textures
}
}

Expand Down