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 | |
| 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')
| -rw-r--r-- | source/compiler-core/slang-downstream-compiler.h | 3 | ||||
| -rw-r--r-- | source/compiler-core/slang-dxc-compiler.cpp | 51 | ||||
| -rw-r--r-- | source/compiler-core/slang-glslang-compiler.cpp | 41 | ||||
| -rw-r--r-- | source/core/slang-md5.cpp | 5 | ||||
| -rw-r--r-- | source/core/slang-md5.h | 2 | ||||
| -rw-r--r-- | source/slang/slang-ast-base.h | 2 | ||||
| -rw-r--r-- | source/slang/slang-ast-type.cpp | 1 | ||||
| -rw-r--r-- | source/slang/slang-ast-type.h | 3 | ||||
| -rw-r--r-- | source/slang/slang-ast-val.h | 2 | ||||
| -rw-r--r-- | source/slang/slang-hash-utils.h | 9 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 12 |
11 files changed, 121 insertions, 10 deletions
diff --git a/source/compiler-core/slang-downstream-compiler.h b/source/compiler-core/slang-downstream-compiler.h index a543f8e46..e7ab4ddad 100644 --- a/source/compiler-core/slang-downstream-compiler.h +++ b/source/compiler-core/slang-downstream-compiler.h @@ -191,6 +191,8 @@ public: virtual SLANG_NO_THROW bool SLANG_MCALL canConvert(const ArtifactDesc& from, const ArtifactDesc& to) = 0; /// Converts an artifact `from` to a desc of `to` and puts the result in outArtifact virtual SLANG_NO_THROW SlangResult SLANG_MCALL convert(IArtifact* from, const ArtifactDesc& to, IArtifact** outArtifact) = 0; + /// Get the version of this compiler + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getVersionString(slang::IBlob** outVersionString) = 0; /// True if underlying compiler uses file system to communicate source virtual SLANG_NO_THROW bool SLANG_MCALL isFileBased() = 0; @@ -208,6 +210,7 @@ public: virtual SLANG_NO_THROW const Desc& SLANG_MCALL getDesc() SLANG_OVERRIDE { return m_desc; } virtual SLANG_NO_THROW bool SLANG_MCALL canConvert(const ArtifactDesc& from, const ArtifactDesc& to) SLANG_OVERRIDE { SLANG_UNUSED(from); SLANG_UNUSED(to); return false; } virtual SLANG_NO_THROW SlangResult SLANG_MCALL convert(IArtifact* from, const ArtifactDesc& to, IArtifact** outArtifact) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getVersionString(slang::IBlob** outVersionString) SLANG_OVERRIDE { *outVersionString = nullptr; return SLANG_FAIL; } DownstreamCompilerBase(const Desc& desc): m_desc(desc) 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; diff --git a/source/compiler-core/slang-glslang-compiler.cpp b/source/compiler-core/slang-glslang-compiler.cpp index d6ae59690..26cbf3292 100644 --- a/source/compiler-core/slang-glslang-compiler.cpp +++ b/source/compiler-core/slang-glslang-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-artifact-associated-impl.h" #include "slang-artifact-desc-util.h" @@ -47,6 +49,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); @@ -60,7 +63,7 @@ protected: glslang_CompileFunc_1_0 m_compile_1_0 = nullptr; glslang_CompileFunc_1_1 m_compile_1_1 = nullptr; - ComPtr<ISlangSharedLibrary> m_sharedLibrary; + ComPtr<ISlangSharedLibrary> m_sharedLibrary; }; SlangResult GlslangDownstreamCompiler::init(ISlangSharedLibrary* library) @@ -78,6 +81,20 @@ SlangResult GlslangDownstreamCompiler::init(ISlangSharedLibrary* library) // It's not clear how to query for a version, but we can get a version number from the header m_desc = Desc(SLANG_PASS_THROUGH_GLSLANG); + Slang::String filename; + if (m_compile_1_1) + { + filename = Slang::SharedLibraryUtils::getSharedLibraryFileName((void*)m_compile_1_1); + } + else if (m_compile_1_0) + { + filename = Slang::SharedLibraryUtils::getSharedLibraryFileName((void*)m_compile_1_0); + } + else + { + return SLANG_FAIL; + } + return SLANG_OK; } @@ -277,6 +294,28 @@ SlangResult GlslangDownstreamCompiler::convert(IArtifact* from, const ArtifactDe return SLANG_OK; } +SlangResult GlslangDownstreamCompiler::getVersionString(slang::IBlob** outVersionString) +{ + uint64_t timestamp; + if (m_compile_1_1) + { + timestamp = SharedLibraryUtils::getSharedLibraryTimestamp((void*)m_compile_1_1); + } + else if (m_compile_1_0) + { + timestamp = SharedLibraryUtils::getSharedLibraryTimestamp((void*)m_compile_1_0); + } + else + { + return SLANG_FAIL; + } + + auto timestampString = String(timestamp); + ComPtr<ISlangBlob> version = StringBlob::create(timestampString.getBuffer()); + *outVersionString = version.detach(); + return SLANG_OK; +} + /* static */SlangResult GlslangDownstreamCompilerUtil::locateCompilers(const String& path, ISlangSharedLibraryLoader* loader, DownstreamCompilerSet* set) { ComPtr<ISlangSharedLibrary> library; diff --git a/source/core/slang-md5.cpp b/source/core/slang-md5.cpp index 95b4816bf..7371b21d2 100644 --- a/source/core/slang-md5.cpp +++ b/source/core/slang-md5.cpp @@ -232,6 +232,11 @@ namespace Slang update(ctx, hash.values, sizeof(hash.values)); } + void MD5HashGen::update(MD5Context* ctx, ISlangBlob* blob) + { + update(ctx, blob->getBufferPointer(), blob->getBufferSize()); + } + void MD5HashGen::update(MD5Context* ctx, const void* data, SlangInt size) { MD5_u32plus saved_lo; diff --git a/source/core/slang-md5.h b/source/core/slang-md5.h index 8c51a03ec..2e99fb667 100644 --- a/source/core/slang-md5.h +++ b/source/core/slang-md5.h @@ -70,6 +70,8 @@ namespace Slang void update(MD5Context* ctx, String str); // Helper update function for Checksums void update(MD5Context* ctx, const slang::Digest& checksum); + // Helper update function for ISlangBlob + void update(MD5Context* ctx, ISlangBlob* blob); void finalize(MD5Context* ctx, slang::Digest* result); diff --git a/source/slang/slang-ast-base.h b/source/slang/slang-ast-base.h index dea02afbb..04788340a 100644 --- a/source/slang/slang-ast-base.h +++ b/source/slang/slang-ast-base.h @@ -9,6 +9,8 @@ #include "slang-serialize-reflection.h" +#include "../core/slang-digest.h" + // This file defines the primary base classes for the hierarchy of // AST nodes and related objects. For example, this is where the // basic `Decl`, `Stmt`, `Expr`, `type`, etc. definitions come from. diff --git a/source/slang/slang-ast-type.cpp b/source/slang/slang-ast-type.cpp index 39b7a8e04..480589af4 100644 --- a/source/slang/slang-ast-type.cpp +++ b/source/slang/slang-ast-type.cpp @@ -1089,7 +1089,6 @@ Val* AndType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet su // ModifiedType - void ModifiedType::_toTextOverride(StringBuilder& out) { for( auto modifier : modifiers ) diff --git a/source/slang/slang-ast-type.h b/source/slang/slang-ast-type.h index 5bb91e5da..895b64f35 100644 --- a/source/slang/slang-ast-type.h +++ b/source/slang/slang-ast-type.h @@ -26,7 +26,6 @@ class InitializerListType : public Type { SLANG_AST_CLASS(InitializerListType) - // Overrides should be public so base classes can access void _toTextOverride(StringBuilder& out); Type* _createCanonicalTypeOverride(); @@ -694,7 +693,7 @@ class NamespaceType : public Type void _toTextOverride(StringBuilder& out); bool _equalsImplOverride(Type* type); HashCode _getHashCodeOverride(); - Type* _createCanonicalTypeOverride(); + Type* _createCanonicalTypeOverride(); }; // The concrete type for a value wrapped in an existential, accessible diff --git a/source/slang/slang-ast-val.h b/source/slang/slang-ast-val.h index a67d62e3b..49189f65c 100644 --- a/source/slang/slang-ast-val.h +++ b/source/slang/slang-ast-val.h @@ -3,6 +3,7 @@ #pragma once #include "slang-ast-base.h" +#include "../core/slang-digest.h" namespace Slang { @@ -379,7 +380,6 @@ class TaggedUnionSubtypeWitness : public SubtypeWitness // List<Val*> caseWitnesses; - // Overrides should be public so base classes can access bool _equalsValOverride(Val* val); void _toTextOverride(StringBuilder& out); diff --git a/source/slang/slang-hash-utils.h b/source/slang/slang-hash-utils.h index 62232dd21..c354e43f0 100644 --- a/source/slang/slang-hash-utils.h +++ b/source/slang/slang-hash-utils.h @@ -29,12 +29,13 @@ namespace Slang { StringBuilder filename; - for (Index i = 0; i < 4; ++i) + uint8_t* uint8Hash = (uint8_t*)hash.values; + + for (Index i = 0; i < 16; ++i) { - auto hashSegmentString = String(hash.values[i], 16); + auto hashSegmentString = String(uint8Hash[i], 16); - auto leadingZeroCount = 8 - hashSegmentString.getLength(); - for (Index j = 0; j < leadingZeroCount; ++j) + if (hashSegmentString.getLength() == 1) { filename.append("0"); } diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 20cad2465..3fb89c549 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -1367,6 +1367,18 @@ void Linkage::updateDependencyBasedHash( { builder.addToDigest(capability); } + + // Add the downstream compiler version (if it exists) to the hash + auto passThroughMode = getDownstreamCompilerRequiredForTarget(targetReq->getTarget()); + auto downstreamCompiler = getSessionImpl()->getOrLoadDownstreamCompiler(passThroughMode, nullptr); + if (downstreamCompiler) + { + ComPtr<ISlangBlob> versionString; + if (SLANG_SUCCEEDED(downstreamCompiler->getVersionString(versionString.writeRef()))) + { + builder.addToDigest(versionString); + } + } } SlangResult Linkage::addSearchPath( |
