From 9d3b75631464e8d87d74bcbb8d1776a1aa07014e Mon Sep 17 00:00:00 2001 From: Alistair Leslie-Hughes Date: Wed, 1 Oct 2025 07:35:50 +1000 Subject: [PATCH] Updated vkd3d to f9c71d5775dd7e3be19911c8bf77fac563bfce85. --- libs/vkd3d/libs/vkd3d-shader/ir.c | 36 +++--- libs/vkd3d/libs/vkd3d-shader/msl.c | 37 ++++++ libs/vkd3d/libs/vkd3d-shader/spirv.c | 182 +++++++++++++-------------- 3 files changed, 143 insertions(+), 112 deletions(-) diff --git a/libs/vkd3d/libs/vkd3d-shader/ir.c b/libs/vkd3d/libs/vkd3d-shader/ir.c index 43bd799d2eb..315ee522e9e 100644 --- a/libs/vkd3d/libs/vkd3d-shader/ir.c +++ b/libs/vkd3d/libs/vkd3d-shader/ir.c @@ -4501,6 +4501,8 @@ static enum vkd3d_result vsir_program_flatten_control_flow_constructs(struct vsi VKD3D_ASSERT(program->cf_type == VSIR_CF_STRUCTURED); + shader_instruction_array_init(&flattener.instructions, 0); + if ((result = cf_flattener_iterate_instruction_array(&flattener, message_context)) >= 0) { vsir_program_replace_instructions(program, &flattener.instructions); @@ -4560,14 +4562,14 @@ static enum vkd3d_result vsir_program_lower_switch_to_selection_ladder(struct vs unsigned int block_count = program->block_count, ssa_count = program->ssa_count, current_label = 0, if_label; struct vsir_program_iterator it = vsir_program_iterator(&program->instructions); struct lower_switch_to_if_ladder_block_mapping *block_map = NULL; - struct vkd3d_shader_instruction_array instructions = {0}; + struct vkd3d_shader_instruction_array instructions; struct vkd3d_shader_instruction *ins, *dst_ins; size_t map_capacity = 0, map_count = 0; VKD3D_ASSERT(program->cf_type == VSIR_CF_BLOCKS); - if (!shader_instruction_array_reserve(&instructions, program->instructions.count)) - goto fail; + if (!shader_instruction_array_init(&instructions, program->instructions.count)) + return VKD3D_ERROR_OUT_OF_MEMORY; /* First subpass: convert SWITCH_MONOLITHIC instructions to * selection ladders, keeping a map between blocks before and @@ -4757,9 +4759,8 @@ static enum vkd3d_result vsir_program_materialise_phi_ssas_to_temps(struct vsir_ { struct vsir_program_iterator it = vsir_program_iterator(&program->instructions); struct ssas_to_temps_block_info *info, *block_info = NULL; - struct vkd3d_shader_instruction_array instructions = {0}; - struct vkd3d_shader_instruction *ins, *dst_ins; struct ssas_to_temps_alloc alloc = {0}; + struct vkd3d_shader_instruction *ins; size_t phi_count, incoming_count; unsigned int current_label = 0; @@ -4817,7 +4818,7 @@ static enum vkd3d_result vsir_program_materialise_phi_ssas_to_temps(struct vsir_ if (!phi_count) goto done; - if (!shader_instruction_array_reserve(&instructions, program->instructions.count + incoming_count - phi_count)) + if (!shader_instruction_array_reserve(&program->instructions, program->instructions.count + incoming_count)) goto fail; for (ins = vsir_program_iterator_head(&it); ins; ins = vsir_program_iterator_next(&it)) @@ -4841,11 +4842,13 @@ static enum vkd3d_result vsir_program_materialise_phi_ssas_to_temps(struct vsir_ case VSIR_OP_SWITCH_MONOLITHIC: info = &block_info[current_label - 1]; + mov_ins = vsir_program_iterator_insert_before_and_move(&it, info->incoming_count); + VKD3D_ASSERT(mov_ins); + for (j = 0; j < info->incoming_count; ++j) { struct phi_incoming_to_temp *incoming = &info->incomings[j]; - mov_ins = shader_instruction_array_append(&instructions); if (!vsir_instruction_init_with_params(program, mov_ins, &ins->location, VSIR_OP_MOV, 1, 0)) { vkd3d_shader_instruction_make_nop(mov_ins); @@ -4854,21 +4857,20 @@ static enum vkd3d_result vsir_program_materialise_phi_ssas_to_temps(struct vsir_ *mov_ins->dst = *incoming->dst; mov_ins->src = incoming->src; mov_ins->src_count = 1; + + mov_ins = vsir_program_iterator_next(&it); } break; case VSIR_OP_PHI: - continue; + vkd3d_shader_instruction_make_nop(ins); + break; default: break; } - - dst_ins = shader_instruction_array_append(&instructions); - *dst_ins = *ins; } - vsir_program_replace_instructions(program, &instructions); program->temp_count = alloc.next_temp_idx; done: ssas_to_temps_block_info_cleanup(block_info, program->block_count); @@ -4877,7 +4879,6 @@ done: return VKD3D_OK; fail: - shader_instruction_array_destroy(&instructions); ssas_to_temps_block_info_cleanup(block_info, program->block_count); vkd3d_free(alloc.table); @@ -7033,7 +7034,7 @@ static enum vkd3d_result vsir_program_structurize(struct vsir_program *program, target.jump_target_temp_idx = program->temp_count; target.temp_count = program->temp_count + 1; - if (!shader_instruction_array_reserve(&target.instructions, target.instructions.count)) + if (!shader_instruction_array_init(&target.instructions, 0)) return VKD3D_ERROR_OUT_OF_MEMORY; for (ins = vsir_program_iterator_head(&it); ins;) @@ -7215,7 +7216,7 @@ static enum vkd3d_result vsir_program_materialize_undominated_ssas_to_temps(stru VKD3D_ASSERT(program->cf_type == VSIR_CF_BLOCKS); - for (ins = vsir_program_iterator_head(&it); ins;) + for (ins = vsir_program_iterator_head(&it); ins; ins = vsir_program_iterator_current(&it)) { switch (ins->opcode) { @@ -7225,8 +7226,6 @@ static enum vkd3d_result vsir_program_materialize_undominated_ssas_to_temps(stru if ((ret = vsir_program_materialize_undominated_ssas_to_temps_in_function( program, message_context, &it)) < 0) return ret; - ins = vsir_program_iterator_current(&it); - VKD3D_ASSERT(!ins); break; case VSIR_OP_HS_CONTROL_POINT_PHASE: @@ -7238,11 +7237,10 @@ static enum vkd3d_result vsir_program_materialize_undominated_ssas_to_temps(stru if ((ret = vsir_program_materialize_undominated_ssas_to_temps_in_function( program, message_context, &it)) < 0) return ret; - ins = vsir_program_iterator_current(&it); break; default: - ins = vsir_program_iterator_next(&it); + vsir_program_iterator_next(&it); break; } } diff --git a/libs/vkd3d/libs/vkd3d-shader/msl.c b/libs/vkd3d/libs/vkd3d-shader/msl.c index 2acb31ed6d6..906392870ed 100644 --- a/libs/vkd3d/libs/vkd3d-shader/msl.c +++ b/libs/vkd3d/libs/vkd3d-shader/msl.c @@ -486,6 +486,10 @@ static enum msl_data_type msl_print_register_name(struct vkd3d_string_buffer *bu vkd3d_string_buffer_printf(buffer, "o_mask"); return MSL_DATA_UNION; + case VKD3DSPR_THREADID: + vkd3d_string_buffer_printf(buffer, "v_thread_id"); + return MSL_DATA_UNION; + default: msl_compiler_error(gen, VKD3D_SHADER_ERROR_MSL_INTERNAL, "Internal compiler error: Unhandled register type %#x.", reg->type); @@ -1456,6 +1460,9 @@ static void msl_handle_instruction(struct msl_generator *gen, const struct vkd3d switch (ins->opcode) { + case VSIR_OP_ACOS: + msl_intrinsic(gen, ins, "acos"); + break; case VSIR_OP_ADD: case VSIR_OP_IADD: msl_binop(gen, ins, "+"); @@ -1463,6 +1470,12 @@ static void msl_handle_instruction(struct msl_generator *gen, const struct vkd3d case VSIR_OP_AND: msl_binop(gen, ins, "&"); break; + case VSIR_OP_ASIN: + msl_intrinsic(gen, ins, "asin"); + break; + case VSIR_OP_ATAN: + msl_intrinsic(gen, ins, "atan"); + break; case VSIR_OP_BREAK: msl_break(gen); break; @@ -1530,6 +1543,9 @@ static void msl_handle_instruction(struct msl_generator *gen, const struct vkd3d case VSIR_OP_FRC: msl_intrinsic(gen, ins, "fract"); break; + case VSIR_OP_FREM: + msl_intrinsic(gen, ins, "fmod"); + break; case VSIR_OP_FTOI: msl_cast(gen, ins, "int"); break; @@ -1558,6 +1574,9 @@ static void msl_handle_instruction(struct msl_generator *gen, const struct vkd3d case VSIR_OP_HSIN: msl_intrinsic(gen, ins, "sinh"); break; + case VSIR_OP_HTAN: + msl_intrinsic(gen, ins, "tanh"); + break; case VSIR_OP_IF: msl_if(gen, ins); break; @@ -1997,6 +2016,12 @@ static void msl_generate_entrypoint_prologue(struct msl_generator *gen) msl_print_write_mask(buffer, e->mask); vkd3d_string_buffer_printf(buffer, ";\n"); } + + if (bitmap_is_set(gen->program->io_dcls, VKD3DSPR_THREADID)) + { + msl_print_indent(gen->buffer, 1); + vkd3d_string_buffer_printf(buffer, "v_thread_id.u = uint4(thread_id, 0u);\n"); + } } static void msl_generate_entrypoint_epilogue(struct msl_generator *gen) @@ -2083,6 +2108,12 @@ static void msl_generate_entrypoint(struct msl_generator *gen) vkd3d_string_buffer_printf(gen->buffer, "uint vertex_id [[vertex_id]],\n"); } + if (bitmap_is_set(gen->program->io_dcls, VKD3DSPR_THREADID)) + { + msl_print_indent(gen->buffer, 2); + vkd3d_string_buffer_printf(gen->buffer, "uint3 thread_id [[thread_position_in_grid]],\n"); + } + msl_print_indent(gen->buffer, 2); vkd3d_string_buffer_printf(gen->buffer, "vkd3d_%s_in input [[stage_in]])\n{\n", gen->prefix); @@ -2092,6 +2123,8 @@ static void msl_generate_entrypoint(struct msl_generator *gen) vkd3d_string_buffer_printf(gen->buffer, " vkd3d_%s_out output;\n", gen->prefix); if (bitmap_is_set(gen->program->io_dcls, VKD3DSPR_SAMPLEMASK)) vkd3d_string_buffer_printf(gen->buffer, " vkd3d_scalar o_mask;\n"); + if (bitmap_is_set(gen->program->io_dcls, VKD3DSPR_THREADID)) + vkd3d_string_buffer_printf(gen->buffer, " vkd3d_vec4 v_thread_id;\n"); vkd3d_string_buffer_printf(gen->buffer, "\n"); msl_generate_entrypoint_prologue(gen); @@ -2103,6 +2136,8 @@ static void msl_generate_entrypoint(struct msl_generator *gen) vkd3d_string_buffer_printf(gen->buffer, ", output.shader_out_depth"); if (bitmap_is_set(gen->program->io_dcls, VKD3DSPR_SAMPLEMASK)) vkd3d_string_buffer_printf(gen->buffer, ", o_mask"); + if (bitmap_is_set(gen->program->io_dcls, VKD3DSPR_THREADID)) + vkd3d_string_buffer_printf(gen->buffer, ", v_thread_id"); if (gen->program->descriptors.descriptor_count) vkd3d_string_buffer_printf(gen->buffer, ", descriptors"); vkd3d_string_buffer_printf(gen->buffer, ");\n\n"); @@ -2176,6 +2211,8 @@ static int msl_generator_generate(struct msl_generator *gen, struct vkd3d_shader vkd3d_string_buffer_printf(gen->buffer, ", thread float &o_depth"); if (bitmap_is_set(gen->program->io_dcls, VKD3DSPR_SAMPLEMASK)) vkd3d_string_buffer_printf(gen->buffer, ", thread vkd3d_scalar &o_mask"); + if (bitmap_is_set(gen->program->io_dcls, VKD3DSPR_THREADID)) + vkd3d_string_buffer_printf(gen->buffer, ", thread vkd3d_vec4 &v_thread_id"); if (gen->program->descriptors.descriptor_count) vkd3d_string_buffer_printf(gen->buffer, ", constant descriptor *descriptors"); vkd3d_string_buffer_printf(gen->buffer, ")\n{\n"); diff --git a/libs/vkd3d/libs/vkd3d-shader/spirv.c b/libs/vkd3d/libs/vkd3d-shader/spirv.c index 41ab6114ffc..1bad74b06bc 100644 --- a/libs/vkd3d/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d/libs/vkd3d-shader/spirv.c @@ -3658,123 +3658,128 @@ static const struct vkd3d_symbol *spirv_compiler_put_symbol(struct spirv_compile } static uint32_t spirv_compiler_get_constant(struct spirv_compiler *compiler, - enum vkd3d_shader_component_type component_type, unsigned int component_count, const uint32_t *values) + enum vsir_data_type data_type, unsigned int component_count, const uint32_t *values) { uint32_t type_id, scalar_type_id, component_ids[VKD3D_VEC4_SIZE]; struct vkd3d_spirv_builder *builder = &compiler->spirv_builder; unsigned int i; VKD3D_ASSERT(0 < component_count && component_count <= VKD3D_VEC4_SIZE); - type_id = spirv_get_type_id_for_component_type(builder, component_type, component_count); + type_id = spirv_get_type_id(builder, data_type, component_count); - switch (component_type) + switch (data_type) { - case VKD3D_SHADER_COMPONENT_UINT: - case VKD3D_SHADER_COMPONENT_INT: - case VKD3D_SHADER_COMPONENT_FLOAT: - break; - case VKD3D_SHADER_COMPONENT_BOOL: + case VSIR_DATA_BOOL: if (component_count == 1) return vkd3d_spirv_get_op_constant_bool(builder, type_id, *values); - FIXME("Unsupported vector of bool.\n"); spirv_compiler_error(compiler, VKD3D_SHADER_ERROR_SPV_INVALID_TYPE, "Vectors of bool type are not supported."); return vkd3d_spirv_get_op_undef(builder, type_id); + + case VSIR_DATA_F16: + case VSIR_DATA_F32: + case VSIR_DATA_I32: + case VSIR_DATA_U16: + case VSIR_DATA_U32: + case VSIR_DATA_SNORM: + case VSIR_DATA_UNORM: + break; + default: spirv_compiler_error(compiler, VKD3D_SHADER_ERROR_SPV_INVALID_TYPE, - "Unhandled component_type %#x.", component_type); + "Unhandled data type \"%s\" (%#x).", + vsir_data_type_get_name(data_type, ""), data_type); return vkd3d_spirv_get_op_undef(builder, type_id); } if (component_count == 1) - { return vkd3d_spirv_get_op_constant(builder, type_id, *values); - } - else + + scalar_type_id = spirv_get_type_id(builder, data_type, 1); + for (i = 0; i < component_count; ++i) { - scalar_type_id = spirv_get_type_id_for_component_type(builder, component_type, 1); - for (i = 0; i < component_count; ++i) - component_ids[i] = vkd3d_spirv_get_op_constant(builder, scalar_type_id, values[i]); - return vkd3d_spirv_get_op_constant_composite(builder, type_id, component_ids, component_count); + component_ids[i] = vkd3d_spirv_get_op_constant(builder, scalar_type_id, values[i]); } + + return vkd3d_spirv_get_op_constant_composite(builder, type_id, component_ids, component_count); } static uint32_t spirv_compiler_get_constant64(struct spirv_compiler *compiler, - enum vkd3d_shader_component_type component_type, unsigned int component_count, const uint64_t *values) + enum vsir_data_type data_type, unsigned int component_count, const uint64_t *values) { uint32_t type_id, scalar_type_id, component_ids[VKD3D_DVEC2_SIZE]; struct vkd3d_spirv_builder *builder = &compiler->spirv_builder; unsigned int i; VKD3D_ASSERT(0 < component_count && component_count <= VKD3D_DVEC2_SIZE); - type_id = spirv_get_type_id_for_component_type(builder, component_type, component_count); + type_id = spirv_get_type_id(builder, data_type, component_count); - if (component_type != VKD3D_SHADER_COMPONENT_DOUBLE && component_type != VKD3D_SHADER_COMPONENT_INT64 - && component_type != VKD3D_SHADER_COMPONENT_UINT64) + if (data_type != VSIR_DATA_F64 && data_type != VSIR_DATA_I64 && data_type != VSIR_DATA_U64) { - FIXME("Unhandled component_type %#x.\n", component_type); + spirv_compiler_error(compiler, VKD3D_SHADER_ERROR_SPV_INVALID_TYPE, + "Unhandled data type \"%s\" (%#x).", + vsir_data_type_get_name(data_type, ""), data_type); return vkd3d_spirv_get_op_undef(builder, type_id); } if (component_count == 1) - { return vkd3d_spirv_get_op_constant64(builder, type_id, *values); - } - else + + scalar_type_id = spirv_get_type_id(builder, data_type, 1); + for (i = 0; i < component_count; ++i) { - scalar_type_id = spirv_get_type_id_for_component_type(builder, component_type, 1); - for (i = 0; i < component_count; ++i) - component_ids[i] = vkd3d_spirv_get_op_constant64(builder, scalar_type_id, values[i]); - return vkd3d_spirv_get_op_constant_composite(builder, type_id, component_ids, component_count); + component_ids[i] = vkd3d_spirv_get_op_constant64(builder, scalar_type_id, values[i]); } + + return vkd3d_spirv_get_op_constant_composite(builder, type_id, component_ids, component_count); } -static uint32_t spirv_compiler_get_constant_uint(struct spirv_compiler *compiler, - uint32_t value) +static uint32_t spirv_compiler_get_constant_uint(struct spirv_compiler *compiler, uint32_t value) { - return spirv_compiler_get_constant(compiler, VKD3D_SHADER_COMPONENT_UINT, 1, &value); + return spirv_compiler_get_constant(compiler, VSIR_DATA_U32, 1, &value); } -static uint32_t spirv_compiler_get_constant_float(struct spirv_compiler *compiler, - float value) +static uint32_t spirv_compiler_get_constant_float(struct spirv_compiler *compiler, float value) { - return spirv_compiler_get_constant(compiler, VKD3D_SHADER_COMPONENT_FLOAT, 1, (uint32_t *)&value); + return spirv_compiler_get_constant(compiler, VSIR_DATA_F32, 1, (uint32_t *)&value); } static uint32_t spirv_compiler_get_constant_vector(struct spirv_compiler *compiler, - enum vkd3d_shader_component_type component_type, unsigned int component_count, uint32_t value) + enum vsir_data_type data_type, unsigned int component_count, uint32_t value) { const uint32_t values[] = {value, value, value, value}; - return spirv_compiler_get_constant(compiler, component_type, component_count, values); + + return spirv_compiler_get_constant(compiler, data_type, component_count, values); } static uint32_t spirv_compiler_get_constant_uint_vector(struct spirv_compiler *compiler, uint32_t value, unsigned int component_count) { - return spirv_compiler_get_constant_vector(compiler, VKD3D_SHADER_COMPONENT_UINT, component_count, value); + return spirv_compiler_get_constant_vector(compiler, VSIR_DATA_U32, component_count, value); } static uint32_t spirv_compiler_get_constant_float_vector(struct spirv_compiler *compiler, float value, unsigned int component_count) { const float values[] = {value, value, value, value}; - return spirv_compiler_get_constant(compiler, VKD3D_SHADER_COMPONENT_FLOAT, - component_count, (const uint32_t *)values); + + return spirv_compiler_get_constant(compiler, VSIR_DATA_F32, component_count, (const uint32_t *)values); } static uint32_t spirv_compiler_get_constant_double_vector(struct spirv_compiler *compiler, double value, unsigned int component_count) { const double values[] = {value, value}; - return spirv_compiler_get_constant64(compiler, VKD3D_SHADER_COMPONENT_DOUBLE, - component_count, (const uint64_t *)values); + + return spirv_compiler_get_constant64(compiler, VSIR_DATA_F64, component_count, (const uint64_t *)values); } static uint32_t spirv_compiler_get_constant_uint64_vector(struct spirv_compiler *compiler, uint64_t value, unsigned int component_count) { const uint64_t values[] = {value, value}; - return spirv_compiler_get_constant64(compiler, VKD3D_SHADER_COMPONENT_UINT64, component_count, values); + + return spirv_compiler_get_constant64(compiler, VSIR_DATA_U64, component_count, values); } static uint32_t spirv_compiler_get_type_id_for_reg(struct spirv_compiler *compiler, @@ -4095,8 +4100,8 @@ static uint32_t spirv_compiler_emit_shader_parameter(struct spirv_compiler *comp type, component_count, name, parameter->data_type); if (parameter->type == VKD3D_SHADER_PARAMETER_TYPE_IMMEDIATE_CONSTANT) - return spirv_compiler_get_constant(compiler, vkd3d_component_type_from_data_type(type), - component_count, (const uint32_t *)¶meter->u.immediate_constant); + return spirv_compiler_get_constant(compiler, type, component_count, + (const uint32_t *)¶meter->u.immediate_constant); if (parameter->type == VKD3D_SHADER_PARAMETER_TYPE_SPECIALIZATION_CONSTANT) return spirv_compiler_get_spec_constant(compiler, name, @@ -4112,32 +4117,32 @@ default_parameter: } static uint32_t spirv_compiler_emit_construct_vector(struct spirv_compiler *compiler, - enum vkd3d_shader_component_type component_type, unsigned int component_count, - uint32_t val_id, unsigned int val_component_idx, unsigned int val_component_count) + enum vsir_data_type data_type, unsigned int component_count, uint32_t val_id, + unsigned int val_component_idx, unsigned int val_component_count) { struct vkd3d_spirv_builder *builder = &compiler->spirv_builder; uint32_t components[VKD3D_VEC4_SIZE]; - uint32_t type_id, result_id; + uint32_t type_id; unsigned int i; VKD3D_ASSERT(val_component_idx < val_component_count); - type_id = spirv_get_type_id_for_component_type(builder, component_type, component_count); + type_id = spirv_get_type_id(builder, data_type, component_count); if (val_component_count == 1) { for (i = 0; i < component_count; ++i) + { components[i] = val_id; - result_id = vkd3d_spirv_build_op_composite_construct(builder, - type_id, components, component_count); + } + return vkd3d_spirv_build_op_composite_construct(builder, type_id, components, component_count); } - else + + for (i = 0; i < component_count; ++i) { - for (i = 0; i < component_count; ++i) - components[i] = val_component_idx; - result_id = vkd3d_spirv_build_op_vector_shuffle(builder, - type_id, val_id, val_id, components, component_count); + components[i] = val_component_idx; } - return result_id; + + return vkd3d_spirv_build_op_vector_shuffle(builder, type_id, val_id, val_id, components, component_count); } static uint32_t spirv_compiler_emit_load_src(struct spirv_compiler *compiler, @@ -4588,8 +4593,7 @@ static uint32_t spirv_compiler_emit_load_constant(struct spirv_compiler *compile } } - return spirv_compiler_get_constant(compiler, - vkd3d_component_type_from_data_type(reg->data_type), component_count, values); + return spirv_compiler_get_constant(compiler, reg->data_type, component_count, values); } static uint32_t spirv_compiler_emit_load_constant64(struct spirv_compiler *compiler, @@ -4615,8 +4619,7 @@ static uint32_t spirv_compiler_emit_load_constant64(struct spirv_compiler *compi } } - return spirv_compiler_get_constant64(compiler, - vkd3d_component_type_from_data_type(reg->data_type), component_count, values); + return spirv_compiler_get_constant64(compiler, reg->data_type, component_count, values); } static uint32_t spirv_compiler_emit_load_undef(struct spirv_compiler *compiler, @@ -4699,12 +4702,10 @@ static uint32_t spirv_compiler_emit_constant_array(struct spirv_compiler *compil { uint32_t *elements, elem_type_id, length_id, type_id, const_id; struct vkd3d_spirv_builder *builder = &compiler->spirv_builder; - enum vkd3d_shader_component_type component_type; unsigned int i, element_count, component_count; element_count = icb->element_count; - component_type = vkd3d_component_type_from_data_type(icb->data_type); component_count = icb->component_count; elem_type_id = spirv_get_type_id(builder, icb->data_type, component_count); length_id = spirv_compiler_get_constant_uint(compiler, element_count); @@ -4721,7 +4722,6 @@ static uint32_t spirv_compiler_emit_constant_array(struct spirv_compiler *compil if (!(elements = vkd3d_calloc(element_count, sizeof(*elements)))) { - ERR("Failed to allocate %u elements.", element_count); spirv_compiler_error(compiler, VKD3D_SHADER_ERROR_SPV_OUT_OF_MEMORY, "Failed to allocate %u constant array elements.", element_count); return 0; @@ -4733,23 +4733,27 @@ static uint32_t spirv_compiler_emit_constant_array(struct spirv_compiler *compil case VSIR_DATA_I32: case VSIR_DATA_U32: for (i = 0; i < element_count; ++i) - elements[i] = spirv_compiler_get_constant(compiler, component_type, component_count, - &icb->data[component_count * i]); + { + elements[i] = spirv_compiler_get_constant(compiler, icb->data_type, + component_count, &icb->data[component_count * i]); + } break; + case VSIR_DATA_F64: case VSIR_DATA_I64: case VSIR_DATA_U64: { uint64_t *data = (uint64_t *)icb->data; for (i = 0; i < element_count; ++i) - elements[i] = spirv_compiler_get_constant64(compiler, component_type, component_count, - &data[component_count * i]); + elements[i] = spirv_compiler_get_constant64(compiler, icb->data_type, + component_count, &data[component_count * i]); break; } + default: - FIXME("Unhandled data type %u.\n", icb->data_type); spirv_compiler_error(compiler, VKD3D_SHADER_ERROR_SPV_INVALID_TYPE, - "Immediate constant buffer data type %u is unhandled.", icb->data_type); + "Immediate constant buffer data type \"%s\" (%#x) is unhandled.", + vsir_data_type_get_name(icb->data_type, ""), icb->data_type); break; } @@ -6252,7 +6256,7 @@ static void spirv_compiler_emit_store_shader_output(struct spirv_compiler *compi /* Set values to 0 for not initialized shader output components. */ write_mask |= uninit_mask; zero_id = spirv_compiler_get_constant_vector(compiler, - output_info->component_type, VKD3D_VEC4_SIZE, 0); + vsir_data_type_from_component_type(output_info->component_type), VKD3D_VEC4_SIZE, 0); val_id = spirv_compiler_emit_vector_shuffle(compiler, zero_id, val_id, swizzle, uninit_mask, output_info->component_type, vsir_write_mask_component_count(write_mask)); @@ -7758,7 +7762,7 @@ static enum vkd3d_result spirv_compiler_emit_alu_instruction(struct spirv_compil || instruction->opcode == VSIR_OP_ISHR || instruction->opcode == VSIR_OP_USHR)) { uint32_t mask_id = spirv_compiler_get_constant_vector(compiler, - VKD3D_SHADER_COMPONENT_UINT, vsir_write_mask_component_count(dst->write_mask), 0x1f); + VSIR_DATA_U32, vsir_write_mask_component_count(dst->write_mask), 0x1f); src_ids[1] = vkd3d_spirv_build_op_and(builder, type_id, src_ids[1], mask_id); } @@ -8044,13 +8048,13 @@ static void spirv_compiler_emit_dot(struct spirv_compiler *compiler, struct vkd3d_spirv_builder *builder = &compiler->spirv_builder; const struct vkd3d_shader_dst_param *dst = instruction->dst; const struct vkd3d_shader_src_param *src = instruction->src; - enum vkd3d_shader_component_type component_type; uint32_t type_id, val_id, src_ids[2]; unsigned int component_count, i; + enum vsir_data_type data_type; uint32_t write_mask; component_count = vsir_write_mask_component_count(dst->write_mask); - component_type = vkd3d_component_type_from_data_type(dst->reg.data_type); + data_type = dst->reg.data_type; if (instruction->opcode == VSIR_OP_DP4) write_mask = VKD3DSP_WRITEMASK_ALL; @@ -8063,15 +8067,12 @@ static void spirv_compiler_emit_dot(struct spirv_compiler *compiler, for (i = 0; i < ARRAY_SIZE(src_ids); ++i) src_ids[i] = spirv_compiler_emit_load_src(compiler, &src[i], write_mask); - type_id = spirv_get_type_id(builder, dst->reg.data_type, 1); + type_id = spirv_get_type_id(builder, data_type, 1); val_id = vkd3d_spirv_build_op_tr2(builder, &builder->function_stream, SpvOpDot, type_id, src_ids[0], src_ids[1]); if (component_count > 1) - { - val_id = spirv_compiler_emit_construct_vector(compiler, - component_type, component_count, val_id, 0, 1); - } + val_id = spirv_compiler_emit_construct_vector(compiler, data_type, component_count, val_id, 0, 1); if (instruction->flags & VKD3DSI_PRECISE_XYZW) vkd3d_spirv_build_op_decorate(builder, val_id, SpvDecorationNoContraction, NULL, 0); @@ -8128,7 +8129,6 @@ static void spirv_compiler_emit_ftoi(struct spirv_compiler *compiler, const struct vkd3d_shader_dst_param *dst = instruction->dst; const struct vkd3d_shader_src_param *src = instruction->src; uint32_t src_type_id, dst_type_id, condition_type_id; - enum vkd3d_shader_component_type component_type; unsigned int component_count; uint32_t write_mask; @@ -8160,9 +8160,8 @@ static void spirv_compiler_emit_ftoi(struct spirv_compiler *compiler, val_id = vkd3d_spirv_build_op_glsl_std450_max(builder, src_type_id, src_id, int_min_id); /* VSIR allows the destination of a signed conversion to be unsigned. */ - component_type = vkd3d_component_type_from_data_type(dst->reg.data_type); - int_max_id = spirv_compiler_get_constant_vector(compiler, component_type, component_count, INT_MAX); + int_max_id = spirv_compiler_get_constant_vector(compiler, dst->reg.data_type, component_count, INT_MAX); condition_type_id = spirv_get_type_id(builder, VSIR_DATA_BOOL, component_count); condition_id = vkd3d_spirv_build_op_tr2(builder, &builder->function_stream, SpvOpFOrdGreaterThanEqual, condition_type_id, val_id, float_max_id); @@ -8170,7 +8169,7 @@ static void spirv_compiler_emit_ftoi(struct spirv_compiler *compiler, val_id = vkd3d_spirv_build_op_tr1(builder, &builder->function_stream, SpvOpConvertFToS, dst_type_id, val_id); val_id = vkd3d_spirv_build_op_select(builder, dst_type_id, condition_id, int_max_id, val_id); - zero_id = spirv_compiler_get_constant_vector(compiler, component_type, component_count, 0); + zero_id = spirv_compiler_get_constant_vector(compiler, dst->reg.data_type, component_count, 0); condition_id = vkd3d_spirv_build_op_tr1(builder, &builder->function_stream, SpvOpIsNan, condition_type_id, src_id); val_id = vkd3d_spirv_build_op_select(builder, dst_type_id, condition_id, zero_id, val_id); @@ -8994,8 +8993,7 @@ static uint32_t spirv_compiler_emit_texel_offset(struct spirv_compiler *compiler int32_t data[4] = {offset->u, offset->v, offset->w, 0}; VKD3D_ASSERT(resource_type_info->dim != SpvDimCube); - return spirv_compiler_get_constant(compiler, - VKD3D_SHADER_COMPONENT_INT, component_count, (const uint32_t *)data); + return spirv_compiler_get_constant(compiler, VSIR_DATA_I32, component_count, (const uint32_t *)data); } static void spirv_compiler_emit_ld(struct spirv_compiler *compiler, @@ -9251,8 +9249,7 @@ static void spirv_compiler_emit_gather4(struct spirv_compiler *compiler, { component_idx = vsir_swizzle_get_component(sampler->swizzle, 0); /* Nvidia driver requires signed integer type. */ - component_id = spirv_compiler_get_constant(compiler, - VKD3D_SHADER_COMPONENT_INT, 1, &component_idx); + component_id = spirv_compiler_get_constant(compiler, VSIR_DATA_I32, 1, &component_idx); val_id = vkd3d_spirv_build_op_image_gather(builder, sampled_type_id, image.sampled_image_id, coordinate_id, component_id, operands_mask, image_operands, image_operand_count); @@ -9499,7 +9496,7 @@ static void spirv_compiler_emit_store_uav_raw_structured(struct spirv_compiler * for (component_idx = 0; component_idx < component_count; ++component_idx) { /* Mesa Vulkan drivers require the texel parameter to be a vector. */ - data_id = spirv_compiler_emit_construct_vector(compiler, VKD3D_SHADER_COMPONENT_UINT, + data_id = spirv_compiler_emit_construct_vector(compiler, VSIR_DATA_U32, VKD3D_VEC4_SIZE, val_id, component_idx, component_count); coordinate_id = base_coordinate_id; @@ -10158,10 +10155,10 @@ static void spirv_compiler_emit_sample_position(struct spirv_compiler *compiler, length_id = spirv_compiler_get_constant_uint(compiler, ARRAY_SIZE(standard_sample_positions)); array_type_id = vkd3d_spirv_get_op_type_array(builder, type_id, length_id); - for (i = 0; i < ARRAY_SIZE(standard_sample_positions); ++ i) + for (i = 0; i < ARRAY_SIZE(standard_sample_positions); ++i) { - constituents[i] = spirv_compiler_get_constant(compiler, - VKD3D_SHADER_COMPONENT_FLOAT, 2, (const uint32_t *)standard_sample_positions[i]); + constituents[i] = spirv_compiler_get_constant(compiler, VSIR_DATA_F32, + 2, (const uint32_t *)standard_sample_positions[i]); } id = vkd3d_spirv_build_op_constant_composite(builder, array_type_id, constituents, ARRAY_SIZE(constituents)); @@ -11092,8 +11089,7 @@ static int spirv_compiler_generate_spirv(struct spirv_compiler *compiler, { uint32_t type_id, struct_id, ptr_type_id, var_id; - type_id = spirv_get_type_id_for_component_type(builder, - vkd3d_component_type_from_data_type(parameter_data_type_map[parameter->data_type].type), + type_id = spirv_get_type_id(builder, parameter_data_type_map[parameter->data_type].type, parameter_data_type_map[parameter->data_type].component_count); struct_id = vkd3d_spirv_build_op_type_struct(builder, &type_id, 1); -- 2.51.0