Skip to content

Commit 209582f

Browse files
committed
address all of Justin + Damyan 2c
1 parent 2383541 commit 209582f

26 files changed

+196
-203
lines changed

include/dxc/Support/HLSLOptions.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class raw_ostream;
3737

3838
namespace dxc {
3939
class SpecificDllLoader;
40+
class DllLoader;
4041
}
4142

4243
namespace hlsl {
@@ -304,10 +305,9 @@ int ReadDxcOpts(const llvm::opt::OptTable *optionTable, unsigned flagsToInclude,
304305
const MainArgs &argStrings, DxcOpts &opts,
305306
llvm::raw_ostream &errors);
306307

307-
/// Sets up the specified SpecificDllLoader instance as per the given options.
308-
int SetupSpecificDllLoader(const DxcOpts &opts,
309-
dxc::SpecificDllLoader &dxcSupport,
310-
llvm::raw_ostream &errors);
308+
/// Sets up the specified DllLoader instance as per the given options.
309+
int SetupDllLoader(const DxcOpts &opts, dxc::DllLoader &dxcSupport,
310+
llvm::raw_ostream &errors);
311311

312312
void CopyArgsToWStrings(const llvm::opt::InputArgList &inArgs,
313313
unsigned flagsToInclude,

include/dxc/Support/dxcapi.extval.h

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
#include "dxc/Support/dxcapi.use.h"
2+
#include <cassert>
23
#include <string>
34

45
namespace dxc {
5-
class DxcDllExtValidationLoader : public IDllLoader {
6+
class DxcDllExtValidationLoader : public DllLoader {
67
// DxCompilerSupport manages the
78
// lifetime of dxcompiler.dll, while DxilExtValSupport
89
// manages the lifetime of dxil.dll
910
dxc::SpecificDllLoader DxCompilerSupport;
1011
dxc::SpecificDllLoader DxilExtValSupport;
1112

12-
DxcCreateInstanceProc m_createFn;
13-
DxcCreateInstance2Proc m_createFn2;
14-
1513
std::string DxilDllPath;
1614
HRESULT InitializeInternal(LPCSTR fnName);
1715

@@ -21,23 +19,29 @@ class DxcDllExtValidationLoader : public IDllLoader {
2119
return !DxilDllPath.empty() && !DxilExtValSupport.IsEnabled();
2220
}
2321

24-
HRESULT CreateInstance(REFCLSID clsid, REFIID riid, IUnknown **pResult);
25-
HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid,
26-
IUnknown **pResult);
22+
HRESULT CreateInstanceImpl(REFCLSID clsid, REFIID riid, IUnknown **pResult);
23+
HRESULT CreateInstance2Impl(IMalloc *pMalloc, REFCLSID clsid, REFIID riid,
24+
IUnknown **pResult);
2725

2826
HRESULT Initialize() { return InitializeInternal("DxcCreateInstance"); }
27+
28+
/* Note, OverrideDll takes this dll argument and ignores it
29+
to satisfy the IDllLoader interface. The parameter is ignored
30+
because the relevant dlls are specific and known: dxcompiler.dll
31+
and dxil.dll. This class is not designed to handle any other dlls */
2932
HRESULT OverrideDll(LPCSTR dll, LPCSTR entryPoint) {
30-
return InitializeInternal(dll);
33+
return InitializeInternal(entryPoint);
3134
}
3235

33-
bool HasCreateWithMalloc() const { return m_createFn2 != nullptr; }
36+
bool HasCreateWithMalloc() const {
37+
assert(DxCompilerSupport.HasCreateWithMalloc() &&
38+
DxilExtValSupport.HasCreateWithMalloc());
39+
return true;
40+
}
3441

3542
bool IsEnabled() const { return DxCompilerSupport.IsEnabled(); }
3643

37-
bool GetCreateInstanceProcs(DxcCreateInstanceProc *pCreateFn,
38-
DxcCreateInstance2Proc *pCreateFn2) const;
39-
40-
void Cleanup() {
44+
void Cleanup() override {
4145
DxilExtValSupport.Cleanup();
4246
DxCompilerSupport.Cleanup();
4347
}

include/dxc/Support/dxcapi.use.h

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,47 @@ extern const char *kDxCompilerLib;
2020
extern const char *kDxilLib;
2121

2222
// Interface for common dll operations
23-
class IDllLoader {
23+
class DllLoader {
2424
public:
2525
virtual HRESULT OverrideDll(LPCSTR dll, LPCSTR entryPoint) = 0;
2626

27+
protected:
28+
virtual HRESULT CreateInstanceImpl(REFCLSID clsid, REFIID riid,
29+
IUnknown **pResult) = 0;
30+
virtual HRESULT CreateInstance2Impl(IMalloc *pMalloc, REFCLSID clsid,
31+
REFIID riid, IUnknown **pResult) = 0;
32+
33+
public:
2734
template <typename TInterface>
2835
HRESULT CreateInstance(REFCLSID clsid, TInterface **pResult) {
29-
return CreateInstance(clsid, __uuidof(TInterface), (IUnknown **)pResult);
36+
return CreateInstanceImpl(clsid, __uuidof(TInterface),
37+
(IUnknown **)pResult);
38+
}
39+
HRESULT CreateInstance(REFCLSID clsid, REFIID riid, IUnknown **pResult) {
40+
return CreateInstanceImpl(clsid, riid, (IUnknown **)pResult);
3041
}
31-
32-
virtual HRESULT CreateInstance(REFCLSID clsid, REFIID riid,
33-
IUnknown **pResult) = 0;
3442

3543
template <typename TInterface>
3644
HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid,
3745
TInterface **pResult) {
38-
return CreateInstance2(pMalloc, clsid, __uuidof(TInterface),
39-
(IUnknown **)pResult);
46+
return CreateInstance2Impl(pMalloc, clsid, __uuidof(TInterface),
47+
(IUnknown **)pResult);
48+
}
49+
HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid,
50+
IUnknown **pResult) {
51+
return CreateInstance2Impl(pMalloc, clsid, riid, (IUnknown **)pResult);
4052
}
41-
42-
virtual HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid,
43-
IUnknown **pResult) = 0;
4453

4554
virtual bool HasCreateWithMalloc() const = 0;
4655

4756
virtual bool IsEnabled() const = 0;
4857

49-
virtual bool
50-
GetCreateInstanceProcs(DxcCreateInstanceProc *pCreateFn,
51-
DxcCreateInstance2Proc *pCreateFn2) const = 0;
52-
5358
virtual void Cleanup() = 0;
5459
virtual HMODULE Detach() = 0;
5560
};
5661

5762
// Helper class to dynamically load the dxcompiler or a compatible libraries.
58-
class SpecificDllLoader : public IDllLoader {
63+
class SpecificDllLoader : public DllLoader {
5964

6065
HMODULE m_dll;
6166
DxcCreateInstanceProc m_createFn;
@@ -133,8 +138,8 @@ class SpecificDllLoader : public IDllLoader {
133138

134139
// Also bring visibility into the interface definition of this function
135140
// which takes 2 args
136-
using IDllLoader::CreateInstance;
137-
HRESULT CreateInstance(REFCLSID clsid, REFIID riid, IUnknown **pResult) {
141+
using DllLoader::CreateInstanceImpl;
142+
HRESULT CreateInstanceImpl(REFCLSID clsid, REFIID riid, IUnknown **pResult) {
138143
if (pResult == nullptr)
139144
return E_POINTER;
140145
if (m_dll == nullptr)
@@ -145,9 +150,9 @@ class SpecificDllLoader : public IDllLoader {
145150

146151
// Also bring visibility into the interface definition of this function
147152
// which takes 3 args
148-
using IDllLoader::CreateInstance2;
149-
HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid,
150-
IUnknown **pResult) {
153+
using DllLoader::CreateInstance2Impl;
154+
HRESULT CreateInstance2Impl(IMalloc *pMalloc, REFCLSID clsid, REFIID riid,
155+
IUnknown **pResult) {
151156
if (pResult == nullptr)
152157
return E_POINTER;
153158
if (m_dll == nullptr)
@@ -171,7 +176,7 @@ class SpecificDllLoader : public IDllLoader {
171176
return true;
172177
}
173178

174-
void Cleanup() {
179+
void Cleanup() override {
175180
if (m_dll != nullptr) {
176181
m_createFn = nullptr;
177182
m_createFn2 = nullptr;
@@ -201,8 +206,8 @@ inline DxcDefine GetDefine(LPCWSTR name, LPCWSTR value) {
201206
// Checks an HRESULT and formats an error message with the appended data.
202207
void IFT_Data(HRESULT hr, LPCWSTR data);
203208

204-
void EnsureEnabled(SpecificDllLoader &dxcSupport);
205-
void ReadFileIntoBlob(SpecificDllLoader &dxcSupport, LPCWSTR pFileName,
209+
void EnsureEnabled(DllLoader &dxcSupport);
210+
void ReadFileIntoBlob(DllLoader &dxcSupport, LPCWSTR pFileName,
206211
IDxcBlobEncoding **ppBlobEncoding);
207212
void WriteBlobToConsole(IDxcBlob *pBlob, DWORD streamType = STD_OUTPUT_HANDLE);
208213
void WriteBlobToFile(IDxcBlob *pBlob, LPCWSTR pFileName, UINT32 textCodePage);

include/dxc/Test/DxcTestUtils.h

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ class FileRunCommandPart {
109109
FileRunCommandPart(const FileRunCommandPart &) = default;
110110
FileRunCommandPart(FileRunCommandPart &&) = default;
111111

112-
FileRunCommandResult Run(dxc::SpecificDllLoader &DllSupport,
112+
FileRunCommandResult Run(dxc::DllLoader &DllSupport,
113113
const FileRunCommandResult *Prior,
114114
PluginToolsPaths *pPluginToolsPaths = nullptr,
115115
LPCWSTR dumpName = nullptr);
116-
FileRunCommandResult RunHashTests(dxc::SpecificDllLoader &DllSupport);
116+
FileRunCommandResult RunHashTests(dxc::DllLoader &DllSupport);
117117

118118
FileRunCommandResult ReadOptsForDxc(hlsl::options::MainArgs &argStrings,
119119
hlsl::options::DxcOpts &Opts,
@@ -127,30 +127,30 @@ class FileRunCommandPart {
127127
private:
128128
FileRunCommandResult RunFileChecker(const FileRunCommandResult *Prior,
129129
LPCWSTR dumpName = nullptr);
130-
FileRunCommandResult RunDxc(dxc::SpecificDllLoader &DllSupport,
130+
FileRunCommandResult RunDxc(dxc::DllLoader &DllSupport,
131131
const FileRunCommandResult *Prior);
132-
FileRunCommandResult RunDxv(dxc::SpecificDllLoader &DllSupport,
132+
FileRunCommandResult RunDxv(dxc::DllLoader &DllSupport,
133133
const FileRunCommandResult *Prior);
134-
FileRunCommandResult RunOpt(dxc::SpecificDllLoader &DllSupport,
134+
FileRunCommandResult RunOpt(dxc::DllLoader &DllSupport,
135135
const FileRunCommandResult *Prior);
136-
FileRunCommandResult RunListParts(dxc::SpecificDllLoader &DllSupport,
136+
FileRunCommandResult RunListParts(dxc::DllLoader &DllSupport,
137137
const FileRunCommandResult *Prior);
138-
FileRunCommandResult RunD3DReflect(dxc::SpecificDllLoader &DllSupport,
138+
FileRunCommandResult RunD3DReflect(dxc::DllLoader &DllSupport,
139139
const FileRunCommandResult *Prior);
140-
FileRunCommandResult RunDxr(dxc::SpecificDllLoader &DllSupport,
140+
FileRunCommandResult RunDxr(dxc::DllLoader &DllSupport,
141141
const FileRunCommandResult *Prior);
142-
FileRunCommandResult RunLink(dxc::SpecificDllLoader &DllSupport,
142+
FileRunCommandResult RunLink(dxc::DllLoader &DllSupport,
143143
const FileRunCommandResult *Prior);
144144
FileRunCommandResult RunTee(const FileRunCommandResult *Prior);
145145
FileRunCommandResult RunXFail(const FileRunCommandResult *Prior);
146-
FileRunCommandResult RunDxilVer(dxc::SpecificDllLoader &DllSupport,
146+
FileRunCommandResult RunDxilVer(dxc::DllLoader &DllSupport,
147147
const FileRunCommandResult *Prior);
148-
FileRunCommandResult RunDxcHashTest(dxc::SpecificDllLoader &DllSupport);
148+
FileRunCommandResult RunDxcHashTest(dxc::DllLoader &DllSupport);
149149
FileRunCommandResult RunFromPath(const std::string &path,
150150
const FileRunCommandResult *Prior);
151151
FileRunCommandResult RunFileCompareText(const FileRunCommandResult *Prior);
152152
#ifdef _WIN32
153-
FileRunCommandResult RunFxc(dxc::SpecificDllLoader &DllSupport,
153+
FileRunCommandResult RunFxc(dxc::DllLoader &DllSupport,
154154
const FileRunCommandResult *Prior);
155155
#endif
156156

@@ -180,7 +180,7 @@ class FileRunTestResult {
180180
LPCWSTR dumpName = nullptr);
181181
};
182182

183-
void AssembleToContainer(dxc::SpecificDllLoader &dllSupport, IDxcBlob *pModule,
183+
void AssembleToContainer(dxc::DllLoader &dllSupport, IDxcBlob *pModule,
184184
IDxcBlob **pContainer);
185185
std::string BlobToUtf8(IDxcBlob *pBlob);
186186
std::wstring BlobToWide(IDxcBlob *pBlob);
@@ -195,36 +195,33 @@ bool CheckMsgs(const LPCSTR pText, size_t TextCount, const LPCSTR *pErrorMsgs,
195195
size_t errorMsgCount, bool bRegex);
196196
bool CheckNotMsgs(const LPCSTR pText, size_t TextCount,
197197
const LPCSTR *pErrorMsgs, size_t errorMsgCount, bool bRegex);
198-
void GetDxilPart(dxc::SpecificDllLoader &dllSupport, IDxcBlob *pProgram,
198+
void GetDxilPart(dxc::DllLoader &dllSupport, IDxcBlob *pProgram,
199199
IDxcBlob **pDxilPart);
200-
std::string DisassembleProgram(dxc::SpecificDllLoader &dllSupport,
201-
IDxcBlob *pProgram);
200+
std::string DisassembleProgram(dxc::DllLoader &dllSupport, IDxcBlob *pProgram);
202201
void SplitPassList(LPWSTR pPassesBuffer, std::vector<LPCWSTR> &passes);
203-
void MultiByteStringToBlob(dxc::SpecificDllLoader &dllSupport,
204-
const std::string &val, UINT32 codePoint,
205-
IDxcBlob **ppBlob);
206-
void MultiByteStringToBlob(dxc::SpecificDllLoader &dllSupport,
207-
const std::string &val, UINT32 codePoint,
208-
IDxcBlobEncoding **ppBlob);
209-
void Utf8ToBlob(dxc::SpecificDllLoader &dllSupport, const std::string &val,
202+
void MultiByteStringToBlob(dxc::DllLoader &dllSupport, const std::string &val,
203+
UINT32 codePoint, IDxcBlob **ppBlob);
204+
void MultiByteStringToBlob(dxc::DllLoader &dllSupport, const std::string &val,
205+
UINT32 codePoint, IDxcBlobEncoding **ppBlob);
206+
void Utf8ToBlob(dxc::DllLoader &dllSupport, const std::string &val,
210207
IDxcBlob **ppBlob);
211-
void Utf8ToBlob(dxc::SpecificDllLoader &dllSupport, const std::string &val,
208+
void Utf8ToBlob(dxc::DllLoader &dllSupport, const std::string &val,
212209
IDxcBlobEncoding **ppBlob);
213-
void Utf8ToBlob(dxc::SpecificDllLoader &dllSupport, const char *pVal,
210+
void Utf8ToBlob(dxc::DllLoader &dllSupport, const char *pVal,
214211
IDxcBlobEncoding **ppBlob);
215-
void WideToBlob(dxc::SpecificDllLoader &dllSupport, const std::wstring &val,
212+
void WideToBlob(dxc::DllLoader &dllSupport, const std::wstring &val,
216213
IDxcBlob **ppBlob);
217-
void WideToBlob(dxc::SpecificDllLoader &dllSupport, const std::wstring &val,
214+
void WideToBlob(dxc::DllLoader &dllSupport, const std::wstring &val,
218215
IDxcBlobEncoding **ppBlob);
219-
void VerifyCompileOK(dxc::SpecificDllLoader &dllSupport, LPCSTR pText,
216+
void VerifyCompileOK(dxc::DllLoader &dllSupport, LPCSTR pText,
220217
LPCWSTR pTargetProfile, LPCWSTR pArgs,
221218
IDxcBlob **ppResult);
222-
void VerifyCompileOK(dxc::SpecificDllLoader &dllSupport, LPCSTR pText,
219+
void VerifyCompileOK(dxc::DllLoader &dllSupport, LPCSTR pText,
223220
LPCWSTR pTargetProfile, std::vector<LPCWSTR> &args,
224221
IDxcBlob **ppResult);
225222

226-
HRESULT GetVersion(dxc::SpecificDllLoader &DllSupport, REFCLSID clsid,
227-
unsigned &Major, unsigned &Minor);
223+
HRESULT GetVersion(dxc::DllLoader &DllSupport, REFCLSID clsid, unsigned &Major,
224+
unsigned &Minor);
228225
bool ParseTargetProfile(llvm::StringRef targetProfile,
229226
llvm::StringRef &outStage, unsigned &outMajor,
230227
unsigned &outMinor);
@@ -240,7 +237,7 @@ class VersionSupportInfo {
240237

241238
VersionSupportInfo();
242239
// Initialize version info structure. TODO: add device shader model support
243-
void Initialize(dxc::SpecificDllLoader &dllSupport);
240+
void Initialize(dxc::DllLoader &dllSupport);
244241
// Return true if IR sensitive test should be skipped, and log comment
245242
bool SkipIRSensitiveTest();
246243
// Return true if test requiring DXIL of given version should be skipped, and

lib/DxcSupport/HLSLOptions.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,10 +1383,9 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
13831383
return 0;
13841384
}
13851385

1386-
/// Sets up the specified SpecificDllLoader instance as per the given options.
1387-
int SetupSpecificDllLoader(const DxcOpts &opts,
1388-
dxc::SpecificDllLoader &dxcSupport,
1389-
llvm::raw_ostream &errors) {
1386+
/// Sets up the specified DllLoader instance as per the given options.
1387+
int SetupDllLoader(const DxcOpts &opts, dxc::DllLoader &dxcSupport,
1388+
llvm::raw_ostream &errors) {
13901389
if (!opts.ExternalLib.empty()) {
13911390
DXASSERT(!opts.ExternalFn.empty(), "else ReadDxcOpts should have failed");
13921391
HRESULT hrLoad =

lib/DxcSupport/dxcapi.extval.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@
66

77
namespace dxc {
88

9-
HRESULT DxcDllExtValidationLoader::CreateInstance(REFCLSID clsid, REFIID riid,
10-
IUnknown **pResult) {
9+
HRESULT DxcDllExtValidationLoader::CreateInstanceImpl(REFCLSID clsid,
10+
REFIID riid,
11+
IUnknown **pResult) {
1112
if (DxilExtValSupport.IsEnabled() && clsid == CLSID_DxcValidator)
1213
return DxilExtValSupport.CreateInstance(clsid, riid, pResult);
1314

1415
return DxCompilerSupport.CreateInstance(clsid, riid, pResult);
1516
}
1617

17-
HRESULT DxcDllExtValidationLoader::CreateInstance2(IMalloc *pMalloc,
18-
REFCLSID clsid, REFIID riid,
19-
IUnknown **pResult) {
18+
HRESULT DxcDllExtValidationLoader::CreateInstance2Impl(IMalloc *pMalloc,
19+
REFCLSID clsid,
20+
REFIID riid,
21+
IUnknown **pResult) {
2022
if (DxilExtValSupport.IsEnabled() && clsid == CLSID_DxcValidator)
2123
return DxilExtValSupport.CreateInstance2(pMalloc, clsid, riid, pResult);
2224

@@ -47,15 +49,4 @@ HRESULT DxcDllExtValidationLoader::InitializeInternal(LPCSTR fnName) {
4749

4850
return DxilExtValSupport.OverrideDll(DxilDllPath.c_str(), fnName);
4951
}
50-
51-
bool DxcDllExtValidationLoader::GetCreateInstanceProcs(
52-
DxcCreateInstanceProc *pCreateFn,
53-
DxcCreateInstance2Proc *pCreateFn2) const {
54-
if (pCreateFn == nullptr || pCreateFn2 == nullptr || m_createFn == nullptr)
55-
return false;
56-
*pCreateFn = m_createFn;
57-
*pCreateFn2 = m_createFn2;
58-
return true;
59-
}
60-
61-
} // namespace dxc
52+
} // namespace dxc

lib/DxcSupport/dxcapi.use.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ void IFT_Data(HRESULT hr, LPCWSTR data) {
7373
throw ::hlsl::Exception(hr, errMsg);
7474
}
7575

76-
void EnsureEnabled(SpecificDllLoader &dxcSupport) {
76+
void EnsureEnabled(DllLoader &dxcSupport) {
7777
if (!dxcSupport.IsEnabled()) {
78-
IFT(dxcSupport.Initialize());
78+
IFT(dxcSupport.OverrideDll(kDxCompilerLib, "DxcCreateInstance"));
7979
}
8080
}
8181

82-
void ReadFileIntoBlob(SpecificDllLoader &dxcSupport, LPCWSTR pFileName,
82+
void ReadFileIntoBlob(DllLoader &dxcSupport, LPCWSTR pFileName,
8383
IDxcBlobEncoding **ppBlobEncoding) {
8484
CComPtr<IDxcLibrary> library;
8585
IFT(dxcSupport.CreateInstance(CLSID_DxcLibrary, &library));

0 commit comments

Comments
 (0)