Quellcode durchsuchen

Merge branch 'rtmaster' into user/texr/rt-merge-rebase

Tex Riddell vor 7 Jahren
Ursprung
Commit
634fd7556b
33 geänderte Dateien mit 277 neuen und 92 gelöschten Zeilen
  1. 1 1
      external/SPIRV-Tools
  2. 2 2
      lib/HLSL/DxilOperations.cpp
  3. 21 3
      lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp
  4. 102 0
      tools/clang/lib/CodeGen/CGHLSLMS.cpp
  5. 2 3
      tools/clang/lib/SPIRV/DeclResultIdMapper.cpp
  6. 41 21
      tools/clang/lib/SPIRV/SPIRVEmitter.cpp
  7. 5 5
      tools/clang/lib/SPIRV/SPIRVEmitter.h
  8. 3 4
      tools/clang/lib/Sema/SemaHLSL.cpp
  9. 11 0
      tools/clang/test/CodeGenHLSL/quick-test/immSel.hlsl
  10. 10 0
      tools/clang/test/CodeGenHLSL/quick-test/signature_dbg_info.hlsl
  11. 16 0
      tools/clang/test/CodeGenHLSL/quick-test/vecCombineSel.hlsl
  12. 6 0
      tools/clang/test/CodeGenSPIRV/attribute.earlydepthstencil.ps.hlsl
  13. 3 3
      tools/clang/test/CodeGenSPIRV/cast.flat-conversion.no-op.hlsl
  14. 4 4
      tools/clang/test/CodeGenSPIRV/cf.if.plain.hlsl
  15. 3 3
      tools/clang/test/CodeGenSPIRV/fn.ctbuffer.hlsl
  16. 5 5
      tools/clang/test/CodeGenSPIRV/op.cbuffer.access.hlsl
  17. 5 5
      tools/clang/test/CodeGenSPIRV/op.tbuffer.access.hlsl
  18. 4 4
      tools/clang/test/CodeGenSPIRV/type.cbuffer.hlsl
  19. 4 4
      tools/clang/test/CodeGenSPIRV/type.tbuffer.hlsl
  20. 2 2
      tools/clang/test/CodeGenSPIRV/var.init.cross-storage-class.hlsl
  21. 2 2
      tools/clang/test/CodeGenSPIRV/vk.binding.explicit.hlsl
  22. 2 2
      tools/clang/test/CodeGenSPIRV/vk.binding.implicit.hlsl
  23. 2 2
      tools/clang/test/CodeGenSPIRV/vk.binding.register.hlsl
  24. 2 2
      tools/clang/test/CodeGenSPIRV/vk.cloption.ignore-unused-resources.hlsl
  25. 3 3
      tools/clang/test/CodeGenSPIRV/vk.layout.cbuffer.zpc.hlsl
  26. 3 3
      tools/clang/test/CodeGenSPIRV/vk.layout.cbuffer.zpr.hlsl
  27. 1 1
      tools/clang/test/HLSL/vector-conditional.hlsl
  28. 1 1
      tools/clang/tools/dxc/dxc.cpp
  29. 3 2
      tools/clang/unittests/HLSL/ExecutionTest.cpp
  30. 2 2
      tools/clang/unittests/HLSL/ShaderOpArithTable.xml
  31. 3 0
      tools/clang/unittests/SPIRV/CodeGenSPIRVTest.cpp
  32. 2 2
      utils/hct/hctdb.py
  33. 1 1
      utils/hct/hctdb_test.py

+ 1 - 1
external/SPIRV-Tools

@@ -1 +1 @@
-Subproject commit e7fafdaa68a3775be5f2406e91db4b5d3fbc7b35
+Subproject commit 6c75050136a2657dac4501ca16d447852fc69e5f

+ 2 - 2
lib/HLSL/DxilOperations.cpp

@@ -160,8 +160,8 @@ const OP::OpCodeProperty OP::m_OpCodeProps[(unsigned)OP::OpCode::NumOpCodes] = {
   {  OC::GetDimensions,           "GetDimensions",            OCC::GetDimensions,            "getDimensions",               true, false, false, false, false, false, false, false, false, false, false, Attribute::ReadOnly, },
   {  OC::GetDimensions,           "GetDimensions",            OCC::GetDimensions,            "getDimensions",               true, false, false, false, false, false, false, false, false, false, false, Attribute::ReadOnly, },
 
 
   // Resources - gather                                                                                                     void,     h,     f,     d,    i1,    i8,   i16,   i32,   i64,   udt,  obj,  function attribute
   // Resources - gather                                                                                                     void,     h,     f,     d,    i1,    i8,   i16,   i32,   i64,   udt,  obj,  function attribute
-  {  OC::TextureGather,           "TextureGather",            OCC::TextureGather,            "textureGather",              false, false,  true, false, false, false, false,  true, false, false, false, Attribute::ReadOnly, },
-  {  OC::TextureGatherCmp,        "TextureGatherCmp",         OCC::TextureGatherCmp,         "textureGatherCmp",           false, false,  true, false, false, false, false,  true, false, false, false, Attribute::ReadOnly, },
+  {  OC::TextureGather,           "TextureGather",            OCC::TextureGather,            "textureGather",              false,  true,  true, false, false, false,  true,  true, false, false, false, Attribute::ReadOnly, },
+  {  OC::TextureGatherCmp,        "TextureGatherCmp",         OCC::TextureGatherCmp,         "textureGatherCmp",           false,  true,  true, false, false, false,  true,  true, false, false, false, Attribute::ReadOnly, },
 
 
   // Resources - sample                                                                                                     void,     h,     f,     d,    i1,    i8,   i16,   i32,   i64,   udt,  obj,  function attribute
   // Resources - sample                                                                                                     void,     h,     f,     d,    i1,    i8,   i16,   i32,   i64,   udt,  obj,  function attribute
   {  OC::Texture2DMSGetSamplePosition, "Texture2DMSGetSamplePosition", OCC::Texture2DMSGetSamplePosition, "texture2DMSGetSamplePosition",   true, false, false, false, false, false, false, false, false, false, false, Attribute::ReadOnly, },
   {  OC::Texture2DMSGetSamplePosition, "Texture2DMSGetSamplePosition", OCC::Texture2DMSGetSamplePosition, "texture2DMSGetSamplePosition",   true, false, false, false, false, false, false, false, false, false, false, Attribute::ReadOnly, },

+ 21 - 3
lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp

@@ -5898,14 +5898,32 @@ void SROA_Parameter_HLSL::createFlattenedFunction(Function *F) {
                              castParamMap[flatArg].second, Builder);
                              castParamMap[flatArg].second, Builder);
       }
       }
 
 
-      flatArg->replaceAllUsesWith(Arg);
       // Update arg debug info.
       // Update arg debug info.
       DbgDeclareInst *DDI = llvm::FindAllocaDbgDeclare(flatArg);
       DbgDeclareInst *DDI = llvm::FindAllocaDbgDeclare(flatArg);
       if (DDI) {
       if (DDI) {
-        Value *VMD = MetadataAsValue::get(Context, ValueAsMetadata::get(Arg));
-        DDI->setArgOperand(0, VMD);
+        if (!flatArg->getType()->isPointerTy()) {
+          // Create alloca to hold the debug info.
+          Value *allocaArg = nullptr;
+          if (flatArg->hasOneUse() && isa<StoreInst>(*flatArg->user_begin())) {
+            StoreInst *SI = cast<StoreInst>(*flatArg->user_begin());
+            allocaArg = SI->getPointerOperand();
+          } else {
+            allocaArg = Builder.CreateAlloca(flatArg->getType());
+            StoreInst *initArg = Builder.CreateStore(flatArg, allocaArg);
+            Value *ldArg = Builder.CreateLoad(allocaArg);
+            flatArg->replaceAllUsesWith(ldArg);
+            initArg->setOperand(0, flatArg);
+          }
+          Value *VMD = MetadataAsValue::get(Context, ValueAsMetadata::get(allocaArg));
+          DDI->setArgOperand(0, VMD);
+        } else {
+          Value *VMD = MetadataAsValue::get(Context, ValueAsMetadata::get(Arg));
+          DDI->setArgOperand(0, VMD);
+        }
       }
       }
 
 
+      flatArg->replaceAllUsesWith(Arg);
+
       HLModule::MergeGepUse(Arg);
       HLModule::MergeGepUse(Arg);
       // Flatten store of array parameter.
       // Flatten store of array parameter.
       if (Arg->getType()->isPointerTy()) {
       if (Arg->getType()->isPointerTy()) {

+ 102 - 0
tools/clang/lib/CodeGen/CGHLSLMS.cpp

@@ -5479,6 +5479,83 @@ void CGMSHLSLRuntime::EmitHLSLDiscard(CodeGenFunction &CGF) {
       TheModule);
       TheModule);
 }
 }
 
 
+static llvm::Type *MergeIntType(llvm::IntegerType *T0, llvm::IntegerType *T1) {
+  if (T0->getBitWidth() > T1->getBitWidth())
+    return T0;
+  else
+    return T1;
+}
+
+static Value *CreateExt(CGBuilderTy &Builder, Value *Src, llvm::Type *DstTy,
+                        bool bSigned) {
+  if (bSigned)
+    return Builder.CreateSExt(Src, DstTy);
+  else
+    return Builder.CreateZExt(Src, DstTy);
+}
+// For integer literal, try to get lowest precision.
+static Value *CalcHLSLLiteralToLowestPrecision(CGBuilderTy &Builder, Value *Src,
+                                               bool bSigned) {
+  if (ConstantInt *CI = dyn_cast<ConstantInt>(Src)) {
+    APInt v = CI->getValue();
+    switch (v.getActiveWords()) {
+    case 4:
+      return Builder.getInt32(v.getLimitedValue());
+    case 8:
+      return Builder.getInt64(v.getLimitedValue());
+    case 2:
+      // TODO: use low precision type when support it in dxil.
+      // return Builder.getInt16(v.getLimitedValue());
+      return Builder.getInt32(v.getLimitedValue());
+    case 1:
+      // TODO: use precision type when support it in dxil.
+      // return Builder.getInt8(v.getLimitedValue());
+      return Builder.getInt32(v.getLimitedValue());
+    default:
+      return nullptr;
+    }
+  } else if (SelectInst *SI = dyn_cast<SelectInst>(Src)) {
+    if (SI->getType()->isIntegerTy()) {
+      Value *T = SI->getTrueValue();
+      Value *F = SI->getFalseValue();
+      Value *lowT = CalcHLSLLiteralToLowestPrecision(Builder, T, bSigned);
+      Value *lowF = CalcHLSLLiteralToLowestPrecision(Builder, F, bSigned);
+      if (lowT && lowF && lowT != T && lowF != F) {
+        llvm::IntegerType *TTy = cast<llvm::IntegerType>(lowT->getType());
+        llvm::IntegerType *FTy = cast<llvm::IntegerType>(lowF->getType());
+        llvm::Type *Ty = MergeIntType(TTy, FTy);
+        if (TTy != Ty) {
+          lowT = CreateExt(Builder, lowT, Ty, bSigned);
+        }
+        if (FTy != Ty) {
+          lowF = CreateExt(Builder, lowF, Ty, bSigned);
+        }
+        Value *Cond = SI->getCondition();
+        return Builder.CreateSelect(Cond, lowT, lowF);
+      }
+    }
+  } else if (llvm::BinaryOperator *BO = dyn_cast<llvm::BinaryOperator>(Src)) {
+    Value *Src0 = BO->getOperand(0);
+    Value *Src1 = BO->getOperand(1);
+    Value *CastSrc0 = CalcHLSLLiteralToLowestPrecision(Builder, Src0, bSigned);
+    Value *CastSrc1 = CalcHLSLLiteralToLowestPrecision(Builder, Src1, bSigned);
+    if (Src0 != CastSrc0 && Src1 != CastSrc1 && CastSrc0 && CastSrc1 &&
+        CastSrc0->getType() == CastSrc1->getType()) {
+      llvm::IntegerType *Ty0 = cast<llvm::IntegerType>(CastSrc0->getType());
+      llvm::IntegerType *Ty1 = cast<llvm::IntegerType>(CastSrc0->getType());
+      llvm::Type *Ty = MergeIntType(Ty0, Ty1);
+      if (Ty0 != Ty) {
+        CastSrc0 = CreateExt(Builder, CastSrc0, Ty, bSigned);
+      }
+      if (Ty1 != Ty) {
+        CastSrc1 = CreateExt(Builder, CastSrc1, Ty, bSigned);
+      }
+      return Builder.CreateBinOp(BO->getOpcode(), CastSrc0, CastSrc1);
+    }
+  }
+  return nullptr;
+}
+
 Value *CGMSHLSLRuntime::EmitHLSLLiteralCast(CodeGenFunction &CGF, Value *Src,
 Value *CGMSHLSLRuntime::EmitHLSLLiteralCast(CodeGenFunction &CGF, Value *Src,
                                             QualType SrcType,
                                             QualType SrcType,
                                             QualType DstType) {
                                             QualType DstType) {
@@ -5588,6 +5665,31 @@ Value *CGMSHLSLRuntime::EmitHLSLLiteralCast(CodeGenFunction &CGF, Value *Src,
           return Sel;
           return Sel;
         }
         }
       }
       }
+    } else if (llvm::BinaryOperator *BO = dyn_cast<llvm::BinaryOperator>(I)) {
+      // For integer binary operator, do the calc on lowest precision, then cast
+      // to dstTy.
+      if (I->getType()->isIntegerTy()) {
+        bool bSigned = DstType->isSignedIntegerType();
+        Value *CastResult =
+            CalcHLSLLiteralToLowestPrecision(Builder, BO, bSigned);
+        if (!CastResult)
+          return nullptr;
+        if (llvm::IntegerType *IT = dyn_cast<llvm::IntegerType>(DstTy)) {
+          if (DstTy == CastResult->getType()) {
+            return CastResult;
+          } else {
+            if (bSigned)
+              return Builder.CreateSExtOrTrunc(CastResult, DstTy);
+            else
+              return Builder.CreateZExtOrTrunc(CastResult, DstTy);
+          }
+        } else {
+          if (bDstSigned)
+            return Builder.CreateSIToFP(CastResult, DstTy);
+          else
+            return Builder.CreateUIToFP(CastResult, DstTy);
+        }
+      }
     }
     }
     // TODO: support other opcode if need.
     // TODO: support other opcode if need.
     return nullptr;
     return nullptr;

+ 2 - 3
tools/clang/lib/SPIRV/DeclResultIdMapper.cpp

@@ -555,9 +555,8 @@ uint32_t DeclResultIdMapper::createCTBuffer(const HLSLBufferDecl *decl) {
   const auto usageKind =
   const auto usageKind =
       decl->isCBuffer() ? ContextUsageKind::CBuffer : ContextUsageKind::TBuffer;
       decl->isCBuffer() ? ContextUsageKind::CBuffer : ContextUsageKind::TBuffer;
   const std::string structName = "type." + decl->getName().str();
   const std::string structName = "type." + decl->getName().str();
-  const std::string varName = "var." + decl->getName().str();
-  const uint32_t bufferVar =
-      createVarOfExplicitLayoutStruct(decl, usageKind, structName, varName);
+  const uint32_t bufferVar = createVarOfExplicitLayoutStruct(
+      decl, usageKind, structName, decl->getName());
 
 
   // We still register all VarDecls seperately here. All the VarDecls are
   // We still register all VarDecls seperately here. All the VarDecls are
   // mapped to the <result-id> of the buffer object, which means when querying
   // mapped to the <result-id> of the buffer object, which means when querying

+ 41 - 21
tools/clang/lib/SPIRV/SPIRVEmitter.cpp

@@ -535,8 +535,6 @@ void SPIRVEmitter::HandleTranslationUnit(ASTContext &context) {
   theBuilder.addEntryPoint(getSpirvShaderStage(shaderModel), entryFunctionId,
   theBuilder.addEntryPoint(getSpirvShaderStage(shaderModel), entryFunctionId,
                            entryFunctionName, declIdMapper.collectStageVars());
                            entryFunctionName, declIdMapper.collectStageVars());
 
 
-  AddExecutionModeForEntryPoint(entryFunctionId);
-
   // Add Location decorations to stage input/output variables.
   // Add Location decorations to stage input/output variables.
   if (!declIdMapper.decorateStageIOLocations())
   if (!declIdMapper.decorateStageIOLocations())
     return;
     return;
@@ -631,7 +629,7 @@ void SPIRVEmitter::doStmt(const Stmt *stmt,
   } else if (const auto *declStmt = dyn_cast<DeclStmt>(stmt)) {
   } else if (const auto *declStmt = dyn_cast<DeclStmt>(stmt)) {
     doDeclStmt(declStmt);
     doDeclStmt(declStmt);
   } else if (const auto *ifStmt = dyn_cast<IfStmt>(stmt)) {
   } else if (const auto *ifStmt = dyn_cast<IfStmt>(stmt)) {
-    doIfStmt(ifStmt);
+    doIfStmt(ifStmt, attrs);
   } else if (const auto *switchStmt = dyn_cast<SwitchStmt>(stmt)) {
   } else if (const auto *switchStmt = dyn_cast<SwitchStmt>(stmt)) {
     doSwitchStmt(switchStmt, attrs);
     doSwitchStmt(switchStmt, attrs);
   } else if (const auto *caseStmt = dyn_cast<CaseStmt>(stmt)) {
   } else if (const auto *caseStmt = dyn_cast<CaseStmt>(stmt)) {
@@ -1513,7 +1511,8 @@ void SPIRVEmitter::doForStmt(const ForStmt *forStmt,
   breakStack.pop();
   breakStack.pop();
 }
 }
 
 
-void SPIRVEmitter::doIfStmt(const IfStmt *ifStmt) {
+void SPIRVEmitter::doIfStmt(const IfStmt *ifStmt,
+                            llvm::ArrayRef<const Attr *> attrs) {
   // if statements are composed of:
   // if statements are composed of:
   //   if (<check>) { <then> } else { <else> }
   //   if (<check>) { <then> } else { <else> }
   //
   //
@@ -1551,6 +1550,24 @@ void SPIRVEmitter::doIfStmt(const IfStmt *ifStmt) {
     }
     }
   }
   }
 
 
+  auto selectionControl = spv::SelectionControlMask::MaskNone;
+  if (!attrs.empty()) {
+    const Attr *attribute = attrs.front();
+    switch (attribute->getKind()) {
+    case attr::HLSLBranch:
+      selectionControl = spv::SelectionControlMask::DontFlatten;
+      break;
+    case attr::HLSLFlatten:
+      selectionControl = spv::SelectionControlMask::Flatten;
+      break;
+    default:
+      emitWarning("unknown if statement attribute '%0' ignored",
+                  attribute->getLocation())
+          << attribute->getSpelling();
+      break;
+    }
+  }
+
   if (const auto *declStmt = ifStmt->getConditionVariableDeclStmt())
   if (const auto *declStmt = ifStmt->getConditionVariableDeclStmt())
     doDeclStmt(declStmt);
     doDeclStmt(declStmt);
 
 
@@ -1566,7 +1583,8 @@ void SPIRVEmitter::doIfStmt(const IfStmt *ifStmt) {
       hasElse ? theBuilder.createBasicBlock("if.false") : mergeBB;
       hasElse ? theBuilder.createBasicBlock("if.false") : mergeBB;
 
 
   // Create the branch instruction. This will end the current basic block.
   // Create the branch instruction. This will end the current basic block.
-  theBuilder.createConditionalBranch(condition, thenBB, elseBB, mergeBB);
+  theBuilder.createConditionalBranch(condition, thenBB, elseBB, mergeBB,
+                                     /*continue*/ 0, selectionControl);
   theBuilder.addSuccessor(thenBB);
   theBuilder.addSuccessor(thenBB);
   theBuilder.addSuccessor(elseBB);
   theBuilder.addSuccessor(elseBB);
   // The current basic block has the OpSelectionMerge instruction. We need
   // The current basic block has the OpSelectionMerge instruction. We need
@@ -5574,10 +5592,9 @@ uint32_t SPIRVEmitter::castToInt(const uint32_t fromVal, QualType fromType,
       // The source matrix and the target matrix must have the same dimensions.
       // The source matrix and the target matrix must have the same dimensions.
       QualType toElemType = {};
       QualType toElemType = {};
       uint32_t toNumRows = 0, toNumCols = 0;
       uint32_t toNumRows = 0, toNumCols = 0;
-      assert(TypeTranslator::isMxNMatrix(toIntType, &toElemType, &toNumRows,
-                                         &toNumCols) &&
-             numRows == toNumRows && numCols == toNumCols);
-      (void)toElemType;
+      const bool isMat = TypeTranslator::isMxNMatrix(toIntType, &toElemType,
+                                                     &toNumRows, &toNumCols);
+      assert(isMat && numRows == toNumRows && numCols == toNumCols);
       (void)toNumRows;
       (void)toNumRows;
       (void)toNumCols;
       (void)toNumCols;
 
 
@@ -5636,10 +5653,9 @@ uint32_t SPIRVEmitter::castToFloat(const uint32_t fromVal, QualType fromType,
       // The source matrix and the target matrix must have the same dimensions.
       // The source matrix and the target matrix must have the same dimensions.
       QualType toElemType = {};
       QualType toElemType = {};
       uint32_t toNumRows = 0, toNumCols = 0;
       uint32_t toNumRows = 0, toNumCols = 0;
-      assert(TypeTranslator::isMxNMatrix(toFloatType, &toElemType, &toNumRows,
-                                         &toNumCols) &&
-             numRows == toNumRows && numCols == toNumCols);
-      (void)toElemType;
+      const auto isMat = TypeTranslator::isMxNMatrix(toFloatType, &toElemType,
+                                                     &toNumRows, &toNumCols);
+      assert(isMat && numRows == toNumRows && numCols == toNumCols);
       (void)toNumRows;
       (void)toNumRows;
       (void)toNumCols;
       (void)toNumCols;
 
 
@@ -8092,13 +8108,6 @@ void SPIRVEmitter::AddRequiredCapabilitiesForShaderModel() {
   }
   }
 }
 }
 
 
-void SPIRVEmitter::AddExecutionModeForEntryPoint(uint32_t entryPointId) {
-  if (shaderModel.IsPS()) {
-    theBuilder.addExecutionMode(entryPointId,
-                                spv::ExecutionMode::OriginUpperLeft, {});
-  }
-}
-
 bool SPIRVEmitter::processGeometryShaderAttributes(const FunctionDecl *decl,
 bool SPIRVEmitter::processGeometryShaderAttributes(const FunctionDecl *decl,
                                                    uint32_t *arraySize) {
                                                    uint32_t *arraySize) {
   bool success = true;
   bool success = true;
@@ -8188,6 +8197,15 @@ bool SPIRVEmitter::processGeometryShaderAttributes(const FunctionDecl *decl,
   return success;
   return success;
 }
 }
 
 
+void SPIRVEmitter::processPixelShaderAttributes(const FunctionDecl *decl) {
+  theBuilder.addExecutionMode(entryFunctionId,
+                              spv::ExecutionMode::OriginUpperLeft, {});
+  if (auto *numThreadsAttr = decl->getAttr<HLSLEarlyDepthStencilAttr>()) {
+    theBuilder.addExecutionMode(entryFunctionId,
+                                spv::ExecutionMode::EarlyFragmentTests, {});
+  }
+}
+
 void SPIRVEmitter::processComputeShaderAttributes(const FunctionDecl *decl) {
 void SPIRVEmitter::processComputeShaderAttributes(const FunctionDecl *decl) {
   // If not explicitly specified, x, y, and z should be defaulted to 1.
   // If not explicitly specified, x, y, and z should be defaulted to 1.
   uint32_t x = 1, y = 1, z = 1;
   uint32_t x = 1, y = 1, z = 1;
@@ -8314,7 +8332,9 @@ bool SPIRVEmitter::emitEntryFunctionWrapper(const FunctionDecl *decl,
   declIdMapper.setEntryFunctionId(entryFunctionId);
   declIdMapper.setEntryFunctionId(entryFunctionId);
 
 
   // Handle attributes specific to each shader stage
   // Handle attributes specific to each shader stage
-  if (shaderModel.IsCS()) {
+  if (shaderModel.IsPS()) {
+    processPixelShaderAttributes(decl);
+  } else if (shaderModel.IsCS()) {
     processComputeShaderAttributes(decl);
     processComputeShaderAttributes(decl);
   } else if (shaderModel.IsHS()) {
   } else if (shaderModel.IsHS()) {
     if (!processTessellationShaderAttributes(decl, &numOutputControlPoints))
     if (!processTessellationShaderAttributes(decl, &numOutputControlPoints))

+ 5 - 5
tools/clang/lib/SPIRV/SPIRVEmitter.h

@@ -83,7 +83,7 @@ private:
   void doDiscardStmt(const DiscardStmt *stmt);
   void doDiscardStmt(const DiscardStmt *stmt);
   inline void doDeclStmt(const DeclStmt *stmt);
   inline void doDeclStmt(const DeclStmt *stmt);
   void doForStmt(const ForStmt *, llvm::ArrayRef<const Attr *> attrs = {});
   void doForStmt(const ForStmt *, llvm::ArrayRef<const Attr *> attrs = {});
-  void doIfStmt(const IfStmt *ifStmt);
+  void doIfStmt(const IfStmt *ifStmt, llvm::ArrayRef<const Attr *> attrs = {});
   void doReturnStmt(const ReturnStmt *stmt);
   void doReturnStmt(const ReturnStmt *stmt);
   void doSwitchStmt(const SwitchStmt *stmt,
   void doSwitchStmt(const SwitchStmt *stmt,
                     llvm::ArrayRef<const Attr *> attrs = {});
                     llvm::ArrayRef<const Attr *> attrs = {});
@@ -507,10 +507,6 @@ private:
 
 
   void AddRequiredCapabilitiesForShaderModel();
   void AddRequiredCapabilitiesForShaderModel();
 
 
-  /// \brief Adds the execution mode for the given entry point based on the
-  /// shader model.
-  void AddExecutionModeForEntryPoint(uint32_t entryPointId);
-
   /// \brief Adds necessary execution modes for the hull/domain shaders based on
   /// \brief Adds necessary execution modes for the hull/domain shaders based on
   /// the HLSL attributes of the entry point function.
   /// the HLSL attributes of the entry point function.
   /// In the case of hull shaders, also writes the number of output control
   /// In the case of hull shaders, also writes the number of output control
@@ -525,6 +521,10 @@ private:
   bool processGeometryShaderAttributes(const FunctionDecl *entryFunction,
   bool processGeometryShaderAttributes(const FunctionDecl *entryFunction,
                                        uint32_t *arraySize);
                                        uint32_t *arraySize);
 
 
+  /// \brief Adds necessary execution modes for the pixel shader based on the
+  /// HLSL attributes of the entry point function.
+  void processPixelShaderAttributes(const FunctionDecl *decl);
+
   /// \brief Adds necessary execution modes for the compute shader based on the
   /// \brief Adds necessary execution modes for the compute shader based on the
   /// HLSL attributes of the entry point function.
   /// HLSL attributes of the entry point function.
   void processComputeShaderAttributes(const FunctionDecl *entryFunction);
   void processComputeShaderAttributes(const FunctionDecl *entryFunction);

+ 3 - 4
tools/clang/lib/Sema/SemaHLSL.cpp

@@ -8431,10 +8431,6 @@ clang::QualType HLSLExternalSource::CheckVectorConditional(
       rightObjectKind == AR_TOBJ_BASIC || rightObjectKind == AR_TOBJ_VECTOR ||
       rightObjectKind == AR_TOBJ_BASIC || rightObjectKind == AR_TOBJ_VECTOR ||
       rightObjectKind == AR_TOBJ_MATRIX;
       rightObjectKind == AR_TOBJ_MATRIX;
 
 
-  
-  UINT rowCount, colCount;
-  GetRowsAndColsForAny(ResultTy, rowCount, colCount);
-
   if (!leftIsSimple || !rightIsSimple) {
   if (!leftIsSimple || !rightIsSimple) {
     if (leftObjectKind == AR_TOBJ_OBJECT && leftObjectKind == AR_TOBJ_OBJECT) {
     if (leftObjectKind == AR_TOBJ_OBJECT && leftObjectKind == AR_TOBJ_OBJECT) {
       if (leftType == rightType) {
       if (leftType == rightType) {
@@ -8465,6 +8461,9 @@ clang::QualType HLSLExternalSource::CheckVectorConditional(
     return QualType();
     return QualType();
   }
   }
 
 
+  UINT rowCount, colCount;
+  GetRowsAndColsForAny(ResultTy, rowCount, colCount);
+
   // If result is scalar, use condition dimensions.
   // If result is scalar, use condition dimensions.
   // Otherwise, condition must either match or is scalar, then use result dimensions
   // Otherwise, condition must either match or is scalar, then use result dimensions
   if (rowCount * colCount == 1) {
   if (rowCount * colCount == 1) {

+ 11 - 0
tools/clang/test/CodeGenHLSL/quick-test/immSel.hlsl

@@ -0,0 +1,11 @@
+// RUN: %dxc -T ps_6_0 -O0 -E main %s | FileCheck %s
+
+// Make sure use literal int is selected into i32 for value fit in i32.
+
+// CHECK-NOT: or i64
+// CHECK: or i32
+
+uint main(const float4 P: A ) : SV_Target
+{
+    return ((P.x < -P.w) ? 3 : 9) | ((P.y < -P.z) ? 5 : 3);
+}

+ 10 - 0
tools/clang/test/CodeGenHLSL/quick-test/signature_dbg_info.hlsl

@@ -0,0 +1,10 @@
+// RUN: %dxc -E main -T ps_6_0 -Od -Zi  %s | FileCheck %s
+
+// Make sure debug info for inp exist.
+// CHECK: !DILocalVariable(tag: DW_TAG_arg_variable, name: "inp"
+
+
+float4 main(float4 inp : COLOR) : SV_TARGET0 {
+    float4 a = inp;
+    return a;
+}

+ 16 - 0
tools/clang/test/CodeGenHLSL/quick-test/vecCombineSel.hlsl

@@ -0,0 +1,16 @@
+// RUN: %dxc -E main -T cs_6_0 %s | FileCheck %s
+
+
+
+// Make sure both channel is used.
+
+// CHECK: extractvalue %dx.types.CBufRet.i32 {{.*}}, 0
+// CHECK: extractvalue %dx.types.CBufRet.i32 {{.*}}, 1
+
+RWBuffer<uint2> output;
+uint2 a;
+[numthreads(4, 4, 4)]
+void main(uint3 iv : SV_GroupThreadID)
+{
+	output[0] = iv.x == 0 ? 0 : a;
+}

+ 6 - 0
tools/clang/test/CodeGenSPIRV/attribute.earlydepthstencil.ps.hlsl

@@ -0,0 +1,6 @@
+// Run: %dxc -T ps_6_0 -E main
+
+// CHECK: OpExecutionMode %main EarlyFragmentTests
+
+[earlydepthstencil]
+float4 main() : SV_Target { return 1.0; }

+ 3 - 3
tools/clang/test/CodeGenSPIRV/cast.flat-conversion.no-op.hlsl

@@ -15,7 +15,7 @@ struct T {
 float4 main() : SV_Target {
 float4 main() : SV_Target {
     T t;
     T t;
 
 
-// CHECK:        [[gscalars_ptr:%\d+]] = OpAccessChain %_ptr_Uniform__arr_float_uint_1 %var_Data %int_0
+// CHECK:        [[gscalars_ptr:%\d+]] = OpAccessChain %_ptr_Uniform__arr_float_uint_1 %Data %int_0
 // CHECK-NEXT:   [[gscalars_val:%\d+]] = OpLoad %_arr_float_uint_1 [[gscalars_ptr]]
 // CHECK-NEXT:   [[gscalars_val:%\d+]] = OpLoad %_arr_float_uint_1 [[gscalars_ptr]]
 // CHECK-NEXT:    [[scalars_ptr:%\d+]] = OpAccessChain %_ptr_Function__arr_float_uint_1_0 %t %int_0
 // CHECK-NEXT:    [[scalars_ptr:%\d+]] = OpAccessChain %_ptr_Function__arr_float_uint_1_0 %t %int_0
 // CHECK-NEXT:      [[gscalars0:%\d+]] = OpCompositeExtract %float [[gscalars_val]] 0
 // CHECK-NEXT:      [[gscalars0:%\d+]] = OpCompositeExtract %float [[gscalars_val]] 0
@@ -23,7 +23,7 @@ float4 main() : SV_Target {
 // CHECK-NEXT:                           OpStore [[scalars0_ptr]] [[gscalars0]]
 // CHECK-NEXT:                           OpStore [[scalars0_ptr]] [[gscalars0]]
     t.scalars = gScalars;
     t.scalars = gScalars;
 
 
-// CHECK-NEXT: [[gvecs_ptr:%\d+]] = OpAccessChain %_ptr_Uniform__arr_v4float_uint_2 %var_Data %int_1
+// CHECK-NEXT: [[gvecs_ptr:%\d+]] = OpAccessChain %_ptr_Uniform__arr_v4float_uint_2 %Data %int_1
 // CHECK-NEXT: [[gvecs_val:%\d+]] = OpLoad %_arr_v4float_uint_2 [[gvecs_ptr]]
 // CHECK-NEXT: [[gvecs_val:%\d+]] = OpLoad %_arr_v4float_uint_2 [[gvecs_ptr]]
 // CHECK-NEXT:  [[vecs_ptr:%\d+]] = OpAccessChain %_ptr_Function__arr_v4float_uint_2_0 %t %int_1
 // CHECK-NEXT:  [[vecs_ptr:%\d+]] = OpAccessChain %_ptr_Function__arr_v4float_uint_2_0 %t %int_1
 // CHECK-NEXT:    [[gvecs0:%\d+]] = OpCompositeExtract %v4float [[gvecs_val]] 0
 // CHECK-NEXT:    [[gvecs0:%\d+]] = OpCompositeExtract %v4float [[gvecs_val]] 0
@@ -34,7 +34,7 @@ float4 main() : SV_Target {
 // CHECK-NEXT:                      OpStore [[vecs1_ptr]] [[gvecs1]]
 // CHECK-NEXT:                      OpStore [[vecs1_ptr]] [[gvecs1]]
     t.vecs    = gVecs;
     t.vecs    = gVecs;
 
 
-// CHECK-NEXT: [[gmats_ptr:%\d+]] = OpAccessChain %_ptr_Uniform__arr_mat2v3float_uint_1 %var_Data %int_2
+// CHECK-NEXT: [[gmats_ptr:%\d+]] = OpAccessChain %_ptr_Uniform__arr_mat2v3float_uint_1 %Data %int_2
 // CHECK-NEXT: [[gmats_val:%\d+]] = OpLoad %_arr_mat2v3float_uint_1 [[gmats_ptr]]
 // CHECK-NEXT: [[gmats_val:%\d+]] = OpLoad %_arr_mat2v3float_uint_1 [[gmats_ptr]]
 // CHECK-NEXT:  [[mats_ptr:%\d+]] = OpAccessChain %_ptr_Function__arr_mat2v3float_uint_1_0 %t %int_2
 // CHECK-NEXT:  [[mats_ptr:%\d+]] = OpAccessChain %_ptr_Function__arr_mat2v3float_uint_1_0 %t %int_2
 // CHECK-NEXT:    [[gmats0:%\d+]] = OpCompositeExtract %mat2v3float [[gmats_val]] 0
 // CHECK-NEXT:    [[gmats0:%\d+]] = OpCompositeExtract %mat2v3float [[gmats_val]] 0

+ 4 - 4
tools/clang/test/CodeGenSPIRV/cf.if.plain.hlsl

@@ -7,9 +7,9 @@ void main() {
 
 
     // Both then and else
     // Both then and else
 // CHECK:      [[c0:%\d+]] = OpLoad %bool %c
 // CHECK:      [[c0:%\d+]] = OpLoad %bool %c
-// CHECK-NEXT: OpSelectionMerge %if_merge None
+// CHECK-NEXT: OpSelectionMerge %if_merge Flatten
 // CHECK-NEXT: OpBranchConditional [[c0]] %if_true %if_false
 // CHECK-NEXT: OpBranchConditional [[c0]] %if_true %if_false
-    if (c) {
+    [flatten] if (c) {
 // CHECK-LABEL: %if_true = OpLabel
 // CHECK-LABEL: %if_true = OpLabel
 // CHECK-NEXT: [[val0:%\d+]] = OpLoad %int %val
 // CHECK-NEXT: [[val0:%\d+]] = OpLoad %int %val
 // CHECK-NEXT: [[val1:%\d+]] = OpIAdd %int [[val0]] %int_1
 // CHECK-NEXT: [[val1:%\d+]] = OpIAdd %int [[val0]] %int_1
@@ -67,9 +67,9 @@ void main() {
 // CHECK-NEXT: OpStore %d [[val4]]
 // CHECK-NEXT: OpStore %d [[val4]]
 // CHECK-NEXT: [[d:%\d+]] = OpLoad %int %d
 // CHECK-NEXT: [[d:%\d+]] = OpLoad %int %d
 // CHECK-NEXT: [[cmp:%\d+]] = OpINotEqual %bool [[d]] %int_0
 // CHECK-NEXT: [[cmp:%\d+]] = OpINotEqual %bool [[d]] %int_0
-// CHECK-NEXT: OpSelectionMerge %if_merge_3 None
+// CHECK-NEXT: OpSelectionMerge %if_merge_3 DontFlatten
 // CHECK-NEXT: OpBranchConditional [[cmp]] %if_true_3 %if_merge_3
 // CHECK-NEXT: OpBranchConditional [[cmp]] %if_true_3 %if_merge_3
-    if (int d = val) {
+    [branch] if (int d = val) {
 // CHECK-LABEL: %if_true_3 = OpLabel
 // CHECK-LABEL: %if_true_3 = OpLabel
 // CHECK-NEXT: OpStore %c %true
 // CHECK-NEXT: OpStore %c %true
         c = true;
         c = true;

+ 3 - 3
tools/clang/test/CodeGenSPIRV/fn.ctbuffer.hlsl

@@ -27,7 +27,7 @@ tbuffer MyTBuffer {
 float4 main() : SV_Target {
 float4 main() : SV_Target {
 // %S vs %S_0: need destruction and construction
 // %S vs %S_0: need destruction and construction
 // CHECK:         %temp_var_S = OpVariable %_ptr_Function_S_0 Function
 // CHECK:         %temp_var_S = OpVariable %_ptr_Function_S_0 Function
-// CHECK:       [[tb_s:%\d+]] = OpAccessChain %_ptr_Uniform_S %var_MyTBuffer %int_1
+// CHECK:       [[tb_s:%\d+]] = OpAccessChain %_ptr_Uniform_S %MyTBuffer %int_1
 // CHECK-NEXT:     [[s:%\d+]] = OpLoad %S [[tb_s]]
 // CHECK-NEXT:     [[s:%\d+]] = OpLoad %S [[tb_s]]
 // CHECK-NEXT: [[s_val:%\d+]] = OpCompositeExtract %v3float [[s]] 0
 // CHECK-NEXT: [[s_val:%\d+]] = OpCompositeExtract %v3float [[s]] 0
 // CHECK-NEXT:   [[ptr:%\d+]] = OpAccessChain %_ptr_Function_v3float %temp_var_S %uint_0
 // CHECK-NEXT:   [[ptr:%\d+]] = OpAccessChain %_ptr_Function_v3float %temp_var_S %uint_0
@@ -37,11 +37,11 @@ float4 main() : SV_Target {
 }
 }
 
 
 // CHECK:      %get_cb_val = OpFunction %v4float None {{%\d+}}
 // CHECK:      %get_cb_val = OpFunction %v4float None {{%\d+}}
-// CHECK:         {{%\d+}} = OpAccessChain %_ptr_Uniform_v4float %var_MyCBuffer %int_0
+// CHECK:         {{%\d+}} = OpAccessChain %_ptr_Uniform_v4float %MyCBuffer %int_0
 
 
 // CHECK:     %S_get_s_val = OpFunction %v3float None {{%\d+}}
 // CHECK:     %S_get_s_val = OpFunction %v3float None {{%\d+}}
 // CHECK-NEXT: %param_this = OpFunctionParameter %_ptr_Function_S_0
 // CHECK-NEXT: %param_this = OpFunctionParameter %_ptr_Function_S_0
 // CHECK:         {{%\d+}} = OpAccessChain %_ptr_Function_v3float %param_this %int_0
 // CHECK:         {{%\d+}} = OpAccessChain %_ptr_Function_v3float %param_this %int_0
 
 
 // CHECK:      %get_tb_val = OpFunction %float None {{%\d+}}
 // CHECK:      %get_tb_val = OpFunction %float None {{%\d+}}
-// CHECK:         {{%\d+}} = OpAccessChain %_ptr_Uniform_float %var_MyTBuffer %int_0
+// CHECK:         {{%\d+}} = OpAccessChain %_ptr_Uniform_float %MyTBuffer %int_0

+ 5 - 5
tools/clang/test/CodeGenSPIRV/op.cbuffer.access.hlsl

@@ -13,22 +13,22 @@ cbuffer MyCbuffer : register(b1) {
 };
 };
 
 
 float main() : A {
 float main() : A {
-// CHECK:      [[a:%\d+]] = OpAccessChain %_ptr_Uniform_float %var_MyCbuffer %int_0
+// CHECK:      [[a:%\d+]] = OpAccessChain %_ptr_Uniform_float %MyCbuffer %int_0
 // CHECK-NEXT: {{%\d+}} = OpLoad %float [[a]]
 // CHECK-NEXT: {{%\d+}} = OpLoad %float [[a]]
 
 
-// CHECK:      [[b:%\d+]] = OpAccessChain %_ptr_Uniform_v2float %var_MyCbuffer %int_1
+// CHECK:      [[b:%\d+]] = OpAccessChain %_ptr_Uniform_v2float %MyCbuffer %int_1
 // CHECK-NEXT: [[b0:%\d+]] = OpAccessChain %_ptr_Uniform_float [[b]] %int_0
 // CHECK-NEXT: [[b0:%\d+]] = OpAccessChain %_ptr_Uniform_float [[b]] %int_0
 // CHECK-NEXT: {{%\d+}} = OpLoad %float [[b0]]
 // CHECK-NEXT: {{%\d+}} = OpLoad %float [[b0]]
 
 
-// CHECK:      [[c:%\d+]] = OpAccessChain %_ptr_Uniform_mat3v4float %var_MyCbuffer %int_2
+// CHECK:      [[c:%\d+]] = OpAccessChain %_ptr_Uniform_mat3v4float %MyCbuffer %int_2
 // CHECK-NEXT: [[c12:%\d+]] = OpAccessChain %_ptr_Uniform_float [[c]] %uint_1 %uint_2
 // CHECK-NEXT: [[c12:%\d+]] = OpAccessChain %_ptr_Uniform_float [[c]] %uint_1 %uint_2
 // CHECK-NEXT: {{%\d+}} = OpLoad %float [[c12]]
 // CHECK-NEXT: {{%\d+}} = OpLoad %float [[c12]]
 
 
-// CHECK:      [[s:%\d+]] = OpAccessChain %_ptr_Uniform_S %var_MyCbuffer %int_3
+// CHECK:      [[s:%\d+]] = OpAccessChain %_ptr_Uniform_S %MyCbuffer %int_3
 // CHECK-NEXT: [[s0:%\d+]] = OpAccessChain %_ptr_Uniform_float [[s]] %int_0
 // CHECK-NEXT: [[s0:%\d+]] = OpAccessChain %_ptr_Uniform_float [[s]] %int_0
 // CHECK-NEXT: {{%\d+}} = OpLoad %float [[s0]]
 // CHECK-NEXT: {{%\d+}} = OpLoad %float [[s0]]
 
 
-// CHECK:      [[t:%\d+]] = OpAccessChain %_ptr_Uniform__arr_float_uint_4 %var_MyCbuffer %int_4
+// CHECK:      [[t:%\d+]] = OpAccessChain %_ptr_Uniform__arr_float_uint_4 %MyCbuffer %int_4
 // CHECK-NEXT: [[t3:%\d+]] = OpAccessChain %_ptr_Uniform_float [[t]] %int_3
 // CHECK-NEXT: [[t3:%\d+]] = OpAccessChain %_ptr_Uniform_float [[t]] %int_3
 // CHECK-NEXT: {{%\d+}} = OpLoad %float [[t3]]
 // CHECK-NEXT: {{%\d+}} = OpLoad %float [[t3]]
     return a + b.x + c[1][2] + s.f + t[3];
     return a + b.x + c[1][2] + s.f + t[3];

+ 5 - 5
tools/clang/test/CodeGenSPIRV/op.tbuffer.access.hlsl

@@ -13,22 +13,22 @@ tbuffer MyTbuffer : register(t0) {
 };
 };
 
 
 float main() : A {
 float main() : A {
-// CHECK:      [[a:%\d+]] = OpAccessChain %_ptr_Uniform_float %var_MyTbuffer %int_0
+// CHECK:      [[a:%\d+]] = OpAccessChain %_ptr_Uniform_float %MyTbuffer %int_0
 // CHECK-NEXT: {{%\d+}} = OpLoad %float [[a]]
 // CHECK-NEXT: {{%\d+}} = OpLoad %float [[a]]
 
 
-// CHECK:      [[b:%\d+]] = OpAccessChain %_ptr_Uniform_v2float %var_MyTbuffer %int_1
+// CHECK:      [[b:%\d+]] = OpAccessChain %_ptr_Uniform_v2float %MyTbuffer %int_1
 // CHECK-NEXT: [[b0:%\d+]] = OpAccessChain %_ptr_Uniform_float [[b]] %int_0
 // CHECK-NEXT: [[b0:%\d+]] = OpAccessChain %_ptr_Uniform_float [[b]] %int_0
 // CHECK-NEXT: {{%\d+}} = OpLoad %float [[b0]]
 // CHECK-NEXT: {{%\d+}} = OpLoad %float [[b0]]
 
 
-// CHECK:      [[c:%\d+]] = OpAccessChain %_ptr_Uniform_mat3v4float %var_MyTbuffer %int_2
+// CHECK:      [[c:%\d+]] = OpAccessChain %_ptr_Uniform_mat3v4float %MyTbuffer %int_2
 // CHECK-NEXT: [[c12:%\d+]] = OpAccessChain %_ptr_Uniform_float [[c]] %uint_1 %uint_2
 // CHECK-NEXT: [[c12:%\d+]] = OpAccessChain %_ptr_Uniform_float [[c]] %uint_1 %uint_2
 // CHECK-NEXT: {{%\d+}} = OpLoad %float [[c12]]
 // CHECK-NEXT: {{%\d+}} = OpLoad %float [[c12]]
 
 
-// CHECK:      [[s:%\d+]] = OpAccessChain %_ptr_Uniform_S %var_MyTbuffer %int_3
+// CHECK:      [[s:%\d+]] = OpAccessChain %_ptr_Uniform_S %MyTbuffer %int_3
 // CHECK-NEXT: [[s0:%\d+]] = OpAccessChain %_ptr_Uniform_float [[s]] %int_0
 // CHECK-NEXT: [[s0:%\d+]] = OpAccessChain %_ptr_Uniform_float [[s]] %int_0
 // CHECK-NEXT: {{%\d+}} = OpLoad %float [[s0]]
 // CHECK-NEXT: {{%\d+}} = OpLoad %float [[s0]]
 
 
-// CHECK:      [[t:%\d+]] = OpAccessChain %_ptr_Uniform__arr_float_uint_4 %var_MyTbuffer %int_4
+// CHECK:      [[t:%\d+]] = OpAccessChain %_ptr_Uniform__arr_float_uint_4 %MyTbuffer %int_4
 // CHECK-NEXT: [[t3:%\d+]] = OpAccessChain %_ptr_Uniform_float [[t]] %int_3
 // CHECK-NEXT: [[t3:%\d+]] = OpAccessChain %_ptr_Uniform_float [[t]] %int_3
 // CHECK-NEXT: {{%\d+}} = OpLoad %float [[t3]]
 // CHECK-NEXT: {{%\d+}} = OpLoad %float [[t3]]
     return a + b.x + c[1][2] + s.f + t[3];
     return a + b.x + c[1][2] + s.f + t[3];

+ 4 - 4
tools/clang/test/CodeGenSPIRV/type.cbuffer.hlsl

@@ -8,13 +8,13 @@
 // CHECK-NEXT: OpMemberName %type_MyCbuffer 4 "s"
 // CHECK-NEXT: OpMemberName %type_MyCbuffer 4 "s"
 // CHECK-NEXT: OpMemberName %type_MyCbuffer 5 "t"
 // CHECK-NEXT: OpMemberName %type_MyCbuffer 5 "t"
 
 
-// CHECK:      OpName %var_MyCbuffer "var.MyCbuffer"
+// CHECK:      OpName %MyCbuffer "MyCbuffer"
 
 
 // CHECK:      OpName %type_AnotherCBuffer "type.AnotherCBuffer"
 // CHECK:      OpName %type_AnotherCBuffer "type.AnotherCBuffer"
 // CHECK-NEXT: OpMemberName %type_AnotherCBuffer 0 "m"
 // CHECK-NEXT: OpMemberName %type_AnotherCBuffer 0 "m"
 // CHECK-NEXT: OpMemberName %type_AnotherCBuffer 1 "n"
 // CHECK-NEXT: OpMemberName %type_AnotherCBuffer 1 "n"
 
 
-// CHECK:      OpName %var_AnotherCBuffer "var.AnotherCBuffer"
+// CHECK:      OpName %AnotherCBuffer "AnotherCBuffer"
 
 
 struct S {
 struct S {
     float  f1;
     float  f1;
@@ -39,8 +39,8 @@ cbuffer AnotherCBuffer : register(b2) {
 
 
 // CHECK: %type_AnotherCBuffer = OpTypeStruct %v3float %v4float
 // CHECK: %type_AnotherCBuffer = OpTypeStruct %v3float %v4float
 
 
-// CHECK: %var_MyCbuffer = OpVariable %_ptr_Uniform_type_MyCbuffer Uniform
-// CHECK: %var_AnotherCBuffer = OpVariable %_ptr_Uniform_type_AnotherCBuffer Uniform
+// CHECK: %MyCbuffer = OpVariable %_ptr_Uniform_type_MyCbuffer Uniform
+// CHECK: %AnotherCBuffer = OpVariable %_ptr_Uniform_type_AnotherCBuffer Uniform
 
 
 void main() {
 void main() {
 }
 }

+ 4 - 4
tools/clang/test/CodeGenSPIRV/type.tbuffer.hlsl

@@ -8,13 +8,13 @@
 // CHECK-NEXT: OpMemberName %type_MyTbuffer 4 "s"
 // CHECK-NEXT: OpMemberName %type_MyTbuffer 4 "s"
 // CHECK-NEXT: OpMemberName %type_MyTbuffer 5 "t"
 // CHECK-NEXT: OpMemberName %type_MyTbuffer 5 "t"
 
 
-// CHECK:      OpName %var_MyTbuffer "var.MyTbuffer"
+// CHECK:      OpName %MyTbuffer "MyTbuffer"
 
 
 // CHECK:      OpName %type_AnotherTbuffer "type.AnotherTbuffer"
 // CHECK:      OpName %type_AnotherTbuffer "type.AnotherTbuffer"
 // CHECK-NEXT: OpMemberName %type_AnotherTbuffer 0 "m"
 // CHECK-NEXT: OpMemberName %type_AnotherTbuffer 0 "m"
 // CHECK-NEXT: OpMemberName %type_AnotherTbuffer 1 "n"
 // CHECK-NEXT: OpMemberName %type_AnotherTbuffer 1 "n"
 
 
-// CHECK:      OpName %var_AnotherTbuffer "var.AnotherTbuffer"
+// CHECK:      OpName %AnotherTbuffer "AnotherTbuffer"
 
 
 struct S {
 struct S {
     float  f1;
     float  f1;
@@ -39,8 +39,8 @@ tbuffer AnotherTbuffer : register(t2) {
 
 
 // CHECK: %type_AnotherTbuffer = OpTypeStruct %v3float %v4float
 // CHECK: %type_AnotherTbuffer = OpTypeStruct %v3float %v4float
 
 
-// CHECK: %var_MyTbuffer = OpVariable %_ptr_Uniform_type_MyTbuffer Uniform
-// CHECK: %var_AnotherTbuffer = OpVariable %_ptr_Uniform_type_AnotherTbuffer Uniform
+// CHECK: %MyTbuffer = OpVariable %_ptr_Uniform_type_MyTbuffer Uniform
+// CHECK: %AnotherTbuffer = OpVariable %_ptr_Uniform_type_AnotherTbuffer Uniform
 
 
 void main() {
 void main() {
 }
 }

+ 2 - 2
tools/clang/test/CodeGenSPIRV/var.init.cross-storage-class.hlsl

@@ -16,7 +16,7 @@ cbuffer Constants {
 
 
 // CHECK-LABEL:           %main = OpFunction
 // CHECK-LABEL:           %main = OpFunction
 
 
-// CHECK:          [[ptr:%\d+]] = OpAccessChain %_ptr_Uniform_S %var_Constants %int_0
+// CHECK:          [[ptr:%\d+]] = OpAccessChain %_ptr_Uniform_S %Constants %int_0
 // CHECK-NEXT: [[uniform:%\d+]] = OpLoad %S [[ptr]]
 // CHECK-NEXT: [[uniform:%\d+]] = OpLoad %S [[ptr]]
 // CHECK-NEXT:     [[vec:%\d+]] = OpCompositeExtract %v4float [[uniform]] 0
 // CHECK-NEXT:     [[vec:%\d+]] = OpCompositeExtract %v4float [[uniform]] 0
 // CHECK-NEXT:     [[ptr:%\d+]] = OpAccessChain %_ptr_Private_v4float %private_struct %uint_0
 // CHECK-NEXT:     [[ptr:%\d+]] = OpAccessChain %_ptr_Private_v4float %private_struct %uint_0
@@ -39,7 +39,7 @@ S main()
 float4 foo()
 float4 foo()
 // CHECK-LABEL:            %foo = OpFunction
 // CHECK-LABEL:            %foo = OpFunction
 {
 {
-// CHECK:          [[ptr:%\d+]] = OpAccessChain %_ptr_Uniform_S %var_Constants %int_0
+// CHECK:          [[ptr:%\d+]] = OpAccessChain %_ptr_Uniform_S %Constants %int_0
 // CHECK-NEXT: [[uniform:%\d+]] = OpLoad %S [[ptr]]
 // CHECK-NEXT: [[uniform:%\d+]] = OpLoad %S [[ptr]]
 // CHECK-NEXT:     [[vec:%\d+]] = OpCompositeExtract %v4float [[uniform]] 0
 // CHECK-NEXT:     [[vec:%\d+]] = OpCompositeExtract %v4float [[uniform]] 0
 // CHECK-NEXT:     [[ptr:%\d+]] = OpAccessChain %_ptr_Private_v4float %fn_private_struct %uint_0
 // CHECK-NEXT:     [[ptr:%\d+]] = OpAccessChain %_ptr_Private_v4float %fn_private_struct %uint_0

+ 2 - 2
tools/clang/test/CodeGenSPIRV/vk.binding.explicit.hlsl

@@ -30,8 +30,8 @@ Buffer<int> myBuffer : register(t1, space0);
 [[vk::binding(4, 1)]]
 [[vk::binding(4, 1)]]
 RWBuffer<float4> myRWBuffer : register(u0, space1);
 RWBuffer<float4> myRWBuffer : register(u0, space1);
 
 
-// CHECK: OpDecorate %var_myCBuffer DescriptorSet 3
-// CHECK-NEXT: OpDecorate %var_myCBuffer Binding 10
+// CHECK: OpDecorate %myCBuffer DescriptorSet 3
+// CHECK-NEXT: OpDecorate %myCBuffer Binding 10
 [[vk::binding(10, 3)]]
 [[vk::binding(10, 3)]]
 cbuffer myCBuffer : register(b5, space1) {
 cbuffer myCBuffer : register(b5, space1) {
     float cbfield;
     float cbfield;

+ 2 - 2
tools/clang/test/CodeGenSPIRV/vk.binding.implicit.hlsl

@@ -16,8 +16,8 @@ Texture3D<float4> texture2;
 // CHECK-NEXT: OpDecorate %sampler2 Binding 3
 // CHECK-NEXT: OpDecorate %sampler2 Binding 3
 SamplerState sampler2;
 SamplerState sampler2;
 
 
-// CHECK:      OpDecorate %var_myCbuffer DescriptorSet 0
-// CHECK-NEXT: OpDecorate %var_myCbuffer Binding 4
+// CHECK:      OpDecorate %myCbuffer DescriptorSet 0
+// CHECK-NEXT: OpDecorate %myCbuffer Binding 4
 cbuffer myCbuffer {
 cbuffer myCbuffer {
     float4 stuff;
     float4 stuff;
 }
 }

+ 2 - 2
tools/clang/test/CodeGenSPIRV/vk.binding.register.hlsl

@@ -20,8 +20,8 @@ SamplerState sampler3;
 
 
 SamplerState sampler4;
 SamplerState sampler4;
 
 
-// CHECK:      OpDecorate %var_myCbuffer DescriptorSet 3
-// CHECK-NEXT: OpDecorate %var_myCbuffer Binding 1
+// CHECK:      OpDecorate %myCbuffer DescriptorSet 3
+// CHECK-NEXT: OpDecorate %myCbuffer Binding 1
 cbuffer myCbuffer : register(b1, space3) {
 cbuffer myCbuffer : register(b1, space3) {
     float4 stuff;
     float4 stuff;
 }
 }

+ 2 - 2
tools/clang/test/CodeGenSPIRV/vk.cloption.ignore-unused-resources.hlsl

@@ -20,12 +20,12 @@ Texture2D gTex2D2;
 Texture2D gTex2D3;
 Texture2D gTex2D3;
 Texture2D gTex2D4;
 Texture2D gTex2D4;
 
 
-// CHECK-NOT: %var_gCBuffer1 = OpVariable
+// CHECK-NOT: %gCBuffer1 = OpVariable
 cbuffer gCBuffer1 {
 cbuffer gCBuffer1 {
     float4 cb_f;
     float4 cb_f;
 };
 };
 
 
-// CHECK:     %var_gTBuffer1 = OpVariable
+// CHECK:     %gTBuffer1 = OpVariable
 tbuffer gTBuffer1 {
 tbuffer gTBuffer1 {
     float4 tb_f;
     float4 tb_f;
 };
 };

+ 3 - 3
tools/clang/test/CodeGenSPIRV/vk.layout.cbuffer.zpc.hlsl

@@ -16,9 +16,9 @@ cbuffer MyCBuffer {
 
 
 void main() {
 void main() {
     // Check that the result types for access chains are correct
     // Check that the result types for access chains are correct
-// CHECK: {{%\d+}} = OpAccessChain %_ptr_Uniform__arr_mat2v3float_uint_5 %var_MyCBuffer %int_0
-// CHECK: {{%\d+}} = OpAccessChain %_ptr_Uniform__arr_mat2v3float_uint_5_0 %var_MyCBuffer %int_1
-// CHECK: {{%\d+}} = OpAccessChain %_ptr_Uniform__arr_mat2v3float_uint_5_0 %var_MyCBuffer %int_2
+// CHECK: {{%\d+}} = OpAccessChain %_ptr_Uniform__arr_mat2v3float_uint_5 %MyCBuffer %int_0
+// CHECK: {{%\d+}} = OpAccessChain %_ptr_Uniform__arr_mat2v3float_uint_5_0 %MyCBuffer %int_1
+// CHECK: {{%\d+}} = OpAccessChain %_ptr_Uniform__arr_mat2v3float_uint_5_0 %MyCBuffer %int_2
     float2x3 m1 = matrices1[1];
     float2x3 m1 = matrices1[1];
     float2x3 m2 = matrices2[2];
     float2x3 m2 = matrices2[2];
     float2x3 m3 = matrices3[3];
     float2x3 m3 = matrices3[3];

+ 3 - 3
tools/clang/test/CodeGenSPIRV/vk.layout.cbuffer.zpr.hlsl

@@ -16,9 +16,9 @@ cbuffer MyCBuffer {
 
 
 void main() {
 void main() {
     // Check that the result types for access chains are correct
     // Check that the result types for access chains are correct
-// CHECK: {{%\d+}} = OpAccessChain %_ptr_Uniform__arr_mat2v3float_uint_5 %var_MyCBuffer %int_0
-// CHECK: {{%\d+}} = OpAccessChain %_ptr_Uniform__arr_mat2v3float_uint_5_0 %var_MyCBuffer %int_1
-// CHECK: {{%\d+}} = OpAccessChain %_ptr_Uniform__arr_mat2v3float_uint_5 %var_MyCBuffer %int_2
+// CHECK: {{%\d+}} = OpAccessChain %_ptr_Uniform__arr_mat2v3float_uint_5 %MyCBuffer %int_0
+// CHECK: {{%\d+}} = OpAccessChain %_ptr_Uniform__arr_mat2v3float_uint_5_0 %MyCBuffer %int_1
+// CHECK: {{%\d+}} = OpAccessChain %_ptr_Uniform__arr_mat2v3float_uint_5 %MyCBuffer %int_2
     float2x3 m1 = matrices1[1];
     float2x3 m1 = matrices1[1];
     float2x3 m2 = matrices2[2];
     float2x3 m2 = matrices2[2];
     float2x3 m3 = matrices3[3];
     float2x3 m3 = matrices3[3];

+ 1 - 1
tools/clang/test/HLSL/vector-conditional.hlsl

@@ -146,7 +146,7 @@ float4 main(float4 v0 : TEXCOORD) : SV_Target
   acc += b4 ? v0.xy : 1.0F;                                 /* expected-error {{conditional operator condition and result dimensions mismatch.}} fxc-error {{X3017: cannot implicitly convert from 'float2' to 'float4'}} */
   acc += b4 ? v0.xy : 1.0F;                                 /* expected-error {{conditional operator condition and result dimensions mismatch.}} fxc-error {{X3017: cannot implicitly convert from 'float2' to 'float4'}} */
   acc += b4 ? v0.xy : (v0 + 1.0F);                          /* expected-error {{conditional operator condition and result dimensions mismatch.}} fxc-error {{X3017: cannot implicitly convert from 'float2' to 'const float4'}} */
   acc += b4 ? v0.xy : (v0 + 1.0F);                          /* expected-error {{conditional operator condition and result dimensions mismatch.}} fxc-error {{X3017: cannot implicitly convert from 'float2' to 'const float4'}} */
   acc += b4.xy ? v0 : (v0 + 1.0F);                          /* expected-error {{conditional operator condition and result dimensions mismatch.}} fxc-error {{X3020: dimension of conditional does not match value}} */
   acc += b4.xy ? v0 : (v0 + 1.0F);                          /* expected-error {{conditional operator condition and result dimensions mismatch.}} fxc-error {{X3020: dimension of conditional does not match value}} */
-  acc += b4.xy ? v0 : (v0.xy + 1.0F);                       /* expected-error {{conditional operator condition and result dimensions mismatch.}} fxc-error {{X3017: cannot implicitly convert from 'const float2' to 'float4'}} fxc-warning {{X3206: implicit truncation of vector type}} */
+  acc += b4.xy ? v0 : (v0.xy + 1.0F);                       /* expected-error {{cannot convert from 'vector<float, 2>' to 'float4'}} fxc-error {{X3017: cannot implicitly convert from 'const float2' to 'float4'}} fxc-warning {{X3206: implicit truncation of vector type}} */
 
 
   // lit float/int
   // lit float/int
   acc += b4 ? v0 : 1.1;
   acc += b4 ? v0 : 1.1;

+ 1 - 1
tools/clang/tools/dxc/dxc.cpp

@@ -726,7 +726,7 @@ void DxcContext::Recompile(IDxcBlob *pSource, IDxcLibrary *pLibrary, IDxcCompile
     IFT(pIncludeHandler->insertIncludeFile(pFileName, pBlobEncoding, dataLen));
     IFT(pIncludeHandler->insertIncludeFile(pFileName, pBlobEncoding, dataLen));
     // Check if this file is the main file or included file
     // Check if this file is the main file or included file
     if (wcscmp(pFileName, pMainFileName) == 0) {
     if (wcscmp(pFileName, pMainFileName) == 0) {
-      pCompileSource = pBlobEncoding.Detach();
+      pCompileSource.Attach(pBlobEncoding.Detach());
     }
     }
   }
   }
 
 

+ 3 - 2
tools/clang/unittests/HLSL/ExecutionTest.cpp

@@ -446,6 +446,7 @@ public:
       UINT minor = testModel & 0x0f;
       UINT minor = testModel & 0x0f;
       LogCommentFmt(L"Installed SDK does not support "
       LogCommentFmt(L"Installed SDK does not support "
           L"shader model 6.%1u", minor);
           L"shader model 6.%1u", minor);
+      WEX::Logging::Log::Result(WEX::Logging::TestResults::Blocked);
       return false;
       return false;
     }
     }
     const D3D_FEATURE_LEVEL FeatureLevelRequired = D3D_FEATURE_LEVEL_11_0;
     const D3D_FEATURE_LEVEL FeatureLevelRequired = D3D_FEATURE_LEVEL_11_0;
@@ -492,7 +493,7 @@ public:
       } D3D12_FEATURE_DATA_SHADER_MODEL;
       } D3D12_FEATURE_DATA_SHADER_MODEL;
       const UINT D3D12_FEATURE_SHADER_MODEL = 7;
       const UINT D3D12_FEATURE_SHADER_MODEL = 7;
       D3D12_FEATURE_DATA_SHADER_MODEL SMData;
       D3D12_FEATURE_DATA_SHADER_MODEL SMData;
-      SMData.HighestShaderModel = HIGHEST_SHADER_MODEL;
+      SMData.HighestShaderModel = testModel;
       VERIFY_SUCCEEDED(pDevice->CheckFeatureSupport(
       VERIFY_SUCCEEDED(pDevice->CheckFeatureSupport(
         (D3D12_FEATURE)D3D12_FEATURE_SHADER_MODEL, &SMData, sizeof(SMData)));
         (D3D12_FEATURE)D3D12_FEATURE_SHADER_MODEL, &SMData, sizeof(SMData)));
       if (SMData.HighestShaderModel < testModel) {
       if (SMData.HighestShaderModel < testModel) {
@@ -4935,7 +4936,7 @@ TEST_F(ExecutionTest, DenormTertiaryFloatOpTest) {
     // use shader from data table
     // use shader from data table
     pShaderOp->Shaders.at(0).Target = Target.m_psz;
     pShaderOp->Shaders.at(0).Target = Target.m_psz;
     pShaderOp->Shaders.at(0).Text = Text.m_psz;
     pShaderOp->Shaders.at(0).Text = Text.m_psz;
-    pShaderOp->Shaders.at(0).Arguments = Text.m_psz;
+    pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
   });
   });
 
 
   MappedData data;
   MappedData data;

+ 2 - 2
tools/clang/unittests/HLSL/ShaderOpArithTable.xml

@@ -6304,7 +6304,7 @@
                 <Value>0x00800000</Value>
                 <Value>0x00800000</Value>
             </Parameter>
             </Parameter>
             <Parameter Name="Validation.Expected1">
             <Parameter Name="Validation.Expected1">
-                <Value>0x80780000</Value>
+                <Value>0x80F00000</Value>
                 <Value>0x80700000</Value>
                 <Value>0x80700000</Value>
                 <Value>0x01380000</Value>
                 <Value>0x01380000</Value>
             </Parameter>
             </Parameter>
@@ -6343,7 +6343,7 @@
                 <Value>0x00800000</Value>
                 <Value>0x00800000</Value>
             </Parameter>
             </Parameter>
             <Parameter Name="Validation.Expected1">
             <Parameter Name="Validation.Expected1">
-                <Value>0x80780000</Value>
+                <Value>0x80F00000</Value>
                 <Value>0x80700000</Value>
                 <Value>0x80700000</Value>
                 <Value>0x01380000</Value>
                 <Value>0x01380000</Value>
             </Parameter>
             </Parameter>

+ 3 - 0
tools/clang/unittests/SPIRV/CodeGenSPIRVTest.cpp

@@ -904,6 +904,9 @@ TEST_F(FileTest, IntrinsicsGetRenderTargetSamplePosition) {
 }
 }
 
 
 // For attributes
 // For attributes
+TEST_F(FileTest, AttributeEarlyDepthStencil) {
+  runFileTest("attribute.earlydepthstencil.ps.hlsl");
+}
 TEST_F(FileTest, AttributeNumThreads) {
 TEST_F(FileTest, AttributeNumThreads) {
   runFileTest("attribute.numthreads.hlsl");
   runFileTest("attribute.numthreads.hlsl");
 }
 }

+ 2 - 2
utils/hct/hctdb.py

@@ -735,7 +735,7 @@ class db_dxil(object):
             db_dxil_param(2, "res", "handle", "resource handle to query"),
             db_dxil_param(2, "res", "handle", "resource handle to query"),
             db_dxil_param(3, "i32", "mipLevel", "mip level to query")])
             db_dxil_param(3, "i32", "mipLevel", "mip level to query")])
         next_op_idx += 1
         next_op_idx += 1
-        self.add_dxil_op("TextureGather", next_op_idx, "TextureGather", "gathers the four texels that would be used in a bi-linear filtering operation", "fi", "ro", [
+        self.add_dxil_op("TextureGather", next_op_idx, "TextureGather", "gathers the four texels that would be used in a bi-linear filtering operation", "hfwi", "ro", [
             db_dxil_param(0, "$r", "", "dimension information for texture"),
             db_dxil_param(0, "$r", "", "dimension information for texture"),
             db_dxil_param(2, "res", "srv", "handle of SRV to sample"),
             db_dxil_param(2, "res", "srv", "handle of SRV to sample"),
             db_dxil_param(3, "res", "sampler", "handle of sampler to use"),
             db_dxil_param(3, "res", "sampler", "handle of sampler to use"),
@@ -747,7 +747,7 @@ class db_dxil(object):
             db_dxil_param(9, "i32", "offset1", "optional offset, applicable to Texture2D, Texture2DArray, and as part of offset2"),
             db_dxil_param(9, "i32", "offset1", "optional offset, applicable to Texture2D, Texture2DArray, and as part of offset2"),
             db_dxil_param(10, "i32", "channel", "channel to sample")])
             db_dxil_param(10, "i32", "channel", "channel to sample")])
         next_op_idx += 1
         next_op_idx += 1
-        self.add_dxil_op("TextureGatherCmp", next_op_idx, "TextureGatherCmp", "same as TextureGather, except this instrution performs comparison on texels, similar to SampleCmp", "fi", "ro", [
+        self.add_dxil_op("TextureGatherCmp", next_op_idx, "TextureGatherCmp", "same as TextureGather, except this instrution performs comparison on texels, similar to SampleCmp", "hfwi", "ro", [
             db_dxil_param(0, "$r", "", "gathered texels"),
             db_dxil_param(0, "$r", "", "gathered texels"),
             db_dxil_param(2, "res", "srv", "handle of SRV to sample"),
             db_dxil_param(2, "res", "srv", "handle of SRV to sample"),
             db_dxil_param(3, "res", "sampler", "handle of sampler to use"),
             db_dxil_param(3, "res", "sampler", "handle of sampler to use"),

+ 1 - 1
utils/hct/hctdb_test.py

@@ -841,7 +841,7 @@ def add_test_cases():
      ['1', '2', '2'],
      ['1', '2', '2'],
      ['0x80780000', '0x00800000', '0x00800000']],
      ['0x80780000', '0x00800000', '0x00800000']],
     [['0', '0x00800000', '0x00800000']],
     [['0', '0x00800000', '0x00800000']],
-     [['0x80780000', '0x80700000', '0x01380000']],
+     [['0x80F00000', '0x80700000', '0x01380000']],
                   'cs_6_2', get_shader_text("tertiary float", "mad"))
                   'cs_6_2', get_shader_text("tertiary float", "mad"))
 
 
     # Unary Int
     # Unary Int