Skip to content

Commit 189cb7c

Browse files
committed
almost almost
1 parent 65f1df4 commit 189cb7c

File tree

14 files changed

+78
-257
lines changed

14 files changed

+78
-257
lines changed

include/dxc/Support/dxcapi.extval.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "dxc/Support/dxcapi.use.h"
2+
#include "dxc/dxcapi.h"
3+
4+
using dxc::DxcDllSupport;
5+
6+
class DxcDllExtValidationSupport : public DxcDllSupport {
7+
// DxcDllExtValidationSupport manages the
8+
// lifetime of dxcompiler.dll, while the member, m_DxilSupport,
9+
// manages the lifetime of dxil.dll
10+
DxcDllSupport m_DxilSupport;
11+
12+
std::string DxilDllPath;
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);
16+
17+
std::string GetDxilDLLPathExt() { return DxilDllPath; }
18+
bool DxilDllSuccessfullyLoaded() {
19+
return !DxilDllPath.empty() && !m_DxilSupport.IsEnabled();
20+
}
21+
22+
HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) {
23+
// Load dxcompiler.dll
24+
HRESULT result = InitializeForDll(dllName, fnName);
25+
// if dxcompiler.dll fails to load, then we won't try loading dxil.dll,
26+
// so set this boolean to false.
27+
28+
// now handle external dxil.dll
29+
const char *envVal = std::getenv("DXC_DXIL_DLL_PATH");
30+
bool ValidateInternally = false;
31+
if (!envVal || std::string(envVal).empty()) {
32+
return S_OK;
33+
}
34+
35+
std::string DllPathStr(envVal);
36+
DxilDllPath = DllPathStr;
37+
std::filesystem::path DllPath(DllPathStr);
38+
39+
// Check if path is absolute and exists
40+
if (!DllPath.is_absolute() || !std::filesystem::exists(DllPath)) {
41+
return S_OK;
42+
}
43+
// code that calls this function is responsible for checking
44+
// to see if dxil.dll is successfully loaded.
45+
// the CheckDxilDLLLoaded function can determine whether there were any
46+
// problems loading dxil.dll or not
47+
m_DxilSupport.InitializeForDll(DllPathStr.data(), fnName);
48+
49+
return S_OK;
50+
}
51+
};

include/dxc/Support/dxcapi.use.h

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ class DxcDllSupport {
135135

136136
bool virtual HasCreateWithMalloc() const { return m_createFn2 != nullptr; }
137137

138-
bool virtual IsEnabled() const { return m_dll != nullptr; }
138+
bool IsEnabled() const { return m_dll != nullptr; }
139139

140-
bool virtual GetCreateInstanceProcs(DxcCreateInstanceProc *pCreateFn,
140+
bool GetCreateInstanceProcs(DxcCreateInstanceProc *pCreateFn,
141141
DxcCreateInstance2Proc *pCreateFn2) const {
142142
if (pCreateFn == nullptr || pCreateFn2 == nullptr ||
143143
m_createFn == nullptr)
@@ -193,64 +193,6 @@ void WriteOperationErrorsToConsole(IDxcOperationResult *pResult,
193193
void WriteOperationResultToConsole(IDxcOperationResult *pRewriteResult,
194194
bool outputWarnings);
195195

196-
class DxcDllExtValidationSupport : public DxcDllSupport {
197-
// DxcDllExtValidationSupport manages the
198-
// lifetime of dxcompiler.dll, while the member, m_DxilSupport,
199-
// manages the lifetime of dxil.dll
200-
DxcDllSupport *m_DxilSupport = nullptr;
201-
202-
std::string DxilDLLPathExt = "";
203-
bool ExternalDxilDLLInitializationSuccess = false;
204-
// override DxcDllSupport's implementation of InitializeInternal,
205-
// adding the environment variable value check for a path to a dxil.dll
206-
// for external validation
207-
HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName){
208-
209-
// Load dxcompiler.dll
210-
HRESULT result = InitializeForDll(dllName, fnName);
211-
// if dxcompiler.dll fails to load, then we won't try loading dxil.dll,
212-
// so set this boolean to false.
213-
ExternalDxilDLLInitializationSuccess = DXC_FAILED(result) ? false : true;
214-
if (!ExternalDxilDLLInitializationSuccess) {
215-
return result;
216-
}
217-
218-
// now handle external dxil.dll
219-
const char *envVal = std::getenv("DXC_DXIL_DLL_PATH");
220-
bool ValidateInternally = false;
221-
if (!envVal || std::string(envVal).empty()) {
222-
ValidateInternally = true;
223-
}
224-
225-
if (!ValidateInternally){
226-
std::string DllPathStr(envVal);
227-
DxilDLLPathExt = DllPathStr;
228-
std::filesystem::path DllPath(DllPathStr);
229-
230-
// Check if path is absolute and exists
231-
if (!DllPath.is_absolute() || !std::filesystem::exists(DllPath)) {
232-
ExternalDxilDLLInitializationSuccess = false;
233-
// TODO: Ideally emit some diagnostic that the given absolute path doesn't exist
234-
return HRESULT_FROM_WIN32(GetLastError());
235-
}
236-
result = m_DxilSupport->InitializeForDll(DllPathStr.data(), fnName);
237-
if (DXC_FAILED(result)) {
238-
ExternalDxilDLLInitializationSuccess = false;
239-
return result;
240-
}
241-
ExternalDxilDLLInitializationSuccess = true;
242-
} else {
243-
// nothing to do if we are validating internally, dxcompiler.dll
244-
// is loaded and it'll take care of validation.
245-
// No external dxil.dll will be loaded in this case
246-
ExternalDxilDLLInitializationSuccess = false;
247-
}
248-
return S_OK;
249-
}
250-
251-
std::string GetDxilDLLPathExt() { return DxilDLLPathExt; }
252-
253-
};
254196
} // namespace dxc
255197

256198
#endif

lib/DxcSupport/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_llvm_library(LLVMDxcSupport
1010
WinAdapter.cpp
1111
WinIncludes.cpp
1212
WinFunctions.cpp
13+
dxcapi.extval.cpp
1314
)
1415

1516
#generate header with platform-specific library name

lib/DxcSupport/dxcapi.extval.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

tools/clang/tools/dxcompiler/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ set(SOURCES
5757
DXCompiler.rc
5858
DXCompiler.def
5959
dxcfilesystem.cpp
60-
dxillib.cpp
6160
dxcutil.cpp
6261
dxcdisassembler.cpp
6362
dxcpdbutils.cpp
@@ -75,7 +74,6 @@ set(SOURCES
7574
dxcutil.cpp
7675
dxcdisassembler.cpp
7776
dxcpdbutils.cpp
78-
dxillib.cpp
7977
dxcvalidator.cpp
8078
dxclinker.cpp
8179
dxcshadersourceinfo.cpp

tools/clang/tools/dxcompiler/DXCompiler.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#ifdef LLVM_ON_WIN32
2020
#include "dxcetw.h"
2121
#endif
22-
#include "dxillib.h"
2322

2423
namespace hlsl {
2524
HRESULT SetupRegistryPassForHLSL();

tools/clang/tools/dxcompiler/dxcapi.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "dxcetw.h"
2626
#endif
2727
#include "dxc/DxilContainer/DxcContainerBuilder.h"
28-
#include "dxillib.h"
2928
#include <memory>
3029

3130
HRESULT CreateDxcCompiler(REFIID riid, _Out_ LPVOID *ppv);
@@ -60,8 +59,9 @@ HRESULT CreateDxcContainerBuilder(REFIID riid, _Out_ LPVOID *ppv) {
6059
// Call dxil.dll's containerbuilder
6160
*ppv = nullptr;
6261
const char *warning;
63-
HRESULT hr = DxilLibCreateInstance(CLSID_DxcContainerBuilder,
64-
(IDxcContainerBuilder **)ppv);
62+
HRESULT hr =
63+
S_OK; // originally: DxilLibCreateInstance(CLSID_DxcContainerBuilder,
64+
// (IDxcContainerBuilder **)ppv);
6565
if (FAILED(hr)) {
6666
warning = "Unable to create container builder from dxil.dll. Resulting "
6767
"container will not be signed.\n";

tools/clang/tools/dxcompiler/dxcassembler.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "dxc/Support/dxcfilesystem.h"
2020
#include "dxc/Support/microcom.h"
2121
#include "dxcutil.h"
22-
#include "dxillib.h"
2322

2423
#include "llvm/Bitcode/ReaderWriter.h"
2524
#include "llvm/IR/LLVMContext.h"

tools/clang/tools/dxcompiler/dxclinker.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "dxc/Support/dxcapi.impl.h"
1919
#include "dxc/Support/microcom.h"
2020
#include "dxc/dxcapi.h"
21-
#include "dxillib.h"
2221

2322
#include "llvm/ADT/SmallVector.h"
2423
#include <algorithm>

tools/clang/tools/dxcompiler/dxcompilerobj.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
#include "dxcompileradapter.h"
5757
#include "dxcshadersourceinfo.h"
5858
#include "dxcversion.inc"
59-
#include "dxillib.h"
6059
#include <algorithm>
6160
#include <cfloat>
6261

@@ -1322,7 +1321,7 @@ class DxcCompiler : public IDxcCompiler3,
13221321
std::string msg("Internal Compiler error: ");
13231322
switch (hr) {
13241323
case DXC_E_VALIDATOR_MISSING:
1325-
msg = "Error: external validator selected, but DXIL.dll not found.";
1324+
msg = "Error: DXIL.dll not found.";
13261325
break;
13271326
default:
13281327
break;

0 commit comments

Comments
 (0)