renderer_d3d.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright 2011-2013 Branimir Karadzic. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  4. */
  5. #ifndef __RENDERER_D3D_H__
  6. #define __RENDERER_D3D_H__
  7. #if BGFX_CONFIG_DEBUG && BGFX_CONFIG_RENDERER_DIRECT3D9
  8. # include <sal.h>
  9. # include <dxerr.h>
  10. # if BX_COMPILER_MSVC
  11. # pragma comment(lib, "dxerr.lib")
  12. # endif // BX_COMPILER_MSVC
  13. # define DX_CHECK_EXTRA_F " (%s): %s"
  14. # define DX_CHECK_EXTRA_ARGS , DXGetErrorString(__hr__), DXGetErrorDescription(__hr__)
  15. #else
  16. # define DX_CHECK_EXTRA_F ""
  17. # define DX_CHECK_EXTRA_ARGS
  18. #endif // BGFX_CONFIG_DEBUG && BGFX_CONFIG_RENDERER_DIRECT3D9
  19. namespace bgfx
  20. {
  21. #define _DX_CHECK(_call) \
  22. do { \
  23. HRESULT __hr__ = _call; \
  24. BX_CHECK(SUCCEEDED(__hr__), #_call " FAILED 0x%08x" DX_CHECK_EXTRA_F "\n" \
  25. , (uint32_t)__hr__ \
  26. DX_CHECK_EXTRA_ARGS \
  27. ); \
  28. } while (0)
  29. #define _DX_RELEASE(_ptr, _expected, _check) \
  30. do { \
  31. if (NULL != _ptr) \
  32. { \
  33. ULONG count = _ptr->Release(); \
  34. _check(isGraphicsDebuggerPresent() || _expected == count, "%p RefCount is %d (expected %d).", _ptr, count, _expected); BX_UNUSED(count); \
  35. _ptr = NULL; \
  36. } \
  37. } while (0)
  38. # define _DX_CHECK_REFCOUNT(_ptr, _expected) \
  39. do { \
  40. ULONG count = getRefCount(_ptr); \
  41. BX_CHECK(isGraphicsDebuggerPresent() || _expected == count, "%p RefCount is %d (expected %d).", _ptr, count, _expected); \
  42. } while (0)
  43. #if BGFX_CONFIG_DEBUG
  44. # define DX_CHECK(_call) _DX_CHECK(_call)
  45. # define DX_CHECK_REFCOUNT(_ptr, _expected) _DX_CHECK_REFCOUNT(_ptr, _expected)
  46. #else
  47. # define DX_CHECK(_call) _call
  48. # define DX_CHECK_REFCOUNT(_ptr, _expected)
  49. #endif // BGFX_CONFIG_DEBUG
  50. #define DX_RELEASE(_ptr, _expected) _DX_RELEASE(_ptr, _expected, BX_CHECK)
  51. #define DX_RELEASE_WARNONLY(_ptr, _expected) _DX_RELEASE(_ptr, _expected, BX_WARN)
  52. typedef int (WINAPI *D3DPERF_BeginEventFunc)(DWORD _color, LPCWSTR _wszName);
  53. typedef int (WINAPI *D3DPERF_EndEventFunc)();
  54. typedef void (WINAPI *D3DPERF_SetMarkerFunc)(DWORD _color, LPCWSTR _wszName);
  55. typedef void (WINAPI *D3DPERF_SetRegionFunc)(DWORD _color, LPCWSTR _wszName);
  56. typedef BOOL (WINAPI *D3DPERF_QueryRepeatFrameFunc)();
  57. typedef void (WINAPI *D3DPERF_SetOptionsFunc)(DWORD _options);
  58. typedef DWORD (WINAPI *D3DPERF_GetStatusFunc)();
  59. #define _PIX_SETMARKER(_col, _name) s_renderCtx->m_D3DPERF_SetMarker(_col, _name)
  60. #define _PIX_BEGINEVENT(_col, _name) s_renderCtx->m_D3DPERF_BeginEvent(_col, _name)
  61. #define _PIX_ENDEVENT() s_renderCtx->m_D3DPERF_EndEvent()
  62. #if BGFX_CONFIG_DEBUG_PIX
  63. # define PIX_SETMARKER(_color, _name) _PIX_SETMARKER(_color, _name)
  64. # define PIX_BEGINEVENT(_color, _name) _PIX_BEGINEVENT(_color, _name)
  65. # define PIX_ENDEVENT() _PIX_ENDEVENT()
  66. #else
  67. # define PIX_SETMARKER(_color, _name)
  68. # define PIX_BEGINEVENT(_color, _name)
  69. # define PIX_ENDEVENT()
  70. #endif // BGFX_CONFIG_DEBUG_PIX
  71. inline int getRefCount(IUnknown* _interface)
  72. {
  73. _interface->AddRef();
  74. return _interface->Release();
  75. }
  76. } // namespace bgfx
  77. #endif // __RENDERER_D3D_H__