composite.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #include "source/opt/composite.h"
  17. #include <vector>
  18. #include "source/opt/ir_context.h"
  19. #include "source/opt/iterator.h"
  20. #include "spirv/1.2/GLSL.std.450.h"
  21. namespace spvtools {
  22. namespace opt {
  23. bool ExtInsMatch(const std::vector<uint32_t>& extIndices,
  24. const Instruction* insInst, const uint32_t extOffset) {
  25. uint32_t numIndices = static_cast<uint32_t>(extIndices.size()) - extOffset;
  26. if (numIndices != insInst->NumInOperands() - 2) return false;
  27. for (uint32_t i = 0; i < numIndices; ++i)
  28. if (extIndices[i + extOffset] != insInst->GetSingleWordInOperand(i + 2))
  29. return false;
  30. return true;
  31. }
  32. bool ExtInsConflict(const std::vector<uint32_t>& extIndices,
  33. const Instruction* insInst, const uint32_t extOffset) {
  34. if (extIndices.size() - extOffset == insInst->NumInOperands() - 2)
  35. return false;
  36. uint32_t extNumIndices = static_cast<uint32_t>(extIndices.size()) - extOffset;
  37. uint32_t insNumIndices = insInst->NumInOperands() - 2;
  38. uint32_t numIndices = std::min(extNumIndices, insNumIndices);
  39. for (uint32_t i = 0; i < numIndices; ++i)
  40. if (extIndices[i + extOffset] != insInst->GetSingleWordInOperand(i + 2))
  41. return false;
  42. return true;
  43. }
  44. } // namespace opt
  45. } // namespace spvtools