vkd3d-shader/ir: Store code block names in struct vkd3d_shader_desc.

This commit is contained in:
Conor McCarthy 2023-11-08 13:14:01 +10:00 committed by Alexandre Julliard
parent ffc65215ba
commit 37d9dba512
Notes: Alexandre Julliard 2024-01-17 22:42:55 +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/450
4 changed files with 74 additions and 0 deletions

View File

@ -552,9 +552,14 @@ static int shdr_handler(const struct vkd3d_shader_dxbc_section_desc *section,
void free_shader_desc(struct vkd3d_shader_desc *desc) void free_shader_desc(struct vkd3d_shader_desc *desc)
{ {
size_t i;
shader_signature_cleanup(&desc->input_signature); shader_signature_cleanup(&desc->input_signature);
shader_signature_cleanup(&desc->output_signature); shader_signature_cleanup(&desc->output_signature);
shader_signature_cleanup(&desc->patch_constant_signature); shader_signature_cleanup(&desc->patch_constant_signature);
for (i = 0; i < desc->block_name_count; ++i)
vkd3d_free((void *)desc->block_names[i]);
vkd3d_free(desc->block_names);
} }
int shader_extract_from_dxbc(const struct vkd3d_shader_code *dxbc, int shader_extract_from_dxbc(const struct vkd3d_shader_code *dxbc,

View File

@ -1511,6 +1511,7 @@ static enum vkd3d_result normalise_combined_samplers(struct vkd3d_shader_parser
struct cf_flattener_if_info struct cf_flattener_if_info
{ {
struct vkd3d_shader_src_param *false_param; struct vkd3d_shader_src_param *false_param;
unsigned int id;
uint32_t merge_block_id; uint32_t merge_block_id;
unsigned int else_block_id; unsigned int else_block_id;
}; };
@ -1532,6 +1533,7 @@ struct cf_flattener_switch_info
{ {
size_t ins_location; size_t ins_location;
const struct vkd3d_shader_src_param *condition; const struct vkd3d_shader_src_param *condition;
unsigned int id;
unsigned int merge_block_id; unsigned int merge_block_id;
unsigned int default_block_id; unsigned int default_block_id;
struct cf_flattener_switch_case *cases; struct cf_flattener_switch_case *cases;
@ -1569,6 +1571,13 @@ struct cf_flattener
size_t instruction_count; size_t instruction_count;
unsigned int block_id; unsigned int block_id;
const char **block_names;
size_t block_name_capacity;
size_t block_name_count;
unsigned int branch_id;
unsigned int loop_id;
unsigned int switch_id;
unsigned int control_flow_depth; unsigned int control_flow_depth;
struct cf_flattener_info *control_flow_info; struct cf_flattener_info *control_flow_info;
@ -1751,6 +1760,31 @@ static struct cf_flattener_info *cf_flattener_find_innermost_breakable_cf_constr
return NULL; return NULL;
} }
static void VKD3D_PRINTF_FUNC(3, 4) cf_flattener_create_block_name(struct cf_flattener *flattener,
unsigned int block_id, const char *fmt, ...)
{
struct vkd3d_string_buffer buffer;
size_t block_name_count;
va_list args;
--block_id;
block_name_count = max(flattener->block_name_count, block_id + 1);
if (!vkd3d_array_reserve((void **)&flattener->block_names, &flattener->block_name_capacity,
block_name_count, sizeof(*flattener->block_names)))
return;
memset(&flattener->block_names[flattener->block_name_count], 0,
(block_name_count - flattener->block_name_count) * sizeof(*flattener->block_names));
flattener->block_name_count = block_name_count;
vkd3d_string_buffer_init(&buffer);
va_start(args, fmt);
vkd3d_string_buffer_vprintf(&buffer, fmt, args);
va_end(args);
flattener->block_names[block_id] = buffer.buffer;
}
static enum vkd3d_result cf_flattener_iterate_instruction_array(struct cf_flattener *flattener) static enum vkd3d_result cf_flattener_iterate_instruction_array(struct cf_flattener *flattener)
{ {
struct vkd3d_shader_parser *parser = flattener->parser; struct vkd3d_shader_parser *parser = flattener->parser;
@ -1797,10 +1831,15 @@ static enum vkd3d_result cf_flattener_iterate_instruction_array(struct cf_flatte
cf_flattener_emit_label(flattener, true_block_id); cf_flattener_emit_label(flattener, true_block_id);
cf_info->u.if_.id = flattener->branch_id;
cf_info->u.if_.merge_block_id = merge_block_id; cf_info->u.if_.merge_block_id = merge_block_id;
cf_info->u.if_.else_block_id = 0; cf_info->u.if_.else_block_id = 0;
cf_info->inside_block = true; cf_info->inside_block = true;
cf_info->current_block = VKD3D_BLOCK_IF; cf_info->current_block = VKD3D_BLOCK_IF;
cf_flattener_create_block_name(flattener, merge_block_id, "branch%u_merge", flattener->branch_id);
cf_flattener_create_block_name(flattener, true_block_id, "branch%u_true", flattener->branch_id);
++flattener->branch_id;
break; break;
case VKD3DSIH_ELSE: case VKD3DSIH_ELSE:
@ -1810,6 +1849,8 @@ static enum vkd3d_result cf_flattener_iterate_instruction_array(struct cf_flatte
cf_info->u.if_.else_block_id = cf_flattener_alloc_block_id(flattener); cf_info->u.if_.else_block_id = cf_flattener_alloc_block_id(flattener);
cf_info->u.if_.false_param->reg.idx[0].offset = cf_info->u.if_.else_block_id; cf_info->u.if_.false_param->reg.idx[0].offset = cf_info->u.if_.else_block_id;
cf_flattener_create_block_name(flattener,
cf_info->u.if_.else_block_id, "branch%u_false", cf_info->u.if_.id);
cf_flattener_emit_label(flattener, cf_info->u.if_.else_block_id); cf_flattener_emit_label(flattener, cf_info->u.if_.else_block_id);
cf_info->inside_block = true; cf_info->inside_block = true;
@ -1845,6 +1886,12 @@ static enum vkd3d_result cf_flattener_iterate_instruction_array(struct cf_flatte
cf_info->u.loop.merge_block_id = merge_block_id; cf_info->u.loop.merge_block_id = merge_block_id;
cf_info->current_block = VKD3D_BLOCK_LOOP; cf_info->current_block = VKD3D_BLOCK_LOOP;
cf_info->inside_block = true; cf_info->inside_block = true;
cf_flattener_create_block_name(flattener, loop_header_block_id, "loop%u_header", flattener->loop_id);
cf_flattener_create_block_name(flattener, loop_body_block_id, "loop%u_body", flattener->loop_id);
cf_flattener_create_block_name(flattener, continue_block_id, "loop%u_continue", flattener->loop_id);
cf_flattener_create_block_name(flattener, merge_block_id, "loop%u_merge", flattener->loop_id);
++flattener->loop_id;
break; break;
case VKD3DSIH_ENDLOOP: case VKD3DSIH_ENDLOOP:
@ -1872,6 +1919,7 @@ static enum vkd3d_result cf_flattener_iterate_instruction_array(struct cf_flatte
vsir_instruction_init(dst_ins, &instruction->location, VKD3DSIH_SWITCH_MONOLITHIC); vsir_instruction_init(dst_ins, &instruction->location, VKD3DSIH_SWITCH_MONOLITHIC);
++flattener->instruction_count; ++flattener->instruction_count;
cf_info->u.switch_.id = flattener->switch_id;
cf_info->u.switch_.merge_block_id = merge_block_id; cf_info->u.switch_.merge_block_id = merge_block_id;
cf_info->u.switch_.cases = NULL; cf_info->u.switch_.cases = NULL;
cf_info->u.switch_.cases_size = 0; cf_info->u.switch_.cases_size = 0;
@ -1880,6 +1928,9 @@ static enum vkd3d_result cf_flattener_iterate_instruction_array(struct cf_flatte
cf_info->inside_block = false; cf_info->inside_block = false;
cf_info->current_block = VKD3D_BLOCK_SWITCH; cf_info->current_block = VKD3D_BLOCK_SWITCH;
cf_flattener_create_block_name(flattener, merge_block_id, "switch%u_merge", flattener->switch_id);
++flattener->switch_id;
if (!vkd3d_array_reserve((void **)&cf_info->u.switch_.cases, &cf_info->u.switch_.cases_size, if (!vkd3d_array_reserve((void **)&cf_info->u.switch_.cases, &cf_info->u.switch_.cases_size,
10, sizeof(*cf_info->u.switch_.cases))) 10, sizeof(*cf_info->u.switch_.cases)))
return VKD3D_ERROR_OUT_OF_MEMORY; return VKD3D_ERROR_OUT_OF_MEMORY;
@ -1946,6 +1997,7 @@ static enum vkd3d_result cf_flattener_iterate_instruction_array(struct cf_flatte
++cf_info->u.switch_.cases_count; ++cf_info->u.switch_.cases_count;
cf_flattener_emit_label(flattener, label_id); cf_flattener_emit_label(flattener, label_id);
cf_flattener_create_block_name(flattener, label_id, "switch%u_case%u", cf_info->u.switch_.id, value);
cf_info->inside_block = true; cf_info->inside_block = true;
break; break;
} }
@ -1956,6 +2008,9 @@ static enum vkd3d_result cf_flattener_iterate_instruction_array(struct cf_flatte
cf_flattener_emit_unconditional_branch(flattener, cf_info->u.switch_.default_block_id); cf_flattener_emit_unconditional_branch(flattener, cf_info->u.switch_.default_block_id);
cf_flattener_emit_label(flattener, cf_info->u.switch_.default_block_id); cf_flattener_emit_label(flattener, cf_info->u.switch_.default_block_id);
cf_flattener_create_block_name(flattener, cf_info->u.switch_.default_block_id,
"switch%u_default", cf_info->u.switch_.id);
cf_info->inside_block = true; cf_info->inside_block = true;
break; break;
@ -2078,6 +2133,9 @@ static enum vkd3d_result flatten_control_flow_constructs(struct vkd3d_shader_par
} }
vkd3d_free(flattener.control_flow_info); vkd3d_free(flattener.control_flow_info);
/* Simpler to always free these in free_shader_desc(). */
parser->shader_desc.block_names = flattener.block_names;
parser->shader_desc.block_name_count = flattener.block_name_count;
return result; return result;
} }

View File

@ -2358,6 +2358,8 @@ struct spirv_compiler
uint32_t *block_label_ids; uint32_t *block_label_ids;
unsigned int block_count; unsigned int block_count;
const char **block_names;
size_t block_name_count;
}; };
static bool is_in_default_phase(const struct spirv_compiler *compiler) static bool is_in_default_phase(const struct spirv_compiler *compiler)
@ -7576,6 +7578,10 @@ static void spirv_compiler_emit_label(struct spirv_compiler *compiler,
label_id = spirv_compiler_get_label_id(compiler, block_id); label_id = spirv_compiler_get_label_id(compiler, block_id);
vkd3d_spirv_build_op_label(builder, label_id); vkd3d_spirv_build_op_label(builder, label_id);
--block_id;
if (block_id < compiler->block_name_count && compiler->block_names[block_id])
vkd3d_spirv_build_op_name(builder, label_id, compiler->block_names[block_id]);
} }
static void spirv_compiler_emit_merge(struct spirv_compiler *compiler, static void spirv_compiler_emit_merge(struct spirv_compiler *compiler,
@ -9671,6 +9677,8 @@ static int spirv_compiler_generate_spirv(struct spirv_compiler *compiler,
memset(&shader_desc->output_signature, 0, sizeof(shader_desc->output_signature)); memset(&shader_desc->output_signature, 0, sizeof(shader_desc->output_signature));
memset(&shader_desc->patch_constant_signature, 0, sizeof(shader_desc->patch_constant_signature)); memset(&shader_desc->patch_constant_signature, 0, sizeof(shader_desc->patch_constant_signature));
compiler->use_vocp = parser->shader_desc.use_vocp; compiler->use_vocp = parser->shader_desc.use_vocp;
compiler->block_names = parser->shader_desc.block_names;
compiler->block_name_count = parser->shader_desc.block_name_count;
compiler->input_control_point_count = shader_desc->input_control_point_count; compiler->input_control_point_count = shader_desc->input_control_point_count;
compiler->output_control_point_count = shader_desc->output_control_point_count; compiler->output_control_point_count = shader_desc->output_control_point_count;

View File

@ -1026,6 +1026,9 @@ struct vkd3d_shader_desc
} flat_constant_count[3]; } flat_constant_count[3];
bool use_vocp; bool use_vocp;
const char **block_names;
size_t block_name_count;
}; };
struct vkd3d_shader_register_semantic struct vkd3d_shader_register_semantic