Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 7 | #include "compiler/translator/FlagStd140Structs.h" |
Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 8 | |
| 9 | namespace sh |
| 10 | { |
| 11 | |
| 12 | bool FlagStd140Structs::visitBinary(Visit visit, TIntermBinary *binaryNode) |
| 13 | { |
| 14 | if (binaryNode->getRight()->getBasicType() == EbtStruct) |
| 15 | { |
| 16 | switch (binaryNode->getOp()) |
| 17 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 18 | case EOpIndexDirectInterfaceBlock: |
| 19 | case EOpIndexDirectStruct: |
| 20 | if (isInStd140InterfaceBlock(binaryNode->getLeft())) |
| 21 | { |
| 22 | mFlaggedNodes.push_back(binaryNode); |
| 23 | } |
| 24 | break; |
Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 25 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 26 | default: |
| 27 | break; |
Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 28 | } |
| 29 | return false; |
| 30 | } |
| 31 | |
| 32 | if (binaryNode->getOp() == EOpIndexDirectStruct) |
| 33 | { |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | return visit == PreVisit; |
| 38 | } |
| 39 | |
| 40 | void FlagStd140Structs::visitSymbol(TIntermSymbol *symbol) |
| 41 | { |
| 42 | if (isInStd140InterfaceBlock(symbol) && symbol->getBasicType() == EbtStruct) |
| 43 | { |
| 44 | mFlaggedNodes.push_back(symbol); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | bool FlagStd140Structs::isInStd140InterfaceBlock(TIntermTyped *node) const |
| 49 | { |
| 50 | TIntermBinary *binaryNode = node->getAsBinaryNode(); |
| 51 | |
| 52 | if (binaryNode) |
| 53 | { |
| 54 | return isInStd140InterfaceBlock(binaryNode->getLeft()); |
| 55 | } |
| 56 | |
| 57 | const TType &type = node->getType(); |
| 58 | |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 59 | // determine if we are in the standard layout |
| 60 | const TInterfaceBlock *interfaceBlock = type.getInterfaceBlock(); |
| 61 | if (interfaceBlock) |
Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 62 | { |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 63 | return (interfaceBlock->blockStorage() == EbsStd140); |
Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | std::vector<TIntermTyped *> FlagStd140ValueStructs(TIntermNode *node) |
| 70 | { |
| 71 | FlagStd140Structs flaggingTraversal; |
| 72 | |
| 73 | node->traverse(&flaggingTraversal); |
| 74 | |
| 75 | return flaggingTraversal.getFlaggedNodes(); |
| 76 | } |
Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 77 | } |