Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 68ac3b9

Browse files
brianosmanSkia Commit-Bot
authored andcommitted
Revert "Move GL's SkSL::Compiler to the GPU (like all other backends)"
This reverts commit cddfce2. Reason for revert: Failing Flutter unit tests with *certain* test orderings. 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> TBR=brianosman@google.com,michaelludwig@google.com,johnstiles@google.com Change-Id: I043ad395472fe20addcc59784aefe9061dae02ba No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://skia-review.googlesource.com/c/skia/+/338039 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
1 parent 3df7196 commit 68ac3b9

File tree

7 files changed

+31
-25
lines changed

7 files changed

+31
-25
lines changed

src/gpu/gl/GrGLContext.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "src/gpu/gl/GrGLContext.h"
99
#include "src/gpu/gl/GrGLGLSL.h"
10+
#include "src/sksl/SkSLCompiler.h"
1011

1112
#ifdef SK_BUILD_FOR_ANDROID
1213
#include <sys/system_properties.h>
@@ -89,7 +90,16 @@ std::unique_ptr<GrGLContext> GrGLContext::Make(sk_sp<const GrGLInterface> interf
8990
return std::unique_ptr<GrGLContext>(new GrGLContext(std::move(args)));
9091
}
9192

92-
GrGLContext::~GrGLContext() {}
93+
GrGLContext::~GrGLContext() {
94+
delete fCompiler;
95+
}
96+
97+
SkSL::Compiler* GrGLContext::compiler() const {
98+
if (!fCompiler) {
99+
fCompiler = new SkSL::Compiler(fGLCaps->shaderCaps());
100+
}
101+
return fCompiler;
102+
}
93103

94104
GrGLContextInfo::GrGLContextInfo(ConstructorArgs&& args) {
95105
fInterface = std::move(args.fInterface);

src/gpu/gl/GrGLContext.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#include "src/gpu/glsl/GrGLSL.h"
1717

1818
struct GrContextOptions;
19+
namespace SkSL {
20+
class Compiler;
21+
} // namespace SkSL
1922

2023
/**
2124
* Encapsulates information about an OpenGL context including the OpenGL
@@ -79,7 +82,7 @@ class GrGLContextInfo {
7982
};
8083

8184
/**
82-
* Extension of GrGLContextInfo that also provides access to GrGLInterface.
85+
* Extension of GrGLContextInfo that also provides access to GrGLInterface and SkSL::Compiler.
8386
*/
8487
class GrGLContext : public GrGLContextInfo {
8588
public:
@@ -91,10 +94,14 @@ class GrGLContext : public GrGLContextInfo {
9194

9295
const GrGLInterface* glInterface() const { return fInterface.get(); }
9396

97+
SkSL::Compiler* compiler() const;
98+
9499
~GrGLContext() override;
95100

96101
private:
97-
GrGLContext(ConstructorArgs&& args) : INHERITED(std::move(args)) {}
102+
GrGLContext(ConstructorArgs&& args) : INHERITED(std::move(args)), fCompiler(nullptr) {}
103+
104+
mutable SkSL::Compiler* fCompiler;
98105

99106
using INHERITED = GrGLContextInfo;
100107
};

src/gpu/gl/GrGLGpu.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,6 @@ GrGLGpu::GrGLGpu(std::unique_ptr<GrGLContext> ctx, GrDirectContext* direct)
352352
this->checkAndResetOOMed();
353353

354354
fCaps = sk_ref_sp(fGLContext->caps());
355-
fCompiler = std::make_unique<SkSL::Compiler>(fCaps->shaderCaps());
356355

357356
fHWTextureUnitBindings.reset(this->numTextureUnits());
358357

@@ -3049,14 +3048,14 @@ bool GrGLGpu::createCopyProgram(GrTexture* srcTex) {
30493048
SkSL::String sksl(vshaderTxt.c_str(), vshaderTxt.size());
30503049
SkSL::Program::Settings settings;
30513050
SkSL::String glsl;
3052-
std::unique_ptr<SkSL::Program> program = GrSkSLtoGLSL(this, SkSL::Program::kVertex_Kind,
3051+
std::unique_ptr<SkSL::Program> program = GrSkSLtoGLSL(*fGLContext, SkSL::Program::kVertex_Kind,
30533052
sksl, settings, &glsl, errorHandler);
30543053
GrGLuint vshader = GrGLCompileAndAttachShader(*fGLContext, fCopyPrograms[progIdx].fProgram,
30553054
GR_GL_VERTEX_SHADER, glsl, &fStats, errorHandler);
30563055
SkASSERT(program->fInputs.isEmpty());
30573056

30583057
sksl.assign(fshaderTxt.c_str(), fshaderTxt.size());
3059-
program = GrSkSLtoGLSL(this, SkSL::Program::kFragment_Kind, sksl, settings, &glsl,
3058+
program = GrSkSLtoGLSL(*fGLContext, SkSL::Program::kFragment_Kind, sksl, settings, &glsl,
30603059
errorHandler);
30613060
GrGLuint fshader = GrGLCompileAndAttachShader(*fGLContext, fCopyPrograms[progIdx].fProgram,
30623061
GR_GL_FRAGMENT_SHADER, glsl, &fStats,
@@ -3202,14 +3201,14 @@ bool GrGLGpu::createMipmapProgram(int progIdx) {
32023201
SkSL::String sksl(vshaderTxt.c_str(), vshaderTxt.size());
32033202
SkSL::Program::Settings settings;
32043203
SkSL::String glsl;
3205-
std::unique_ptr<SkSL::Program> program = GrSkSLtoGLSL(this, SkSL::Program::kVertex_Kind,
3204+
std::unique_ptr<SkSL::Program> program = GrSkSLtoGLSL(*fGLContext, SkSL::Program::kVertex_Kind,
32063205
sksl, settings, &glsl, errorHandler);
32073206
GrGLuint vshader = GrGLCompileAndAttachShader(*fGLContext, fMipmapPrograms[progIdx].fProgram,
32083207
GR_GL_VERTEX_SHADER, glsl, &fStats, errorHandler);
32093208
SkASSERT(program->fInputs.isEmpty());
32103209

32113210
sksl.assign(fshaderTxt.c_str(), fshaderTxt.size());
3212-
program = GrSkSLtoGLSL(this, SkSL::Program::kFragment_Kind, sksl, settings, &glsl,
3211+
program = GrSkSLtoGLSL(*fGLContext, SkSL::Program::kFragment_Kind, sksl, settings, &glsl,
32133212
errorHandler);
32143213
GrGLuint fshader = GrGLCompileAndAttachShader(*fGLContext, fMipmapPrograms[progIdx].fProgram,
32153214
GR_GL_FRAGMENT_SHADER, glsl, &fStats,

src/gpu/gl/GrGLGpu.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ class GrGLOpsRenderPass;
3030
class GrPipeline;
3131
class GrSwizzle;
3232

33-
namespace SkSL {
34-
class Compiler;
35-
}
36-
3733
class GrGLGpu final : public GrGpu {
3834
public:
3935
static sk_sp<GrGpu> Make(sk_sp<const GrGLInterface>, const GrContextOptions&, GrDirectContext*);
@@ -197,10 +193,6 @@ class GrGLGpu final : public GrGpu {
197193
// Version for programs that aren't GrGLProgram.
198194
void flushProgram(GrGLuint);
199195

200-
SkSL::Compiler* shaderCompiler() const {
201-
return fCompiler.get();
202-
}
203-
204196
private:
205197
GrGLGpu(std::unique_ptr<GrGLContext>, GrDirectContext*);
206198

@@ -521,8 +513,6 @@ class GrGLGpu final : public GrGpu {
521513
// GL program-related state
522514
std::unique_ptr<ProgramCache> fProgramCache;
523515

524-
std::unique_ptr<SkSL::Compiler> fCompiler;
525-
526516
///////////////////////////////////////////////////////////////////////////
527517
///@name Caching of GL State
528518
///@{

src/gpu/gl/builders/GrGLProgramBuilder.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ sk_sp<GrGLProgram> GrGLProgramBuilder::finalize(const GrGLPrecompiledProgram* pr
329329
if (fFS.fForceHighPrecision) {
330330
settings.fForceHighPrecision = true;
331331
}
332-
std::unique_ptr<SkSL::Program> fs = GrSkSLtoGLSL(this->gpu(),
332+
std::unique_ptr<SkSL::Program> fs = GrSkSLtoGLSL(gpu()->glContext(),
333333
SkSL::Program::kFragment_Kind,
334334
*sksl[kFragment_GrShaderType],
335335
settings,
@@ -354,7 +354,7 @@ sk_sp<GrGLProgram> GrGLProgramBuilder::finalize(const GrGLPrecompiledProgram* pr
354354
*/
355355
if (glsl[kVertex_GrShaderType].empty()) {
356356
// Don't have cached GLSL, need to compile SkSL->GLSL
357-
std::unique_ptr<SkSL::Program> vs = GrSkSLtoGLSL(this->gpu(),
357+
std::unique_ptr<SkSL::Program> vs = GrSkSLtoGLSL(gpu()->glContext(),
358358
SkSL::Program::kVertex_Kind,
359359
*sksl[kVertex_GrShaderType],
360360
settings,
@@ -418,7 +418,7 @@ sk_sp<GrGLProgram> GrGLProgramBuilder::finalize(const GrGLPrecompiledProgram* pr
418418
if (glsl[kGeometry_GrShaderType].empty()) {
419419
// Don't have cached GLSL, need to compile SkSL->GLSL
420420
std::unique_ptr<SkSL::Program> gs;
421-
gs = GrSkSLtoGLSL(this->gpu(),
421+
gs = GrSkSLtoGLSL(gpu()->glContext(),
422422
SkSL::Program::kGeometry_Kind,
423423
*sksl[kGeometry_GrShaderType],
424424
settings,
@@ -601,7 +601,7 @@ bool GrGLProgramBuilder::PrecompileProgram(GrGLPrecompiledProgram* precompiledPr
601601

602602
auto compileShader = [&](SkSL::Program::Kind kind, const SkSL::String& sksl, GrGLenum type) {
603603
SkSL::String glsl;
604-
auto program = GrSkSLtoGLSL(gpu, kind, sksl, settings, &glsl, errorHandler);
604+
auto program = GrSkSLtoGLSL(gpu->glContext(), kind, sksl, settings, &glsl, errorHandler);
605605
if (!program) {
606606
return false;
607607
}

src/gpu/gl/builders/GrGLShaderStringBuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
static const bool gPrintSKSL = false;
1818
static const bool gPrintGLSL = false;
1919

20-
std::unique_ptr<SkSL::Program> GrSkSLtoGLSL(const GrGLGpu* gpu,
20+
std::unique_ptr<SkSL::Program> GrSkSLtoGLSL(const GrGLContext& context,
2121
SkSL::Program::Kind programKind,
2222
const SkSL::String& sksl,
2323
const SkSL::Program::Settings& settings,
2424
SkSL::String* glsl,
2525
GrContextOptions::ShaderErrorHandler* errorHandler) {
26-
SkSL::Compiler* compiler = gpu->shaderCompiler();
26+
SkSL::Compiler* compiler = context.compiler();
2727
std::unique_ptr<SkSL::Program> program;
2828
#ifdef SK_DEBUG
2929
SkSL::String src = GrShaderUtils::PrettyPrint(sksl);

src/gpu/gl/builders/GrGLShaderStringBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "src/gpu/gl/GrGLContext.h"
1515
#include "src/sksl/SkSLGLSLCodeGenerator.h"
1616

17-
std::unique_ptr<SkSL::Program> GrSkSLtoGLSL(const GrGLGpu* gpu,
17+
std::unique_ptr<SkSL::Program> GrSkSLtoGLSL(const GrGLContext& context,
1818
SkSL::Program::Kind programKind,
1919
const SkSL::String& sksl,
2020
const SkSL::Program::Settings& settings,

0 commit comments

Comments
 (0)