diff --git a/src/intel/vulkan/anv_blorp.c b/src/intel/vulkan/anv_blorp.c index 3eca84a0d84..f9b533e15c5 100644 --- a/src/intel/vulkan/anv_blorp.c +++ b/src/intel/vulkan/anv_blorp.c @@ -89,9 +89,14 @@ upload_blorp_shader(struct blorp_batch *batch, uint32_t stage, if (INTEL_DEBUG(DEBUG_SHADERS_LINENO)) { /* shader hash is zero in this context */ if (!intel_shader_dump_filter) { - brw_disassemble_with_lineno(&device->physical->compiler->isa, - stage, -1, 0, kernel, 0, - bin->kernel.offset, stderr); + FILE *out = mesa_log_file_streami(); + + if (out) { + brw_disassemble_with_lineno(&device->physical->compiler->isa, + stage, -1, 0, kernel, 0, + bin->kernel.offset, out); + fclose(out); + } } } diff --git a/src/util/log.c b/src/util/log.c index 4022b6b556e..4fbbac599e4 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -554,3 +554,77 @@ _mesa_log_multiline(enum mesa_log_level level, const char *tag, const char *line mesa_log_stream_flush(&tmp, 0); free(tmp.msg); } + +#if DETECT_OS_LINUX && !DETECT_OS_ANDROID +/* glibc-based Linux (has fopencookie) */ +static ssize_t +log_stream_write_cookie(void *cookie, const char *buf, size_t size) +{ + mesa_log_stream_printf(cookie, "%.*s", (int)size, buf); + + return size; +} + +static int +log_stream_close_cookie(void *cookie) +{ + mesa_log_stream_destroy(cookie); + + return 0; +} + +FILE * +mesa_log_stream_to_file(struct log_stream *stream) +{ + if (!stream) + return NULL; + + static const cookie_io_functions_t funcs = { + .read = NULL, + .write = log_stream_write_cookie, + .seek = NULL, + .close = log_stream_close_cookie + }; + + return fopencookie(stream, "w", funcs); +} +#elif DETECT_OS_ANDROID || DETECT_OS_APPLE || DETECT_OS_BSD +/* BSD-style (has funopen) */ +static int +log_stream_write_func(void *cookie, const char *buf, int size) +{ + mesa_log_stream_printf(cookie, "%.*s", size, buf); + + return size; +} + +static int +log_stream_close_func(void *cookie) +{ + mesa_log_stream_destroy(cookie); + + return 0; +} + +FILE * +mesa_log_stream_to_file(struct log_stream *stream) +{ + if (!stream) + return NULL; + + return funopen(stream, + NULL, /* read */ + log_stream_write_func, /* write */ + NULL, /* seek */ + log_stream_close_func); /* close */ +} + +#else +/* Unsupported platform */ +FILE * +mesa_log_stream_to_file(struct log_stream *stream) +{ + (void)stream; + return NULL; +} +#endif diff --git a/src/util/log.h b/src/util/log.h index c1d9f806232..cb0ea4c4962 100644 --- a/src/util/log.h +++ b/src/util/log.h @@ -129,6 +129,13 @@ static inline void PRINTFLIKE(1, 2) __mesa_log_use_args(UNUSED const char *format, ...) { } #endif +FILE * +mesa_log_stream_to_file(struct log_stream *stream); + +#define mesa_log_file_streame() mesa_log_stream_to_file(mesa_log_streame()) +#define mesa_log_file_streamw() mesa_log_stream_to_file(mesa_log_streamw()) +#define mesa_log_file_streami() mesa_log_stream_to_file(mesa_log_streami()) + #ifdef __cplusplus } #endif