From 6adc26f2d2ca61d6f9204c00d750496c1a332bb8 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Fri, 11 Oct 2024 19:36:15 -0700 Subject: [PATCH] CMake support for using latest WARP and D3D12 (#42) --- .github/dependabot.yml | 2 +- CMakeLists.txt | 65 ++++++++++++++++++++++++++++++++++++++++-- CMakePresets.json | 22 ++++++++++---- dxgi.cpp | 32 ++++++++++++++++++--- 4 files changed, 108 insertions(+), 13 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 253bcb7..ca79ca5 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -3,4 +3,4 @@ updates: - package-ecosystem: github-actions directory: / schedule: - interval: daily + interval: weekly diff --git a/CMakeLists.txt b/CMakeLists.txt index 4125ae1..5ad835c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -cmake_minimum_required (VERSION 3.20) +cmake_minimum_required (VERSION 3.21) project (dxcapsviewer DESCRIPTION "DirectX Capabilities Viewer" @@ -10,6 +10,12 @@ project (dxcapsviewer option(ENABLE_CODE_ANALYSIS "Use Static Code Analysis on build" OFF) +option(BUILD_WITH_NEW_WARP "Use the WARP package on NuGet" OFF) +set(DIRECTX_WARP_VERSION 1.0.13) + +option(BUILD_WITH_NEW_DX12 "Use the DirectX 12 Agility SDK Binaries" OFF) +set(DIRECTX_DX12_VERSION 1.614.1) + set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) @@ -59,7 +65,7 @@ find_package(directx-headers CONFIG QUIET) if(directx-headers_FOUND) message(STATUS "Using DirectX-Headers package") target_link_libraries(${PROJECT_NAME} PRIVATE Microsoft::DirectX-Headers) - target_compile_definitions(${PROJECT_NAME} PRIVATE USING_DIRECTX_HEADERS USING_D3D12_AGILITY_SDK) + target_compile_definitions(${PROJECT_NAME} PRIVATE USING_DIRECTX_HEADERS) endif() if(MSVC) @@ -141,3 +147,58 @@ endif() set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME}) install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + +if(WIN32) + if(${DIRECTX_ARCH} STREQUAL "x86") + set(NUGET_ARCH win32) + else() + set(NUGET_ARCH ${DIRECTX_ARCH}) + endif() + + if(BUILD_WITH_NEW_WARP) + message(STATUS "Downloading Microsoft.Direct3D.WARP...") + set(DIRECTX_WARP_ARCHIVE "${CMAKE_BINARY_DIR}/Microsoft.Direct3D.WARP.${DIRECTX_WARP_VERSION}.zip") + file(DOWNLOAD "https://www.nuget.org/api/v2/package/Microsoft.Direct3D.WARP/${DIRECTX_WARP_VERSION}/" + ${DIRECTX_WARP_ARCHIVE} + EXPECTED_HASH SHA512=9f5e480947cbdd433f46ffd1a00805db5b8545938867c4a2becf1b49d85dd58234914c45caf3b84686dfd642e9d655f1df56d05a065f5ddc551bf6f1aed58162 + ) + + file(ARCHIVE_EXTRACT INPUT ${DIRECTX_WARP_ARCHIVE} DESTINATION "${CMAKE_BINARY_DIR}/temp" PATTERNS *${NUGET_ARCH}*dll *${NUGET_ARCH}*pdb) + + file(GLOB_RECURSE DXBINS "${CMAKE_BINARY_DIR}/temp/*.dll" $,"${CMAKE_BINARY_DIR}/temp/*.pdb">) + + file(MAKE_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") + + foreach(FILE ${DXBINS}) + get_filename_component(FILENAME ${FILE} NAME) + file(COPY_FILE ${FILE} "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${FILENAME}") + endforeach(FILE) + + file(REMOVE_RECURSE "${CMAKE_BINARY_DIR}/temp") + endif() + + if (BUILD_WITH_NEW_DX12) + target_compile_definitions(${PROJECT_NAME} PRIVATE USING_D3D12_AGILITY_SDK) + + message(STATUS "Downloading Microsoft.Direct3D.D3D12...") + set(DIRECTX_DX12_ARCHIVE "${CMAKE_BINARY_DIR}/Microsoft.Direct3D.D3D12.${DIRECTX_DX12_VERSION}.zip") + file(DOWNLOAD "https://www.nuget.org/api/v2/package/Microsoft.Direct3D.D3D12/${DIRECTX_DX12_VERSION}/" + ${DIRECTX_DX12_ARCHIVE} + EXPECTED_HASH SHA512=05baa55231684ab10a3e905c9b85ce78f04ade9360f7de84a06bbae3bfc3123bcccaa563647a25e151cc759106bc19e37740ef78563592d28e3a723fd744b42f + ) + + file(ARCHIVE_EXTRACT INPUT ${DIRECTX_DX12_ARCHIVE} DESTINATION "${CMAKE_BINARY_DIR}/temp" PATTERNS *${NUGET_ARCH}*dll *${NUGET_ARCH}*exe *${NUGET_ARCH}*pdb) + + file(GLOB_RECURSE DXBINS "${CMAKE_BINARY_DIR}/temp/*.dll" "${CMAKE_BINARY_DIR}/temp/*.exe" $,"${CMAKE_BINARY_DIR}/temp/*.pdb">) + + file(MAKE_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/D3D12") + + foreach(FILE ${DXBINS}) + get_filename_component(FILENAME ${FILE} NAME) + file(COPY_FILE ${FILE} "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/D3D12//${FILENAME}") + endforeach(FILE) + + file(REMOVE_RECURSE "${CMAKE_BINARY_DIR}/temp") + endif() +endif() diff --git a/CMakePresets.json b/CMakePresets.json index ca1c90a..5467d69 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -82,6 +82,14 @@ } }, + { + "name": "NuGet", + "cacheVariables": { + "BUILD_WITH_NEW_WARP": true, + "BUILD_WITH_NEW_DX12": true + }, + "hidden": true + }, { "name": "VCPKG", "cacheVariables": { @@ -102,11 +110,11 @@ { "name": "arm64ec-Debug" , "description": "MSVC for ARM64EC (Debug)", "inherits": [ "base", "ARM64EC", "Debug", "MSVC" ], "environment": { "CXXFLAGS": "/arm64EC" } }, { "name": "arm64ec-Release", "description": "MSVC for ARM64EC (Release)", "inherits": [ "base", "ARM64EC", "Release", "MSVC" ], "environment": { "CXXFLAGS": "/arm64EC" } }, - { "name": "x64-Debug-VCPKG" , "description": "MSVC for x64 (Debug)", "inherits": [ "base", "x64", "Debug", "MSVC", "VCPKG" ] }, - { "name": "x64-Release-VCPKG" , "description": "MSVC for x64 (Release)", "inherits": [ "base", "x64", "Release", "MSVC", "VCPKG" ] }, - { "name": "x86-Debug-VCPKG" , "description": "MSVC for x86 (Debug)", "inherits": [ "base", "x86", "Debug", "MSVC", "VCPKG" ] }, - { "name": "x86-Release-VCPKG" , "description": "MSVC for x86 (Release)", "inherits": [ "base", "x86", "Release", "MSVC", "VCPKG" ] }, - { "name": "arm64-Debug-VCPKG" , "description": "MSVC for ARM64 (Debug)", "inherits": [ "base", "ARM64", "Debug", "MSVC", "VCPKG" ] }, + { "name": "x64-Debug-VCPKG" , "description": "MSVC for x64 (Debug)", "inherits": [ "base", "x64", "Debug", "MSVC", "VCPKG", "NuGet" ] }, + { "name": "x64-Release-VCPKG" , "description": "MSVC for x64 (Release)", "inherits": [ "base", "x64", "Release", "MSVC", "VCPKG", "NuGet" ] }, + { "name": "x86-Debug-VCPKG" , "description": "MSVC for x86 (Debug)", "inherits": [ "base", "x86", "Debug", "MSVC", "VCPKG", "NuGet" ] }, + { "name": "x86-Release-VCPKG" , "description": "MSVC for x86 (Release)", "inherits": [ "base", "x86", "Release", "MSVC", "VCPKG", "NuGet" ] }, + { "name": "arm64-Debug-VCPKG" , "description": "MSVC for ARM64 (Debug)", "inherits": [ "base", "ARM64", "Debug", "MSVC", "VCPKG", "NuGet" ] }, { "name": "arm64-Release-VCPKG", "description": "MSVC for ARM64 (Release)", "inherits": [ "base", "ARM64", "Release", "MSVC", "VCPKG" ] }, { "name": "arm64ec-Debug-VCPKG" , "description": "MSVC for ARM64EC (Debug)", "inherits": [ "base", "ARM64EC", "Debug", "MSVC", "VCPKG" ], "environment": { "CXXFLAGS": "/arm64EC" }, "cacheVariables": { "VCPKG_TARGET_TRIPLET": "arm64ec-windows" } }, { "name": "arm64ec-Release-VCPKG", "description": "MSVC for ARM64EC (Release)", "inherits": [ "base", "ARM64EC", "Release", "MSVC", "VCPKG" ], "environment": { "CXXFLAGS": "/arm64EC" }, "cacheVariables": { "VCPKG_TARGET_TRIPLET": "arm64ec-windows" } }, @@ -123,6 +131,8 @@ { "name": "x86-Debug-Clang-VCPKG" , "description": "Clang/LLVM for x86 (Debug)", "inherits": [ "base", "x86", "Debug", "Clang", "VCPKG" ], "environment": { "CXXFLAGS": "-m32" } }, { "name": "x86-Release-Clang-VCPKG" , "description": "Clang/LLVM for x86 (Release)", "inherits": [ "base", "x86", "Release", "Clang", "VCPKG" ], "environment": { "CXXFLAGS": "-m32" } }, { "name": "arm64-Debug-Clang-VCPKG" , "description": "Clang/LLVM for AArch64 (Debug)", "inherits": [ "base", "ARM64", "Debug", "Clang", "VCPKG" ], "environment": { "CXXFLAGS": "--target=arm64-pc-windows-msvc" } }, - { "name": "arm64-Release-Clang-VCPKG", "description": "Clang/LLVM for AArch64 (Release)", "inherits": [ "base", "ARM64", "Release", "Clang", "VCPKG" ], "environment": { "CXXFLAGS": "--target=arm64-pc-windows-msvc" } } + { "name": "arm64-Release-Clang-VCPKG", "description": "Clang/LLVM for AArch64 (Release)", "inherits": [ "base", "ARM64", "Release", "Clang", "VCPKG" ], "environment": { "CXXFLAGS": "--target=arm64-pc-windows-msvc" } }, + + { "name": "x64-Analyze" , "description": "MSVC for x64 (Debug) using /analyze", "inherits": [ "base", "x64", "Debug", "MSVC" ], "cacheVariables": { "ENABLE_CODE_ANALYSIS": true } } ] } \ No newline at end of file diff --git a/dxgi.cpp b/dxgi.cpp index 19c267e..61d139e 100644 --- a/dxgi.cpp +++ b/dxgi.cpp @@ -25,6 +25,15 @@ // Define for some debug output //#define EXTRA_DEBUG +#ifdef USING_D3D12_AGILITY_SDK +extern "C" +{ + // Used to enable the "Agility SDK" components + __declspec(dllexport) extern const UINT D3D12SDKVersion = D3D12_SDK_VERSION; + __declspec(dllexport) extern const char* D3D12SDKPath = u8".\\D3D12\\"; +} +#endif + //----------------------------------------------------------------------------- // This mask is only needed for Direct3D 10.x/11 where some devices had 'holes' in the feature support. @@ -4514,6 +4523,17 @@ namespace auto d3d12opts16 = GetD3D12Options(pDevice); #endif +#if defined(NTDDI_WIN11_GE) || defined(USING_D3D12_AGILITY_SDK) + auto d3d12opts17 = GetD3D12Options(pDevice); + auto d3d12opts18 = GetD3D12Options(pDevice); + auto d3d12opts19 = GetD3D12Options(pDevice); + auto d3d12opts20 = GetD3D12Options(pDevice); +#endif + +#if defined(NTDDI_WIN11_DT) || defined(USING_D3D12_AGILITY_SDK) + auto d3d12opts21 = GetD3D12Options(pDevice); +#endif + if (!pPrintInfo) { LVLINE("Feature Level", FLName(fl)); @@ -4570,10 +4590,12 @@ namespace LVYESNO("Triangle fans primitives", d3d12opts15.TriangleFanSupported); LVYESNO("Dynamic IB strip-cut support", d3d12opts15.DynamicIndexBufferStripCutSupported); LVYESNO("Dynamic depth bias support", d3d12opts16.DynamicDepthBiasSupported); + LVYESNO("GPU upload heap support", d3d12opts16.GPUUploadHeapSupported); #endif -#if defined(NTDDI_WIN10_CU) - LVYESNO("GPU upload heap support", d3d12opts16.GPUUploadHeapSupported); +#if defined(NTDDI_WIN11_GE) || defined(USING_D3D12_AGILITY_SDK) + LVYESNO("Non-normalized coordinate samplers", d3d12opts17.NonNormalizedCoordinateSamplersSupported); + LVYESNO("Manual write tracking res", d3d12opts17.ManualWriteTrackingResourceSupported); #endif } else @@ -4632,10 +4654,12 @@ namespace PRINTYESNO("Triangle fan primitives", d3d12opts15.TriangleFanSupported); PRINTYESNO("Dynamic IB strip-cut support", d3d12opts15.DynamicIndexBufferStripCutSupported); PRINTYESNO("Dynamic depth bias support", d3d12opts16.DynamicDepthBiasSupported); + PRINTYESNO("GPU upload heap support", d3d12opts16.GPUUploadHeapSupported); #endif -#if defined(NTDDI_WIN10_CU) - PRINTYESNO("GPU upload heap support", d3d12opts16.GPUUploadHeapSupported); +#if defined(NTDDI_WIN11_GE) || defined(USING_D3D12_AGILITY_SDK) + PRINTYESNO("Non-normalized coordinate samplers", d3d12opts17.NonNormalizedCoordinateSamplersSupported); + PRINTYESNO("Manual write tracking res", d3d12opts17.ManualWriteTrackingResourceSupported); #endif }