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

Conversation

@chinmaygarde
Copy link
Member

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
Screenshot 2023-04-02 at 4 08 20 PM

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
Copy link
Member

@zanderso zanderso left a 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;
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah. Still lgtm.

Copy link
Member

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)?

Copy link
Member Author

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 = {
Copy link
Member

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?

Copy link
Member Author

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>.

@chinmaygarde chinmaygarde added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 3, 2023
@auto-submit auto-submit bot merged commit b789b19 into flutter:main Apr 3, 2023
@chinmaygarde chinmaygarde deleted the retoolcompiler branch April 3, 2023 00:28
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App e: impeller

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

[Impeller] SPIRV for the Vulkan backend includes debugging information. [Impeller] Add Stage 2 SPRIV transformation for the Vulkan compiler backend.

3 participants