Make it safe to include SkRuntimeEffect.h from client code

Bundling the pipeline stage arguments also simplifies the code in
several spots.

Change-Id: I85e81b436a39378f753cc9404b6eeb27fe055525
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/261778
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2019-12-30 15:02:30 -05:00 committed by Skia Commit-Bot
parent 60b69ecc8d
commit 107c66669d
8 changed files with 31 additions and 27 deletions

View File

@ -12,7 +12,6 @@
bool FuzzSKSL2Pipeline(sk_sp<SkData> bytes) {
SkSL::Compiler compiler;
SkSL::String output;
SkSL::Program::Settings settings;
sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default();
settings.fCaps = caps.get();
@ -21,9 +20,8 @@ bool FuzzSKSL2Pipeline(sk_sp<SkData> bytes) {
SkSL::String((const char*) bytes->data(),
bytes->size()),
settings);
std::vector<SkSL::Compiler::FormatArg> formatArgs;
std::vector<SkSL::Compiler::GLSLFunction> functions;
if (!program || !compiler.toPipelineStage(*program, &output, &formatArgs, &functions)) {
SkSL::PipelineStageArgs args;
if (!program || !compiler.toPipelineStage(*program, &args)) {
return false;
}
return true;

View File

@ -53,6 +53,7 @@
#include "src/core/SkFontMgrPriv.h"
#include "src/core/SkResourceCache.h"
#include "src/core/SkRuntimeEffect.h"
#include "src/sksl/SkSLCompiler.h"
#include <iostream>
#include <string>

View File

@ -182,9 +182,7 @@ size_t SkRuntimeEffect::inputSize() const {
#if SK_SUPPORT_GPU
bool SkRuntimeEffect::toPipelineStage(const void* inputs, const GrShaderCaps* shaderCaps,
SkSL::String* outCode,
std::vector<SkSL::Compiler::FormatArg>* outFormatArgs,
std::vector<SkSL::Compiler::GLSLFunction>* outFunctions) {
SkSL::PipelineStageArgs* outArgs) {
// This function is used by the GPU backend, and can't reuse our previously built fBaseProgram.
// If the supplied shaderCaps have any non-default values, we have baked in the wrong settings.
SkSL::Program::Settings settings;
@ -233,7 +231,7 @@ bool SkRuntimeEffect::toPipelineStage(const void* inputs, const GrShaderCaps* sh
return false;
}
if (!fCompiler->toPipelineStage(*specialized, outCode, outFormatArgs, outFunctions)) {
if (!fCompiler->toPipelineStage(*specialized, outArgs)) {
SkDebugf("%s\n", fCompiler->errorText().c_str());
SkASSERT(false);
return false;

View File

@ -9,16 +9,21 @@
#define SkRuntimeEffect_DEFINED
#include "include/core/SkString.h"
#include "src/sksl/SkSLCompiler.h"
#include <vector>
#if SK_SUPPORT_GPU
#include "include/private/GrTypesPriv.h"
#endif
class GrShaderCaps;
class SkMatrix;
class SkShader;
namespace SkSL {
class ByteCode;
class Compiler;
struct PipelineStageArgs;
struct Program;
}
@ -79,9 +84,7 @@ public:
// This re-compiles the program from scratch, using the supplied shader caps.
// This is necessary to get the correct values of settings.
bool toPipelineStage(const void* inputs, const GrShaderCaps* shaderCaps,
SkSL::String* outCode,
std::vector<SkSL::Compiler::FormatArg>* outFormatArgs,
std::vector<SkSL::Compiler::GLSLFunction>* outFunctions);
SkSL::PipelineStageArgs* outArgs);
#endif
// [ByteCode, ErrorText]

View File

@ -217,12 +217,10 @@ void GrSkSLFP::addChild(std::unique_ptr<GrFragmentProcessor> child) {
GrGLSLFragmentProcessor* GrSkSLFP::onCreateGLSLInstance() const {
// Note: This is actually SkSL (again) but with inline format specifiers.
SkSL::String code;
std::vector<SkSL::Compiler::FormatArg> formatArgs;
std::vector<SkSL::Compiler::GLSLFunction> functions;
SkAssertResult(fEffect->toPipelineStage(fInputs.get(), fShaderCaps.get(),
&code, &formatArgs, &functions));
return new GrGLSLSkSLFP(code, formatArgs, functions);
SkSL::PipelineStageArgs args;
SkAssertResult(fEffect->toPipelineStage(fInputs.get(), fShaderCaps.get(), &args));
return new GrGLSLSkSLFP(std::move(args.fCode), std::move(args.fFormatArgs),
std::move(args.fFunctions));
}
void GrSkSLFP::onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {

View File

@ -1597,18 +1597,16 @@ bool Compiler::toH(Program& program, String name, OutputStream& out) {
#endif
#if !defined(SKSL_STANDALONE) && SK_SUPPORT_GPU
bool Compiler::toPipelineStage(const Program& program, String* out,
std::vector<FormatArg>* outFormatArgs,
std::vector<GLSLFunction>* outFunctions) {
bool Compiler::toPipelineStage(const Program& program, PipelineStageArgs* outArgs) {
SkASSERT(program.fIsOptimized);
fSource = program.fSource.get();
StringStream buffer;
PipelineStageCodeGenerator cg(fContext.get(), &program, this, &buffer, outFormatArgs,
outFunctions);
PipelineStageCodeGenerator cg(fContext.get(), &program, this, &buffer, &outArgs->fFormatArgs,
&outArgs->fFunctions);
bool result = cg.generateCode();
fSource = nullptr;
if (result) {
*out = buffer.str();
outArgs->fCode = buffer.str();
}
return result;
}

View File

@ -50,6 +50,7 @@ namespace SkSL {
class ByteCode;
class ExternalValue;
class IRGenerator;
struct PipelineStageArgs;
/**
* Main compiler entry point. This is a traditional compiler design which first parses the .sksl
@ -147,9 +148,7 @@ public:
std::unique_ptr<ByteCode> toByteCode(Program& program);
#if !defined(SKSL_STANDALONE) && SK_SUPPORT_GPU
bool toPipelineStage(const Program& program, String* out,
std::vector<FormatArg>* outFormatArgs,
std::vector<GLSLFunction>* outFunctions);
bool toPipelineStage(const Program& program, PipelineStageArgs* outArgs);
#endif
/**
@ -241,6 +240,14 @@ private:
String fErrorText;
};
#if !defined(SKSL_STANDALONE) && SK_SUPPORT_GPU
struct PipelineStageArgs {
String fCode;
std::vector<Compiler::FormatArg> fFormatArgs;
std::vector<Compiler::GLSLFunction> fFunctions;
};
#endif
} // namespace
#endif

View File

@ -12,6 +12,7 @@
#include "tools/Resources.h"
#include "tools/viewer/ImGuiLayer.h"
#include <algorithm>
#include "imgui.h"
using namespace sk_app;