Disallow returning array types in SkSL.
This is illegal in older versions of GLSL and in Metal. We now fail at SkSL compilation time and properly report the error. Change-Id: I6ddaeabff5386a1ed6ca3eb8703a6035476ec77a Bug: skia:11021 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/339298 Commit-Queue: John Stiles <johnstiles@google.com> Reviewed-by: Brian Osman <brianosman@google.com> Auto-Submit: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
3dba3ee465
commit
076e9a2f34
@ -72,6 +72,7 @@ sksl_error_tests = [
|
||||
"$_tests/sksl/errors/ArgumentCountMismatch.sksl",
|
||||
"$_tests/sksl/errors/ArgumentMismatch.sksl",
|
||||
"$_tests/sksl/errors/ArgumentModifiers.sksl",
|
||||
"$_tests/sksl/errors/ArrayReturnTypes.sksl",
|
||||
"$_tests/sksl/errors/ArrayTooManyDimensions.sksl",
|
||||
"$_tests/sksl/errors/ArrayUnspecifiedDimensions.sksl",
|
||||
"$_tests/sksl/errors/AssignmentTypeMismatch.sksl",
|
||||
@ -189,7 +190,6 @@ sksl_shared_tests = [
|
||||
"$_tests/sksl/shared/ArrayConstructors.sksl",
|
||||
"$_tests/sksl/shared/ArrayIndexTypes.sksl",
|
||||
"$_tests/sksl/shared/ArrayMaxDimensions.sksl",
|
||||
"$_tests/sksl/shared/ArrayReturnTypes.sksl",
|
||||
"$_tests/sksl/shared/ArrayTypes.sksl",
|
||||
"$_tests/sksl/shared/Assignment.sksl",
|
||||
"$_tests/sksl/shared/BoolFolding.sksl",
|
||||
|
@ -877,7 +877,7 @@ void IRGenerator::convertFunction(const ASTNode& f) {
|
||||
if (returnType == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto type_is_allowed = [&](const Type* t) {
|
||||
auto typeIsAllowed = [&](const Type* t) {
|
||||
#if defined(SKSL_STANDALONE)
|
||||
return true;
|
||||
#else
|
||||
@ -887,7 +887,8 @@ void IRGenerator::convertFunction(const ASTNode& f) {
|
||||
#endif
|
||||
};
|
||||
if (returnType->nonnullable() == *fContext.fFragmentProcessor_Type ||
|
||||
!type_is_allowed(returnType)) {
|
||||
returnType->typeKind() == Type::TypeKind::kArray ||
|
||||
!typeIsAllowed(returnType)) {
|
||||
fErrors.error(f.fOffset,
|
||||
"functions may not return type '" + returnType->displayName() + "'");
|
||||
return;
|
||||
@ -916,7 +917,7 @@ void IRGenerator::convertFunction(const ASTNode& f) {
|
||||
|
||||
// Only the (builtin) declarations of 'sample' are allowed to have FP parameters
|
||||
if ((type->nonnullable() == *fContext.fFragmentProcessor_Type && !fIsBuiltinCode) ||
|
||||
!type_is_allowed(type)) {
|
||||
!typeIsAllowed(type)) {
|
||||
fErrors.error(param.fOffset,
|
||||
"parameters of type '" + type->displayName() + "' not allowed");
|
||||
return;
|
||||
|
@ -601,13 +601,13 @@ DEF_TEST(SkSLInterpreterCompound, r) {
|
||||
"RectAndColor copy_big(RectAndColor r) { RectAndColor s; s = r; return s; }\n"
|
||||
|
||||
// Same for arrays, including some non-constant indexing
|
||||
"float tempFloats[8];\n"
|
||||
"int median(int a[15]) { return a[7]; }\n"
|
||||
"float[8] sums(float a[8]) {\n"
|
||||
" float tempFloats[8];\n"
|
||||
|
||||
"float tempFloats[8];\n"
|
||||
"float sums(float a[8]) {\n"
|
||||
" tempFloats[0] = a[0];\n"
|
||||
" for (int i = 1; i < 8; ++i) { tempFloats[i] = tempFloats[i - 1] + a[i]; }\n"
|
||||
" return tempFloats;\n"
|
||||
" return tempFloats[7];\n"
|
||||
"}\n"
|
||||
|
||||
// Uniforms, array-of-structs, dynamic indices
|
||||
@ -671,11 +671,9 @@ DEF_TEST(SkSLInterpreterCompound, r) {
|
||||
|
||||
{
|
||||
float in[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
|
||||
float out[8] = { 0 };
|
||||
SkAssertResult(byteCode->run(sums, in, 8, out, 8, fRects, 16));
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
REPORTER_ASSERT(r, out[i] == static_cast<float>((i + 1) * (i + 2) / 2));
|
||||
}
|
||||
float out = 0;
|
||||
SkAssertResult(byteCode->run(sums, in, 8, &out, 1, fRects, 16));
|
||||
REPORTER_ASSERT(r, out == static_cast<float>((7 + 1) * (7 + 2) / 2));
|
||||
}
|
||||
|
||||
{
|
||||
|
2
tests/sksl/errors/ArrayReturnTypes.sksl
Normal file
2
tests/sksl/errors/ArrayReturnTypes.sksl
Normal file
@ -0,0 +1,2 @@
|
||||
half[2][4] return_half_2_2() {}
|
||||
int[1] return_int_1() {}
|
5
tests/sksl/errors/golden/ArrayReturnTypes.glsl
Normal file
5
tests/sksl/errors/golden/ArrayReturnTypes.glsl
Normal file
@ -0,0 +1,5 @@
|
||||
### Compilation failed:
|
||||
|
||||
error: 1: functions may not return type 'half[2][4]'
|
||||
error: 2: functions may not return type 'int[1]'
|
||||
2 errors
|
@ -1,7 +0,0 @@
|
||||
half[2][2] fn2() { return half[2][2](half[2](1, 2), half[2](3, 4)); }
|
||||
half[2][2] fn() { return fn2(); }
|
||||
|
||||
void main() {
|
||||
half[2][2] x = fn();
|
||||
sk_FragColor = half4(x[0][0], x[0][1], x[1][0], x[1][1]);
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
OpCapability Shader
|
||||
%1 = OpExtInstImport "GLSL.std.450"
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint Fragment %main "main" %sk_FragColor %sk_Clockwise
|
||||
OpExecutionMode %main OriginUpperLeft
|
||||
OpName %sk_FragColor "sk_FragColor"
|
||||
OpName %sk_Clockwise "sk_Clockwise"
|
||||
OpName %main "main"
|
||||
OpDecorate %sk_FragColor RelaxedPrecision
|
||||
OpDecorate %sk_FragColor Location 0
|
||||
OpDecorate %sk_FragColor Index 0
|
||||
OpDecorate %sk_Clockwise RelaxedPrecision
|
||||
OpDecorate %sk_Clockwise BuiltIn FrontFacing
|
||||
OpDecorate %_arr_float_int_2 ArrayStride 16
|
||||
OpDecorate %_arr__arr_float_int_2_int_2 ArrayStride 32
|
||||
OpDecorate %29 RelaxedPrecision
|
||||
OpDecorate %36 RelaxedPrecision
|
||||
OpDecorate %42 RelaxedPrecision
|
||||
OpDecorate %48 RelaxedPrecision
|
||||
%float = OpTypeFloat 32
|
||||
%v4float = OpTypeVector %float 4
|
||||
%_ptr_Output_v4float = OpTypePointer Output %v4float
|
||||
%sk_FragColor = OpVariable %_ptr_Output_v4float Output
|
||||
%bool = OpTypeBool
|
||||
%_ptr_Input_bool = OpTypePointer Input %bool
|
||||
%sk_Clockwise = OpVariable %_ptr_Input_bool Input
|
||||
%void = OpTypeVoid
|
||||
%11 = OpTypeFunction %void
|
||||
%int = OpTypeInt 32 1
|
||||
%int_2 = OpConstant %int 2
|
||||
%_arr_float_int_2 = OpTypeArray %float %int_2
|
||||
%_arr__arr_float_int_2_int_2 = OpTypeArray %_arr_float_int_2 %int_2
|
||||
%_ptr_Function__arr__arr_float_int_2_int_2 = OpTypePointer Function %_arr__arr_float_int_2_int_2
|
||||
%float_1 = OpConstant %float 1
|
||||
%float_2 = OpConstant %float 2
|
||||
%float_3 = OpConstant %float 3
|
||||
%float_4 = OpConstant %float 4
|
||||
%int_0 = OpConstant %int 0
|
||||
%_ptr_Function_float = OpTypePointer Function %float
|
||||
%int_1 = OpConstant %int 1
|
||||
%main = OpFunction %void None %11
|
||||
%12 = OpLabel
|
||||
%13 = OpVariable %_ptr_Function__arr__arr_float_int_2_int_2 Function
|
||||
%30 = OpVariable %_ptr_Function__arr__arr_float_int_2_int_2 Function
|
||||
%37 = OpVariable %_ptr_Function__arr__arr_float_int_2_int_2 Function
|
||||
%43 = OpVariable %_ptr_Function__arr__arr_float_int_2_int_2 Function
|
||||
%21 = OpCompositeConstruct %_arr_float_int_2 %float_1 %float_2
|
||||
%24 = OpCompositeConstruct %_arr_float_int_2 %float_3 %float_4
|
||||
%25 = OpCompositeConstruct %_arr__arr_float_int_2_int_2 %21 %24
|
||||
OpStore %13 %25
|
||||
%27 = OpAccessChain %_ptr_Function_float %13 %int_0 %int_0
|
||||
%29 = OpLoad %float %27
|
||||
%31 = OpCompositeConstruct %_arr_float_int_2 %float_1 %float_2
|
||||
%32 = OpCompositeConstruct %_arr_float_int_2 %float_3 %float_4
|
||||
%33 = OpCompositeConstruct %_arr__arr_float_int_2_int_2 %31 %32
|
||||
OpStore %30 %33
|
||||
%35 = OpAccessChain %_ptr_Function_float %30 %int_0 %int_1
|
||||
%36 = OpLoad %float %35
|
||||
%38 = OpCompositeConstruct %_arr_float_int_2 %float_1 %float_2
|
||||
%39 = OpCompositeConstruct %_arr_float_int_2 %float_3 %float_4
|
||||
%40 = OpCompositeConstruct %_arr__arr_float_int_2_int_2 %38 %39
|
||||
OpStore %37 %40
|
||||
%41 = OpAccessChain %_ptr_Function_float %37 %int_1 %int_0
|
||||
%42 = OpLoad %float %41
|
||||
%44 = OpCompositeConstruct %_arr_float_int_2 %float_1 %float_2
|
||||
%45 = OpCompositeConstruct %_arr_float_int_2 %float_3 %float_4
|
||||
%46 = OpCompositeConstruct %_arr__arr_float_int_2_int_2 %44 %45
|
||||
OpStore %43 %46
|
||||
%47 = OpAccessChain %_ptr_Function_float %43 %int_1 %int_1
|
||||
%48 = OpLoad %float %47
|
||||
%49 = OpCompositeConstruct %v4float %29 %36 %42 %48
|
||||
OpStore %sk_FragColor %49
|
||||
OpReturn
|
||||
OpFunctionEnd
|
@ -1,5 +0,0 @@
|
||||
|
||||
out vec4 sk_FragColor;
|
||||
void main() {
|
||||
sk_FragColor = vec4(float[2][2](float[2](1.0, 2.0), float[2](3.0, 4.0))[0][0], float[2][2](float[2](1.0, 2.0), float[2](3.0, 4.0))[0][1], float[2][2](float[2](1.0, 2.0), float[2](3.0, 4.0))[1][0], float[2][2](float[2](1.0, 2.0), float[2](3.0, 4.0))[1][1]);
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
### Compilation failed:
|
||||
|
||||
error: 1: Metal does not support array types in this context
|
||||
error: 1: Metal does not support array types in this context
|
||||
error: 1: Metal does not support array types in this context
|
||||
error: 1: Metal does not support array types in this context
|
||||
error: 1: Metal does not support array types in this context
|
||||
error: 1: Metal does not support array types in this context
|
||||
error: 1: Metal does not support array types in this context
|
||||
error: 1: Metal does not support array types in this context
|
||||
error: 1: Metal does not support array types in this context
|
||||
error: 1: Metal does not support array types in this context
|
||||
error: 1: Metal does not support array types in this context
|
||||
error: 1: Metal does not support array types in this context
|
||||
12 errors
|
Loading…
Reference in New Issue
Block a user