bgfx/src/renderer_d3d.h

92 lines
3.2 KiB
C
Raw Normal View History

2013-02-22 09:07:31 +04:00
/*
2014-02-11 10:07:04 +04:00
* Copyright 2011-2014 Branimir Karadzic. All rights reserved.
2013-02-22 09:07:31 +04:00
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#ifndef BGFX_RENDERER_D3D_H_HEADER_GUARD
#define BGFX_RENDERER_D3D_H_HEADER_GUARD
2013-02-22 09:07:31 +04:00
#if 0 // BGFX_CONFIG_DEBUG && BGFX_CONFIG_RENDERER_DIRECT3D9 && !(BX_COMPILER_GCC || BX_COMPILER_CLANG)
2013-04-08 00:44:10 +04:00
# include <sal.h>
2013-02-22 09:07:31 +04:00
# include <dxerr.h>
2013-04-08 01:08:20 +04:00
# if BX_COMPILER_MSVC
# pragma comment(lib, "dxerr.lib")
# endif // BX_COMPILER_MSVC
2013-02-22 09:07:31 +04:00
# define DX_CHECK_EXTRA_F " (%s): %s"
# define DX_CHECK_EXTRA_ARGS , DXGetErrorString(__hr__), DXGetErrorDescription(__hr__)
#else
# define DX_CHECK_EXTRA_F ""
# define DX_CHECK_EXTRA_ARGS
2013-04-08 01:08:20 +04:00
#endif // BGFX_CONFIG_DEBUG && BGFX_CONFIG_RENDERER_DIRECT3D9
2013-02-22 09:07:31 +04:00
namespace bgfx
{
#define _DX_CHECK(_call) \
2014-06-09 07:57:39 +04:00
BX_MACRO_BLOCK_BEGIN \
2013-02-22 09:07:31 +04:00
HRESULT __hr__ = _call; \
BX_CHECK(SUCCEEDED(__hr__), #_call " FAILED 0x%08x" DX_CHECK_EXTRA_F "\n" \
, (uint32_t)__hr__ \
DX_CHECK_EXTRA_ARGS \
); \
2014-06-09 07:57:39 +04:00
BX_MACRO_BLOCK_END
2013-02-22 09:07:31 +04:00
#define _DX_RELEASE(_ptr, _expected, _check) \
2014-06-09 07:57:39 +04:00
BX_MACRO_BLOCK_BEGIN \
if (NULL != _ptr) \
{ \
ULONG count = _ptr->Release(); \
_check(isGraphicsDebuggerPresent() || _expected == count, "%p RefCount is %d (expected %d).", _ptr, count, _expected); BX_UNUSED(count); \
_ptr = NULL; \
} \
2014-06-09 07:57:39 +04:00
BX_MACRO_BLOCK_END
# define _DX_CHECK_REFCOUNT(_ptr, _expected) \
2014-06-09 07:57:39 +04:00
BX_MACRO_BLOCK_BEGIN \
ULONG count = getRefCount(_ptr); \
BX_CHECK(isGraphicsDebuggerPresent() || _expected == count, "%p RefCount is %d (expected %d).", _ptr, count, _expected); \
2014-06-09 07:57:39 +04:00
BX_MACRO_BLOCK_END
2013-02-22 09:07:31 +04:00
#if BGFX_CONFIG_DEBUG
# define DX_CHECK(_call) _DX_CHECK(_call)
# define DX_CHECK_REFCOUNT(_ptr, _expected) _DX_CHECK_REFCOUNT(_ptr, _expected)
2013-02-22 09:07:31 +04:00
#else
# define DX_CHECK(_call) _call
# define DX_CHECK_REFCOUNT(_ptr, _expected)
2013-02-22 09:07:31 +04:00
#endif // BGFX_CONFIG_DEBUG
#define DX_RELEASE(_ptr, _expected) _DX_RELEASE(_ptr, _expected, BX_CHECK)
#define DX_RELEASE_WARNONLY(_ptr, _expected) _DX_RELEASE(_ptr, _expected, BX_WARN)
2014-10-07 09:10:55 +04:00
typedef int (WINAPI* PFN_D3DPERF_BEGIN_EVENT)(DWORD _color, LPCWSTR _wszName);
typedef int (WINAPI* PFN_D3DPERF_END_EVENT)();
typedef void (WINAPI* PFN_D3DPERF_SET_MARKER)(DWORD _color, LPCWSTR _wszName);
typedef void (WINAPI* PFN_D3DPERF_SET_REGION)(DWORD _color, LPCWSTR _wszName);
typedef BOOL (WINAPI* PFN_D3DPERF_QUERY_REPEAT_FRAME)();
typedef void (WINAPI* PFN_D3DPERF_SET_OPTIONS)(DWORD _options);
typedef DWORD (WINAPI* PFN_D3DPERF_GET_STATUS)();
typedef HRESULT (WINAPI* PFN_CREATE_DXGI_FACTORY)(REFIID _riid, void** _factory);
2014-10-07 09:10:55 +04:00
#define _PIX_SETMARKER(_col, _name) D3DPERF_SetMarker(_col, _name)
#define _PIX_BEGINEVENT(_col, _name) D3DPERF_BeginEvent(_col, _name)
#define _PIX_ENDEVENT() D3DPERF_EndEvent()
#if BGFX_CONFIG_DEBUG_PIX
# define PIX_SETMARKER(_color, _name) _PIX_SETMARKER(_color, _name)
# define PIX_BEGINEVENT(_color, _name) _PIX_BEGINEVENT(_color, _name)
# define PIX_ENDEVENT() _PIX_ENDEVENT()
#else
# define PIX_SETMARKER(_color, _name)
# define PIX_BEGINEVENT(_color, _name)
# define PIX_ENDEVENT()
#endif // BGFX_CONFIG_DEBUG_PIX
2013-02-22 09:07:31 +04:00
inline int getRefCount(IUnknown* _interface)
{
_interface->AddRef();
return _interface->Release();
}
} // namespace bgfx
#endif // BGFX_RENDERER_D3D_H_HEADER_GUARD