diff options
author | Jason Ekstrand <[email protected]> | 2017-10-19 09:23:07 -0700 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2017-12-05 22:01:53 -0800 |
commit | 843c192e2be3d194f4640a273f4efde561bcc8fc (patch) | |
tree | 31eff1e5693efe47d886064084e29299bb2cfadf | |
parent | 6dffef6308200d90a983301444e6952223616444 (diff) |
spirv: Use offset_pointer_dereference to instead of get_vulkan_resource_index
There is no good reason why we should have the same logic repeated in
get_vulkan_resource_index and vtn_ssa_offset_pointer_dereference. If
we're a bit more careful about how we do things, we can just use the one
function and get rid of the other entirely. This also makes the push
constant special case a lot more clear.
Reviewed-by: Kristian H. Kristensen <[email protected]>
-rw-r--r-- | src/compiler/spirv/vtn_variables.c | 54 |
1 files changed, 19 insertions, 35 deletions
diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c index 4c76ec6b5c1..c67b34e7931 100644 --- a/src/compiler/spirv/vtn_variables.c +++ b/src/compiler/spirv/vtn_variables.c @@ -504,45 +504,26 @@ vtn_local_store(struct vtn_builder *b, struct vtn_ssa_value *src, } } -static nir_ssa_def * -get_vulkan_resource_index(struct vtn_builder *b, struct vtn_pointer *ptr, - struct vtn_type **type, unsigned *chain_idx) -{ - /* Push constants have no explicit binding */ - if (ptr->mode == vtn_variable_mode_push_constant) { - *chain_idx = 0; - *type = ptr->var->type; - return NULL; - } - - if (glsl_type_is_array(ptr->var->type->type)) { - 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; - *type = ptr->var->type->array_element; - return vtn_variable_resource_index(b, ptr->var, desc_array_index); - } else { - *chain_idx = 0; - *type = ptr->var->type; - return vtn_variable_resource_index(b, ptr->var, NULL); - } -} - nir_ssa_def * vtn_pointer_to_offset(struct vtn_builder *b, struct vtn_pointer *ptr, nir_ssa_def **index_out, unsigned *end_idx_out) { - if (ptr->offset) { - vtn_assert(ptr->block_index); + if (vtn_pointer_uses_ssa_offset(b, ptr)) { + if (!ptr->offset) { + struct vtn_access_chain chain = { + .length = 0, + }; + ptr = vtn_ssa_offset_pointer_dereference(b, ptr, &chain); + } *index_out = ptr->block_index; return ptr->offset; } - unsigned idx = 0; - struct vtn_type *type; - *index_out = get_vulkan_resource_index(b, ptr, &type, &idx); + vtn_assert(ptr->mode == vtn_variable_mode_push_constant); + *index_out = NULL; + unsigned idx = 0; + struct vtn_type *type = ptr->var->type; nir_ssa_def *offset = nir_imm_int(&b->nb, 0); for (; idx < ptr->chain->length; idx++) { enum glsl_base_type base_type = glsl_get_base_type(type->type); @@ -1898,15 +1879,18 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode, const uint32_t offset = ptr->var->type->offsets[w[4]]; const uint32_t stride = ptr->var->type->members[w[4]]->stride; - unsigned chain_idx; - struct vtn_type *type; - nir_ssa_def *index = - get_vulkan_resource_index(b, ptr, &type, &chain_idx); + if (!ptr->block_index) { + struct vtn_access_chain chain = { + .length = 0, + }; + ptr = vtn_ssa_offset_pointer_dereference(b, ptr, &chain); + vtn_assert(ptr->block_index); + } nir_intrinsic_instr *instr = nir_intrinsic_instr_create(b->nb.shader, nir_intrinsic_get_buffer_size); - instr->src[0] = nir_src_for_ssa(index); + instr->src[0] = nir_src_for_ssa(ptr->block_index); nir_ssa_dest_init(&instr->instr, &instr->dest, 1, 32, NULL); nir_builder_instr_insert(&b->nb, &instr->instr); nir_ssa_def *buf_size = &instr->dest.ssa; |