vkd3d-shader/ir: Don't preallocate instructions in cf_flattener_iterate_instruction_array().

This commit is contained in:
Francisco Casas
2025-10-07 22:18:22 -03:00
committed by Henri Verbeet
parent 7dea1e83d2
commit aefa22a063
Notes: Henri Verbeet 2025-10-08 13:51:10 +02:00
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1777

View File

@@ -3982,6 +3982,19 @@ static void cf_flattener_set_error(struct cf_flattener *flattener, enum vkd3d_re
flattener->status = error; flattener->status = error;
} }
static struct vkd3d_shader_instruction *cf_flattener_instruction_append(struct cf_flattener *flattener)
{
struct vkd3d_shader_instruction *ins;
if (!(ins = shader_instruction_array_append(&flattener->instructions)))
{
ERR("Failed to allocate instructions.\n");
cf_flattener_set_error(flattener, VKD3D_ERROR_OUT_OF_MEMORY);
return NULL;
}
return ins;
}
static bool cf_flattener_copy_instruction(struct cf_flattener *flattener, static bool cf_flattener_copy_instruction(struct cf_flattener *flattener,
const struct vkd3d_shader_instruction *instruction) const struct vkd3d_shader_instruction *instruction)
{ {
@@ -3990,7 +4003,7 @@ static bool cf_flattener_copy_instruction(struct cf_flattener *flattener,
if (instruction->opcode == VSIR_OP_NOP) if (instruction->opcode == VSIR_OP_NOP)
return true; return true;
if (!(dst_ins = shader_instruction_array_append(&flattener->instructions))) if (!(dst_ins = cf_flattener_instruction_append(flattener)))
return false; return false;
*dst_ins = *instruction; *dst_ins = *instruction;
@@ -4021,7 +4034,7 @@ static void cf_flattener_emit_label(struct cf_flattener *flattener, unsigned int
{ {
struct vkd3d_shader_instruction *ins; struct vkd3d_shader_instruction *ins;
if (!(ins = shader_instruction_array_append(&flattener->instructions))) if (!(ins = cf_flattener_instruction_append(flattener)))
return; return;
if (!vsir_instruction_init_label(ins, &flattener->location, label_id, flattener->program)) if (!vsir_instruction_init_label(ins, &flattener->location, label_id, flattener->program))
{ {
@@ -4039,7 +4052,7 @@ static struct vkd3d_shader_src_param *cf_flattener_emit_branch(struct cf_flatten
struct vkd3d_shader_src_param *src_params, *false_branch_param; struct vkd3d_shader_src_param *src_params, *false_branch_param;
struct vkd3d_shader_instruction *ins; struct vkd3d_shader_instruction *ins;
if (!(ins = shader_instruction_array_append(&flattener->instructions))) if (!(ins = cf_flattener_instruction_append(flattener)))
return NULL; return NULL;
vsir_instruction_init(ins, &flattener->location, VSIR_OP_BRANCH); vsir_instruction_init(ins, &flattener->location, VSIR_OP_BRANCH);
@@ -4190,13 +4203,6 @@ static enum vkd3d_result cf_flattener_iterate_instruction_array(struct cf_flatte
is_hull_shader = program->shader_version.type == VKD3D_SHADER_TYPE_HULL; is_hull_shader = program->shader_version.type == VKD3D_SHADER_TYPE_HULL;
after_declarations_section = is_hull_shader; after_declarations_section = is_hull_shader;
if (!shader_instruction_array_reserve(&flattener->instructions, instructions->count + 1))
{
ERR("Failed to allocate instructions.\n");
cf_flattener_set_error(flattener, VKD3D_ERROR_OUT_OF_MEMORY);
return VKD3D_ERROR_OUT_OF_MEMORY;
}
it = vsir_program_iterator(instructions); it = vsir_program_iterator(instructions);
for (instruction = vsir_program_iterator_head(&it); instruction; instruction = vsir_program_iterator_next(&it)) for (instruction = vsir_program_iterator_head(&it); instruction; instruction = vsir_program_iterator_next(&it))
{ {