spirv: propagate the access flag for store and load derefs

It was only propagated when UBO/SSBO access are lowered to offsets.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: <Jason Ekstrand jason@jlekstrand.net>
This commit is contained in:
Samuel Pitoiset
2019-03-26 23:07:39 +01:00
parent 4d0b03c83d
commit bea540173c
3 changed files with 32 additions and 24 deletions

View File

@@ -232,7 +232,7 @@ vtn_handle_function_call(struct vtn_builder *b, SpvOp opcode,
if (ret_type->base_type == vtn_base_type_void) { if (ret_type->base_type == vtn_base_type_void) {
vtn_push_value(b, w[2], vtn_value_type_undef); vtn_push_value(b, w[2], vtn_value_type_undef);
} else { } else {
vtn_push_ssa(b, w[2], res_type, vtn_local_load(b, ret_deref)); vtn_push_ssa(b, w[2], res_type, vtn_local_load(b, ret_deref, 0));
} }
} }
@@ -794,7 +794,7 @@ vtn_handle_phis_first_pass(struct vtn_builder *b, SpvOp opcode,
_mesa_hash_table_insert(b->phi_table, w, phi_var); _mesa_hash_table_insert(b->phi_table, w, phi_var);
vtn_push_ssa(b, w[2], type, vtn_push_ssa(b, w[2], type,
vtn_local_load(b, nir_build_deref_var(&b->nb, phi_var))); vtn_local_load(b, nir_build_deref_var(&b->nb, phi_var), 0));
return true; return true;
} }
@@ -818,7 +818,7 @@ vtn_handle_phi_second_pass(struct vtn_builder *b, SpvOp opcode,
struct vtn_ssa_value *src = vtn_ssa_value(b, w[i]); struct vtn_ssa_value *src = vtn_ssa_value(b, w[i]);
vtn_local_store(b, src, nir_build_deref_var(&b->nb, phi_var)); vtn_local_store(b, src, nir_build_deref_var(&b->nb, phi_var), 0);
} }
return true; return true;
@@ -943,7 +943,7 @@ vtn_emit_cf_list(struct vtn_builder *b, struct list_head *cf_list,
nir_deref_instr *ret_deref = nir_deref_instr *ret_deref =
nir_build_deref_cast(&b->nb, nir_load_param(&b->nb, 0), nir_build_deref_cast(&b->nb, nir_load_param(&b->nb, 0),
nir_var_function_temp, ret_type, 0); nir_var_function_temp, ret_type, 0);
vtn_local_store(b, src, ret_deref); vtn_local_store(b, src, ret_deref, 0);
} }
if (block->branch_type != vtn_branch_type_none) { if (block->branch_type != vtn_branch_type_none) {

View File

@@ -730,10 +730,12 @@ vtn_pointer_to_offset(struct vtn_builder *b, struct vtn_pointer *ptr,
nir_ssa_def **index_out); nir_ssa_def **index_out);
struct vtn_ssa_value * struct vtn_ssa_value *
vtn_local_load(struct vtn_builder *b, nir_deref_instr *src); vtn_local_load(struct vtn_builder *b, nir_deref_instr *src,
enum gl_access_qualifier access);
void vtn_local_store(struct vtn_builder *b, struct vtn_ssa_value *src, void vtn_local_store(struct vtn_builder *b, struct vtn_ssa_value *src,
nir_deref_instr *dest); nir_deref_instr *dest,
enum gl_access_qualifier access);
struct vtn_ssa_value * struct vtn_ssa_value *
vtn_variable_load(struct vtn_builder *b, struct vtn_pointer *src); vtn_variable_load(struct vtn_builder *b, struct vtn_pointer *src);

View File

@@ -590,13 +590,14 @@ vtn_pointer_to_deref(struct vtn_builder *b, struct vtn_pointer *ptr)
static void static void
_vtn_local_load_store(struct vtn_builder *b, bool load, nir_deref_instr *deref, _vtn_local_load_store(struct vtn_builder *b, bool load, nir_deref_instr *deref,
struct vtn_ssa_value *inout) struct vtn_ssa_value *inout,
enum gl_access_qualifier access)
{ {
if (glsl_type_is_vector_or_scalar(deref->type)) { if (glsl_type_is_vector_or_scalar(deref->type)) {
if (load) { if (load) {
inout->def = nir_load_deref(&b->nb, deref); inout->def = nir_load_deref_with_access(&b->nb, deref, access);
} else { } else {
nir_store_deref(&b->nb, deref, inout->def, ~0); nir_store_deref_with_access(&b->nb, deref, inout->def, ~0, access);
} }
} else if (glsl_type_is_array(deref->type) || } else if (glsl_type_is_array(deref->type) ||
glsl_type_is_matrix(deref->type)) { glsl_type_is_matrix(deref->type)) {
@@ -604,14 +605,14 @@ _vtn_local_load_store(struct vtn_builder *b, bool load, nir_deref_instr *deref,
for (unsigned i = 0; i < elems; i++) { for (unsigned i = 0; i < elems; i++) {
nir_deref_instr *child = nir_deref_instr *child =
nir_build_deref_array_imm(&b->nb, deref, i); nir_build_deref_array_imm(&b->nb, deref, i);
_vtn_local_load_store(b, load, child, inout->elems[i]); _vtn_local_load_store(b, load, child, inout->elems[i], access);
} }
} else { } else {
vtn_assert(glsl_type_is_struct_or_ifc(deref->type)); vtn_assert(glsl_type_is_struct_or_ifc(deref->type));
unsigned elems = glsl_get_length(deref->type); unsigned elems = glsl_get_length(deref->type);
for (unsigned i = 0; i < elems; i++) { for (unsigned i = 0; i < elems; i++) {
nir_deref_instr *child = nir_build_deref_struct(&b->nb, deref, i); nir_deref_instr *child = nir_build_deref_struct(&b->nb, deref, i);
_vtn_local_load_store(b, load, child, inout->elems[i]); _vtn_local_load_store(b, load, child, inout->elems[i], access);
} }
} }
} }
@@ -644,11 +645,12 @@ get_deref_tail(nir_deref_instr *deref)
} }
struct vtn_ssa_value * struct vtn_ssa_value *
vtn_local_load(struct vtn_builder *b, nir_deref_instr *src) vtn_local_load(struct vtn_builder *b, nir_deref_instr *src,
enum gl_access_qualifier access)
{ {
nir_deref_instr *src_tail = get_deref_tail(src); nir_deref_instr *src_tail = get_deref_tail(src);
struct vtn_ssa_value *val = vtn_create_ssa_value(b, src_tail->type); struct vtn_ssa_value *val = vtn_create_ssa_value(b, src_tail->type);
_vtn_local_load_store(b, true, src_tail, val); _vtn_local_load_store(b, true, src_tail, val, access);
if (src_tail != src) { if (src_tail != src) {
val->type = src->type; val->type = src->type;
@@ -664,13 +666,13 @@ vtn_local_load(struct vtn_builder *b, nir_deref_instr *src)
void void
vtn_local_store(struct vtn_builder *b, struct vtn_ssa_value *src, vtn_local_store(struct vtn_builder *b, struct vtn_ssa_value *src,
nir_deref_instr *dest) nir_deref_instr *dest, enum gl_access_qualifier access)
{ {
nir_deref_instr *dest_tail = get_deref_tail(dest); nir_deref_instr *dest_tail = get_deref_tail(dest);
if (dest_tail != dest) { if (dest_tail != dest) {
struct vtn_ssa_value *val = vtn_create_ssa_value(b, dest_tail->type); struct vtn_ssa_value *val = vtn_create_ssa_value(b, dest_tail->type);
_vtn_local_load_store(b, true, dest_tail, val); _vtn_local_load_store(b, true, dest_tail, val, access);
if (nir_src_is_const(dest->arr.index)) if (nir_src_is_const(dest->arr.index))
val->def = vtn_vector_insert(b, val->def, src->def, val->def = vtn_vector_insert(b, val->def, src->def,
@@ -678,9 +680,9 @@ vtn_local_store(struct vtn_builder *b, struct vtn_ssa_value *src,
else else
val->def = vtn_vector_insert_dynamic(b, val->def, src->def, val->def = vtn_vector_insert_dynamic(b, val->def, src->def,
dest->arr.index.ssa); dest->arr.index.ssa);
_vtn_local_load_store(b, false, dest_tail, val); _vtn_local_load_store(b, false, dest_tail, val, access);
} else { } else {
_vtn_local_load_store(b, false, dest_tail, src); _vtn_local_load_store(b, false, dest_tail, src, access);
} }
} }
@@ -1014,6 +1016,7 @@ vtn_block_store(struct vtn_builder *b, struct vtn_ssa_value *src,
static void static void
_vtn_variable_load_store(struct vtn_builder *b, bool load, _vtn_variable_load_store(struct vtn_builder *b, bool load,
struct vtn_pointer *ptr, struct vtn_pointer *ptr,
enum gl_access_qualifier access,
struct vtn_ssa_value **inout) struct vtn_ssa_value **inout)
{ {
enum glsl_base_type base_type = glsl_get_base_type(ptr->type->type); enum glsl_base_type base_type = glsl_get_base_type(ptr->type->type);
@@ -1045,15 +1048,17 @@ _vtn_variable_load_store(struct vtn_builder *b, bool load,
*/ */
if (load) { if (load) {
*inout = vtn_create_ssa_value(b, ptr->type->type); *inout = vtn_create_ssa_value(b, ptr->type->type);
(*inout)->def = nir_load_deref(&b->nb, deref); (*inout)->def = nir_load_deref_with_access(&b->nb, deref,
ptr->type->access | access);
} else { } else {
nir_store_deref(&b->nb, deref, (*inout)->def, ~0); nir_store_deref_with_access(&b->nb, deref, (*inout)->def, ~0,
ptr->type->access | access);
} }
} else { } else {
if (load) { if (load) {
*inout = vtn_local_load(b, deref); *inout = vtn_local_load(b, deref, ptr->type->access | access);
} else { } else {
vtn_local_store(b, *inout, deref); vtn_local_store(b, *inout, deref, ptr->type->access | access);
} }
} }
return; return;
@@ -1080,7 +1085,8 @@ _vtn_variable_load_store(struct vtn_builder *b, bool load,
for (unsigned i = 0; i < elems; i++) { for (unsigned i = 0; i < elems; i++) {
chain.link[0].id = i; chain.link[0].id = i;
struct vtn_pointer *elem = vtn_pointer_dereference(b, ptr, &chain); struct vtn_pointer *elem = vtn_pointer_dereference(b, ptr, &chain);
_vtn_variable_load_store(b, load, elem, &(*inout)->elems[i]); _vtn_variable_load_store(b, load, elem, ptr->type->access | access,
&(*inout)->elems[i]);
} }
return; return;
} }
@@ -1097,7 +1103,7 @@ vtn_variable_load(struct vtn_builder *b, struct vtn_pointer *src)
return vtn_block_load(b, src); return vtn_block_load(b, src);
} else { } else {
struct vtn_ssa_value *val = NULL; struct vtn_ssa_value *val = NULL;
_vtn_variable_load_store(b, true, src, &val); _vtn_variable_load_store(b, true, src, src->access, &val);
return val; return val;
} }
} }
@@ -1111,7 +1117,7 @@ vtn_variable_store(struct vtn_builder *b, struct vtn_ssa_value *src,
dest->mode == vtn_variable_mode_workgroup); dest->mode == vtn_variable_mode_workgroup);
vtn_block_store(b, src, dest); vtn_block_store(b, src, dest);
} else { } else {
_vtn_variable_load_store(b, false, dest, &src); _vtn_variable_load_store(b, false, dest, dest->access, &src);
} }
} }