util/mesa: move mesa/main log code to util

This removes the unrequired dependance on _mesa_init_debug() and moves
all log code to the util file so that _mesa_log* can now be used without
creating a dependance on mesa/main. Since the code we are moving depends
on the code already in the util (as it was moved here previously) this is
also a much better spot for the code.

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30012>
This commit is contained in:
Timothy Arceri
2024-07-03 19:08:10 +10:00
committed by Marge Bot
parent 6c4e03024c
commit 22bd26079f
5 changed files with 61 additions and 55 deletions

View File

@@ -34,6 +34,7 @@
#include "version.h"
#include "util/hash_table.h"
#include "util/list.h"
#include "util/log.h"
#include "util/u_memory.h"
#include "api_exec_decl.h"

View File

@@ -39,33 +39,6 @@
#include "util/log.h"
#include "api_exec_decl.h"
static void
output_if_debug(enum mesa_log_level level, const char *outputString)
{
static int debug = -1;
/* Init the local 'debug' var once.
* Note: the _mesa_init_debug() function should have been called
* by now so MESA_DEBUG_FLAGS will be initialized.
*/
if (debug == -1) {
#ifndef NDEBUG
/* in debug builds, print messages unless MESA_DEBUG="silent" */
if (MESA_DEBUG_FLAGS & DEBUG_SILENT)
debug = 0;
else
debug = 1;
#else
const char *env = getenv("MESA_DEBUG");
debug = env && strstr(env, "silent") == NULL;
#endif
}
/* Now only print the string if we're required to do so. */
if (debug)
mesa_log(level, "Mesa", "%s", outputString);
}
/**
* When a new type of error is recorded, print a message describing
* previous errors which were accumulated.
@@ -80,7 +53,7 @@ flush_delayed_errors( struct gl_context *ctx )
ctx->ErrorDebugCount,
_mesa_enum_to_string(ctx->ErrorValue));
output_if_debug(MESA_LOG_ERROR, s);
mesa_log_if_debug(MESA_LOG_ERROR, s);
ctx->ErrorDebugCount = 0;
}
@@ -106,7 +79,7 @@ _mesa_warning( struct gl_context *ctx, const char *fmtString, ... )
if (ctx)
flush_delayed_errors( ctx );
output_if_debug(MESA_LOG_WARN, str);
mesa_log_if_debug(MESA_LOG_WARN, str);
}
@@ -306,7 +279,7 @@ _mesa_error( struct gl_context *ctx, GLenum error, const char *fmtString, ... )
/* Print the error to stderr if needed. */
if (do_output) {
output_if_debug(MESA_LOG_ERROR, s2);
mesa_log_if_debug(MESA_LOG_ERROR, s2);
}
/* Log the error via ARB_debug_output if needed.*/
@@ -344,30 +317,12 @@ _mesa_debug( const struct gl_context *ctx, const char *fmtString, ... )
va_start(args, fmtString);
vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args);
va_end(args);
output_if_debug(MESA_LOG_DEBUG, s);
mesa_log_if_debug(MESA_LOG_DEBUG, s);
#endif /* !NDEBUG */
(void) ctx;
(void) fmtString;
}
void
_mesa_log(const char *fmtString, ...)
{
char s[MAX_DEBUG_MESSAGE_LENGTH];
va_list args;
va_start(args, fmtString);
vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args);
va_end(args);
output_if_debug(MESA_LOG_INFO, s);
}
void
_mesa_log_direct(const char *string)
{
output_if_debug(MESA_LOG_INFO, string);
}
/**
* Report debug information from the shader compiler via GL_ARB_debug_output.
*

View File

@@ -63,12 +63,6 @@ _mesa_error_no_memory(const char *caller);
extern void
_mesa_debug( const struct gl_context *ctx, const char *fmtString, ... ) PRINTFLIKE(2, 3);
extern void
_mesa_log(const char *fmtString, ...) PRINTFLIKE(1, 2);
extern void
_mesa_log_direct(const char *string);
void
_mesa_shader_debug(struct gl_context *ctx, GLenum type, GLuint *id,

View File

@@ -119,6 +119,34 @@ mesa_log_init(void)
call_once(&once, mesa_log_init_once);
}
void
mesa_log_if_debug(enum mesa_log_level level, const char *outputString)
{
static int debug = -1;
/* Init the local 'debug' var once. */
if (debug == -1) {
const char *env = getenv("MESA_DEBUG");
bool silent = env && strstr(env, "silent") != NULL;
#ifndef NDEBUG
/* in debug builds, print messages unless MESA_DEBUG="silent" */
if (silent)
debug = 0;
else
debug = 1;
#else
/* in release builds, print messages if any MESA_DEBUG value other than
* MESA_DEBUG="silent" is set
*/
debug = env && !silent;
#endif
}
/* Now only print the string if we're required to do so. */
if (debug)
mesa_log(level, "Mesa", "%s", outputString);
}
static inline const char *
level_to_str(enum mesa_log_level l)
{
@@ -387,6 +415,23 @@ mesa_log_v(enum mesa_log_level level, const char *tag, const char *format,
}
}
void
_mesa_log(const char *fmtString, ...)
{
char s[MAX_LOG_MESSAGE_LENGTH];
va_list args;
va_start(args, fmtString);
vsnprintf(s, MAX_LOG_MESSAGE_LENGTH, fmtString, args);
va_end(args);
mesa_log_if_debug(MESA_LOG_INFO, s);
}
void
_mesa_log_direct(const char *string)
{
mesa_log_if_debug(MESA_LOG_INFO, string);
}
struct log_stream *
_mesa_log_stream_create(enum mesa_log_level level, const char *tag)
{

View File

@@ -44,6 +44,8 @@ enum mesa_log_level {
MESA_LOG_DEBUG,
};
#define MAX_LOG_MESSAGE_LENGTH 4096
FILE *
mesa_log_get_file(void);
@@ -54,6 +56,15 @@ void
mesa_log_v(enum mesa_log_level, const char *tag, const char *format,
va_list va);
void
_mesa_log(const char *fmtString, ...) PRINTFLIKE(1, 2);
void
_mesa_log_direct(const char *string);
void
mesa_log_if_debug(enum mesa_log_level level, const char *outputString);
#define mesa_loge(fmt, ...) mesa_log(MESA_LOG_ERROR, (MESA_LOG_TAG), (fmt), ##__VA_ARGS__)
#define mesa_logw(fmt, ...) mesa_log(MESA_LOG_WARN, (MESA_LOG_TAG), (fmt), ##__VA_ARGS__)
#define mesa_logi(fmt, ...) mesa_log(MESA_LOG_INFO, (MESA_LOG_TAG), (fmt), ##__VA_ARGS__)