From c417c4623cb6d30bc3de0bc9003585e8b844322a Mon Sep 17 00:00:00 2001 From: Dan Field Date: Wed, 31 Jan 2024 13:30:02 -0800 Subject: [PATCH] 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. --- .../lib/src/build_system/targets/android.dart | 2 - .../lib/src/build_system/targets/assets.dart | 5 +- .../lib/src/build_system/targets/common.dart | 1 - .../lib/src/build_system/targets/ios.dart | 3 - .../lib/src/build_system/targets/linux.dart | 2 - .../lib/src/build_system/targets/macos.dart | 2 - .../build_system/targets/shader_compiler.dart | 87 +++-- .../lib/src/build_system/targets/web.dart | 2 - .../lib/src/build_system/targets/windows.dart | 2 - .../flutter_tools/lib/src/bundle_builder.dart | 8 +- packages/flutter_tools/lib/src/run_hot.dart | 5 +- .../test/general.shard/asset_bundle_test.dart | 2 + .../build_system/targets/android_test.dart | 1 + .../build_system/targets/ios_test.dart | 1 + .../targets/shader_compiler_test.dart | 309 +++++++++++------- .../test/general.shard/cold_test.dart | 5 +- .../test/general.shard/devfs_test.dart | 6 +- .../test/general.shard/hot_test.dart | 5 +- .../general.shard/resident_runner_test.dart | 5 +- .../resident_web_runner_test.dart | 5 +- .../general.shard/terminal_handler_test.dart | 5 +- .../general.shard/web/devfs_web_test.dart | 6 +- .../shader_compiler_test.dart | 7 +- 23 files changed, 250 insertions(+), 226 deletions(-) diff --git a/packages/flutter_tools/lib/src/build_system/targets/android.dart b/packages/flutter_tools/lib/src/build_system/targets/android.dart index 8254234de2..d1b7dc62a3 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/android.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/android.dart @@ -15,7 +15,6 @@ import '../exceptions.dart'; import 'assets.dart'; import 'common.dart'; import 'icon_tree_shaker.dart'; -import 'shader_compiler.dart'; /// Prepares the asset bundle in the format expected by flutter.gradle. /// @@ -68,7 +67,6 @@ abstract class AndroidAssetBundle extends Target { outputDirectory, targetPlatform: TargetPlatform.android, buildMode: buildMode, - shaderTarget: ShaderTarget.impellerAndroid, flavor: environment.defines[kFlavor], ); environment.depFileService.writeToFile( diff --git a/packages/flutter_tools/lib/src/build_system/targets/assets.dart b/packages/flutter_tools/lib/src/build_system/targets/assets.dart index a8a96e7e7f..8b5d8275a9 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/assets.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/assets.dart @@ -32,7 +32,6 @@ Future copyAssets( Map additionalContent = const {}, required TargetPlatform targetPlatform, BuildMode? buildMode, - required ShaderTarget shaderTarget, List additionalInputs = const [], String? flavor, }) async { @@ -140,8 +139,7 @@ Future copyAssets( doCopy = !await shaderCompiler.compileShader( input: content.file as File, outputPath: file.path, - target: shaderTarget, - json: targetPlatform == TargetPlatform.web_javascript, + targetPlatform: targetPlatform, ); case AssetKind.model: doCopy = !await sceneImporter.importScene( @@ -328,7 +326,6 @@ class CopyAssets extends Target { environment, output, targetPlatform: TargetPlatform.android, - shaderTarget: ShaderTarget.sksl, flavor: environment.defines[kFlavor], ); environment.depFileService.writeToFile( diff --git a/packages/flutter_tools/lib/src/build_system/targets/common.dart b/packages/flutter_tools/lib/src/build_system/targets/common.dart index fda26a4758..46f35b7e95 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/common.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/common.dart @@ -79,7 +79,6 @@ class CopyFlutterBundle extends Target { environment.outputDir, targetPlatform: TargetPlatform.android, buildMode: buildMode, - shaderTarget: ShaderTarget.sksl, flavor: flavor, ); environment.depFileService.writeToFile( diff --git a/packages/flutter_tools/lib/src/build_system/targets/ios.dart b/packages/flutter_tools/lib/src/build_system/targets/ios.dart index 0b8ddfbada..f05a91e350 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/ios.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/ios.dart @@ -503,9 +503,6 @@ abstract class IosAssetBundle extends Target { environment, assetDirectory, 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: [ flutterProject.ios.infoPlist, flutterProject.ios.appFrameworkInfoPlist, diff --git a/packages/flutter_tools/lib/src/build_system/targets/linux.dart b/packages/flutter_tools/lib/src/build_system/targets/linux.dart index 0c7e1d85e0..bc446c5fa6 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/linux.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/linux.dart @@ -15,7 +15,6 @@ import 'assets.dart'; import 'common.dart'; import 'desktop.dart'; import 'icon_tree_shaker.dart'; -import 'shader_compiler.dart'; /// The only files/subdirectories we care out. const List _kLinuxArtifacts = [ @@ -141,7 +140,6 @@ abstract class BundleLinuxAssets extends Target { additionalContent: { 'version.json': DevFSStringContent(versionInfo), }, - shaderTarget: ShaderTarget.sksl, ); environment.depFileService.writeToFile( depfile, diff --git a/packages/flutter_tools/lib/src/build_system/targets/macos.dart b/packages/flutter_tools/lib/src/build_system/targets/macos.dart index 0881169ea0..7f69f52fa8 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/macos.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/macos.dart @@ -18,7 +18,6 @@ import '../exceptions.dart'; import 'assets.dart'; import 'common.dart'; import 'icon_tree_shaker.dart'; -import 'shader_compiler.dart'; /// Copy the macOS framework to the correct copy dir by invoking 'rsync'. /// @@ -439,7 +438,6 @@ abstract class MacOSBundleFlutterAssets extends Target { environment, assetDirectory, targetPlatform: TargetPlatform.darwin, - shaderTarget: ShaderTarget.sksl, flavor: environment.defines[kFlavor], ); environment.depFileService.writeToFile( diff --git a/packages/flutter_tools/lib/src/build_system/targets/shader_compiler.dart b/packages/flutter_tools/lib/src/build_system/targets/shader_compiler.dart index c03ef892e7..4c9d48fb77 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/shader_compiler.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/shader_compiler.dart @@ -17,21 +17,8 @@ import '../../base/logger.dart'; import '../../build_info.dart'; import '../../convert.dart'; import '../../devfs.dart'; -import '../../device.dart'; import '../build_system.dart'; -/// The output shader format that should be used by the [ShaderCompiler]. -enum ShaderTarget { - impellerAndroid(['--runtime-stage-gles', '--runtime-stage-vulkan']), - impelleriOS(['--runtime-stage-metal']), - impellerSwiftShader(['--runtime-stage-vulkan']), - sksl(['--sksl']); - - const ShaderTarget(this.stages); - - final List stages; -} - /// A wrapper around [ShaderCompiler] to support hot reload of shader sources. class DevelopmentShaderCompiler { DevelopmentShaderCompiler({ @@ -47,42 +34,16 @@ class DevelopmentShaderCompiler { final Pool _compilationPool = Pool(4); final math.Random _random; - late ShaderTarget _shaderTarget; + late TargetPlatform _targetPlatform; bool _debugConfigured = false; - bool _jsonMode = false; /// Configure the output format of the shader compiler for a particular /// flutter device. - void configureCompiler(TargetPlatform? platform, { required ImpellerStatus impellerStatus }) { - switch (platform) { - 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; + void configureCompiler(TargetPlatform? platform) { + if (platform == null) { + return; } + _targetPlatform = platform; _debugConfigured = true; } @@ -107,9 +68,8 @@ class DevelopmentShaderCompiler { final bool success = await _shaderCompiler.compileShader( input: inputFile, outputPath: output.path, - target: _shaderTarget, + targetPlatform: _targetPlatform, fatal: false, - json: _jsonMode, ); if (!success) { return null; @@ -144,6 +104,34 @@ class ShaderCompiler { final FileSystem _fs; final Artifacts _artifacts; + List _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 ['--sksl', '--runtime-stage-gles', '--runtime-stage-vulkan']; + + case TargetPlatform.ios: + case TargetPlatform.darwin: + return ['--sksl', '--runtime-stage-metal']; + + case TargetPlatform.fuchsia_arm64: + case TargetPlatform.fuchsia_x64: + case TargetPlatform.tester: + return ['--sksl', '--runtime-stage-vulkan']; + + case TargetPlatform.web_javascript: + return ['--sksl']; + + } + } + /// The [Source] inputs that targets using this should depend on. /// /// See [Target.inputs]. @@ -163,9 +151,8 @@ class ShaderCompiler { Future compileShader({ required File input, required String outputPath, - required ShaderTarget target, + required TargetPlatform targetPlatform, bool fatal = true, - required bool json, }) async { final File impellerc = _fs.file( _artifacts.getHostArtifact(HostArtifact.impellerc), @@ -180,9 +167,9 @@ class ShaderCompiler { final String shaderLibPath = _fs.path.join(impellerc.parent.absolute.path, 'shader_lib'); final List cmd = [ impellerc.path, - ...target.stages, + ..._shaderTargetsFromTargetPlatform(targetPlatform), '--iplr', - if (json) + if (targetPlatform == TargetPlatform.web_javascript) '--json', '--sl=$outputPath', '--spirv=$outputPath.spirv', diff --git a/packages/flutter_tools/lib/src/build_system/targets/web.dart b/packages/flutter_tools/lib/src/build_system/targets/web.dart index 0c650b91dc..28413c44d6 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/web.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/web.dart @@ -28,7 +28,6 @@ import '../depfile.dart'; import '../exceptions.dart'; import 'assets.dart'; import 'localizations.dart'; -import 'shader_compiler.dart'; /// Whether the application has web plugins. const String kHasWebPlugins = 'HasWebPlugins'; @@ -395,7 +394,6 @@ class WebReleaseBundle extends Target { environment, environment.outputDir.childDirectory('assets'), targetPlatform: TargetPlatform.web_javascript, - shaderTarget: ShaderTarget.sksl, ); final DepfileService depfileService = environment.depFileService; depfileService.writeToFile( diff --git a/packages/flutter_tools/lib/src/build_system/targets/windows.dart b/packages/flutter_tools/lib/src/build_system/targets/windows.dart index 983eb5cee8..ada0afe5b5 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/windows.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/windows.dart @@ -12,7 +12,6 @@ import 'assets.dart'; import 'common.dart'; import 'desktop.dart'; import 'icon_tree_shaker.dart'; -import 'shader_compiler.dart'; /// The only files/subdirectories we care about. const List _kWindowsArtifacts = [ @@ -143,7 +142,6 @@ abstract class BundleWindowsAssets extends Target { environment, outputDirectory, targetPlatform: targetPlatform, - shaderTarget: ShaderTarget.sksl, ); environment.depFileService.writeToFile( depfile, diff --git a/packages/flutter_tools/lib/src/bundle_builder.dart b/packages/flutter_tools/lib/src/bundle_builder.dart index b2fb4ce601..f8d204db63 100644 --- a/packages/flutter_tools/lib/src/bundle_builder.dart +++ b/packages/flutter_tools/lib/src/bundle_builder.dart @@ -169,11 +169,6 @@ Future writeBundle( 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. final Pool pool = Pool(64); await Future.wait( @@ -200,8 +195,7 @@ Future writeBundle( doCopy = !await shaderCompiler.compileShader( input: input, outputPath: file.path, - target: shaderTarget, - json: targetPlatform == TargetPlatform.web_javascript, + targetPlatform: targetPlatform, ); case AssetKind.model: doCopy = !await sceneImporter.importScene( diff --git a/packages/flutter_tools/lib/src/run_hot.dart b/packages/flutter_tools/lib/src/run_hot.dart index 12d8aafc0e..5f7cc6aa71 100644 --- a/packages/flutter_tools/lib/src/run_hot.dart +++ b/packages/flutter_tools/lib/src/run_hot.dart @@ -268,10 +268,7 @@ class HotRunner extends ResidentRunner { await device!.initLogReader(); device .developmentShaderCompiler - .configureCompiler( - device.targetPlatform, - impellerStatus: debuggingOptions.enableImpeller, - ); + .configureCompiler(device.targetPlatform); } try { final List baseUris = await _initDevFS(); diff --git a/packages/flutter_tools/test/general.shard/asset_bundle_test.dart b/packages/flutter_tools/test/general.shard/asset_bundle_test.dart index 3ea8959273..1a9f02e8d0 100644 --- a/packages/flutter_tools/test/general.shard/asset_bundle_test.dart +++ b/packages/flutter_tools/test/general.shard/asset_bundle_test.dart @@ -672,6 +672,8 @@ flutter: command: [ impellerc, '--sksl', + '--runtime-stage-gles', + '--runtime-stage-vulkan', '--iplr', '--sl=$outputPath', '--spirv=$outputPath.spirv', diff --git a/packages/flutter_tools/test/general.shard/build_system/targets/android_test.dart b/packages/flutter_tools/test/general.shard/build_system/targets/android_test.dart index 21c8b0f59e..a69aeed750 100644 --- a/packages/flutter_tools/test/general.shard/build_system/targets/android_test.dart +++ b/packages/flutter_tools/test/general.shard/build_system/targets/android_test.dart @@ -535,6 +535,7 @@ void main() { processManager.addCommands([ const FakeCommand(command: [ 'HostArtifact.impellerc', + '--sksl', '--runtime-stage-gles', '--runtime-stage-vulkan', '--iplr', diff --git a/packages/flutter_tools/test/general.shard/build_system/targets/ios_test.dart b/packages/flutter_tools/test/general.shard/build_system/targets/ios_test.dart index ccffea131a..33bf54e29a 100644 --- a/packages/flutter_tools/test/general.shard/build_system/targets/ios_test.dart +++ b/packages/flutter_tools/test/general.shard/build_system/targets/ios_test.dart @@ -287,6 +287,7 @@ void main() { processManager.addCommands([ const FakeCommand(command: [ 'HostArtifact.impellerc', + '--sksl', '--runtime-stage-metal', '--iplr', '--sl=/App.framework/flutter_assets/shader.glsl', diff --git a/packages/flutter_tools/test/general.shard/build_system/targets/shader_compiler_test.dart b/packages/flutter_tools/test/general.shard/build_system/targets/shader_compiler_test.dart index bf238eb446..a1b6cec356 100644 --- a/packages/flutter_tools/test/general.shard/build_system/targets/shader_compiler_test.dart +++ b/packages/flutter_tools/test/general.shard/build_system/targets/shader_compiler_test.dart @@ -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( command: [ 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: [ 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: [ 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: [ 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([1, 2, 3, 4]); - } - ), - ]); - fileSystem.file(fragPath).writeAsBytesSync([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(), [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( - command: [ - 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([1, 2, 3, 4]); - } - ), - ]); - fileSystem.file(fragPath).writeAsBytesSync([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(), [1, 2, 3, 4]); - expect(processManager.hasRemainingExpectations, false); - }); - - testWithoutContext('DevelopmentShaderCompiler can compile for android with impeller', () async { - final FakeProcessManager processManager = FakeProcessManager.list([ - FakeCommand( - command: [ - 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(), [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( + command: [ + 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([1, 2, 3, 4]); + } + ), + ]); + fileSystem.file(fragPath).writeAsBytesSync([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(), [1, 2, 3, 4]); + expect(processManager.hasRemainingExpectations, false); + }); + + testWithoutContext('DevelopmentShaderCompiler can compile for android with impeller', () async { + final FakeProcessManager processManager = FakeProcessManager.list([ + FakeCommand( + command: [ + 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([1, 2, 3, 4]); + } + ), + ]); + fileSystem.file(fragPath).writeAsBytesSync([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(), [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( + command: [ + 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 args) { + fileSystem.file('/.tmp_rand0/0.8255140718871702.temp.spirv').createSync(); + fileSystem.file('/.tmp_rand0/0.8255140718871702.temp') + ..createSync() + ..writeAsBytesSync([1, 2, 3, 4]); + } + ), + ]); + fileSystem.file(fragPath).writeAsBytesSync([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(), [1, 2, 3, 4]); + expect(processManager.hasRemainingExpectations, false); + }); + + testWithoutContext('DevelopmentShaderCompiler can compile for android with impeller', () async { + final FakeProcessManager processManager = FakeProcessManager.list([ + FakeCommand( + command: [ + 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 args) { + fileSystem.file('/.tmp_rand0/0.8255140718871702.temp.spirv').createSync(); + fileSystem.file('/.tmp_rand0/0.8255140718871702.temp') + ..createSync() + ..writeAsBytesSync([1, 2, 3, 4]); + } + ), + ]); + fileSystem.file(fragPath).writeAsBytesSync([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))); diff --git a/packages/flutter_tools/test/general.shard/cold_test.dart b/packages/flutter_tools/test/general.shard/cold_test.dart index 7ebb61a2e4..7b819057f7 100644 --- a/packages/flutter_tools/test/general.shard/cold_test.dart +++ b/packages/flutter_tools/test/general.shard/cold_test.dart @@ -279,10 +279,7 @@ class FakeShaderCompiler implements DevelopmentShaderCompiler { const FakeShaderCompiler(); @override - void configureCompiler( - TargetPlatform? platform, { - required ImpellerStatus impellerStatus, - }) { } + void configureCompiler(TargetPlatform? platform) { } @override Future recompileShader(DevFSContent inputShader) { diff --git a/packages/flutter_tools/test/general.shard/devfs_test.dart b/packages/flutter_tools/test/general.shard/devfs_test.dart index 475a208969..63473bd25b 100644 --- a/packages/flutter_tools/test/general.shard/devfs_test.dart +++ b/packages/flutter_tools/test/general.shard/devfs_test.dart @@ -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 recompileShader(DevFSContent inputShader) async { diff --git a/packages/flutter_tools/test/general.shard/hot_test.dart b/packages/flutter_tools/test/general.shard/hot_test.dart index 327c686f92..df9becfea3 100644 --- a/packages/flutter_tools/test/general.shard/hot_test.dart +++ b/packages/flutter_tools/test/general.shard/hot_test.dart @@ -967,10 +967,7 @@ class FakeShaderCompiler implements DevelopmentShaderCompiler { const FakeShaderCompiler(); @override - void configureCompiler( - TargetPlatform? platform, { - required ImpellerStatus impellerStatus, - }) { } + void configureCompiler(TargetPlatform? platform) { } @override Future recompileShader(DevFSContent inputShader) { diff --git a/packages/flutter_tools/test/general.shard/resident_runner_test.dart b/packages/flutter_tools/test/general.shard/resident_runner_test.dart index 497fd3b3cf..5e6834ca03 100644 --- a/packages/flutter_tools/test/general.shard/resident_runner_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_runner_test.dart @@ -2957,10 +2957,7 @@ class FakeShaderCompiler implements DevelopmentShaderCompiler { const FakeShaderCompiler(); @override - void configureCompiler( - TargetPlatform? platform, { - required ImpellerStatus impellerStatus, - }) { } + void configureCompiler(TargetPlatform? platform) { } @override Future recompileShader(DevFSContent inputShader) { diff --git a/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart b/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart index 592d75b20c..00c0bbbe5a 100644 --- a/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart @@ -1756,10 +1756,7 @@ class FakeShaderCompiler implements DevelopmentShaderCompiler { const FakeShaderCompiler(); @override - void configureCompiler( - TargetPlatform? platform, { - required ImpellerStatus impellerStatus, - }) { } + void configureCompiler(TargetPlatform? platform) { } @override Future recompileShader(DevFSContent inputShader) { diff --git a/packages/flutter_tools/test/general.shard/terminal_handler_test.dart b/packages/flutter_tools/test/general.shard/terminal_handler_test.dart index 87ab451d96..cdc19c22da 100644 --- a/packages/flutter_tools/test/general.shard/terminal_handler_test.dart +++ b/packages/flutter_tools/test/general.shard/terminal_handler_test.dart @@ -1475,10 +1475,7 @@ class FakeShaderCompiler implements DevelopmentShaderCompiler { const FakeShaderCompiler(); @override - void configureCompiler( - TargetPlatform? platform, { - required ImpellerStatus impellerStatus, - }) { } + void configureCompiler(TargetPlatform? platform) { } @override Future recompileShader(DevFSContent inputShader) { diff --git a/packages/flutter_tools/test/general.shard/web/devfs_web_test.dart b/packages/flutter_tools/test/general.shard/web/devfs_web_test.dart index 7a9ce0476d..5034959c2e 100644 --- a/packages/flutter_tools/test/general.shard/web/devfs_web_test.dart +++ b/packages/flutter_tools/test/general.shard/web/devfs_web_test.dart @@ -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 recompileShader(DevFSContent inputShader) { diff --git a/packages/flutter_tools/test/integration.shard/shader_compiler_test.dart b/packages/flutter_tools/test/integration.shard/shader_compiler_test.dart index 53a3bb350b..b0da068b83 100644 --- a/packages/flutter_tools/test/integration.shard/shader_compiler_test.dart +++ b/packages/flutter_tools/test/integration.shard/shader_compiler_test.dart @@ -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);