-
Notifications
You must be signed in to change notification settings - Fork 6k
[Flutter GPU] Runtime shader import. #48875
Changes from 1 commit
2e2cd70
ea36c73
e3f8cbf
f8e4703
91cfa25
cf61483
5243eff
7f45044
35614d4
34e063a
fea9317
d639c2a
fe51086
b475d35
0f12626
1da673e
98f3cf5
ce7ee8d
e57b927
c9176dc
cd5ba50
ce28f95
2146d31
9e3fccc
1919922
d7ef71d
be1078c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -242,18 +242,35 @@ template("embed_blob") { | |
| # the impeller_use_prebuilt_impellerc argument. Forwards all variables to | ||
| # compiled_action_foreach or action_foreach as appropriate. | ||
| template("_impellerc") { | ||
| if (impeller_use_prebuilt_impellerc == "") { | ||
| compiled_action_foreach(target_name) { | ||
| forward_variables_from(invoker, "*") | ||
| tool = "//flutter/impeller/compiler:impellerc" | ||
| if (invoker.single_invocation) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please document the template parameter in the comment on the template.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| 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 { | ||
| 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 | ||
| 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 | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -262,8 +279,13 @@ template("impellerc") { | |
| assert(defined(invoker.shaders), "Impeller shaders must be specified.") | ||
| assert(defined(invoker.shader_target_flag), | ||
| "The flag to impellerc for target selection must be specified.") | ||
| assert(defined(invoker.sl_file_extension), | ||
| 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_output_bundle must also be specified.") | ||
| } | ||
|
|
||
| sksl = invoker.shader_target_flag == "--sksl" | ||
| iplr = false | ||
|
|
@@ -279,17 +301,26 @@ template("impellerc") { | |
| not_needed([ | ||
| "iplr", | ||
| "sksl", | ||
| "shader_bundle", | ||
| "shader_bundle_output", | ||
| ]) | ||
|
|
||
| # Optional: invoker.iplr Causes --sl output to be in iplr format. | ||
| # Optional: invoker.iplr_bundle specifies a Flutter GPU shader bundle configuration. | ||
| # Optional: invoker.shader_bundle specifies a Flutter GPU shader bundle configuration. | ||
|
||
| # Optional: invoker.shader_bundle_output specifies the output filename of the shader | ||
| # bundle. This is required if invoker.shader_bundle is supplied. | ||
| # Optional: invoker.defines specifies a list of valueless macro definitions. | ||
| # Optional: invoker.intermediates_subdir specifies the subdirectory in which | ||
| # to put intermediates. | ||
| # Optional: invoker.json Causes output format to be JSON instead of flatbuffer. | ||
|
|
||
| _impellerc(target_name) { | ||
| sources = invoker.shaders | ||
| 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" | ||
|
|
@@ -299,22 +330,25 @@ template("impellerc") { | |
|
|
||
| shader_target_flag = invoker.shader_target_flag | ||
|
|
||
| spirv_intermediate = "$generated_dir/{{source_file_part}}.spirv" | ||
| spirv_intermediate_path = rebase_path(spirv_intermediate, root_build_dir) | ||
|
|
||
| depfile_path = "$generated_dir/{{source_file_part}}.d" | ||
| depfile_intermediate_path = rebase_path(depfile_path, root_build_dir) | ||
| depfile = depfile_path | ||
|
|
||
| shader_lib_dir = rebase_path("//flutter/impeller/compiler/shader_lib") | ||
| args = [ | ||
| "--input={{source}}", | ||
| "--include={{source_dir}}", | ||
| "--include=$shader_lib_dir", | ||
| "--depfile=$depfile_intermediate_path", | ||
| "$shader_target_flag", | ||
| ] | ||
|
|
||
| # When we're in single invocation mode, we can't use source enumeration. | ||
| if (!single_invocation) { | ||
| args += [ | ||
| "--input={{source}}", | ||
| "--include={{source_dir}}", | ||
| ] | ||
| } | ||
|
|
||
| if (defined(invoker.gles_language_version)) { | ||
| gles_language_version = invoker.gles_language_version | ||
| args += [ "--gles-language-version=$gles_language_version" ] | ||
|
|
@@ -338,27 +372,60 @@ template("impellerc") { | |
| args += [ "--json" ] | ||
| } | ||
|
|
||
| if (sksl) { | ||
| sl_intermediate = | ||
| 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 the `shader_target_flag`, 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_intermediate_path = rebase_path(sl_intermediate, root_build_dir) | ||
| 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_intermediate_path", | ||
| "--sl=$sl_output_path", | ||
| "--spirv=$spirv_intermediate_path", | ||
| ] | ||
| if (iplr) { | ||
| args += [ "--iplr" ] | ||
| } | ||
|
|
||
| outputs = [ sl_intermediate ] | ||
| outputs = [ sl_output ] | ||
| } else { | ||
| sl_intermediate = | ||
| # 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" | ||
|
|
||
| sl_intermediate_path = rebase_path(sl_intermediate, root_build_dir) | ||
| 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 = | ||
|
|
@@ -367,21 +434,15 @@ template("impellerc") { | |
| rebase_path(reflection_cc_intermediate, root_build_dir) | ||
|
|
||
| args += [ | ||
| "--sl=$sl_intermediate_path", | ||
| "--sl=$sl_output_path", | ||
| "--spirv=$spirv_intermediate_path", | ||
| "--reflection-json=$reflection_json_path", | ||
| "--reflection-header=$reflection_header_path", | ||
| "--reflection-cc=$reflection_cc_path", | ||
| ] | ||
| if (iplr) { | ||
| args += [ "--iplr" ] | ||
| } | ||
| if (defined(invoker.iplr_bundle)) { | ||
| args += [ "--iplr-bundle=${invoker.iplr_bundle}" ] | ||
| } | ||
|
|
||
| outputs = [ | ||
| sl_intermediate, | ||
| sl_output, | ||
| reflection_header_intermediate, | ||
| reflection_cc_intermediate, | ||
| ] | ||
|
|
@@ -392,6 +453,12 @@ template("impellerc") { | |
| args += [ "--define=$def" ] | ||
| } | ||
| } | ||
|
|
||
| if (single_invocation) { | ||
| inputs = invoker.shaders | ||
| } else { | ||
| sources = invoker.shaders | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any thoughts about reading the json spec in from a file instead of the flag itself being json-valued? I wonder which will be easier for tools that wrap/call
impellerc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My hunch is that storing it in a file before invoking is more of a pain given the ephemeral nature. Although it would be slightly more convenient for the many of manual invocations I've been doing over the past couple of days. : )