2021-01-25 15:57:47 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2021 Google LLC
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkData.h"
|
|
|
|
#include "include/core/SkFont.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/effects/SkGradientShader.h"
|
|
|
|
#include "include/effects/SkImageFilters.h"
|
|
|
|
#include "include/effects/SkRuntimeEffect.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
|
|
|
#include "tests/Test.h"
|
|
|
|
#include "tools/Resources.h"
|
|
|
|
#include "tools/ToolUtils.h"
|
|
|
|
|
|
|
|
static const SkRect kRect = SkRect::MakeWH(1, 1);
|
|
|
|
|
2021-01-26 21:28:12 +00:00
|
|
|
template <typename T>
|
|
|
|
static void set_uniform(SkRuntimeShaderBuilder* builder, const char* name, const T& value) {
|
|
|
|
SkRuntimeShaderBuilder::BuilderUniform uniform = builder->uniform(name);
|
|
|
|
if (uniform.fVar) {
|
|
|
|
uniform = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-25 15:57:47 +00:00
|
|
|
static void test(skiatest::Reporter* r, SkSurface* surface, const char* testFile) {
|
|
|
|
SkString resourcePath = SkStringPrintf("sksl/%s", testFile);
|
|
|
|
sk_sp<SkData> shaderData = GetResourceAsData(resourcePath.c_str());
|
|
|
|
if (!shaderData) {
|
|
|
|
ERRORF(r, "%s: Unable to load file", testFile);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkString shaderString{reinterpret_cast<const char*>(shaderData->bytes()), shaderData->size()};
|
|
|
|
auto [effect, error] = SkRuntimeEffect::Make(shaderString);
|
|
|
|
if (!effect) {
|
|
|
|
ERRORF(r, "%s: %s", testFile, error.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkRuntimeShaderBuilder builder(effect);
|
2021-01-29 16:44:13 +00:00
|
|
|
set_uniform(&builder, "colorBlack", SkV4{0, 0, 0, 1});
|
|
|
|
set_uniform(&builder, "colorRed", SkV4{1, 0, 0, 1});
|
|
|
|
set_uniform(&builder, "colorGreen", SkV4{0, 1, 0, 1});
|
|
|
|
set_uniform(&builder, "colorBlue", SkV4{0, 0, 1, 1});
|
|
|
|
set_uniform(&builder, "colorWhite", SkV4{1, 1, 1, 1});
|
|
|
|
set_uniform(&builder, "testInputs", SkV4{-1.25, 0, 0.75, 2.25});
|
|
|
|
set_uniform(&builder, "unknownInput", 1.0f);
|
2021-01-26 21:28:12 +00:00
|
|
|
|
2021-01-25 15:57:47 +00:00
|
|
|
sk_sp<SkShader> shader = builder.makeShader(/*localMatrix=*/nullptr, /*isOpaque=*/true);
|
|
|
|
if (!shader) {
|
|
|
|
ERRORF(r, "%s: Unable to build shader", testFile);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkPaint paintShader;
|
|
|
|
paintShader.setShader(shader);
|
|
|
|
surface->getCanvas()->drawRect(kRect, paintShader);
|
|
|
|
|
|
|
|
SkBitmap bitmap;
|
|
|
|
REPORTER_ASSERT(r, bitmap.tryAllocPixels(surface->imageInfo()));
|
|
|
|
REPORTER_ASSERT(r, surface->readPixels(bitmap.info(), bitmap.getPixels(), bitmap.rowBytes(),
|
|
|
|
/*srcX=*/0, /*srcY=*/0));
|
|
|
|
|
|
|
|
SkColor color = bitmap.getColor(0, 0);
|
|
|
|
REPORTER_ASSERT(r, color == SkColorSetARGB(0xFF, 0x00, 0xFF, 0x00),
|
|
|
|
"Expected: solid green. Actual: A=%02X R=%02X G=%02X B=%02X.",
|
|
|
|
SkColorGetA(color), SkColorGetR(color), SkColorGetG(color), SkColorGetB(color));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_cpu(skiatest::Reporter* r, const char* testFile) {
|
|
|
|
const SkImageInfo info = SkImageInfo::MakeN32Premul(kRect.width(), kRect.height());
|
|
|
|
sk_sp<SkSurface> surface(SkSurface::MakeRaster(info));
|
|
|
|
|
|
|
|
test(r, surface.get(), testFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_gpu(skiatest::Reporter* r, GrDirectContext* ctx, const char* testFile) {
|
|
|
|
const SkImageInfo info = SkImageInfo::MakeN32Premul(kRect.width(), kRect.height());
|
|
|
|
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info));
|
|
|
|
|
|
|
|
test(r, surface.get(), testFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SKSL_TEST(name, path) \
|
|
|
|
DEF_TEST(name ## _CPU, r) { \
|
|
|
|
test_cpu(r, path); \
|
|
|
|
} \
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(name ## _GPU, r, ctxInfo) { \
|
|
|
|
test_gpu(r, ctxInfo.directContext(), path); \
|
|
|
|
}
|
|
|
|
|
|
|
|
SKSL_TEST(SkSLBoolFolding, "folding/BoolFolding.sksl")
|
|
|
|
SKSL_TEST(SkSLIntFoldingES2, "folding/IntFoldingES2.sksl")
|
2021-01-25 18:04:12 +00:00
|
|
|
SKSL_TEST(SkSLFloatFolding, "folding/FloatFolding.sksl")
|
2021-01-25 15:57:47 +00:00
|
|
|
SKSL_TEST(SkSLMatrixFoldingES2, "folding/MatrixFoldingES2.sksl")
|
|
|
|
SKSL_TEST(SkSLShortCircuitBoolFolding, "folding/ShortCircuitBoolFolding.sksl")
|
|
|
|
SKSL_TEST(SkSLVectorScalarFolding, "folding/VectorScalarFolding.sksl")
|
|
|
|
SKSL_TEST(SkSLVectorVectorFolding, "folding/VectorVectorFolding.sksl")
|
|
|
|
|
2021-01-29 16:44:13 +00:00
|
|
|
SKSL_TEST(SkSLIntrinsicAbsFloat, "intrinsics/AbsFloat.sksl")
|
|
|
|
SKSL_TEST(SkSLIntrinsicCeil, "intrinsics/Ceil.sksl")
|
Implement additional Runtime Effect intrinsic tests.
Tested in dm:
- max(halfN, halfN)
- max(halfN, half)
- min(halfN, halfN)
- min(halfN, half)
- clamp(halfN, halfN, halfN)
- clamp(halfN, half, half)
- mix(halfN, halfN, halfN)
- mix(halfN, halfN, half)
Compiled outputs only (not in ES2):
- max(intN, intN)
- max(intN, int)
- min(intN, intN)
- min(intN, int)
- clamp(intN, intN, intN)
- clamp(intN, int, int)
- mix(halfN, halfN, boolN) - broken in Metal/SPIR-V (skia:11222)
- mix(intN, intN, boolN) - broken in Metal/SPIR-V (skia:11222)
Change-Id: Iaafc5429b16d2a8710b9d171ae281c268c0fd70d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/361438
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2021-01-29 16:51:47 +00:00
|
|
|
SKSL_TEST(SkSLIntrinsicClampFloat, "intrinsics/ClampFloat.sksl")
|
|
|
|
SKSL_TEST(SkSLIntrinsicMaxFloat, "intrinsics/MaxFloat.sksl")
|
|
|
|
SKSL_TEST(SkSLIntrinsicMinFloat, "intrinsics/MinFloat.sksl")
|
|
|
|
SKSL_TEST(SkSLIntrinsicMixFloat, "intrinsics/MixFloat.sksl")
|
2021-01-29 16:44:13 +00:00
|
|
|
SKSL_TEST(SkSLIntrinsicSignFloat, "intrinsics/SignFloat.sksl")
|
|
|
|
|
2021-01-27 14:56:04 +00:00
|
|
|
SKSL_TEST(SkSLForLoopControlFlow, "shared/ForLoopControlFlow.sksl")
|
|
|
|
|
2021-01-29 16:44:13 +00:00
|
|
|
/*
|
|
|
|
TODO(johnstiles): work around failures on ANGLE + Intel6000 + DX9 configuration and reland
|
|
|
|
SKSL_TEST(SkSLIntrinsicFloor, "intrinsics/Floor.sksl")
|
|
|
|
*/
|
|
|
|
|
2021-01-27 18:53:43 +00:00
|
|
|
/*
|
|
|
|
TODO(skia:10939): enable this test when Runtime Effects supports structs in function signatures
|
|
|
|
SKSL_TEST(SkSLStructsInFunctions, "shared/StructsInFunctions.sksl")
|
|
|
|
*/
|
|
|
|
|
2021-01-25 15:57:47 +00:00
|
|
|
/*
|
|
|
|
TODO(skia:11209): enable these tests when Runtime Effects have support for ES3
|
|
|
|
|
|
|
|
SKSL_TEST(SkSLIntFoldingES3, "folding/IntFoldingES3.sksl")
|
|
|
|
SKSL_TEST(SkSLMatrixFoldingES3, "folding/MatrixFoldingES3.sksl")
|
2021-01-27 14:56:04 +00:00
|
|
|
|
2021-01-29 16:44:13 +00:00
|
|
|
SKSL_TEST(SkSLIntrinsicAbsInt, "intrinsics/AbsInt.sksl")
|
Implement additional Runtime Effect intrinsic tests.
Tested in dm:
- max(halfN, halfN)
- max(halfN, half)
- min(halfN, halfN)
- min(halfN, half)
- clamp(halfN, halfN, halfN)
- clamp(halfN, half, half)
- mix(halfN, halfN, halfN)
- mix(halfN, halfN, half)
Compiled outputs only (not in ES2):
- max(intN, intN)
- max(intN, int)
- min(intN, intN)
- min(intN, int)
- clamp(intN, intN, intN)
- clamp(intN, int, int)
- mix(halfN, halfN, boolN) - broken in Metal/SPIR-V (skia:11222)
- mix(intN, intN, boolN) - broken in Metal/SPIR-V (skia:11222)
Change-Id: Iaafc5429b16d2a8710b9d171ae281c268c0fd70d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/361438
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2021-01-29 16:51:47 +00:00
|
|
|
SKSL_TEST(SkSLIntrinsicClampInt, "intrinsics/ClampInt.sksl")
|
|
|
|
SKSL_TEST(SkSLIntrinsicMaxInt, "intrinsics/MaxInt.sksl")
|
|
|
|
SKSL_TEST(SkSLIntrinsicMinInt, "intrinsics/MinInt.sksl")
|
|
|
|
SKSL_TEST(SkSLIntrinsicMixBool, "intrinsics/MixBool.sksl")
|
2021-01-29 16:44:13 +00:00
|
|
|
SKSL_TEST(SkSLIntrinsicSignInt, "intrinsics/SignInt.sksl")
|
|
|
|
|
2021-01-27 14:56:04 +00:00
|
|
|
SKSL_TEST(SkSLDoWhileControlFlow, "shared/DoWhileControlFlow.sksl")
|
|
|
|
SKSL_TEST(SkSLWhileLoopControlFlow, "shared/WhileLoopControlFlow.sksl")
|
2021-01-25 15:57:47 +00:00
|
|
|
*/
|