-- v2: vkd3d-shader/d3d-asm: Add an "internal" mode for the ASM dumper.
From: Giovanni Mascellani gmascellani@codeweavers.com
--- libs/vkd3d-shader/d3d_asm.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/libs/vkd3d-shader/d3d_asm.c b/libs/vkd3d-shader/d3d_asm.c index 82d1d71d9..9ddcf3612 100644 --- a/libs/vkd3d-shader/d3d_asm.c +++ b/libs/vkd3d-shader/d3d_asm.c @@ -2002,6 +2002,7 @@ enum vkd3d_result vkd3d_dxbc_binary_to_text(const struct vkd3d_shader_instructio { case VKD3DSIH_ELSE: case VKD3DSIH_IF: + case VKD3DSIH_IFC: case VKD3DSIH_LOOP: case VKD3DSIH_SWITCH: ++indent;
From: Giovanni Mascellani gmascellani@codeweavers.com
--- libs/vkd3d-shader/d3d_asm.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/libs/vkd3d-shader/d3d_asm.c b/libs/vkd3d-shader/d3d_asm.c index 9ddcf3612..aadaed2aa 100644 --- a/libs/vkd3d-shader/d3d_asm.c +++ b/libs/vkd3d-shader/d3d_asm.c @@ -606,7 +606,7 @@ static void shader_dump_resource_type(struct vkd3d_d3d_asm_compiler *compiler, e vkd3d_string_buffer_printf(&compiler->buffer, "unknown"); }
-static void shader_dump_data_type(struct vkd3d_d3d_asm_compiler *compiler, const enum vkd3d_data_type *type) +static void shader_dump_data_type(struct vkd3d_d3d_asm_compiler *compiler, enum vkd3d_data_type type) { static const char *const data_type_names[] = { @@ -624,18 +624,27 @@ static void shader_dump_data_type(struct vkd3d_d3d_asm_compiler *compiler, const [VKD3D_DATA_CONTINUED] = "<continued>", [VKD3D_DATA_UNUSED ] = "<unused>", }; + const char *name; + + if (type < ARRAY_SIZE(data_type_names)) + name = data_type_names[type]; + else + name = "unknown"; + + vkd3d_string_buffer_printf(&compiler->buffer, "%s", name); +} + +static void shader_dump_resource_data_type(struct vkd3d_d3d_asm_compiler *compiler, const enum vkd3d_data_type *type) +{ int i;
vkd3d_string_buffer_printf(&compiler->buffer, "(");
for (i = 0; i < 4; i++) { - if (type[i] < ARRAY_SIZE(data_type_names)) - name = data_type_names[type[i]]; - else - name = "unknown"; - vkd3d_string_buffer_printf(&compiler->buffer, "%s%s", i == 0 ? "" : ",", name); + vkd3d_string_buffer_printf(&compiler->buffer, "%s", i == 0 ? "" : ","); + shader_dump_data_type(compiler, type[i]); }
vkd3d_string_buffer_printf(&compiler->buffer, ")"); @@ -682,7 +691,7 @@ static void shader_dump_decl_usage(struct vkd3d_d3d_asm_compiler *compiler, if (semantic->resource.reg.reg.type == VKD3DSPR_UAV) shader_dump_uav_flags(compiler, flags); shader_addline(buffer, " "); - shader_dump_data_type(compiler, semantic->resource_data_type); + shader_dump_resource_data_type(compiler, semantic->resource_data_type); } else { @@ -1883,7 +1892,7 @@ static void shader_dump_instruction(struct vkd3d_d3d_asm_compiler *compiler, || ins->resource_data_type[1] != VKD3D_DATA_FLOAT || ins->resource_data_type[2] != VKD3D_DATA_FLOAT || ins->resource_data_type[3] != VKD3D_DATA_FLOAT) - shader_dump_data_type(compiler, ins->resource_data_type); + shader_dump_resource_data_type(compiler, ins->resource_data_type);
for (i = 0; i < ins->dst_count; ++i) {
From: Giovanni Mascellani gmascellani@codeweavers.com
--- libs/vkd3d-shader/d3d_asm.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/libs/vkd3d-shader/d3d_asm.c b/libs/vkd3d-shader/d3d_asm.c index aadaed2aa..63fb7bb30 100644 --- a/libs/vkd3d-shader/d3d_asm.c +++ b/libs/vkd3d-shader/d3d_asm.c @@ -623,6 +623,9 @@ static void shader_dump_data_type(struct vkd3d_d3d_asm_compiler *compiler, enum [VKD3D_DATA_DOUBLE ] = "double", [VKD3D_DATA_CONTINUED] = "<continued>", [VKD3D_DATA_UNUSED ] = "<unused>", + [VKD3D_DATA_UINT8 ] = "uint8", + [VKD3D_DATA_UINT64 ] = "uint64", + [VKD3D_DATA_BOOL ] = "bool", };
const char *name;
From: Giovanni Mascellani gmascellani@codeweavers.com
In analogy with "<continued>" and "<unused>". --- libs/vkd3d-shader/d3d_asm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/d3d_asm.c b/libs/vkd3d-shader/d3d_asm.c index 63fb7bb30..132427d45 100644 --- a/libs/vkd3d-shader/d3d_asm.c +++ b/libs/vkd3d-shader/d3d_asm.c @@ -633,7 +633,7 @@ static void shader_dump_data_type(struct vkd3d_d3d_asm_compiler *compiler, enum if (type < ARRAY_SIZE(data_type_names)) name = data_type_names[type]; else - name = "unknown"; + name = "<unknown>";
vkd3d_string_buffer_printf(&compiler->buffer, "%s", name); }
From: Giovanni Mascellani gmascellani@codeweavers.com
The new mode exposes more details about what's going on inside the VSIR code and it's meant to ease development and debugging. --- libs/vkd3d-shader/d3d_asm.c | 38 ++++++++++++++++++++++-- libs/vkd3d-shader/vkd3d_shader_main.c | 4 +-- libs/vkd3d-shader/vkd3d_shader_private.h | 8 ++++- 3 files changed, 44 insertions(+), 6 deletions(-)
diff --git a/libs/vkd3d-shader/d3d_asm.c b/libs/vkd3d-shader/d3d_asm.c index 132427d45..2a33d95e8 100644 --- a/libs/vkd3d-shader/d3d_asm.c +++ b/libs/vkd3d-shader/d3d_asm.c @@ -364,6 +364,7 @@ struct vkd3d_d3d_asm_compiler struct vkd3d_string_buffer buffer; struct vkd3d_shader_version shader_version; 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, ...) @@ -1277,6 +1278,32 @@ static void shader_print_non_uniform(struct vkd3d_d3d_asm_compiler *compiler, co 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, 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, ¶m->reg); shader_print_non_uniform(compiler, ¶m->reg); + shader_dump_reg_type(compiler, ¶m->reg); }
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, ¶m->reg); shader_print_non_uniform(compiler, ¶m->reg); + shader_dump_reg_type(compiler, ¶m->reg); }
static void shader_dump_ins_modifiers(struct vkd3d_d3d_asm_compiler *compiler, @@ -1918,10 +1947,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, 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; - struct vkd3d_d3d_asm_compiler compiler; + struct vkd3d_d3d_asm_compiler compiler = + { + .dialect = dialect, + }; enum vkd3d_result result = VKD3D_OK; struct vkd3d_string_buffer *buffer; unsigned int indent, i, j; @@ -2047,7 +2079,7 @@ void vkd3d_shader_trace(const struct vkd3d_shader_instruction_array *instruction const char *p, *q, *end; 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;
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 77164c9c9..85fbf3336 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -1549,7 +1549,7 @@ static int vkd3d_shader_parser_compile(struct vkd3d_shader_parser *parser, switch (compile_info->target_type) { 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;
case VKD3D_SHADER_TARGET_GLSL: @@ -1626,7 +1626,7 @@ static int compile_d3d_bytecode(const struct vkd3d_shader_compile_info *compile_
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); return ret; } diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index d3989672b..43c1e1a22 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -1306,9 +1306,15 @@ struct vkd3d_string_buffer_cache 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, 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); struct vkd3d_string_buffer *vkd3d_string_buffer_get(struct vkd3d_string_buffer_cache *list); void vkd3d_string_buffer_init(struct vkd3d_string_buffer *buffer);
On Mon Dec 4 12:31:17 2023 +0000, Henri Verbeet wrote:
There are probably a few details to fix, like handling colors and
possibly coming up with a better format for types, but in the meantime what do you think about the general idea? Seems fine to me; we may even be able to fix the parameter order for the internal variant. ;) I'd probably try to avoid the bool "internal" flag though, and use a dialect/variant enum instead. E.g. VSIR_ASM_D3D and VSIR_ASM_VSIR.
Done. I also tweaked the representation so it's a bit more compact.