-
Notifications
You must be signed in to change notification settings - Fork 792
Create new class to handle external validation, and rename existing dll loading class. #7514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 21 commits
d7d1936
c527502
7f7dc30
e7ec854
39f913c
3700bfd
33c88f9
544a9c7
eeb1516
9800c91
a4c9629
a9282fd
e781627
2915a8d
57dd853
98b25af
c274e5b
b46def4
b76fab2
89dcc4a
acbf68a
f2890f5
eb1e96f
36c33a2
6577046
80b50a6
bfc508f
a144ca1
bd01fa5
647c946
a29f6ee
fffb407
5411894
45f74fa
64f61a8
ed23ada
2383541
209582f
daf6f0a
c8d867e
0aa3c8d
15fceac
09be489
be99192
cba829b
17f26c6
c0ee094
cdf321e
c8b704a
965f78c
48fb6fa
b100acd
f66408c
c8bebee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "dxc/Support/dxcapi.use.h" | ||
#include <string> | ||
|
||
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; | ||
tex3d marked this conversation as resolved.
Show resolved
Hide resolved
damyanp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
std::string DxilDllPath; | ||
tex3d marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// 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() { | ||
tex3d marked this conversation as resolved.
Show resolved
Hide resolved
damyanp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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(); | ||
return DxcDllSupport::Detach(); | ||
} | ||
|
||
HRESULT CreateInstance(REFCLSID clsid, REFIID riid, | ||
IUnknown **pResult) override; | ||
HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, | ||
IUnknown **pResult) override; | ||
}; | ||
tex3d marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,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; | ||
|
||
|
@@ -85,7 +85,7 @@ class DxcDllSupport { | |
other.m_createFn2 = nullptr; | ||
} | ||
|
||
~DxcDllSupport() { Cleanup(); } | ||
virtual ~DxcDllSupport() { Cleanup(); } | ||
|
||
HRESULT Initialize() { | ||
return InitializeInternal(kDxCompilerLib, "DxcCreateInstance"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having this particular implementation of I don't think this is really possible without either removing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps it would raise an eyebrow on first glance, but the initialize function needs a dll to work with, because it has no args. We need some dll to default to, and dxcompilerlib is a fine one to default to. If users wanted something else, they could initialize with OverrideDll and specify the dll. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I'm saying is is "do we even want an For convenience, we could subclass this with |
||
|
@@ -100,7 +100,8 @@ class DxcDllSupport { | |
return CreateInstance(clsid, __uuidof(TInterface), (IUnknown **)pResult); | ||
} | ||
|
||
HRESULT CreateInstance(REFCLSID clsid, REFIID riid, IUnknown **pResult) { | ||
virtual HRESULT CreateInstance(REFCLSID clsid, REFIID riid, | ||
IUnknown **pResult) { | ||
if (pResult == nullptr) | ||
return E_POINTER; | ||
if (m_dll == nullptr) | ||
|
@@ -116,8 +117,8 @@ class DxcDllSupport { | |
(IUnknown **)pResult); | ||
} | ||
|
||
HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, | ||
IUnknown **pResult) { | ||
virtual HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, | ||
IUnknown **pResult) { | ||
tex3d marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (pResult == nullptr) | ||
return E_POINTER; | ||
if (m_dll == nullptr) | ||
|
@@ -132,7 +133,16 @@ class DxcDllSupport { | |
|
||
bool IsEnabled() const { return m_dll != nullptr; } | ||
|
||
void Cleanup() { | ||
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; | ||
} | ||
|
||
virtual void Cleanup() { | ||
if (m_dll != nullptr) { | ||
m_createFn = nullptr; | ||
m_createFn2 = nullptr; | ||
|
@@ -145,7 +155,7 @@ class DxcDllSupport { | |
} | ||
} | ||
|
||
HMODULE Detach() { | ||
virtual HMODULE Detach() { | ||
HMODULE hModule = m_dll; | ||
m_dll = nullptr; | ||
return hModule; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "dxc/Support/WinIncludes.h" | ||
#include <dxc/Support/Global.h> // for hresult handling with DXC_FAILED | ||
#include <filesystem> // 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 | ||
damyanp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
HRESULT Result = DxcDllSupport::InitializeInternal(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 *EnvVarVal = std::getenv("DXC_DXIL_DLL_PATH"); | ||
if (!EnvVarVal || std::string(EnvVarVal).empty()) { | ||
return S_OK; | ||
} | ||
|
||
std::string DllPathStr(EnvVarVal); | ||
DxilDllPath = DllPathStr; | ||
damyanp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
DxilSupport.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); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.