Reland "Move GL's SkSL::Compiler to the GPU (like all other backends)"
This is a reland of cddfce2c24
Original change's description:
> Move GL's SkSL::Compiler to the GPU (like all other backends)
>
> This was the only backend that didn't store the compiler on the GrGpu,
> and also the only one that did lazy-instantiation. Trying to standardize
> this code a bit.
>
> Change-Id: Ibdd1bcc2dc9c3756b46a4c6f0543b5bb20fe135d
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/337716
> Reviewed-by: John Stiles <johnstiles@google.com>
> Commit-Queue: Brian Osman <brianosman@google.com>
Change-Id: I28cd2b20a86ca2cc34460cd494feff5b599f65bb
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/338597
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
611b2a6a0d
commit
79719263ae
@ -7,7 +7,6 @@
|
||||
|
||||
#include "src/gpu/gl/GrGLContext.h"
|
||||
#include "src/gpu/gl/GrGLGLSL.h"
|
||||
#include "src/sksl/SkSLCompiler.h"
|
||||
|
||||
#ifdef SK_BUILD_FOR_ANDROID
|
||||
#include <sys/system_properties.h>
|
||||
@ -90,16 +89,7 @@ std::unique_ptr<GrGLContext> GrGLContext::Make(sk_sp<const GrGLInterface> interf
|
||||
return std::unique_ptr<GrGLContext>(new GrGLContext(std::move(args)));
|
||||
}
|
||||
|
||||
GrGLContext::~GrGLContext() {
|
||||
delete fCompiler;
|
||||
}
|
||||
|
||||
SkSL::Compiler* GrGLContext::compiler() const {
|
||||
if (!fCompiler) {
|
||||
fCompiler = new SkSL::Compiler(fGLCaps->shaderCaps());
|
||||
}
|
||||
return fCompiler;
|
||||
}
|
||||
GrGLContext::~GrGLContext() {}
|
||||
|
||||
GrGLContextInfo::GrGLContextInfo(ConstructorArgs&& args) {
|
||||
fInterface = std::move(args.fInterface);
|
||||
|
@ -16,9 +16,6 @@
|
||||
#include "src/gpu/glsl/GrGLSL.h"
|
||||
|
||||
struct GrContextOptions;
|
||||
namespace SkSL {
|
||||
class Compiler;
|
||||
} // namespace SkSL
|
||||
|
||||
/**
|
||||
* Encapsulates information about an OpenGL context including the OpenGL
|
||||
@ -82,7 +79,7 @@ protected:
|
||||
};
|
||||
|
||||
/**
|
||||
* Extension of GrGLContextInfo that also provides access to GrGLInterface and SkSL::Compiler.
|
||||
* Extension of GrGLContextInfo that also provides access to GrGLInterface.
|
||||
*/
|
||||
class GrGLContext : public GrGLContextInfo {
|
||||
public:
|
||||
@ -94,14 +91,10 @@ public:
|
||||
|
||||
const GrGLInterface* glInterface() const { return fInterface.get(); }
|
||||
|
||||
SkSL::Compiler* compiler() const;
|
||||
|
||||
~GrGLContext() override;
|
||||
|
||||
private:
|
||||
GrGLContext(ConstructorArgs&& args) : INHERITED(std::move(args)), fCompiler(nullptr) {}
|
||||
|
||||
mutable SkSL::Compiler* fCompiler;
|
||||
GrGLContext(ConstructorArgs&& args) : INHERITED(std::move(args)) {}
|
||||
|
||||
using INHERITED = GrGLContextInfo;
|
||||
};
|
||||
|
@ -352,6 +352,7 @@ GrGLGpu::GrGLGpu(std::unique_ptr<GrGLContext> ctx, GrDirectContext* direct)
|
||||
this->checkAndResetOOMed();
|
||||
|
||||
fCaps = sk_ref_sp(fGLContext->caps());
|
||||
fCompiler = std::make_unique<SkSL::Compiler>(fCaps->shaderCaps());
|
||||
|
||||
fHWTextureUnitBindings.reset(this->numTextureUnits());
|
||||
|
||||
@ -3048,14 +3049,14 @@ bool GrGLGpu::createCopyProgram(GrTexture* srcTex) {
|
||||
SkSL::String sksl(vshaderTxt.c_str(), vshaderTxt.size());
|
||||
SkSL::Program::Settings settings;
|
||||
SkSL::String glsl;
|
||||
std::unique_ptr<SkSL::Program> program = GrSkSLtoGLSL(*fGLContext, SkSL::Program::kVertex_Kind,
|
||||
std::unique_ptr<SkSL::Program> program = GrSkSLtoGLSL(this, SkSL::Program::kVertex_Kind,
|
||||
sksl, settings, &glsl, errorHandler);
|
||||
GrGLuint vshader = GrGLCompileAndAttachShader(*fGLContext, fCopyPrograms[progIdx].fProgram,
|
||||
GR_GL_VERTEX_SHADER, glsl, &fStats, errorHandler);
|
||||
SkASSERT(program->fInputs.isEmpty());
|
||||
|
||||
sksl.assign(fshaderTxt.c_str(), fshaderTxt.size());
|
||||
program = GrSkSLtoGLSL(*fGLContext, SkSL::Program::kFragment_Kind, sksl, settings, &glsl,
|
||||
program = GrSkSLtoGLSL(this, SkSL::Program::kFragment_Kind, sksl, settings, &glsl,
|
||||
errorHandler);
|
||||
GrGLuint fshader = GrGLCompileAndAttachShader(*fGLContext, fCopyPrograms[progIdx].fProgram,
|
||||
GR_GL_FRAGMENT_SHADER, glsl, &fStats,
|
||||
@ -3201,14 +3202,14 @@ bool GrGLGpu::createMipmapProgram(int progIdx) {
|
||||
SkSL::String sksl(vshaderTxt.c_str(), vshaderTxt.size());
|
||||
SkSL::Program::Settings settings;
|
||||
SkSL::String glsl;
|
||||
std::unique_ptr<SkSL::Program> program = GrSkSLtoGLSL(*fGLContext, SkSL::Program::kVertex_Kind,
|
||||
std::unique_ptr<SkSL::Program> program = GrSkSLtoGLSL(this, SkSL::Program::kVertex_Kind,
|
||||
sksl, settings, &glsl, errorHandler);
|
||||
GrGLuint vshader = GrGLCompileAndAttachShader(*fGLContext, fMipmapPrograms[progIdx].fProgram,
|
||||
GR_GL_VERTEX_SHADER, glsl, &fStats, errorHandler);
|
||||
SkASSERT(program->fInputs.isEmpty());
|
||||
|
||||
sksl.assign(fshaderTxt.c_str(), fshaderTxt.size());
|
||||
program = GrSkSLtoGLSL(*fGLContext, SkSL::Program::kFragment_Kind, sksl, settings, &glsl,
|
||||
program = GrSkSLtoGLSL(this, SkSL::Program::kFragment_Kind, sksl, settings, &glsl,
|
||||
errorHandler);
|
||||
GrGLuint fshader = GrGLCompileAndAttachShader(*fGLContext, fMipmapPrograms[progIdx].fProgram,
|
||||
GR_GL_FRAGMENT_SHADER, glsl, &fStats,
|
||||
|
@ -30,6 +30,10 @@ class GrGLOpsRenderPass;
|
||||
class GrPipeline;
|
||||
class GrSwizzle;
|
||||
|
||||
namespace SkSL {
|
||||
class Compiler;
|
||||
}
|
||||
|
||||
class GrGLGpu final : public GrGpu {
|
||||
public:
|
||||
static sk_sp<GrGpu> Make(sk_sp<const GrGLInterface>, const GrContextOptions&, GrDirectContext*);
|
||||
@ -193,6 +197,10 @@ public:
|
||||
// Version for programs that aren't GrGLProgram.
|
||||
void flushProgram(GrGLuint);
|
||||
|
||||
SkSL::Compiler* shaderCompiler() const {
|
||||
return fCompiler.get();
|
||||
}
|
||||
|
||||
private:
|
||||
GrGLGpu(std::unique_ptr<GrGLContext>, GrDirectContext*);
|
||||
|
||||
@ -513,6 +521,8 @@ private:
|
||||
// GL program-related state
|
||||
std::unique_ptr<ProgramCache> fProgramCache;
|
||||
|
||||
std::unique_ptr<SkSL::Compiler> fCompiler;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
///@name Caching of GL State
|
||||
///@{
|
||||
|
@ -329,7 +329,7 @@ sk_sp<GrGLProgram> GrGLProgramBuilder::finalize(const GrGLPrecompiledProgram* pr
|
||||
if (fFS.fForceHighPrecision) {
|
||||
settings.fForceHighPrecision = true;
|
||||
}
|
||||
std::unique_ptr<SkSL::Program> fs = GrSkSLtoGLSL(gpu()->glContext(),
|
||||
std::unique_ptr<SkSL::Program> fs = GrSkSLtoGLSL(this->gpu(),
|
||||
SkSL::Program::kFragment_Kind,
|
||||
*sksl[kFragment_GrShaderType],
|
||||
settings,
|
||||
@ -354,7 +354,7 @@ sk_sp<GrGLProgram> GrGLProgramBuilder::finalize(const GrGLPrecompiledProgram* pr
|
||||
*/
|
||||
if (glsl[kVertex_GrShaderType].empty()) {
|
||||
// Don't have cached GLSL, need to compile SkSL->GLSL
|
||||
std::unique_ptr<SkSL::Program> vs = GrSkSLtoGLSL(gpu()->glContext(),
|
||||
std::unique_ptr<SkSL::Program> vs = GrSkSLtoGLSL(this->gpu(),
|
||||
SkSL::Program::kVertex_Kind,
|
||||
*sksl[kVertex_GrShaderType],
|
||||
settings,
|
||||
@ -418,7 +418,7 @@ sk_sp<GrGLProgram> GrGLProgramBuilder::finalize(const GrGLPrecompiledProgram* pr
|
||||
if (glsl[kGeometry_GrShaderType].empty()) {
|
||||
// Don't have cached GLSL, need to compile SkSL->GLSL
|
||||
std::unique_ptr<SkSL::Program> gs;
|
||||
gs = GrSkSLtoGLSL(gpu()->glContext(),
|
||||
gs = GrSkSLtoGLSL(this->gpu(),
|
||||
SkSL::Program::kGeometry_Kind,
|
||||
*sksl[kGeometry_GrShaderType],
|
||||
settings,
|
||||
@ -601,7 +601,7 @@ bool GrGLProgramBuilder::PrecompileProgram(GrGLPrecompiledProgram* precompiledPr
|
||||
|
||||
auto compileShader = [&](SkSL::Program::Kind kind, const SkSL::String& sksl, GrGLenum type) {
|
||||
SkSL::String glsl;
|
||||
auto program = GrSkSLtoGLSL(gpu->glContext(), kind, sksl, settings, &glsl, errorHandler);
|
||||
auto program = GrSkSLtoGLSL(gpu, kind, sksl, settings, &glsl, errorHandler);
|
||||
if (!program) {
|
||||
return false;
|
||||
}
|
||||
|
@ -17,13 +17,13 @@
|
||||
static const bool gPrintSKSL = false;
|
||||
static const bool gPrintGLSL = false;
|
||||
|
||||
std::unique_ptr<SkSL::Program> GrSkSLtoGLSL(const GrGLContext& context,
|
||||
std::unique_ptr<SkSL::Program> GrSkSLtoGLSL(const GrGLGpu* gpu,
|
||||
SkSL::Program::Kind programKind,
|
||||
const SkSL::String& sksl,
|
||||
const SkSL::Program::Settings& settings,
|
||||
SkSL::String* glsl,
|
||||
GrContextOptions::ShaderErrorHandler* errorHandler) {
|
||||
SkSL::Compiler* compiler = context.compiler();
|
||||
SkSL::Compiler* compiler = gpu->shaderCompiler();
|
||||
std::unique_ptr<SkSL::Program> program;
|
||||
#ifdef SK_DEBUG
|
||||
SkSL::String src = GrShaderUtils::PrettyPrint(sksl);
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include "src/gpu/gl/GrGLContext.h"
|
||||
#include "src/sksl/SkSLGLSLCodeGenerator.h"
|
||||
|
||||
std::unique_ptr<SkSL::Program> GrSkSLtoGLSL(const GrGLContext& context,
|
||||
std::unique_ptr<SkSL::Program> GrSkSLtoGLSL(const GrGLGpu* gpu,
|
||||
SkSL::Program::Kind programKind,
|
||||
const SkSL::String& sksl,
|
||||
const SkSL::Program::Settings& settings,
|
||||
|
Loading…
Reference in New Issue
Block a user