From acf2bc48d9de0dd7eae669f0956fc44d72f78707 Mon Sep 17 00:00:00 2001 From: Tex Riddell Date: Wed, 31 Jan 2018 13:45:54 -0800 Subject: [PATCH] Set !dx.valver in Linker (#1031) --- include/dxc/HLSL/DxilLinker.h | 5 +++-- lib/HLSL/DxilLinker.cpp | 22 +++++++++++++++++----- tools/clang/tools/dxcompiler/dxclinker.cpp | 15 +++------------ 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/include/dxc/HLSL/DxilLinker.h b/include/dxc/HLSL/DxilLinker.h index 9357dd03e..a79796c35 100644 --- a/include/dxc/HLSL/DxilLinker.h +++ b/include/dxc/HLSL/DxilLinker.h @@ -33,7 +33,7 @@ class DxilResourceBase; class DxilLinker { public: virtual ~DxilLinker() {} - static DxilLinker *CreateLinker(llvm::LLVMContext &Ctx); + static DxilLinker *CreateLinker(llvm::LLVMContext &Ctx, unsigned valMajor, unsigned valMinor); virtual bool HasLibNameRegistered(llvm::StringRef name) = 0; virtual bool RegisterLib(llvm::StringRef name, @@ -47,8 +47,9 @@ public: llvm::StringRef profile) = 0; protected: - DxilLinker(llvm::LLVMContext &Ctx) : m_ctx(Ctx) {} + DxilLinker(llvm::LLVMContext &Ctx, unsigned valMajor, unsigned valMinor) : m_ctx(Ctx), m_valMajor(valMajor), m_valMinor(valMinor) {} llvm::LLVMContext &m_ctx; + unsigned m_valMajor, m_valMinor; }; } // namespace hlsl diff --git a/lib/HLSL/DxilLinker.cpp b/lib/HLSL/DxilLinker.cpp index 7ef5f13a1..4e783eefc 100644 --- a/lib/HLSL/DxilLinker.cpp +++ b/lib/HLSL/DxilLinker.cpp @@ -127,7 +127,7 @@ struct DxilLinkJob; class DxilLinkerImpl : public hlsl::DxilLinker { public: - DxilLinkerImpl(LLVMContext &Ctx) : DxilLinker(Ctx) {} + DxilLinkerImpl(LLVMContext &Ctx, unsigned valMajor, unsigned valMinor) : DxilLinker(Ctx, valMajor, valMinor) {} virtual ~DxilLinkerImpl() {} bool HasLibNameRegistered(StringRef name) override; bool RegisterLib(StringRef name, std::unique_ptr pModule, @@ -315,7 +315,7 @@ DxilResourceBase *DxilLib::GetResource(const llvm::Constant *GV) { namespace { // Create module from link defines. struct DxilLinkJob { - DxilLinkJob(LLVMContext &Ctx) : m_ctx(Ctx) {} + DxilLinkJob(LLVMContext &Ctx, unsigned valMajor, unsigned valMinor) : m_ctx(Ctx), m_valMajor(valMajor), m_valMinor(valMinor) {} std::unique_ptr Link(std::pair &entryLinkPair, StringRef profile); @@ -336,6 +336,7 @@ private: llvm::StringMap> m_resourceMap; LLVMContext &m_ctx; + unsigned m_valMajor, m_valMinor; }; } // namespace @@ -350,6 +351,7 @@ const char kNoEntryProps[] = "Cannot find function property for entry function "; const char kRedefineResource[] = "Resource already exists as "; +const char kInvalidValidatorVersion[] = "Validator version does not support target profile "; } // namespace //------------------------------------------------------------------------------ // @@ -540,6 +542,16 @@ DxilLinkJob::Link(std::pair &entryLinkPair, const bool bSkipInit = true; DxilModule &DM = pM->GetOrCreateDxilModule(bSkipInit); DM.SetShaderModel(pSM); + + // Set Validator version, verifying that it supports the requested profile + unsigned minValMajor, minValMinor; + DM.GetMinValidatorVersion(minValMajor, minValMinor); + if (minValMajor > m_valMajor || (minValMajor == m_valMajor && minValMinor > m_valMinor)) { + m_ctx.emitError(Twine(kInvalidValidatorVersion) + profile); + return nullptr; + } + DM.SetValidatorVersion(m_valMajor, m_valMinor); + // Add type sys DxilTypeSystem &typeSys = DM.GetTypeSystem(); @@ -891,7 +903,7 @@ std::unique_ptr DxilLinkerImpl::Link(StringRef entry, SmallVector workList; workList.emplace_back(entry); - DxilLinkJob linkJob(m_ctx); + DxilLinkJob linkJob(m_ctx, m_valMajor, m_valMinor); DenseSet libSet; if (!AddFunctions(workList, libSet, addedFunctionSet, linkJob, @@ -922,7 +934,7 @@ std::unique_ptr DxilLinkerImpl::Link(StringRef entry, namespace hlsl { -DxilLinker *DxilLinker::CreateLinker(LLVMContext &Ctx) { - return new DxilLinkerImpl(Ctx); +DxilLinker *DxilLinker::CreateLinker(LLVMContext &Ctx, unsigned valMajor, unsigned valMinor) { + return new DxilLinkerImpl(Ctx, valMajor, valMinor); } } // namespace hlsl \ No newline at end of file diff --git a/tools/clang/tools/dxcompiler/dxclinker.cpp b/tools/clang/tools/dxcompiler/dxclinker.cpp index a5f6dcf5b..fae42fc5c 100644 --- a/tools/clang/tools/dxcompiler/dxclinker.cpp +++ b/tools/clang/tools/dxcompiler/dxclinker.cpp @@ -91,7 +91,9 @@ public: } void Initialize() { - m_pLinker.reset(DxilLinker::CreateLinker(m_Ctx)); + UINT32 valMajor, valMinor; + dxcutil::GetValidatorVersion(&valMajor, &valMinor); + m_pLinker.reset(DxilLinker::CreateLinker(m_Ctx, valMajor, valMinor)); } ~DxcLinker() { @@ -182,19 +184,8 @@ HRESULT STDMETHODCALLTYPE DxcLinker::Link( std::string warnings; llvm::raw_string_ostream w(warnings); - - { - UINT32 majorVer, minorVer; - dxcutil::GetValidatorVersion(&majorVer, &minorVer); - // TODO: use validation version when link. - (majorVer); - (minorVer); - } - IFT(CreateMemoryStream(pMalloc, &pDiagStream)); - raw_stream_ostream DiagStream(pDiagStream); - llvm::DiagnosticPrinterRawOStream DiagPrinter(DiagStream); PrintDiagnosticContext DiagContext(DiagPrinter); m_Ctx.setDiagnosticHandler(PrintDiagnosticContext::PrintDiagnosticHandler,