Fix RE's VulkanInterface destruction & unnecessary initialization
SurfaceFlinger's initialization of RE now:
- Only attempts to check for VK support if either the GaneshVk or
GraphiteVk flag is set.
- Caches the VulkanInterface created to check for VK support until a VK
instance of RE is created.
- Tears down a partially initialized VulkanInterface if some required
feature is unsupported.
Additionally, SkiaVkRenderEngine's destructor now tears down the static
VulkanInterfaces it uses, which necessitates:
- Caching whether VK is supported.
- Ensuring all Skia resources are destroyed *before* the VK resources
managed by VulkanInterface that they rely on are torn down. This
involves ensuring all textures are destroyed, and all Skia
context-like objects are destroyed.
This latter change means that tests in librenderengine_test that are
parameterized by Skia backend must now recreate RE's VulkanInterfaces
twice for each test case (once for GaneshVk, and again for GraphiteVk),
which results in a minor regression in test duration. However, this is
necessary because holding on to a VulkanInterface while attempting to
set up a test for GaneshGL will cause contention over the real-time
GPU context priority, which can only be held exclusively by either a GL
context OR a VK context on some hardware.
Many thanks to joseph.cheng@imgtec.com for raising the issue of SF's
init of RE not tearing down the VulkanInterface used to check for
support, and for proposing an initial patch (b/333477752) which this
change builds upon. And thanks to scroggo@google.com for proposing the
reordering of SF's flag vs. VK support checks.
Bug: b/293371537
Bug: b/333477752
Test: librenderengine_test && manual boot validation across 3 backends
Flag: com.android.graphics.surfaceflinger.flags.graphite_renderengine-READ-ONLY
Change-Id: I289c3f7699d16707d1462179f4d5e8c54e4bb049
diff --git a/libs/renderengine/skia/compat/SkiaGpuContext.h b/libs/renderengine/skia/compat/SkiaGpuContext.h
index a2457e5..282dfe7 100644
--- a/libs/renderengine/skia/compat/SkiaGpuContext.h
+++ b/libs/renderengine/skia/compat/SkiaGpuContext.h
@@ -36,18 +36,32 @@
/**
* Abstraction over Ganesh and Graphite's underlying context-like objects.
+ *
+ * On destruction, subclasses will submit any pending work before destroying their internal Skia
+ * context(s). Any unused cached SkiaBackendTextures created from a SkiaGpuContext that are awaiting
+ * cleanup must be deleted before destroying that SkiaGpuContext, and any textures that are released
+ * during ~SkiaGpuContext must be configured to be deleted immediately.
*/
class SkiaGpuContext {
public:
+ /**
+ * glInterface must remain valid until after SkiaGpuContext is destroyed.
+ */
static std::unique_ptr<SkiaGpuContext> MakeGL_Ganesh(
sk_sp<const GrGLInterface> glInterface,
GrContextOptions::PersistentCache& skSLCacheMonitor);
+ /**
+ * grVkBackendContext must remain valid until after SkiaGpuContext is destroyed.
+ */
static std::unique_ptr<SkiaGpuContext> MakeVulkan_Ganesh(
const GrVkBackendContext& grVkBackendContext,
GrContextOptions::PersistentCache& skSLCacheMonitor);
// TODO: b/293371537 - Need shader / pipeline monitoring support in Graphite.
+ /**
+ * vulkanBackendContext must remain valid until after SkiaGpuContext is destroyed.
+ */
static std::unique_ptr<SkiaGpuContext> MakeVulkan_Graphite(
const skgpu::VulkanBackendContext& vulkanBackendContext);
@@ -91,7 +105,6 @@
virtual size_t getMaxTextureSize() const = 0;
virtual void setResourceCacheLimit(size_t maxResourceBytes) = 0;
- virtual void finishRenderingAndAbandonContext() = 0;
virtual void purgeUnlockedScratchResources() = 0;
virtual void resetContextIfApplicable() = 0; // No-op outside of GL (&& Ganesh at this point.)