Skip to content

Commit

Permalink
[Impeller] Add shader include with FlutterFragCoord for use by Fragme…
Browse files Browse the repository at this point in the history
…ntProgram (#114214)
  • Loading branch information
bdero authored Nov 15, 2022
1 parent 9d64a0f commit e9c6212
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/flutter/lib/src/material/shaders/ink_sparkle.frag
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

precision highp float;

#include <flutter/runtime_effect.glsl>

// TODO(antrob): Put these in a more logical order (e.g. separate consts vs varying, etc)

layout(location = 0) uniform vec4 u_color;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -175,6 +175,8 @@ class ShaderCompiler {
);
}

final String shaderLibPath = _fs.path.join(_fs.path.dirname(impellerc.path), 'shader_lib');

final List<String> cmd = <String>[
impellerc.path,
target.target,
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -452,6 +454,7 @@ flutter:
'--input=/$shaderPath',
'--input-type=frag',
'--include=/$assetsPath',
'--include=$shaderLibDir',
],
onRun: () {
fileSystem.file(outputPath).createSync(recursive: true);
Expand Down Expand Up @@ -498,6 +501,7 @@ flutter:
'--input=/$shaderPath',
'--input-type=frag',
'--include=/$assetsPath',
'--include=$shaderLibDir',
],
onRun: () {
fileSystem.file(outputPath).createSync(recursive: true);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: <String>[
'codesign',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -50,6 +51,7 @@ void main() {
'--input=$fragPath',
'--input-type=frag',
'--include=$fragDir',
'--include=$shaderLibDir',
],
onRun: () {
fileSystem.file(outputPath).createSync(recursive: true);
Expand Down Expand Up @@ -89,6 +91,7 @@ void main() {
'--input=$fragPath',
'--input-type=frag',
'--include=$fragDir',
'--include=$shaderLibDir',
],
onRun: () {
fileSystem.file(outputPath).createSync(recursive: true);
Expand Down Expand Up @@ -126,6 +129,7 @@ void main() {
'--input=$fragPath',
'--input-type=frag',
'--include=$fragDir',
'--include=$shaderLibDir',
],
onRun: () {
fileSystem.file(outputPath).createSync(recursive: true);
Expand Down Expand Up @@ -163,6 +167,7 @@ void main() {
'--input=$notFragPath',
'--input-type=frag',
'--include=$fragDir',
'--include=$shaderLibDir',
],
onRun: () {
fileSystem.file(outputPath).createSync(recursive: true);
Expand Down Expand Up @@ -202,6 +207,7 @@ void main() {
'--input=$notFragPath',
'--input-type=frag',
'--include=$fragDir',
'--include=$shaderLibDir',
],
stdout: 'impellerc stdout',
stderr: 'impellerc stderr',
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit e9c6212

Please sign in to comment.