diff options
| author | lucy96chen <47800040+lucy96chen@users.noreply.github.com> | 2022-10-13 16:00:05 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-13 16:00:05 -0700 |
| commit | e03026a07c4aa32c1a2de5ce199d910d74511c27 (patch) | |
| tree | ddf2282242353a3daabe01a6836365e8dc02a5fc /source/compiler-core/slang-dxc-compiler.cpp | |
| parent | 09054f7ae00aad0458de465a7f0b780a91c694dd (diff) | |
Add getVersionString() to IDownstreamCompiler (#2446)
* checkpoint
* Added shaderCachePath field to IDevice desc in gfx.slang, gfx-smoke.slang should be functional
* ran premake
* Added getVersionString() to IDownstreamCompiler and implemented it in DownstreamCompilerBase, GlslangDownstreamCompiler, and DXCDownstreamCompiler
* Added hashInto to Val and implemented for all subtypes which contain _getHashCodeOverride implementations; nothing hooked up to caching yet
* Revert erroneous commits from rebasing
* Re-ran premake.bat; changed hashInto implementations to _hashIntoOverride
* downstream compiler getVersionString hooked up into shader cache
* Rebuild CI, Win32 Release builds successfully locally
* Rebuild CI, Win32 and x64 Release build successfully locally
* Reverted Val::hashInto changes, deferred for later; modified init() for downstream compilers to fetch, hash, and save the hashes of their corresponding dlls (currently implemented for glslang and dxc), changed getVersionString() to directly return the saved hash for key computation
* call site changes post-merge; fixing CI build failures
* Removed remaining hashInto; Updated hashToString to produce string one byte at a time
* Fixed expected output to match new hashToString output order
* Missed string edit in hashing related unit tests
* Updated dxcapi.h; Replaced getVersionString implementation in glslang with the shared library timestamp, dxc implementation queries for IDxcVersionInfo and IDxcVersionInfo2 then fetches and returns the relevant values
* Fixing CI build failures
* Changed RawBlob to StringBlob for strings
* Modified getVersionString for dxc to always return either the version plus commit hash or shared library timestamp
Diffstat (limited to 'source/compiler-core/slang-dxc-compiler.cpp')
| -rw-r--r-- | source/compiler-core/slang-dxc-compiler.cpp | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/source/compiler-core/slang-dxc-compiler.cpp b/source/compiler-core/slang-dxc-compiler.cpp index c92eea47b..6619d000c 100644 --- a/source/compiler-core/slang-dxc-compiler.cpp +++ b/source/compiler-core/slang-dxc-compiler.cpp @@ -14,6 +14,8 @@ #include "../core/slang-semantic-version.h" #include "../core/slang-char-util.h" +#include "../core/slang-digest.h" + #include "slang-include-system.h" #include "slang-source-loc.h" @@ -168,6 +170,7 @@ public: virtual SLANG_NO_THROW bool SLANG_MCALL canConvert(const ArtifactDesc& from, const ArtifactDesc& to) SLANG_OVERRIDE; virtual SLANG_NO_THROW SlangResult SLANG_MCALL convert(IArtifact* from, const ArtifactDesc& to, IArtifact** outArtifact) SLANG_OVERRIDE; virtual SLANG_NO_THROW bool SLANG_MCALL isFileBased() SLANG_OVERRIDE { return false; } + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getVersionString(slang::IBlob** outVersionString) SLANG_OVERRIDE; /// Must be called before use SlangResult init(ISlangSharedLibrary* library); @@ -191,7 +194,7 @@ SlangResult DXCDownstreamCompiler::init(ISlangSharedLibrary* library) return SLANG_FAIL; } - m_desc = Desc(SLANG_PASS_THROUGH_DXC); + m_desc = Desc(SLANG_PASS_THROUGH_DXC); return SLANG_OK; } @@ -572,6 +575,52 @@ SlangResult DXCDownstreamCompiler::convert(IArtifact* from, const ArtifactDesc& return SLANG_OK; } +SlangResult DXCDownstreamCompiler::getVersionString(slang::IBlob** outVersionString) +{ + ComPtr<IDxcCompiler> dxcCompiler; + SLANG_RETURN_ON_FAIL(m_createInstance(CLSID_DxcCompiler, __uuidof(dxcCompiler), (LPVOID*)dxcCompiler.writeRef())); + + ComPtr<ISlangBlob> version; + ComPtr<IDxcVersionInfo> versionInfo; + if (SLANG_SUCCEEDED(dxcCompiler->QueryInterface(versionInfo.writeRef()))) + { + // Because the major/minor version alone does not necessarily capture different releases + // of the DX compiler, we also need to query for the commit hash. If we are unable to + // obtain the commit hash, then we return the shared library timestamp instead. + ComPtr<IDxcVersionInfo2> versionInfo2; + if (SLANG_SUCCEEDED(dxcCompiler->QueryInterface(versionInfo2.writeRef()))) + { + uint32_t major; + uint32_t minor; + versionInfo->GetVersion(&major, &minor); + + StringBuilder versionString; + versionString.append(major); + versionString.append("."); + versionString.append(minor); + + char* commitHash; + uint32_t unused; + versionInfo2->GetCommitInfo(&unused, &commitHash); + + versionString.append(commitHash); + CoTaskMemFree(commitHash); + + version = StringBlob::create(versionString.getBuffer()); + *outVersionString = version.detach(); + return SLANG_OK; + } + } + + // If either of the QueryInterface calls fails, we return the shared library timestamp + // as the version instead. + auto timestamp = SharedLibraryUtils::getSharedLibraryTimestamp(m_createInstance); + auto timestampString = String(timestamp); + version = StringBlob::create(timestampString.getBuffer()); + *outVersionString = version.detach(); + return SLANG_OK; +} + /* static */SlangResult DXCDownstreamCompilerUtil::locateCompilers(const String& path, ISlangSharedLibraryLoader* loader, DownstreamCompilerSet* set) { ComPtr<ISlangSharedLibrary> library; |
