Skip to content

Add build-time checks for ImpellerC's SkSL compiler#180861

Merged
auto-submit[bot] merged 2 commits into
flutter:masterfrom
b-luk:sksl-compiler-checks
Jan 13, 2026
Merged

Add build-time checks for ImpellerC's SkSL compiler#180861
auto-submit[bot] merged 2 commits into
flutter:masterfrom
b-luk:sksl-compiler-checks

Conversation

@b-luk

@b-luk b-luk commented Jan 12, 2026

Copy link
Copy Markdown
Contributor

Adds build-time checks for ImpellerC's SkSL compiler in two places:

  • The CompilerSkSL class in spirv_sksl.cc generates the compiled SkSL from the user's input shader code. It has an existing detect_unsupported_resources method which analyzes the generated ParsedIR to detect various features that SkSL does not support (e.g. UBOs and SSBOs, push constant blocks, and user specified inputs). This PR adds additional checks to detect_unsupported_resources to detect array initialization using array initializers (e.g. float[](1.0, 2.0)), which is not supported by SkSL. This specifically addresses [Impeller] Compiler: GLSL array literals in shaders crash at runtime. #125630.
  • In the main Compiler class in compiler.cc, when compiling to SkSL, validate the compiled SkSL by using it to create a SkRuntimeEffect. Some invalid SkSL cases, like array assignment (float[2] float_array = another_float_array;) are hard to detect from the ParsedIR, so CompilerSkSL does not attempt to detect these invalid cases. The validation added in Compiler will catch all of these cases after SkSL compilation. The error messages produced from this validation are less informative than error messages from CompilerSkSL's checks. It surfaces the error produced by Skia's SkSL parser and outputs the entire generated SkSL file (which can be substantially different from the user's input shader code).

Fixes #125630.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels Jan 12, 2026
@b-luk
b-luk requested a review from gaaclarke January 12, 2026 20:09

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds build-time checks for ImpellerC's SkSL compiler. The changes introduce validation in two key areas: first, by enhancing the CompilerSkSL class to detect unsupported array initializers directly from the ParsedIR, providing precise error messages. Second, it adds a post-compilation validation step in the Compiler class, which uses Skia's SkRuntimeEffect to catch a broader range of SkSL invalidities that are harder to detect from the IR, such as array assignments. The changes are accompanied by a comprehensive set of unit tests that cover both successful and failing compilation scenarios, ensuring the new checks work as expected. The implementation is solid and improves the robustness of the SkSL compilation process.

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The approach is looking good to me. The testing is looking good too. My only hangup is making sure we aren't being over prescriptive, I thought going into this it was only array initializers at file scope that was the problem.

// this.
auto& block = id.get<SPIRBlock>();

// File ane line information for use in the error message.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// File ane line information for use in the error message.
// File and line information for use in the error message.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

// Check for OpStore instructions that store an array constant. This
// detects array initializations which use compile-time constants
// (e.g. `float[2] nums = float[](1.0, 2.0);`).
auto& store_object_id = ir.ids[ir.spirv[instruction.offset + 1]];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

// next OpLine instruction.
file = get<SPIRString>(ir.spirv[instruction.offset]).str;
line = ir.spirv[instruction.offset + 1];
} else if (instruction.op == OpStore) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is the problem limited to arrays at file scope? Will this check catch things in function scope?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This check catches array initialization at both file and function scope.

The problem isn't limited to array at file scope. The array initializer syntax isn't supported at all in SkSL.

Skia's doc for SkSL gives very little information about what syntax is or isn't supported, and no details on what GLSL version SkSL is based upon.

Older versions of GLSL do not support array initializers:

  • The GLSL 1.10 spec in section "4.1.9 Arrays" states: "There is no mechanism for initializing arrays at declaration time from within a shader."
  • The GLSL 1.20 spec in section "4.1.9 Arrays" is updated to show array initializer use.

I don't know what specific version of GLSL was used to base SkSL off of, so it's hard to figure out exactly what syntax is supported. From experimenting at https://shaders.skia.org/, all single-line array initialization gives an error. So I assume SkSL is based on an older GLSL version that does not support any array initializers.


float more_nums[2];
// SkSL does not support array assignment.
more_nums = nums;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same question as above, I thought the problem was just for initializers of uniforms, this is a problem too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

return;
}

if (sl_compiler.GetType() == CompilerBackend::Type::kSkSL) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This isn't technically needed right? This is just a backstop for other issues? This sounds good to me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's a backstop to detect any issues which we don't have explicit checks for in spirv_sksl.cc. The array_assignment.frag test case is one such undetected issue which this backstop catches.

Without this, we have the existing behavior of the invalid SkSL triggering a runtime error when the fragment program is loaded. With this backstop, the invalid SkSL triggers an error at build time instead of runtime.

@b-luk
b-luk requested a review from gaaclarke January 12, 2026 22:58

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm, thanks b-luk!

@b-luk b-luk added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 12, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Jan 13, 2026
Merged via the queue into flutter:master with commit 3dda832 Jan 13, 2026
181 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 13, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 14, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 14, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 14, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 14, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 14, 2026
@b-luk
b-luk deleted the sksl-compiler-checks branch January 14, 2026 22:56
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 15, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 15, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 15, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 15, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Jan 15, 2026
Manual roll requested by [email protected]

flutter/flutter@793b0b8...b45a73b

2026-01-13 [email protected] Roll pub packages (flutter/flutter#180900)
2026-01-13 [email protected] Roll Dart SDK from 34318de9874b to ebaf52c13799 (1 revision) (flutter/flutter#180870)
2026-01-13 [email protected] Make sure that an ErrorWidget doesn't crash in 0x0 environment (flutter/flutter#180830)
2026-01-13 [email protected] Make sure that a Banner doesn't crash in 0x0 environment (flutter/flutter#180254)
2026-01-13 [email protected] Adds metal background to engine dart tests (flutter/flutter#180700)
2026-01-13 [email protected] Add TabBar API example for scroll notification integration (flutter/flutter#180728)
2026-01-13 [email protected] Roll Skia from 714d0af2eda7 to 8f3134206e8d (1 revision) (flutter/flutter#180874)
2026-01-13 [email protected] Add build-time checks for ImpellerC's SkSL compiler (flutter/flutter#180861)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
ikramhasan pushed a commit to ikramhasan/flutter that referenced this pull request Jan 15, 2026
Adds build-time checks for ImpellerC's SkSL compiler in two places:
- The `CompilerSkSL` class in `spirv_sksl.cc` generates the compiled
SkSL from the user's input shader code. It has an existing
`detect_unsupported_resources` method which analyzes the generated
`ParsedIR` to detect various features that SkSL does not support (e.g.
UBOs and SSBOs, push constant blocks, and user specified inputs). This
PR adds additional checks to `detect_unsupported_resources` to detect
array initialization using array initializers (e.g. `float[](1.0,
2.0)`), which is not supported by SkSL. This specifically addresses
flutter#125630.
- In the main `Compiler` class in `compiler.cc`, when compiling to SkSL,
validate the compiled SkSL by using it to create a `SkRuntimeEffect`.
Some invalid SkSL cases, like array assignment (`float[2] float_array =
another_float_array;`) are hard to detect from the `ParsedIR`, so
`CompilerSkSL` does not attempt to detect these invalid cases. The
validation added in `Compiler` will catch all of these cases after SkSL
compilation. The error messages produced from this validation are less
informative than error messages from `CompilerSkSL`'s checks. It
surfaces the error produced by Skia's SkSL parser and outputs the entire
generated SkSL file (which can be substantially different from the
user's input shader code).

Fixes flutter#125630.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
ivan-vanyusho pushed a commit to ivan-vanyusho/packages that referenced this pull request Jan 26, 2026
)

Manual roll requested by [email protected]

flutter/flutter@793b0b8...b45a73b

2026-01-13 [email protected] Roll pub packages (flutter/flutter#180900)
2026-01-13 [email protected] Roll Dart SDK from 34318de9874b to ebaf52c13799 (1 revision) (flutter/flutter#180870)
2026-01-13 [email protected] Make sure that an ErrorWidget doesn't crash in 0x0 environment (flutter/flutter#180830)
2026-01-13 [email protected] Make sure that a Banner doesn't crash in 0x0 environment (flutter/flutter#180254)
2026-01-13 [email protected] Adds metal background to engine dart tests (flutter/flutter#180700)
2026-01-13 [email protected] Add TabBar API example for scroll notification integration (flutter/flutter#180728)
2026-01-13 [email protected] Roll Skia from 714d0af2eda7 to 8f3134206e8d (1 revision) (flutter/flutter#180874)
2026-01-13 [email protected] Add build-time checks for ImpellerC's SkSL compiler (flutter/flutter#180861)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
)

Manual roll requested by [email protected]

flutter/flutter@793b0b8...b45a73b

2026-01-13 [email protected] Roll pub packages (flutter/flutter#180900)
2026-01-13 [email protected] Roll Dart SDK from 34318de9874b to ebaf52c13799 (1 revision) (flutter/flutter#180870)
2026-01-13 [email protected] Make sure that an ErrorWidget doesn't crash in 0x0 environment (flutter/flutter#180830)
2026-01-13 [email protected] Make sure that a Banner doesn't crash in 0x0 environment (flutter/flutter#180254)
2026-01-13 [email protected] Adds metal background to engine dart tests (flutter/flutter#180700)
2026-01-13 [email protected] Add TabBar API example for scroll notification integration (flutter/flutter#180728)
2026-01-13 [email protected] Roll Skia from 714d0af2eda7 to 8f3134206e8d (1 revision) (flutter/flutter#180874)
2026-01-13 [email protected] Add build-time checks for ImpellerC's SkSL compiler (flutter/flutter#180861)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e: impeller Impeller rendering backend issues and features requests engine flutter/engine related. See also e: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Impeller] Compiler: GLSL array literals in shaders crash at runtime.

2 participants