Mesa (main): dzn: add debug option to redirect stdout/stderr

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jun 1 09:07:10 UTC 2022


Module: Mesa
Branch: main
Commit: 8901df12ab0379ec30bc5ce12cf049ff11ceb3de
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8901df12ab0379ec30bc5ce12cf049ff11ceb3de

Author: Erik Faye-Lund <erik.faye-lund at collabora.com>
Date:   Thu May 19 14:47:31 2022 +0200

dzn: add debug option to redirect stdout/stderr

For applications that doesn't have a terminal, it's useful to get output
like nir_log etc output somewhere.

This outputs these to stderr.txt and stdout.txt in the current user's
home directory, typically in C:\Users\my-user\.

Acked-by: Boris Brezillon <boris.brezillon at collabora.com>
Acked-by: Jesse Natalie <jenatali at microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16640>

---

 src/microsoft/vulkan/dzn_device.c  | 12 ++++++++++++
 src/microsoft/vulkan/dzn_private.h |  1 +
 2 files changed, 13 insertions(+)

diff --git a/src/microsoft/vulkan/dzn_device.c b/src/microsoft/vulkan/dzn_device.c
index 941d0ddb77c..34f56078b09 100644
--- a/src/microsoft/vulkan/dzn_device.c
+++ b/src/microsoft/vulkan/dzn_device.c
@@ -43,6 +43,7 @@
 #include <stdlib.h>
 
 #include <windows.h>
+#include <shlobj.h>
 
 #include <directx/d3d12sdklayers.h>
 
@@ -111,6 +112,7 @@ static const struct debug_control dzn_debug_options[] = {
    { "gbv", DZN_DEBUG_GBV },
    { "d3d12", DZN_DEBUG_D3D12 },
    { "debugger", DZN_DEBUG_DEBUGGER },
+   { "redirects", DZN_DEBUG_REDIRECTS },
    { NULL, 0 }
 };
 
@@ -187,6 +189,16 @@ dzn_instance_create(const VkInstanceCreateInfo *pCreateInfo,
       }
    }
 
+   if (instance->debug_flags & DZN_DEBUG_REDIRECTS) {
+      char home[MAX_PATH], path[MAX_PATH];
+      if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_PROFILE, NULL, 0, home))) {
+         snprintf(path, sizeof(path), "%s\\stderr.txt", home);
+         freopen(path, "w", stderr);
+         snprintf(path, sizeof(path), "%s\\stdout.txt", home);
+         freopen(path, "w", stdout);
+      }
+   }
+
    instance->dxil_validator = dxil_create_validator(NULL);
    instance->d3d12.serialize_root_sig = d3d12_get_serialize_root_sig();
 
diff --git a/src/microsoft/vulkan/dzn_private.h b/src/microsoft/vulkan/dzn_private.h
index f9142fe389f..1d09e0a3251 100644
--- a/src/microsoft/vulkan/dzn_private.h
+++ b/src/microsoft/vulkan/dzn_private.h
@@ -921,6 +921,7 @@ enum dzn_debug_flags {
    DZN_DEBUG_GBV = 1 << 6,
    DZN_DEBUG_D3D12 = 1 << 7,
    DZN_DEBUG_DEBUGGER = 1 << 8,
+   DZN_DEBUG_REDIRECTS = 1 << 9,
 };
 
 struct dzn_instance {



More information about the mesa-commit mailing list