Skip to content

Commit

Permalink
A number of build fixes
Browse files Browse the repository at this point in the history
* Reworked D3D11/D3D12 support detection to rely on try_compile
* Reworked Windows SDK version detection to work in CMake 3.27
* Fixed PipelineResourceSignatureTest.RunTimeResourceArray_HLSL test that started to fail because of the WARP bug workaround
  • Loading branch information
TheMostDiligent committed Oct 20, 2023
1 parent 813864e commit 36e7347
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 29 deletions.
File renamed without changes.
6 changes: 6 additions & 0 deletions BuildTools/CMake/CheckATL.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <atlbase.h>

int main()
{
return 0;
}
6 changes: 6 additions & 0 deletions BuildTools/CMake/CheckD3D11.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <d3d11.h>

int main()
{
return 0;
}
6 changes: 6 additions & 0 deletions BuildTools/CMake/CheckD3D12.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <d3d12.h>

int main()
{
return 0;
}
52 changes: 35 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,24 @@ endif()
message("CMake generator: " ${CMAKE_GENERATOR})

if(WIN32)
if (CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION)
set(WINDOWS_SDK_VERSION ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION} CACHE INTERNAL "Windows SDK version")
elseif(DEFINED ENV{WindowsSDKVersion})
set(WINDOWS_SDK_VERSION $ENV{WindowsSDKVersion})
# For unbeknown reason, the value ends with a backslash, so we need to remove it
string(REPLACE "\\" "" WINDOWS_SDK_VERSION ${WINDOWS_SDK_VERSION})
set(WINDOWS_SDK_VERSION ${WINDOWS_SDK_VERSION} CACHE INTERNAL "Windows SDK version")
else()
set(WINDOWS_SDK_VERSION "0.0" CACHE INTERNAL "Windows SDK version")
message(WARNING "Unable to determine Windows SDK version: neither the CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION CMake variable nor the WindowsSDKVersion environment variable is set")
endif()

if(${CMAKE_SYSTEM_NAME} STREQUAL "WindowsStore")
set(PLATFORM_UNIVERSAL_WINDOWS TRUE CACHE INTERNAL "Target platform: Windows Store")
message("Target platform: Universal Windows " ${ARCH} ". SDK Version: " ${CMAKE_SYSTEM_VERSION})
message("Target platform: Universal Windows " ${ARCH} ". Windows SDK Version: " ${WINDOWS_SDK_VERSION})
else()
set(PLATFORM_WIN32 TRUE CACHE INTERNAL "Target platform: Win32") #WIN32 is a variable, so we cannot use string "WIN32"
message("Target platform: Win32 " ${ARCH} ". SDK Version: " ${CMAKE_SYSTEM_VERSION})
message("Target platform: Win32 " ${ARCH} ". Windows SDK Version: " ${WINDOWS_SDK_VERSION})
endif()
else()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
Expand Down Expand Up @@ -141,28 +153,34 @@ endif()

add_library(Diligent-PublicBuildSettings INTERFACE)

if(PLATFORM_WIN32)
if(MSVC)
set(D3D11_SUPPORTED TRUE CACHE INTERNAL "D3D11 is supported on Win32 platform")
if(CMAKE_SYSTEM_VERSION VERSION_GREATER_EQUAL "10.0")
set(D3D12_SUPPORTED TRUE CACHE INTERNAL "D3D12 is supported on Win32 platform")
endif()
if(PLATFORM_WIN32 OR PLATFORM_UNIVERSAL_WINDOWS)
try_compile(HAS_D3D11 "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/BuildTools/CMake/CheckD3D11.cpp")
try_compile(HAS_D3D12 "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/BuildTools/CMake/CheckD3D12.cpp")
try_compile(HAS_ATL "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/BuildTools/CMake/CheckATL.cpp")

if (HAS_D3D11 AND HAS_ATL)
set(D3D11_SUPPORTED TRUE CACHE INTERNAL "D3D11 is supported")
else()
message("Building with MinGW")
set(MINGW_BUILD TRUE CACHE INTERNAL "Building with MinGW")
set(D3D11_SUPPORTED FALSE CACHE INTERNAL "D3D11 requires compiling with MSVC")
set(D3D12_SUPPORTED FALSE CACHE INTERNAL "D3D12 requires compiling with MSVC")
set(D3D11_SUPPORTED FALSE CACHE INTERNAL "D3D11 is not supported")
endif()
if (HAS_D3D12 AND HAS_ATL)
set(D3D12_SUPPORTED TRUE CACHE INTERNAL "D3D12 is supported")
else()
set(D3D12_SUPPORTED FALSE CACHE INTERNAL "D3D12 is not supported")
endif()
endif()

if(${CMAKE_GENERATOR} MATCHES "MinGW")
message("Building with MinGW")
set(MINGW_BUILD TRUE CACHE INTERNAL "Building with MinGW")
endif()

if(PLATFORM_WIN32)
set(GL_SUPPORTED TRUE CACHE INTERNAL "OpenGL is supported on Win32 platform")
set(VULKAN_SUPPORTED TRUE CACHE INTERNAL "Vulkan is supported on Win32 platform")
set(ARCHIVER_SUPPORTED TRUE CACHE INTERNAL "Archiver is supported on Win32 platform")
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_WIN32=1)
elseif(PLATFORM_UNIVERSAL_WINDOWS)
set(D3D11_SUPPORTED TRUE CACHE INTERNAL "D3D11 is supported on Universal Windows platform")
if(CMAKE_SYSTEM_VERSION VERSION_GREATER_EQUAL "10.0")
set(D3D12_SUPPORTED TRUE CACHE INTERNAL "D3D12 is supported on Universal Windows platform")
endif()
set(ARCHIVER_SUPPORTED TRUE CACHE INTERNAL "Archiver is supported on Universal Windows platform")
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_UNIVERSAL_WINDOWS=1)
elseif(PLATFORM_ANDROID)
Expand Down Expand Up @@ -496,7 +514,7 @@ elseif (NOT IS_ABSOLUTE ${CMAKE_INSTALL_PREFIX})
message("Transformed CMAKE_INSTALL_PREFIX into absolute path: " ${CMAKE_INSTALL_PREFIX})
endif()

include(BuildUtils.cmake)
include(BuildTools/CMake/BuildUtils.cmake)

if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
# Find available .NET SDKs
Expand Down
4 changes: 2 additions & 2 deletions Graphics/GraphicsEngineD3DBase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ if(MSVC)

# Note that CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION is stated to be defined when targeting Windows 10
# and above, however it is also defined when targeting 8.1 and Visual Studio 2019 (but not VS2017)
if(CMAKE_SYSTEM_VERSION VERSION_GREATER_EQUAL "10.0")
if("${WINDOWS_SDK_VERSION}" VERSION_GREATER_EQUAL "10.0")
if (DEFINED CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION)
# Note that VS_WINDOWS_SDK_BIN_DIR as well as all derived paths can only be used in Visual Studio
# commands and are not valid paths during CMake configuration
Expand All @@ -94,7 +94,7 @@ if(MSVC)
set(VS_DXIL_SIGNER_PATH "\"${VS_WINDOWS_SDK_BIN_DIR}\\dxil.dll\"" CACHE INTERNAL "dxil.dll path")
endif()
endif()
elseif(CMAKE_SYSTEM_VERSION VERSION_EQUAL "8.1")
elseif("${WINDOWS_SDK_VERSION}" VERSION_EQUAL "8.1")
# D3Dcompiler_47.dll from Win8.1 SDK is ancient (from 2013) and fails to
# compile a number of test shaders. Use the compiler from Visual Studio
# executable path instead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ float4 VerifyResources(uint index, float2 coord)
uint RWStructBuffIdx = index % NUM_RWSTRUCT_BUFFERS;
uint RWFmtBuffIdx = index % NUM_RWFMT_BUFFERS;

#ifdef USE_D3D12_WARP_BUG_WORKAROUND
ConstBuffIdx = 0;
#endif

float4 AllCorrect = float4(1.0, 1.0, 1.0, 1.0);
AllCorrect *= CheckValue(g_Textures[TEXTURES_NONUNIFORM(TexIdx)].SampleLevel(g_Samplers[NonUniformResourceIndex(SamIdx)], coord, 0.0), TexRefValues[TexIdx]);
AllCorrect *= CheckValue(g_ConstantBuffers[CONST_BUFFERS_NONUNIFORM(ConstBuffIdx)].Data, ConstBuffRefValues[ConstBuffIdx]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1808,12 +1808,6 @@ static void TestRunTimeResourceArray(bool IsGLSL, IShaderSourceInputStreamFactor
Macros.AddShaderMacro("RWSTRUCT_BUFFERS_NONUNIFORM_INDEXING", UAVBufferNonUniformIndexing ? 1 : 0);
Macros.AddShaderMacro("RWFMT_BUFFERS_NONUNIFORM_INDEXING", UAVBufferNonUniformIndexing ? 1 : 0);

if (pEnv->NeedWARPResourceArrayIndexingBugWorkaround())
{
// Constant buffer indexing does not work properly in D3D12 WARP - only the 0th element is accessed correctly
Macros.AddShaderMacro("USE_D3D12_WARP_BUG_WORKAROUND", 1);
}

if (IsGLSL)
Macros.AddShaderMacro("float4", "vec4");
for (Uint32 i = 0; i < TexArraySize; ++i)
Expand Down

0 comments on commit 36e7347

Please sign in to comment.