Forráskód Böngészése

Clean up for versions (#829)

-bump up dll version for fixed version
-show dxcompiler and dxil version number for dxc help message
-emit warnings for dxcompiler validator that container will not be signed
Young Kim 7 éve
szülő
commit
8ba7f5a200

+ 3 - 3
cmake/modules/AddLLVM.cmake

@@ -960,14 +960,14 @@ function(hlsl_update_product_ver RC_INTERNAL_NAME)
                  "RC_COMPANY_NAME=\"Microsoft(r) Corporation\""
                  "RC_VERSION_FIELD_1=0"
                  "RC_VERSION_FIELD_2=2017"
-                 "RC_VERSION_FIELD_3=10"
+                 "RC_VERSION_FIELD_3=11"
                  "RC_VERSION_FIELD_4=0"
-                 "RC_FILE_VERSION=\"0.2017.10.0\""
+                 "RC_FILE_VERSION=\"0.2017.11.0\""
                  "RC_FILE_DESCRIPTION=\"DirectX Compiler - Out Of Band\""
                  "RC_INTERNAL_NAME=\"${RC_INTERNAL_NAME}\""
                  "RC_COPYRIGHT=\"(c) Microsoft Corporation. All rights reserved.\""
                  "RC_PRODUCT_NAME=\"Microsoft(r) DirectX for Windows(r) - Out Of Band\""
-                 "RC_PRODUCT_VERSION=\"0.2017.10.0\"")
+                 "RC_PRODUCT_VERSION=\"0.2017.11.0\"")
   endif (HLSL_ENABLE_FIXED_VER)
 endfunction(hlsl_update_product_ver)
 # HLSL Change Ends

+ 6 - 5
include/llvm/Option/OptTable.h

@@ -163,12 +163,13 @@ public:
   /// \param FlagsToInclude - If non-zero, only include options with any
   ///                         of these flags set.
   /// \param FlagsToExclude - Exclude options with any of these flags set.
-  void PrintHelp(raw_ostream &OS, const char *Name,
-                 const char *Title, unsigned FlagsToInclude,
-                 unsigned FlagsToExclude) const;
+  void PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
+                 /* HLSL Change - version info */ const char *VersionInfo,
+                 unsigned FlagsToInclude, unsigned FlagsToExclude) const;
 
-  void PrintHelp(raw_ostream &OS, const char *Name,
-                  const char *Title, bool ShowHidden = false) const;
+  void PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
+                 /* HLSL Change - version info */ const char *VersionInfo,
+                 bool ShowHidden = false) const;
 };
 } // end namespace opt
 } // end namespace llvm

+ 18 - 18
lib/DxcSupport/HLSLOptions.cpp

@@ -198,6 +198,24 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
   unsigned missingArgIndex = 0, missingArgCount = 0;
   InputArgList Args = optionTable->ParseArgs(
     argStrings.getArrayRef(), missingArgIndex, missingArgCount, flagsToInclude);
+  // Verify consistency for external library support.
+  opts.ExternalLib = Args.getLastArgValue(OPT_external_lib);
+  opts.ExternalFn = Args.getLastArgValue(OPT_external_fn);
+  if (opts.ExternalLib.empty()) {
+    if (!opts.ExternalFn.empty()) {
+      errors << "External function cannot be specified without an external "
+        "library name.";
+      return 1;
+    }
+  }
+  else {
+    if (opts.ExternalFn.empty()) {
+      errors << "External library name requires specifying an external "
+        "function name.";
+      return 1;
+    }
+  }
+
   opts.ShowHelp = Args.hasFlag(OPT_help, OPT_INVALID, false);
   if (opts.ShowHelp) {
     return 0;
@@ -224,24 +242,6 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
   }
   opts.Defines.BuildDefines(); // Must be called after all defines are pushed back
 
-  opts.ExternalLib = Args.getLastArgValue(OPT_external_lib);
-  opts.ExternalFn = Args.getLastArgValue(OPT_external_fn);
-
-  // Verify consistency for external library support.
-  if (opts.ExternalLib.empty()) {
-    if (!opts.ExternalFn.empty()) {
-      errors << "External function cannot be specified without an external "
-        "library name.";
-      return 1;
-    }
-  }
-  else {
-    if (opts.ExternalFn.empty()) {
-      errors << "External library name requires specifying an external "
-        "function name.";
-      return 1;
-    }
-  }
   DXASSERT(opts.ExternalLib.empty() == opts.ExternalFn.empty(),
            "else flow above is incorrect");
 

+ 5 - 4
lib/Option/OptTable.cpp

@@ -384,17 +384,18 @@ static const char *getOptionHelpGroup(const OptTable &Opts, OptSpecifier Id) {
 }
 
 void OptTable::PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
-                         bool ShowHidden) const {
-  PrintHelp(OS, Name, Title, /*Include*/ 0, /*Exclude*/
+                         const char *VersionInfo, bool ShowHidden) const {
+  PrintHelp(OS, Name, Title, VersionInfo, /*Include*/ 0, /*Exclude*/
             (ShowHidden ? 0 : HelpHidden));
 }
 
-
 void OptTable::PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
-                         unsigned FlagsToInclude,
+                         const char *VersionInfo, unsigned FlagsToInclude,
                          unsigned FlagsToExclude) const {
   OS << "OVERVIEW: " << Title << "\n";
   OS << '\n';
+  OS << "Version: " << VersionInfo << "\n";
+  OS << '\n';
   OS << "USAGE: " << Name << " [options] <inputs>\n";
   OS << '\n';
 

+ 1 - 1
tools/clang/lib/Basic/CMakeLists.txt

@@ -32,7 +32,7 @@ set(get_svn_script "${LLVM_MAIN_SRC_DIR}/cmake/modules/GetSVN.cmake")
 
 # HLSL Change Starts
 if (HLSL_ENABLE_FIXED_VER)
-  add_definitions(/DHLSL_FIXED_VER="dxcoob 2017.10")
+  add_definitions(/DHLSL_FIXED_VER="dxcoob 2017.11")
 endif (HLSL_ENABLE_FIXED_VER)
 # HLSL Change Ends
 

+ 1 - 1
tools/clang/lib/Basic/Version.cpp

@@ -175,7 +175,7 @@ std::string getClangFullCPPVersion() {
 #ifdef CLANG_VENDOR
   OS << CLANG_VENDOR;
 #endif
-  OS << "Clang " CLANG_VERSION_STRING " " << getClangFullRepositoryVersion();
+  OS << "unofficial";
   return OS.str();
 #endif // HLSL Change Ends
 }

+ 1 - 1
tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp

@@ -168,7 +168,7 @@ bool clang::ExecuteCompilerInvocation(CompilerInstance *Clang) {
   if (Clang->getFrontendOpts().ShowHelp) {
     std::unique_ptr<OptTable> Opts(driver::createDriverOptTable());
     Opts->PrintHelp(llvm::outs(), "clang -cc1",
-                    "LLVM 'Clang' Compiler: http://clang.llvm.org",
+                    "LLVM 'Clang' Compiler: http://clang.llvm.org", "",
                     /*Include=*/ driver::options::CC1Option, /*Exclude=*/ 0);
     return true;
   }

+ 93 - 10
tools/clang/tools/dxc/dxc.cpp

@@ -62,6 +62,8 @@
 #include <algorithm>
 #include <unordered_map>
 
+#pragma comment(lib, "version.lib")
+
 // SPIRV Change Starts
 #ifdef ENABLE_SPIRV_CODEGEN
 #include "spirv-tools/libspirv.hpp"
@@ -204,6 +206,7 @@ public:
   void Recompile(IDxcBlob *pSource, IDxcLibrary *pLibrary, IDxcCompiler *pCompiler, std::vector<LPCWSTR> &args, IDxcOperationResult **pCompileResult);
   int DumpBinary();
   void Preprocess();
+  void GetCompilerVersionInfo(llvm::raw_string_ostream &OS);
 };
 
 static void WriteBlobToFile(_In_opt_ IDxcBlob *pBlob, llvm::StringRef FName) {
@@ -974,6 +977,83 @@ HRESULT DxcContext::GetDxcDiaTable(IDxcLibrary *pLibrary, IDxcBlob *pTargetBlob,
   return S_OK;
 }
 
+bool GetDLLFileVersionInfo(const char *dllPath, unsigned int *version) {
+  DWORD dwVerHnd = 0;
+  DWORD size = GetFileVersionInfoSize(dllPath, &dwVerHnd);
+  if (size == 0) return false;
+  std::unique_ptr<int[]> VfInfo(new int[size]);
+  if (GetFileVersionInfo(dllPath, NULL, size, VfInfo.get())) {
+      LPVOID versionInfo;
+      UINT size;
+      if (VerQueryValue(VfInfo.get(), "\\", &versionInfo, &size)) {
+          if (size >= sizeof(VS_FIXEDFILEINFO)) {
+              VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *)versionInfo;
+              version[0] = (verInfo->dwFileVersionMS >> 16) & 0xffff;
+              version[1] = (verInfo->dwFileVersionMS >> 0) & 0xffff;
+              version[2] = (verInfo->dwFileVersionLS >> 16) & 0xffff;
+              version[3] = (verInfo->dwFileVersionLS >> 0) & 0xffff;
+              return true;
+          }
+      }
+  }
+  return false;
+}
+
+// Collects compiler/validator version info
+void DxcContext::GetCompilerVersionInfo(llvm::raw_string_ostream &OS) {
+  if (m_dxcSupport.IsEnabled()) {
+    UINT32 compilerMajor = 1;
+    UINT32 compilerMinor = 0;
+    CComPtr<IDxcVersionInfo> VerInfo;
+    const char *compilerName =
+        m_Opts.ExternalFn.empty() ? "dxcompiler.dll" : m_Opts.ExternalFn.data();
+    if (SUCCEEDED(CreateInstance(CLSID_DxcCompiler, &VerInfo))) {
+      VerInfo->GetVersion(&compilerMajor, &compilerMinor);
+      OS << compilerName << ": " << compilerMajor << "." << compilerMinor;
+    }
+    // compiler.dll 1.0 did not support IdxcVersionInfo
+    else if (m_Opts.ExternalFn.empty()) {
+      OS << compilerName << ": " << 1 << "." << 0;
+    }
+
+    unsigned int version[4];
+    if (GetDLLFileVersionInfo(compilerName, version)) {
+      // unofficial version always have file version 3.7.0.0
+      if (version[0] == 3 && version[1] == 7 && version[2] == 0 &&
+          version[3] == 0) {
+        OS << "(unofficial)";
+      } else {
+        OS << "(" << version[0] << "." << version[1] << "." << version[2] << "."
+           << version[3] << ")";
+      }
+    }
+  }
+  // Print validator if exists
+  DxcDllSupport DxilSupport;
+  DxilSupport.InitializeForDll(L"dxil.dll", "DxcCreateInstance");
+  if (DxilSupport.IsEnabled()) {
+    CComPtr<IDxcVersionInfo> VerInfo;
+    if (SUCCEEDED(DxilSupport.CreateInstance(CLSID_DxcValidator, &VerInfo))) {
+      UINT32 validatorMajor, validatorMinor = 0;
+      VerInfo->GetVersion(&validatorMajor, &validatorMinor);
+      OS << "; "
+         << "dxil.dll"
+         << ": " << validatorMajor << "." << validatorMinor;
+
+    }
+    // dxil.dll 1.0 did not support IdxcVersionInfo
+    else {
+      OS << "; "
+         << "dxil.dll: " << 1 << "." << 0;
+    }
+    unsigned int version[4];
+    if (GetDLLFileVersionInfo("dxil.dll", version)) {
+      OS << "(" << version[0] << "." << version[1] << "." << version[2] << "."
+         << version[3] << ")";
+    }
+  }
+}
+
 int __cdecl wmain(int argc, const wchar_t **argv_) {
   const char *pStage = "Operation";
   int retVal = 0;
@@ -1005,16 +1085,6 @@ int __cdecl wmain(int argc, const wchar_t **argv_) {
       }
     }
 
-    // Handle help request, which overrides any other processing.
-    if (dxcOpts.ShowHelp) {
-      std::string helpString;
-      llvm::raw_string_ostream helpStream(helpString);
-      optionTable->PrintHelp(helpStream, "dxc.exe", "HLSL Compiler");
-      helpStream.flush();
-      WriteUtf8ToConsoleSizeT(helpString.data(), helpString.size());
-      return 0;
-    }
-
     // Apply defaults.
     if (dxcOpts.EntryPoint.empty() && !dxcOpts.RecompileFromBinary) {
       dxcOpts.EntryPoint = "main";
@@ -1035,6 +1105,19 @@ int __cdecl wmain(int argc, const wchar_t **argv_) {
 
     EnsureEnabled(dxcSupport);
     DxcContext context(dxcOpts, dxcSupport);
+    // Handle help request, which overrides any other processing.
+    if (dxcOpts.ShowHelp) {
+      std::string helpString;
+      llvm::raw_string_ostream helpStream(helpString);
+      std::string version;
+      llvm::raw_string_ostream versionStream(version);
+      context.GetCompilerVersionInfo(versionStream);
+      optionTable->PrintHelp(helpStream, "dxc.exe", "HLSL Compiler", versionStream.str().c_str());
+      helpStream.flush();
+      WriteUtf8ToConsoleSizeT(helpString.data(), helpString.size());
+      return 0;
+    }
+
     // TODO: implement all other actions.
     if (!dxcOpts.Preprocess.empty()) {
       pStage = "Preprocessing";

+ 17 - 7
tools/clang/tools/dxcompiler/dxcutil.cpp

@@ -137,13 +137,23 @@ HRESULT ValidateAndAssembleToContainer(
 
   CComPtr<IDxcValidator> pValidator;
   bool bInternalValidator = CreateValidator(pValidator);
-  // If using the internal validator, we'll use the modules directly.
-  // In this case, we'll want to make a clone to avoid
-  // SerializeDxilContainerForModule stripping all the debug info. The debug
-  // info will be stripped from the orginal module, but preserved in the cloned
-  // module.
-  if (bInternalValidator && bDebugInfo)
-    llvmModule.CloneForDebugInfo();
+  // Warning on internal Validator
+
+  if (bInternalValidator) {
+    unsigned diagID =
+        Diag.getCustomDiagID(clang::DiagnosticsEngine::Level::Warning,
+                             "DXIL.dll not found.  Resulting DXIL will not be "
+                             "signed for use in release environments.\r\n");
+    Diag.Report(diagID);
+    // If using the internal validator, we'll use the modules directly.
+    // In this case, we'll want to make a clone to avoid
+    // SerializeDxilContainerForModule stripping all the debug info. The debug
+    // info will be stripped from the orginal module, but preserved in the cloned
+    // module.
+    if (bDebugInfo) {
+      llvmModule.CloneForDebugInfo();
+    }
+  }
 
   llvmModule.WrapModuleInDxilContainer(pMalloc, pOutputStream, pOutputBlob,
                                        SerializeFlags);

+ 1 - 1
tools/clang/unittests/dxc_batch/dxc_batch.cpp

@@ -891,7 +891,7 @@ int __cdecl wmain(int argc, const wchar_t **argv_) {
     if (dxcOpts.ShowHelp) {
       std::string helpString;
       llvm::raw_string_ostream helpStream(helpString);
-      optionTable->PrintHelp(helpStream, "dxc_bach.exe", "HLSL Compiler");
+      optionTable->PrintHelp(helpStream, "dxc_bach.exe", "HLSL Compiler", "");
       helpStream << "multi-thread";
       helpStream.flush();
       dxc::WriteUtf8ToConsoleSizeT(helpString.data(), helpString.size());