Skip to content

Commit e9c6212

Browse files
authored
[Impeller] Add shader include with FlutterFragCoord for use by FragmentProgram (#114214)
1 parent 9d64a0f commit e9c6212

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

packages/flutter/lib/src/material/shaders/ink_sparkle.frag

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
precision highp float;
88

9+
#include <flutter/runtime_effect.glsl>
10+
911
// TODO(antrob): Put these in a more logical order (e.g. separate consts vs varying, etc)
1012

1113
layout(location = 0) uniform vec4 u_color;
@@ -88,7 +90,7 @@ float turbulence(vec2 uv) {
8890
}
8991

9092
void main() {
91-
vec2 p = gl_FragCoord.xy;
93+
vec2 p = FlutterFragCoord();
9294
vec2 uv = p * u_resolution_scale;
9395
vec2 density_uv = uv - mod(p, u_noise_scale);
9496
float radius = u_max_radius * u_radius_scale;

packages/flutter_tools/lib/src/build_system/targets/shader_compiler.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class DevelopmentShaderCompiler {
5454
void configureCompiler(TargetPlatform? platform, { required bool enableImpeller }) {
5555
switch (platform) {
5656
case TargetPlatform.ios:
57-
_shaderTarget = enableImpeller ? ShaderTarget.impelleriOS : ShaderTarget.sksl;
57+
_shaderTarget = ShaderTarget.impelleriOS;
5858
break;
5959
case TargetPlatform.android_arm64:
6060
case TargetPlatform.android_x64:
@@ -175,6 +175,8 @@ class ShaderCompiler {
175175
);
176176
}
177177

178+
final String shaderLibPath = _fs.path.join(_fs.path.dirname(impellerc.path), 'shader_lib');
179+
178180
final List<String> cmd = <String>[
179181
impellerc.path,
180182
target.target,
@@ -186,6 +188,7 @@ class ShaderCompiler {
186188
'--input=${input.path}',
187189
'--input-type=frag',
188190
'--include=${input.parent.path}',
191+
'--include=$shaderLibPath',
189192
];
190193
final Process impellercProcess = await _processManager.start(cmd);
191194
final int code = await impellercProcess.exitCode;

packages/flutter_tools/test/general.shard/asset_bundle_test.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import 'package:flutter_tools/src/globals.dart' as globals;
1717
import '../src/common.dart';
1818
import '../src/context.dart';
1919

20+
const String shaderLibDir = './shader_lib';
21+
2022
void main() {
2123
group('AssetBundle.build', () {
2224
late FileSystem testFileSystem;
@@ -452,6 +454,7 @@ flutter:
452454
'--input=/$shaderPath',
453455
'--input-type=frag',
454456
'--include=/$assetsPath',
457+
'--include=$shaderLibDir',
455458
],
456459
onRun: () {
457460
fileSystem.file(outputPath).createSync(recursive: true);
@@ -498,6 +501,7 @@ flutter:
498501
'--input=/$shaderPath',
499502
'--input-type=frag',
500503
'--include=/$assetsPath',
504+
'--include=$shaderLibDir',
501505
],
502506
onRun: () {
503507
fileSystem.file(outputPath).createSync(recursive: true);
@@ -538,6 +542,7 @@ flutter:
538542
'--input=${fileSystem.path.join(materialDir.path, 'shaders', 'ink_sparkle.frag')}',
539543
'--input-type=frag',
540544
'--include=${fileSystem.path.join(materialDir.path, 'shaders')}',
545+
'--include=$shaderLibDir',
541546
],
542547
onRun: () {
543548
fileSystem.file(outputPath).createSync(recursive: true);

packages/flutter_tools/test/general.shard/build_system/targets/ios_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ void main() {
262262
'--spirv=/App.framework/flutter_assets/shader.glsl.spirv',
263263
'--input=/shader.glsl',
264264
'--input-type=frag',
265-
'--include=/'
265+
'--include=/',
266+
'--include=./shader_lib',
266267
]),
267268
FakeCommand(command: <String>[
268269
'codesign',

packages/flutter_tools/test/general.shard/build_system/targets/shader_compiler_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import '../../../src/common.dart';
1616
import '../../../src/fake_process_manager.dart';
1717

1818
const String fragDir = '/shaders';
19+
const String shaderLibDir = './shader_lib';
1920
const String fragPath = '/shaders/my_shader.frag';
2021
const String notFragPath = '/shaders/not_a_frag.file';
2122
const String outputSpirvPath = '/output/shaders/my_shader.frag.spirv';
@@ -50,6 +51,7 @@ void main() {
5051
'--input=$fragPath',
5152
'--input-type=frag',
5253
'--include=$fragDir',
54+
'--include=$shaderLibDir',
5355
],
5456
onRun: () {
5557
fileSystem.file(outputPath).createSync(recursive: true);
@@ -89,6 +91,7 @@ void main() {
8991
'--input=$fragPath',
9092
'--input-type=frag',
9193
'--include=$fragDir',
94+
'--include=$shaderLibDir',
9295
],
9396
onRun: () {
9497
fileSystem.file(outputPath).createSync(recursive: true);
@@ -126,6 +129,7 @@ void main() {
126129
'--input=$fragPath',
127130
'--input-type=frag',
128131
'--include=$fragDir',
132+
'--include=$shaderLibDir',
129133
],
130134
onRun: () {
131135
fileSystem.file(outputPath).createSync(recursive: true);
@@ -163,6 +167,7 @@ void main() {
163167
'--input=$notFragPath',
164168
'--input-type=frag',
165169
'--include=$fragDir',
170+
'--include=$shaderLibDir',
166171
],
167172
onRun: () {
168173
fileSystem.file(outputPath).createSync(recursive: true);
@@ -202,6 +207,7 @@ void main() {
202207
'--input=$notFragPath',
203208
'--input-type=frag',
204209
'--include=$fragDir',
210+
'--include=$shaderLibDir',
205211
],
206212
stdout: 'impellerc stdout',
207213
stderr: 'impellerc stderr',
@@ -243,6 +249,7 @@ void main() {
243249
'--input=$fragPath',
244250
'--input-type=frag',
245251
'--include=$fragDir',
252+
'--include=$shaderLibDir',
246253
],
247254
onRun: () {
248255
fileSystem.file('/.tmp_rand0/0.8255140718871702.temp.spirv').createSync();
@@ -287,6 +294,7 @@ void main() {
287294
'--input=$fragPath',
288295
'--input-type=frag',
289296
'--include=$fragDir',
297+
'--include=$shaderLibDir',
290298
],
291299
onRun: () {
292300
fileSystem.file('/.tmp_rand0/0.8255140718871702.temp.spirv').createSync();
@@ -332,6 +340,7 @@ void main() {
332340
'--input=$fragPath',
333341
'--input-type=frag',
334342
'--include=$fragDir',
343+
'--include=$shaderLibDir',
335344
],
336345
onRun: () {
337346
fileSystem.file('/.tmp_rand0/0.8255140718871702.temp.spirv').createSync();

0 commit comments

Comments
 (0)