|
| 1 | +# Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | +# Use of this source code is governed by a BSD-style license that can be |
| 3 | +# found in the LICENSE file. |
| 4 | + |
| 5 | +import("//build/compiled_action.gni") |
| 6 | +import("//flutter/common/config.gni") |
| 7 | +import("//flutter/testing/testing.gni") |
| 8 | + |
| 9 | +declare_args() { |
| 10 | + # Path to the Mali offline compiler tool 'malioc'. |
| 11 | + impeller_malioc_path = "" |
| 12 | + |
| 13 | + impeller_malioc_cores = [] |
| 14 | +} |
| 15 | + |
| 16 | +if (impeller_malioc_path != "" && impeller_malioc_cores == []) { |
| 17 | + core_list_file = "$root_gen_dir/mali_core_list.json" |
| 18 | + exec_script("//build/gn_run_binary.py", |
| 19 | + [ |
| 20 | + rebase_path(impeller_malioc_path, root_build_dir), |
| 21 | + "--list", |
| 22 | + "--format", |
| 23 | + "json", |
| 24 | + "--output", |
| 25 | + rebase_path(core_list_file), |
| 26 | + ]) |
| 27 | + _mali_cores = read_file(core_list_file, "json") |
| 28 | + foreach(mali_core, _mali_cores.cores) { |
| 29 | + impeller_malioc_cores += [ mali_core.core ] |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +template("malioc_analyze_shaders") { |
| 34 | + # TODO(zra): Check that gles_language_version is in the supported set. For now |
| 35 | + # assume that if it is set, it is being set to 460, which malioc does not |
| 36 | + # support. |
| 37 | + if (impeller_malioc_path == "" || defined(invoker.gles_language_version)) { |
| 38 | + if (defined(invoker.gles_language_version) && |
| 39 | + invoker.gles_language_version != "460") { |
| 40 | + print("Disabling analysis for shaders in $target_name due to gles", |
| 41 | + "version explicitly set to ${invoker.gles_language_version}.") |
| 42 | + } |
| 43 | + group(target_name) { |
| 44 | + not_needed(invoker, "*") |
| 45 | + } |
| 46 | + } else { |
| 47 | + target_deps = [] |
| 48 | + foreach(core, impeller_malioc_cores) { |
| 49 | + foreach(source, invoker.shaders) { |
| 50 | + shader_file_name = get_path_info(source, "name") |
| 51 | + analysis_target = "${target_name}_${shader_file_name}_${core}_malioc" |
| 52 | + target_deps += [ ":$analysis_target" ] |
| 53 | + action(analysis_target) { |
| 54 | + forward_variables_from(invoker, |
| 55 | + "*", |
| 56 | + [ |
| 57 | + "args", |
| 58 | + "depfile", |
| 59 | + "inputs", |
| 60 | + "outputs", |
| 61 | + "pool", |
| 62 | + "script", |
| 63 | + ]) |
| 64 | + |
| 65 | + script = "//build/gn_run_binary.py" |
| 66 | + pool = "//flutter/impeller/tools:malioc_pool" |
| 67 | + |
| 68 | + # Should be "gles" or "vkspv" |
| 69 | + backend_ext = get_path_info(source, "extension") |
| 70 | + assert(backend_ext == "gles", |
| 71 | + "Shader for unsupported backend passed to malioc: {{source}}") |
| 72 | + |
| 73 | + # Nest all malioc output under its own subdirectory of root_gen_dir |
| 74 | + # so that it's easier to diff it against the state before any changes. |
| 75 | + subdir = rebase_path(target_gen_dir, root_gen_dir) |
| 76 | + output_file = |
| 77 | + "$root_gen_dir/malioc/$subdir/${shader_file_name}.$core.json" |
| 78 | + outputs = [ output_file ] |
| 79 | + |
| 80 | + # Determine the kind of the shader from the file name |
| 81 | + name = get_path_info(source, "name") |
| 82 | + shader_kind_ext = get_path_info(name, "extension") |
| 83 | + |
| 84 | + if (shader_kind_ext == "comp") { |
| 85 | + shader_kind_flag = "--compute" |
| 86 | + } else if (shader_kind_ext == "frag") { |
| 87 | + shader_kind_flag = "--fragment" |
| 88 | + } else if (shader_kind_ext == "geom") { |
| 89 | + shader_kind_flag = "--geometry" |
| 90 | + } else if (shader_kind_ext == "tesc") { |
| 91 | + shader_kind_flag = "--tessellation_control" |
| 92 | + } else if (shader_kind_ext == "tese") { |
| 93 | + shader_kind_flag = "--tessellation_evaluation" |
| 94 | + } else if (shader_kind_ext == "vert") { |
| 95 | + shader_kind_flag = "--vertex" |
| 96 | + } else { |
| 97 | + assert(false, "Unknown shader kind: {{source}}") |
| 98 | + } |
| 99 | + |
| 100 | + args = [ |
| 101 | + rebase_path(impeller_malioc_path, root_build_dir), |
| 102 | + "--format", |
| 103 | + "json", |
| 104 | + shader_kind_flag, |
| 105 | + "--core", |
| 106 | + core, |
| 107 | + "--output", |
| 108 | + rebase_path(output_file), |
| 109 | + ] |
| 110 | + |
| 111 | + if (backend_ext == "vkspv") { |
| 112 | + args += [ "--vulkan" ] |
| 113 | + } |
| 114 | + |
| 115 | + args += [ rebase_path(source) ] |
| 116 | + } |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + group(target_name) { |
| 121 | + deps = target_deps |
| 122 | + } |
| 123 | + } |
| 124 | +} |
0 commit comments