diff --git a/libs/vkd3d-shader/d3dbc.c b/libs/vkd3d-shader/d3dbc.c index 6499a59e..9ad9f735 100644 --- a/libs/vkd3d-shader/d3dbc.c +++ b/libs/vkd3d-shader/d3dbc.c @@ -899,7 +899,7 @@ static void shader_sm1_read_src_param(struct vkd3d_shader_sm1_parser *sm1, const shader_sm1_read_param(sm1, ptr, &token, &addr_token); if (has_relative_address(token)) { - if (!(src_rel_addr = shader_parser_get_src_params(&sm1->p, 1))) + if (!(src_rel_addr = vsir_program_get_src_params(&sm1->p.program, 1))) { vkd3d_shader_parser_error(&sm1->p, VKD3D_SHADER_ERROR_D3DBC_OUT_OF_MEMORY, "Out of memory."); @@ -920,7 +920,7 @@ static void shader_sm1_read_dst_param(struct vkd3d_shader_sm1_parser *sm1, const shader_sm1_read_param(sm1, ptr, &token, &addr_token); if (has_relative_address(token)) { - if (!(dst_rel_addr = shader_parser_get_src_params(&sm1->p, 1))) + if (!(dst_rel_addr = vsir_program_get_src_params(&sm1->p.program, 1))) { vkd3d_shader_parser_error(&sm1->p, VKD3D_SHADER_ERROR_D3DBC_OUT_OF_MEMORY, "Out of memory."); @@ -1122,11 +1122,11 @@ static void shader_sm1_read_instruction(struct vkd3d_shader_sm1_parser *sm1, str ins->raw = false; ins->structured = false; predicated = !!(opcode_token & VKD3D_SM1_INSTRUCTION_PREDICATED); - ins->predicate = predicate = predicated ? shader_parser_get_src_params(&sm1->p, 1) : NULL; + ins->predicate = predicate = predicated ? vsir_program_get_src_params(program, 1) : NULL; ins->dst_count = opcode_info->dst_count; ins->dst = dst_param = vsir_program_get_dst_params(program, ins->dst_count); ins->src_count = opcode_info->src_count; - ins->src = src_params = shader_parser_get_src_params(&sm1->p, ins->src_count); + ins->src = src_params = vsir_program_get_src_params(program, ins->src_count); if ((!predicate && predicated) || (!src_params && ins->src_count) || (!dst_param && ins->dst_count)) { vkd3d_shader_parser_error(&sm1->p, VKD3D_SHADER_ERROR_D3DBC_OUT_OF_MEMORY, "Out of memory."); diff --git a/libs/vkd3d-shader/dxil.c b/libs/vkd3d-shader/dxil.c index 2718f94f..0358dbb6 100644 --- a/libs/vkd3d-shader/dxil.c +++ b/libs/vkd3d-shader/dxil.c @@ -2092,8 +2092,9 @@ static void instruction_init_with_resource(struct vkd3d_shader_instruction *ins, static struct vkd3d_shader_src_param *instruction_src_params_alloc(struct vkd3d_shader_instruction *ins, unsigned int count, struct sm6_parser *sm6) { - struct vkd3d_shader_src_param *params = shader_parser_get_src_params(&sm6->p, count); - if (!params) + struct vkd3d_shader_src_param *params; + + if (!(params = vsir_program_get_src_params(&sm6->p.program, count))) { ERR("Failed to allocate src params.\n"); vkd3d_shader_parser_error(&sm6->p, VKD3D_SHADER_ERROR_DXIL_OUT_OF_MEMORY, @@ -2253,7 +2254,7 @@ static void register_index_address_init(struct vkd3d_shader_register_index *idx, } else { - struct vkd3d_shader_src_param *rel_addr = shader_parser_get_src_params(&sm6->p, 1); + struct vkd3d_shader_src_param *rel_addr = vsir_program_get_src_params(&sm6->p.program, 1); if (rel_addr) src_param_init_from_value(rel_addr, address); idx->offset = 0; diff --git a/libs/vkd3d-shader/ir.c b/libs/vkd3d-shader/ir.c index 2d388b85..a0d6212c 100644 --- a/libs/vkd3d-shader/ir.c +++ b/libs/vkd3d-shader/ir.c @@ -66,7 +66,7 @@ static void remove_dcl_temps(struct vsir_program *program) } } -static bool vsir_instruction_init_with_params(struct vkd3d_shader_parser *parser, +static 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 handler_idx, unsigned int dst_count, unsigned int src_count) { @@ -74,13 +74,13 @@ static bool vsir_instruction_init_with_params(struct vkd3d_shader_parser *parser ins->dst_count = dst_count; ins->src_count = src_count; - if (!(ins->dst = vsir_program_get_dst_params(&parser->program, ins->dst_count))) + if (!(ins->dst = vsir_program_get_dst_params(program, ins->dst_count))) { ERR("Failed to allocate %u destination parameters.\n", dst_count); return false; } - if (!(ins->src = shader_parser_get_src_params(parser, ins->src_count))) + if (!(ins->src = vsir_program_get_src_params(program, ins->src_count))) { ERR("Failed to allocate %u source parameters.\n", src_count); return false; @@ -116,7 +116,7 @@ static enum vkd3d_result instruction_array_lower_texkills(struct vkd3d_shader_pa /* tmp = ins->dst[0] < 0 */ ins = &instructions->elements[i + 1]; - if (!vsir_instruction_init_with_params(parser, ins, &texkill_ins->location, VKD3DSIH_LTO, 1, 2)) + if (!vsir_instruction_init_with_params(program, ins, &texkill_ins->location, VKD3DSIH_LTO, 1, 2)) return VKD3D_ERROR_OUT_OF_MEMORY; vsir_register_init(&ins->dst[0].reg, VKD3DSPR_TEMP, VKD3D_DATA_UINT, 1); @@ -139,7 +139,7 @@ static enum vkd3d_result instruction_array_lower_texkills(struct vkd3d_shader_pa for (k = 1; k < components_read; ++k) { ins = &instructions->elements[i + 1 + k]; - if (!(vsir_instruction_init_with_params(parser, ins, &texkill_ins->location, VKD3DSIH_OR, 1, 2))) + if (!(vsir_instruction_init_with_params(program, ins, &texkill_ins->location, VKD3DSIH_OR, 1, 2))) return VKD3D_ERROR_OUT_OF_MEMORY; vsir_register_init(&ins->dst[0].reg, VKD3DSPR_TEMP, VKD3D_DATA_UINT, 1); @@ -160,7 +160,7 @@ static enum vkd3d_result instruction_array_lower_texkills(struct vkd3d_shader_pa /* discard_nz tmp.x */ ins = &instructions->elements[i + 1 + components_read]; - if (!(vsir_instruction_init_with_params(parser, ins, &texkill_ins->location, VKD3DSIH_DISCARD, 0, 1))) + if (!(vsir_instruction_init_with_params(program, ins, &texkill_ins->location, VKD3DSIH_DISCARD, 0, 1))) return VKD3D_ERROR_OUT_OF_MEMORY; ins->flags = VKD3D_SHADER_CONDITIONAL_OP_NZ; @@ -478,12 +478,12 @@ void vsir_instruction_init(struct vkd3d_shader_instruction *ins, const struct vk ins->handler_idx = handler_idx; } -static bool vsir_instruction_init_label(struct vkd3d_shader_instruction *ins, const struct vkd3d_shader_location *location, - unsigned int label_id, void *parser) +static bool vsir_instruction_init_label(struct vkd3d_shader_instruction *ins, + const struct vkd3d_shader_location *location, unsigned int label_id, struct vsir_program *program) { struct vkd3d_shader_src_param *src_param; - if (!(src_param = shader_parser_get_src_params(parser, 1))) + if (!(src_param = vsir_program_get_src_params(program, 1))) return false; vsir_src_param_init_label(src_param, label_id); @@ -1829,8 +1829,9 @@ static unsigned int cf_flattener_alloc_block_id(struct cf_flattener *flattener) static struct vkd3d_shader_src_param *instruction_src_params_alloc(struct vkd3d_shader_instruction *ins, unsigned int count, struct cf_flattener *flattener) { - struct vkd3d_shader_src_param *params = shader_parser_get_src_params(flattener->parser, count); - if (!params) + struct vkd3d_shader_src_param *params; + + if (!(params = vsir_program_get_src_params(&flattener->parser->program, count))) { flattener->allocation_failed = true; return NULL; @@ -1846,7 +1847,7 @@ static void cf_flattener_emit_label(struct cf_flattener *flattener, unsigned int if (!(ins = cf_flattener_require_space(flattener, 1))) return; - if (vsir_instruction_init_label(ins, &flattener->location, label_id, flattener->parser)) + if (vsir_instruction_init_label(ins, &flattener->location, label_id, &flattener->parser->program)) ++flattener->instruction_count; else flattener->allocation_failed = true; @@ -2416,22 +2417,22 @@ static bool lower_switch_to_if_ladder_add_block_mapping(struct lower_switch_to_i return true; } -static enum vkd3d_result lower_switch_to_if_ladder(struct vkd3d_shader_parser *parser) +static enum vkd3d_result lower_switch_to_if_ladder(struct vsir_program *program) { - unsigned int block_count = parser->program.block_count, ssa_count = parser->program.ssa_count, current_label = 0, if_label; + unsigned int block_count = program->block_count, ssa_count = program->ssa_count, current_label = 0, if_label; size_t ins_capacity = 0, ins_count = 0, i, map_capacity = 0, map_count = 0; struct vkd3d_shader_instruction *instructions = NULL; struct lower_switch_to_if_ladder_block_mapping *block_map = NULL; - if (!reserve_instructions(&instructions, &ins_capacity, parser->program.instructions.count)) + if (!reserve_instructions(&instructions, &ins_capacity, program->instructions.count)) goto fail; /* First subpass: convert SWITCH_MONOLITHIC instructions to * selection ladders, keeping a map between blocks before and * after the subpass. */ - for (i = 0; i < parser->program.instructions.count; ++i) + for (i = 0; i < program->instructions.count; ++i) { - struct vkd3d_shader_instruction *ins = &parser->program.instructions.elements[i]; + struct vkd3d_shader_instruction *ins = &program->instructions.elements[i]; unsigned int case_count, j, default_label; switch (ins->handler_idx) @@ -2463,7 +2464,8 @@ static enum vkd3d_result lower_switch_to_if_ladder(struct vkd3d_shader_parser *p if (!reserve_instructions(&instructions, &ins_capacity, ins_count + 1)) goto fail; - if (!vsir_instruction_init_with_params(parser, &instructions[ins_count], &ins->location, VKD3DSIH_BRANCH, 0, 1)) + if (!vsir_instruction_init_with_params(program, &instructions[ins_count], + &ins->location, VKD3DSIH_BRANCH, 0, 1)) goto fail; vsir_src_param_init_label(&instructions[ins_count].src[0], default_label); ++ins_count; @@ -2478,7 +2480,8 @@ static enum vkd3d_result lower_switch_to_if_ladder(struct vkd3d_shader_parser *p { unsigned int fallthrough_label, case_label = label_from_src_param(&ins->src[3 + 2 * j + 1]); - if (!vsir_instruction_init_with_params(parser, &instructions[ins_count], &ins->location, VKD3DSIH_IEQ, 1, 2)) + if (!vsir_instruction_init_with_params(program, + &instructions[ins_count], &ins->location, VKD3DSIH_IEQ, 1, 2)) goto fail; dst_param_init_ssa_bool(&instructions[ins_count].dst[0], ssa_count); instructions[ins_count].src[0] = ins->src[0]; @@ -2493,7 +2496,8 @@ static enum vkd3d_result lower_switch_to_if_ladder(struct vkd3d_shader_parser *p else fallthrough_label = block_count + 1; - if (!vsir_instruction_init_with_params(parser, &instructions[ins_count], &ins->location, VKD3DSIH_BRANCH, 0, 3)) + if (!vsir_instruction_init_with_params(program, &instructions[ins_count], + &ins->location, VKD3DSIH_BRANCH, 0, 3)) goto fail; src_param_init_ssa_bool(&instructions[ins_count].src[0], ssa_count); vsir_src_param_init_label(&instructions[ins_count].src[1], case_label); @@ -2514,7 +2518,8 @@ static enum vkd3d_result lower_switch_to_if_ladder(struct vkd3d_shader_parser *p } else { - if (!vsir_instruction_init_with_params(parser, &instructions[ins_count], &ins->location, VKD3DSIH_LABEL, 0, 1)) + if (!vsir_instruction_init_with_params(program, + &instructions[ins_count], &ins->location, VKD3DSIH_LABEL, 0, 1)) goto fail; vsir_src_param_init_label(&instructions[ins_count].src[0], ++block_count); ++ins_count; @@ -2573,7 +2578,7 @@ static enum vkd3d_result lower_switch_to_if_ladder(struct vkd3d_shader_parser *p } else { - if (!(new_src = shader_parser_get_src_params(parser, new_src_count))) + if (!(new_src = vsir_program_get_src_params(program, new_src_count))) { ERR("Failed to allocate %u source parameters.\n", new_src_count); goto fail; @@ -2615,13 +2620,13 @@ static enum vkd3d_result lower_switch_to_if_ladder(struct vkd3d_shader_parser *p ins->src = new_src; } - vkd3d_free(parser->program.instructions.elements); + vkd3d_free(program->instructions.elements); vkd3d_free(block_map); - parser->program.instructions.elements = instructions; - parser->program.instructions.capacity = ins_capacity; - parser->program.instructions.count = ins_count; - parser->program.block_count = block_count; - parser->program.ssa_count = ssa_count; + program->instructions.elements = instructions; + program->instructions.capacity = ins_capacity; + program->instructions.count = ins_count; + program->block_count = block_count; + program->ssa_count = ssa_count; return VKD3D_OK; @@ -2645,7 +2650,7 @@ enum vkd3d_result vkd3d_shader_normalise(struct vkd3d_shader_parser *parser, if (parser->shader_desc.is_dxil) { - if ((result = lower_switch_to_if_ladder(parser)) < 0) + if ((result = lower_switch_to_if_ladder(&parser->program)) < 0) return result; } else diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index ed56a347..adfddd32 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -1742,7 +1742,7 @@ static bool shader_sm4_read_reg_idx(struct vkd3d_shader_sm4_parser *priv, const { if (addressing & VKD3D_SM4_ADDRESSING_RELATIVE) { - struct vkd3d_shader_src_param *rel_addr = shader_parser_get_src_params(&priv->p, 1); + struct vkd3d_shader_src_param *rel_addr = vsir_program_get_src_params(&priv->p.program, 1); if (!(reg_idx->rel_addr = rel_addr)) { @@ -2344,6 +2344,7 @@ static void shader_sm4_read_instruction_modifier(uint32_t modifier, struct vkd3d static void shader_sm4_read_instruction(struct vkd3d_shader_sm4_parser *sm4, struct vkd3d_shader_instruction *ins) { const struct vkd3d_sm4_opcode_info *opcode_info; + struct vsir_program *program = &sm4->p.program; uint32_t opcode_token, opcode, previous_token; struct vkd3d_shader_dst_param *dst_params; struct vkd3d_shader_src_param *src_params; @@ -2402,7 +2403,7 @@ static void shader_sm4_read_instruction(struct vkd3d_shader_sm4_parser *sm4, str ins->predicate = NULL; ins->dst_count = strnlen(opcode_info->dst_info, SM4_MAX_DST_COUNT); ins->src_count = strnlen(opcode_info->src_info, SM4_MAX_SRC_COUNT); - ins->src = src_params = shader_parser_get_src_params(&sm4->p, ins->src_count); + ins->src = src_params = vsir_program_get_src_params(program, ins->src_count); if (!src_params && ins->src_count) { ERR("Failed to allocate src parameters.\n"); @@ -2444,7 +2445,7 @@ static void shader_sm4_read_instruction(struct vkd3d_shader_sm4_parser *sm4, str precise = (opcode_token & VKD3D_SM5_PRECISE_MASK) >> VKD3D_SM5_PRECISE_SHIFT; ins->flags |= precise << VKD3DSI_PRECISE_SHIFT; - ins->dst = dst_params = vsir_program_get_dst_params(&sm4->p.program, ins->dst_count); + ins->dst = dst_params = vsir_program_get_dst_params(program, ins->dst_count); if (!dst_params && ins->dst_count) { ERR("Failed to allocate dst parameters.\n"); diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index 55dc499d..d7f981a5 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -1293,6 +1293,12 @@ static inline struct vkd3d_shader_dst_param *vsir_program_get_dst_params( return shader_dst_param_allocator_get(&program->instructions.dst_params, count); } +static inline struct vkd3d_shader_src_param *vsir_program_get_src_params( + struct vsir_program *program, unsigned int count) +{ + return shader_src_param_allocator_get(&program->instructions.src_params, count); +} + struct vkd3d_shader_parser { struct vkd3d_shader_message_context *message_context; @@ -1320,12 +1326,6 @@ bool vkd3d_shader_parser_init(struct vkd3d_shader_parser *parser, void vkd3d_shader_parser_warning(struct vkd3d_shader_parser *parser, enum vkd3d_shader_error error, const char *format, ...) VKD3D_PRINTF_FUNC(3, 4); -static inline struct vkd3d_shader_src_param *shader_parser_get_src_params( - struct vkd3d_shader_parser *parser, unsigned int count) -{ - return shader_src_param_allocator_get(&parser->program.instructions.src_params, count); -} - static inline void vkd3d_shader_parser_destroy(struct vkd3d_shader_parser *parser) { parser->ops->parser_destroy(parser);