mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
vkd3d-shader/ir: Split handling loops when emitting a structured program.
This commit is contained in:
parent
5e42f6779a
commit
052df4d693
Notes:
Alexandre Julliard
2024-04-15 22:22:40 +02:00
Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Conor McCarthy (@cmccarthy) Approved-by: Henri Verbeet (@hverbeet) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/778
@ -2917,7 +2917,7 @@ struct vsir_cfg_structure
|
||||
union
|
||||
{
|
||||
struct vsir_block *block;
|
||||
struct
|
||||
struct vsir_cfg_structure_loop
|
||||
{
|
||||
struct vsir_cfg_structure_list body;
|
||||
unsigned idx;
|
||||
@ -4441,6 +4441,9 @@ static enum vkd3d_result vsir_cfg_optimize(struct vsir_cfg *cfg)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static enum vkd3d_result vsir_cfg_structure_list_emit(struct vsir_cfg *cfg,
|
||||
struct vsir_cfg_structure_list *list, unsigned int loop_idx);
|
||||
|
||||
static enum vkd3d_result vsir_cfg_structure_list_emit_block(struct vsir_cfg *cfg,
|
||||
struct vsir_block *block)
|
||||
{
|
||||
@ -4458,33 +4461,19 @@ static enum vkd3d_result vsir_cfg_structure_list_emit_block(struct vsir_cfg *cfg
|
||||
return VKD3D_OK;
|
||||
}
|
||||
|
||||
static enum vkd3d_result vsir_cfg_structure_list_emit(struct vsir_cfg *cfg,
|
||||
struct vsir_cfg_structure_list *list, unsigned int loop_idx)
|
||||
static enum vkd3d_result vsir_cfg_structure_list_emit_loop(struct vsir_cfg *cfg,
|
||||
struct vsir_cfg_structure_loop *loop, unsigned int loop_idx)
|
||||
{
|
||||
struct vsir_cfg_emit_target *target = cfg->target;
|
||||
const struct vkd3d_shader_location no_loc = {0};
|
||||
enum vkd3d_result ret;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < list->count; ++i)
|
||||
{
|
||||
struct vsir_cfg_structure *structure = &list->structures[i];
|
||||
|
||||
switch (structure->type)
|
||||
{
|
||||
case STRUCTURE_TYPE_BLOCK:
|
||||
if ((ret = vsir_cfg_structure_list_emit_block(cfg, structure->u.block)) < 0)
|
||||
return ret;
|
||||
break;
|
||||
|
||||
case STRUCTURE_TYPE_LOOP:
|
||||
{
|
||||
if (!reserve_instructions(&target->instructions, &target->ins_capacity, target->ins_count + 1))
|
||||
return VKD3D_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
vsir_instruction_init(&target->instructions[target->ins_count++], &no_loc, VKD3DSIH_LOOP);
|
||||
|
||||
if ((ret = vsir_cfg_structure_list_emit(cfg, &structure->u.loop.body, structure->u.loop.idx)) < 0)
|
||||
if ((ret = vsir_cfg_structure_list_emit(cfg, &loop->body, loop->idx)) < 0)
|
||||
return ret;
|
||||
|
||||
if (!reserve_instructions(&target->instructions, &target->ins_capacity, target->ins_count + 5))
|
||||
@ -4502,7 +4491,7 @@ static enum vkd3d_result vsir_cfg_structure_list_emit(struct vsir_cfg *cfg,
|
||||
/* If the multilevel jump is a `continue' to any other target, or if it is a `break'
|
||||
* and the target is not the loop we just finished emitting, then it means that
|
||||
* we have to reach an outer loop, so we keep breaking. */
|
||||
const unsigned int inner_break_target = structure->u.loop.idx << 1;
|
||||
const unsigned int inner_break_target = loop->idx << 1;
|
||||
|
||||
if (!vsir_instruction_init_with_params(cfg->program, &target->instructions[target->ins_count],
|
||||
&no_loc, VKD3DSIH_IEQ, 1, 2))
|
||||
@ -4544,9 +4533,33 @@ static enum vkd3d_result vsir_cfg_structure_list_emit(struct vsir_cfg *cfg,
|
||||
++target->temp_count;
|
||||
}
|
||||
|
||||
break;
|
||||
return VKD3D_OK;
|
||||
}
|
||||
|
||||
static enum vkd3d_result vsir_cfg_structure_list_emit(struct vsir_cfg *cfg,
|
||||
struct vsir_cfg_structure_list *list, unsigned int loop_idx)
|
||||
{
|
||||
struct vsir_cfg_emit_target *target = cfg->target;
|
||||
const struct vkd3d_shader_location no_loc = {0};
|
||||
enum vkd3d_result ret;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < list->count; ++i)
|
||||
{
|
||||
struct vsir_cfg_structure *structure = &list->structures[i];
|
||||
|
||||
switch (structure->type)
|
||||
{
|
||||
case STRUCTURE_TYPE_BLOCK:
|
||||
if ((ret = vsir_cfg_structure_list_emit_block(cfg, structure->u.block)) < 0)
|
||||
return ret;
|
||||
break;
|
||||
|
||||
case STRUCTURE_TYPE_LOOP:
|
||||
if ((ret = vsir_cfg_structure_list_emit_loop(cfg, &structure->u.loop, loop_idx)) < 0)
|
||||
return ret;
|
||||
break;
|
||||
|
||||
case STRUCTURE_TYPE_SELECTION:
|
||||
if (!reserve_instructions(&target->instructions, &target->ins_capacity, target->ins_count + 1))
|
||||
return VKD3D_ERROR_OUT_OF_MEMORY;
|
||||
|
Loading…
Reference in New Issue
Block a user