Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
Il 02/06/22 02:01, Zebediah Figura ha scritto:
When using PE vkd3d through Wine, debug output may be swallowed by writing to Win32 stderr. Avoid this by providing a way to hook up vkd3d log output to Wine output.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
include/private/vkd3d_debug.h | 1 + include/vkd3d_shader.h | 15 ++++++++++++++ include/vkd3d_types.h | 4 ++++ libs/vkd3d-common/debug.c | 28 +++++++++++++++++++++++++-- libs/vkd3d-shader/vkd3d_shader.map | 1 + libs/vkd3d-shader/vkd3d_shader_main.c | 5 +++++ 6 files changed, 52 insertions(+), 2 deletions(-)
diff --git a/include/private/vkd3d_debug.h b/include/private/vkd3d_debug.h index 8ab653aef..579c33d36 100644 --- a/include/private/vkd3d_debug.h +++ b/include/private/vkd3d_debug.h @@ -47,6 +47,7 @@ enum vkd3d_dbg_level 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); diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h index 05d235f9d..1e5a332ef 100644 --- a/include/vkd3d_shader.h +++ b/include/vkd3d_shader.h @@ -1806,6 +1806,18 @@ VKD3D_SHADER_API void vkd3d_shader_free_shader_signature(struct vkd3d_shader_sig VKD3D_SHADER_API int vkd3d_shader_preprocess(const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *out, char **messages);
+/**
- Set a callback to be called when vkd3d-shader outputs debug logging.
- If NULL, or if this function has not been called, libvkd3d-shader will print
- all enabled log output to stderr.
- \param callback Callback function to set.
- \since 1.4
- */
+VKD3D_SHADER_API void vkd3d_shader_set_log_callback(PFN_vkd3d_log callback);
#endif /* VKD3D_SHADER_NO_PROTOTYPES */
/** Type of vkd3d_shader_get_version(). */
@@ -1859,6 +1871,9 @@ typedef void (*PFN_vkd3d_shader_free_shader_signature)(struct vkd3d_shader_signa typedef void (*PFN_vkd3d_shader_preprocess)(struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *out, char **messages);
+/** Type of vkd3d_shader_set_log_callback(). \since 1.4 */ +typedef void (*PFN_vkd3d_shader_set_log_callback)(PFN_vkd3d_log callback);
- #ifdef __cplusplus } #endif /* __cplusplus */
diff --git a/include/vkd3d_types.h b/include/vkd3d_types.h index 7014f4c25..4a7aca236 100644 --- a/include/vkd3d_types.h +++ b/include/vkd3d_types.h @@ -19,6 +19,8 @@ #ifndef __VKD3D_TYPES_H #define __VKD3D_TYPES_H
+#include <stdarg.h>
- #ifdef __cplusplus extern "C" { #endif /* __cplusplus */
@@ -53,6 +55,8 @@ enum vkd3d_result VKD3D_FORCE_32_BIT_ENUM(VKD3D_RESULT), };
+typedef void (*PFN_vkd3d_log)(const char *format, va_list args);
- #ifdef _WIN32 # define VKD3D_IMPORT __declspec(dllimport) # define VKD3D_EXPORT __declspec(dllexport)
diff --git a/libs/vkd3d-common/debug.c b/libs/vkd3d-common/debug.c index 4868f3fba..0b9e765ac 100644 --- a/libs/vkd3d-common/debug.c +++ b/libs/vkd3d-common/debug.c @@ -68,6 +68,25 @@ enum vkd3d_dbg_level vkd3d_dbg_get_level(void) return level; }
+static PFN_vkd3d_log log_callback;
+static void vkd3d_dbg_voutput(const char *fmt, va_list args) +{
- if (log_callback)
log_callback(fmt, args);
- else
vfprintf(stderr, fmt, args);
+}
+static void vkd3d_dbg_output(const char *fmt, ...) +{
- va_list args;
- va_start(args, fmt);
- vkd3d_dbg_voutput(fmt, args);
- va_end(args);
+}
- void vkd3d_dbg_printf(enum vkd3d_dbg_level level, const char *function, const char *fmt, ...) { va_list args;
@@ -77,12 +96,17 @@ void vkd3d_dbg_printf(enum vkd3d_dbg_level level, const char *function, const ch
assert(level < ARRAY_SIZE(debug_level_names));
- fprintf(stderr, "%s:%s: ", debug_level_names[level], function);
- vkd3d_dbg_output("%s:%s ", debug_level_names[level], function); va_start(args, fmt);
- vfprintf(stderr, fmt, args);
- vkd3d_dbg_voutput(fmt, args); va_end(args); }
+void vkd3d_dbg_set_log_callback(PFN_vkd3d_log callback) +{
- log_callback = callback;
+}
- static char *get_buffer(void) { static char buffers[VKD3D_DEBUG_BUFFER_COUNT][VKD3D_DEBUG_BUFFER_SIZE];
diff --git a/libs/vkd3d-shader/vkd3d_shader.map b/libs/vkd3d-shader/vkd3d_shader.map index 2e49fe248..cac96972a 100644 --- a/libs/vkd3d-shader/vkd3d_shader.map +++ b/libs/vkd3d-shader/vkd3d_shader.map @@ -17,6 +17,7 @@ global: vkd3d_shader_preprocess; vkd3d_shader_scan; vkd3d_shader_serialize_root_signature;
vkd3d_shader_set_log_callback;
local: *; };
diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index 6fd32435a..7d0157fca 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -1550,3 +1550,8 @@ int vkd3d_shader_preprocess(const struct vkd3d_shader_compile_info *compile_info vkd3d_shader_message_context_cleanup(&message_context); return ret; }
+void vkd3d_shader_set_log_callback(PFN_vkd3d_log callback) +{
- vkd3d_dbg_set_log_callback(callback);
+}