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 <kherbst@redhat.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26541>
This commit is contained in:
Karol Herbst 2023-12-06 02:29:27 +01:00
parent d2b08f9437
commit 36012af17f
5 changed files with 3 additions and 18 deletions

View file

@ -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;

View file

@ -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),

View file

@ -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);

View file

@ -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);

View file

@ -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);