OSDN Git Service

spirv/nir: handle location decorations on block interface members
authorNeil Roberts <nroberts@igalia.com>
Fri, 27 Jul 2018 14:05:05 +0000 (16:05 +0200)
committerAlejandro Piñeiro <apinheiro@igalia.com>
Mon, 28 Jan 2019 10:42:46 +0000 (11:42 +0100)
commitdfc3a7cb3c06c2e0d57e96ad15f7126461540994
tree7abbfbabce86dc4718673ec45052ab261e046724
parent34458c1cf6caf1718e111096143e74aabc7985a7
spirv/nir: handle location decorations on block interface members

Previously the code was taking any location decoration on the block
and using that to calculate the member locations for all of the
members. I think this was assuming that there would only be one
location decoration for the entire block. According to the Vulkan spec
it is possible to add location decorations to individual members:

   “If the structure type is a Block but without a Location, then each
    of its members must have a Location decoration. If it is a Block
    with a Location decoration, then its members are assigned
    consecutive locations in declaration order, starting from the
    first member which is initially the Block. Any member with its own
    Location decoration is assigned that location. Each remaining
    member is assigned the location after the immediately preceding
    member in declaration order.”

This patch makes it instead keep track of which members have been
assigned an explicit location. It also has a space to store the
location for the struct as a whole. Once all the decorations have been
processed it iterates over each member to fill in the missing
locations using the rules described above.

So, this commit is needed to get working a case like this, on both
Vulkan and OpenGL using SPIR-V (ARB_gl_spirv):

     out block {
            layout(location = 2) vec4 c;
            layout(location = 3) vec4 d;
            layout(location = 0) vec4 a;
            layout(location = 1) vec4 b;
     } name;

v2: (changes made by Alejandro Piñeiro)
   * Update after introducing struct member splitting (See commit b0c643d)
   * Update after only exposing interface_type for blocks, not to any struct
   * Update after last changes done for xfb support

v3: use "assign" instead of "add" on the new method added (Tapani)

Signed-off-by: Neil Roberts <nroberts@igalia.com>
Signed-off-by: Alejandro Piñeiro <apinheiro@igalia.com>
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
src/compiler/spirv/vtn_private.h
src/compiler/spirv/vtn_variables.c