GrGlGpu::ProgramCache no longer holds a GrGlGpu back pointer
In the threaded compilation world, the GrUtilityContext active on a given thread will have to be passed in to the cache. Change-Id: Id4f59b2e710080ab808275aeb2ffbcab38b3eadc Reviewed-on: https://skia-review.googlesource.com/c/skia/+/379061 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
b9bd12d6f8
commit
962708fbb9
@ -336,10 +336,10 @@ sk_sp<GrGpu> GrGLGpu::Make(sk_sp<const GrGLInterface> interface, const GrContext
|
||||
return sk_sp<GrGpu>(new GrGLGpu(std::move(glContext), direct));
|
||||
}
|
||||
|
||||
GrGLGpu::GrGLGpu(std::unique_ptr<GrGLContext> ctx, GrDirectContext* direct)
|
||||
: GrGpu(direct)
|
||||
GrGLGpu::GrGLGpu(std::unique_ptr<GrGLContext> ctx, GrDirectContext* dContext)
|
||||
: GrGpu(dContext)
|
||||
, fGLContext(std::move(ctx))
|
||||
, fProgramCache(new ProgramCache(this))
|
||||
, fProgramCache(new ProgramCache(dContext->priv().options().fRuntimeProgramCacheSize))
|
||||
, fHWProgramID(0)
|
||||
, fTempSrcFBOID(0)
|
||||
, fTempDstFBOID(0)
|
||||
@ -1817,7 +1817,8 @@ void GrGLGpu::disableWindowRectangles() {
|
||||
bool GrGLGpu::flushGLState(GrRenderTarget* renderTarget, const GrProgramInfo& programInfo) {
|
||||
this->handleDirtyContext();
|
||||
|
||||
sk_sp<GrGLProgram> program = fProgramCache->findOrCreateProgram(renderTarget, programInfo);
|
||||
sk_sp<GrGLProgram> program = fProgramCache->findOrCreateProgram(this->getContext(),
|
||||
renderTarget, programInfo);
|
||||
if (!program) {
|
||||
GrCapsDebugf(this->caps(), "Failed to create program!\n");
|
||||
return false;
|
||||
@ -3691,7 +3692,8 @@ bool GrGLGpu::compile(const GrProgramDesc& desc, const GrProgramInfo& programInf
|
||||
|
||||
GrThreadSafePipelineBuilder::Stats::ProgramCacheResult stat;
|
||||
|
||||
sk_sp<GrGLProgram> tmp = fProgramCache->findOrCreateProgram(desc, programInfo, &stat);
|
||||
sk_sp<GrGLProgram> tmp = fProgramCache->findOrCreateProgram(this->getContext(),
|
||||
desc, programInfo, &stat);
|
||||
if (!tmp) {
|
||||
return false;
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ public:
|
||||
bool compile(const GrProgramDesc&, const GrProgramInfo&) override;
|
||||
|
||||
bool precompileShader(const SkData& key, const SkData& data) override {
|
||||
return fProgramCache->precompileShader(key, data);
|
||||
return fProgramCache->precompileShader(this->getContext(), key, data);
|
||||
}
|
||||
|
||||
#if GR_TEST_UTILS
|
||||
@ -358,16 +358,20 @@ private:
|
||||
|
||||
class ProgramCache : public GrThreadSafePipelineBuilder {
|
||||
public:
|
||||
ProgramCache(GrGLGpu* gpu);
|
||||
ProgramCache(int runtimeProgramCacheSize);
|
||||
~ProgramCache() override;
|
||||
|
||||
void abandon();
|
||||
void reset();
|
||||
sk_sp<GrGLProgram> findOrCreateProgram(GrRenderTarget*, const GrProgramInfo&);
|
||||
sk_sp<GrGLProgram> findOrCreateProgram(const GrProgramDesc& desc,
|
||||
sk_sp<GrGLProgram> findOrCreateProgram(GrDirectContext*,
|
||||
GrRenderTarget*,
|
||||
const GrProgramInfo&);
|
||||
sk_sp<GrGLProgram> findOrCreateProgram(GrDirectContext* dContext,
|
||||
const GrProgramDesc& desc,
|
||||
const GrProgramInfo& programInfo,
|
||||
Stats::ProgramCacheResult* stat) {
|
||||
sk_sp<GrGLProgram> tmp = this->findOrCreateProgram(nullptr, desc, programInfo, stat);
|
||||
sk_sp<GrGLProgram> tmp = this->findOrCreateProgram(dContext, nullptr, desc,
|
||||
programInfo, stat);
|
||||
if (!tmp) {
|
||||
fStats.incNumPreCompilationFailures();
|
||||
} else {
|
||||
@ -376,12 +380,13 @@ private:
|
||||
|
||||
return tmp;
|
||||
}
|
||||
bool precompileShader(const SkData& key, const SkData& data);
|
||||
bool precompileShader(GrDirectContext*, const SkData& key, const SkData& data);
|
||||
|
||||
private:
|
||||
struct Entry;
|
||||
|
||||
sk_sp<GrGLProgram> findOrCreateProgram(GrRenderTarget*,
|
||||
sk_sp<GrGLProgram> findOrCreateProgram(GrDirectContext*,
|
||||
GrRenderTarget*,
|
||||
const GrProgramDesc&,
|
||||
const GrProgramInfo&,
|
||||
Stats::ProgramCacheResult*);
|
||||
@ -393,8 +398,6 @@ private:
|
||||
};
|
||||
|
||||
SkLRUCache<GrProgramDesc, std::unique_ptr<Entry>, DescHash> fMap;
|
||||
|
||||
GrGLGpu* fGpu;
|
||||
};
|
||||
|
||||
void flushPatchVertexCount(uint8_t count);
|
||||
|
@ -28,9 +28,9 @@ struct GrGLGpu::ProgramCache::Entry {
|
||||
GrGLPrecompiledProgram fPrecompiledProgram;
|
||||
};
|
||||
|
||||
GrGLGpu::ProgramCache::ProgramCache(GrGLGpu* gpu)
|
||||
: fMap(gpu->getContext()->priv().options().fRuntimeProgramCacheSize)
|
||||
, fGpu(gpu) {}
|
||||
GrGLGpu::ProgramCache::ProgramCache(int runtimeProgramCacheSize)
|
||||
: fMap(runtimeProgramCacheSize) {
|
||||
}
|
||||
|
||||
GrGLGpu::ProgramCache::~ProgramCache() {}
|
||||
|
||||
@ -48,18 +48,20 @@ void GrGLGpu::ProgramCache::reset() {
|
||||
fMap.reset();
|
||||
}
|
||||
|
||||
sk_sp<GrGLProgram> GrGLGpu::ProgramCache::findOrCreateProgram(GrRenderTarget* renderTarget,
|
||||
sk_sp<GrGLProgram> GrGLGpu::ProgramCache::findOrCreateProgram(GrDirectContext* dContext,
|
||||
GrRenderTarget* renderTarget,
|
||||
const GrProgramInfo& programInfo) {
|
||||
const GrCaps& caps = *fGpu->caps();
|
||||
const GrCaps* caps = dContext->priv().caps();
|
||||
|
||||
GrProgramDesc desc = caps.makeDesc(renderTarget, programInfo);
|
||||
GrProgramDesc desc = caps->makeDesc(renderTarget, programInfo);
|
||||
if (!desc.isValid()) {
|
||||
GrCapsDebugf(&caps, "Failed to gl program descriptor!\n");
|
||||
GrCapsDebugf(caps, "Failed to gl program descriptor!\n");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Stats::ProgramCacheResult stat;
|
||||
sk_sp<GrGLProgram> tmp = this->findOrCreateProgram(renderTarget, desc, programInfo, &stat);
|
||||
sk_sp<GrGLProgram> tmp = this->findOrCreateProgram(dContext, renderTarget, desc,
|
||||
programInfo, &stat);
|
||||
if (!tmp) {
|
||||
fStats.incNumInlineCompilationFailures();
|
||||
} else {
|
||||
@ -69,7 +71,8 @@ sk_sp<GrGLProgram> GrGLGpu::ProgramCache::findOrCreateProgram(GrRenderTarget* re
|
||||
return tmp;
|
||||
}
|
||||
|
||||
sk_sp<GrGLProgram> GrGLGpu::ProgramCache::findOrCreateProgram(GrRenderTarget* renderTarget,
|
||||
sk_sp<GrGLProgram> GrGLGpu::ProgramCache::findOrCreateProgram(GrDirectContext* dContext,
|
||||
GrRenderTarget* renderTarget,
|
||||
const GrProgramDesc& desc,
|
||||
const GrProgramInfo& programInfo,
|
||||
Stats::ProgramCacheResult* stat) {
|
||||
@ -79,7 +82,7 @@ sk_sp<GrGLProgram> GrGLGpu::ProgramCache::findOrCreateProgram(GrRenderTarget* re
|
||||
// We've pre-compiled the GL program, but don't have the GrGLProgram scaffolding
|
||||
const GrGLPrecompiledProgram* precompiledProgram = &((*entry)->fPrecompiledProgram);
|
||||
SkASSERT(precompiledProgram->fProgramID != 0);
|
||||
(*entry)->fProgram = GrGLProgramBuilder::CreateProgram(fGpu, renderTarget, desc,
|
||||
(*entry)->fProgram = GrGLProgramBuilder::CreateProgram(dContext, renderTarget, desc,
|
||||
programInfo, precompiledProgram);
|
||||
if (!(*entry)->fProgram) {
|
||||
// Should we purge the program ID from the cache at this point?
|
||||
@ -91,7 +94,7 @@ sk_sp<GrGLProgram> GrGLGpu::ProgramCache::findOrCreateProgram(GrRenderTarget* re
|
||||
*stat = Stats::ProgramCacheResult::kPartial;
|
||||
} else if (!entry) {
|
||||
// We have a cache miss
|
||||
sk_sp<GrGLProgram> program = GrGLProgramBuilder::CreateProgram(fGpu, renderTarget,
|
||||
sk_sp<GrGLProgram> program = GrGLProgramBuilder::CreateProgram(dContext, renderTarget,
|
||||
desc, programInfo);
|
||||
if (!program) {
|
||||
fStats.incNumCompilationFailures();
|
||||
@ -105,7 +108,9 @@ sk_sp<GrGLProgram> GrGLGpu::ProgramCache::findOrCreateProgram(GrRenderTarget* re
|
||||
return (*entry)->fProgram;
|
||||
}
|
||||
|
||||
bool GrGLGpu::ProgramCache::precompileShader(const SkData& key, const SkData& data) {
|
||||
bool GrGLGpu::ProgramCache::precompileShader(GrDirectContext* dContext,
|
||||
const SkData& key,
|
||||
const SkData& data) {
|
||||
GrProgramDesc desc;
|
||||
if (!GrProgramDesc::BuildFromData(&desc, key.data(), key.size())) {
|
||||
return false;
|
||||
@ -118,7 +123,7 @@ bool GrGLGpu::ProgramCache::precompileShader(const SkData& key, const SkData& da
|
||||
}
|
||||
|
||||
GrGLPrecompiledProgram precompiledProgram;
|
||||
if (!GrGLProgramBuilder::PrecompileProgram(&precompiledProgram, fGpu, data)) {
|
||||
if (!GrGLProgramBuilder::PrecompileProgram(dContext, &precompiledProgram, data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ static void cleanup_program(GrGLGpu* gpu, GrGLuint programID,
|
||||
}
|
||||
|
||||
sk_sp<GrGLProgram> GrGLProgramBuilder::CreateProgram(
|
||||
GrGLGpu* gpu,
|
||||
GrDirectContext* dContext,
|
||||
GrRenderTarget* renderTarget,
|
||||
const GrProgramDesc& desc,
|
||||
const GrProgramInfo& programInfo,
|
||||
@ -55,11 +55,13 @@ sk_sp<GrGLProgram> GrGLProgramBuilder::CreateProgram(
|
||||
TRACE_EVENT0_ALWAYS("skia.gpu", "shader_compile");
|
||||
GrAutoLocaleSetter als("C");
|
||||
|
||||
GrGLGpu* glGpu = static_cast<GrGLGpu*>(dContext->priv().getGpu());
|
||||
|
||||
// create a builder. This will be handed off to effects so they can use it to add
|
||||
// uniforms, varyings, textures, etc
|
||||
GrGLProgramBuilder builder(gpu, renderTarget, desc, programInfo);
|
||||
GrGLProgramBuilder builder(glGpu, renderTarget, desc, programInfo);
|
||||
|
||||
auto persistentCache = gpu->getContext()->priv().getPersistentCache();
|
||||
auto persistentCache = dContext->priv().getPersistentCache();
|
||||
if (persistentCache && !precompiledProgram) {
|
||||
sk_sp<SkData> key = SkData::MakeWithoutCopy(desc.asKey(), desc.keyLength());
|
||||
builder.fCached = persistentCache->load(*key);
|
||||
@ -575,8 +577,8 @@ sk_sp<GrGLProgram> GrGLProgramBuilder::createProgram(GrGLuint programID) {
|
||||
fInstanceStride);
|
||||
}
|
||||
|
||||
bool GrGLProgramBuilder::PrecompileProgram(GrGLPrecompiledProgram* precompiledProgram,
|
||||
GrGLGpu* gpu,
|
||||
bool GrGLProgramBuilder::PrecompileProgram(GrDirectContext* dContext,
|
||||
GrGLPrecompiledProgram* precompiledProgram,
|
||||
const SkData& cachedData) {
|
||||
SkReadBuffer reader(cachedData.data(), cachedData.size());
|
||||
SkFourByteTag shaderType = GrPersistentCacheUtils::GetType(&reader);
|
||||
@ -585,11 +587,13 @@ bool GrGLProgramBuilder::PrecompileProgram(GrGLPrecompiledProgram* precompiledPr
|
||||
return false;
|
||||
}
|
||||
|
||||
const GrGLInterface* gl = gpu->glInterface();
|
||||
auto errorHandler = gpu->getContext()->priv().getShaderErrorHandler();
|
||||
GrGLGpu* glGpu = static_cast<GrGLGpu*>(dContext->priv().getGpu());
|
||||
|
||||
const GrGLInterface* gl = glGpu->glInterface();
|
||||
auto errorHandler = dContext->priv().getShaderErrorHandler();
|
||||
|
||||
SkSL::Program::Settings settings;
|
||||
settings.fSharpenTextures = gpu->getContext()->priv().options().fSharpenMipmappedTextures;
|
||||
settings.fSharpenTextures = dContext->priv().options().fSharpenMipmappedTextures;
|
||||
GrPersistentCacheUtils::ShaderMetadata meta;
|
||||
meta.fSettings = &settings;
|
||||
|
||||
@ -609,13 +613,13 @@ bool GrGLProgramBuilder::PrecompileProgram(GrGLPrecompiledProgram* precompiledPr
|
||||
|
||||
auto compileShader = [&](SkSL::ProgramKind kind, const SkSL::String& sksl, GrGLenum type) {
|
||||
SkSL::String glsl;
|
||||
auto program = GrSkSLtoGLSL(gpu, kind, sksl, settings, &glsl, errorHandler);
|
||||
auto program = GrSkSLtoGLSL(glGpu, kind, sksl, settings, &glsl, errorHandler);
|
||||
if (!program) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (GrGLuint shaderID = GrGLCompileAndAttachShader(gpu->glContext(), programID, type, glsl,
|
||||
gpu->pipelineBuilder()->stats(),
|
||||
if (GrGLuint shaderID = GrGLCompileAndAttachShader(glGpu->glContext(), programID, type,
|
||||
glsl, glGpu->pipelineBuilder()->stats(),
|
||||
errorHandler)) {
|
||||
shadersToDelete.push_back(shaderID);
|
||||
return true;
|
||||
@ -634,34 +638,36 @@ bool GrGLProgramBuilder::PrecompileProgram(GrGLPrecompiledProgram* precompiledPr
|
||||
!compileShader(SkSL::ProgramKind::kGeometry,
|
||||
shaders[kGeometry_GrShaderType],
|
||||
GR_GL_GEOMETRY_SHADER))) {
|
||||
cleanup_program(gpu, programID, shadersToDelete);
|
||||
cleanup_program(glGpu, programID, shadersToDelete);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < meta.fAttributeNames.count(); ++i) {
|
||||
GR_GL_CALL(gpu->glInterface(), BindAttribLocation(programID, i,
|
||||
GR_GL_CALL(glGpu->glInterface(), BindAttribLocation(programID, i,
|
||||
meta.fAttributeNames[i].c_str()));
|
||||
}
|
||||
|
||||
const GrGLCaps& caps = gpu->glCaps();
|
||||
const GrGLCaps& caps = glGpu->glCaps();
|
||||
if (meta.fHasCustomColorOutput && caps.bindFragDataLocationSupport()) {
|
||||
GR_GL_CALL(gpu->glInterface(), BindFragDataLocation(programID, 0,
|
||||
GrGLSLFragmentShaderBuilder::DeclaredColorOutputName()));
|
||||
GR_GL_CALL(glGpu->glInterface(),
|
||||
BindFragDataLocation(programID, 0,
|
||||
GrGLSLFragmentShaderBuilder::DeclaredColorOutputName()));
|
||||
}
|
||||
if (meta.fHasSecondaryColorOutput && caps.shaderCaps()->mustDeclareFragmentShaderOutput()) {
|
||||
GR_GL_CALL(gpu->glInterface(), BindFragDataLocationIndexed(programID, 0, 1,
|
||||
GrGLSLFragmentShaderBuilder::DeclaredSecondaryColorOutputName()));
|
||||
GR_GL_CALL(glGpu->glInterface(),
|
||||
BindFragDataLocationIndexed(programID, 0, 1,
|
||||
GrGLSLFragmentShaderBuilder::DeclaredSecondaryColorOutputName()));
|
||||
}
|
||||
|
||||
GR_GL_CALL(gpu->glInterface(), LinkProgram(programID));
|
||||
GR_GL_CALL(glGpu->glInterface(), LinkProgram(programID));
|
||||
GrGLint linked = GR_GL_INIT_ZERO;
|
||||
GR_GL_CALL(gpu->glInterface(), GetProgramiv(programID, GR_GL_LINK_STATUS, &linked));
|
||||
GR_GL_CALL(glGpu->glInterface(), GetProgramiv(programID, GR_GL_LINK_STATUS, &linked));
|
||||
if (!linked) {
|
||||
cleanup_program(gpu, programID, shadersToDelete);
|
||||
cleanup_program(glGpu, programID, shadersToDelete);
|
||||
return false;
|
||||
}
|
||||
|
||||
cleanup_shaders(gpu, shadersToDelete);
|
||||
cleanup_shaders(glGpu, shadersToDelete);
|
||||
|
||||
precompiledProgram->fProgramID = programID;
|
||||
precompiledProgram->fInputs = inputs;
|
||||
|
@ -44,13 +44,13 @@ public:
|
||||
* be supplied to skip the shader compilation.
|
||||
* @return the created program if generation was successful.
|
||||
*/
|
||||
static sk_sp<GrGLProgram> CreateProgram(GrGLGpu*,
|
||||
static sk_sp<GrGLProgram> CreateProgram(GrDirectContext*,
|
||||
GrRenderTarget*,
|
||||
const GrProgramDesc&,
|
||||
const GrProgramInfo&,
|
||||
const GrGLPrecompiledProgram* = nullptr);
|
||||
|
||||
static bool PrecompileProgram(GrGLPrecompiledProgram*, GrGLGpu*, const SkData&);
|
||||
static bool PrecompileProgram(GrDirectContext*, GrGLPrecompiledProgram*, const SkData&);
|
||||
|
||||
const GrCaps* caps() const override;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user