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"
|
2022-04-07 15:20:24 +00:00
|
|
|
#include "src/gpu/ganesh/GrCaps.h"
|
|
|
|
#include "src/gpu/ganesh/GrRecordingContextPriv.h"
|
|
|
|
#include "src/gpu/ganesh/mock/GrMockCaps.h"
|
2019-05-31 21:06:53 +00:00
|
|
|
#include "src/sksl/SkSLCompiler.h"
|
2021-07-20 19:23:04 +00:00
|
|
|
#include "src/sksl/SkSLDSLParser.h"
|
2022-04-26 00:16:16 +00:00
|
|
|
#include "src/sksl/codegen/SkSLVMCodeGenerator.h"
|
|
|
|
|
|
|
|
#include <regex>
|
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 {
|
2021-10-20 19:44:59 +00:00
|
|
|
GrShaderCaps caps;
|
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,
|
2022-04-26 00:16:16 +00:00
|
|
|
kSPIRV,
|
|
|
|
kSkVM, // raw SkVM bytecode
|
|
|
|
kSkVMOpt, // optimized SkVM bytecode
|
|
|
|
kSkVMJIT, // optimized native assembly code
|
2020-11-06 14:28:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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) {
|
2022-04-26 00:16:16 +00:00
|
|
|
case Output::kNone: return "";
|
|
|
|
case Output::kGLSL: return "glsl_";
|
|
|
|
case Output::kMetal: return "metal_";
|
|
|
|
case Output::kSPIRV: return "spirv_";
|
|
|
|
case Output::kSkVM: return "skvm_";
|
|
|
|
case Output::kSkVMOpt: return "skvm_opt_";
|
|
|
|
case Output::kSkVMJIT: return "skvm_jit_";
|
2020-11-06 14:28:04 +00:00
|
|
|
}
|
|
|
|
SkUNREACHABLE;
|
|
|
|
}
|
|
|
|
|
2022-02-02 21:51:18 +00:00
|
|
|
SkSLCompileBench(std::string name, const char* src, bool optimize, Output output)
|
|
|
|
: fName(std::string("sksl_") + (optimize ? "" : "unoptimized_") + output_string(output) +
|
2020-11-06 14:28:04 +00:00
|
|
|
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;
|
2021-07-20 19:23:04 +00:00
|
|
|
fSettings.fDSLMangling = false;
|
2022-04-26 00:16:16 +00:00
|
|
|
fSettings.fEnforceES2Restrictions = false;
|
2020-11-06 14:28:04 +00:00
|
|
|
// 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;
|
2022-04-26 00:16:16 +00:00
|
|
|
|
|
|
|
this->fixUpSource();
|
2020-11-06 14:28:04 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2022-04-26 00:16:16 +00:00
|
|
|
bool usesRuntimeShader() const {
|
|
|
|
return fOutput >= Output::kSkVM;
|
|
|
|
}
|
|
|
|
|
|
|
|
void fixUpSource() {
|
|
|
|
auto fixup = [this](const char* input, const char* replacement) {
|
|
|
|
fSrc = std::regex_replace(fSrc, std::regex(input), replacement);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Runtime shaders which have slightly different conventions than fragment shaders.
|
|
|
|
// Perform a handful of fixups to compensate. These are hand-tuned for our current set of
|
|
|
|
// test shaders and will probably need to be updated if we add more.
|
|
|
|
if (this->usesRuntimeShader()) {
|
|
|
|
fixup(R"(void main\(\))", "half4 main(float2 xy)");
|
|
|
|
fixup(R"(sk_FragColor =)", "return");
|
|
|
|
fixup(R"(sk_FragCoord)", "_FragCoord");
|
|
|
|
fixup(R"(out half4 sk_FragColor;)", "");
|
|
|
|
fixup(R"(uniform sampler2D )", "uniform shader ");
|
|
|
|
fixup(R"((flat |noperspective |)in )", "uniform ");
|
|
|
|
fixup(R"(sample\(([A-Za-z0-9_]+), ([A-Za-z0-9_]+)\))", "$01.eval($02)");
|
|
|
|
fSrc = "uniform float4 _FragCoord;\n" + fSrc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-06 14:28:04 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2022-04-27 14:08:47 +00:00
|
|
|
const SkSL::ProgramKind kind = this->usesRuntimeShader() ? SkSL::ProgramKind::kRuntimeShader
|
|
|
|
: SkSL::ProgramKind::kFragment;
|
2019-05-31 21:06:53 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
Apply SkSL optimizations properly in nanobench.
At http://go/skiareview/c/skia/+/400622/55/bench/SkSLBench.cpp#84,
during the initial DSL parser land, Nanobench was updated to construct
a DSLParser directly instead of calling SkSLCompiler::convertProgram.
This skipped over some important compiler setup--specifically, applying
optimization flags and resetting the inliner.
Unfortunately this means that our optimized benchmark results for the
past ~9 months are not trustworthy at all. The numbers are wildly off:
http://screen/YfZHDvhs9V9Ka6x
"Unoptimized" benchmarks seem to be correct in practice, due to
redundant flag checks. "Optimized" benchmarks, however, are reporting
much better values than they should. The benchmark would stop inlining
after a few iterations of the test, because we'd quickly hit our
internal inlining limit
(https://osscs.corp.google.com/skia/skia/+/main:src/sksl/SkSLInliner.cpp;l=70)
at which point the inliner would turn itself off.
To fix the root cause, Nanobench uses SkSLCompiler::convertProgram
again. Additionally, Compiler::optimize now defensively calls
inliner.reset() before inlining. A second reset shouldn't be necessary,
but it's harmless and free. (This just sets two int fields to zero.)
Change-Id: I690ead14137e4bf74d0f7aa32812bd5b3c21bef5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/534560
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2022-04-27 13:56:51 +00:00
|
|
|
std::unique_ptr<SkSL::Program> program = fCompiler.convertProgram(kind, 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());
|
|
|
|
}
|
2022-02-02 21:51:18 +00:00
|
|
|
std::string result;
|
2020-11-06 14:28:04 +00:00
|
|
|
switch (fOutput) {
|
2022-04-27 14:08:47 +00:00
|
|
|
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;
|
2022-04-26 00:16:16 +00:00
|
|
|
case Output::kSkVM:
|
|
|
|
case Output::kSkVMOpt:
|
2022-04-27 14:08:47 +00:00
|
|
|
case Output::kSkVMJIT: SkAssertResult(CompileToSkVM(*program, fOutput)); break;
|
2020-11-06 14:28:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-26 00:16:16 +00:00
|
|
|
static bool CompileToSkVM(const SkSL::Program& program, Output mode) {
|
|
|
|
const bool optimize = (mode >= Output::kSkVMOpt);
|
|
|
|
const bool allowJIT = (mode >= Output::kSkVMJIT);
|
|
|
|
skvm::Builder builder{skvm::Features{}};
|
|
|
|
if (!SkSL::testingOnly_ProgramToSkVMShader(program, &builder, /*debugTrace=*/nullptr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (optimize) {
|
|
|
|
builder.done("SkSLBench", allowJIT);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-06 14:28:04 +00:00
|
|
|
private:
|
2022-02-02 21:51:18 +00:00
|
|
|
std::string fName;
|
|
|
|
std::string fSrc;
|
2020-11-06 14:28:04 +00:00
|
|
|
GrMockCaps fCaps;
|
|
|
|
SkSL::Compiler fCompiler;
|
|
|
|
SkSL::Program::Settings fSettings;
|
|
|
|
Output fOutput;
|
|
|
|
|
|
|
|
using INHERITED = Benchmark;
|
|
|
|
};
|
|
|
|
|
2019-05-31 21:06:53 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2022-04-26 00:16:16 +00:00
|
|
|
#define COMPILER_BENCH(name, text) \
|
|
|
|
static constexpr char name ## _SRC[] = text; \
|
|
|
|
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);) \
|
|
|
|
DEF_BENCH(return new SkSLCompileBench(#name, name ## _SRC, /*optimize=*/true, Output::kSkVM);) \
|
|
|
|
DEF_BENCH(return new SkSLCompileBench(#name, name ## _SRC, /*optimize=*/true, Output::kSkVMOpt);) \
|
|
|
|
DEF_BENCH(return new SkSLCompileBench(#name, name ## _SRC, /*optimize=*/true, Output::kSkVMJIT);)
|
2020-11-06 14:28:04 +00:00
|
|
|
|
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.
|
2022-04-25 22:04:37 +00:00
|
|
|
// To get an ES2 compatible shader, nonconstantArrayIndexSupport in GrShaderCaps is forced off.
|
2020-11-06 14:28:04 +00:00
|
|
|
COMPILER_BENCH(large, R"(
|
2021-11-22 20:25:28 +00:00
|
|
|
uniform float3x3 umatrix_S1_c0;
|
2022-04-25 22:04:37 +00:00
|
|
|
uniform half4 uthresholds1_7_S1_c1_c0_c0;
|
|
|
|
uniform half4 uthresholds9_13_S1_c1_c0_c0;
|
2021-11-22 20:25:28 +00:00
|
|
|
uniform float4 uscale_S1_c1_c0_c0[4];
|
|
|
|
uniform float4 ubias_S1_c1_c0_c0[4];
|
|
|
|
uniform half uinvR1_S1_c1_c0_c1_c0;
|
|
|
|
uniform half ufx_S1_c1_c0_c1_c0;
|
|
|
|
uniform float3x3 umatrix_S1_c1_c0_c1;
|
|
|
|
uniform half4 uleftBorderColor_S1_c1_c0;
|
|
|
|
uniform half4 urightBorderColor_S1_c1_c0;
|
|
|
|
uniform half urange_S1;
|
|
|
|
uniform sampler2D uTextureSampler_0_S1;
|
|
|
|
flat in half4 vcolor_S0;
|
|
|
|
noperspective in float2 vTransformedCoords_8_S0;
|
2020-09-30 13:29:13 +00:00
|
|
|
out half4 sk_FragColor;
|
2021-11-22 20:25:28 +00:00
|
|
|
half4 TextureEffect_S1_c0_c0(half4 _input, float2 _coords)
|
2020-09-30 13:29:13 +00:00
|
|
|
{
|
2021-11-22 20:25:28 +00:00
|
|
|
return sample(uTextureSampler_0_S1, _coords).000r;
|
2020-09-30 13:29:13 +00:00
|
|
|
}
|
2021-11-22 20:25:28 +00:00
|
|
|
half4 MatrixEffect_S1_c0(half4 _input, float2 _coords)
|
2020-09-30 13:29:13 +00:00
|
|
|
{
|
2021-11-22 20:25:28 +00:00
|
|
|
return TextureEffect_S1_c0_c0(_input, float3x2(umatrix_S1_c0) * _coords.xy1);
|
2020-09-30 13:29:13 +00:00
|
|
|
}
|
2022-04-25 22:04:37 +00:00
|
|
|
half4 UnrolledBinaryColorizer_S1_c1_c0_c0(half4 _input, float2 _coords)
|
2020-09-30 13:29:13 +00:00
|
|
|
{
|
2021-11-22 20:25:28 +00:00
|
|
|
half4 _tmp_0_inColor = _input;
|
|
|
|
float2 _tmp_1_coords = _coords;
|
|
|
|
half t = half(_tmp_1_coords.x);
|
2022-04-25 22:04:37 +00:00
|
|
|
float4 s;
|
|
|
|
float4 b;
|
2021-11-22 20:25:28 +00:00
|
|
|
{
|
2022-04-25 22:04:37 +00:00
|
|
|
if (t < uthresholds1_7_S1_c1_c0_c0.y)
|
|
|
|
{
|
|
|
|
if (t < uthresholds1_7_S1_c1_c0_c0.x)
|
|
|
|
{
|
|
|
|
s = uscale_S1_c1_c0_c0[0];
|
|
|
|
b = ubias_S1_c1_c0_c0[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s = uscale_S1_c1_c0_c0[1];
|
|
|
|
b = ubias_S1_c1_c0_c0[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (t < uthresholds1_7_S1_c1_c0_c0.z)
|
|
|
|
{
|
|
|
|
s = uscale_S1_c1_c0_c0[2];
|
|
|
|
b = ubias_S1_c1_c0_c0[2];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s = uscale_S1_c1_c0_c0[3];
|
|
|
|
b = ubias_S1_c1_c0_c0[3];
|
|
|
|
}
|
|
|
|
}
|
2021-11-22 20:25:28 +00:00
|
|
|
}
|
2022-04-25 22:04:37 +00:00
|
|
|
return half4(half4(float(t) * s + b));
|
2020-09-30 13:29:13 +00:00
|
|
|
}
|
2021-11-22 20:25:28 +00:00
|
|
|
half4 TwoPointConicalFocalLayout_S1_c1_c0_c1_c0(half4 _input)
|
2020-09-30 13:29:13 +00:00
|
|
|
{
|
2021-11-22 20:25:28 +00:00
|
|
|
half4 _tmp_2_inColor = _input;
|
|
|
|
float2 _tmp_3_coords = vTransformedCoords_8_S0;
|
|
|
|
float t = -1.0;
|
|
|
|
half v = 1.0;
|
|
|
|
float x_t = -1.0;
|
|
|
|
if (bool(int(0)))
|
|
|
|
{
|
|
|
|
x_t = dot(_tmp_3_coords, _tmp_3_coords) / _tmp_3_coords.x;
|
|
|
|
}
|
|
|
|
else if (bool(int(0)))
|
|
|
|
{
|
|
|
|
x_t = length(_tmp_3_coords) - _tmp_3_coords.x * float(uinvR1_S1_c1_c0_c1_c0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float temp = _tmp_3_coords.x * _tmp_3_coords.x - _tmp_3_coords.y * _tmp_3_coords.y;
|
|
|
|
if (temp >= 0.0)
|
|
|
|
{
|
|
|
|
if (bool(int(0)) || !bool(int(1)))
|
|
|
|
{
|
|
|
|
x_t = -sqrt(temp) - _tmp_3_coords.x * float(uinvR1_S1_c1_c0_c1_c0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x_t = sqrt(temp) - _tmp_3_coords.x * float(uinvR1_S1_c1_c0_c1_c0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!bool(int(0)))
|
|
|
|
{
|
|
|
|
if (x_t <= 0.0)
|
|
|
|
{
|
|
|
|
v = -1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bool(int(1)))
|
|
|
|
{
|
|
|
|
if (bool(int(0)))
|
|
|
|
{
|
|
|
|
t = x_t;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
t = x_t + float(ufx_S1_c1_c0_c1_c0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (bool(int(0)))
|
|
|
|
{
|
|
|
|
t = -x_t;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
t = -x_t + float(ufx_S1_c1_c0_c1_c0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bool(int(0)))
|
|
|
|
{
|
|
|
|
t = 1.0 - t;
|
|
|
|
}
|
|
|
|
return half4(half4(half(t), v, 0.0, 0.0));
|
2020-09-30 13:29:13 +00:00
|
|
|
}
|
2021-11-22 20:25:28 +00:00
|
|
|
half4 MatrixEffect_S1_c1_c0_c1(half4 _input)
|
2020-09-30 13:29:13 +00:00
|
|
|
{
|
2021-11-22 20:25:28 +00:00
|
|
|
return TwoPointConicalFocalLayout_S1_c1_c0_c1_c0(_input);
|
2021-03-15 22:04:05 +00:00
|
|
|
}
|
2021-11-22 20:25:28 +00:00
|
|
|
half4 ClampedGradient_S1_c1_c0(half4 _input)
|
2021-03-15 22:04:05 +00:00
|
|
|
{
|
2021-11-22 20:25:28 +00:00
|
|
|
half4 _tmp_4_inColor = _input;
|
|
|
|
half4 t = MatrixEffect_S1_c1_c0_c1(_tmp_4_inColor);
|
|
|
|
half4 outColor;
|
|
|
|
if (!bool(int(0)) && t.y < 0.0)
|
|
|
|
{
|
|
|
|
outColor = half4(0.0);
|
|
|
|
}
|
|
|
|
else if (t.x < 0.0)
|
|
|
|
{
|
|
|
|
outColor = uleftBorderColor_S1_c1_c0;
|
|
|
|
}
|
|
|
|
else if (t.x > 1.0)
|
|
|
|
{
|
|
|
|
outColor = urightBorderColor_S1_c1_c0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-04-25 22:04:37 +00:00
|
|
|
outColor = UnrolledBinaryColorizer_S1_c1_c0_c0(_tmp_4_inColor, float2(half2(t.x, 0.0)));
|
2021-11-22 20:25:28 +00:00
|
|
|
}
|
|
|
|
if (bool(int(0)))
|
|
|
|
{
|
|
|
|
outColor.xyz *= outColor.w;
|
|
|
|
}
|
|
|
|
return half4(outColor);
|
|
|
|
}
|
|
|
|
half4 DisableCoverageAsAlpha_S1_c1(half4 _input)
|
|
|
|
{
|
|
|
|
_input = ClampedGradient_S1_c1_c0(_input);
|
|
|
|
half4 _tmp_5_inColor = _input;
|
|
|
|
return half4(_input);
|
|
|
|
}
|
|
|
|
half4 Dither_S1(half4 _input)
|
|
|
|
{
|
|
|
|
_input = DisableCoverageAsAlpha_S1_c1(_input);
|
|
|
|
half4 _tmp_6_inColor = _input;
|
|
|
|
half value = MatrixEffect_S1_c0(_tmp_6_inColor, sk_FragCoord.xy).w - 0.5;
|
|
|
|
return half4(half4(clamp(_input.xyz + value * urange_S1, 0.0, _input.w), _input.w));
|
2020-09-30 13:29:13 +00:00
|
|
|
}
|
|
|
|
void main()
|
|
|
|
{
|
2021-11-22 20:25:28 +00:00
|
|
|
// Stage 0, QuadPerEdgeAAGeometryProcessor
|
|
|
|
half4 outputColor_S0;
|
|
|
|
outputColor_S0 = vcolor_S0;
|
|
|
|
const half4 outputCoverage_S0 = half4(1);
|
|
|
|
half4 output_S1;
|
|
|
|
output_S1 = Dither_S1(outputColor_S0);
|
|
|
|
{
|
|
|
|
// Xfer Processor: Porter Duff
|
|
|
|
sk_FragColor = output_S1 * outputCoverage_S0;
|
|
|
|
}
|
2020-09-30 13:29:13 +00:00
|
|
|
}
|
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-11-22 20:25:28 +00:00
|
|
|
uniform float3x3 umatrix_S1_c0;
|
|
|
|
uniform float3x3 umatrix_S2_c0_c0;
|
|
|
|
uniform float4 urect_S2_c0;
|
|
|
|
uniform sampler2D uTextureSampler_0_S1;
|
|
|
|
uniform sampler2D uTextureSampler_0_S2;
|
|
|
|
flat in half4 vcolor_S0;
|
|
|
|
noperspective in float2 vTransformedCoords_3_S0;
|
2021-03-15 22:04:05 +00:00
|
|
|
out half4 sk_FragColor;
|
2021-11-22 20:25:28 +00:00
|
|
|
half4 TextureEffect_S1_c0_c0(half4 _input)
|
2021-03-15 22:04:05 +00:00
|
|
|
{
|
2021-11-22 20:25:28 +00:00
|
|
|
return sample(uTextureSampler_0_S1, vTransformedCoords_3_S0);
|
2021-03-15 22:04:05 +00:00
|
|
|
}
|
2021-11-22 20:25:28 +00:00
|
|
|
half4 MatrixEffect_S1_c0(half4 _input)
|
2021-03-15 22:04:05 +00:00
|
|
|
{
|
2021-11-22 20:25:28 +00:00
|
|
|
return TextureEffect_S1_c0_c0(_input);
|
2021-03-15 22:04:05 +00:00
|
|
|
}
|
2021-11-22 20:25:28 +00:00
|
|
|
half4 DisableCoverageAsAlpha_S1(half4 _input)
|
2021-03-15 22:04:05 +00:00
|
|
|
{
|
2021-11-22 20:25:28 +00:00
|
|
|
_input = MatrixEffect_S1_c0(_input);
|
|
|
|
half4 _tmp_0_inColor = _input;
|
|
|
|
return half4(_input);
|
2021-03-15 22:04:05 +00:00
|
|
|
}
|
2021-11-22 20:25:28 +00:00
|
|
|
half4 TextureEffect_S2_c0_c0_c0(half4 _input, float2 _coords)
|
2021-03-15 22:04:05 +00:00
|
|
|
{
|
2021-11-22 20:25:28 +00:00
|
|
|
return sample(uTextureSampler_0_S2, _coords).000r;
|
2021-03-15 22:04:05 +00:00
|
|
|
}
|
2021-11-22 20:25:28 +00:00
|
|
|
half4 MatrixEffect_S2_c0_c0(half4 _input, float2 _coords)
|
2021-03-15 22:04:05 +00:00
|
|
|
{
|
2021-11-22 20:25:28 +00:00
|
|
|
return TextureEffect_S2_c0_c0_c0(_input, float3x2(umatrix_S2_c0_c0) * _coords.xy1);
|
2021-03-15 22:04:05 +00:00
|
|
|
}
|
2021-11-22 20:25:28 +00:00
|
|
|
half4 RectBlur_S2_c0(half4 _input, float2 _coords)
|
2021-03-15 22:04:05 +00:00
|
|
|
{
|
2021-11-22 20:25:28 +00:00
|
|
|
half4 _tmp_1_inColor = _input;
|
|
|
|
float2 _tmp_2_coords = _coords;
|
|
|
|
half xCoverage;
|
|
|
|
half yCoverage;
|
|
|
|
if (bool(int(1)))
|
|
|
|
{
|
|
|
|
half2 xy = max(half2(urect_S2_c0.xy - _tmp_2_coords), half2(_tmp_2_coords - urect_S2_c0.zw));
|
|
|
|
xCoverage = MatrixEffect_S2_c0_c0(_tmp_1_inColor, float2(half2(xy.x, 0.5))).w;
|
|
|
|
yCoverage = MatrixEffect_S2_c0_c0(_tmp_1_inColor, float2(half2(xy.y, 0.5))).w;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
half4 rect = half4(half2(urect_S2_c0.xy - _tmp_2_coords), half2(_tmp_2_coords - urect_S2_c0.zw));
|
|
|
|
xCoverage = (1.0 - MatrixEffect_S2_c0_c0(_tmp_1_inColor, float2(half2(rect.x, 0.5))).w) - MatrixEffect_S2_c0_c0(_tmp_1_inColor, float2(half2(rect.z, 0.5))).w;
|
|
|
|
yCoverage = (1.0 - MatrixEffect_S2_c0_c0(_tmp_1_inColor, float2(half2(rect.y, 0.5))).w) - MatrixEffect_S2_c0_c0(_tmp_1_inColor, float2(half2(rect.w, 0.5))).w;
|
|
|
|
}
|
|
|
|
return half4((_input * xCoverage) * yCoverage);
|
2021-03-15 22:04:05 +00:00
|
|
|
}
|
2021-11-22 20:25:28 +00:00
|
|
|
half4 DeviceSpace_S2(half4 _input)
|
2021-03-15 22:04:05 +00:00
|
|
|
{
|
2021-11-22 20:25:28 +00:00
|
|
|
return RectBlur_S2_c0(_input, sk_FragCoord.xy);
|
2021-03-15 22:04:05 +00:00
|
|
|
}
|
|
|
|
void main()
|
|
|
|
{
|
2021-11-22 20:25:28 +00:00
|
|
|
// Stage 0, QuadPerEdgeAAGeometryProcessor
|
|
|
|
half4 outputColor_S0;
|
|
|
|
outputColor_S0 = vcolor_S0;
|
|
|
|
const half4 outputCoverage_S0 = half4(1);
|
|
|
|
half4 output_S1;
|
|
|
|
output_S1 = DisableCoverageAsAlpha_S1(outputColor_S0);
|
|
|
|
half4 output_S2;
|
|
|
|
output_S2 = DeviceSpace_S2(outputCoverage_S0);
|
|
|
|
{
|
|
|
|
// Xfer Processor: Porter Duff
|
|
|
|
sk_FragColor = output_S1 * output_S2;
|
|
|
|
}
|
2021-03-15 22:04:05 +00:00
|
|
|
}
|
2020-11-06 14:28:04 +00:00
|
|
|
)");
|
2020-07-08 18:12:43 +00:00
|
|
|
|
2022-04-25 20:28:32 +00:00
|
|
|
// This fragment shader is taken from GM_lcdtext.
|
2020-11-06 14:28:04 +00:00
|
|
|
COMPILER_BENCH(small, R"(
|
2022-04-25 20:28:32 +00:00
|
|
|
uniform sampler2D uTextureSampler_0_S0;
|
|
|
|
noperspective in float2 vTextureCoords_S0;
|
|
|
|
flat in float vTexIndex_S0;
|
|
|
|
noperspective in half4 vinColor_S0;
|
2021-03-15 22:04:05 +00:00
|
|
|
out half4 sk_FragColor;
|
|
|
|
void main()
|
|
|
|
{
|
2022-04-25 20:28:32 +00:00
|
|
|
// Stage 0, BitmapText
|
2021-11-22 20:25:28 +00:00
|
|
|
half4 outputColor_S0;
|
2022-04-25 20:28:32 +00:00
|
|
|
outputColor_S0 = vinColor_S0;
|
|
|
|
half4 texColor;
|
|
|
|
{
|
|
|
|
texColor = sample(uTextureSampler_0_S0, vTextureCoords_S0).rrrr;
|
|
|
|
}
|
|
|
|
half4 outputCoverage_S0 = texColor;
|
2021-11-22 20:25:28 +00:00
|
|
|
{
|
|
|
|
// Xfer Processor: Porter Duff
|
2022-04-25 20:28:32 +00:00
|
|
|
sk_FragColor = outputColor_S0 * outputCoverage_S0;
|
2021-11-22 20:25:28 +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();
|
2021-10-20 19:44:59 +00:00
|
|
|
GrShaderCaps caps;
|
2020-11-18 20:38:39 +00:00
|
|
|
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();
|
2021-10-20 19:44:59 +00:00
|
|
|
GrShaderCaps caps;
|
2020-11-20 17:38:07 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-04-21 19:18:24 +00:00
|
|
|
// Heap used by a compiler with the two main Graphite modules (fragment + vertex) loaded
|
|
|
|
{
|
|
|
|
int before = heap_bytes_used();
|
|
|
|
GrShaderCaps caps;
|
|
|
|
SkSL::Compiler compiler(&caps);
|
|
|
|
compiler.moduleForProgramKind(SkSL::ProgramKind::kGraphiteVertex);
|
|
|
|
compiler.moduleForProgramKind(SkSL::ProgramKind::kGraphiteFragment);
|
|
|
|
int after = heap_bytes_used();
|
|
|
|
bench("sksl_compiler_graphite", 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();
|
2021-10-20 19:44:59 +00:00
|
|
|
GrShaderCaps caps;
|
2020-11-20 17:38:07 +00:00
|
|
|
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
|