Skip to content

Commit

Permalink
Remove unused macros and fix warnings (#198)
Browse files Browse the repository at this point in the history
* Fix compiler diagnositc pragmas and FGDLL definition scope
* Correctly check for clang & GCC compilers
* Suppress 4275 warnings from vc++ on downstream projects
* Remove unused macros and fix warnings
* Remove obsolete disable warnings in ComputeCopy OpenCL code-path
* Revert cmake CUDA language based changes in examples (CUDA language support in cmake is a bit buggy at the moment)
  • Loading branch information
9prady9 authored Mar 10, 2019
1 parent ad6f551 commit 61a3ea6
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 77 deletions.
20 changes: 15 additions & 5 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ include(CMakeParseArguments)
include(CMakeDependentOption)
include(InternalUtils)

option(FG_BUILD_CUDA_EXAMPLES "Turn off/on building cuda examples" ${CUDA_FOUND})
option(FG_BUILD_OPENCL_EXAMPLES "Turn off/on building opencl examples" ${OpenCL_FOUND})
cmake_dependent_option(FG_BUILD_OPENCL_EXAMPLES
"Build opencl examples" ON
"OpenCL_FOUND;FG_BUILD_EXAMPLES" OFF)

cmake_dependent_option(FG_USE_SYSTEM_CL2HPP "Use system cl2.hpp header" OFF "OpenCL_FOUND" OFF)
cmake_dependent_option(FG_BUILD_CUDA_EXAMPLES
"Build cuda examples" ON
"CUDA_FOUND;FG_BUILD_EXAMPLES" OFF)

cmake_dependent_option(FG_USE_SYSTEM_CL2HPP
"Use system cl2.hpp header" OFF "OpenCL_FOUND" OFF)

include_if_not(FG_USE_SYSTEM_CL2HPP build_cl2hpp)

Expand All @@ -58,8 +64,12 @@ function(add_example target_name source backend)

string(TOLOWER ${backend} lowerCaseBackend)

if (${lowerCaseBackend} STREQUAL "cuda" AND ${CMAKE_VERSION} VERSION_LESS "3.10.0")
cuda_add_executable(${target} ${source})
if (${lowerCaseBackend} STREQUAL "cuda")
set(native_cc_flags
"-Xcompiler /wd4275 -Xcompiler /bigobj -Xcompiler /EHsc")
cuda_add_executable(${target} ${source}
OPTIONS "${native_cc_flags} -Xcudafe \"--diag_suppress=1388\""
)
else ()
add_executable(${target} ${source})
endif ()
Expand Down
4 changes: 2 additions & 2 deletions examples/cpu/bubblechart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ int main(void)
std::default_random_engine e1(r());
std::mt19937_64 gen(r());

std::uniform_int_distribution<int> uDist(20, 80);
std::uniform_real_distribution<float> nDist(0.0f, 1.0f);
std::uniform_real_distribution<float> cDist(0.2f, 0.6f);
std::uniform_real_distribution<float> fDist(0.4f, 0.6f);

auto clr = std::bind(cDist, gen);
auto rnd = std::bind(uDist, e1);
auto rnd = std::bind(nDist, e1);
auto alp = std::bind(fDist, gen);

std::vector<float> colors(3*tanData.size());
Expand Down
8 changes: 0 additions & 8 deletions examples/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ project(Forge-CUDA-Examples LANGUAGES CXX)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORCE_INLINES")

if (${CMAKE_VERSION} VERSION_LESS "3.10.0")
INCLUDE_DIRECTORIES(
${CUDA_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR})
else()
enable_language(CUDA)
endif ()

macro(make_cuda_example target src)
add_example(${target} ${src} cuda CXX11
INCLUDE_DIRS
Expand Down
23 changes: 2 additions & 21 deletions include/ComputeCopy.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,6 @@ void copyToGLBuffer(GfxHandle* pGLDestination, ComputeResourceHandle pSource, c

#if defined(USE_FORGE_OPENCL_COPY_HELPERS)

#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#endif

#define FORGE_OCL_CHECK(cl_status, message) \
if(cl_status != CL_SUCCESS) \
{ \
Expand All @@ -194,14 +189,11 @@ void copyToGLBuffer(GfxHandle* pGLDestination, ComputeResourceHandle pSource, c
static
void createGLBuffer(GfxHandle** pOut, const unsigned pResourceId, const BufferType pTarget)
{
GfxHandle* temp = (GfxHandle*)malloc(sizeof(GfxHandle));

temp->mTarget = pTarget;

GfxHandle* temp = (GfxHandle*)malloc(sizeof(GfxHandle));
temp->mTarget = pTarget;
cl_int returnCode = CL_SUCCESS;

temp->mId = clCreateFromGLBuffer(getContext(), CL_MEM_WRITE_ONLY, pResourceId, &returnCode);

FORGE_OCL_CHECK(returnCode, "Failed in clCreateFromGLBuffer");

*pOut = temp;
Expand All @@ -220,34 +212,23 @@ void copyToGLBuffer(GfxHandle* pGLDestination, ComputeResourceHandle pSource, c
// The user is expected to implement a function
// `cl_command_queue getCommandQueue()`
cl_command_queue queue = getCommandQueue();

cl_event waitEvent;

cl_mem src = (cl_mem)pSource;
cl_mem dst = pGLDestination->mId;

fg_finish();

FORGE_OCL_CHECK(clEnqueueAcquireGLObjects(queue, 1, &dst, 0, NULL, &waitEvent),
"Failed in clEnqueueAcquireGLObjects");

FORGE_OCL_CHECK(clWaitForEvents(1, &waitEvent),
"Failed in clWaitForEvents after clEnqueueAcquireGLObjects");

FORGE_OCL_CHECK(clEnqueueCopyBuffer(queue, src, dst, 0, 0, pSize, 0, NULL, &waitEvent),
"Failed in clEnqueueCopyBuffer");

FORGE_OCL_CHECK(clEnqueueReleaseGLObjects(queue, 1, &dst, 0, NULL, &waitEvent),
"Failed in clEnqueueReleaseGLObjects");

FORGE_OCL_CHECK(clWaitForEvents(1, &waitEvent),
"Failed in clWaitForEvents after clEnqueueReleaseGLObjects");
}

#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif

#endif

///////////////////////////////////////////////////////////////////////////////
Expand Down
3 changes: 0 additions & 3 deletions include/fg/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@
#define false 0
#define true 1
#endif

#define FG_STATIC_ static
#else
#define FGAPI __attribute__((visibility("default")))
#include <stdbool.h>
#define FG_STATIC_
#endif

#include <fg/version.h>
Expand Down
31 changes: 18 additions & 13 deletions src/api/cpp/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@

#include <fg/exception.h>
#include <err_common.hpp>
#include <string>
#include <iostream>
#include <sstream>

#include <algorithm>
#include <cstring>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>

using std::string;
using std::stringstream;
Expand All @@ -27,7 +29,7 @@ void stringcopy(char* dest, const char* src, size_t len)
#if defined(OS_WIN)
strncpy_s(dest, forge::common::MAX_ERR_SIZE, src, len);
#else
strncpy(dest, src, len);
std::strncpy(dest, src, len);
#endif
}

Expand All @@ -46,29 +48,32 @@ Error::Error(const char * const pMessage)
Error::Error(const char * const pFileName, int pLine, ErrorCode pErrCode)
: mErrCode(pErrCode)
{
snprintf(mMessage, sizeof(mMessage) - 1,
"Forge Exception (%s:%d):\nIn %s:%d",
fg_err_to_string(pErrCode), (int)pErrCode, pFileName, pLine);
std::snprintf(mMessage, sizeof(mMessage) - 1,
"Forge Exception (%s:%d):\nIn %s:%d",
fg_err_to_string(pErrCode), (int)pErrCode,
pFileName, pLine);
mMessage[sizeof(mMessage)-1] = '\0';
}

Error::Error(const char * const pMessage,
const char * const pFileName, const int pLine, ErrorCode pErrCode)
: mErrCode(pErrCode)
{
snprintf(mMessage, sizeof(mMessage) - 1,
"Forge Exception (%s:%d):\n%s\nIn %s:%d",
fg_err_to_string(pErrCode), (int)pErrCode, pMessage, pFileName, pLine);
std::snprintf(mMessage, sizeof(mMessage) - 1,
"Forge Exception (%s:%d):\n%s\nIn %s:%d",
fg_err_to_string(pErrCode), (int)pErrCode,
pMessage, pFileName, pLine);
mMessage[sizeof(mMessage)-1] = '\0';
}

Error::Error(const char * const pMessage, const char * const pFuncName,
const char * const pFileName, const int pLine, ErrorCode pErrCode)
: mErrCode(pErrCode)
{
snprintf(mMessage, sizeof(mMessage) - 1,
"Forge Exception (%s:%d):\n%sIn function %s\nIn file %s:%d",
fg_err_to_string(pErrCode), (int)pErrCode, pMessage, pFuncName, pFileName, pLine);
std::snprintf(mMessage, sizeof(mMessage) - 1,
"Forge Exception (%s:%d):\n%sIn function %s\nIn file %s:%d",
fg_err_to_string(pErrCode), (int)pErrCode,
pMessage, pFuncName, pFileName, pLine);
mMessage[sizeof(mMessage)-1] = '\0';
}

Expand Down
43 changes: 32 additions & 11 deletions src/backend/common/cmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,26 @@ namespace forge
namespace common
{

// Surppress implicit conversion warning for this file
#if defined(OS_WIN)
#pragma warning( push )
#pragma warning( disable : 4305)
#elif defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#elif defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wconversion"
#endif

/**
* Color maps: heat, rainbow are pulled from the following resource:
*
* http://www.paraview.org/Wiki/Colormaps
* */

/* grayscale */
float cmap_default[] =
static const float cmap_default[] =
{
0.0000f, 0.0000f, 0.0000f, 1.0000f,
0.0039f, 0.0039f, 0.0039f, 1.0000f,
Expand Down Expand Up @@ -316,7 +328,7 @@ float cmap_default[] =
* rgb = (rgb > 0.0) .* rgb;
* ```
* */
float cmap_spectrum[] =
static const float cmap_spectrum[] =
{
0.01127986 , 0 , 0.08038571f , 1.0f ,
0.01541133 , 4.283736e-43 , 0.0994883f , 1.0f ,
Expand Down Expand Up @@ -576,7 +588,7 @@ float cmap_spectrum[] =
2.389238e-05 , -0 , -0 , 1.0f ,
};

float cmap_rainbow[] =
static const float cmap_rainbow[] =
{
1.000000f, 0.000000f, 0.164706f, 1.0,
1.000000f, 0.000000f, 0.142745f, 1.0,
Expand Down Expand Up @@ -836,7 +848,7 @@ float cmap_rainbow[] =
1.000000f, 0.000000f, 0.807843f, 1.0,
};

float cmap_red[] =
static const float cmap_red[] =
{
1.0000000000f, 1.0000000000f, 1.0000000000f, 1.0000f,
1.0000000000f, 1.0000000000f, 0.9921568627f, 1.0000f,
Expand Down Expand Up @@ -1095,7 +1107,7 @@ float cmap_red[] =
};

/*-- http://mycarta.wordpress.com/2013/03/06/perceptual-rainbow-palette-the-goodies/ */
float cmap_mood[] =
static const float cmap_mood[] =
{
0.5151f, 0.0482f, 0.6697f, 1.0000f,
0.5159f, 0.0561f, 0.6785f, 1.0000f,
Expand Down Expand Up @@ -1355,7 +1367,7 @@ float cmap_mood[] =
0.8000f, 0.9255f, 0.3529f, 1.0000f,
};

float cmap_heat[] =
static const float cmap_heat[] =
{
0.000000f, 0.000000f, 0.000000f, 1.0f,
0.003660f, 0.000000f, 0.000000f, 1.0f,
Expand Down Expand Up @@ -1615,7 +1627,7 @@ float cmap_heat[] =
1.000000f, 0.984314f, 0.968627f, 1.0f,
};

float cmap_blue[] =
static const float cmap_blue[] =
{
0.968627f, 0.984314f, 1.000000f, 1.0f,
0.965552f, 0.982345f, 0.999016f, 1.0f,
Expand Down Expand Up @@ -1891,7 +1903,7 @@ float cmap_blue[] =
/// work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.

/// inferno perceptually uniform shades of black-red-yellow
float cmap_inferno[] =
static const float cmap_inferno[] =
{
0.001462f, 0.000466f, 0.013866f, 1.0f,
0.002267f, 0.001270f, 0.018570f, 1.0f,
Expand Down Expand Up @@ -2152,7 +2164,7 @@ float cmap_inferno[] =
};

/// magma perceptually uniform shades of black-red-white
float cmap_magma[] =
static const float cmap_magma[] =
{
0.001462f, 0.000466f, 0.013866f, 1.0f,
0.002258f, 0.001295f, 0.018331f, 1.0f,
Expand Down Expand Up @@ -2413,7 +2425,7 @@ float cmap_magma[] =
};

/// plasma perceptually uniform shades of blue-red-yellow
float cmap_plasma[] =
static const float cmap_plasma[] =
{
0.050383f, 0.029803f, 0.527975f, 1.0f,
0.063536f, 0.028426f, 0.533124f, 1.0f,
Expand Down Expand Up @@ -2674,7 +2686,7 @@ float cmap_plasma[] =
};

/// viridis perceptually uniform shades of blue-green-yellow
float cmap_viridis[] =
static const float cmap_viridis[] =
{
0.267004f, 0.004874f, 0.329415f, 1.0f,
0.268510f, 0.009605f, 0.335427f, 1.0f,
Expand Down Expand Up @@ -2934,5 +2946,14 @@ float cmap_viridis[] =
0.993248f, 0.906157f, 0.143936f, 1.0f,
};

// re-enable conversion warning
#if defined(OS_WIN)
#pragma warning( pop )
#elif defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#elif defined(__clang__)
#pragma clang diagnostic pop
#endif

}
}
8 changes: 0 additions & 8 deletions src/backend/common/defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,8 @@ clipPath(std::string path, std::string str)

#if defined(OS_WIN)
#define __PRETTY_FUNCTION__ __FUNCSIG__
#if _MSC_VER < 1900
#define snprintf sprintf_s
#endif
#define STATIC_ static
#define __FG_FILENAME__ (forge::common::clipPath(__FILE__, "src\\").c_str())
#else
//#ifndef __PRETTY_FUNCTION__
// #define __PRETTY_FUNCTION__ __func__ // __PRETTY_FUNCTION__ Fallback
//#endif
#define STATIC_ inline
#define __FG_FILENAME__ (forge::common::clipPath(__FILE__, "src/").c_str())
#endif

Expand Down
9 changes: 7 additions & 2 deletions src/backend/opengl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ set_target_properties(${BackendTarget} PROPERTIES SOVERSION ${Forge_VERSION_MAJO

if (WIN32)
target_compile_definitions(${BackendTarget}
PUBLIC FGDLL
PRIVATE OS_WIN WIN32_MEAN_AND_LEAN)
PRIVATE FGDLL OS_WIN WIN32_MEAN_AND_LEAN)

# C4068: Warnings about unknown pragmas
# C4275: Warnings about using non-exported classes as base class of an
Expand Down Expand Up @@ -111,6 +110,12 @@ if(UNIX)
)
endif(UNIX)

if (WIN32)
# C4275: Warnings about using non-exported classes as base class of an
# exported class
target_compile_options(${BackendTarget} PUBLIC /wd4275)
endif ()

add_dependencies(${BackendTarget} ${glsl_shader_targets})

source_group(include REGULAR_EXPRESSION ${Forge_SOURCE_DIR}/include/*)
Expand Down
Loading

0 comments on commit 61a3ea6

Please sign in to comment.