vkd3d-shader/d3d-asm: Add an "internal" mode for the ASM dumper.

The new mode exposes more details about what's going on inside the VSIR
code and it's meant to ease development and debugging.
This commit is contained in:
Giovanni Mascellani 2023-11-30 12:09:04 +01:00 committed by Alexandre Julliard
parent e7fdf2e97f
commit 1015cc952e
Notes: Alexandre Julliard 2023-12-12 23:17:24 +01:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/502
3 changed files with 44 additions and 6 deletions

View File

@ -364,6 +364,7 @@ struct vkd3d_d3d_asm_compiler
struct vkd3d_string_buffer buffer; struct vkd3d_string_buffer buffer;
struct vkd3d_shader_version shader_version; struct vkd3d_shader_version shader_version;
struct vkd3d_d3d_asm_colours colours; struct vkd3d_d3d_asm_colours colours;
enum vsir_asm_dialect dialect;
}; };
static int VKD3D_PRINTF_FUNC(2, 3) shader_addline(struct vkd3d_string_buffer *buffer, const char *format, ...) static int VKD3D_PRINTF_FUNC(2, 3) shader_addline(struct vkd3d_string_buffer *buffer, const char *format, ...)
@ -1277,6 +1278,32 @@ static void shader_print_non_uniform(struct vkd3d_d3d_asm_compiler *compiler, co
compiler->colours.modifier, compiler->colours.reset); compiler->colours.modifier, compiler->colours.reset);
} }
static void shader_dump_reg_type(struct vkd3d_d3d_asm_compiler *compiler,
const struct vkd3d_shader_register *reg)
{
static const char *dimensions[] =
{
[VSIR_DIMENSION_NONE] = "",
[VSIR_DIMENSION_SCALAR] = "s:",
[VSIR_DIMENSION_VEC4] = "v4:",
};
struct vkd3d_string_buffer *buffer = &compiler->buffer;
const char *dimension;
if (compiler->dialect != VSIR_ASM_VSIR)
return;
if (reg->dimension < ARRAY_SIZE(dimensions))
dimension = dimensions[reg->dimension];
else
dimension = "??";
shader_addline(buffer, " <%s", dimension);
shader_dump_data_type(compiler, reg->data_type);
shader_addline(buffer, ">");
}
static void shader_dump_dst_param(struct vkd3d_d3d_asm_compiler *compiler, static void shader_dump_dst_param(struct vkd3d_d3d_asm_compiler *compiler,
const struct vkd3d_shader_dst_param *param, bool is_declaration) const struct vkd3d_shader_dst_param *param, bool is_declaration)
{ {
@ -1306,6 +1333,7 @@ static void shader_dump_dst_param(struct vkd3d_d3d_asm_compiler *compiler,
shader_print_precision(compiler, &param->reg); shader_print_precision(compiler, &param->reg);
shader_print_non_uniform(compiler, &param->reg); shader_print_non_uniform(compiler, &param->reg);
shader_dump_reg_type(compiler, &param->reg);
} }
static void shader_dump_src_param(struct vkd3d_d3d_asm_compiler *compiler, static void shader_dump_src_param(struct vkd3d_d3d_asm_compiler *compiler,
@ -1379,6 +1407,7 @@ static void shader_dump_src_param(struct vkd3d_d3d_asm_compiler *compiler,
shader_print_precision(compiler, &param->reg); shader_print_precision(compiler, &param->reg);
shader_print_non_uniform(compiler, &param->reg); shader_print_non_uniform(compiler, &param->reg);
shader_dump_reg_type(compiler, &param->reg);
} }
static void shader_dump_ins_modifiers(struct vkd3d_d3d_asm_compiler *compiler, static void shader_dump_ins_modifiers(struct vkd3d_d3d_asm_compiler *compiler,
@ -1924,10 +1953,13 @@ static void shader_dump_instruction(struct vkd3d_d3d_asm_compiler *compiler,
enum vkd3d_result vkd3d_dxbc_binary_to_text(const struct vkd3d_shader_instruction_array *instructions, enum vkd3d_result vkd3d_dxbc_binary_to_text(const struct vkd3d_shader_instruction_array *instructions,
const struct vkd3d_shader_version *shader_version, const struct vkd3d_shader_compile_info *compile_info, const struct vkd3d_shader_version *shader_version, const struct vkd3d_shader_compile_info *compile_info,
struct vkd3d_shader_code *out) struct vkd3d_shader_code *out, enum vsir_asm_dialect dialect)
{ {
enum vkd3d_shader_compile_option_formatting_flags formatting; enum vkd3d_shader_compile_option_formatting_flags formatting;
struct vkd3d_d3d_asm_compiler compiler; struct vkd3d_d3d_asm_compiler compiler =
{
.dialect = dialect,
};
enum vkd3d_result result = VKD3D_OK; enum vkd3d_result result = VKD3D_OK;
struct vkd3d_string_buffer *buffer; struct vkd3d_string_buffer *buffer;
unsigned int indent, i, j; unsigned int indent, i, j;
@ -2053,7 +2085,7 @@ void vkd3d_shader_trace(const struct vkd3d_shader_instruction_array *instruction
const char *p, *q, *end; const char *p, *q, *end;
struct vkd3d_shader_code code; struct vkd3d_shader_code code;
if (vkd3d_dxbc_binary_to_text(instructions, shader_version, NULL, &code) != VKD3D_OK) if (vkd3d_dxbc_binary_to_text(instructions, shader_version, NULL, &code, VSIR_ASM_VSIR) != VKD3D_OK)
return; return;
end = (const char *)code.code + code.size; end = (const char *)code.code + code.size;

View File

@ -1546,7 +1546,7 @@ static int vkd3d_shader_parser_compile(struct vkd3d_shader_parser *parser,
switch (compile_info->target_type) switch (compile_info->target_type)
{ {
case VKD3D_SHADER_TARGET_D3D_ASM: case VKD3D_SHADER_TARGET_D3D_ASM:
ret = vkd3d_dxbc_binary_to_text(&parser->instructions, &parser->shader_version, compile_info, out); ret = vkd3d_dxbc_binary_to_text(&parser->instructions, &parser->shader_version, compile_info, out, VSIR_ASM_D3D);
break; break;
case VKD3D_SHADER_TARGET_GLSL: case VKD3D_SHADER_TARGET_GLSL:
@ -1623,7 +1623,7 @@ static int compile_d3d_bytecode(const struct vkd3d_shader_compile_info *compile_
if (compile_info->target_type == VKD3D_SHADER_TARGET_D3D_ASM) if (compile_info->target_type == VKD3D_SHADER_TARGET_D3D_ASM)
{ {
ret = vkd3d_dxbc_binary_to_text(&parser->instructions, &parser->shader_version, compile_info, out); ret = vkd3d_dxbc_binary_to_text(&parser->instructions, &parser->shader_version, compile_info, out, VSIR_ASM_D3D);
vkd3d_shader_parser_destroy(parser); vkd3d_shader_parser_destroy(parser);
return ret; return ret;
} }

View File

@ -1315,9 +1315,15 @@ struct vkd3d_string_buffer_cache
size_t count, max_count, capacity; size_t count, max_count, capacity;
}; };
enum vsir_asm_dialect
{
VSIR_ASM_VSIR,
VSIR_ASM_D3D,
};
enum vkd3d_result vkd3d_dxbc_binary_to_text(const struct vkd3d_shader_instruction_array *instructions, enum vkd3d_result vkd3d_dxbc_binary_to_text(const struct vkd3d_shader_instruction_array *instructions,
const struct vkd3d_shader_version *shader_version, const struct vkd3d_shader_compile_info *compile_info, const struct vkd3d_shader_version *shader_version, const struct vkd3d_shader_compile_info *compile_info,
struct vkd3d_shader_code *out); struct vkd3d_shader_code *out, enum vsir_asm_dialect dialect);
void vkd3d_string_buffer_cleanup(struct vkd3d_string_buffer *buffer); void vkd3d_string_buffer_cleanup(struct vkd3d_string_buffer *buffer);
struct vkd3d_string_buffer *vkd3d_string_buffer_get(struct vkd3d_string_buffer_cache *list); struct vkd3d_string_buffer *vkd3d_string_buffer_get(struct vkd3d_string_buffer_cache *list);
void vkd3d_string_buffer_init(struct vkd3d_string_buffer *buffer); void vkd3d_string_buffer_init(struct vkd3d_string_buffer *buffer);