Skip to content

Commit 9cacdc0

Browse files
author
lizzie
committed
FreeBSD port of QRenderDoc
1 parent 60e7f69 commit 9cacdc0

File tree

5 files changed

+91
-4
lines changed

5 files changed

+91
-4
lines changed

qrenderdoc/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ if(NOT ${CMAKE_VERSION} VERSION_LESS "3.24")
159159
cmake_policy(SET CMP0135 NEW)
160160
endif()
161161

162+
if(FREEBSD)
163+
set(CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES};/usr/local/include")
164+
endif()
165+
162166
CHECK_INCLUDE_FILE(pcre.h PCRE_HEADER)
163167

164168
set(PCRE_PREFIX_PATH "")

renderdoc/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,11 @@ target_link_libraries(renderdoc ${RDOC_LIBRARIES})
632632
add_dependencies(renderdoc renderdoc_libentry)
633633

634634
if(UNIX AND NOT ANDROID AND NOT APPLE)
635-
set(RDOC_LINK_FLAGS "-Wl,--undefined,force_include_libentry -Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/${RDOC_BASE_NAME}.version")
635+
if(FREEBSD)
636+
set(RDOC_LINK_FLAGS "-Wl,--undefined,force_include_libentry")
637+
else()
638+
set(RDOC_LINK_FLAGS "-Wl,--undefined,force_include_libentry -Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/${RDOC_BASE_NAME}.version")
639+
endif()
636640

637641
if(NOT ENABLE_ASAN AND NOT ENABLE_TSAN)
638642
set(RDOC_LINK_FLAGS "${RDOC_LINK_FLAGS} -Wl,--no-undefined")

renderdoc/api/app/renderdoc_app.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
#if defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER)
3737
#define RENDERDOC_CC __cdecl
38-
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__sun__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(__MidnightBSD__)
38+
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__sun__) || defined(__OpenBSD__)
3939
#define RENDERDOC_CC
4040
#elif defined(__APPLE__)
4141
#define RENDERDOC_CC

renderdoc/os/posix/bsd/bsd_hook.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ static void CheckLoadedLibraries()
428428

429429
for(FunctionLoadCallback cb : callbacks)
430430
if(cb)
431-
cb(handle);
431+
cb(handle, libName.c_str());
432432
}
433433
}
434434

@@ -470,7 +470,7 @@ void *intercept_dlopen(const char *filename, int flag, void *ret)
470470

471471
for(FunctionLoadCallback cb : callbacks)
472472
if(cb)
473-
cb(ret);
473+
cb(ret, libName.c_str());
474474

475475
ret = realdlopen("lib" STRINGIZE(RDOC_BASE_NAME) ".so", flag);
476476
break;

renderdoc/os/posix/bsd/bsd_threading.cpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@
2424

2525
#include "os/os_specific.h"
2626

27+
#include "common/common.h"
28+
29+
#include <errno.h>
30+
#include <semaphore.h>
2731
#include <time.h>
2832
#include <unistd.h>
33+
#include <pthread.h>
2934

3035
double Timing::GetTickFrequency()
3136
{
@@ -41,4 +46,78 @@ uint64_t Timing::GetTick()
4146

4247
void Threading::SetCurrentThreadName(const rdcstr &name)
4348
{
49+
// only substantial difference from linux_threading.cpp
50+
pthread_setname_np(pthread_self(), name.c_str());
51+
}
52+
53+
uint32_t Threading::NumberOfCores()
54+
{
55+
long ret = sysconf(_SC_NPROCESSORS_ONLN);
56+
if(ret <= 0)
57+
return 1;
58+
return uint32_t(ret);
59+
}
60+
61+
namespace Threading
62+
{
63+
64+
// works for all posix except apple, hence being here
65+
struct PosixSemaphore : public Semaphore
66+
{
67+
~PosixSemaphore() {}
68+
69+
sem_t h;
70+
};
71+
72+
Semaphore *Semaphore::Create()
73+
{
74+
PosixSemaphore *sem = new PosixSemaphore();
75+
int err = sem_init(&sem->h, 0, 0);
76+
// only documented errors are too large initial value (impossible for 0) or for shared semaphores
77+
// going wrong (we're not shared)
78+
RDCASSERT(err == 0, (int)errno);
79+
return sem;
4480
}
81+
82+
void Semaphore::Destroy()
83+
{
84+
PosixSemaphore *sem = (PosixSemaphore *)this;
85+
sem_destroy(&sem->h);
86+
delete sem;
87+
}
88+
89+
void Semaphore::Wake(uint32_t numToWake)
90+
{
91+
PosixSemaphore *sem = (PosixSemaphore *)this;
92+
for(uint32_t i = 0; i < numToWake; i++)
93+
sem_post(&sem->h);
94+
}
95+
96+
void Semaphore::WaitForWake()
97+
{
98+
PosixSemaphore *sem = (PosixSemaphore *)this;
99+
100+
// handle extremely moronic stupid signal interruptions
101+
do
102+
{
103+
int ret = sem_wait(&sem->h);
104+
105+
if(ret == -1)
106+
{
107+
if(errno == EINTR)
108+
continue;
109+
110+
RDCWARN("Semaphore wait failed: %d", errno);
111+
}
112+
} while(false);
113+
}
114+
115+
Semaphore::Semaphore()
116+
{
117+
}
118+
119+
Semaphore::~Semaphore()
120+
{
121+
}
122+
123+
};

0 commit comments

Comments
 (0)