Skip to content

Commit

Permalink
Unify feature macro handling
Browse files Browse the repository at this point in the history
  • Loading branch information
baldurk committed Nov 7, 2016
1 parent f1b247f commit 8d09154
Show file tree
Hide file tree
Showing 63 changed files with 330 additions and 312 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif()
endif()

add_definitions(-DRENDERDOC_PLATFORM_POSIX)

if(ANDROID)
add_definitions(-DRENDERDOC_PLATFORM_ANDROID)
elseif(APPLE)
Expand Down
3 changes: 2 additions & 1 deletion renderdoc/api/replay/renderdoc_replay.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ typedef uint32_t bool32;
#endif
#define RENDERDOC_CC __cdecl

#elif defined(RENDERDOC_PLATFORM_POSIX)
#elif defined(RENDERDOC_PLATFORM_LINUX) || defined(RENDERDOC_PLATFORM_APPLE) || \
defined(RENDERDOC_PLATFORM_ANDROID)

#ifdef RENDERDOC_EXPORTS
#define RENDERDOC_API __attribute__((visibility("default")))
Expand Down
16 changes: 8 additions & 8 deletions renderdoc/common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ bool Vec16NotEqual(void *a, void *b)
}

return false;
#elif defined(WIN64)
#elif ENABLED(RDOC_X64)
uint64_t *a64 = (uint64_t *)a;
uint64_t *b64 = (uint64_t *)b;

Expand Down Expand Up @@ -244,7 +244,7 @@ uint32_t Log2Floor(uint32_t value)
return 31 - Bits::CountLeadingZeroes(value);
}

#if RDC64BIT
#if ENABLED(RDOC_X64)
uint64_t Log2Floor(uint64_t value)
{
RDCASSERT(value > 0);
Expand Down Expand Up @@ -312,20 +312,20 @@ void rdclogprint_int(LogType type, const char *fullMsg, const char *msg)

SCOPED_LOCK(lock);

#if defined(OUTPUT_LOG_TO_DEBUG_OUT)
#if ENABLED(OUTPUT_LOG_TO_DEBUG_OUT)
OSUtility::WriteOutput(OSUtility::Output_DebugMon, fullMsg);
#endif
#if defined(OUTPUT_LOG_TO_STDOUT)
#if ENABLED(OUTPUT_LOG_TO_STDOUT)
// don't output debug messages to stdout/stderr
if(type != RDCLog_Debug && log_output_enabled)
OSUtility::WriteOutput(OSUtility::Output_StdOut, msg);
#endif
#if defined(OUTPUT_LOG_TO_STDERR)
#if ENABLED(OUTPUT_LOG_TO_STDERR)
// don't output debug messages to stdout/stderr
if(type != RDCLog_Debug && log_output_enabled)
OSUtility::WriteOutput(OSUtility::Output_StdErr, msg);
#endif
#if defined(OUTPUT_LOG_TO_DISK)
#if ENABLED(OUTPUT_LOG_TO_DISK)
if(logfileHandle)
{
// strlen used as byte length - str is UTF-8 so this is NOT number of characters
Expand All @@ -350,12 +350,12 @@ void rdclog_int(LogType type, const char *project, const char *file, unsigned in
va_start(args, fmt);

char timestamp[64] = {0};
#if defined(INCLUDE_TIMESTAMP_IN_LOG)
#if ENABLED(INCLUDE_TIMESTAMP_IN_LOG)
StringFormat::sntimef(timestamp, 63, "[%H:%M:%S] ");
#endif

char location[64] = {0};
#if defined(INCLUDE_LOCATION_IN_LOG)
#if ENABLED(INCLUDE_LOCATION_IN_LOG)
string loc;
loc = basename(string(file));
StringFormat::snprintf(location, 63, "% 20s(%4d) - ", loc.c_str(), line);
Expand Down
14 changes: 7 additions & 7 deletions renderdoc/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ bool FindDiffRange(void *a, void *b, size_t bufSize, size_t &diffStart, size_t &
uint32_t CalcNumMips(int Width, int Height, int Depth);

uint32_t Log2Floor(uint32_t value);
#if RDC64BIT
#if ENABLED(RDOC_X64)
uint64_t Log2Floor(uint64_t value);
#endif

Expand All @@ -171,7 +171,7 @@ uint64_t Log2Floor(uint64_t value);
OSUtility::ForceCrash(); \
} while((void)0, 0)

#if !defined(RELEASE) || defined(FORCE_DEBUGBREAK)
#if ENABLED(RDOC_DEVEL) || ENABLED(FORCE_DEBUGBREAK)
#define RDCBREAK() \
do \
{ \
Expand Down Expand Up @@ -207,7 +207,7 @@ enum LogType
RDCLog_NumTypes,
};

#if defined(STRIP_LOG)
#if ENABLED(STRIP_LOG)
#define RDCLOGFILE(fn) \
do \
{ \
Expand Down Expand Up @@ -274,7 +274,7 @@ void rdclog_closelog();
#define RDCLOGOUTPUT() rdclog_enableoutput()
#define RDCSTOPLOGGING() rdclog_closelog()

#if(!defined(RELEASE) || defined(FORCE_DEBUG_LOGS)) && !defined(STRIP_DEBUG_LOGS)
#if(ENABLED(RDOC_DEVEL) || ENABLED(FORCE_DEBUG_LOGS)) && DISABLED(STRIP_DEBUG_LOGS)
#define RDCDEBUG(...) rdclog(RDCLog_Debug, __VA_ARGS__)
#else
#define RDCDEBUG(...) \
Expand All @@ -286,7 +286,7 @@ void rdclog_closelog();
#define RDCLOG(...) rdclog(RDCLog_Comment, __VA_ARGS__)
#define RDCWARN(...) rdclog(RDCLog_Warning, __VA_ARGS__)

#if defined(DEBUGBREAK_ON_ERROR_LOG)
#if ENABLED(DEBUGBREAK_ON_ERROR_LOG)
#define RDCERR(...) \
do \
{ \
Expand Down Expand Up @@ -320,7 +320,7 @@ void rdclog_closelog();
// Assert
//

#if !defined(RELEASE) || defined(FORCE_ASSERTS)
#if ENABLED(RDOC_DEVEL) || ENABLED(FORCE_ASSERTS)
void rdcassert(const char *msg, const char *file, unsigned int line, const char *func);

// this defines the root macro, RDCASSERTMSG(msg, cond, ...)
Expand All @@ -344,7 +344,7 @@ void rdcassert(const char *msg, const char *file, unsigned int line, const char
// Compile asserts
//

#if defined(STRIP_COMPILE_ASSERTS)
#if ENABLED(STRIP_COMPILE_ASSERTS)
#define RDCCOMPILE_ASSERT(condition, message) \
do \
{ \
Expand Down
2 changes: 1 addition & 1 deletion renderdoc/common/custom_assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

#define RDCASSERT_GETCOND(cond, ...) cond

#ifdef _MSC_VER
#if ENABLED(RDOC_MSVS)

// only needed on VC++, but unfortunately breaks on g++/clang++
#define RDCASSERT_FAILMSG_INVOKE(macro, args) macro args
Expand Down
125 changes: 99 additions & 26 deletions renderdoc/common/globalconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,88 @@

#pragma once

/////////////////////////////////////////////////
// Option macros
// From: http://www.codersnotes.com/notes/easy-preprocessor-defines/

#define OPTION_ON +
#define OPTION_OFF -
#define ENABLED(opt) ((1 opt 1) == 2)
#define DISABLED(opt) ((1 opt 1) == 0)

/////////////////////////////////////////////////
// Build/machine configuration
#if defined(__LP64__) || defined(_WIN64) || defined(__x86_64__) || defined(_M_X64) || \
defined(__ia64) || defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
#define RDC64BIT 1
#define RDOC_X64 OPTION_ON
#else
#define RDOC_X64 OPTION_OFF
#endif

#if defined(RELEASE) || defined(_RELEASE)
#define RDOC_RELEASE OPTION_ON
#define RDOC_DEVEL OPTION_OFF
#else
#define RDOC_RELEASE OPTION_OFF
#define RDOC_DEVEL OPTION_ON
#endif

#if defined(_MSC_VER)
#define RDOC_MSVS OPTION_ON
#else
#define RDOC_MSVS OPTION_OFF
#endif

// translate from build system defines, so they don't have to be defined to anything in
// particular
#if defined(RENDERDOC_PLATFORM_WIN32)

#define RDOC_WIN32 OPTION_ON
#define RDOC_ANDROID OPTION_OFF
#define RDOC_LINUX OPTION_OFF
#define RDOC_APPLE OPTION_OFF
#define RDOC_POSIX OPTION_OFF

#elif defined(RENDERDOC_PLATFORM_ANDROID)

#define RDOC_WIN32 OPTION_OFF
#define RDOC_ANDROID OPTION_ON
#define RDOC_LINUX OPTION_OFF
#define RDOC_APPLE OPTION_OFF
#define RDOC_POSIX OPTION_ON

#elif defined(RENDERDOC_PLATFORM_LINUX)

#define RDOC_WIN32 OPTION_OFF
#define RDOC_ANDROID OPTION_OFF
#define RDOC_LINUX OPTION_ON
#define RDOC_APPLE OPTION_OFF
#define RDOC_POSIX OPTION_ON

#elif defined(RENDERDOC_PLATFORM_APPLE)

#define RDOC_WIN32 OPTION_OFF
#define RDOC_ANDROID OPTION_OFF
#define RDOC_LINUX OPTION_OFF
#define RDOC_APPLE OPTION_ON
#define RDOC_POSIX OPTION_ON

#else

#error "No platform configured in build system"

#endif

#if defined(RENDERDOC_WINDOWING_XLIB)
#define RDOC_XLIB OPTION_ON
#else
#define RDOC_XLIB OPTION_OFF
#endif

#if defined(RENDERDOC_WINDOWING_XCB)
#define RDOC_XCB OPTION_ON
#else
#define RDOC_XCB OPTION_OFF
#endif

/////////////////////////////////////////////////
Expand All @@ -46,55 +123,51 @@ enum
// Debugging features configuration

// remove all logging code
//#define STRIP_LOG
#define STRIP_LOG OPTION_OFF

// remove all compile time asserts. Normally done even in release
// but this would speed up compilation
//#define STRIP_COMPILE_ASSERTS
#define STRIP_COMPILE_ASSERTS OPTION_OFF

// force asserts regardless of debug/release mode
#define FORCE_ASSERTS
#define FORCE_ASSERTS OPTION_ON

// force debugbreaks regardless of debug/release mode
//#define FORCE_DEBUGBREAK
#define FORCE_DEBUGBREAK OPTION_OFF

/////////////////////////////////////////////////
// Logging configuration

// error logs trigger a breakpoint
#define DEBUGBREAK_ON_ERROR_LOG
#define DEBUGBREAK_ON_ERROR_LOG OPTION_ON

// whether to include timestamp on log lines
#define INCLUDE_TIMESTAMP_IN_LOG
#define INCLUDE_TIMESTAMP_IN_LOG OPTION_ON

// whether to include file and line on log lines
#define INCLUDE_LOCATION_IN_LOG
#define INCLUDE_LOCATION_IN_LOG OPTION_ON

#if !defined(RENDERDOC_PLATFORM_WIN32)
// logs go to stdout/stderr
#define OUTPUT_LOG_TO_STDOUT
//#define OUTPUT_LOG_TO_STDERR
#if ENABLED(RDOC_WIN32)

#define OUTPUT_LOG_TO_STDOUT OPTION_OFF
#define OUTPUT_LOG_TO_STDERR OPTION_OFF

#else

#define OUTPUT_LOG_TO_STDOUT OPTION_ON
#define OUTPUT_LOG_TO_STDERR OPTION_OFF

#endif

// logs go to debug output (visual studio output window)
#define OUTPUT_LOG_TO_DEBUG_OUT
#define OUTPUT_LOG_TO_DEBUG_OUT OPTION_ON

// logs go to disk
#define OUTPUT_LOG_TO_DISK
#define OUTPUT_LOG_TO_DISK OPTION_ON

// normally only in a debug build do we
// include debug logs. This prints them all the time
//#define FORCE_DEBUG_LOGS
#define FORCE_DEBUG_LOGS OPTION_OFF
// this strips them completely
//#define STRIP_DEBUG_LOGS

/////////////////////////////////////////////////
// optional features

#if defined(NVIDIA_PERFKIT_DIR)
#define ENABLE_NVIDIA_PERFKIT
#endif

#if defined(AMD_PERFAPI_DIR)
#define ENABLE_AMD_PERFAPI
#endif
#define STRIP_DEBUG_LOGS OPTION_OFF
Loading

0 comments on commit 8d09154

Please sign in to comment.