Skip to content

Commit e4e902d

Browse files
[flutter_tools] add compilation failure tests for new cases added in impellerc (#114757)
1 parent f1cdfa2 commit e4e902d

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

packages/flutter_tools/test/integration.shard/shader_compiler_test.dart

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,26 @@ void main() {
1717
logger = BufferLogger.test();
1818
});
1919

20+
Future<void> testCompileShader(String source) async {
21+
final Directory tmpDir = globals.fs.systemTempDirectory.createTempSync(
22+
'shader_compiler_test.',
23+
);
24+
final File file = tmpDir.childFile('test_shader.frag')
25+
..writeAsStringSync(source);
26+
final ShaderCompiler shaderCompiler = ShaderCompiler(
27+
processManager: globals.processManager,
28+
logger: logger,
29+
fileSystem: globals.fs,
30+
artifacts: globals.artifacts!,
31+
);
32+
await shaderCompiler.compileShader(
33+
input: file,
34+
outputPath: tmpDir.childFile('test_shader.frag.out').path,
35+
target: ShaderTarget.sksl,
36+
json: false,
37+
);
38+
}
39+
2040
testUsingContext('impellerc .iplr output has correct permissions', () async {
2141
if (globals.platform.isWindows) {
2242
return;
@@ -54,4 +74,66 @@ void main() {
5474
final int expectedMode = int.parse('644', radix: 8);
5575
expect(resultFile.statSync().mode & expectedMode, equals(expectedMode));
5676
});
77+
78+
testUsingContext('Compilation error with in storage', () async {
79+
const String kShaderWithInput = '''
80+
in float foo;
81+
82+
out vec4 fragColor;
83+
84+
void main() {
85+
fragColor = vec4(1.0, 0.0, 0.0, 1.0);
86+
}
87+
''';
88+
89+
expect(() => testCompileShader(kShaderWithInput), throwsA(isA<ShaderCompilerException>()
90+
.having(
91+
(ShaderCompilerException exception) => exception.message,
92+
'message',
93+
contains('SkSL does not support inputs'),
94+
),
95+
));
96+
});
97+
98+
testUsingContext('Compilation error with UBO', () async {
99+
const String kShaderWithInput = '''
100+
uniform Data {
101+
vec4 foo;
102+
} data;
103+
104+
out vec4 fragColor;
105+
106+
void main() {
107+
fragColor = data.foo;
108+
}
109+
''';
110+
111+
expect(() => testCompileShader(kShaderWithInput), throwsA(isA<ShaderCompilerException>()
112+
.having(
113+
(ShaderCompilerException exception) => exception.message,
114+
'message',
115+
contains('SkSL does not support UBOs or SSBOs'),
116+
),
117+
));
118+
});
119+
120+
testUsingContext('Compilation error with texture arguments besides position or sampler', () async {
121+
const String kShaderWithInput = '''
122+
uniform sampler2D tex;
123+
124+
out vec4 fragColor;
125+
126+
void main() {
127+
fragColor = texture(tex, vec2(0.5, 0.3), 0.5);
128+
}
129+
''';
130+
131+
expect(() => testCompileShader(kShaderWithInput), throwsA(isA<ShaderCompilerException>()
132+
.having(
133+
(ShaderCompilerException exception) => exception.message,
134+
'message',
135+
contains('Only sampler and position arguments are supported in texture() calls'),
136+
),
137+
));
138+
});
57139
}

0 commit comments

Comments
 (0)