1616
1717namespace 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
8089public:
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 }
0 commit comments