Loading vulkan/vkjson/vkjson.cc +15 −5 Original line number Original line Diff line number Diff line Loading @@ -21,11 +21,14 @@ #include "vkjson.h" #include "vkjson.h" #include <assert.h> #include <assert.h> #include <string.h> #include <stdlib.h> #include <stdlib.h> #include <string.h> #include <cmath> #include <json/json.h> #include <algorithm> #include <cinttypes> #include <cinttypes> #include <cmath> #include <cstdio> #include <cstdio> #include <limits> #include <limits> #include <memory> #include <memory> Loading @@ -33,8 +36,6 @@ #include <type_traits> #include <type_traits> #include <utility> #include <utility> #include <json/json.h> namespace { namespace { inline bool IsIntegral(double value) { inline bool IsIntegral(double value) { Loading @@ -46,6 +47,14 @@ inline bool IsIntegral(double value) { #endif #endif } } // Floating point fields of Vulkan structure use single precision. The string // output of max double value in c++ will be larger than Java double's infinity // value. Below fake double max/min values are only to serve the safe json text // parsing in between C++ and Java, becasue Java json library simply cannot // handle infinity. static const double SAFE_DOUBLE_MAX = 0.99 * std::numeric_limits<double>::max(); static const double SAFE_DOUBLE_MIN = 0.99 * std::numeric_limits<double>::min(); template <typename T> struct EnumTraits; template <typename T> struct EnumTraits; template <> struct EnumTraits<VkPhysicalDeviceType> { template <> struct EnumTraits<VkPhysicalDeviceType> { static uint32_t min() { return VK_PHYSICAL_DEVICE_TYPE_BEGIN_RANGE; } static uint32_t min() { return VK_PHYSICAL_DEVICE_TYPE_BEGIN_RANGE; } Loading Loading @@ -851,7 +860,8 @@ Json::Value ToJsonValue(const T& value); template <typename T, typename = EnableForArithmetic<T>> template <typename T, typename = EnableForArithmetic<T>> inline Json::Value ToJsonValue(const T& value) { inline Json::Value ToJsonValue(const T& value) { return Json::Value(static_cast<double>(value)); return Json::Value( std::clamp(static_cast<double>(value), SAFE_DOUBLE_MIN, SAFE_DOUBLE_MAX)); } } inline Json::Value ToJsonValue(const uint64_t& value) { inline Json::Value ToJsonValue(const uint64_t& value) { Loading Loading
vulkan/vkjson/vkjson.cc +15 −5 Original line number Original line Diff line number Diff line Loading @@ -21,11 +21,14 @@ #include "vkjson.h" #include "vkjson.h" #include <assert.h> #include <assert.h> #include <string.h> #include <stdlib.h> #include <stdlib.h> #include <string.h> #include <cmath> #include <json/json.h> #include <algorithm> #include <cinttypes> #include <cinttypes> #include <cmath> #include <cstdio> #include <cstdio> #include <limits> #include <limits> #include <memory> #include <memory> Loading @@ -33,8 +36,6 @@ #include <type_traits> #include <type_traits> #include <utility> #include <utility> #include <json/json.h> namespace { namespace { inline bool IsIntegral(double value) { inline bool IsIntegral(double value) { Loading @@ -46,6 +47,14 @@ inline bool IsIntegral(double value) { #endif #endif } } // Floating point fields of Vulkan structure use single precision. The string // output of max double value in c++ will be larger than Java double's infinity // value. Below fake double max/min values are only to serve the safe json text // parsing in between C++ and Java, becasue Java json library simply cannot // handle infinity. static const double SAFE_DOUBLE_MAX = 0.99 * std::numeric_limits<double>::max(); static const double SAFE_DOUBLE_MIN = 0.99 * std::numeric_limits<double>::min(); template <typename T> struct EnumTraits; template <typename T> struct EnumTraits; template <> struct EnumTraits<VkPhysicalDeviceType> { template <> struct EnumTraits<VkPhysicalDeviceType> { static uint32_t min() { return VK_PHYSICAL_DEVICE_TYPE_BEGIN_RANGE; } static uint32_t min() { return VK_PHYSICAL_DEVICE_TYPE_BEGIN_RANGE; } Loading Loading @@ -851,7 +860,8 @@ Json::Value ToJsonValue(const T& value); template <typename T, typename = EnableForArithmetic<T>> template <typename T, typename = EnableForArithmetic<T>> inline Json::Value ToJsonValue(const T& value) { inline Json::Value ToJsonValue(const T& value) { return Json::Value(static_cast<double>(value)); return Json::Value( std::clamp(static_cast<double>(value), SAFE_DOUBLE_MIN, SAFE_DOUBLE_MAX)); } } inline Json::Value ToJsonValue(const uint64_t& value) { inline Json::Value ToJsonValue(const uint64_t& value) { Loading