diff --git a/lib/DxcSupport/dxcapi.extval.cpp b/lib/DxcSupport/dxcapi.extval.cpp index 66b94a2a20..b50fd05e0c 100644 --- a/lib/DxcSupport/dxcapi.extval.cpp +++ b/lib/DxcSupport/dxcapi.extval.cpp @@ -171,7 +171,10 @@ class ExtValidationArgHelper { // '-Vd' and sets the default validator version with '-validator-version'. // After a successful compilation, it uses the provided IDxcValidator to // perform validation when it would normally be performed. -class ExternalValidationCompiler : public IDxcCompiler2, public IDxcCompiler3 { +class ExternalValidationCompiler : public IDxcCompiler2, + public IDxcCompiler3, + public IDxcVersionInfo2, + public IDxcVersionInfo3 { public: ExternalValidationCompiler(IMalloc *Malloc, IDxcValidator *OtherValidator, IUnknown *OtherCompiler) @@ -203,8 +206,10 @@ class ExternalValidationCompiler : public IDxcCompiler2, public IDxcCompiler3 { // calls. CComPtr NewWrapper( Alloc(m_pMalloc, Validator, TempCompiler)); - return DoBasicQueryInterface( - NewWrapper.p, Iid, ResultObject); + return DoBasicQueryInterface(NewWrapper.p, Iid, + ResultObject); } catch (...) { return E_FAIL; } @@ -305,6 +310,28 @@ class ExternalValidationCompiler : public IDxcCompiler2, public IDxcCompiler3 { return cast()->Disassemble(Object, Riid, ResultObject); } + // IDxcVersionInfo implementation + HRESULT STDMETHODCALLTYPE GetVersion(_Out_ UINT32 *pMajor, + _Out_ UINT32 *pMinor) override { + return cast()->GetVersion(pMajor, pMinor); + } + HRESULT STDMETHODCALLTYPE GetFlags(_Out_ UINT32 *pFlags) override { + return cast()->GetFlags(pFlags); + } + + // IDxcVersionInfo2 implementation + HRESULT STDMETHODCALLTYPE + GetCommitInfo(_Out_ UINT32 *pCommitCount, + _Outptr_result_z_ char **pCommitHash) override { + return cast()->GetCommitInfo(pCommitCount, pCommitHash); + } + + // IDxcVersionInfo3 implementation + HRESULT STDMETHODCALLTYPE + GetCustomVersionString(_Outptr_result_z_ char **pVersionString) override { + return cast()->GetCustomVersionString(pVersionString); + } + private: CComPtr Validator; diff --git a/tools/clang/test/LitDXILValidation/lit.local.cfg b/tools/clang/test/LitDXILValidation/lit.local.cfg new file mode 100644 index 0000000000..a8d9b3b933 --- /dev/null +++ b/tools/clang/test/LitDXILValidation/lit.local.cfg @@ -0,0 +1,2 @@ +# Skip when testing compiler's DXIL output against released validators. +config.unsupported = "dxc_dxil_dll_path" in config.available_features \ No newline at end of file diff --git a/tools/clang/test/lit.cfg b/tools/clang/test/lit.cfg index 1af4a05958..563a4915cb 100644 --- a/tools/clang/test/lit.cfg +++ b/tools/clang/test/lit.cfg @@ -522,24 +522,18 @@ def get_dxil_version(): else: result = subprocess.run([lit.util.which('dxc', llvm_tools_dir), "--version"], stdout=subprocess.PIPE) output = result.stdout.decode("utf-8") - dxcPat = re.compile(r"(dxcompiler.dll|libdxcompiler.so|libdxcompiler.dylib): (?P[0-9]+)\.(?P[0-9]+).") + dxcPat = re.compile(r"(dxcompiler\.dll|libdxcompiler\.so|libdxcompiler\.dylib): (?P[0-9]+)\.(?P[0-9]+)") m = dxcPat.search(output) dxcMajor = int(m.group("dxcMajor")) dxcMinor = int(m.group("dxcMinor")) - dxilPat = re.compile(r"; (dxil.dll|libdxil.so): (?P[0-9]+)\.(?P[0-9]+)") + dxilPat = re.compile(r"(dxil\.dll|libdxil\.so|libdxil\.dylib): (?P[0-9]+)\.(?P[0-9]+)") m = dxilPat.search(output) if None == m: return dxcMajor, dxcMinor dxilMajor = int(m.group("dxilMajor")) dxilMinor = int(m.group("dxilMinor")) - if dxcMajor < dxilMajor: - return dxcMajor, dxcMinor - if dxcMajor > dxilMajor: - return dxilMajor, dxilMinor - if dxcMinor < dxilMinor: - return dxcMajor, dxcMinor - return dxilMajor, dxilMinor + return min((dxcMajor, dxcMinor), (dxilMajor, dxilMinor)) dxilMajor, dxilMinor = get_dxil_version() if dxilMajor == 1: diff --git a/tools/clang/tools/dxclib/dxc.cpp b/tools/clang/tools/dxclib/dxc.cpp index 8388cd70e0..4d12cffe56 100644 --- a/tools/clang/tools/dxclib/dxc.cpp +++ b/tools/clang/tools/dxclib/dxc.cpp @@ -1242,83 +1242,86 @@ namespace dxc { // Writes compiler version info to stream void WriteDxCompilerVersionInfo(llvm::raw_ostream &OS, const char *ExternalLib, const char *ExternalFn, DllLoader &DxcSupport) { - if (DxcSupport.IsEnabled()) { - UINT32 compilerMajor = 1; - UINT32 compilerMinor = 0; - CComPtr VerInfo; - -#ifdef SUPPORT_QUERY_GIT_COMMIT_INFO - UINT32 commitCount = 0; - CComHeapPtr commitHash; - CComPtr VerInfo2; -#endif // SUPPORT_QUERY_GIT_COMMIT_INFO - - const char *dllName = !ExternalLib ? kDxCompilerLib : ExternalLib; - std::string compilerName(dllName); - if (ExternalFn) - compilerName = compilerName + "!" + ExternalFn; - - if (SUCCEEDED(DxcSupport.CreateInstance(CLSID_DxcCompiler, &VerInfo))) { - VerInfo->GetVersion(&compilerMajor, &compilerMinor); -#ifdef SUPPORT_QUERY_GIT_COMMIT_INFO - if (SUCCEEDED(VerInfo->QueryInterface(&VerInfo2))) - VerInfo2->GetCommitInfo(&commitCount, &commitHash); -#endif // SUPPORT_QUERY_GIT_COMMIT_INFO - OS << compilerName << ": " << compilerMajor << "." << compilerMinor; - } + if (!DxcSupport.IsEnabled()) + return; + + UINT32 VersionMajor = 1; + UINT32 VersionMinor = 0; + CComPtr VerInfo; + + UINT32 CommitCount = 0; + CComHeapPtr CommitHash; + CComPtr VerInfo2; + + CComHeapPtr CustomVersionString; + CComPtr VerInfo3; + + const char *dllName = !ExternalLib ? kDxCompilerLib : ExternalLib; + std::string CompilerName(dllName); + if (ExternalFn) + CompilerName = CompilerName + "!" + ExternalFn; + + if (SUCCEEDED(DxcSupport.CreateInstance(CLSID_DxcCompiler, &VerInfo))) { + VerInfo->GetVersion(&VersionMajor, &VersionMinor); + if (SUCCEEDED(VerInfo->QueryInterface(&VerInfo2))) + VerInfo2->GetCommitInfo(&CommitCount, &CommitHash); + if (SUCCEEDED(VerInfo->QueryInterface(&VerInfo3))) + VerInfo3->GetCustomVersionString(&CustomVersionString); + OS << CompilerName << ": " << VersionMajor << "." << VersionMinor; + } else if (!ExternalLib) { // compiler.dll 1.0 did not support IdxcVersionInfo - else if (!ExternalLib) { - OS << compilerName << ": " << 1 << "." << 0; - } else { - // ExternalLib/ExternalFn, no version info: - OS << compilerName; - } + OS << CompilerName << ": " << 1 << "." << 0; + } else { + // ExternalLib/ExternalFn, no version info: + OS << CompilerName; + return; + } -#ifdef _WIN32 - unsigned int version[4]; - if (GetDLLFileVersionInfo(dllName, version)) { - // back-compat - old dev buidls had version 3.7.0.0 - if (version[0] == 3 && version[1] == 7 && version[2] == 0 && - version[3] == 0) { -#endif - OS << "(dev" -#ifdef SUPPORT_QUERY_GIT_COMMIT_INFO - << ";" << commitCount << "-" - << (commitHash.m_pData ? commitHash.m_pData : "") -#endif // SUPPORT_QUERY_GIT_COMMIT_I#else - << ")"; -#ifdef _WIN32 - } else { - std::string productVersion; - if (GetDLLProductVersionInfo(dllName, productVersion)) { - OS << " - " << productVersion; - } - } - } -#endif + if (CommitCount != 0 || CommitHash.m_pData) { + OS << "(" << CommitCount << "-" + << (CommitHash.m_pData ? CommitHash.m_pData : "") + << ")"; } + + if (CustomVersionString.m_pData) + OS << "(" << CustomVersionString.m_pData << ")"; + + std::string ProductVersion; + if (GetDLLProductVersionInfo(dllName, ProductVersion)) + OS << " - " << ProductVersion; } // Writes compiler version info to stream -void WriteDXILVersionInfo(llvm::raw_ostream &OS, DllLoader &DxilSupport) { - if (DxilSupport.IsEnabled()) { - CComPtr VerInfo; - if (SUCCEEDED(DxilSupport.CreateInstance(CLSID_DxcValidator, &VerInfo))) { - UINT32 validatorMajor, validatorMinor = 0; - VerInfo->GetVersion(&validatorMajor, &validatorMinor); - OS << "; " << kDxilLib << ": " << validatorMajor << "." << validatorMinor; +void WriteDXILVersionInfo(llvm::raw_ostream &OS, const char *DxilLib, + DllLoader &DxilSupport) { + if (!DxilSupport.IsEnabled()) + return; - } - // dxil.dll 1.0 did not support IdxcVersionInfo - else { - OS << "; " << kDxilLib << ": " << 1 << "." << 0; - } - unsigned int version[4]; - if (GetDLLFileVersionInfo(kDxilLib, version)) { - OS << "(" << version[0] << "." << version[1] << "." << version[2] << "." - << version[3] << ")"; - } + UINT32 VersionMajor = 1; + UINT32 VersionMinor = 0; + CComPtr VerInfo; + + UINT32 CommitCount = 0; + CComHeapPtr CommitHash; + CComPtr VerInfo2; + + if (SUCCEEDED(DxilSupport.CreateInstance(CLSID_DxcValidator, &VerInfo))) { + VerInfo->GetVersion(&VersionMajor, &VersionMinor); + if (SUCCEEDED(VerInfo->QueryInterface(&VerInfo2))) + VerInfo2->GetCommitInfo(&CommitCount, &CommitHash); } + + OS << "; " << DxilLib << ": " << VersionMajor << "." << VersionMinor; + + if (CommitCount != 0 || CommitHash.m_pData) { + OS << "(" << CommitCount << "-" + << (CommitHash.m_pData ? CommitHash.m_pData : "") + << ")"; + } + + std::string ProductVersion; + if (GetDLLProductVersionInfo(DxilLib, ProductVersion)) + OS << " - " << ProductVersion; } } // namespace dxc @@ -1330,10 +1333,12 @@ void DxcContext::GetCompilerVersionInfo(llvm::raw_string_ostream &OS) { m_Opts.ExternalFn.empty() ? nullptr : m_Opts.ExternalFn.data(), m_dxcSupport); - // Print validator if exists - SpecificDllLoader DxilSupport; - DxilSupport.InitializeForDll(kDxilLib, "DxcCreateInstance"); - WriteDXILVersionInfo(OS, DxilSupport); + // Print validator version if external + if (m_dxcSupport.IsEnabled() && !m_dxcSupport.getDxilDllPath().empty()) { + SpecificDllLoader DxilSupport; + WriteDXILVersionInfo(OS, m_dxcSupport.getDxilDllPath().c_str(), + m_dxcSupport); + } } #ifndef VERSION_STRING_SUFFIX