From e9c6212da02ab7edc39cc0295f72df4a40f0d2ba Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Mon, 14 Nov 2022 21:38:46 -0800 Subject: [PATCH] [Impeller] Add shader include with FlutterFragCoord for use by FragmentProgram (#114214) --- .../flutter/lib/src/material/shaders/ink_sparkle.frag | 4 +++- .../lib/src/build_system/targets/shader_compiler.dart | 5 ++++- .../test/general.shard/asset_bundle_test.dart | 5 +++++ .../general.shard/build_system/targets/ios_test.dart | 3 ++- .../build_system/targets/shader_compiler_test.dart | 9 +++++++++ 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/flutter/lib/src/material/shaders/ink_sparkle.frag b/packages/flutter/lib/src/material/shaders/ink_sparkle.frag index b94541d352..aa82583921 100644 --- a/packages/flutter/lib/src/material/shaders/ink_sparkle.frag +++ b/packages/flutter/lib/src/material/shaders/ink_sparkle.frag @@ -6,6 +6,8 @@ precision highp float; +#include + // TODO(antrob): Put these in a more logical order (e.g. separate consts vs varying, etc) layout(location = 0) uniform vec4 u_color; @@ -88,7 +90,7 @@ float turbulence(vec2 uv) { } void main() { - vec2 p = gl_FragCoord.xy; + vec2 p = FlutterFragCoord(); vec2 uv = p * u_resolution_scale; vec2 density_uv = uv - mod(p, u_noise_scale); float radius = u_max_radius * u_radius_scale; 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 a1721a097c..611c4fb240 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 @@ -54,7 +54,7 @@ class DevelopmentShaderCompiler { void configureCompiler(TargetPlatform? platform, { required bool enableImpeller }) { switch (platform) { case TargetPlatform.ios: - _shaderTarget = enableImpeller ? ShaderTarget.impelleriOS : ShaderTarget.sksl; + _shaderTarget = ShaderTarget.impelleriOS; break; case TargetPlatform.android_arm64: case TargetPlatform.android_x64: @@ -175,6 +175,8 @@ class ShaderCompiler { ); } + final String shaderLibPath = _fs.path.join(_fs.path.dirname(impellerc.path), 'shader_lib'); + final List cmd = [ impellerc.path, target.target, @@ -186,6 +188,7 @@ class ShaderCompiler { '--input=${input.path}', '--input-type=frag', '--include=${input.parent.path}', + '--include=$shaderLibPath', ]; final Process impellercProcess = await _processManager.start(cmd); final int code = await impellercProcess.exitCode; 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 61d31e6364..8c90a1a43e 100644 --- a/packages/flutter_tools/test/general.shard/asset_bundle_test.dart +++ b/packages/flutter_tools/test/general.shard/asset_bundle_test.dart @@ -17,6 +17,8 @@ import 'package:flutter_tools/src/globals.dart' as globals; import '../src/common.dart'; import '../src/context.dart'; +const String shaderLibDir = './shader_lib'; + void main() { group('AssetBundle.build', () { late FileSystem testFileSystem; @@ -452,6 +454,7 @@ flutter: '--input=/$shaderPath', '--input-type=frag', '--include=/$assetsPath', + '--include=$shaderLibDir', ], onRun: () { fileSystem.file(outputPath).createSync(recursive: true); @@ -498,6 +501,7 @@ flutter: '--input=/$shaderPath', '--input-type=frag', '--include=/$assetsPath', + '--include=$shaderLibDir', ], onRun: () { fileSystem.file(outputPath).createSync(recursive: true); @@ -538,6 +542,7 @@ flutter: '--input=${fileSystem.path.join(materialDir.path, 'shaders', 'ink_sparkle.frag')}', '--input-type=frag', '--include=${fileSystem.path.join(materialDir.path, 'shaders')}', + '--include=$shaderLibDir', ], onRun: () { fileSystem.file(outputPath).createSync(recursive: true); 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 2c02c8e5a1..04f48425c1 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 @@ -262,7 +262,8 @@ void main() { '--spirv=/App.framework/flutter_assets/shader.glsl.spirv', '--input=/shader.glsl', '--input-type=frag', - '--include=/' + '--include=/', + '--include=./shader_lib', ]), FakeCommand(command: [ 'codesign', 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 198bebb328..b6dc1df516 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 @@ -16,6 +16,7 @@ import '../../../src/common.dart'; import '../../../src/fake_process_manager.dart'; const String fragDir = '/shaders'; +const String shaderLibDir = './shader_lib'; const String fragPath = '/shaders/my_shader.frag'; const String notFragPath = '/shaders/not_a_frag.file'; const String outputSpirvPath = '/output/shaders/my_shader.frag.spirv'; @@ -50,6 +51,7 @@ void main() { '--input=$fragPath', '--input-type=frag', '--include=$fragDir', + '--include=$shaderLibDir', ], onRun: () { fileSystem.file(outputPath).createSync(recursive: true); @@ -89,6 +91,7 @@ void main() { '--input=$fragPath', '--input-type=frag', '--include=$fragDir', + '--include=$shaderLibDir', ], onRun: () { fileSystem.file(outputPath).createSync(recursive: true); @@ -126,6 +129,7 @@ void main() { '--input=$fragPath', '--input-type=frag', '--include=$fragDir', + '--include=$shaderLibDir', ], onRun: () { fileSystem.file(outputPath).createSync(recursive: true); @@ -163,6 +167,7 @@ void main() { '--input=$notFragPath', '--input-type=frag', '--include=$fragDir', + '--include=$shaderLibDir', ], onRun: () { fileSystem.file(outputPath).createSync(recursive: true); @@ -202,6 +207,7 @@ void main() { '--input=$notFragPath', '--input-type=frag', '--include=$fragDir', + '--include=$shaderLibDir', ], stdout: 'impellerc stdout', stderr: 'impellerc stderr', @@ -243,6 +249,7 @@ void main() { '--input=$fragPath', '--input-type=frag', '--include=$fragDir', + '--include=$shaderLibDir', ], onRun: () { fileSystem.file('/.tmp_rand0/0.8255140718871702.temp.spirv').createSync(); @@ -287,6 +294,7 @@ void main() { '--input=$fragPath', '--input-type=frag', '--include=$fragDir', + '--include=$shaderLibDir', ], onRun: () { fileSystem.file('/.tmp_rand0/0.8255140718871702.temp.spirv').createSync(); @@ -332,6 +340,7 @@ void main() { '--input=$fragPath', '--input-type=frag', '--include=$fragDir', + '--include=$shaderLibDir', ], onRun: () { fileSystem.file('/.tmp_rand0/0.8255140718871702.temp.spirv').createSync();