Skip to content

Commit a7770e6

Browse files
authored
Added IDxcVersionInfo3 for custom version string (#3517)
1 parent c7d8ac5 commit a7770e6

3 files changed

Lines changed: 56 additions & 18 deletions

File tree

include/dxc/dxcapi.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ struct IDxcCompiler2 : public IDxcCompiler {
320320
_In_ UINT32 defineCount, // Number of defines
321321
_In_opt_ IDxcIncludeHandler *pIncludeHandler, // user-provided interface to handle #include directives (optional)
322322
_COM_Outptr_ IDxcOperationResult **ppResult, // Compiler output status, buffer, and errors
323-
_Outptr_opt_result_z_ LPWSTR *ppDebugBlobName,// Suggested file name for debug blob. (Must be HeapFree()'d!)
323+
_Outptr_opt_result_z_ LPWSTR *ppDebugBlobName,// Suggested file name for debug blob. (Must be CoTaskMemFree()'d!)
324324
_COM_Outptr_opt_ IDxcBlob **ppDebugBlob // Debug blob
325325
) = 0;
326326
};
@@ -569,7 +569,17 @@ struct IDxcVersionInfo : public IUnknown {
569569

570570
CROSS_PLATFORM_UUIDOF(IDxcVersionInfo2, "fb6904c4-42f0-4b62-9c46-983af7da7c83")
571571
struct IDxcVersionInfo2 : public IDxcVersionInfo {
572-
virtual HRESULT STDMETHODCALLTYPE GetCommitInfo(_Out_ UINT32 *pCommitCount, _Out_ char **pCommitHash) = 0;
572+
virtual HRESULT STDMETHODCALLTYPE GetCommitInfo(
573+
_Out_ UINT32 *pCommitCount, // The total number commits.
574+
_Outptr_result_z_ char **pCommitHash // The SHA of the latest commit. (Must be CoTaskMemFree()'d!)
575+
) = 0;
576+
};
577+
578+
CROSS_PLATFORM_UUIDOF(IDxcVersionInfo3, "5e13e843-9d25-473c-9ad2-03b2d0b44b1e")
579+
struct IDxcVersionInfo3 : public IDxcVersionInfo2 {
580+
virtual HRESULT STDMETHODCALLTYPE GetCustomVersionString(
581+
_Outptr_result_z_ char **pVersionString // Custom version string for compiler. (Must be CoTaskMemFree()'d!)
582+
) = 0;
573583
};
574584

575585
CROSS_PLATFORM_UUIDOF(IDxcPdbUtils, "E6C9647E-9D6A-4C3B-B94C-524B5A6C343D")

tools/clang/tools/dxcompiler/dxcpdbutils.cpp

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ static void ComputeFlagsBasedOnArgs(ArrayRef<std::wstring> args, std::vector<std
144144
}
145145
}
146146

147-
struct DxcPdbVersionInfo : public IDxcVersionInfo2 {
147+
struct DxcPdbVersionInfo : public IDxcVersionInfo3 {
148148
private:
149149
DXC_MICROCOM_TM_REF_FIELDS()
150150

@@ -156,9 +156,22 @@ struct DxcPdbVersionInfo : public IDxcVersionInfo2 {
156156

157157
hlsl::DxilCompilerVersion m_Version = {};
158158
std::string m_VersionCommitSha = {};
159+
std::string m_VersionString = {};
160+
161+
static HRESULT CopyStringToOutStringPtr(const std::string &Str, _Out_ char **ppOutString) {
162+
*ppOutString = nullptr;
163+
char *const pString = (char *)CoTaskMemAlloc(Str.size() + 1);
164+
if (pString == nullptr)
165+
return E_OUTOFMEMORY;
166+
std::memcpy(pString, Str.data(), Str.size());
167+
pString[Str.size()] = 0;
168+
169+
*ppOutString = pString;
170+
return S_OK;
171+
}
159172

160173
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppvObject) override {
161-
return DoBasicQueryInterface<IDxcVersionInfo, IDxcVersionInfo2>(this, iid, ppvObject);
174+
return DoBasicQueryInterface<IDxcVersionInfo, IDxcVersionInfo2, IDxcVersionInfo3>(this, iid, ppvObject);
162175
}
163176

164177
virtual HRESULT STDMETHODCALLTYPE GetVersion(_Out_ UINT32 *pMajor, _Out_ UINT32 *pMinor) override {
@@ -175,23 +188,22 @@ struct DxcPdbVersionInfo : public IDxcVersionInfo2 {
175188
return S_OK;
176189
}
177190

178-
virtual HRESULT STDMETHODCALLTYPE GetCommitInfo(_Out_ UINT32 *pCommitCount, _Out_ char **pCommitHash) {
191+
virtual HRESULT STDMETHODCALLTYPE GetCommitInfo(_Out_ UINT32 *pCommitCount, _Outptr_result_z_ char **pCommitHash) {
179192
if (!pCommitHash)
180193
return E_POINTER;
181194

182-
*pCommitHash = nullptr;
183-
184-
char *const hash = (char *)CoTaskMemAlloc(m_VersionCommitSha.size() + 1);
185-
if (hash == nullptr)
186-
return E_OUTOFMEMORY;
187-
std::memcpy(hash, m_VersionCommitSha.data(), m_VersionCommitSha.size());
188-
hash[m_VersionCommitSha.size()] = 0;
189-
190-
*pCommitHash = hash;
195+
IFR(CopyStringToOutStringPtr(m_VersionCommitSha, pCommitHash));
191196
*pCommitCount = m_Version.CommitCount;
192197

193198
return S_OK;
194199
}
200+
201+
virtual HRESULT STDMETHODCALLTYPE GetCustomVersionString(_Outptr_result_z_ char **pVersionString) {
202+
if (!pVersionString)
203+
return E_POINTER;
204+
IFR(CopyStringToOutStringPtr(m_VersionString, pVersionString));
205+
return S_OK;
206+
}
195207
};
196208

197209
struct PdbRecompilerIncludeHandler : public IDxcIncludeHandler {
@@ -861,6 +873,7 @@ struct DxcPdbUtils : public IDxcPdbUtils, public IDxcPixDxilDebugInfoFactory
861873
}
862874
result->m_Version = m_VersionInfo;
863875
result->m_VersionCommitSha = m_VersionCommitSha;
876+
result->m_VersionString = m_VersionString;
864877
*ppVersionInfo = result.Detach();
865878
return S_OK;
866879
}

tools/clang/unittests/HLSL/CompilerTest.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,9 @@ static void VerifyPdbUtil(dxc::DxcDllSupport &dllSupport,
10101010
VERIFY_IS_NOT_NULL(pVersion);
10111011
VERIFY_SUCCEEDED(pVersion.QueryInterface(&pVersion2));
10121012

1013+
CComPtr<IDxcVersionInfo3> pVersion3;
1014+
VERIFY_SUCCEEDED(pVersion.QueryInterface(&pVersion3));
1015+
10131016
CComPtr<IDxcVersionInfo> pCompilerVersion;
10141017
pCompiler->QueryInterface(&pCompilerVersion);
10151018

@@ -1030,19 +1033,31 @@ static void VerifyPdbUtil(dxc::DxcDllSupport &dllSupport,
10301033
VERIFY_ARE_EQUAL(uMinor, uCompilerMinor);
10311034
VERIFY_ARE_EQUAL(uFlags, uCompilerFlags);
10321035

1036+
// IDxcVersionInfo2
1037+
UINT32 uCommitCount = 0;
1038+
CComHeapPtr<char> CommitVersionHash;
1039+
VERIFY_SUCCEEDED(pVersion2->GetCommitInfo(&uCommitCount, &CommitVersionHash));
1040+
10331041
CComPtr<IDxcVersionInfo2> pCompilerVersion2;
10341042
if (SUCCEEDED(pCompiler->QueryInterface(&pCompilerVersion2))) {
10351043
UINT32 uCompilerCommitCount = 0;
10361044
CComHeapPtr<char> CompilerCommitVersionHash;
10371045
VERIFY_SUCCEEDED(pCompilerVersion2->GetCommitInfo(&uCompilerCommitCount, &CompilerCommitVersionHash));
10381046

1039-
UINT32 uCommitCount = 0;
1040-
CComHeapPtr<char> CommitVersionHash;
1041-
VERIFY_SUCCEEDED(pVersion2->GetCommitInfo(&uCommitCount, &CommitVersionHash));
1042-
10431047
VERIFY_IS_TRUE(0 == strcmp(CommitVersionHash, CompilerCommitVersionHash));
10441048
VERIFY_ARE_EQUAL(uCommitCount, uCompilerCommitCount);
10451049
}
1050+
1051+
// IDxcVersionInfo3
1052+
CComHeapPtr<char> VersionString;
1053+
VERIFY_SUCCEEDED(pVersion3->GetCustomVersionString(&VersionString));
1054+
1055+
CComPtr<IDxcVersionInfo3> pCompilerVersion3;
1056+
if (SUCCEEDED(pCompiler->QueryInterface(&pCompilerVersion3))) {
1057+
CComHeapPtr<char> CompilerVersionString;
1058+
VERIFY_SUCCEEDED(pCompilerVersion3->GetCustomVersionString(&CompilerVersionString));
1059+
VERIFY_IS_TRUE(0 == strcmp(CompilerVersionString, VersionString));
1060+
}
10461061
}
10471062
}
10481063

0 commit comments

Comments
 (0)