From 487514ae6120fd66d6b58cddea1c27b5fe8573e5 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Thu, 6 Dec 2018 11:20:26 -0600 Subject: [PATCH] nir/large_constants: Properly handle 1-bit bools Reviewed-by: Eric Anholt Reviewed-by: Bas Nieuwenhuizen Tested-by: Bas Nieuwenhuizen --- src/compiler/nir/nir_opt_large_constants.c | 24 +++++++++++++++++++++- src/compiler/nir_types.cpp | 9 +++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/compiler/nir/nir_opt_large_constants.c b/src/compiler/nir/nir_opt_large_constants.c index 634913aa9e5..aa22f05d809 100644 --- a/src/compiler/nir/nir_opt_large_constants.c +++ b/src/compiler/nir/nir_opt_large_constants.c @@ -53,7 +53,23 @@ build_constant_load(nir_builder *b, nir_deref_instr *deref, num_components, bit_size, NULL); nir_builder_instr_insert(b, &load->instr); - return &load->dest.ssa; + if (load->dest.ssa.bit_size < 8) { + /* Booleans are special-cased to be 32-bit + * + * Ideally, for drivers that can handle 32-bit booleans, we wouldn't + * emit the i2b here. However, at this point, the driver is likely to + * still have 1-bit booleans so we need to at least convert bit sizes. + * Unfortunately, we don't have a good way to annotate the load as + * loading a known boolean value so the optimizer isn't going to be + * able to get rid of the conversion. Some day, we may solve that + * problem but not today. + */ + assert(glsl_type_is_boolean(deref->type)); + load->dest.ssa.bit_size = 32; + return nir_i2b(b, &load->dest.ssa); + } else { + return &load->dest.ssa; + } } static void @@ -74,6 +90,12 @@ handle_constant_store(nir_builder *b, nir_intrinsic_instr *store, nir_const_value *val = nir_src_as_const_value(store->src[1]); switch (bit_size) { + case 1: + /* Booleans are special-cased to be 32-bit */ + for (unsigned i = 0; i < num_components; i++) + ((int32_t *)dst)[i] = -(int)val->b[i]; + break; + case 8: for (unsigned i = 0; i < num_components; i++) ((uint8_t *)dst)[i] = val->u8[i]; diff --git a/src/compiler/nir_types.cpp b/src/compiler/nir_types.cpp index 3cd61f66056..c8906dc6954 100644 --- a/src/compiler/nir_types.cpp +++ b/src/compiler/nir_types.cpp @@ -528,6 +528,14 @@ glsl_get_natural_size_align_bytes(const struct glsl_type *type, unsigned *size, unsigned *align) { switch (type->base_type) { + case GLSL_TYPE_BOOL: + /* We special-case Booleans to 32 bits to not cause heartburn for + * drivers that suddenly get an 8-bit load. + */ + *size = 4 * type->components(); + *align = 4; + break; + case GLSL_TYPE_UINT8: case GLSL_TYPE_INT8: case GLSL_TYPE_UINT16: @@ -536,7 +544,6 @@ glsl_get_natural_size_align_bytes(const struct glsl_type *type, case GLSL_TYPE_UINT: case GLSL_TYPE_INT: case GLSL_TYPE_FLOAT: - case GLSL_TYPE_BOOL: case GLSL_TYPE_DOUBLE: case GLSL_TYPE_UINT64: case GLSL_TYPE_INT64: { -- 2.30.2