nir/large_constants: Properly handle 1-bit bools

Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Tested-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
This commit is contained in:
Jason Ekstrand 2018-12-06 11:20:26 -06:00 committed by Jason Ekstrand
parent 3191a82372
commit 487514ae61
2 changed files with 31 additions and 2 deletions

View file

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

View file

@ -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: {