From 36012af17fc2d8445a4f84dfb603e44369143822 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Wed, 6 Dec 2023 02:29:27 +0100 Subject: [PATCH] nir/printf: remove treat_doubles_as_floats It is broken and clang uses fp32 for float constants if the fp64 extension isn't enabled anyway. SPIRVs can't use fp64 constants with printf unless they enable the Float64 cap, which also requires cl_khr_fp64 to be supported. So just remove it and rely on clang handling -cl-single-precision-constant correctly, which at the moment doesn't seem to be the case, but we can think about that once we plan to support cl_khr_fp64. Signed-off-by: Karol Herbst Reviewed-by: Jesse Natalie Part-of: --- src/compiler/nir/nir.h | 1 - src/compiler/nir/nir_lower_printf.c | 12 ------------ src/gallium/frontends/clover/nir/invocation.cpp | 1 - src/gallium/frontends/rusticl/core/kernel.rs | 6 +++--- src/microsoft/clc/clc_compiler.c | 1 - 5 files changed, 3 insertions(+), 18 deletions(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 86df5f52f3d..4c29e35c12f 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -6243,7 +6243,6 @@ bool nir_lower_ssbo(nir_shader *shader); bool nir_lower_helper_writes(nir_shader *shader, bool lower_plain_stores); typedef struct nir_lower_printf_options { - bool treat_doubles_as_floats : 1; unsigned max_buffer_size; } nir_lower_printf_options; diff --git a/src/compiler/nir/nir_lower_printf.c b/src/compiler/nir/nir_lower_printf.c index db338fb0bfe..55d1162a356 100644 --- a/src/compiler/nir/nir_lower_printf.c +++ b/src/compiler/nir/nir_lower_printf.c @@ -93,18 +93,6 @@ lower_printf_intrin(nir_builder *b, nir_intrinsic_instr *prntf, void *_options) nir_def *arg = nir_load_deref(b, arg_deref); const struct glsl_type *arg_type = arg_deref->type; - /* Clang does promotion of arguments to their "native" size. That means - * that any floats have been converted to doubles for the call to - * printf. Since doubles are optional, some drivers might not support - * them. For those drivers, convert them back to float before writing. - * Copy prop and other optimizations should remove all hints of doubles. - */ - if (glsl_get_base_type(arg_type) == GLSL_TYPE_DOUBLE && - options && options->treat_doubles_as_floats) { - arg = nir_f2f32(b, arg); - arg_type = glsl_float_type(); - } - unsigned field_offset = glsl_get_struct_field_offset(args->type, i); nir_def *arg_offset = nir_i2iN(b, nir_iadd_imm(b, offset, fmt_str_id_size + field_offset), diff --git a/src/gallium/frontends/clover/nir/invocation.cpp b/src/gallium/frontends/clover/nir/invocation.cpp index 038b234b3ae..b5e18fbe21c 100644 --- a/src/gallium/frontends/clover/nir/invocation.cpp +++ b/src/gallium/frontends/clover/nir/invocation.cpp @@ -325,7 +325,6 @@ binary clover::nir::spirv_to_nir(const binary &mod, const device &dev, NIR_PASS_V(nir, nir_lower_variable_initializers, ~nir_var_function_temp); struct nir_lower_printf_options printf_options; - printf_options.treat_doubles_as_floats = false; printf_options.max_buffer_size = dev.max_printf_buffer_size(); NIR_PASS_V(nir, nir_lower_printf, &printf_options); diff --git a/src/gallium/frontends/rusticl/core/kernel.rs b/src/gallium/frontends/rusticl/core/kernel.rs index 73ebcbb1ff1..b32c07209e4 100644 --- a/src/gallium/frontends/rusticl/core/kernel.rs +++ b/src/gallium/frontends/rusticl/core/kernel.rs @@ -448,9 +448,9 @@ fn lower_and_optimize_nir( nir_pass!(nir, nir_dedup_inline_samplers); - let mut printf_opts = nir_lower_printf_options::default(); - printf_opts.set_treat_doubles_as_floats(false); - printf_opts.max_buffer_size = dev.printf_buffer_size() as u32; + let printf_opts = nir_lower_printf_options { + max_buffer_size: dev.printf_buffer_size() as u32, + }; nir_pass!(nir, nir_lower_printf, &printf_opts); opt_nir(nir, dev, false); diff --git a/src/microsoft/clc/clc_compiler.c b/src/microsoft/clc/clc_compiler.c index b3ef8b33aab..d8f18129630 100644 --- a/src/microsoft/clc/clc_compiler.c +++ b/src/microsoft/clc/clc_compiler.c @@ -772,7 +772,6 @@ clc_spirv_to_dxil(struct clc_libclc *lib, NIR_PASS_V(nir, nir_lower_vars_to_explicit_types, nir_var_function_temp, glsl_get_cl_type_size_align); nir_lower_printf_options printf_options = { - .treat_doubles_as_floats = true, .max_buffer_size = 1024 * 1024 }; NIR_PASS_V(nir, nir_lower_printf, &printf_options);