Commit 3109939
authored
Don't compile shaders to SkSL unless --sksl arg is present (#182519)
The main change of this PR is to make `impellerc_main` no longer use
`TargetPlatformBundlesSkSL(switches.SelectDefaultTargetPlatform())` to
determine whether to compile to SkSL.
Addresses the "sksl unexpectedly compiling when building for ios"
mentioned in #182400.
`TargetPlatformBundlesSkSL()` returned `true` when running impellerc
targeting *any* runtime shaders. So even though
https://github.com/flutter/flutter/pull/163144/changes changed iOS
runtime shaders to no longer call impellerc with the `--sksl` runtime
target, it would still compile to SkSL because of the
`--runtime-stage-metal` runtime target.
After this PR, impellerc will only compile to SkSL if `--sksl` is
explicitly provided when calling impellerc.
The rest of the changes in this PR are related changes to improve code
organization and to update tests.
- `impellerc_main.cc`:
- `OutputIPLR()`: Remove the custom logic for compiling to SkSL. SkSL is
now treated the same as all the other compile targets in the `for (const
auto& platform : switches.PlatformsToCompile())` loop. This is the only
change with a behavioral difference in the PR. We no longer use
`TargetPlatformBundlesSkSL(switches.SelectDefaultTargetPlatform())` to
determine whether to compile to SkSL. Instead, it's treated the same as
any other compilation target and will only be targeted when it is
specified as an arg to the executable.
- Remove the `CompileSkSL()` helper function. This had the exact same
logic as what is used for all the other compilation targets in the `for
(const auto& platform : switches.PlatformsToCompile())` loop. So it is
not needed.
- `OutputDepfile()`: Remove the switch/case. The
`TargetPlatform::kUnknown` case is unreachable, so this used the other
case 100% of the time.
- `Main()`: `switches.CreateSourceOptions()` no longer has a default
platform target parameter. It doesn't matter which target it's called
with here. Arbitrarily call it with
`switches.PlatformsToCompile().front()`.
- `types.h/cc`:
- Remove the `TargetPlatformBundlesSkSL()` function. The only place this
was used was for `impellerc_main.cc`'s special case logic for SkSL,
which was removed as described above.
- `switches.h/cc`:
- Remove the optional/default parameter for `CreateSourceOptions()`.
This used to fall back to calling `SelectDefaultTargetPlatform()` to
determine the default value. I found this to be very unclear behavior.
The only place this was actually called with the default parameter is in
one function in `shader_bundle.cc` where the selected target platform
does not actually matter, so it doesn't even need this
somewhat-convoluted logic to select a platform with
`SelectDefaultTargetPlatform()`. I changed `CreateSourceOptions()` to
require an explicit parameter, which I think makes the function's
behavior clearer by removing the confusing default parameter.
- Remove the `SelectDefaultTargetPlatform()` function. I think it was a
little unclear/nonobvious what this was actually returning. It was only
used in 3 places, all of which were kind of confusing/unneeded:
1. In this same file, to pick the default target platform in
`switches.CreateSourceOptions()`. As described above, this seems
entirely unnecessary.
1. In `impeller_main.cc`, used in
`TargetPlatformBundlesSkSL(switches.SelectDefaultTargetPlatform())` to
determine whether to compile to SkSL. As described above, we don't want
this behavior. I think it was also kind of confusing.
1. In `impeller_main.cc`, used for the switch/case in `OutputDepfile()`.
As described above, this switch/case is entirely unnecessary.
- Change the `kKnownRuntimeStages` map to be a vector of pairs. This is
iterated through to populate the returned `runtime_stages_` list of
`Switches::PlatformsToCompile()`. Making it a vector makes the
`runtime_stages_` list maintain the ordering of `kKnownRuntimeStages`
(previously, iterating through the map would iterate in alphabetical
order of the keys).
- `impellerc_main.cc`'s `OutputIPLR()` now compiles to targets based on
`Switches::PlatformsToCompile()`, without special case logic to always
compile to "sksl" first. Changing this to a vector with "sksl" as the
first value preserves the original behavior of compiling to "sksl"
before any other targets. We do this because certain tests that perform
a failed shader compilation check specifically for an SkSL-based error
message (e.g. [this
one](https://github.com/flutter/flutter/blob/64866862f623ceeb45fd8be4782e8db8b58910c0/packages/flutter_tools/test/integration.shard/shader_compiler_test.dart#L150-L170)).
So for these tests, we need to try/fail with the SkSL compiler first,
before trying/failing with other compilers which would produce a
different error message.
- `shader_bundle.cc`
- As described above, change the usage of
`switches.CreateSourceOptions()` to require an explicit target platform
parameter. This particular usage doesn't matter, so use
`TargetPlatform::kUnknown` and add an explanatory comment.
- `compiler.cc`
- In `CreateCompiler()`, Add an `FML_UNREACHABLE` for the
`TargetPlatform::kUnknown` case, instead of falling back to using a
vulkan compiler. It doesn't make sense to call `CreateCompiler()` with
`TargetPlatform::kUnknown`. And currently, it can't happen: The only use
of `CreateCompiler()` is in the `Compiler` constructor on [line
432](https://github.com/flutter/flutter/blob/24ce716cfddfef201027c1a5fa2299a8aeffb03e/engine/src/flutter/impeller/compiler/compiler.cc#L432),
and there is a check preventing `TargetPlatform::kUnknown` earlier on
[line
292](https://github.com/flutter/flutter/blob/24ce716cfddfef201027c1a5fa2299a8aeffb03e/engine/src/flutter/impeller/compiler/compiler.cc#L292).
- `compiler_unittests.cc`, `compiler_test.h`
- The
`INSTANTIATE_{TARGET|RUNTIME_TARGET|SKSL_TARGET}_PLATFORM_TEST_SUITE_P`
defines were oddly located in the file in the middle of the tests. Move
them to the top of the file.
- `INSTANTIATE_TARGET_PLATFORM_TEST_SUITE_P`
- Remove the `kSkSL` target. These tests seem to be specifically for
non-runtime targets, so SkSL doesn't belong here. All of these tests had
a filter to skip for SkSL, so none of them actually ran for SkSL. These
skips are now removed.
- Add the `kVulkan` target, so all non-runtime platform targets are
covered: opengles, openglesdesktop, metaldesktop, metalios, vulkan.
- `INSTANTIATE_RUNTIME_TARGET_PLATFORM_TEST_SUITE_P`
- This used to only test with `kRuntimeStageMetal`. For better coverage,
I added all other runtime stages to this. It now tests on the metal,
gles, gles3, vulkan, and sksl runtime targets.
- Two tests, `UniformsAppearInJson` and `PositionedUniformsAppearInJson`
fail when running with vulkan and with sksl. I added skips for these. I
haven't dug deeper, but the failures seem unexpected to me. It's
possible that this is revealing a bug with the vulkan and sksl
compilers.
- `INSTANTIATE_UNKNOWN_TARGET_PLATFORM_TEST_SUITE_P`
- Added this new define for running tests with
`TargetPlatform::kUnknown`.
- Added a `MustFailDueToUnknownPlatform` test for this case.
- `fixtures/BUILD.gn`, `runtime_stage_unittests.cc`
- For the `impellerc("runtime_stages")` build target, add `--sksl` to
the impellerc flags. This preserves the existing behavior of these
targets being compiled for SkSL. They used to compile for SkSL because
other runtime targets are specified. But now impellerc only compiles to
SkSL when `--sksl` is explicitly specified.
- Create a new `impellerc("runtime_stages_non_sksl")` target that runs
impellerc without `--sksl`. Use this for a new
`ContainsExpectedShaderTypesNoSksl` test in the unit test file. That
test is the same as the existing `ContainsExpectedShaderTypes` test, but
using the non-sksl output from `impellerc("runtime_stages_non_sksl")`.
### Update for commit 2 of the PR:
The original PR had an issue that failed CI because a build rule
expected an impellerc output to include C++ reflection data, but the
reflection data was not output. I added a sizable commit to address
this:
- Fix compiler.gni logic around when to generate reflection state.
- This used to incorrectly generate reflection state whenever the last
shader_target_flags is not "--sksl".
- Instead, generate reflection state when any non-runtime target is in
shader_target_flags.
- Consolidate some of the if/else logic to reduce duplicate code.
- Remove the TargetPlatformNeedsReflection check in impeller_main.cc.
- Instead, whether reflection state is generated depends only on the
presence or absense of "reflection_{json|header|cc}_name" flags.
- The logic of whether to include these flags is already in
compiler.gni. So it's redundant to also have logic for whether to
generate the reflection state here.
- The TargetPlatformNeedsReflection method had faulty logic.
- It returned true for everything except SkSL, even though reflection
state isn't needed for runtime targets.
- It was called on the target from
Switches::SelectDefaultTargetPlatform. When impellerc is used with
multiple runtime targets, this would return the runtime target that is
first alphabetically by flag name. So if --sksl is provided along with
any other --runtime-stage-* target, SelectDefaultTargetPlatform returns
the non-sksl runtime target. Effectively this meant that
TargetPlatformNeedsReflection returns true except for when --sksl is the
only provided runtime target.
- Removes the TargetPlatformNeedsReflection function entirely.
## 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.md1 parent f38a3e0 commit 3109939
14 files changed
Lines changed: 239 additions & 296 deletions
File tree
- engine/src/flutter/impeller
- compiler
- fixtures
- runtime_stage
- tools
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
245 | | - | |
246 | 245 | | |
247 | 246 | | |
248 | 247 | | |
| |||
251 | 250 | | |
252 | 251 | | |
253 | 252 | | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
254 | 256 | | |
255 | 257 | | |
256 | 258 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
192 | 189 | | |
193 | 190 | | |
194 | 191 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | | - | |
| 52 | + | |
51 | 53 | | |
52 | 54 | | |
53 | 55 | | |
| |||
Lines changed: 61 additions & 47 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
18 | 58 | | |
19 | 59 | | |
20 | 60 | | |
| |||
48 | 88 | | |
49 | 89 | | |
50 | 90 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | 91 | | |
55 | 92 | | |
56 | 93 | | |
57 | 94 | | |
58 | 95 | | |
59 | 96 | | |
60 | 97 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | 98 | | |
65 | 99 | | |
66 | 100 | | |
67 | 101 | | |
68 | 102 | | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | 103 | | |
73 | 104 | | |
74 | 105 | | |
| |||
87 | 118 | | |
88 | 119 | | |
89 | 120 | | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | 121 | | |
94 | 122 | | |
95 | 123 | | |
96 | 124 | | |
97 | 125 | | |
98 | 126 | | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | 127 | | |
103 | 128 | | |
104 | 129 | | |
| |||
202 | 227 | | |
203 | 228 | | |
204 | 229 | | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
205 | 236 | | |
206 | 237 | | |
207 | 238 | | |
| |||
248 | 279 | | |
249 | 280 | | |
250 | 281 | | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
251 | 288 | | |
252 | 289 | | |
253 | 290 | | |
| |||
377 | 414 | | |
378 | 415 | | |
379 | 416 | | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | 417 | | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
413 | 422 | | |
414 | 423 | | |
415 | 424 | | |
| |||
448 | 457 | | |
449 | 458 | | |
450 | 459 | | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
451 | 465 | | |
452 | 466 | | |
453 | 467 | | |
0 commit comments