Mem2Reg: Allow Image and Sampler types as base target types.
authorGregF <greg@LunarG.com>
Thu, 3 Aug 2017 23:27:02 +0000 (17:27 -0600)
committerDavid Neto <dneto@google.com>
Fri, 4 Aug 2017 21:52:32 +0000 (17:52 -0400)
source/opt/mem_pass.cpp
source/opt/mem_pass.h

index fb97a04..9ca91f2 100644 (file)
@@ -33,7 +33,7 @@ const uint32_t kTypePointerTypeIdInIdx = 1;
 }  // namespace anonymous
 
 
-bool MemPass::IsMathType(
+bool MemPass::IsBaseTargetType(
     const ir::Instruction* typeInst) const {
   switch (typeInst->opcode()) {
   case SpvOpTypeInt:
@@ -41,6 +41,9 @@ bool MemPass::IsMathType(
   case SpvOpTypeBool:
   case SpvOpTypeVector:
   case SpvOpTypeMatrix:
+  case SpvOpTypeImage:
+  case SpvOpTypeSampler:
+  case SpvOpTypeSampledImage:
     return true;
   default:
     break;
@@ -50,17 +53,18 @@ bool MemPass::IsMathType(
 
 bool MemPass::IsTargetType(
     const ir::Instruction* typeInst) const {
-  if (IsMathType(typeInst))
+  if (IsBaseTargetType(typeInst))
     return true;
   if (typeInst->opcode() == SpvOpTypeArray)
-    return IsMathType(def_use_mgr_->GetDef(typeInst->GetSingleWordOperand(1)));
+    return IsBaseTargetType(
+        def_use_mgr_->GetDef(typeInst->GetSingleWordOperand(1)));
   if (typeInst->opcode() != SpvOpTypeStruct)
     return false;
   // All struct members must be math type
   int nonMathComp = 0;
   typeInst->ForEachInId([&nonMathComp,this](const uint32_t* tid) {
     ir::Instruction* compTypeInst = def_use_mgr_->GetDef(*tid);
-    if (!IsMathType(compTypeInst)) ++nonMathComp;
+    if (!IsBaseTargetType(compTypeInst)) ++nonMathComp;
   });
   return nonMathComp == 0;
 }
index f670289..4f28cc8 100644 (file)
@@ -43,7 +43,7 @@ class MemPass : public Pass {
  protected:
   // Returns true if |typeInst| is a scalar type
   // or a vector or matrix
-  bool IsMathType(const ir::Instruction* typeInst) const;
+  bool IsBaseTargetType(const ir::Instruction* typeInst) const;
 
   // Returns true if |typeInst| is a math type or a struct or array
   // of a math type.