[Mesa-dev] [PATCH v2 20/29] nir/large_constants: Properly handle 1-bit bools
Jason Ekstrand
jason at jlekstrand.net
Thu Dec 6 19:45:11 UTC 2018
---
src/compiler/nir/nir_opt_large_constants.c | 14 +++++++++++++-
src/compiler/nir_types.cpp | 2 +-
2 files changed, 14 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..5884fd0ac6b 100644
--- a/src/compiler/nir/nir_opt_large_constants.c
+++ b/src/compiler/nir/nir_opt_large_constants.c
@@ -53,7 +53,14 @@ 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 (bit_size < 8) {
+ /* We have to load at least a byte */
+ assert(glsl_type_is_boolean(deref->type));
+ load->dest.ssa.bit_size = 8;
+ return nir_i2b(b, &load->dest.ssa);
+ } else {
+ return &load->dest.ssa;
+ }
}
static void
@@ -74,6 +81,11 @@ 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:
+ for (unsigned i = 0; i < num_components; i++)
+ ((uint8_t *)dst)[i] = 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..bbf6af829f9 100644
--- a/src/compiler/nir_types.cpp
+++ b/src/compiler/nir_types.cpp
@@ -540,7 +540,7 @@ glsl_get_natural_size_align_bytes(const struct glsl_type *type,
case GLSL_TYPE_DOUBLE:
case GLSL_TYPE_UINT64:
case GLSL_TYPE_INT64: {
- unsigned N = glsl_get_bit_size(type) / 8;
+ unsigned N = DIV_ROUND_UP(glsl_get_bit_size(type), 8);
*size = N * type->components();
*align = N;
break;
--
2.19.2
More information about the mesa-dev
mailing list