Skip to content

Commit 36c33a2

Browse files
committed
do not inherit from DxcDllSupport
1 parent eb1e96f commit 36c33a2

File tree

4 files changed

+56
-46
lines changed

4 files changed

+56
-46
lines changed

include/dxc/Support/dxcapi.extval.h

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,43 @@
11
#include "dxc/Support/dxcapi.use.h"
22
#include <string>
33

4-
class DxcDllExtValidationSupport : public dxc::DxcDllSupport {
5-
// DxcDllExtValidationSupport manages the
6-
// lifetime of dxcompiler.dll, while the member, DxilSupport,
4+
namespace dxc {
5+
class DxcDllExtValidationSupport {
6+
// DxcompilerSupport manages the
7+
// lifetime of dxcompiler.dll, while DxilExtValSupport
78
// manages the lifetime of dxil.dll
89
protected:
9-
dxc::DxcDllSupport DxilSupport;
10+
dxc::DxcDllSupport DxcompilerSupport;
11+
dxc::DxcDllSupport DxilExtValSupport;
1012

1113
std::string DxilDllPath;
1214

13-
// override DxcDllSupport's implementation of InitializeInternal,
14-
// adding the environment variable value check for a path to a dxil.dll
15-
HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) override;
16-
1715
public:
1816
std::string GetDxilDllPath() { return DxilDllPath; }
1917
bool DxilDllFailedToLoad() {
20-
return !DxilDllPath.empty() && !DxilSupport.IsEnabled();
18+
return !DxilDllPath.empty() && !DxilExtValSupport.IsEnabled();
2119
}
2220

23-
void Cleanup() override {
24-
DxilSupport.Cleanup();
25-
DxcDllSupport::Cleanup();
21+
void Cleanup() {
22+
DxilExtValSupport.Cleanup();
23+
DxcompilerSupport.Cleanup();
2624
}
2725

28-
HMODULE Detach() override {
26+
HMODULE Detach() {
2927
// Can't Detach and return a handle for DxilSupport. Cleanup() instead.
30-
DxilSupport.Cleanup();
31-
return DxcDllSupport::Detach();
28+
DxilExtValSupport.Cleanup();
29+
return DxcompilerSupport.Detach();
3230
}
3331

34-
HRESULT CreateInstance(REFCLSID clsid, REFIID riid,
35-
IUnknown **pResult) override;
32+
HRESULT CreateInstance(REFCLSID clsid, REFIID riid, IUnknown **pResult);
3633
HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid,
37-
IUnknown **pResult) override;
34+
IUnknown **pResult);
35+
36+
HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName);
37+
HRESULT Initialize() {
38+
return InitializeInternal(kDxCompilerLib, "DxcCreateInstance");
39+
}
40+
41+
bool IsEnabled() const { return DxcompilerSupport.m_dll != nullptr; }
3842
};
43+
} // namespace dxc

include/dxc/Support/dxcapi.use.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ extern const char *kDxilLib;
2121

2222
// Helper class to dynamically load the dxcompiler or a compatible libraries.
2323
class DxcDllSupport {
24+
friend class DxcDllExtValidationSupport;
25+
2426
protected:
2527
HMODULE m_dll;
2628
DxcCreateInstanceProc m_createFn;
2729
DxcCreateInstance2Proc m_createFn2;
2830

29-
virtual HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) {
31+
HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) {
3032
if (m_dll != nullptr)
3133
return S_OK;
3234

@@ -85,7 +87,7 @@ class DxcDllSupport {
8587
other.m_createFn2 = nullptr;
8688
}
8789

88-
virtual ~DxcDllSupport() { Cleanup(); }
90+
~DxcDllSupport() { Cleanup(); }
8991

9092
HRESULT Initialize() {
9193
return InitializeInternal(kDxCompilerLib, "DxcCreateInstance");
@@ -100,8 +102,7 @@ class DxcDllSupport {
100102
return CreateInstance(clsid, __uuidof(TInterface), (IUnknown **)pResult);
101103
}
102104

103-
virtual HRESULT CreateInstance(REFCLSID clsid, REFIID riid,
104-
IUnknown **pResult) {
105+
HRESULT CreateInstance(REFCLSID clsid, REFIID riid, IUnknown **pResult) {
105106
if (pResult == nullptr)
106107
return E_POINTER;
107108
if (m_dll == nullptr)
@@ -117,8 +118,8 @@ class DxcDllSupport {
117118
(IUnknown **)pResult);
118119
}
119120

120-
virtual HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid,
121-
IUnknown **pResult) {
121+
HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid,
122+
IUnknown **pResult) {
122123
if (pResult == nullptr)
123124
return E_POINTER;
124125
if (m_dll == nullptr)
@@ -142,7 +143,7 @@ class DxcDllSupport {
142143
return true;
143144
}
144145

145-
virtual void Cleanup() {
146+
void Cleanup() {
146147
if (m_dll != nullptr) {
147148
m_createFn = nullptr;
148149
m_createFn2 = nullptr;
@@ -155,7 +156,7 @@ class DxcDllSupport {
155156
}
156157
}
157158

158-
virtual HMODULE Detach() {
159+
HMODULE Detach() {
159160
HMODULE hModule = m_dll;
160161
m_dll = nullptr;
161162
return hModule;

lib/DxcSupport/dxcapi.extval.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,29 @@
44
// WinIncludes must come before dxcapi.extval.h
55
#include "dxc/Support/dxcapi.extval.h"
66

7+
namespace dxc {
8+
9+
HRESULT DxcDllExtValidationSupport::CreateInstance(REFCLSID clsid, REFIID riid,
10+
IUnknown **pResult) {
11+
if (DxilExtValSupport.IsEnabled() && clsid == CLSID_DxcValidator)
12+
return DxilExtValSupport.CreateInstance(clsid, riid, pResult);
13+
14+
return DxcompilerSupport.CreateInstance(clsid, riid, pResult);
15+
}
16+
17+
HRESULT DxcDllExtValidationSupport::CreateInstance2(IMalloc *pMalloc,
18+
REFCLSID clsid, REFIID riid,
19+
IUnknown **pResult) {
20+
if (DxilExtValSupport.IsEnabled() && clsid == CLSID_DxcValidator)
21+
return DxilExtValSupport.CreateInstance2(pMalloc, clsid, riid, pResult);
22+
23+
return DxcompilerSupport.CreateInstance2(pMalloc, clsid, riid, pResult);
24+
}
25+
726
HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR dllName,
827
LPCSTR fnName) {
928
// Load dxcompiler.dll
10-
HRESULT Result = DxcDllSupport::InitializeInternal(dllName, fnName);
29+
HRESULT Result = DxcompilerSupport.InitializeInternal(dllName, fnName);
1130
// if dxcompiler.dll fails to load, return the failed HRESULT
1231
if (DXC_FAILED(Result)) {
1332
return Result;
@@ -31,24 +50,9 @@ HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR dllName,
3150
// to see if dxil.dll is successfully loaded.
3251
// the CheckDxilDLLLoaded function can determine whether there were any
3352
// problems loading dxil.dll or not
34-
DxilSupport.InitializeForDll(DllPathStr.data(), fnName);
53+
DxilExtValSupport.InitializeForDll(DllPathStr.data(), fnName);
3554

3655
return S_OK;
3756
}
3857

39-
HRESULT DxcDllExtValidationSupport::CreateInstance(REFCLSID clsid, REFIID riid,
40-
IUnknown **pResult) {
41-
if (DxilSupport.IsEnabled() && clsid == CLSID_DxcValidator)
42-
return DxilSupport.CreateInstance(clsid, riid, pResult);
43-
44-
return DxcDllSupport::CreateInstance(clsid, riid, pResult);
45-
}
46-
47-
HRESULT DxcDllExtValidationSupport::CreateInstance2(IMalloc *pMalloc,
48-
REFCLSID clsid, REFIID riid,
49-
IUnknown **pResult) {
50-
if (DxilSupport.IsEnabled() && clsid == CLSID_DxcValidator)
51-
return DxilSupport.CreateInstance2(pMalloc, clsid, riid, pResult);
52-
53-
return DxcDllSupport::CreateInstance2(pMalloc, clsid, riid, pResult);
54-
}
58+
} // namespace dxc

tools/clang/unittests/HLSL/ValidationTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4235,8 +4235,8 @@ void SetEnvVarW(const std::wstring &VarName, const std::wstring &VarValue) {
42354235
// works as intended.
42364236

42374237
TEST_F(ValidationTest, UnitTestExtValidationSupport) {
4238-
DxcDllExtValidationSupport ExtSupportEmpty;
4239-
DxcDllExtValidationSupport ExtSupportBogus;
4238+
dxc::DxcDllExtValidationSupport ExtSupportEmpty;
4239+
dxc::DxcDllExtValidationSupport ExtSupportBogus;
42404240

42414241
// capture any existing value in the environment variable,
42424242
// so that it can be restored after the test

0 commit comments

Comments
 (0)