intel/compiler: Add id parameter to shader_debug_log callback

There are two problems with the current architecture.

In OpenGL, the id is supposed to be a unique identifier for a particular
log source.  This is done so that applications can (theoretically)
filter particular log messages.  The debug callback infrastructure in
Mesa assigns a uniqe value when a value of 0 is passed in.  This causes
the id to get set once to a unique value for each message.

By passing a stack variable that is initialized to 0 on every call,
every time the same message is logged, it will have a different id.
This isn't great, but it's also not catastrophic.

When threaded shader compiles are used, the id *pointer* is saved and
dereferenced at a possibly much later time on a possibly different
thread.  This causes one thread to access the stack from a different
thread... and that stack frame might not be valid any more. :(

This fixes shader-db crashes of various kinds on Iris with threaded
shader compiles enabled.

Fixes: 42c34e1ac8 ("iris: Enable threaded shader compilation")
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12136>
This commit is contained in:
Ian Romanick
2021-07-29 14:13:27 -07:00
committed by Marge Bot
parent 80160a67ab
commit 043c5bf966
7 changed files with 33 additions and 31 deletions

View File

@@ -674,17 +674,16 @@ crocus_get_default_l3_config(const struct intel_device_info *devinfo,
}
static void
crocus_shader_debug_log(void *data, const char *fmt, ...)
crocus_shader_debug_log(void *data, unsigned *id, const char *fmt, ...)
{
struct pipe_debug_callback *dbg = data;
unsigned id = 0;
va_list args;
if (!dbg->debug_message)
return;
va_start(args, fmt);
dbg->debug_message(dbg->data, &id, PIPE_DEBUG_TYPE_SHADER_INFO, fmt, args);
dbg->debug_message(dbg->data, id, PIPE_DEBUG_TYPE_SHADER_INFO, fmt, args);
va_end(args);
}

View File

@@ -717,17 +717,16 @@ iris_get_default_l3_config(const struct intel_device_info *devinfo,
}
static void
iris_shader_debug_log(void *data, const char *fmt, ...)
iris_shader_debug_log(void *data, unsigned *id, const char *fmt, ...)
{
struct pipe_debug_callback *dbg = data;
unsigned id = 0;
va_list args;
if (!dbg->debug_message)
return;
va_start(args, fmt);
dbg->debug_message(dbg->data, &id, PIPE_DEBUG_TYPE_SHADER_INFO, fmt, args);
dbg->debug_message(dbg->data, id, PIPE_DEBUG_TYPE_SHADER_INFO, fmt, args);
va_end(args);
}

View File

@@ -69,7 +69,7 @@ struct brw_compiler {
struct ra_class *aligned_bary_class;
} fs_reg_sets[3];
void (*shader_debug_log)(void *, const char *str, ...) PRINTFLIKE(2, 3);
void (*shader_debug_log)(void *, unsigned *id, const char *str, ...) PRINTFLIKE(3, 4);
void (*shader_perf_log)(void *, const char *str, ...) PRINTFLIKE(2, 3);
bool scalar_stage[MESA_ALL_SHADER_STAGES];
@@ -121,6 +121,11 @@ struct brw_compiler {
bool indirect_ubos_use_sampler;
};
#define brw_shader_debug_log(compiler, data, fmt, ... ) do { \
static unsigned id = 0; \
compiler->shader_debug_log(data, &id, fmt, ##__VA_ARGS__); \
} while (0)
/**
* We use a constant subgroup size of 32. It really only needs to be a
* maximum and, since we do SIMD32 for compute shaders in some cases, it

View File

@@ -2794,7 +2794,7 @@ fs_generator::generate_code(const cfg_t *cfg, int dispatch_width,
#endif
assert(validated);
compiler->shader_debug_log(log_data,
brw_shader_debug_log(compiler, log_data,
"%s SIMD%d shader: %d inst, %d loops, %u cycles, "
"%d:%d spills:fills, %u sends, "
"scheduled with mode %s, "

View File

@@ -2263,7 +2263,7 @@ generate_code(struct brw_codegen *p,
ralloc_free(disasm_info);
assert(validated);
compiler->shader_debug_log(log_data,
brw_shader_debug_log(compiler, log_data,
"%s vec4 shader: %d inst, %d loops, %u cycles, "
"%d:%d spills:fills, %u sends, "
"compacted %d to %d bytes.",

View File

@@ -85,7 +85,7 @@ static const driOptionDescription anv_dri_options[] = {
#endif
static void
compiler_debug_log(void *data, const char *fmt, ...)
compiler_debug_log(void *data, UNUSED unsigned *id, const char *fmt, ...)
{
char str[MAX_DEBUG_MESSAGE_LENGTH];
struct anv_device *device = (struct anv_device *)data;

View File

@@ -2472,14 +2472,13 @@ set_max_gl_versions(struct brw_screen *screen)
}
static void
shader_debug_log_mesa(void *data, const char *fmt, ...)
shader_debug_log_mesa(void *data, unsigned *msg_id, const char *fmt, ...)
{
struct brw_context *brw = (struct brw_context *)data;
va_list args;
va_start(args, fmt);
GLuint msg_id = 0;
_mesa_gl_vdebugf(&brw->ctx, &msg_id,
_mesa_gl_vdebugf(&brw->ctx, msg_id,
MESA_DEBUG_SOURCE_SHADER_COMPILER,
MESA_DEBUG_TYPE_OTHER,
MESA_DEBUG_SEVERITY_NOTIFICATION, fmt, args);