From 0789578175a7e4db57414a8ea58ec1902202fcc9 Mon Sep 17 00:00:00 2001 From: Giovanni Mascellani Date: Mon, 21 Jul 2025 21:41:16 +0200 Subject: [PATCH] vkd3d-shader/ir: Introduce vsir_program_append(). To append an instruction to the end of the vsir program. --- libs/vkd3d-shader/tpf.c | 7 +------ libs/vkd3d-shader/vkd3d_shader_private.h | 10 ++++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index f66d01f85..7b68575f6 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -2896,7 +2896,6 @@ static void shader_sm4_validate_default_phase_index_ranges(struct vkd3d_shader_s int tpf_parse(const struct vkd3d_shader_compile_info *compile_info, uint64_t config_flags, struct vkd3d_shader_message_context *message_context, struct vsir_program *program) { - struct vkd3d_shader_instruction_array *instructions; struct vkd3d_shader_sm4_parser sm4 = {0}; struct dxbc_shader_desc dxbc_desc = {0}; struct vkd3d_shader_instruction *ins; @@ -2956,17 +2955,14 @@ int tpf_parse(const struct vkd3d_shader_compile_info *compile_info, uint64_t con return VKD3D_ERROR_INVALID_SHADER; } - instructions = &program->instructions; while (sm4.ptr != sm4.end) { - if (!shader_instruction_array_reserve(instructions, instructions->count + 1)) + if (!(ins = vsir_program_append(program))) { - ERR("Failed to allocate instructions.\n"); vkd3d_shader_parser_error(&sm4.p, VKD3D_SHADER_ERROR_TPF_OUT_OF_MEMORY, "Out of memory."); vsir_program_cleanup(program); return VKD3D_ERROR_OUT_OF_MEMORY; } - ins = &instructions->elements[instructions->count]; shader_sm4_read_instruction(&sm4, ins); if (ins->opcode == VSIR_OP_INVALID) @@ -2975,7 +2971,6 @@ int tpf_parse(const struct vkd3d_shader_compile_info *compile_info, uint64_t con vsir_program_cleanup(program); return VKD3D_ERROR_OUT_OF_MEMORY; } - ++instructions->count; } if (program->shader_version.type == VKD3D_SHADER_TYPE_HULL && !sm4.has_control_point_phase && !sm4.p.failed) diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index 872e34c35..ebe1741da 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -1583,6 +1583,16 @@ bool vsir_instruction_init_with_params(struct vsir_program *program, struct vkd3d_shader_instruction *ins, const struct vkd3d_shader_location *location, enum vkd3d_shader_opcode opcode, unsigned int dst_count, unsigned int src_count); +static inline struct vkd3d_shader_instruction *vsir_program_append(struct vsir_program *program) +{ + struct vkd3d_shader_instruction_array *array = &program->instructions; + + if (!shader_instruction_array_insert_at(array, array->count, 1)) + return NULL; + + return &array->elements[array->count - 1]; +} + static inline struct vkd3d_shader_dst_param *vsir_program_get_dst_params( struct vsir_program *program, unsigned int count) {