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
47 changes: 22 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,38 +38,32 @@ set(GAME_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Game/source")
set(GAME_INC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Game/include")
set(ASSET_DIR "${CMAKE_CURRENT_SOURCE_DIR}/assets")
# DirectX 12 Agility SDK
# set(AGILITY_SDK_VERSION "1.618.4")
# Turn on/off DirectX 12 Agility SDK Preview Version
option(USE_PREVIEW_SDK "Enable DirectX 12 Agility SDK Preview Version (715)" OFF)
if(USE_PREVIEW_SDK)
# DirectX 12 Agility SDK 1.715.0-preview or later is required for Mesh Nodes
set(AGILITY_SDK_VERSION "1.717.0-preview")
set(AGILITY_SDK_VERSION "1.715.0-preview")
add_compile_definitions(USE_PREVIEW_SDK=1)
else()
set(AGILITY_SDK_VERSION "1.618.4")
add_compile_definitions(USE_PREVIEW_SDK=0)
endif()

# CMAKE_BINARY_DIR is used to locate directory where files are built
set(NUGET_PACKAGES_ROOT "${CMAKE_BINARY_DIR}/packages")
set(AGILITY_SDK_PATH "${NUGET_PACKAGES_ROOT}/Microsoft.Direct3D.D3D12.${AGILITY_SDK_VERSION}")
set(AGILITY_SDK_INCLUDE_DIR "${AGILITY_SDK_PATH}/build/native/include")
set(AGILITY_SDK_BIN_DIR "${AGILITY_SDK_PATH}/build/native/bin/x64")
# set(NUGET_PACKAGES_DIR "${CMAKE_BINARY_DIR}/packages/Microsoft.Direct3D.D3D12.${AGILITY_SDK_VERSION}")
# set(D3D12_CORE_DLL "${NUGET_PACKAGES_DIR}/build/native/bin/x64/D3D12Core.dll")
# set(D3D12_LAYERS_DLL "${NUGET_PACKAGES_DIR}/build/native/bin/x64/D3D12SDKLayers.dll")
# add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:${PROJECT_NAME}>/D3D12"
# COMMAND ${CMAKE_COMMAND} -E copy_if_different
# "${D3D12_CORE_DLL}"
# "$<TARGET_FILE_DIR:${PROJECT_NAME}>/D3D12/"
# COMMAND ${CMAKE_COMMAND} -E copy_if_different
# "${D3D12_LAYERS_DLL}"
# "$<TARGET_FILE_DIR:${PROJECT_NAME}>/D3D12/"
# COMMENT "Copying Agility SDK DLLs to .exe/D3D12 folder..."
# )

# Copy packages.config to build folder for NuGet package restore (for DirectX 12 Agility SDK)
configure_file(packages.config ${CMAKE_CURRENT_BINARY_DIR}/packages.config COPYONLY)
# configure_file(packages.config ${CMAKE_CURRENT_BINARY_DIR}/packages.config COPYONLY)

set(NUGET_EXE "${CMAKE_CURRENT_SOURCE_DIR}/nuget.exe")
if (NOT EXISTS "${NUGET_EXE}")
message(FATAL_ERROR "nuget.exe not found at ${NUGET_EXE}. Please download it from https://www.nuget.org/downloads and place it in the project root directory.")
endif()

message(STATUS "Installing NuGet packages...")

execute_process(
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/nuget.exe install ${CMAKE_CURRENT_BINARY_DIR}/packages.config -OutputDirectory ${NUGET_PACKAGES_ROOT} -Version ${AGILITY_SDK_VERSION}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/nuget.exe install Microsoft.Direct3D.D3D12 -OutputDirectory ${NUGET_PACKAGES_ROOT} -Version ${AGILITY_SDK_VERSION}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
RESULT_VARIABLE NUGET_RESULT
)
Expand All @@ -78,6 +72,9 @@ if (NOT NUGET_RESULT EQUAL 0)
message(FATAL_ERROR "NuGet restore failed. Please ensure 'nuget.exe' is in your PATH.")
endif()

set(AGILITY_SDK_BIN_DIR "${NUGET_PACKAGES_ROOT}/Microsoft.Direct3D.D3D12.${AGILITY_SDK_VERSION}/build/native/bin/x64")
set(AGILITY_SDK_INCLUDE_DIR "${NUGET_PACKAGES_ROOT}/Microsoft.Direct3D.D3D12.${AGILITY_SDK_VERSION}/build/native/include")

# Subdirectories
# common_gl
add_subdirectory(${GL_DIR})
Expand Down Expand Up @@ -134,13 +131,12 @@ add_executable(${PROJECT_NAME} main.cpp ${DEBUG_TOOLS_SRC} ${ENGINE_SRC} ${GAME_

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:${PROJECT_NAME}>/D3D12"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${AGILITY_SDK_BIN_DIR}/D3D12Core.dll"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${AGILITY_SDK_BIN_DIR}/D3D12Core.dll"
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/D3D12/"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${AGILITY_SDK_BIN_DIR}/D3D12SDKLayers.dll"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${AGILITY_SDK_BIN_DIR}/D3D12SDKLayers.dll"
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/D3D12/"
COMMENT "Copying Agility SDK DLLs to .exe/D3D12 folder..."
)

source_group("DebugTools" FILES ${DEBUG_TOOLS_SRC})
Expand Down Expand Up @@ -196,6 +192,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE optimized ${FFX_INC_DIR}/../bin/ff
target_link_libraries(${PROJECT_NAME} PRIVATE opengl32)

# Include Directories
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${AGILITY_SDK_INCLUDE_DIR})
target_include_directories(${PROJECT_NAME} PRIVATE ${GL_DIR}/include)
target_include_directories(${PROJECT_NAME} PRIVATE ${VK_DIR}/include)
target_include_directories(${PROJECT_NAME} PRIVATE ${DX_DIR}/include)
Expand Down
5 changes: 5 additions & 0 deletions Engine/common_dx/include/DXHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <wrl.h>
#include <vector>
#include <filesystem>
// For CompileShader
//#include <d3dcommon.h>

#include "DebugTools.hpp"

Expand Down Expand Up @@ -35,4 +37,7 @@ namespace DXHelper

// Read in precompiled shader
std::vector<char> ReadShaderFile(const std::filesystem::path& path);

// @TODO AI-Generated: Review shader compilation function
//ID3DBlob* CompileShader(const std::string& shaderCode, const wchar_t* entryPoint, const wchar_t* targetProfile);
}
13 changes: 12 additions & 1 deletion Engine/common_dx/include/DXWorkGraphsStateObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,20 @@ class DXWorkGraphsStateObject
const std::filesystem::path& nodePath,
const wchar_t* workGraphName
);
#if USE_PREVIEW_SDK
DXWorkGraphsStateObject(
const ComPtr<ID3D12Device14>& device,
//const ComPtr<ID3D12RootSignature>& rootSignature,
const std::filesystem::path& nodePath,
const std::filesystem::path& pixelPath,
const DXGI_FORMAT& depthFormat,
const DXGI_FORMAT& renderTargetFormat,
const wchar_t* workGraphName
);
#endif
~DXWorkGraphsStateObject() = default;

D3D12_SET_PROGRAM_DESC GetProgramDesc();
D3D12_SET_PROGRAM_DESC GetProgramDesc() const;
ID3D12RootSignature* GetGlobalRootSignature() const { return m_rootSignature.Get(); }
//UINT GetWorkGraphIndex() const { return m_workGraphIndex; }
UINT GetEntrypointIndex(LPCWSTR nodeName);
Expand Down
126 changes: 126 additions & 0 deletions Engine/common_dx/source/DXHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
#include <d3dx12/d3dx12_core.h>
#include <stdexcept>
#include <fstream>
// For CompileShader
//#include <dxcapi.h>

#include <conio.h>
#define ERROR_QUIT(value, ...) if(!(value)) { printf("ERROR: "); printf(__VA_ARGS__); printf("\nPress any key to terminate...\n"); _getch(); throw 0; }

void DXHelper::ThrowIfFailed(HRESULT hr/*, UINT64& frameCounter*/)
{
Expand Down Expand Up @@ -64,3 +69,124 @@ std::vector<char> DXHelper::ReadShaderFile(const std::filesystem::path& path)

return shaderCode;
}

// @TODO AI-Generated: Review shader compilation function
//ID3DBlob* DXHelper::CompileShader(const std::string& shaderCode, const wchar_t* entryPoint, const wchar_t* targetProfile)
//{
// ID3DBlob* resultBlob = nullptr;
// HMODULE sDxCompilerDLL = LoadLibrary("dxcompiler.dll");
// ERROR_QUIT(sDxCompilerDLL, "Failed to initialize compiler.");
// if (sDxCompilerDLL)
// {
// DxcCreateInstanceProc pDxcCreateInstance;
// pDxcCreateInstance = (DxcCreateInstanceProc)GetProcAddress(sDxCompilerDLL, "DxcCreateInstance");
//
// if (pDxcCreateInstance)
// {
// ComPtr<IDxcUtils> pUtils;
// ComPtr<IDxcCompiler> pCompiler;
// ComPtr<IDxcBlobEncoding> pSource;
// ComPtr<IDxcOperationResult> pOperationResult;
//
// if (SUCCEEDED(pDxcCreateInstance(CLSID_DxcUtils, IID_PPV_ARGS(&pUtils))) && SUCCEEDED(pDxcCreateInstance(CLSID_DxcCompiler, IID_PPV_ARGS(&pCompiler))))
// {
// if (SUCCEEDED(pUtils->CreateBlob(shaderCode.c_str(), static_cast<uint32_t>(shaderCode.length()), 0, &pSource)))
// {
// if (SUCCEEDED(pCompiler->Compile(pSource.Get(), nullptr, entryPoint, targetProfile, nullptr, 0, nullptr, 0, nullptr, &pOperationResult)))
// {
// HRESULT hr;
// pOperationResult->GetStatus(&hr);
// if (SUCCEEDED(hr))
// {
// pOperationResult->GetResult((IDxcBlob**)&resultBlob);
// }
// }
// }
// }
// }
// }
//
// ERROR_QUIT(resultBlob, "Failed to compile GWG Library.");
// return resultBlob;
//}

// @TODO AI-Generated: Review shader compilation function
//ID3DBlob* DXHelper::CompileShader(const std::string& shaderCode, const wchar_t* entryPoint, const wchar_t* targetProfile)
//{
// ID3DBlob* resultBlob = nullptr;
// HMODULE sDxCompilerDLL = LoadLibrary("dxcompiler.dll");
// ERROR_QUIT(sDxCompilerDLL, "Failed to initialize compiler.");
// if (sDxCompilerDLL)
// {
// DxcCreateInstanceProc pDxcCreateInstance;
// pDxcCreateInstance = (DxcCreateInstanceProc)GetProcAddress(sDxCompilerDLL, "DxcCreateInstance");
//
// if (pDxcCreateInstance)
// {
// ComPtr<IDxcUtils> pUtils;
// ComPtr<IDxcCompiler> pCompiler;
// ComPtr<IDxcBlobEncoding> pSource;
// ComPtr<IDxcOperationResult> pOperationResult;
//
// if (SUCCEEDED(pDxcCreateInstance(CLSID_DxcUtils, IID_PPV_ARGS(&pUtils))) && SUCCEEDED(pDxcCreateInstance(CLSID_DxcCompiler, IID_PPV_ARGS(&pCompiler))))
// {
// if (SUCCEEDED(pUtils->CreateBlob(shaderCode.c_str(), static_cast<uint32_t>(shaderCode.length()), 0, &pSource)))
// {
// HRESULT compileResult = pCompiler->Compile(pSource.Get(), nullptr, entryPoint, targetProfile, nullptr, 0, nullptr, 0, nullptr, &pOperationResult);
//
// if (SUCCEEDED(compileResult) && pOperationResult)
// {
// HRESULT hr;
// pOperationResult->GetStatus(&hr);
//
// // Always try to get error buffer for warnings/errors
// ComPtr<IDxcBlobEncoding> pErrorBlob;
// if (SUCCEEDED(pOperationResult->GetErrorBuffer(&pErrorBlob)) && pErrorBlob && pErrorBlob->GetBufferSize() > 0)
// {
// std::string errorMsg(static_cast<const char*>(pErrorBlob->GetBufferPointer()), pErrorBlob->GetBufferSize());
// OutputDebugStringA("=== Shader Compilation Output ===\n");
// OutputDebugStringA(errorMsg.c_str());
// OutputDebugStringA("\n=================================\n");
//
// // Also print to console
// printf("=== Shader Compilation Output ===\n");
// printf("%s\n", errorMsg.c_str());
// printf("=================================\n");
// }
//
// if (SUCCEEDED(hr))
// {
// pOperationResult->GetResult((IDxcBlob**)&resultBlob);
// }
// else
// {
// // Print additional context on failure
// printf("Shader compilation failed!\n");
// printf(" Entry Point: %ls\n", entryPoint);
// printf(" Target Profile: %ls\n", targetProfile);
// }
// }
// else
// {
// printf("Failed to execute shader compilation. HRESULT: 0x%08X\n", compileResult);
// }
// }
// else
// {
// printf("Failed to create source blob from shader code.\n");
// }
// }
// else
// {
// printf("Failed to create DXC Utils or Compiler instance.\n");
// }
// }
// else
// {
// printf("Failed to get DxcCreateInstance from dxcompiler.dll.\n");
// }
// }
//
// ERROR_QUIT(resultBlob, "Failed to compile GWG Library.");
// return resultBlob;
//}
Loading