aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/gpu
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2016-04-11 14:21:33 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-04-11 14:21:33 -0700
commitdc0fcd41e75682a8bfd5e285d684461475226330 (patch)
treea88c9ae58427a3d3afbd3bfb9705db49cb9fa298 /tools/gpu
parent849b175c029bcb5d4abb7fdadc45e8ed36f29a78 (diff)
Vulkan config in dm
Diffstat (limited to 'tools/gpu')
-rwxr-xr-xtools/gpu/GrContextFactory.cpp171
-rw-r--r--tools/gpu/GrContextFactory.h55
2 files changed, 128 insertions, 98 deletions
diff --git a/tools/gpu/GrContextFactory.cpp b/tools/gpu/GrContextFactory.cpp
index f54aa90c6c..651f3fcde2 100755
--- a/tools/gpu/GrContextFactory.cpp
+++ b/tools/gpu/GrContextFactory.cpp
@@ -43,33 +43,42 @@ void GrContextFactory::destroyContexts() {
context.fGLContext->makeCurrent();
}
if (!context.fGrContext->unique()) {
- context.fGrContext->abandonContext();
+ context.fGrContext->releaseResourcesAndAbandonContext();
+ context.fAbandoned = true;
}
context.fGrContext->unref();
- delete(context.fGLContext);
+ delete context.fGLContext;
}
fContexts.reset();
}
void GrContextFactory::abandonContexts() {
for (Context& context : fContexts) {
- if (context.fGLContext) {
- context.fGLContext->makeCurrent();
- context.fGLContext->testAbandon();
- delete(context.fGLContext);
- context.fGLContext = nullptr;
+ if (!context.fAbandoned) {
+ if (context.fGLContext) {
+ context.fGLContext->makeCurrent();
+ context.fGLContext->testAbandon();
+ delete(context.fGLContext);
+ context.fGLContext = nullptr;
+ }
+ context.fGrContext->abandonContext();
+ context.fAbandoned = true;
}
- context.fGrContext->abandonContext();
}
}
void GrContextFactory::releaseResourcesAndAbandonContexts() {
for (Context& context : fContexts) {
- if (context.fGLContext) {
- context.fGLContext->makeCurrent();
+ if (!context.fAbandoned) {
+ if (context.fGLContext) {
+ context.fGLContext->makeCurrent();
+ }
context.fGrContext->releaseResourcesAndAbandonContext();
- delete(context.fGLContext);
- context.fGLContext = nullptr;
+ context.fAbandoned = true;
+ if (context.fGLContext) {
+ delete context.fGLContext;
+ context.fGLContext = nullptr;
+ }
}
}
}
@@ -85,78 +94,103 @@ const GrContextFactory::ContextType GrContextFactory::kNativeGL_ContextType =
ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOptions options) {
for (int i = 0; i < fContexts.count(); ++i) {
Context& context = fContexts[i];
- if (!context.fGLContext) {
- continue;
- }
if (context.fType == type &&
- context.fOptions == options) {
- context.fGLContext->makeCurrent();
+ context.fOptions == options &&
+ !context.fAbandoned) {
+ if (context.fGLContext) {
+ context.fGLContext->makeCurrent();
+ }
return ContextInfo(context.fGrContext, context.fGLContext);
}
}
SkAutoTDelete<GLTestContext> glCtx;
- SkAutoTUnref<GrContext> grCtx;
- switch (type) {
- case kGL_ContextType:
- glCtx.reset(CreatePlatformGLTestContext(kGL_GrGLStandard));
- break;
- case kGLES_ContextType:
- glCtx.reset(CreatePlatformGLTestContext(kGLES_GrGLStandard));
- break;
-#if SK_ANGLE
-#ifdef SK_BUILD_FOR_WIN
- case kANGLE_ContextType:
- glCtx.reset(CreateANGLEDirect3DGLTestContext());
- break;
+ sk_sp<GrContext> grCtx;
+ GrBackendContext backendContext = 0;
+ sk_sp<const GrGLInterface> glInterface;
+#ifdef SK_VULKAN
+ sk_sp<const GrVkBackendContext> vkBackend;
#endif
- case kANGLE_GL_ContextType:
- glCtx.reset(CreateANGLEOpenGLGLTestContext());
- break;
+ GrBackend backend = ContextTypeBackend(type);
+ switch (backend) {
+ case kOpenGL_GrBackend:
+ switch (type) {
+ case kGL_ContextType:
+ glCtx.reset(CreatePlatformGLTestContext(kGL_GrGLStandard));
+ break;
+ case kGLES_ContextType:
+ glCtx.reset(CreatePlatformGLTestContext(kGLES_GrGLStandard));
+ break;
+#if SK_ANGLE
+# ifdef SK_BUILD_FOR_WIN
+ case kANGLE_ContextType:
+ glCtx.reset(CreateANGLEDirect3DGLTestContext());
+ break;
+# endif
+ case kANGLE_GL_ContextType:
+ glCtx.reset(CreateANGLEOpenGLGLTestContext());
+ break;
#endif
#if SK_COMMAND_BUFFER
- case kCommandBuffer_ContextType:
- glCtx.reset(CommandBufferGLTestContext::Create());
- break;
+ case kCommandBuffer_ContextType:
+ glCtx.reset(CommandBufferGLTestContext::Create());
+ break;
#endif
#if SK_MESA
- case kMESA_ContextType:
- glCtx.reset(CreateMesaGLTestContext());
- break;
+ case kMESA_ContextType:
+ glCtx.reset(CreateMesaGLTestContext());
+ break;
#endif
- case kNullGL_ContextType:
- glCtx.reset(CreateNullGLTestContext());
+ case kNullGL_ContextType:
+ glCtx.reset(CreateNullGLTestContext());
+ break;
+ case kDebugGL_ContextType:
+ glCtx.reset(CreateDebugGLTestContext());
+ break;
+ default:
+ return ContextInfo();
+ }
+ if (nullptr == glCtx.get()) {
+ return ContextInfo();
+ }
+ glInterface.reset(SkRef(glCtx->gl()));
+ // Block NVPR from non-NVPR types.
+ if (!(kEnableNVPR_ContextOptions & options)) {
+ glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface.get()));
+ if (!glInterface) {
+ return ContextInfo();
+ }
+ }
+ backendContext = reinterpret_cast<GrBackendContext>(glInterface.get());
+ glCtx->makeCurrent();
break;
- case kDebugGL_ContextType:
- glCtx.reset(CreateDebugGLTestContext());
+#ifdef SK_VULKAN
+ case kVulkan_GrBackend:
+ SkASSERT(kVulkan_ContextType == type);
+ if ((kEnableNVPR_ContextOptions & options) ||
+ (kRequireSRGBSupport_ContextOptions & options)) {
+ return ContextInfo();
+ }
+ vkBackend.reset(GrVkBackendContext::Create());
+ if (!vkBackend) {
+ return ContextInfo();
+ }
+ backendContext = reinterpret_cast<GrBackendContext>(vkBackend.get());
+ // There is some bug (either in Skia or the NV Vulkan driver) where VkDevice
+ // destruction will hang occaisonally. For some reason having an existing GL
+ // context fixes this.
+ if (!fSentinelGLContext) {
+ fSentinelGLContext.reset(CreatePlatformGLTestContext(kGL_GrGLStandard));
+ if (!fSentinelGLContext) {
+ fSentinelGLContext.reset(CreatePlatformGLTestContext(kGLES_GrGLStandard));
+ }
+ }
break;
- }
- if (nullptr == glCtx.get()) {
- return ContextInfo();
- }
-
- SkASSERT(glCtx->isValid());
-
- // Block NVPR from non-NVPR types.
- SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx->gl()));
- if (!(kEnableNVPR_ContextOptions & options)) {
- glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface));
- if (!glInterface) {
+#endif
+ default:
return ContextInfo();
- }
}
- glCtx->makeCurrent();
-#ifdef SK_VULKAN
- if (kEnableNVPR_ContextOptions & options) {
- return ContextInfo();
- } else {
- GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(GrVkBackendContext::Create());
- grCtx.reset(GrContext::Create(kVulkan_GrBackend, p3dctx, fGlobalOptions));
- }
-#else
- GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(glInterface.get());
- grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx, fGlobalOptions));
-#endif
+ grCtx.reset(GrContext::Create(backend, backendContext, fGlobalOptions));
if (!grCtx.get()) {
return ContextInfo();
}
@@ -176,6 +210,7 @@ ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOptions op
context.fGrContext = SkRef(grCtx.get());
context.fType = type;
context.fOptions = options;
+ context.fAbandoned = false;
return ContextInfo(context.fGrContext, context.fGLContext);
}
} // namespace sk_gpu_test
diff --git a/tools/gpu/GrContextFactory.h b/tools/gpu/GrContextFactory.h
index 89ca9cadf0..0dc8c20cd5 100644
--- a/tools/gpu/GrContextFactory.h
+++ b/tools/gpu/GrContextFactory.h
@@ -14,6 +14,8 @@
#include "gl/GLTestContext.h"
#include "SkTArray.h"
+struct GrVkBackendContext;
+
namespace sk_gpu_test {
struct ContextInfo {
@@ -23,7 +25,7 @@ struct ContextInfo {
: fGrContext(grContext), fGLContext(glContext) { }
GrContext* fGrContext;
GLTestContext* fGLContext; //! Valid until the factory destroys it via abandonContexts() or
- //! destroyContexts().
+ //! destroyContexts(). Null if context is not based on OpenGL.
};
/**
@@ -35,24 +37,19 @@ struct ContextInfo {
*/
class GrContextFactory : SkNoncopyable {
public:
+ // The availability of context types is subject to platform and build configuration
+ // restrictions.
enum ContextType {
kGL_ContextType, //! OpenGL context.
kGLES_ContextType, //! OpenGL ES context.
-#if SK_ANGLE
-#ifdef SK_BUILD_FOR_WIN
kANGLE_ContextType, //! ANGLE on DirectX OpenGL ES context.
-#endif
kANGLE_GL_ContextType, //! ANGLE on OpenGL OpenGL ES context.
-#endif
-#if SK_COMMAND_BUFFER
kCommandBuffer_ContextType, //! Chromium command buffer OpenGL ES context.
-#endif
-#if SK_MESA
kMESA_ContextType, //! MESA OpenGL context
-#endif
kNullGL_ContextType, //! Non-rendering OpenGL mock context.
kDebugGL_ContextType, //! Non-rendering, state verifying OpenGL context.
- kLastContextType = kDebugGL_ContextType
+ kVulkan_ContextType, //! Vulkan
+ kLastContextType = kVulkan_ContextType
};
//! OpenGL or OpenGL ES context depending on the platform. To be removed.
@@ -81,8 +78,12 @@ public:
}
static GrBackend ContextTypeBackend(ContextType type) {
- // Currently all the context types use the GL backed
- return kOpenGL_GrBackend;
+ switch (type) {
+ case kVulkan_ContextType:
+ return kVulkan_GrBackend;
+ default:
+ return kOpenGL_GrBackend;
+ }
}
static const char* ContextTypeName(ContextType type) {
@@ -91,28 +92,20 @@ public:
return "gl";
case kGLES_ContextType:
return "gles";
-#if SK_ANGLE
-#ifdef SK_BUILD_FOR_WIN
case kANGLE_ContextType:
return "angle";
-#endif
case kANGLE_GL_ContextType:
return "angle-gl";
-#endif
-#if SK_COMMAND_BUFFER
case kCommandBuffer_ContextType:
return "commandbuffer";
-#endif
-#if SK_MESA
case kMESA_ContextType:
return "mesa";
-#endif
case kNullGL_ContextType:
- return "null";
+ return "nullgl";
case kDebugGL_ContextType:
- return "debug";
- default:
- SkFAIL("Unknown GL Context type.");
+ return "debuggl";
+ case kVulkan_ContextType:
+ return "vulkan";
}
}
@@ -140,13 +133,15 @@ public:
private:
struct Context {
- ContextType fType;
- ContextOptions fOptions;
- GLTestContext* fGLContext; // null if non-GL
- GrContext* fGrContext;
+ ContextType fType;
+ ContextOptions fOptions;
+ GLTestContext* fGLContext; // null if non-GL
+ GrContext* fGrContext;
+ bool fAbandoned;
};
- SkTArray<Context, true> fContexts;
- const GrContextOptions fGlobalOptions;
+ SkTArray<Context, true> fContexts;
+ SkAutoTDelete<GLTestContext> fSentinelGLContext;
+ const GrContextOptions fGlobalOptions;
};
} // namespace sk_gpu_test
#endif