Skip to content

Commit

Permalink
Changes to meet hybrid requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
mixern6 committed Sep 26, 2024
1 parent 1bbe66e commit c6fc2f2
Show file tree
Hide file tree
Showing 26 changed files with 532 additions and 201 deletions.
98 changes: 63 additions & 35 deletions ffx-api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ if(POLICY CMP0147)
cmake_policy(SET CMP0147 NEW)
endif()

if (FFX_API_BACKEND STREQUAL VK_X64)
set(FFX_PLATFORM_NAME vk)
set(FFX_PLATFORM_NAME_VK vk)
set(FFX_PLATFORM_NAME_DX12 dx12)

if(FFX_API_BACKEND_VK_X64 AND
FFX_API_BACKEND_DX12_X64)
project(FFX_API_${FFX_PLATFORM_NAME_VK}_${FFX_PLATFORM_NAME_DX12})
elseif(FFX_API_BACKEND_VK_X64)
project(FFX_API_${FFX_PLATFORM_NAME_VK})
elseif(FFX_API_BACKEND_DX12_X64)
project(FFX_API_${FFX_PLATFORM_NAME_VK})
endif()
if (FFX_API_BACKEND STREQUAL DX12_X64)
set(FFX_PLATFORM_NAME dx12)
endif()

project(FFX_API_${FFX_PLATFORM_NAME})

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -44,19 +47,8 @@ if (MSVC)
endif()

set(CMAKE_CONFIGURATION_TYPES Debug Release RelWithDebInfo)
set(CMAKE_DEBUG_POSTFIX d)
set(CMAKE_RELWITHDEBINFO_POSTFIX drel)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_HOME_DIRECTORY}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_HOME_DIRECTORY}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_HOME_DIRECTORY}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_HOME_DIRECTORY}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_HOME_DIRECTORY}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_HOME_DIRECTORY}/bin)


# set(CMAKE_DEBUG_POSTFIX d)
# set(CMAKE_RELWITHDEBINFO_POSTFIX drel)

add_compile_definitions(FFXDLL_VERSION_MAJOR=1)
add_compile_definitions(FFXDLL_VERSION_MINOR=0)
Expand All @@ -75,12 +67,11 @@ file(GLOB private_ffx_api

file(GLOB public_ffx_api
${CMAKE_CURRENT_SOURCE_DIR}/include/ffx_api/*.h
${CMAKE_CURRENT_SOURCE_DIR}/include/ffx_api/*.hpp)
${CMAKE_CURRENT_SOURCE_DIR}/include/ffx_api/*.hpp)

if (FFX_API_BACKEND STREQUAL VK_X64)
if (FFX_API_BACKEND_VK_X64)
message(WARNING "Setting FFX_BACKEND_VK")
add_compile_definitions(FFXDLL_VERSION_API=VK)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS FFX_BACKEND_VK)

file(GLOB private_ffx_api_backend_vk
${CMAKE_CURRENT_SOURCE_DIR}/src/vk/*.h
Expand All @@ -91,10 +82,9 @@ if (FFX_API_BACKEND STREQUAL VK_X64)
${CMAKE_CURRENT_SOURCE_DIR}/include/ffx_api/vk/*.hpp)
endif()

if (FFX_API_BACKEND STREQUAL DX12_X64)
if (FFX_API_BACKEND_DX12_X64)
message(WARNING "Setting FFX_BACKEND_DX12")
add_compile_definitions(FFXDLL_VERSION_API=DX12)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS FFX_BACKEND_DX12)

file(GLOB private_ffx_api_backend_dx12
${CMAKE_CURRENT_SOURCE_DIR}/src/dx12/*.h
Expand All @@ -105,23 +95,47 @@ if (FFX_API_BACKEND STREQUAL DX12_X64)
${CMAKE_CURRENT_SOURCE_DIR}/include/ffx_api/dx12/*.hpp)
endif()

add_library(amd_fidelityfx_${FFX_PLATFORM_NAME} SHARED ${private_ffx_api} ${private_ffx_api_backend_dx12} ${private_ffx_api_backend_vk} ${public_ffx_api} ${public_ffx_api_backend_dx12} ${public_ffx_api_backend_vk})
if(FFX_API_BACKEND_VK_X64 AND
FFX_API_BACKEND_DX12_X64)
add_library(amd_fidelityfx_${FFX_PLATFORM_NAME_VK} SHARED ${private_ffx_api} ${private_ffx_api_backend_vk} ${public_ffx_api} ${public_ffx_api_backend_vk})
add_library(amd_fidelityfx_${FFX_PLATFORM_NAME_DX12} SHARED ${private_ffx_api} ${private_ffx_api_backend_dx12} ${public_ffx_api} ${public_ffx_api_backend_dx12})
set_property(TARGET amd_fidelityfx_${FFX_PLATFORM_NAME_VK} APPEND PROPERTY COMPILE_DEFINITIONS FFX_BACKEND_VK)
set_property(TARGET amd_fidelityfx_${FFX_PLATFORM_NAME_DX12} APPEND PROPERTY COMPILE_DEFINITIONS FFX_BACKEND_DX12)
elseif(FFX_API_BACKEND_VK_X64)
add_library(amd_fidelityfx_${FFX_PLATFORM_NAME_VK} SHARED ${private_ffx_api} ${private_ffx_api_backend_vk} ${public_ffx_api} ${public_ffx_api_backend_vk})
set_property(TARGET amd_fidelityfx_${FFX_PLATFORM_NAME_VK} APPEND PROPERTY COMPILE_DEFINITIONS FFX_BACKEND_VK)
elseif(FFX_API_BACKEND_DX12_X64)
add_library(amd_fidelityfx_${FFX_PLATFORM_NAME_DX12} SHARED ${private_ffx_api} ${private_ffx_api_backend_dx12} ${public_ffx_api} ${public_ffx_api_backend_dx12})
set_property(TARGET amd_fidelityfx_${FFX_PLATFORM_NAME_DX12} APPEND PROPERTY COMPILE_DEFINITIONS FFX_BACKEND_DX12)
endif()

source_group("private_source" FILES ${private_ffx_api})
source_group("public_source" FILES ${public_ffx_api})

if (FFX_API_BACKEND STREQUAL VK_X64)
if (FFX_API_BACKEND_VK_X64)
source_group("private_source\\vk" FILES ${private_ffx_api_backend_vk})
source_group("public_source\\vk" FILES ${public_ffx_api_backend_vk})
endif()

if (FFX_API_BACKEND STREQUAL DX12_X64)
if (FFX_API_BACKEND_DX12_X64)
source_group("private_source\\dx12" FILES ${private_ffx_api_backend_dx12})
source_group("public_source\\dx12" FILES ${public_ffx_api_backend_dx12})
endif()

target_include_directories(amd_fidelityfx_${FFX_PLATFORM_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(amd_fidelityfx_${FFX_PLATFORM_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../sdk/include)

if(FFX_API_BACKEND_VK_X64 AND
FFX_API_BACKEND_DX12_X64)
target_include_directories(amd_fidelityfx_${FFX_PLATFORM_NAME_VK} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(amd_fidelityfx_${FFX_PLATFORM_NAME_VK} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../sdk/include)
target_include_directories(amd_fidelityfx_${FFX_PLATFORM_NAME_DX12} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(amd_fidelityfx_${FFX_PLATFORM_NAME_DX12} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../sdk/include)
elseif(FFX_API_BACKEND_VK_X64)
target_include_directories(amd_fidelityfx_${FFX_PLATFORM_NAME_VK} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(amd_fidelityfx_${FFX_PLATFORM_NAME_VK} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../sdk/include)
elseif(FFX_API_BACKEND_DX12_X64)
target_include_directories(amd_fidelityfx_${FFX_PLATFORM_NAME_DX12} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(amd_fidelityfx_${FFX_PLATFORM_NAME_DX12} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../sdk/include)
endif()

# FSR dependency, must be built before using BuildFidelityFXSDK.bat

Expand All @@ -134,10 +148,24 @@ set(FFX_AUTO_COMPILE_SHADERS ON)
set(FFX_BUILD_AS_DLL OFF)
add_subdirectory(../sdk sdk)

target_link_libraries(amd_fidelityfx_${FFX_PLATFORM_NAME} PRIVATE ffx_fsr2_x64 ffx_fsr3upscaler_x64 ffx_opticalflow_x64 ffx_frameinterpolation_x64 DXGI)
if (FFX_API_BACKEND STREQUAL VK_X64)
if(FFX_API_BACKEND_VK_X64 AND
FFX_API_BACKEND_DX12_X64)
target_link_libraries(amd_fidelityfx_${FFX_PLATFORM_NAME_VK} PRIVATE ffx_fsr2_x64 ffx_fsr3upscaler_x64 ffx_opticalflow_x64 ffx_frameinterpolation_x64 DXGI)
target_link_libraries(amd_fidelityfx_${FFX_PLATFORM_NAME_DX12} PRIVATE ffx_fsr2_x64 ffx_fsr3upscaler_x64 ffx_opticalflow_x64 ffx_frameinterpolation_x64 DXGI)
elseif(FFX_API_BACKEND_VK_X64)
target_link_libraries(amd_fidelityfx_${FFX_PLATFORM_NAME_VK} PRIVATE ffx_fsr2_x64 ffx_fsr3upscaler_x64 ffx_opticalflow_x64 ffx_frameinterpolation_x64 DXGI)
elseif(FFX_API_BACKEND_DX12_X64)
target_link_libraries(amd_fidelityfx_${FFX_PLATFORM_NAME_DX12} PRIVATE ffx_fsr2_x64 ffx_fsr3upscaler_x64 ffx_opticalflow_x64 ffx_frameinterpolation_x64 DXGI)
endif()

if(FFX_API_BACKEND_VK_X64 AND
FFX_API_BACKEND_DX12_X64)
find_package(Vulkan REQUIRED)
target_link_libraries(amd_fidelityfx_${FFX_PLATFORM_NAME_VK} PRIVATE Vulkan::Headers ffx_backend_vk_x64)
target_link_libraries(amd_fidelityfx_${FFX_PLATFORM_NAME_DX12} PRIVATE D3D12 ffx_backend_dx12_x64)
elseif(FFX_API_BACKEND_VK_X64)
find_package(Vulkan REQUIRED)
target_link_libraries(amd_fidelityfx_${FFX_PLATFORM_NAME} PRIVATE Vulkan::Headers ffx_backend_vk_x64)
else() # DX12
target_link_libraries(amd_fidelityfx_${FFX_PLATFORM_NAME} PRIVATE D3D12 ffx_backend_dx12_x64)
target_link_libraries(amd_fidelityfx_${FFX_PLATFORM_NAME_VK} PRIVATE Vulkan::Headers ffx_backend_vk_x64)
elseif(FFX_API_BACKEND_DX12_X64)
target_link_libraries(amd_fidelityfx_${FFX_PLATFORM_NAME_DX12} PRIVATE D3D12 ffx_backend_dx12_x64)
endif()
46 changes: 45 additions & 1 deletion ffx-api/include/ffx_api/dx12/ffx_api_dx12.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,56 @@
// THE SOFTWARE.

#pragma once
#include "../ffx_api.h"
#include "../ffx_api_types.h"
#include <d3d12.h>
#include <dxgi.h>
#include <dxgi1_5.h>

#if defined(__cplusplus)
extern "C" {
#endif // #if defined(__cplusplus)

#include "../ffx_api.h"

#define FFX_API_ENTRY __declspec(dllexport)
#include <stdint.h>

// Creates a FFX object context.
// Depending on the desc structures provided to this function, the context will be created with the desired version and attributes.
// Non-zero return indicates error code.
// Pointers passed in desc must remain live until ffxDestroyContext is called on the context.
// MemCb may be null; the system allocator (malloc/free) will be used in this case.
FFX_API_ENTRY ffxReturnCode_t ffxCreateContextDX12(ffxContext* context, ffxCreateContextDescHeader* desc, const ffxAllocationCallbacks* memCb);
typedef ffxReturnCode_t (*PfnFfxCreateContextDX12)(ffxContext* context, ffxCreateContextDescHeader* desc, const ffxAllocationCallbacks* memCb);

// Destroys an FFX object context.
// Non-zero return indicates error code.
// MemCb must be compatible with the callbacks passed into ffxCreateContext.
FFX_API_ENTRY ffxReturnCode_t ffxDestroyContextDX12(ffxContext* context, const ffxAllocationCallbacks* memCb);
typedef ffxReturnCode_t (*PfnFfxDestroyContextDX12)(ffxContext* context, const ffxAllocationCallbacks* memCb);

// Configures the provided FFX object context.
// If context is null, configure operates on any global state.
// Non-zero return indicates error code.
FFX_API_ENTRY ffxReturnCode_t ffxConfigureDX12(ffxContext* context, const ffxConfigureDescHeader* desc);
typedef ffxReturnCode_t (*PfnFfxConfigureDX12)(ffxContext* context, const ffxConfigureDescHeader* desc);

// Queries the provided FFX object context.
// If context is null, query operates on any global state.
// Non-zero return indicates error code.
FFX_API_ENTRY ffxReturnCode_t ffxQueryDX12(ffxContext* context, ffxQueryDescHeader* desc);
typedef ffxReturnCode_t (*PfnFfxQueryDX12)(ffxContext* context, ffxQueryDescHeader* desc);

// Dispatches work on the given FFX object context defined by the dispatch descriptor.
// Non-zero return indicates error code.
FFX_API_ENTRY ffxReturnCode_t ffxDispatchDX12(ffxContext* context, const ffxDispatchDescHeader* desc);
typedef ffxReturnCode_t (*PfnFfxDispatchDX12)(ffxContext* context, const ffxDispatchDescHeader* desc);

#if defined(__cplusplus)
}
#endif // #if defined(__cplusplus)


#define FFX_API_CREATE_CONTEXT_DESC_TYPE_BACKEND_DX12 0x0000002u
struct ffxCreateBackendDX12Desc
{
Expand Down
55 changes: 55 additions & 0 deletions ffx-api/include/ffx_api/dx12/ffx_api_dx12.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,66 @@
#include "../ffx_api.hpp"
#include "ffx_api_dx12.h"

#include <cstdint>
#include <type_traits>

// Helper types for header initialization. Api definition is in .h file.

namespace ffx
{

namespace dx12
{

template <class... Desc>
inline ReturnCode CreateContext(Context& context, ffxAllocationCallbacks* memCb, Desc&... desc)
{
auto header = LinkHeaders(desc.header...);
return detail::ConvertReturnCode(ffxCreateContextDX12(&context, header, memCb));
}

inline ReturnCode DestroyContext(Context& context, ffxAllocationCallbacks* memCb = nullptr)
{
return detail::ConvertReturnCode(ffxDestroyContextDX12(&context, memCb));
}

template <class... Desc>
inline ReturnCode Configure(Context& context, Desc&... desc)
{
auto header = LinkHeaders(desc.header...);
return detail::ConvertReturnCode(ffxConfigureDX12(&context, header));
}

template <class... Desc>
inline ReturnCode Configure(Desc&... desc)
{
auto header = LinkHeaders(desc.header...);
return detail::ConvertReturnCode(ffxConfigureDX12(nullptr, header));
}

template <class... Desc>
inline ReturnCode Query(Context& context, Desc&... desc)
{
auto header = LinkHeaders(desc.header...);
return detail::ConvertReturnCode(ffxQueryDX12(&context, header));
}

template <class... Desc>
inline ReturnCode Query(Desc&... desc)
{
auto header = LinkHeaders(desc.header...);
return detail::ConvertReturnCode(ffxQueryDX12(nullptr, header));
}

template <class... Desc>
inline ReturnCode Dispatch(Context& context, Desc&... desc)
{
auto header = LinkHeaders(desc.header...);
return detail::ConvertReturnCode(ffxDispatchDX12(&context, header));
}

} // namespace dx12

template<>
struct struct_type<ffxCreateBackendDX12Desc> : std::integral_constant<uint64_t, FFX_API_CREATE_CONTEXT_DESC_TYPE_BACKEND_DX12> {};

Expand Down
48 changes: 48 additions & 0 deletions ffx-api/include/ffx_api/dx12/ffx_api_loader_dx12.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#pragma once

#include "ffx_api_dx12.h"
#include <windows.h>

namespace dx12
{

typedef struct ffxFunctions {
PfnFfxCreateContextDX12 CreateContextDX12;
PfnFfxDestroyContextDX12 DestroyContextDX12;
PfnFfxConfigureDX12 ConfigureDX12;
PfnFfxQueryDX12 QueryDX12;
PfnFfxDispatchDX12 DispatchDX12;
} ffxFunctions;

static inline void ffxLoadFunctions(ffxFunctions* pOutFunctions, HMODULE module)
{
pOutFunctions->CreateContextDX12 = (PfnFfxCreateContextDX12)GetProcAddress(module, "ffxCreateContextDX12");
pOutFunctions->DestroyContextDX12 = (PfnFfxDestroyContextDX12)GetProcAddress(module, "ffxDestroyContextDX12");
pOutFunctions->ConfigureDX12 = (PfnFfxConfigureDX12)GetProcAddress(module, "ffxConfigureDX12");
pOutFunctions->QueryDX12 = (PfnFfxQueryDX12)GetProcAddress(module, "ffxQueryDX12");
pOutFunctions->DispatchDX12 = (PfnFfxDispatchDX12)GetProcAddress(module, "ffxDispatchDX12");
}

} // namespace dx12
41 changes: 1 addition & 40 deletions ffx-api/include/ffx_api/ffx_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@

#pragma once

#if defined(__cplusplus)
extern "C" {
#endif // #if defined(__cplusplus)

#define FFX_API_ENTRY __declspec(dllexport)
#include <stdint.h>

enum FfxApiReturnCodes
Expand All @@ -40,6 +35,7 @@ enum FfxApiReturnCodes
FFX_API_RETURN_ERROR_PARAMETER = 6, ///< A parameter was invalid, e.g. a null pointer, empty resource or out-of-bounds enum value.
};

typedef void* ffxSwapchain;
typedef void* ffxContext;
typedef uint32_t ffxReturnCode_t;

Expand Down Expand Up @@ -113,38 +109,3 @@ typedef struct ffxAllocationCallbacks
ffxAlloc alloc;
ffxDealloc dealloc;
} ffxAllocationCallbacks;

// Creates a FFX object context.
// Depending on the desc structures provided to this function, the context will be created with the desired version and attributes.
// Non-zero return indicates error code.
// Pointers passed in desc must remain live until ffxDestroyContext is called on the context.
// MemCb may be null; the system allocator (malloc/free) will be used in this case.
FFX_API_ENTRY ffxReturnCode_t ffxCreateContext(ffxContext* context, ffxCreateContextDescHeader* desc, const ffxAllocationCallbacks* memCb);
typedef ffxReturnCode_t (*PfnFfxCreateContext)(ffxContext* context, ffxCreateContextDescHeader* desc, const ffxAllocationCallbacks* memCb);

// Destroys an FFX object context.
// Non-zero return indicates error code.
// MemCb must be compatible with the callbacks passed into ffxCreateContext.
FFX_API_ENTRY ffxReturnCode_t ffxDestroyContext(ffxContext* context, const ffxAllocationCallbacks* memCb);
typedef ffxReturnCode_t (*PfnFfxDestroyContext)(ffxContext* context, const ffxAllocationCallbacks* memCb);

// Configures the provided FFX object context.
// If context is null, configure operates on any global state.
// Non-zero return indicates error code.
FFX_API_ENTRY ffxReturnCode_t ffxConfigure(ffxContext* context, const ffxConfigureDescHeader* desc);
typedef ffxReturnCode_t (*PfnFfxConfigure)(ffxContext* context, const ffxConfigureDescHeader* desc);

// Queries the provided FFX object context.
// If context is null, query operates on any global state.
// Non-zero return indicates error code.
FFX_API_ENTRY ffxReturnCode_t ffxQuery(ffxContext* context, ffxQueryDescHeader* desc);
typedef ffxReturnCode_t (*PfnFfxQuery)(ffxContext* context, ffxQueryDescHeader* desc);

// Dispatches work on the given FFX object context defined by the dispatch descriptor.
// Non-zero return indicates error code.
FFX_API_ENTRY ffxReturnCode_t ffxDispatch(ffxContext* context, const ffxDispatchDescHeader* desc);
typedef ffxReturnCode_t (*PfnFfxDispatch)(ffxContext* context, const ffxDispatchDescHeader* desc);

#if defined(__cplusplus)
}
#endif // #if defined(__cplusplus)
Loading

0 comments on commit c6fc2f2

Please sign in to comment.