Unverified Commit f2745e97 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

When Impeller is enabled for flutter tester choose correct shader target. (#141391)

When compiling shaders for flutter tester, include Vulkan shaders when targeting Impeller.
parent 2da87e61
......@@ -24,6 +24,7 @@ import '../build_system.dart';
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);
......@@ -71,8 +72,9 @@ class DevelopmentShaderCompiler {
case TargetPlatform.fuchsia_arm64:
case TargetPlatform.fuchsia_x64:
case TargetPlatform.tester:
assert(impellerStatus != ImpellerStatus.enabled);
_shaderTarget = ShaderTarget.sksl;
_shaderTarget = impellerStatus == ImpellerStatus.enabled
? ShaderTarget.impellerSwiftShader
: ShaderTarget.sksl;
case TargetPlatform.web_javascript:
assert(impellerStatus != ImpellerStatus.enabled);
_shaderTarget = ShaderTarget.sksl;
......
......@@ -18,6 +18,7 @@ import 'build_system/targets/shader_compiler.dart';
import 'bundle.dart';
import 'cache.dart';
import 'devfs.dart';
import 'device.dart';
import 'globals.dart' as globals;
import 'project.dart';
......@@ -140,6 +141,7 @@ Future<void> writeBundle(
Map<String, AssetKind> entryKinds, {
Logger? loggerOverride,
required TargetPlatform targetPlatform,
required ImpellerStatus impellerStatus,
}) async {
loggerOverride ??= globals.logger;
if (bundleDir.existsSync()) {
......@@ -168,6 +170,11 @@ Future<void> 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<void>(
......@@ -195,7 +202,7 @@ Future<void> writeBundle(
doCopy = !await shaderCompiler.compileShader(
input: input,
outputPath: file.path,
target: ShaderTarget.sksl, // TODO(zanderso): configure impeller target when enabled.
target: shaderTarget,
json: targetPlatform == TargetPlatform.web_javascript,
);
case AssetKind.model:
......
......@@ -345,13 +345,6 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
);
}
String? testAssetDirectory;
if (buildTestAssets) {
await _buildTestAsset(flavor: buildInfo.flavor);
testAssetDirectory = globals.fs.path.
join(flutterProject.directory.path, 'build', 'unit_test_assets');
}
final bool startPaused = boolArg('start-paused');
if (startPaused && _testFileUris.length != 1) {
throwToolExit(
......@@ -360,6 +353,26 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
);
}
final DebuggingOptions debuggingOptions = DebuggingOptions.enabled(
buildInfo,
startPaused: startPaused,
disableServiceAuthCodes: boolArg('disable-service-auth-codes'),
serveObservatory: boolArg('serve-observatory'),
// On iOS >=14, keeping this enabled will leave a prompt on the screen.
disablePortPublication: true,
enableDds: enableDds,
nullAssertions: boolArg(FlutterOptions.kNullAssertions),
usingCISystem: usingCISystem,
enableImpeller: ImpellerStatus.fromBool(argResults!['enable-impeller'] as bool?),
);
String? testAssetDirectory;
if (buildTestAssets) {
await _buildTestAsset(flavor: buildInfo.flavor, impellerStatus: debuggingOptions.enableImpeller);
testAssetDirectory = globals.fs.path.
join(flutterProject.directory.path, 'build', 'unit_test_assets');
}
final String? concurrencyString = stringArg('concurrency');
int? jobs = concurrencyString == null ? null : int.tryParse(concurrencyString);
if (jobs != null && (jobs <= 0 || !jobs.isFinite)) {
......@@ -427,19 +440,6 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
watcher = collector;
}
final DebuggingOptions debuggingOptions = DebuggingOptions.enabled(
buildInfo,
startPaused: startPaused,
disableServiceAuthCodes: boolArg('disable-service-auth-codes'),
serveObservatory: boolArg('serve-observatory'),
// On iOS >=14, keeping this enabled will leave a prompt on the screen.
disablePortPublication: true,
enableDds: enableDds,
nullAssertions: boolArg(FlutterOptions.kNullAssertions),
usingCISystem: usingCISystem,
enableImpeller: ImpellerStatus.fromBool(argResults!['enable-impeller'] as bool?),
);
Device? integrationTestDevice;
if (_isIntegrationTest) {
integrationTestDevice = await findTargetDevice();
......@@ -569,6 +569,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
Future<void> _buildTestAsset({
required String? flavor,
required ImpellerStatus impellerStatus,
}) async {
final AssetBundle assetBundle = AssetBundleFactory.instance.createBundle();
final int build = await assetBundle.build(
......@@ -584,6 +585,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
assetBundle.entries,
assetBundle.entryKinds,
targetPlatform: TargetPlatform.tester,
impellerStatus: impellerStatus,
);
}
}
......
......@@ -32,6 +32,7 @@ import '../compile.dart';
import '../convert.dart';
import '../dart/package_map.dart';
import '../devfs.dart';
import '../device.dart';
import '../globals.dart' as globals;
import '../html_utils.dart';
import '../project.dart';
......@@ -885,6 +886,7 @@ class WebDevFS implements DevFS {
bundle.entries,
bundle.entryKinds,
targetPlatform: TargetPlatform.web_javascript,
impellerStatus: ImpellerStatus.disabled,
);
}
}
......
......@@ -16,6 +16,7 @@ import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/bundle_builder.dart';
import 'package:flutter_tools/src/cache.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/project.dart';
import 'package:standard_message_codec/standard_message_codec.dart';
......@@ -622,6 +623,7 @@ flutter:
<String, AssetKind>{},
loggerOverride: testLogger,
targetPlatform: TargetPlatform.android,
impellerStatus: ImpellerStatus.disabled,
);
expect(testLogger.warningText, contains('Expected Error Text'));
......@@ -744,6 +746,7 @@ flutter:
bundle.entryKinds,
loggerOverride: testLogger,
targetPlatform: TargetPlatform.android,
impellerStatus: ImpellerStatus.disabled,
);
}, overrides: <Type, Generator>{
......@@ -790,6 +793,7 @@ flutter:
bundle.entryKinds,
loggerOverride: testLogger,
targetPlatform: TargetPlatform.web_javascript,
impellerStatus: ImpellerStatus.disabled,
);
}, overrides: <Type, Generator>{
......@@ -873,6 +877,7 @@ flutter:
bundle.entryKinds,
loggerOverride: testLogger,
targetPlatform: TargetPlatform.web_javascript,
impellerStatus: ImpellerStatus.disabled,
);
expect((globals.processManager as FakeProcessManager).hasRemainingExpectations, false);
}, overrides: <Type, Generator>{
......
......@@ -287,6 +287,53 @@ void main() {
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(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment