Skip to content

Commit

Permalink
Wrap SkRP ops in #ifdef SK_ENABLE_SKSL_IN_RASTER_PIPELINE.
Browse files Browse the repository at this point in the history
If we don't have Raster Pipeline SkSL enabled, we no longer pay a
build-size cost for these ops. If both SkVM and SkRP are disabled,
paints which use Runtime Effects will be dropped.

Change-Id: I801250aef5a0ef18d6463545d965f64a39298c4e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/675121
Reviewed-by: Brian Osman <[email protected]>
Commit-Queue: John Stiles <[email protected]>
  • Loading branch information
johnstiles-google authored and SkCQ committed Apr 26, 2023
1 parent 3ab6d7d commit ca1a36f
Show file tree
Hide file tree
Showing 14 changed files with 155 additions and 83 deletions.
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@ if (skia_compile_sksl_tests) {
"SKSL_STANDALONE",
"SK_DISABLE_TRACING",
"SK_ENABLE_SKVM",
"SK_ENABLE_SKSL_IN_RASTER_PIPELINE",
"SK_ENABLE_SPIRV_CROSS",
"SK_ENABLE_SPIRV_VALIDATION",
"SK_ENABLE_WGSL_VALIDATION",
Expand Down
48 changes: 30 additions & 18 deletions bench/SkSLBench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ enum class Output {
kGLSL,
kMetal,
kSPIRV,
#if defined(SK_ENABLE_SKSL_IN_RASTER_PIPELINE)
kSkRP,
#endif
#if defined(SK_ENABLE_SKVM)
kSkVM, // raw SkVM bytecode
kSkVMOpt, // optimized SkVM bytecode
Expand All @@ -77,7 +79,9 @@ class SkSLCompileBench : public Benchmark {
case Output::kGLSL: return "glsl_";
case Output::kMetal: return "metal_";
case Output::kSPIRV: return "spirv_";
#if defined(SK_ENABLE_SKSL_IN_RASTER_PIPELINE)
case Output::kSkRP: return "skrp_";
#endif
#if defined(SK_ENABLE_SKVM)
case Output::kSkVM: return "skvm_";
case Output::kSkVMOpt: return "skvm_opt_";
Expand Down Expand Up @@ -112,7 +116,7 @@ class SkSLCompileBench : public Benchmark {
}

bool usesRuntimeShader() const {
return fOutput >= Output::kSkRP;
return fOutput > Output::kSPIRV;
}

void fixUpSource() {
Expand Down Expand Up @@ -149,7 +153,9 @@ class SkSLCompileBench : public Benchmark {
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;
#if defined(SK_ENABLE_SKSL_IN_RASTER_PIPELINE)
case Output::kSkRP: SkAssertResult(CompileToSkRP(*program)); break;
#endif
#if defined(SK_ENABLE_SKVM)
case Output::kSkVM:
case Output::kSkVMOpt:
Expand All @@ -174,6 +180,7 @@ class SkSLCompileBench : public Benchmark {
}
#endif

#ifdef SK_ENABLE_SKSL_IN_RASTER_PIPELINE
static bool CompileToSkRP(const SkSL::Program& program) {
const SkSL::FunctionDeclaration* main = program.getFunction("main");
if (!main) {
Expand Down Expand Up @@ -203,6 +210,7 @@ class SkSLCompileBench : public Benchmark {
/*uniforms=*/SkSpan{uniformBuffer, rasterProg->numUniforms()});
return true;
}
#endif // SK_ENABLE_SKSL_IN_RASTER_PIPELINE

private:
std::string fName;
Expand All @@ -217,28 +225,32 @@ class SkSLCompileBench : public Benchmark {

///////////////////////////////////////////////////////////////////////////////

#define COMPILER_BENCH_COMMON(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::kSkRP);)
#if defined(SK_ENABLE_SKSL_IN_RASTER_PIPELINE)
#define COMPILER_BENCH_SKRP(name, text) \
DEF_BENCH(return new SkSLCompileBench(#name, name##_SRC, /*optimize=*/true, Output::kSkRP);)
#else
#define COMPILER_BENCH_SKRP(name, text) /* SkRP is disabled; no benchmarking */
#endif

#if defined(SK_ENABLE_SKVM)

#define COMPILER_BENCH(name, text) \
COMPILER_BENCH_COMMON(name, text) \
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);)

#define COMPILER_BENCH_SKVM(name, text) \
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);)
#else
#define COMPILER_BENCH_SKVM(name, text) /* SkVM is disabled; no benchmarking */
#endif

#define COMPILER_BENCH(name, text) COMPILER_BENCH_COMMON(name, text)
#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);) \
COMPILER_BENCH_SKRP(name, text) \
COMPILER_BENCH_SKVM(name, text)

#endif

// This fragment shader is from the third tile on the top row of GM_gradients_2pt_conical_outside.
// To get an ES2 compatible shader, nonconstantArrayIndexSupport in GrShaderCaps is forced off.
Expand Down
119 changes: 65 additions & 54 deletions src/core/SkRasterPipelineOpList.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
#ifndef SkRasterPipelineOpList_DEFINED
#define SkRasterPipelineOpList_DEFINED

// There are two macros here: The first defines ops that have lowp (and highp) implementations.
// The second defines ops that are only present in the highp pipeline.
// `SK_RASTER_PIPELINE_OPS_LOWP` defines ops that have parallel lowp and highp implementations.
#define SK_RASTER_PIPELINE_OPS_LOWP(M) \
M(move_src_dst) M(move_dst_src) M(swap_src_dst) \
M(clamp_01) M(clamp_gamut) \
Expand Down Expand Up @@ -53,55 +52,11 @@
M(emboss) \
M(swizzle)

#define SK_RASTER_PIPELINE_OPS_HIGHP_ONLY(M) \
M(callback) \
M(stack_checkpoint) M(stack_rewind) \
M(unbounded_set_rgb) M(unbounded_uniform_color) \
M(unpremul) M(unpremul_polar) M(dither) \
M(load_16161616) M(load_16161616_dst) M(store_16161616) M(gather_16161616) \
M(load_a16) M(load_a16_dst) M(store_a16) M(gather_a16) \
M(load_rg1616) M(load_rg1616_dst) M(store_rg1616) M(gather_rg1616) \
M(load_f16) M(load_f16_dst) M(store_f16) M(gather_f16) \
M(load_af16) M(load_af16_dst) M(store_af16) M(gather_af16) \
M(load_rgf16) M(load_rgf16_dst) M(store_rgf16) M(gather_rgf16) \
M(load_f32) M(load_f32_dst) M(store_f32) M(gather_f32) \
M(load_rgf32) M(store_rgf32) \
M(load_1010102) M(load_1010102_dst) M(store_1010102) M(gather_1010102) \
M(load_1010102_xr) M(load_1010102_xr_dst) M(store_1010102_xr) \
M(store_u16_be) \
M(store_src_rg) M(load_src_rg) \
M(byte_tables) \
M(colorburn) M(colordodge) M(softlight) \
M(hue) M(saturation) M(color) M(luminosity) \
M(matrix_3x3) M(matrix_3x4) M(matrix_4x5) M(matrix_4x3) \
M(parametric) M(gamma_) M(PQish) M(HLGish) M(HLGinvish) \
M(rgb_to_hsl) M(hsl_to_rgb) \
M(css_lab_to_xyz) M(css_oklab_to_linear_srgb) \
M(css_hcl_to_lab) \
M(css_hsl_to_srgb) M(css_hwb_to_srgb) \
M(gauss_a_to_rgba) \
M(mirror_x) M(repeat_x) \
M(mirror_y) M(repeat_y) \
M(negate_x) \
M(bicubic_clamp_8888) \
M(bilinear_setup) \
M(bilinear_nx) M(bilinear_px) M(bilinear_ny) M(bilinear_py) \
M(bicubic_setup) \
M(bicubic_n3x) M(bicubic_n1x) M(bicubic_p1x) M(bicubic_p3x) \
M(bicubic_n3y) M(bicubic_n1y) M(bicubic_p1y) M(bicubic_p3y) \
M(accumulate) \
M(mipmap_linear_init) M(mipmap_linear_update) M(mipmap_linear_finish) \
M(xy_to_2pt_conical_strip) \
M(xy_to_2pt_conical_focal_on_circle) \
M(xy_to_2pt_conical_well_behaved) \
M(xy_to_2pt_conical_smaller) \
M(xy_to_2pt_conical_greater) \
M(alter_2pt_conical_compensate_focal) \
M(alter_2pt_conical_unswap) \
M(mask_2pt_conical_nan) \
M(mask_2pt_conical_degenerates) M(apply_vector_mask) \
M(set_base_pointer) \
/* Dedicated SkSL stages begin here: */ \
// `SK_RASTER_PIPELINE_OPS_SKSL` defines ops used by SkSL.
// This set can be empty if software SkSL (SK_ENABLE_SKSL_IN_RASTER_PIPELINE) is not enabled.
#ifdef SK_ENABLE_SKSL_IN_RASTER_PIPELINE

#define SK_RASTER_PIPELINE_OPS_SKSL(M) \
M(init_lane_masks) M(store_device_xy01) M(exchange_src) \
M(load_condition_mask) M(store_condition_mask) M(merge_condition_mask) \
M(load_loop_mask) M(store_loop_mask) M(mask_off_loop_mask) \
Expand Down Expand Up @@ -190,9 +145,65 @@
M(cmpne_n_ints) M(cmpne_int) M(cmpne_2_ints) M(cmpne_3_ints) M(cmpne_4_ints) \
M(trace_line) M(trace_var) M(trace_enter) M(trace_exit) M(trace_scope)

// The combined list of all RasterPipeline ops:
#define SK_RASTER_PIPELINE_OPS_ALL(M) \
SK_RASTER_PIPELINE_OPS_LOWP(M) \
#else
#define SK_RASTER_PIPELINE_OPS_SKSL(M)
#endif

// `SK_RASTER_PIPELINE_OPS_HIGHP_ONLY` defines ops that are only available in highp; this subset
// includes all of SkSL.
#define SK_RASTER_PIPELINE_OPS_HIGHP_ONLY(M) \
M(callback) \
M(stack_checkpoint) M(stack_rewind) \
M(unbounded_set_rgb) M(unbounded_uniform_color) \
M(unpremul) M(unpremul_polar) M(dither) \
M(load_16161616) M(load_16161616_dst) M(store_16161616) M(gather_16161616) \
M(load_a16) M(load_a16_dst) M(store_a16) M(gather_a16) \
M(load_rg1616) M(load_rg1616_dst) M(store_rg1616) M(gather_rg1616) \
M(load_f16) M(load_f16_dst) M(store_f16) M(gather_f16) \
M(load_af16) M(load_af16_dst) M(store_af16) M(gather_af16) \
M(load_rgf16) M(load_rgf16_dst) M(store_rgf16) M(gather_rgf16) \
M(load_f32) M(load_f32_dst) M(store_f32) M(gather_f32) \
M(load_rgf32) M(store_rgf32) \
M(load_1010102) M(load_1010102_dst) M(store_1010102) M(gather_1010102) \
M(load_1010102_xr) M(load_1010102_xr_dst) M(store_1010102_xr) \
M(store_u16_be) \
M(store_src_rg) M(load_src_rg) \
M(byte_tables) \
M(colorburn) M(colordodge) M(softlight) \
M(hue) M(saturation) M(color) M(luminosity) \
M(matrix_3x3) M(matrix_3x4) M(matrix_4x5) M(matrix_4x3) \
M(parametric) M(gamma_) M(PQish) M(HLGish) M(HLGinvish) \
M(rgb_to_hsl) M(hsl_to_rgb) \
M(css_lab_to_xyz) M(css_oklab_to_linear_srgb) \
M(css_hcl_to_lab) \
M(css_hsl_to_srgb) M(css_hwb_to_srgb) \
M(gauss_a_to_rgba) \
M(mirror_x) M(repeat_x) \
M(mirror_y) M(repeat_y) \
M(negate_x) \
M(bicubic_clamp_8888) \
M(bilinear_setup) \
M(bilinear_nx) M(bilinear_px) M(bilinear_ny) M(bilinear_py) \
M(bicubic_setup) \
M(bicubic_n3x) M(bicubic_n1x) M(bicubic_p1x) M(bicubic_p3x) \
M(bicubic_n3y) M(bicubic_n1y) M(bicubic_p1y) M(bicubic_p3y) \
M(accumulate) \
M(mipmap_linear_init) M(mipmap_linear_update) M(mipmap_linear_finish) \
M(xy_to_2pt_conical_strip) \
M(xy_to_2pt_conical_focal_on_circle) \
M(xy_to_2pt_conical_well_behaved) \
M(xy_to_2pt_conical_smaller) \
M(xy_to_2pt_conical_greater) \
M(alter_2pt_conical_compensate_focal) \
M(alter_2pt_conical_unswap) \
M(mask_2pt_conical_nan) \
M(mask_2pt_conical_degenerates) M(apply_vector_mask) \
M(set_base_pointer) \
SK_RASTER_PIPELINE_OPS_SKSL(M)

// The combined set of all RasterPipeline ops:
#define SK_RASTER_PIPELINE_OPS_ALL(M) \
SK_RASTER_PIPELINE_OPS_LOWP(M) \
SK_RASTER_PIPELINE_OPS_HIGHP_ONLY(M)

// An enumeration of every RasterPipeline op:
Expand Down
2 changes: 2 additions & 0 deletions src/core/SkRuntimeEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ const SkSL::RP::Program* SkRuntimeEffect::getRPProgram(SkSL::DebugTracePriv* deb
originalData->size() / sizeof(float)};
}

#ifdef SK_ENABLE_SKSL_IN_RASTER_PIPELINE
class RuntimeEffectRPCallbacks : public SkSL::RP::Callbacks {
public:
RuntimeEffectRPCallbacks(const SkStageRec& s,
Expand Down Expand Up @@ -327,6 +328,7 @@ class RuntimeEffectRPCallbacks : public SkSL::RP::Callbacks {
SkSpan<const SkRuntimeEffect::ChildPtr> fChildren;
SkSpan<const SkSL::SampleUsage> fSampleUsages;
};
#endif // SK_ENABLE_SKSL_IN_RASTER_PIPELINE

bool SkRuntimeEffectPriv::CanDraw(const SkCapabilities* caps, const SkSL::Program* program) {
SkASSERT(caps && program);
Expand Down
11 changes: 8 additions & 3 deletions src/opts/SkRasterPipeline_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -3294,6 +3294,12 @@ STAGE(callback, SkRasterPipeline_CallbackCtx* c) {
load4(c->read_from,0, &r,&g,&b,&a);
}

STAGE_TAIL(set_base_pointer, std::byte* p) {
base = p;
}

#ifdef SK_ENABLE_SKSL_IN_RASTER_PIPELINE

// All control flow stages used by SkSL maintain some state in the common registers:
// r: condition mask
// g: loop mask
Expand All @@ -3304,9 +3310,6 @@ STAGE(callback, SkRasterPipeline_CallbackCtx* c) {
#define update_execution_mask() a = sk_bit_cast<F>(sk_bit_cast<I32>(r) & \
sk_bit_cast<I32>(g) & \
sk_bit_cast<I32>(b))
STAGE_TAIL(set_base_pointer, std::byte* p) {
base = p;
}

STAGE_TAIL(init_lane_masks, NoCtx) {
uint32_t iota[] = {0,1,2,3,4,5,6,7};
Expand Down Expand Up @@ -4308,6 +4311,8 @@ DECLARE_TERNARY_INT(mix)
#undef DECLARE_TERNARY_FLOAT
#undef DECLARE_TERNARY_INT

#endif // SK_ENABLE_SKSL_IN_RASTER_PIPELINE

STAGE(gauss_a_to_rgba, NoCtx) {
// x = 1 - x;
// exp(-x * x * 4) - 0.018f;
Expand Down
13 changes: 8 additions & 5 deletions src/sksl/codegen/SkSLRasterPipelineBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* found in the LICENSE file.
*/

#include "src/sksl/codegen/SkSLRasterPipelineBuilder.h"

#ifdef SK_ENABLE_SKSL_IN_RASTER_PIPELINE

#include "include/core/SkStream.h"
#include "include/private/base/SkMalloc.h"
#include "include/private/base/SkTo.h"
Expand All @@ -16,7 +20,6 @@
#include "src/core/SkTHash.h"
#include "src/sksl/SkSLPosition.h"
#include "src/sksl/SkSLString.h"
#include "src/sksl/codegen/SkSLRasterPipelineBuilder.h"
#include "src/sksl/tracing/SkSLDebugTracePriv.h"
#include "src/sksl/tracing/SkSLTraceHook.h"
#include "src/utils/SkBitSet.h"
Expand All @@ -38,8 +41,7 @@

using namespace skia_private;

namespace SkSL {
namespace RP {
namespace SkSL::RP {

#define ALL_SINGLE_SLOT_UNARY_OP_CASES \
BuilderOp::acos_float: \
Expand Down Expand Up @@ -3370,5 +3372,6 @@ void Program::dump(SkWStream* out) const {
}
}

} // namespace RP
} // namespace SkSL
} // namespace SkSL::RP

#endif // SK_ENABLE_SKSL_IN_RASTER_PIPELINE
13 changes: 13 additions & 0 deletions src/sksl/codegen/SkSLRasterPipelineBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#ifndef SKSL_RASTERPIPELINEBUILDER
#define SKSL_RASTERPIPELINEBUILDER

#include "include/core/SkTypes.h"

#ifdef SK_ENABLE_SKSL_IN_RASTER_PIPELINE

#include "include/core/SkSpan.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkTArray.h"
Expand Down Expand Up @@ -683,4 +687,13 @@ class Builder {
} // namespace RP
} // namespace SkSL

#else // !defined(SK_ENABLE_SKSL_IN_RASTER_PIPELINE)

namespace SkSL::RP {

class Program {};

} // namespace SkSL::RP

#endif // SK_ENABLE_SKSL_IN_RASTER_PIPELINE
#endif // SKSL_RASTERPIPELINEBUILDER
7 changes: 6 additions & 1 deletion src/sksl/codegen/SkSLRasterPipelineCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* found in the LICENSE file.
*/

#include "src/sksl/codegen/SkSLRasterPipelineCodeGenerator.h"

#ifdef SK_ENABLE_SKSL_IN_RASTER_PIPELINE

#include "include/core/SkPoint.h"
#include "include/core/SkSpan.h"
#include "include/private/SkSLDefines.h"
Expand All @@ -21,7 +25,6 @@
#include "src/sksl/SkSLOperator.h"
#include "src/sksl/SkSLPosition.h"
#include "src/sksl/codegen/SkSLRasterPipelineBuilder.h"
#include "src/sksl/codegen/SkSLRasterPipelineCodeGenerator.h"
#include "src/sksl/ir/SkSLBinaryExpression.h"
#include "src/sksl/ir/SkSLBlock.h"
#include "src/sksl/ir/SkSLBreakStatement.h"
Expand Down Expand Up @@ -3730,3 +3733,5 @@ std::unique_ptr<RP::Program> MakeRasterPipelineProgram(const SkSL::Program& prog
}

} // namespace SkSL

#endif // SK_ENABLE_SKSL_IN_RASTER_PIPELINE
Loading

0 comments on commit ca1a36f

Please sign in to comment.