tgsi: allow dumping to a file directly

This commit is contained in:
Marek Olšák 2015-07-04 13:17:07 +02:00
parent d082c53249
commit 8141b4cee5
3 changed files with 23 additions and 8 deletions

View File

@ -48,6 +48,7 @@ struct dump_ctx
int indent;
uint indentation;
FILE *file;
void (*dump_printf)(struct dump_ctx *ctx, const char *format, ...);
};
@ -58,7 +59,10 @@ dump_ctx_printf(struct dump_ctx *ctx, const char *format, ...)
va_list ap;
(void)ctx;
va_start(ap, format);
_debug_vprintf(format, ap);
if (ctx->file)
vfprintf(ctx->file, format, ap);
else
_debug_vprintf(format, ap);
va_end(ap);
}
@ -659,9 +663,7 @@ prolog(
}
void
tgsi_dump(
const struct tgsi_token *tokens,
uint flags )
tgsi_dump_to_file(const struct tgsi_token *tokens, uint flags, FILE *file)
{
struct dump_ctx ctx;
@ -677,10 +679,17 @@ tgsi_dump(
ctx.indent = 0;
ctx.dump_printf = dump_ctx_printf;
ctx.indentation = 0;
ctx.file = file;
tgsi_iterate_shader( tokens, &ctx.iter );
}
void
tgsi_dump(const struct tgsi_token *tokens, uint flags)
{
tgsi_dump_to_file(tokens, flags, NULL);
}
struct str_dump_ctx
{
struct dump_ctx base;
@ -733,6 +742,7 @@ tgsi_dump_str(
ctx.base.indent = 0;
ctx.base.dump_printf = &str_dump_ctx_printf;
ctx.base.indentation = 0;
ctx.base.file = NULL;
ctx.str = str;
ctx.str[0] = 0;
@ -756,6 +766,7 @@ tgsi_dump_instruction_str(
ctx.base.indent = 0;
ctx.base.dump_printf = &str_dump_ctx_printf;
ctx.base.indentation = 0;
ctx.base.file = NULL;
ctx.str = str;
ctx.str[0] = 0;

View File

@ -32,6 +32,8 @@
#include "pipe/p_defines.h"
#include "pipe/p_shader_tokens.h"
#include <stdio.h>
#if defined __cplusplus
extern "C" {
#endif
@ -43,6 +45,9 @@ tgsi_dump_str(
char *str,
size_t size);
void
tgsi_dump_to_file(const struct tgsi_token *tokens, uint flags, FILE *file);
void
tgsi_dump(
const struct tgsi_token *tokens,

View File

@ -426,7 +426,6 @@ util_dump_clip_state(FILE *stream, const struct pipe_clip_state *state)
void
util_dump_shader_state(FILE *stream, const struct pipe_shader_state *state)
{
char str[8192];
unsigned i;
if(!state) {
@ -434,12 +433,12 @@ util_dump_shader_state(FILE *stream, const struct pipe_shader_state *state)
return;
}
tgsi_dump_str(state->tokens, 0, str, sizeof(str));
util_dump_struct_begin(stream, "pipe_shader_state");
util_dump_member_begin(stream, "tokens");
util_dump_string(stream, str);
fprintf(stream, "\"\n");
tgsi_dump_to_file(state->tokens, 0, stream);
fprintf(stream, "\"");
util_dump_member_end(stream);
util_dump_member_begin(stream, "stream_output");