Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,75 @@ 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 <MAJOR.MINOR.PATCH> 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/${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}'")

else()
message("GREX_AGILITY_SDK not supported for non D3D12 platforms")
endif()
endif()

# ------------------------------------------------------------------------------
# Graphics experiments
# ------------------------------------------------------------------------------
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,28 @@ 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.

Using this option will
* 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}`

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(
${PROJECT_NAME}
PUBLIC GREX_USE_AGILITY_SDK
GREX_AGILITY_SDK_VERSION=${GREX_AGILITY_SDK_VERSION}
GREX_AGILITY_SDK_PATH="${GREX_AGILITY_RELATIVE_SDK_PATH}"
)

target_include_directories(${PROJECT_NAME} PUBLIC ${GREX_AGILITY_SDK_INCLUDES})
```
9 changes: 8 additions & 1 deletion projects/common/dx_renderer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#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; }

#endif

bool IsCompressed(DXGI_FORMAT fmt);
bool IsVideo(DXGI_FORMAT fmt);
uint32_t BitsPerPixel(DXGI_FORMAT fmt);
Expand Down Expand Up @@ -2296,4 +2303,4 @@ HRESULT CopyDataToBuffer(size_t dataSize, void* pData, ID3D12Resource* pBuffer)
pBuffer->Unmap(0, nullptr);

return S_OK;
}
}
2 changes: 2 additions & 0 deletions projects/common/dx_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <d3d12.h>
#endif
Expand Down