Skip to content

Commit c417c46

Browse files
authored
Refactor ShaderTarget to not explicitly mention impeller or Skia (#141460)
Refactors `ShaderTarget` to make it opaque as to whether it's using Impeller or SkSL and instead has it focus on the target platform it's generating for. ImpellerC includes SkSL right now whether you ask for it or not. The tester target also might need SkSL or Vulkan depending on whether `--enable-impeller` is passed.
1 parent ceab0e0 commit c417c46

23 files changed

+164
-140
lines changed

packages/flutter_tools/lib/src/build_system/targets/android.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import '../exceptions.dart';
1515
import 'assets.dart';
1616
import 'common.dart';
1717
import 'icon_tree_shaker.dart';
18-
import 'shader_compiler.dart';
1918

2019
/// Prepares the asset bundle in the format expected by flutter.gradle.
2120
///
@@ -68,7 +67,6 @@ abstract class AndroidAssetBundle extends Target {
6867
outputDirectory,
6968
targetPlatform: TargetPlatform.android,
7069
buildMode: buildMode,
71-
shaderTarget: ShaderTarget.impellerAndroid,
7270
flavor: environment.defines[kFlavor],
7371
);
7472
environment.depFileService.writeToFile(

packages/flutter_tools/lib/src/build_system/targets/assets.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ Future<Depfile> copyAssets(
3232
Map<String, DevFSContent> additionalContent = const <String, DevFSContent>{},
3333
required TargetPlatform targetPlatform,
3434
BuildMode? buildMode,
35-
required ShaderTarget shaderTarget,
3635
List<File> additionalInputs = const <File>[],
3736
String? flavor,
3837
}) async {
@@ -140,8 +139,7 @@ Future<Depfile> copyAssets(
140139
doCopy = !await shaderCompiler.compileShader(
141140
input: content.file as File,
142141
outputPath: file.path,
143-
target: shaderTarget,
144-
json: targetPlatform == TargetPlatform.web_javascript,
142+
targetPlatform: targetPlatform,
145143
);
146144
case AssetKind.model:
147145
doCopy = !await sceneImporter.importScene(
@@ -328,7 +326,6 @@ class CopyAssets extends Target {
328326
environment,
329327
output,
330328
targetPlatform: TargetPlatform.android,
331-
shaderTarget: ShaderTarget.sksl,
332329
flavor: environment.defines[kFlavor],
333330
);
334331
environment.depFileService.writeToFile(

packages/flutter_tools/lib/src/build_system/targets/common.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ class CopyFlutterBundle extends Target {
7979
environment.outputDir,
8080
targetPlatform: TargetPlatform.android,
8181
buildMode: buildMode,
82-
shaderTarget: ShaderTarget.sksl,
8382
flavor: flavor,
8483
);
8584
environment.depFileService.writeToFile(

packages/flutter_tools/lib/src/build_system/targets/ios.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,6 @@ abstract class IosAssetBundle extends Target {
503503
environment,
504504
assetDirectory,
505505
targetPlatform: TargetPlatform.ios,
506-
// Always specify an impeller shader target so that we support runtime toggling and
507-
// the --enable-impeller debug flag.
508-
shaderTarget: ShaderTarget.impelleriOS,
509506
additionalInputs: <File>[
510507
flutterProject.ios.infoPlist,
511508
flutterProject.ios.appFrameworkInfoPlist,

packages/flutter_tools/lib/src/build_system/targets/linux.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import 'assets.dart';
1515
import 'common.dart';
1616
import 'desktop.dart';
1717
import 'icon_tree_shaker.dart';
18-
import 'shader_compiler.dart';
1918

2019
/// The only files/subdirectories we care out.
2120
const List<String> _kLinuxArtifacts = <String>[
@@ -141,7 +140,6 @@ abstract class BundleLinuxAssets extends Target {
141140
additionalContent: <String, DevFSContent>{
142141
'version.json': DevFSStringContent(versionInfo),
143142
},
144-
shaderTarget: ShaderTarget.sksl,
145143
);
146144
environment.depFileService.writeToFile(
147145
depfile,

packages/flutter_tools/lib/src/build_system/targets/macos.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import '../exceptions.dart';
1818
import 'assets.dart';
1919
import 'common.dart';
2020
import 'icon_tree_shaker.dart';
21-
import 'shader_compiler.dart';
2221

2322
/// Copy the macOS framework to the correct copy dir by invoking 'rsync'.
2423
///
@@ -439,7 +438,6 @@ abstract class MacOSBundleFlutterAssets extends Target {
439438
environment,
440439
assetDirectory,
441440
targetPlatform: TargetPlatform.darwin,
442-
shaderTarget: ShaderTarget.sksl,
443441
flavor: environment.defines[kFlavor],
444442
);
445443
environment.depFileService.writeToFile(

packages/flutter_tools/lib/src/build_system/targets/shader_compiler.dart

Lines changed: 37 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,8 @@ import '../../base/logger.dart';
1717
import '../../build_info.dart';
1818
import '../../convert.dart';
1919
import '../../devfs.dart';
20-
import '../../device.dart';
2120
import '../build_system.dart';
2221

23-
/// The output shader format that should be used by the [ShaderCompiler].
24-
enum ShaderTarget {
25-
impellerAndroid(<String>['--runtime-stage-gles', '--runtime-stage-vulkan']),
26-
impelleriOS(<String>['--runtime-stage-metal']),
27-
impellerSwiftShader(<String>['--runtime-stage-vulkan']),
28-
sksl(<String>['--sksl']);
29-
30-
const ShaderTarget(this.stages);
31-
32-
final List<String> stages;
33-
}
34-
3522
/// A wrapper around [ShaderCompiler] to support hot reload of shader sources.
3623
class DevelopmentShaderCompiler {
3724
DevelopmentShaderCompiler({
@@ -47,42 +34,16 @@ class DevelopmentShaderCompiler {
4734
final Pool _compilationPool = Pool(4);
4835
final math.Random _random;
4936

50-
late ShaderTarget _shaderTarget;
37+
late TargetPlatform _targetPlatform;
5138
bool _debugConfigured = false;
52-
bool _jsonMode = false;
5339

5440
/// Configure the output format of the shader compiler for a particular
5541
/// flutter device.
56-
void configureCompiler(TargetPlatform? platform, { required ImpellerStatus impellerStatus }) {
57-
switch (platform) {
58-
case TargetPlatform.ios:
59-
_shaderTarget = ShaderTarget.impelleriOS;
60-
case TargetPlatform.android_arm64:
61-
case TargetPlatform.android_x64:
62-
case TargetPlatform.android_x86:
63-
case TargetPlatform.android_arm:
64-
case TargetPlatform.android:
65-
_shaderTarget = impellerStatus == ImpellerStatus.enabled
66-
? ShaderTarget.impellerAndroid
67-
: ShaderTarget.sksl;
68-
case TargetPlatform.darwin:
69-
case TargetPlatform.linux_x64:
70-
case TargetPlatform.linux_arm64:
71-
case TargetPlatform.windows_x64:
72-
case TargetPlatform.windows_arm64:
73-
case TargetPlatform.fuchsia_arm64:
74-
case TargetPlatform.fuchsia_x64:
75-
case TargetPlatform.tester:
76-
_shaderTarget = impellerStatus == ImpellerStatus.enabled
77-
? ShaderTarget.impellerSwiftShader
78-
: ShaderTarget.sksl;
79-
case TargetPlatform.web_javascript:
80-
assert(impellerStatus != ImpellerStatus.enabled);
81-
_shaderTarget = ShaderTarget.sksl;
82-
_jsonMode = true;
83-
case null:
84-
return;
42+
void configureCompiler(TargetPlatform? platform) {
43+
if (platform == null) {
44+
return;
8545
}
46+
_targetPlatform = platform;
8647
_debugConfigured = true;
8748
}
8849

@@ -107,9 +68,8 @@ class DevelopmentShaderCompiler {
10768
final bool success = await _shaderCompiler.compileShader(
10869
input: inputFile,
10970
outputPath: output.path,
110-
target: _shaderTarget,
71+
targetPlatform: _targetPlatform,
11172
fatal: false,
112-
json: _jsonMode,
11373
);
11474
if (!success) {
11575
return null;
@@ -144,6 +104,34 @@ class ShaderCompiler {
144104
final FileSystem _fs;
145105
final Artifacts _artifacts;
146106

107+
List<String> _shaderTargetsFromTargetPlatform(TargetPlatform targetPlatform) {
108+
switch (targetPlatform) {
109+
case TargetPlatform.android_x64:
110+
case TargetPlatform.android_x86:
111+
case TargetPlatform.android_arm:
112+
case TargetPlatform.android_arm64:
113+
case TargetPlatform.android:
114+
case TargetPlatform.linux_x64:
115+
case TargetPlatform.linux_arm64:
116+
case TargetPlatform.windows_x64:
117+
case TargetPlatform.windows_arm64:
118+
return <String>['--sksl', '--runtime-stage-gles', '--runtime-stage-vulkan'];
119+
120+
case TargetPlatform.ios:
121+
case TargetPlatform.darwin:
122+
return <String>['--sksl', '--runtime-stage-metal'];
123+
124+
case TargetPlatform.fuchsia_arm64:
125+
case TargetPlatform.fuchsia_x64:
126+
case TargetPlatform.tester:
127+
return <String>['--sksl', '--runtime-stage-vulkan'];
128+
129+
case TargetPlatform.web_javascript:
130+
return <String>['--sksl'];
131+
132+
}
133+
}
134+
147135
/// The [Source] inputs that targets using this should depend on.
148136
///
149137
/// See [Target.inputs].
@@ -163,9 +151,8 @@ class ShaderCompiler {
163151
Future<bool> compileShader({
164152
required File input,
165153
required String outputPath,
166-
required ShaderTarget target,
154+
required TargetPlatform targetPlatform,
167155
bool fatal = true,
168-
required bool json,
169156
}) async {
170157
final File impellerc = _fs.file(
171158
_artifacts.getHostArtifact(HostArtifact.impellerc),
@@ -180,9 +167,9 @@ class ShaderCompiler {
180167
final String shaderLibPath = _fs.path.join(impellerc.parent.absolute.path, 'shader_lib');
181168
final List<String> cmd = <String>[
182169
impellerc.path,
183-
...target.stages,
170+
..._shaderTargetsFromTargetPlatform(targetPlatform),
184171
'--iplr',
185-
if (json)
172+
if (targetPlatform == TargetPlatform.web_javascript)
186173
'--json',
187174
'--sl=$outputPath',
188175
'--spirv=$outputPath.spirv',

packages/flutter_tools/lib/src/build_system/targets/web.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import '../depfile.dart';
2828
import '../exceptions.dart';
2929
import 'assets.dart';
3030
import 'localizations.dart';
31-
import 'shader_compiler.dart';
3231

3332
/// Whether the application has web plugins.
3433
const String kHasWebPlugins = 'HasWebPlugins';
@@ -395,7 +394,6 @@ class WebReleaseBundle extends Target {
395394
environment,
396395
environment.outputDir.childDirectory('assets'),
397396
targetPlatform: TargetPlatform.web_javascript,
398-
shaderTarget: ShaderTarget.sksl,
399397
);
400398
final DepfileService depfileService = environment.depFileService;
401399
depfileService.writeToFile(

packages/flutter_tools/lib/src/build_system/targets/windows.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import 'assets.dart';
1212
import 'common.dart';
1313
import 'desktop.dart';
1414
import 'icon_tree_shaker.dart';
15-
import 'shader_compiler.dart';
1615

1716
/// The only files/subdirectories we care about.
1817
const List<String> _kWindowsArtifacts = <String>[
@@ -143,7 +142,6 @@ abstract class BundleWindowsAssets extends Target {
143142
environment,
144143
outputDirectory,
145144
targetPlatform: targetPlatform,
146-
shaderTarget: ShaderTarget.sksl,
147145
);
148146
environment.depFileService.writeToFile(
149147
depfile,

packages/flutter_tools/lib/src/bundle_builder.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,6 @@ Future<void> writeBundle(
169169
artifacts: globals.artifacts!,
170170
);
171171

172-
ShaderTarget shaderTarget = ShaderTarget.sksl;
173-
if (targetPlatform == TargetPlatform.tester && impellerStatus == ImpellerStatus.enabled) {
174-
shaderTarget = ShaderTarget.impellerSwiftShader;
175-
}
176-
177172
// Limit number of open files to avoid running out of file descriptors.
178173
final Pool pool = Pool(64);
179174
await Future.wait<void>(
@@ -200,8 +195,7 @@ Future<void> writeBundle(
200195
doCopy = !await shaderCompiler.compileShader(
201196
input: input,
202197
outputPath: file.path,
203-
target: shaderTarget,
204-
json: targetPlatform == TargetPlatform.web_javascript,
198+
targetPlatform: targetPlatform,
205199
);
206200
case AssetKind.model:
207201
doCopy = !await sceneImporter.importScene(

0 commit comments

Comments
 (0)