From f04287c0be2dfd0d6e50c0e3c8b4fb5f5a271a0e Mon Sep 17 00:00:00 2001 From: Maaz Mombasawala Date: Wed, 19 Feb 2025 15:14:52 -0800 Subject: [PATCH] svga: Check float type when emitting atomic instructions When translating atomic instructions, the base type of the imageView can be float only for image_atomic_exchange. If a float type image is used with other atomic instructions the results are undefined. Enforce this check in the shader translator and don't emit any instruction if it fails. Fixes crash in piglit test arb_shader_image_load_store@invalid. Signed-off-by: Maaz Mombasawala Part-of: --- src/gallium/drivers/svga/svga_tgsi_vgpu10.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/gallium/drivers/svga/svga_tgsi_vgpu10.c b/src/gallium/drivers/svga/svga_tgsi_vgpu10.c index 41e7f9dd7e5..3176e85e690 100644 --- a/src/gallium/drivers/svga/svga_tgsi_vgpu10.c +++ b/src/gallium/drivers/svga/svga_tgsi_vgpu10.c @@ -10793,6 +10793,17 @@ emit_atomic(struct svga_shader_emitter_v10 *emit, emit->cur_atomic_opcode = opcode; + /* Float types are only supported for image atomic exchange instruction, + * if this check fails then don't emit any intruction. + */ + if (resourceType == TGSI_FILE_IMAGE && + emit->key.images[resourceIndex].return_type == VGPU10_RETURN_TYPE_FLOAT && + opcode != VGPU10_OPCODE_IMM_ATOMIC_EXCH) { + debug_printf("Unexpected atomic TGSI opcode %s with float type image.", + tgsi_get_opcode_name(inst->Instruction.Opcode)); + return true; + } + /* If the resource register has indirect index, we will need * to expand it since SM5 device does not support indirect indexing * for uav.