From d7d1936a65cb141c85b69b4a313afcc5446f0087 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Thu, 5 Jun 2025 17:17:38 -0700 Subject: [PATCH 01/53] implement stage 2 --- include/dxc/Support/dxcapi.extval.h | 20 ++++++++++++++ include/dxc/Support/dxcapi.use.h | 21 ++++++++------ lib/DxcSupport/CMakeLists.txt | 1 + lib/DxcSupport/dxcapi.extval.cpp | 43 +++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 include/dxc/Support/dxcapi.extval.h create mode 100644 lib/DxcSupport/dxcapi.extval.cpp diff --git a/include/dxc/Support/dxcapi.extval.h b/include/dxc/Support/dxcapi.extval.h new file mode 100644 index 0000000000..c051b2d9f8 --- /dev/null +++ b/include/dxc/Support/dxcapi.extval.h @@ -0,0 +1,20 @@ +#include "dxc/Support/dxcapi.use.h" +#include "dxc/dxcapi.h" + +class DxcDllExtValidationSupport : public dxc::DxcDllSupport { + // DxcDllExtValidationSupport manages the + // lifetime of dxcompiler.dll, while the member, m_DxilSupport, + // manages the lifetime of dxil.dll + dxc::DxcDllSupport m_DxilSupport; + + std::string DxilDllPath; + // override DxcDllSupport's implementation of InitializeInternal, + // adding the environment variable value check for a path to a dxil.dll + + std::string GetDxilDLLPathExt() { return DxilDllPath; } + bool DxilDllSuccessfullyLoaded() { + return !DxilDllPath.empty() && !m_DxilSupport.IsEnabled(); + } + + HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName); +}; diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index 44fe23bad6..f29c7b6f93 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -13,6 +13,10 @@ #define __DXCAPI_USE_H__ #include "dxc/dxcapi.h" +#include // for getenv +#include +#include // C++17 and later +#include // for hresult handling with DXC_FAILED namespace dxc { @@ -85,13 +89,13 @@ class DxcDllSupport { other.m_createFn2 = nullptr; } - ~DxcDllSupport() { Cleanup(); } + virtual ~DxcDllSupport() { Cleanup(); } - HRESULT Initialize() { + HRESULT virtual Initialize() { return InitializeInternal(kDxCompilerLib, "DxcCreateInstance"); } - HRESULT InitializeForDll(LPCSTR dll, LPCSTR entryPoint) { + HRESULT virtual InitializeForDll(LPCSTR dll, LPCSTR entryPoint) { return InitializeInternal(dll, entryPoint); } @@ -100,7 +104,8 @@ class DxcDllSupport { return CreateInstance(clsid, __uuidof(TInterface), (IUnknown **)pResult); } - HRESULT CreateInstance(REFCLSID clsid, REFIID riid, IUnknown **pResult) { + HRESULT virtual CreateInstance(REFCLSID clsid, REFIID riid, + IUnknown **pResult) { if (pResult == nullptr) return E_POINTER; if (m_dll == nullptr) @@ -116,7 +121,7 @@ class DxcDllSupport { (IUnknown **)pResult); } - HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, + HRESULT virtual CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, IUnknown **pResult) { if (pResult == nullptr) return E_POINTER; @@ -128,11 +133,11 @@ class DxcDllSupport { return hr; } - bool HasCreateWithMalloc() const { return m_createFn2 != nullptr; } + bool virtual HasCreateWithMalloc() const { return m_createFn2 != nullptr; } bool IsEnabled() const { return m_dll != nullptr; } - void Cleanup() { + void virtual Cleanup() { if (m_dll != nullptr) { m_createFn = nullptr; m_createFn2 = nullptr; @@ -145,7 +150,7 @@ class DxcDllSupport { } } - HMODULE Detach() { + HMODULE virtual Detach() { HMODULE hModule = m_dll; m_dll = nullptr; return hModule; diff --git a/lib/DxcSupport/CMakeLists.txt b/lib/DxcSupport/CMakeLists.txt index dbc8ef0c26..96474bd620 100644 --- a/lib/DxcSupport/CMakeLists.txt +++ b/lib/DxcSupport/CMakeLists.txt @@ -10,6 +10,7 @@ add_llvm_library(LLVMDxcSupport WinAdapter.cpp WinIncludes.cpp WinFunctions.cpp + dxcapi.extval.cpp ) #generate header with platform-specific library name diff --git a/lib/DxcSupport/dxcapi.extval.cpp b/lib/DxcSupport/dxcapi.extval.cpp new file mode 100644 index 0000000000..9a29febb18 --- /dev/null +++ b/lib/DxcSupport/dxcapi.extval.cpp @@ -0,0 +1,43 @@ +#include "dxc/Support/WinIncludes.h" + +#include "dxc/Support/dxcapi.use.h" + +#include "dxc/Support/FileIOHelper.h" +#include "dxc/Support/Global.h" +#include "dxc/Support/SharedLibAffix.h" // header generated during DXC build +#include "dxc/Support/Unicode.h" +#include "dxc/Support/WinFunctions.h" + +#include "dxc/Support/dxcapi.extval.h" + +HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR dllName, + LPCSTR fnName) { + // Load dxcompiler.dll + HRESULT result = InitializeForDll(dllName, fnName); + // if dxcompiler.dll fails to load, return the failed HRESULT + if (DXC_FAILED(result)) { + return result; + } + + // now handle external dxil.dll + const char *envVal = std::getenv("DXC_DXIL_DLL_PATH"); + if (!envVal || std::string(envVal).empty()) { + return S_OK; + } + + std::string DllPathStr(envVal); + DxilDllPath = DllPathStr; + std::filesystem::path DllPath(DllPathStr); + + // Check if path is absolute and exists + if (!DllPath.is_absolute() || !std::filesystem::exists(DllPath)) { + return S_OK; + } + // code that calls this function is responsible for checking + // to see if dxil.dll is successfully loaded. + // the CheckDxilDLLLoaded function can determine whether there were any + // problems loading dxil.dll or not + m_DxilSupport.InitializeForDll(DllPathStr.data(), fnName); + + return S_OK; +} From c527502b9ab0c8beafab500b8349f6d224c24f7c Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Thu, 5 Jun 2025 17:18:09 -0700 Subject: [PATCH 02/53] add crucial headers --- include/dxc/Support/dxcapi.use.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index f29c7b6f93..2381f814cb 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -137,6 +137,16 @@ class DxcDllSupport { bool IsEnabled() const { return m_dll != nullptr; } + bool GetCreateInstanceProcs(DxcCreateInstanceProc *pCreateFn, + DxcCreateInstance2Proc *pCreateFn2) const { + if (pCreateFn == nullptr || pCreateFn2 == nullptr || + m_createFn == nullptr) + return false; + *pCreateFn = m_createFn; + *pCreateFn2 = m_createFn2; + return true; + } + void virtual Cleanup() { if (m_dll != nullptr) { m_createFn = nullptr; From 7f7dc30a9f35e892338168b552d62aa465746ba1 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 6 Jun 2025 00:27:21 +0000 Subject: [PATCH 03/53] chore: autopublish 2025-06-06T00:27:21Z --- include/dxc/Support/dxcapi.use.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index 2381f814cb..90e027b436 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -13,10 +13,10 @@ #define __DXCAPI_USE_H__ #include "dxc/dxcapi.h" -#include // for getenv -#include -#include // C++17 and later +#include // for getenv #include // for hresult handling with DXC_FAILED +#include // C++17 and later +#include namespace dxc { @@ -122,7 +122,7 @@ class DxcDllSupport { } HRESULT virtual CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, - IUnknown **pResult) { + IUnknown **pResult) { if (pResult == nullptr) return E_POINTER; if (m_dll == nullptr) @@ -139,9 +139,8 @@ class DxcDllSupport { bool GetCreateInstanceProcs(DxcCreateInstanceProc *pCreateFn, DxcCreateInstance2Proc *pCreateFn2) const { - if (pCreateFn == nullptr || pCreateFn2 == nullptr || - m_createFn == nullptr) - return false; + if (pCreateFn == nullptr || pCreateFn2 == nullptr || m_createFn == nullptr) + return false; *pCreateFn = m_createFn; *pCreateFn2 = m_createFn2; return true; From e7ec854ac1b695b5673d9135987db5b2ca6580e8 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Fri, 6 Jun 2025 11:58:35 -0700 Subject: [PATCH 04/53] address Tex non-header changes --- include/dxc/Support/dxcapi.extval.h | 8 ++++---- include/dxc/Support/dxcapi.use.h | 2 +- lib/DxcSupport/dxcapi.extval.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/dxc/Support/dxcapi.extval.h b/include/dxc/Support/dxcapi.extval.h index c051b2d9f8..37ef70f269 100644 --- a/include/dxc/Support/dxcapi.extval.h +++ b/include/dxc/Support/dxcapi.extval.h @@ -5,15 +5,15 @@ class DxcDllExtValidationSupport : public dxc::DxcDllSupport { // DxcDllExtValidationSupport manages the // lifetime of dxcompiler.dll, while the member, m_DxilSupport, // manages the lifetime of dxil.dll - dxc::DxcDllSupport m_DxilSupport; + dxc::DxcDllSupport DxilSupport; std::string DxilDllPath; // override DxcDllSupport's implementation of InitializeInternal, // adding the environment variable value check for a path to a dxil.dll - std::string GetDxilDLLPathExt() { return DxilDllPath; } - bool DxilDllSuccessfullyLoaded() { - return !DxilDllPath.empty() && !m_DxilSupport.IsEnabled(); + std::string GetDxilDllPath() { return DxilDllPath; } + bool DxilDllFailedToLoad() { + return !DxilDllPath.empty() && !DxilSupport.IsEnabled(); } HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName); diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index 90e027b436..895b1a84d1 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -133,7 +133,7 @@ class DxcDllSupport { return hr; } - bool virtual HasCreateWithMalloc() const { return m_createFn2 != nullptr; } + bool HasCreateWithMalloc() const { return m_createFn2 != nullptr; } bool IsEnabled() const { return m_dll != nullptr; } diff --git a/lib/DxcSupport/dxcapi.extval.cpp b/lib/DxcSupport/dxcapi.extval.cpp index 9a29febb18..13adc76aaf 100644 --- a/lib/DxcSupport/dxcapi.extval.cpp +++ b/lib/DxcSupport/dxcapi.extval.cpp @@ -37,7 +37,7 @@ HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR dllName, // to see if dxil.dll is successfully loaded. // the CheckDxilDLLLoaded function can determine whether there were any // problems loading dxil.dll or not - m_DxilSupport.InitializeForDll(DllPathStr.data(), fnName); + DxilSupport.InitializeForDll(DllPathStr.data(), fnName); return S_OK; } From 39f913c0652390dd693cdf96c8bb585800feab94 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Fri, 6 Jun 2025 12:12:54 -0700 Subject: [PATCH 05/53] handle includes --- include/dxc/Support/dxcapi.use.h | 2 -- lib/DxcSupport/dxcapi.extval.cpp | 11 +---------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index 895b1a84d1..58e34313ee 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -13,10 +13,8 @@ #define __DXCAPI_USE_H__ #include "dxc/dxcapi.h" -#include // for getenv #include // for hresult handling with DXC_FAILED #include // C++17 and later -#include namespace dxc { diff --git a/lib/DxcSupport/dxcapi.extval.cpp b/lib/DxcSupport/dxcapi.extval.cpp index 13adc76aaf..fe3581b999 100644 --- a/lib/DxcSupport/dxcapi.extval.cpp +++ b/lib/DxcSupport/dxcapi.extval.cpp @@ -1,14 +1,5 @@ -#include "dxc/Support/WinIncludes.h" - -#include "dxc/Support/dxcapi.use.h" - -#include "dxc/Support/FileIOHelper.h" -#include "dxc/Support/Global.h" -#include "dxc/Support/SharedLibAffix.h" // header generated during DXC build -#include "dxc/Support/Unicode.h" -#include "dxc/Support/WinFunctions.h" - #include "dxc/Support/dxcapi.extval.h" +#include "dxc/Support/WinIncludes.h" HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR dllName, LPCSTR fnName) { From 3700bfd30733b3fecffefa80290837131109b8f2 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Fri, 6 Jun 2025 15:28:00 -0700 Subject: [PATCH 06/53] swap include order --- lib/DxcSupport/dxcapi.extval.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/DxcSupport/dxcapi.extval.cpp b/lib/DxcSupport/dxcapi.extval.cpp index fe3581b999..462ac0e783 100644 --- a/lib/DxcSupport/dxcapi.extval.cpp +++ b/lib/DxcSupport/dxcapi.extval.cpp @@ -1,5 +1,6 @@ -#include "dxc/Support/dxcapi.extval.h" #include "dxc/Support/WinIncludes.h" +// WinIncludes must come before dxcapi.extval.h +#include "dxc/Support/dxcapi.extval.h" HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR dllName, LPCSTR fnName) { From 33c88f98b1bde3da9576aacd696a14d7c5fec0e2 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Tue, 17 Jun 2025 20:31:17 -0700 Subject: [PATCH 07/53] address Tex, and make a flawed attempt at writing a unit test --- include/dxc/Support/dxcapi.extval.h | 20 ++++++++++-- include/dxc/Support/dxcapi.use.h | 16 ++++------ lib/DxcSupport/dxcapi.extval.cpp | 5 ++- tools/clang/unittests/HLSL/ValidationTest.cpp | 32 ++++++++++++++++++- 4 files changed, 59 insertions(+), 14 deletions(-) diff --git a/include/dxc/Support/dxcapi.extval.h b/include/dxc/Support/dxcapi.extval.h index 37ef70f269..40722e458a 100644 --- a/include/dxc/Support/dxcapi.extval.h +++ b/include/dxc/Support/dxcapi.extval.h @@ -1,13 +1,18 @@ #include "dxc/Support/dxcapi.use.h" -#include "dxc/dxcapi.h" +#include class DxcDllExtValidationSupport : public dxc::DxcDllSupport { // DxcDllExtValidationSupport manages the // lifetime of dxcompiler.dll, while the member, m_DxilSupport, // manages the lifetime of dxil.dll + protected: dxc::DxcDllSupport DxilSupport; std::string DxilDllPath; + + HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) override; + + public: // override DxcDllSupport's implementation of InitializeInternal, // adding the environment variable value check for a path to a dxil.dll @@ -15,6 +20,15 @@ class DxcDllExtValidationSupport : public dxc::DxcDllSupport { bool DxilDllFailedToLoad() { return !DxilDllPath.empty() && !DxilSupport.IsEnabled(); } - - HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName); + + void Cleanup() override { + DxilSupport.Cleanup(); + DxcDllSupport::Cleanup(); + } + + HMODULE Detach() override { + // Can't Detach and return a handle for DxilSupport. Cleanup() instead. + DxilSupport.Cleanup(); + return DxcDllSupport::Detach(); + } }; diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index 58e34313ee..1699a0c15f 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -13,8 +13,6 @@ #define __DXCAPI_USE_H__ #include "dxc/dxcapi.h" -#include // for hresult handling with DXC_FAILED -#include // C++17 and later namespace dxc { @@ -28,7 +26,7 @@ class DxcDllSupport { DxcCreateInstanceProc m_createFn; DxcCreateInstance2Proc m_createFn2; - HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) { + virtual HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) { if (m_dll != nullptr) return S_OK; @@ -89,11 +87,11 @@ class DxcDllSupport { virtual ~DxcDllSupport() { Cleanup(); } - HRESULT virtual Initialize() { + HRESULT Initialize() { return InitializeInternal(kDxCompilerLib, "DxcCreateInstance"); } - HRESULT virtual InitializeForDll(LPCSTR dll, LPCSTR entryPoint) { + HRESULT InitializeForDll(LPCSTR dll, LPCSTR entryPoint) { return InitializeInternal(dll, entryPoint); } @@ -102,7 +100,7 @@ class DxcDllSupport { return CreateInstance(clsid, __uuidof(TInterface), (IUnknown **)pResult); } - HRESULT virtual CreateInstance(REFCLSID clsid, REFIID riid, + virtual HRESULT CreateInstance(REFCLSID clsid, REFIID riid, IUnknown **pResult) { if (pResult == nullptr) return E_POINTER; @@ -119,7 +117,7 @@ class DxcDllSupport { (IUnknown **)pResult); } - HRESULT virtual CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, + virtual HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, IUnknown **pResult) { if (pResult == nullptr) return E_POINTER; @@ -144,7 +142,7 @@ class DxcDllSupport { return true; } - void virtual Cleanup() { + virtual void Cleanup() { if (m_dll != nullptr) { m_createFn = nullptr; m_createFn2 = nullptr; @@ -157,7 +155,7 @@ class DxcDllSupport { } } - HMODULE virtual Detach() { + virtual HMODULE Detach() { HMODULE hModule = m_dll; m_dll = nullptr; return hModule; diff --git a/lib/DxcSupport/dxcapi.extval.cpp b/lib/DxcSupport/dxcapi.extval.cpp index 462ac0e783..d8e243d143 100644 --- a/lib/DxcSupport/dxcapi.extval.cpp +++ b/lib/DxcSupport/dxcapi.extval.cpp @@ -1,11 +1,14 @@ #include "dxc/Support/WinIncludes.h" +#include // for hresult handling with DXC_FAILED +#include // C++17 and later // WinIncludes must come before dxcapi.extval.h #include "dxc/Support/dxcapi.extval.h" + HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR dllName, LPCSTR fnName) { // Load dxcompiler.dll - HRESULT result = InitializeForDll(dllName, fnName); + HRESULT result = DxcDllSupport::InitializeInternal(dllName, fnName); // if dxcompiler.dll fails to load, return the failed HRESULT if (DXC_FAILED(result)) { return result; diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp index 980bf6c7c2..a251d91a88 100644 --- a/tools/clang/unittests/HLSL/ValidationTest.cpp +++ b/tools/clang/unittests/HLSL/ValidationTest.cpp @@ -32,7 +32,8 @@ #include "dxc/Support/Global.h" #include "dxc/DXIL/DxilShaderModel.h" -#include "dxc/Test/DxcTestUtils.h" +#include "dxc/Test/DxcTestUtils.h" // includes dxcapi.use.h +#include "dxc/Support/dxcapi.extval.h" #include "dxc/Test/HlslTestUtils.h" using namespace std; @@ -299,6 +300,7 @@ class ValidationTest : public ::testing::Test { TEST_METHOD(ValidatePrintfNotAllowed) TEST_METHOD(ValidateWithHash) + TEST_METHOD(ValidateWithExternalValidator) TEST_METHOD(ValidateVersionNotAllowed) TEST_METHOD(ValidatePreviewBypassHash) TEST_METHOD(ValidateProgramVersionAgainstDxilModule) @@ -328,6 +330,7 @@ class ValidationTest : public ::testing::Test { TEST_METHOD(WrongPSVVersion) dxc::DxcDllSupport m_dllSupport; + DxcDllExtValidationSupport m_dllExtSupport; VersionSupportInfo m_ver; void TestCheck(LPCWSTR name) { @@ -4207,6 +4210,33 @@ TEST_F(ValidationTest, ValidateWithHash) { VERIFY_ARE_EQUAL(memcmp(Result, pHeader->Hash.Digest, sizeof(Result)), 0); } +TEST_F(ValidationTest, ValidateWithExternalValidator) { + if (!m_dllExtSupport.IsEnabled()) { + VERIFY_SUCCEEDED(m_dllExtSupport.Initialize()); + } + + if (m_ver.SkipDxilVersion(1, ShaderModel::kHighestReleasedMinor)) + return; + CComPtr pProgram; + CompileSource("float4 main(float a:A, float b:B) : SV_Target { return 1; }", + "ps_6_0", &pProgram); + + CComPtr pValidator; + CComPtr pResult; + unsigned Flags = 0; + VERIFY_SUCCEEDED( + m_dllExtSupport.CreateInstance(CLSID_DxcValidator, &pValidator)); + // With hash. + VERIFY_SUCCEEDED(pValidator->Validate(pProgram, Flags, &pResult)); + // Make sure the validation was successful. + HRESULT status; + VERIFY_IS_NOT_NULL(pResult); + CComPtr pValidationOutput; + pResult->GetStatus(&status); + VERIFY_SUCCEEDED(status); + pResult->GetResult(&pValidationOutput); +} + TEST_F(ValidationTest, ValidatePreviewBypassHash) { if (m_ver.SkipDxilVersion(1, ShaderModel::kHighestMinor)) return; From 544a9c753f81bd2ac44f7d175803bc23fc02c833 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 18 Jun 2025 04:25:46 +0000 Subject: [PATCH 08/53] chore: autopublish 2025-06-18T04:25:45Z --- include/dxc/Support/dxcapi.extval.h | 8 ++++---- lib/DxcSupport/dxcapi.extval.cpp | 1 - tools/clang/unittests/HLSL/ValidationTest.cpp | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/include/dxc/Support/dxcapi.extval.h b/include/dxc/Support/dxcapi.extval.h index 40722e458a..89f3592ca8 100644 --- a/include/dxc/Support/dxcapi.extval.h +++ b/include/dxc/Support/dxcapi.extval.h @@ -5,14 +5,14 @@ class DxcDllExtValidationSupport : public dxc::DxcDllSupport { // DxcDllExtValidationSupport manages the // lifetime of dxcompiler.dll, while the member, m_DxilSupport, // manages the lifetime of dxil.dll - protected: +protected: dxc::DxcDllSupport DxilSupport; std::string DxilDllPath; HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) override; - public: +public: // override DxcDllSupport's implementation of InitializeInternal, // adding the environment variable value check for a path to a dxil.dll @@ -20,12 +20,12 @@ class DxcDllExtValidationSupport : public dxc::DxcDllSupport { bool DxilDllFailedToLoad() { return !DxilDllPath.empty() && !DxilSupport.IsEnabled(); } - + void Cleanup() override { DxilSupport.Cleanup(); DxcDllSupport::Cleanup(); } - + HMODULE Detach() override { // Can't Detach and return a handle for DxilSupport. Cleanup() instead. DxilSupport.Cleanup(); diff --git a/lib/DxcSupport/dxcapi.extval.cpp b/lib/DxcSupport/dxcapi.extval.cpp index d8e243d143..8fe7287ff6 100644 --- a/lib/DxcSupport/dxcapi.extval.cpp +++ b/lib/DxcSupport/dxcapi.extval.cpp @@ -4,7 +4,6 @@ // WinIncludes must come before dxcapi.extval.h #include "dxc/Support/dxcapi.extval.h" - HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR dllName, LPCSTR fnName) { // Load dxcompiler.dll diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp index a251d91a88..048301a37e 100644 --- a/tools/clang/unittests/HLSL/ValidationTest.cpp +++ b/tools/clang/unittests/HLSL/ValidationTest.cpp @@ -32,8 +32,8 @@ #include "dxc/Support/Global.h" #include "dxc/DXIL/DxilShaderModel.h" -#include "dxc/Test/DxcTestUtils.h" // includes dxcapi.use.h #include "dxc/Support/dxcapi.extval.h" +#include "dxc/Test/DxcTestUtils.h" // includes dxcapi.use.h #include "dxc/Test/HlslTestUtils.h" using namespace std; @@ -4234,7 +4234,7 @@ TEST_F(ValidationTest, ValidateWithExternalValidator) { CComPtr pValidationOutput; pResult->GetStatus(&status); VERIFY_SUCCEEDED(status); - pResult->GetResult(&pValidationOutput); + pResult->GetResult(&pValidationOutput); } TEST_F(ValidationTest, ValidatePreviewBypassHash) { From eeb151602fab0737c4de5cecf97b62e7d4455a58 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Tue, 17 Jun 2025 22:59:06 -0700 Subject: [PATCH 09/53] validated that local test passes --- tools/clang/unittests/HLSL/ValidationTest.cpp | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp index 048301a37e..7ea87a4e2b 100644 --- a/tools/clang/unittests/HLSL/ValidationTest.cpp +++ b/tools/clang/unittests/HLSL/ValidationTest.cpp @@ -4211,6 +4211,19 @@ TEST_F(ValidationTest, ValidateWithHash) { } TEST_F(ValidationTest, ValidateWithExternalValidator) { + /* + // The below part of the test was run on a local machine, + // but shouldn't be run yet in automated scenarios, since + // the DXC repo does not yet have a checked-in dxil.dll. + + // set the environment variable that stores the path to the extenral + // dxil.dll + SetEnvironmentVariableW(L"DXC_DXIL_DLL_PATH", + L"D:\\hlsl.bin\\Debug\\bin\\dxil.dll"); + // also update the CRT environment + _putenv_s("DXC_DXIL_DLL_PATH", "D:\\hlsl.bin\\Debug\\bin\\dxil.dll"); + */ + if (!m_dllExtSupport.IsEnabled()) { VERIFY_SUCCEEDED(m_dllExtSupport.Initialize()); } @@ -4235,6 +4248,17 @@ TEST_F(ValidationTest, ValidateWithExternalValidator) { pResult->GetStatus(&status); VERIFY_SUCCEEDED(status); pResult->GetResult(&pValidationOutput); + + /* + // as described above, this should only be tested in local scenarios, + // until dxil.dll is checked into the dxc repo + + // validate that m_dllExtSupport was able to capture the environment + // variable's value, and that loading the external validator was successful + VERIFY_IS_TRUE(!m_dllExtSupport.DxilDllFailedToLoad()); + std::string extPath("D:\\hlsl.bin\\Debug\\bin\\dxil.dll"); + VERIFY_ARE_EQUAL(m_dllExtSupport.GetDxilDllPath(), extPath); + */ } TEST_F(ValidationTest, ValidatePreviewBypassHash) { From 9800c91458e715fa94cbc16f052ffd867580aa24 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Tue, 24 Jun 2025 17:33:18 -0700 Subject: [PATCH 10/53] address tex, update unit test --- include/dxc/Support/dxcapi.extval.h | 10 +- lib/DxcSupport/dxcapi.extval.cpp | 29 ++++++ tools/clang/unittests/HLSL/ValidationTest.cpp | 97 +++++++++++-------- 3 files changed, 90 insertions(+), 46 deletions(-) diff --git a/include/dxc/Support/dxcapi.extval.h b/include/dxc/Support/dxcapi.extval.h index 89f3592ca8..a8a8a36e9a 100644 --- a/include/dxc/Support/dxcapi.extval.h +++ b/include/dxc/Support/dxcapi.extval.h @@ -10,12 +10,11 @@ class DxcDllExtValidationSupport : public dxc::DxcDllSupport { std::string DxilDllPath; - HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) override; - -public: // override DxcDllSupport's implementation of InitializeInternal, // adding the environment variable value check for a path to a dxil.dll + HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) override; +public: std::string GetDxilDllPath() { return DxilDllPath; } bool DxilDllFailedToLoad() { return !DxilDllPath.empty() && !DxilSupport.IsEnabled(); @@ -31,4 +30,9 @@ class DxcDllExtValidationSupport : public dxc::DxcDllSupport { DxilSupport.Cleanup(); return DxcDllSupport::Detach(); } + + HRESULT CreateInstance(REFCLSID clsid, REFIID riid, + IUnknown **pResult) override; + HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, + IUnknown **pResult) override; }; diff --git a/lib/DxcSupport/dxcapi.extval.cpp b/lib/DxcSupport/dxcapi.extval.cpp index 8fe7287ff6..9bffb4c500 100644 --- a/lib/DxcSupport/dxcapi.extval.cpp +++ b/lib/DxcSupport/dxcapi.extval.cpp @@ -35,3 +35,32 @@ HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR dllName, return S_OK; } + +HRESULT DxcDllExtValidationSupport::CreateInstance(REFCLSID clsid, REFIID riid, + IUnknown **pResult) { + if (DxilSupport.IsEnabled() && clsid == CLSID_DxcValidator) + return DxilSupport.CreateInstance(clsid, riid, pResult); + + if (pResult == nullptr) + return E_POINTER; + if (m_dll == nullptr) + return E_FAIL; + HRESULT hr = m_createFn(clsid, riid, (LPVOID *)pResult); + return hr; +} + +HRESULT DxcDllExtValidationSupport::CreateInstance2(IMalloc *pMalloc, + REFCLSID clsid, REFIID riid, + IUnknown **pResult) { + if (DxilSupport.IsEnabled() && clsid == CLSID_DxcValidator) + return DxilSupport.CreateInstance2(pMalloc, clsid, riid, pResult); + + if (pResult == nullptr) + return E_POINTER; + if (m_dll == nullptr) + return E_FAIL; + if (m_createFn2 == nullptr) + return E_FAIL; + HRESULT hr = m_createFn2(pMalloc, clsid, riid, (LPVOID *)pResult); + return hr; +} diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp index 7ea87a4e2b..eed2b8fc89 100644 --- a/tools/clang/unittests/HLSL/ValidationTest.cpp +++ b/tools/clang/unittests/HLSL/ValidationTest.cpp @@ -300,7 +300,6 @@ class ValidationTest : public ::testing::Test { TEST_METHOD(ValidatePrintfNotAllowed) TEST_METHOD(ValidateWithHash) - TEST_METHOD(ValidateWithExternalValidator) TEST_METHOD(ValidateVersionNotAllowed) TEST_METHOD(ValidatePreviewBypassHash) TEST_METHOD(ValidateProgramVersionAgainstDxilModule) @@ -325,12 +324,12 @@ class ValidationTest : public ::testing::Test { TEST_METHOD(PSVContentValidationCS) TEST_METHOD(PSVContentValidationMS) TEST_METHOD(PSVContentValidationAS) + TEST_METHOD(UnitTestExtValidationSupport) TEST_METHOD(WrongPSVSize) TEST_METHOD(WrongPSVSizeOnZeros) TEST_METHOD(WrongPSVVersion) dxc::DxcDllSupport m_dllSupport; - DxcDllExtValidationSupport m_dllExtSupport; VersionSupportInfo m_ver; void TestCheck(LPCWSTR name) { @@ -4210,55 +4209,67 @@ TEST_F(ValidationTest, ValidateWithHash) { VERIFY_ARE_EQUAL(memcmp(Result, pHeader->Hash.Digest, sizeof(Result)), 0); } -TEST_F(ValidationTest, ValidateWithExternalValidator) { - /* - // The below part of the test was run on a local machine, - // but shouldn't be run yet in automated scenarios, since - // the DXC repo does not yet have a checked-in dxil.dll. - - // set the environment variable that stores the path to the extenral - // dxil.dll - SetEnvironmentVariableW(L"DXC_DXIL_DLL_PATH", - L"D:\\hlsl.bin\\Debug\\bin\\dxil.dll"); +// For now, 3 things are tested: +// 1. The environment variable is not set. GetDxilDllPath() is empty and +// DxilDllFailedToLoad() returns false +// 2. Given a bogus path in the environment variable, GetDxilDllPath() +// retrieves the path but fails to load it as a dll, and returns true +// for DxilDllFailedToLoad() +// 3. CLSID_DxcCompiler, CLSID_DxcLinker, CLSID_DxcValidator +// may be created through DxcDllExtValidationSupport. +// This is all to simply test that the new class, DxcDllExtValidationSupport, +// works as intended. + +TEST_F(ValidationTest, UnitTestExtValidationSupport) { + DxcDllExtValidationSupport m_dllExtSupport1; + DxcDllExtValidationSupport m_dllExtSupport2; + + // 1. with no env var set, test GetDxilDllPath() and DxilDllFailedToLoad() + m_dllExtSupport1.Initialize(); + VERIFY_IS_FALSE(m_dllExtSupport1.DxilDllFailedToLoad()); + VERIFY_ARE_EQUAL(m_dllExtSupport1.GetDxilDllPath(), ""); + + // 2. Test with a bogus path in the environment variable + SetEnvironmentVariableW(L"DXC_DXIL_DLL_PATH", L"bogus"); // also update the CRT environment - _putenv_s("DXC_DXIL_DLL_PATH", "D:\\hlsl.bin\\Debug\\bin\\dxil.dll"); - */ + _putenv_s("DXC_DXIL_DLL_PATH", "bogus"); - if (!m_dllExtSupport.IsEnabled()) { - VERIFY_SUCCEEDED(m_dllExtSupport.Initialize()); + if (!m_dllExtSupport2.IsEnabled()) { + VERIFY_SUCCEEDED(m_dllExtSupport2.Initialize()); } - if (m_ver.SkipDxilVersion(1, ShaderModel::kHighestReleasedMinor)) - return; - CComPtr pProgram; - CompileSource("float4 main(float a:A, float b:B) : SV_Target { return 1; }", - "ps_6_0", &pProgram); + // validate that m_dllExtSupport2 was able to capture the environment + // variable's value, and that loading the bogus path was unsuccessful + std::string extPath("bogus"); + VERIFY_ARE_EQUAL(m_dllExtSupport2.GetDxilDllPath(), extPath); + VERIFY_IS_TRUE(m_dllExtSupport2.DxilDllFailedToLoad()); + // 3. Test production of class IDs CLSID_DxcCompiler, CLSID_DxcLinker, + // and CLSID_DxcValidator through DxcDllExtValidationSupport. + CComPtr pCompiler; + CComPtr pLinker; CComPtr pValidator; CComPtr pResult; - unsigned Flags = 0; - VERIFY_SUCCEEDED( - m_dllExtSupport.CreateInstance(CLSID_DxcValidator, &pValidator)); - // With hash. - VERIFY_SUCCEEDED(pValidator->Validate(pProgram, Flags, &pResult)); - // Make sure the validation was successful. - HRESULT status; - VERIFY_IS_NOT_NULL(pResult); - CComPtr pValidationOutput; - pResult->GetStatus(&status); - VERIFY_SUCCEEDED(status); - pResult->GetResult(&pValidationOutput); - - /* - // as described above, this should only be tested in local scenarios, - // until dxil.dll is checked into the dxc repo - // validate that m_dllExtSupport was able to capture the environment - // variable's value, and that loading the external validator was successful - VERIFY_IS_TRUE(!m_dllExtSupport.DxilDllFailedToLoad()); - std::string extPath("D:\\hlsl.bin\\Debug\\bin\\dxil.dll"); - VERIFY_ARE_EQUAL(m_dllExtSupport.GetDxilDllPath(), extPath); - */ + VERIFY_SUCCEEDED(m_dllExtSupport2.CreateInstance( + CLSID_DxcCompiler, __uuidof(IDxcCompiler), (IUnknown **)&pCompiler)); + VERIFY_SUCCEEDED(m_dllExtSupport2.CreateInstance( + CLSID_DxcLinker, __uuidof(IDxcLinker), (IUnknown **)&pLinker)); + VERIFY_SUCCEEDED(m_dllExtSupport2.CreateInstance( + CLSID_DxcValidator, __uuidof(IDxcValidator), (IUnknown **)&pValidator)); + CComPtr pMalloc; + CComPtr pCompiler2; + pLinker.Release(); + pValidator.Release(); + VERIFY_SUCCEEDED(DxcCoGetMalloc(1, &pMalloc)); + VERIFY_SUCCEEDED(m_dllExtSupport2.CreateInstance2(pMalloc, CLSID_DxcCompiler, + __uuidof(IDxcCompiler), + (IUnknown **)&pCompiler2)); + VERIFY_SUCCEEDED(m_dllExtSupport2.CreateInstance2( + pMalloc, CLSID_DxcLinker, __uuidof(IDxcLinker), (IUnknown **)&pLinker)); + VERIFY_SUCCEEDED(m_dllExtSupport2.CreateInstance2(pMalloc, CLSID_DxcValidator, + __uuidof(IDxcValidator), + (IUnknown **)&pValidator)); } TEST_F(ValidationTest, ValidatePreviewBypassHash) { From a4c9629c14799acfaf5abc92574e38a267669a01 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Wed, 25 Jun 2025 00:21:00 -0700 Subject: [PATCH 11/53] ifdef for windows vs unix env var addition --- tools/clang/unittests/HLSL/ValidationTest.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp index eed2b8fc89..f8f0a3cdc6 100644 --- a/tools/clang/unittests/HLSL/ValidationTest.cpp +++ b/tools/clang/unittests/HLSL/ValidationTest.cpp @@ -24,6 +24,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Regex.h" +#include // for setenv(), getenv(), unsetenv() #ifdef _WIN32 #include @@ -4230,10 +4231,15 @@ TEST_F(ValidationTest, UnitTestExtValidationSupport) { VERIFY_ARE_EQUAL(m_dllExtSupport1.GetDxilDllPath(), ""); // 2. Test with a bogus path in the environment variable +#ifdef _WIN32 SetEnvironmentVariableW(L"DXC_DXIL_DLL_PATH", L"bogus"); // also update the CRT environment _putenv_s("DXC_DXIL_DLL_PATH", "bogus"); +#else + setenv("DXC_DXIL_DLL_PATH", "bogus", 1); +#endif + if (!m_dllExtSupport2.IsEnabled()) { VERIFY_SUCCEEDED(m_dllExtSupport2.Initialize()); } From a9282fd68e8208bcc6a7235f0db68ca9c9106f05 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Wed, 25 Jun 2025 11:31:29 -0700 Subject: [PATCH 12/53] add wstring conversion stuff and env var resets --- tools/clang/unittests/HLSL/ValidationTest.cpp | 79 ++++++++++++++++--- 1 file changed, 70 insertions(+), 9 deletions(-) diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp index f8f0a3cdc6..13fcf52715 100644 --- a/tools/clang/unittests/HLSL/ValidationTest.cpp +++ b/tools/clang/unittests/HLSL/ValidationTest.cpp @@ -4210,6 +4210,59 @@ TEST_F(ValidationTest, ValidateWithHash) { VERIFY_ARE_EQUAL(memcmp(Result, pHeader->Hash.Digest, sizeof(Result)), 0); } +std::wstring string_to_wstring(const std::string &str) { + if (str.empty()) + return L""; + + int size_needed = + MultiByteToWideChar(CP_UTF8, 0, str.c_str(), (int)str.size(), nullptr, 0); + std::wstring wstrTo(size_needed, 0); + MultiByteToWideChar(CP_UTF8, 0, str.c_str(), (int)str.size(), &wstrTo[0], + size_needed); + return wstrTo; +} + +std::string wstring_to_utf8(const std::wstring &wstr) { + if (wstr.empty()) + return ""; + + int size = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), -1, nullptr, 0, + nullptr, nullptr); + std::string result(size - 1, 0); // -1 to exclude null terminator + WideCharToMultiByte(CP_UTF8, 0, wstr.data(), -1, &result[0], size, nullptr, + nullptr); + return result; +} + +std::string GetEnvVarA(const std::string &varName) { +#ifdef _WIN32 + DWORD size = GetEnvironmentVariableA(varName.c_str(), nullptr, 0); + if (size == 0) { + return ""; // Not found or empty + } + + std::string buffer(size - 1, '\0'); // size includes null terminator + GetEnvironmentVariableA(varName.c_str(), &buffer[0], size); + return buffer; +#else + const char *result = std::getenv(varName.c_str()); + return result ? std::string(result) : std::string(); +#endif +} + +void SetEnvVarW(const std::wstring &varName, const std::wstring &varValue) { +#ifdef _WIN32 + VERIFY_IS_TRUE(SetEnvironmentVariableW(varName.c_str(), varValue.c_str())); + // also update the CRT environment + _putenv_s(wstring_to_utf8(varName).c_str(), + wstring_to_utf8(varValue).c_str()); +#else + std::string name_utf8 = wstring_to_utf8(varName); + std::string value_utf8 = wstring_to_utf8(varValue); + setenv(name_utf8.c_str(), value_utf8.c_str(), 1); +#endif +} + // For now, 3 things are tested: // 1. The environment variable is not set. GetDxilDllPath() is empty and // DxilDllFailedToLoad() returns false @@ -4225,20 +4278,23 @@ TEST_F(ValidationTest, UnitTestExtValidationSupport) { DxcDllExtValidationSupport m_dllExtSupport1; DxcDllExtValidationSupport m_dllExtSupport2; + // capture any existing value in the environment variable, + // so that it can be restored after the test + std::string oldEnvVal = GetEnvVarA("DXC_DXIL_DLL_PATH"); + // 1. with no env var set, test GetDxilDllPath() and DxilDllFailedToLoad() - m_dllExtSupport1.Initialize(); + + // make sure the variable is cleared, in case other tests may have set it + SetEnvVarW(L"DXC_DXIL_DLL_PATH", L""); + + // empty initialization should succeed + VERIFY_SUCCEEDED(m_dllExtSupport1.Initialize()); + VERIFY_IS_FALSE(m_dllExtSupport1.DxilDllFailedToLoad()); VERIFY_ARE_EQUAL(m_dllExtSupport1.GetDxilDllPath(), ""); // 2. Test with a bogus path in the environment variable -#ifdef _WIN32 - SetEnvironmentVariableW(L"DXC_DXIL_DLL_PATH", L"bogus"); - // also update the CRT environment - _putenv_s("DXC_DXIL_DLL_PATH", "bogus"); - -#else - setenv("DXC_DXIL_DLL_PATH", "bogus", 1); -#endif + SetEnvVarW(L"DXC_DXIL_DLL_PATH", L"bogus"); if (!m_dllExtSupport2.IsEnabled()) { VERIFY_SUCCEEDED(m_dllExtSupport2.Initialize()); @@ -4276,6 +4332,11 @@ TEST_F(ValidationTest, UnitTestExtValidationSupport) { VERIFY_SUCCEEDED(m_dllExtSupport2.CreateInstance2(pMalloc, CLSID_DxcValidator, __uuidof(IDxcValidator), (IUnknown **)&pValidator)); + + // reset the environment variable to its previous value, if it had one. + if (!oldEnvVal.empty()) { + SetEnvVarW(L"DXC_DXIL_DLL_PATH", string_to_wstring(oldEnvVal)); + } } TEST_F(ValidationTest, ValidatePreviewBypassHash) { From e781627f8a0522d8621a35522a0eb4609428246c Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Wed, 25 Jun 2025 13:44:12 -0700 Subject: [PATCH 13/53] address tex --- tools/clang/unittests/HLSL/CMakeLists.txt | 2 + tools/clang/unittests/HLSL/ValidationTest.cpp | 59 ++++++++----------- 2 files changed, 28 insertions(+), 33 deletions(-) diff --git a/tools/clang/unittests/HLSL/CMakeLists.txt b/tools/clang/unittests/HLSL/CMakeLists.txt index eaba5049b2..5aea11bcd0 100644 --- a/tools/clang/unittests/HLSL/CMakeLists.txt +++ b/tools/clang/unittests/HLSL/CMakeLists.txt @@ -48,6 +48,7 @@ add_clang_library(ClangHLSLTests SHARED PixTestUtils.cpp RewriterTest.cpp SystemValueTest.cpp + ${CMAKE_SOURCE_DIR}/lib/dxcsupport/Unicode.cpp ValidationTest.cpp VerifierTest.cpp ) @@ -78,6 +79,7 @@ add_clang_unittest(ClangHLSLTests PixTestUtils.cpp SystemValueTest.cpp TestMain.cpp + ${CMAKE_SOURCE_DIR}/lib/dxcsupport/Unicode.cpp ValidationTest.cpp VerifierTest.cpp ) diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp index 13fcf52715..a736de07f6 100644 --- a/tools/clang/unittests/HLSL/ValidationTest.cpp +++ b/tools/clang/unittests/HLSL/ValidationTest.cpp @@ -20,6 +20,7 @@ #include "dxc/DxilContainer/DxilContainerAssembler.h" #include "dxc/DxilContainer/DxilPipelineStateValidation.h" #include "dxc/DxilHash/DxilHash.h" +#include "dxc/Support/Unicode.h" // for wstring conversions like WideToUtf8String #include "dxc/Support/WinIncludes.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" @@ -4210,39 +4211,15 @@ TEST_F(ValidationTest, ValidateWithHash) { VERIFY_ARE_EQUAL(memcmp(Result, pHeader->Hash.Digest, sizeof(Result)), 0); } -std::wstring string_to_wstring(const std::string &str) { - if (str.empty()) - return L""; - - int size_needed = - MultiByteToWideChar(CP_UTF8, 0, str.c_str(), (int)str.size(), nullptr, 0); - std::wstring wstrTo(size_needed, 0); - MultiByteToWideChar(CP_UTF8, 0, str.c_str(), (int)str.size(), &wstrTo[0], - size_needed); - return wstrTo; -} - -std::string wstring_to_utf8(const std::wstring &wstr) { - if (wstr.empty()) - return ""; - - int size = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), -1, nullptr, 0, - nullptr, nullptr); - std::string result(size - 1, 0); // -1 to exclude null terminator - WideCharToMultiByte(CP_UTF8, 0, wstr.data(), -1, &result[0], size, nullptr, - nullptr); - return result; -} - -std::string GetEnvVarA(const std::string &varName) { +std::wstring GetEnvVarW(const std::wstring &varName) { #ifdef _WIN32 - DWORD size = GetEnvironmentVariableA(varName.c_str(), nullptr, 0); + DWORD size = GetEnvironmentVariableW(varName.c_str(), nullptr, 0); if (size == 0) { - return ""; // Not found or empty + return L""; // Not found or empty } - std::string buffer(size - 1, '\0'); // size includes null terminator - GetEnvironmentVariableA(varName.c_str(), &buffer[0], size); + std::wstring buffer(size - 1, '\0'); // size includes null terminator + GetEnvironmentVariableW(varName.c_str(), &buffer[0], size); return buffer; #else const char *result = std::getenv(varName.c_str()); @@ -4254,8 +4231,11 @@ void SetEnvVarW(const std::wstring &varName, const std::wstring &varValue) { #ifdef _WIN32 VERIFY_IS_TRUE(SetEnvironmentVariableW(varName.c_str(), varValue.c_str())); // also update the CRT environment - _putenv_s(wstring_to_utf8(varName).c_str(), - wstring_to_utf8(varValue).c_str()); + std::string varNameStr; + std::string varValueStr; + Unicode::WideToUTF8String(varName.c_str(), &varNameStr); + Unicode::WideToUTF8String(varValue.c_str(), &varValueStr); + _putenv_s(varNameStr.c_str(), varValueStr.c_str()); #else std::string name_utf8 = wstring_to_utf8(varName); std::string value_utf8 = wstring_to_utf8(varValue); @@ -4263,6 +4243,17 @@ void SetEnvVarW(const std::wstring &varName, const std::wstring &varValue) { #endif } +void ClearEnvVarW(const std::wstring &varName) { + std::string varNameStr; + Unicode::WideToUTF8String(varName.c_str(), &varNameStr); +#ifdef _WIN32 + SetEnvironmentVariableW(varName.c_str(), nullptr); + _putenv_s(varNameStr.c_str(), ""); +#else + unsetenv(varNameStr.c_str()); +#endif +} + // For now, 3 things are tested: // 1. The environment variable is not set. GetDxilDllPath() is empty and // DxilDllFailedToLoad() returns false @@ -4280,7 +4271,7 @@ TEST_F(ValidationTest, UnitTestExtValidationSupport) { // capture any existing value in the environment variable, // so that it can be restored after the test - std::string oldEnvVal = GetEnvVarA("DXC_DXIL_DLL_PATH"); + std::wstring oldEnvVal = GetEnvVarW(L"DXC_DXIL_DLL_PATH"); // 1. with no env var set, test GetDxilDllPath() and DxilDllFailedToLoad() @@ -4335,7 +4326,9 @@ TEST_F(ValidationTest, UnitTestExtValidationSupport) { // reset the environment variable to its previous value, if it had one. if (!oldEnvVal.empty()) { - SetEnvVarW(L"DXC_DXIL_DLL_PATH", string_to_wstring(oldEnvVal)); + SetEnvVarW(L"DXC_DXIL_DLL_PATH", oldEnvVal); + } else { + ClearEnvVarW(L"DXC_DXIL_DLL_PATH"); } } From 2915a8d8952e0b8feb3a5db0aa6ab51e024f7cb1 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Wed, 25 Jun 2025 16:24:51 -0700 Subject: [PATCH 14/53] special casing for unix systems --- tools/clang/unittests/HLSL/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/clang/unittests/HLSL/CMakeLists.txt b/tools/clang/unittests/HLSL/CMakeLists.txt index 5aea11bcd0..c3f618773e 100644 --- a/tools/clang/unittests/HLSL/CMakeLists.txt +++ b/tools/clang/unittests/HLSL/CMakeLists.txt @@ -48,7 +48,7 @@ add_clang_library(ClangHLSLTests SHARED PixTestUtils.cpp RewriterTest.cpp SystemValueTest.cpp - ${CMAKE_SOURCE_DIR}/lib/dxcsupport/Unicode.cpp + ${CMAKE_SOURCE_DIR}/lib/DxcSupport/Unicode.cpp ValidationTest.cpp VerifierTest.cpp ) @@ -79,7 +79,7 @@ add_clang_unittest(ClangHLSLTests PixTestUtils.cpp SystemValueTest.cpp TestMain.cpp - ${CMAKE_SOURCE_DIR}/lib/dxcsupport/Unicode.cpp + ${CMAKE_SOURCE_DIR}/lib/DxcSupport/Unicode.cpp ValidationTest.cpp VerifierTest.cpp ) From 57dd8534f121dd7d6e3bf8f5a7c6b6428e710d28 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Mon, 30 Jun 2025 13:40:38 -0700 Subject: [PATCH 15/53] address tex, make wstrings more universal too --- include/dxc/Support/dxcapi.extval.h | 4 +- lib/DxcSupport/dxcapi.extval.cpp | 21 +-- tools/clang/unittests/HLSL/ValidationTest.cpp | 131 ++++++++---------- 3 files changed, 71 insertions(+), 85 deletions(-) diff --git a/include/dxc/Support/dxcapi.extval.h b/include/dxc/Support/dxcapi.extval.h index a8a8a36e9a..e205406333 100644 --- a/include/dxc/Support/dxcapi.extval.h +++ b/include/dxc/Support/dxcapi.extval.h @@ -8,14 +8,14 @@ class DxcDllExtValidationSupport : public dxc::DxcDllSupport { protected: dxc::DxcDllSupport DxilSupport; - std::string DxilDllPath; + std::wstring DxilDllPath; // override DxcDllSupport's implementation of InitializeInternal, // adding the environment variable value check for a path to a dxil.dll HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) override; public: - std::string GetDxilDllPath() { return DxilDllPath; } + std::wstring GetDxilDllPath() { return DxilDllPath; } bool DxilDllFailedToLoad() { return !DxilDllPath.empty() && !DxilSupport.IsEnabled(); } diff --git a/lib/DxcSupport/dxcapi.extval.cpp b/lib/DxcSupport/dxcapi.extval.cpp index 9bffb4c500..7f132028fa 100644 --- a/lib/DxcSupport/dxcapi.extval.cpp +++ b/lib/DxcSupport/dxcapi.extval.cpp @@ -2,26 +2,30 @@ #include // for hresult handling with DXC_FAILED #include // C++17 and later // WinIncludes must come before dxcapi.extval.h +#include "dxc/Support/Unicode.h" // for wstring conversions like WideToUtf8String #include "dxc/Support/dxcapi.extval.h" HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR dllName, LPCSTR fnName) { // Load dxcompiler.dll - HRESULT result = DxcDllSupport::InitializeInternal(dllName, fnName); + HRESULT Result = DxcDllSupport::InitializeInternal(dllName, fnName); // if dxcompiler.dll fails to load, return the failed HRESULT - if (DXC_FAILED(result)) { - return result; + if (DXC_FAILED(Result)) { + return Result; } // now handle external dxil.dll - const char *envVal = std::getenv("DXC_DXIL_DLL_PATH"); - if (!envVal || std::string(envVal).empty()) { + const wchar_t *EnvVarValue = _wgetenv(L"DXC_DXIL_DLL_PATH"); + if (!EnvVarValue || std::wstring(EnvVarValue).empty()) { return S_OK; } - std::string DllPathStr(envVal); - DxilDllPath = DllPathStr; - std::filesystem::path DllPath(DllPathStr); + std::wstring DllPathWStr(EnvVarValue); + std::string DllPathStr; + Unicode::WideToUTF8String(DllPathWStr.data(), &DllPathStr); + + DxilDllPath = DllPathWStr; + std::filesystem::path DllPath(DllPathWStr); // Check if path is absolute and exists if (!DllPath.is_absolute() || !std::filesystem::exists(DllPath)) { @@ -31,6 +35,7 @@ HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR dllName, // to see if dxil.dll is successfully loaded. // the CheckDxilDLLLoaded function can determine whether there were any // problems loading dxil.dll or not + DxilSupport.InitializeForDll(DllPathStr.data(), fnName); return S_OK; diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp index a736de07f6..f7aa93e225 100644 --- a/tools/clang/unittests/HLSL/ValidationTest.cpp +++ b/tools/clang/unittests/HLSL/ValidationTest.cpp @@ -4211,46 +4211,31 @@ TEST_F(ValidationTest, ValidateWithHash) { VERIFY_ARE_EQUAL(memcmp(Result, pHeader->Hash.Digest, sizeof(Result)), 0); } -std::wstring GetEnvVarW(const std::wstring &varName) { +std::wstring GetEnvVarW(const std::wstring &VarName) { #ifdef _WIN32 - DWORD size = GetEnvironmentVariableW(varName.c_str(), nullptr, 0); - if (size == 0) { - return L""; // Not found or empty - } - - std::wstring buffer(size - 1, '\0'); // size includes null terminator - GetEnvironmentVariableW(varName.c_str(), &buffer[0], size); - return buffer; -#else - const char *result = std::getenv(varName.c_str()); - return result ? std::string(result) : std::string(); -#endif -} - -void SetEnvVarW(const std::wstring &varName, const std::wstring &varValue) { -#ifdef _WIN32 - VERIFY_IS_TRUE(SetEnvironmentVariableW(varName.c_str(), varValue.c_str())); - // also update the CRT environment - std::string varNameStr; - std::string varValueStr; - Unicode::WideToUTF8String(varName.c_str(), &varNameStr); - Unicode::WideToUTF8String(varValue.c_str(), &varValueStr); - _putenv_s(varNameStr.c_str(), varValueStr.c_str()); + if (const wchar_t *Result = _wgetenv(VarName.c_str())) + return std::wstring(Result); #else - std::string name_utf8 = wstring_to_utf8(varName); - std::string value_utf8 = wstring_to_utf8(varValue); - setenv(name_utf8.c_str(), value_utf8.c_str(), 1); + std::string NameUtf8; + WideToUTF8String(Name.c_str, &NameUtf8); + if (const char *Result = std::getenv(NameUtf8.c_str())) { + std::wstring ResultWide; + Unicode::UTF8ToWideString(Result.c_str(), &ResultWide); + return std::wstring(ResultWide); + } #endif + return std::wstring(); } -void ClearEnvVarW(const std::wstring &varName) { - std::string varNameStr; - Unicode::WideToUTF8String(varName.c_str(), &varNameStr); +void SetEnvVarW(const std::wstring &VarName, const std::wstring &VarValue) { #ifdef _WIN32 - SetEnvironmentVariableW(varName.c_str(), nullptr); - _putenv_s(varNameStr.c_str(), ""); + _wputenv_s(VarName.c_str(), VarValue.c_str()); #else - unsetenv(varNameStr.c_str()); + std::string VarNameUtf8; + std::string VarValueUtf8; + Unicode::WideToUTF8String(VarName.c_str(), &VarNameUtf8); + Unicode::WideToUTF8String(VarValue.c_str(), &VarValueUtf8); + setenv(VarNameUtf8.c_str(), VarValueUtf8.c_str(), 1); #endif } @@ -4266,12 +4251,12 @@ void ClearEnvVarW(const std::wstring &varName) { // works as intended. TEST_F(ValidationTest, UnitTestExtValidationSupport) { - DxcDllExtValidationSupport m_dllExtSupport1; - DxcDllExtValidationSupport m_dllExtSupport2; + DxcDllExtValidationSupport ExtSupportEmpty; + DxcDllExtValidationSupport ExtSupportBogus; // capture any existing value in the environment variable, // so that it can be restored after the test - std::wstring oldEnvVal = GetEnvVarW(L"DXC_DXIL_DLL_PATH"); + std::wstring OldEnvVal = GetEnvVarW(L"DXC_DXIL_DLL_PATH"); // 1. with no env var set, test GetDxilDllPath() and DxilDllFailedToLoad() @@ -4279,57 +4264,53 @@ TEST_F(ValidationTest, UnitTestExtValidationSupport) { SetEnvVarW(L"DXC_DXIL_DLL_PATH", L""); // empty initialization should succeed - VERIFY_SUCCEEDED(m_dllExtSupport1.Initialize()); + VERIFY_SUCCEEDED(ExtSupportEmpty.Initialize()); - VERIFY_IS_FALSE(m_dllExtSupport1.DxilDllFailedToLoad()); - VERIFY_ARE_EQUAL(m_dllExtSupport1.GetDxilDllPath(), ""); + VERIFY_IS_FALSE(ExtSupportEmpty.DxilDllFailedToLoad()); + VERIFY_ARE_EQUAL_WSTR(ExtSupportEmpty.GetDxilDllPath().c_str(), L""); // 2. Test with a bogus path in the environment variable SetEnvVarW(L"DXC_DXIL_DLL_PATH", L"bogus"); - if (!m_dllExtSupport2.IsEnabled()) { - VERIFY_SUCCEEDED(m_dllExtSupport2.Initialize()); + if (!ExtSupportBogus.IsEnabled()) { + VERIFY_SUCCEEDED(ExtSupportBogus.Initialize()); } // validate that m_dllExtSupport2 was able to capture the environment // variable's value, and that loading the bogus path was unsuccessful - std::string extPath("bogus"); - VERIFY_ARE_EQUAL(m_dllExtSupport2.GetDxilDllPath(), extPath); - VERIFY_IS_TRUE(m_dllExtSupport2.DxilDllFailedToLoad()); + VERIFY_ARE_EQUAL_WSTR(ExtSupportBogus.GetDxilDllPath().c_str(), L"bogus"); + VERIFY_IS_TRUE(ExtSupportBogus.DxilDllFailedToLoad()); // 3. Test production of class IDs CLSID_DxcCompiler, CLSID_DxcLinker, // and CLSID_DxcValidator through DxcDllExtValidationSupport. - CComPtr pCompiler; - CComPtr pLinker; - CComPtr pValidator; - CComPtr pResult; - - VERIFY_SUCCEEDED(m_dllExtSupport2.CreateInstance( - CLSID_DxcCompiler, __uuidof(IDxcCompiler), (IUnknown **)&pCompiler)); - VERIFY_SUCCEEDED(m_dllExtSupport2.CreateInstance( - CLSID_DxcLinker, __uuidof(IDxcLinker), (IUnknown **)&pLinker)); - VERIFY_SUCCEEDED(m_dllExtSupport2.CreateInstance( - CLSID_DxcValidator, __uuidof(IDxcValidator), (IUnknown **)&pValidator)); - CComPtr pMalloc; - CComPtr pCompiler2; - pLinker.Release(); - pValidator.Release(); - VERIFY_SUCCEEDED(DxcCoGetMalloc(1, &pMalloc)); - VERIFY_SUCCEEDED(m_dllExtSupport2.CreateInstance2(pMalloc, CLSID_DxcCompiler, - __uuidof(IDxcCompiler), - (IUnknown **)&pCompiler2)); - VERIFY_SUCCEEDED(m_dllExtSupport2.CreateInstance2( - pMalloc, CLSID_DxcLinker, __uuidof(IDxcLinker), (IUnknown **)&pLinker)); - VERIFY_SUCCEEDED(m_dllExtSupport2.CreateInstance2(pMalloc, CLSID_DxcValidator, - __uuidof(IDxcValidator), - (IUnknown **)&pValidator)); - - // reset the environment variable to its previous value, if it had one. - if (!oldEnvVal.empty()) { - SetEnvVarW(L"DXC_DXIL_DLL_PATH", oldEnvVal); - } else { - ClearEnvVarW(L"DXC_DXIL_DLL_PATH"); - } + CComPtr Compiler; + CComPtr Linker; + CComPtr Validator; + + VERIFY_SUCCEEDED(ExtSupportBogus.CreateInstance( + CLSID_DxcCompiler, __uuidof(IDxcCompiler), (IUnknown **)&Compiler)); + VERIFY_SUCCEEDED(ExtSupportBogus.CreateInstance( + CLSID_DxcLinker, __uuidof(IDxcLinker), (IUnknown **)&Linker)); + VERIFY_SUCCEEDED(ExtSupportBogus.CreateInstance( + CLSID_DxcValidator, __uuidof(IDxcValidator), (IUnknown **)&Validator)); + + CComPtr Malloc; + CComPtr Compiler2; + Linker.Release(); + Validator.Release(); + VERIFY_SUCCEEDED(DxcCoGetMalloc(1, &Malloc)); + VERIFY_SUCCEEDED(ExtSupportBogus.CreateInstance2(Malloc, CLSID_DxcCompiler, + __uuidof(IDxcCompiler), + (IUnknown **)&Compiler2)); + VERIFY_SUCCEEDED(ExtSupportBogus.CreateInstance2( + Malloc, CLSID_DxcLinker, __uuidof(IDxcLinker), (IUnknown **)&Linker)); + VERIFY_SUCCEEDED(ExtSupportBogus.CreateInstance2(Malloc, CLSID_DxcValidator, + __uuidof(IDxcValidator), + (IUnknown **)&Validator)); + + // reset the environment variable to its previous value, + // or the empty string if there was no previous value + SetEnvVarW(L"DXC_DXIL_DLL_PATH", OldEnvVal); } TEST_F(ValidationTest, ValidatePreviewBypassHash) { From 98b25af9e799ab810b0c42d9ca0fb93b061c7f68 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Mon, 30 Jun 2025 13:57:11 -0700 Subject: [PATCH 16/53] add includes for _wgetenv --- lib/DxcSupport/dxcapi.extval.cpp | 1 + tools/clang/unittests/HLSL/ValidationTest.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/DxcSupport/dxcapi.extval.cpp b/lib/DxcSupport/dxcapi.extval.cpp index 7f132028fa..4bd501a020 100644 --- a/lib/DxcSupport/dxcapi.extval.cpp +++ b/lib/DxcSupport/dxcapi.extval.cpp @@ -4,6 +4,7 @@ // WinIncludes must come before dxcapi.extval.h #include "dxc/Support/Unicode.h" // for wstring conversions like WideToUtf8String #include "dxc/Support/dxcapi.extval.h" +#include // for _wgetenv HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR dllName, LPCSTR fnName) { diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp index f7aa93e225..ca88d4e865 100644 --- a/tools/clang/unittests/HLSL/ValidationTest.cpp +++ b/tools/clang/unittests/HLSL/ValidationTest.cpp @@ -26,6 +26,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Support/Regex.h" #include // for setenv(), getenv(), unsetenv() +#include // for _wgetenv #ifdef _WIN32 #include From c274e5b4f3af08841d28310536165f4de7d8428f Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Mon, 30 Jun 2025 15:21:59 -0700 Subject: [PATCH 17/53] remove wstring for simplicity --- include/dxc/Support/dxcapi.extval.h | 4 ++-- lib/DxcSupport/dxcapi.extval.cpp | 16 +++++----------- tools/clang/unittests/HLSL/ValidationTest.cpp | 4 ++-- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/include/dxc/Support/dxcapi.extval.h b/include/dxc/Support/dxcapi.extval.h index e205406333..a8a8a36e9a 100644 --- a/include/dxc/Support/dxcapi.extval.h +++ b/include/dxc/Support/dxcapi.extval.h @@ -8,14 +8,14 @@ class DxcDllExtValidationSupport : public dxc::DxcDllSupport { protected: dxc::DxcDllSupport DxilSupport; - std::wstring DxilDllPath; + std::string DxilDllPath; // override DxcDllSupport's implementation of InitializeInternal, // adding the environment variable value check for a path to a dxil.dll HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) override; public: - std::wstring GetDxilDllPath() { return DxilDllPath; } + std::string GetDxilDllPath() { return DxilDllPath; } bool DxilDllFailedToLoad() { return !DxilDllPath.empty() && !DxilSupport.IsEnabled(); } diff --git a/lib/DxcSupport/dxcapi.extval.cpp b/lib/DxcSupport/dxcapi.extval.cpp index 4bd501a020..e40a45e02e 100644 --- a/lib/DxcSupport/dxcapi.extval.cpp +++ b/lib/DxcSupport/dxcapi.extval.cpp @@ -2,9 +2,7 @@ #include // for hresult handling with DXC_FAILED #include // C++17 and later // WinIncludes must come before dxcapi.extval.h -#include "dxc/Support/Unicode.h" // for wstring conversions like WideToUtf8String #include "dxc/Support/dxcapi.extval.h" -#include // for _wgetenv HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR dllName, LPCSTR fnName) { @@ -16,17 +14,14 @@ HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR dllName, } // now handle external dxil.dll - const wchar_t *EnvVarValue = _wgetenv(L"DXC_DXIL_DLL_PATH"); - if (!EnvVarValue || std::wstring(EnvVarValue).empty()) { + const char *EnvVarVal = std::getenv("DXC_DXIL_DLL_PATH"); + if (!EnvVarVal || std::string(EnvVarVal).empty()) { return S_OK; } - std::wstring DllPathWStr(EnvVarValue); - std::string DllPathStr; - Unicode::WideToUTF8String(DllPathWStr.data(), &DllPathStr); - - DxilDllPath = DllPathWStr; - std::filesystem::path DllPath(DllPathWStr); + std::string DllPathStr(EnvVarVal); + DxilDllPath = DllPathStr; + std::filesystem::path DllPath(DllPathStr); // Check if path is absolute and exists if (!DllPath.is_absolute() || !std::filesystem::exists(DllPath)) { @@ -36,7 +31,6 @@ HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR dllName, // to see if dxil.dll is successfully loaded. // the CheckDxilDLLLoaded function can determine whether there were any // problems loading dxil.dll or not - DxilSupport.InitializeForDll(DllPathStr.data(), fnName); return S_OK; diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp index ca88d4e865..7c79719cac 100644 --- a/tools/clang/unittests/HLSL/ValidationTest.cpp +++ b/tools/clang/unittests/HLSL/ValidationTest.cpp @@ -4268,7 +4268,7 @@ TEST_F(ValidationTest, UnitTestExtValidationSupport) { VERIFY_SUCCEEDED(ExtSupportEmpty.Initialize()); VERIFY_IS_FALSE(ExtSupportEmpty.DxilDllFailedToLoad()); - VERIFY_ARE_EQUAL_WSTR(ExtSupportEmpty.GetDxilDllPath().c_str(), L""); + VERIFY_ARE_EQUAL_STR(ExtSupportEmpty.GetDxilDllPath().c_str(), ""); // 2. Test with a bogus path in the environment variable SetEnvVarW(L"DXC_DXIL_DLL_PATH", L"bogus"); @@ -4279,7 +4279,7 @@ TEST_F(ValidationTest, UnitTestExtValidationSupport) { // validate that m_dllExtSupport2 was able to capture the environment // variable's value, and that loading the bogus path was unsuccessful - VERIFY_ARE_EQUAL_WSTR(ExtSupportBogus.GetDxilDllPath().c_str(), L"bogus"); + VERIFY_ARE_EQUAL_STR(ExtSupportBogus.GetDxilDllPath().c_str(), "bogus"); VERIFY_IS_TRUE(ExtSupportBogus.DxilDllFailedToLoad()); // 3. Test production of class IDs CLSID_DxcCompiler, CLSID_DxcLinker, From b46def4d14ea060dc06c1604b0cd80806370098c Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Mon, 30 Jun 2025 16:30:18 -0700 Subject: [PATCH 18/53] fix undeclared variables in non windows case, and pointer lifetime bug --- tools/clang/unittests/HLSL/ValidationTest.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp index 7c79719cac..64df21f919 100644 --- a/tools/clang/unittests/HLSL/ValidationTest.cpp +++ b/tools/clang/unittests/HLSL/ValidationTest.cpp @@ -4217,11 +4217,11 @@ std::wstring GetEnvVarW(const std::wstring &VarName) { if (const wchar_t *Result = _wgetenv(VarName.c_str())) return std::wstring(Result); #else - std::string NameUtf8; - WideToUTF8String(Name.c_str, &NameUtf8); - if (const char *Result = std::getenv(NameUtf8.c_str())) { + std::string VarNameUtf8; + WideToUTF8String(VarName.c_str, &VarNameUtf8); + if (const char *Result = std::getenv(VarNameUtf8.c_str())) { std::wstring ResultWide; - Unicode::UTF8ToWideString(Result.c_str(), &ResultWide); + Unicode::UTF8ToWideString(Result, &ResultWide); return std::wstring(ResultWide); } #endif @@ -4268,7 +4268,8 @@ TEST_F(ValidationTest, UnitTestExtValidationSupport) { VERIFY_SUCCEEDED(ExtSupportEmpty.Initialize()); VERIFY_IS_FALSE(ExtSupportEmpty.DxilDllFailedToLoad()); - VERIFY_ARE_EQUAL_STR(ExtSupportEmpty.GetDxilDllPath().c_str(), ""); + std::string EmptyPath = ExtSupportBogus.GetDxilDllPath(); + VERIFY_ARE_EQUAL_STR(EmptyPath.c_str(), ""); // 2. Test with a bogus path in the environment variable SetEnvVarW(L"DXC_DXIL_DLL_PATH", L"bogus"); @@ -4279,7 +4280,8 @@ TEST_F(ValidationTest, UnitTestExtValidationSupport) { // validate that m_dllExtSupport2 was able to capture the environment // variable's value, and that loading the bogus path was unsuccessful - VERIFY_ARE_EQUAL_STR(ExtSupportBogus.GetDxilDllPath().c_str(), "bogus"); + std::string BogusPath = ExtSupportBogus.GetDxilDllPath(); + VERIFY_ARE_EQUAL_STR(BogusPath.c_str(), "bogus"); VERIFY_IS_TRUE(ExtSupportBogus.DxilDllFailedToLoad()); // 3. Test production of class IDs CLSID_DxcCompiler, CLSID_DxcLinker, From b76fab2abdac54c998fc1cf8468c61a98a012f18 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Mon, 30 Jun 2025 17:26:49 -0700 Subject: [PATCH 19/53] adjust for build errors --- tools/clang/unittests/HLSL/ValidationTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp index 64df21f919..f6d73031bd 100644 --- a/tools/clang/unittests/HLSL/ValidationTest.cpp +++ b/tools/clang/unittests/HLSL/ValidationTest.cpp @@ -4218,7 +4218,7 @@ std::wstring GetEnvVarW(const std::wstring &VarName) { return std::wstring(Result); #else std::string VarNameUtf8; - WideToUTF8String(VarName.c_str, &VarNameUtf8); + Unicode::WideToUTF8String(VarName.c_str(), &VarNameUtf8); if (const char *Result = std::getenv(VarNameUtf8.c_str())) { std::wstring ResultWide; Unicode::UTF8ToWideString(Result, &ResultWide); From 89dcc4a0ac83b0364505041e67889bb9f2d3baea Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Tue, 1 Jul 2025 13:22:20 -0700 Subject: [PATCH 20/53] address final forgotten comments --- lib/DxcSupport/dxcapi.extval.cpp | 16 ++-------------- tools/clang/unittests/HLSL/ValidationTest.cpp | 2 +- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/lib/DxcSupport/dxcapi.extval.cpp b/lib/DxcSupport/dxcapi.extval.cpp index e40a45e02e..4d1ad44bf5 100644 --- a/lib/DxcSupport/dxcapi.extval.cpp +++ b/lib/DxcSupport/dxcapi.extval.cpp @@ -41,12 +41,7 @@ HRESULT DxcDllExtValidationSupport::CreateInstance(REFCLSID clsid, REFIID riid, if (DxilSupport.IsEnabled() && clsid == CLSID_DxcValidator) return DxilSupport.CreateInstance(clsid, riid, pResult); - if (pResult == nullptr) - return E_POINTER; - if (m_dll == nullptr) - return E_FAIL; - HRESULT hr = m_createFn(clsid, riid, (LPVOID *)pResult); - return hr; + return DxcDllSupport::CreateInstance(clsid, riid, pResult); } HRESULT DxcDllExtValidationSupport::CreateInstance2(IMalloc *pMalloc, @@ -55,12 +50,5 @@ HRESULT DxcDllExtValidationSupport::CreateInstance2(IMalloc *pMalloc, if (DxilSupport.IsEnabled() && clsid == CLSID_DxcValidator) return DxilSupport.CreateInstance2(pMalloc, clsid, riid, pResult); - if (pResult == nullptr) - return E_POINTER; - if (m_dll == nullptr) - return E_FAIL; - if (m_createFn2 == nullptr) - return E_FAIL; - HRESULT hr = m_createFn2(pMalloc, clsid, riid, (LPVOID *)pResult); - return hr; + return DxcDllSupport::CreateInstance2(pMalloc, clsid, riid, pResult); } diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp index f6d73031bd..d167f853ce 100644 --- a/tools/clang/unittests/HLSL/ValidationTest.cpp +++ b/tools/clang/unittests/HLSL/ValidationTest.cpp @@ -36,7 +36,7 @@ #include "dxc/DXIL/DxilShaderModel.h" #include "dxc/Support/dxcapi.extval.h" -#include "dxc/Test/DxcTestUtils.h" // includes dxcapi.use.h +#include "dxc/Test/DxcTestUtils.h" #include "dxc/Test/HlslTestUtils.h" using namespace std; From acbf68a4b3f50c25f6ebc809dcd8cd8b4884a711 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Wed, 2 Jul 2025 11:15:21 -0700 Subject: [PATCH 21/53] try removing unicode from cmakelists --- tools/clang/unittests/HLSL/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/clang/unittests/HLSL/CMakeLists.txt b/tools/clang/unittests/HLSL/CMakeLists.txt index c3f618773e..eaba5049b2 100644 --- a/tools/clang/unittests/HLSL/CMakeLists.txt +++ b/tools/clang/unittests/HLSL/CMakeLists.txt @@ -48,7 +48,6 @@ add_clang_library(ClangHLSLTests SHARED PixTestUtils.cpp RewriterTest.cpp SystemValueTest.cpp - ${CMAKE_SOURCE_DIR}/lib/DxcSupport/Unicode.cpp ValidationTest.cpp VerifierTest.cpp ) @@ -79,7 +78,6 @@ add_clang_unittest(ClangHLSLTests PixTestUtils.cpp SystemValueTest.cpp TestMain.cpp - ${CMAKE_SOURCE_DIR}/lib/DxcSupport/Unicode.cpp ValidationTest.cpp VerifierTest.cpp ) From f2890f584d0e5538d80ab98881d5206e5b51f285 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Thu, 3 Jul 2025 12:46:23 -0700 Subject: [PATCH 22/53] update comment Justin pointed out was outdated --- include/dxc/Support/dxcapi.extval.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/dxc/Support/dxcapi.extval.h b/include/dxc/Support/dxcapi.extval.h index a8a8a36e9a..05ca83e413 100644 --- a/include/dxc/Support/dxcapi.extval.h +++ b/include/dxc/Support/dxcapi.extval.h @@ -3,7 +3,7 @@ class DxcDllExtValidationSupport : public dxc::DxcDllSupport { // DxcDllExtValidationSupport manages the - // lifetime of dxcompiler.dll, while the member, m_DxilSupport, + // lifetime of dxcompiler.dll, while the member, DxilSupport, // manages the lifetime of dxil.dll protected: dxc::DxcDllSupport DxilSupport; From eb1e96fc5b174b2aed4d225859890e0a895ecf77 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Mon, 7 Jul 2025 14:07:02 -0700 Subject: [PATCH 23/53] remove Linux definitions from windows only testing, address ambiguity in comment --- tools/clang/unittests/HLSL/ValidationTest.cpp | 26 ++++--------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp index d167f853ce..12977c418e 100644 --- a/tools/clang/unittests/HLSL/ValidationTest.cpp +++ b/tools/clang/unittests/HLSL/ValidationTest.cpp @@ -4213,39 +4213,22 @@ TEST_F(ValidationTest, ValidateWithHash) { } std::wstring GetEnvVarW(const std::wstring &VarName) { -#ifdef _WIN32 if (const wchar_t *Result = _wgetenv(VarName.c_str())) return std::wstring(Result); -#else - std::string VarNameUtf8; - Unicode::WideToUTF8String(VarName.c_str(), &VarNameUtf8); - if (const char *Result = std::getenv(VarNameUtf8.c_str())) { - std::wstring ResultWide; - Unicode::UTF8ToWideString(Result, &ResultWide); - return std::wstring(ResultWide); - } -#endif return std::wstring(); } void SetEnvVarW(const std::wstring &VarName, const std::wstring &VarValue) { -#ifdef _WIN32 _wputenv_s(VarName.c_str(), VarValue.c_str()); -#else - std::string VarNameUtf8; - std::string VarValueUtf8; - Unicode::WideToUTF8String(VarName.c_str(), &VarNameUtf8); - Unicode::WideToUTF8String(VarValue.c_str(), &VarValueUtf8); - setenv(VarNameUtf8.c_str(), VarValueUtf8.c_str(), 1); -#endif } // For now, 3 things are tested: // 1. The environment variable is not set. GetDxilDllPath() is empty and // DxilDllFailedToLoad() returns false -// 2. Given a bogus path in the environment variable, GetDxilDllPath() -// retrieves the path but fails to load it as a dll, and returns true -// for DxilDllFailedToLoad() +// 2. Given a bogus path in the environment variable, and an initialized +// DxcDllExtValidationSupport object, GetDxilDllPath() +// retrieves the bogus path despite DxcDllExtValidationSupport failing to load +// it as a dll, and DxilDllFailedToLoad() returns true. // 3. CLSID_DxcCompiler, CLSID_DxcLinker, CLSID_DxcValidator // may be created through DxcDllExtValidationSupport. // This is all to simply test that the new class, DxcDllExtValidationSupport, @@ -4301,6 +4284,7 @@ TEST_F(ValidationTest, UnitTestExtValidationSupport) { CComPtr Compiler2; Linker.Release(); Validator.Release(); + Compiler.Release(); VERIFY_SUCCEEDED(DxcCoGetMalloc(1, &Malloc)); VERIFY_SUCCEEDED(ExtSupportBogus.CreateInstance2(Malloc, CLSID_DxcCompiler, __uuidof(IDxcCompiler), From 36c33a25e8728694a6d879d3e86b3c4e14d87886 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Mon, 7 Jul 2025 15:03:23 -0700 Subject: [PATCH 24/53] do not inherit from DxcDllSupport --- include/dxc/Support/dxcapi.extval.h | 41 +++++++++++-------- include/dxc/Support/dxcapi.use.h | 17 ++++---- lib/DxcSupport/dxcapi.extval.cpp | 40 ++++++++++-------- tools/clang/unittests/HLSL/ValidationTest.cpp | 4 +- 4 files changed, 56 insertions(+), 46 deletions(-) diff --git a/include/dxc/Support/dxcapi.extval.h b/include/dxc/Support/dxcapi.extval.h index 05ca83e413..9ac06c3a67 100644 --- a/include/dxc/Support/dxcapi.extval.h +++ b/include/dxc/Support/dxcapi.extval.h @@ -1,38 +1,43 @@ #include "dxc/Support/dxcapi.use.h" #include -class DxcDllExtValidationSupport : public dxc::DxcDllSupport { - // DxcDllExtValidationSupport manages the - // lifetime of dxcompiler.dll, while the member, DxilSupport, +namespace dxc { +class DxcDllExtValidationSupport { + // DxcompilerSupport manages the + // lifetime of dxcompiler.dll, while DxilExtValSupport // manages the lifetime of dxil.dll protected: - dxc::DxcDllSupport DxilSupport; + dxc::DxcDllSupport DxcompilerSupport; + dxc::DxcDllSupport DxilExtValSupport; std::string DxilDllPath; - // override DxcDllSupport's implementation of InitializeInternal, - // adding the environment variable value check for a path to a dxil.dll - HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) override; - public: std::string GetDxilDllPath() { return DxilDllPath; } bool DxilDllFailedToLoad() { - return !DxilDllPath.empty() && !DxilSupport.IsEnabled(); + return !DxilDllPath.empty() && !DxilExtValSupport.IsEnabled(); } - void Cleanup() override { - DxilSupport.Cleanup(); - DxcDllSupport::Cleanup(); + void Cleanup() { + DxilExtValSupport.Cleanup(); + DxcompilerSupport.Cleanup(); } - HMODULE Detach() override { + HMODULE Detach() { // Can't Detach and return a handle for DxilSupport. Cleanup() instead. - DxilSupport.Cleanup(); - return DxcDllSupport::Detach(); + DxilExtValSupport.Cleanup(); + return DxcompilerSupport.Detach(); } - HRESULT CreateInstance(REFCLSID clsid, REFIID riid, - IUnknown **pResult) override; + HRESULT CreateInstance(REFCLSID clsid, REFIID riid, IUnknown **pResult); HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, - IUnknown **pResult) override; + IUnknown **pResult); + + HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName); + HRESULT Initialize() { + return InitializeInternal(kDxCompilerLib, "DxcCreateInstance"); + } + + bool IsEnabled() const { return DxcompilerSupport.m_dll != nullptr; } }; +} // namespace dxc \ No newline at end of file diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index 1699a0c15f..46f742dfd1 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -21,12 +21,14 @@ extern const char *kDxilLib; // Helper class to dynamically load the dxcompiler or a compatible libraries. class DxcDllSupport { + friend class DxcDllExtValidationSupport; + protected: HMODULE m_dll; DxcCreateInstanceProc m_createFn; DxcCreateInstance2Proc m_createFn2; - virtual HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) { + HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) { if (m_dll != nullptr) return S_OK; @@ -85,7 +87,7 @@ class DxcDllSupport { other.m_createFn2 = nullptr; } - virtual ~DxcDllSupport() { Cleanup(); } + ~DxcDllSupport() { Cleanup(); } HRESULT Initialize() { return InitializeInternal(kDxCompilerLib, "DxcCreateInstance"); @@ -100,8 +102,7 @@ class DxcDllSupport { return CreateInstance(clsid, __uuidof(TInterface), (IUnknown **)pResult); } - virtual HRESULT CreateInstance(REFCLSID clsid, REFIID riid, - IUnknown **pResult) { + HRESULT CreateInstance(REFCLSID clsid, REFIID riid, IUnknown **pResult) { if (pResult == nullptr) return E_POINTER; if (m_dll == nullptr) @@ -117,8 +118,8 @@ class DxcDllSupport { (IUnknown **)pResult); } - virtual HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, - IUnknown **pResult) { + HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, + IUnknown **pResult) { if (pResult == nullptr) return E_POINTER; if (m_dll == nullptr) @@ -142,7 +143,7 @@ class DxcDllSupport { return true; } - virtual void Cleanup() { + void Cleanup() { if (m_dll != nullptr) { m_createFn = nullptr; m_createFn2 = nullptr; @@ -155,7 +156,7 @@ class DxcDllSupport { } } - virtual HMODULE Detach() { + HMODULE Detach() { HMODULE hModule = m_dll; m_dll = nullptr; return hModule; diff --git a/lib/DxcSupport/dxcapi.extval.cpp b/lib/DxcSupport/dxcapi.extval.cpp index 4d1ad44bf5..168bbca46c 100644 --- a/lib/DxcSupport/dxcapi.extval.cpp +++ b/lib/DxcSupport/dxcapi.extval.cpp @@ -4,10 +4,29 @@ // WinIncludes must come before dxcapi.extval.h #include "dxc/Support/dxcapi.extval.h" +namespace dxc { + +HRESULT DxcDllExtValidationSupport::CreateInstance(REFCLSID clsid, REFIID riid, + IUnknown **pResult) { + if (DxilExtValSupport.IsEnabled() && clsid == CLSID_DxcValidator) + return DxilExtValSupport.CreateInstance(clsid, riid, pResult); + + return DxcompilerSupport.CreateInstance(clsid, riid, pResult); +} + +HRESULT DxcDllExtValidationSupport::CreateInstance2(IMalloc *pMalloc, + REFCLSID clsid, REFIID riid, + IUnknown **pResult) { + if (DxilExtValSupport.IsEnabled() && clsid == CLSID_DxcValidator) + return DxilExtValSupport.CreateInstance2(pMalloc, clsid, riid, pResult); + + return DxcompilerSupport.CreateInstance2(pMalloc, clsid, riid, pResult); +} + HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR dllName, LPCSTR fnName) { // Load dxcompiler.dll - HRESULT Result = DxcDllSupport::InitializeInternal(dllName, fnName); + HRESULT Result = DxcompilerSupport.InitializeInternal(dllName, fnName); // if dxcompiler.dll fails to load, return the failed HRESULT if (DXC_FAILED(Result)) { return Result; @@ -31,24 +50,9 @@ HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR dllName, // to see if dxil.dll is successfully loaded. // the CheckDxilDLLLoaded function can determine whether there were any // problems loading dxil.dll or not - DxilSupport.InitializeForDll(DllPathStr.data(), fnName); + DxilExtValSupport.InitializeForDll(DllPathStr.data(), fnName); return S_OK; } -HRESULT DxcDllExtValidationSupport::CreateInstance(REFCLSID clsid, REFIID riid, - IUnknown **pResult) { - if (DxilSupport.IsEnabled() && clsid == CLSID_DxcValidator) - return DxilSupport.CreateInstance(clsid, riid, pResult); - - return DxcDllSupport::CreateInstance(clsid, riid, pResult); -} - -HRESULT DxcDllExtValidationSupport::CreateInstance2(IMalloc *pMalloc, - REFCLSID clsid, REFIID riid, - IUnknown **pResult) { - if (DxilSupport.IsEnabled() && clsid == CLSID_DxcValidator) - return DxilSupport.CreateInstance2(pMalloc, clsid, riid, pResult); - - return DxcDllSupport::CreateInstance2(pMalloc, clsid, riid, pResult); -} +} // namespace dxc \ No newline at end of file diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp index 12977c418e..ee3e6c1c9d 100644 --- a/tools/clang/unittests/HLSL/ValidationTest.cpp +++ b/tools/clang/unittests/HLSL/ValidationTest.cpp @@ -4235,8 +4235,8 @@ void SetEnvVarW(const std::wstring &VarName, const std::wstring &VarValue) { // works as intended. TEST_F(ValidationTest, UnitTestExtValidationSupport) { - DxcDllExtValidationSupport ExtSupportEmpty; - DxcDllExtValidationSupport ExtSupportBogus; + dxc::DxcDllExtValidationSupport ExtSupportEmpty; + dxc::DxcDllExtValidationSupport ExtSupportBogus; // capture any existing value in the environment variable, // so that it can be restored after the test From 65770462c6ffe32997fb2fb9e9703d2188af9936 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Mon, 7 Jul 2025 15:32:37 -0700 Subject: [PATCH 25/53] add win32 preprocessor gate to allow non windows envs to build --- tools/clang/unittests/HLSL/ValidationTest.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp index ee3e6c1c9d..0446d1cf26 100644 --- a/tools/clang/unittests/HLSL/ValidationTest.cpp +++ b/tools/clang/unittests/HLSL/ValidationTest.cpp @@ -4213,13 +4213,17 @@ TEST_F(ValidationTest, ValidateWithHash) { } std::wstring GetEnvVarW(const std::wstring &VarName) { +#ifdef _WIN32 if (const wchar_t *Result = _wgetenv(VarName.c_str())) return std::wstring(Result); +#endif return std::wstring(); } void SetEnvVarW(const std::wstring &VarName, const std::wstring &VarValue) { +#ifdef _WIN32 _wputenv_s(VarName.c_str(), VarValue.c_str()); +#endif } // For now, 3 things are tested: From 80b50a626ab2da304fce85f10782fe3facaa813c Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Mon, 7 Jul 2025 16:06:00 -0700 Subject: [PATCH 26/53] remove test from non-windows since it depends on wide strings --- tools/clang/unittests/HLSL/ValidationTest.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp index 0446d1cf26..84c564ce05 100644 --- a/tools/clang/unittests/HLSL/ValidationTest.cpp +++ b/tools/clang/unittests/HLSL/ValidationTest.cpp @@ -4212,18 +4212,15 @@ TEST_F(ValidationTest, ValidateWithHash) { VERIFY_ARE_EQUAL(memcmp(Result, pHeader->Hash.Digest, sizeof(Result)), 0); } -std::wstring GetEnvVarW(const std::wstring &VarName) { #ifdef _WIN32 +std::wstring GetEnvVarW(const std::wstring &VarName) { if (const wchar_t *Result = _wgetenv(VarName.c_str())) return std::wstring(Result); -#endif return std::wstring(); } void SetEnvVarW(const std::wstring &VarName, const std::wstring &VarValue) { -#ifdef _WIN32 _wputenv_s(VarName.c_str(), VarValue.c_str()); -#endif } // For now, 3 things are tested: @@ -4303,6 +4300,7 @@ TEST_F(ValidationTest, UnitTestExtValidationSupport) { // or the empty string if there was no previous value SetEnvVarW(L"DXC_DXIL_DLL_PATH", OldEnvVal); } +#endif TEST_F(ValidationTest, ValidatePreviewBypassHash) { if (m_ver.SkipDxilVersion(1, ShaderModel::kHighestMinor)) From bfc508fe445d66a7bb1d3d41970c4d1eb0a84955 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Tue, 8 Jul 2025 09:19:54 -0700 Subject: [PATCH 27/53] remove friend, remove protected: --- include/dxc/Support/dxcapi.extval.h | 5 ++--- include/dxc/Support/dxcapi.use.h | 2 -- lib/DxcSupport/dxcapi.extval.cpp | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/include/dxc/Support/dxcapi.extval.h b/include/dxc/Support/dxcapi.extval.h index 9ac06c3a67..93a8973532 100644 --- a/include/dxc/Support/dxcapi.extval.h +++ b/include/dxc/Support/dxcapi.extval.h @@ -6,11 +6,11 @@ class DxcDllExtValidationSupport { // DxcompilerSupport manages the // lifetime of dxcompiler.dll, while DxilExtValSupport // manages the lifetime of dxil.dll -protected: dxc::DxcDllSupport DxcompilerSupport; dxc::DxcDllSupport DxilExtValSupport; std::string DxilDllPath; + HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName); public: std::string GetDxilDllPath() { return DxilDllPath; } @@ -33,11 +33,10 @@ class DxcDllExtValidationSupport { HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, IUnknown **pResult); - HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName); HRESULT Initialize() { return InitializeInternal(kDxCompilerLib, "DxcCreateInstance"); } - bool IsEnabled() const { return DxcompilerSupport.m_dll != nullptr; } + bool IsEnabled() const { return DxcompilerSupport.IsEnabled(); } }; } // namespace dxc \ No newline at end of file diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index 46f742dfd1..d91fb7d76f 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -21,9 +21,7 @@ extern const char *kDxilLib; // Helper class to dynamically load the dxcompiler or a compatible libraries. class DxcDllSupport { - friend class DxcDllExtValidationSupport; -protected: HMODULE m_dll; DxcCreateInstanceProc m_createFn; DxcCreateInstance2Proc m_createFn2; diff --git a/lib/DxcSupport/dxcapi.extval.cpp b/lib/DxcSupport/dxcapi.extval.cpp index 168bbca46c..38f0f34eb6 100644 --- a/lib/DxcSupport/dxcapi.extval.cpp +++ b/lib/DxcSupport/dxcapi.extval.cpp @@ -26,7 +26,7 @@ HRESULT DxcDllExtValidationSupport::CreateInstance2(IMalloc *pMalloc, HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR dllName, LPCSTR fnName) { // Load dxcompiler.dll - HRESULT Result = DxcompilerSupport.InitializeInternal(dllName, fnName); + HRESULT Result = DxcompilerSupport.InitializeForDll(dllName, fnName); // if dxcompiler.dll fails to load, return the failed HRESULT if (DXC_FAILED(Result)) { return Result; From a144ca11e52ba6456ac11067dbe5e0116129ddc7 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Fri, 11 Jul 2025 16:58:29 -0700 Subject: [PATCH 28/53] address Damyan final concerns --- include/dxc/Support/dxcapi.extval.h | 6 ++---- lib/DxcSupport/dxcapi.extval.cpp | 17 +++++++---------- tools/clang/unittests/HLSL/ValidationTest.cpp | 6 +++--- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/include/dxc/Support/dxcapi.extval.h b/include/dxc/Support/dxcapi.extval.h index 93a8973532..f0993c6898 100644 --- a/include/dxc/Support/dxcapi.extval.h +++ b/include/dxc/Support/dxcapi.extval.h @@ -10,7 +10,7 @@ class DxcDllExtValidationSupport { dxc::DxcDllSupport DxilExtValSupport; std::string DxilDllPath; - HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName); + HRESULT InitializeInternal(LPCSTR fnName); public: std::string GetDxilDllPath() { return DxilDllPath; } @@ -33,9 +33,7 @@ class DxcDllExtValidationSupport { HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, IUnknown **pResult); - HRESULT Initialize() { - return InitializeInternal(kDxCompilerLib, "DxcCreateInstance"); - } + HRESULT Initialize() { return InitializeInternal("DxcCreateInstance"); } bool IsEnabled() const { return DxcompilerSupport.IsEnabled(); } }; diff --git a/lib/DxcSupport/dxcapi.extval.cpp b/lib/DxcSupport/dxcapi.extval.cpp index 38f0f34eb6..458cc0370d 100644 --- a/lib/DxcSupport/dxcapi.extval.cpp +++ b/lib/DxcSupport/dxcapi.extval.cpp @@ -23,10 +23,9 @@ HRESULT DxcDllExtValidationSupport::CreateInstance2(IMalloc *pMalloc, return DxcompilerSupport.CreateInstance2(pMalloc, clsid, riid, pResult); } -HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR dllName, - LPCSTR fnName) { +HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR fnName) { // Load dxcompiler.dll - HRESULT Result = DxcompilerSupport.InitializeForDll(dllName, fnName); + HRESULT Result = DxcompilerSupport.InitializeForDll(kDxCompilerLib, fnName); // if dxcompiler.dll fails to load, return the failed HRESULT if (DXC_FAILED(Result)) { return Result; @@ -38,21 +37,19 @@ HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR dllName, return S_OK; } - std::string DllPathStr(EnvVarVal); - DxilDllPath = DllPathStr; - std::filesystem::path DllPath(DllPathStr); + DxilDllPath = std::string(EnvVarVal); + std::filesystem::path DllPath(DxilDllPath); // Check if path is absolute and exists if (!DllPath.is_absolute() || !std::filesystem::exists(DllPath)) { - return S_OK; + return ERROR_DLL_INIT_FAILED; } // code that calls this function is responsible for checking // to see if dxil.dll is successfully loaded. - // the CheckDxilDLLLoaded function can determine whether there were any + // the DxilDllFailedToLoad function can determine whether there were any // problems loading dxil.dll or not - DxilExtValSupport.InitializeForDll(DllPathStr.data(), fnName); - return S_OK; + return DxilExtValSupport.InitializeForDll(DxilDllPath.c_str(), fnName); } } // namespace dxc \ No newline at end of file diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp index 84c564ce05..e205025228 100644 --- a/tools/clang/unittests/HLSL/ValidationTest.cpp +++ b/tools/clang/unittests/HLSL/ValidationTest.cpp @@ -25,7 +25,6 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Regex.h" -#include // for setenv(), getenv(), unsetenv() #include // for _wgetenv #ifdef _WIN32 @@ -4281,11 +4280,12 @@ TEST_F(ValidationTest, UnitTestExtValidationSupport) { VERIFY_SUCCEEDED(ExtSupportBogus.CreateInstance( CLSID_DxcValidator, __uuidof(IDxcValidator), (IUnknown **)&Validator)); - CComPtr Malloc; - CComPtr Compiler2; Linker.Release(); Validator.Release(); Compiler.Release(); + + CComPtr Malloc; + CComPtr Compiler2; VERIFY_SUCCEEDED(DxcCoGetMalloc(1, &Malloc)); VERIFY_SUCCEEDED(ExtSupportBogus.CreateInstance2(Malloc, CLSID_DxcCompiler, __uuidof(IDxcCompiler), From bd01fa51ca2ff799efa13eb73429f832c9201460 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Fri, 11 Jul 2025 17:51:31 -0700 Subject: [PATCH 29/53] try another way to emit an hresult --- lib/DxcSupport/dxcapi.extval.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/DxcSupport/dxcapi.extval.cpp b/lib/DxcSupport/dxcapi.extval.cpp index 458cc0370d..4b913ed78a 100644 --- a/lib/DxcSupport/dxcapi.extval.cpp +++ b/lib/DxcSupport/dxcapi.extval.cpp @@ -42,7 +42,8 @@ HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR fnName) { // Check if path is absolute and exists if (!DllPath.is_absolute() || !std::filesystem::exists(DllPath)) { - return ERROR_DLL_INIT_FAILED; + // ERROR_DLL_INIT_FAILED + return (HRESULT)1114L; } // code that calls this function is responsible for checking // to see if dxil.dll is successfully loaded. From 647c946fafd4d5919f9d6232ca94cca92c0ad33f Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Mon, 14 Jul 2025 11:09:42 -0700 Subject: [PATCH 30/53] try E_INVALIDARG --- lib/DxcSupport/dxcapi.extval.cpp | 7 +------ tools/clang/unittests/HLSL/ValidationTest.cpp | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/DxcSupport/dxcapi.extval.cpp b/lib/DxcSupport/dxcapi.extval.cpp index 4b913ed78a..d8029a25af 100644 --- a/lib/DxcSupport/dxcapi.extval.cpp +++ b/lib/DxcSupport/dxcapi.extval.cpp @@ -42,13 +42,8 @@ HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR fnName) { // Check if path is absolute and exists if (!DllPath.is_absolute() || !std::filesystem::exists(DllPath)) { - // ERROR_DLL_INIT_FAILED - return (HRESULT)1114L; + return E_INVALIDARG; } - // code that calls this function is responsible for checking - // to see if dxil.dll is successfully loaded. - // the DxilDllFailedToLoad function can determine whether there were any - // problems loading dxil.dll or not return DxilExtValSupport.InitializeForDll(DxilDllPath.c_str(), fnName); } diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp index e205025228..571184b0e9 100644 --- a/tools/clang/unittests/HLSL/ValidationTest.cpp +++ b/tools/clang/unittests/HLSL/ValidationTest.cpp @@ -4258,7 +4258,7 @@ TEST_F(ValidationTest, UnitTestExtValidationSupport) { SetEnvVarW(L"DXC_DXIL_DLL_PATH", L"bogus"); if (!ExtSupportBogus.IsEnabled()) { - VERIFY_SUCCEEDED(ExtSupportBogus.Initialize()); + VERIFY_FAILED(ExtSupportBogus.Initialize()); } // validate that m_dllExtSupport2 was able to capture the environment From a29f6eef2edbeef695d0a66906f673fbd432e5f6 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Fri, 18 Jul 2025 14:58:20 -0700 Subject: [PATCH 31/53] use an interface --- include/dxc/Support/dxcapi.extval.h | 38 +++++++++++------ include/dxc/Support/dxcapi.use.h | 63 +++++++++++++++++++++++------ lib/DxcSupport/dxcapi.extval.cpp | 16 ++++++-- 3 files changed, 88 insertions(+), 29 deletions(-) diff --git a/include/dxc/Support/dxcapi.extval.h b/include/dxc/Support/dxcapi.extval.h index f0993c6898..e8068b1ce8 100644 --- a/include/dxc/Support/dxcapi.extval.h +++ b/include/dxc/Support/dxcapi.extval.h @@ -2,13 +2,16 @@ #include namespace dxc { -class DxcDllExtValidationSupport { - // DxcompilerSupport manages the +class DxcDllExtValidationSupport : public IDllSupport { + // DxCompilerSupport manages the // lifetime of dxcompiler.dll, while DxilExtValSupport // manages the lifetime of dxil.dll - dxc::DxcDllSupport DxcompilerSupport; + dxc::DxcDllSupport DxCompilerSupport; dxc::DxcDllSupport DxilExtValSupport; + DxcCreateInstanceProc m_createFn; + DxcCreateInstance2Proc m_createFn2; + std::string DxilDllPath; HRESULT InitializeInternal(LPCSTR fnName); @@ -18,23 +21,32 @@ class DxcDllExtValidationSupport { return !DxilDllPath.empty() && !DxilExtValSupport.IsEnabled(); } + HRESULT CreateInstance(REFCLSID clsid, REFIID riid, IUnknown **pResult); + HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, + IUnknown **pResult); + + HRESULT Initialize() { return InitializeInternal("DxcCreateInstance"); } + HRESULT InitializeForDll(LPCSTR dll, LPCSTR entryPoint) { + return InitializeInternal(dll); + } + + bool HasCreateWithMalloc() const { return m_createFn2 != nullptr; } + + bool IsEnabled() const { return DxCompilerSupport.IsEnabled(); } + + bool DxcDllExtValidationSupport::GetCreateInstanceProcs( + DxcCreateInstanceProc *pCreateFn, + DxcCreateInstance2Proc *pCreateFn2) const; + void Cleanup() { DxilExtValSupport.Cleanup(); - DxcompilerSupport.Cleanup(); + DxCompilerSupport.Cleanup(); } HMODULE Detach() { // Can't Detach and return a handle for DxilSupport. Cleanup() instead. DxilExtValSupport.Cleanup(); - return DxcompilerSupport.Detach(); + return DxCompilerSupport.Detach(); } - - HRESULT CreateInstance(REFCLSID clsid, REFIID riid, IUnknown **pResult); - HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, - IUnknown **pResult); - - HRESULT Initialize() { return InitializeInternal("DxcCreateInstance"); } - - bool IsEnabled() const { return DxcompilerSupport.IsEnabled(); } }; } // namespace dxc \ No newline at end of file diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index d91fb7d76f..e73b53868d 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -19,8 +19,51 @@ namespace dxc { extern const char *kDxCompilerLib; extern const char *kDxilLib; +// Interface for common dll operations +class IDllSupport { +public: + IDllSupport() = default; + + IDllSupport(IDllSupport &&other) = default; + + virtual ~IDllSupport() = default; + + virtual HRESULT Initialize() = 0; + + virtual HRESULT InitializeForDll(LPCSTR dll, LPCSTR entryPoint) = 0; + + template + HRESULT CreateInstance(REFCLSID clsid, TInterface **pResult) { + return CreateInstance(clsid, __uuidof(TInterface), (IUnknown **)pResult); + } + + virtual HRESULT CreateInstance(REFCLSID clsid, REFIID riid, + IUnknown **pResult) = 0; + + template + HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, + TInterface **pResult) { + return CreateInstance2(pMalloc, clsid, __uuidof(TInterface), + (IUnknown **)pResult); + } + + virtual HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, + IUnknown **pResult) = 0; + + virtual bool HasCreateWithMalloc() const = 0; + + virtual bool IsEnabled() const = 0; + + virtual bool + GetCreateInstanceProcs(DxcCreateInstanceProc *pCreateFn, + DxcCreateInstance2Proc *pCreateFn2) const = 0; + + virtual void Cleanup() = 0; + virtual HMODULE Detach() = 0; +}; + // Helper class to dynamically load the dxcompiler or a compatible libraries. -class DxcDllSupport { +class DxcDllSupport : public IDllSupport { HMODULE m_dll; DxcCreateInstanceProc m_createFn; @@ -95,11 +138,9 @@ class DxcDllSupport { return InitializeInternal(dll, entryPoint); } - template - HRESULT CreateInstance(REFCLSID clsid, TInterface **pResult) { - return CreateInstance(clsid, __uuidof(TInterface), (IUnknown **)pResult); - } - + // Also bring visibility into the interface definition of this function + // which takes 2 args + using IDllSupport::CreateInstance; HRESULT CreateInstance(REFCLSID clsid, REFIID riid, IUnknown **pResult) { if (pResult == nullptr) return E_POINTER; @@ -109,13 +150,9 @@ class DxcDllSupport { return hr; } - template - HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, - TInterface **pResult) { - return CreateInstance2(pMalloc, clsid, __uuidof(TInterface), - (IUnknown **)pResult); - } - + // Also bring visibility into the interface definition of this function + // which takes 3 args + using IDllSupport::CreateInstance2; HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, IUnknown **pResult) { if (pResult == nullptr) diff --git a/lib/DxcSupport/dxcapi.extval.cpp b/lib/DxcSupport/dxcapi.extval.cpp index d8029a25af..f838dae91b 100644 --- a/lib/DxcSupport/dxcapi.extval.cpp +++ b/lib/DxcSupport/dxcapi.extval.cpp @@ -11,7 +11,7 @@ HRESULT DxcDllExtValidationSupport::CreateInstance(REFCLSID clsid, REFIID riid, if (DxilExtValSupport.IsEnabled() && clsid == CLSID_DxcValidator) return DxilExtValSupport.CreateInstance(clsid, riid, pResult); - return DxcompilerSupport.CreateInstance(clsid, riid, pResult); + return DxCompilerSupport.CreateInstance(clsid, riid, pResult); } HRESULT DxcDllExtValidationSupport::CreateInstance2(IMalloc *pMalloc, @@ -20,12 +20,12 @@ HRESULT DxcDllExtValidationSupport::CreateInstance2(IMalloc *pMalloc, if (DxilExtValSupport.IsEnabled() && clsid == CLSID_DxcValidator) return DxilExtValSupport.CreateInstance2(pMalloc, clsid, riid, pResult); - return DxcompilerSupport.CreateInstance2(pMalloc, clsid, riid, pResult); + return DxCompilerSupport.CreateInstance2(pMalloc, clsid, riid, pResult); } HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR fnName) { // Load dxcompiler.dll - HRESULT Result = DxcompilerSupport.InitializeForDll(kDxCompilerLib, fnName); + HRESULT Result = DxCompilerSupport.InitializeForDll(kDxCompilerLib, fnName); // if dxcompiler.dll fails to load, return the failed HRESULT if (DXC_FAILED(Result)) { return Result; @@ -48,4 +48,14 @@ HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR fnName) { return DxilExtValSupport.InitializeForDll(DxilDllPath.c_str(), fnName); } +bool DxcDllExtValidationSupport::GetCreateInstanceProcs( + DxcCreateInstanceProc *pCreateFn, + DxcCreateInstance2Proc *pCreateFn2) const { + if (pCreateFn == nullptr || pCreateFn2 == nullptr || m_createFn == nullptr) + return false; + *pCreateFn = m_createFn; + *pCreateFn2 = m_createFn2; + return true; +} + } // namespace dxc \ No newline at end of file From fffb407afe4a6d3e12721febb793425b6cfd4a84 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Fri, 18 Jul 2025 15:07:02 -0700 Subject: [PATCH 32/53] fix nix error --- include/dxc/Support/dxcapi.extval.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/dxc/Support/dxcapi.extval.h b/include/dxc/Support/dxcapi.extval.h index e8068b1ce8..69c21ae083 100644 --- a/include/dxc/Support/dxcapi.extval.h +++ b/include/dxc/Support/dxcapi.extval.h @@ -34,9 +34,8 @@ class DxcDllExtValidationSupport : public IDllSupport { bool IsEnabled() const { return DxCompilerSupport.IsEnabled(); } - bool DxcDllExtValidationSupport::GetCreateInstanceProcs( - DxcCreateInstanceProc *pCreateFn, - DxcCreateInstance2Proc *pCreateFn2) const; + bool GetCreateInstanceProcs(DxcCreateInstanceProc *pCreateFn, + DxcCreateInstance2Proc *pCreateFn2) const; void Cleanup() { DxilExtValSupport.Cleanup(); From 5411894e105cc005f6d97e7c71ebe34621b55c40 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Thu, 24 Jul 2025 14:18:11 -0700 Subject: [PATCH 33/53] remove comment on header that is likely to become stale --- tools/clang/unittests/HLSL/ValidationTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp index 571184b0e9..ed9df41980 100644 --- a/tools/clang/unittests/HLSL/ValidationTest.cpp +++ b/tools/clang/unittests/HLSL/ValidationTest.cpp @@ -25,7 +25,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Regex.h" -#include // for _wgetenv +#include #ifdef _WIN32 #include From 45f74fa86eb9946ac9e055c036faafc17aa4a82b Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Mon, 28 Jul 2025 13:39:06 -0700 Subject: [PATCH 34/53] perform rename --- include/dxc/Support/HLSLOptions.h | 9 ++-- include/dxc/Support/dxcapi.extval.h | 6 +-- include/dxc/Support/dxcapi.use.h | 25 ++++----- include/dxc/Test/CompilationResult.h | 4 +- include/dxc/Test/DxcTestUtils.h | 54 +++++++++---------- lib/DxcSupport/HLSLOptions.cpp | 7 +-- lib/DxcSupport/dxcapi.extval.cpp | 14 ++--- lib/DxcSupport/dxcapi.use.cpp | 4 +- projects/dxilconv/unittests/DxilConvTests.cpp | 2 +- tools/clang/tools/dxa/dxa.cpp | 6 +-- tools/clang/tools/dxclib/dxc.cpp | 16 +++--- tools/clang/tools/dxclib/dxc.h | 6 +-- tools/clang/tools/dxcompiler/dxillib.cpp | 2 +- .../tools/dxlib-sample/lib_cache_manager.cpp | 2 +- tools/clang/tools/dxopt/dxopt.cpp | 2 +- tools/clang/tools/dxr/dxr.cpp | 5 +- .../tools/dxrfallbackcompiler/dxillib.cpp | 2 +- tools/clang/tools/dxv/dxv.cpp | 6 +-- .../DxrFallback/ShaderTesterImpl.cpp | 2 +- .../DxrFallback/test_DxrFallback.cpp | 10 ++-- tools/clang/unittests/HLSL/CompilerTest.cpp | 14 ++--- .../unittests/HLSL/DxilContainerTest.cpp | 2 +- tools/clang/unittests/HLSL/DxilModuleTest.cpp | 6 +-- tools/clang/unittests/HLSL/ExtensionTest.cpp | 8 +-- tools/clang/unittests/HLSL/FunctionTest.cpp | 2 +- tools/clang/unittests/HLSL/LinkerTest.cpp | 2 +- tools/clang/unittests/HLSL/OptimizerTest.cpp | 2 +- tools/clang/unittests/HLSL/PixDiaTest.cpp | 28 +++++----- tools/clang/unittests/HLSL/PixTest.cpp | 2 +- tools/clang/unittests/HLSL/PixTestUtils.cpp | 21 ++++---- tools/clang/unittests/HLSL/PixTestUtils.h | 19 +++---- tools/clang/unittests/HLSL/RewriterTest.cpp | 4 +- .../clang/unittests/HLSL/SystemValueTest.cpp | 2 +- tools/clang/unittests/HLSL/ValidationTest.cpp | 6 +-- .../unittests/HLSLExec/ExecutionTest.cpp | 30 +++++------ .../clang/unittests/HLSLExec/ShaderOpTest.cpp | 4 +- tools/clang/unittests/HLSLExec/ShaderOpTest.h | 6 +-- .../unittests/HLSLTestLib/DxcTestUtils.cpp | 26 ++++----- .../unittests/HLSLTestLib/FileCheckerTest.cpp | 36 ++++++------- tools/clang/unittests/SPIRV/LibTestUtils.cpp | 2 +- tools/clang/unittests/dxc_batch/dxc_batch.cpp | 15 +++--- 41 files changed, 215 insertions(+), 206 deletions(-) diff --git a/include/dxc/Support/HLSLOptions.h b/include/dxc/Support/HLSLOptions.h index bad330747b..a237589b1f 100644 --- a/include/dxc/Support/HLSLOptions.h +++ b/include/dxc/Support/HLSLOptions.h @@ -36,7 +36,7 @@ class raw_ostream; } // namespace llvm namespace dxc { -class DxcDllSupport; +class SpecificDllLoader; } namespace hlsl { @@ -313,9 +313,10 @@ int ReadDxcOpts(const llvm::opt::OptTable *optionTable, unsigned flagsToInclude, const MainArgs &argStrings, DxcOpts &opts, llvm::raw_ostream &errors); -/// Sets up the specified DxcDllSupport instance as per the given options. -int SetupDxcDllSupport(const DxcOpts &opts, dxc::DxcDllSupport &dxcSupport, - llvm::raw_ostream &errors); +/// Sets up the specified SpecificDllLoader instance as per the given options. +int SetupSpecificDllLoader(const DxcOpts &opts, + dxc::SpecificDllLoader &dxcSupport, + llvm::raw_ostream &errors); void CopyArgsToWStrings(const llvm::opt::InputArgList &inArgs, unsigned flagsToInclude, diff --git a/include/dxc/Support/dxcapi.extval.h b/include/dxc/Support/dxcapi.extval.h index 69c21ae083..a08a7aac85 100644 --- a/include/dxc/Support/dxcapi.extval.h +++ b/include/dxc/Support/dxcapi.extval.h @@ -2,12 +2,12 @@ #include namespace dxc { -class DxcDllExtValidationSupport : public IDllSupport { +class DxcDllExtValidationLoader : public DllLoader { // DxCompilerSupport manages the // lifetime of dxcompiler.dll, while DxilExtValSupport // manages the lifetime of dxil.dll - dxc::DxcDllSupport DxCompilerSupport; - dxc::DxcDllSupport DxilExtValSupport; + dxc::SpecificDllLoader DxCompilerSupport; + dxc::SpecificDllLoader DxilExtValSupport; DxcCreateInstanceProc m_createFn; DxcCreateInstance2Proc m_createFn2; diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index e73b53868d..fb47054719 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -20,13 +20,13 @@ extern const char *kDxCompilerLib; extern const char *kDxilLib; // Interface for common dll operations -class IDllSupport { +class DllLoader { public: - IDllSupport() = default; + DllLoader() = default; - IDllSupport(IDllSupport &&other) = default; + DllLoader(DllLoader &&other) = default; - virtual ~IDllSupport() = default; + virtual ~DllLoader() = default; virtual HRESULT Initialize() = 0; @@ -63,7 +63,7 @@ class IDllSupport { }; // Helper class to dynamically load the dxcompiler or a compatible libraries. -class DxcDllSupport : public IDllSupport { +class SpecificDllLoader : public DllLoader { HMODULE m_dll; DxcCreateInstanceProc m_createFn; @@ -117,9 +117,10 @@ class DxcDllSupport : public IDllSupport { } public: - DxcDllSupport() : m_dll(nullptr), m_createFn(nullptr), m_createFn2(nullptr) {} + SpecificDllLoader() + : m_dll(nullptr), m_createFn(nullptr), m_createFn2(nullptr) {} - DxcDllSupport(DxcDllSupport &&other) { + SpecificDllLoader(SpecificDllLoader &&other) { m_dll = other.m_dll; other.m_dll = nullptr; m_createFn = other.m_createFn; @@ -128,7 +129,7 @@ class DxcDllSupport : public IDllSupport { other.m_createFn2 = nullptr; } - ~DxcDllSupport() { Cleanup(); } + ~SpecificDllLoader() { Cleanup(); } HRESULT Initialize() { return InitializeInternal(kDxCompilerLib, "DxcCreateInstance"); @@ -140,7 +141,7 @@ class DxcDllSupport : public IDllSupport { // Also bring visibility into the interface definition of this function // which takes 2 args - using IDllSupport::CreateInstance; + using DllLoader::CreateInstance; HRESULT CreateInstance(REFCLSID clsid, REFIID riid, IUnknown **pResult) { if (pResult == nullptr) return E_POINTER; @@ -152,7 +153,7 @@ class DxcDllSupport : public IDllSupport { // Also bring visibility into the interface definition of this function // which takes 3 args - using IDllSupport::CreateInstance2; + using DllLoader::CreateInstance2; HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, IUnknown **pResult) { if (pResult == nullptr) @@ -208,8 +209,8 @@ inline DxcDefine GetDefine(LPCWSTR name, LPCWSTR value) { // Checks an HRESULT and formats an error message with the appended data. void IFT_Data(HRESULT hr, LPCWSTR data); -void EnsureEnabled(DxcDllSupport &dxcSupport); -void ReadFileIntoBlob(DxcDllSupport &dxcSupport, LPCWSTR pFileName, +void EnsureEnabled(SpecificDllLoader &dxcSupport); +void ReadFileIntoBlob(SpecificDllLoader &dxcSupport, LPCWSTR pFileName, IDxcBlobEncoding **ppBlobEncoding); void WriteBlobToConsole(IDxcBlob *pBlob, DWORD streamType = STD_OUTPUT_HANDLE); void WriteBlobToFile(IDxcBlob *pBlob, LPCWSTR pFileName, UINT32 textCodePage); diff --git a/include/dxc/Test/CompilationResult.h b/include/dxc/Test/CompilationResult.h index 1d1272b379..f5920aabc8 100644 --- a/include/dxc/Test/CompilationResult.h +++ b/include/dxc/Test/CompilationResult.h @@ -101,11 +101,11 @@ class TrivialDxcUnsavedFile : public IDxcUnsavedFile { } }; -class HlslIntellisenseSupport : public dxc::DxcDllSupport { +class HlslIntellisenseSupport : public dxc::SpecificDllLoader { public: HlslIntellisenseSupport() {} HlslIntellisenseSupport(HlslIntellisenseSupport &&other) - : dxc::DxcDllSupport(std::move(other)) {} + : dxc::SpecificDllLoader(std::move(other)) {} HRESULT CreateIntellisense(IDxcIntelliSense **pResult) { return CreateInstance(CLSID_DxcIntelliSense, pResult); diff --git a/include/dxc/Test/DxcTestUtils.h b/include/dxc/Test/DxcTestUtils.h index 79ab49ee9a..f6d12aafa9 100644 --- a/include/dxc/Test/DxcTestUtils.h +++ b/include/dxc/Test/DxcTestUtils.h @@ -109,11 +109,11 @@ class FileRunCommandPart { FileRunCommandPart(const FileRunCommandPart &) = default; FileRunCommandPart(FileRunCommandPart &&) = default; - FileRunCommandResult Run(dxc::DxcDllSupport &DllSupport, + FileRunCommandResult Run(dxc::SpecificDllLoader &DllSupport, const FileRunCommandResult *Prior, PluginToolsPaths *pPluginToolsPaths = nullptr, LPCWSTR dumpName = nullptr); - FileRunCommandResult RunHashTests(dxc::DxcDllSupport &DllSupport); + FileRunCommandResult RunHashTests(dxc::SpecificDllLoader &DllSupport); FileRunCommandResult ReadOptsForDxc(hlsl::options::MainArgs &argStrings, hlsl::options::DxcOpts &Opts, @@ -127,30 +127,30 @@ class FileRunCommandPart { private: FileRunCommandResult RunFileChecker(const FileRunCommandResult *Prior, LPCWSTR dumpName = nullptr); - FileRunCommandResult RunDxc(dxc::DxcDllSupport &DllSupport, + FileRunCommandResult RunDxc(dxc::SpecificDllLoader &DllSupport, const FileRunCommandResult *Prior); - FileRunCommandResult RunDxv(dxc::DxcDllSupport &DllSupport, + FileRunCommandResult RunDxv(dxc::SpecificDllLoader &DllSupport, const FileRunCommandResult *Prior); - FileRunCommandResult RunOpt(dxc::DxcDllSupport &DllSupport, + FileRunCommandResult RunOpt(dxc::SpecificDllLoader &DllSupport, const FileRunCommandResult *Prior); - FileRunCommandResult RunListParts(dxc::DxcDllSupport &DllSupport, + FileRunCommandResult RunListParts(dxc::SpecificDllLoader &DllSupport, const FileRunCommandResult *Prior); - FileRunCommandResult RunD3DReflect(dxc::DxcDllSupport &DllSupport, + FileRunCommandResult RunD3DReflect(dxc::SpecificDllLoader &DllSupport, const FileRunCommandResult *Prior); - FileRunCommandResult RunDxr(dxc::DxcDllSupport &DllSupport, + FileRunCommandResult RunDxr(dxc::SpecificDllLoader &DllSupport, const FileRunCommandResult *Prior); - FileRunCommandResult RunLink(dxc::DxcDllSupport &DllSupport, + FileRunCommandResult RunLink(dxc::SpecificDllLoader &DllSupport, const FileRunCommandResult *Prior); FileRunCommandResult RunTee(const FileRunCommandResult *Prior); FileRunCommandResult RunXFail(const FileRunCommandResult *Prior); - FileRunCommandResult RunDxilVer(dxc::DxcDllSupport &DllSupport, + FileRunCommandResult RunDxilVer(dxc::SpecificDllLoader &DllSupport, const FileRunCommandResult *Prior); - FileRunCommandResult RunDxcHashTest(dxc::DxcDllSupport &DllSupport); + FileRunCommandResult RunDxcHashTest(dxc::SpecificDllLoader &DllSupport); FileRunCommandResult RunFromPath(const std::string &path, const FileRunCommandResult *Prior); FileRunCommandResult RunFileCompareText(const FileRunCommandResult *Prior); #ifdef _WIN32 - FileRunCommandResult RunFxc(dxc::DxcDllSupport &DllSupport, + FileRunCommandResult RunFxc(dxc::SpecificDllLoader &DllSupport, const FileRunCommandResult *Prior); #endif @@ -175,12 +175,12 @@ class FileRunTestResult { PluginToolsPaths *pPluginToolsPaths = nullptr, LPCWSTR dumpName = nullptr); static FileRunTestResult - RunFromFileCommands(LPCWSTR fileName, dxc::DxcDllSupport &dllSupport, + RunFromFileCommands(LPCWSTR fileName, dxc::SpecificDllLoader &dllSupport, PluginToolsPaths *pPluginToolsPaths = nullptr, LPCWSTR dumpName = nullptr); }; -void AssembleToContainer(dxc::DxcDllSupport &dllSupport, IDxcBlob *pModule, +void AssembleToContainer(dxc::SpecificDllLoader &dllSupport, IDxcBlob *pModule, IDxcBlob **pContainer); std::string BlobToUtf8(IDxcBlob *pBlob); std::wstring BlobToWide(IDxcBlob *pBlob); @@ -195,35 +195,35 @@ bool CheckMsgs(const LPCSTR pText, size_t TextCount, const LPCSTR *pErrorMsgs, size_t errorMsgCount, bool bRegex); bool CheckNotMsgs(const LPCSTR pText, size_t TextCount, const LPCSTR *pErrorMsgs, size_t errorMsgCount, bool bRegex); -void GetDxilPart(dxc::DxcDllSupport &dllSupport, IDxcBlob *pProgram, +void GetDxilPart(dxc::SpecificDllLoader &dllSupport, IDxcBlob *pProgram, IDxcBlob **pDxilPart); -std::string DisassembleProgram(dxc::DxcDllSupport &dllSupport, +std::string DisassembleProgram(dxc::SpecificDllLoader &dllSupport, IDxcBlob *pProgram); void SplitPassList(LPWSTR pPassesBuffer, std::vector &passes); -void MultiByteStringToBlob(dxc::DxcDllSupport &dllSupport, +void MultiByteStringToBlob(dxc::SpecificDllLoader &dllSupport, const std::string &val, UINT32 codePoint, IDxcBlob **ppBlob); -void MultiByteStringToBlob(dxc::DxcDllSupport &dllSupport, +void MultiByteStringToBlob(dxc::SpecificDllLoader &dllSupport, const std::string &val, UINT32 codePoint, IDxcBlobEncoding **ppBlob); -void Utf8ToBlob(dxc::DxcDllSupport &dllSupport, const std::string &val, +void Utf8ToBlob(dxc::SpecificDllLoader &dllSupport, const std::string &val, IDxcBlob **ppBlob); -void Utf8ToBlob(dxc::DxcDllSupport &dllSupport, const std::string &val, +void Utf8ToBlob(dxc::SpecificDllLoader &dllSupport, const std::string &val, IDxcBlobEncoding **ppBlob); -void Utf8ToBlob(dxc::DxcDllSupport &dllSupport, const char *pVal, +void Utf8ToBlob(dxc::SpecificDllLoader &dllSupport, const char *pVal, IDxcBlobEncoding **ppBlob); -void WideToBlob(dxc::DxcDllSupport &dllSupport, const std::wstring &val, +void WideToBlob(dxc::SpecificDllLoader &dllSupport, const std::wstring &val, IDxcBlob **ppBlob); -void WideToBlob(dxc::DxcDllSupport &dllSupport, const std::wstring &val, +void WideToBlob(dxc::SpecificDllLoader &dllSupport, const std::wstring &val, IDxcBlobEncoding **ppBlob); -void VerifyCompileOK(dxc::DxcDllSupport &dllSupport, LPCSTR pText, +void VerifyCompileOK(dxc::SpecificDllLoader &dllSupport, LPCSTR pText, LPCWSTR pTargetProfile, LPCWSTR pArgs, IDxcBlob **ppResult); -void VerifyCompileOK(dxc::DxcDllSupport &dllSupport, LPCSTR pText, +void VerifyCompileOK(dxc::SpecificDllLoader &dllSupport, LPCSTR pText, LPCWSTR pTargetProfile, std::vector &args, IDxcBlob **ppResult); -HRESULT GetVersion(dxc::DxcDllSupport &DllSupport, REFCLSID clsid, +HRESULT GetVersion(dxc::SpecificDllLoader &DllSupport, REFCLSID clsid, unsigned &Major, unsigned &Minor); bool ParseTargetProfile(llvm::StringRef targetProfile, llvm::StringRef &outStage, unsigned &outMajor, @@ -240,7 +240,7 @@ class VersionSupportInfo { VersionSupportInfo(); // Initialize version info structure. TODO: add device shader model support - void Initialize(dxc::DxcDllSupport &dllSupport); + void Initialize(dxc::SpecificDllLoader &dllSupport); // Return true if IR sensitive test should be skipped, and log comment bool SkipIRSensitiveTest(); // Return true if test requiring DXIL of given version should be skipped, and diff --git a/lib/DxcSupport/HLSLOptions.cpp b/lib/DxcSupport/HLSLOptions.cpp index eb071eb0a6..a7065b058b 100644 --- a/lib/DxcSupport/HLSLOptions.cpp +++ b/lib/DxcSupport/HLSLOptions.cpp @@ -1381,9 +1381,10 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude, return 0; } -/// Sets up the specified DxcDllSupport instance as per the given options. -int SetupDxcDllSupport(const DxcOpts &opts, dxc::DxcDllSupport &dxcSupport, - llvm::raw_ostream &errors) { +/// Sets up the specified SpecificDllLoader instance as per the given options. +int SetupSpecificDllLoader(const DxcOpts &opts, + dxc::SpecificDllLoader &dxcSupport, + llvm::raw_ostream &errors) { if (!opts.ExternalLib.empty()) { DXASSERT(!opts.ExternalFn.empty(), "else ReadDxcOpts should have failed"); HRESULT hrLoad = dxcSupport.InitializeForDll(opts.ExternalLib.data(), diff --git a/lib/DxcSupport/dxcapi.extval.cpp b/lib/DxcSupport/dxcapi.extval.cpp index f838dae91b..bd1e6701c2 100644 --- a/lib/DxcSupport/dxcapi.extval.cpp +++ b/lib/DxcSupport/dxcapi.extval.cpp @@ -6,24 +6,24 @@ namespace dxc { -HRESULT DxcDllExtValidationSupport::CreateInstance(REFCLSID clsid, REFIID riid, - IUnknown **pResult) { +HRESULT DxcDllExtValidationLoader::CreateInstance(REFCLSID clsid, REFIID riid, + IUnknown **pResult) { if (DxilExtValSupport.IsEnabled() && clsid == CLSID_DxcValidator) return DxilExtValSupport.CreateInstance(clsid, riid, pResult); return DxCompilerSupport.CreateInstance(clsid, riid, pResult); } -HRESULT DxcDllExtValidationSupport::CreateInstance2(IMalloc *pMalloc, - REFCLSID clsid, REFIID riid, - IUnknown **pResult) { +HRESULT DxcDllExtValidationLoader::CreateInstance2(IMalloc *pMalloc, + REFCLSID clsid, REFIID riid, + IUnknown **pResult) { if (DxilExtValSupport.IsEnabled() && clsid == CLSID_DxcValidator) return DxilExtValSupport.CreateInstance2(pMalloc, clsid, riid, pResult); return DxCompilerSupport.CreateInstance2(pMalloc, clsid, riid, pResult); } -HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR fnName) { +HRESULT DxcDllExtValidationLoader::InitializeInternal(LPCSTR fnName) { // Load dxcompiler.dll HRESULT Result = DxCompilerSupport.InitializeForDll(kDxCompilerLib, fnName); // if dxcompiler.dll fails to load, return the failed HRESULT @@ -48,7 +48,7 @@ HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR fnName) { return DxilExtValSupport.InitializeForDll(DxilDllPath.c_str(), fnName); } -bool DxcDllExtValidationSupport::GetCreateInstanceProcs( +bool DxcDllExtValidationLoader::GetCreateInstanceProcs( DxcCreateInstanceProc *pCreateFn, DxcCreateInstance2Proc *pCreateFn2) const { if (pCreateFn == nullptr || pCreateFn2 == nullptr || m_createFn == nullptr) diff --git a/lib/DxcSupport/dxcapi.use.cpp b/lib/DxcSupport/dxcapi.use.cpp index 399259ef87..4096d58de7 100644 --- a/lib/DxcSupport/dxcapi.use.cpp +++ b/lib/DxcSupport/dxcapi.use.cpp @@ -73,13 +73,13 @@ void IFT_Data(HRESULT hr, LPCWSTR data) { throw ::hlsl::Exception(hr, errMsg); } -void EnsureEnabled(DxcDllSupport &dxcSupport) { +void EnsureEnabled(SpecificDllLoader &dxcSupport) { if (!dxcSupport.IsEnabled()) { IFT(dxcSupport.Initialize()); } } -void ReadFileIntoBlob(DxcDllSupport &dxcSupport, LPCWSTR pFileName, +void ReadFileIntoBlob(SpecificDllLoader &dxcSupport, LPCWSTR pFileName, IDxcBlobEncoding **ppBlobEncoding) { CComPtr library; IFT(dxcSupport.CreateInstance(CLSID_DxcLibrary, &library)); diff --git a/projects/dxilconv/unittests/DxilConvTests.cpp b/projects/dxilconv/unittests/DxilConvTests.cpp index 6589647f73..2f92c86f53 100644 --- a/projects/dxilconv/unittests/DxilConvTests.cpp +++ b/projects/dxilconv/unittests/DxilConvTests.cpp @@ -67,7 +67,7 @@ class DxilConvTest { END_TEST_METHOD() private: - dxc::DxcDllSupport m_dllSupport; + dxc::SpecificDllLoader m_dllSupport; PluginToolsPaths m_TestToolPaths; void DxilConvTestCheckFile(LPCWSTR path) { diff --git a/tools/clang/tools/dxa/dxa.cpp b/tools/clang/tools/dxa/dxa.cpp index 11d9d642e5..af3681c38f 100644 --- a/tools/clang/tools/dxa/dxa.cpp +++ b/tools/clang/tools/dxa/dxa.cpp @@ -79,14 +79,14 @@ static cl::opt DumpPSV("dumppsv", class DxaContext { private: - DxcDllSupport &m_dxcSupport; + SpecificDllLoader &m_dxcSupport; HRESULT FindModule(hlsl::DxilFourCC fourCC, IDxcBlob *pSource, IDxcLibrary *pLibrary, IDxcBlob **ppTarget); bool ExtractPart(uint32_t Part, IDxcBlob **ppTargetBlob); bool ExtractPart(IDxcBlob *pSource, uint32_t Part, IDxcBlob **ppTargetBlob); public: - DxaContext(DxcDllSupport &dxcSupport) : m_dxcSupport(dxcSupport) {} + DxaContext(SpecificDllLoader &dxcSupport) : m_dxcSupport(dxcSupport) {} void Assemble(); bool ExtractFile(const char *pName); @@ -546,7 +546,7 @@ int main(int argc, const char **argv) { return 2; } - DxcDllSupport dxcSupport; + SpecificDllLoader dxcSupport; dxc::EnsureEnabled(dxcSupport); DxaContext context(dxcSupport); if (ListParts) { diff --git a/tools/clang/tools/dxclib/dxc.cpp b/tools/clang/tools/dxclib/dxc.cpp index cdcfe2b3f6..f5e763526e 100644 --- a/tools/clang/tools/dxclib/dxc.cpp +++ b/tools/clang/tools/dxclib/dxc.cpp @@ -125,7 +125,7 @@ class DxcContext { private: DxcOpts &m_Opts; - DxcDllSupport &m_dxcSupport; + SpecificDllLoader &m_dxcSupport; int ActOnBlob(IDxcBlob *pBlob); int ActOnBlob(IDxcBlob *pBlob, IDxcBlob *pDebugBlob, LPCWSTR pDebugBlobName); @@ -155,7 +155,7 @@ class DxcContext { } public: - DxcContext(DxcOpts &Opts, DxcDllSupport &dxcSupport) + DxcContext(DxcOpts &Opts, SpecificDllLoader &dxcSupport) : m_Opts(Opts), m_dxcSupport(dxcSupport) {} int Compile(); @@ -1235,7 +1235,7 @@ namespace dxc { // Writes compiler version info to stream void WriteDxCompilerVersionInfo(llvm::raw_ostream &OS, const char *ExternalLib, const char *ExternalFn, - DxcDllSupport &DxcSupport) { + SpecificDllLoader &DxcSupport) { if (DxcSupport.IsEnabled()) { UINT32 compilerMajor = 1; UINT32 compilerMinor = 0; @@ -1294,7 +1294,8 @@ void WriteDxCompilerVersionInfo(llvm::raw_ostream &OS, const char *ExternalLib, } // Writes compiler version info to stream -void WriteDXILVersionInfo(llvm::raw_ostream &OS, DxcDllSupport &DxilSupport) { +void WriteDXILVersionInfo(llvm::raw_ostream &OS, + SpecificDllLoader &DxilSupport) { if (DxilSupport.IsEnabled()) { CComPtr VerInfo; if (SUCCEEDED(DxilSupport.CreateInstance(CLSID_DxcValidator, &VerInfo))) { @@ -1325,7 +1326,7 @@ void DxcContext::GetCompilerVersionInfo(llvm::raw_string_ostream &OS) { m_dxcSupport); // Print validator if exists - DxcDllSupport DxilSupport; + SpecificDllLoader DxilSupport; DxilSupport.InitializeForDll(kDxilLib, "DxcCreateInstance"); WriteDXILVersionInfo(OS, DxilSupport); } @@ -1417,7 +1418,7 @@ int dxc::main(int argc, const char **argv_) { const OptTable *optionTable = getHlslOptTable(); MainArgs argStrings(argc, argv_); DxcOpts dxcOpts; - DxcDllSupport dxcSupport; + SpecificDllLoader dxcSupport; // Read options and check errors. { @@ -1452,7 +1453,8 @@ int dxc::main(int argc, const char **argv_) { { std::string dllErrorString; llvm::raw_string_ostream dllErrorStream(dllErrorString); - int dllResult = SetupDxcDllSupport(dxcOpts, dxcSupport, dllErrorStream); + int dllResult = + SetupSpecificDllLoader(dxcOpts, dxcSupport, dllErrorStream); dllErrorStream.flush(); if (dllErrorString.size()) { fprintf(stderr, "%s\n", dllErrorString.data()); diff --git a/tools/clang/tools/dxclib/dxc.h b/tools/clang/tools/dxclib/dxc.h index 9ae7a06ffb..2740f2ca81 100644 --- a/tools/clang/tools/dxclib/dxc.h +++ b/tools/clang/tools/dxclib/dxc.h @@ -18,14 +18,14 @@ class raw_ostream; } namespace dxc { -class DxcDllSupport; +class SpecificDllLoader; // Writes compiler version info to stream void WriteDxCompilerVersionInfo(llvm::raw_ostream &OS, const char *ExternalLib, const char *ExternalFn, - dxc::DxcDllSupport &DxcSupport); + dxc::SpecificDllLoader &DxcSupport); void WriteDXILVersionInfo(llvm::raw_ostream &OS, - dxc::DxcDllSupport &DxilSupport); + dxc::SpecificDllLoader &DxilSupport); #ifdef _WIN32 int main(int argc, const wchar_t **argv_); diff --git a/tools/clang/tools/dxcompiler/dxillib.cpp b/tools/clang/tools/dxcompiler/dxillib.cpp index 72abc869da..5f183bfad0 100644 --- a/tools/clang/tools/dxcompiler/dxillib.cpp +++ b/tools/clang/tools/dxcompiler/dxillib.cpp @@ -16,7 +16,7 @@ using namespace dxc; -static DxcDllSupport g_DllSupport; +static dxc::SpecificDllLoader g_DllSupport; static HRESULT g_DllLibResult = S_OK; static llvm::sys::Mutex *cs = nullptr; diff --git a/tools/clang/tools/dxlib-sample/lib_cache_manager.cpp b/tools/clang/tools/dxlib-sample/lib_cache_manager.cpp index e6379415af..c423b97b28 100644 --- a/tools/clang/tools/dxlib-sample/lib_cache_manager.cpp +++ b/tools/clang/tools/dxlib-sample/lib_cache_manager.cpp @@ -40,7 +40,7 @@ class NoFuncBodyRewriter { private: CComPtr m_pRewriter; - dxc::DxcDllSupport m_dllSupport; + dxc::SpecificDllLoader m_dllSupport; }; HRESULT NoFuncBodyRewriter::RewriteToNoFuncBody( diff --git a/tools/clang/tools/dxopt/dxopt.cpp b/tools/clang/tools/dxopt/dxopt.cpp index 29e3876e7d..2b42e2220d 100644 --- a/tools/clang/tools/dxopt/dxopt.cpp +++ b/tools/clang/tools/dxopt/dxopt.cpp @@ -43,7 +43,7 @@ inline bool wcsieqopt(LPCWSTR text, LPCWSTR opt) { return (text[0] == L'-' || text[0] == L'/') && wcsieq(text + 1, opt); } -static dxc::DxcDllSupport g_DxcSupport; +static dxc::SpecificDllLoader g_DxcSupport; enum class ProgramAction { PrintHelp, diff --git a/tools/clang/tools/dxr/dxr.cpp b/tools/clang/tools/dxr/dxr.cpp index e64a050ffc..4162b0765d 100644 --- a/tools/clang/tools/dxr/dxr.cpp +++ b/tools/clang/tools/dxr/dxr.cpp @@ -50,7 +50,7 @@ int main(int argc, const char **argv) { const OptTable *optionTable = getHlslOptTable(); MainArgs argStrings(argc, argv_); DxcOpts dxcOpts; - DxcDllSupport dxcSupport; + SpecificDllLoader dxcSupport; // Read options and check errors. { @@ -76,7 +76,8 @@ int main(int argc, const char **argv) { { std::string dllErrorString; llvm::raw_string_ostream dllErrorStream(dllErrorString); - int dllResult = SetupDxcDllSupport(dxcOpts, dxcSupport, dllErrorStream); + int dllResult = + SetupSpecificDllLoader(dxcOpts, dxcSupport, dllErrorStream); dllErrorStream.flush(); if (dllErrorString.size()) { fprintf(stderr, "%s\n", dllErrorString.data()); diff --git a/tools/clang/tools/dxrfallbackcompiler/dxillib.cpp b/tools/clang/tools/dxrfallbackcompiler/dxillib.cpp index 1c54ea6fa3..e12a7412da 100644 --- a/tools/clang/tools/dxrfallbackcompiler/dxillib.cpp +++ b/tools/clang/tools/dxrfallbackcompiler/dxillib.cpp @@ -15,7 +15,7 @@ using namespace dxc; -static DxcDllSupport g_DllSupport; +static SpecificDllLoader g_DllSupport; static HRESULT g_DllLibResult = S_OK; static CRITICAL_SECTION cs; diff --git a/tools/clang/tools/dxv/dxv.cpp b/tools/clang/tools/dxv/dxv.cpp index 6e1ea8013e..7ce5c983cc 100644 --- a/tools/clang/tools/dxv/dxv.cpp +++ b/tools/clang/tools/dxv/dxv.cpp @@ -42,10 +42,10 @@ static cl::opt class DxvContext { private: - DxcDllSupport &m_dxcSupport; + SpecificDllLoader &m_dxcSupport; public: - DxvContext(DxcDllSupport &dxcSupport) : m_dxcSupport(dxcSupport) {} + DxvContext(SpecificDllLoader &dxcSupport) : m_dxcSupport(dxcSupport) {} void Validate(); }; @@ -160,7 +160,7 @@ int main(int argc, const char **argv) { return 2; } - DxcDllSupport dxcSupport; + SpecificDllLoader dxcSupport; dxc::EnsureEnabled(dxcSupport); DxvContext context(dxcSupport); diff --git a/tools/clang/unittests/DxrFallback/ShaderTesterImpl.cpp b/tools/clang/unittests/DxrFallback/ShaderTesterImpl.cpp index 08ae2c3c75..5c85a6057b 100644 --- a/tools/clang/unittests/DxrFallback/ShaderTesterImpl.cpp +++ b/tools/clang/unittests/DxrFallback/ShaderTesterImpl.cpp @@ -32,7 +32,7 @@ using Microsoft::WRL::ComPtr; #include "dxc/dxcapi.h" #include -static dxc::DxcDllSupport g_DxcDllHelper; +static dxc::SpecificDllLoader g_DxcDllHelper; #define VERIFY_SUCCEEDED(expr) \ { \ diff --git a/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp b/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp index d8352ae1c1..321a9d6682 100644 --- a/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp +++ b/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp @@ -49,7 +49,7 @@ void printErrors(CComPtr pResult) { // IFTMSG(status, msg); } -void CompileToDxilFromFile(DxcDllSupport &dxcSupport, +void CompileToDxilFromFile(SpecificDllLoader &dxcSupport, LPCWSTR pShaderTextFilePath, LPCWSTR pEntryPoint, LPCWSTR pTargetProfile, LPCWSTR *pArgs, UINT32 argCount, const DxcDefine *pDefines, @@ -83,8 +83,8 @@ void CompileToDxilFromFile(DxcDllSupport &dxcSupport, } } -bool DxrCompile(DxcDllSupport &dxrFallbackSupport, const std::string &entryName, - std::vector &libs, +bool DxrCompile(SpecificDllLoader &dxrFallbackSupport, + const std::string &entryName, std::vector &libs, const std::vector &shaderNames, std::vector &shaderIds, bool findCalledShaders, IDxcBlob **ppResultBlob) { @@ -161,8 +161,8 @@ class Tester { } protected: - DxcDllSupport m_dxcSupport; - DxcDllSupport m_dxrFallbackSupport; + SpecificDllLoader m_dxcSupport; + SpecificDllLoader m_dxrFallbackSupport; std::wstring m_deviceName; std::vector> m_inputBlobs; std::vector m_inputBlobPtrs; diff --git a/tools/clang/unittests/HLSL/CompilerTest.cpp b/tools/clang/unittests/HLSL/CompilerTest.cpp index 3f4fb30d58..524e6bc7e6 100644 --- a/tools/clang/unittests/HLSL/CompilerTest.cpp +++ b/tools/clang/unittests/HLSL/CompilerTest.cpp @@ -80,9 +80,9 @@ class TestIncludeHandler : public IDxcIncludeHandler { DXC_MICROCOM_REF_FIELD(m_dwRef) public: DXC_MICROCOM_ADDREF_RELEASE_IMPL(m_dwRef) - dxc::DxcDllSupport &m_dllSupport; + dxc::SpecificDllLoader &m_dllSupport; HRESULT m_defaultErrorCode = E_FAIL; - TestIncludeHandler(dxc::DxcDllSupport &dllSupport) + TestIncludeHandler(dxc::SpecificDllLoader &dllSupport) : m_dwRef(0), m_dllSupport(dllSupport), callIndex(0) {} HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppvObject) override { @@ -285,7 +285,7 @@ class CompilerTest : public ::testing::Test { TEST_METHOD_PROPERTY(L"Ignore", L"true") END_TEST_METHOD() - dxc::DxcDllSupport m_dllSupport; + dxc::SpecificDllLoader m_dllSupport; VersionSupportInfo m_ver; void CreateBlobPinned(LPCVOID data, SIZE_T size, UINT32 codePage, @@ -1264,8 +1264,8 @@ TEST_F(CompilerTest, CompileThenTestReflectionThreadSizeMS) { } static void VerifyPdbUtil( - dxc::DxcDllSupport &dllSupport, IDxcBlob *pBlob, IDxcPdbUtils *pPdbUtils, - const WCHAR *pMainFileName, + dxc::SpecificDllLoader &dllSupport, IDxcBlob *pBlob, + IDxcPdbUtils *pPdbUtils, const WCHAR *pMainFileName, llvm::ArrayRef> ExpectedArgs, llvm::ArrayRef> ExpectedFlags, llvm::ArrayRef ExpectedDefines, IDxcCompiler *pCompiler, @@ -2902,9 +2902,9 @@ class SimpleIncludeHanlder : public IDxcIncludeHandler { DXC_MICROCOM_REF_FIELD(m_dwRef) public: DXC_MICROCOM_ADDREF_RELEASE_IMPL(m_dwRef) - dxc::DxcDllSupport &m_dllSupport; + dxc::SpecificDllLoader &m_dllSupport; HRESULT m_defaultErrorCode = E_FAIL; - SimpleIncludeHanlder(dxc::DxcDllSupport &dllSupport) + SimpleIncludeHanlder(dxc::SpecificDllLoader &dllSupport) : m_dwRef(0), m_dllSupport(dllSupport) {} HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppvObject) override { diff --git a/tools/clang/unittests/HLSL/DxilContainerTest.cpp b/tools/clang/unittests/HLSL/DxilContainerTest.cpp index 34b4d338fe..0b364e46d6 100644 --- a/tools/clang/unittests/HLSL/DxilContainerTest.cpp +++ b/tools/clang/unittests/HLSL/DxilContainerTest.cpp @@ -124,7 +124,7 @@ class DxilContainerTest : public ::testing::Test { TEST_METHOD_PROPERTY(L"Priority", L"1") END_TEST_METHOD() - dxc::DxcDllSupport m_dllSupport; + dxc::SpecificDllLoader m_dllSupport; VersionSupportInfo m_ver; void CreateBlobPinned(LPCVOID data, SIZE_T size, UINT32 codePage, diff --git a/tools/clang/unittests/HLSL/DxilModuleTest.cpp b/tools/clang/unittests/HLSL/DxilModuleTest.cpp index 9893127809..ac8bf9ce49 100644 --- a/tools/clang/unittests/HLSL/DxilModuleTest.cpp +++ b/tools/clang/unittests/HLSL/DxilModuleTest.cpp @@ -46,7 +46,7 @@ class DxilModuleTest : public ::testing::Test { TEST_CLASS_SETUP(InitSupport); - dxc::DxcDllSupport m_dllSupport; + dxc::SpecificDllLoader m_dllSupport; VersionSupportInfo m_ver; // Basic loading tests. @@ -96,7 +96,7 @@ bool DxilModuleTest::InitSupport() { namespace { class Compiler { public: - Compiler(dxc::DxcDllSupport &dll) + Compiler(dxc::SpecificDllLoader &dll) : m_dllSupport(dll), m_msf(CreateMSFileSystem()), m_pts(m_msf.get()) { m_ver.Initialize(m_dllSupport); VERIFY_SUCCEEDED( @@ -179,7 +179,7 @@ class Compiler { return msfPtr; } - dxc::DxcDllSupport &m_dllSupport; + dxc::SpecificDllLoader &m_dllSupport; VersionSupportInfo m_ver; CComPtr pCompiler; CComPtr pCodeBlob; diff --git a/tools/clang/unittests/HLSL/ExtensionTest.cpp b/tools/clang/unittests/HLSL/ExtensionTest.cpp index 65407291ca..336bd791e6 100644 --- a/tools/clang/unittests/HLSL/ExtensionTest.cpp +++ b/tools/clang/unittests/HLSL/ExtensionTest.cpp @@ -572,7 +572,7 @@ class TestSemanticDefineValidator : public IDxcSemanticDefineValidator { auto Check = [pName](const std::vector &errors, IDxcBlobEncoding **blob) { if (std::find(errors.begin(), errors.end(), pName) != errors.end()) { - dxc::DxcDllSupport dllSupport; + dxc::SpecificDllLoader dllSupport; VERIFY_SUCCEEDED(dllSupport.Initialize()); std::string error("bad define: "); error.append(pName); @@ -601,7 +601,7 @@ static std::string GetCompileErrors(IDxcOperationResult *pResult) { class Compiler { public: - Compiler(dxc::DxcDllSupport &dll) : m_dllSupport(dll) { + Compiler(dxc::SpecificDllLoader &dll) : m_dllSupport(dll) { VERIFY_SUCCEEDED(m_dllSupport.Initialize()); VERIFY_SUCCEEDED( m_dllSupport.CreateInstance(CLSID_DxcCompiler, &pCompiler)); @@ -654,7 +654,7 @@ class Compiler { return DisassembleProgram(m_dllSupport, pBlob); } - dxc::DxcDllSupport &m_dllSupport; + dxc::SpecificDllLoader &m_dllSupport; CComPtr pCompiler; CComPtr pLangExtensions; CComPtr pCodeBlob; @@ -677,7 +677,7 @@ class ExtensionTest : public ::testing::Test { TEST_METHOD_PROPERTY(L"Priority", L"0") END_TEST_CLASS() - dxc::DxcDllSupport m_dllSupport; + dxc::SpecificDllLoader m_dllSupport; TEST_METHOD(EvalAttributeCollision) TEST_METHOD(NoUnwind) diff --git a/tools/clang/unittests/HLSL/FunctionTest.cpp b/tools/clang/unittests/HLSL/FunctionTest.cpp index e8b087a369..3aa9c30f6b 100644 --- a/tools/clang/unittests/HLSL/FunctionTest.cpp +++ b/tools/clang/unittests/HLSL/FunctionTest.cpp @@ -36,7 +36,7 @@ class FunctionTest : public ::testing::Test { TEST_METHOD(AllowedInParamUsesClass) TEST_METHOD(ParseRootSignature) - dxc::DxcDllSupport m_support; + dxc::SpecificDllLoader m_support; std::vector rootSigText; std::string BuildSampleFunction(const char *StorageClassKeyword) { diff --git a/tools/clang/unittests/HLSL/LinkerTest.cpp b/tools/clang/unittests/HLSL/LinkerTest.cpp index df8bb644e1..30b449d3c1 100644 --- a/tools/clang/unittests/HLSL/LinkerTest.cpp +++ b/tools/clang/unittests/HLSL/LinkerTest.cpp @@ -80,7 +80,7 @@ class LinkerTest : public ::testing::Test { TEST_METHOD(RunLinkWithDxcResultRdat) TEST_METHOD(RunLinkWithDxcResultErrors) - dxc::DxcDllSupport m_dllSupport; + dxc::SpecificDllLoader m_dllSupport; VersionSupportInfo m_ver; void CreateLinker(IDxcLinker **pResultLinker) { diff --git a/tools/clang/unittests/HLSL/OptimizerTest.cpp b/tools/clang/unittests/HLSL/OptimizerTest.cpp index 42eff4b1a7..8e75d9398b 100644 --- a/tools/clang/unittests/HLSL/OptimizerTest.cpp +++ b/tools/clang/unittests/HLSL/OptimizerTest.cpp @@ -117,7 +117,7 @@ class OptimizerTest : public ::testing::Test { const wchar_t *profile, bool usesViewId, int streamCount = 1); - dxc::DxcDllSupport m_dllSupport; + dxc::SpecificDllLoader m_dllSupport; VersionSupportInfo m_ver; HRESULT CreateCompiler(IDxcCompiler **ppResult) { diff --git a/tools/clang/unittests/HLSL/PixDiaTest.cpp b/tools/clang/unittests/HLSL/PixDiaTest.cpp index a4439b998d..ea0fe7488e 100644 --- a/tools/clang/unittests/HLSL/PixDiaTest.cpp +++ b/tools/clang/unittests/HLSL/PixDiaTest.cpp @@ -84,7 +84,7 @@ const char *DataKindText[] = { "FileStatic", "Global", "Member", "StaticMember", "Constant", }; -static void CompileAndGetDebugPart(dxc::DxcDllSupport &dllSupport, +static void CompileAndGetDebugPart(dxc::SpecificDllLoader &dllSupport, const char *source, const wchar_t *profile, IDxcBlob **ppDebugPart) { CComPtr pContainer; @@ -199,7 +199,7 @@ class PixDiaTest { TEST_METHOD(DxcPixDxilDebugInfo_VariableScopes_Function) TEST_METHOD(DxcPixDxilDebugInfo_VariableScopes_Member) - dxc::DxcDllSupport m_dllSupport; + dxc::SpecificDllLoader m_dllSupport; VersionSupportInfo m_ver; void RunSubProgramsCase(const char *hlsl); @@ -639,12 +639,12 @@ class PixDiaTest { } void CompileAndRunAnnotationAndGetDebugPart( - dxc::DxcDllSupport &dllSupport, const char *source, + dxc::SpecificDllLoader &dllSupport, const char *source, const wchar_t *profile, IDxcIncludeHandler *includer, IDxcBlob **ppDebugPart, std::vector extraArgs = {L"-Od"}); void CompileAndRunAnnotationAndLoadDiaSource( - dxc::DxcDllSupport &dllSupport, const char *source, + dxc::SpecificDllLoader &dllSupport, const char *source, const wchar_t *profile, IDxcIncludeHandler *includer, IDiaDataSource **ppDataSource, std::vector extraArgs = {L"-Od"}); @@ -779,9 +779,9 @@ bool PixDiaTest::InitSupport() { } void PixDiaTest::CompileAndRunAnnotationAndGetDebugPart( - dxc::DxcDllSupport &dllSupport, const char *source, const wchar_t *profile, - IDxcIncludeHandler *includer, IDxcBlob **ppDebugPart, - std::vector extraArgs) { + dxc::SpecificDllLoader &dllSupport, const char *source, + const wchar_t *profile, IDxcIncludeHandler *includer, + IDxcBlob **ppDebugPart, std::vector extraArgs) { CComPtr pContainer; std::vector args; @@ -1020,7 +1020,7 @@ TEST_F(PixDiaTest, DiaLoadBadBitcodeThenFail) { VERIFY_FAILED(pDiaSource->loadDataFromIStream(pStream)); } -static void CompileTestAndLoadDiaSource(dxc::DxcDllSupport &dllSupport, +static void CompileTestAndLoadDiaSource(dxc::SpecificDllLoader &dllSupport, const char *source, const wchar_t *profile, IDiaDataSource **ppDataSource) { @@ -1040,7 +1040,7 @@ static void CompileTestAndLoadDiaSource(dxc::DxcDllSupport &dllSupport, } } -static void CompileTestAndLoadDia(dxc::DxcDllSupport &dllSupport, +static void CompileTestAndLoadDia(dxc::SpecificDllLoader &dllSupport, IDiaDataSource **ppDataSource) { CompileTestAndLoadDiaSource(dllSupport, "[numthreads(8,8,1)] void main() { }", L"cs_6_0", ppDataSource); @@ -1202,7 +1202,7 @@ TEST_F(PixDiaTest, DiaCompileArgs) { args.push_back(L"/D"); args.push_back(DefineList[i]); } - auto CompileAndGetDebugPart = [&args](dxc::DxcDllSupport &dllSupport, + auto CompileAndGetDebugPart = [&args](dxc::SpecificDllLoader &dllSupport, const char *source, const wchar_t *profile, IDxcBlob **ppDebugPart) { @@ -1462,7 +1462,7 @@ TEST_F(PixDiaTest, PixDebugCompileInfo) { args.push_back(DefineList[i]); } - auto CompileAndGetDebugPart = [&args](dxc::DxcDllSupport &dllSupport, + auto CompileAndGetDebugPart = [&args](dxc::SpecificDllLoader &dllSupport, const char *source, const wchar_t *profile, IDxcBlob **ppDebugPart) { @@ -1530,9 +1530,9 @@ TEST_F(PixDiaTest, PixDebugCompileInfo) { } void PixDiaTest::CompileAndRunAnnotationAndLoadDiaSource( - dxc::DxcDllSupport &dllSupport, const char *source, const wchar_t *profile, - IDxcIncludeHandler *includer, IDiaDataSource **ppDataSource, - std::vector extraArgs) { + dxc::SpecificDllLoader &dllSupport, const char *source, + const wchar_t *profile, IDxcIncludeHandler *includer, + IDiaDataSource **ppDataSource, std::vector extraArgs) { CComPtr pDebugContent; CComPtr pStream; CComPtr pDiaSource; diff --git a/tools/clang/unittests/HLSL/PixTest.cpp b/tools/clang/unittests/HLSL/PixTest.cpp index af7801c7bf..d103e23922 100644 --- a/tools/clang/unittests/HLSL/PixTest.cpp +++ b/tools/clang/unittests/HLSL/PixTest.cpp @@ -156,7 +156,7 @@ class PixTest : public ::testing::Test { TEST_METHOD(NonUniformResourceIndex_DescriptorHeap) TEST_METHOD(NonUniformResourceIndex_Raytracing) - dxc::DxcDllSupport m_dllSupport; + dxc::SpecificDllLoader m_dllSupport; VersionSupportInfo m_ver; HRESULT CreateContainerBuilder(IDxcContainerBuilder **ppResult) { diff --git a/tools/clang/unittests/HLSL/PixTestUtils.cpp b/tools/clang/unittests/HLSL/PixTestUtils.cpp index 61647ff5fa..3a1debae6c 100644 --- a/tools/clang/unittests/HLSL/PixTestUtils.cpp +++ b/tools/clang/unittests/HLSL/PixTestUtils.cpp @@ -166,7 +166,8 @@ DxilRegisterToNameMap BuildDxilRegisterToNameMap(char const *disassembly) { return ret; } -std::wstring Disassemble(dxc::DxcDllSupport &dllSupport, IDxcBlob *pProgram) { +std::wstring Disassemble(dxc::SpecificDllLoader &dllSupport, + IDxcBlob *pProgram) { CComPtr pCompiler; VERIFY_SUCCEEDED(pix_test::CreateCompiler(dllSupport, &pCompiler)); @@ -182,7 +183,7 @@ std::wstring Disassemble(dxc::DxcDllSupport &dllSupport, IDxcBlob *pProgram) { // For CreateBlobFromText namespace { -void CreateBlobPinned(dxc::DxcDllSupport &dllSupport, +void CreateBlobPinned(dxc::SpecificDllLoader &dllSupport, _In_bytecount_(size) LPCVOID data, SIZE_T size, UINT32 codePage, IDxcBlobEncoding **ppBlob) { CComPtr library; @@ -215,7 +216,7 @@ std::vector SplitAndPreserveEmptyLines(std::string const &str, return lines; } -void CompileAndLogErrors(dxc::DxcDllSupport &dllSupport, LPCSTR pText, +void CompileAndLogErrors(dxc::SpecificDllLoader &dllSupport, LPCSTR pText, LPCWSTR pTargetProfile, std::vector &args, IDxcIncludeHandler *includer, _Outptr_ IDxcBlob **ppResult) { @@ -241,8 +242,8 @@ void CompileAndLogErrors(dxc::DxcDllSupport &dllSupport, LPCSTR pText, VERIFY_SUCCEEDED(pResult->GetResult(ppResult)); } -PassOutput RunAnnotationPasses(dxc::DxcDllSupport &dllSupport, IDxcBlob *dxil, - int startingLineNumber) { +PassOutput RunAnnotationPasses(dxc::SpecificDllLoader &dllSupport, + IDxcBlob *dxil, int startingLineNumber) { CComPtr pOptimizer; VERIFY_SUCCEEDED(dllSupport.CreateInstance(CLSID_DxcOptimizer, &pOptimizer)); std::vector Options; @@ -334,7 +335,7 @@ GatherDebugLocLabelsFromDxcUtils(DebuggerInterfaces &debuggerInterfaces) { return std::make_unique(debuggerInterfaces); } -CComPtr GetDebugPart(dxc::DxcDllSupport &dllSupport, +CComPtr GetDebugPart(dxc::SpecificDllLoader &dllSupport, IDxcBlob *container) { CComPtr pLib; @@ -355,17 +356,17 @@ CComPtr GetDebugPart(dxc::DxcDllSupport &dllSupport, return debugPart; } -void CreateBlobFromText(dxc::DxcDllSupport &dllSupport, const char *pText, +void CreateBlobFromText(dxc::SpecificDllLoader &dllSupport, const char *pText, IDxcBlobEncoding **ppBlob) { CreateBlobPinned(dllSupport, pText, strlen(pText) + 1, CP_UTF8, ppBlob); } -HRESULT CreateCompiler(dxc::DxcDllSupport &dllSupport, +HRESULT CreateCompiler(dxc::SpecificDllLoader &dllSupport, IDxcCompiler **ppResult) { return dllSupport.CreateInstance(CLSID_DxcCompiler, ppResult); } -CComPtr Compile(dxc::DxcDllSupport &dllSupport, const char *hlsl, +CComPtr Compile(dxc::SpecificDllLoader &dllSupport, const char *hlsl, const wchar_t *target, std::vector extraArgs, const wchar_t *entry) { @@ -428,7 +429,7 @@ CComPtr Compile(dxc::DxcDllSupport &dllSupport, const char *hlsl, return pProgram; } -CComPtr WrapInNewContainer(dxc::DxcDllSupport &dllSupport, +CComPtr WrapInNewContainer(dxc::SpecificDllLoader &dllSupport, IDxcBlob *part) { CComPtr pAssembler; IFT(dllSupport.CreateInstance(CLSID_DxcAssembler, &pAssembler)); diff --git a/tools/clang/unittests/HLSL/PixTestUtils.h b/tools/clang/unittests/HLSL/PixTestUtils.h index 8f7d0cdf45..ece5c64137 100644 --- a/tools/clang/unittests/HLSL/PixTestUtils.h +++ b/tools/clang/unittests/HLSL/PixTestUtils.h @@ -19,7 +19,7 @@ #include namespace dxc { -class DxcDllSupport; +class SpecificDllLoader; } namespace pix_test { @@ -27,23 +27,24 @@ namespace pix_test { std::vector SplitAndPreserveEmptyLines(std::string const &str, char delimeter); -CComPtr GetDebugPart(dxc::DxcDllSupport &dllSupport, +CComPtr GetDebugPart(dxc::SpecificDllLoader &dllSupport, IDxcBlob *container); -void CreateBlobFromText(dxc::DxcDllSupport &dllSupport, const char *pText, +void CreateBlobFromText(dxc::SpecificDllLoader &dllSupport, const char *pText, IDxcBlobEncoding **ppBlob); -HRESULT CreateCompiler(dxc::DxcDllSupport &dllSupport, IDxcCompiler **ppResult); -CComPtr Compile(dxc::DxcDllSupport &dllSupport, const char *hlsl, +HRESULT CreateCompiler(dxc::SpecificDllLoader &dllSupport, + IDxcCompiler **ppResult); +CComPtr Compile(dxc::SpecificDllLoader &dllSupport, const char *hlsl, const wchar_t *target, std::vector extraArgs = {}, const wchar_t *entry = L"main"); -void CompileAndLogErrors(dxc::DxcDllSupport &dllSupport, LPCSTR pText, +void CompileAndLogErrors(dxc::SpecificDllLoader &dllSupport, LPCSTR pText, LPCWSTR pTargetProfile, std::vector &args, IDxcIncludeHandler *includer, _Outptr_ IDxcBlob **ppResult); -CComPtr WrapInNewContainer(dxc::DxcDllSupport &dllSupport, +CComPtr WrapInNewContainer(dxc::SpecificDllLoader &dllSupport, IDxcBlob *part); struct ValueLocation { @@ -56,8 +57,8 @@ struct PassOutput { std::vector lines; }; -PassOutput RunAnnotationPasses(dxc::DxcDllSupport &dllSupport, IDxcBlob *dxil, - int startingLineNumber = 0); +PassOutput RunAnnotationPasses(dxc::SpecificDllLoader &dllSupport, + IDxcBlob *dxil, int startingLineNumber = 0); struct DebuggerInterfaces { CComPtr debugInfo; diff --git a/tools/clang/unittests/HLSL/RewriterTest.cpp b/tools/clang/unittests/HLSL/RewriterTest.cpp index 613c8561a3..ebee433564 100644 --- a/tools/clang/unittests/HLSL/RewriterTest.cpp +++ b/tools/clang/unittests/HLSL/RewriterTest.cpp @@ -103,7 +103,7 @@ class RewriterTest : public ::testing::Test { TEST_METHOD(RunGlobalsUsedInMethod) TEST_METHOD(RunRewriterFails) - dxc::DxcDllSupport m_dllSupport; + dxc::SpecificDllLoader m_dllSupport; CComPtr m_pIncludeHandler; struct VerifyResult { @@ -173,7 +173,7 @@ class RewriterTest : public ::testing::Test { struct FileWithBlob { CComPtr BlobEncoding; - FileWithBlob(dxc::DxcDllSupport &support, LPCWSTR path) { + FileWithBlob(dxc::SpecificDllLoader &support, LPCWSTR path) { CComPtr library; IFT(support.CreateInstance(CLSID_DxcLibrary, &library)); UINT32 codePage = CP_UTF8; diff --git a/tools/clang/unittests/HLSL/SystemValueTest.cpp b/tools/clang/unittests/HLSL/SystemValueTest.cpp index be29612890..a5d1f076a6 100644 --- a/tools/clang/unittests/HLSL/SystemValueTest.cpp +++ b/tools/clang/unittests/HLSL/SystemValueTest.cpp @@ -198,7 +198,7 @@ class SystemValueTest : public ::testing::Test { VERIFY_IS_TRUE(bMessageFound); } - dxc::DxcDllSupport m_dllSupport; + dxc::SpecificDllLoader m_dllSupport; VersionSupportInfo m_ver; unsigned m_HighestMajor, m_HighestMinor; // Shader Model Supported diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp index ed9df41980..6aa826a3ae 100644 --- a/tools/clang/unittests/HLSL/ValidationTest.cpp +++ b/tools/clang/unittests/HLSL/ValidationTest.cpp @@ -331,7 +331,7 @@ class ValidationTest : public ::testing::Test { TEST_METHOD(WrongPSVSizeOnZeros) TEST_METHOD(WrongPSVVersion) - dxc::DxcDllSupport m_dllSupport; + dxc::SpecificDllLoader m_dllSupport; VersionSupportInfo m_ver; void TestCheck(LPCWSTR name) { @@ -4235,8 +4235,8 @@ void SetEnvVarW(const std::wstring &VarName, const std::wstring &VarValue) { // works as intended. TEST_F(ValidationTest, UnitTestExtValidationSupport) { - dxc::DxcDllExtValidationSupport ExtSupportEmpty; - dxc::DxcDllExtValidationSupport ExtSupportBogus; + dxc::DxcDllExtValidationLoader ExtSupportEmpty; + dxc::DxcDllExtValidationLoader ExtSupportBogus; // capture any existing value in the environment variable, // so that it can be restored after the test diff --git a/tools/clang/unittests/HLSLExec/ExecutionTest.cpp b/tools/clang/unittests/HLSLExec/ExecutionTest.cpp index 6db27d7a41..a9e93fca19 100644 --- a/tools/clang/unittests/HLSLExec/ExecutionTest.cpp +++ b/tools/clang/unittests/HLSLExec/ExecutionTest.cpp @@ -501,7 +501,7 @@ class ExecutionTest { L"Table:ShaderOpArithTable.xml#PackUnpackOpTable") END_TEST_METHOD() - dxc::DxcDllSupport m_support; + dxc::SpecificDllLoader m_support; bool m_D3DInitCompleted = false; bool m_ExperimentalModeEnabled = false; @@ -3505,8 +3505,8 @@ struct SPrimitives { }; std::shared_ptr -RunShaderOpTestAfterParse(ID3D12Device *pDevice, dxc::DxcDllSupport &support, - LPCSTR pName, +RunShaderOpTestAfterParse(ID3D12Device *pDevice, + dxc::SpecificDllLoader &support, LPCSTR pName, st::ShaderOpTest::TInitCallbackFn pInitCallback, st::ShaderOpTest::TShaderCallbackFn pShaderCallback, std::shared_ptr ShaderOpSet) { @@ -3537,7 +3537,7 @@ RunShaderOpTestAfterParse(ID3D12Device *pDevice, dxc::DxcDllSupport &support, pShaderOp->UseWarpDevice = GetTestParamUseWARP(true); std::shared_ptr test = std::make_shared(); - test->SetDxcSupport(&support); + test->SetSpecificDllLoader(&support); test->SetInitCallback(pInitCallback); test->SetShaderCallback(pShaderCallback); test->SetDevice(pDevice); @@ -3552,8 +3552,8 @@ RunShaderOpTestAfterParse(ID3D12Device *pDevice, dxc::DxcDllSupport &support, } std::shared_ptr -RunShaderOpTestAfterParse(ID3D12Device *pDevice, dxc::DxcDllSupport &support, - LPCSTR pName, +RunShaderOpTestAfterParse(ID3D12Device *pDevice, + dxc::SpecificDllLoader &support, LPCSTR pName, st::ShaderOpTest::TInitCallbackFn pInitCallback, std::shared_ptr ShaderOpSet) { return RunShaderOpTestAfterParse(pDevice, support, pName, pInitCallback, @@ -3561,7 +3561,7 @@ RunShaderOpTestAfterParse(ID3D12Device *pDevice, dxc::DxcDllSupport &support, } std::shared_ptr -RunShaderOpTest(ID3D12Device *pDevice, dxc::DxcDllSupport &support, +RunShaderOpTest(ID3D12Device *pDevice, dxc::SpecificDllLoader &support, IStream *pStream, LPCSTR pName, st::ShaderOpTest::TInitCallbackFn pInitCallback) { DXASSERT_NOMSG(pStream != nullptr); @@ -3814,13 +3814,13 @@ struct Dispatch { }; std::shared_ptr RunDispatch(ID3D12Device *pDevice, - dxc::DxcDllSupport &support, + dxc::SpecificDllLoader &support, st::ShaderOp *pShaderOp, const Dispatch D) { char compilerOptions[256]; std::shared_ptr test = std::make_shared(); - test->SetDxcSupport(&support); + test->SetSpecificDllLoader(&support); test->SetInitCallback(nullptr); test->SetDevice(pDevice); @@ -11550,7 +11550,7 @@ TEST_F(ExecutionTest, DynamicResourcesDynamicIndexingTest) { void RunWaveSizeTest(UINT minWaveSize, UINT maxWaveSize, std::shared_ptr ShaderOpSet, CComPtr pDevice, - dxc::DxcDllSupport &m_support) { + dxc::SpecificDllLoader &m_support) { // format shader source const char waveSizeTestShader[] = R"(struct TestData { @@ -11619,7 +11619,7 @@ bool TestShaderRangeAgainstRequirements(UINT shaderminws, UINT shadermaxws, void ExecuteWaveSizeRangeInstance(UINT minWaveSize, UINT maxWaveSize, std::shared_ptr ShaderOpSet, CComPtr pDevice, - dxc::DxcDllSupport &m_support, + dxc::SpecificDllLoader &m_support, UINT minShaderWaveSize, UINT maxShaderWaveSize, UINT prefShaderWaveSize, bool usePreferred) { @@ -11702,7 +11702,7 @@ void ExecuteWaveSizeRangeInstance(UINT minWaveSize, UINT maxWaveSize, void RunWaveSizeRangeTest(UINT minWaveSize, UINT maxWaveSize, std::shared_ptr ShaderOpSet, CComPtr pDevice, - dxc::DxcDllSupport &m_support) { + dxc::SpecificDllLoader &m_support) { for (UINT minShaderWaveSize = 4; minShaderWaveSize <= maxWaveSize; minShaderWaveSize *= 2) { @@ -13206,7 +13206,7 @@ TEST_F(ExecutionTest, QuadAnyAll) { // input string pointers. st::ShaderOpTest::TShaderCallbackFn MakeShaderReplacementCallback( std::vector dxcArgs, std::vector lookFors, - std::vector replacements, dxc::DxcDllSupport &dllSupport) { + std::vector replacements, dxc::SpecificDllLoader &dllSupport) { auto ShaderInitFn = [dxcArgs, lookFors, replacements, &dllSupport]( LPCSTR Name, LPCSTR pText, IDxcBlob **ppShaderBlob, @@ -13521,7 +13521,7 @@ __declspec(dllexport) HRESULT WINAPI pOutputStrFn(pStrCtx, L"Unable to enable info queue for D3D.\r\n."); } try { - dxc::DxcDllSupport m_support; + dxc::SpecificDllLoader m_support; m_support.Initialize(); const char *pName = nullptr; @@ -13557,7 +13557,7 @@ __declspec(dllexport) HRESULT WINAPI std::shared_ptr test = std::make_shared(); test->SetupRenderTarget(pShaderOp, pDevice, pCommandQueue, pRenderTarget); - test->SetDxcSupport(&m_support); + test->SetSpecificDllLoader(&m_support); test->RunShaderOp(pShaderOp); test->PresentRenderTarget(pShaderOp, pCommandQueue, pRenderTarget); diff --git a/tools/clang/unittests/HLSLExec/ShaderOpTest.cpp b/tools/clang/unittests/HLSLExec/ShaderOpTest.cpp index 8dde3faa0b..6ca9550a00 100644 --- a/tools/clang/unittests/HLSLExec/ShaderOpTest.cpp +++ b/tools/clang/unittests/HLSLExec/ShaderOpTest.cpp @@ -25,7 +25,7 @@ #include "HlslTestUtils.h" // LogCommentFmt #include "dxc/DXIL/DxilConstants.h" // ComponentType #include "dxc/Support/Global.h" // OutputDebugBytes -#include "dxc/Support/dxcapi.use.h" // DxcDllSupport +#include "dxc/Support/dxcapi.use.h" // SpecificDllLoader #include "dxc/dxcapi.h" // IDxcCompiler #include @@ -1143,7 +1143,7 @@ void ShaderOpTest::SetRootValues(ID3D12GraphicsCommandList *pList, void ShaderOpTest::SetDevice(ID3D12Device *pDevice) { m_pDevice = pDevice; } -void ShaderOpTest::SetDxcSupport(dxc::DxcDllSupport *pDxcSupport) { +void ShaderOpTest::SetSpecificDllLoader(dxc::SpecificDllLoader *pDxcSupport) { m_pDxcSupport = pDxcSupport; } diff --git a/tools/clang/unittests/HLSLExec/ShaderOpTest.h b/tools/clang/unittests/HLSLExec/ShaderOpTest.h index b71ee08765..d1ed909814 100644 --- a/tools/clang/unittests/HLSLExec/ShaderOpTest.h +++ b/tools/clang/unittests/HLSLExec/ShaderOpTest.h @@ -31,7 +31,7 @@ /////////////////////////////////////////////////////////////////////////////// // Forward declarations. namespace dxc { -class DxcDllSupport; +class SpecificDllLoader; } struct IStream; struct IXmlReader; @@ -283,7 +283,7 @@ class ShaderOpTest { void RunShaderOp(ShaderOp *pShaderOp); void RunShaderOp(std::shared_ptr pShaderOp); void SetDevice(ID3D12Device *pDevice); - void SetDxcSupport(dxc::DxcDllSupport *pDxcSupport); + void SetSpecificDllLoader(dxc::SpecificDllLoader *pDxcSupport); void SetInitCallback(TInitCallbackFn InitCallbackFn); void SetShaderCallback(TShaderCallbackFn ShaderCallbackFn); void SetupRenderTarget(ShaderOp *pShaderOp, ID3D12Device *pDevice, @@ -313,7 +313,7 @@ class ShaderOpTest { CComPtr m_pRootSignature; CComPtr m_pQueryHeap; CComPtr m_pQueryBuffer; - dxc::DxcDllSupport *m_pDxcSupport = nullptr; + dxc::SpecificDllLoader *m_pDxcSupport = nullptr; CommandListRefs m_CommandList; HANDLE m_hFence; ShaderOp *m_pShaderOp; diff --git a/tools/clang/unittests/HLSLTestLib/DxcTestUtils.cpp b/tools/clang/unittests/HLSLTestLib/DxcTestUtils.cpp index 7e59b8f10f..177f37c97b 100644 --- a/tools/clang/unittests/HLSLTestLib/DxcTestUtils.cpp +++ b/tools/clang/unittests/HLSLTestLib/DxcTestUtils.cpp @@ -173,7 +173,7 @@ bool CheckOperationResultMsgs(IDxcOperationResult *pResult, maySucceedAnyway, bRegex); } -std::string DisassembleProgram(dxc::DxcDllSupport &dllSupport, +std::string DisassembleProgram(dxc::SpecificDllLoader &dllSupport, IDxcBlob *pProgram) { CComPtr pCompiler; CComPtr pDisassembly; @@ -187,7 +187,7 @@ std::string DisassembleProgram(dxc::DxcDllSupport &dllSupport, return BlobToUtf8(pDisassembly); } -void AssembleToContainer(dxc::DxcDllSupport &dllSupport, IDxcBlob *pModule, +void AssembleToContainer(dxc::SpecificDllLoader &dllSupport, IDxcBlob *pModule, IDxcBlob **pContainer) { CComPtr pAssembler; CComPtr pResult; @@ -302,7 +302,7 @@ std::wstring BlobToWide(IDxcBlob *pBlob) { } } -void Utf8ToBlob(dxc::DxcDllSupport &dllSupport, const char *pVal, +void Utf8ToBlob(dxc::SpecificDllLoader &dllSupport, const char *pVal, IDxcBlobEncoding **ppBlob) { CComPtr library; IFT(dllSupport.CreateInstance(CLSID_DxcLibrary, &library)); @@ -310,7 +310,7 @@ void Utf8ToBlob(dxc::DxcDllSupport &dllSupport, const char *pVal, ppBlob)); } -void MultiByteStringToBlob(dxc::DxcDllSupport &dllSupport, +void MultiByteStringToBlob(dxc::SpecificDllLoader &dllSupport, const std::string &val, UINT32 codePage, IDxcBlobEncoding **ppBlob) { CComPtr library; @@ -319,23 +319,23 @@ void MultiByteStringToBlob(dxc::DxcDllSupport &dllSupport, codePage, ppBlob)); } -void MultiByteStringToBlob(dxc::DxcDllSupport &dllSupport, +void MultiByteStringToBlob(dxc::SpecificDllLoader &dllSupport, const std::string &val, UINT32 codePage, IDxcBlob **ppBlob) { MultiByteStringToBlob(dllSupport, val, codePage, (IDxcBlobEncoding **)ppBlob); } -void Utf8ToBlob(dxc::DxcDllSupport &dllSupport, const std::string &val, +void Utf8ToBlob(dxc::SpecificDllLoader &dllSupport, const std::string &val, IDxcBlobEncoding **ppBlob) { MultiByteStringToBlob(dllSupport, val, CP_UTF8, ppBlob); } -void Utf8ToBlob(dxc::DxcDllSupport &dllSupport, const std::string &val, +void Utf8ToBlob(dxc::SpecificDllLoader &dllSupport, const std::string &val, IDxcBlob **ppBlob) { Utf8ToBlob(dllSupport, val, (IDxcBlobEncoding **)ppBlob); } -void WideToBlob(dxc::DxcDllSupport &dllSupport, const std::wstring &val, +void WideToBlob(dxc::SpecificDllLoader &dllSupport, const std::wstring &val, IDxcBlobEncoding **ppBlob) { CComPtr library; IFT(dllSupport.CreateInstance(CLSID_DxcLibrary, &library)); @@ -343,12 +343,12 @@ void WideToBlob(dxc::DxcDllSupport &dllSupport, const std::wstring &val, val.data(), val.size() * sizeof(wchar_t), DXC_CP_WIDE, ppBlob)); } -void WideToBlob(dxc::DxcDllSupport &dllSupport, const std::wstring &val, +void WideToBlob(dxc::SpecificDllLoader &dllSupport, const std::wstring &val, IDxcBlob **ppBlob) { WideToBlob(dllSupport, val, (IDxcBlobEncoding **)ppBlob); } -void VerifyCompileOK(dxc::DxcDllSupport &dllSupport, LPCSTR pText, +void VerifyCompileOK(dxc::SpecificDllLoader &dllSupport, LPCSTR pText, LPCWSTR pTargetProfile, LPCWSTR pArgs, IDxcBlob **ppResult) { std::vector argsW; @@ -363,7 +363,7 @@ void VerifyCompileOK(dxc::DxcDllSupport &dllSupport, LPCSTR pText, VerifyCompileOK(dllSupport, pText, pTargetProfile, args, ppResult); } -void VerifyCompileOK(dxc::DxcDllSupport &dllSupport, LPCSTR pText, +void VerifyCompileOK(dxc::SpecificDllLoader &dllSupport, LPCSTR pText, LPCWSTR pTargetProfile, std::vector &args, IDxcBlob **ppResult) { CComPtr pCompiler; @@ -381,7 +381,7 @@ void VerifyCompileOK(dxc::DxcDllSupport &dllSupport, LPCSTR pText, VERIFY_SUCCEEDED(pResult->GetResult(ppResult)); } -HRESULT GetVersion(dxc::DxcDllSupport &DllSupport, REFCLSID clsid, +HRESULT GetVersion(dxc::SpecificDllLoader &DllSupport, REFCLSID clsid, unsigned &Major, unsigned &Minor) { CComPtr pUnk; if (SUCCEEDED(DllSupport.CreateInstance(clsid, &pUnk))) { @@ -418,7 +418,7 @@ VersionSupportInfo::VersionSupportInfo() : m_CompilerIsDebugBuild(false), m_InternalValidator(false), m_DxilMajor(0), m_DxilMinor(0), m_ValMajor(0), m_ValMinor(0) {} -void VersionSupportInfo::Initialize(dxc::DxcDllSupport &dllSupport) { +void VersionSupportInfo::Initialize(dxc::SpecificDllLoader &dllSupport) { VERIFY_IS_TRUE(dllSupport.IsEnabled()); // Default to Dxil 1.0 and internal Val 1.0 diff --git a/tools/clang/unittests/HLSLTestLib/FileCheckerTest.cpp b/tools/clang/unittests/HLSLTestLib/FileCheckerTest.cpp index 2c75d45e5e..f2927161d0 100644 --- a/tools/clang/unittests/HLSLTestLib/FileCheckerTest.cpp +++ b/tools/clang/unittests/HLSLTestLib/FileCheckerTest.cpp @@ -59,7 +59,7 @@ FileRunCommandPart::FileRunCommandPart(const std::string &command, } FileRunCommandResult -FileRunCommandPart::RunHashTests(dxc::DxcDllSupport &DllSupport) { +FileRunCommandPart::RunHashTests(dxc::SpecificDllLoader &DllSupport) { if (0 == _stricmp(Command.c_str(), "%dxc")) { return RunDxcHashTest(DllSupport); } else { @@ -68,7 +68,7 @@ FileRunCommandPart::RunHashTests(dxc::DxcDllSupport &DllSupport) { } FileRunCommandResult -FileRunCommandPart::Run(dxc::DxcDllSupport &DllSupport, +FileRunCommandPart::Run(dxc::SpecificDllLoader &DllSupport, const FileRunCommandResult *Prior, PluginToolsPaths *pPluginToolsPaths /*=nullptr*/, LPCWSTR dumpName /*=nullptr*/) { @@ -302,7 +302,7 @@ static void AddOutputsToFileMap(IUnknown *pUnkResult, FileMap *pVFS) { static HRESULT CompileForHash(hlsl::options::DxcOpts &opts, LPCWSTR CommandFileName, - dxc::DxcDllSupport &DllSupport, + dxc::SpecificDllLoader &DllSupport, std::vector &flags, IDxcBlob **ppHashBlob, std::string &output) { CComPtr pLibrary; @@ -375,7 +375,7 @@ static HRESULT CompileForHash(hlsl::options::DxcOpts &opts, } FileRunCommandResult -FileRunCommandPart::RunDxcHashTest(dxc::DxcDllSupport &DllSupport) { +FileRunCommandPart::RunDxcHashTest(dxc::SpecificDllLoader &DllSupport) { hlsl::options::MainArgs args; hlsl::options::DxcOpts opts; ReadOptsForDxc(args, opts); @@ -453,7 +453,7 @@ FileRunCommandPart::RunDxcHashTest(dxc::DxcDllSupport &DllSupport) { return FileRunCommandResult::Success(); } -static FileRunCommandResult CheckDxilVer(dxc::DxcDllSupport &DllSupport, +static FileRunCommandResult CheckDxilVer(dxc::SpecificDllLoader &DllSupport, unsigned RequiredDxilMajor, unsigned RequiredDxilMinor, bool bCheckValidator = true) { @@ -487,7 +487,7 @@ static FileRunCommandResult CheckDxilVer(dxc::DxcDllSupport &DllSupport, } FileRunCommandResult -FileRunCommandPart::RunDxc(dxc::DxcDllSupport &DllSupport, +FileRunCommandPart::RunDxc(dxc::SpecificDllLoader &DllSupport, const FileRunCommandResult *Prior) { // Support piping stdin from prior if needed. UNREFERENCED_PARAMETER(Prior); @@ -604,7 +604,7 @@ FileRunCommandPart::RunDxc(dxc::DxcDllSupport &DllSupport, } FileRunCommandResult -FileRunCommandPart::RunDxv(dxc::DxcDllSupport &DllSupport, +FileRunCommandPart::RunDxv(dxc::SpecificDllLoader &DllSupport, const FileRunCommandResult *Prior) { std::string args(strtrim(Arguments)); const char *inputPos = strstr(args.c_str(), "%s"); @@ -657,7 +657,7 @@ FileRunCommandPart::RunDxv(dxc::DxcDllSupport &DllSupport, } FileRunCommandResult -FileRunCommandPart::RunOpt(dxc::DxcDllSupport &DllSupport, +FileRunCommandPart::RunOpt(dxc::SpecificDllLoader &DllSupport, const FileRunCommandResult *Prior) { std::string args(strtrim(Arguments)); const char *inputPos = strstr(args.c_str(), "%s"); @@ -708,7 +708,7 @@ FileRunCommandPart::RunOpt(dxc::DxcDllSupport &DllSupport, } FileRunCommandResult -FileRunCommandPart::RunListParts(dxc::DxcDllSupport &DllSupport, +FileRunCommandPart::RunListParts(dxc::SpecificDllLoader &DllSupport, const FileRunCommandResult *Prior) { std::string args(strtrim(Arguments)); const char *inputPos = strstr(args.c_str(), "%s"); @@ -776,7 +776,7 @@ FileRunCommandPart::RunListParts(dxc::DxcDllSupport &DllSupport, } FileRunCommandResult -FileRunCommandPart::RunD3DReflect(dxc::DxcDllSupport &DllSupport, +FileRunCommandPart::RunD3DReflect(dxc::SpecificDllLoader &DllSupport, const FileRunCommandResult *Prior) { std::string args(strtrim(Arguments)); if (args != "%s") @@ -872,7 +872,7 @@ FileRunCommandPart::RunD3DReflect(dxc::DxcDllSupport &DllSupport, } FileRunCommandResult -FileRunCommandPart::RunDxr(dxc::DxcDllSupport &DllSupport, +FileRunCommandPart::RunDxr(dxc::SpecificDllLoader &DllSupport, const FileRunCommandResult *Prior) { // Support piping stdin from prior if needed. UNREFERENCED_PARAMETER(Prior); @@ -925,7 +925,7 @@ FileRunCommandPart::RunDxr(dxc::DxcDllSupport &DllSupport, } FileRunCommandResult -FileRunCommandPart::RunLink(dxc::DxcDllSupport &DllSupport, +FileRunCommandPart::RunLink(dxc::SpecificDllLoader &DllSupport, const FileRunCommandResult *Prior) { hlsl::options::MainArgs args; hlsl::options::DxcOpts opts; @@ -1160,7 +1160,7 @@ FileRunCommandPart::RunXFail(const FileRunCommandResult *Prior) { } FileRunCommandResult -FileRunCommandPart::RunDxilVer(dxc::DxcDllSupport &DllSupport, +FileRunCommandPart::RunDxilVer(dxc::SpecificDllLoader &DllSupport, const FileRunCommandResult *Prior) { Arguments = strtrim(Arguments); if (Arguments.size() != 3 || !std::isdigit(Arguments[0]) || @@ -1265,7 +1265,7 @@ FileRunCommandPart::RunFromPath(const std::string &toolPath, #endif //_WIN32 class FileRunTestResultImpl : public FileRunTestResult { - dxc::DxcDllSupport &m_support; + dxc::SpecificDllLoader &m_support; PluginToolsPaths *m_pPluginToolsPaths; LPCWSTR m_dumpName = nullptr; // keep track of virtual files for duration of this test (for all RUN lines) @@ -1339,7 +1339,7 @@ class FileRunTestResultImpl : public FileRunTestResult { } public: - FileRunTestResultImpl(dxc::DxcDllSupport &support, + FileRunTestResultImpl(dxc::SpecificDllLoader &support, PluginToolsPaths *pPluginToolsPaths = nullptr, LPCWSTR dumpName = nullptr) : m_support(support), m_pPluginToolsPaths(pPluginToolsPaths), @@ -1378,7 +1378,7 @@ class FileRunTestResultImpl : public FileRunTestResult { FileRunTestResult FileRunTestResult::RunHashTestFromFileCommands(LPCWSTR fileName) { - dxc::DxcDllSupport dllSupport; + dxc::SpecificDllLoader dllSupport; IFT(dllSupport.Initialize()); FileRunTestResultImpl result(dllSupport); result.RunHashTestFromFileCommands(fileName); @@ -1388,7 +1388,7 @@ FileRunTestResult::RunHashTestFromFileCommands(LPCWSTR fileName) { FileRunTestResult FileRunTestResult::RunFromFileCommands( LPCWSTR fileName, PluginToolsPaths *pPluginToolsPaths /*=nullptr*/, LPCWSTR dumpName /*=nullptr*/) { - dxc::DxcDllSupport dllSupport; + dxc::SpecificDllLoader dllSupport; IFT(dllSupport.Initialize()); FileRunTestResultImpl result(dllSupport, pPluginToolsPaths, dumpName); result.RunFileCheckFromFileCommands(fileName); @@ -1396,7 +1396,7 @@ FileRunTestResult FileRunTestResult::RunFromFileCommands( } FileRunTestResult FileRunTestResult::RunFromFileCommands( - LPCWSTR fileName, dxc::DxcDllSupport &dllSupport, + LPCWSTR fileName, dxc::SpecificDllLoader &dllSupport, PluginToolsPaths *pPluginToolsPaths /*=nullptr*/, LPCWSTR dumpName /*=nullptr*/) { FileRunTestResultImpl result(dllSupport, pPluginToolsPaths, dumpName); diff --git a/tools/clang/unittests/SPIRV/LibTestUtils.cpp b/tools/clang/unittests/SPIRV/LibTestUtils.cpp index a5ec27977b..d3719d7e83 100644 --- a/tools/clang/unittests/SPIRV/LibTestUtils.cpp +++ b/tools/clang/unittests/SPIRV/LibTestUtils.cpp @@ -130,7 +130,7 @@ bool compileCodeWithSpirvGeneration(const llvm::StringRef code, rest.emplace_back(arg.begin(), arg.end()); try { - dxc::DxcDllSupport dllSupport; + dxc::SpecificDllLoader dllSupport; IFT(dllSupport.Initialize()); if (hlsl::options::initHlslOptTable()) diff --git a/tools/clang/unittests/dxc_batch/dxc_batch.cpp b/tools/clang/unittests/dxc_batch/dxc_batch.cpp index 1c3c86b46f..29df47c615 100644 --- a/tools/clang/unittests/dxc_batch/dxc_batch.cpp +++ b/tools/clang/unittests/dxc_batch/dxc_batch.cpp @@ -68,7 +68,7 @@ class DxcContext { private: DxcOpts &m_Opts; - DxcDllSupport &m_dxcSupport; + SpecificDllLoader &m_dxcSupport; int ActOnBlob(IDxcBlob *pBlob); int ActOnBlob(IDxcBlob *pBlob, IDxcBlob *pDebugBlob, LPCWSTR pDebugBlobName); @@ -83,7 +83,7 @@ class DxcContext { int VerifyRootSignature(); public: - DxcContext(DxcOpts &Opts, DxcDllSupport &dxcSupport) + DxcContext(DxcOpts &Opts, SpecificDllLoader &dxcSupport) : m_Opts(Opts), m_dxcSupport(dxcSupport) {} int Compile(llvm::StringRef path, bool bLibLink); @@ -124,7 +124,7 @@ static void PrintHlslException(const ::hlsl::Exception &hlslException, } } -static int Compile(llvm::StringRef command, DxcDllSupport &dxcSupport, +static int Compile(llvm::StringRef command, SpecificDllLoader &dxcSupport, llvm::StringRef path, bool bLinkLib, std::string &errorString) { // llvm::raw_string_ostream &errorStream) { @@ -756,14 +756,14 @@ void DxcContext::WriteHeader(IDxcBlobEncoding *pDisassembly, IDxcBlob *pCode, class DxcBatchContext { public: - DxcBatchContext(DxcOpts &Opts, DxcDllSupport &dxcSupport) + DxcBatchContext(DxcOpts &Opts, SpecificDllLoader &dxcSupport) : m_Opts(Opts), m_dxcSupport(dxcSupport) {} int BatchCompile(bool bMultiThread, bool bLibLink); private: DxcOpts &m_Opts; - DxcDllSupport &m_dxcSupport; + SpecificDllLoader &m_dxcSupport; }; int DxcBatchContext::BatchCompile(bool bMultiThread, bool bLibLink) { @@ -880,7 +880,7 @@ int __cdecl wmain(int argc, const wchar_t **argv_) { MainArgs batchArgStrings(refArgs); DxcOpts dxcOpts; - DxcDllSupport dxcSupport; + SpecificDllLoader dxcSupport; // Read options and check errors. { @@ -913,7 +913,8 @@ int __cdecl wmain(int argc, const wchar_t **argv_) { { std::string dllErrorString; llvm::raw_string_ostream dllErrorStream(dllErrorString); - int dllResult = SetupDxcDllSupport(dxcOpts, dxcSupport, dllErrorStream); + int dllResult = + SetupSpecificDllLoader(dxcOpts, dxcSupport, dllErrorStream); dllErrorStream.flush(); if (dllErrorString.size()) { fprintf(stderr, "%s", dllErrorString.data()); From ed23ada25fa212b47cfdcea43e36a5a48d93abee Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Mon, 28 Jul 2025 15:29:49 -0700 Subject: [PATCH 35/53] update old class name --- tools/clang/lib/SPIRV/EmitVisitor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/clang/lib/SPIRV/EmitVisitor.cpp b/tools/clang/lib/SPIRV/EmitVisitor.cpp index bed3cd69bb..ea6a7a12a9 100644 --- a/tools/clang/lib/SPIRV/EmitVisitor.cpp +++ b/tools/clang/lib/SPIRV/EmitVisitor.cpp @@ -139,7 +139,7 @@ ReadSourceCode(llvm::StringRef filePath, std::string localFilePath(filePath.begin(), filePath.end()); try { - dxc::DxcDllSupport dllSupport; + dxc::SpecificDllLoader dllSupport; IFT(dllSupport.Initialize()); CComPtr pLibrary; From 238354113ecfdc854a0c0a9c6f73de454ce1ed17 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Wed, 6 Aug 2025 10:36:58 -0700 Subject: [PATCH 36/53] rename to IDllLoader, rename to OverrideDll, remove defaulted functions, remove initialize --- include/dxc/Support/dxcapi.extval.h | 4 ++-- include/dxc/Support/dxcapi.use.h | 20 ++++++------------- lib/DxcSupport/HLSLOptions.cpp | 4 ++-- lib/DxcSupport/dxcapi.extval.cpp | 4 ++-- projects/dxilconv/unittests/DxilConvTests.cpp | 2 +- tools/clang/tools/dxclib/dxc.cpp | 2 +- tools/clang/tools/dxopt/dxopt.cpp | 2 +- .../tools/dxrfallbackcompiler/dxillib.cpp | 3 +-- .../DxrFallback/test_DxrFallback.cpp | 4 ++-- 9 files changed, 18 insertions(+), 27 deletions(-) diff --git a/include/dxc/Support/dxcapi.extval.h b/include/dxc/Support/dxcapi.extval.h index a08a7aac85..52c20209d8 100644 --- a/include/dxc/Support/dxcapi.extval.h +++ b/include/dxc/Support/dxcapi.extval.h @@ -2,7 +2,7 @@ #include namespace dxc { -class DxcDllExtValidationLoader : public DllLoader { +class DxcDllExtValidationLoader : public IDllLoader { // DxCompilerSupport manages the // lifetime of dxcompiler.dll, while DxilExtValSupport // manages the lifetime of dxil.dll @@ -26,7 +26,7 @@ class DxcDllExtValidationLoader : public DllLoader { IUnknown **pResult); HRESULT Initialize() { return InitializeInternal("DxcCreateInstance"); } - HRESULT InitializeForDll(LPCSTR dll, LPCSTR entryPoint) { + HRESULT OverrideDll(LPCSTR dll, LPCSTR entryPoint) { return InitializeInternal(dll); } diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index fb47054719..3eb18e7f47 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -20,17 +20,9 @@ extern const char *kDxCompilerLib; extern const char *kDxilLib; // Interface for common dll operations -class DllLoader { +class IDllLoader { public: - DllLoader() = default; - - DllLoader(DllLoader &&other) = default; - - virtual ~DllLoader() = default; - - virtual HRESULT Initialize() = 0; - - virtual HRESULT InitializeForDll(LPCSTR dll, LPCSTR entryPoint) = 0; + virtual HRESULT OverrideDll(LPCSTR dll, LPCSTR entryPoint) = 0; template HRESULT CreateInstance(REFCLSID clsid, TInterface **pResult) { @@ -63,7 +55,7 @@ class DllLoader { }; // Helper class to dynamically load the dxcompiler or a compatible libraries. -class SpecificDllLoader : public DllLoader { +class SpecificDllLoader : public IDllLoader { HMODULE m_dll; DxcCreateInstanceProc m_createFn; @@ -135,13 +127,13 @@ class SpecificDllLoader : public DllLoader { return InitializeInternal(kDxCompilerLib, "DxcCreateInstance"); } - HRESULT InitializeForDll(LPCSTR dll, LPCSTR entryPoint) { + HRESULT OverrideDll(LPCSTR dll, LPCSTR entryPoint) { return InitializeInternal(dll, entryPoint); } // Also bring visibility into the interface definition of this function // which takes 2 args - using DllLoader::CreateInstance; + using IDllLoader::CreateInstance; HRESULT CreateInstance(REFCLSID clsid, REFIID riid, IUnknown **pResult) { if (pResult == nullptr) return E_POINTER; @@ -153,7 +145,7 @@ class SpecificDllLoader : public DllLoader { // Also bring visibility into the interface definition of this function // which takes 3 args - using DllLoader::CreateInstance2; + using IDllLoader::CreateInstance2; HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, IUnknown **pResult) { if (pResult == nullptr) diff --git a/lib/DxcSupport/HLSLOptions.cpp b/lib/DxcSupport/HLSLOptions.cpp index 2bd2a66dc2..6a9be79de9 100644 --- a/lib/DxcSupport/HLSLOptions.cpp +++ b/lib/DxcSupport/HLSLOptions.cpp @@ -1389,8 +1389,8 @@ int SetupSpecificDllLoader(const DxcOpts &opts, llvm::raw_ostream &errors) { if (!opts.ExternalLib.empty()) { DXASSERT(!opts.ExternalFn.empty(), "else ReadDxcOpts should have failed"); - HRESULT hrLoad = dxcSupport.InitializeForDll(opts.ExternalLib.data(), - opts.ExternalFn.data()); + HRESULT hrLoad = + dxcSupport.OverrideDll(opts.ExternalLib.data(), opts.ExternalFn.data()); if (DXC_FAILED(hrLoad)) { errors << "Unable to load support for external DLL " << opts.ExternalLib << " with function " << opts.ExternalFn << " - error 0x"; diff --git a/lib/DxcSupport/dxcapi.extval.cpp b/lib/DxcSupport/dxcapi.extval.cpp index bd1e6701c2..07670c8f09 100644 --- a/lib/DxcSupport/dxcapi.extval.cpp +++ b/lib/DxcSupport/dxcapi.extval.cpp @@ -25,7 +25,7 @@ HRESULT DxcDllExtValidationLoader::CreateInstance2(IMalloc *pMalloc, HRESULT DxcDllExtValidationLoader::InitializeInternal(LPCSTR fnName) { // Load dxcompiler.dll - HRESULT Result = DxCompilerSupport.InitializeForDll(kDxCompilerLib, fnName); + HRESULT Result = DxCompilerSupport.OverrideDll(kDxCompilerLib, fnName); // if dxcompiler.dll fails to load, return the failed HRESULT if (DXC_FAILED(Result)) { return Result; @@ -45,7 +45,7 @@ HRESULT DxcDllExtValidationLoader::InitializeInternal(LPCSTR fnName) { return E_INVALIDARG; } - return DxilExtValSupport.InitializeForDll(DxilDllPath.c_str(), fnName); + return DxilExtValSupport.OverrideDll(DxilDllPath.c_str(), fnName); } bool DxcDllExtValidationLoader::GetCreateInstanceProcs( diff --git a/projects/dxilconv/unittests/DxilConvTests.cpp b/projects/dxilconv/unittests/DxilConvTests.cpp index 2f92c86f53..280edc28e5 100644 --- a/projects/dxilconv/unittests/DxilConvTests.cpp +++ b/projects/dxilconv/unittests/DxilConvTests.cpp @@ -170,7 +170,7 @@ class DxilConvTest { bool DxilConvTest::InitSupport() { if (!m_dllSupport.IsEnabled()) { VERIFY_SUCCEEDED( - m_dllSupport.InitializeForDll("dxilconv.dll", "DxcCreateInstance")); + m_dllSupport.OverrideDll("dxilconv.dll", "DxcCreateInstance")); } if (!FindToolInBinDir("%dxbc2dxil", "dxbc2dxil.exe")) { diff --git a/tools/clang/tools/dxclib/dxc.cpp b/tools/clang/tools/dxclib/dxc.cpp index f5e763526e..be4c639c74 100644 --- a/tools/clang/tools/dxclib/dxc.cpp +++ b/tools/clang/tools/dxclib/dxc.cpp @@ -1327,7 +1327,7 @@ void DxcContext::GetCompilerVersionInfo(llvm::raw_string_ostream &OS) { // Print validator if exists SpecificDllLoader DxilSupport; - DxilSupport.InitializeForDll(kDxilLib, "DxcCreateInstance"); + DxilSupport.OverrideDll(kDxilLib, "DxcCreateInstance"); WriteDXILVersionInfo(OS, DxilSupport); } diff --git a/tools/clang/tools/dxopt/dxopt.cpp b/tools/clang/tools/dxopt/dxopt.cpp index 2b42e2220d..c3b8337fc1 100644 --- a/tools/clang/tools/dxopt/dxopt.cpp +++ b/tools/clang/tools/dxopt/dxopt.cpp @@ -317,7 +317,7 @@ int main(int argc, const char **argv) { if (externalLib) { CW2A externalFnA(externalFn); CW2A externalLibA(externalLib); - IFT(g_DxcSupport.InitializeForDll(externalLibA, externalFnA)); + IFT(g_DxcSupport.OverrideDll(externalLibA, externalFnA)); } else { IFT(g_DxcSupport.Initialize()); } diff --git a/tools/clang/tools/dxrfallbackcompiler/dxillib.cpp b/tools/clang/tools/dxrfallbackcompiler/dxillib.cpp index e12a7412da..0c2026a7e8 100644 --- a/tools/clang/tools/dxrfallbackcompiler/dxillib.cpp +++ b/tools/clang/tools/dxrfallbackcompiler/dxillib.cpp @@ -46,8 +46,7 @@ bool DxilLibIsEnabled() { EnterCriticalSection(&cs); if (SUCCEEDED(g_DllLibResult)) { if (!g_DllSupport.IsEnabled()) { - g_DllLibResult = - g_DllSupport.InitializeForDll(kDxilLib, "DxcCreateInstance"); + g_DllLibResult = g_DllSupport.OverrideDll(kDxilLib, "DxcCreateInstance"); } } LeaveCriticalSection(&cs); diff --git a/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp b/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp index 321a9d6682..d1f3c07185 100644 --- a/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp +++ b/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp @@ -140,8 +140,8 @@ class Tester { Tester(const std::string &deviceName, const std::string &path) : m_deviceName(s2ws(deviceName)), m_path(path) { dxc::EnsureEnabled(m_dxcSupport); - m_dxrFallbackSupport.InitializeForDll("DxrFallbackCompiler.dll", - "DxcCreateDxrFallbackCompiler"); + m_dxrFallbackSupport.OverrideDll("DxrFallbackCompiler.dll", + "DxcCreateDxrFallbackCompiler"); } void setFiles(const std::vector &files) { From 209582f464d2cc8ae7022df200e1aafa417e9026 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Wed, 6 Aug 2025 18:02:25 -0700 Subject: [PATCH 37/53] address all of Justin + Damyan 2c --- include/dxc/Support/HLSLOptions.h | 8 +-- include/dxc/Support/dxcapi.extval.h | 30 +++++---- include/dxc/Support/dxcapi.use.h | 51 +++++++++------- include/dxc/Test/DxcTestUtils.h | 61 +++++++++---------- lib/DxcSupport/HLSLOptions.cpp | 7 +-- lib/DxcSupport/dxcapi.extval.cpp | 25 +++----- lib/DxcSupport/dxcapi.use.cpp | 6 +- tools/clang/tools/dxclib/dxc.cpp | 9 +-- tools/clang/tools/dxclib/dxc.h | 8 +-- tools/clang/tools/dxr/dxr.cpp | 7 +-- .../DxrFallback/test_DxrFallback.cpp | 14 ++--- tools/clang/unittests/HLSL/CompilerTest.cpp | 4 +- tools/clang/unittests/HLSL/PixDiaTest.cpp | 32 +++++----- tools/clang/unittests/HLSL/PixTestUtils.cpp | 22 +++---- tools/clang/unittests/HLSL/PixTestUtils.h | 20 +++--- tools/clang/unittests/HLSL/RewriterTest.cpp | 2 +- tools/clang/unittests/HLSLExec/CMakeLists.txt | 2 + .../unittests/HLSLExec/ExecutionTest.cpp | 2 +- .../unittests/HLSLExec/HlslExecTestUtils.h | 5 +- .../clang/unittests/HLSLExec/LongVectors.cpp | 4 +- tools/clang/unittests/HLSLExec/LongVectors.h | 2 +- .../clang/unittests/HLSLExec/ShaderOpTest.cpp | 2 +- tools/clang/unittests/HLSLExec/ShaderOpTest.h | 1 + .../unittests/HLSLTestLib/DxcTestUtils.cpp | 46 ++++++++------ .../unittests/HLSLTestLib/FileCheckerTest.cpp | 26 ++++---- tools/clang/unittests/dxc_batch/dxc_batch.cpp | 3 +- 26 files changed, 196 insertions(+), 203 deletions(-) diff --git a/include/dxc/Support/HLSLOptions.h b/include/dxc/Support/HLSLOptions.h index 4f92f238a9..41a79a815c 100644 --- a/include/dxc/Support/HLSLOptions.h +++ b/include/dxc/Support/HLSLOptions.h @@ -37,6 +37,7 @@ class raw_ostream; namespace dxc { class SpecificDllLoader; +class DllLoader; } namespace hlsl { @@ -304,10 +305,9 @@ int ReadDxcOpts(const llvm::opt::OptTable *optionTable, unsigned flagsToInclude, const MainArgs &argStrings, DxcOpts &opts, llvm::raw_ostream &errors); -/// Sets up the specified SpecificDllLoader instance as per the given options. -int SetupSpecificDllLoader(const DxcOpts &opts, - dxc::SpecificDllLoader &dxcSupport, - llvm::raw_ostream &errors); +/// Sets up the specified DllLoader instance as per the given options. +int SetupDllLoader(const DxcOpts &opts, dxc::DllLoader &dxcSupport, + llvm::raw_ostream &errors); void CopyArgsToWStrings(const llvm::opt::InputArgList &inArgs, unsigned flagsToInclude, diff --git a/include/dxc/Support/dxcapi.extval.h b/include/dxc/Support/dxcapi.extval.h index 52c20209d8..8bc30ca582 100644 --- a/include/dxc/Support/dxcapi.extval.h +++ b/include/dxc/Support/dxcapi.extval.h @@ -1,17 +1,15 @@ #include "dxc/Support/dxcapi.use.h" +#include #include namespace dxc { -class DxcDllExtValidationLoader : public IDllLoader { +class DxcDllExtValidationLoader : public DllLoader { // DxCompilerSupport manages the // lifetime of dxcompiler.dll, while DxilExtValSupport // manages the lifetime of dxil.dll dxc::SpecificDllLoader DxCompilerSupport; dxc::SpecificDllLoader DxilExtValSupport; - DxcCreateInstanceProc m_createFn; - DxcCreateInstance2Proc m_createFn2; - std::string DxilDllPath; HRESULT InitializeInternal(LPCSTR fnName); @@ -21,23 +19,29 @@ class DxcDllExtValidationLoader : public IDllLoader { return !DxilDllPath.empty() && !DxilExtValSupport.IsEnabled(); } - HRESULT CreateInstance(REFCLSID clsid, REFIID riid, IUnknown **pResult); - HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, - IUnknown **pResult); + HRESULT CreateInstanceImpl(REFCLSID clsid, REFIID riid, IUnknown **pResult); + HRESULT CreateInstance2Impl(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, + IUnknown **pResult); HRESULT Initialize() { return InitializeInternal("DxcCreateInstance"); } + + /* Note, OverrideDll takes this dll argument and ignores it + to satisfy the IDllLoader interface. The parameter is ignored + because the relevant dlls are specific and known: dxcompiler.dll + and dxil.dll. This class is not designed to handle any other dlls */ HRESULT OverrideDll(LPCSTR dll, LPCSTR entryPoint) { - return InitializeInternal(dll); + return InitializeInternal(entryPoint); } - bool HasCreateWithMalloc() const { return m_createFn2 != nullptr; } + bool HasCreateWithMalloc() const { + assert(DxCompilerSupport.HasCreateWithMalloc() && + DxilExtValSupport.HasCreateWithMalloc()); + return true; + } bool IsEnabled() const { return DxCompilerSupport.IsEnabled(); } - bool GetCreateInstanceProcs(DxcCreateInstanceProc *pCreateFn, - DxcCreateInstance2Proc *pCreateFn2) const; - - void Cleanup() { + void Cleanup() override { DxilExtValSupport.Cleanup(); DxCompilerSupport.Cleanup(); } diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index 3eb18e7f47..39993a7109 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -20,42 +20,47 @@ extern const char *kDxCompilerLib; extern const char *kDxilLib; // Interface for common dll operations -class IDllLoader { +class DllLoader { public: virtual HRESULT OverrideDll(LPCSTR dll, LPCSTR entryPoint) = 0; +protected: + virtual HRESULT CreateInstanceImpl(REFCLSID clsid, REFIID riid, + IUnknown **pResult) = 0; + virtual HRESULT CreateInstance2Impl(IMalloc *pMalloc, REFCLSID clsid, + REFIID riid, IUnknown **pResult) = 0; + +public: template HRESULT CreateInstance(REFCLSID clsid, TInterface **pResult) { - return CreateInstance(clsid, __uuidof(TInterface), (IUnknown **)pResult); + return CreateInstanceImpl(clsid, __uuidof(TInterface), + (IUnknown **)pResult); + } + HRESULT CreateInstance(REFCLSID clsid, REFIID riid, IUnknown **pResult) { + return CreateInstanceImpl(clsid, riid, (IUnknown **)pResult); } - - virtual HRESULT CreateInstance(REFCLSID clsid, REFIID riid, - IUnknown **pResult) = 0; template HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, TInterface **pResult) { - return CreateInstance2(pMalloc, clsid, __uuidof(TInterface), - (IUnknown **)pResult); + return CreateInstance2Impl(pMalloc, clsid, __uuidof(TInterface), + (IUnknown **)pResult); + } + HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, + IUnknown **pResult) { + return CreateInstance2Impl(pMalloc, clsid, riid, (IUnknown **)pResult); } - - virtual HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, - IUnknown **pResult) = 0; virtual bool HasCreateWithMalloc() const = 0; virtual bool IsEnabled() const = 0; - virtual bool - GetCreateInstanceProcs(DxcCreateInstanceProc *pCreateFn, - DxcCreateInstance2Proc *pCreateFn2) const = 0; - virtual void Cleanup() = 0; virtual HMODULE Detach() = 0; }; // Helper class to dynamically load the dxcompiler or a compatible libraries. -class SpecificDllLoader : public IDllLoader { +class SpecificDllLoader : public DllLoader { HMODULE m_dll; DxcCreateInstanceProc m_createFn; @@ -133,8 +138,8 @@ class SpecificDllLoader : public IDllLoader { // Also bring visibility into the interface definition of this function // which takes 2 args - using IDllLoader::CreateInstance; - HRESULT CreateInstance(REFCLSID clsid, REFIID riid, IUnknown **pResult) { + using DllLoader::CreateInstanceImpl; + HRESULT CreateInstanceImpl(REFCLSID clsid, REFIID riid, IUnknown **pResult) { if (pResult == nullptr) return E_POINTER; if (m_dll == nullptr) @@ -145,9 +150,9 @@ class SpecificDllLoader : public IDllLoader { // Also bring visibility into the interface definition of this function // which takes 3 args - using IDllLoader::CreateInstance2; - HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, - IUnknown **pResult) { + using DllLoader::CreateInstance2Impl; + HRESULT CreateInstance2Impl(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, + IUnknown **pResult) { if (pResult == nullptr) return E_POINTER; if (m_dll == nullptr) @@ -171,7 +176,7 @@ class SpecificDllLoader : public IDllLoader { return true; } - void Cleanup() { + void Cleanup() override { if (m_dll != nullptr) { m_createFn = nullptr; m_createFn2 = nullptr; @@ -201,8 +206,8 @@ inline DxcDefine GetDefine(LPCWSTR name, LPCWSTR value) { // Checks an HRESULT and formats an error message with the appended data. void IFT_Data(HRESULT hr, LPCWSTR data); -void EnsureEnabled(SpecificDllLoader &dxcSupport); -void ReadFileIntoBlob(SpecificDllLoader &dxcSupport, LPCWSTR pFileName, +void EnsureEnabled(DllLoader &dxcSupport); +void ReadFileIntoBlob(DllLoader &dxcSupport, LPCWSTR pFileName, IDxcBlobEncoding **ppBlobEncoding); void WriteBlobToConsole(IDxcBlob *pBlob, DWORD streamType = STD_OUTPUT_HANDLE); void WriteBlobToFile(IDxcBlob *pBlob, LPCWSTR pFileName, UINT32 textCodePage); diff --git a/include/dxc/Test/DxcTestUtils.h b/include/dxc/Test/DxcTestUtils.h index f6d12aafa9..1b239793ab 100644 --- a/include/dxc/Test/DxcTestUtils.h +++ b/include/dxc/Test/DxcTestUtils.h @@ -109,11 +109,11 @@ class FileRunCommandPart { FileRunCommandPart(const FileRunCommandPart &) = default; FileRunCommandPart(FileRunCommandPart &&) = default; - FileRunCommandResult Run(dxc::SpecificDllLoader &DllSupport, + FileRunCommandResult Run(dxc::DllLoader &DllSupport, const FileRunCommandResult *Prior, PluginToolsPaths *pPluginToolsPaths = nullptr, LPCWSTR dumpName = nullptr); - FileRunCommandResult RunHashTests(dxc::SpecificDllLoader &DllSupport); + FileRunCommandResult RunHashTests(dxc::DllLoader &DllSupport); FileRunCommandResult ReadOptsForDxc(hlsl::options::MainArgs &argStrings, hlsl::options::DxcOpts &Opts, @@ -127,30 +127,30 @@ class FileRunCommandPart { private: FileRunCommandResult RunFileChecker(const FileRunCommandResult *Prior, LPCWSTR dumpName = nullptr); - FileRunCommandResult RunDxc(dxc::SpecificDllLoader &DllSupport, + FileRunCommandResult RunDxc(dxc::DllLoader &DllSupport, const FileRunCommandResult *Prior); - FileRunCommandResult RunDxv(dxc::SpecificDllLoader &DllSupport, + FileRunCommandResult RunDxv(dxc::DllLoader &DllSupport, const FileRunCommandResult *Prior); - FileRunCommandResult RunOpt(dxc::SpecificDllLoader &DllSupport, + FileRunCommandResult RunOpt(dxc::DllLoader &DllSupport, const FileRunCommandResult *Prior); - FileRunCommandResult RunListParts(dxc::SpecificDllLoader &DllSupport, + FileRunCommandResult RunListParts(dxc::DllLoader &DllSupport, const FileRunCommandResult *Prior); - FileRunCommandResult RunD3DReflect(dxc::SpecificDllLoader &DllSupport, + FileRunCommandResult RunD3DReflect(dxc::DllLoader &DllSupport, const FileRunCommandResult *Prior); - FileRunCommandResult RunDxr(dxc::SpecificDllLoader &DllSupport, + FileRunCommandResult RunDxr(dxc::DllLoader &DllSupport, const FileRunCommandResult *Prior); - FileRunCommandResult RunLink(dxc::SpecificDllLoader &DllSupport, + FileRunCommandResult RunLink(dxc::DllLoader &DllSupport, const FileRunCommandResult *Prior); FileRunCommandResult RunTee(const FileRunCommandResult *Prior); FileRunCommandResult RunXFail(const FileRunCommandResult *Prior); - FileRunCommandResult RunDxilVer(dxc::SpecificDllLoader &DllSupport, + FileRunCommandResult RunDxilVer(dxc::DllLoader &DllSupport, const FileRunCommandResult *Prior); - FileRunCommandResult RunDxcHashTest(dxc::SpecificDllLoader &DllSupport); + FileRunCommandResult RunDxcHashTest(dxc::DllLoader &DllSupport); FileRunCommandResult RunFromPath(const std::string &path, const FileRunCommandResult *Prior); FileRunCommandResult RunFileCompareText(const FileRunCommandResult *Prior); #ifdef _WIN32 - FileRunCommandResult RunFxc(dxc::SpecificDllLoader &DllSupport, + FileRunCommandResult RunFxc(dxc::DllLoader &DllSupport, const FileRunCommandResult *Prior); #endif @@ -180,7 +180,7 @@ class FileRunTestResult { LPCWSTR dumpName = nullptr); }; -void AssembleToContainer(dxc::SpecificDllLoader &dllSupport, IDxcBlob *pModule, +void AssembleToContainer(dxc::DllLoader &dllSupport, IDxcBlob *pModule, IDxcBlob **pContainer); std::string BlobToUtf8(IDxcBlob *pBlob); std::wstring BlobToWide(IDxcBlob *pBlob); @@ -195,36 +195,33 @@ bool CheckMsgs(const LPCSTR pText, size_t TextCount, const LPCSTR *pErrorMsgs, size_t errorMsgCount, bool bRegex); bool CheckNotMsgs(const LPCSTR pText, size_t TextCount, const LPCSTR *pErrorMsgs, size_t errorMsgCount, bool bRegex); -void GetDxilPart(dxc::SpecificDllLoader &dllSupport, IDxcBlob *pProgram, +void GetDxilPart(dxc::DllLoader &dllSupport, IDxcBlob *pProgram, IDxcBlob **pDxilPart); -std::string DisassembleProgram(dxc::SpecificDllLoader &dllSupport, - IDxcBlob *pProgram); +std::string DisassembleProgram(dxc::DllLoader &dllSupport, IDxcBlob *pProgram); void SplitPassList(LPWSTR pPassesBuffer, std::vector &passes); -void MultiByteStringToBlob(dxc::SpecificDllLoader &dllSupport, - const std::string &val, UINT32 codePoint, - IDxcBlob **ppBlob); -void MultiByteStringToBlob(dxc::SpecificDllLoader &dllSupport, - const std::string &val, UINT32 codePoint, - IDxcBlobEncoding **ppBlob); -void Utf8ToBlob(dxc::SpecificDllLoader &dllSupport, const std::string &val, +void MultiByteStringToBlob(dxc::DllLoader &dllSupport, const std::string &val, + UINT32 codePoint, IDxcBlob **ppBlob); +void MultiByteStringToBlob(dxc::DllLoader &dllSupport, const std::string &val, + UINT32 codePoint, IDxcBlobEncoding **ppBlob); +void Utf8ToBlob(dxc::DllLoader &dllSupport, const std::string &val, IDxcBlob **ppBlob); -void Utf8ToBlob(dxc::SpecificDllLoader &dllSupport, const std::string &val, +void Utf8ToBlob(dxc::DllLoader &dllSupport, const std::string &val, IDxcBlobEncoding **ppBlob); -void Utf8ToBlob(dxc::SpecificDllLoader &dllSupport, const char *pVal, +void Utf8ToBlob(dxc::DllLoader &dllSupport, const char *pVal, IDxcBlobEncoding **ppBlob); -void WideToBlob(dxc::SpecificDllLoader &dllSupport, const std::wstring &val, +void WideToBlob(dxc::DllLoader &dllSupport, const std::wstring &val, IDxcBlob **ppBlob); -void WideToBlob(dxc::SpecificDllLoader &dllSupport, const std::wstring &val, +void WideToBlob(dxc::DllLoader &dllSupport, const std::wstring &val, IDxcBlobEncoding **ppBlob); -void VerifyCompileOK(dxc::SpecificDllLoader &dllSupport, LPCSTR pText, +void VerifyCompileOK(dxc::DllLoader &dllSupport, LPCSTR pText, LPCWSTR pTargetProfile, LPCWSTR pArgs, IDxcBlob **ppResult); -void VerifyCompileOK(dxc::SpecificDllLoader &dllSupport, LPCSTR pText, +void VerifyCompileOK(dxc::DllLoader &dllSupport, LPCSTR pText, LPCWSTR pTargetProfile, std::vector &args, IDxcBlob **ppResult); -HRESULT GetVersion(dxc::SpecificDllLoader &DllSupport, REFCLSID clsid, - unsigned &Major, unsigned &Minor); +HRESULT GetVersion(dxc::DllLoader &DllSupport, REFCLSID clsid, unsigned &Major, + unsigned &Minor); bool ParseTargetProfile(llvm::StringRef targetProfile, llvm::StringRef &outStage, unsigned &outMajor, unsigned &outMinor); @@ -240,7 +237,7 @@ class VersionSupportInfo { VersionSupportInfo(); // Initialize version info structure. TODO: add device shader model support - void Initialize(dxc::SpecificDllLoader &dllSupport); + void Initialize(dxc::DllLoader &dllSupport); // Return true if IR sensitive test should be skipped, and log comment bool SkipIRSensitiveTest(); // Return true if test requiring DXIL of given version should be skipped, and diff --git a/lib/DxcSupport/HLSLOptions.cpp b/lib/DxcSupport/HLSLOptions.cpp index 6a9be79de9..3224de78c1 100644 --- a/lib/DxcSupport/HLSLOptions.cpp +++ b/lib/DxcSupport/HLSLOptions.cpp @@ -1383,10 +1383,9 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude, return 0; } -/// Sets up the specified SpecificDllLoader instance as per the given options. -int SetupSpecificDllLoader(const DxcOpts &opts, - dxc::SpecificDllLoader &dxcSupport, - llvm::raw_ostream &errors) { +/// Sets up the specified DllLoader instance as per the given options. +int SetupDllLoader(const DxcOpts &opts, dxc::DllLoader &dxcSupport, + llvm::raw_ostream &errors) { if (!opts.ExternalLib.empty()) { DXASSERT(!opts.ExternalFn.empty(), "else ReadDxcOpts should have failed"); HRESULT hrLoad = diff --git a/lib/DxcSupport/dxcapi.extval.cpp b/lib/DxcSupport/dxcapi.extval.cpp index 07670c8f09..64fe9e4185 100644 --- a/lib/DxcSupport/dxcapi.extval.cpp +++ b/lib/DxcSupport/dxcapi.extval.cpp @@ -6,17 +6,19 @@ namespace dxc { -HRESULT DxcDllExtValidationLoader::CreateInstance(REFCLSID clsid, REFIID riid, - IUnknown **pResult) { +HRESULT DxcDllExtValidationLoader::CreateInstanceImpl(REFCLSID clsid, + REFIID riid, + IUnknown **pResult) { if (DxilExtValSupport.IsEnabled() && clsid == CLSID_DxcValidator) return DxilExtValSupport.CreateInstance(clsid, riid, pResult); return DxCompilerSupport.CreateInstance(clsid, riid, pResult); } -HRESULT DxcDllExtValidationLoader::CreateInstance2(IMalloc *pMalloc, - REFCLSID clsid, REFIID riid, - IUnknown **pResult) { +HRESULT DxcDllExtValidationLoader::CreateInstance2Impl(IMalloc *pMalloc, + REFCLSID clsid, + REFIID riid, + IUnknown **pResult) { if (DxilExtValSupport.IsEnabled() && clsid == CLSID_DxcValidator) return DxilExtValSupport.CreateInstance2(pMalloc, clsid, riid, pResult); @@ -47,15 +49,4 @@ HRESULT DxcDllExtValidationLoader::InitializeInternal(LPCSTR fnName) { return DxilExtValSupport.OverrideDll(DxilDllPath.c_str(), fnName); } - -bool DxcDllExtValidationLoader::GetCreateInstanceProcs( - DxcCreateInstanceProc *pCreateFn, - DxcCreateInstance2Proc *pCreateFn2) const { - if (pCreateFn == nullptr || pCreateFn2 == nullptr || m_createFn == nullptr) - return false; - *pCreateFn = m_createFn; - *pCreateFn2 = m_createFn2; - return true; -} - -} // namespace dxc \ No newline at end of file +} // namespace dxc diff --git a/lib/DxcSupport/dxcapi.use.cpp b/lib/DxcSupport/dxcapi.use.cpp index 4096d58de7..fc145a2b62 100644 --- a/lib/DxcSupport/dxcapi.use.cpp +++ b/lib/DxcSupport/dxcapi.use.cpp @@ -73,13 +73,13 @@ void IFT_Data(HRESULT hr, LPCWSTR data) { throw ::hlsl::Exception(hr, errMsg); } -void EnsureEnabled(SpecificDllLoader &dxcSupport) { +void EnsureEnabled(DllLoader &dxcSupport) { if (!dxcSupport.IsEnabled()) { - IFT(dxcSupport.Initialize()); + IFT(dxcSupport.OverrideDll(kDxCompilerLib, "DxcCreateInstance")); } } -void ReadFileIntoBlob(SpecificDllLoader &dxcSupport, LPCWSTR pFileName, +void ReadFileIntoBlob(DllLoader &dxcSupport, LPCWSTR pFileName, IDxcBlobEncoding **ppBlobEncoding) { CComPtr library; IFT(dxcSupport.CreateInstance(CLSID_DxcLibrary, &library)); diff --git a/tools/clang/tools/dxclib/dxc.cpp b/tools/clang/tools/dxclib/dxc.cpp index be4c639c74..5e4d179b98 100644 --- a/tools/clang/tools/dxclib/dxc.cpp +++ b/tools/clang/tools/dxclib/dxc.cpp @@ -1234,8 +1234,7 @@ namespace dxc { // Writes compiler version info to stream void WriteDxCompilerVersionInfo(llvm::raw_ostream &OS, const char *ExternalLib, - const char *ExternalFn, - SpecificDllLoader &DxcSupport) { + const char *ExternalFn, DllLoader &DxcSupport) { if (DxcSupport.IsEnabled()) { UINT32 compilerMajor = 1; UINT32 compilerMinor = 0; @@ -1294,8 +1293,7 @@ void WriteDxCompilerVersionInfo(llvm::raw_ostream &OS, const char *ExternalLib, } // Writes compiler version info to stream -void WriteDXILVersionInfo(llvm::raw_ostream &OS, - SpecificDllLoader &DxilSupport) { +void WriteDXILVersionInfo(llvm::raw_ostream &OS, DllLoader &DxilSupport) { if (DxilSupport.IsEnabled()) { CComPtr VerInfo; if (SUCCEEDED(DxilSupport.CreateInstance(CLSID_DxcValidator, &VerInfo))) { @@ -1453,8 +1451,7 @@ int dxc::main(int argc, const char **argv_) { { std::string dllErrorString; llvm::raw_string_ostream dllErrorStream(dllErrorString); - int dllResult = - SetupSpecificDllLoader(dxcOpts, dxcSupport, dllErrorStream); + int dllResult = SetupDllLoader(dxcOpts, dxcSupport, dllErrorStream); dllErrorStream.flush(); if (dllErrorString.size()) { fprintf(stderr, "%s\n", dllErrorString.data()); diff --git a/tools/clang/tools/dxclib/dxc.h b/tools/clang/tools/dxclib/dxc.h index 2740f2ca81..387c97cab0 100644 --- a/tools/clang/tools/dxclib/dxc.h +++ b/tools/clang/tools/dxclib/dxc.h @@ -18,14 +18,12 @@ class raw_ostream; } namespace dxc { -class SpecificDllLoader; +class DllLoader; // Writes compiler version info to stream void WriteDxCompilerVersionInfo(llvm::raw_ostream &OS, const char *ExternalLib, - const char *ExternalFn, - dxc::SpecificDllLoader &DxcSupport); -void WriteDXILVersionInfo(llvm::raw_ostream &OS, - dxc::SpecificDllLoader &DxilSupport); + const char *ExternalFn, DllLoader &DxcSupport); +void WriteDXILVersionInfo(llvm::raw_ostream &OS, DllLoader &DxilSupport); #ifdef _WIN32 int main(int argc, const wchar_t **argv_); diff --git a/tools/clang/tools/dxr/dxr.cpp b/tools/clang/tools/dxr/dxr.cpp index 4162b0765d..5329e42356 100644 --- a/tools/clang/tools/dxr/dxr.cpp +++ b/tools/clang/tools/dxr/dxr.cpp @@ -76,8 +76,7 @@ int main(int argc, const char **argv) { { std::string dllErrorString; llvm::raw_string_ostream dllErrorStream(dllErrorString); - int dllResult = - SetupSpecificDllLoader(dxcOpts, dxcSupport, dllErrorStream); + int dllResult = SetupDllLoader(dxcOpts, dxcSupport, dllErrorStream); dllErrorStream.flush(); if (dllErrorString.size()) { fprintf(stderr, "%s\n", dllErrorString.data()); @@ -93,7 +92,7 @@ int main(int argc, const char **argv) { llvm::raw_string_ostream helpStream(helpString); std::string version; llvm::raw_string_ostream versionStream(version); - WriteDxCompilerVersionInfo( + dxc::WriteDxCompilerVersionInfo( versionStream, dxcOpts.ExternalLib.empty() ? (LPCSTR) nullptr : dxcOpts.ExternalLib.data(), @@ -112,7 +111,7 @@ int main(int argc, const char **argv) { if (dxcOpts.ShowVersion) { std::string version; llvm::raw_string_ostream versionStream(version); - WriteDxCompilerVersionInfo( + dxc::WriteDxCompilerVersionInfo( versionStream, dxcOpts.ExternalLib.empty() ? (LPCSTR) nullptr : dxcOpts.ExternalLib.data(), diff --git a/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp b/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp index d1f3c07185..5ec0326a53 100644 --- a/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp +++ b/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp @@ -49,11 +49,11 @@ void printErrors(CComPtr pResult) { // IFTMSG(status, msg); } -void CompileToDxilFromFile(SpecificDllLoader &dxcSupport, - LPCWSTR pShaderTextFilePath, LPCWSTR pEntryPoint, - LPCWSTR pTargetProfile, LPCWSTR *pArgs, - UINT32 argCount, const DxcDefine *pDefines, - UINT32 defineCount, IDxcBlob **ppBlob) { +void CompileToDxilFromFile(DllLoader &dxcSupport, LPCWSTR pShaderTextFilePath, + LPCWSTR pEntryPoint, LPCWSTR pTargetProfile, + LPCWSTR *pArgs, UINT32 argCount, + const DxcDefine *pDefines, UINT32 defineCount, + IDxcBlob **ppBlob) { CComPtr pLibrary; IFT(dxcSupport.CreateInstance(CLSID_DxcLibrary, &pLibrary)); @@ -83,8 +83,8 @@ void CompileToDxilFromFile(SpecificDllLoader &dxcSupport, } } -bool DxrCompile(SpecificDllLoader &dxrFallbackSupport, - const std::string &entryName, std::vector &libs, +bool DxrCompile(DllLoader &dxrFallbackSupport, const std::string &entryName, + std::vector &libs, const std::vector &shaderNames, std::vector &shaderIds, bool findCalledShaders, IDxcBlob **ppResultBlob) { diff --git a/tools/clang/unittests/HLSL/CompilerTest.cpp b/tools/clang/unittests/HLSL/CompilerTest.cpp index 524e6bc7e6..67a3f08443 100644 --- a/tools/clang/unittests/HLSL/CompilerTest.cpp +++ b/tools/clang/unittests/HLSL/CompilerTest.cpp @@ -1264,8 +1264,8 @@ TEST_F(CompilerTest, CompileThenTestReflectionThreadSizeMS) { } static void VerifyPdbUtil( - dxc::SpecificDllLoader &dllSupport, IDxcBlob *pBlob, - IDxcPdbUtils *pPdbUtils, const WCHAR *pMainFileName, + dxc::DllLoader &dllSupport, IDxcBlob *pBlob, IDxcPdbUtils *pPdbUtils, + const WCHAR *pMainFileName, llvm::ArrayRef> ExpectedArgs, llvm::ArrayRef> ExpectedFlags, llvm::ArrayRef ExpectedDefines, IDxcCompiler *pCompiler, diff --git a/tools/clang/unittests/HLSL/PixDiaTest.cpp b/tools/clang/unittests/HLSL/PixDiaTest.cpp index 709b9ed5d8..360d0d81ce 100644 --- a/tools/clang/unittests/HLSL/PixDiaTest.cpp +++ b/tools/clang/unittests/HLSL/PixDiaTest.cpp @@ -85,7 +85,7 @@ const char *DataKindText[] = { "FileStatic", "Global", "Member", "StaticMember", "Constant", }; -static void CompileAndGetDebugPart(dxc::SpecificDllLoader &dllSupport, +static void CompileAndGetDebugPart(dxc::DllLoader &dllSupport, const char *source, const wchar_t *profile, IDxcBlob **ppDebugPart) { CComPtr pContainer; @@ -641,14 +641,12 @@ class PixDiaTest { } void CompileAndRunAnnotationAndGetDebugPart( - dxc::SpecificDllLoader &dllSupport, const char *source, - const wchar_t *profile, IDxcIncludeHandler *includer, - IDxcBlob **ppDebugPart, + dxc::DllLoader &dllSupport, const char *source, const wchar_t *profile, + IDxcIncludeHandler *includer, IDxcBlob **ppDebugPart, std::vector extraArgs = {L"-Od"}); void CompileAndRunAnnotationAndLoadDiaSource( - dxc::SpecificDllLoader &dllSupport, const char *source, - const wchar_t *profile, IDxcIncludeHandler *includer, - IDiaDataSource **ppDataSource, + dxc::DllLoader &dllSupport, const char *source, const wchar_t *profile, + IDxcIncludeHandler *includer, IDiaDataSource **ppDataSource, std::vector extraArgs = {L"-Od"}); struct VariableComponentInfo { @@ -781,9 +779,9 @@ bool PixDiaTest::InitSupport() { } void PixDiaTest::CompileAndRunAnnotationAndGetDebugPart( - dxc::SpecificDllLoader &dllSupport, const char *source, - const wchar_t *profile, IDxcIncludeHandler *includer, - IDxcBlob **ppDebugPart, std::vector extraArgs) { + dxc::DllLoader &dllSupport, const char *source, const wchar_t *profile, + IDxcIncludeHandler *includer, IDxcBlob **ppDebugPart, + std::vector extraArgs) { CComPtr pContainer; std::vector args; @@ -1022,7 +1020,7 @@ TEST_F(PixDiaTest, DiaLoadBadBitcodeThenFail) { VERIFY_FAILED(pDiaSource->loadDataFromIStream(pStream)); } -static void CompileTestAndLoadDiaSource(dxc::SpecificDllLoader &dllSupport, +static void CompileTestAndLoadDiaSource(dxc::DllLoader &dllSupport, const char *source, const wchar_t *profile, IDiaDataSource **ppDataSource) { @@ -1042,7 +1040,7 @@ static void CompileTestAndLoadDiaSource(dxc::SpecificDllLoader &dllSupport, } } -static void CompileTestAndLoadDia(dxc::SpecificDllLoader &dllSupport, +static void CompileTestAndLoadDia(dxc::DllLoader &dllSupport, IDiaDataSource **ppDataSource) { CompileTestAndLoadDiaSource(dllSupport, "[numthreads(8,8,1)] void main() { }", L"cs_6_0", ppDataSource); @@ -1204,7 +1202,7 @@ TEST_F(PixDiaTest, DiaCompileArgs) { args.push_back(L"/D"); args.push_back(DefineList[i]); } - auto CompileAndGetDebugPart = [&args](dxc::SpecificDllLoader &dllSupport, + auto CompileAndGetDebugPart = [&args](dxc::DllLoader &dllSupport, const char *source, const wchar_t *profile, IDxcBlob **ppDebugPart) { @@ -1464,7 +1462,7 @@ TEST_F(PixDiaTest, PixDebugCompileInfo) { args.push_back(DefineList[i]); } - auto CompileAndGetDebugPart = [&args](dxc::SpecificDllLoader &dllSupport, + auto CompileAndGetDebugPart = [&args](dxc::DllLoader &dllSupport, const char *source, const wchar_t *profile, IDxcBlob **ppDebugPart) { @@ -1532,9 +1530,9 @@ TEST_F(PixDiaTest, PixDebugCompileInfo) { } void PixDiaTest::CompileAndRunAnnotationAndLoadDiaSource( - dxc::SpecificDllLoader &dllSupport, const char *source, - const wchar_t *profile, IDxcIncludeHandler *includer, - IDiaDataSource **ppDataSource, std::vector extraArgs) { + dxc::DllLoader &dllSupport, const char *source, const wchar_t *profile, + IDxcIncludeHandler *includer, IDiaDataSource **ppDataSource, + std::vector extraArgs) { CComPtr pDebugContent; CComPtr pStream; CComPtr pDiaSource; diff --git a/tools/clang/unittests/HLSL/PixTestUtils.cpp b/tools/clang/unittests/HLSL/PixTestUtils.cpp index 3a1debae6c..4707ca9f7f 100644 --- a/tools/clang/unittests/HLSL/PixTestUtils.cpp +++ b/tools/clang/unittests/HLSL/PixTestUtils.cpp @@ -166,8 +166,7 @@ DxilRegisterToNameMap BuildDxilRegisterToNameMap(char const *disassembly) { return ret; } -std::wstring Disassemble(dxc::SpecificDllLoader &dllSupport, - IDxcBlob *pProgram) { +std::wstring Disassemble(dxc::DllLoader &dllSupport, IDxcBlob *pProgram) { CComPtr pCompiler; VERIFY_SUCCEEDED(pix_test::CreateCompiler(dllSupport, &pCompiler)); @@ -183,7 +182,7 @@ std::wstring Disassemble(dxc::SpecificDllLoader &dllSupport, // For CreateBlobFromText namespace { -void CreateBlobPinned(dxc::SpecificDllLoader &dllSupport, +void CreateBlobPinned(dxc::DllLoader &dllSupport, _In_bytecount_(size) LPCVOID data, SIZE_T size, UINT32 codePage, IDxcBlobEncoding **ppBlob) { CComPtr library; @@ -216,7 +215,7 @@ std::vector SplitAndPreserveEmptyLines(std::string const &str, return lines; } -void CompileAndLogErrors(dxc::SpecificDllLoader &dllSupport, LPCSTR pText, +void CompileAndLogErrors(dxc::DllLoader &dllSupport, LPCSTR pText, LPCWSTR pTargetProfile, std::vector &args, IDxcIncludeHandler *includer, _Outptr_ IDxcBlob **ppResult) { @@ -242,8 +241,8 @@ void CompileAndLogErrors(dxc::SpecificDllLoader &dllSupport, LPCSTR pText, VERIFY_SUCCEEDED(pResult->GetResult(ppResult)); } -PassOutput RunAnnotationPasses(dxc::SpecificDllLoader &dllSupport, - IDxcBlob *dxil, int startingLineNumber) { +PassOutput RunAnnotationPasses(dxc::DllLoader &dllSupport, IDxcBlob *dxil, + int startingLineNumber) { CComPtr pOptimizer; VERIFY_SUCCEEDED(dllSupport.CreateInstance(CLSID_DxcOptimizer, &pOptimizer)); std::vector Options; @@ -335,7 +334,7 @@ GatherDebugLocLabelsFromDxcUtils(DebuggerInterfaces &debuggerInterfaces) { return std::make_unique(debuggerInterfaces); } -CComPtr GetDebugPart(dxc::SpecificDllLoader &dllSupport, +CComPtr GetDebugPart(dxc::DllLoader &dllSupport, IDxcBlob *container) { CComPtr pLib; @@ -356,17 +355,16 @@ CComPtr GetDebugPart(dxc::SpecificDllLoader &dllSupport, return debugPart; } -void CreateBlobFromText(dxc::SpecificDllLoader &dllSupport, const char *pText, +void CreateBlobFromText(dxc::DllLoader &dllSupport, const char *pText, IDxcBlobEncoding **ppBlob) { CreateBlobPinned(dllSupport, pText, strlen(pText) + 1, CP_UTF8, ppBlob); } -HRESULT CreateCompiler(dxc::SpecificDllLoader &dllSupport, - IDxcCompiler **ppResult) { +HRESULT CreateCompiler(dxc::DllLoader &dllSupport, IDxcCompiler **ppResult) { return dllSupport.CreateInstance(CLSID_DxcCompiler, ppResult); } -CComPtr Compile(dxc::SpecificDllLoader &dllSupport, const char *hlsl, +CComPtr Compile(dxc::DllLoader &dllSupport, const char *hlsl, const wchar_t *target, std::vector extraArgs, const wchar_t *entry) { @@ -429,7 +427,7 @@ CComPtr Compile(dxc::SpecificDllLoader &dllSupport, const char *hlsl, return pProgram; } -CComPtr WrapInNewContainer(dxc::SpecificDllLoader &dllSupport, +CComPtr WrapInNewContainer(dxc::DllLoader &dllSupport, IDxcBlob *part) { CComPtr pAssembler; IFT(dllSupport.CreateInstance(CLSID_DxcAssembler, &pAssembler)); diff --git a/tools/clang/unittests/HLSL/PixTestUtils.h b/tools/clang/unittests/HLSL/PixTestUtils.h index ece5c64137..d55868e75c 100644 --- a/tools/clang/unittests/HLSL/PixTestUtils.h +++ b/tools/clang/unittests/HLSL/PixTestUtils.h @@ -19,7 +19,7 @@ #include namespace dxc { -class SpecificDllLoader; +class DllLoader; } namespace pix_test { @@ -27,24 +27,22 @@ namespace pix_test { std::vector SplitAndPreserveEmptyLines(std::string const &str, char delimeter); -CComPtr GetDebugPart(dxc::SpecificDllLoader &dllSupport, - IDxcBlob *container); -void CreateBlobFromText(dxc::SpecificDllLoader &dllSupport, const char *pText, +CComPtr GetDebugPart(dxc::DllLoader &dllSupport, IDxcBlob *container); +void CreateBlobFromText(dxc::DllLoader &dllSupport, const char *pText, IDxcBlobEncoding **ppBlob); -HRESULT CreateCompiler(dxc::SpecificDllLoader &dllSupport, - IDxcCompiler **ppResult); -CComPtr Compile(dxc::SpecificDllLoader &dllSupport, const char *hlsl, +HRESULT CreateCompiler(dxc::DllLoader &dllSupport, IDxcCompiler **ppResult); +CComPtr Compile(dxc::DllLoader &dllSupport, const char *hlsl, const wchar_t *target, std::vector extraArgs = {}, const wchar_t *entry = L"main"); -void CompileAndLogErrors(dxc::SpecificDllLoader &dllSupport, LPCSTR pText, +void CompileAndLogErrors(dxc::DllLoader &dllSupport, LPCSTR pText, LPCWSTR pTargetProfile, std::vector &args, IDxcIncludeHandler *includer, _Outptr_ IDxcBlob **ppResult); -CComPtr WrapInNewContainer(dxc::SpecificDllLoader &dllSupport, +CComPtr WrapInNewContainer(dxc::DllLoader &dllSupport, IDxcBlob *part); struct ValueLocation { @@ -57,8 +55,8 @@ struct PassOutput { std::vector lines; }; -PassOutput RunAnnotationPasses(dxc::SpecificDllLoader &dllSupport, - IDxcBlob *dxil, int startingLineNumber = 0); +PassOutput RunAnnotationPasses(dxc::DllLoader &dllSupport, IDxcBlob *dxil, + int startingLineNumber = 0); struct DebuggerInterfaces { CComPtr debugInfo; diff --git a/tools/clang/unittests/HLSL/RewriterTest.cpp b/tools/clang/unittests/HLSL/RewriterTest.cpp index ebee433564..e5c69d7cb8 100644 --- a/tools/clang/unittests/HLSL/RewriterTest.cpp +++ b/tools/clang/unittests/HLSL/RewriterTest.cpp @@ -173,7 +173,7 @@ class RewriterTest : public ::testing::Test { struct FileWithBlob { CComPtr BlobEncoding; - FileWithBlob(dxc::SpecificDllLoader &support, LPCWSTR path) { + FileWithBlob(dxc::DllLoader &support, LPCWSTR path) { CComPtr library; IFT(support.CreateInstance(CLSID_DxcLibrary, &library)); UINT32 codePage = CP_UTF8; diff --git a/tools/clang/unittests/HLSLExec/CMakeLists.txt b/tools/clang/unittests/HLSLExec/CMakeLists.txt index b490ac94e9..ac305a31a1 100644 --- a/tools/clang/unittests/HLSLExec/CMakeLists.txt +++ b/tools/clang/unittests/HLSLExec/CMakeLists.txt @@ -5,6 +5,8 @@ find_package(D3D12 REQUIRED) # Used for ExecutionTest.cpp. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") +set(DXCSUPPORT_DIR "${CMAKE_SOURCE_DIR}/lib/DxcSupport") + add_clang_library(ExecHLSLTests SHARED ExecutionTest.cpp ShaderOpTest.cpp diff --git a/tools/clang/unittests/HLSLExec/ExecutionTest.cpp b/tools/clang/unittests/HLSLExec/ExecutionTest.cpp index bfcb5e1af0..4f8dad3ecc 100644 --- a/tools/clang/unittests/HLSLExec/ExecutionTest.cpp +++ b/tools/clang/unittests/HLSLExec/ExecutionTest.cpp @@ -12427,7 +12427,7 @@ TEST_F(ExecutionTest, QuadAnyAll) { // input string pointers. st::ShaderOpTest::TShaderCallbackFn MakeShaderReplacementCallback( std::vector dxcArgs, std::vector lookFors, - std::vector replacements, dxc::SpecificDllLoader &dllSupport) { + std::vector replacements, dxc::DllLoader &dllSupport) { auto ShaderInitFn = [dxcArgs, lookFors, replacements, &dllSupport]( LPCSTR Name, LPCSTR pText, IDxcBlob **ppShaderBlob, diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h index 86d022b07f..6877b2fb77 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h @@ -228,8 +228,9 @@ static bool createDevice(ID3D12Device **D3DDevice, } inline void readHlslDataIntoNewStream(LPCWSTR RelativePath, IStream **Stream, - dxc::SpecificDllLoader &Support) { - VERIFY_SUCCEEDED(Support.Initialize()); + dxc::DllLoader &Support) { + VERIFY_SUCCEEDED( + Support.OverrideDll(dxc::kDxCompilerLib, "DxcCreateInstance")); CComPtr Library; CComPtr Blob; CComPtr StreamCom; diff --git a/tools/clang/unittests/HLSLExec/LongVectors.cpp b/tools/clang/unittests/HLSLExec/LongVectors.cpp index 0d6f3ffeef..f0f8902023 100644 --- a/tools/clang/unittests/HLSLExec/LongVectors.cpp +++ b/tools/clang/unittests/HLSLExec/LongVectors.cpp @@ -273,14 +273,14 @@ void LongVector::OpTest::testBaseMethod( LPCSTR ShaderName = "LongVectorOp"; // ShaderOpArith.xml defines the input/output resources and the shader source. CComPtr TestXML; - readHlslDataIntoNewStream(L"ShaderOpArith.xml", &TestXML, SpecificDllLoader); + readHlslDataIntoNewStream(L"ShaderOpArith.xml", &TestXML, DxilDllLoader); // RunShaderOpTest is a helper function that handles resource creation // and setup. It also handles the shader compilation and execution. It takes a // callback that is called when the shader is compiled, but before it is // executed. std::shared_ptr TestResult = st::RunShaderOpTest( - D3DDevice, SpecificDllLoader, TestXML, ShaderName, + D3DDevice, DxilDllLoader, TestXML, ShaderName, [&](LPCSTR Name, std::vector &ShaderData, st::ShaderOp *ShaderOp) { hlsl_test::LogCommentFmt(L"RunShaderOpTest CallBack. Resource Name: %S", Name); diff --git a/tools/clang/unittests/HLSLExec/LongVectors.h b/tools/clang/unittests/HLSLExec/LongVectors.h index 16a8b851fa..fb6f016f7e 100644 --- a/tools/clang/unittests/HLSLExec/LongVectors.h +++ b/tools/clang/unittests/HLSLExec/LongVectors.h @@ -59,7 +59,7 @@ class OpTest { size_t VectorSizeToTest); private: - dxc::SpecificDllLoader SpecificDllLoader; + dxc::SpecificDllLoader DxilDllLoader; bool Initialized = false; }; diff --git a/tools/clang/unittests/HLSLExec/ShaderOpTest.cpp b/tools/clang/unittests/HLSLExec/ShaderOpTest.cpp index d31293ffb4..5ef2068165 100644 --- a/tools/clang/unittests/HLSLExec/ShaderOpTest.cpp +++ b/tools/clang/unittests/HLSLExec/ShaderOpTest.cpp @@ -25,7 +25,7 @@ #include "HlslTestUtils.h" // LogCommentFmt #include "dxc/DXIL/DxilConstants.h" // ComponentType #include "dxc/Support/Global.h" // OutputDebugBytes -#include "dxc/Support/dxcapi.use.h" // SpecificDllLoader +#include "dxc/Support/dxcapi.use.h" // *DllLoader #include "dxc/dxcapi.h" // IDxcCompiler #include diff --git a/tools/clang/unittests/HLSLExec/ShaderOpTest.h b/tools/clang/unittests/HLSLExec/ShaderOpTest.h index 60783cf7c3..bdf2443436 100644 --- a/tools/clang/unittests/HLSLExec/ShaderOpTest.h +++ b/tools/clang/unittests/HLSLExec/ShaderOpTest.h @@ -31,6 +31,7 @@ /////////////////////////////////////////////////////////////////////////////// // Forward declarations. namespace dxc { +class DllLoader; class SpecificDllLoader; } struct IStream; diff --git a/tools/clang/unittests/HLSLTestLib/DxcTestUtils.cpp b/tools/clang/unittests/HLSLTestLib/DxcTestUtils.cpp index 177f37c97b..e484d48f4e 100644 --- a/tools/clang/unittests/HLSLTestLib/DxcTestUtils.cpp +++ b/tools/clang/unittests/HLSLTestLib/DxcTestUtils.cpp @@ -13,6 +13,7 @@ #include "dxc/Support/Global.h" #include "dxc/Support/HLSLOptions.h" #include "dxc/Support/Unicode.h" +#include "dxc/Support/dxcapi.use.h" #include "dxc/Test/CompilationResult.h" #include "dxc/Test/HlslTestUtils.h" #include "llvm/ADT/APInt.h" @@ -24,6 +25,13 @@ using namespace std; using namespace hlsl_test; +namespace dxc { + +extern const char *kDxCompilerLib; +extern const char *kDxilLib; + +} // namespace dxc + MODULE_SETUP(TestModuleSetup) MODULE_CLEANUP(TestModuleCleanup) @@ -173,13 +181,13 @@ bool CheckOperationResultMsgs(IDxcOperationResult *pResult, maySucceedAnyway, bRegex); } -std::string DisassembleProgram(dxc::SpecificDllLoader &dllSupport, - IDxcBlob *pProgram) { +std::string DisassembleProgram(dxc::DllLoader &dllSupport, IDxcBlob *pProgram) { CComPtr pCompiler; CComPtr pDisassembly; if (!dllSupport.IsEnabled()) { - VERIFY_SUCCEEDED(dllSupport.Initialize()); + VERIFY_SUCCEEDED( + dllSupport.OverrideDll(dxc::kDxCompilerLib, "DxcCreateInstance")); } VERIFY_SUCCEEDED(dllSupport.CreateInstance(CLSID_DxcCompiler, &pCompiler)); @@ -187,7 +195,7 @@ std::string DisassembleProgram(dxc::SpecificDllLoader &dllSupport, return BlobToUtf8(pDisassembly); } -void AssembleToContainer(dxc::SpecificDllLoader &dllSupport, IDxcBlob *pModule, +void AssembleToContainer(dxc::DllLoader &dllSupport, IDxcBlob *pModule, IDxcBlob **pContainer) { CComPtr pAssembler; CComPtr pResult; @@ -302,7 +310,7 @@ std::wstring BlobToWide(IDxcBlob *pBlob) { } } -void Utf8ToBlob(dxc::SpecificDllLoader &dllSupport, const char *pVal, +void Utf8ToBlob(dxc::DllLoader &dllSupport, const char *pVal, IDxcBlobEncoding **ppBlob) { CComPtr library; IFT(dllSupport.CreateInstance(CLSID_DxcLibrary, &library)); @@ -310,32 +318,30 @@ void Utf8ToBlob(dxc::SpecificDllLoader &dllSupport, const char *pVal, ppBlob)); } -void MultiByteStringToBlob(dxc::SpecificDllLoader &dllSupport, - const std::string &val, UINT32 codePage, - IDxcBlobEncoding **ppBlob) { +void MultiByteStringToBlob(dxc::DllLoader &dllSupport, const std::string &val, + UINT32 codePage, IDxcBlobEncoding **ppBlob) { CComPtr library; IFT(dllSupport.CreateInstance(CLSID_DxcLibrary, &library)); IFT(library->CreateBlobWithEncodingOnHeapCopy(val.data(), val.size(), codePage, ppBlob)); } -void MultiByteStringToBlob(dxc::SpecificDllLoader &dllSupport, - const std::string &val, UINT32 codePage, - IDxcBlob **ppBlob) { +void MultiByteStringToBlob(dxc::DllLoader &dllSupport, const std::string &val, + UINT32 codePage, IDxcBlob **ppBlob) { MultiByteStringToBlob(dllSupport, val, codePage, (IDxcBlobEncoding **)ppBlob); } -void Utf8ToBlob(dxc::SpecificDllLoader &dllSupport, const std::string &val, +void Utf8ToBlob(dxc::DllLoader &dllSupport, const std::string &val, IDxcBlobEncoding **ppBlob) { MultiByteStringToBlob(dllSupport, val, CP_UTF8, ppBlob); } -void Utf8ToBlob(dxc::SpecificDllLoader &dllSupport, const std::string &val, +void Utf8ToBlob(dxc::DllLoader &dllSupport, const std::string &val, IDxcBlob **ppBlob) { Utf8ToBlob(dllSupport, val, (IDxcBlobEncoding **)ppBlob); } -void WideToBlob(dxc::SpecificDllLoader &dllSupport, const std::wstring &val, +void WideToBlob(dxc::DllLoader &dllSupport, const std::wstring &val, IDxcBlobEncoding **ppBlob) { CComPtr library; IFT(dllSupport.CreateInstance(CLSID_DxcLibrary, &library)); @@ -343,12 +349,12 @@ void WideToBlob(dxc::SpecificDllLoader &dllSupport, const std::wstring &val, val.data(), val.size() * sizeof(wchar_t), DXC_CP_WIDE, ppBlob)); } -void WideToBlob(dxc::SpecificDllLoader &dllSupport, const std::wstring &val, +void WideToBlob(dxc::DllLoader &dllSupport, const std::wstring &val, IDxcBlob **ppBlob) { WideToBlob(dllSupport, val, (IDxcBlobEncoding **)ppBlob); } -void VerifyCompileOK(dxc::SpecificDllLoader &dllSupport, LPCSTR pText, +void VerifyCompileOK(dxc::DllLoader &dllSupport, LPCSTR pText, LPCWSTR pTargetProfile, LPCWSTR pArgs, IDxcBlob **ppResult) { std::vector argsW; @@ -363,7 +369,7 @@ void VerifyCompileOK(dxc::SpecificDllLoader &dllSupport, LPCSTR pText, VerifyCompileOK(dllSupport, pText, pTargetProfile, args, ppResult); } -void VerifyCompileOK(dxc::SpecificDllLoader &dllSupport, LPCSTR pText, +void VerifyCompileOK(dxc::DllLoader &dllSupport, LPCSTR pText, LPCWSTR pTargetProfile, std::vector &args, IDxcBlob **ppResult) { CComPtr pCompiler; @@ -381,8 +387,8 @@ void VerifyCompileOK(dxc::SpecificDllLoader &dllSupport, LPCSTR pText, VERIFY_SUCCEEDED(pResult->GetResult(ppResult)); } -HRESULT GetVersion(dxc::SpecificDllLoader &DllSupport, REFCLSID clsid, - unsigned &Major, unsigned &Minor) { +HRESULT GetVersion(dxc::DllLoader &DllSupport, REFCLSID clsid, unsigned &Major, + unsigned &Minor) { CComPtr pUnk; if (SUCCEEDED(DllSupport.CreateInstance(clsid, &pUnk))) { CComPtr pVersionInfo; @@ -418,7 +424,7 @@ VersionSupportInfo::VersionSupportInfo() : m_CompilerIsDebugBuild(false), m_InternalValidator(false), m_DxilMajor(0), m_DxilMinor(0), m_ValMajor(0), m_ValMinor(0) {} -void VersionSupportInfo::Initialize(dxc::SpecificDllLoader &dllSupport) { +void VersionSupportInfo::Initialize(dxc::DllLoader &dllSupport) { VERIFY_IS_TRUE(dllSupport.IsEnabled()); // Default to Dxil 1.0 and internal Val 1.0 diff --git a/tools/clang/unittests/HLSLTestLib/FileCheckerTest.cpp b/tools/clang/unittests/HLSLTestLib/FileCheckerTest.cpp index 44c80e40fc..c166257bbe 100644 --- a/tools/clang/unittests/HLSLTestLib/FileCheckerTest.cpp +++ b/tools/clang/unittests/HLSLTestLib/FileCheckerTest.cpp @@ -59,7 +59,7 @@ FileRunCommandPart::FileRunCommandPart(const std::string &command, } FileRunCommandResult -FileRunCommandPart::RunHashTests(dxc::SpecificDllLoader &DllSupport) { +FileRunCommandPart::RunHashTests(dxc::DllLoader &DllSupport) { if (0 == _stricmp(Command.c_str(), "%dxc")) { return RunDxcHashTest(DllSupport); } else { @@ -68,7 +68,7 @@ FileRunCommandPart::RunHashTests(dxc::SpecificDllLoader &DllSupport) { } FileRunCommandResult -FileRunCommandPart::Run(dxc::SpecificDllLoader &DllSupport, +FileRunCommandPart::Run(dxc::DllLoader &DllSupport, const FileRunCommandResult *Prior, PluginToolsPaths *pPluginToolsPaths /*=nullptr*/, LPCWSTR dumpName /*=nullptr*/) { @@ -302,7 +302,7 @@ static void AddOutputsToFileMap(IUnknown *pUnkResult, FileMap *pVFS) { static HRESULT CompileForHash(hlsl::options::DxcOpts &opts, LPCWSTR CommandFileName, - dxc::SpecificDllLoader &DllSupport, + dxc::DllLoader &DllSupport, std::vector &flags, IDxcBlob **ppHashBlob, std::string &output) { CComPtr pLibrary; @@ -375,7 +375,7 @@ static HRESULT CompileForHash(hlsl::options::DxcOpts &opts, } FileRunCommandResult -FileRunCommandPart::RunDxcHashTest(dxc::SpecificDllLoader &DllSupport) { +FileRunCommandPart::RunDxcHashTest(dxc::DllLoader &DllSupport) { hlsl::options::MainArgs args; hlsl::options::DxcOpts opts; ReadOptsForDxc(args, opts); @@ -453,7 +453,7 @@ FileRunCommandPart::RunDxcHashTest(dxc::SpecificDllLoader &DllSupport) { return FileRunCommandResult::Success(); } -static FileRunCommandResult CheckDxilVer(dxc::SpecificDllLoader &DllSupport, +static FileRunCommandResult CheckDxilVer(dxc::DllLoader &DllSupport, unsigned RequiredDxilMajor, unsigned RequiredDxilMinor, bool bCheckValidator = true) { @@ -487,7 +487,7 @@ static FileRunCommandResult CheckDxilVer(dxc::SpecificDllLoader &DllSupport, } FileRunCommandResult -FileRunCommandPart::RunDxc(dxc::SpecificDllLoader &DllSupport, +FileRunCommandPart::RunDxc(dxc::DllLoader &DllSupport, const FileRunCommandResult *Prior) { // Support piping stdin from prior if needed. UNREFERENCED_PARAMETER(Prior); @@ -597,7 +597,7 @@ FileRunCommandPart::RunDxc(dxc::SpecificDllLoader &DllSupport, } FileRunCommandResult -FileRunCommandPart::RunDxv(dxc::SpecificDllLoader &DllSupport, +FileRunCommandPart::RunDxv(dxc::DllLoader &DllSupport, const FileRunCommandResult *Prior) { std::string args(strtrim(Arguments)); const char *inputPos = strstr(args.c_str(), "%s"); @@ -650,7 +650,7 @@ FileRunCommandPart::RunDxv(dxc::SpecificDllLoader &DllSupport, } FileRunCommandResult -FileRunCommandPart::RunOpt(dxc::SpecificDllLoader &DllSupport, +FileRunCommandPart::RunOpt(dxc::DllLoader &DllSupport, const FileRunCommandResult *Prior) { std::string args(strtrim(Arguments)); const char *inputPos = strstr(args.c_str(), "%s"); @@ -701,7 +701,7 @@ FileRunCommandPart::RunOpt(dxc::SpecificDllLoader &DllSupport, } FileRunCommandResult -FileRunCommandPart::RunListParts(dxc::SpecificDllLoader &DllSupport, +FileRunCommandPart::RunListParts(dxc::DllLoader &DllSupport, const FileRunCommandResult *Prior) { std::string args(strtrim(Arguments)); const char *inputPos = strstr(args.c_str(), "%s"); @@ -769,7 +769,7 @@ FileRunCommandPart::RunListParts(dxc::SpecificDllLoader &DllSupport, } FileRunCommandResult -FileRunCommandPart::RunD3DReflect(dxc::SpecificDllLoader &DllSupport, +FileRunCommandPart::RunD3DReflect(dxc::DllLoader &DllSupport, const FileRunCommandResult *Prior) { std::string args(strtrim(Arguments)); if (args != "%s") @@ -865,7 +865,7 @@ FileRunCommandPart::RunD3DReflect(dxc::SpecificDllLoader &DllSupport, } FileRunCommandResult -FileRunCommandPart::RunDxr(dxc::SpecificDllLoader &DllSupport, +FileRunCommandPart::RunDxr(dxc::DllLoader &DllSupport, const FileRunCommandResult *Prior) { // Support piping stdin from prior if needed. UNREFERENCED_PARAMETER(Prior); @@ -918,7 +918,7 @@ FileRunCommandPart::RunDxr(dxc::SpecificDllLoader &DllSupport, } FileRunCommandResult -FileRunCommandPart::RunLink(dxc::SpecificDllLoader &DllSupport, +FileRunCommandPart::RunLink(dxc::DllLoader &DllSupport, const FileRunCommandResult *Prior) { hlsl::options::MainArgs args; hlsl::options::DxcOpts opts; @@ -1153,7 +1153,7 @@ FileRunCommandPart::RunXFail(const FileRunCommandResult *Prior) { } FileRunCommandResult -FileRunCommandPart::RunDxilVer(dxc::SpecificDllLoader &DllSupport, +FileRunCommandPart::RunDxilVer(dxc::DllLoader &DllSupport, const FileRunCommandResult *Prior) { Arguments = strtrim(Arguments); if (Arguments.size() != 3 || !std::isdigit(Arguments[0]) || diff --git a/tools/clang/unittests/dxc_batch/dxc_batch.cpp b/tools/clang/unittests/dxc_batch/dxc_batch.cpp index 29df47c615..f611a7ee53 100644 --- a/tools/clang/unittests/dxc_batch/dxc_batch.cpp +++ b/tools/clang/unittests/dxc_batch/dxc_batch.cpp @@ -913,8 +913,7 @@ int __cdecl wmain(int argc, const wchar_t **argv_) { { std::string dllErrorString; llvm::raw_string_ostream dllErrorStream(dllErrorString); - int dllResult = - SetupSpecificDllLoader(dxcOpts, dxcSupport, dllErrorStream); + int dllResult = SetupDllLoader(dxcOpts, dxcSupport, dllErrorStream); dllErrorStream.flush(); if (dllErrorString.size()) { fprintf(stderr, "%s", dllErrorString.data()); From daf6f0af2e51603f346c84b5acac1cb3d8722f4a Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Wed, 6 Aug 2025 20:50:28 -0700 Subject: [PATCH 38/53] add override --- include/dxc/Support/dxcapi.use.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index 39993a7109..e8197b515b 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -132,14 +132,15 @@ class SpecificDllLoader : public DllLoader { return InitializeInternal(kDxCompilerLib, "DxcCreateInstance"); } - HRESULT OverrideDll(LPCSTR dll, LPCSTR entryPoint) { + HRESULT OverrideDll(LPCSTR dll, LPCSTR entryPoint) override { return InitializeInternal(dll, entryPoint); } // Also bring visibility into the interface definition of this function // which takes 2 args using DllLoader::CreateInstanceImpl; - HRESULT CreateInstanceImpl(REFCLSID clsid, REFIID riid, IUnknown **pResult) { + HRESULT CreateInstanceImpl(REFCLSID clsid, REFIID riid, + IUnknown **pResult) override { if (pResult == nullptr) return E_POINTER; if (m_dll == nullptr) @@ -152,7 +153,7 @@ class SpecificDllLoader : public DllLoader { // which takes 3 args using DllLoader::CreateInstance2Impl; HRESULT CreateInstance2Impl(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, - IUnknown **pResult) { + IUnknown **pResult) override { if (pResult == nullptr) return E_POINTER; if (m_dll == nullptr) @@ -163,9 +164,9 @@ class SpecificDllLoader : public DllLoader { return hr; } - bool HasCreateWithMalloc() const { return m_createFn2 != nullptr; } + bool HasCreateWithMalloc() const override { return m_createFn2 != nullptr; } - bool IsEnabled() const { return m_dll != nullptr; } + bool IsEnabled() const override { return m_dll != nullptr; } bool GetCreateInstanceProcs(DxcCreateInstanceProc *pCreateFn, DxcCreateInstance2Proc *pCreateFn2) const { @@ -189,7 +190,7 @@ class SpecificDllLoader : public DllLoader { } } - HMODULE Detach() { + HMODULE Detach() override { HMODULE hModule = m_dll; m_dll = nullptr; return hModule; From c8d867eed868b9aaec251013c95634c098a6927c Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Wed, 6 Aug 2025 21:04:51 -0700 Subject: [PATCH 39/53] add more overrides --- include/dxc/Support/dxcapi.extval.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/include/dxc/Support/dxcapi.extval.h b/include/dxc/Support/dxcapi.extval.h index 8bc30ca582..40cb11761a 100644 --- a/include/dxc/Support/dxcapi.extval.h +++ b/include/dxc/Support/dxcapi.extval.h @@ -19,9 +19,10 @@ class DxcDllExtValidationLoader : public DllLoader { return !DxilDllPath.empty() && !DxilExtValSupport.IsEnabled(); } - HRESULT CreateInstanceImpl(REFCLSID clsid, REFIID riid, IUnknown **pResult); + HRESULT CreateInstanceImpl(REFCLSID clsid, REFIID riid, + IUnknown **pResult) override; HRESULT CreateInstance2Impl(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, - IUnknown **pResult); + IUnknown **pResult) override; HRESULT Initialize() { return InitializeInternal("DxcCreateInstance"); } @@ -29,24 +30,24 @@ class DxcDllExtValidationLoader : public DllLoader { to satisfy the IDllLoader interface. The parameter is ignored because the relevant dlls are specific and known: dxcompiler.dll and dxil.dll. This class is not designed to handle any other dlls */ - HRESULT OverrideDll(LPCSTR dll, LPCSTR entryPoint) { + HRESULT OverrideDll(LPCSTR dll, LPCSTR entryPoint) override { return InitializeInternal(entryPoint); } - bool HasCreateWithMalloc() const { + bool HasCreateWithMalloc() const override { assert(DxCompilerSupport.HasCreateWithMalloc() && DxilExtValSupport.HasCreateWithMalloc()); return true; } - bool IsEnabled() const { return DxCompilerSupport.IsEnabled(); } + bool IsEnabled() const override { return DxCompilerSupport.IsEnabled(); } void Cleanup() override { DxilExtValSupport.Cleanup(); DxCompilerSupport.Cleanup(); } - HMODULE Detach() { + HMODULE Detach() override { // Can't Detach and return a handle for DxilSupport. Cleanup() instead. DxilExtValSupport.Cleanup(); return DxCompilerSupport.Detach(); From 0aa3c8dcd240054c7b7dbd97f522573b95debe00 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Wed, 6 Aug 2025 21:36:34 -0700 Subject: [PATCH 40/53] add virtual to destructor for HlslIntellisense --- include/dxc/Support/dxcapi.use.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index e8197b515b..6d5e539308 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -126,7 +126,7 @@ class SpecificDllLoader : public DllLoader { other.m_createFn2 = nullptr; } - ~SpecificDllLoader() { Cleanup(); } + virtual ~SpecificDllLoader() { Cleanup(); } HRESULT Initialize() { return InitializeInternal(kDxCompilerLib, "DxcCreateInstance"); From 15fceac67a4f1d6d6ecf269980f3ec9106a8e98d Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Thu, 7 Aug 2025 11:22:35 -0700 Subject: [PATCH 41/53] address Damyan: specify constructors in interface, remove cleanup from interface --- include/dxc/Support/dxcapi.extval.h | 2 +- include/dxc/Support/dxcapi.use.h | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/dxc/Support/dxcapi.extval.h b/include/dxc/Support/dxcapi.extval.h index 40cb11761a..2c7994b3c4 100644 --- a/include/dxc/Support/dxcapi.extval.h +++ b/include/dxc/Support/dxcapi.extval.h @@ -42,7 +42,7 @@ class DxcDllExtValidationLoader : public DllLoader { bool IsEnabled() const override { return DxCompilerSupport.IsEnabled(); } - void Cleanup() override { + void Cleanup() { DxilExtValSupport.Cleanup(); DxCompilerSupport.Cleanup(); } diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index 6d5e539308..d07b2476c8 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -23,6 +23,9 @@ extern const char *kDxilLib; class DllLoader { public: virtual HRESULT OverrideDll(LPCSTR dll, LPCSTR entryPoint) = 0; + DllLoader() = default; + DllLoader(const DllLoader &) = delete; + DllLoader(DllLoader &&) = delete; protected: virtual HRESULT CreateInstanceImpl(REFCLSID clsid, REFIID riid, @@ -55,7 +58,6 @@ class DllLoader { virtual bool IsEnabled() const = 0; - virtual void Cleanup() = 0; virtual HMODULE Detach() = 0; }; @@ -177,7 +179,7 @@ class SpecificDllLoader : public DllLoader { return true; } - void Cleanup() override { + void Cleanup() { if (m_dll != nullptr) { m_createFn = nullptr; m_createFn2 = nullptr; From 09be489d8a0c715984552253bb9c2ce07e1e6699 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Fri, 8 Aug 2025 12:18:43 -0700 Subject: [PATCH 42/53] address Damyan --- include/dxc/Support/HLSLOptions.h | 2 +- include/dxc/Support/dxcapi.extval.h | 11 +++------ include/dxc/Support/dxcapi.use.h | 24 ++++++++----------- include/dxc/Test/DxcTestUtils.h | 3 ++- lib/DxcSupport/HLSLOptions.cpp | 2 +- lib/DxcSupport/dxcapi.use.cpp | 2 +- .../unittests/HLSLExec/HlslExecTestUtils.h | 2 +- .../unittests/HLSLTestLib/DxcTestUtils.cpp | 3 ++- 8 files changed, 21 insertions(+), 28 deletions(-) diff --git a/include/dxc/Support/HLSLOptions.h b/include/dxc/Support/HLSLOptions.h index 41a79a815c..32293f1a7f 100644 --- a/include/dxc/Support/HLSLOptions.h +++ b/include/dxc/Support/HLSLOptions.h @@ -306,7 +306,7 @@ int ReadDxcOpts(const llvm::opt::OptTable *optionTable, unsigned flagsToInclude, llvm::raw_ostream &errors); /// Sets up the specified DllLoader instance as per the given options. -int SetupDllLoader(const DxcOpts &opts, dxc::DllLoader &dxcSupport, +int SetupDllLoader(const DxcOpts &opts, dxc::SpecificDllLoader &dxcSupport, llvm::raw_ostream &errors); void CopyArgsToWStrings(const llvm::opt::InputArgList &inArgs, diff --git a/include/dxc/Support/dxcapi.extval.h b/include/dxc/Support/dxcapi.extval.h index 2c7994b3c4..317bc87960 100644 --- a/include/dxc/Support/dxcapi.extval.h +++ b/include/dxc/Support/dxcapi.extval.h @@ -30,11 +30,11 @@ class DxcDllExtValidationLoader : public DllLoader { to satisfy the IDllLoader interface. The parameter is ignored because the relevant dlls are specific and known: dxcompiler.dll and dxil.dll. This class is not designed to handle any other dlls */ - HRESULT OverrideDll(LPCSTR dll, LPCSTR entryPoint) override { + HRESULT OverrideDll(LPCSTR dll, LPCSTR entryPoint) { return InitializeInternal(entryPoint); } - bool HasCreateWithMalloc() const override { + bool HasCreateWithMalloc() const { assert(DxCompilerSupport.HasCreateWithMalloc() && DxilExtValSupport.HasCreateWithMalloc()); return true; @@ -42,12 +42,7 @@ class DxcDllExtValidationLoader : public DllLoader { bool IsEnabled() const override { return DxCompilerSupport.IsEnabled(); } - void Cleanup() { - DxilExtValSupport.Cleanup(); - DxCompilerSupport.Cleanup(); - } - - HMODULE Detach() override { + HMODULE Detach() { // Can't Detach and return a handle for DxilSupport. Cleanup() instead. DxilExtValSupport.Cleanup(); return DxCompilerSupport.Detach(); diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index d07b2476c8..27aa45dd1c 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -21,19 +21,19 @@ extern const char *kDxilLib; // Interface for common dll operations class DllLoader { -public: - virtual HRESULT OverrideDll(LPCSTR dll, LPCSTR entryPoint) = 0; - DllLoader() = default; - DllLoader(const DllLoader &) = delete; - DllLoader(DllLoader &&) = delete; protected: virtual HRESULT CreateInstanceImpl(REFCLSID clsid, REFIID riid, IUnknown **pResult) = 0; virtual HRESULT CreateInstance2Impl(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, IUnknown **pResult) = 0; + virtual ~DllLoader() {} public: + DllLoader() = default; + DllLoader(const DllLoader &) = delete; + DllLoader(DllLoader &&) = delete; + template HRESULT CreateInstance(REFCLSID clsid, TInterface **pResult) { return CreateInstanceImpl(clsid, __uuidof(TInterface), @@ -54,11 +54,7 @@ class DllLoader { return CreateInstance2Impl(pMalloc, clsid, riid, (IUnknown **)pResult); } - virtual bool HasCreateWithMalloc() const = 0; - virtual bool IsEnabled() const = 0; - - virtual HMODULE Detach() = 0; }; // Helper class to dynamically load the dxcompiler or a compatible libraries. @@ -128,13 +124,13 @@ class SpecificDllLoader : public DllLoader { other.m_createFn2 = nullptr; } - virtual ~SpecificDllLoader() { Cleanup(); } + ~SpecificDllLoader() override { Cleanup(); } HRESULT Initialize() { return InitializeInternal(kDxCompilerLib, "DxcCreateInstance"); } - HRESULT OverrideDll(LPCSTR dll, LPCSTR entryPoint) override { + HRESULT OverrideDll(LPCSTR dll, LPCSTR entryPoint) { return InitializeInternal(dll, entryPoint); } @@ -166,7 +162,7 @@ class SpecificDllLoader : public DllLoader { return hr; } - bool HasCreateWithMalloc() const override { return m_createFn2 != nullptr; } + bool HasCreateWithMalloc() const { return m_createFn2 != nullptr; } bool IsEnabled() const override { return m_dll != nullptr; } @@ -192,7 +188,7 @@ class SpecificDllLoader : public DllLoader { } } - HMODULE Detach() override { + HMODULE Detach() { HMODULE hModule = m_dll; m_dll = nullptr; return hModule; @@ -209,7 +205,7 @@ inline DxcDefine GetDefine(LPCWSTR name, LPCWSTR value) { // Checks an HRESULT and formats an error message with the appended data. void IFT_Data(HRESULT hr, LPCWSTR data); -void EnsureEnabled(DllLoader &dxcSupport); +void EnsureEnabled(SpecificDllLoader &dxcSupport); void ReadFileIntoBlob(DllLoader &dxcSupport, LPCWSTR pFileName, IDxcBlobEncoding **ppBlobEncoding); void WriteBlobToConsole(IDxcBlob *pBlob, DWORD streamType = STD_OUTPUT_HANDLE); diff --git a/include/dxc/Test/DxcTestUtils.h b/include/dxc/Test/DxcTestUtils.h index 1b239793ab..f00a359ed0 100644 --- a/include/dxc/Test/DxcTestUtils.h +++ b/include/dxc/Test/DxcTestUtils.h @@ -197,7 +197,8 @@ bool CheckNotMsgs(const LPCSTR pText, size_t TextCount, const LPCSTR *pErrorMsgs, size_t errorMsgCount, bool bRegex); void GetDxilPart(dxc::DllLoader &dllSupport, IDxcBlob *pProgram, IDxcBlob **pDxilPart); -std::string DisassembleProgram(dxc::DllLoader &dllSupport, IDxcBlob *pProgram); +std::string DisassembleProgram(dxc::SpecificDllLoader &dllSupport, + IDxcBlob *pProgram); void SplitPassList(LPWSTR pPassesBuffer, std::vector &passes); void MultiByteStringToBlob(dxc::DllLoader &dllSupport, const std::string &val, UINT32 codePoint, IDxcBlob **ppBlob); diff --git a/lib/DxcSupport/HLSLOptions.cpp b/lib/DxcSupport/HLSLOptions.cpp index 3224de78c1..97be9b1beb 100644 --- a/lib/DxcSupport/HLSLOptions.cpp +++ b/lib/DxcSupport/HLSLOptions.cpp @@ -1384,7 +1384,7 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude, } /// Sets up the specified DllLoader instance as per the given options. -int SetupDllLoader(const DxcOpts &opts, dxc::DllLoader &dxcSupport, +int SetupDllLoader(const DxcOpts &opts, dxc::SpecificDllLoader &dxcSupport, llvm::raw_ostream &errors) { if (!opts.ExternalLib.empty()) { DXASSERT(!opts.ExternalFn.empty(), "else ReadDxcOpts should have failed"); diff --git a/lib/DxcSupport/dxcapi.use.cpp b/lib/DxcSupport/dxcapi.use.cpp index fc145a2b62..a3ce461a79 100644 --- a/lib/DxcSupport/dxcapi.use.cpp +++ b/lib/DxcSupport/dxcapi.use.cpp @@ -73,7 +73,7 @@ void IFT_Data(HRESULT hr, LPCWSTR data) { throw ::hlsl::Exception(hr, errMsg); } -void EnsureEnabled(DllLoader &dxcSupport) { +void EnsureEnabled(SpecificDllLoader &dxcSupport) { if (!dxcSupport.IsEnabled()) { IFT(dxcSupport.OverrideDll(kDxCompilerLib, "DxcCreateInstance")); } diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h index 6877b2fb77..5248136ea4 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h @@ -228,7 +228,7 @@ static bool createDevice(ID3D12Device **D3DDevice, } inline void readHlslDataIntoNewStream(LPCWSTR RelativePath, IStream **Stream, - dxc::DllLoader &Support) { + dxc::SpecificDllLoader &Support) { VERIFY_SUCCEEDED( Support.OverrideDll(dxc::kDxCompilerLib, "DxcCreateInstance")); CComPtr Library; diff --git a/tools/clang/unittests/HLSLTestLib/DxcTestUtils.cpp b/tools/clang/unittests/HLSLTestLib/DxcTestUtils.cpp index e484d48f4e..93c0e56daa 100644 --- a/tools/clang/unittests/HLSLTestLib/DxcTestUtils.cpp +++ b/tools/clang/unittests/HLSLTestLib/DxcTestUtils.cpp @@ -181,7 +181,8 @@ bool CheckOperationResultMsgs(IDxcOperationResult *pResult, maySucceedAnyway, bRegex); } -std::string DisassembleProgram(dxc::DllLoader &dllSupport, IDxcBlob *pProgram) { +std::string DisassembleProgram(dxc::SpecificDllLoader &dllSupport, + IDxcBlob *pProgram) { CComPtr pCompiler; CComPtr pDisassembly; From cba829b34caa25f6e1cbfad56b4ddf118cd79c36 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Fri, 8 Aug 2025 14:10:20 -0700 Subject: [PATCH 43/53] we keep trying, this should be it --- include/dxc/Support/dxcapi.extval.h | 23 ++--------------------- include/dxc/Support/dxcapi.use.h | 11 +---------- 2 files changed, 3 insertions(+), 31 deletions(-) diff --git a/include/dxc/Support/dxcapi.extval.h b/include/dxc/Support/dxcapi.extval.h index 317bc87960..5d0bf0173a 100644 --- a/include/dxc/Support/dxcapi.extval.h +++ b/include/dxc/Support/dxcapi.extval.h @@ -26,26 +26,7 @@ class DxcDllExtValidationLoader : public DllLoader { HRESULT Initialize() { return InitializeInternal("DxcCreateInstance"); } - /* Note, OverrideDll takes this dll argument and ignores it - to satisfy the IDllLoader interface. The parameter is ignored - because the relevant dlls are specific and known: dxcompiler.dll - and dxil.dll. This class is not designed to handle any other dlls */ - HRESULT OverrideDll(LPCSTR dll, LPCSTR entryPoint) { - return InitializeInternal(entryPoint); - } - - bool HasCreateWithMalloc() const { - assert(DxCompilerSupport.HasCreateWithMalloc() && - DxilExtValSupport.HasCreateWithMalloc()); - return true; - } - + bool IsEnabled() const override { return DxCompilerSupport.IsEnabled(); } - - HMODULE Detach() { - // Can't Detach and return a handle for DxilSupport. Cleanup() instead. - DxilExtValSupport.Cleanup(); - return DxCompilerSupport.Detach(); - } }; -} // namespace dxc \ No newline at end of file +} // namespace dxc diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index 27aa45dd1c..3b4603da82 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -31,7 +31,7 @@ class DllLoader { public: DllLoader() = default; - DllLoader(const DllLoader &) = delete; + DllLoader(const DllLoader &) = default; // needed for HlslIntellisenseSupport DllLoader(DllLoader &&) = delete; template @@ -115,15 +115,6 @@ class SpecificDllLoader : public DllLoader { SpecificDllLoader() : m_dll(nullptr), m_createFn(nullptr), m_createFn2(nullptr) {} - SpecificDllLoader(SpecificDllLoader &&other) { - m_dll = other.m_dll; - other.m_dll = nullptr; - m_createFn = other.m_createFn; - other.m_createFn = nullptr; - m_createFn2 = other.m_createFn2; - other.m_createFn2 = nullptr; - } - ~SpecificDllLoader() override { Cleanup(); } HRESULT Initialize() { From 17f26c6fc8dc8fe93c7b6a6090e1a3225c2fc4cd Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Fri, 8 Aug 2025 14:15:19 -0700 Subject: [PATCH 44/53] clang format --- include/dxc/Support/dxcapi.extval.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/dxc/Support/dxcapi.extval.h b/include/dxc/Support/dxcapi.extval.h index 5d0bf0173a..16bf8db86c 100644 --- a/include/dxc/Support/dxcapi.extval.h +++ b/include/dxc/Support/dxcapi.extval.h @@ -26,7 +26,6 @@ class DxcDllExtValidationLoader : public DllLoader { HRESULT Initialize() { return InitializeInternal("DxcCreateInstance"); } - bool IsEnabled() const override { return DxCompilerSupport.IsEnabled(); } }; } // namespace dxc From c0ee0944e5a12f952bfb8556b50537141605de06 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Fri, 8 Aug 2025 14:22:06 -0700 Subject: [PATCH 45/53] remove move ctor and copy ctor --- include/dxc/Support/dxcapi.use.h | 2 +- include/dxc/Test/CompilationResult.h | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index 3b4603da82..10ba9bcfd7 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -31,7 +31,7 @@ class DllLoader { public: DllLoader() = default; - DllLoader(const DllLoader &) = default; // needed for HlslIntellisenseSupport + DllLoader(const DllLoader &) = delete; DllLoader(DllLoader &&) = delete; template diff --git a/include/dxc/Test/CompilationResult.h b/include/dxc/Test/CompilationResult.h index f5920aabc8..8853d97c51 100644 --- a/include/dxc/Test/CompilationResult.h +++ b/include/dxc/Test/CompilationResult.h @@ -104,8 +104,6 @@ class TrivialDxcUnsavedFile : public IDxcUnsavedFile { class HlslIntellisenseSupport : public dxc::SpecificDllLoader { public: HlslIntellisenseSupport() {} - HlslIntellisenseSupport(HlslIntellisenseSupport &&other) - : dxc::SpecificDllLoader(std::move(other)) {} HRESULT CreateIntellisense(IDxcIntelliSense **pResult) { return CreateInstance(CLSID_DxcIntelliSense, pResult); From cdf321e1811271d1fdbee0ccf5cfbba810bdb06b Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Mon, 11 Aug 2025 13:29:32 -0700 Subject: [PATCH 46/53] address all but justins last comment --- external/SPIRV-Tools | 2 +- include/dxc/Support/HLSLOptions.h | 3 +-- include/dxc/Support/dxcapi.extval.h | 4 +--- include/dxc/Support/dxcapi.use.h | 4 +--- lib/DxcSupport/HLSLOptions.cpp | 4 ++-- lib/DxcSupport/dxcapi.extval.cpp | 8 +++++--- lib/DxcSupport/dxcapi.use.cpp | 2 +- projects/dxilconv/unittests/DxilConvTests.cpp | 2 +- tools/clang/tools/dxclib/dxc.cpp | 2 +- tools/clang/tools/dxopt/dxopt.cpp | 2 +- tools/clang/tools/dxrfallbackcompiler/dxillib.cpp | 3 ++- tools/clang/unittests/DxrFallback/test_DxrFallback.cpp | 4 ++-- tools/clang/unittests/HLSLExec/HlslExecTestUtils.h | 2 +- tools/clang/unittests/HLSLTestLib/DxcTestUtils.cpp | 2 +- 14 files changed, 21 insertions(+), 23 deletions(-) diff --git a/external/SPIRV-Tools b/external/SPIRV-Tools index 7dd001e5dc..7dda3c01fb 160000 --- a/external/SPIRV-Tools +++ b/external/SPIRV-Tools @@ -1 +1 @@ -Subproject commit 7dd001e5dcf5847543e252c308f036c10b0c4c42 +Subproject commit 7dda3c01fb4c0f9941d3cb792947d57d896ac55f diff --git a/include/dxc/Support/HLSLOptions.h b/include/dxc/Support/HLSLOptions.h index 32293f1a7f..4aa457355a 100644 --- a/include/dxc/Support/HLSLOptions.h +++ b/include/dxc/Support/HLSLOptions.h @@ -37,7 +37,6 @@ class raw_ostream; namespace dxc { class SpecificDllLoader; -class DllLoader; } namespace hlsl { @@ -305,7 +304,7 @@ int ReadDxcOpts(const llvm::opt::OptTable *optionTable, unsigned flagsToInclude, const MainArgs &argStrings, DxcOpts &opts, llvm::raw_ostream &errors); -/// Sets up the specified DllLoader instance as per the given options. +/// Sets up a SpecificDllLoader instance as per the given options. int SetupDllLoader(const DxcOpts &opts, dxc::SpecificDllLoader &dxcSupport, llvm::raw_ostream &errors); diff --git a/include/dxc/Support/dxcapi.extval.h b/include/dxc/Support/dxcapi.extval.h index 16bf8db86c..e479c9cce1 100644 --- a/include/dxc/Support/dxcapi.extval.h +++ b/include/dxc/Support/dxcapi.extval.h @@ -9,9 +9,7 @@ class DxcDllExtValidationLoader : public DllLoader { // manages the lifetime of dxil.dll dxc::SpecificDllLoader DxCompilerSupport; dxc::SpecificDllLoader DxilExtValSupport; - std::string DxilDllPath; - HRESULT InitializeInternal(LPCSTR fnName); public: std::string GetDxilDllPath() { return DxilDllPath; } @@ -24,7 +22,7 @@ class DxcDllExtValidationLoader : public DllLoader { HRESULT CreateInstance2Impl(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, IUnknown **pResult) override; - HRESULT Initialize() { return InitializeInternal("DxcCreateInstance"); } + HRESULT Initialize(); bool IsEnabled() const override { return DxCompilerSupport.IsEnabled(); } }; diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index 10ba9bcfd7..8ef5df72ad 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -121,13 +121,12 @@ class SpecificDllLoader : public DllLoader { return InitializeInternal(kDxCompilerLib, "DxcCreateInstance"); } - HRESULT OverrideDll(LPCSTR dll, LPCSTR entryPoint) { + HRESULT InitializeForDll(LPCSTR dll, LPCSTR entryPoint) { return InitializeInternal(dll, entryPoint); } // Also bring visibility into the interface definition of this function // which takes 2 args - using DllLoader::CreateInstanceImpl; HRESULT CreateInstanceImpl(REFCLSID clsid, REFIID riid, IUnknown **pResult) override { if (pResult == nullptr) @@ -140,7 +139,6 @@ class SpecificDllLoader : public DllLoader { // Also bring visibility into the interface definition of this function // which takes 3 args - using DllLoader::CreateInstance2Impl; HRESULT CreateInstance2Impl(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, IUnknown **pResult) override { if (pResult == nullptr) diff --git a/lib/DxcSupport/HLSLOptions.cpp b/lib/DxcSupport/HLSLOptions.cpp index 97be9b1beb..0490eea1b9 100644 --- a/lib/DxcSupport/HLSLOptions.cpp +++ b/lib/DxcSupport/HLSLOptions.cpp @@ -1388,8 +1388,8 @@ int SetupDllLoader(const DxcOpts &opts, dxc::SpecificDllLoader &dxcSupport, llvm::raw_ostream &errors) { if (!opts.ExternalLib.empty()) { DXASSERT(!opts.ExternalFn.empty(), "else ReadDxcOpts should have failed"); - HRESULT hrLoad = - dxcSupport.OverrideDll(opts.ExternalLib.data(), opts.ExternalFn.data()); + HRESULT hrLoad = dxcSupport.InitializeForDll(opts.ExternalLib.data(), + opts.ExternalFn.data()); if (DXC_FAILED(hrLoad)) { errors << "Unable to load support for external DLL " << opts.ExternalLib << " with function " << opts.ExternalFn << " - error 0x"; diff --git a/lib/DxcSupport/dxcapi.extval.cpp b/lib/DxcSupport/dxcapi.extval.cpp index 64fe9e4185..699873cc3d 100644 --- a/lib/DxcSupport/dxcapi.extval.cpp +++ b/lib/DxcSupport/dxcapi.extval.cpp @@ -25,9 +25,10 @@ HRESULT DxcDllExtValidationLoader::CreateInstance2Impl(IMalloc *pMalloc, return DxCompilerSupport.CreateInstance2(pMalloc, clsid, riid, pResult); } -HRESULT DxcDllExtValidationLoader::InitializeInternal(LPCSTR fnName) { +HRESULT DxcDllExtValidationLoader::Initialize() { // Load dxcompiler.dll - HRESULT Result = DxCompilerSupport.OverrideDll(kDxCompilerLib, fnName); + HRESULT Result = + DxCompilerSupport.InitializeForDll(kDxCompilerLib, "DxcCreateInstance"); // if dxcompiler.dll fails to load, return the failed HRESULT if (DXC_FAILED(Result)) { return Result; @@ -47,6 +48,7 @@ HRESULT DxcDllExtValidationLoader::InitializeInternal(LPCSTR fnName) { return E_INVALIDARG; } - return DxilExtValSupport.OverrideDll(DxilDllPath.c_str(), fnName); + return DxilExtValSupport.InitializeForDll(DxilDllPath.c_str(), + "DxcCreateInstance"); } } // namespace dxc diff --git a/lib/DxcSupport/dxcapi.use.cpp b/lib/DxcSupport/dxcapi.use.cpp index a3ce461a79..4bd501b63c 100644 --- a/lib/DxcSupport/dxcapi.use.cpp +++ b/lib/DxcSupport/dxcapi.use.cpp @@ -75,7 +75,7 @@ void IFT_Data(HRESULT hr, LPCWSTR data) { void EnsureEnabled(SpecificDllLoader &dxcSupport) { if (!dxcSupport.IsEnabled()) { - IFT(dxcSupport.OverrideDll(kDxCompilerLib, "DxcCreateInstance")); + IFT(dxcSupport.InitializeForDll(kDxCompilerLib, "DxcCreateInstance")); } } diff --git a/projects/dxilconv/unittests/DxilConvTests.cpp b/projects/dxilconv/unittests/DxilConvTests.cpp index 280edc28e5..2f92c86f53 100644 --- a/projects/dxilconv/unittests/DxilConvTests.cpp +++ b/projects/dxilconv/unittests/DxilConvTests.cpp @@ -170,7 +170,7 @@ class DxilConvTest { bool DxilConvTest::InitSupport() { if (!m_dllSupport.IsEnabled()) { VERIFY_SUCCEEDED( - m_dllSupport.OverrideDll("dxilconv.dll", "DxcCreateInstance")); + m_dllSupport.InitializeForDll("dxilconv.dll", "DxcCreateInstance")); } if (!FindToolInBinDir("%dxbc2dxil", "dxbc2dxil.exe")) { diff --git a/tools/clang/tools/dxclib/dxc.cpp b/tools/clang/tools/dxclib/dxc.cpp index 5e4d179b98..74dbc70040 100644 --- a/tools/clang/tools/dxclib/dxc.cpp +++ b/tools/clang/tools/dxclib/dxc.cpp @@ -1325,7 +1325,7 @@ void DxcContext::GetCompilerVersionInfo(llvm::raw_string_ostream &OS) { // Print validator if exists SpecificDllLoader DxilSupport; - DxilSupport.OverrideDll(kDxilLib, "DxcCreateInstance"); + DxilSupport.InitializeForDll(kDxilLib, "DxcCreateInstance"); WriteDXILVersionInfo(OS, DxilSupport); } diff --git a/tools/clang/tools/dxopt/dxopt.cpp b/tools/clang/tools/dxopt/dxopt.cpp index c3b8337fc1..2b42e2220d 100644 --- a/tools/clang/tools/dxopt/dxopt.cpp +++ b/tools/clang/tools/dxopt/dxopt.cpp @@ -317,7 +317,7 @@ int main(int argc, const char **argv) { if (externalLib) { CW2A externalFnA(externalFn); CW2A externalLibA(externalLib); - IFT(g_DxcSupport.OverrideDll(externalLibA, externalFnA)); + IFT(g_DxcSupport.InitializeForDll(externalLibA, externalFnA)); } else { IFT(g_DxcSupport.Initialize()); } diff --git a/tools/clang/tools/dxrfallbackcompiler/dxillib.cpp b/tools/clang/tools/dxrfallbackcompiler/dxillib.cpp index 0c2026a7e8..e12a7412da 100644 --- a/tools/clang/tools/dxrfallbackcompiler/dxillib.cpp +++ b/tools/clang/tools/dxrfallbackcompiler/dxillib.cpp @@ -46,7 +46,8 @@ bool DxilLibIsEnabled() { EnterCriticalSection(&cs); if (SUCCEEDED(g_DllLibResult)) { if (!g_DllSupport.IsEnabled()) { - g_DllLibResult = g_DllSupport.OverrideDll(kDxilLib, "DxcCreateInstance"); + g_DllLibResult = + g_DllSupport.InitializeForDll(kDxilLib, "DxcCreateInstance"); } } LeaveCriticalSection(&cs); diff --git a/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp b/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp index 5ec0326a53..7fd219544b 100644 --- a/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp +++ b/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp @@ -140,8 +140,8 @@ class Tester { Tester(const std::string &deviceName, const std::string &path) : m_deviceName(s2ws(deviceName)), m_path(path) { dxc::EnsureEnabled(m_dxcSupport); - m_dxrFallbackSupport.OverrideDll("DxrFallbackCompiler.dll", - "DxcCreateDxrFallbackCompiler"); + m_dxrFallbackSupport.InitializeForDll("DxrFallbackCompiler.dll", + "DxcCreateDxrFallbackCompiler"); } void setFiles(const std::vector &files) { diff --git a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h index 5248136ea4..96b756f535 100644 --- a/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h +++ b/tools/clang/unittests/HLSLExec/HlslExecTestUtils.h @@ -230,7 +230,7 @@ static bool createDevice(ID3D12Device **D3DDevice, inline void readHlslDataIntoNewStream(LPCWSTR RelativePath, IStream **Stream, dxc::SpecificDllLoader &Support) { VERIFY_SUCCEEDED( - Support.OverrideDll(dxc::kDxCompilerLib, "DxcCreateInstance")); + Support.InitializeForDll(dxc::kDxCompilerLib, "DxcCreateInstance")); CComPtr Library; CComPtr Blob; CComPtr StreamCom; diff --git a/tools/clang/unittests/HLSLTestLib/DxcTestUtils.cpp b/tools/clang/unittests/HLSLTestLib/DxcTestUtils.cpp index 93c0e56daa..e316e29441 100644 --- a/tools/clang/unittests/HLSLTestLib/DxcTestUtils.cpp +++ b/tools/clang/unittests/HLSLTestLib/DxcTestUtils.cpp @@ -188,7 +188,7 @@ std::string DisassembleProgram(dxc::SpecificDllLoader &dllSupport, if (!dllSupport.IsEnabled()) { VERIFY_SUCCEEDED( - dllSupport.OverrideDll(dxc::kDxCompilerLib, "DxcCreateInstance")); + dllSupport.InitializeForDll(dxc::kDxCompilerLib, "DxcCreateInstance")); } VERIFY_SUCCEEDED(dllSupport.CreateInstance(CLSID_DxcCompiler, &pCompiler)); From c8b704ac75091efcaa80cdcdb0d24869f1e49fc5 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Mon, 11 Aug 2025 15:05:04 -0700 Subject: [PATCH 47/53] do a function rename --- include/dxc/Support/HLSLOptions.h | 5 +++-- lib/DxcSupport/HLSLOptions.cpp | 7 ++++--- tools/clang/tools/dxclib/dxc.cpp | 3 ++- tools/clang/tools/dxr/dxr.cpp | 3 ++- tools/clang/unittests/dxc_batch/dxc_batch.cpp | 3 ++- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/include/dxc/Support/HLSLOptions.h b/include/dxc/Support/HLSLOptions.h index 4aa457355a..4a6868956a 100644 --- a/include/dxc/Support/HLSLOptions.h +++ b/include/dxc/Support/HLSLOptions.h @@ -305,8 +305,9 @@ int ReadDxcOpts(const llvm::opt::OptTable *optionTable, unsigned flagsToInclude, llvm::raw_ostream &errors); /// Sets up a SpecificDllLoader instance as per the given options. -int SetupDllLoader(const DxcOpts &opts, dxc::SpecificDllLoader &dxcSupport, - llvm::raw_ostream &errors); +int SetupSpecificDllLoader(const DxcOpts &opts, + dxc::SpecificDllLoader &dxcSupport, + llvm::raw_ostream &errors); void CopyArgsToWStrings(const llvm::opt::InputArgList &inArgs, unsigned flagsToInclude, diff --git a/lib/DxcSupport/HLSLOptions.cpp b/lib/DxcSupport/HLSLOptions.cpp index 0490eea1b9..06e6a1bed6 100644 --- a/lib/DxcSupport/HLSLOptions.cpp +++ b/lib/DxcSupport/HLSLOptions.cpp @@ -1383,9 +1383,10 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude, return 0; } -/// Sets up the specified DllLoader instance as per the given options. -int SetupDllLoader(const DxcOpts &opts, dxc::SpecificDllLoader &dxcSupport, - llvm::raw_ostream &errors) { +/// Sets up a SpecificDllLoader instance as per the given options. +int SetupSpecificDllLoader(const DxcOpts &opts, + dxc::SpecificDllLoader &dxcSupport, + llvm::raw_ostream &errors) { if (!opts.ExternalLib.empty()) { DXASSERT(!opts.ExternalFn.empty(), "else ReadDxcOpts should have failed"); HRESULT hrLoad = dxcSupport.InitializeForDll(opts.ExternalLib.data(), diff --git a/tools/clang/tools/dxclib/dxc.cpp b/tools/clang/tools/dxclib/dxc.cpp index 74dbc70040..098c6f4eda 100644 --- a/tools/clang/tools/dxclib/dxc.cpp +++ b/tools/clang/tools/dxclib/dxc.cpp @@ -1451,7 +1451,8 @@ int dxc::main(int argc, const char **argv_) { { std::string dllErrorString; llvm::raw_string_ostream dllErrorStream(dllErrorString); - int dllResult = SetupDllLoader(dxcOpts, dxcSupport, dllErrorStream); + int dllResult = + SetupSpecificDllLoader(dxcOpts, dxcSupport, dllErrorStream); dllErrorStream.flush(); if (dllErrorString.size()) { fprintf(stderr, "%s\n", dllErrorString.data()); diff --git a/tools/clang/tools/dxr/dxr.cpp b/tools/clang/tools/dxr/dxr.cpp index 5329e42356..54b501a196 100644 --- a/tools/clang/tools/dxr/dxr.cpp +++ b/tools/clang/tools/dxr/dxr.cpp @@ -76,7 +76,8 @@ int main(int argc, const char **argv) { { std::string dllErrorString; llvm::raw_string_ostream dllErrorStream(dllErrorString); - int dllResult = SetupDllLoader(dxcOpts, dxcSupport, dllErrorStream); + int dllResult = + SetupSpecificDllLoader(dxcOpts, dxcSupport, dllErrorStream); dllErrorStream.flush(); if (dllErrorString.size()) { fprintf(stderr, "%s\n", dllErrorString.data()); diff --git a/tools/clang/unittests/dxc_batch/dxc_batch.cpp b/tools/clang/unittests/dxc_batch/dxc_batch.cpp index f611a7ee53..29df47c615 100644 --- a/tools/clang/unittests/dxc_batch/dxc_batch.cpp +++ b/tools/clang/unittests/dxc_batch/dxc_batch.cpp @@ -913,7 +913,8 @@ int __cdecl wmain(int argc, const wchar_t **argv_) { { std::string dllErrorString; llvm::raw_string_ostream dllErrorStream(dllErrorString); - int dllResult = SetupDllLoader(dxcOpts, dxcSupport, dllErrorStream); + int dllResult = + SetupSpecificDllLoader(dxcOpts, dxcSupport, dllErrorStream); dllErrorStream.flush(); if (dllErrorString.size()) { fprintf(stderr, "%s", dllErrorString.data()); From 965f78c847f7195c66d51c64f5e44d0d11075ac2 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Tue, 12 Aug 2025 10:59:54 -0700 Subject: [PATCH 48/53] try undoing spirv change --- external/SPIRV-Tools | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/SPIRV-Tools b/external/SPIRV-Tools index 7dda3c01fb..7dd001e5dc 160000 --- a/external/SPIRV-Tools +++ b/external/SPIRV-Tools @@ -1 +1 @@ -Subproject commit 7dda3c01fb4c0f9941d3cb792947d57d896ac55f +Subproject commit 7dd001e5dcf5847543e252c308f036c10b0c4c42 From 48fb6fa4fca8635ec1a9c70f145e74948b97ca76 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Tue, 12 Aug 2025 16:11:57 -0700 Subject: [PATCH 49/53] remove unneeded forward decl --- tools/clang/unittests/HLSLExec/ShaderOpTest.h | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/clang/unittests/HLSLExec/ShaderOpTest.h b/tools/clang/unittests/HLSLExec/ShaderOpTest.h index 3c2ebd1417..23078f5303 100644 --- a/tools/clang/unittests/HLSLExec/ShaderOpTest.h +++ b/tools/clang/unittests/HLSLExec/ShaderOpTest.h @@ -31,7 +31,6 @@ /////////////////////////////////////////////////////////////////////////////// // Forward declarations. namespace dxc { -class DllLoader; class SpecificDllLoader; } struct IStream; From b100acd88d1175160137d61d0f5fb4319fc4d96e Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Wed, 13 Aug 2025 00:53:40 -0700 Subject: [PATCH 50/53] add DxCompilerDllLoader class, and use it --- include/dxc/Support/dxcapi.use.h | 11 +++++++---- include/dxc/Test/CompilationResult.h | 2 +- include/dxc/Test/DxcTestUtils.h | 2 +- projects/dxilconv/unittests/DxilConvTests.cpp | 2 +- tools/clang/tools/dxlib-sample/lib_cache_manager.cpp | 2 +- tools/clang/tools/dxopt/CMakeLists.txt | 3 +++ tools/clang/tools/dxopt/dxopt.cpp | 6 +++++- .../clang/unittests/DxrFallback/ShaderTesterImpl.cpp | 2 +- tools/clang/unittests/HLSL/CompilerTest.cpp | 10 +++++----- tools/clang/unittests/HLSL/DxilContainerTest.cpp | 2 +- tools/clang/unittests/HLSL/DxilModuleTest.cpp | 2 +- tools/clang/unittests/HLSL/ExtensionTest.cpp | 8 ++++---- tools/clang/unittests/HLSL/FunctionTest.cpp | 2 +- tools/clang/unittests/HLSL/LinkerTest.cpp | 2 +- tools/clang/unittests/HLSL/OptimizerTest.cpp | 2 +- tools/clang/unittests/HLSL/PixDiaTest.cpp | 2 +- tools/clang/unittests/HLSL/PixTest.cpp | 2 +- tools/clang/unittests/HLSL/RewriterTest.cpp | 2 +- tools/clang/unittests/HLSL/SystemValueTest.cpp | 2 +- tools/clang/unittests/HLSL/ValidationTest.cpp | 2 +- tools/clang/unittests/HLSLExec/ExecutionTest.cpp | 4 ++-- tools/clang/unittests/HLSLTestLib/FileCheckerTest.cpp | 10 +++++----- 22 files changed, 46 insertions(+), 36 deletions(-) diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index 8ef5df72ad..90752ed1da 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -117,10 +117,6 @@ class SpecificDllLoader : public DllLoader { ~SpecificDllLoader() override { Cleanup(); } - HRESULT Initialize() { - return InitializeInternal(kDxCompilerLib, "DxcCreateInstance"); - } - HRESULT InitializeForDll(LPCSTR dll, LPCSTR entryPoint) { return InitializeInternal(dll, entryPoint); } @@ -184,6 +180,13 @@ class SpecificDllLoader : public DllLoader { } }; +class DxCompilerDllLoader : public SpecificDllLoader { +public: + HRESULT Initialize() { + return InitializeForDll(kDxCompilerLib, "DxcCreateInstance"); + } +}; + inline DxcDefine GetDefine(LPCWSTR name, LPCWSTR value) { DxcDefine result; result.Name = name; diff --git a/include/dxc/Test/CompilationResult.h b/include/dxc/Test/CompilationResult.h index 8853d97c51..03a2a14bc4 100644 --- a/include/dxc/Test/CompilationResult.h +++ b/include/dxc/Test/CompilationResult.h @@ -101,7 +101,7 @@ class TrivialDxcUnsavedFile : public IDxcUnsavedFile { } }; -class HlslIntellisenseSupport : public dxc::SpecificDllLoader { +class HlslIntellisenseSupport : public dxc::DxCompilerDllLoader { public: HlslIntellisenseSupport() {} diff --git a/include/dxc/Test/DxcTestUtils.h b/include/dxc/Test/DxcTestUtils.h index f00a359ed0..60f959bfbf 100644 --- a/include/dxc/Test/DxcTestUtils.h +++ b/include/dxc/Test/DxcTestUtils.h @@ -175,7 +175,7 @@ class FileRunTestResult { PluginToolsPaths *pPluginToolsPaths = nullptr, LPCWSTR dumpName = nullptr); static FileRunTestResult - RunFromFileCommands(LPCWSTR fileName, dxc::SpecificDllLoader &dllSupport, + RunFromFileCommands(LPCWSTR fileName, dxc::DxCompilerDllLoader &dllSupport, PluginToolsPaths *pPluginToolsPaths = nullptr, LPCWSTR dumpName = nullptr); }; diff --git a/projects/dxilconv/unittests/DxilConvTests.cpp b/projects/dxilconv/unittests/DxilConvTests.cpp index 2f92c86f53..c166abb7c8 100644 --- a/projects/dxilconv/unittests/DxilConvTests.cpp +++ b/projects/dxilconv/unittests/DxilConvTests.cpp @@ -67,7 +67,7 @@ class DxilConvTest { END_TEST_METHOD() private: - dxc::SpecificDllLoader m_dllSupport; + dxc::DxCompilerDllLoader m_dllSupport; PluginToolsPaths m_TestToolPaths; void DxilConvTestCheckFile(LPCWSTR path) { diff --git a/tools/clang/tools/dxlib-sample/lib_cache_manager.cpp b/tools/clang/tools/dxlib-sample/lib_cache_manager.cpp index c423b97b28..f8a93a59f9 100644 --- a/tools/clang/tools/dxlib-sample/lib_cache_manager.cpp +++ b/tools/clang/tools/dxlib-sample/lib_cache_manager.cpp @@ -40,7 +40,7 @@ class NoFuncBodyRewriter { private: CComPtr m_pRewriter; - dxc::SpecificDllLoader m_dllSupport; + dxc::DxCompilerDllLoader m_dllSupport; }; HRESULT NoFuncBodyRewriter::RewriteToNoFuncBody( diff --git a/tools/clang/tools/dxopt/CMakeLists.txt b/tools/clang/tools/dxopt/CMakeLists.txt index 1d41efc0d2..090ce21d87 100644 --- a/tools/clang/tools/dxopt/CMakeLists.txt +++ b/tools/clang/tools/dxopt/CMakeLists.txt @@ -8,8 +8,11 @@ set( LLVM_LINK_COMPONENTS Support # just for assert and raw streams ) +set(DXCSUPPORT_DIR "${CMAKE_SOURCE_DIR}/lib/DxcSupport") + add_clang_executable(dxopt dxopt.cpp + ${DXCSUPPORT_DIR}/dxcapi.use.cpp ) target_link_libraries(dxopt diff --git a/tools/clang/tools/dxopt/dxopt.cpp b/tools/clang/tools/dxopt/dxopt.cpp index 2b42e2220d..e03c11ccc7 100644 --- a/tools/clang/tools/dxopt/dxopt.cpp +++ b/tools/clang/tools/dxopt/dxopt.cpp @@ -12,6 +12,7 @@ #include "dxc/Support/Global.h" #include "dxc/Support/Unicode.h" #include "dxc/Support/WinIncludes.h" +#include "dxc/Support/dxcapi.use.h" #include #include @@ -30,6 +31,8 @@ #include "llvm/Support/FileSystem.h" +extern const char *kDxCompilerLib; + inline bool wcseq(LPCWSTR a, LPCWSTR b) { return (a == nullptr && b == nullptr) || (a != nullptr && b != nullptr && wcscmp(a, b) == 0); @@ -319,7 +322,8 @@ int main(int argc, const char **argv) { CW2A externalLibA(externalLib); IFT(g_DxcSupport.InitializeForDll(externalLibA, externalFnA)); } else { - IFT(g_DxcSupport.Initialize()); + IFT(g_DxcSupport.InitializeForDll(dxc::kDxCompilerLib, + "DxcCreateInstance")); } CComPtr pBlob; diff --git a/tools/clang/unittests/DxrFallback/ShaderTesterImpl.cpp b/tools/clang/unittests/DxrFallback/ShaderTesterImpl.cpp index 5c85a6057b..ad37f5fe18 100644 --- a/tools/clang/unittests/DxrFallback/ShaderTesterImpl.cpp +++ b/tools/clang/unittests/DxrFallback/ShaderTesterImpl.cpp @@ -32,7 +32,7 @@ using Microsoft::WRL::ComPtr; #include "dxc/dxcapi.h" #include -static dxc::SpecificDllLoader g_DxcDllHelper; +static dxc::DxCompilerDllLoader g_DxcDllHelper; #define VERIFY_SUCCEEDED(expr) \ { \ diff --git a/tools/clang/unittests/HLSL/CompilerTest.cpp b/tools/clang/unittests/HLSL/CompilerTest.cpp index 67a3f08443..02b8652ad5 100644 --- a/tools/clang/unittests/HLSL/CompilerTest.cpp +++ b/tools/clang/unittests/HLSL/CompilerTest.cpp @@ -80,9 +80,9 @@ class TestIncludeHandler : public IDxcIncludeHandler { DXC_MICROCOM_REF_FIELD(m_dwRef) public: DXC_MICROCOM_ADDREF_RELEASE_IMPL(m_dwRef) - dxc::SpecificDllLoader &m_dllSupport; + dxc::DxCompilerDllLoader &m_dllSupport; HRESULT m_defaultErrorCode = E_FAIL; - TestIncludeHandler(dxc::SpecificDllLoader &dllSupport) + TestIncludeHandler(dxc::DxCompilerDllLoader &dllSupport) : m_dwRef(0), m_dllSupport(dllSupport), callIndex(0) {} HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppvObject) override { @@ -285,7 +285,7 @@ class CompilerTest : public ::testing::Test { TEST_METHOD_PROPERTY(L"Ignore", L"true") END_TEST_METHOD() - dxc::SpecificDllLoader m_dllSupport; + dxc::DxCompilerDllLoader m_dllSupport; VersionSupportInfo m_ver; void CreateBlobPinned(LPCVOID data, SIZE_T size, UINT32 codePage, @@ -2902,9 +2902,9 @@ class SimpleIncludeHanlder : public IDxcIncludeHandler { DXC_MICROCOM_REF_FIELD(m_dwRef) public: DXC_MICROCOM_ADDREF_RELEASE_IMPL(m_dwRef) - dxc::SpecificDllLoader &m_dllSupport; + dxc::DxCompilerDllLoader &m_dllSupport; HRESULT m_defaultErrorCode = E_FAIL; - SimpleIncludeHanlder(dxc::SpecificDllLoader &dllSupport) + SimpleIncludeHanlder(dxc::DxCompilerDllLoader &dllSupport) : m_dwRef(0), m_dllSupport(dllSupport) {} HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppvObject) override { diff --git a/tools/clang/unittests/HLSL/DxilContainerTest.cpp b/tools/clang/unittests/HLSL/DxilContainerTest.cpp index 0b364e46d6..5869923802 100644 --- a/tools/clang/unittests/HLSL/DxilContainerTest.cpp +++ b/tools/clang/unittests/HLSL/DxilContainerTest.cpp @@ -124,7 +124,7 @@ class DxilContainerTest : public ::testing::Test { TEST_METHOD_PROPERTY(L"Priority", L"1") END_TEST_METHOD() - dxc::SpecificDllLoader m_dllSupport; + dxc::DxCompilerDllLoader m_dllSupport; VersionSupportInfo m_ver; void CreateBlobPinned(LPCVOID data, SIZE_T size, UINT32 codePage, diff --git a/tools/clang/unittests/HLSL/DxilModuleTest.cpp b/tools/clang/unittests/HLSL/DxilModuleTest.cpp index ac8bf9ce49..e93bad60a1 100644 --- a/tools/clang/unittests/HLSL/DxilModuleTest.cpp +++ b/tools/clang/unittests/HLSL/DxilModuleTest.cpp @@ -46,7 +46,7 @@ class DxilModuleTest : public ::testing::Test { TEST_CLASS_SETUP(InitSupport); - dxc::SpecificDllLoader m_dllSupport; + dxc::DxCompilerDllLoader m_dllSupport; VersionSupportInfo m_ver; // Basic loading tests. diff --git a/tools/clang/unittests/HLSL/ExtensionTest.cpp b/tools/clang/unittests/HLSL/ExtensionTest.cpp index 5e5bbf53fb..47d19a3e0d 100644 --- a/tools/clang/unittests/HLSL/ExtensionTest.cpp +++ b/tools/clang/unittests/HLSL/ExtensionTest.cpp @@ -572,7 +572,7 @@ class TestSemanticDefineValidator : public IDxcSemanticDefineValidator { auto Check = [pName](const std::vector &errors, IDxcBlobEncoding **blob) { if (std::find(errors.begin(), errors.end(), pName) != errors.end()) { - dxc::SpecificDllLoader dllSupport; + dxc::DxCompilerDllLoader dllSupport; VERIFY_SUCCEEDED(dllSupport.Initialize()); std::string error("bad define: "); error.append(pName); @@ -601,7 +601,7 @@ static std::string GetCompileErrors(IDxcOperationResult *pResult) { class Compiler { public: - Compiler(dxc::SpecificDllLoader &dll) : m_dllSupport(dll) { + Compiler(dxc::DxCompilerDllLoader &dll) : m_dllSupport(dll) { VERIFY_SUCCEEDED(m_dllSupport.Initialize()); VERIFY_SUCCEEDED( m_dllSupport.CreateInstance(CLSID_DxcCompiler, &pCompiler)); @@ -654,7 +654,7 @@ class Compiler { return DisassembleProgram(m_dllSupport, pBlob); } - dxc::SpecificDllLoader &m_dllSupport; + dxc::DxCompilerDllLoader &m_dllSupport; CComPtr pCompiler; CComPtr pLangExtensions; CComPtr pCodeBlob; @@ -677,7 +677,7 @@ class ExtensionTest : public ::testing::Test { TEST_METHOD_PROPERTY(L"Priority", L"0") END_TEST_CLASS() - dxc::SpecificDllLoader m_dllSupport; + dxc::DxCompilerDllLoader m_dllSupport; TEST_METHOD(EvalAttributeCollision) TEST_METHOD(NoUnwind) diff --git a/tools/clang/unittests/HLSL/FunctionTest.cpp b/tools/clang/unittests/HLSL/FunctionTest.cpp index 3aa9c30f6b..5234b4f1f0 100644 --- a/tools/clang/unittests/HLSL/FunctionTest.cpp +++ b/tools/clang/unittests/HLSL/FunctionTest.cpp @@ -36,7 +36,7 @@ class FunctionTest : public ::testing::Test { TEST_METHOD(AllowedInParamUsesClass) TEST_METHOD(ParseRootSignature) - dxc::SpecificDllLoader m_support; + dxc::DxCompilerDllLoader m_support; std::vector rootSigText; std::string BuildSampleFunction(const char *StorageClassKeyword) { diff --git a/tools/clang/unittests/HLSL/LinkerTest.cpp b/tools/clang/unittests/HLSL/LinkerTest.cpp index 30b449d3c1..2eddcc7f6f 100644 --- a/tools/clang/unittests/HLSL/LinkerTest.cpp +++ b/tools/clang/unittests/HLSL/LinkerTest.cpp @@ -80,7 +80,7 @@ class LinkerTest : public ::testing::Test { TEST_METHOD(RunLinkWithDxcResultRdat) TEST_METHOD(RunLinkWithDxcResultErrors) - dxc::SpecificDllLoader m_dllSupport; + dxc::DxCompilerDllLoader m_dllSupport; VersionSupportInfo m_ver; void CreateLinker(IDxcLinker **pResultLinker) { diff --git a/tools/clang/unittests/HLSL/OptimizerTest.cpp b/tools/clang/unittests/HLSL/OptimizerTest.cpp index 8e75d9398b..1294a41434 100644 --- a/tools/clang/unittests/HLSL/OptimizerTest.cpp +++ b/tools/clang/unittests/HLSL/OptimizerTest.cpp @@ -117,7 +117,7 @@ class OptimizerTest : public ::testing::Test { const wchar_t *profile, bool usesViewId, int streamCount = 1); - dxc::SpecificDllLoader m_dllSupport; + dxc::DxCompilerDllLoader m_dllSupport; VersionSupportInfo m_ver; HRESULT CreateCompiler(IDxcCompiler **ppResult) { diff --git a/tools/clang/unittests/HLSL/PixDiaTest.cpp b/tools/clang/unittests/HLSL/PixDiaTest.cpp index 360d0d81ce..8890a0082c 100644 --- a/tools/clang/unittests/HLSL/PixDiaTest.cpp +++ b/tools/clang/unittests/HLSL/PixDiaTest.cpp @@ -201,7 +201,7 @@ class PixDiaTest { TEST_METHOD(DxcPixDxilDebugInfo_VariableScopes_Function) TEST_METHOD(DxcPixDxilDebugInfo_VariableScopes_Member) - dxc::SpecificDllLoader m_dllSupport; + dxc::DxCompilerDllLoader m_dllSupport; VersionSupportInfo m_ver; void RunSubProgramsCase(const char *hlsl); diff --git a/tools/clang/unittests/HLSL/PixTest.cpp b/tools/clang/unittests/HLSL/PixTest.cpp index 363d606978..991c4f38fc 100644 --- a/tools/clang/unittests/HLSL/PixTest.cpp +++ b/tools/clang/unittests/HLSL/PixTest.cpp @@ -156,7 +156,7 @@ class PixTest : public ::testing::Test { TEST_METHOD(NonUniformResourceIndex_DescriptorHeap) TEST_METHOD(NonUniformResourceIndex_Raytracing) - dxc::SpecificDllLoader m_dllSupport; + dxc::DxCompilerDllLoader m_dllSupport; VersionSupportInfo m_ver; HRESULT CreateContainerBuilder(IDxcContainerBuilder **ppResult) { diff --git a/tools/clang/unittests/HLSL/RewriterTest.cpp b/tools/clang/unittests/HLSL/RewriterTest.cpp index e5c69d7cb8..1d53a733ef 100644 --- a/tools/clang/unittests/HLSL/RewriterTest.cpp +++ b/tools/clang/unittests/HLSL/RewriterTest.cpp @@ -103,7 +103,7 @@ class RewriterTest : public ::testing::Test { TEST_METHOD(RunGlobalsUsedInMethod) TEST_METHOD(RunRewriterFails) - dxc::SpecificDllLoader m_dllSupport; + dxc::DxCompilerDllLoader m_dllSupport; CComPtr m_pIncludeHandler; struct VerifyResult { diff --git a/tools/clang/unittests/HLSL/SystemValueTest.cpp b/tools/clang/unittests/HLSL/SystemValueTest.cpp index a5d1f076a6..91d6cf1215 100644 --- a/tools/clang/unittests/HLSL/SystemValueTest.cpp +++ b/tools/clang/unittests/HLSL/SystemValueTest.cpp @@ -198,7 +198,7 @@ class SystemValueTest : public ::testing::Test { VERIFY_IS_TRUE(bMessageFound); } - dxc::SpecificDllLoader m_dllSupport; + dxc::DxCompilerDllLoader m_dllSupport; VersionSupportInfo m_ver; unsigned m_HighestMajor, m_HighestMinor; // Shader Model Supported diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp index 6aa826a3ae..1c64caf7aa 100644 --- a/tools/clang/unittests/HLSL/ValidationTest.cpp +++ b/tools/clang/unittests/HLSL/ValidationTest.cpp @@ -331,7 +331,7 @@ class ValidationTest : public ::testing::Test { TEST_METHOD(WrongPSVSizeOnZeros) TEST_METHOD(WrongPSVVersion) - dxc::SpecificDllLoader m_dllSupport; + dxc::DxCompilerDllLoader m_dllSupport; VersionSupportInfo m_ver; void TestCheck(LPCWSTR name) { diff --git a/tools/clang/unittests/HLSLExec/ExecutionTest.cpp b/tools/clang/unittests/HLSLExec/ExecutionTest.cpp index 4f8dad3ecc..68e94794cc 100644 --- a/tools/clang/unittests/HLSLExec/ExecutionTest.cpp +++ b/tools/clang/unittests/HLSLExec/ExecutionTest.cpp @@ -459,7 +459,7 @@ class ExecutionTest { L"Table:ShaderOpArithTable.xml#PackUnpackOpTable") END_TEST_METHOD() - dxc::SpecificDllLoader m_support; + dxc::DxCompilerDllLoader m_support; bool m_D3DInitCompleted = false; bool m_ExperimentalModeEnabled = false; @@ -12743,7 +12743,7 @@ __declspec(dllexport) HRESULT WINAPI pOutputStrFn(pStrCtx, L"Unable to enable info queue for D3D.\r\n."); } try { - dxc::SpecificDllLoader m_support; + dxc::DxCompilerDllLoader m_support; m_support.Initialize(); const char *pName = nullptr; diff --git a/tools/clang/unittests/HLSLTestLib/FileCheckerTest.cpp b/tools/clang/unittests/HLSLTestLib/FileCheckerTest.cpp index c166257bbe..1fc0664fa9 100644 --- a/tools/clang/unittests/HLSLTestLib/FileCheckerTest.cpp +++ b/tools/clang/unittests/HLSLTestLib/FileCheckerTest.cpp @@ -1258,7 +1258,7 @@ FileRunCommandPart::RunFromPath(const std::string &toolPath, #endif //_WIN32 class FileRunTestResultImpl : public FileRunTestResult { - dxc::SpecificDllLoader &m_support; + dxc::DxCompilerDllLoader &m_support; PluginToolsPaths *m_pPluginToolsPaths; LPCWSTR m_dumpName = nullptr; // keep track of virtual files for duration of this test (for all RUN lines) @@ -1332,7 +1332,7 @@ class FileRunTestResultImpl : public FileRunTestResult { } public: - FileRunTestResultImpl(dxc::SpecificDllLoader &support, + FileRunTestResultImpl(dxc::DxCompilerDllLoader &support, PluginToolsPaths *pPluginToolsPaths = nullptr, LPCWSTR dumpName = nullptr) : m_support(support), m_pPluginToolsPaths(pPluginToolsPaths), @@ -1371,7 +1371,7 @@ class FileRunTestResultImpl : public FileRunTestResult { FileRunTestResult FileRunTestResult::RunHashTestFromFileCommands(LPCWSTR fileName) { - dxc::SpecificDllLoader dllSupport; + dxc::DxCompilerDllLoader dllSupport; IFT(dllSupport.Initialize()); FileRunTestResultImpl result(dllSupport); result.RunHashTestFromFileCommands(fileName); @@ -1381,7 +1381,7 @@ FileRunTestResult::RunHashTestFromFileCommands(LPCWSTR fileName) { FileRunTestResult FileRunTestResult::RunFromFileCommands( LPCWSTR fileName, PluginToolsPaths *pPluginToolsPaths /*=nullptr*/, LPCWSTR dumpName /*=nullptr*/) { - dxc::SpecificDllLoader dllSupport; + dxc::DxCompilerDllLoader dllSupport; IFT(dllSupport.Initialize()); FileRunTestResultImpl result(dllSupport, pPluginToolsPaths, dumpName); result.RunFileCheckFromFileCommands(fileName); @@ -1389,7 +1389,7 @@ FileRunTestResult FileRunTestResult::RunFromFileCommands( } FileRunTestResult FileRunTestResult::RunFromFileCommands( - LPCWSTR fileName, dxc::SpecificDllLoader &dllSupport, + LPCWSTR fileName, dxc::DxCompilerDllLoader &dllSupport, PluginToolsPaths *pPluginToolsPaths /*=nullptr*/, LPCWSTR dumpName /*=nullptr*/) { FileRunTestResultImpl result(dllSupport, pPluginToolsPaths, dumpName); From f66408c0b18e7d2dc576cbd437d5c446269c9644 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Wed, 13 Aug 2025 11:32:12 -0700 Subject: [PATCH 51/53] address Justin --- include/dxc/Test/DxcTestUtils.h | 2 +- tools/clang/lib/SPIRV/EmitVisitor.cpp | 2 +- tools/clang/unittests/DxrFallback/test_DxrFallback.cpp | 2 +- tools/clang/unittests/HLSL/DxilModuleTest.cpp | 4 ++-- tools/clang/unittests/HLSLTestLib/DxcTestUtils.cpp | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/dxc/Test/DxcTestUtils.h b/include/dxc/Test/DxcTestUtils.h index 60f959bfbf..f1face7194 100644 --- a/include/dxc/Test/DxcTestUtils.h +++ b/include/dxc/Test/DxcTestUtils.h @@ -197,7 +197,7 @@ bool CheckNotMsgs(const LPCSTR pText, size_t TextCount, const LPCSTR *pErrorMsgs, size_t errorMsgCount, bool bRegex); void GetDxilPart(dxc::DllLoader &dllSupport, IDxcBlob *pProgram, IDxcBlob **pDxilPart); -std::string DisassembleProgram(dxc::SpecificDllLoader &dllSupport, +std::string DisassembleProgram(dxc::DxCompilerDllLoader &dllSupport, IDxcBlob *pProgram); void SplitPassList(LPWSTR pPassesBuffer, std::vector &passes); void MultiByteStringToBlob(dxc::DllLoader &dllSupport, const std::string &val, diff --git a/tools/clang/lib/SPIRV/EmitVisitor.cpp b/tools/clang/lib/SPIRV/EmitVisitor.cpp index a4ac83db77..1f7a9c5d3c 100644 --- a/tools/clang/lib/SPIRV/EmitVisitor.cpp +++ b/tools/clang/lib/SPIRV/EmitVisitor.cpp @@ -139,7 +139,7 @@ ReadSourceCode(llvm::StringRef filePath, std::string localFilePath(filePath.begin(), filePath.end()); try { - dxc::SpecificDllLoader dllSupport; + dxc::DxCompilerDllLoader dllSupport; IFT(dllSupport.Initialize()); CComPtr pLibrary; diff --git a/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp b/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp index 7fd219544b..7bc9a1b16a 100644 --- a/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp +++ b/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp @@ -161,7 +161,7 @@ class Tester { } protected: - SpecificDllLoader m_dxcSupport; + DxCompilerDllLoader m_dxcSupport; SpecificDllLoader m_dxrFallbackSupport; std::wstring m_deviceName; std::vector> m_inputBlobs; diff --git a/tools/clang/unittests/HLSL/DxilModuleTest.cpp b/tools/clang/unittests/HLSL/DxilModuleTest.cpp index e93bad60a1..51ff34c07c 100644 --- a/tools/clang/unittests/HLSL/DxilModuleTest.cpp +++ b/tools/clang/unittests/HLSL/DxilModuleTest.cpp @@ -96,7 +96,7 @@ bool DxilModuleTest::InitSupport() { namespace { class Compiler { public: - Compiler(dxc::SpecificDllLoader &dll) + Compiler(dxc::DxCompilerDllLoader &dll) : m_dllSupport(dll), m_msf(CreateMSFileSystem()), m_pts(m_msf.get()) { m_ver.Initialize(m_dllSupport); VERIFY_SUCCEEDED( @@ -179,7 +179,7 @@ class Compiler { return msfPtr; } - dxc::SpecificDllLoader &m_dllSupport; + dxc::DxCompilerDllLoader &m_dllSupport; VersionSupportInfo m_ver; CComPtr pCompiler; CComPtr pCodeBlob; diff --git a/tools/clang/unittests/HLSLTestLib/DxcTestUtils.cpp b/tools/clang/unittests/HLSLTestLib/DxcTestUtils.cpp index e316e29441..207a77e1ea 100644 --- a/tools/clang/unittests/HLSLTestLib/DxcTestUtils.cpp +++ b/tools/clang/unittests/HLSLTestLib/DxcTestUtils.cpp @@ -181,7 +181,7 @@ bool CheckOperationResultMsgs(IDxcOperationResult *pResult, maySucceedAnyway, bRegex); } -std::string DisassembleProgram(dxc::SpecificDllLoader &dllSupport, +std::string DisassembleProgram(dxc::DxCompilerDllLoader &dllSupport, IDxcBlob *pProgram) { CComPtr pCompiler; CComPtr pDisassembly; From c8bebeeb8a3a6f0892d5534cef3fcad80cbf5ea3 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Wed, 13 Aug 2025 12:26:05 -0700 Subject: [PATCH 52/53] fix build err --- tools/clang/unittests/SPIRV/LibTestUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/clang/unittests/SPIRV/LibTestUtils.cpp b/tools/clang/unittests/SPIRV/LibTestUtils.cpp index d3719d7e83..d5f5b32e5f 100644 --- a/tools/clang/unittests/SPIRV/LibTestUtils.cpp +++ b/tools/clang/unittests/SPIRV/LibTestUtils.cpp @@ -130,7 +130,7 @@ bool compileCodeWithSpirvGeneration(const llvm::StringRef code, rest.emplace_back(arg.begin(), arg.end()); try { - dxc::SpecificDllLoader dllSupport; + dxc::DxCompilerDllLoader dllSupport; IFT(dllSupport.Initialize()); if (hlsl::options::initHlslOptTable()) From 4633dccba11153c1374339fa1828959a8194ad50 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Thu, 14 Aug 2025 12:18:41 -0700 Subject: [PATCH 53/53] remove specificdllloader from ensureenabled, use new LibraryDllLoader instead --- include/dxc/Support/dxcapi.use.h | 15 ++++++++++++++- lib/DxcSupport/dxcapi.use.cpp | 2 +- tools/clang/tools/dxa/dxa.cpp | 2 +- tools/clang/tools/dxclib/dxc.cpp | 2 +- tools/clang/tools/dxr/dxr.cpp | 2 +- tools/clang/tools/dxv/dxv.cpp | 2 +- .../unittests/DxrFallback/test_DxrFallback.cpp | 2 +- tools/clang/unittests/dxc_batch/dxc_batch.cpp | 2 +- 8 files changed, 21 insertions(+), 8 deletions(-) diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index 90752ed1da..2a3c350dd8 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -180,6 +180,8 @@ class SpecificDllLoader : public DllLoader { } }; +// This class is for instances where we *only* expect +// to load dxcompiler.dll, and nothing else class DxCompilerDllLoader : public SpecificDllLoader { public: HRESULT Initialize() { @@ -187,6 +189,17 @@ class DxCompilerDllLoader : public SpecificDllLoader { } }; +// This class is for instances where we want to load a +// subset of any dlls that would give DxcLibrary functionality. +// e.g, load a IDxcLibrary object. +// Includes but isn't limited to dxcompiler.dll and dxil.dll +class LibraryDllLoader : public SpecificDllLoader { +public: + HRESULT Initialize() { + return InitializeForDll(kDxCompilerLib, "DxcCreateInstance"); + } +}; + inline DxcDefine GetDefine(LPCWSTR name, LPCWSTR value) { DxcDefine result; result.Name = name; @@ -197,7 +210,7 @@ inline DxcDefine GetDefine(LPCWSTR name, LPCWSTR value) { // Checks an HRESULT and formats an error message with the appended data. void IFT_Data(HRESULT hr, LPCWSTR data); -void EnsureEnabled(SpecificDllLoader &dxcSupport); +void EnsureEnabled(LibraryDllLoader &dxcSupport); void ReadFileIntoBlob(DllLoader &dxcSupport, LPCWSTR pFileName, IDxcBlobEncoding **ppBlobEncoding); void WriteBlobToConsole(IDxcBlob *pBlob, DWORD streamType = STD_OUTPUT_HANDLE); diff --git a/lib/DxcSupport/dxcapi.use.cpp b/lib/DxcSupport/dxcapi.use.cpp index 4bd501b63c..d6084f2334 100644 --- a/lib/DxcSupport/dxcapi.use.cpp +++ b/lib/DxcSupport/dxcapi.use.cpp @@ -73,7 +73,7 @@ void IFT_Data(HRESULT hr, LPCWSTR data) { throw ::hlsl::Exception(hr, errMsg); } -void EnsureEnabled(SpecificDllLoader &dxcSupport) { +void EnsureEnabled(LibraryDllLoader &dxcSupport) { if (!dxcSupport.IsEnabled()) { IFT(dxcSupport.InitializeForDll(kDxCompilerLib, "DxcCreateInstance")); } diff --git a/tools/clang/tools/dxa/dxa.cpp b/tools/clang/tools/dxa/dxa.cpp index af3681c38f..7e391c3d0d 100644 --- a/tools/clang/tools/dxa/dxa.cpp +++ b/tools/clang/tools/dxa/dxa.cpp @@ -546,7 +546,7 @@ int main(int argc, const char **argv) { return 2; } - SpecificDllLoader dxcSupport; + LibraryDllLoader dxcSupport; dxc::EnsureEnabled(dxcSupport); DxaContext context(dxcSupport); if (ListParts) { diff --git a/tools/clang/tools/dxclib/dxc.cpp b/tools/clang/tools/dxclib/dxc.cpp index 098c6f4eda..8fbe55af0a 100644 --- a/tools/clang/tools/dxclib/dxc.cpp +++ b/tools/clang/tools/dxclib/dxc.cpp @@ -1416,7 +1416,7 @@ int dxc::main(int argc, const char **argv_) { const OptTable *optionTable = getHlslOptTable(); MainArgs argStrings(argc, argv_); DxcOpts dxcOpts; - SpecificDllLoader dxcSupport; + LibraryDllLoader dxcSupport; // Read options and check errors. { diff --git a/tools/clang/tools/dxr/dxr.cpp b/tools/clang/tools/dxr/dxr.cpp index 54b501a196..e88865694e 100644 --- a/tools/clang/tools/dxr/dxr.cpp +++ b/tools/clang/tools/dxr/dxr.cpp @@ -50,7 +50,7 @@ int main(int argc, const char **argv) { const OptTable *optionTable = getHlslOptTable(); MainArgs argStrings(argc, argv_); DxcOpts dxcOpts; - SpecificDllLoader dxcSupport; + LibraryDllLoader dxcSupport; // Read options and check errors. { diff --git a/tools/clang/tools/dxv/dxv.cpp b/tools/clang/tools/dxv/dxv.cpp index 7ce5c983cc..eabae86a75 100644 --- a/tools/clang/tools/dxv/dxv.cpp +++ b/tools/clang/tools/dxv/dxv.cpp @@ -160,7 +160,7 @@ int main(int argc, const char **argv) { return 2; } - SpecificDllLoader dxcSupport; + LibraryDllLoader dxcSupport; dxc::EnsureEnabled(dxcSupport); DxvContext context(dxcSupport); diff --git a/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp b/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp index 7bc9a1b16a..85d4c33255 100644 --- a/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp +++ b/tools/clang/unittests/DxrFallback/test_DxrFallback.cpp @@ -161,7 +161,7 @@ class Tester { } protected: - DxCompilerDllLoader m_dxcSupport; + LibraryDllLoader m_dxcSupport; SpecificDllLoader m_dxrFallbackSupport; std::wstring m_deviceName; std::vector> m_inputBlobs; diff --git a/tools/clang/unittests/dxc_batch/dxc_batch.cpp b/tools/clang/unittests/dxc_batch/dxc_batch.cpp index 29df47c615..a642cacf78 100644 --- a/tools/clang/unittests/dxc_batch/dxc_batch.cpp +++ b/tools/clang/unittests/dxc_batch/dxc_batch.cpp @@ -880,7 +880,7 @@ int __cdecl wmain(int argc, const wchar_t **argv_) { MainArgs batchArgStrings(refArgs); DxcOpts dxcOpts; - SpecificDllLoader dxcSupport; + LibraryDllLoader dxcSupport; // Read options and check errors. {