From 712b4f83ef25c38cabda6f340dfd9ce14da1f93a Mon Sep 17 00:00:00 2001 From: loosche Date: Sun, 27 Oct 2024 20:19:37 -0700 Subject: [PATCH 1/7] Initial Agility SDK Checkin Setup the required exported variables for using the Agility SDK based on the new -DGREX_AGILITY_SDK=X.Y.Z command line parameter. The way to use it is in README.md but does not actually call NuGet to get the package in question, instead giving instructions on what steps you'll need to take in Visual Studio. --- CMakeLists.txt | 38 +++++++++++++++++++++++++++++++++ README.md | 31 +++++++++++++++++++++++++++ projects/common/dx_renderer.cpp | 9 ++++++++ projects/common/dx_renderer.h | 2 ++ 4 files changed, 80 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 90bd7ac4..138c1f98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,6 +197,44 @@ set(IMGUI_INC_DIR ${GREX_THIRD_PARTY_DIR}/imgui) # ------------------------------------------------------------------------------ add_subdirectory(${GREX_THIRD_PARTY_DIR}/meshoptimizer) +# ------------------------------------------------------------------------------ +# Direct3D Agility SDK +# ------------------------------------------------------------------------------ +if (GREX_AGILITY_SDK) + + if (GREX_ENABLE_D3D12) + # Split the version into three parts (major.minor.patch) + string(REGEX MATCHALL "[0-9]+" VERSION_LIST "${GREX_AGILITY_SDK}") + list(LENGTH VERSION_LIST VERSION_LENGTH) + + if (VERSION_LENGTH EQUAL 3) + list(GET VERSION_LIST 1 GREX_AGILITY_SDK_VERSION) + else() + message(FATAL_ERROR "Unknown DirectX Agility SDK Version ${GREX_AGILITY_SDK}. Should be for the SDK version you wish to use") + endif() + + # D3D12SDKPath needs to be a relative path from the binary to the D3D12Core.lib + # you want to use + cmake_path(RELATIVE_PATH CMAKE_BINARY_DIR + BASE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} + OUTPUT_VARIABLE BIN_TO_BUILD_PATH) + + + # We need the extra leading ../ to deal with the sub-directory for the build format (Debug/Release/etc ...) + set(GREX_AGILITY_RELATIVE_SDK_PATH "../${BIN_TO_BUILD_PATH}/packages/Microsoft.Direct3D.D3D12.${GREX_AGILITY_SDK}/build/native/bin/x64") + + # Output the results on the command line during build + message("Generating DirectX Agility SDK Export Symbols:") + message(" D3D12SDKVersion: ${GREX_AGILITY_SDK_VERSION}") + message(" D3D12SDKPath: '${GREX_AGILITY_RELATIVE_SDK_PATH}'") + message(" NuGet PM: NuGet\\Install-Package Microsoft.Direct3D.D3D12 -Version ${GREX_AGILITY_SDK}") + message("") + + else() + message("GREX_AGILITY_SDK not supported for non D3D12 platforms") + endif() +endif() + # ------------------------------------------------------------------------------ # Graphics experiments # ------------------------------------------------------------------------------ diff --git a/README.md b/README.md index a77ada91..2f15f7c9 100644 --- a/README.md +++ b/README.md @@ -67,3 +67,34 @@ cmake -B build-vs2022 ``` This will generate a solution for Visual Studio 2022 Professional in the `build-vs2022` directory. +### Direct3D Agility SDK + +You can specify what Agility SDK you want to use with the command `-DGREX_AGILITY_SDK=X.Y.Z` where `X.Y.Z` is the version of the Agility SDK you want to use. + +It will generate the following symbols that can be used by individual projects +* ${GREX_AGILITY_SDK_VERSION} +* ${GREX_AGILITY_RELATIVE_SDK_PATH} + +You can enable the specified Agility SDK in your project by adding the following to a project's CMakeLists.txt file + +``` +target_compile_definitions( + MyTargetName + PUBLIC + GREX_USE_AGILITY_SDK + GREX_AGILITY_SDK_VERSION=${GREX_AGILITY_SDK_VERSION} + GREX_AGILITY_SDK_PATH="${GREX_AGILITY_RELATIVE_SDK_PATH}" +) +``` + +Currently the `VS_PACKAGE_REFERENCES()` is not used to actually download/setup the NuGet file as it doesn't seem to work +for C++ projects. However, the cmake process should print out the command you'll need to use in the Nuget Package +Manager Console in Visual Studio (Tools -> NuGet Package Manager -> Package Manager Console). + +``` +NuGet\Install-Package Microsoft.Direct3D.D3D12 -Version X.Y.Z +``` + +Which will download the package to the `build/packages/...` directory and setup your project to use it. + + diff --git a/projects/common/dx_renderer.cpp b/projects/common/dx_renderer.cpp index 6686c77f..19e6a206 100644 --- a/projects/common/dx_renderer.cpp +++ b/projects/common/dx_renderer.cpp @@ -1,5 +1,13 @@ #include "dx_renderer.h" +#if defined(GREX_USE_AGILITY_SDK) + + extern "C" { __declspec(dllexport) extern const UINT D3D12SDKVersion = GREX_AGILITY_SDK_VERSION; } + extern "C" { __declspec(dllexport) extern const char* D3D12SDKPath = GREX_AGILITY_SDK_PATH; } + // extern "C" { __declspec(dllexport) extern const char* D3D12SDKPath = "../../third_party/DirectX-AgilitySDK/1.614.1/bin/x64"; } + +#endif + bool IsCompressed(DXGI_FORMAT fmt); bool IsVideo(DXGI_FORMAT fmt); uint32_t BitsPerPixel(DXGI_FORMAT fmt); @@ -106,6 +114,7 @@ bool InitDx(DxRenderer* pRenderer, bool enableDebug) // Filter out remote and software adapters if (desc.Flags == DXGI_ADAPTER_FLAG_NONE) + //if (desc.Flags == DXGI_ADAPTER_FLAG_SOFTWARE) { adapters.push_back(pEnumeratedAdapter); } diff --git a/projects/common/dx_renderer.h b/projects/common/dx_renderer.h index 0cc72681..b965d795 100644 --- a/projects/common/dx_renderer.h +++ b/projects/common/dx_renderer.h @@ -4,6 +4,8 @@ #if defined(GREX_USE_D3DX12) #include "directx/d3dx12.h" +#elif defined(GREX_USE_AGILITY_SDK) +#include "d3dx12/d3dx12.h" #else #include #endif From 618c7bc397f6dfc64a981373a3c1806b3c125f1a Mon Sep 17 00:00:00 2001 From: loosche Date: Sun, 27 Oct 2024 20:22:59 -0700 Subject: [PATCH 2/7] Fix typo in dx_renderer.cpp that got checked in --- projects/common/dx_renderer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/projects/common/dx_renderer.cpp b/projects/common/dx_renderer.cpp index 19e6a206..74c68cbb 100644 --- a/projects/common/dx_renderer.cpp +++ b/projects/common/dx_renderer.cpp @@ -114,7 +114,6 @@ bool InitDx(DxRenderer* pRenderer, bool enableDebug) // Filter out remote and software adapters if (desc.Flags == DXGI_ADAPTER_FLAG_NONE) - //if (desc.Flags == DXGI_ADAPTER_FLAG_SOFTWARE) { adapters.push_back(pEnumeratedAdapter); } From aacffc9dfc97f769ce1bb2084cb8c88135be351e Mon Sep 17 00:00:00 2001 From: loosche Date: Sun, 27 Oct 2024 20:24:26 -0700 Subject: [PATCH 3/7] Fix typo in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2f15f7c9..27a5d30b 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ target_compile_definitions( Currently the `VS_PACKAGE_REFERENCES()` is not used to actually download/setup the NuGet file as it doesn't seem to work for C++ projects. However, the cmake process should print out the command you'll need to use in the Nuget Package -Manager Console in Visual Studio (Tools -> NuGet Package Manager -> Package Manager Console). +Manager Console in Visual Studio (*Tools -> NuGet Package Manager -> Package Manager Console*). ``` NuGet\Install-Package Microsoft.Direct3D.D3D12 -Version X.Y.Z From fc22cef2eb9bab52034c646ea9934e4311932252 Mon Sep 17 00:00:00 2001 From: loosche Date: Sat, 2 Nov 2024 21:55:44 -0700 Subject: [PATCH 4/7] Change CMake to download nuget.exe and install Agility SDK packages --- CMakeLists.txt | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 138c1f98..8b3063ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -213,22 +213,53 @@ if (GREX_AGILITY_SDK) message(FATAL_ERROR "Unknown DirectX Agility SDK Version ${GREX_AGILITY_SDK}. Should be for the SDK version you wish to use") endif() + set(GREX_AGILITY_SDK_NAME "Microsoft.Direct3D.D3D12") + set(GREX_AGILITY_SDK_PACKAGE_LOCATION ${CMAKE_BINARY_DIR}/packages/${GREX_AGILITY_SDK_NAME}.${GREX_AGILITY_SDK}) + + # Install nuget if we don't have it + set(GREX_NUGET_WEB_ADDRESS "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe") + set(GREX_NUGET_EXE ${CMAKE_BINARY_DIR}/bin/nuget.exe) + + if (NOT EXISTS ${GREX_NUGET_EXE}) + message(CHECK_START "Downloading nuget.exe") + file(DOWNLOAD ${GREX_NUGET_WEB_ADDRESS} ${GREX_NUGET_EXE} STATUS GREX_NUGET_DOWNLOAD_STATUS) + + list(GET GREX_NUGET_DOWNLOAD_STATUS 0 GREX_NUGET_DOWNLOAD_ERROR_CODE) + list(GET GREX_NUGET_DOWNLOAD_STATUS 1 GREX_NUGET_DOWNLOAD_ERROR_STRING) + if (${GREX_NUGET_DOWNLOAD_ERROR_CODE} EQUAL 0) + message(CHECK_PASS "downloaded") + else() + file(REMOVE ${GREX_NUGET_EXE}) + message(CHECK_FAIL "not downloaded") + message(FATAL_ERROR "'${GREX_NUGET_WEB_ADDRESS}' not found (${GREX_NUGET_DOWNLOAD_ERROR_CODE}) ${GREX_NUGET_DOWNLOAD_ERROR_STRING}") + + endif() + endif() + + # Install the DirectX Agility SDK if we don't have it + if (NOT EXISTS ${GREX_AGILITY_SDK_PACKAGE_LOCATION}) + message(CHECK_START "Attempting to nuget install ${GREX_AGILITY_SDK_NAME} Ver: ${GREX_AGILITY_SDK}") + execute_process( + COMMAND "${GREX_NUGET_EXE}" install ${GREX_AGILITY_SDK_NAME} -Version ${GREX_AGILITY_SDK} -OutputDirectory ${CMAKE_BINARY_DIR}/packages + OUTPUT_QUIET + COMMAND_ERROR_IS_FATAL ANY) + message(CHECK_PASS "installed") + endif() + # D3D12SDKPath needs to be a relative path from the binary to the D3D12Core.lib # you want to use cmake_path(RELATIVE_PATH CMAKE_BINARY_DIR BASE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} OUTPUT_VARIABLE BIN_TO_BUILD_PATH) - # We need the extra leading ../ to deal with the sub-directory for the build format (Debug/Release/etc ...) - set(GREX_AGILITY_RELATIVE_SDK_PATH "../${BIN_TO_BUILD_PATH}/packages/Microsoft.Direct3D.D3D12.${GREX_AGILITY_SDK}/build/native/bin/x64") + set(GREX_AGILITY_RELATIVE_SDK_PATH "../${BIN_TO_BUILD_PATH}/packages/${GREX_AGILITY_SDK_NAME}.${GREX_AGILITY_SDK}/build/native/bin/x64") + set(GREX_AGILITY_SDK_INCLUDES "${CMAKE_BINARY_DIR}/packages/${GREX_AGILITY_SDK_NAME}.${GREX_AGILITY_SDK}/build/native/include") # Output the results on the command line during build - message("Generating DirectX Agility SDK Export Symbols:") - message(" D3D12SDKVersion: ${GREX_AGILITY_SDK_VERSION}") - message(" D3D12SDKPath: '${GREX_AGILITY_RELATIVE_SDK_PATH}'") - message(" NuGet PM: NuGet\\Install-Package Microsoft.Direct3D.D3D12 -Version ${GREX_AGILITY_SDK}") - message("") + message(" Generating DirectX Agility SDK Export Symbols:") + message(" D3D12SDKVersion: ${GREX_AGILITY_SDK_VERSION}") + message(" D3D12SDKPath: '${GREX_AGILITY_RELATIVE_SDK_PATH}'") else() message("GREX_AGILITY_SDK not supported for non D3D12 platforms") From 4d766e09671d7aba5452cb82e9552d5bbfba3870 Mon Sep 17 00:00:00 2001 From: loosche Date: Sat, 2 Nov 2024 22:05:07 -0700 Subject: [PATCH 5/7] Update the README.md file --- README.md | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 27a5d30b..8713b34f 100644 --- a/README.md +++ b/README.md @@ -69,32 +69,26 @@ This will generate a solution for Visual Studio 2022 Professional in the `build- ### Direct3D Agility SDK -You can specify what Agility SDK you want to use with the command `-DGREX_AGILITY_SDK=X.Y.Z` where `X.Y.Z` is the version of the Agility SDK you want to use. +You can specify what Agility SDK you want to use with the command `-DGREX_AGILITY_SDK=X.Y.Z` where `X.Y.Z` is the version of the Agility SDK you want to use. -It will generate the following symbols that can be used by individual projects +Using this option will +* Download nuget.exe to /bin/nuget.exe +* Download the desired Agility SDK to /packages/... which is what the NuGet Package Manager would do for you in Visual Studio +* Create a global variable that points to the include directory for the Agility SDK: ${GREX_AGILITY_SDK_INCLUDES} + +It will also generate the following symbols that can then be used by individual projects * ${GREX_AGILITY_SDK_VERSION} * ${GREX_AGILITY_RELATIVE_SDK_PATH} -You can enable the specified Agility SDK in your project by adding the following to a project's CMakeLists.txt file +You can enable the specified Agility SDK in your project's CMakeLists.txt file by adding the following to a project's CMakeLists.txt file ``` target_compile_definitions( - MyTargetName - PUBLIC - GREX_USE_AGILITY_SDK - GREX_AGILITY_SDK_VERSION=${GREX_AGILITY_SDK_VERSION} - GREX_AGILITY_SDK_PATH="${GREX_AGILITY_RELATIVE_SDK_PATH}" + ${PROJECT_NAME} + PUBLIC GREX_USE_AGILITY_SDK + GREX_AGILITY_SDK_VERSION=${GREX_AGILITY_SDK_VERSION} + GREX_AGILITY_SDK_PATH="${GREX_AGILITY_RELATIVE_SDK_PATH}" ) -``` -Currently the `VS_PACKAGE_REFERENCES()` is not used to actually download/setup the NuGet file as it doesn't seem to work -for C++ projects. However, the cmake process should print out the command you'll need to use in the Nuget Package -Manager Console in Visual Studio (*Tools -> NuGet Package Manager -> Package Manager Console*). - -``` -NuGet\Install-Package Microsoft.Direct3D.D3D12 -Version X.Y.Z +target_include_directories(${PROJECT_NAME} PUBLIC ${GREX_AGILITY_SDK_INCLUDES}) ``` - -Which will download the package to the `build/packages/...` directory and setup your project to use it. - - From 514fe768781cf049ed908f4b0bf9d6326147a2a8 Mon Sep 17 00:00:00 2001 From: loosche Date: Sat, 2 Nov 2024 22:07:46 -0700 Subject: [PATCH 6/7] Readme updates --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8713b34f..a1ba1cb2 100644 --- a/README.md +++ b/README.md @@ -72,13 +72,13 @@ This will generate a solution for Visual Studio 2022 Professional in the `build- You can specify what Agility SDK you want to use with the command `-DGREX_AGILITY_SDK=X.Y.Z` where `X.Y.Z` is the version of the Agility SDK you want to use. Using this option will -* Download nuget.exe to /bin/nuget.exe -* Download the desired Agility SDK to /packages/... which is what the NuGet Package Manager would do for you in Visual Studio -* Create a global variable that points to the include directory for the Agility SDK: ${GREX_AGILITY_SDK_INCLUDES} +* Download nuget.exe to `BUILD DIRECTORY/bin/nuget.exe` +* Download the desired Agility SDK to `BUILD DIRECTORY/packages/...` which is what the NuGet Package Manager would do for you in Visual Studio +* Create a global variable that points to the include directory for the Agility SDK: `${GREX_AGILITY_SDK_INCLUDES}` It will also generate the following symbols that can then be used by individual projects -* ${GREX_AGILITY_SDK_VERSION} -* ${GREX_AGILITY_RELATIVE_SDK_PATH} +* `${GREX_AGILITY_SDK_VERSION}` +* `${GREX_AGILITY_RELATIVE_SDK_PATH}` You can enable the specified Agility SDK in your project's CMakeLists.txt file by adding the following to a project's CMakeLists.txt file From 66804cd0a7dd629d5aa2ffa8e24b51b9d825b2ed Mon Sep 17 00:00:00 2001 From: loosche Date: Sat, 2 Nov 2024 22:15:37 -0700 Subject: [PATCH 7/7] Remove commented out line of code --- projects/common/dx_renderer.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/projects/common/dx_renderer.cpp b/projects/common/dx_renderer.cpp index 74c68cbb..2e5313ce 100644 --- a/projects/common/dx_renderer.cpp +++ b/projects/common/dx_renderer.cpp @@ -4,7 +4,6 @@ extern "C" { __declspec(dllexport) extern const UINT D3D12SDKVersion = GREX_AGILITY_SDK_VERSION; } extern "C" { __declspec(dllexport) extern const char* D3D12SDKPath = GREX_AGILITY_SDK_PATH; } - // extern "C" { __declspec(dllexport) extern const char* D3D12SDKPath = "../../third_party/DirectX-AgilitySDK/1.614.1/bin/x64"; } #endif @@ -2304,4 +2303,4 @@ HRESULT CopyDataToBuffer(size_t dataSize, void* pData, ID3D12Resource* pBuffer) pBuffer->Unmap(0, nullptr); return S_OK; -} \ No newline at end of file +}