mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-12-15 08:03:30 -08:00
vkd3d-shader/ir: Execute PHI SSA to TEMP materialization in a single pass.
This commit is contained in:
committed by
Henri Verbeet
parent
fc84f80c96
commit
f9c71d5775
Notes:
Henri Verbeet
2025-09-30 17:26:34 +02:00
Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1760
@@ -4759,17 +4759,13 @@ static enum vkd3d_result vsir_program_materialise_phi_ssas_to_temps(struct vsir_
|
|||||||
{
|
{
|
||||||
struct vsir_program_iterator it = vsir_program_iterator(&program->instructions);
|
struct vsir_program_iterator it = vsir_program_iterator(&program->instructions);
|
||||||
struct ssas_to_temps_block_info *info, *block_info = NULL;
|
struct ssas_to_temps_block_info *info, *block_info = NULL;
|
||||||
struct vkd3d_shader_instruction_array instructions;
|
|
||||||
struct vkd3d_shader_instruction *ins, *dst_ins;
|
|
||||||
struct ssas_to_temps_alloc alloc = {0};
|
struct ssas_to_temps_alloc alloc = {0};
|
||||||
|
struct vkd3d_shader_instruction *ins;
|
||||||
size_t phi_count, incoming_count;
|
size_t phi_count, incoming_count;
|
||||||
unsigned int current_label = 0;
|
unsigned int current_label = 0;
|
||||||
|
|
||||||
VKD3D_ASSERT(program->cf_type == VSIR_CF_BLOCKS);
|
VKD3D_ASSERT(program->cf_type == VSIR_CF_BLOCKS);
|
||||||
|
|
||||||
if (!shader_instruction_array_init(&instructions, 0))
|
|
||||||
return VKD3D_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
if (!(block_info = vkd3d_calloc(program->block_count, sizeof(*block_info))))
|
if (!(block_info = vkd3d_calloc(program->block_count, sizeof(*block_info))))
|
||||||
{
|
{
|
||||||
ERR("Failed to allocate block info array.\n");
|
ERR("Failed to allocate block info array.\n");
|
||||||
@@ -4822,7 +4818,7 @@ static enum vkd3d_result vsir_program_materialise_phi_ssas_to_temps(struct vsir_
|
|||||||
if (!phi_count)
|
if (!phi_count)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
if (!shader_instruction_array_reserve(&instructions, program->instructions.count + incoming_count - phi_count))
|
if (!shader_instruction_array_reserve(&program->instructions, program->instructions.count + incoming_count))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
for (ins = vsir_program_iterator_head(&it); ins; ins = vsir_program_iterator_next(&it))
|
for (ins = vsir_program_iterator_head(&it); ins; ins = vsir_program_iterator_next(&it))
|
||||||
@@ -4846,11 +4842,13 @@ static enum vkd3d_result vsir_program_materialise_phi_ssas_to_temps(struct vsir_
|
|||||||
case VSIR_OP_SWITCH_MONOLITHIC:
|
case VSIR_OP_SWITCH_MONOLITHIC:
|
||||||
info = &block_info[current_label - 1];
|
info = &block_info[current_label - 1];
|
||||||
|
|
||||||
|
mov_ins = vsir_program_iterator_insert_before_and_move(&it, info->incoming_count);
|
||||||
|
VKD3D_ASSERT(mov_ins);
|
||||||
|
|
||||||
for (j = 0; j < info->incoming_count; ++j)
|
for (j = 0; j < info->incoming_count; ++j)
|
||||||
{
|
{
|
||||||
struct phi_incoming_to_temp *incoming = &info->incomings[j];
|
struct phi_incoming_to_temp *incoming = &info->incomings[j];
|
||||||
|
|
||||||
mov_ins = shader_instruction_array_append(&instructions);
|
|
||||||
if (!vsir_instruction_init_with_params(program, mov_ins, &ins->location, VSIR_OP_MOV, 1, 0))
|
if (!vsir_instruction_init_with_params(program, mov_ins, &ins->location, VSIR_OP_MOV, 1, 0))
|
||||||
{
|
{
|
||||||
vkd3d_shader_instruction_make_nop(mov_ins);
|
vkd3d_shader_instruction_make_nop(mov_ins);
|
||||||
@@ -4859,21 +4857,20 @@ static enum vkd3d_result vsir_program_materialise_phi_ssas_to_temps(struct vsir_
|
|||||||
*mov_ins->dst = *incoming->dst;
|
*mov_ins->dst = *incoming->dst;
|
||||||
mov_ins->src = incoming->src;
|
mov_ins->src = incoming->src;
|
||||||
mov_ins->src_count = 1;
|
mov_ins->src_count = 1;
|
||||||
|
|
||||||
|
mov_ins = vsir_program_iterator_next(&it);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VSIR_OP_PHI:
|
case VSIR_OP_PHI:
|
||||||
continue;
|
vkd3d_shader_instruction_make_nop(ins);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
dst_ins = shader_instruction_array_append(&instructions);
|
|
||||||
*dst_ins = *ins;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vsir_program_replace_instructions(program, &instructions);
|
|
||||||
program->temp_count = alloc.next_temp_idx;
|
program->temp_count = alloc.next_temp_idx;
|
||||||
done:
|
done:
|
||||||
ssas_to_temps_block_info_cleanup(block_info, program->block_count);
|
ssas_to_temps_block_info_cleanup(block_info, program->block_count);
|
||||||
@@ -4882,7 +4879,6 @@ done:
|
|||||||
return VKD3D_OK;
|
return VKD3D_OK;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
shader_instruction_array_destroy(&instructions);
|
|
||||||
ssas_to_temps_block_info_cleanup(block_info, program->block_count);
|
ssas_to_temps_block_info_cleanup(block_info, program->block_count);
|
||||||
vkd3d_free(alloc.table);
|
vkd3d_free(alloc.table);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user