5151#include " dxillib.h"
5252#include " dxcshadersourceinfo.h"
5353#include " dxcompileradapter.h"
54+ #include " dxcversion.inc"
5455#include < algorithm>
5556#include < cfloat>
5657
@@ -97,6 +98,8 @@ struct CompilerVersionPartWriter {
9798 hlsl::DxilCompilerVersion m_Header = {};
9899 CComHeapPtr<char > m_CommitShaStorage;
99100 llvm::StringRef m_CommitSha = " " ;
101+ CComHeapPtr<char > m_CustomStringStorage;
102+ llvm::StringRef m_CustomString = " " ;
100103
101104 void Init (IDxcVersionInfo *pVersionInfo) {
102105 m_Header = {};
@@ -115,7 +118,14 @@ struct CompilerVersionPartWriter {
115118 IFT (pVersionInfo2->GetCommitInfo (&CommitCount, &m_CommitShaStorage));
116119 m_CommitSha = llvm::StringRef (m_CommitShaStorage.m_pData , strlen (m_CommitShaStorage.m_pData ));
117120 m_Header.CommitCount = CommitCount;
118- m_Header.VersionStringListSizeInBytes = m_CommitSha.size () + /* null term*/ 1 + /* another null term for the empty custom string*/ 1 ;
121+ m_Header.VersionStringListSizeInBytes += m_CommitSha.size () + /* null term*/ 1 ;
122+ }
123+
124+ CComPtr<IDxcVersionInfo3> pVersionInfo3;
125+ if (SUCCEEDED (pVersionInfo->QueryInterface (&pVersionInfo3))) {
126+ IFT (pVersionInfo3->GetCustomVersionString (&m_CustomStringStorage));
127+ m_CustomString = llvm::StringRef (m_CustomStringStorage, strlen (m_CustomStringStorage.m_pData ));
128+ m_Header.VersionStringListSizeInBytes += m_CustomString.size () + /* null term*/ 1 ;
119129 }
120130 }
121131
@@ -150,7 +160,9 @@ struct CompilerVersionPartWriter {
150160 // Null terminator for the commit sha
151161 IFT (pStream->Write (&padByte, sizeof (padByte), &cbWritten));
152162
153- // Null terminator for the empty version string
163+ // Write the custom version string.
164+ IFT (pStream->Write (m_CustomString.data (), m_CustomString.size (), &cbWritten));
165+ // Null terminator for the custom version string.
154166 IFT (pStream->Write (&padByte, sizeof (padByte), &cbWritten));
155167
156168 // Write padding
@@ -537,10 +549,9 @@ static void CreateDefineStrings(
537549class DxcCompiler : public IDxcCompiler3 ,
538550 public IDxcLangExtensions2,
539551 public IDxcContainerEvent,
552+ public IDxcVersionInfo3,
540553#ifdef SUPPORT_QUERY_GIT_COMMIT_INFO
541554 public IDxcVersionInfo2
542- #else
543- public IDxcVersionInfo
544555#endif // SUPPORT_QUERY_GIT_COMMIT_INFO
545556{
546557private:
@@ -577,6 +588,7 @@ class DxcCompiler : public IDxcCompiler3,
577588#ifdef SUPPORT_QUERY_GIT_COMMIT_INFO
578589 ,IDxcVersionInfo2
579590#endif // SUPPORT_QUERY_GIT_COMMIT_INFO
591+ ,IDxcVersionInfo3
580592 >
581593 (this , iid, ppvObject);
582594 if (FAILED (hr)) {
@@ -1393,6 +1405,19 @@ class DxcCompiler : public IDxcCompiler3,
13931405 *pMinor = DXIL::kDxilMinor ;
13941406 return S_OK;
13951407 }
1408+ HRESULT STDMETHODCALLTYPE GetCustomVersionString (
1409+ _Outptr_result_z_ char **pVersionString // Custom version string for compiler. (Must be CoTaskMemFree()'d!)
1410+ ) override
1411+ {
1412+ size_t size = strlen (RC_FILE_VERSION);
1413+ char *const result = (char *)CoTaskMemAlloc (size + 1 );
1414+ if (result == nullptr )
1415+ return E_OUTOFMEMORY;
1416+ std::strcpy (result, RC_FILE_VERSION);
1417+ *pVersionString = result;
1418+ return S_OK;
1419+ }
1420+
13961421#ifdef SUPPORT_QUERY_GIT_COMMIT_INFO
13971422 HRESULT STDMETHODCALLTYPE GetCommitInfo (_Out_ UINT32 *pCommitCount,
13981423 _Out_ char **pCommitHash) override {
@@ -1410,6 +1435,7 @@ class DxcCompiler : public IDxcCompiler3,
14101435 return S_OK;
14111436 }
14121437#endif // SUPPORT_QUERY_GIT_COMMIT_INFO
1438+
14131439 HRESULT STDMETHODCALLTYPE GetFlags (_Out_ UINT32 *pFlags) override {
14141440 if (pFlags == nullptr )
14151441 return E_INVALIDARG;
0 commit comments