Unverified Commit dd20919a authored by Zachary Anderson's avatar Zachary Anderson Committed by GitHub

[flutter_tool] Build shaders as .iplr and use FragmentProgram.fromAsset for ink_sparkle (#108071)

parent cc62a5b9
...@@ -7,7 +7,6 @@ import 'dart:math' as math; ...@@ -7,7 +7,6 @@ import 'dart:math' as math;
import 'dart:typed_data'; import 'dart:typed_data';
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:vector_math/vector_math_64.dart'; import 'package:vector_math/vector_math_64.dart';
...@@ -522,16 +521,10 @@ class FragmentShaderManager { ...@@ -522,16 +521,10 @@ class FragmentShaderManager {
/// Creates an [FragmentShaderManager] with an [InkSparkle] effect. /// Creates an [FragmentShaderManager] with an [InkSparkle] effect.
static Future<FragmentShaderManager> inkSparkle() async { static Future<FragmentShaderManager> inkSparkle() async {
final FragmentShaderManager manager = FragmentShaderManager._(); final FragmentShaderManager manager = FragmentShaderManager._();
await manager._compile(); _program = ui.FragmentProgram.fromAsset('shaders/ink_sparkle.frag');
return manager; return manager;
} }
/// Compiles the spir-v bytecode into a shader program.
Future<void> _compile() async {
final ByteData data = await rootBundle.load('shaders/ink_sparkle.frag');
_program = await ui.FragmentProgram.compile(spirv: data.buffer);
}
/// Creates a shader with the original program and optional uniforms. /// Creates a shader with the original program and optional uniforms.
/// ///
/// A new shader must be made whenever the uniforms are updated. /// A new shader must be made whenever the uniforms are updated.
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'package:process/process.dart'; import 'package:process/process.dart';
import '../../artifacts.dart'; import '../../artifacts.dart';
import '../../base/error_handling_io.dart';
import '../../base/file_system.dart'; import '../../base/file_system.dart';
import '../../base/io.dart'; import '../../base/io.dart';
import '../../base/logger.dart'; import '../../base/logger.dart';
...@@ -64,8 +65,10 @@ class ShaderCompiler { ...@@ -64,8 +65,10 @@ class ShaderCompiler {
// TODO(zanderso): When impeller is enabled, the correct flags for the // TODO(zanderso): When impeller is enabled, the correct flags for the
// target backend will need to be passed. // target backend will need to be passed.
// https://github.com/flutter/flutter/issues/102853 // https://github.com/flutter/flutter/issues/102853
'--flutter-spirv', '--sksl',
'--spirv=$outputPath', '--iplr',
'--sl=$outputPath',
'--spirv=$outputPath.spirv',
'--input=${input.path}', '--input=${input.path}',
'--input-type=frag', '--input-type=frag',
'--include=${input.parent.path}', '--include=${input.parent.path}',
...@@ -81,6 +84,7 @@ class ShaderCompiler { ...@@ -81,6 +84,7 @@ class ShaderCompiler {
); );
} }
ErrorHandlingFileSystem.deleteIfExists(_fs.file('$outputPath.spirv'));
return true; return true;
} }
} }
......
...@@ -443,14 +443,17 @@ flutter: ...@@ -443,14 +443,17 @@ flutter:
FakeCommand( FakeCommand(
command: <String>[ command: <String>[
impellerc, impellerc,
'--flutter-spirv', '--sksl',
'--spirv=$outputPath', '--iplr',
'--sl=$outputPath',
'--spirv=$outputPath.spirv',
'--input=/$shaderPath', '--input=/$shaderPath',
'--input-type=frag', '--input-type=frag',
'--include=/$assetsPath', '--include=/$assetsPath',
], ],
onRun: () { onRun: () {
fileSystem.file(outputPath).createSync(recursive: true); fileSystem.file(outputPath).createSync(recursive: true);
fileSystem.file('$outputPath.spirv').createSync(recursive: true);
}, },
), ),
]), ]),
......
...@@ -13,7 +13,8 @@ import '../../../src/fake_process_manager.dart'; ...@@ -13,7 +13,8 @@ import '../../../src/fake_process_manager.dart';
const String fragDir = '/shaders'; const String fragDir = '/shaders';
const String fragPath = '/shaders/my_shader.frag'; const String fragPath = '/shaders/my_shader.frag';
const String notFragPath = '/shaders/not_a_frag.file'; const String notFragPath = '/shaders/not_a_frag.file';
const String outputPath = '/output/shaders/my_shader.spv'; const String outputSpirvPath = '/output/shaders/my_shader.frag.spirv';
const String outputPath = '/output/shaders/my_shader.frag';
void main() { void main() {
late BufferLogger logger; late BufferLogger logger;
...@@ -37,14 +38,17 @@ void main() { ...@@ -37,14 +38,17 @@ void main() {
FakeCommand( FakeCommand(
command: <String>[ command: <String>[
impellerc, impellerc,
'--flutter-spirv', '--sksl',
'--spirv=$outputPath', '--iplr',
'--sl=$outputPath',
'--spirv=$outputSpirvPath',
'--input=$fragPath', '--input=$fragPath',
'--input-type=frag', '--input-type=frag',
'--include=$fragDir', '--include=$fragDir',
], ],
onRun: () { onRun: () {
fileSystem.file(outputPath).createSync(recursive: true); fileSystem.file(outputPath).createSync(recursive: true);
fileSystem.file(outputSpirvPath).createSync(recursive: true);
}, },
), ),
]); ]);
...@@ -63,6 +67,7 @@ void main() { ...@@ -63,6 +67,7 @@ void main() {
true, true,
); );
expect(fileSystem.file(outputPath).existsSync(), true); expect(fileSystem.file(outputPath).existsSync(), true);
expect(fileSystem.file(outputSpirvPath).existsSync(), false);
}); });
testWithoutContext('compileShader invokes impellerc for non-.frag files', () async { testWithoutContext('compileShader invokes impellerc for non-.frag files', () async {
...@@ -70,14 +75,17 @@ void main() { ...@@ -70,14 +75,17 @@ void main() {
FakeCommand( FakeCommand(
command: <String>[ command: <String>[
impellerc, impellerc,
'--flutter-spirv', '--sksl',
'--spirv=$outputPath', '--iplr',
'--sl=$outputPath',
'--spirv=$outputSpirvPath',
'--input=$notFragPath', '--input=$notFragPath',
'--input-type=frag', '--input-type=frag',
'--include=$fragDir', '--include=$fragDir',
], ],
onRun: () { onRun: () {
fileSystem.file(outputPath).createSync(recursive: true); fileSystem.file(outputPath).createSync(recursive: true);
fileSystem.file(outputSpirvPath).createSync(recursive: true);
}, },
), ),
]); ]);
...@@ -96,6 +104,7 @@ void main() { ...@@ -96,6 +104,7 @@ void main() {
true, true,
); );
expect(fileSystem.file(outputPath).existsSync(), true); expect(fileSystem.file(outputPath).existsSync(), true);
expect(fileSystem.file(outputSpirvPath).existsSync(), false);
}); });
testWithoutContext('compileShader throws an exception when impellerc fails', () async { testWithoutContext('compileShader throws an exception when impellerc fails', () async {
...@@ -103,8 +112,10 @@ void main() { ...@@ -103,8 +112,10 @@ void main() {
FakeCommand( FakeCommand(
command: <String>[ command: <String>[
impellerc, impellerc,
'--flutter-spirv', '--sksl',
'--spirv=$outputPath', '--iplr',
'--sl=$outputPath',
'--spirv=$outputSpirvPath',
'--input=$notFragPath', '--input=$notFragPath',
'--input-type=frag', '--input-type=frag',
'--include=$fragDir', '--include=$fragDir',
......
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