debug_renderdoc.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright 2011-2016 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  4. */
  5. #include "bgfx_p.h"
  6. #if BGFX_CONFIG_DEBUG_PIX && (BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX)
  7. # if BX_PLATFORM_WINDOWS
  8. # include <psapi.h>
  9. # endif // BX_PLATFORM_WINDOWS
  10. # include <renderdoc/renderdoc_app.h>
  11. namespace bgfx
  12. {
  13. bool findModule(const char* _name)
  14. {
  15. #if BX_PLATFORM_WINDOWS
  16. HANDLE process = GetCurrentProcess();
  17. DWORD size;
  18. BOOL result = EnumProcessModules(process
  19. , NULL
  20. , 0
  21. , &size
  22. );
  23. if (0 != result)
  24. {
  25. HMODULE* modules = (HMODULE*)alloca(size);
  26. result = EnumProcessModules(process
  27. , modules
  28. , size
  29. , &size
  30. );
  31. if (0 != result)
  32. {
  33. char moduleName[MAX_PATH];
  34. for (uint32_t ii = 0, num = uint32_t(size/sizeof(HMODULE) ); ii < num; ++ii)
  35. {
  36. result = GetModuleBaseNameA(process
  37. , modules[ii]
  38. , moduleName
  39. , BX_COUNTOF(moduleName)
  40. );
  41. if (0 != result
  42. && 0 == bx::stricmp(_name, moduleName) )
  43. {
  44. return true;
  45. }
  46. }
  47. }
  48. }
  49. #endif // BX_PLATFORM_WINDOWS
  50. BX_UNUSED(_name);
  51. return false;
  52. }
  53. pRENDERDOC_GetAPI RENDERDOC_GetAPI;
  54. static RENDERDOC_API_1_0_0* s_renderDoc;
  55. void* loadRenderDoc()
  56. {
  57. // Skip loading RenderDoc when IntelGPA is present to avoid RenderDoc crash.
  58. if (findModule(BX_ARCH_32BIT ? "shimloader32.dll" : "shimloader64.dll") )
  59. {
  60. return NULL;
  61. }
  62. void* renderdocdll = bx::dlopen("renderdoc.dll");
  63. if (NULL != renderdocdll)
  64. {
  65. RENDERDOC_GetAPI = (pRENDERDOC_GetAPI)bx::dlsym(renderdocdll, "RENDERDOC_GetAPI");
  66. if (NULL != RENDERDOC_GetAPI
  67. && 1 == RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_0_0, (void**)&s_renderDoc) )
  68. {
  69. s_renderDoc->SetLogFilePathTemplate("temp/bgfx");
  70. s_renderDoc->SetFocusToggleKeys(NULL, 0);
  71. RENDERDOC_InputButton captureKey = eRENDERDOC_Key_F11;
  72. s_renderDoc->SetCaptureKeys(&captureKey, 1);
  73. s_renderDoc->SetCaptureOptionU32(eRENDERDOC_Option_AllowVSync, 1);
  74. s_renderDoc->SetCaptureOptionU32(eRENDERDOC_Option_SaveAllInitials, 1);
  75. s_renderDoc->MaskOverlayBits(eRENDERDOC_Overlay_None, eRENDERDOC_Overlay_None);
  76. }
  77. else
  78. {
  79. bx::dlclose(renderdocdll);
  80. renderdocdll = NULL;
  81. }
  82. }
  83. return renderdocdll;
  84. }
  85. void unloadRenderDoc(void* _renderdocdll)
  86. {
  87. if (NULL != _renderdocdll)
  88. {
  89. s_renderDoc->Shutdown();
  90. bx::dlclose(_renderdocdll);
  91. }
  92. }
  93. } // namespace bgfx
  94. #else
  95. namespace bgfx
  96. {
  97. void* loadRenderDoc()
  98. {
  99. return NULL;
  100. }
  101. void unloadRenderDoc(void*)
  102. {
  103. }
  104. } // namespace bgfx
  105. #endif // BGFX_CONFIG_DEBUG_PIX && (BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX)