From 6b841486d430dd9d53acca5c2fbe589cc9adaefb Mon Sep 17 00:00:00 2001 From: Giovanni Mascellani Date: Fri, 12 Apr 2024 16:19:49 +0200 Subject: [PATCH] vkd3d-shader/ir: Materialize SSAs in each function of a hull shader. --- libs/vkd3d-shader/ir.c | 65 ++++++++++++++++++++++------- tests/hlsl/tessellation.shader_test | 2 +- 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/libs/vkd3d-shader/ir.c b/libs/vkd3d-shader/ir.c index b0bd99f9..62292f16 100644 --- a/libs/vkd3d-shader/ir.c +++ b/libs/vkd3d-shader/ir.c @@ -3098,6 +3098,8 @@ struct vsir_cfg { struct vkd3d_shader_message_context *message_context; struct vsir_program *program; + size_t function_begin; + size_t function_end; struct vsir_block *blocks; struct vsir_block *entry; size_t block_count; @@ -3354,6 +3356,7 @@ static enum vkd3d_result vsir_cfg_init(struct vsir_cfg *cfg, struct vsir_program cfg->program = program; cfg->block_count = program->block_count; cfg->target = target; + cfg->function_begin = *pos; vsir_block_list_init(&cfg->order); @@ -3414,6 +3417,7 @@ static enum vkd3d_result vsir_cfg_init(struct vsir_cfg *cfg, struct vsir_program } *pos = i; + cfg->function_end = *pos; for (i = 0; i < cfg->block_count; ++i) { @@ -5063,7 +5067,7 @@ static enum vkd3d_result vsir_cfg_materialize_undominated_ssas_to_temps(struct v TRACE("Emitting temps for %u values with undominated usage.\n", alloc.next_temp_idx - program->temp_count); - for (i = 0; i < program->instructions.count; ++i) + for (i = cfg->function_begin; i < cfg->function_end; ++i) { struct vkd3d_shader_instruction *ins = &program->instructions.elements[i]; @@ -5082,26 +5086,16 @@ done: return VKD3D_OK; } -static enum vkd3d_result vsir_program_materialize_undominated_ssas_to_temps(struct vsir_program *program, - struct vkd3d_shader_message_context *message_context) +static enum vkd3d_result vsir_program_materialize_undominated_ssas_to_temps_in_function( + struct vsir_program *program, struct vkd3d_shader_message_context *message_context, + size_t *pos) { enum vkd3d_result ret; struct vsir_cfg cfg; - size_t stop_pos = 0; - if (program->shader_version.type == VKD3D_SHADER_TYPE_HULL) - { - FIXME("Hull shaders are not supported.\n"); - vkd3d_shader_error(message_context, NULL, VKD3D_SHADER_ERROR_VSIR_NOT_IMPLEMENTED, - "The structurizer does not support hull shaders."); - return VKD3D_ERROR_INVALID_SHADER; - } - - if ((ret = vsir_cfg_init(&cfg, program, message_context, NULL, &stop_pos)) < 0) + if ((ret = vsir_cfg_init(&cfg, program, message_context, NULL, pos)) < 0) return ret; - assert(stop_pos == program->instructions.count); - vsir_cfg_compute_dominators(&cfg); ret = vsir_cfg_materialize_undominated_ssas_to_temps(&cfg); @@ -5111,6 +5105,47 @@ static enum vkd3d_result vsir_program_materialize_undominated_ssas_to_temps(stru return ret; } +static enum vkd3d_result vsir_program_materialize_undominated_ssas_to_temps(struct vsir_program *program, + struct vkd3d_shader_message_context *message_context) +{ + enum vkd3d_result ret; + size_t i; + + for (i = 0; i < program->instructions.count;) + { + struct vkd3d_shader_instruction *ins = &program->instructions.elements[i]; + + switch (ins->handler_idx) + { + case VKD3DSIH_LABEL: + assert(program->shader_version.type != VKD3D_SHADER_TYPE_HULL); + TRACE("Materializing undominated SSAs in a non-hull shader.\n"); + if ((ret = vsir_program_materialize_undominated_ssas_to_temps_in_function( + program, message_context, &i)) < 0) + return ret; + assert(i == program->instructions.count); + break; + + case VKD3DSIH_HS_CONTROL_POINT_PHASE: + case VKD3DSIH_HS_FORK_PHASE: + case VKD3DSIH_HS_JOIN_PHASE: + assert(program->shader_version.type == VKD3D_SHADER_TYPE_HULL); + TRACE("Materializing undominated SSAs in phase %u of a hull shader.\n", ins->handler_idx); + ++i; + if ((ret = vsir_program_materialize_undominated_ssas_to_temps_in_function( + program, message_context, &i)) < 0) + return ret; + break; + + default: + ++i; + break; + } + } + + return VKD3D_OK; +} + struct validation_context { struct vkd3d_shader_message_context *message_context; diff --git a/tests/hlsl/tessellation.shader_test b/tests/hlsl/tessellation.shader_test index d8b26347..77bc49ee 100644 --- a/tests/hlsl/tessellation.shader_test +++ b/tests/hlsl/tessellation.shader_test @@ -94,5 +94,5 @@ float4 main(data input) : sv_target } [test] -todo draw 3 control point patch list 3 +todo(sm<6) draw 3 control point patch list 3 probe all rgba (0.0, 1.0, 0.0, 1.0)