Mesa (master): nir/large_constants: Properly handle 1-bit bools

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sun Dec 16 21:03:24 UTC 2018


Module: Mesa
Branch: master
Commit: 487514ae6120fd66d6b58cddea1c27b5fe8573e5
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=487514ae6120fd66d6b58cddea1c27b5fe8573e5

Author: Jason Ekstrand <jason.ekstrand at intel.com>
Date:   Thu Dec  6 11:20:26 2018 -0600

nir/large_constants: Properly handle 1-bit bools

Reviewed-by: Eric Anholt <eric at anholt.net>
Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Tested-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>

---

 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 634913aa9e..aa22f05d80 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 3cd61f6605..c8906dc695 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: {




More information about the mesa-commit mailing list