Skip to content

Commit

Permalink
Remove global -ffast-math flag, but apply fast math to just calcColor…
Browse files Browse the repository at this point in the history
…Transform()

Still apply FTZ&DAZ to gamescope executables
  • Loading branch information
sharkautarch committed Aug 29, 2024
1 parent 467e12c commit 7f942ac
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
4 changes: 0 additions & 4 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ add_project_arguments(cppc.get_supported_arguments([
'-Wno-missing-braces',
]), language: 'cpp')

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

pipewire_dep = dependency('libpipewire-0.3', required: get_option('pipewire'))
librt_dep = cppc.find_library('rt', required : get_option('pipewire'))
hwdata_dep = dependency('hwdata', required : false)
Expand Down
14 changes: 14 additions & 0 deletions src/Utils/Directives.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#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
6 changes: 5 additions & 1 deletion src/color_helpers.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#define COLOR_HELPERS_CPP
#include "color_helpers_impl.h"

FAST_MATH_ON

#include <algorithm>
#include <cstdint>
#include <cmath>
Expand Down Expand Up @@ -214,7 +216,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 +912,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
8 changes: 7 additions & 1 deletion src/color_helpers_impl.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#pragma once
#include "Utils/Directives.h"

FAST_MATH_ON

#include "color_helpers.h"

namespace rendervulkan {
Expand All @@ -17,4 +21,6 @@ namespace ns_color_tests {

#ifdef COLOR_HELPERS_CPP
REGISTER_LUT_EDGE_SIZE(rendervulkan::s_nLutEdgeSize3d);
#endif
#endif

FAST_MATH_OFF
10 changes: 7 additions & 3 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ src = [
]

gamescope_cpp_args = []
faster_math_flags = cppc.get_supported_arguments([
'-mdaz-ftz'
])

if drm_dep.found()
src += 'Backends/DRMBackend.cpp'
src += 'modegen.cpp'
Expand Down Expand Up @@ -179,7 +183,7 @@ gamescope_version = vcs_tag(
libdecor_dep, eis_dep,
],
install: true,
cpp_args: gamescope_cpp_args,
cpp_args: gamescope_cpp_args + faster_math_flags,
)

gamescope_core_src = [
Expand All @@ -196,8 +200,8 @@ endif
executable('gamescopereaper', ['Apps/gamescopereaper.cpp', gamescope_core_src], gamescope_version, install:true )

benchmark_dep = dependency('benchmark', required: get_option('benchmark'), disabler: true)
executable('gamescope_color_microbench', ['color_bench.cpp', 'color_helpers.cpp'], gamescope_core_src, gamescope_version, dependencies:[benchmark_dep, glm_dep])
executable('gamescope_color_microbench', ['color_bench.cpp', 'color_helpers.cpp'], gamescope_core_src, gamescope_version, dependencies:[benchmark_dep, glm_dep], cpp_args: faster_math_flags)

executable('gamescope_color_tests', ['color_tests.cpp', 'color_helpers.cpp'], gamescope_core_src, gamescope_version, dependencies:[glm_dep])
executable('gamescope_color_tests', ['color_tests.cpp', 'color_helpers.cpp'], gamescope_core_src, gamescope_version, dependencies:[glm_dep], cpp_args: faster_math_flags)

executable('gamescopectl', ['Apps/gamescopectl.cpp'], gamescope_core_src, gamescope_version, protocols_client_src, dependencies: [dep_wayland], install:true )
2 changes: 1 addition & 1 deletion src/steamcompmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5069,7 +5069,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

0 comments on commit 7f942ac

Please sign in to comment.