From 944070fdd7208444453b132e49c111f032fe8694 Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 9 Nov 2020 17:59:53 +0000 Subject: [PATCH] Fix warnings with clang build of half library * Comma operator problems when doing math functions that return two parameters (e.g quotient). * Passing bool tag type through varargs - the varargs aren't actually used and there's an overload for true_type, so we can instead accept false_type. * gcc seems to declare numeric_limits as a struct, so friend'ing it as a class throws a warning. Since we only care about C++11 we can omit the tag from the friend declaration. --- renderdoc/3rdparty/half/half.hpp | 43 +++++++++++++------ .../driver/shaders/spirv/spirv_processor.h | 6 ++- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/renderdoc/3rdparty/half/half.hpp b/renderdoc/3rdparty/half/half.hpp index 0f60403e9..76d7f3b1d 100644 --- a/renderdoc/3rdparty/half/half.hpp +++ b/renderdoc/3rdparty/half/half.hpp @@ -1028,7 +1028,7 @@ namespace half_float /// \exception FE_OVERFLOW on overflows /// \exception FE_UNDERFLOW on underflows /// \exception FE_INEXACT if value had to be rounded - template unsigned int float2half_impl(T value, ...) + template unsigned int float2half_impl(T value, false_type) { unsigned int hbits = static_cast(builtin_signbit(value)) << 15; if(value == T()) @@ -1280,7 +1280,7 @@ namespace half_float /// \tparam T type to convert to (builtin integer type) /// \param value half-precision value to convert /// \return floating-point value - template T half2float_impl(unsigned int value, T, ...) + template T half2float_impl(unsigned int value, T, false_type) { T out; unsigned int abs = value & 0x7FFF; @@ -1381,7 +1381,8 @@ namespace half_float { #if HALF_ENABLE_CPP11_LONG_LONG unsigned long long xx = static_cast(x) << 32; - return s = (xx%y!=0), static_cast(xx/y); + s = (xx%y!=0); + return static_cast(xx/y); #else y >>= 1; uint32 rem = x, div = 0; @@ -1395,7 +1396,8 @@ namespace half_float } rem <<= 1; } - return s = rem > 1, div; + s = rem > 1; + return div; #endif } @@ -1440,7 +1442,10 @@ namespace half_float { q &= (1<<(std::numeric_limits::digits-1)) - 1; if(!mx) - return *quo = q, 0; + { + *quo = q; + return 0; + } } for(; mx<0x400; mx<<=1,--expy) ; x = (expy>0) ? ((expy<<10)|(mx&0x3FF)) : (mx>>(1-expy)); @@ -1606,7 +1611,10 @@ namespace half_float uint32 m = (abs&0x3FF) | ((abs>0x3FF)<<10); int exp = (abs>>10) + (abs<=0x3FF) - 15; if(abs < 0x3A48) - return k = 0, m << (exp+20); + { + k = 0; + return m << (exp+20); + } #if HALF_ENABLE_CPP11_LONG_LONG unsigned long long y = m * 0xA2F9836E4E442, mask = (1ULL<<(62-exp)) - 1, yi = (y+(mask>>1)) & ~mask, f = y - yi; uint32 sign = -static_cast(f>>63); @@ -2255,7 +2263,7 @@ namespace half_float friend HALF_CONSTEXPR bool islessequal(half, half); friend HALF_CONSTEXPR bool islessgreater(half, half); template friend struct detail::half_caster; - friend class std::numeric_limits; + friend std::numeric_limits; #if HALF_ENABLE_CPP11_HASH friend struct std::hash; #endif @@ -2784,15 +2792,19 @@ namespace half_float { unsigned int absx = x.data_ & 0x7FFF, absy = y.data_ & 0x7FFF, value = x.data_ & 0x8000; if(absx >= 0x7C00 || absy >= 0x7C00) + { + *quo = 0; return half(detail::binary, (absx>0x7C00 || absy>0x7C00) ? detail::signal(x.data_, y.data_) : - (absx==0x7C00) ? detail::invalid() : (*quo = 0, x.data_)); + (absx==0x7C00) ? detail::invalid() : (x.data_)); + } if(!absy) return half(detail::binary, detail::invalid()); bool qsign = ((value^y.data_)&0x8000) != 0; int q = 1; if(absx != absy) value ^= detail::mod(absx, absy, &q); - return *quo = qsign ? -q : q, half(detail::binary, value); + *quo = qsign ? -q : q; + return half(detail::binary, value); } /// Fused multiply add. @@ -4196,12 +4208,19 @@ namespace half_float if(abs > 0x7C00) { arg = half(detail::binary, detail::signal(arg.data_)); - return *iptr = arg, arg; + *iptr = arg; + return arg; } if(abs >= 0x6400) - return *iptr = arg, half(detail::binary, arg.data_&0x8000); + { + *iptr = arg; + return half(detail::binary, arg.data_&0x8000); + } if(abs < 0x3C00) - return iptr->data_ = arg.data_ & 0x8000, arg; + { + iptr->data_ = arg.data_ & 0x8000; + return arg; + } unsigned int exp = abs >> 10, mask = (1<<(25-exp)) - 1, m = arg.data_ & mask; iptr->data_ = arg.data_ & ~mask; if(!m) diff --git a/renderdoc/driver/shaders/spirv/spirv_processor.h b/renderdoc/driver/shaders/spirv/spirv_processor.h index 779098ff0..5499c2304 100644 --- a/renderdoc/driver/shaders/spirv/spirv_processor.h +++ b/renderdoc/driver/shaders/spirv/spirv_processor.h @@ -27,7 +27,6 @@ #include #include #include -#include "3rdparty/half/half.hpp" #include "api/replay/rdcarray.h" #include "api/replay/rdcpair.h" #include "api/replay/rdcstr.h" @@ -36,6 +35,11 @@ #include "common/common.h" #include "spirv_common.h" +namespace half_float +{ +class half; +}; + namespace rdcspv { struct Scalar