From 8084db38bc3a85fbdc7af9f7c18cb552860f516a Mon Sep 17 00:00:00 2001
From: Tobias Frisch <tfrisch@uni-koblenz.de>
Date: Mon, 2 Aug 2021 07:17:04 +0200
Subject: [PATCH] [#101] Fix for MSVC

Signed-off-by: Tobias Frisch <tfrisch@uni-koblenz.de>
---
 CMakeLists.txt              |  2 +-
 src/vkcv/FeatureManager.cpp | 28 +++++++++++++++++-----------
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index dfafe1cd..da150fcb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -65,7 +65,7 @@ add_library(vkcv STATIC ${vkcv_sources})
 
 if(MSVC)
   #enable multicore compilation on visual studio
-  target_compile_options(vkcv PRIVATE "/MP" "/openmp")
+  target_compile_options(vkcv PRIVATE "/MP" "/openmp" "/Zc:offsetof-")
 
   #set source groups to create proper filters in visual studio
   source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${vkcv_sources})
diff --git a/src/vkcv/FeatureManager.cpp b/src/vkcv/FeatureManager.cpp
index bb331de1..1ef33b16 100644
--- a/src/vkcv/FeatureManager.cpp
+++ b/src/vkcv/FeatureManager.cpp
@@ -1,26 +1,32 @@
 
 #include "vkcv/FeatureManager.hpp"
 
+#include <stddef.h>
 #include <string.h>
+#include <type_traits>
 
 namespace vkcv {
-
+	
+#ifdef _MSVC_LANG
+#define typeof(var) std::decay<decltype((var))>::type
+#endif
+	
 #define vkcv_check_init_features2(type)\
 type supported;                        \
 vk::PhysicalDeviceFeatures2 query;     \
 query.setPNext(&supported);            \
 m_physicalDevice.getFeatures2(&query)
 
-#define vkcv_check_feature(attribute) {                                                                  \
-  const char *f = reinterpret_cast<const char*>(&(features));                                            \
-  const char *s = reinterpret_cast<const char*>(&(supported));                                           \
-  const vk::Bool32* fb = reinterpret_cast<const vk::Bool32*>(f + offsetof(typeof(features), attribute)); \
-  const vk::Bool32* sb = reinterpret_cast<const vk::Bool32*>(s + offsetof(typeof(features), attribute)); \
-  if ((*fb) && (!*sb)) {                                                                                 \
-    vkcv_log(((required)? LogLevel::ERROR : LogLevel::WARNING),                                          \
-    "Feature '" #attribute "' is not supported");                                                        \
-    return false;                                                                                        \
-  }                                                                                                      \
+#define vkcv_check_feature(attribute) {                                                                    \
+  const char *f = reinterpret_cast<const char*>(&(features));                                              \
+  const char *s = reinterpret_cast<const char*>(&(supported));                                             \
+  const vk::Bool32* fb = reinterpret_cast<const vk::Bool32*>(f + offsetof(typeof((features)), attribute)); \
+  const vk::Bool32* sb = reinterpret_cast<const vk::Bool32*>(s + offsetof(typeof((features)), attribute)); \
+  if ((*fb) && (!*sb)) {                                                                                   \
+    vkcv_log(((required)? LogLevel::ERROR : LogLevel::WARNING),                                            \
+    "Feature '" #attribute "' is not supported");                                                          \
+    return false;                                                                                          \
+  }                                                                                                        \
 }
 	
 	bool FeatureManager::checkSupport(const vk::PhysicalDevice16BitStorageFeatures &features, bool required) const {
-- 
GitLab