Skip to content

Commit

Permalink
feat: add FidelityFX-SDK-DX11 submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
FlayaN committed Aug 20, 2024
1 parent efe0460 commit e57caaa
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "extern/NVAPI"]
path = extern/NVAPI
url = https://github.com/NVIDIA/nvapi.git
[submodule "extern/FidelityFX-SDK-DX11"]
path = extern/FidelityFX-SDK-DX11
url = https://github.com/metarutaiga/FidelityFX-SDK-DX11
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ find_package(cppwinrt CONFIG REQUIRED)
find_package(unordered_dense CONFIG REQUIRED)
find_package(efsw CONFIG REQUIRED)
find_package(Tracy CONFIG REQUIRED)
add_subdirectory(${CMAKE_SOURCE_DIR}/cmake/FidelityFX)

set(NVAPI_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/extern/nvapi/" CACHE STRING "Path to NVAPI include headers/shaders" )
set(NVAPI_LIBRARY "${CMAKE_SOURCE_DIR}/extern/nvapi/amd64/nvapi64.lib" CACHE STRING "Path to NVAPI .lib file")
Expand Down Expand Up @@ -78,7 +79,8 @@ target_link_libraries(
unordered_dense::unordered_dense
efsw::efsw
Tracy::TracyClient
${NVAPI_LIBRARY}
FidelityFX
${NVAPI_LIBRARY}
)

# https://gitlab.kitware.com/cmake/cmake/-/issues/24922#note_1371990
Expand Down
47 changes: 47 additions & 0 deletions cmake/FidelityFX/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
cmake_minimum_required(VERSION 3.15)

set(FidelityFXPath "../../extern/FidelityFX-SDK-DX11")
project(FidelityFX)

set(SOURCES
${FidelityFXPath}/DXBC/md5.h
${FidelityFXPath}/FidelityFX/gpu/ffx_common_types.h
${FidelityFXPath}/FidelityFX/gpu/ffx_core.h
${FidelityFXPath}/FidelityFX/gpu/ffx_core_gpu_common.h
${FidelityFXPath}/FidelityFX/gpu/ffx_core_gpu_common_half.h
${FidelityFXPath}/FidelityFX/gpu/ffx_core_hlsl.h
${FidelityFXPath}/FidelityFX/gpu/ffx_core_portability.h
${FidelityFXPath}/FidelityFX/host/ffx_assert.h
${FidelityFXPath}/FidelityFX/host/ffx_error.h
${FidelityFXPath}/FidelityFX/host/ffx_interface.h
${FidelityFXPath}/FidelityFX/host/ffx_types.h
${FidelityFXPath}/FidelityFX/host/ffx_util.h
${FidelityFXPath}/FidelityFX/host/shared/ffx_object_management.h
${FidelityFXPath}/DXBC/DXBCChecksum.c
${FidelityFXPath}/DXBC/md5.c
${FidelityFXPath}/FidelityFX/host/shared/ffx_assert.cpp
${FidelityFXPath}/FidelityFX/host/shared/ffx_object_management.cpp
${FidelityFXPath}/FidelityFX/host/backends/dx11/ffx_dx11.cpp
${FidelityFXPath}/FidelityFX/host/components/frameinterpolation/ffx_frameinterpolation.cpp
${FidelityFXPath}/FidelityFX/host/backends/ffx_shader_blobs.cpp)

add_library(${PROJECT_NAME} STATIC ${SOURCES})

target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_23)

if(MSVC)
target_compile_options(
${PROJECT_NAME}
PUBLIC # disable warnings
/wd4065
/wd4100
/wd4189
/wd4324
/wd4456
/wd4505
/wd4996)
endif()

target_include_directories(
${PROJECT_NAME} PUBLIC ${FidelityFXPath} ${FidelityFXPath}/FidelityFX
${FidelityFXPath}/FidelityFX/host/shared)
1 change: 1 addition & 0 deletions extern/FidelityFX-SDK-DX11
Submodule FidelityFX-SDK-DX11 added at bc7462
24 changes: 24 additions & 0 deletions src/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

#include "VariableRateShading.h"

#include "FidelityFX/host/backends/dx11/ffx_dx11.h"
#include "FidelityFX/host/ffx_fsr3.h"

enum class PermutationFlags : uint32_t
{
InWorld = 1 << 24,
Expand Down Expand Up @@ -385,6 +388,27 @@ void State::SetupResources()
context->QueryInterface(__uuidof(pPerf), reinterpret_cast<void**>(&pPerf));

tracyCtx = TracyD3D11Context(device, context);

FfxDevice fsrDevice = ffxGetDeviceDX11(State::GetSingleton()->device);

size_t scratchBufferSize = ffxGetScratchMemorySizeDX11(1);
void* scratchBuffer = malloc(scratchBufferSize);
memset(scratchBuffer, 0, scratchBufferSize);

FfxInterface backendInterface;
ffxGetInterfaceDX11(&backendInterface, fsrDevice, scratchBuffer, scratchBufferSize, 1);

FfxFrameInterpolationContext* fgContext = nullptr;
FfxFrameInterpolationContextDescription fgDescription;
fgDescription.flags = 0;
fgDescription.maxRenderSize = { (uint)State::GetSingleton()->screenSize.x, (uint)State::GetSingleton()->screenSize.y };
fgDescription.displaySize = fgDescription.maxRenderSize;
fgDescription.backBufferFormat = FFX_SURFACE_FORMAT_R8G8B8A8_UNORM;
fgDescription.backendInterface = backendInterface;

auto result = ffxFrameInterpolationContextCreate(fgContext, &fgDescription);

logger::info("{}", result == FFX_OK ? "ok" : "not ok");
}

void State::ModifyShaderLookup(const RE::BSShader& a_shader, uint& a_vertexDescriptor, uint& a_pixelDescriptor, bool a_forceDeferred)
Expand Down

0 comments on commit e57caaa

Please sign in to comment.