Mesa (master): spirv: Pull offset/stride from the pointer for OpArrayLength

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Mar 5 17:39:51 UTC 2019


Module: Mesa
Branch: master
Commit: f1dbc7e97d3dcb2104b9438d32cace9529575208
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=f1dbc7e97d3dcb2104b9438d32cace9529575208

Author: Jason Ekstrand <jason.ekstrand at intel.com>
Date:   Sat Jan 12 10:32:13 2019 -0600

spirv: Pull offset/stride from the pointer for OpArrayLength

We can't pull it from the variable type because it might be an array of
blocks and not just the one block.  While we're here, throw in some
error checking.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Cc: mesa-stable at lists.freedesktop.org

---

 src/compiler/spirv/vtn_variables.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c
index 51152520bb6..f2bf09034ca 100644
--- a/src/compiler/spirv/vtn_variables.c
+++ b/src/compiler/spirv/vtn_variables.c
@@ -2438,9 +2438,17 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
    case SpvOpArrayLength: {
       struct vtn_pointer *ptr =
          vtn_value(b, w[3], vtn_value_type_pointer)->pointer;
+      const uint32_t field = w[4];
 
-      const uint32_t offset = ptr->var->type->offsets[w[4]];
-      const uint32_t stride = ptr->var->type->members[w[4]]->stride;
+      vtn_fail_if(ptr->type->base_type != vtn_base_type_struct,
+                  "OpArrayLength must take a pointer to a structure type");
+      vtn_fail_if(field != ptr->type->length - 1 ||
+                  ptr->type->members[field]->base_type != vtn_base_type_array,
+                  "OpArrayLength must reference the last memeber of the "
+                  "structure and that must be an array");
+
+      const uint32_t offset = ptr->type->offsets[field];
+      const uint32_t stride = ptr->type->members[field]->stride;
 
       if (!ptr->block_index) {
          struct vtn_access_chain chain = {




More information about the mesa-commit mailing list