diff options
author | Jason Ekstrand <jason@jlekstrand.net> | 2017-10-19 11:04:10 -0700 |
---|---|---|
committer | Chad Versace <chadversary@chromium.org> | 2017-11-30 23:38:23 +0000 |
commit | 26ae9a5650081ac4e416d1ddb7e9fa5054a8a3aa (patch) | |
tree | 55a67116e6eb4290d4603ffd39dfadb39a05f793 /src | |
parent | 00898cd71d65c870afa480541421c04b57be8811 (diff) |
FROMLIST: 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.
Archived-At: https://lists.freedesktop.org/archives/mesa-dev/2017-October/173535.html
(am from https://patchwork.freedesktop.org/patch/183828/)
Needed for SPIR-V VariablePointers capability.
BUG=b:68708929
TEST=No regressions on Eve in `cts-tradefed run cts -m CtsDeqpTestCases`.
Change-Id: I338bf2214e916c779b86628c684e434ece81b4a5
Reviewed-on: https://chromium-review.googlesource.com/799677
Tested-by: Chad Versace <chadversary@chromium.org>
Reviewed-by: Kristian H. Kristensen <hoegsberg@chromium.org>
Commit-Queue: Kristian H. Kristensen <hoegsberg@chromium.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/spirv/vtn_variables.c | 56 |
1 files changed, 21 insertions, 35 deletions
diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c index ed5002b3390..2c952cd478e 100644 --- a/src/compiler/spirv/vtn_variables.c +++ b/src/compiler/spirv/vtn_variables.c @@ -503,45 +503,27 @@ 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)) { - 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) { - assert(ptr->block_index); + if (vtn_pointer_uses_ssa_offset(b, ptr)) { + if (!ptr->offset) { + assert(ptr->mode == vtn_variable_mode_workgroup); + 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); + 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); @@ -1895,15 +1877,19 @@ 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) { + assert(ptr->mode == vtn_variable_mode_workgroup); + struct vtn_access_chain chain = { + .length = 0, + }; + ptr = vtn_ssa_offset_pointer_dereference(b, ptr, &chain); + 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; |