}
if (var->constant_initializer) {
- fprintf(fp, " = { ");
- print_constant(var->constant_initializer, var->type, state);
- fprintf(fp, " }");
+ if (var->constant_initializer->is_null_constant) {
+ fprintf(fp, " = null");
+ } else {
+ fprintf(fp, " = { ");
+ print_constant(var->constant_initializer, var->type, state);
+ fprintf(fp, " }");
+ }
}
if (glsl_type_is_sampler(var->type) && var->data.sampler.is_inline_sampler) {
fprintf(fp, " = { %s, %s, %s }",
{
nir_constant *c = ralloc(nvar, nir_constant);
+ static const nir_const_value zero_vals[ARRAY_SIZE(c->values)] = { 0 };
blob_copy_bytes(ctx->blob, (uint8_t *)c->values, sizeof(c->values));
+ c->is_null_constant = memcmp(c->values, zero_vals, sizeof(c->values)) == 0;
c->num_elements = blob_read_uint32(ctx->blob);
c->elements = ralloc_array(nvar, nir_constant *, c->num_elements);
- for (unsigned i = 0; i < c->num_elements; i++)
+ for (unsigned i = 0; i < c->num_elements; i++) {
c->elements[i] = read_constant(ctx, nvar);
+ c->is_null_constant &= c->elements[i]->is_null_constant;
+ }
return c;
}
static void
validate_const_value(nir_const_value *val, unsigned bit_size,
- validate_state *state)
+ bool is_null_constant, validate_state *state)
{
/* In order for block copies to work properly for things like instruction
* comparisons and [de]serialization, we require the unused bits of the
*/
nir_const_value cmp_val;
memset(&cmp_val, 0, sizeof(cmp_val));
- switch (bit_size) {
- case 1:
- cmp_val.b = val->b;
- break;
- case 8:
- cmp_val.u8 = val->u8;
- break;
- case 16:
- cmp_val.u16 = val->u16;
- break;
- case 32:
- cmp_val.u32 = val->u32;
- break;
- case 64:
- cmp_val.u64 = val->u64;
- break;
- default:
- validate_assert(state, !"Invalid load_const bit size");
+ if (!is_null_constant) {
+ switch (bit_size) {
+ case 1:
+ cmp_val.b = val->b;
+ break;
+ case 8:
+ cmp_val.u8 = val->u8;
+ break;
+ case 16:
+ cmp_val.u16 = val->u16;
+ break;
+ case 32:
+ cmp_val.u32 = val->u32;
+ break;
+ case 64:
+ cmp_val.u64 = val->u64;
+ break;
+ default:
+ validate_assert(state, !"Invalid load_const bit size");
+ }
}
validate_assert(state, memcmp(val, &cmp_val, sizeof(cmp_val)) == 0);
}
validate_ssa_def(&instr->def, state);
for (unsigned i = 0; i < instr->def.num_components; i++)
- validate_const_value(&instr->value[i], instr->def.bit_size, state);
+ validate_const_value(&instr->value[i], instr->def.bit_size, false, state);
}
static void
unsigned num_components = glsl_get_vector_elements(type);
unsigned bit_size = glsl_get_bit_size(type);
for (unsigned i = 0; i < num_components; i++)
- validate_const_value(&c->values[i], bit_size, state);
+ validate_const_value(&c->values[i], bit_size, c->is_null_constant, state);
for (unsigned i = num_components; i < NIR_MAX_VEC_COMPONENTS; i++)
validate_assert(state, c->values[i].u64 == 0);
} else {
for (unsigned i = 0; i < c->num_elements; i++) {
const struct glsl_type *elem_type = glsl_get_struct_field(type, i);
validate_constant(c->elements[i], elem_type, state);
+ validate_assert(state, !c->is_null_constant || c->elements[i]->is_null_constant);
}
} else if (glsl_type_is_array_or_matrix(type)) {
const struct glsl_type *elem_type = glsl_get_array_element(type);
- for (unsigned i = 0; i < c->num_elements; i++)
+ for (unsigned i = 0; i < c->num_elements; i++) {
validate_constant(c->elements[i], elem_type, state);
+ validate_assert(state, !c->is_null_constant || c->elements[i]->is_null_constant);
+ }
} else {
validate_assert(state, !"Invalid type for nir_constant");
}