32 bit compilation fixes for Visual Studio
This cl fixes all issues related to building Vulkan using the x86 compiler in Visual Studio:
- Added dummy function to prevent compiler crash in VkGetProcAddress.cpp
- Added missing WIN32 check in SwiftShader's Vulkan unit tests
- Removed alignment code which broke Win32 DLL. Removing all of it should work on all other
platforms as well.
Minor nit fix:
- Renamed VkWrapper to VkNonDispatchableHandle, which is a more accurate name.
Bug b/129979580
Change-Id: Ib2bf305433e9aae71ff6f9d796fb86bc7ea733b0
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/31609
Tested-by: Alexis Hétu <sugoi@google.com>
Presubmit-Ready: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Vulkan/VkGetProcAddress.cpp b/src/Vulkan/VkGetProcAddress.cpp
index 308c0b5..55cd84a 100644
--- a/src/Vulkan/VkGetProcAddress.cpp
+++ b/src/Vulkan/VkGetProcAddress.cpp
@@ -429,3 +429,36 @@
};
#endif
+
+#if defined(_MSC_VER) && !defined(_WIN64)
+namespace
+{
+ // The following function is a hack to allow compilation in Visual Studio using the 32 bit compiler"
+ // "fatal error C1001: An internal error has occurred in the compiler.
+ // (compiler file 'd:\agent\_work\1\s\src\vctools\compiler\utc\src\p2\main.c', line 187)"
+ void Dummy()
+ {
+ { VkSemaphore handle; }
+ { VkFence handle; }
+ { VkDeviceMemory handle; }
+ { VkBuffer handle; }
+ { VkImage handle; }
+ { VkEvent handle; }
+ { VkQueryPool handle; }
+ { VkBufferView handle; }
+ { VkImageView handle; }
+ { VkShaderModule handle; }
+ { VkPipelineCache handle; }
+ { VkPipelineLayout handle; }
+ { VkRenderPass handle; }
+ { VkPipeline handle; }
+ { VkDescriptorSetLayout handle; }
+ { VkSampler handle; }
+ { VkDescriptorPool handle; }
+ { VkFramebuffer handle; }
+ { VkCommandPool handle; }
+ { VkSamplerYcbcrConversion handle; }
+ { VkDescriptorUpdateTemplate handle; }
+ }
+}
+#endif
\ No newline at end of file
diff --git a/src/Vulkan/VulkanPlatform.h b/src/Vulkan/VulkanPlatform.h
index 9825197..068d3eb 100644
--- a/src/Vulkan/VulkanPlatform.h
+++ b/src/Vulkan/VulkanPlatform.h
@@ -18,20 +18,10 @@
#include <cstddef>
#include <cstdint>
-// We can't directly use alignas(uint64_t) because on some platforms a uint64_t
-// has an alignment of 8 outside of a struct but inside it has an alignment of
-// 4. We use this dummy struct to figure out the alignment of uint64_t inside a
-// struct.
-struct DummyUInt64Wrapper {
- uint64_t dummy;
-};
-
-static constexpr size_t kNativeVkHandleAlignment = alignof(DummyUInt64Wrapper);
-
-template<typename HandleType> class alignas(kNativeVkHandleAlignment) VkWrapperBase
+template<typename HandleType> class VkNonDispatchableHandleBase
{
public:
- VkWrapperBase(HandleType handle)
+ VkNonDispatchableHandleBase(HandleType handle)
{
u.dummy = 0;
u.handle = handle;
@@ -57,23 +47,23 @@
union PointerHandleUnion
{
HandleType handle;
- uint64_t dummy; // VkWrapper's size must always be 64 bits even when void* is 32 bits
+ uint64_t dummy; // VkNonDispatchableHandle's size must always be 64 bits even when void* is 32 bits
};
PointerHandleUnion u;
};
-template<typename T> class alignas(kNativeVkHandleAlignment) VkWrapper : public VkWrapperBase<T>
+template<typename T> class VkNonDispatchableHandle : public VkNonDispatchableHandleBase<T>
{
public:
using HandleType = T;
- VkWrapper() : VkWrapperBase<T>(nullptr)
+ VkNonDispatchableHandle() : VkNonDispatchableHandleBase<T>(nullptr)
{
}
- VkWrapper(HandleType handle) : VkWrapperBase<T>(handle)
+ VkNonDispatchableHandle(HandleType handle) : VkNonDispatchableHandleBase<T>(handle)
{
- static_assert(sizeof(VkWrapper) == sizeof(uint64_t), "Size is not 64 bits!");
+ static_assert(sizeof(VkNonDispatchableHandle) == sizeof(uint64_t), "Size is not 64 bits!");
}
void operator=(HandleType handle)
@@ -85,14 +75,14 @@
// VkDescriptorSet objects are really just memory in the VkDescriptorPool
// object, so define different/more convenient operators for this object.
struct VkDescriptorSet_T;
-template<> class alignas(kNativeVkHandleAlignment) VkWrapper<VkDescriptorSet_T*> : public VkWrapperBase<uint8_t*>
+template<> class VkNonDispatchableHandle<VkDescriptorSet_T*> : public VkNonDispatchableHandleBase<uint8_t*>
{
public:
using HandleType = uint8_t*;
- VkWrapper(HandleType handle) : VkWrapperBase<uint8_t*>(handle)
+ VkNonDispatchableHandle(HandleType handle) : VkNonDispatchableHandleBase<uint8_t*>(handle)
{
- static_assert(sizeof(VkWrapper) == sizeof(uint64_t), "Size is not 64 bits!");
+ static_assert(sizeof(VkNonDispatchableHandle) == sizeof(uint64_t), "Size is not 64 bits!");
}
HandleType operator+(ptrdiff_t rhs) const
@@ -113,7 +103,7 @@
#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) \
typedef struct object##_T *object##Ptr; \
- typedef VkWrapper<object##Ptr> object;
+ typedef VkNonDispatchableHandle<object##Ptr> object;
#include <vulkan/vulkan.h>
diff --git a/tests/VulkanUnitTests/Driver.cpp b/tests/VulkanUnitTests/Driver.cpp
index c53f1f7..440ea8e 100644
--- a/tests/VulkanUnitTests/Driver.cpp
+++ b/tests/VulkanUnitTests/Driver.cpp
@@ -14,7 +14,7 @@
#include "Driver.hpp"
-#if defined(_WIN64)
+#if defined(_WIN32)
# include "Windows.h"
# define OS_WINDOWS 1
#elif defined(__APPLE__)