Skip to content

Commit e1fc524

Browse files
author
Stephen Gutekanst
committed
correct dxcompiler.dll -> static approach
Signed-off-by: Stephen Gutekanst <[email protected]>
1 parent b304393 commit e1fc524

File tree

2 files changed

+70
-63
lines changed

2 files changed

+70
-63
lines changed

include/dxc/Support/dxcapi.use.h

Lines changed: 63 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717
namespace dxc {
1818

19-
// Mach change start: static dxcompiler
20-
// extern const char *kDxCompilerLib;
21-
// Mach change end
19+
extern const char *kDxCompilerLib;
2220
// Mach change start: static dxil
2321
// extern const char *kDxilLib;
2422
// Mach change end
@@ -30,52 +28,63 @@ class DxcDllSupport {
3028
DxcCreateInstanceProc m_createFn;
3129
DxcCreateInstance2Proc m_createFn2;
3230

31+
// Mach change start: static dxcompiler
32+
// HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) {
33+
// if (m_dll != nullptr)
34+
// return S_OK;
35+
36+
// #ifdef _WIN32
37+
// m_dll = LoadLibraryA(dllName);
38+
// if (m_dll == nullptr)
39+
// return HRESULT_FROM_WIN32(GetLastError());
40+
// m_createFn = (DxcCreateInstanceProc)GetProcAddress(m_dll, fnName);
41+
42+
// if (m_createFn == nullptr) {
43+
// HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
44+
// FreeLibrary(m_dll);
45+
// m_dll = nullptr;
46+
// return hr;
47+
// }
48+
// #else
49+
// m_dll = ::dlopen(dllName, RTLD_LAZY);
50+
// if (m_dll == nullptr)
51+
// return E_FAIL;
52+
// m_createFn = (DxcCreateInstanceProc)::dlsym(m_dll, fnName);
53+
54+
// if (m_createFn == nullptr) {
55+
// ::dlclose(m_dll);
56+
// m_dll = nullptr;
57+
// return E_FAIL;
58+
// }
59+
// #endif
60+
61+
// // Only basic functions used to avoid requiring additional headers.
62+
// m_createFn2 = nullptr;
63+
// char fnName2[128];
64+
// size_t s = strlen(fnName);
65+
// if (s < sizeof(fnName2) - 2) {
66+
// memcpy(fnName2, fnName, s);
67+
// fnName2[s] = '2';
68+
// fnName2[s + 1] = '\0';
69+
// #ifdef _WIN32
70+
// m_createFn2 = (DxcCreateInstance2Proc)GetProcAddress(m_dll, fnName2);
71+
// #else
72+
// m_createFn2 = (DxcCreateInstance2Proc)::dlsym(m_dll, fnName2);
73+
// #endif
74+
// }
75+
76+
// return S_OK;
77+
// }
3378
HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) {
34-
if (m_dll != nullptr)
79+
if (strcmp(fnName, "DxcCreateInstance") == 0) {
80+
m_createFn = &DxcCreateInstance;
81+
m_createFn2 = &DxcCreateInstance2;
3582
return S_OK;
36-
37-
#ifdef _WIN32
38-
m_dll = LoadLibraryA(dllName);
39-
if (m_dll == nullptr)
40-
return HRESULT_FROM_WIN32(GetLastError());
41-
m_createFn = (DxcCreateInstanceProc)GetProcAddress(m_dll, fnName);
42-
43-
if (m_createFn == nullptr) {
44-
HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
45-
FreeLibrary(m_dll);
46-
m_dll = nullptr;
47-
return hr;
48-
}
49-
#else
50-
m_dll = ::dlopen(dllName, RTLD_LAZY);
51-
if (m_dll == nullptr)
52-
return E_FAIL;
53-
m_createFn = (DxcCreateInstanceProc)::dlsym(m_dll, fnName);
54-
55-
if (m_createFn == nullptr) {
56-
::dlclose(m_dll);
57-
m_dll = nullptr;
58-
return E_FAIL;
5983
}
60-
#endif
61-
62-
// Only basic functions used to avoid requiring additional headers.
63-
m_createFn2 = nullptr;
64-
char fnName2[128];
65-
size_t s = strlen(fnName);
66-
if (s < sizeof(fnName2) - 2) {
67-
memcpy(fnName2, fnName, s);
68-
fnName2[s] = '2';
69-
fnName2[s + 1] = '\0';
70-
#ifdef _WIN32
71-
m_createFn2 = (DxcCreateInstance2Proc)GetProcAddress(m_dll, fnName2);
72-
#else
73-
m_createFn2 = (DxcCreateInstance2Proc)::dlsym(m_dll, fnName2);
74-
#endif
75-
}
76-
77-
return S_OK;
84+
fprintf(stderr, "mach-dxcompiler: InitializeInternal: unknown GetProcAddress name: %s\n", fnName);
85+
return E_FAIL;
7886
}
87+
// Mach change end
7988

8089
public:
8190
DxcDllSupport() : m_dll(nullptr), m_createFn(nullptr), m_createFn2(nullptr) {}
@@ -91,11 +100,9 @@ class DxcDllSupport {
91100

92101
~DxcDllSupport() { Cleanup(); }
93102

94-
// Mach change start: static dxcompiler
95-
// HRESULT Initialize() {
96-
// return InitializeInternal(kDxCompilerLib, "DxcCreateInstance");
97-
// }
98-
// Mach change end
103+
HRESULT Initialize() {
104+
return InitializeInternal(kDxCompilerLib, "DxcCreateInstance");
105+
}
99106

100107
HRESULT InitializeForDll(LPCSTR dll, LPCSTR entryPoint) {
101108
return InitializeInternal(dll, entryPoint);
@@ -109,8 +116,8 @@ class DxcDllSupport {
109116
HRESULT CreateInstance(REFCLSID clsid, REFIID riid, IUnknown **pResult) {
110117
if (pResult == nullptr)
111118
return E_POINTER;
112-
if (m_dll == nullptr)
113-
return E_FAIL;
119+
// if (m_dll == nullptr)
120+
// return E_FAIL;
114121
HRESULT hr = m_createFn(clsid, riid, (LPVOID *)pResult);
115122
return hr;
116123
}
@@ -126,10 +133,10 @@ class DxcDllSupport {
126133
IUnknown **pResult) {
127134
if (pResult == nullptr)
128135
return E_POINTER;
129-
if (m_dll == nullptr)
130-
return E_FAIL;
131-
if (m_createFn2 == nullptr)
132-
return E_FAIL;
136+
// if (m_dll == nullptr)
137+
// return E_FAIL;
138+
// if (m_createFn2 == nullptr)
139+
// return E_FAIL;
133140
HRESULT hr = m_createFn2(pMalloc, clsid, riid, (LPVOID *)pResult);
134141
return hr;
135142
}

lib/DxcSupport/dxcapi.use.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
namespace dxc {
2727

2828
// Mach change start: static dxcompiler
29-
// const char *kDxCompilerLib =
30-
// CMAKE_SHARED_LIBRARY_PREFIX "dxcompiler" CMAKE_SHARED_LIBRARY_SUFFIX;
29+
#define CMAKE_SHARED_LIBRARY_PREFIX
30+
#define CMAKE_SHARED_LIBRARY_SUFFIX
3131
// Mach change end
32+
const char *kDxCompilerLib =
33+
CMAKE_SHARED_LIBRARY_PREFIX "dxcompiler" CMAKE_SHARED_LIBRARY_SUFFIX;
3234
// Mach change start: static dxil
3335
// const char *kDxilLib =
3436
// CMAKE_SHARED_LIBRARY_PREFIX "dxil" CMAKE_SHARED_LIBRARY_SUFFIX;
@@ -83,11 +85,9 @@ void IFT_Data(HRESULT hr, LPCWSTR data) {
8385
}
8486

8587
void EnsureEnabled(DxcDllSupport &dxcSupport) {
86-
// Mach change start: static dxcompiler
87-
// if (!dxcSupport.IsEnabled()) {
88-
// IFT(dxcSupport.Initialize());
89-
// }
90-
// Mach change end
88+
if (!dxcSupport.IsEnabled()) {
89+
IFT(dxcSupport.Initialize());
90+
}
9191
}
9292

9393
void ReadFileIntoBlob(DxcDllSupport &dxcSupport, LPCWSTR pFileName,

0 commit comments

Comments
 (0)