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.
This commit is contained in:
Dan Field
2024-01-31 13:30:02 -08:00
committed by GitHub
parent ceab0e005f
commit c417c4623c
23 changed files with 250 additions and 226 deletions

View File

@@ -672,6 +672,8 @@ flutter:
command: <String>[
impellerc,
'--sksl',
'--runtime-stage-gles',
'--runtime-stage-vulkan',
'--iplr',
'--sl=$outputPath',
'--spirv=$outputPath.spirv',

View File

@@ -535,6 +535,7 @@ void main() {
processManager.addCommands(<FakeCommand>[
const FakeCommand(command: <String>[
'HostArtifact.impellerc',
'--sksl',
'--runtime-stage-gles',
'--runtime-stage-vulkan',
'--iplr',

View File

@@ -287,6 +287,7 @@ void main() {
processManager.addCommands(<FakeCommand>[
const FakeCommand(command: <String>[
'HostArtifact.impellerc',
'--sksl',
'--runtime-stage-metal',
'--iplr',
'--sl=/App.framework/flutter_assets/shader.glsl',

View File

@@ -11,7 +11,6 @@ import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/build_system/targets/shader_compiler.dart';
import 'package:flutter_tools/src/devfs.dart';
import 'package:flutter_tools/src/device.dart';
import '../../../src/common.dart';
import '../../../src/fake_process_manager.dart';
@@ -40,13 +39,14 @@ void main() {
fileSystem.file(notFragPath).createSync(recursive: true);
});
testWithoutContext('compileShader invokes impellerc for .frag files and sksl target', () async {
testWithoutContext('compileShader invokes impellerc for .frag files and web target', () async {
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>[
impellerc,
'--sksl',
'--iplr',
'--json',
'--sl=$outputPath',
'--spirv=$outputSpirvPath',
'--input=$fragPath',
@@ -71,8 +71,7 @@ void main() {
await shaderCompiler.compileShader(
input: fileSystem.file(fragPath),
outputPath: outputPath,
target: ShaderTarget.sksl,
json: false,
targetPlatform: TargetPlatform.web_javascript,
),
true,
);
@@ -85,6 +84,7 @@ void main() {
FakeCommand(
command: <String>[
impellerc,
'--sksl',
'--runtime-stage-metal',
'--iplr',
'--sl=$outputPath',
@@ -110,8 +110,7 @@ void main() {
await shaderCompiler.compileShader(
input: fileSystem.file(fragPath),
outputPath: outputPath,
target: ShaderTarget.impelleriOS,
json: false,
targetPlatform: TargetPlatform.ios,
),
true,
);
@@ -123,6 +122,7 @@ void main() {
FakeCommand(
command: <String>[
impellerc,
'--sksl',
'--runtime-stage-gles',
'--runtime-stage-vulkan',
'--iplr',
@@ -149,8 +149,7 @@ void main() {
await shaderCompiler.compileShader(
input: fileSystem.file(fragPath),
outputPath: outputPath,
target: ShaderTarget.impellerAndroid,
json: false,
targetPlatform: TargetPlatform.android,
),
true,
);
@@ -164,6 +163,7 @@ void main() {
impellerc,
'--sksl',
'--iplr',
'--json',
'--sl=$outputPath',
'--spirv=$outputSpirvPath',
'--input=$notFragPath',
@@ -188,8 +188,7 @@ void main() {
await shaderCompiler.compileShader(
input: fileSystem.file(notFragPath),
outputPath: outputPath,
target: ShaderTarget.sksl,
json: false,
targetPlatform: TargetPlatform.web_javascript,
),
true,
);
@@ -204,6 +203,7 @@ void main() {
impellerc,
'--sksl',
'--iplr',
'--json',
'--sl=$outputPath',
'--spirv=$outputSpirvPath',
'--input=$notFragPath',
@@ -227,8 +227,7 @@ void main() {
await shaderCompiler.compileShader(
input: fileSystem.file(notFragPath),
outputPath: outputPath,
target: ShaderTarget.sksl,
json: false,
targetPlatform: TargetPlatform.web_javascript,
);
fail('unreachable');
} on ShaderCompilerException catch (e) {
@@ -245,100 +244,6 @@ void main() {
command: <String>[
impellerc,
'--sksl',
'--iplr',
'--sl=/.tmp_rand0/0.8255140718871702.temp',
'--spirv=/.tmp_rand0/0.8255140718871702.temp.spirv',
'--input=$fragPath',
'--input-type=frag',
'--include=$fragDir',
'--include=$shaderLibDir',
],
onRun: (_) {
fileSystem.file('/.tmp_rand0/0.8255140718871702.temp.spirv').createSync();
fileSystem.file('/.tmp_rand0/0.8255140718871702.temp')
..createSync()
..writeAsBytesSync(<int>[1, 2, 3, 4]);
}
),
]);
fileSystem.file(fragPath).writeAsBytesSync(<int>[1, 2, 3, 4]);
final ShaderCompiler shaderCompiler = ShaderCompiler(
processManager: processManager,
logger: logger,
fileSystem: fileSystem,
artifacts: artifacts,
);
final DevelopmentShaderCompiler developmentShaderCompiler = DevelopmentShaderCompiler(
shaderCompiler: shaderCompiler,
fileSystem: fileSystem,
random: math.Random(0),
);
developmentShaderCompiler.configureCompiler(
TargetPlatform.android,
impellerStatus: ImpellerStatus.disabled,
);
final DevFSContent? content = await developmentShaderCompiler
.recompileShader(DevFSFileContent(fileSystem.file(fragPath)));
expect(await content!.contentsAsBytes(), <int>[1, 2, 3, 4]);
expect(fileSystem.file('/.tmp_rand0/0.8255140718871702.temp.spirv'), isNot(exists));
expect(fileSystem.file('/.tmp_rand0/0.8255140718871702.temp'), isNot(exists));
});
testWithoutContext('DevelopmentShaderCompiler can compile for Flutter Tester with Impeller and Vulkan', () async {
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>[
impellerc,
'--runtime-stage-vulkan',
'--iplr',
'--sl=/.tmp_rand0/0.8255140718871702.temp',
'--spirv=/.tmp_rand0/0.8255140718871702.temp.spirv',
'--input=$fragPath',
'--input-type=frag',
'--include=$fragDir',
'--include=$shaderLibDir',
],
onRun: (_) {
fileSystem.file('/.tmp_rand0/0.8255140718871702.temp.spirv').createSync();
fileSystem.file('/.tmp_rand0/0.8255140718871702.temp')
..createSync()
..writeAsBytesSync(<int>[1, 2, 3, 4]);
}
),
]);
fileSystem.file(fragPath).writeAsBytesSync(<int>[1, 2, 3, 4]);
final ShaderCompiler shaderCompiler = ShaderCompiler(
processManager: processManager,
logger: logger,
fileSystem: fileSystem,
artifacts: artifacts,
);
final DevelopmentShaderCompiler developmentShaderCompiler = DevelopmentShaderCompiler(
shaderCompiler: shaderCompiler,
fileSystem: fileSystem,
random: math.Random(0),
);
developmentShaderCompiler.configureCompiler(
TargetPlatform.tester,
impellerStatus: ImpellerStatus.enabled,
);
final DevFSContent? content = await developmentShaderCompiler
.recompileShader(DevFSFileContent(fileSystem.file(fragPath)));
expect(await content!.contentsAsBytes(), <int>[1, 2, 3, 4]);
expect(processManager.hasRemainingExpectations, false);
});
testWithoutContext('DevelopmentShaderCompiler can compile for android with impeller', () async {
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>[
impellerc,
'--runtime-stage-gles',
'--runtime-stage-vulkan',
'--iplr',
@@ -370,10 +275,191 @@ void main() {
random: math.Random(0),
);
developmentShaderCompiler.configureCompiler(
TargetPlatform.android,
impellerStatus: ImpellerStatus.enabled,
developmentShaderCompiler.configureCompiler(TargetPlatform.android);
final DevFSContent? content = await developmentShaderCompiler
.recompileShader(DevFSFileContent(fileSystem.file(fragPath)));
expect(await content!.contentsAsBytes(), <int>[1, 2, 3, 4]);
expect(fileSystem.file('/.tmp_rand0/0.8255140718871702.temp.spirv'), isNot(exists));
expect(fileSystem.file('/.tmp_rand0/0.8255140718871702.temp'), isNot(exists));
});
testWithoutContext('DevelopmentShaderCompiler can compile for Flutter Tester with Impeller and Vulkan', () async {
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>[
impellerc,
'--sksl',
'--runtime-stage-vulkan',
'--iplr',
'--sl=/.tmp_rand0/0.8255140718871702.temp',
'--spirv=/.tmp_rand0/0.8255140718871702.temp.spirv',
'--input=$fragPath',
'--input-type=frag',
'--include=$fragDir',
'--include=$shaderLibDir',
],
onRun: (_) {
fileSystem.file('/.tmp_rand0/0.8255140718871702.temp.spirv').createSync();
fileSystem.file('/.tmp_rand0/0.8255140718871702.temp')
..createSync()
..writeAsBytesSync(<int>[1, 2, 3, 4]);
}
),
]);
fileSystem.file(fragPath).writeAsBytesSync(<int>[1, 2, 3, 4]);
final ShaderCompiler shaderCompiler = ShaderCompiler(
processManager: processManager,
logger: logger,
fileSystem: fileSystem,
artifacts: artifacts,
);
final DevelopmentShaderCompiler developmentShaderCompiler = DevelopmentShaderCompiler(
shaderCompiler: shaderCompiler,
fileSystem: fileSystem,
random: math.Random(0),
);
developmentShaderCompiler.configureCompiler(TargetPlatform.tester);
final DevFSContent? content = await developmentShaderCompiler
.recompileShader(DevFSFileContent(fileSystem.file(fragPath)));
expect(await content!.contentsAsBytes(), <int>[1, 2, 3, 4]);
expect(processManager.hasRemainingExpectations, false);
});
testWithoutContext('DevelopmentShaderCompiler can compile for android with impeller', () async {
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>[
impellerc,
'--sksl',
'--runtime-stage-gles',
'--runtime-stage-vulkan',
'--iplr',
'--sl=/.tmp_rand0/0.8255140718871702.temp',
'--spirv=/.tmp_rand0/0.8255140718871702.temp.spirv',
'--input=$fragPath',
'--input-type=frag',
'--include=$fragDir',
'--include=$shaderLibDir',
],
onRun: (_) {
fileSystem.file('/.tmp_rand0/0.8255140718871702.temp.spirv').createSync();
fileSystem.file('/.tmp_rand0/0.8255140718871702.temp')
..createSync()
..writeAsBytesSync(<int>[1, 2, 3, 4]);
}
),
]);
fileSystem.file(fragPath).writeAsBytesSync(<int>[1, 2, 3, 4]);
final ShaderCompiler shaderCompiler = ShaderCompiler(
processManager: processManager,
logger: logger,
fileSystem: fileSystem,
artifacts: artifacts,
);
final DevelopmentShaderCompiler developmentShaderCompiler = DevelopmentShaderCompiler(
shaderCompiler: shaderCompiler,
fileSystem: fileSystem,
random: math.Random(0),
);
developmentShaderCompiler.configureCompiler(TargetPlatform.android);
final DevFSContent? content = await developmentShaderCompiler
.recompileShader(DevFSFileContent(fileSystem.file(fragPath)));
expect(await content!.contentsAsBytes(), <int>[1, 2, 3, 4]);
expect(fileSystem.file('/.tmp_rand0/0.8255140718871702.temp.spirv'), isNot(exists));
expect(fileSystem.file('/.tmp_rand0/0.8255140718871702.temp'), isNot(exists));
});
testWithoutContext('DevelopmentShaderCompiler can compile for Flutter Tester with Impeller and Vulkan', () async {
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>[
impellerc,
'--sksl',
'--runtime-stage-vulkan',
'--iplr',
'--sl=/.tmp_rand0/0.8255140718871702.temp',
'--spirv=/.tmp_rand0/0.8255140718871702.temp.spirv',
'--input=$fragPath',
'--input-type=frag',
'--include=$fragDir',
'--include=$shaderLibDir',
],
onRun: (List<String> args) {
fileSystem.file('/.tmp_rand0/0.8255140718871702.temp.spirv').createSync();
fileSystem.file('/.tmp_rand0/0.8255140718871702.temp')
..createSync()
..writeAsBytesSync(<int>[1, 2, 3, 4]);
}
),
]);
fileSystem.file(fragPath).writeAsBytesSync(<int>[1, 2, 3, 4]);
final ShaderCompiler shaderCompiler = ShaderCompiler(
processManager: processManager,
logger: logger,
fileSystem: fileSystem,
artifacts: artifacts,
);
final DevelopmentShaderCompiler developmentShaderCompiler = DevelopmentShaderCompiler(
shaderCompiler: shaderCompiler,
fileSystem: fileSystem,
random: math.Random(0),
);
developmentShaderCompiler.configureCompiler(TargetPlatform.tester);
final DevFSContent? content = await developmentShaderCompiler
.recompileShader(DevFSFileContent(fileSystem.file(fragPath)));
expect(await content!.contentsAsBytes(), <int>[1, 2, 3, 4]);
expect(processManager.hasRemainingExpectations, false);
});
testWithoutContext('DevelopmentShaderCompiler can compile for android with impeller', () async {
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>[
impellerc,
'--sksl',
'--runtime-stage-gles',
'--runtime-stage-vulkan',
'--iplr',
'--sl=/.tmp_rand0/0.8255140718871702.temp',
'--spirv=/.tmp_rand0/0.8255140718871702.temp.spirv',
'--input=$fragPath',
'--input-type=frag',
'--include=$fragDir',
'--include=$shaderLibDir',
],
onRun: (List<String> args) {
fileSystem.file('/.tmp_rand0/0.8255140718871702.temp.spirv').createSync();
fileSystem.file('/.tmp_rand0/0.8255140718871702.temp')
..createSync()
..writeAsBytesSync(<int>[1, 2, 3, 4]);
}
),
]);
fileSystem.file(fragPath).writeAsBytesSync(<int>[1, 2, 3, 4]);
final ShaderCompiler shaderCompiler = ShaderCompiler(
processManager: processManager,
logger: logger,
fileSystem: fileSystem,
artifacts: artifacts,
);
final DevelopmentShaderCompiler developmentShaderCompiler = DevelopmentShaderCompiler(
shaderCompiler: shaderCompiler,
fileSystem: fileSystem,
random: math.Random(0),
);
developmentShaderCompiler.configureCompiler(TargetPlatform.android);
final DevFSContent? content = await developmentShaderCompiler
.recompileShader(DevFSFileContent(fileSystem.file(fragPath)));
@@ -419,10 +505,7 @@ void main() {
random: math.Random(0),
);
developmentShaderCompiler.configureCompiler(
TargetPlatform.web_javascript,
impellerStatus: ImpellerStatus.disabled,
);
developmentShaderCompiler.configureCompiler(TargetPlatform.web_javascript);
final DevFSContent? content = await developmentShaderCompiler
.recompileShader(DevFSFileContent(fileSystem.file(fragPath)));

View File

@@ -279,10 +279,7 @@ class FakeShaderCompiler implements DevelopmentShaderCompiler {
const FakeShaderCompiler();
@override
void configureCompiler(
TargetPlatform? platform, {
required ImpellerStatus impellerStatus,
}) { }
void configureCompiler(TargetPlatform? platform) { }
@override
Future<DevFSContent> recompileShader(DevFSContent inputShader) {

View File

@@ -20,7 +20,6 @@ import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/build_system/targets/shader_compiler.dart';
import 'package:flutter_tools/src/compile.dart';
import 'package:flutter_tools/src/devfs.dart';
import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/vmservice.dart';
import 'package:package_config/package_config.dart';
import 'package:test/fake.dart';
@@ -831,10 +830,7 @@ class FakeShaderCompiler implements DevelopmentShaderCompiler {
const FakeShaderCompiler();
@override
void configureCompiler(
TargetPlatform? platform, {
required ImpellerStatus impellerStatus,
}) { }
void configureCompiler(TargetPlatform? platform) { }
@override
Future<DevFSContent> recompileShader(DevFSContent inputShader) async {

View File

@@ -967,10 +967,7 @@ class FakeShaderCompiler implements DevelopmentShaderCompiler {
const FakeShaderCompiler();
@override
void configureCompiler(
TargetPlatform? platform, {
required ImpellerStatus impellerStatus,
}) { }
void configureCompiler(TargetPlatform? platform) { }
@override
Future<DevFSContent> recompileShader(DevFSContent inputShader) {

View File

@@ -2957,10 +2957,7 @@ class FakeShaderCompiler implements DevelopmentShaderCompiler {
const FakeShaderCompiler();
@override
void configureCompiler(
TargetPlatform? platform, {
required ImpellerStatus impellerStatus,
}) { }
void configureCompiler(TargetPlatform? platform) { }
@override
Future<DevFSContent> recompileShader(DevFSContent inputShader) {

View File

@@ -1756,10 +1756,7 @@ class FakeShaderCompiler implements DevelopmentShaderCompiler {
const FakeShaderCompiler();
@override
void configureCompiler(
TargetPlatform? platform, {
required ImpellerStatus impellerStatus,
}) { }
void configureCompiler(TargetPlatform? platform) { }
@override
Future<DevFSContent> recompileShader(DevFSContent inputShader) {

View File

@@ -1475,10 +1475,7 @@ class FakeShaderCompiler implements DevelopmentShaderCompiler {
const FakeShaderCompiler();
@override
void configureCompiler(
TargetPlatform? platform, {
required ImpellerStatus impellerStatus,
}) { }
void configureCompiler(TargetPlatform? platform) { }
@override
Future<DevFSContent> recompileShader(DevFSContent inputShader) {

View File

@@ -16,7 +16,6 @@ import 'package:flutter_tools/src/build_system/targets/shader_compiler.dart';
import 'package:flutter_tools/src/compile.dart';
import 'package:flutter_tools/src/convert.dart';
import 'package:flutter_tools/src/devfs.dart';
import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/html_utils.dart';
import 'package:flutter_tools/src/isolated/devfs_web.dart';
@@ -1309,10 +1308,7 @@ class FakeShaderCompiler implements DevelopmentShaderCompiler {
const FakeShaderCompiler();
@override
void configureCompiler(
TargetPlatform? platform, {
required ImpellerStatus impellerStatus,
}) { }
void configureCompiler(TargetPlatform? platform) { }
@override
Future<DevFSContent> recompileShader(DevFSContent inputShader) {

View File

@@ -4,6 +4,7 @@
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/build_system/targets/shader_compiler.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
@@ -32,8 +33,7 @@ void main() {
await shaderCompiler.compileShader(
input: file,
outputPath: tmpDir.childFile('test_shader.frag.out').path,
target: ShaderTarget.sksl,
json: false,
targetPlatform: TargetPlatform.tester,
);
}
@@ -62,8 +62,7 @@ void main() {
final bool compileResult = await shaderCompiler.compileShader(
input: globals.fs.file(inkSparklePath),
outputPath: inkSparkleOutputPath,
target: ShaderTarget.sksl,
json: false,
targetPlatform: TargetPlatform.tester,
);
final File resultFile = globals.fs.file(inkSparkleOutputPath);