2019-05-31 21:06:53 +00:00
|
|
|
/*
|
2019-06-06 14:04:27 +00:00
|
|
|
* Copyright 2019 Google LLC
|
2019-05-31 21:06:53 +00:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
#include "bench/Benchmark.h"
|
2020-07-08 18:12:43 +00:00
|
|
|
#include "bench/ResultsWriter.h"
|
|
|
|
#include "bench/SkSLBench.h"
|
2020-11-06 14:28:04 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "src/gpu/GrCaps.h"
|
|
|
|
#include "src/gpu/GrRecordingContextPriv.h"
|
|
|
|
#include "src/gpu/mock/GrMockCaps.h"
|
2019-05-31 21:06:53 +00:00
|
|
|
#include "src/sksl/SkSLCompiler.h"
|
2020-11-06 14:28:04 +00:00
|
|
|
#include "src/sksl/SkSLIRGenerator.h"
|
|
|
|
#include "src/sksl/SkSLParser.h"
|
2019-05-31 21:06:53 +00:00
|
|
|
|
2020-09-29 19:08:55 +00:00
|
|
|
class SkSLCompilerStartupBench : public Benchmark {
|
|
|
|
protected:
|
|
|
|
const char* onGetName() override {
|
|
|
|
return "sksl_compiler_startup";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isSuitableFor(Backend backend) override {
|
|
|
|
return backend == kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2020-11-18 20:38:39 +00:00
|
|
|
GrShaderCaps caps(GrContextOptions{});
|
2020-09-29 19:08:55 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2020-11-18 20:38:39 +00:00
|
|
|
SkSL::Compiler compiler(&caps);
|
2020-09-29 19:08:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_BENCH(return new SkSLCompilerStartupBench();)
|
|
|
|
|
2020-11-06 14:28:04 +00:00
|
|
|
enum class Output {
|
|
|
|
kNone,
|
|
|
|
kGLSL,
|
|
|
|
kMetal,
|
|
|
|
kSPIRV
|
|
|
|
};
|
|
|
|
|
|
|
|
class SkSLCompileBench : public Benchmark {
|
2019-05-31 21:06:53 +00:00
|
|
|
public:
|
2020-11-06 14:28:04 +00:00
|
|
|
static const char* output_string(Output output) {
|
|
|
|
switch (output) {
|
|
|
|
case Output::kNone: return "";
|
|
|
|
case Output::kGLSL: return "glsl_";
|
|
|
|
case Output::kMetal: return "metal_";
|
|
|
|
case Output::kSPIRV: return "spirv_";
|
|
|
|
}
|
|
|
|
SkUNREACHABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkSLCompileBench(SkSL::String name, const char* src, bool optimize, Output output)
|
|
|
|
: fName(SkSL::String("sksl_") + (optimize ? "" : "unoptimized_") + output_string(output) +
|
|
|
|
name)
|
2020-11-02 17:26:22 +00:00
|
|
|
, fSrc(src)
|
2020-11-06 14:28:04 +00:00
|
|
|
, fCaps(GrContextOptions(), GrMockOptions())
|
|
|
|
, fCompiler(fCaps.shaderCaps())
|
|
|
|
, fOutput(output) {
|
|
|
|
fSettings.fOptimize = optimize;
|
|
|
|
// The test programs we compile don't follow Vulkan rules and thus produce invalid
|
|
|
|
// SPIR-V. This is harmless, so long as we don't try to validate them.
|
|
|
|
fSettings.fValidateSPIRV = false;
|
|
|
|
}
|
2019-05-31 21:06:53 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
const char* onGetName() override {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isSuitableFor(Backend backend) override {
|
|
|
|
return backend == kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
|
2020-11-06 14:28:04 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2019-05-31 21:06:53 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
|
|
|
std::unique_ptr<SkSL::Program> program = fCompiler.convertProgram(
|
2021-02-16 18:29:15 +00:00
|
|
|
SkSL::ProgramKind::kFragment,
|
2019-05-31 21:06:53 +00:00
|
|
|
fSrc,
|
|
|
|
fSettings);
|
2020-09-14 15:33:47 +00:00
|
|
|
if (fCompiler.errorCount()) {
|
2020-11-06 14:28:04 +00:00
|
|
|
SK_ABORT("shader compilation failed: %s\n", fCompiler.errorText().c_str());
|
|
|
|
}
|
|
|
|
SkSL::String result;
|
|
|
|
switch (fOutput) {
|
|
|
|
case Output::kNone: break;
|
|
|
|
case Output::kGLSL: SkAssertResult(fCompiler.toGLSL(*program, &result)); break;
|
|
|
|
case Output::kMetal: SkAssertResult(fCompiler.toMetal(*program, &result)); break;
|
|
|
|
case Output::kSPIRV: SkAssertResult(fCompiler.toSPIRV(*program, &result)); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkSL::String fName;
|
|
|
|
SkSL::String fSrc;
|
|
|
|
GrMockCaps fCaps;
|
|
|
|
SkSL::Compiler fCompiler;
|
|
|
|
SkSL::Program::Settings fSettings;
|
|
|
|
Output fOutput;
|
|
|
|
|
|
|
|
using INHERITED = Benchmark;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SkSLParseBench : public Benchmark {
|
|
|
|
public:
|
|
|
|
SkSLParseBench(SkSL::String name, const char* src)
|
|
|
|
: fName("sksl_parse_" + name)
|
|
|
|
, fSrc(src)
|
2020-11-18 20:38:39 +00:00
|
|
|
, fCaps(GrContextOptions())
|
|
|
|
, fCompiler(&fCaps) {}
|
2020-11-06 14:28:04 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
const char* onGetName() override {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isSuitableFor(Backend backend) override {
|
|
|
|
return backend == kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDelayedSetup() override {
|
2021-02-16 18:29:15 +00:00
|
|
|
SkSL::ParsedModule module = fCompiler.moduleForProgramKind(SkSL::ProgramKind::kFragment);
|
2020-11-06 14:28:04 +00:00
|
|
|
fCompiler.irGenerator().setSymbolTable(module.fSymbols);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
|
|
|
for (int i = 0; i < loops; i++) {
|
|
|
|
fCompiler.irGenerator().pushSymbolTable();
|
2021-06-15 15:42:07 +00:00
|
|
|
SkSL::Parser parser(fSrc, *fCompiler.irGenerator().symbolTable(), fCompiler);
|
2020-11-06 14:28:04 +00:00
|
|
|
parser.compilationUnit();
|
|
|
|
fCompiler.irGenerator().popSymbolTable();
|
|
|
|
if (fCompiler.errorCount()) {
|
|
|
|
SK_ABORT("shader compilation failed: %s\n", fCompiler.errorText().c_str());
|
2019-05-31 21:06:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkSL::String fName;
|
|
|
|
SkSL::String fSrc;
|
2020-11-18 20:38:39 +00:00
|
|
|
GrShaderCaps fCaps;
|
2019-05-31 21:06:53 +00:00
|
|
|
SkSL::Compiler fCompiler;
|
|
|
|
SkSL::Program::Settings fSettings;
|
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = Benchmark;
|
2019-05-31 21:06:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2020-11-06 14:28:04 +00:00
|
|
|
#define COMPILER_BENCH(name, text) \
|
|
|
|
static constexpr char name ## _SRC[] = text; \
|
|
|
|
DEF_BENCH(return new SkSLParseBench(#name, name ## _SRC);) \
|
|
|
|
DEF_BENCH(return new SkSLCompileBench(#name, name ## _SRC, /*optimize=*/false, Output::kNone);) \
|
|
|
|
DEF_BENCH(return new SkSLCompileBench(#name, name ## _SRC, /*optimize=*/true, Output::kNone);) \
|
|
|
|
DEF_BENCH(return new SkSLCompileBench(#name, name ## _SRC, /*optimize=*/true, Output::kGLSL);) \
|
|
|
|
DEF_BENCH(return new SkSLCompileBench(#name, name ## _SRC, /*optimize=*/true, Output::kMetal);) \
|
|
|
|
DEF_BENCH(return new SkSLCompileBench(#name, name ## _SRC, /*optimize=*/true, Output::kSPIRV);)
|
|
|
|
|
2021-03-15 22:04:05 +00:00
|
|
|
// This fragment shader is from the third tile on the top row of GM_gradients_2pt_conical_outside.
|
2020-11-06 14:28:04 +00:00
|
|
|
COMPILER_BENCH(large, R"(
|
2021-03-15 22:04:05 +00:00
|
|
|
layout(set=0, binding=0) uniform half urange_Stage1_c0;
|
|
|
|
layout(set=0, binding=0) uniform half4 uleftBorderColor_Stage1_c0_c0_c0;
|
|
|
|
layout(set=0, binding=0) uniform half4 urightBorderColor_Stage1_c0_c0_c0;
|
|
|
|
layout(set=0, binding=0) uniform float3x3 umatrix_Stage1_c0_c0_c0_c0;
|
|
|
|
layout(set=0, binding=0) uniform half2 ufocalParams_Stage1_c0_c0_c0_c0_c0;
|
|
|
|
layout(set=0, binding=0) uniform float4 uscale0_1_Stage1_c0_c0_c0_c1;
|
|
|
|
layout(set=0, binding=0) uniform float4 uscale2_3_Stage1_c0_c0_c0_c1;
|
|
|
|
layout(set=0, binding=0) uniform float4 uscale4_5_Stage1_c0_c0_c0_c1;
|
|
|
|
layout(set=0, binding=0) uniform float4 uscale6_7_Stage1_c0_c0_c0_c1;
|
|
|
|
layout(set=0, binding=0) uniform float4 ubias0_1_Stage1_c0_c0_c0_c1;
|
|
|
|
layout(set=0, binding=0) uniform float4 ubias2_3_Stage1_c0_c0_c0_c1;
|
|
|
|
layout(set=0, binding=0) uniform float4 ubias4_5_Stage1_c0_c0_c0_c1;
|
|
|
|
layout(set=0, binding=0) uniform float4 ubias6_7_Stage1_c0_c0_c0_c1;
|
|
|
|
layout(set=0, binding=0) uniform half4 uthresholds1_7_Stage1_c0_c0_c0_c1;
|
|
|
|
layout(set=0, binding=0) uniform half4 uthresholds9_13_Stage1_c0_c0_c0_c1;
|
2020-09-30 13:29:13 +00:00
|
|
|
flat in half4 vcolor_Stage0;
|
2021-03-15 22:04:05 +00:00
|
|
|
noperspective in float2 vTransformedCoords_0_Stage0;
|
2020-09-30 13:29:13 +00:00
|
|
|
out half4 sk_FragColor;
|
2021-03-15 22:04:05 +00:00
|
|
|
half4 TwoPointConicalGradientLayout_Stage1_c0_c0_c0_c0_c0(half4 _input)
|
2020-09-30 13:29:13 +00:00
|
|
|
{
|
|
|
|
float t = -1.0;
|
|
|
|
half v = 1.0;
|
|
|
|
@switch (2)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
half r0_2 = ufocalParams_Stage1_c0_c0_c0_c0_c0.y;
|
2020-09-30 13:29:13 +00:00
|
|
|
t = float(r0_2) - vTransformedCoords_0_Stage0.y * vTransformedCoords_0_Stage0.y;
|
|
|
|
if (t >= 0.0)
|
|
|
|
{
|
|
|
|
t = vTransformedCoords_0_Stage0.x + sqrt(t);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
v = -1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
half r0 = ufocalParams_Stage1_c0_c0_c0_c0_c0.x;
|
2020-09-30 13:29:13 +00:00
|
|
|
@if (true)
|
|
|
|
{
|
|
|
|
t = length(vTransformedCoords_0_Stage0) - float(r0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
t = -length(vTransformedCoords_0_Stage0) - float(r0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
half invR1 = ufocalParams_Stage1_c0_c0_c0_c0_c0.x;
|
|
|
|
half fx = ufocalParams_Stage1_c0_c0_c0_c0_c0.y;
|
2020-09-30 13:29:13 +00:00
|
|
|
float x_t = -1.0;
|
|
|
|
@if (false)
|
|
|
|
{
|
|
|
|
x_t = dot(vTransformedCoords_0_Stage0, vTransformedCoords_0_Stage0) / vTransformedCoords_0_Stage0.x;
|
|
|
|
}
|
2021-03-15 22:04:05 +00:00
|
|
|
else if (false)
|
2020-09-30 13:29:13 +00:00
|
|
|
{
|
|
|
|
x_t = length(vTransformedCoords_0_Stage0) - vTransformedCoords_0_Stage0.x * float(invR1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float temp = vTransformedCoords_0_Stage0.x * vTransformedCoords_0_Stage0.x - vTransformedCoords_0_Stage0.y * vTransformedCoords_0_Stage0.y;
|
|
|
|
if (temp >= 0.0)
|
|
|
|
{
|
|
|
|
@if (false || !true)
|
|
|
|
{
|
|
|
|
x_t = -sqrt(temp) - vTransformedCoords_0_Stage0.x * float(invR1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x_t = sqrt(temp) - vTransformedCoords_0_Stage0.x * float(invR1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-15 22:04:05 +00:00
|
|
|
@if (!false)
|
2020-09-30 13:29:13 +00:00
|
|
|
{
|
|
|
|
if (x_t <= 0.0)
|
|
|
|
{
|
|
|
|
v = -1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@if (true)
|
|
|
|
{
|
|
|
|
@if (false)
|
|
|
|
{
|
|
|
|
t = x_t;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
t = x_t + float(fx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
@if (false)
|
|
|
|
{
|
|
|
|
t = -x_t;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
t = -x_t + float(fx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@if (false)
|
|
|
|
{
|
|
|
|
t = 1.0 - t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2021-03-15 22:04:05 +00:00
|
|
|
return half4(half(t), v, 0.0, 0.0);
|
2020-09-30 13:29:13 +00:00
|
|
|
}
|
2021-03-15 22:04:05 +00:00
|
|
|
half4 MatrixEffect_Stage1_c0_c0_c0_c0(half4 _input)
|
2020-09-30 13:29:13 +00:00
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
return TwoPointConicalGradientLayout_Stage1_c0_c0_c0_c0_c0(_input);
|
2020-09-30 13:29:13 +00:00
|
|
|
}
|
2021-03-15 22:04:05 +00:00
|
|
|
half4 UnrolledBinaryGradientColorizer_Stage1_c0_c0_c0_c1(half4 _input, float2 _coords)
|
2020-09-30 13:29:13 +00:00
|
|
|
{
|
|
|
|
half t = half(_coords.x);
|
2021-03-15 22:04:05 +00:00
|
|
|
float4 scale;
|
|
|
|
float4 bias;
|
|
|
|
if (4 <= 4 || t < uthresholds1_7_Stage1_c0_c0_c0_c1.w)
|
2020-09-30 13:29:13 +00:00
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
if (4 <= 2 || t < uthresholds1_7_Stage1_c0_c0_c0_c1.y)
|
2020-09-30 13:29:13 +00:00
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
if (4 <= 1 || t < uthresholds1_7_Stage1_c0_c0_c0_c1.x)
|
2020-09-30 13:29:13 +00:00
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
scale = uscale0_1_Stage1_c0_c0_c0_c1;
|
|
|
|
bias = ubias0_1_Stage1_c0_c0_c0_c1;
|
2020-09-30 13:29:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
scale = uscale2_3_Stage1_c0_c0_c0_c1;
|
|
|
|
bias = ubias2_3_Stage1_c0_c0_c0_c1;
|
2020-09-30 13:29:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
if (4 <= 3 || t < uthresholds1_7_Stage1_c0_c0_c0_c1.z)
|
2020-09-30 13:29:13 +00:00
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
scale = uscale4_5_Stage1_c0_c0_c0_c1;
|
|
|
|
bias = ubias4_5_Stage1_c0_c0_c0_c1;
|
2020-09-30 13:29:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
scale = uscale6_7_Stage1_c0_c0_c0_c1;
|
|
|
|
bias = ubias6_7_Stage1_c0_c0_c0_c1;
|
2020-09-30 13:29:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
if (4 <= 6 || t < uthresholds9_13_Stage1_c0_c0_c0_c1.y)
|
2020-09-30 13:29:13 +00:00
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
if (4 <= 5 || t < uthresholds9_13_Stage1_c0_c0_c0_c1.x)
|
2020-09-30 13:29:13 +00:00
|
|
|
{
|
|
|
|
scale = float4(0);
|
|
|
|
bias = float4(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
scale = float4(0);
|
|
|
|
bias = float4(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
if (4 <= 7 || t < uthresholds9_13_Stage1_c0_c0_c0_c1.z)
|
2020-09-30 13:29:13 +00:00
|
|
|
{
|
|
|
|
scale = float4(0);
|
|
|
|
bias = float4(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
scale = float4(0);
|
|
|
|
bias = float4(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-15 22:04:05 +00:00
|
|
|
return half4(float(t) * scale + bias);
|
2020-09-30 13:29:13 +00:00
|
|
|
}
|
2021-03-15 22:04:05 +00:00
|
|
|
half4 ClampedGradientEffect_Stage1_c0_c0_c0(half4 _input)
|
2020-09-30 13:29:13 +00:00
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
half4 t = MatrixEffect_Stage1_c0_c0_c0_c0(_input);
|
|
|
|
half4 outColor;
|
2020-09-30 13:29:13 +00:00
|
|
|
if (!false && t.y < 0.0)
|
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
outColor = half4(0.0);
|
2020-09-30 13:29:13 +00:00
|
|
|
}
|
|
|
|
else if (t.x < 0.0)
|
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
outColor = uleftBorderColor_Stage1_c0_c0_c0;
|
2020-09-30 13:29:13 +00:00
|
|
|
}
|
|
|
|
else if (t.x > 1.0)
|
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
outColor = urightBorderColor_Stage1_c0_c0_c0;
|
2020-09-30 13:29:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
outColor = UnrolledBinaryGradientColorizer_Stage1_c0_c0_c0_c1(_input, float2(half2(t.x, 0.0)));
|
2020-09-30 13:29:13 +00:00
|
|
|
}
|
|
|
|
@if (false)
|
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
outColor.xyz *= outColor.w;
|
2020-09-30 13:29:13 +00:00
|
|
|
}
|
2021-03-15 22:04:05 +00:00
|
|
|
return outColor;
|
2020-09-30 13:29:13 +00:00
|
|
|
}
|
2021-03-15 22:04:05 +00:00
|
|
|
half4 OverrideInputFragmentProcessor_Stage1_c0_c0(half4 _input)
|
2020-09-30 13:29:13 +00:00
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
return ClampedGradientEffect_Stage1_c0_c0_c0(false ? half4(0) : half4(1.000000, 1.000000, 1.000000, 1.000000));
|
|
|
|
}
|
|
|
|
half4 DitherEffect_Stage1_c0(half4 _input)
|
|
|
|
{
|
|
|
|
half4 color = OverrideInputFragmentProcessor_Stage1_c0_c0(_input);
|
|
|
|
half value;
|
|
|
|
@if (sk_Caps.integerSupport)
|
2020-09-30 13:29:13 +00:00
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
uint x = uint(sk_FragCoord.x);
|
|
|
|
uint y = uint(sk_FragCoord.y) ^ x;
|
|
|
|
uint m = (((((y & 1) << 5 | (x & 1) << 4) | (y & 2) << 2) | (x & 2) << 1) | (y & 4) >> 1) | (x & 4) >> 2;
|
|
|
|
value = half(m) / 64.0 - 0.4921875;
|
2020-09-30 13:29:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
half4 bits = mod(half4(sk_FragCoord.yxyx), half4(2.0, 2.0, 4.0, 4.0));
|
|
|
|
bits.zw = step(2.0, bits.zw);
|
|
|
|
bits.xz = abs(bits.xz - bits.yw);
|
|
|
|
value = dot(bits, half4(0.5, 0.25, 0.125, 0.0625)) - 0.46875;
|
2020-09-30 13:29:13 +00:00
|
|
|
}
|
2021-03-15 22:04:05 +00:00
|
|
|
return half4(clamp(color.xyz + value * urange_Stage1_c0, 0.0, color.w), color.w);
|
2020-09-30 13:29:13 +00:00
|
|
|
}
|
|
|
|
void main()
|
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
// Stage 0, QuadPerEdgeAAGeometryProcessor
|
2020-09-30 13:29:13 +00:00
|
|
|
half4 outputColor_Stage0;
|
2021-03-15 22:04:05 +00:00
|
|
|
outputColor_Stage0 = vcolor_Stage0;
|
|
|
|
const half4 outputCoverage_Stage0 = half4(1);
|
2020-09-30 13:29:13 +00:00
|
|
|
half4 output_Stage1;
|
2021-03-15 22:04:05 +00:00
|
|
|
output_Stage1 = DitherEffect_Stage1_c0(outputColor_Stage0);
|
2020-09-30 13:29:13 +00:00
|
|
|
{
|
|
|
|
// Xfer Processor: Porter Duff
|
|
|
|
sk_FragColor = output_Stage1 * outputCoverage_Stage0;
|
|
|
|
}
|
|
|
|
}
|
2020-11-06 14:28:04 +00:00
|
|
|
)");
|
2020-09-30 13:29:13 +00:00
|
|
|
|
2021-03-15 22:04:05 +00:00
|
|
|
// This fragment shader is taken from GM_BlurDrawImage.
|
2020-11-06 14:28:04 +00:00
|
|
|
COMPILER_BENCH(medium, R"(
|
2021-03-15 22:04:05 +00:00
|
|
|
layout(set=0, binding=0) uniform float3x3 umatrix_Stage1_c0_c0_c0;
|
|
|
|
layout(set=0, binding=0) uniform half4 urectH_Stage2_c1;
|
|
|
|
layout(set=0, binding=0) uniform float3x3 umatrix_Stage2_c1_c0;
|
|
|
|
layout(set=0, binding=0) uniform sampler2D uTextureSampler_0_Stage1;
|
|
|
|
layout(set=0, binding=0) uniform sampler2D uTextureSampler_0_Stage2;
|
|
|
|
flat in half4 vcolor_Stage0;
|
|
|
|
noperspective in float2 vTransformedCoords_0_Stage0;
|
|
|
|
out half4 sk_FragColor;
|
|
|
|
half4 TextureEffect_Stage1_c0_c0_c0_c0(half4 _input)
|
|
|
|
{
|
|
|
|
return sample(uTextureSampler_0_Stage1, vTransformedCoords_0_Stage0);
|
|
|
|
}
|
|
|
|
half4 MatrixEffect_Stage1_c0_c0_c0(half4 _input)
|
|
|
|
{
|
|
|
|
return TextureEffect_Stage1_c0_c0_c0_c0(_input);
|
|
|
|
}
|
|
|
|
half4 Blend_Stage1_c0_c0(half4 _input)
|
|
|
|
{
|
|
|
|
// Blend mode: SrcIn (Compose-One behavior)
|
|
|
|
return blend_src_in(MatrixEffect_Stage1_c0_c0_c0(half4(1)), _input);
|
|
|
|
}
|
|
|
|
half4 OverrideInputFragmentProcessor_Stage1_c0(half4 _input)
|
|
|
|
{
|
|
|
|
return Blend_Stage1_c0_c0(false ? half4(0) : half4(1.000000, 1.000000, 1.000000, 1.000000));
|
|
|
|
}
|
|
|
|
half4 TextureEffect_Stage2_c1_c0_c0(half4 _input, float2 _coords)
|
|
|
|
{
|
|
|
|
return sample(uTextureSampler_0_Stage2, _coords).000r;
|
|
|
|
}
|
|
|
|
half4 MatrixEffect_Stage2_c1_c0(half4 _input, float2 _coords)
|
|
|
|
{
|
|
|
|
return TextureEffect_Stage2_c1_c0_c0(_input, ((umatrix_Stage2_c1_c0) * _coords.xy1).xy);
|
|
|
|
}
|
|
|
|
half4 RectBlurEffect_Stage2_c1(half4 _input)
|
|
|
|
{
|
|
|
|
/* key */ const bool highPrecision = false;
|
|
|
|
half xCoverage;
|
|
|
|
half yCoverage;
|
|
|
|
float2 pos = sk_FragCoord.xy;
|
|
|
|
@if (false)
|
|
|
|
{
|
|
|
|
pos = (float3x3(1) * float3(pos, 1.0)).xy;
|
2019-05-31 21:06:53 +00:00
|
|
|
}
|
2021-03-15 22:04:05 +00:00
|
|
|
@if (true)
|
|
|
|
{
|
|
|
|
half2 xy;
|
|
|
|
@if (highPrecision)
|
|
|
|
{
|
|
|
|
xy = max(half2(float4(0).xy - pos), half2(pos - float4(0).zw));
|
2019-05-31 21:06:53 +00:00
|
|
|
}
|
2021-03-15 22:04:05 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
xy = max(half2(float2(urectH_Stage2_c1.xy) - pos), half2(pos - float2(urectH_Stage2_c1.zw)));
|
2019-05-31 21:06:53 +00:00
|
|
|
}
|
2021-03-15 22:04:05 +00:00
|
|
|
xCoverage = MatrixEffect_Stage2_c1_c0(_input, float2(half2(xy.x, 0.5))).w;
|
|
|
|
yCoverage = MatrixEffect_Stage2_c1_c0(_input, float2(half2(xy.y, 0.5))).w;
|
2019-05-31 21:06:53 +00:00
|
|
|
}
|
2021-03-15 22:04:05 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
half4 rect;
|
|
|
|
@if (highPrecision)
|
|
|
|
{
|
|
|
|
rect.xy = half2(float4(0).xy - pos);
|
|
|
|
rect.zw = half2(pos - float4(0).zw);
|
2019-05-31 21:06:53 +00:00
|
|
|
}
|
2021-03-15 22:04:05 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
rect.xy = half2(float2(urectH_Stage2_c1.xy) - pos);
|
|
|
|
rect.zw = half2(pos - float2(urectH_Stage2_c1.zw));
|
2019-05-31 21:06:53 +00:00
|
|
|
}
|
2021-03-15 22:04:05 +00:00
|
|
|
xCoverage = (1.0 - MatrixEffect_Stage2_c1_c0(_input, float2(half2(rect.x, 0.5))).w) - MatrixEffect_Stage2_c1_c0(_input, float2(half2(rect.z, 0.5))).w;
|
|
|
|
yCoverage = (1.0 - MatrixEffect_Stage2_c1_c0(_input, float2(half2(rect.y, 0.5))).w) - MatrixEffect_Stage2_c1_c0(_input, float2(half2(rect.w, 0.5))).w;
|
2019-05-31 21:06:53 +00:00
|
|
|
}
|
2021-03-15 22:04:05 +00:00
|
|
|
return (_input * xCoverage) * yCoverage;
|
|
|
|
}
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
// Stage 0, QuadPerEdgeAAGeometryProcessor
|
|
|
|
half4 outputColor_Stage0;
|
|
|
|
outputColor_Stage0 = vcolor_Stage0;
|
|
|
|
const half4 outputCoverage_Stage0 = half4(1);
|
|
|
|
half4 output_Stage1;
|
|
|
|
output_Stage1 = OverrideInputFragmentProcessor_Stage1_c0(outputColor_Stage0);
|
|
|
|
half4 output_Stage2;
|
|
|
|
output_Stage2 = RectBlurEffect_Stage2_c1(outputCoverage_Stage0);
|
|
|
|
{
|
|
|
|
// Xfer Processor: Porter Duff
|
|
|
|
sk_FragColor = output_Stage1 * output_Stage2;
|
|
|
|
}
|
|
|
|
}
|
2020-11-06 14:28:04 +00:00
|
|
|
)");
|
2020-07-08 18:12:43 +00:00
|
|
|
|
2021-03-15 22:04:05 +00:00
|
|
|
// This is the fragment shader used to blit the Viewer window when running the software rasterizer.
|
2020-11-06 14:28:04 +00:00
|
|
|
COMPILER_BENCH(small, R"(
|
2021-03-15 22:04:05 +00:00
|
|
|
layout(set=0, binding=0) uniform float3x3 umatrix_Stage1_c0_c0;
|
|
|
|
layout(set=0, binding=0) uniform sampler2D uTextureSampler_0_Stage1;
|
|
|
|
noperspective in float2 vTransformedCoords_0_Stage0;
|
|
|
|
out half4 sk_FragColor;
|
|
|
|
half4 TextureEffect_Stage1_c0_c0_c0(half4 _input)
|
|
|
|
{
|
|
|
|
return sample(uTextureSampler_0_Stage1, vTransformedCoords_0_Stage0);
|
|
|
|
}
|
|
|
|
half4 MatrixEffect_Stage1_c0_c0(half4 _input)
|
|
|
|
{
|
|
|
|
return TextureEffect_Stage1_c0_c0_c0(_input);
|
|
|
|
}
|
|
|
|
half4 Blend_Stage1_c0(half4 _input)
|
|
|
|
{
|
|
|
|
// Blend mode: Modulate (Compose-One behavior)
|
|
|
|
return blend_modulate(MatrixEffect_Stage1_c0_c0(half4(1)), _input);
|
|
|
|
}
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
// Stage 0, QuadPerEdgeAAGeometryProcessor
|
|
|
|
half4 outputColor_Stage0 = half4(1);
|
|
|
|
const half4 outputCoverage_Stage0 = half4(1);
|
|
|
|
half4 output_Stage1;
|
|
|
|
output_Stage1 = Blend_Stage1_c0(outputColor_Stage0);
|
2020-10-23 22:37:29 +00:00
|
|
|
{
|
2021-03-15 22:04:05 +00:00
|
|
|
// Xfer Processor: Porter Duff
|
|
|
|
sk_FragColor = output_Stage1 * outputCoverage_Stage0;
|
2020-10-23 22:37:29 +00:00
|
|
|
}
|
2021-03-15 22:04:05 +00:00
|
|
|
}
|
2020-11-06 14:28:04 +00:00
|
|
|
)");
|
2020-10-23 22:37:29 +00:00
|
|
|
|
2020-11-06 14:28:04 +00:00
|
|
|
COMPILER_BENCH(tiny, "void main() { sk_FragColor = half4(1); }");
|
2020-10-23 22:37:29 +00:00
|
|
|
|
2020-07-09 14:04:33 +00:00
|
|
|
#if defined(SK_BUILD_FOR_UNIX)
|
|
|
|
|
|
|
|
#include <malloc.h>
|
|
|
|
|
2020-07-08 18:12:43 +00:00
|
|
|
// These benchmarks aren't timed, they produce memory usage statistics. They run standalone, and
|
|
|
|
// directly add their results to the nanobench log.
|
|
|
|
void RunSkSLMemoryBenchmarks(NanoJSONResultsWriter* log) {
|
2020-07-09 14:04:33 +00:00
|
|
|
auto heap_bytes_used = []() { return mallinfo().uordblks; };
|
|
|
|
auto bench = [log](const char* name, int bytes) {
|
2020-07-08 18:12:43 +00:00
|
|
|
log->beginObject(name); // test
|
|
|
|
log->beginObject("meta"); // config
|
2020-07-09 14:04:33 +00:00
|
|
|
log->appendS32("bytes", bytes); // sub_result
|
2020-07-08 18:12:43 +00:00
|
|
|
log->endObject(); // config
|
|
|
|
log->endObject(); // test
|
|
|
|
};
|
|
|
|
|
2020-11-20 17:38:07 +00:00
|
|
|
// Heap used by a default compiler (with no modules loaded)
|
2020-07-08 18:12:43 +00:00
|
|
|
{
|
2020-07-09 14:04:33 +00:00
|
|
|
int before = heap_bytes_used();
|
2020-11-18 20:38:39 +00:00
|
|
|
GrShaderCaps caps(GrContextOptions{});
|
|
|
|
SkSL::Compiler compiler(&caps);
|
2020-07-09 14:04:33 +00:00
|
|
|
int after = heap_bytes_used();
|
|
|
|
bench("sksl_compiler_baseline", after - before);
|
2020-07-08 18:12:43 +00:00
|
|
|
}
|
2020-11-20 17:38:07 +00:00
|
|
|
|
|
|
|
// Heap used by a compiler with the two main GPU modules (fragment + vertex) loaded
|
|
|
|
{
|
|
|
|
int before = heap_bytes_used();
|
|
|
|
GrShaderCaps caps(GrContextOptions{});
|
|
|
|
SkSL::Compiler compiler(&caps);
|
2021-02-16 18:29:15 +00:00
|
|
|
compiler.moduleForProgramKind(SkSL::ProgramKind::kVertex);
|
|
|
|
compiler.moduleForProgramKind(SkSL::ProgramKind::kFragment);
|
2020-11-20 17:38:07 +00:00
|
|
|
int after = heap_bytes_used();
|
|
|
|
bench("sksl_compiler_gpu", after - before);
|
|
|
|
}
|
|
|
|
|
2021-06-08 18:06:22 +00:00
|
|
|
// Heap used by a compiler with the runtime shader, color filter and blending modules loaded
|
2020-11-20 17:38:07 +00:00
|
|
|
{
|
|
|
|
int before = heap_bytes_used();
|
|
|
|
GrShaderCaps caps(GrContextOptions{});
|
|
|
|
SkSL::Compiler compiler(&caps);
|
2021-04-12 13:49:20 +00:00
|
|
|
compiler.moduleForProgramKind(SkSL::ProgramKind::kRuntimeColorFilter);
|
|
|
|
compiler.moduleForProgramKind(SkSL::ProgramKind::kRuntimeShader);
|
2021-06-16 15:33:13 +00:00
|
|
|
compiler.moduleForProgramKind(SkSL::ProgramKind::kRuntimeBlender);
|
2020-11-20 17:38:07 +00:00
|
|
|
int after = heap_bytes_used();
|
|
|
|
bench("sksl_compiler_runtimeeffect", after - before);
|
|
|
|
}
|
2020-07-08 18:12:43 +00:00
|
|
|
}
|
2020-07-09 14:04:33 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
void RunSkSLMemoryBenchmarks(NanoJSONResultsWriter*) {}
|
|
|
|
|
|
|
|
#endif
|