Runtime effects: Detect calls to undefined functions

Previously, the CPU backend would catch this later (ByteCodeGenerator),
and the GPU backend would assert in expandFormatArgs (out-of-range
function index).

Change-Id: Ib84bf7c477ddcc9fd3091c5b106ebdd654e9a30b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/276000
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2020-03-09 11:53:24 -04:00 committed by Skia Commit-Bot
parent 39ca9734a7
commit 5f6b41e6d8
2 changed files with 22 additions and 14 deletions

View File

@ -1784,6 +1784,11 @@ std::unique_ptr<Expression> IRGenerator::call(int offset,
fErrors.error(offset, msg);
return nullptr;
}
if (fKind == Program::kPipelineStage_Kind && !function.fDefined && !function.fBuiltin) {
String msg = "call to undefined function '" + function.fName + "'";
fErrors.error(offset, msg);
return nullptr;
}
std::vector<const Type*> types;
const Type* returnType;
if (!function.determineFinalTypes(arguments, &types, &returnType)) {

View File

@ -14,9 +14,10 @@
#include <algorithm>
DEF_TEST(SkRuntimeEffectInvalidInputs, r) {
auto test = [r](const char* hdr, const char* expected) {
SkString src = SkStringPrintf("%s void main(float2 p, inout half4 color) {}", hdr);
DEF_TEST(SkRuntimeEffectInvalid, r) {
auto test = [r](const char* hdr, const char* body, const char* expected) {
SkString src = SkStringPrintf("%s void main(float2 p, inout half4 color) { %s }",
hdr, body);
auto[effect, errorText] = SkRuntimeEffect::Make(src);
REPORTER_ASSERT(r, !effect);
REPORTER_ASSERT(r, errorText.contains(expected),
@ -26,27 +27,29 @@ DEF_TEST(SkRuntimeEffectInvalidInputs, r) {
// Features that are only allowed in .fp files (key, in uniform, ctype, when, tracked).
// Ensure that these fail, and the error messages contain the relevant keyword.
test("layout(key) in bool Input;", "key");
test("in uniform float Input;", "in uniform");
test("layout(ctype=SkRect) float4 Input;", "ctype");
test("in bool Flag; layout(when=Flag) uniform float Input;", "when");
test("layout(tracked) uniform float Input;", "tracked");
test("layout(key) in bool Input;", "", "key");
test("in uniform float Input;", "", "in uniform");
test("layout(ctype=SkRect) float4 Input;", "", "ctype");
test("in bool Flag; layout(when=Flag) uniform float Input;", "", "when");
test("layout(tracked) uniform float Input;", "", "tracked");
// Runtime SkSL supports a limited set of uniform types. No samplers, for example:
test("uniform sampler2D s;", "sampler2D");
test("uniform sampler2D s;", "", "sampler2D");
// 'in' variables can't be arrays
test("in int Input[2];", "array");
test("in int Input[2];", "", "array");
// Type specific restrictions:
// 'bool', 'int' can't be 'uniform'
test("uniform bool Input;", "'uniform'");
test("uniform int Input;", "'uniform'");
test("uniform bool Input;", "", "'uniform'");
test("uniform int Input;", "", "'uniform'");
// vector and matrix types can't be 'in'
test("in float2 Input;", "'in'");
test("in half3x3 Input;", "'in'");
test("in float2 Input;", "", "'in'");
test("in half3x3 Input;", "", "'in'");
test("half missing();", "color.r = missing();", "undefined function");
}
// Our packing rules and unit test code here relies on this: