From 83ba2e95e736a3f4f150c6fa16b92c4ad01845cd Mon Sep 17 00:00:00 2001 From: Remi Palandri Date: Wed, 30 May 2018 15:06:39 -0700 Subject: [PATCH] add support for VR end-of-frame markers via glDebugMessageInsert --- renderdoc/android/android.cpp | 3 +- renderdoc/driver/gl/gl_driver.h | 1 + renderdoc/driver/gl/gl_hooks_vrapi.cpp | 30 ++----------------- .../driver/gl/wrappers/gl_debug_funcs.cpp | 12 ++++++++ 4 files changed, 18 insertions(+), 28 deletions(-) diff --git a/renderdoc/android/android.cpp b/renderdoc/android/android.cpp index 10067898a..bdabef2a3 100644 --- a/renderdoc/android/android.cpp +++ b/renderdoc/android/android.cpp @@ -200,9 +200,10 @@ ExecuteResult StartAndroidPackageForCapture(const char *host, const char *packag adbExecCommand(deviceID, "shell am force-stop " + packageName); // enable the vulkan layer (will only be used by vulkan programs) adbExecCommand(deviceID, "shell setprop debug.vulkan.layers " RENDERDOC_VULKAN_LAYER_NAME); + // if in VR mode, enable frame delimiter markers + adbExecCommand(deviceID, "shell setprop debug.vr.profiler 1"); // create the data directory we will use for storing, in case the application doesn't adbExecCommand(deviceID, "shell mkdir -p /sdcard/Android/data/" + packageName); - // set our property with the capture options encoded, to be picked up by the library on the device adbExecCommand(deviceID, StringFormat::Fmt("shell setprop debug.rdoc.RENDERDOC_CAPTUREOPTS %s", opts.EncodeAsString().c_str())); diff --git a/renderdoc/driver/gl/gl_driver.h b/renderdoc/driver/gl/gl_driver.h index d9a335917..079866a9b 100644 --- a/renderdoc/driver/gl/gl_driver.h +++ b/renderdoc/driver/gl/gl_driver.h @@ -615,6 +615,7 @@ public: void SwapBuffers(void *windowHandle); void CreateVRAPITextureSwapChain(GLuint tex, GLenum textureType, GLenum internalformat, GLsizei width, GLsizei height, GLint levels); + void HandleVRFrameMarkers(const GLchar *buf,GLsizei length); void FirstFrame(void *ctx, void *wndHandle); diff --git a/renderdoc/driver/gl/gl_hooks_vrapi.cpp b/renderdoc/driver/gl/gl_hooks_vrapi.cpp index 5a2fde149..922a4ab3b 100644 --- a/renderdoc/driver/gl/gl_hooks_vrapi.cpp +++ b/renderdoc/driver/gl/gl_hooks_vrapi.cpp @@ -31,7 +31,6 @@ #include "official/VrApi_Types.h" //----------------------------------------------------------------------------------------------------------------- -typedef void (*PFN_vrapi_SubmitFrame)(ovrMobile *, const ovrFrameParms *); typedef int (*PFN_vrapi_GetTextureSwapChainLength)(ovrTextureSwapChain *); typedef unsigned int (*PFN_vrapi_GetTextureSwapChainHandle)(ovrTextureSwapChain *, int); typedef int (*PFN_vrapi_GetSystemPropertyInt)(const ovrJava *, const ovrSystemProperty); @@ -48,8 +47,7 @@ class VRAPIHook : LibraryHook { public: VRAPIHook() - : vrapi_SubmitFrame_real(NULL), - vrapi_GetTextureSwapChainLength_real(NULL), + : vrapi_GetTextureSwapChainLength_real(NULL), vrapi_GetTextureSwapChainHandle_real(NULL), vrapi_GetSystemPropertyInt_real(NULL), m_PopulatedHooks(false), @@ -57,7 +55,7 @@ public: { LibraryHooks::GetInstance().RegisterHook("libvrapi.so", this); - m_EnabledHooks = true; + m_EnabledHooks = false; } ~VRAPIHook() {} static void libHooked(void *realLib); @@ -75,7 +73,6 @@ public: //--------------------------------------------------------------------------------------------------------- PFN_vrapi_CreateTextureSwapChain2 vrapi_CreateTextureSwapChain2_real; PFN_vrapi_CreateTextureSwapChain vrapi_CreateTextureSwapChain_real; - PFN_vrapi_SubmitFrame vrapi_SubmitFrame_real; PFN_vrapi_GetTextureSwapChainLength vrapi_GetTextureSwapChainLength_real; PFN_vrapi_GetTextureSwapChainHandle vrapi_GetTextureSwapChainHandle_real; @@ -93,9 +90,6 @@ public: if(vrapi_CreateTextureSwapChain_real == NULL) vrapi_CreateTextureSwapChain_real = (PFN_vrapi_CreateTextureSwapChain)PosixGetFunction( libvrapi_symHandle, "vrapi_CreateTextureSwapChain"); - if(vrapi_SubmitFrame_real == NULL) - vrapi_SubmitFrame_real = - (PFN_vrapi_SubmitFrame)PosixGetFunction(libvrapi_symHandle, "vrapi_SubmitFrame"); if(vrapi_GetTextureSwapChainLength_real == NULL) vrapi_GetTextureSwapChainLength_real = (PFN_vrapi_GetTextureSwapChainLength)PosixGetFunction( @@ -107,7 +101,7 @@ public: vrapi_GetSystemPropertyInt_real = (PFN_vrapi_GetSystemPropertyInt)PosixGetFunction( libvrapi_symHandle, "vrapi_GetSystemPropertyInt"); - return vrapi_SubmitFrame_real != NULL; + return vrapi_CreateTextureSwapChain2_real != NULL; } } vrapi_hooks; @@ -232,23 +226,6 @@ __attribute__((visibility("default"))) ovrTextureSwapChain *vrapi_CreateTextureS return texture_swapchain; } -__attribute__((visibility("default"))) void vrapi_SubmitFrame(ovrMobile *ovr, - const ovrFrameParms *parms) -{ - if(vrapi_hooks.vrapi_SubmitFrame_real == NULL || vrapi_hooks.vrapi_GetSystemPropertyInt_real == NULL) - { - vrapi_hooks.SetupHooks(); - } - - if(m_GLDriver) - { - SCOPED_LOCK(glLock); - - m_GLDriver->SwapBuffers(ovr); - } - - vrapi_hooks.vrapi_SubmitFrame_real(ovr, parms); -} } // extern "C" void VRAPIHook::libHooked(void *realLib) @@ -266,7 +243,6 @@ bool VRAPIHook::CreateHooks(const char *libName) { PosixHookFunction("vrapi_CreateTextureSwapChain2", (void *)&vrapi_CreateTextureSwapChain2); PosixHookFunction("vrapi_CreateTextureSwapChain", (void *)&vrapi_CreateTextureSwapChain); - PosixHookFunction("vrapi_SubmitFrame", (void *)&vrapi_SubmitFrame); PosixHookLibrary(libName, &libHooked); return true; diff --git a/renderdoc/driver/gl/wrappers/gl_debug_funcs.cpp b/renderdoc/driver/gl/wrappers/gl_debug_funcs.cpp index af4de9c02..49291afd2 100644 --- a/renderdoc/driver/gl/wrappers/gl_debug_funcs.cpp +++ b/renderdoc/driver/gl/wrappers/gl_debug_funcs.cpp @@ -191,11 +191,23 @@ bool WrappedOpenGL::Serialise_glDebugMessageInsert(SerialiserType &ser, GLenum s return true; } +void WrappedOpenGL::HandleVRFrameMarkers(const GLchar *buf, GLsizei length) +{ + if (strstr(buf, "vr-marker,frame_end,type,application") != NULL) + { + void *ctx = NULL, *wnd = NULL; + RenderDoc::Inst().GetActiveWindow(ctx, wnd); + SwapBuffers(wnd); + } +} + void WrappedOpenGL::glDebugMessageInsert(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf) { SERIALISE_TIME_CALL(m_Real.glDebugMessageInsert(source, type, id, severity, length, buf)); + HandleVRFrameMarkers(buf, length); + if(IsActiveCapturing(m_State) && type == eGL_DEBUG_TYPE_MARKER) { USE_SCRATCH_SERIALISER();