spirv: Replace assert with vtn_assert

Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Ian Romanick <idr@freedesktop.org>
This commit is contained in:
Jason Ekstrand
2017-08-16 17:38:13 -07:00
parent 94ca8e04ad
commit b7ef60d846
5 changed files with 251 additions and 249 deletions

View File

@@ -71,14 +71,14 @@ vtn_access_chain_pointer_dereference(struct vtn_builder *b,
* pointers. For everything else, the client is expected to just pass us
* the right access chain.
*/
assert(!deref_chain->ptr_as_array);
vtn_assert(!deref_chain->ptr_as_array);
unsigned start = base->chain ? base->chain->length : 0;
for (unsigned i = 0; i < deref_chain->length; i++) {
chain->link[start + i] = deref_chain->link[i];
if (glsl_type_is_struct(type->type)) {
assert(deref_chain->link[i].mode == vtn_access_mode_literal);
vtn_assert(deref_chain->link[i].mode == vtn_access_mode_literal);
type = type->members[deref_chain->link[i].id];
} else {
type = type->array_element;
@@ -98,7 +98,7 @@ static nir_ssa_def *
vtn_access_link_as_ssa(struct vtn_builder *b, struct vtn_access_link link,
unsigned stride)
{
assert(stride > 0);
vtn_assert(stride > 0);
if (link.mode == vtn_access_mode_literal) {
return nir_imm_int(&b->nb, link.id * stride);
} else if (stride == 1) {
@@ -119,7 +119,7 @@ vtn_variable_resource_index(struct vtn_builder *b, struct vtn_variable *var,
nir_ssa_def *desc_array_index)
{
if (!desc_array_index) {
assert(glsl_type_is_struct(var->type->type));
vtn_assert(glsl_type_is_struct(var->type->type));
desc_array_index = nir_imm_int(&b->nb, 0);
}
@@ -148,11 +148,11 @@ vtn_ssa_offset_pointer_dereference(struct vtn_builder *b,
unsigned idx = 0;
if (deref_chain->ptr_as_array) {
/* We need ptr_type for the stride */
assert(base->ptr_type);
vtn_assert(base->ptr_type);
/* This must be a pointer to an actual element somewhere */
assert(block_index && offset);
vtn_assert(block_index && offset);
/* We need at least one element in the chain */
assert(deref_chain->length >= 1);
vtn_assert(deref_chain->length >= 1);
nir_ssa_def *elem_offset =
vtn_access_link_as_ssa(b, deref_chain->link[idx],
@@ -162,10 +162,10 @@ vtn_ssa_offset_pointer_dereference(struct vtn_builder *b,
}
if (!block_index) {
assert(base->var);
vtn_assert(base->var);
if (glsl_type_is_array(type->type)) {
/* We need at least one element in the chain */
assert(deref_chain->length >= 1);
vtn_assert(deref_chain->length >= 1);
nir_ssa_def *desc_arr_idx =
vtn_access_link_as_ssa(b, deref_chain->link[0], 1);
@@ -177,10 +177,10 @@ vtn_ssa_offset_pointer_dereference(struct vtn_builder *b,
}
/* This is the first access chain so we also need an offset */
assert(!offset);
vtn_assert(!offset);
offset = nir_imm_int(&b->nb, 0);
}
assert(offset);
vtn_assert(offset);
for (; idx < deref_chain->length; idx++) {
switch (glsl_get_base_type(type->type)) {
@@ -200,7 +200,7 @@ vtn_ssa_offset_pointer_dereference(struct vtn_builder *b,
}
case GLSL_TYPE_STRUCT: {
assert(deref_chain->link[idx].mode == vtn_access_mode_literal);
vtn_assert(deref_chain->link[idx].mode == vtn_access_mode_literal);
unsigned member = deref_chain->link[idx].id;
nir_ssa_def *mem_offset = nir_imm_int(&b->nb, type->offsets[member]);
offset = nir_iadd(&b->nb, offset, mem_offset);
@@ -240,13 +240,14 @@ vtn_pointer_dereference(struct vtn_builder *b,
* tail_type. This is useful for split structures.
*/
static void
rewrite_deref_types(nir_deref *deref, const struct glsl_type *type)
rewrite_deref_types(struct vtn_builder *b, nir_deref *deref,
const struct glsl_type *type)
{
deref->type = type;
if (deref->child) {
assert(deref->child->deref_type == nir_deref_type_array);
assert(glsl_type_is_array(deref->type));
rewrite_deref_types(deref->child, glsl_get_array_element(type));
vtn_assert(deref->child->deref_type == nir_deref_type_array);
vtn_assert(glsl_type_is_array(deref->type));
rewrite_deref_types(b, deref->child, glsl_get_array_element(type));
}
}
@@ -258,8 +259,8 @@ vtn_pointer_for_variable(struct vtn_builder *b,
pointer->mode = var->mode;
pointer->type = var->type;
assert(ptr_type->base_type == vtn_base_type_pointer);
assert(ptr_type->deref->type == var->type->type);
vtn_assert(ptr_type->base_type == vtn_base_type_pointer);
vtn_assert(ptr_type->deref->type == var->type->type);
pointer->ptr_type = ptr_type;
pointer->var = var;
@@ -280,14 +281,14 @@ vtn_pointer_to_deref(struct vtn_builder *b, struct vtn_pointer *ptr)
if (!ptr->chain)
return deref_var;
} else {
assert(ptr->var->members);
vtn_assert(ptr->var->members);
/* Create the deref_var manually. It will get filled out later. */
deref_var = rzalloc(b, nir_deref_var);
deref_var->deref.deref_type = nir_deref_type_var;
}
struct vtn_access_chain *chain = ptr->chain;
assert(chain);
vtn_assert(chain);
struct vtn_type *deref_type = ptr->var->type;
nir_deref *tail = &deref_var->deref;
@@ -313,7 +314,7 @@ vtn_pointer_to_deref(struct vtn_builder *b, struct vtn_pointer *ptr)
deref_arr->deref_array_type = nir_deref_array_type_direct;
deref_arr->base_offset = chain->link[i].id;
} else {
assert(chain->link[i].mode == vtn_access_mode_id);
vtn_assert(chain->link[i].mode == vtn_access_mode_id);
deref_arr->deref_array_type = nir_deref_array_type_indirect;
deref_arr->base_offset = 0;
deref_arr->indirect =
@@ -325,14 +326,14 @@ vtn_pointer_to_deref(struct vtn_builder *b, struct vtn_pointer *ptr)
}
case GLSL_TYPE_STRUCT: {
assert(chain->link[i].mode == vtn_access_mode_literal);
vtn_assert(chain->link[i].mode == vtn_access_mode_literal);
unsigned idx = chain->link[i].id;
deref_type = deref_type->members[idx];
if (members) {
/* This is a pre-split structure. */
deref_var->var = members[idx];
rewrite_deref_types(&deref_var->deref, members[idx]->type);
assert(tail->type == deref_type->type);
rewrite_deref_types(b, &deref_var->deref, members[idx]->type);
vtn_assert(tail->type == deref_type->type);
members = NULL;
} else {
nir_deref_struct *deref_struct = nir_deref_struct_create(b, idx);
@@ -347,7 +348,7 @@ vtn_pointer_to_deref(struct vtn_builder *b, struct vtn_pointer *ptr)
}
}
assert(members == NULL);
vtn_assert(members == NULL);
return deref_var;
}
@@ -398,7 +399,7 @@ _vtn_local_load_store(struct vtn_builder *b, bool load, nir_deref_var *deref,
_vtn_local_load_store(b, load, deref, tail->child, inout->elems[i]);
}
} else {
assert(glsl_get_base_type(tail->type) == GLSL_TYPE_STRUCT);
vtn_assert(glsl_get_base_type(tail->type) == GLSL_TYPE_STRUCT);
unsigned elems = glsl_get_length(tail->type);
nir_deref_struct *deref_struct = nir_deref_struct_create(b, 0);
tail->child = &deref_struct->deref;
@@ -443,7 +444,7 @@ vtn_local_load(struct vtn_builder *b, nir_deref_var *src)
if (src_tail->child) {
nir_deref_array *vec_deref = nir_deref_as_array(src_tail->child);
assert(vec_deref->deref.child == NULL);
vtn_assert(vec_deref->deref.child == NULL);
val->type = vec_deref->deref.type;
if (vec_deref->deref_array_type == nir_deref_array_type_direct)
val->def = vtn_vector_extract(b, val->def, vec_deref->base_offset);
@@ -465,7 +466,7 @@ vtn_local_store(struct vtn_builder *b, struct vtn_ssa_value *src,
struct vtn_ssa_value *val = vtn_create_ssa_value(b, dest_tail->type);
_vtn_local_load_store(b, true, dest, dest_tail, val);
nir_deref_array *deref = nir_deref_as_array(dest_tail->child);
assert(deref->deref.child == NULL);
vtn_assert(deref->deref.child == NULL);
if (deref->deref_array_type == nir_deref_array_type_direct)
val->def = vtn_vector_insert(b, val->def, src->def,
deref->base_offset);
@@ -490,7 +491,7 @@ get_vulkan_resource_index(struct vtn_builder *b, struct vtn_pointer *ptr,
}
if (glsl_type_is_array(ptr->var->type->type)) {
assert(ptr->chain->length > 0);
vtn_assert(ptr->chain->length > 0);
nir_ssa_def *desc_array_index =
vtn_access_link_as_ssa(b, ptr->chain->link[0], 1);
*chain_idx = 1;
@@ -508,7 +509,7 @@ vtn_pointer_to_offset(struct vtn_builder *b, struct vtn_pointer *ptr,
nir_ssa_def **index_out, unsigned *end_idx_out)
{
if (ptr->offset) {
assert(ptr->block_index);
vtn_assert(ptr->block_index);
*index_out = ptr->block_index;
return ptr->offset;
}
@@ -537,7 +538,7 @@ vtn_pointer_to_offset(struct vtn_builder *b, struct vtn_pointer *ptr,
break;
case GLSL_TYPE_STRUCT: {
assert(ptr->chain->link[idx].mode == vtn_access_mode_literal);
vtn_assert(ptr->chain->link[idx].mode == vtn_access_mode_literal);
unsigned member = ptr->chain->link[idx].id;
offset = nir_iadd(&b->nb, offset,
nir_imm_int(&b->nb, type->offsets[member]));
@@ -550,7 +551,7 @@ vtn_pointer_to_offset(struct vtn_builder *b, struct vtn_pointer *ptr,
}
}
assert(type == ptr->type);
vtn_assert(type == ptr->type);
if (end_idx_out)
*end_idx_out = idx;
@@ -561,7 +562,7 @@ vtn_pointer_to_offset(struct vtn_builder *b, struct vtn_pointer *ptr,
* offsets that are provided to us in the SPIR-V source.
*/
static unsigned
vtn_type_block_size(struct vtn_type *type)
vtn_type_block_size(struct vtn_builder *b, struct vtn_type *type)
{
enum glsl_base_type base_type = glsl_get_base_type(type->type);
switch (base_type) {
@@ -575,7 +576,7 @@ vtn_type_block_size(struct vtn_type *type)
unsigned cols = type->row_major ? glsl_get_vector_elements(type->type) :
glsl_get_matrix_columns(type->type);
if (cols > 1) {
assert(type->stride > 0);
vtn_assert(type->stride > 0);
return type->stride * cols;
} else if (base_type == GLSL_TYPE_DOUBLE ||
base_type == GLSL_TYPE_UINT64 ||
@@ -592,15 +593,15 @@ vtn_type_block_size(struct vtn_type *type)
unsigned num_fields = glsl_get_length(type->type);
for (unsigned f = 0; f < num_fields; f++) {
unsigned field_end = type->offsets[f] +
vtn_type_block_size(type->members[f]);
vtn_type_block_size(b, type->members[f]);
size = MAX2(size, field_end);
}
return size;
}
case GLSL_TYPE_ARRAY:
assert(type->stride > 0);
assert(glsl_get_length(type->type) > 0);
vtn_assert(type->stride > 0);
vtn_assert(glsl_get_length(type->type) > 0);
return type->stride * glsl_get_length(type->type);
default:
@@ -610,7 +611,8 @@ vtn_type_block_size(struct vtn_type *type)
}
static void
vtn_access_chain_get_offset_size(struct vtn_access_chain *chain,
vtn_access_chain_get_offset_size(struct vtn_builder *b,
struct vtn_access_chain *chain,
struct vtn_type *type,
unsigned *access_offset,
unsigned *access_size)
@@ -630,7 +632,7 @@ vtn_access_chain_get_offset_size(struct vtn_access_chain *chain,
}
}
*access_size = vtn_type_block_size(type);
*access_size = vtn_type_block_size(b, type);
}
static void
@@ -649,7 +651,7 @@ _vtn_load_store_tail(struct vtn_builder *b, nir_intrinsic_op op, bool load,
}
if (op == nir_intrinsic_load_push_constant) {
assert(access_offset % 4 == 0);
vtn_assert(access_offset % 4 == 0);
nir_intrinsic_set_base(instr, access_offset);
nir_intrinsic_set_range(instr, access_size);
@@ -744,7 +746,7 @@ _vtn_block_load_store(struct vtn_builder *b, nir_intrinsic_op op, bool load,
unsigned type_size = glsl_get_bit_size(type->type) / 8;
if (elems == 1 || type->stride == type_size) {
/* This is a tightly-packed normal scalar or vector load */
assert(glsl_type_is_vector_or_scalar(type->type));
vtn_assert(glsl_type_is_vector_or_scalar(type->type));
_vtn_load_store_tail(b, op, load, index, offset,
access_offset, access_size,
inout, type->type);
@@ -752,8 +754,8 @@ _vtn_block_load_store(struct vtn_builder *b, nir_intrinsic_op op, bool load,
/* This is a strided load. We have to load N things separately.
* This is the single column of a row-major matrix case.
*/
assert(type->stride > type_size);
assert(type->stride % type_size == 0);
vtn_assert(type->stride > type_size);
vtn_assert(type->stride % type_size == 0);
nir_ssa_def *per_comp[4];
for (unsigned i = 0; i < elems; i++) {
@@ -826,7 +828,7 @@ vtn_block_load(struct vtn_builder *b, struct vtn_pointer *src)
break;
case vtn_variable_mode_push_constant:
op = nir_intrinsic_load_push_constant;
vtn_access_chain_get_offset_size(src->chain, src->var->type,
vtn_access_chain_get_offset_size(b, src->chain, src->var->type,
&access_offset, &access_size);
break;
default:
@@ -895,7 +897,7 @@ _vtn_variable_load_store(struct vtn_builder *b, bool load,
case GLSL_TYPE_STRUCT: {
unsigned elems = glsl_get_length(ptr->type->type);
if (load) {
assert(*inout == NULL);
vtn_assert(*inout == NULL);
*inout = rzalloc(b, struct vtn_ssa_value);
(*inout)->type = ptr->type->type;
(*inout)->elems = rzalloc_array(b, struct vtn_ssa_value *, elems);
@@ -937,7 +939,7 @@ vtn_variable_store(struct vtn_builder *b, struct vtn_ssa_value *src,
struct vtn_pointer *dest)
{
if (vtn_pointer_is_external_block(dest)) {
assert(dest->mode == vtn_variable_mode_ssbo);
vtn_assert(dest->mode == vtn_variable_mode_ssbo);
vtn_block_store(b, src, dest);
} else {
_vtn_variable_load_store(b, false, dest, &src);
@@ -948,7 +950,7 @@ static void
_vtn_variable_copy(struct vtn_builder *b, struct vtn_pointer *dest,
struct vtn_pointer *src)
{
assert(src->type->type == dest->type->type);
vtn_assert(src->type->type == dest->type->type);
enum glsl_base_type base_type = glsl_get_base_type(src->type->type);
switch (base_type) {
case GLSL_TYPE_UINT:
@@ -1004,9 +1006,9 @@ vtn_variable_copy(struct vtn_builder *b, struct vtn_pointer *dest,
}
static void
set_mode_system_value(nir_variable_mode *mode)
set_mode_system_value(struct vtn_builder *b, nir_variable_mode *mode)
{
assert(*mode == nir_var_system_value || *mode == nir_var_shader_in);
vtn_assert(*mode == nir_var_system_value || *mode == nir_var_shader_in);
*mode = nir_var_system_value;
}
@@ -1030,37 +1032,37 @@ vtn_get_builtin_location(struct vtn_builder *b,
break;
case SpvBuiltInVertexIndex:
*location = SYSTEM_VALUE_VERTEX_ID;
set_mode_system_value(mode);
set_mode_system_value(b, mode);
break;
case SpvBuiltInVertexId:
/* Vulkan defines VertexID to be zero-based and reserves the new
* builtin keyword VertexIndex to indicate the non-zero-based value.
*/
*location = SYSTEM_VALUE_VERTEX_ID_ZERO_BASE;
set_mode_system_value(mode);
set_mode_system_value(b, mode);
break;
case SpvBuiltInInstanceIndex:
*location = SYSTEM_VALUE_INSTANCE_INDEX;
set_mode_system_value(mode);
set_mode_system_value(b, mode);
break;
case SpvBuiltInInstanceId:
*location = SYSTEM_VALUE_INSTANCE_ID;
set_mode_system_value(mode);
set_mode_system_value(b, mode);
break;
case SpvBuiltInPrimitiveId:
if (b->shader->info.stage == MESA_SHADER_FRAGMENT) {
assert(*mode == nir_var_shader_in);
vtn_assert(*mode == nir_var_shader_in);
*location = VARYING_SLOT_PRIMITIVE_ID;
} else if (*mode == nir_var_shader_out) {
*location = VARYING_SLOT_PRIMITIVE_ID;
} else {
*location = SYSTEM_VALUE_PRIMITIVE_ID;
set_mode_system_value(mode);
set_mode_system_value(b, mode);
}
break;
case SpvBuiltInInvocationId:
*location = SYSTEM_VALUE_INVOCATION_ID;
set_mode_system_value(mode);
set_mode_system_value(b, mode);
break;
case SpvBuiltInLayer:
*location = VARYING_SLOT_LAYER;
@@ -1088,51 +1090,51 @@ vtn_get_builtin_location(struct vtn_builder *b,
break;
case SpvBuiltInTessCoord:
*location = SYSTEM_VALUE_TESS_COORD;
set_mode_system_value(mode);
set_mode_system_value(b, mode);
break;
case SpvBuiltInPatchVertices:
*location = SYSTEM_VALUE_VERTICES_IN;
set_mode_system_value(mode);
set_mode_system_value(b, mode);
break;
case SpvBuiltInFragCoord:
*location = VARYING_SLOT_POS;
assert(*mode == nir_var_shader_in);
vtn_assert(*mode == nir_var_shader_in);
break;
case SpvBuiltInPointCoord:
*location = VARYING_SLOT_PNTC;
assert(*mode == nir_var_shader_in);
vtn_assert(*mode == nir_var_shader_in);
break;
case SpvBuiltInFrontFacing:
*location = SYSTEM_VALUE_FRONT_FACE;
set_mode_system_value(mode);
set_mode_system_value(b, mode);
break;
case SpvBuiltInSampleId:
*location = SYSTEM_VALUE_SAMPLE_ID;
set_mode_system_value(mode);
set_mode_system_value(b, mode);
break;
case SpvBuiltInSamplePosition:
*location = SYSTEM_VALUE_SAMPLE_POS;
set_mode_system_value(mode);
set_mode_system_value(b, mode);
break;
case SpvBuiltInSampleMask:
if (*mode == nir_var_shader_out) {
*location = FRAG_RESULT_SAMPLE_MASK;
} else {
*location = SYSTEM_VALUE_SAMPLE_MASK_IN;
set_mode_system_value(mode);
set_mode_system_value(b, mode);
}
break;
case SpvBuiltInFragDepth:
*location = FRAG_RESULT_DEPTH;
assert(*mode == nir_var_shader_out);
vtn_assert(*mode == nir_var_shader_out);
break;
case SpvBuiltInHelperInvocation:
*location = SYSTEM_VALUE_HELPER_INVOCATION;
set_mode_system_value(mode);
set_mode_system_value(b, mode);
break;
case SpvBuiltInNumWorkgroups:
*location = SYSTEM_VALUE_NUM_WORK_GROUPS;
set_mode_system_value(mode);
set_mode_system_value(b, mode);
break;
case SpvBuiltInWorkgroupSize:
/* This should already be handled */
@@ -1140,35 +1142,35 @@ vtn_get_builtin_location(struct vtn_builder *b,
break;
case SpvBuiltInWorkgroupId:
*location = SYSTEM_VALUE_WORK_GROUP_ID;
set_mode_system_value(mode);
set_mode_system_value(b, mode);
break;
case SpvBuiltInLocalInvocationId:
*location = SYSTEM_VALUE_LOCAL_INVOCATION_ID;
set_mode_system_value(mode);
set_mode_system_value(b, mode);
break;
case SpvBuiltInLocalInvocationIndex:
*location = SYSTEM_VALUE_LOCAL_INVOCATION_INDEX;
set_mode_system_value(mode);
set_mode_system_value(b, mode);
break;
case SpvBuiltInGlobalInvocationId:
*location = SYSTEM_VALUE_GLOBAL_INVOCATION_ID;
set_mode_system_value(mode);
set_mode_system_value(b, mode);
break;
case SpvBuiltInBaseVertex:
*location = SYSTEM_VALUE_BASE_VERTEX;
set_mode_system_value(mode);
set_mode_system_value(b, mode);
break;
case SpvBuiltInBaseInstance:
*location = SYSTEM_VALUE_BASE_INSTANCE;
set_mode_system_value(mode);
set_mode_system_value(b, mode);
break;
case SpvBuiltInDrawIndex:
*location = SYSTEM_VALUE_DRAW_ID;
set_mode_system_value(mode);
set_mode_system_value(b, mode);
break;
case SpvBuiltInViewIndex:
*location = SYSTEM_VALUE_VIEW_INDEX;
set_mode_system_value(mode);
set_mode_system_value(b, mode);
break;
default:
unreachable("unsupported builtin");
@@ -1198,7 +1200,7 @@ apply_var_decoration(struct vtn_builder *b, nir_variable *nir_var,
nir_var->data.invariant = true;
break;
case SpvDecorationConstant:
assert(nir_var->constant_initializer != NULL);
vtn_assert(nir_var->constant_initializer != NULL);
nir_var->data.read_only = true;
break;
case SpvDecorationNonReadable:
@@ -1341,11 +1343,11 @@ var_decoration_cb(struct vtn_builder *b, struct vtn_value *val, int member,
}
if (val->value_type == vtn_value_type_pointer) {
assert(val->pointer->var == void_var);
assert(val->pointer->chain == NULL);
assert(member == -1);
vtn_assert(val->pointer->var == void_var);
vtn_assert(val->pointer->chain == NULL);
vtn_assert(member == -1);
} else {
assert(val->value_type == vtn_value_type_type);
vtn_assert(val->value_type == vtn_value_type_type);
}
/* Location is odd. If applied to a split structure, we have to walk the
@@ -1377,7 +1379,7 @@ var_decoration_cb(struct vtn_builder *b, struct vtn_value *val, int member,
vtn_var->var->data.location = location;
} else {
/* This handles the structure member case */
assert(vtn_var->members);
vtn_assert(vtn_var->members);
unsigned length =
glsl_get_length(glsl_without_array(vtn_var->type->type));
for (unsigned i = 0; i < length; i++) {
@@ -1390,11 +1392,11 @@ var_decoration_cb(struct vtn_builder *b, struct vtn_value *val, int member,
return;
} else {
if (vtn_var->var) {
assert(member <= 0);
vtn_assert(member <= 0);
apply_var_decoration(b, vtn_var->var, dec);
} else if (vtn_var->members) {
if (member >= 0) {
assert(vtn_var->members);
vtn_assert(vtn_var->members);
apply_var_decoration(b, vtn_var->members[member], dec);
} else {
unsigned length =
@@ -1407,9 +1409,9 @@ var_decoration_cb(struct vtn_builder *b, struct vtn_value *val, int member,
* nir_variables associated with them. Fortunately, all decorations
* we care about for those variables are on the type only.
*/
assert(vtn_var->mode == vtn_variable_mode_ubo ||
vtn_var->mode == vtn_variable_mode_ssbo ||
vtn_var->mode == vtn_variable_mode_push_constant);
vtn_assert(vtn_var->mode == vtn_variable_mode_ubo ||
vtn_var->mode == vtn_variable_mode_ssbo ||
vtn_var->mode == vtn_variable_mode_push_constant);
}
}
}
@@ -1489,8 +1491,8 @@ nir_ssa_def *
vtn_pointer_to_ssa(struct vtn_builder *b, struct vtn_pointer *ptr)
{
/* This pointer needs to have a pointer type with actual storage */
assert(ptr->ptr_type);
assert(ptr->ptr_type->type);
vtn_assert(ptr->ptr_type);
vtn_assert(ptr->ptr_type->type);
if (ptr->offset && ptr->block_index) {
return nir_vec2(&b->nb, ptr->block_index, ptr->offset);
@@ -1498,13 +1500,13 @@ vtn_pointer_to_ssa(struct vtn_builder *b, struct vtn_pointer *ptr)
/* If we don't have an offset or block index, then we must be a pointer
* to the variable itself.
*/
assert(!ptr->offset && !ptr->block_index);
vtn_assert(!ptr->offset && !ptr->block_index);
/* We can't handle a pointer to an array of descriptors because we have
* no way of knowing later on that we need to add to update the block
* index when dereferencing.
*/
assert(ptr->var && ptr->var->type->base_type == vtn_base_type_struct);
vtn_assert(ptr->var && ptr->var->type->base_type == vtn_base_type_struct);
return nir_vec2(&b->nb, vtn_variable_resource_index(b, ptr->var, NULL),
nir_imm_int(&b->nb, 0));
@@ -1515,11 +1517,11 @@ struct vtn_pointer *
vtn_pointer_from_ssa(struct vtn_builder *b, nir_ssa_def *ssa,
struct vtn_type *ptr_type)
{
assert(ssa->num_components == 2 && ssa->bit_size == 32);
assert(ptr_type->base_type == vtn_base_type_pointer);
assert(ptr_type->deref->base_type != vtn_base_type_pointer);
vtn_assert(ssa->num_components == 2 && ssa->bit_size == 32);
vtn_assert(ptr_type->base_type == vtn_base_type_pointer);
vtn_assert(ptr_type->deref->base_type != vtn_base_type_pointer);
/* This pointer type needs to have actual storage */
assert(ptr_type->type);
vtn_assert(ptr_type->type);
struct vtn_pointer *ptr = rzalloc(b, struct vtn_pointer);
ptr->mode = vtn_storage_class_to_mode(ptr_type->storage_class,
@@ -1555,7 +1557,7 @@ vtn_create_variable(struct vtn_builder *b, struct vtn_value *val,
struct vtn_type *ptr_type, SpvStorageClass storage_class,
nir_constant *initializer)
{
assert(ptr_type->base_type == vtn_base_type_pointer);
vtn_assert(ptr_type->base_type == vtn_base_type_pointer);
struct vtn_type *type = ptr_type->deref;
struct vtn_type *without_array = type;
@@ -1580,7 +1582,7 @@ vtn_create_variable(struct vtn_builder *b, struct vtn_value *val,
b->shader->info.num_textures++;
break;
case vtn_variable_mode_push_constant:
b->shader->num_uniforms = vtn_type_block_size(type);
b->shader->num_uniforms = vtn_type_block_size(b, type);
break;
default:
/* No tallying is needed */
@@ -1591,7 +1593,7 @@ vtn_create_variable(struct vtn_builder *b, struct vtn_value *val,
var->type = type;
var->mode = mode;
assert(val->value_type == vtn_value_type_pointer);
vtn_assert(val->value_type == vtn_value_type_pointer);
val->pointer = vtn_pointer_for_variable(b, var, ptr_type);
switch (var->mode) {
@@ -1730,20 +1732,20 @@ vtn_create_variable(struct vtn_builder *b, struct vtn_value *val,
}
if (var->mode == vtn_variable_mode_local) {
assert(var->members == NULL && var->var != NULL);
vtn_assert(var->members == NULL && var->var != NULL);
nir_function_impl_add_variable(b->nb.impl, var->var);
} else if (var->var) {
nir_shader_add_variable(b->shader, var->var);
} else if (var->members) {
unsigned count = glsl_get_length(without_array->type);
for (unsigned i = 0; i < count; i++) {
assert(var->members[i]->data.mode != nir_var_local);
vtn_assert(var->members[i]->data.mode != nir_var_local);
nir_shader_add_variable(b->shader, var->members[i]);
}
} else {
assert(var->mode == vtn_variable_mode_ubo ||
var->mode == vtn_variable_mode_ssbo ||
var->mode == vtn_variable_mode_push_constant);
vtn_assert(var->mode == vtn_variable_mode_ubo ||
var->mode == vtn_variable_mode_ssbo ||
var->mode == vtn_variable_mode_push_constant);
}
}
@@ -1810,7 +1812,7 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
vtn_pointer_dereference(b, base_val->sampled_image->image, chain);
val->sampled_image->sampler = base_val->sampled_image->sampler;
} else {
assert(base_val->value_type == vtn_value_type_pointer);
vtn_assert(base_val->value_type == vtn_value_type_pointer);
struct vtn_value *val =
vtn_push_value(b, w[2], vtn_value_type_pointer);
val->pointer = vtn_pointer_dereference(b, base_val->pointer, chain);
@@ -1850,7 +1852,7 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
if (glsl_type_is_sampler(dest->type->type)) {
vtn_warn("OpStore of a sampler detected. Doing on-the-fly copy "
"propagation to workaround the problem.");
assert(dest->var->copy_prop_sampler == NULL);
vtn_assert(dest->var->copy_prop_sampler == NULL);
dest->var->copy_prop_sampler =
vtn_value(b, w[2], vtn_value_type_pointer)->pointer;
break;