Signed-off-by: Henri Verbeet hverbeet@codeweavers.com --- libs/vkd3d-shader/trace.c | 51 ++++++++++++++++++++++++++++---- libs/vkd3d-shader/vkd3d_shader_main.c | 2 +- libs/vkd3d-shader/vkd3d_shader_private.h | 3 +- 3 files changed, 49 insertions(+), 7 deletions(-)
diff --git a/libs/vkd3d-shader/trace.c b/libs/vkd3d-shader/trace.c index 18e80e59..fb5370ad 100644 --- a/libs/vkd3d-shader/trace.c +++ b/libs/vkd3d-shader/trace.c @@ -300,10 +300,17 @@ shader_input_sysval_semantic_names[] = {VKD3D_SIV_LINE_DENSITY_TESS_FACTOR, "finalLineDensityTessFactor"}, };
+struct vkd3d_d3d_asm_colours +{ + const char *reset; + const char *opcode; +}; + struct vkd3d_d3d_asm_compiler { struct vkd3d_string_buffer buffer; struct vkd3d_shader_version shader_version; + struct vkd3d_d3d_asm_colours colours; };
static int shader_ver_ge(const struct vkd3d_shader_version *v, int major, int minor) @@ -1334,7 +1341,8 @@ static void shader_dump_register_space(struct vkd3d_d3d_asm_compiler *compiler,
static void shader_print_opcode(struct vkd3d_d3d_asm_compiler *compiler, enum vkd3d_shader_opcode opcode) { - vkd3d_string_buffer_printf(&compiler->buffer, "%s", shader_opcode_names[opcode]); + vkd3d_string_buffer_printf(&compiler->buffer, "%s%s%s", compiler->colours.opcode, + shader_opcode_names[opcode], compiler->colours.reset); }
static void shader_dump_instruction(struct vkd3d_d3d_asm_compiler *compiler, @@ -1360,9 +1368,10 @@ static void shader_dump_instruction(struct vkd3d_d3d_asm_compiler *compiler, { case VKD3DSIH_DCL: case VKD3DSIH_DCL_UAV_TYPED: + vkd3d_string_buffer_printf(buffer, "%s", compiler->colours.opcode); shader_dump_decl_usage(compiler, &ins->declaration.semantic, ins->flags); shader_dump_ins_modifiers(compiler, &ins->declaration.semantic.resource.reg); - shader_addline(buffer, " "); + vkd3d_string_buffer_printf(buffer, "%s ", compiler->colours.reset); shader_dump_register(compiler, &ins->declaration.semantic.resource.reg.reg); shader_dump_register_space(compiler, ins->declaration.semantic.resource.register_space); break; @@ -1602,21 +1611,53 @@ static void shader_dump_instruction(struct vkd3d_d3d_asm_compiler *compiler, shader_addline(buffer, "\n"); }
-enum vkd3d_result vkd3d_dxbc_binary_to_text(void *data, struct vkd3d_shader_code *out) +enum vkd3d_result vkd3d_dxbc_binary_to_text(void *data, + const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *out) { + enum vkd3d_shader_compile_option_formatting_flags formatting; struct vkd3d_shader_version *shader_version; struct vkd3d_d3d_asm_compiler compiler; enum vkd3d_result result = VKD3D_OK; struct vkd3d_string_buffer *buffer; const DWORD *ptr; + unsigned int i; void *code;
+ static const struct vkd3d_d3d_asm_colours no_colours = + { + .reset = "", + .opcode = "", + }; + static const struct vkd3d_d3d_asm_colours colours = + { + .reset = "\x1b[m", + .opcode = "\x1b[96;1m", + }; + + formatting = VKD3D_SHADER_COMPILE_OPTION_FORMATTING_INDENT + | VKD3D_SHADER_COMPILE_OPTION_FORMATTING_HEADER; + if (compile_info) + { + for (i = 0; i < compile_info->option_count; ++i) + { + const struct vkd3d_shader_compile_option *option = &compile_info->options[i]; + + if (option->name == VKD3D_SHADER_COMPILE_OPTION_FORMATTING) + formatting = option->value; + } + } + + if (formatting & VKD3D_SHADER_COMPILE_OPTION_FORMATTING_COLOUR) + compiler.colours = colours; + else + compiler.colours = no_colours; + buffer = &compiler.buffer; vkd3d_string_buffer_init(buffer);
shader_version = &compiler.shader_version; shader_sm4_read_header(data, &ptr, shader_version); - vkd3d_string_buffer_printf(buffer, "%s_%u_%u\n", + vkd3d_string_buffer_printf(buffer, "%s%s_%u_%u\n", compiler.colours.reset, shader_get_type_prefix(shader_version->type), shader_version->major, shader_version->minor);
while (!shader_sm4_is_end(data, &ptr)) @@ -1656,7 +1697,7 @@ void vkd3d_shader_trace(void *data) const char *p, *q, *end; struct vkd3d_shader_code code;
- if (vkd3d_dxbc_binary_to_text(data, &code) != VKD3D_OK) + if (vkd3d_dxbc_binary_to_text(data, NULL, &code) != VKD3D_OK) return;
end = (const char *)code.code + code.size; diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index c1306cac..6f1482ab 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -920,7 +920,7 @@ static int compile_dxbc_tpf(const struct vkd3d_shader_compile_info *compile_info if (compile_info->target_type == VKD3D_SHADER_TARGET_D3D_ASM) { vkd3d_shader_free_scan_descriptor_info(&scan_descriptor_info); - ret = vkd3d_dxbc_binary_to_text(parser.data, out); + ret = vkd3d_dxbc_binary_to_text(parser.data, compile_info, out); vkd3d_shader_parser_destroy(&parser); return ret; } diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index 19758481..e9e10baf 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -851,7 +851,8 @@ struct vkd3d_string_buffer unsigned int content_size; };
-enum vkd3d_result vkd3d_dxbc_binary_to_text(void *data, struct vkd3d_shader_code *out) DECLSPEC_HIDDEN; +enum vkd3d_result vkd3d_dxbc_binary_to_text(void *data, + const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *out) DECLSPEC_HIDDEN; void vkd3d_string_buffer_cleanup(struct vkd3d_string_buffer *buffer) DECLSPEC_HIDDEN; void vkd3d_string_buffer_init(struct vkd3d_string_buffer *buffer) DECLSPEC_HIDDEN; int vkd3d_string_buffer_printf(struct vkd3d_string_buffer *buffer,