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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 250 additions and 226 deletions

View File

@ -15,7 +15,6 @@ import '../exceptions.dart';
import 'assets.dart'; import 'assets.dart';
import 'common.dart'; import 'common.dart';
import 'icon_tree_shaker.dart'; import 'icon_tree_shaker.dart';
import 'shader_compiler.dart';
/// Prepares the asset bundle in the format expected by flutter.gradle. /// Prepares the asset bundle in the format expected by flutter.gradle.
/// ///
@ -68,7 +67,6 @@ abstract class AndroidAssetBundle extends Target {
outputDirectory, outputDirectory,
targetPlatform: TargetPlatform.android, targetPlatform: TargetPlatform.android,
buildMode: buildMode, buildMode: buildMode,
shaderTarget: ShaderTarget.impellerAndroid,
flavor: environment.defines[kFlavor], flavor: environment.defines[kFlavor],
); );
environment.depFileService.writeToFile( environment.depFileService.writeToFile(

View File

@ -32,7 +32,6 @@ Future<Depfile> copyAssets(
Map<String, DevFSContent> additionalContent = const <String, DevFSContent>{}, Map<String, DevFSContent> additionalContent = const <String, DevFSContent>{},
required TargetPlatform targetPlatform, required TargetPlatform targetPlatform,
BuildMode? buildMode, BuildMode? buildMode,
required ShaderTarget shaderTarget,
List<File> additionalInputs = const <File>[], List<File> additionalInputs = const <File>[],
String? flavor, String? flavor,
}) async { }) async {
@ -140,8 +139,7 @@ Future<Depfile> copyAssets(
doCopy = !await shaderCompiler.compileShader( doCopy = !await shaderCompiler.compileShader(
input: content.file as File, input: content.file as File,
outputPath: file.path, outputPath: file.path,
target: shaderTarget, targetPlatform: targetPlatform,
json: targetPlatform == TargetPlatform.web_javascript,
); );
case AssetKind.model: case AssetKind.model:
doCopy = !await sceneImporter.importScene( doCopy = !await sceneImporter.importScene(
@ -328,7 +326,6 @@ class CopyAssets extends Target {
environment, environment,
output, output,
targetPlatform: TargetPlatform.android, targetPlatform: TargetPlatform.android,
shaderTarget: ShaderTarget.sksl,
flavor: environment.defines[kFlavor], flavor: environment.defines[kFlavor],
); );
environment.depFileService.writeToFile( environment.depFileService.writeToFile(

View File

@ -79,7 +79,6 @@ class CopyFlutterBundle extends Target {
environment.outputDir, environment.outputDir,
targetPlatform: TargetPlatform.android, targetPlatform: TargetPlatform.android,
buildMode: buildMode, buildMode: buildMode,
shaderTarget: ShaderTarget.sksl,
flavor: flavor, flavor: flavor,
); );
environment.depFileService.writeToFile( environment.depFileService.writeToFile(

View File

@ -503,9 +503,6 @@ abstract class IosAssetBundle extends Target {
environment, environment,
assetDirectory, assetDirectory,
targetPlatform: TargetPlatform.ios, targetPlatform: TargetPlatform.ios,
// Always specify an impeller shader target so that we support runtime toggling and
// the --enable-impeller debug flag.
shaderTarget: ShaderTarget.impelleriOS,
additionalInputs: <File>[ additionalInputs: <File>[
flutterProject.ios.infoPlist, flutterProject.ios.infoPlist,
flutterProject.ios.appFrameworkInfoPlist, flutterProject.ios.appFrameworkInfoPlist,

View File

@ -15,7 +15,6 @@ import 'assets.dart';
import 'common.dart'; import 'common.dart';
import 'desktop.dart'; import 'desktop.dart';
import 'icon_tree_shaker.dart'; import 'icon_tree_shaker.dart';
import 'shader_compiler.dart';
/// The only files/subdirectories we care out. /// The only files/subdirectories we care out.
const List<String> _kLinuxArtifacts = <String>[ const List<String> _kLinuxArtifacts = <String>[
@ -141,7 +140,6 @@ abstract class BundleLinuxAssets extends Target {
additionalContent: <String, DevFSContent>{ additionalContent: <String, DevFSContent>{
'version.json': DevFSStringContent(versionInfo), 'version.json': DevFSStringContent(versionInfo),
}, },
shaderTarget: ShaderTarget.sksl,
); );
environment.depFileService.writeToFile( environment.depFileService.writeToFile(
depfile, depfile,

View File

@ -18,7 +18,6 @@ import '../exceptions.dart';
import 'assets.dart'; import 'assets.dart';
import 'common.dart'; import 'common.dart';
import 'icon_tree_shaker.dart'; import 'icon_tree_shaker.dart';
import 'shader_compiler.dart';
/// Copy the macOS framework to the correct copy dir by invoking 'rsync'. /// Copy the macOS framework to the correct copy dir by invoking 'rsync'.
/// ///
@ -439,7 +438,6 @@ abstract class MacOSBundleFlutterAssets extends Target {
environment, environment,
assetDirectory, assetDirectory,
targetPlatform: TargetPlatform.darwin, targetPlatform: TargetPlatform.darwin,
shaderTarget: ShaderTarget.sksl,
flavor: environment.defines[kFlavor], flavor: environment.defines[kFlavor],
); );
environment.depFileService.writeToFile( environment.depFileService.writeToFile(

View File

@ -17,21 +17,8 @@ import '../../base/logger.dart';
import '../../build_info.dart'; import '../../build_info.dart';
import '../../convert.dart'; import '../../convert.dart';
import '../../devfs.dart'; import '../../devfs.dart';
import '../../device.dart';
import '../build_system.dart'; import '../build_system.dart';
/// The output shader format that should be used by the [ShaderCompiler].
enum ShaderTarget {
impellerAndroid(<String>['--runtime-stage-gles', '--runtime-stage-vulkan']),
impelleriOS(<String>['--runtime-stage-metal']),
impellerSwiftShader(<String>['--runtime-stage-vulkan']),
sksl(<String>['--sksl']);
const ShaderTarget(this.stages);
final List<String> stages;
}
/// A wrapper around [ShaderCompiler] to support hot reload of shader sources. /// A wrapper around [ShaderCompiler] to support hot reload of shader sources.
class DevelopmentShaderCompiler { class DevelopmentShaderCompiler {
DevelopmentShaderCompiler({ DevelopmentShaderCompiler({
@ -47,42 +34,16 @@ class DevelopmentShaderCompiler {
final Pool _compilationPool = Pool(4); final Pool _compilationPool = Pool(4);
final math.Random _random; final math.Random _random;
late ShaderTarget _shaderTarget; late TargetPlatform _targetPlatform;
bool _debugConfigured = false; bool _debugConfigured = false;
bool _jsonMode = false;
/// Configure the output format of the shader compiler for a particular /// Configure the output format of the shader compiler for a particular
/// flutter device. /// flutter device.
void configureCompiler(TargetPlatform? platform, { required ImpellerStatus impellerStatus }) { void configureCompiler(TargetPlatform? platform) {
switch (platform) { if (platform == null) {
case TargetPlatform.ios:
_shaderTarget = ShaderTarget.impelleriOS;
case TargetPlatform.android_arm64:
case TargetPlatform.android_x64:
case TargetPlatform.android_x86:
case TargetPlatform.android_arm:
case TargetPlatform.android:
_shaderTarget = impellerStatus == ImpellerStatus.enabled
? ShaderTarget.impellerAndroid
: ShaderTarget.sksl;
case TargetPlatform.darwin:
case TargetPlatform.linux_x64:
case TargetPlatform.linux_arm64:
case TargetPlatform.windows_x64:
case TargetPlatform.windows_arm64:
case TargetPlatform.fuchsia_arm64:
case TargetPlatform.fuchsia_x64:
case TargetPlatform.tester:
_shaderTarget = impellerStatus == ImpellerStatus.enabled
? ShaderTarget.impellerSwiftShader
: ShaderTarget.sksl;
case TargetPlatform.web_javascript:
assert(impellerStatus != ImpellerStatus.enabled);
_shaderTarget = ShaderTarget.sksl;
_jsonMode = true;
case null:
return; return;
} }
_targetPlatform = platform;
_debugConfigured = true; _debugConfigured = true;
} }
@ -107,9 +68,8 @@ class DevelopmentShaderCompiler {
final bool success = await _shaderCompiler.compileShader( final bool success = await _shaderCompiler.compileShader(
input: inputFile, input: inputFile,
outputPath: output.path, outputPath: output.path,
target: _shaderTarget, targetPlatform: _targetPlatform,
fatal: false, fatal: false,
json: _jsonMode,
); );
if (!success) { if (!success) {
return null; return null;
@ -144,6 +104,34 @@ class ShaderCompiler {
final FileSystem _fs; final FileSystem _fs;
final Artifacts _artifacts; final Artifacts _artifacts;
List<String> _shaderTargetsFromTargetPlatform(TargetPlatform targetPlatform) {
switch (targetPlatform) {
case TargetPlatform.android_x64:
case TargetPlatform.android_x86:
case TargetPlatform.android_arm:
case TargetPlatform.android_arm64:
case TargetPlatform.android:
case TargetPlatform.linux_x64:
case TargetPlatform.linux_arm64:
case TargetPlatform.windows_x64:
case TargetPlatform.windows_arm64:
return <String>['--sksl', '--runtime-stage-gles', '--runtime-stage-vulkan'];
case TargetPlatform.ios:
case TargetPlatform.darwin:
return <String>['--sksl', '--runtime-stage-metal'];
case TargetPlatform.fuchsia_arm64:
case TargetPlatform.fuchsia_x64:
case TargetPlatform.tester:
return <String>['--sksl', '--runtime-stage-vulkan'];
case TargetPlatform.web_javascript:
return <String>['--sksl'];
}
}
/// The [Source] inputs that targets using this should depend on. /// The [Source] inputs that targets using this should depend on.
/// ///
/// See [Target.inputs]. /// See [Target.inputs].
@ -163,9 +151,8 @@ class ShaderCompiler {
Future<bool> compileShader({ Future<bool> compileShader({
required File input, required File input,
required String outputPath, required String outputPath,
required ShaderTarget target, required TargetPlatform targetPlatform,
bool fatal = true, bool fatal = true,
required bool json,
}) async { }) async {
final File impellerc = _fs.file( final File impellerc = _fs.file(
_artifacts.getHostArtifact(HostArtifact.impellerc), _artifacts.getHostArtifact(HostArtifact.impellerc),
@ -180,9 +167,9 @@ class ShaderCompiler {
final String shaderLibPath = _fs.path.join(impellerc.parent.absolute.path, 'shader_lib'); final String shaderLibPath = _fs.path.join(impellerc.parent.absolute.path, 'shader_lib');
final List<String> cmd = <String>[ final List<String> cmd = <String>[
impellerc.path, impellerc.path,
...target.stages, ..._shaderTargetsFromTargetPlatform(targetPlatform),
'--iplr', '--iplr',
if (json) if (targetPlatform == TargetPlatform.web_javascript)
'--json', '--json',
'--sl=$outputPath', '--sl=$outputPath',
'--spirv=$outputPath.spirv', '--spirv=$outputPath.spirv',

View File

@ -28,7 +28,6 @@ import '../depfile.dart';
import '../exceptions.dart'; import '../exceptions.dart';
import 'assets.dart'; import 'assets.dart';
import 'localizations.dart'; import 'localizations.dart';
import 'shader_compiler.dart';
/// Whether the application has web plugins. /// Whether the application has web plugins.
const String kHasWebPlugins = 'HasWebPlugins'; const String kHasWebPlugins = 'HasWebPlugins';
@ -395,7 +394,6 @@ class WebReleaseBundle extends Target {
environment, environment,
environment.outputDir.childDirectory('assets'), environment.outputDir.childDirectory('assets'),
targetPlatform: TargetPlatform.web_javascript, targetPlatform: TargetPlatform.web_javascript,
shaderTarget: ShaderTarget.sksl,
); );
final DepfileService depfileService = environment.depFileService; final DepfileService depfileService = environment.depFileService;
depfileService.writeToFile( depfileService.writeToFile(

View File

@ -12,7 +12,6 @@ import 'assets.dart';
import 'common.dart'; import 'common.dart';
import 'desktop.dart'; import 'desktop.dart';
import 'icon_tree_shaker.dart'; import 'icon_tree_shaker.dart';
import 'shader_compiler.dart';
/// The only files/subdirectories we care about. /// The only files/subdirectories we care about.
const List<String> _kWindowsArtifacts = <String>[ const List<String> _kWindowsArtifacts = <String>[
@ -143,7 +142,6 @@ abstract class BundleWindowsAssets extends Target {
environment, environment,
outputDirectory, outputDirectory,
targetPlatform: targetPlatform, targetPlatform: targetPlatform,
shaderTarget: ShaderTarget.sksl,
); );
environment.depFileService.writeToFile( environment.depFileService.writeToFile(
depfile, depfile,

View File

@ -169,11 +169,6 @@ Future<void> writeBundle(
artifacts: globals.artifacts!, artifacts: globals.artifacts!,
); );
ShaderTarget shaderTarget = ShaderTarget.sksl;
if (targetPlatform == TargetPlatform.tester && impellerStatus == ImpellerStatus.enabled) {
shaderTarget = ShaderTarget.impellerSwiftShader;
}
// Limit number of open files to avoid running out of file descriptors. // Limit number of open files to avoid running out of file descriptors.
final Pool pool = Pool(64); final Pool pool = Pool(64);
await Future.wait<void>( await Future.wait<void>(
@ -200,8 +195,7 @@ Future<void> writeBundle(
doCopy = !await shaderCompiler.compileShader( doCopy = !await shaderCompiler.compileShader(
input: input, input: input,
outputPath: file.path, outputPath: file.path,
target: shaderTarget, targetPlatform: targetPlatform,
json: targetPlatform == TargetPlatform.web_javascript,
); );
case AssetKind.model: case AssetKind.model:
doCopy = !await sceneImporter.importScene( doCopy = !await sceneImporter.importScene(

View File

@ -268,10 +268,7 @@ class HotRunner extends ResidentRunner {
await device!.initLogReader(); await device!.initLogReader();
device device
.developmentShaderCompiler .developmentShaderCompiler
.configureCompiler( .configureCompiler(device.targetPlatform);
device.targetPlatform,
impellerStatus: debuggingOptions.enableImpeller,
);
} }
try { try {
final List<Uri?> baseUris = await _initDevFS(); final List<Uri?> baseUris = await _initDevFS();

View File

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

View File

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

View File

@ -287,6 +287,7 @@ void main() {
processManager.addCommands(<FakeCommand>[ processManager.addCommands(<FakeCommand>[
const FakeCommand(command: <String>[ const FakeCommand(command: <String>[
'HostArtifact.impellerc', 'HostArtifact.impellerc',
'--sksl',
'--runtime-stage-metal', '--runtime-stage-metal',
'--iplr', '--iplr',
'--sl=/App.framework/flutter_assets/shader.glsl', '--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_info.dart';
import 'package:flutter_tools/src/build_system/targets/shader_compiler.dart'; import 'package:flutter_tools/src/build_system/targets/shader_compiler.dart';
import 'package:flutter_tools/src/devfs.dart'; import 'package:flutter_tools/src/devfs.dart';
import 'package:flutter_tools/src/device.dart';
import '../../../src/common.dart'; import '../../../src/common.dart';
import '../../../src/fake_process_manager.dart'; import '../../../src/fake_process_manager.dart';
@ -40,13 +39,14 @@ void main() {
fileSystem.file(notFragPath).createSync(recursive: true); 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>[ final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand( FakeCommand(
command: <String>[ command: <String>[
impellerc, impellerc,
'--sksl', '--sksl',
'--iplr', '--iplr',
'--json',
'--sl=$outputPath', '--sl=$outputPath',
'--spirv=$outputSpirvPath', '--spirv=$outputSpirvPath',
'--input=$fragPath', '--input=$fragPath',
@ -71,8 +71,7 @@ void main() {
await shaderCompiler.compileShader( await shaderCompiler.compileShader(
input: fileSystem.file(fragPath), input: fileSystem.file(fragPath),
outputPath: outputPath, outputPath: outputPath,
target: ShaderTarget.sksl, targetPlatform: TargetPlatform.web_javascript,
json: false,
), ),
true, true,
); );
@ -85,6 +84,7 @@ void main() {
FakeCommand( FakeCommand(
command: <String>[ command: <String>[
impellerc, impellerc,
'--sksl',
'--runtime-stage-metal', '--runtime-stage-metal',
'--iplr', '--iplr',
'--sl=$outputPath', '--sl=$outputPath',
@ -110,8 +110,7 @@ void main() {
await shaderCompiler.compileShader( await shaderCompiler.compileShader(
input: fileSystem.file(fragPath), input: fileSystem.file(fragPath),
outputPath: outputPath, outputPath: outputPath,
target: ShaderTarget.impelleriOS, targetPlatform: TargetPlatform.ios,
json: false,
), ),
true, true,
); );
@ -123,6 +122,7 @@ void main() {
FakeCommand( FakeCommand(
command: <String>[ command: <String>[
impellerc, impellerc,
'--sksl',
'--runtime-stage-gles', '--runtime-stage-gles',
'--runtime-stage-vulkan', '--runtime-stage-vulkan',
'--iplr', '--iplr',
@ -149,8 +149,7 @@ void main() {
await shaderCompiler.compileShader( await shaderCompiler.compileShader(
input: fileSystem.file(fragPath), input: fileSystem.file(fragPath),
outputPath: outputPath, outputPath: outputPath,
target: ShaderTarget.impellerAndroid, targetPlatform: TargetPlatform.android,
json: false,
), ),
true, true,
); );
@ -164,6 +163,7 @@ void main() {
impellerc, impellerc,
'--sksl', '--sksl',
'--iplr', '--iplr',
'--json',
'--sl=$outputPath', '--sl=$outputPath',
'--spirv=$outputSpirvPath', '--spirv=$outputSpirvPath',
'--input=$notFragPath', '--input=$notFragPath',
@ -188,8 +188,7 @@ void main() {
await shaderCompiler.compileShader( await shaderCompiler.compileShader(
input: fileSystem.file(notFragPath), input: fileSystem.file(notFragPath),
outputPath: outputPath, outputPath: outputPath,
target: ShaderTarget.sksl, targetPlatform: TargetPlatform.web_javascript,
json: false,
), ),
true, true,
); );
@ -204,6 +203,7 @@ void main() {
impellerc, impellerc,
'--sksl', '--sksl',
'--iplr', '--iplr',
'--json',
'--sl=$outputPath', '--sl=$outputPath',
'--spirv=$outputSpirvPath', '--spirv=$outputSpirvPath',
'--input=$notFragPath', '--input=$notFragPath',
@ -227,8 +227,7 @@ void main() {
await shaderCompiler.compileShader( await shaderCompiler.compileShader(
input: fileSystem.file(notFragPath), input: fileSystem.file(notFragPath),
outputPath: outputPath, outputPath: outputPath,
target: ShaderTarget.sksl, targetPlatform: TargetPlatform.web_javascript,
json: false,
); );
fail('unreachable'); fail('unreachable');
} on ShaderCompilerException catch (e) { } on ShaderCompilerException catch (e) {
@ -245,100 +244,6 @@ void main() {
command: <String>[ command: <String>[
impellerc, impellerc,
'--sksl', '--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-gles',
'--runtime-stage-vulkan', '--runtime-stage-vulkan',
'--iplr', '--iplr',
@ -370,10 +275,191 @@ void main() {
random: math.Random(0), random: math.Random(0),
); );
developmentShaderCompiler.configureCompiler( developmentShaderCompiler.configureCompiler(TargetPlatform.android);
TargetPlatform.android,
impellerStatus: ImpellerStatus.enabled, 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 final DevFSContent? content = await developmentShaderCompiler
.recompileShader(DevFSFileContent(fileSystem.file(fragPath))); .recompileShader(DevFSFileContent(fileSystem.file(fragPath)));
@ -419,10 +505,7 @@ void main() {
random: math.Random(0), random: math.Random(0),
); );
developmentShaderCompiler.configureCompiler( developmentShaderCompiler.configureCompiler(TargetPlatform.web_javascript);
TargetPlatform.web_javascript,
impellerStatus: ImpellerStatus.disabled,
);
final DevFSContent? content = await developmentShaderCompiler final DevFSContent? content = await developmentShaderCompiler
.recompileShader(DevFSFileContent(fileSystem.file(fragPath))); .recompileShader(DevFSFileContent(fileSystem.file(fragPath)));

View File

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

View File

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

View File

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

View File

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

View File

@ -1475,10 +1475,7 @@ class FakeShaderCompiler implements DevelopmentShaderCompiler {
const FakeShaderCompiler(); const FakeShaderCompiler();
@override @override
void configureCompiler( void configureCompiler(TargetPlatform? platform) { }
TargetPlatform? platform, {
required ImpellerStatus impellerStatus,
}) { }
@override @override
Future<DevFSContent> recompileShader(DevFSContent inputShader) { 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/compile.dart';
import 'package:flutter_tools/src/convert.dart'; import 'package:flutter_tools/src/convert.dart';
import 'package:flutter_tools/src/devfs.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/globals.dart' as globals;
import 'package:flutter_tools/src/html_utils.dart'; import 'package:flutter_tools/src/html_utils.dart';
import 'package:flutter_tools/src/isolated/devfs_web.dart'; import 'package:flutter_tools/src/isolated/devfs_web.dart';
@ -1309,10 +1308,7 @@ class FakeShaderCompiler implements DevelopmentShaderCompiler {
const FakeShaderCompiler(); const FakeShaderCompiler();
@override @override
void configureCompiler( void configureCompiler(TargetPlatform? platform) { }
TargetPlatform? platform, {
required ImpellerStatus impellerStatus,
}) { }
@override @override
Future<DevFSContent> recompileShader(DevFSContent inputShader) { 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/file_system.dart';
import 'package:flutter_tools/src/base/logger.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/build_system/targets/shader_compiler.dart';
import 'package:flutter_tools/src/globals.dart' as globals; import 'package:flutter_tools/src/globals.dart' as globals;
@ -32,8 +33,7 @@ void main() {
await shaderCompiler.compileShader( await shaderCompiler.compileShader(
input: file, input: file,
outputPath: tmpDir.childFile('test_shader.frag.out').path, outputPath: tmpDir.childFile('test_shader.frag.out').path,
target: ShaderTarget.sksl, targetPlatform: TargetPlatform.tester,
json: false,
); );
} }
@ -62,8 +62,7 @@ void main() {
final bool compileResult = await shaderCompiler.compileShader( final bool compileResult = await shaderCompiler.compileShader(
input: globals.fs.file(inkSparklePath), input: globals.fs.file(inkSparklePath),
outputPath: inkSparkleOutputPath, outputPath: inkSparkleOutputPath,
target: ShaderTarget.sksl, targetPlatform: TargetPlatform.tester,
json: false,
); );
final File resultFile = globals.fs.file(inkSparkleOutputPath); final File resultFile = globals.fs.file(inkSparkleOutputPath);