asahi: Add a helper macro for debug/error messages
authorAsahi Lina <lina@asahilina.net>
Wed, 5 Apr 2023 06:39:46 +0000 (15:39 +0900)
committerMarge Bot <emma+marge@anholt.net>
Fri, 7 Apr 2023 03:23:04 +0000 (03:23 +0000)
This includes the program short name in the message, which is useful
when running entire desktop sessions with a single log to figure out who
is doing what.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22353>

src/gallium/drivers/asahi/agx_fence.c
src/gallium/drivers/asahi/agx_pipe.c
src/gallium/drivers/asahi/agx_state.c
src/gallium/drivers/asahi/agx_state.h

index ad8e281..6cb16f6 100644 (file)
@@ -82,20 +82,20 @@ agx_fence_from_fd(struct agx_context *ctx, int fd, enum pipe_fd_type type)
    if (type == PIPE_FD_TYPE_NATIVE_SYNC) {
       ret = drmSyncobjCreate(dev->fd, 0, &f->syncobj);
       if (ret) {
-         fprintf(stderr, "create syncobj failed\n");
+         agx_msg("create syncobj failed\n");
          goto err_free_fence;
       }
 
       ret = drmSyncobjImportSyncFile(dev->fd, f->syncobj, fd);
       if (ret) {
-         fprintf(stderr, "import syncfile failed\n");
+         agx_msg("import syncfile failed\n");
          goto err_destroy_syncobj;
       }
    } else {
       assert(type == PIPE_FD_TYPE_SYNCOBJ);
       ret = drmSyncobjFDToHandle(dev->fd, fd, &f->syncobj);
       if (ret) {
-         fprintf(stderr, "import syncobj FD failed\n");
+         agx_msg("import syncobj FD failed\n");
          goto err_free_fence;
       }
    }
@@ -125,7 +125,7 @@ agx_fence_create(struct agx_context *ctx)
    ret = drmSyncobjExportSyncFile(dev->fd, ctx->syncobj, &fd);
    assert(ret >= 0 && fd != -1 && "export failed");
    if (ret || fd == -1) {
-      fprintf(stderr, "export failed\n");
+      agx_msg("export failed\n");
       return NULL;
    }
 
index 18d7270..fb2e00a 100644 (file)
@@ -474,7 +474,7 @@ agx_resource_create_with_modifiers(struct pipe_screen *screen,
          renderonly_scanout_for_resource(&scanout_tmpl, dev->ro, &handle);
 
       if (!nresource->scanout) {
-         fprintf(stderr, "Failed to create scanout resource\n");
+         agx_msg("Failed to create scanout resource\n");
          free(nresource);
          return NULL;
       }
@@ -1963,10 +1963,10 @@ agx_screen_create(int fd, struct renderonly *ro, struct sw_winsys *winsys)
       static bool warned_about_hacks = false;
 
       if (!warned_about_hacks) {
-         fprintf(stderr, "\n------------------\n"
-                         "Unsupported debug parameter set. Expect breakage.\n"
-                         "Do not report bugs.\n"
-                         "------------------\n\n");
+         agx_msg("\n------------------\n"
+                 "Unsupported debug parameter set. Expect breakage.\n"
+                 "Do not report bugs.\n"
+                 "------------------\n\n");
          warned_about_hacks = true;
       }
    }
index b3be212..52eba19 100644 (file)
@@ -379,8 +379,8 @@ agx_create_rs_state(struct pipe_context *ctx,
     * implementation lowers to multiple draws with culling. Warn.
     */
    if (unlikely(cso->fill_front != cso->fill_back)) {
-      fprintf(stderr, "Warning: Two-sided fill modes are unsupported, "
-                      "rendering may be incorrect.\n");
+      agx_msg("Warning: Two-sided fill modes are unsupported, "
+              "rendering may be incorrect.\n");
    }
 
    so->polygon_mode = agx_translate_polygon_mode(cso->fill_front);
index cc2a5d8..74afda3 100644 (file)
 #include "util/u_range.h"
 #include "agx_meta.h"
 
+#ifdef __GLIBC__
+#include <errno.h>
+#define agx_msg(fmt, ...)                                                      \
+   fprintf(stderr, "[%s] " fmt, program_invocation_short_name, ##__VA_ARGS__)
+#else
+#define agx_msg(...) fprintf(stderr, __VA_ARGS)
+#endif
+
 struct agx_streamout_target {
    struct pipe_stream_output_target base;
    uint32_t offset;