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

[Impeller] Refactor impeller.gni #52942

Merged
merged 1 commit into from
May 21, 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
2 changes: 1 addition & 1 deletion ci/licenses_golden/excluded_files
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@
../../../flutter/impeller/tessellator/tessellator_unittests.cc
../../../flutter/impeller/toolkit/android/README.md
../../../flutter/impeller/toolkit/android/toolkit_android_unittests.cc
../../../flutter/impeller/tools/build_metal_library.py
../../../flutter/impeller/tools/check_licenses.py
../../../flutter/impeller/tools/malioc_cores.py
../../../flutter/impeller/tools/malioc_diff.py
../../../flutter/impeller/tools/metal_library.py
../../../flutter/impeller/tools/xxd.py
../../../flutter/impeller/typographer/typographer_unittests.cc
../../../flutter/lib/gpu/analysis_options.yaml
Expand Down
62 changes: 62 additions & 0 deletions impeller/tools/args.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//flutter/common/config.gni")
import("//flutter/testing/testing.gni")

declare_args() {
impeller_debug =
flutter_runtime_mode == "debug" || flutter_runtime_mode == "profile"

# Whether the runtime capture/playback system is enabled.
impeller_capture = flutter_runtime_mode == "debug"
Copy link
Member

Choose a reason for hiding this comment

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

This is unused post #52932


# Whether the Metal backend is enabled.
impeller_enable_metal = (is_mac || is_ios) && target_os != "fuchsia"

# Whether the OpenGLES backend is enabled.
impeller_enable_opengles = (is_linux || is_win || is_android || is_mac ||
enable_unittests) && target_os != "fuchsia"

# Whether the Vulkan backend is enabled.
impeller_enable_vulkan = (is_linux || is_win || is_android || is_mac ||
enable_unittests) && target_os != "fuchsia"

# Whether to use a prebuilt impellerc.
# If this is the empty string, impellerc will be built.
# If it is non-empty, it should be the absolute path to impellerc.
impeller_use_prebuilt_impellerc = ""
Copy link
Member

Choose a reason for hiding this comment

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

This option is no longer being used since migrating to the engine_v2 recipes. Using it in the engine_v2 recipes would be difficult. If you're up for it, it can be safely deleted.

Copy link
Member Author

@chinmaygarde chinmaygarde May 21, 2024

Choose a reason for hiding this comment

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

Wilco in a followup. Is this also the case for impeller_use_prebuilt_scenec?


# Whether to use a prebuilt scenec.
# If this is the empty string, scenec will be built.
# If it is non-empty, it should be the absolute path to scenec.
impeller_use_prebuilt_scenec = ""

# If enabled, all OpenGL calls will be traced. Because additional trace
# overhead may be substantial, this is not enabled by default.
impeller_trace_all_gl_calls = false

# Enable experimental 3D scene rendering.
impeller_enable_3d = false

# Enable to get trace statements for canvas usage.
impeller_trace_canvas = false
Copy link
Member

Choose a reason for hiding this comment

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

This is unused.

}

# Arguments that are combinations of other arguments by default but which can
# be overridden by the user.

declare_args() {
# Wether to build and include the validation layers.
impeller_enable_vulkan_validation_layers =
impeller_enable_vulkan && flutter_runtime_mode == "debug" &&
target_cpu == "arm64"

# Whether Impeller supports rendering on the platform.
impeller_supports_rendering =
impeller_enable_metal || impeller_enable_opengles ||
impeller_enable_vulkan

impeller_enable_compute = impeller_enable_vulkan || impeller_enable_metal
}
291 changes: 291 additions & 0 deletions impeller/tools/compiler.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/compiled_action.gni")
import("//flutter/impeller/tools/args.gni")

# Dispatches to the build or prebuilt impellerc depending on the value of
# the `impeller_use_prebuilt_impellerc` argument.
# * When the `single_invocation` argument is false, all variables are
# forwarded to `compiled_action_foreach` or `action_foreach`, which will
# invoke `impellerc` separately for each source.
# * When the `single_invocation` argument is true, `impellerc` is only
# invoked once via `compiled_action` or `action`.
template("_impellerc") {
if (invoker.single_invocation) {
if (impeller_use_prebuilt_impellerc == "") {
compiled_action(target_name) {
forward_variables_from(invoker, "*")
tool = "//flutter/impeller/compiler:impellerc"
}
} else {
action(target_name) {
forward_variables_from(invoker, "*", [ "args" ])
script = "//build/gn_run_binary.py"
impellerc_path =
rebase_path(impeller_use_prebuilt_impellerc, root_build_dir)
args = [ impellerc_path ] + invoker.args
}
}
} else {
if (impeller_use_prebuilt_impellerc == "") {
compiled_action_foreach(target_name) {
forward_variables_from(invoker, "*")
tool = "//flutter/impeller/compiler:impellerc"
}
} else {
action_foreach(target_name) {
forward_variables_from(invoker, "*", [ "args" ])
script = "//build/gn_run_binary.py"
impellerc_path =
rebase_path(impeller_use_prebuilt_impellerc, root_build_dir)
args = [ impellerc_path ] + invoker.args
}
}
}
}

# Required: shaders The list of shaders inputs to compile.
# Required: shader_target_flags The target flag(s) to append. Valid options:
# --sksl
# --metal-ios
# --metal-desktop
# --opengl-es
# --opengl-desktop
# --vulkan
# --runtime-stage-metal
# --runtime-stage-gles
# --runtime-stage-vulkan
# Not required for --shader_bundle mode.
# Required: sl_file_extension The file extension to use for output files.
# Not required for --shader_bundle mode.
# Optional: iplr Causes --sl output to be in iplr/runtime
# stage flatbuffer format.
# Optional: shader_bundle Specifies a Flutter GPU shader bundle
# configuration.
# Required: shader_bundle_output Specifies the output filename of the shader
# bundle. This is only required if
# shader_bundle is supplied.
# Optional: defines Specifies a list of valueless macro
# definitions.
# Optional: intermediates_subdir Specifies the subdirectory in which to put
# intermediates.
# Optional: json Causes output format to be JSON instead of
# flatbuffer.
template("impellerc") {
assert(defined(invoker.shaders), "Impeller shaders must be specified.")
assert(defined(invoker.shader_target_flags) || defined(invoker.shader_bundle),
"The flag to impellerc for target selection must be specified.")
assert(defined(invoker.sl_file_extension) || defined(invoker.shader_bundle),
"The extension of the SL file must be specified (metal, glsl, etc..).")
if (defined(invoker.shader_bundle)) {
assert(
defined(invoker.shader_bundle_output),
"When shader_bundle is specified, shader_bundle_output must also be specified.")
}

if (defined(invoker.shader_target_flags)) {
shader_target_flags = invoker.shader_target_flags
} else {
shader_target_flags = []
}

sksl = false
foreach(shader_target_flag, shader_target_flags) {
sksl = shader_target_flag == "--sksl"
}
iplr = false
if (defined(invoker.iplr) && invoker.iplr) {
iplr = invoker.iplr
}
json = false
if (defined(invoker.json) && invoker.json) {
json = invoker.json
}

# Not needed on every path.
not_needed([
"iplr",
"sksl",
"shader_bundle",
"shader_bundle_output",
])

_impellerc(target_name) {
pool = "//build/toolchain:toolchain_pool"
shader_bundle = defined(invoker.shader_bundle)

# When single_invocation is true, impellerc will be invoked exactly once. When it's
# false, impellerc be invoked for each of the source file entries (invoker.shaders).
single_invocation = shader_bundle

if (defined(invoker.intermediates_subdir)) {
subdir = invoker.intermediates_subdir
generated_dir = "$target_gen_dir/$subdir"
} else {
generated_dir = "$target_gen_dir"
}

shader_lib_dir = rebase_path("//flutter/impeller/compiler/shader_lib")
args = [ "--include=$shader_lib_dir" ] + shader_target_flags

# When we're in single invocation mode, we can't use source enumeration.
if (!single_invocation) {
depfile_path = "$generated_dir/{{source_file_part}}.d"
depfile_intermediate_path = rebase_path(depfile_path, root_build_dir)
depfile = depfile_path
args += [
"--input={{source}}",
"--include={{source_dir}}",
"--depfile=$depfile_intermediate_path",
]

if (defined(invoker.shader_target_flag)) {
args += [ "${invoker.shader_target_flag}" ]
}
}

if (defined(invoker.gles_language_version)) {
gles_language_version = invoker.gles_language_version
args += [ "--gles-language-version=$gles_language_version" ]
}

if (defined(invoker.metal_version)) {
assert(is_mac || is_ios)
metal_version = invoker.metal_version
args += [ "--metal-version=$metal_version" ]
}

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

if (json) {
args += [ "--json" ]
}

if (iplr) {
# When building in IPLR mode, the compiler may be executed twice
args += [ "--iplr" ]
}

# The `sl_output` is the raw shader file output by the compiler. For --iplr
# and --shader-bundle, this is used as the filename for the flatbuffer to
# output.

if (shader_bundle) {
# When a shader bundle is specified, don't bother supplying flags for
# the reflection state as these are ignored. In this mode, the compiler
# is invoked multiple times and the reflection state for each shader is
# written to the output flatbuffer.
sl_output = "$generated_dir/${invoker.shader_bundle_output}"
sl_output_path = rebase_path(sl_output, root_build_dir)

args += [
"--sl=$sl_output_path",
"--shader-bundle=${invoker.shader_bundle}",
]

outputs = [ sl_output ]
} else if (sksl) {
# When SkSL is selected as a `shader_target_flags`, don't generate
# C++ reflection state. Nothing needs to use it and it's likely invalid
# given the special cases when generating SkSL.
# Note that this configuration is orthogonal to the "--iplr" flag
sl_output =
"$generated_dir/{{source_file_part}}.${invoker.sl_file_extension}"
sl_output_path = rebase_path(sl_output, root_build_dir)

spirv_intermediate = "$generated_dir/{{source_file_part}}.spirv"
spirv_intermediate_path = rebase_path(spirv_intermediate, root_build_dir)
args += [
"--sl=$sl_output_path",
"--spirv=$spirv_intermediate_path",
]

outputs = [ sl_output ]
} else {
# The default branch. Here we just generate one shader along with all of
# its C++ reflection state.

sl_output =
"$generated_dir/{{source_file_part}}.${invoker.sl_file_extension}"
sl_output_path = rebase_path(sl_output, root_build_dir)

reflection_json_intermediate = "$generated_dir/{{source_file_part}}.json"
reflection_header_intermediate = "$generated_dir/{{source_file_part}}.h"
reflection_cc_intermediate = "$generated_dir/{{source_file_part}}.cc"

spirv_intermediate = "$generated_dir/{{source_file_part}}.spirv"
spirv_intermediate_path = rebase_path(spirv_intermediate, root_build_dir)
reflection_json_path =
rebase_path(reflection_json_intermediate, root_build_dir)
reflection_header_path =
rebase_path(reflection_header_intermediate, root_build_dir)
reflection_cc_path =
rebase_path(reflection_cc_intermediate, root_build_dir)

args += [
"--sl=$sl_output_path",
"--spirv=$spirv_intermediate_path",
"--reflection-json=$reflection_json_path",
"--reflection-header=$reflection_header_path",
"--reflection-cc=$reflection_cc_path",
]

outputs = [
sl_output,
reflection_header_intermediate,
reflection_cc_intermediate,
]
}

if (defined(invoker.defines)) {
foreach(def, invoker.defines) {
args += [ "--define=$def" ]
}
}

if (single_invocation) {
inputs = invoker.shaders
} else {
sources = invoker.shaders
}
}
}

template("impellerc_reflect") {
assert(
defined(invoker.impellerc_invocation),
"The target that specifies the ImpellerC invocation to reflect must be defined.")

reflect_config = "reflect_$target_name"
config(reflect_config) {
include_dirs = [ get_path_info(
get_label_info("//flutter/impeller:impeller", "target_gen_dir"),
"dir") ]
}

impellerc_invocation = invoker.impellerc_invocation

source_set(target_name) {
public_configs = [ ":$reflect_config" ]
public = filter_include(get_target_outputs(impellerc_invocation), [ "*.h" ])
sources = filter_include(get_target_outputs(impellerc_invocation),
[
"*.h",
"*.cc",
"*.mm",
])

deps = [
"//flutter/impeller/core",
impellerc_invocation,
]
}
}
Loading