From b88be5b92bf3a5194643c1fdfa1a41397d084708 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Tue, 22 Jul 2025 20:49:15 +0200 Subject: [PATCH] vkd3d-shader/ir: Consistently use VSIR_DATA_U32 for sample_info_uint destination operands. The HLSL compiler already did this; the TPF and DXIL parsers did not. Previously spirv_compiler_emit_sample_info() was unable to correctly handle VSIR_DATA_U32 destinations; the new version is arguably simpler as well. --- libs/vkd3d-shader/dxil.c | 2 +- libs/vkd3d-shader/spirv.c | 13 +++++++------ libs/vkd3d-shader/tpf.c | 3 +++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/libs/vkd3d-shader/dxil.c b/libs/vkd3d-shader/dxil.c index f83145a60..66e3c1ecd 100644 --- a/libs/vkd3d-shader/dxil.c +++ b/libs/vkd3d-shader/dxil.c @@ -6009,7 +6009,7 @@ static void sm6_parser_emit_dx_get_sample_count(struct sm6_parser *sm6, enum dx_ src_param_init(src_param); instruction_dst_param_init_ssa_scalar(ins, sm6); - ins->dst->reg.data_type = VSIR_DATA_F32; + ins->dst->reg.data_type = VSIR_DATA_U32; } static void sm6_parser_emit_dx_get_sample_pos(struct sm6_parser *sm6, enum dx_intrinsic_opcode op, diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index c670dce96..b6ebffe77 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -10015,6 +10015,7 @@ static uint32_t spirv_compiler_emit_query_sample_count(struct spirv_compiler *co static void spirv_compiler_emit_sample_info(struct spirv_compiler *compiler, const struct vkd3d_shader_instruction *instruction) { + enum vkd3d_shader_component_type component_type = VKD3D_SHADER_COMPONENT_UINT; 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; @@ -10034,14 +10035,14 @@ static void spirv_compiler_emit_sample_info(struct spirv_compiler *compiler, type_id = vkd3d_spirv_get_type_id(builder, VKD3D_SHADER_COMPONENT_UINT, VKD3D_VEC4_SIZE); val_id = vkd3d_spirv_build_op_composite_construct(builder, type_id, constituents, VKD3D_VEC4_SIZE); - type_id = vkd3d_spirv_get_type_id(builder, VKD3D_SHADER_COMPONENT_FLOAT, VKD3D_VEC4_SIZE); - if (instruction->flags == VKD3DSI_SAMPLE_INFO_UINT) - val_id = vkd3d_spirv_build_op_bitcast(builder, type_id, val_id); - else + if (!(instruction->flags & VKD3DSI_SAMPLE_INFO_UINT)) + { + component_type = VKD3D_SHADER_COMPONENT_FLOAT; + type_id = vkd3d_spirv_get_type_id(builder, component_type, VKD3D_VEC4_SIZE); val_id = vkd3d_spirv_build_op_convert_utof(builder, type_id, val_id); - + } val_id = spirv_compiler_emit_swizzle(compiler, val_id, VKD3DSP_WRITEMASK_ALL, - VKD3D_SHADER_COMPONENT_FLOAT, src->swizzle, dst->write_mask); + component_type, src->swizzle, dst->write_mask); spirv_compiler_emit_store_dst(compiler, dst, val_id); } diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index e3993ea74..8e9dbcd25 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -2742,6 +2742,9 @@ static void shader_sm4_read_instruction(struct vkd3d_shader_sm4_parser *sm4, str } } + if (ins->opcode == VSIR_OP_SAMPLE_INFO && ins->flags & VKD3DSI_SAMPLE_INFO_UINT) + ins->dst[0].reg.data_type = VSIR_DATA_U32; + return; fail: