diff --git a/ThunkLibs/GuestLibs/CMakeLists.txt b/ThunkLibs/GuestLibs/CMakeLists.txt index 988901c52..5d91f2b07 100644 --- a/ThunkLibs/GuestLibs/CMakeLists.txt +++ b/ThunkLibs/GuestLibs/CMakeLists.txt @@ -112,7 +112,7 @@ add_guest_lib(asound) generate(libEGL ${CMAKE_CURRENT_SOURCE_DIR}/../libEGL/libEGL_interface.cpp thunks function_packs function_packs_public) add_guest_lib(EGL) -generate(libGL ${CMAKE_CURRENT_SOURCE_DIR}/../libGL/libGL_interface.cpp thunks function_packs function_packs_public) +generate(libGL ${CMAKE_CURRENT_SOURCE_DIR}/../libGL/libGL_interface.cpp thunks function_packs function_packs_public symbol_list) add_guest_lib(GL) # disabled for now, headers are platform specific diff --git a/ThunkLibs/libGL/libGL_Guest.cpp b/ThunkLibs/libGL/libGL_Guest.cpp index c9d8609c7..05fe827f3 100644 --- a/ThunkLibs/libGL/libGL_Guest.cpp +++ b/ThunkLibs/libGL/libGL_Guest.cpp @@ -8,36 +8,56 @@ $end_info$ #define GL_GLEXT_PROTOTYPES 1 #define GLX_GLXEXT_PROTOTYPES 1 -#include "glcorearb.h" - #include #include #include #include + +#undef GL_ARB_viewport_array +#include "glcorearb.h" + #include -#include +#include +#include +#include +#include #include "common/Guest.h" #include "thunks.inl" #include "function_packs.inl" #include "function_packs_public.inl" +#include "symbol_list.inl" typedef void voidFunc(); +// Maps OpenGL API function names to the address of a guest function which is +// linked to the corresponding host function pointer +const std::unordered_map HostPtrInvokers = + std::invoke([]() { +#define PAIR(name, unused) Ret[#name] = reinterpret_cast(GetCallerForHostThunkFromRuntimePointer(name)); + std::unordered_map Ret; + FOREACH_internal_SYMBOL(PAIR) + return Ret; +#undef PAIR + }); + extern "C" { voidFunc *glXGetProcAddress(const GLubyte *procname) { + auto Ret = fexfn_pack_glXGetProcAddress(procname); + if (!Ret) { + return nullptr; + } - for (int i = 0; internal_symtable[i].name; i++) { - if (strcmp(internal_symtable[i].name, (const char*)procname) == 0) { - // for debugging - //printf("glXGetProcAddress: looked up %s %s %p %p\n", procname, internal_symtable[i].name, internal_symtable[i].fn, &glXGetProcAddress); - return internal_symtable[i].fn; - } - } + auto TargetFuncIt = HostPtrInvokers.find(reinterpret_cast(procname)); + if (TargetFuncIt == HostPtrInvokers.end()) { + // Extension found in host but not in our interface definition => treat as fatal error + fprintf(stderr, "glXGetProcAddress: not found %s\n", procname); + __builtin_trap(); + } - printf("glXGetProcAddress: not found %s\n", procname); - return nullptr; + LinkAddressToFunction((uintptr_t)Ret, TargetFuncIt->second); + return Ret; } voidFunc *glXGetProcAddressARB(const GLubyte *procname) { @@ -45,4 +65,4 @@ extern "C" { } } -LOAD_LIB(libGL) \ No newline at end of file +LOAD_LIB(libGL) diff --git a/ThunkLibs/libGL/libGL_Host.cpp b/ThunkLibs/libGL/libGL_Host.cpp index 18c9d6e44..85fbc8169 100644 --- a/ThunkLibs/libGL/libGL_Host.cpp +++ b/ThunkLibs/libGL/libGL_Host.cpp @@ -18,6 +18,8 @@ $end_info$ #include #include +#include + #include "common/Host.h" void fexfn_impl_libGL_glDebugMessageCallbackAMD_internal(GLDEBUGPROCAMD, const void*) { diff --git a/ThunkLibs/libGL/libGL_interface.cpp b/ThunkLibs/libGL/libGL_interface.cpp index 459bf4d44..1822cbc0d 100644 --- a/ThunkLibs/libGL/libGL_interface.cpp +++ b/ThunkLibs/libGL/libGL_interface.cpp @@ -15,6 +15,14 @@ template struct fex_gen_config { }; +template<> struct fex_gen_config : fexgen::custom_guest_entrypoint, fexgen::returns_guest_pointer {}; + +// Symbols queryable through glXGetProcAddr +namespace internal { +template +struct fex_gen_config : fexgen::generate_guest_symtable, fexgen::indirect_guest_calls { +}; + template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; @@ -93,13 +101,6 @@ template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; -// Symbols exposed through glXGetProcAddr -namespace internal { -template -struct fex_gen_config : fexgen::generate_guest_symtable { - const char* load_host_endpoint_via = "symbolFromGlXGetProcAddr"; -}; - template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; @@ -696,9 +697,9 @@ template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; -template<> struct fex_gen_config {}; -template<> struct fex_gen_config {}; -template<> struct fex_gen_config {}; +template<> struct fex_gen_config : fexgen::callback_stub {}; +template<> struct fex_gen_config : fexgen::callback_stub {}; +template<> struct fex_gen_config : fexgen::callback_stub {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {};