mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-06 20:00:16 +02:00
Thunks/GL: Use guest-callable host function pointers to implement glXGetProcAddress
This commit is contained in:
1 parent
599f8f99ed
commit
fe2f54fc3d
4 files changed
+47
-24
No files matched your search
@@ -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
|
||||
|
||||
@@ -8,36 +8,56 @@ $end_info$
|
||||
#define GL_GLEXT_PROTOTYPES 1
|
||||
#define GLX_GLXEXT_PROTOTYPES 1
|
||||
|
||||
#include "glcorearb.h"
|
||||
|
||||
#include <GL/glx.h>
|
||||
#include <GL/glxext.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glext.h>
|
||||
|
||||
#undef GL_ARB_viewport_array
|
||||
#include "glcorearb.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <functional>
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
|
||||
#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<std::string_view, uintptr_t /* guest function address */> HostPtrInvokers =
|
||||
std::invoke([]() {
|
||||
#define PAIR(name, unused) Ret[#name] = reinterpret_cast<uintptr_t>(GetCallerForHostThunkFromRuntimePointer<fexthunks_libGL_hostcall_##name>(name));
|
||||
std::unordered_map<std::string_view, uintptr_t> 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<const char*>(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)
|
||||
LOAD_LIB(libGL)
|
||||
@@ -18,6 +18,8 @@ $end_info$
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glext.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include "common/Host.h"
|
||||
|
||||
void fexfn_impl_libGL_glDebugMessageCallbackAMD_internal(GLDEBUGPROCAMD, const void*) {
|
||||
|
||||
@@ -15,6 +15,14 @@ template<auto>
|
||||
struct fex_gen_config {
|
||||
};
|
||||
|
||||
template<> struct fex_gen_config<glXGetProcAddress> : fexgen::custom_guest_entrypoint, fexgen::returns_guest_pointer {};
|
||||
|
||||
// Symbols queryable through glXGetProcAddr
|
||||
namespace internal {
|
||||
template<auto>
|
||||
struct fex_gen_config : fexgen::generate_guest_symtable, fexgen::indirect_guest_calls {
|
||||
};
|
||||
|
||||
template<> struct fex_gen_config<glXQueryCurrentRendererStringMESA> {};
|
||||
template<> struct fex_gen_config<glXQueryRendererStringMESA> {};
|
||||
template<> struct fex_gen_config<glXGetContextIDEXT> {};
|
||||
@@ -93,13 +101,6 @@ template<> struct fex_gen_config<glXGetVisualFromFBConfig> {};
|
||||
template<> struct fex_gen_config<glXCreateContextAttribsARB> {};
|
||||
template<> struct fex_gen_config<glXSwapIntervalEXT> {};
|
||||
|
||||
// Symbols exposed through glXGetProcAddr
|
||||
namespace internal {
|
||||
template<auto>
|
||||
struct fex_gen_config : fexgen::generate_guest_symtable {
|
||||
const char* load_host_endpoint_via = "symbolFromGlXGetProcAddr";
|
||||
};
|
||||
|
||||
template<> struct fex_gen_config<glColorP3ui> {};
|
||||
template<> struct fex_gen_config<glColorP3uiv> {};
|
||||
template<> struct fex_gen_config<glColorP4ui> {};
|
||||
@@ -696,9 +697,9 @@ template<> struct fex_gen_config<glCullFace> {};
|
||||
template<> struct fex_gen_config<glCullParameterdvEXT> {};
|
||||
template<> struct fex_gen_config<glCullParameterfvEXT> {};
|
||||
template<> struct fex_gen_config<glCurrentPaletteMatrixARB> {};
|
||||
template<> struct fex_gen_config<glDebugMessageCallbackAMD> {};
|
||||
template<> struct fex_gen_config<glDebugMessageCallbackARB> {};
|
||||
template<> struct fex_gen_config<glDebugMessageCallback> {};
|
||||
template<> struct fex_gen_config<glDebugMessageCallbackAMD> : fexgen::callback_stub {};
|
||||
template<> struct fex_gen_config<glDebugMessageCallbackARB> : fexgen::callback_stub {};
|
||||
template<> struct fex_gen_config<glDebugMessageCallback> : fexgen::callback_stub {};
|
||||
template<> struct fex_gen_config<glDebugMessageControlARB> {};
|
||||
template<> struct fex_gen_config<glDebugMessageControl> {};
|
||||
template<> struct fex_gen_config<glDebugMessageEnableAMD> {};
|
||||
|
||||
Reference in new issue
Block a user