From e19ccb00f2cd03060c62479131aafe7ba635c751 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Wed, 9 Apr 2025 13:40:24 +0200 Subject: [PATCH] spirv: support float8 conversions Reviewed-by: Rhys Perry Part-of: --- src/compiler/spirv/vtn_alu.c | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/compiler/spirv/vtn_alu.c b/src/compiler/spirv/vtn_alu.c index 097bc5bf95c..1a4d89c9ed8 100644 --- a/src/compiler/spirv/vtn_alu.c +++ b/src/compiler/spirv/vtn_alu.c @@ -683,6 +683,7 @@ vtn_handle_convert(struct vtn_builder *b, SpvOp opcode, * * For now we are limiting exposure of bfloat16 in NIR, so apply the * extra conversions directly here. + * The same applies to E4M3 and E5M2. */ if (glsl_type_is_bfloat_16(glsl_src_type)) { nir_def *src_as_float = nir_bf2f(&b->nb, src); @@ -699,6 +700,42 @@ vtn_handle_convert(struct vtn_builder *b, SpvOp opcode, src_as_float = vtn_handle_convert(b, opcode, dest_val, glsl_float_type(), glsl_src_type, src); return nir_f2bf(&b->nb, src_as_float); + } else if (glsl_type_is_e4m3fn(glsl_src_type)) { + nir_def *src_as_float = nir_e4m3fn2f(&b->nb, src); + if (glsl_type_is_float(glsl_dest_type)) + return src_as_float; + return vtn_handle_convert(b, opcode, dest_val, glsl_dest_type, + glsl_float_type(), src_as_float); + + } else if (glsl_type_is_e4m3fn(glsl_dest_type)) { + nir_def *src_as_float; + if (glsl_type_is_float(glsl_src_type)) + src_as_float = src; + else + src_as_float = vtn_handle_convert(b, opcode, dest_val, glsl_float_type(), + glsl_src_type, src); + if (vtn_has_decoration(b, dest_val, SpvDecorationSaturatedToLargestFloat8NormalConversionEXT)) + return nir_f2e4m3fn_sat(&b->nb, src_as_float); + else + return nir_f2e4m3fn(&b->nb, src_as_float); + } else if (glsl_type_is_e5m2(glsl_src_type)) { + nir_def *src_as_float = nir_e5m22f(&b->nb, src); + if (glsl_type_is_float(glsl_dest_type)) + return src_as_float; + return vtn_handle_convert(b, opcode, dest_val, glsl_dest_type, + glsl_float_type(), src_as_float); + + } else if (glsl_type_is_e5m2(glsl_dest_type)) { + nir_def *src_as_float; + if (glsl_type_is_float(glsl_src_type)) + src_as_float = src; + else + src_as_float = vtn_handle_convert(b, opcode, dest_val, glsl_float_type(), + glsl_src_type, src); + if (vtn_has_decoration(b, dest_val, SpvDecorationSaturatedToLargestFloat8NormalConversionEXT)) + return nir_f2e5m2_sat(&b->nb, src_as_float); + else + return nir_f2e5m2(&b->nb, src_as_float); } /* Use bit_size from NIR source instead of from the original src type,