Mostly so that the debug primitives don't depend on a shared variable.
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- This allows to keep using a separate debug env var for vkd3d-shader even when building vkd3d as static lib(s). That will eventually make it possible to drop the related change in the vkd3d copy imported into Wine.
include/private/vkd3d_debug.h | 32 +++++++++++++++++---------- libs/vkd3d-common/blob.c | 2 ++ libs/vkd3d-common/debug.c | 23 +++++++++---------- libs/vkd3d-common/error.c | 2 ++ libs/vkd3d-common/memory.c | 2 ++ libs/vkd3d-shader/d3dbc.c | 2 ++ libs/vkd3d-shader/dxbc.c | 2 ++ libs/vkd3d-shader/hlsl.c | 2 ++ libs/vkd3d-shader/hlsl.l | 2 ++ libs/vkd3d-shader/hlsl.y | 2 ++ libs/vkd3d-shader/hlsl_codegen.c | 2 ++ libs/vkd3d-shader/hlsl_constant_ops.c | 2 ++ libs/vkd3d-shader/hlsl_sm1.c | 2 ++ libs/vkd3d-shader/hlsl_sm4.c | 2 ++ libs/vkd3d-shader/preproc.l | 2 ++ libs/vkd3d-shader/preproc.y | 2 ++ libs/vkd3d-shader/spirv.c | 2 ++ libs/vkd3d-shader/trace.c | 2 ++ libs/vkd3d-shader/vkd3d_shader_main.c | 2 +- libs/vkd3d/command.c | 2 ++ libs/vkd3d/device.c | 2 ++ libs/vkd3d/resource.c | 2 ++ libs/vkd3d/state.c | 2 ++ libs/vkd3d/utils.c | 2 ++ 24 files changed, 73 insertions(+), 26 deletions(-)
diff --git a/include/private/vkd3d_debug.h b/include/private/vkd3d_debug.h index 8ab653ae..bc3bf5c9 100644 --- a/include/private/vkd3d_debug.h +++ b/include/private/vkd3d_debug.h @@ -44,9 +44,15 @@ enum vkd3d_dbg_level VKD3D_DBG_LEVEL_TRACE, };
-enum vkd3d_dbg_level vkd3d_dbg_get_level(void); +struct vkd3d_debug_channel +{ + const char name[64]; + enum vkd3d_dbg_level level; +}; + +enum vkd3d_dbg_level vkd3d_dbg_get_level(struct vkd3d_debug_channel *channel);
-void vkd3d_dbg_printf(enum vkd3d_dbg_level level, const char *function, const char *fmt, ...) VKD3D_PRINTF_FUNC(3, 4); +void vkd3d_dbg_printf(struct vkd3d_debug_channel *channel, enum vkd3d_dbg_level level, const char *function, const char *fmt, ...) VKD3D_PRINTF_FUNC(4, 5);
const char *vkd3d_dbg_sprintf(const char *fmt, ...) VKD3D_PRINTF_FUNC(1, 2); const char *vkd3d_dbg_vsprintf(const char *fmt, va_list args); @@ -54,13 +60,15 @@ 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) \ +#define VKD3D_DBG_LOG(channel, level) \ do { \ + struct vkd3d_debug_channel *vkd3d_dbg_channel = &channel; \ const enum vkd3d_dbg_level vkd3d_dbg_level = VKD3D_DBG_LEVEL_##level; \ VKD3D_DBG_PRINTF
-#define VKD3D_DBG_LOG_ONCE(first_time_level, level) \ +#define VKD3D_DBG_LOG_ONCE(channel, first_time_level, level) \ do { \ + struct vkd3d_debug_channel *vkd3d_dbg_channel = &channel; \ 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; \ @@ -68,29 +76,29 @@ const char *debugstr_w(const WCHAR *wstr, size_t wchar_size); VKD3D_DBG_PRINTF
#define VKD3D_DBG_PRINTF(...) \ - vkd3d_dbg_printf(vkd3d_dbg_level, __FUNCTION__, __VA_ARGS__); } while (0) + vkd3d_dbg_printf(vkd3d_dbg_channel, vkd3d_dbg_level, __FUNCTION__, __VA_ARGS__); } while (0)
#ifndef TRACE -#define TRACE VKD3D_DBG_LOG(TRACE) +#define TRACE VKD3D_DBG_LOG(vkd3d_debug_channel, TRACE) #endif
#ifndef WARN -#define WARN VKD3D_DBG_LOG(WARN) +#define WARN VKD3D_DBG_LOG(vkd3d_debug_channel, WARN) #endif
#ifndef FIXME -#define FIXME VKD3D_DBG_LOG(FIXME) +#define FIXME VKD3D_DBG_LOG(vkd3d_debug_channel, FIXME) #endif
-#define ERR VKD3D_DBG_LOG(ERR) +#define ERR VKD3D_DBG_LOG(vkd3d_debug_channel, ERR)
#ifndef TRACE_ON -#define TRACE_ON() (vkd3d_dbg_get_level() == VKD3D_DBG_LEVEL_TRACE) +#define TRACE_ON() (vkd3d_dbg_get_level(&vkd3d_debug_channel) == VKD3D_DBG_LEVEL_TRACE) #endif
-#define FIXME_ONCE VKD3D_DBG_LOG_ONCE(FIXME, WARN) +#define FIXME_ONCE VKD3D_DBG_LOG_ONCE(vkd3d_debug_channel, FIXME, WARN)
-#define VKD3D_DEBUG_ENV_NAME(name) const char *vkd3d_dbg_env_name = name +#define VKD3D_DEBUG_ENV_NAME(name) static struct vkd3d_debug_channel vkd3d_debug_channel = {name, ~0u};
static inline const char *debugstr_guid(const GUID *guid) { diff --git a/libs/vkd3d-common/blob.c b/libs/vkd3d-common/blob.c index c46abb55..1cb817ce 100644 --- a/libs/vkd3d-common/blob.c +++ b/libs/vkd3d-common/blob.c @@ -23,6 +23,8 @@ #include "vkd3d_debug.h" #include "vkd3d_memory.h"
+VKD3D_DEBUG_ENV_NAME("VKD3D_DEBUG"); + struct vkd3d_blob { ID3D10Blob ID3DBlob_iface; diff --git a/libs/vkd3d-common/debug.c b/libs/vkd3d-common/debug.c index 4868f3fb..0cbf2fbe 100644 --- a/libs/vkd3d-common/debug.c +++ b/libs/vkd3d-common/debug.c @@ -31,8 +31,6 @@ #define VKD3D_DEBUG_BUFFER_COUNT 64 #define VKD3D_DEBUG_BUFFER_SIZE 512
-extern const char *vkd3d_dbg_env_name; - static const char *debug_level_names[] = { /* VKD3D_DBG_LEVEL_NONE */ "none", @@ -42,37 +40,36 @@ static const char *debug_level_names[] = /* VKD3D_DBG_LEVEL_TRACE */ "trace", };
-enum vkd3d_dbg_level vkd3d_dbg_get_level(void) +enum vkd3d_dbg_level vkd3d_dbg_get_level(struct vkd3d_debug_channel *channel) { - static unsigned int level = ~0u; const char *vkd3d_debug; unsigned int i;
- if (level != ~0u) - return level; + if (channel->level != ~0u) + return channel->level;
- if (!(vkd3d_debug = getenv(vkd3d_dbg_env_name))) + if (!(vkd3d_debug = getenv(channel->name))) vkd3d_debug = "";
for (i = 0; i < ARRAY_SIZE(debug_level_names); ++i) { if (!strcmp(debug_level_names[i], vkd3d_debug)) { - level = i; - return level; + channel->level = i; + return channel->level; } }
/* Default debug level. */ - level = VKD3D_DBG_LEVEL_FIXME; - return level; + channel->level = VKD3D_DBG_LEVEL_FIXME; + return channel->level; }
-void vkd3d_dbg_printf(enum vkd3d_dbg_level level, const char *function, const char *fmt, ...) +void vkd3d_dbg_printf(struct vkd3d_debug_channel *channel, enum vkd3d_dbg_level level, const char *function, const char *fmt, ...) { va_list args;
- if (vkd3d_dbg_get_level() < level) + if (vkd3d_dbg_get_level(channel) < level) return;
assert(level < ARRAY_SIZE(debug_level_names)); diff --git a/libs/vkd3d-common/error.c b/libs/vkd3d-common/error.c index 81c1fd97..51928148 100644 --- a/libs/vkd3d-common/error.c +++ b/libs/vkd3d-common/error.c @@ -19,6 +19,8 @@ #include "vkd3d_common.h" #include "vkd3d_debug.h"
+VKD3D_DEBUG_ENV_NAME("VKD3D_DEBUG"); + HRESULT hresult_from_vkd3d_result(int vkd3d_result) { switch (vkd3d_result) diff --git a/libs/vkd3d-common/memory.c b/libs/vkd3d-common/memory.c index f46f180c..3546e136 100644 --- a/libs/vkd3d-common/memory.c +++ b/libs/vkd3d-common/memory.c @@ -19,6 +19,8 @@
#include "vkd3d_memory.h"
+VKD3D_DEBUG_ENV_NAME("VKD3D_DEBUG"); + void *vkd3d_malloc(size_t size) { void *ptr; diff --git a/libs/vkd3d-shader/d3dbc.c b/libs/vkd3d-shader/d3dbc.c index c5518752..e0e5c16e 100644 --- a/libs/vkd3d-shader/d3dbc.c +++ b/libs/vkd3d-shader/d3dbc.c @@ -24,6 +24,8 @@
#include "vkd3d_shader_private.h"
+VKD3D_DEBUG_ENV_NAME("VKD3D_SHADER_DEBUG"); + #define VKD3D_SM1_VS 0xfffeu #define VKD3D_SM1_PS 0xffffu
diff --git a/libs/vkd3d-shader/dxbc.c b/libs/vkd3d-shader/dxbc.c index 17be2306..410ed371 100644 --- a/libs/vkd3d-shader/dxbc.c +++ b/libs/vkd3d-shader/dxbc.c @@ -21,6 +21,8 @@ #include "vkd3d_shader_private.h" #include "sm4.h"
+VKD3D_DEBUG_ENV_NAME("VKD3D_SHADER_DEBUG"); + void dxbc_writer_init(struct dxbc_writer *dxbc) { memset(dxbc, 0, sizeof(*dxbc)); diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 7239b183..ffee93a6 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -22,6 +22,8 @@ #include "hlsl.h" #include <stdio.h>
+VKD3D_DEBUG_ENV_NAME("VKD3D_SHADER_DEBUG"); + void hlsl_note(struct hlsl_ctx *ctx, const struct vkd3d_shader_location *loc, enum vkd3d_shader_log_level level, const char *fmt, ...) { diff --git a/libs/vkd3d-shader/hlsl.l b/libs/vkd3d-shader/hlsl.l index 2c398bc8..70a24c16 100644 --- a/libs/vkd3d-shader/hlsl.l +++ b/libs/vkd3d-shader/hlsl.l @@ -24,6 +24,8 @@ #include "hlsl.h" #include "hlsl.tab.h"
+VKD3D_DEBUG_ENV_NAME("VKD3D_SHADER_DEBUG"); + #define YYSTYPE HLSL_YYSTYPE #define YYLTYPE HLSL_YYLTYPE
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 44e4964f..7d2f5014 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -108,6 +108,8 @@ int yylex(HLSL_YYSTYPE *yylval_param, HLSL_YYLTYPE *yylloc_param, void *yyscanne %code {
+VKD3D_DEBUG_ENV_NAME("VKD3D_SHADER_DEBUG"); + #define YYLLOC_DEFAULT(cur, rhs, n) (cur) = YYRHSLOC(rhs, !!n)
static void yyerror(YYLTYPE *loc, void *scanner, struct hlsl_ctx *ctx, const char *s) diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 78b22910..0794cebd 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -21,6 +21,8 @@ #include "hlsl.h" #include <stdio.h>
+VKD3D_DEBUG_ENV_NAME("VKD3D_SHADER_DEBUG"); + /* Split uniforms into two variables representing the constant and temp * registers, and copy the former to the latter, so that writes to uniforms * work. */ diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index d8787c21..647afc98 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -22,6 +22,8 @@
#include "hlsl.h"
+VKD3D_DEBUG_ENV_NAME("VKD3D_SHADER_DEBUG"); + static bool fold_cast(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst, struct hlsl_ir_constant *src) { unsigned int k; diff --git a/libs/vkd3d-shader/hlsl_sm1.c b/libs/vkd3d-shader/hlsl_sm1.c index 0cdd3917..a6d14b32 100644 --- a/libs/vkd3d-shader/hlsl_sm1.c +++ b/libs/vkd3d-shader/hlsl_sm1.c @@ -21,6 +21,8 @@ #include "hlsl.h" #include <stdio.h>
+VKD3D_DEBUG_ENV_NAME("VKD3D_SHADER_DEBUG"); + bool hlsl_sm1_register_from_semantic(struct hlsl_ctx *ctx, const struct hlsl_semantic *semantic, bool output, D3DSHADER_PARAM_REGISTER_TYPE *type, unsigned int *reg) { diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index a5fc094b..ce35d603 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -23,6 +23,8 @@ #include "vkd3d_d3dcommon.h" #include "sm4.h"
+VKD3D_DEBUG_ENV_NAME("VKD3D_SHADER_DEBUG"); + static void write_sm4_block(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer, const struct hlsl_block *block);
static bool type_is_integer(const struct hlsl_type *type) diff --git a/libs/vkd3d-shader/preproc.l b/libs/vkd3d-shader/preproc.l index 7686e018..f4db270d 100644 --- a/libs/vkd3d-shader/preproc.l +++ b/libs/vkd3d-shader/preproc.l @@ -22,6 +22,8 @@
#include "preproc.tab.h"
+VKD3D_DEBUG_ENV_NAME("VKD3D_SHADER_DEBUG"); + #undef ERROR /* defined in wingdi.h */
#define YYSTYPE PREPROC_YYSTYPE diff --git a/libs/vkd3d-shader/preproc.y b/libs/vkd3d-shader/preproc.y index 3f02ac03..79870503 100644 --- a/libs/vkd3d-shader/preproc.y +++ b/libs/vkd3d-shader/preproc.y @@ -46,6 +46,8 @@ int preproc_yylex(PREPROC_YYSTYPE *yylval_param, PREPROC_YYLTYPE *yylloc_param, %code {
+VKD3D_DEBUG_ENV_NAME("VKD3D_SHADER_DEBUG"); + #define YYLLOC_DEFAULT(cur, rhs, n) (cur) = YYRHSLOC(rhs, !!n)
#ifndef S_ISREG diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index 89b16305..b62a3f20 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -34,6 +34,8 @@ # include "vulkan/GLSL.std.450.h" #endif /* HAVE_SPIRV_UNIFIED1_GLSL_STD_450_H */
+VKD3D_DEBUG_ENV_NAME("VKD3D_SHADER_DEBUG"); + #ifdef HAVE_SPIRV_TOOLS # include "spirv-tools/libspirv.h"
diff --git a/libs/vkd3d-shader/trace.c b/libs/vkd3d-shader/trace.c index 6c30edc9..80803d78 100644 --- a/libs/vkd3d-shader/trace.c +++ b/libs/vkd3d-shader/trace.c @@ -27,6 +27,8 @@ #include <stdio.h> #include <math.h>
+VKD3D_DEBUG_ENV_NAME("VKD3D_SHADER_DEBUG"); + static const char * const shader_opcode_names[] = { [VKD3DSIH_ABS ] = "abs", diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index 62baf17f..398d430b 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -140,7 +140,7 @@ void vkd3d_shader_trace_text_(const char *text, size_t size, const char *functio q = end; else ++q; - vkd3d_dbg_printf(VKD3D_DBG_LEVEL_TRACE, function, "%.*s", (int)(q - p), p); + vkd3d_dbg_printf(&vkd3d_debug_channel, VKD3D_DBG_LEVEL_TRACE, function, "%.*s", (int)(q - p), p); } }
diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 55e6be58..60928bfc 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -20,6 +20,8 @@
#include "vkd3d_private.h"
+VKD3D_DEBUG_ENV_NAME("VKD3D_DEBUG"); + static void d3d12_fence_incref(struct d3d12_fence *fence); static void d3d12_fence_decref(struct d3d12_fence *fence); static HRESULT d3d12_fence_signal(struct d3d12_fence *fence, uint64_t value, VkFence vk_fence); diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index 5f8108ec..cfc8ed89 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -19,6 +19,8 @@ #include "vkd3d_private.h" #include "vkd3d_version.h"
+VKD3D_DEBUG_ENV_NAME("VKD3D_DEBUG"); + struct vkd3d_struct { enum vkd3d_structure_type type; diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index 68c28cd1..596b8f9e 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -24,6 +24,8 @@
LONG64 object_global_serial_id;
+VKD3D_DEBUG_ENV_NAME("VKD3D_DEBUG"); + static inline bool is_cpu_accessible_heap(const D3D12_HEAP_PROPERTIES *properties) { if (properties->Type == D3D12_HEAP_TYPE_DEFAULT) diff --git a/libs/vkd3d/state.c b/libs/vkd3d/state.c index 97e2856d..06260dab 100644 --- a/libs/vkd3d/state.c +++ b/libs/vkd3d/state.c @@ -21,6 +21,8 @@ #include "vkd3d_private.h" #include "vkd3d_shaders.h"
+VKD3D_DEBUG_ENV_NAME("VKD3D_DEBUG"); + /* ID3D12RootSignature */ static inline struct d3d12_root_signature *impl_from_ID3D12RootSignature(ID3D12RootSignature *iface) { diff --git a/libs/vkd3d/utils.c b/libs/vkd3d/utils.c index 8169b14b..73037654 100644 --- a/libs/vkd3d/utils.c +++ b/libs/vkd3d/utils.c @@ -20,6 +20,8 @@
#include <errno.h>
+VKD3D_DEBUG_ENV_NAME("VKD3D_DEBUG"); + #define COLOR (VK_IMAGE_ASPECT_COLOR_BIT) #define DEPTH (VK_IMAGE_ASPECT_DEPTH_BIT) #define STENCIL (VK_IMAGE_ASPECT_STENCIL_BIT)