From 4c9c8a7a4d9b97fec6041a562638fbea521533ed Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Fri, 14 Apr 2023 17:08:18 +0800 Subject: Some small fixes with Windows/DX usage (#2797) * Correct case of windows.h includes * Use Slang::SharedLibrary to load directx dlls * s/max/std::max/ * Factor common OS code in calcHasApi * Add DXIL test for compute/simple * s/false/FALSE for calls to WinAPI functions * Factor common OS code in gfxGetAdapters * 2 missing headers d3d12sdklayers for ID3DDebug climits for UINT_MAX * Define out unused function on Linux * Only try to load Vulkan and CUDA on Windows or Linux * simplify D3DUtil::getDxgiModule * Remove WIN32_LEAN_AND_MEAN &co from source files Add a global define * Set WIN32_LEAN_AND_MEAN &friends in headers Restore previous state also * regenerate vs projects --- source/compiler-core/slang-dxc-compiler.cpp | 8 +--- source/compiler-core/slang-fxc-compiler.cpp | 6 +-- .../windows/slang-win-visual-studio-util.cpp | 7 +--- source/core/slang-io.cpp | 5 +-- source/core/slang-platform.cpp | 6 +-- source/core/slang-render-api-util.cpp | 49 ++++++++-------------- source/core/slang-shared-library.cpp | 3 +- source/core/windows/slang-win-process.cpp | 7 +--- source/slang-glslang/slang-glslang.cpp | 2 +- source/slang-rt/slang-rt.cpp | 2 +- 10 files changed, 28 insertions(+), 67 deletions(-) (limited to 'source') diff --git a/source/compiler-core/slang-dxc-compiler.cpp b/source/compiler-core/slang-dxc-compiler.cpp index a275143f8..832c5809c 100644 --- a/source/compiler-core/slang-dxc-compiler.cpp +++ b/source/compiler-core/slang-dxc-compiler.cpp @@ -34,13 +34,9 @@ #if SLANG_ENABLE_DXIL_SUPPORT # ifdef _WIN32 -# define WIN32_LEAN_AND_MEAN -# define NOMINMAX -# include -# include +# include +# include # include "../../external/dxc/dxcapi.h" -# undef WIN32_LEAN_AND_MEAN -# undef NOMINMAX # else # include "../../external/dxc/dxcapi.h" diff --git a/source/compiler-core/slang-fxc-compiler.cpp b/source/compiler-core/slang-fxc-compiler.cpp index de6f5d2bc..9d547e673 100644 --- a/source/compiler-core/slang-fxc-compiler.cpp +++ b/source/compiler-core/slang-fxc-compiler.cpp @@ -26,11 +26,7 @@ // Enable calling through to `fxc` or `dxc` to // generate code on Windows. #ifdef _WIN32 -# define WIN32_LEAN_AND_MEAN -# define NOMINMAX -# include -# undef WIN32_LEAN_AND_MEAN -# undef NOMINMAX +# include # include # ifndef SLANG_ENABLE_DXBC_SUPPORT diff --git a/source/compiler-core/windows/slang-win-visual-studio-util.cpp b/source/compiler-core/windows/slang-win-visual-studio-util.cpp index d4c72e100..cb784b426 100644 --- a/source/compiler-core/windows/slang-win-visual-studio-util.cpp +++ b/source/compiler-core/windows/slang-win-visual-studio-util.cpp @@ -10,12 +10,7 @@ #include "../slang-visual-studio-compiler-util.h" #ifdef _WIN32 -# define WIN32_LEAN_AND_MEAN -# define NOMINMAX -# include -# undef WIN32_LEAN_AND_MEAN -# undef NOMINMAX - +# include # include #pragma comment(lib, "advapi32") #pragma comment(lib, "Shell32") diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp index 5c57a4b3a..30ba41d0f 100644 --- a/source/core/slang-io.cpp +++ b/source/core/slang-io.cpp @@ -16,10 +16,7 @@ #ifdef _WIN32 # include - -# define WIN32_LEAN_AND_MEAN -# define VC_EXTRALEAN -# include +# include #endif #if defined(__linux__) || defined(__CYGWIN__) || SLANG_APPLE_FAMILY diff --git a/source/core/slang-platform.cpp b/source/core/slang-platform.cpp index bb612932c..4f9b0698c 100644 --- a/source/core/slang-platform.cpp +++ b/source/core/slang-platform.cpp @@ -8,11 +8,7 @@ #include "slang-io.h" #ifdef _WIN32 - #define WIN32_LEAN_AND_MEAN - #define NOMINMAX - #include - #undef WIN32_LEAN_AND_MEAN - #undef NOMINMAX + #include #else #include "slang-string.h" #include diff --git a/source/core/slang-render-api-util.cpp b/source/core/slang-render-api-util.cpp index bc15a8164..fa39f46ee 100644 --- a/source/core/slang-render-api-util.cpp +++ b/source/core/slang-render-api-util.cpp @@ -261,41 +261,28 @@ static bool _canLoadSharedLibrary(const char* libName) /* static */bool RenderApiUtil::calcHasApi(RenderApiType type) { -#if SLANG_WINDOWS_FAMILY switch (type) { - case RenderApiType::OpenGl: return _canLoadSharedLibrary("opengl32"); - case RenderApiType::Vulkan: return _canLoadSharedLibrary("vulkan-1") || _canLoadSharedLibrary("vk_swiftshader"); - case RenderApiType::D3D11: return _canLoadSharedLibrary("d3d11"); - case RenderApiType::D3D12: return _canLoadSharedLibrary("d3d12"); - case RenderApiType::CPU: return true; - case RenderApiType::CUDA: - { - // We'll assume it's available, and if not trying to create it will detect it - return true; - } - default: break; - } +#if SLANG_WINDOWS_FAMILY + case RenderApiType::OpenGl: return _canLoadSharedLibrary("opengl32"); + case RenderApiType::Vulkan: return _canLoadSharedLibrary("vulkan-1") || _canLoadSharedLibrary("vk_swiftshader"); + case RenderApiType::D3D11: return _canLoadSharedLibrary("d3d11"); + case RenderApiType::D3D12: return _canLoadSharedLibrary("d3d12"); #elif SLANG_UNIX_FAMILY - // Assume on unix target we never have D3D - switch (type) - { - case RenderApiType::OpenGl: - case RenderApiType::Vulkan: - { - return true; - } - case RenderApiType::CPU: - { - return true; - } - case RenderApiType::CUDA: - { - return true; - } - default: break; - } + case RenderApiType::D3D11: return false; + case RenderApiType::D3D12: return false; + // The below can be used once they're confirmed working with gfx + // case RenderApiType::D3D11: return _canLoadSharedLibrary("dxvk_d3d11"); + // case RenderApiType::D3D12: return _canLoadSharedLibrary("vkd3d-proton-d3d12"); + + case RenderApiType::OpenGl: return true; + case RenderApiType::Vulkan: return true; #endif + case RenderApiType::CPU: return true; + // We'll assume CUDA is available, and if not, trying to create it will detect it + case RenderApiType::CUDA: return true; + default: break; + } return false; } diff --git a/source/core/slang-shared-library.cpp b/source/core/slang-shared-library.cpp index e0fe82012..c3991ad06 100644 --- a/source/core/slang-shared-library.cpp +++ b/source/core/slang-shared-library.cpp @@ -6,8 +6,7 @@ #include "slang-string-util.h" #if defined(_WIN32) -#define WIN32_LEAN_AND_MEAN -#include +#include #elif defined(__linux__) || defined(SLANG_OSX) #include #endif diff --git a/source/core/windows/slang-win-process.cpp b/source/core/windows/slang-win-process.cpp index 215904938..93bff3eb3 100644 --- a/source/core/windows/slang-win-process.cpp +++ b/source/core/windows/slang-win-process.cpp @@ -9,15 +9,10 @@ #include "../../../slang-com-helper.h" #ifdef _WIN32 -// Include Windows header in a way that minimized namespace pollution. // TODO: We could try to avoid including this at all, but it would // mean trying to hide certain struct layouts, which would add // more dynamic allocation. -# define WIN32_LEAN_AND_MEAN -# define NOMINMAX -# include -# undef WIN32_LEAN_AND_MEAN -# undef NOMINMAX +# include #endif #include diff --git a/source/slang-glslang/slang-glslang.cpp b/source/slang-glslang/slang-glslang.cpp index 6b5ed03f0..489294d99 100644 --- a/source/slang-glslang/slang-glslang.cpp +++ b/source/slang-glslang/slang-glslang.cpp @@ -19,7 +19,7 @@ #include "spirv-tools/libspirv.h" #ifdef _WIN32 -# include +# include #endif #include diff --git a/source/slang-rt/slang-rt.cpp b/source/slang-rt/slang-rt.cpp index 49d4f2c9a..75997aeaa 100644 --- a/source/slang-rt/slang-rt.cpp +++ b/source/slang-rt/slang-rt.cpp @@ -3,7 +3,7 @@ #include "../core/slang-shared-library.h" #if SLANG_WINDOWS_FAMILY -# include +# include #endif using namespace Slang; -- cgit v1.2.3