summaryrefslogtreecommitdiff
path: root/source/compiler-core
diff options
context:
space:
mode:
Diffstat (limited to 'source/compiler-core')
-rw-r--r--source/compiler-core/slang-downstream-compiler.h3
-rw-r--r--source/compiler-core/slang-dxc-compiler.cpp51
-rw-r--r--source/compiler-core/slang-glslang-compiler.cpp41
3 files changed, 93 insertions, 2 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;