Add private GrContext::compile API
Currently this is only implemented for GL.
Bug: skia:9455
Change-Id: I8f369273b697e80a4bade5dd2283e66df688f0ec
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/271742
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h
index 8e78956..91bc3f1 100644
--- a/src/gpu/GrContextPriv.h
+++ b/src/gpu/GrContextPriv.h
@@ -123,6 +123,8 @@
void moveRenderTasksToDDL(SkDeferredDisplayList*);
void copyRenderTasksFromDDL(const SkDeferredDisplayList*, GrRenderTargetProxy* newDest);
+ void compile(const GrProgramDesc&, const GrProgramInfo&);
+
GrContextOptions::PersistentCache* getPersistentCache() { return fContext->fPersistentCache; }
GrContextOptions::ShaderErrorHandler* getShaderErrorHandler() const {
return fContext->fShaderErrorHandler;
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index 44ed8e2..5551e6e 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -552,6 +552,11 @@
*/
virtual void deleteBackendTexture(const GrBackendTexture&) = 0;
+ /**
+ * In this case we have a program descriptor and a program info but no render target.
+ */
+ virtual bool compile(const GrProgramDesc&, const GrProgramInfo&) = 0;
+
virtual bool precompileShader(const SkData& key, const SkData& data) { return false; }
#if GR_TEST_UTILS
diff --git a/src/gpu/dawn/GrDawnGpu.cpp b/src/gpu/dawn/GrDawnGpu.cpp
index e80d7b6..907b719 100644
--- a/src/gpu/dawn/GrDawnGpu.cpp
+++ b/src/gpu/dawn/GrDawnGpu.cpp
@@ -370,6 +370,10 @@
}
}
+bool GrDawnGpu::compile(const GrProgramDesc&, const GrProgramInfo&) {
+ return false;
+}
+
#if GR_TEST_UTILS
bool GrDawnGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const {
GrDawnTextureInfo info;
diff --git a/src/gpu/dawn/GrDawnGpu.h b/src/gpu/dawn/GrDawnGpu.h
index 32791d7..d655215 100644
--- a/src/gpu/dawn/GrDawnGpu.h
+++ b/src/gpu/dawn/GrDawnGpu.h
@@ -53,6 +53,9 @@
const BackendTextureData*) override;
void deleteBackendTexture(const GrBackendTexture&) override;
+
+ bool compile(const GrProgramDesc&, const GrProgramInfo&) override;
+
#if GR_TEST_UTILS
bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index f359c5f..45a1ad8 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -126,6 +126,11 @@
const GrRenderTarget* rt, int width, int height, int numStencilSamples) override;
void deleteBackendTexture(const GrBackendTexture&) override;
+ bool compile(const GrProgramDesc& desc, const GrProgramInfo& programInfo) override {
+ sk_sp<GrGLProgram> tmp = fProgramCache->findOrCreateProgram(desc, programInfo);
+ return SkToBool(tmp);
+ }
+
bool precompileShader(const SkData& key, const SkData& data) override {
return fProgramCache->precompileShader(key, data);
}
@@ -319,11 +324,19 @@
void abandon();
void reset();
sk_sp<GrGLProgram> findOrCreateProgram(GrRenderTarget*, const GrProgramInfo&);
+ sk_sp<GrGLProgram> findOrCreateProgram(const GrProgramDesc& desc,
+ const GrProgramInfo& programInfo) {
+ return this->findOrCreateProgram(nullptr, desc, programInfo);
+ }
bool precompileShader(const SkData& key, const SkData& data);
private:
struct Entry;
+ sk_sp<GrGLProgram> findOrCreateProgram(GrRenderTarget*,
+ const GrProgramDesc&,
+ const GrProgramInfo&);
+
struct DescHash {
uint32_t operator()(const GrProgramDesc& desc) const {
return SkOpts::hash_fn(desc.asKey(), desc.keyLength(), 0);
diff --git a/src/gpu/gl/GrGLGpuProgramCache.cpp b/src/gpu/gl/GrGLGpuProgramCache.cpp
index 9c7115f..02c75a1 100644
--- a/src/gpu/gl/GrGLGpuProgramCache.cpp
+++ b/src/gpu/gl/GrGLGpuProgramCache.cpp
@@ -55,6 +55,12 @@
return nullptr;
}
+ return this->findOrCreateProgram(renderTarget, desc, programInfo);
+}
+
+sk_sp<GrGLProgram> GrGLGpu::ProgramCache::findOrCreateProgram(GrRenderTarget* renderTarget,
+ const GrProgramDesc& desc,
+ const GrProgramInfo& programInfo) {
std::unique_ptr<Entry>* entry = fMap.find(desc);
if (entry && !(*entry)->fProgram) {
// We've pre-compiled the GL program, but don't have the GrGLProgram scaffolding
diff --git a/src/gpu/mock/GrMockGpu.h b/src/gpu/mock/GrMockGpu.h
index af95372..15e81ce 100644
--- a/src/gpu/mock/GrMockGpu.h
+++ b/src/gpu/mock/GrMockGpu.h
@@ -153,6 +153,8 @@
const BackendTextureData*) override;
void deleteBackendTexture(const GrBackendTexture&) override;
+ bool compile(const GrProgramDesc&, const GrProgramInfo&) override { return false; }
+
#if GR_TEST_UTILS
bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
diff --git a/src/gpu/mtl/GrMtlGpu.h b/src/gpu/mtl/GrMtlGpu.h
index c464a3e..a27848f 100644
--- a/src/gpu/mtl/GrMtlGpu.h
+++ b/src/gpu/mtl/GrMtlGpu.h
@@ -59,6 +59,8 @@
void deleteBackendTexture(const GrBackendTexture&) override;
+ bool compile(const GrProgramDesc&, const GrProgramInfo&) override;
+
#if GR_TEST_UTILS
bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
diff --git a/src/gpu/mtl/GrMtlGpu.mm b/src/gpu/mtl/GrMtlGpu.mm
index 4a86ff4..0fcf4b6 100644
--- a/src/gpu/mtl/GrMtlGpu.mm
+++ b/src/gpu/mtl/GrMtlGpu.mm
@@ -1009,6 +1009,10 @@
// Nothing to do here, will get cleaned up when the GrBackendTexture object goes away
}
+bool GrMtlGpu::compile(const GrProgramDesc&, const GrProgramInfo&) {
+ return false;
+}
+
#if GR_TEST_UTILS
bool GrMtlGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const {
SkASSERT(GrBackendApi::kMetal == tex.backend());
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index 0215406..5e771b8 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -2006,6 +2006,10 @@
}
}
+bool GrVkGpu::compile(const GrProgramDesc&, const GrProgramInfo&) {
+ return false;
+}
+
#if GR_TEST_UTILS
bool GrVkGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const {
SkASSERT(GrBackendApi::kVulkan == tex.fBackend);
diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h
index 1156d90..fe6375e 100644
--- a/src/gpu/vk/GrVkGpu.h
+++ b/src/gpu/vk/GrVkGpu.h
@@ -75,6 +75,9 @@
void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
void deleteBackendTexture(const GrBackendTexture&) override;
+
+ bool compile(const GrProgramDesc&, const GrProgramInfo&) override;
+
#if GR_TEST_UTILS
bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
diff --git a/src/gpu/vk/GrVkPipelineStateCache.cpp b/src/gpu/vk/GrVkPipelineStateCache.cpp
index a0f5ff4..9a75301 100644
--- a/src/gpu/vk/GrVkPipelineStateCache.cpp
+++ b/src/gpu/vk/GrVkPipelineStateCache.cpp
@@ -89,6 +89,14 @@
return nullptr;
}
+ return this->findOrCreatePipeline(renderTarget, desc, programInfo, compatibleRenderPass);
+}
+
+GrVkPipelineState* GrVkResourceProvider::PipelineStateCache::findOrCreatePipeline(
+ GrRenderTarget* renderTarget,
+ const GrProgramDesc& desc,
+ const GrProgramInfo& programInfo,
+ VkRenderPass compatibleRenderPass) {
std::unique_ptr<Entry>* entry = fMap.find(desc);
if (!entry) {
#ifdef GR_PIPELINE_STATE_CACHE_STATS
diff --git a/src/gpu/vk/GrVkResourceProvider.h b/src/gpu/vk/GrVkResourceProvider.h
index 64b4f93..7e0ffa7 100644
--- a/src/gpu/vk/GrVkResourceProvider.h
+++ b/src/gpu/vk/GrVkResourceProvider.h
@@ -191,6 +191,11 @@
private:
struct Entry;
+ GrVkPipelineState* findOrCreatePipeline(GrRenderTarget*,
+ const GrProgramDesc&,
+ const GrProgramInfo&,
+ VkRenderPass compatibleRenderPass);
+
struct DescHash {
uint32_t operator()(const GrProgramDesc& desc) const {
return SkOpts::hash_fn(desc.asKey(), desc.keyLength(), 0);