OSDN Git Service

spirv: Allow OpPtrAccessChain for block indices
authorJason Ekstrand <jason.ekstrand@intel.com>
Fri, 1 Dec 2017 00:55:45 +0000 (16:55 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Wed, 6 Dec 2017 06:01:54 +0000 (22:01 -0800)
commit93b4cb61eb2a16794d5f4a2f55a70cdcd8a5d521
tree7239b37229dde209befeb98431e90290e2d143c8
parent32c859125b916c24ab76bd52db6e37a1a22f4858
spirv: Allow OpPtrAccessChain for block indices

The SPIR-V spec is a bit underspecified when it comes to exactly how
you're allowed to use OpPtrAccessChain and what it means in certain edge
cases.  In particular, what if the base pointer of the OpPtrAccessChain
points to the base struct of an SSBO instead of an element in that SSBO.
The original variable pointers implementation in mesa assumed that you
weren't allowed to do an OpPtrAccessChain that adjusted the block index
and asserted such.  However, there are some CTS tests that do this and,
if the CTS does it, someone will do it in the wild so we should probably
handle it.  With this commit, we significantly reduce our assumptions
and should be able to handle more-or-less anything.

The one assumption we still make for correctness is that if we see an
OpPtrAccessChain on a pointer to a struct decorated block that the block
index should be adjusted.  In theory, someone could try to put an array
stride on such a pointer and try to make the SSBO an implicit array of
the base struct and we would not give them what they want.  That said,
any index other than 0 would count as an out-of-bounds access which is
invalid.

Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
src/compiler/spirv/vtn_variables.c