Skip to content

Commit

Permalink
Remove bypassLocal params to xxxGetProcAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-clayton committed Jul 13, 2018
1 parent ac671d4 commit c8464bd
Show file tree
Hide file tree
Showing 25 changed files with 242 additions and 354 deletions.
97 changes: 37 additions & 60 deletions core/cc/android/get_gles_proc_address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,87 +29,64 @@

namespace {

void* ResolveSymbol(const char* name, bool bypassLocal) {
void* ResolveSymbol(const char* name) {
using namespace core;
typedef void* (*GPAPROC)(const char* name);

if (bypassLocal) {
static DlLoader libegl(SYSTEM_LIB_PATH "libEGL.so");
if (void* proc = libegl.lookup(name)) {
GAPID_DEBUG("GetGlesProcAddress(%s, %d) -> %p (from libEGL dlsym)", name,
bypassLocal, proc);
return proc;
}
static DlLoader libegl(SYSTEM_LIB_PATH "libEGL.so");
if (void* proc = libegl.lookup(name)) {
GAPID_DEBUG("GetGlesProcAddress(%s) -> %p (from libEGL dlsym)", name, proc);
return proc;
}

static DlLoader libglesv2(SYSTEM_LIB_PATH "libGLESv2.so");
if (void* proc = libglesv2.lookup(name)) {
GAPID_DEBUG("GetGlesProcAddress(%s, %d) -> %p (from libGLESv2 dlsym)",
name, bypassLocal, proc);
return proc;
}
static DlLoader libglesv2(SYSTEM_LIB_PATH "libGLESv2.so");
if (void* proc = libglesv2.lookup(name)) {
GAPID_DEBUG("GetGlesProcAddress(%s) -> %p (from libGLESv2 dlsym)", name,
proc);
return proc;
}

static DlLoader libglesv1(SYSTEM_LIB_PATH "libGLESv1_CM.so");
if (void* proc = libglesv1.lookup(name)) {
GAPID_DEBUG("GetGlesProcAddress(%s, %d) -> %p (from libGLESv1_CM dlsym)",
name, bypassLocal, proc);
return proc;
}
static DlLoader libglesv1(SYSTEM_LIB_PATH "libGLESv1_CM.so");
if (void* proc = libglesv1.lookup(name)) {
GAPID_DEBUG("GetGlesProcAddress(%s) -> %p (from libGLESv1_CM dlsym)", name,
proc);
return proc;
}

if (GPAPROC gpa =
reinterpret_cast<GPAPROC>(libegl.lookup("eglGetProcAddress"))) {
if (void* proc = gpa(name)) {
static DlLoader local(nullptr);
void* local_proc = local.lookup(name);
if (local_proc == proc) {
GAPID_WARNING(
"libEGL eglGetProcAddress returned a local address %p for %s, "
"this will be ignored",
proc, name);
} else {
GAPID_DEBUG(
"GetGlesProcAddress(%s, %d) -> %p (via libEGL eglGetProcAddress)",
name, (int)bypassLocal, proc);
return proc;
}
}
}
} else {
static DlLoader local(nullptr);
if (GPAPROC gpa =
reinterpret_cast<GPAPROC>(local.lookup("eglGetProcAddress"))) {
if (void* proc = gpa(name)) {
if (GPAPROC gpa =
reinterpret_cast<GPAPROC>(libegl.lookup("eglGetProcAddress"))) {
if (void* proc = gpa(name)) {
static DlLoader local(nullptr);
void* local_proc = local.lookup(name);
if (local_proc == proc) {
GAPID_WARNING(
"libEGL eglGetProcAddress returned a local address %p for %s, this "
"will be ignored",
proc, name);
} else {
GAPID_DEBUG(
"GetGlesProcAddress(%s, %d) -> %p (via local eglGetProcAddress)",
name, (int)bypassLocal, proc);
"GetGlesProcAddress(%s) -> %p (via libEGL eglGetProcAddress)", name,
proc);
return proc;
}
}
if (void* proc = local.lookup(name)) {
GAPID_DEBUG("GetGlesProcAddress(%s, %d) -> %p (from local dlsym)", name,
(int)bypassLocal, proc);
return proc;
}
}

GAPID_DEBUG("GetGlesProcAddress(%s, %d) -> not found", name,
(int)bypassLocal);
GAPID_DEBUG("GetGlesProcAddress(%s) -> not found", name);
return nullptr;
}

void* getGlesProcAddress(const char* name, bool bypassLocal) {
void* getGlesProcAddress(const char* name) {
static std::unordered_map<std::string, void*> cache;

const std::string cacheKey =
std::string(name) + (bypassLocal ? "/direct" : "/local");
auto it = cache.find(cacheKey);
auto it = cache.find(name);
if (it != cache.end()) {
GAPID_DEBUG("GetGlesProcAddress(%s, %d) -> %p (from cache)", name,
(int)bypassLocal, it->second);
GAPID_DEBUG("GetGlesProcAddress(%s) -> %p (from cache)", name, it->second);
return it->second;
}

void* proc = ResolveSymbol(name, bypassLocal);
cache[cacheKey] = proc;
void* proc = ResolveSymbol(name);
cache[name] = proc;
return proc;
}

Expand Down
35 changes: 14 additions & 21 deletions core/cc/android/get_vulkan_proc_address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,52 +28,45 @@ typedef void* PFN_vkVoidFunction;
typedef size_t VkDevice;
typedef size_t VkInstance;

void* getVulkanInstanceProcAddress(size_t instance, const char* name,
bool bypassLocal) {
void* getVulkanInstanceProcAddress(size_t instance, const char* name) {
typedef PFN_vkVoidFunction (*VPAPROC)(VkInstance instance, const char* name);

static DlLoader dylib("libvulkan.so");

if (VPAPROC vpa =
reinterpret_cast<VPAPROC>(dylib.lookup("vkGetInstanceProcAddr"))) {
if (void* proc = vpa(instance, name)) {
GAPID_DEBUG(
"GetVulkanInstanceProcAddress(0x%zx, %s, %d) -> %p "
"(via %s vkGetInstanceProcAddr)",
instance, name, bypassLocal, proc,
(bypassLocal ? "libvulkan" : "local"));
GAPID_DEBUG("GetVulkanInstanceProcAddress(0x%zx, %s) -> %p", instance,
name, proc);
return proc;
}
}

GAPID_DEBUG("GetVulkanInstanceProcAddress(0x%zx, %s, %d) -> not found",
instance, name, bypassLocal);
GAPID_DEBUG("GetVulkanInstanceProcAddress(0x%zx, %s) -> not found", instance,
name);
return nullptr;
}

void* getVulkanDeviceProcAddress(size_t instance, size_t device,
const char* name, bool bypassLocal) {
const char* name) {
typedef PFN_vkVoidFunction (*VPAPROC)(VkDevice device, const char* name);

if (auto vpa = reinterpret_cast<VPAPROC>(getVulkanInstanceProcAddress(
instance, "vkGetDeviceProcAddr", bypassLocal))) {
if (auto vpa = reinterpret_cast<VPAPROC>(
getVulkanInstanceProcAddress(instance, "vkGetDeviceProcAddr"))) {
if (void* proc = vpa(device, name)) {
GAPID_DEBUG(
"GetVulkanDeviceProcAddress(0x%zx, 0x%zx, %s, %d) -> %p "
"(via %s vkGetDeviceProcAddr)",
instance, device, name, bypassLocal, proc,
(bypassLocal ? "libvulkan" : "local"));
GAPID_DEBUG("GetVulkanDeviceProcAddress(0x%zx, 0x%zx, %s) -> %p",
instance, device, name, proc);
return proc;
}
}

GAPID_DEBUG("GetVulkanDeviceProcAddress(0x%zx, 0x%zx, %s, %d) -> not found",
instance, device, name, bypassLocal);
GAPID_DEBUG("GetVulkanDeviceProcAddress(0x%zx, 0x%zx, %s) -> not found",
instance, device, name);
return nullptr;
}

void* getVulkanProcAddress(const char* name, bool bypassLocal) {
return getVulkanInstanceProcAddress(0u, name, bypassLocal);
void* getVulkanProcAddress(const char* name) {
return getVulkanInstanceProcAddress(0u, name);
}

} // anonymous namespace
Expand Down
100 changes: 39 additions & 61 deletions core/cc/armlinux/get_gles_proc_address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,88 +25,66 @@

namespace {

void* ResolveSymbol(const char* name, bool bypassLocal) {
void* ResolveSymbol(const char* name) {
using namespace core;
typedef void* (*GPAPROC)(const char* name);

if (bypassLocal) {
static DlLoader libegl(SYSTEM_LIB_PATH "libEGL.so");
if (void* proc = libegl.lookup(name)) {
GAPID_DEBUG("GetGlesProcAddress(%s, %d) -> 0x%x (from libEGL dlsym)",
name, bypassLocal, proc);
return proc;
}
static DlLoader libegl(SYSTEM_LIB_PATH "libEGL.so");
if (void* proc = libegl.lookup(name)) {
GAPID_DEBUG("GetGlesProcAddress(%s) -> 0x%x (from libEGL dlsym)", name,
proc);
return proc;
}

static DlLoader libglesv2(SYSTEM_LIB_PATH "libGLESv2.so");
if (void* proc = libglesv2.lookup(name)) {
GAPID_DEBUG("GetGlesProcAddress(%s, %d) -> 0x%x (from libGLESv2 dlsym)",
name, bypassLocal, proc);
return proc;
}
static DlLoader libglesv2(SYSTEM_LIB_PATH "libGLESv2.so");
if (void* proc = libglesv2.lookup(name)) {
GAPID_DEBUG("GetGlesProcAddress(%s) -> 0x%x (from libGLESv2 dlsym)", name,
proc);
return proc;
}

static DlLoader libglesv1(SYSTEM_LIB_PATH "libGLESv1_CM.so");
if (void* proc = libglesv1.lookup(name)) {
GAPID_DEBUG(
"GetGlesProcAddress(%s, %d) -> 0x%x (from libGLESv1_CM dlsym)", name,
bypassLocal, proc);
return proc;
}
static DlLoader libglesv1(SYSTEM_LIB_PATH "libGLESv1_CM.so");
if (void* proc = libglesv1.lookup(name)) {
GAPID_DEBUG("GetGlesProcAddress(%s) -> 0x%x (from libGLESv1_CM dlsym)",
name, proc);
return proc;
}

if (GPAPROC gpa =
reinterpret_cast<GPAPROC>(libegl.lookup("eglGetProcAddress"))) {
if (void* proc = gpa(name)) {
static DlLoader local(nullptr);
void* local_proc = local.lookup(name);
if (local_proc == proc) {
GAPID_WARNING(
"libEGL eglGetProcAddress returned a local address %p for %s, "
"this will be ignored",
proc, name);
} else {
GAPID_DEBUG(
"GetGlesProcAddress(%s, %d) -> 0x%x "
"(via libEGL eglGetProcAddress)",
name, bypassLocal, proc);
return proc;
}
}
}
} else {
static DlLoader local(nullptr);
if (GPAPROC gpa =
reinterpret_cast<GPAPROC>(local.lookup("eglGetProcAddress"))) {
if (void* proc = gpa(name)) {
if (GPAPROC gpa =
reinterpret_cast<GPAPROC>(libegl.lookup("eglGetProcAddress"))) {
if (void* proc = gpa(name)) {
static DlLoader local(nullptr);
void* local_proc = local.lookup(name);
if (local_proc == proc) {
GAPID_WARNING(
"libEGL eglGetProcAddress returned a local address %p for %s, this "
"will be ignored",
proc, name);
} else {
GAPID_DEBUG(
"GetGlesProcAddress(%s, %d) -> 0x%x (via local eglGetProcAddress)",
name, bypassLocal, proc);
"GetGlesProcAddress(%s) -> 0x%x (via libEGL eglGetProcAddress)",
name, proc);
return proc;
}
}
if (void* proc = local.lookup(name)) {
GAPID_DEBUG("GetGlesProcAddress(%s, %d) -> 0x%x (from local dlsym)", name,
bypassLocal, proc);
return proc;
}
}

GAPID_DEBUG("GetGlesProcAddress(%s, %d) -> not found", name, bypassLocal);
GAPID_DEBUG("GetGlesProcAddress(%s) -> not found", name);
return nullptr;
}

void* getGlesProcAddress(const char* name, bool bypassLocal) {
void* getGlesProcAddress(const char* name) {
static std::unordered_map<std::string, void*> cache;

const std::string cacheKey =
std::string(name) + (bypassLocal ? "/direct" : "/local");
auto it = cache.find(cacheKey);
auto it = cache.find(name);
if (it != cache.end()) {
GAPID_DEBUG("GetGlesProcAddress(%s, %d) -> 0x%x (from cache)", name,
bypassLocal, it->second);
GAPID_DEBUG("GetGlesProcAddress(%s) -> 0x%x (from cache)", name,
it->second);
return it->second;
}

void* proc = ResolveSymbol(name, bypassLocal);
cache[cacheKey] = proc;
void* proc = ResolveSymbol(name);
cache[name] = proc;
return proc;
}

Expand Down
35 changes: 15 additions & 20 deletions core/cc/armlinux/get_vulkan_proc_address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ typedef void* PFN_vkVoidFunction;
typedef size_t VkDevice;
typedef size_t VkInstance;

void* getVulkanInstanceProcAddress(size_t instance, const char* name,
bool bypassLocal) {
void* getVulkanInstanceProcAddress(size_t instance, const char* name) {
typedef PFN_vkVoidFunction (*VPAPROC)(VkInstance instance, const char* name);

static DlLoader dylib("libvulkan.so");
Expand All @@ -38,42 +37,38 @@ void* getVulkanInstanceProcAddress(size_t instance, const char* name,
reinterpret_cast<VPAPROC>(dylib.lookup("vkGetInstanceProcAddr"))) {
if (void* proc = vpa(instance, name)) {
GAPID_DEBUG(
"GetVulkanInstanceProcAddress(0x%x, %s, %d) -> 0x%x "
"(via %s vkGetInstanceProcAddr)",
instance, name, bypassLocal, proc,
(bypassLocal ? "libvulkan" : "local"));
"GetVulkanInstanceProcAddress(0x%x, %s) -> 0x%x (via %s "
"vkGetInstanceProcAddr)",
instance, name, proc);
return proc;
}
}

GAPID_DEBUG("GetVulkanInstanceProcAddress(0x%x, %s, %d) -> not found",
instance, name, bypassLocal);
GAPID_DEBUG("GetVulkanInstanceProcAddress(0x%x, %s) -> not found", instance,
name);
return nullptr;
}

void* getVulkanDeviceProcAddress(size_t instance, size_t device,
const char* name, bool bypassLocal) {
const char* name) {
typedef PFN_vkVoidFunction (*VPAPROC)(VkDevice device, const char* name);

if (auto vpa = reinterpret_cast<VPAPROC>(getVulkanInstanceProcAddress(
instance, "vkGetDeviceProcAddr", bypassLocal))) {
if (auto vpa = reinterpret_cast<VPAPROC>(
getVulkanInstanceProcAddress(instance, "vkGetDeviceProcAddr"))) {
if (void* proc = vpa(device, name)) {
GAPID_DEBUG(
"GetVulkanDeviceProcAddress(0x%x, 0x%x, %s, %d) -> 0x%x "
"(via %s vkGetDeviceProcAddr)",
instance, device, name, bypassLocal, proc,
(bypassLocal ? "libvulkan" : "local"));
GAPID_DEBUG("GetVulkanDeviceProcAddress(0x%x, 0x%x, %s) -> 0x%x",
instance, device, name, proc);
return proc;
}
}

GAPID_DEBUG("GetVulkanDeviceProcAddress(0x%x, 0x%x, %s, %d) -> not found",
instance, device, name, bypassLocal);
GAPID_DEBUG("GetVulkanDeviceProcAddress(0x%x, 0x%x, %s) -> not found",
instance, device, name);
return nullptr;
}

void* getVulkanProcAddress(const char* name, bool bypassLocal) {
return getVulkanInstanceProcAddress(0u, name, bypassLocal);
void* getVulkanProcAddress(const char* name) {
return getVulkanInstanceProcAddress(0u, name);
}

} // anonymous namespace
Expand Down
Loading

0 comments on commit c8464bd

Please sign in to comment.