• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2018 The Khronos Group Inc.
2 // Copyright (c) 2018 Valve Corporation
3 // Copyright (c) 2018 LunarG Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #include "source/opt/composite.h"
18 
19 #include <vector>
20 
21 #include "source/opt/ir_context.h"
22 #include "source/opt/iterator.h"
23 #include "spirv/1.2/GLSL.std.450.h"
24 
25 namespace spvtools {
26 namespace opt {
27 
ExtInsMatch(const std::vector<uint32_t> & extIndices,const Instruction * insInst,const uint32_t extOffset)28 bool ExtInsMatch(const std::vector<uint32_t>& extIndices,
29                  const Instruction* insInst, const uint32_t extOffset) {
30   uint32_t numIndices = static_cast<uint32_t>(extIndices.size()) - extOffset;
31   if (numIndices != insInst->NumInOperands() - 2) return false;
32   for (uint32_t i = 0; i < numIndices; ++i)
33     if (extIndices[i + extOffset] != insInst->GetSingleWordInOperand(i + 2))
34       return false;
35   return true;
36 }
37 
ExtInsConflict(const std::vector<uint32_t> & extIndices,const Instruction * insInst,const uint32_t extOffset)38 bool ExtInsConflict(const std::vector<uint32_t>& extIndices,
39                     const Instruction* insInst, const uint32_t extOffset) {
40   if (extIndices.size() - extOffset == insInst->NumInOperands() - 2)
41     return false;
42   uint32_t extNumIndices = static_cast<uint32_t>(extIndices.size()) - extOffset;
43   uint32_t insNumIndices = insInst->NumInOperands() - 2;
44   uint32_t numIndices = std::min(extNumIndices, insNumIndices);
45   for (uint32_t i = 0; i < numIndices; ++i)
46     if (extIndices[i + extOffset] != insInst->GetSingleWordInOperand(i + 2))
47       return false;
48   return true;
49 }
50 
51 }  // namespace opt
52 }  // namespace spvtools
53