From a54a3ec74ea95326096feb46317fb9c6cd277742 Mon Sep 17 00:00:00 2001 From: Jun Bo Bi <21069675+jambonmcyeah@users.noreply.github.com> Date: Sun, 4 Sep 2022 17:15:40 -0400 Subject: [PATCH] Fix build using clang-cl on windows and improve driver detection (#129) --- CMakeLists.txt | 10 +++++++++- dependencies/DirectX_2010/XAudio2.h | 7 ++++++- .../ih264d/common/x86/ih264_platform_macros.h | 5 ++++- src/Cafe/HW/Espresso/PPCTimer.cpp | 5 +++-- src/Cafe/HW/Latte/Core/LatteTextureCache.cpp | 6 +++++- .../Latte/Renderer/OpenGL/OpenGLRenderer.cpp | 2 +- .../Latte/Renderer/Vulkan/VulkanRenderer.cpp | 6 ++++-- src/resource/cemu.rc | Bin 9690 -> 4689 bytes 8 files changed, 32 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a47fe8af..b001421d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,15 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) if (MSVC) set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT CemuBin) # floating point model: precise, fiber safe optimizations - add_compile_options(/EHsc /fp:precise /GT) + add_compile_options(/EHsc /fp:precise) + if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + # Speeds up static linking (especially helpful in incremental compilation) + if((CMAKE_LINKER MATCHES ".*lld-link.*") AND (CMAKE_AR MATCHES ".*llvm-lib.*")) + set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY STATIC_LIBRARY_OPTIONS /llvmlibthin) + endif() + else() + add_compile_options(/GT) + endif() if (PUBLIC_RELEASE) message(STATUS "Using additional optimization flags for MSVC") add_compile_options(/Oi /Ot) # enable intrinsic functions, favor speed diff --git a/dependencies/DirectX_2010/XAudio2.h b/dependencies/DirectX_2010/XAudio2.h index db0ebd8f..a42c0afc 100644 --- a/dependencies/DirectX_2010/XAudio2.h +++ b/dependencies/DirectX_2010/XAudio2.h @@ -48,10 +48,15 @@ //DEFINE_CLSID(XAudio2_Debug, 47199894, 7cc2, 444d, 98, 73, ce, d2, 56, 2c, c6, 0e); // XAudio 2.7 (June 2010 SDK) +#ifdef __clang__ +class __declspec(uuid("5a508685-a254-4fba-9b82-9a24b00306af")) XAudio2; extern "C" const GUID CLSID_XAudio2; +class __declspec(uuid("db05ea35-0329-4d4b-a53a-6dead03d3852")) XAudio2_Debug; extern "C" const GUID CLSID_XAudio2_Debug; +struct __declspec(uuid("8bcf1f58-9fe7-4583-8ac6-e2adc465c8bb")) IXAudio2; extern "C" const GUID IID_IXAudio2; +#else DEFINE_CLSID(XAudio2, 5a508685, a254, 4fba, 9b, 82, 9a, 24, b0, 03, 06, af); DEFINE_CLSID(XAudio2_Debug, db05ea35, 0329, 4d4b, a5, 3a, 6d, ea, d0, 3d, 38, 52); DEFINE_IID(IXAudio2, 8bcf1f58, 9fe7, 4583, 8a, c6, e2, ad, c4, 65, c8, bb); - +#endif // Ignore the rest of this header if only the GUID definitions were requested #ifndef GUID_DEFS_ONLY diff --git a/dependencies/ih264d/common/x86/ih264_platform_macros.h b/dependencies/ih264d/common/x86/ih264_platform_macros.h index 0b15cf5a..ebc1b106 100644 --- a/dependencies/ih264d/common/x86/ih264_platform_macros.h +++ b/dependencies/ih264d/common/x86/ih264_platform_macros.h @@ -40,6 +40,9 @@ #include #include +#if defined(_MSC_VER) && defined(__clang__) +#include +#endif #define CLIP_U8(x) CLIP3(0, UINT8_MAX, (x)) #define CLIP_S8(x) CLIP3(INT8_MIN, INT8_MAX, (x)) @@ -71,7 +74,7 @@ /* For MSVC x64 */ -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__clang__) static inline int __builtin_clz(unsigned x) { diff --git a/src/Cafe/HW/Espresso/PPCTimer.cpp b/src/Cafe/HW/Espresso/PPCTimer.cpp index bcf1a58d..2a1a7669 100644 --- a/src/Cafe/HW/Espresso/PPCTimer.cpp +++ b/src/Cafe/HW/Espresso/PPCTimer.cpp @@ -110,7 +110,8 @@ uint64 PPCTimer_tscToMicroseconds(uint64 us) uint64 remainder; -#if _MSC_VER < 1923 + +#if _MSC_VER < 1923 || defined(__clang__) const uint64 microseconds = udiv128(r.low, r.high, _rdtscFrequency, &remainder); #else const uint64 microseconds = _udiv128(r.high, r.low, _rdtscFrequency, &remainder); @@ -158,7 +159,7 @@ uint64 PPCTimer_getFromRDTSC() #endif uint64 remainder; -#if _MSC_VER < 1923 +#if _MSC_VER < 1923 || defined(__clang__) uint64 elapsedTick = udiv128(_rdtscAcc.low, _rdtscAcc.high, _rdtscFrequency, &remainder); #else uint64 elapsedTick = _udiv128(_rdtscAcc.high, _rdtscAcc.low, _rdtscFrequency, &remainder); diff --git a/src/Cafe/HW/Latte/Core/LatteTextureCache.cpp b/src/Cafe/HW/Latte/Core/LatteTextureCache.cpp index 151f0661..2caa2cd0 100644 --- a/src/Cafe/HW/Latte/Core/LatteTextureCache.cpp +++ b/src/Cafe/HW/Latte/Core/LatteTextureCache.cpp @@ -145,7 +145,7 @@ uint32 LatteTexture_CalculateTextureDataHash(LatteTexture* hostTexture) bool isCompressedFormat = hostTexture->IsCompressedFormat(); if( isCompressedFormat == false ) { - #if BOOST_OS_WINDOWS +#if BOOST_OS_WINDOWS if (_cpuExtension_AVX2) { __m256i h256 = { 0 }; @@ -157,7 +157,11 @@ uint32 LatteTexture_CalculateTextureDataHash(LatteTexture* hostTexture) readPtr += (288 / 32); h256 = _mm256_xor_si256(h256, temp); } +#ifdef __clang__ + hashVal = h256[0] + h256[1] + h256[2] + h256[3] + h256[4] + h256[5] + h256[6] + h256[7]; +#else hashVal = h256.m256i_u32[0] + h256.m256i_u32[1] + h256.m256i_u32[2] + h256.m256i_u32[3] + h256.m256i_u32[4] + h256.m256i_u32[5] + h256.m256i_u32[6] + h256.m256i_u32[7]; +#endif } #else if( false ) {} diff --git a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp index 80c72918..269f30e8 100644 --- a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp @@ -378,7 +378,7 @@ void OpenGLRenderer::GetVendorInformation() forceLog_printf("GL_RENDERER: %s", glRendererString ? glRendererString : "unknown"); forceLog_printf("GL_VERSION: %s", glVersionString ? glVersionString : "unknown"); - if(boost::icontains(glVersionString, "Mesa") || IsRunningInWine()) + if(boost::icontains(glVersionString, "Mesa")) { m_vendor = GfxVendor::Mesa; return; diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp index e033d954..7c81a3c9 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp @@ -197,7 +197,9 @@ void VulkanRenderer::DetermineVendor() break; } - if (IsRunningInWine()) + VkDriverId driverId = driverProperties.driverID; + + if(driverId == VK_DRIVER_ID_MESA_RADV || driverId == VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA) m_vendor = GfxVendor::Mesa; forceLog_printf("Using GPU: %s", properties.properties.deviceName); @@ -216,7 +218,7 @@ void VulkanRenderer::DetermineVendor() else { forceLog_printf("Driver version (as stored in device info): %08X", properties.properties.driverVersion); - + if(m_vendor == GfxVendor::Nvidia) { // if the driver does not support the extension, diff --git a/src/resource/cemu.rc b/src/resource/cemu.rc index 4781111df8a49cd45832f9e3529faf50f585f3e2..aaa2a850d9a44b4ac6a95a0c75646763b26e983b 100644 GIT binary patch literal 4689 zcmcIoUvr{J5Pv>C#hiJGwZRyZOXcnjWpue9c>FQRmQ@t$pw!}wHNeJH?KiuJ`$+c{ zt_Kh>(UhBWd4QRw`E^fsPfs`h{{7G8B^rh^&SDlMXdK3=AEDl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