From: Conor McCarthy cmccarthy@codeweavers.com
Storing width info in enum vkd3d_data_type makes a separate code path unnecessary. --- libs/vkd3d-shader/spirv.c | 69 ++++++++------------------------------- 1 file changed, 13 insertions(+), 56 deletions(-)
diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index d327ad27..0170a180 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -1120,34 +1120,19 @@ static uint32_t vkd3d_spirv_get_op_type_pointer(struct vkd3d_spirv_builder *buil vkd3d_spirv_build_op_type_pointer); }
-/* Types larger than 32-bits are not supported. */ static uint32_t vkd3d_spirv_build_op_constant(struct vkd3d_spirv_builder *builder, - uint32_t result_type, uint32_t value) -{ - return vkd3d_spirv_build_op_tr1(builder, &builder->global_stream, - SpvOpConstant, result_type, value); -} - -static uint32_t vkd3d_spirv_get_op_constant(struct vkd3d_spirv_builder *builder, - uint32_t result_type, uint32_t value) -{ - return vkd3d_spirv_build_once2(builder, SpvOpConstant, result_type, value, - vkd3d_spirv_build_op_constant); -} - -static uint32_t vkd3d_spirv_build_op_constant64(struct vkd3d_spirv_builder *builder, uint32_t result_type, const uint32_t *values, unsigned int value_count) { - assert(value_count == 2); + assert(0 < value_count && value_count <= 2); return vkd3d_spirv_build_op_trv(builder, &builder->global_stream, SpvOpConstant, result_type, values, value_count); }
-static uint32_t vkd3d_spirv_get_op_constant64(struct vkd3d_spirv_builder *builder, - uint32_t result_type, uint64_t value) +static uint32_t vkd3d_spirv_get_op_constant(struct vkd3d_spirv_builder *builder, + uint32_t result_type, const uint32_t *values, unsigned int value_count) { return vkd3d_spirv_build_once1v(builder, SpvOpConstant, result_type, - (const uint32_t *)&value, 2, vkd3d_spirv_build_op_constant64); + values, value_count, vkd3d_spirv_build_op_constant); }
static uint32_t vkd3d_spirv_build_op_constant_composite(struct vkd3d_spirv_builder *builder, @@ -2765,55 +2750,28 @@ static uint32_t spirv_compiler_get_constant(struct spirv_compiler *compiler, { uint32_t type_id, scalar_type_id, component_ids[VKD3D_VEC4_SIZE]; struct vkd3d_spirv_builder *builder = &compiler->spirv_builder; - unsigned int i; + unsigned int i, j, width, value_count;
assert(0 < component_count && component_count <= VKD3D_VEC4_SIZE); type_id = vkd3d_spirv_get_type_id(builder, data_type, component_count);
- if (!data_type_is_numeric(data_type) || data_type_get_width(data_type) != 32) + if (!data_type_is_numeric(data_type)) { FIXME("Unhandled data type %#x.\n", data_type); return vkd3d_spirv_build_op_undef(builder, &builder->global_stream, type_id); }
+ width = data_type_get_width(data_type); + value_count = max(width, 32u) / 32u; if (component_count == 1) { - return vkd3d_spirv_get_op_constant(builder, type_id, *values); + return vkd3d_spirv_get_op_constant(builder, type_id, values, value_count); } else { scalar_type_id = vkd3d_spirv_get_type_id(builder, data_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); - } -} - -static uint32_t spirv_compiler_get_constant64(struct spirv_compiler *compiler, - enum vkd3d_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; - - assert(0 < component_count && component_count <= VKD3D_DVEC2_SIZE); - type_id = vkd3d_spirv_get_type_id(builder, data_type, component_count); - - if (data_type != VKD3D_DATA_DOUBLE) - { - FIXME("Unhandled data_type %#x.\n", data_type); - return vkd3d_spirv_build_op_undef(builder, &builder->global_stream, type_id); - } - - if (component_count == 1) - { - return vkd3d_spirv_get_op_constant64(builder, type_id, *values); - } - else - { - scalar_type_id = vkd3d_spirv_get_type_id(builder, data_type, 1); - for (i = 0; i < component_count; ++i) - component_ids[i] = vkd3d_spirv_get_op_constant64(builder, scalar_type_id, values[i]); + for (i = 0, j = 0; i < component_count; ++i, j += value_count) + component_ids[i] = vkd3d_spirv_get_op_constant(builder, scalar_type_id, &values[j], value_count); return vkd3d_spirv_get_op_constant_composite(builder, type_id, component_ids, component_count); } } @@ -2854,8 +2812,7 @@ static uint32_t spirv_compiler_get_constant_double_vector(struct spirv_compiler double value, unsigned int component_count) { const double values[] = {value, value}; - return spirv_compiler_get_constant64(compiler, VKD3D_DATA_DOUBLE, - component_count, (const uint64_t *)values); + return spirv_compiler_get_constant(compiler, VKD3D_DATA_DOUBLE, component_count, (const uint32_t *)values); }
static uint32_t spirv_compiler_get_type_id_for_reg(struct spirv_compiler *compiler, @@ -3535,7 +3492,7 @@ static uint32_t spirv_compiler_emit_load_constant64(struct spirv_compiler *compi } }
- return spirv_compiler_get_constant64(compiler, reg->data_type, component_count, values); + return spirv_compiler_get_constant(compiler, reg->data_type, component_count, (const uint32_t *)values); }
static uint32_t spirv_compiler_emit_load_scalar(struct spirv_compiler *compiler,