-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Add a Stage 2 pass to the Vulkan shader compilation pipeline. #40873
Conversation
We just used to use the output of Stage 1 for Vulkan since it was already SPIRV. But that contained debugging information that bloated the size of the SPIRV and the resulting binaries. This reworks the compiler to add a second stage that strips the debug information. While stripping the debug information is effectively what happens, I couldn't find an existing utility in the compiler toolbox that does this. So the source files are processed again for stage 2, but this time without generating the debug information. Just a rudimentary size analysis of the generated SPIRV shows that just gathering all generated shaders in the out directory and applying GZip compression yields a 2.58x size reduction with the total size of all generated shaders being about ~48k. This bring the packaged shader size more in line with the other backends. Results of compression of these shaders in an actual APK may vary. Fixes flutter/flutter#119172 Fixes flutter/flutter#121619
zanderso
left a comment
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.
lgtm w/ optional nit
| spirv_options.SetOptimizationLevel( | ||
| shaderc_optimization_level::shaderc_optimization_level_performance); | ||
| case TargetPlatform::kMetalIOS: { | ||
| SPIRVCompilerTargetEnv target; |
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.
It looks like every switch case declares one of these. If you hoist out the declaration you can avoid the {} in the cases.
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.
May I get this in another patch? The compiler needs some TLC. I'm going to get rid of the unknown platforms with optionals and rework this to explicitly reference Stage1 and Stage2.
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.
Yeah. Still lgtm.
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.
Does "Stage 1" mean source->spirv + reflection, and "Stage 2" mean spirv->target (ideally in Vulkan's case, spirv->optimized spirv)?
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.
Yeah, just the diagram in the readme.
|
|
||
| static void SetDefaultLimitations(shaderc::CompileOptions& compiler_opts) { | ||
| using Limit = std::pair<shaderc_limit, int>; | ||
| static constexpr std::array<Limit, 83> limits = { |
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.
Not sure why only clang on Windows doesn't like this line. Maybe it wants some explicit #include?
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.
Yeah, I moved this to another TU but didn't move the #include<array>.
We just used to use the output of Stage 1 for Vulkan since it was already SPIRV. But that contained debugging information that bloated the size of the SPIRV and the resulting binaries. This reworks the compiler to add a second stage that strips the debug information.
While stripping the debug information is effectively what happens, I couldn't find an existing utility in the compiler toolbox that does this. So the source files are processed again for stage 2, but this time without generating the debug information.
Just a rudimentary size analysis of the generated SPIRV shows that just gathering all generated shaders in the out directory and applying GZip compression yields a 2.58x size reduction with the total size of all generated shaders being about ~48k. This bring the packaged shader size more in line with the other backends. Results of compression of these shaders in an actual APK may vary.
Fixes flutter/flutter#119172

Fixes flutter/flutter#121619