Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove global -ffast-math flag, instead apply fast math to just color_helpers.cpp #1494

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ add_project_arguments(cppc.get_supported_arguments([

add_project_arguments(cppc.get_supported_arguments([
'-fno-exceptions',
'-ffast-math',
]), language: 'cpp')

pipewire_dep = dependency('libpipewire-0.3', required: get_option('pipewire'))
Expand Down
16 changes: 16 additions & 0 deletions src/Utils/Directives.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#ifdef __clang__
# define FAST_MATH_ON _Pragma("float_control(push)"); \
_Pragma("float_control(precise, off)") //https://clang.llvm.org/docs/LanguageExtensions.html#extensions-to-specify-floating-point-flags
# define FAST_MATH_OFF _Pragma("float_control(pop)")

#elif defined(__GNUC__)
# define FAST_MATH_ON _Pragma("GCC push_options"); \
_Pragma("GCC optimize(\"-ffast-math\")")
# define FAST_MATH_OFF _Pragma("GCC pop_options")

#else
# define FAST_MATH_ON
# define FAST_MATH_OFF
#endif
9 changes: 7 additions & 2 deletions src/color_helpers.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#define COLOR_HELPERS_CPP
#include "color_helpers_impl.h"


#include <algorithm>
#include <cstdint>
#include <cmath>
Expand All @@ -9,9 +10,11 @@

#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include <glm/gtx/string_cast.hpp>

FAST_MATH_ON
#include <glm/mat3x3.hpp>
#include <glm/gtx/matrix_operation.hpp>
#include <glm/gtx/string_cast.hpp>


glm::vec3 xyY_to_XYZ( const glm::vec2 & xy, float Y )
Expand Down Expand Up @@ -214,7 +217,7 @@ inline void lerp_rgb(float* out, const float* a, const float* b, const float* c,

inline float ClampAndSanitize( float a, float min, float max )
{
#ifndef __FAST_MATH__
#if !( defined(__FAST_MATH__) || defined(__FINITE_MATH_ONLY__) )
return std::isfinite( a ) ? std::min(std::max(min, a), max) : min;
#else
return std::min(std::max(min, a), max);
Expand Down Expand Up @@ -910,3 +913,5 @@ const glm::mat3 k_xyz_from_2020 = normalised_primary_matrix( displaycolorimetry_
const glm::mat3 k_2020_from_xyz = glm::inverse( k_xyz_from_2020 );

const glm::mat3 k_2020_from_709 = k_2020_from_xyz * k_xyz_from_709;

FAST_MATH_OFF
6 changes: 6 additions & 0 deletions src/color_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
#include <cmath>
#include <vector>

#include "Utils/Directives.h"

#include <glm/vec2.hpp> // glm::vec2
#include <glm/vec3.hpp> // glm::vec3
FAST_MATH_ON
#include <glm/mat3x3.hpp> // glm::mat3
FAST_MATH_OFF
#include <glm/gtx/component_wise.hpp>
FAST_MATH_ON

// Color utils
inline int quantize( float fVal, float fMaxVal )
Expand Down Expand Up @@ -493,3 +498,4 @@ extern const glm::mat3 k_xyz_from_2020;
extern const glm::mat3 k_2020_from_xyz;

extern const glm::mat3 k_2020_from_709;
FAST_MATH_OFF
1 change: 1 addition & 0 deletions src/color_helpers_impl.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once

#include "color_helpers.h"

namespace rendervulkan {
Expand Down
2 changes: 1 addition & 1 deletion src/color_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "color_helpers.h"
#include "color_helpers_impl.h"
#include <cstdio>

//#include <glm/ext.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/steamcompmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5110,7 +5110,7 @@ steamcompmgr_latch_frame_done( steamcompmgr_win_t *w, uint64_t vblank_idx )

static inline float santitize_float( float f )
{
#ifndef __FAST_MATH__
#if !( defined(__FAST_MATH__) || defined(__FINITE_MATH_ONLY__) )
return ( std::isfinite( f ) ? f : 0.f );
#else
return f;
Expand Down
Loading