diff --git a/src/compiler/nir/nir_opcodes.py b/src/compiler/nir/nir_opcodes.py index 469db95a2e2..196d285e570 100644 --- a/src/compiler/nir/nir_opcodes.py +++ b/src/compiler/nir/nir_opcodes.py @@ -339,6 +339,19 @@ unop_numeric_convert_mp("u2f", tfloat16, tuint32) unop_numeric_convert("f2i32_rtne", tint32, tfloat32, "(int32_t)_mesa_roundevenf(src0)") +# Note: 64-bit integers are intentionally not supported. Casting u_uintN_max +# (and related signed values) to double is precisely representable for upto +# 32-bit integers. To support these opcodes for 64-bit integers would require +# a more complex implementation. +for bits in (8, 16, 32): + unop_numeric_convert(f"f2u{bits}_sat", f"uint{bits}", tfloat, + f"(uint{bits}_t)fmin(fmax(src0, 0.0), (double)u_uintN_max({bits}))", + "Convert float to uint with clamping to uint range. NaN becomes zero.") + + unop_numeric_convert(f"f2i{bits}_sat", f"int{bits}", tfloat, + f"(int{bits}_t) isnan(src0) ? 0.0 : fmin(fmax(src0, (double)u_intN_min({bits})), (double)u_intN_max({bits}))", + "Convert float to int with clamping to int range. NaN becomes zero.") + # Unary floating-point rounding operations. diff --git a/src/compiler/nir/nir_shader_compiler_options.h b/src/compiler/nir/nir_shader_compiler_options.h index 9d66b3d4e3f..8e69ad8125d 100644 --- a/src/compiler/nir/nir_shader_compiler_options.h +++ b/src/compiler/nir/nir_shader_compiler_options.h @@ -486,6 +486,19 @@ typedef struct nir_shader_compiler_options { */ bool lower_bfloat16_conversions; + /** + * Set if f2u_sat (or f2i_sat) is supported for converting from 16-, 32-, + * or 64-bit float types to 8-, 16-, or 32-bit integer types (with small + * exceptions). + * + * Due to the prevalence of drivers using \c nir_split_conversion for + * conversions from 64-bit float to 8-bit integer, these flags will not + * enable generation of f2u_sat from 64-bit float types to 8-bit integer + * types. + */ + bool has_f2u_sat; + bool has_f2i_sat; + bool vectorize_tess_levels; bool lower_to_scalar; nir_instr_filter_cb lower_to_scalar_filter;