From d77d3fc94b76d3722e2052bcd662ca9e45906dbe Mon Sep 17 00:00:00 2001 From: TheJackiMonster Date: Fri, 30 Sep 2022 13:14:08 +0200 Subject: [PATCH] Improve wider platform support Signed-off-by: TheJackiMonster --- src/ffx-fsr2-api/CMakeLists.txt | 6 ++++++ src/ffx-fsr2-api/ffx_fsr2.cpp | 19 ++++++++++++------- src/ffx-fsr2-api/ffx_types.h | 1 + 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/ffx-fsr2-api/CMakeLists.txt b/src/ffx-fsr2-api/CMakeLists.txt index 7ef023c..6a456bf 100644 --- a/src/ffx-fsr2-api/CMakeLists.txt +++ b/src/ffx-fsr2-api/CMakeLists.txt @@ -41,6 +41,12 @@ if(CMAKE_GENERATOR_PLATFORM STREQUAL "x64" OR CMAKE_EXE_LINKER_FLAGS STREQUAL "/ set(FSR2_PLATFORM_NAME x64) elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "Win32" OR CMAKE_EXE_LINKER_FLAGS STREQUAL "/machine:X86") set(FSR2_PLATFORM_NAME x86) +elseif(CMAKE_SYSTEM_PROCESSOR) + set(FSR2_PLATFORM_NAME ${CMAKE_SYSTEM_PROCESSOR}) + + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + add_compile_definitions(FFX_GCC) + endif() else() message(FATAL_ERROR "Unsupported target platform - only supporting x64 and Win32 currently") endif() diff --git a/src/ffx-fsr2-api/ffx_fsr2.cpp b/src/ffx-fsr2-api/ffx_fsr2.cpp index ebd69d5..9370fcc 100644 --- a/src/ffx-fsr2-api/ffx_fsr2.cpp +++ b/src/ffx-fsr2-api/ffx_fsr2.cpp @@ -22,6 +22,7 @@ #include // for max used inside SPD CPU code. #include // for fabs, abs, sinf, sqrt, etc. #include // for memset +#include // for wcscmp, wcscpy #include // for FLT_EPSILON #include "ffx_fsr2.h" #define FFX_CPU @@ -36,6 +37,10 @@ #pragma clang diagnostic ignored "-Wunused-variable" #endif +#ifndef _countof +#define _countof(array) (sizeof(array) / sizeof(array[0])) +#endif + // max queued frames for descriptor management static const uint32_t FSR2_MAX_QUEUED_FRAMES = 16; @@ -484,13 +489,13 @@ static void scheduleDispatch(FfxFsr2Context_Private* context, const FfxFsr2Dispa const uint32_t currentResourceId = pipeline->srvResourceBindings[currentShaderResourceViewIndex].resourceIdentifier; const FfxResourceInternal currentResource = context->srvResources[currentResourceId]; jobDescriptor.srvs[currentShaderResourceViewIndex] = currentResource; - wcscpy_s(jobDescriptor.srvNames[currentShaderResourceViewIndex], pipeline->srvResourceBindings[currentShaderResourceViewIndex].name); + wcscpy(jobDescriptor.srvNames[currentShaderResourceViewIndex], pipeline->srvResourceBindings[currentShaderResourceViewIndex].name); } for (uint32_t currentUnorderedAccessViewIndex = 0; currentUnorderedAccessViewIndex < pipeline->uavCount; ++currentUnorderedAccessViewIndex) { const uint32_t currentResourceId = pipeline->uavResourceBindings[currentUnorderedAccessViewIndex].resourceIdentifier; - wcscpy_s(jobDescriptor.uavNames[currentUnorderedAccessViewIndex], pipeline->uavResourceBindings[currentUnorderedAccessViewIndex].name); + wcscpy(jobDescriptor.uavNames[currentUnorderedAccessViewIndex], pipeline->uavResourceBindings[currentUnorderedAccessViewIndex].name); if (currentResourceId >= FFX_FSR2_RESOURCE_IDENTIFIER_AUTO_EXPOSURE_MIPMAP_0 && currentResourceId <= FFX_FSR2_RESOURCE_IDENTIFIER_AUTO_EXPOSURE_MIPMAP_12) { @@ -512,7 +517,7 @@ static void scheduleDispatch(FfxFsr2Context_Private* context, const FfxFsr2Dispa jobDescriptor.pipeline = *pipeline; for (uint32_t currentRootConstantIndex = 0; currentRootConstantIndex < pipeline->constCount; ++currentRootConstantIndex) { - wcscpy_s( jobDescriptor.cbNames[currentRootConstantIndex], pipeline->cbResourceBindings[currentRootConstantIndex].name); + wcscpy( jobDescriptor.cbNames[currentRootConstantIndex], pipeline->cbResourceBindings[currentRootConstantIndex].name); jobDescriptor.cbs[currentRootConstantIndex] = globalFsr2ConstantBuffers[pipeline->cbResourceBindings[currentRootConstantIndex].resourceIdentifier]; } @@ -1003,9 +1008,9 @@ FfxErrorCode ffxFsr2ContextGenerateReactiveMask(FfxFsr2Context* context, const F contextPrivate->contextDescription.callbacks.fpRegisterResource(&contextPrivate->contextDescription.callbacks, ¶ms->colorOpaqueOnly, &jobDescriptor.srvs[0]); contextPrivate->contextDescription.callbacks.fpRegisterResource(&contextPrivate->contextDescription.callbacks, ¶ms->colorPreUpscale, &jobDescriptor.srvs[1]); contextPrivate->contextDescription.callbacks.fpRegisterResource(&contextPrivate->contextDescription.callbacks, ¶ms->outReactive, &jobDescriptor.uavs[0]); - wcscpy_s(jobDescriptor.srvNames[0], pipeline->srvResourceBindings[0].name); - wcscpy_s(jobDescriptor.srvNames[1], pipeline->srvResourceBindings[1].name); - wcscpy_s(jobDescriptor.uavNames[0], pipeline->uavResourceBindings[0].name); + wcscpy(jobDescriptor.srvNames[0], pipeline->srvResourceBindings[0].name); + wcscpy(jobDescriptor.srvNames[1], pipeline->srvResourceBindings[1].name); + wcscpy(jobDescriptor.uavNames[0], pipeline->uavResourceBindings[0].name); jobDescriptor.dimensions[0] = dispatchSrcX; jobDescriptor.dimensions[1] = dispatchSrcY; @@ -1020,7 +1025,7 @@ FfxErrorCode ffxFsr2ContextGenerateReactiveMask(FfxFsr2Context* context, const F jobDescriptor.cbs[0].uint32Size = sizeof(constants); memcpy(&jobDescriptor.cbs[0].data, &constants, sizeof(constants)); - wcscpy_s(jobDescriptor.cbNames[0], pipeline->cbResourceBindings[0].name); + wcscpy(jobDescriptor.cbNames[0], pipeline->cbResourceBindings[0].name); FfxGpuJobDescription dispatchJob = { FFX_GPU_JOB_COMPUTE }; dispatchJob.computeJobDescriptor = jobDescriptor; diff --git a/src/ffx-fsr2-api/ffx_types.h b/src/ffx-fsr2-api/ffx_types.h index 75fb0e8..775d334 100644 --- a/src/ffx-fsr2-api/ffx_types.h +++ b/src/ffx-fsr2-api/ffx_types.h @@ -22,6 +22,7 @@ #pragma once #include +#include #if defined (FFX_GCC) /// FidelityFX exported functions