Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions lib/DxcSupport/dxcapi.extval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -203,8 +206,10 @@ class ExternalValidationCompiler : public IDxcCompiler2, public IDxcCompiler3 {
// calls.
CComPtr<ExternalValidationCompiler> NewWrapper(
Alloc(m_pMalloc, Validator, TempCompiler));
return DoBasicQueryInterface<IDxcCompiler, IDxcCompiler2, IDxcCompiler3>(
NewWrapper.p, Iid, ResultObject);
return DoBasicQueryInterface<IDxcCompiler, IDxcCompiler2, IDxcCompiler3,
IDxcVersionInfo, IDxcVersionInfo2,
IDxcVersionInfo3>(NewWrapper.p, Iid,
ResultObject);
} catch (...) {
return E_FAIL;
}
Expand Down Expand Up @@ -305,6 +310,28 @@ class ExternalValidationCompiler : public IDxcCompiler2, public IDxcCompiler3 {
return cast<IDxcCompiler3>()->Disassemble(Object, Riid, ResultObject);
}

// IDxcVersionInfo implementation
HRESULT STDMETHODCALLTYPE GetVersion(_Out_ UINT32 *pMajor,
_Out_ UINT32 *pMinor) override {
return cast<IDxcVersionInfo>()->GetVersion(pMajor, pMinor);
}
HRESULT STDMETHODCALLTYPE GetFlags(_Out_ UINT32 *pFlags) override {
return cast<IDxcVersionInfo>()->GetFlags(pFlags);
}

// IDxcVersionInfo2 implementation
HRESULT STDMETHODCALLTYPE
GetCommitInfo(_Out_ UINT32 *pCommitCount,
_Outptr_result_z_ char **pCommitHash) override {
return cast<IDxcVersionInfo2>()->GetCommitInfo(pCommitCount, pCommitHash);
}

// IDxcVersionInfo3 implementation
HRESULT STDMETHODCALLTYPE
GetCustomVersionString(_Outptr_result_z_ char **pVersionString) override {
return cast<IDxcVersionInfo3>()->GetCustomVersionString(pVersionString);
}

private:
CComPtr<IDxcValidator> Validator;

Expand Down
2 changes: 2 additions & 0 deletions tools/clang/test/LitDXILValidation/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Skip when testing compiler's DXIL output against released validators.
config.unsupported = "dxc_dxil_dll_path" in config.available_features
12 changes: 3 additions & 9 deletions tools/clang/test/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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<dxcMajor>[0-9]+)\.(?P<dxcMinor>[0-9]+).")
dxcPat = re.compile(r"(dxcompiler\.dll|libdxcompiler\.so|libdxcompiler\.dylib): (?P<dxcMajor>[0-9]+)\.(?P<dxcMinor>[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<dxilMajor>[0-9]+)\.(?P<dxilMinor>[0-9]+)")
dxilPat = re.compile(r"(dxil\.dll|libdxil\.so|libdxil\.dylib): (?P<dxilMajor>[0-9]+)\.(?P<dxilMinor>[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:
Expand Down
151 changes: 78 additions & 73 deletions tools/clang/tools/dxclib/dxc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IDxcVersionInfo> VerInfo;

#ifdef SUPPORT_QUERY_GIT_COMMIT_INFO
UINT32 commitCount = 0;
CComHeapPtr<char> commitHash;
CComPtr<IDxcVersionInfo2> 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<IDxcVersionInfo> VerInfo;

UINT32 CommitCount = 0;
CComHeapPtr<char> CommitHash;
CComPtr<IDxcVersionInfo2> VerInfo2;

CComHeapPtr<char> CustomVersionString;
CComPtr<IDxcVersionInfo3> 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 : "<unknown-git-hash>")
#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 : "<unknown-git-hash>")
<< ")";
}

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<IDxcVersionInfo> 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<IDxcVersionInfo> VerInfo;

UINT32 CommitCount = 0;
CComHeapPtr<char> CommitHash;
CComPtr<IDxcVersionInfo2> 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 : "<unknown-git-hash>")
<< ")";
}

std::string ProductVersion;
if (GetDLLProductVersionInfo(DxilLib, ProductVersion))
OS << " - " << ProductVersion;
}

} // namespace dxc
Expand All @@ -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
Expand Down