Skip to content

Commit 4777e3a

Browse files
rphilliSkia Commit-Bot
authored andcommitted
Cleanup program building a bit
This CL: now passes the GrProgramDesc as a const& returns GrGLProgram as an sk_sp makes the parameter ordering more consistent makes GrVkPipelineState no longer ref-counted This is pulled out of the DDL pre-compile CL which touches this portion of the code. Bug: skia:9455 Change-Id: Id4d06f93450e276de5a2662be330ae9523026244 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/268777 Reviewed-by: Greg Daniel <[email protected]> Commit-Queue: Robert Phillips <[email protected]>
1 parent 3225306 commit 4777e3a

16 files changed

+102
-117
lines changed

src/gpu/gl/GrGLGpu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1817,7 +1817,7 @@ void GrGLGpu::disableWindowRectangles() {
18171817

18181818
bool GrGLGpu::flushGLState(GrRenderTarget* renderTarget, const GrProgramInfo& programInfo) {
18191819

1820-
sk_sp<GrGLProgram> program(fProgramCache->refProgram(this, renderTarget, programInfo));
1820+
sk_sp<GrGLProgram> program(fProgramCache->findOrCreateProgram(renderTarget, programInfo));
18211821
if (!program) {
18221822
GrCapsDebugf(this->caps(), "Failed to create program!\n");
18231823
return false;

src/gpu/gl/GrGLGpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ class GrGLGpu final : public GrGpu, private GrMesh::SendToGpuImpl {
316316

317317
void abandon();
318318
void reset();
319-
GrGLProgram* refProgram(GrGLGpu*, GrRenderTarget*, const GrProgramInfo&);
319+
sk_sp<GrGLProgram> findOrCreateProgram(GrRenderTarget*, const GrProgramInfo&);
320320
bool precompileShader(const SkData& key, const SkData& data);
321321

322322
private:

src/gpu/gl/GrGLGpuProgramCache.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,13 @@ void GrGLGpu::ProgramCache::reset() {
4545
fMap.reset();
4646
}
4747

48-
GrGLProgram* GrGLGpu::ProgramCache::refProgram(GrGLGpu* gpu,
49-
GrRenderTarget* renderTarget,
50-
const GrProgramInfo& programInfo) {
51-
const GrCaps& caps = *gpu->caps();
48+
sk_sp<GrGLProgram> GrGLGpu::ProgramCache::findOrCreateProgram(GrRenderTarget* renderTarget,
49+
const GrProgramInfo& programInfo) {
50+
const GrCaps& caps = *fGpu->caps();
5251

5352
GrProgramDesc desc = caps.makeDesc(renderTarget, programInfo);
5453
if (!desc.isValid()) {
55-
GrCapsDebugf(gpu->caps(), "Failed to gl program descriptor!\n");
54+
GrCapsDebugf(fGpu->caps(), "Failed to gl program descriptor!\n");
5655
return nullptr;
5756
}
5857

@@ -61,26 +60,24 @@ GrGLProgram* GrGLGpu::ProgramCache::refProgram(GrGLGpu* gpu,
6160
// We've pre-compiled the GL program, but don't have the GrGLProgram scaffolding
6261
const GrGLPrecompiledProgram* precompiledProgram = &((*entry)->fPrecompiledProgram);
6362
SkASSERT(precompiledProgram->fProgramID != 0);
64-
GrGLProgram* program = GrGLProgramBuilder::CreateProgram(renderTarget, programInfo,
65-
&desc, fGpu,
66-
precompiledProgram);
67-
if (nullptr == program) {
63+
(*entry)->fProgram = GrGLProgramBuilder::CreateProgram(fGpu, renderTarget, desc,
64+
programInfo, precompiledProgram);
65+
if (!(*entry)->fProgram) {
6866
// Should we purge the program ID from the cache at this point?
6967
SkDEBUGFAIL("Couldn't create program from precompiled program");
7068
return nullptr;
7169
}
72-
(*entry)->fProgram.reset(program);
7370
} else if (!entry) {
7471
// We have a cache miss
75-
GrGLProgram* program = GrGLProgramBuilder::CreateProgram(renderTarget, programInfo,
76-
&desc, fGpu);
77-
if (nullptr == program) {
72+
sk_sp<GrGLProgram> program = GrGLProgramBuilder::CreateProgram(fGpu, renderTarget,
73+
desc, programInfo);
74+
if (!program) {
7875
return nullptr;
7976
}
80-
entry = fMap.insert(desc, std::unique_ptr<Entry>(new Entry(sk_sp<GrGLProgram>(program))));
77+
entry = fMap.insert(desc, std::unique_ptr<Entry>(new Entry(std::move(program))));
8178
}
8279

83-
return SkRef((*entry)->fProgram.get());
80+
return (*entry)->fProgram;
8481
}
8582

8683
bool GrGLGpu::ProgramCache::precompileShader(const SkData& key, const SkData& data) {

src/gpu/gl/builders/GrGLProgramBuilder.cpp

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,22 @@ static void cleanup_program(GrGLGpu* gpu, GrGLuint programID,
4545
cleanup_shaders(gpu, shaderIDs);
4646
}
4747

48-
GrGLProgram* GrGLProgramBuilder::CreateProgram(GrRenderTarget* renderTarget,
49-
const GrProgramInfo& programInfo,
50-
GrProgramDesc* desc,
48+
sk_sp<GrGLProgram> GrGLProgramBuilder::CreateProgram(
5149
GrGLGpu* gpu,
50+
GrRenderTarget* renderTarget,
51+
const GrProgramDesc& desc,
52+
const GrProgramInfo& programInfo,
5253
const GrGLPrecompiledProgram* precompiledProgram) {
5354
ATRACE_ANDROID_FRAMEWORK_ALWAYS("shader_compile");
5455
GrAutoLocaleSetter als("C");
5556

5657
// create a builder. This will be handed off to effects so they can use it to add
5758
// uniforms, varyings, textures, etc
58-
GrGLProgramBuilder builder(gpu, renderTarget, programInfo, desc);
59+
GrGLProgramBuilder builder(gpu, renderTarget, desc, programInfo);
5960

6061
auto persistentCache = gpu->getContext()->priv().getPersistentCache();
6162
if (persistentCache && !precompiledProgram) {
62-
sk_sp<SkData> key = SkData::MakeWithoutCopy(desc->asKey(), desc->keyLength());
63+
sk_sp<SkData> key = SkData::MakeWithoutCopy(desc.asKey(), desc.keyLength());
6364
builder.fCached = persistentCache->load(*key);
6465
// the eventual end goal is to completely skip emitAndInstallProcs on a cache hit, but it's
6566
// doing necessary setup in addition to generating the SkSL code. Currently we are only able
@@ -75,9 +76,9 @@ GrGLProgram* GrGLProgramBuilder::CreateProgram(GrRenderTarget* renderTarget,
7576

7677
GrGLProgramBuilder::GrGLProgramBuilder(GrGLGpu* gpu,
7778
GrRenderTarget* renderTarget,
78-
const GrProgramInfo& programInfo,
79-
GrProgramDesc* desc)
80-
: INHERITED(renderTarget, programInfo, desc)
79+
const GrProgramDesc& desc,
80+
const GrProgramInfo& programInfo)
81+
: INHERITED(renderTarget, desc, programInfo)
8182
, fGpu(gpu)
8283
, fVaryingHandler(this)
8384
, fUniformHandler(this)
@@ -159,7 +160,7 @@ void GrGLProgramBuilder::storeShaderInCache(const SkSL::Program::Inputs& inputs,
159160
if (!this->gpu()->getContext()->priv().getPersistentCache()) {
160161
return;
161162
}
162-
sk_sp<SkData> key = SkData::MakeWithoutCopy(this->desc()->asKey(), this->desc()->keyLength());
163+
sk_sp<SkData> key = SkData::MakeWithoutCopy(this->desc().asKey(), this->desc().keyLength());
163164
if (fGpu->glCaps().programBinarySupport()) {
164165
// binary cache
165166
GrGLsizei length = 0;
@@ -198,7 +199,7 @@ void GrGLProgramBuilder::storeShaderInCache(const SkSL::Program::Inputs& inputs,
198199
}
199200
}
200201

201-
GrGLProgram* GrGLProgramBuilder::finalize(const GrGLPrecompiledProgram* precompiledProgram) {
202+
sk_sp<GrGLProgram> GrGLProgramBuilder::finalize(const GrGLPrecompiledProgram* precompiledProgram) {
202203
TRACE_EVENT0("skia.gpu", TRACE_FUNC);
203204

204205
// verify we can get a program id
@@ -541,22 +542,22 @@ void GrGLProgramBuilder::resolveProgramResourceLocations(GrGLuint programID, boo
541542
}
542543
}
543544

544-
GrGLProgram* GrGLProgramBuilder::createProgram(GrGLuint programID) {
545-
return new GrGLProgram(fGpu,
546-
fUniformHandles,
547-
programID,
548-
fUniformHandler.fUniforms,
549-
fUniformHandler.fSamplers,
550-
fVaryingHandler.fPathProcVaryingInfos,
551-
std::move(fGeometryProcessor),
552-
std::move(fXferProcessor),
553-
std::move(fFragmentProcessors),
554-
fFragmentProcessorCnt,
555-
std::move(fAttributes),
556-
fVertexAttributeCnt,
557-
fInstanceAttributeCnt,
558-
fVertexStride,
559-
fInstanceStride);
545+
sk_sp<GrGLProgram> GrGLProgramBuilder::createProgram(GrGLuint programID) {
546+
return sk_sp<GrGLProgram>(new GrGLProgram(fGpu,
547+
fUniformHandles,
548+
programID,
549+
fUniformHandler.fUniforms,
550+
fUniformHandler.fSamplers,
551+
fVaryingHandler.fPathProcVaryingInfos,
552+
std::move(fGeometryProcessor),
553+
std::move(fXferProcessor),
554+
std::move(fFragmentProcessors),
555+
fFragmentProcessorCnt,
556+
std::move(fAttributes),
557+
fVertexAttributeCnt,
558+
fInstanceAttributeCnt,
559+
fVertexStride,
560+
fInstanceStride));
560561
}
561562

562563
bool GrGLProgramBuilder::PrecompileProgram(GrGLPrecompiledProgram* precompiledProgram,

src/gpu/gl/builders/GrGLProgramBuilder.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,15 @@ class GrGLProgramBuilder : public GrGLSLProgramBuilder {
4040
* The program implements what is specified in the stages given as input.
4141
* After successful generation, the builder result objects are available
4242
* to be used.
43-
* This function may modify the GrProgramDesc by setting the surface origin
44-
* key to 0 (unspecified) if it turns out the program does not care about
45-
* the surface origin.
4643
* If a GL program has already been created, the program ID and inputs can
4744
* be supplied to skip the shader compilation.
48-
* @return true if generation was successful.
45+
* @return the created program if generation was successful.
4946
*/
50-
static GrGLProgram* CreateProgram(GrRenderTarget*,
51-
const GrProgramInfo&,
52-
GrProgramDesc*,
53-
GrGLGpu*,
54-
const GrGLPrecompiledProgram* = nullptr);
47+
static sk_sp<GrGLProgram> CreateProgram(GrGLGpu*,
48+
GrRenderTarget*,
49+
const GrProgramDesc&,
50+
const GrProgramInfo&,
51+
const GrGLPrecompiledProgram* = nullptr);
5552

5653
static bool PrecompileProgram(GrGLPrecompiledProgram*, GrGLGpu*, const SkData&);
5754

@@ -60,7 +57,7 @@ class GrGLProgramBuilder : public GrGLSLProgramBuilder {
6057
GrGLGpu* gpu() const { return fGpu; }
6158

6259
private:
63-
GrGLProgramBuilder(GrGLGpu*, GrRenderTarget*, const GrProgramInfo&, GrProgramDesc*);
60+
GrGLProgramBuilder(GrGLGpu*, GrRenderTarget*, const GrProgramDesc&, const GrProgramInfo&);
6461

6562
void addInputVars(const SkSL::Program::Inputs& inputs);
6663
bool compileAndAttachShaders(const SkSL::String& glsl,
@@ -74,14 +71,14 @@ class GrGLProgramBuilder : public GrGLSLProgramBuilder {
7471
void storeShaderInCache(const SkSL::Program::Inputs& inputs, GrGLuint programID,
7572
const SkSL::String shaders[], bool isSkSL,
7673
SkSL::Program::Settings* settings);
77-
GrGLProgram* finalize(const GrGLPrecompiledProgram*);
74+
sk_sp<GrGLProgram> finalize(const GrGLPrecompiledProgram*);
7875
void bindProgramResourceLocations(GrGLuint programID);
7976
bool checkLinkStatus(GrGLuint programID, GrContextOptions::ShaderErrorHandler* errorHandler,
8077
SkSL::String* sksl[], const SkSL::String glsl[]);
8178
void resolveProgramResourceLocations(GrGLuint programID, bool force);
8279

8380
// Subclasses create different programs
84-
GrGLProgram* createProgram(GrGLuint programID);
81+
sk_sp<GrGLProgram> createProgram(GrGLuint programID);
8582

8683
GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; }
8784
const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; }

src/gpu/glsl/GrGLSLProgramBuilder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
const int GrGLSLProgramBuilder::kVarsPerBlock = 8;
2222

2323
GrGLSLProgramBuilder::GrGLSLProgramBuilder(GrRenderTarget* renderTarget,
24-
const GrProgramInfo& programInfo,
25-
const GrProgramDesc* desc)
24+
const GrProgramDesc& desc,
25+
const GrProgramInfo& programInfo)
2626
: fVS(this)
2727
, fGS(this)
2828
, fFS(this)
2929
, fStageIndex(-1)
3030
, fRenderTarget(renderTarget)
31-
, fProgramInfo(programInfo)
3231
, fDesc(desc)
32+
, fProgramInfo(programInfo)
3333
, fGeometryProcessor(nullptr)
3434
, fXferProcessor(nullptr)
3535
, fNumFragmentSamplers(0) {}

src/gpu/glsl/GrGLSLProgramBuilder.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class GrGLSLProgramBuilder {
5757
return fRenderTarget->renderTargetPriv().getSampleLocations();
5858
}
5959

60-
const GrProgramDesc* desc() const { return fDesc; }
60+
const GrProgramDesc& desc() const { return fDesc; }
6161

6262
void appendUniformDecls(GrShaderFlags visibility, SkString*) const;
6363

@@ -104,10 +104,9 @@ class GrGLSLProgramBuilder {
104104
int fStageIndex;
105105

106106
const GrRenderTarget* fRenderTarget; // TODO: remove this
107+
const GrProgramDesc& fDesc;
107108
const GrProgramInfo& fProgramInfo;
108109

109-
const GrProgramDesc* fDesc;
110-
111110
GrGLSLBuiltinUniformHandles fUniformHandles;
112111

113112
std::unique_ptr<GrGLSLPrimitiveProcessor> fGeometryProcessor;
@@ -116,7 +115,7 @@ class GrGLSLProgramBuilder {
116115
int fFragmentProcessorCnt;
117116

118117
protected:
119-
explicit GrGLSLProgramBuilder(GrRenderTarget*, const GrProgramInfo&, const GrProgramDesc*);
118+
explicit GrGLSLProgramBuilder(GrRenderTarget*, const GrProgramDesc&, const GrProgramInfo&);
120119

121120
void addFeature(GrShaderFlags shaders, uint32_t featureBit, const char* extensionName);
122121

src/gpu/mtl/GrMtlPipelineStateBuilder.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ class GrMtlPipelineStateBuilder : public GrGLSLProgramBuilder {
2929
*
3030
* The GrMtlPipelineState implements what is specified in the GrPipeline and
3131
* GrPrimitiveProcessor as input. After successful generation, the builder result objects are
32-
* available to be used. This function may modify the program key by setting the surface origin
33-
* key to 0 (unspecified) if it turns out the program does not care about the surface origin.
34-
* @return true if generation was successful.
32+
* available to be used.
33+
* @return the created pipeline if generation was successful; nullptr otherwise
3534
*/
3635
static GrMtlPipelineState* CreatePipelineState(GrMtlGpu*,
3736
GrRenderTarget*,
38-
const GrProgramInfo&,
39-
GrProgramDesc*);
37+
const GrProgramDesc&,
38+
const GrProgramInfo&);
4039

4140
private:
42-
GrMtlPipelineStateBuilder(GrMtlGpu*, GrRenderTarget*, const GrProgramInfo&, GrProgramDesc*);
41+
GrMtlPipelineStateBuilder(GrMtlGpu*, GrRenderTarget*,
42+
const GrProgramDesc&, const GrProgramInfo&);
4343

44-
GrMtlPipelineState* finalize(GrRenderTarget*, const GrProgramInfo&, GrProgramDesc*);
44+
GrMtlPipelineState* finalize(GrRenderTarget*, const GrProgramDesc&, const GrProgramInfo&);
4545

4646
const GrCaps* caps() const override;
4747

@@ -52,7 +52,6 @@ class GrMtlPipelineStateBuilder : public GrGLSLProgramBuilder {
5252
id<MTLLibrary> generateMtlShaderLibrary(const SkSL::String& sksl,
5353
SkSL::Program::Kind kind,
5454
const SkSL::Program::Settings& settings,
55-
GrProgramDesc* desc,
5655
SkSL::String* msl,
5756
SkSL::Program::Inputs* inputs);
5857
id<MTLLibrary> compileMtlShaderLibrary(const SkSL::String& shader,

0 commit comments

Comments
 (0)