diff --git a/Makefile.am b/Makefile.am index 8abe0863..a9ea1433 100644 --- a/Makefile.am +++ b/Makefile.am @@ -250,7 +250,6 @@ BUILT_SOURCES = $(widl_headers) \ noinst_LTLIBRARIES = libvkd3d-common.la libvkd3d_common_la_SOURCES = \ - include/private/vkd3d_debug.h \ libs/vkd3d-common/blob.c \ libs/vkd3d-common/debug.c \ libs/vkd3d-common/error.c \ @@ -306,7 +305,6 @@ libvkd3d_shader_la_SOURCES = \ include/private/list.h \ include/private/rbtree.h \ include/private/vkd3d_common.h \ - include/private/vkd3d_debug.h \ include/private/vkd3d_memory.h \ include/vkd3d_shader.h \ libs/vkd3d-shader/checksum.c \ @@ -344,7 +342,6 @@ EXTRA_DIST = \ libvkd3d_la_SOURCES = \ include/private/vkd3d_blob.h \ include/private/vkd3d_common.h \ - include/private/vkd3d_debug.h \ include/private/vkd3d_memory.h \ include/private/vkd3d_shader_utils.h \ include/private/vkd3d_test.h \ diff --git a/include/private/vkd3d_common.h b/include/private/vkd3d_common.h index dc0b2e17..372f39ce 100644 --- a/include/private/vkd3d_common.h +++ b/include/private/vkd3d_common.h @@ -105,6 +105,125 @@ VKD3D_NORETURN static inline void vkd3d_unreachable_(const char *filename, unsig #define vkd3d_unreachable() vkd3d_unreachable_(__FILE__, __LINE__) #endif +#ifdef VKD3D_NO_TRACE_MESSAGES +#define TRACE(args...) do { } while (0) +#define TRACE_ON() (false) +#endif + +#ifdef VKD3D_NO_DEBUG_MESSAGES +#define WARN(args...) do { } while (0) +#define FIXME(args...) do { } while (0) +#endif + +enum vkd3d_dbg_level +{ + VKD3D_DBG_LEVEL_NONE, + VKD3D_DBG_LEVEL_ERR, + VKD3D_DBG_LEVEL_FIXME, + VKD3D_DBG_LEVEL_WARN, + VKD3D_DBG_LEVEL_TRACE, +}; + +enum vkd3d_dbg_level vkd3d_dbg_get_level(void); + +void vkd3d_dbg_printf(enum vkd3d_dbg_level level, const char *function, const char *fmt, ...) VKD3D_PRINTF_FUNC(3, 4); +void vkd3d_dbg_set_log_callback(PFN_vkd3d_log callback); + +const char *vkd3d_dbg_sprintf(const char *fmt, ...) VKD3D_PRINTF_FUNC(1, 2); +const char *vkd3d_dbg_vsprintf(const char *fmt, va_list args); +const char *debugstr_a(const char *str); +const char *debugstr_an(const char *str, size_t n); +const char *debugstr_w(const WCHAR *wstr, size_t wchar_size); + +#define VKD3D_DBG_LOG(level) \ + do { \ + const enum vkd3d_dbg_level vkd3d_dbg_level = VKD3D_DBG_LEVEL_##level; \ + VKD3D_DBG_PRINTF + +#define VKD3D_DBG_LOG_ONCE(first_time_level, level) \ + do { \ + static bool vkd3d_dbg_next_time; \ + const enum vkd3d_dbg_level vkd3d_dbg_level = vkd3d_dbg_next_time \ + ? VKD3D_DBG_LEVEL_##level : VKD3D_DBG_LEVEL_##first_time_level; \ + vkd3d_dbg_next_time = true; \ + VKD3D_DBG_PRINTF + +#define VKD3D_DBG_PRINTF(...) \ + vkd3d_dbg_printf(vkd3d_dbg_level, __FUNCTION__, __VA_ARGS__); } while (0) + +#ifndef TRACE +#define TRACE VKD3D_DBG_LOG(TRACE) +#endif + +#ifndef WARN +#define WARN VKD3D_DBG_LOG(WARN) +#endif + +#ifndef FIXME +#define FIXME VKD3D_DBG_LOG(FIXME) +#endif + +#define ERR VKD3D_DBG_LOG(ERR) + +#ifndef TRACE_ON +#define TRACE_ON() (vkd3d_dbg_get_level() == VKD3D_DBG_LEVEL_TRACE) +#endif + +#ifndef WARN_ON +#define WARN_ON() (vkd3d_dbg_get_level() >= VKD3D_DBG_LEVEL_WARN) +#endif + +#define FIXME_ONCE VKD3D_DBG_LOG_ONCE(FIXME, WARN) + +#define VKD3D_DEBUG_ENV_NAME(name) const char *const vkd3d_dbg_env_name = name + +static inline const char *debugstr_guid(const GUID *guid) +{ + if (!guid) + return "(null)"; + + return vkd3d_dbg_sprintf("{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", + (unsigned long)guid->Data1, guid->Data2, guid->Data3, guid->Data4[0], + guid->Data4[1], guid->Data4[2], guid->Data4[3], guid->Data4[4], + guid->Data4[5], guid->Data4[6], guid->Data4[7]); +} + +static inline const char *debugstr_hresult(HRESULT hr) +{ + switch (hr) + { +#define TO_STR(u) case u: return #u; + TO_STR(S_OK) + TO_STR(S_FALSE) + TO_STR(E_NOTIMPL) + TO_STR(E_NOINTERFACE) + TO_STR(E_POINTER) + TO_STR(E_ABORT) + TO_STR(E_FAIL) + TO_STR(E_OUTOFMEMORY) + TO_STR(E_INVALIDARG) + TO_STR(DXGI_ERROR_NOT_FOUND) + TO_STR(DXGI_ERROR_MORE_DATA) + TO_STR(DXGI_ERROR_UNSUPPORTED) +#undef TO_STR + default: + return vkd3d_dbg_sprintf("%#x", (int)hr); + } +} + +unsigned int vkd3d_env_var_as_uint(const char *name, unsigned int default_value); + +struct vkd3d_debug_option +{ + const char *name; + uint64_t flag; +}; + +bool vkd3d_debug_list_has_member(const char *string, const char *member); +uint64_t vkd3d_parse_debug_options(const char *string, + const struct vkd3d_debug_option *options, unsigned int option_count); +void vkd3d_set_thread_name(const char *name); + static inline unsigned int vkd3d_popcount(unsigned int v) { #ifdef _MSC_VER diff --git a/include/private/vkd3d_debug.h b/include/private/vkd3d_debug.h deleted file mode 100644 index c5b6cced..00000000 --- a/include/private/vkd3d_debug.h +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright 2016 Józef Kucia for CodeWeavers - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#ifndef __VKD3D_DEBUG_H -#define __VKD3D_DEBUG_H - -#include "vkd3d_common.h" - -#include -#include -#include - -#ifdef VKD3D_NO_TRACE_MESSAGES -#define TRACE(args...) do { } while (0) -#define TRACE_ON() (false) -#endif - -#ifdef VKD3D_NO_DEBUG_MESSAGES -#define WARN(args...) do { } while (0) -#define FIXME(args...) do { } while (0) -#endif - -enum vkd3d_dbg_level -{ - VKD3D_DBG_LEVEL_NONE, - VKD3D_DBG_LEVEL_ERR, - VKD3D_DBG_LEVEL_FIXME, - VKD3D_DBG_LEVEL_WARN, - VKD3D_DBG_LEVEL_TRACE, -}; - -enum vkd3d_dbg_level vkd3d_dbg_get_level(void); - -void vkd3d_dbg_printf(enum vkd3d_dbg_level level, const char *function, const char *fmt, ...) VKD3D_PRINTF_FUNC(3, 4); -void vkd3d_dbg_set_log_callback(PFN_vkd3d_log callback); - -const char *vkd3d_dbg_sprintf(const char *fmt, ...) VKD3D_PRINTF_FUNC(1, 2); -const char *vkd3d_dbg_vsprintf(const char *fmt, va_list args); -const char *debugstr_a(const char *str); -const char *debugstr_an(const char *str, size_t n); -const char *debugstr_w(const WCHAR *wstr, size_t wchar_size); - -#define VKD3D_DBG_LOG(level) \ - do { \ - const enum vkd3d_dbg_level vkd3d_dbg_level = VKD3D_DBG_LEVEL_##level; \ - VKD3D_DBG_PRINTF - -#define VKD3D_DBG_LOG_ONCE(first_time_level, level) \ - do { \ - static bool vkd3d_dbg_next_time; \ - const enum vkd3d_dbg_level vkd3d_dbg_level = vkd3d_dbg_next_time \ - ? VKD3D_DBG_LEVEL_##level : VKD3D_DBG_LEVEL_##first_time_level; \ - vkd3d_dbg_next_time = true; \ - VKD3D_DBG_PRINTF - -#define VKD3D_DBG_PRINTF(...) \ - vkd3d_dbg_printf(vkd3d_dbg_level, __FUNCTION__, __VA_ARGS__); } while (0) - -#ifndef TRACE -#define TRACE VKD3D_DBG_LOG(TRACE) -#endif - -#ifndef WARN -#define WARN VKD3D_DBG_LOG(WARN) -#endif - -#ifndef FIXME -#define FIXME VKD3D_DBG_LOG(FIXME) -#endif - -#define ERR VKD3D_DBG_LOG(ERR) - -#ifndef TRACE_ON -#define TRACE_ON() (vkd3d_dbg_get_level() == VKD3D_DBG_LEVEL_TRACE) -#endif - -#ifndef WARN_ON -#define WARN_ON() (vkd3d_dbg_get_level() >= VKD3D_DBG_LEVEL_WARN) -#endif - -#define FIXME_ONCE VKD3D_DBG_LOG_ONCE(FIXME, WARN) - -#define VKD3D_DEBUG_ENV_NAME(name) const char *const vkd3d_dbg_env_name = name - -static inline const char *debugstr_guid(const GUID *guid) -{ - if (!guid) - return "(null)"; - - return vkd3d_dbg_sprintf("{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", - (unsigned long)guid->Data1, guid->Data2, guid->Data3, guid->Data4[0], - guid->Data4[1], guid->Data4[2], guid->Data4[3], guid->Data4[4], - guid->Data4[5], guid->Data4[6], guid->Data4[7]); -} - -static inline const char *debugstr_hresult(HRESULT hr) -{ - switch (hr) - { -#define TO_STR(u) case u: return #u; - TO_STR(S_OK) - TO_STR(S_FALSE) - TO_STR(E_NOTIMPL) - TO_STR(E_NOINTERFACE) - TO_STR(E_POINTER) - TO_STR(E_ABORT) - TO_STR(E_FAIL) - TO_STR(E_OUTOFMEMORY) - TO_STR(E_INVALIDARG) - TO_STR(DXGI_ERROR_NOT_FOUND) - TO_STR(DXGI_ERROR_MORE_DATA) - TO_STR(DXGI_ERROR_UNSUPPORTED) -#undef TO_STR - default: - return vkd3d_dbg_sprintf("%#x", (int)hr); - } -} - -unsigned int vkd3d_env_var_as_uint(const char *name, unsigned int default_value); - -struct vkd3d_debug_option -{ - const char *name; - uint64_t flag; -}; - -bool vkd3d_debug_list_has_member(const char *string, const char *member); -uint64_t vkd3d_parse_debug_options(const char *string, - const struct vkd3d_debug_option *options, unsigned int option_count); -void vkd3d_set_thread_name(const char *name); - -#endif /* __VKD3D_DEBUG_H */ diff --git a/include/private/vkd3d_memory.h b/include/private/vkd3d_memory.h index 8a2edb10..bb177e39 100644 --- a/include/private/vkd3d_memory.h +++ b/include/private/vkd3d_memory.h @@ -24,7 +24,7 @@ #include #include -#include "vkd3d_debug.h" +#include "vkd3d_common.h" static inline void *vkd3d_malloc(size_t size) { diff --git a/libs/vkd3d-common/blob.c b/libs/vkd3d-common/blob.c index cae57610..b12d9630 100644 --- a/libs/vkd3d-common/blob.c +++ b/libs/vkd3d-common/blob.c @@ -21,7 +21,6 @@ #define CONST_VTABLE #include "vkd3d.h" #include "vkd3d_blob.h" -#include "vkd3d_debug.h" #include "vkd3d_memory.h" #include "vkd3d_d3d12shader.h" diff --git a/libs/vkd3d-common/debug.c b/libs/vkd3d-common/debug.c index e12cd394..4523fc99 100644 --- a/libs/vkd3d-common/debug.c +++ b/libs/vkd3d-common/debug.c @@ -20,7 +20,7 @@ # define _WIN32_WINNT 0x0600 /* For InitOnceExecuteOnce(). */ #endif -#include "vkd3d_debug.h" +#include "vkd3d_common.h" #include #include diff --git a/libs/vkd3d-common/error.c b/libs/vkd3d-common/error.c index 3572669a..b8350a54 100644 --- a/libs/vkd3d-common/error.c +++ b/libs/vkd3d-common/error.c @@ -17,7 +17,6 @@ */ #include "vkd3d_common.h" -#include "vkd3d_debug.h" HRESULT hresult_from_vkd3d_result(int vkd3d_result) {