diff --git a/OptiScaler/NVNGX_Parameter.h b/OptiScaler/NVNGX_Parameter.h index 45bbedb6..396a5ed1 100644 --- a/OptiScaler/NVNGX_Parameter.h +++ b/OptiScaler/NVNGX_Parameter.h @@ -1,7 +1,9 @@ #pragma once #include "pch.h" + #include "Config.h" -#include "DLSSG_Mod.h" + +// #include "inputs/FG/DLSSG_Mod.h" #include @@ -469,7 +471,7 @@ inline static void InitNGXParameters(NVSDK_NGX_Parameter* InParams) InParams->Set(NVSDK_NGX_Parameter_RTXValue, 0); // not ideal as it doesn't take different APIs into account - if (DLSSGMod::isLoaded() || Config::Instance()->FGInput == FGInput::DLSSG) + if (State::Instance().activeFgInput == FGInput::Nukems || State::Instance().activeFgInput == FGInput::DLSSG) { InParams->Set("FrameGeneration.Available", 1); InParams->Set("FrameInterpolation.Available", 1); diff --git a/OptiScaler/OptiScaler.vcxproj b/OptiScaler/OptiScaler.vcxproj index 5d090a3a..6bbac5ca 100644 --- a/OptiScaler/OptiScaler.vcxproj +++ b/OptiScaler/OptiScaler.vcxproj @@ -377,7 +377,7 @@ copy NUL "$(SolutionDir)x64\Release\a\!! EXTRACT ALL FILES TO GAME FOLDER !!" /Y - + diff --git a/OptiScaler/DLSSG_Mod.h b/OptiScaler/inputs/FG/DLSSG_Mod.h similarity index 59% rename from OptiScaler/DLSSG_Mod.h rename to OptiScaler/inputs/FG/DLSSG_Mod.h index 6f70c8eb..b272d9e2 100644 --- a/OptiScaler/DLSSG_Mod.h +++ b/OptiScaler/inputs/FG/DLSSG_Mod.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "proxies/NVNGX_Proxy.h" #include "proxies/KernelBase_Proxy.h" @@ -61,46 +63,43 @@ class DLSSGMod { LOG_FUNC(); - if (_dx12_inited) + if (_dx12_inited || Config::Instance()->FGInput.value_or_default() != FGInput::Nukems) return; - if (Config::Instance()->FGInput.value_or_default() == FGInput::Nukems) + if (_dll == nullptr) { - if (_dll == nullptr) - { - auto dllPath = Util::DllPath().parent_path() / "dlssg_to_fsr3_amd_is_better.dll"; - _dll = KernelBaseProxy::LoadLibraryExW_()(dllPath.c_str(), NULL, 0); - } + auto dllPath = Util::DllPath().parent_path() / "dlssg_to_fsr3_amd_is_better.dll"; + _dll = KernelBaseProxy::LoadLibraryExW_()(dllPath.c_str(), NULL, 0); + } - if (_dll != nullptr) - { - _DLSSG_D3D12_Init = (PFN_D3D12_Init) GetProcAddress(_dll, "NVSDK_NGX_D3D12_Init"); - _DLSSG_D3D12_Init_Ext = (PFN_D3D12_Init_Ext) GetProcAddress(_dll, "NVSDK_NGX_D3D12_Init_Ext"); - _DLSSG_D3D12_Shutdown = (PFN_D3D12_Shutdown) GetProcAddress(_dll, "NVSDK_NGX_D3D12_Shutdown"); - _DLSSG_D3D12_Shutdown1 = (PFN_D3D12_Shutdown1) GetProcAddress(_dll, "NVSDK_NGX_D3D12_Shutdown1"); - _DLSSG_D3D12_GetScratchBufferSize = - (PFN_D3D12_GetScratchBufferSize) GetProcAddress(_dll, "NVSDK_NGX_D3D12_GetScratchBufferSize"); - _DLSSG_D3D12_CreateFeature = - (PFN_D3D12_CreateFeature) GetProcAddress(_dll, "NVSDK_NGX_D3D12_CreateFeature"); - _DLSSG_D3D12_ReleaseFeature = - (PFN_D3D12_ReleaseFeature) GetProcAddress(_dll, "NVSDK_NGX_D3D12_ReleaseFeature"); - _DLSSG_D3D12_GetFeatureRequirements = - (PFN_D3D12_GetFeatureRequirements) GetProcAddress(_dll, "NVSDK_NGX_D3D12_GetFeatureRequirements"); - _DLSSG_D3D12_EvaluateFeature = - (PFN_D3D12_EvaluateFeature) GetProcAddress(_dll, "NVSDK_NGX_D3D12_EvaluateFeature"); - _DLSSG_D3D12_PopulateParameters_Impl = - (PFN_D3D12_PopulateParameters_Impl) GetProcAddress(_dll, "NVSDK_NGX_D3D12_PopulateParameters_Impl"); - _refreshGlobalConfiguration = - (PFN_RefreshGlobalConfiguration) GetProcAddress(_dll, "RefreshGlobalConfiguration"); - _fsrDebugView = (PFN_EnableDebugView) GetProcAddress(_dll, "FSRDebugView"); - _dx12_inited = true; + if (_dll != nullptr) + { + _DLSSG_D3D12_Init = (PFN_D3D12_Init) GetProcAddress(_dll, "NVSDK_NGX_D3D12_Init"); + _DLSSG_D3D12_Init_Ext = (PFN_D3D12_Init_Ext) GetProcAddress(_dll, "NVSDK_NGX_D3D12_Init_Ext"); + _DLSSG_D3D12_Shutdown = (PFN_D3D12_Shutdown) GetProcAddress(_dll, "NVSDK_NGX_D3D12_Shutdown"); + _DLSSG_D3D12_Shutdown1 = (PFN_D3D12_Shutdown1) GetProcAddress(_dll, "NVSDK_NGX_D3D12_Shutdown1"); + _DLSSG_D3D12_GetScratchBufferSize = + (PFN_D3D12_GetScratchBufferSize) GetProcAddress(_dll, "NVSDK_NGX_D3D12_GetScratchBufferSize"); + _DLSSG_D3D12_CreateFeature = + (PFN_D3D12_CreateFeature) GetProcAddress(_dll, "NVSDK_NGX_D3D12_CreateFeature"); + _DLSSG_D3D12_ReleaseFeature = + (PFN_D3D12_ReleaseFeature) GetProcAddress(_dll, "NVSDK_NGX_D3D12_ReleaseFeature"); + _DLSSG_D3D12_GetFeatureRequirements = + (PFN_D3D12_GetFeatureRequirements) GetProcAddress(_dll, "NVSDK_NGX_D3D12_GetFeatureRequirements"); + _DLSSG_D3D12_EvaluateFeature = + (PFN_D3D12_EvaluateFeature) GetProcAddress(_dll, "NVSDK_NGX_D3D12_EvaluateFeature"); + _DLSSG_D3D12_PopulateParameters_Impl = + (PFN_D3D12_PopulateParameters_Impl) GetProcAddress(_dll, "NVSDK_NGX_D3D12_PopulateParameters_Impl"); + _refreshGlobalConfiguration = + (PFN_RefreshGlobalConfiguration) GetProcAddress(_dll, "RefreshGlobalConfiguration"); + _fsrDebugView = (PFN_EnableDebugView) GetProcAddress(_dll, "FSRDebugView"); + _dx12_inited = true; - LOG_INFO("DLSSG Mod initialized for DX12"); - } - else - { - LOG_INFO("DLSSG Mod enabled but cannot be loaded"); - } + LOG_INFO("DLSSG Mod initialized for DX12"); + } + else + { + LOG_INFO("DLSSG Mod enabled but cannot be loaded"); } } @@ -108,49 +107,46 @@ class DLSSGMod { LOG_FUNC(); - if (_vulkan_inited) + if (_vulkan_inited || Config::Instance()->FGInput.value_or_default() != FGInput::Nukems) return; - if (Config::Instance()->FGInput.value_or_default() == FGInput::Nukems) + if (_dll == nullptr) { - if (_dll == nullptr) - { - auto dllPath = Util::DllPath().parent_path() / "dlssg_to_fsr3_amd_is_better.dll"; - _dll = KernelBaseProxy::LoadLibraryExW_()(dllPath.c_str(), NULL, 0); - } + auto dllPath = Util::DllPath().parent_path() / "dlssg_to_fsr3_amd_is_better.dll"; + _dll = KernelBaseProxy::LoadLibraryExW_()(dllPath.c_str(), NULL, 0); + } - if (_dll != nullptr) - { - _DLSSG_VULKAN_Init = (PFN_VULKAN_Init) GetProcAddress(_dll, "NVSDK_NGX_VULKAN_Init"); - _DLSSG_VULKAN_Init_Ext = (PFN_VULKAN_Init_Ext) GetProcAddress(_dll, "NVSDK_NGX_VULKAN_Init_Ext"); - _DLSSG_VULKAN_Init_Ext2 = (PFN_VULKAN_Init_Ext2) GetProcAddress(_dll, "NVSDK_NGX_VULKAN_Init_Ext2"); - _DLSSG_VULKAN_Shutdown = (PFN_VULKAN_Shutdown) GetProcAddress(_dll, "NVSDK_NGX_VULKAN_Shutdown"); - _DLSSG_VULKAN_Shutdown1 = (PFN_VULKAN_Shutdown1) GetProcAddress(_dll, "NVSDK_NGX_VULKAN_Shutdown1"); - _DLSSG_VULKAN_GetScratchBufferSize = - (PFN_VULKAN_GetScratchBufferSize) GetProcAddress(_dll, "NVSDK_NGX_VULKAN_GetScratchBufferSize"); - _DLSSG_VULKAN_CreateFeature = - (PFN_VULKAN_CreateFeature) GetProcAddress(_dll, "NVSDK_NGX_VULKAN_CreateFeature"); - _DLSSG_VULKAN_CreateFeature1 = - (PFN_VULKAN_CreateFeature1) GetProcAddress(_dll, "NVSDK_NGX_VULKAN_CreateFeature1"); - _DLSSG_VULKAN_ReleaseFeature = - (PFN_VULKAN_ReleaseFeature) GetProcAddress(_dll, "NVSDK_NGX_VULKAN_ReleaseFeature"); - _DLSSG_VULKAN_GetFeatureRequirements = - (PFN_VULKAN_GetFeatureRequirements) GetProcAddress(_dll, "NVSDK_NGX_VULKAN_GetFeatureRequirements"); - _DLSSG_VULKAN_EvaluateFeature = - (PFN_VULKAN_EvaluateFeature) GetProcAddress(_dll, "NVSDK_NGX_VULKAN_EvaluateFeature"); - _DLSSG_VULKAN_PopulateParameters_Impl = (PFN_VULKAN_PopulateParameters_Impl) GetProcAddress( - _dll, "NVSDK_NGX_VULKAN_PopulateParameters_Impl"); - _refreshGlobalConfiguration = - (PFN_RefreshGlobalConfiguration) GetProcAddress(_dll, "RefreshGlobalConfiguration"); - _fsrDebugView = (PFN_EnableDebugView) GetProcAddress(_dll, "FSRDebugView"); - _vulkan_inited = true; + if (_dll != nullptr) + { + _DLSSG_VULKAN_Init = (PFN_VULKAN_Init) GetProcAddress(_dll, "NVSDK_NGX_VULKAN_Init"); + _DLSSG_VULKAN_Init_Ext = (PFN_VULKAN_Init_Ext) GetProcAddress(_dll, "NVSDK_NGX_VULKAN_Init_Ext"); + _DLSSG_VULKAN_Init_Ext2 = (PFN_VULKAN_Init_Ext2) GetProcAddress(_dll, "NVSDK_NGX_VULKAN_Init_Ext2"); + _DLSSG_VULKAN_Shutdown = (PFN_VULKAN_Shutdown) GetProcAddress(_dll, "NVSDK_NGX_VULKAN_Shutdown"); + _DLSSG_VULKAN_Shutdown1 = (PFN_VULKAN_Shutdown1) GetProcAddress(_dll, "NVSDK_NGX_VULKAN_Shutdown1"); + _DLSSG_VULKAN_GetScratchBufferSize = + (PFN_VULKAN_GetScratchBufferSize) GetProcAddress(_dll, "NVSDK_NGX_VULKAN_GetScratchBufferSize"); + _DLSSG_VULKAN_CreateFeature = + (PFN_VULKAN_CreateFeature) GetProcAddress(_dll, "NVSDK_NGX_VULKAN_CreateFeature"); + _DLSSG_VULKAN_CreateFeature1 = + (PFN_VULKAN_CreateFeature1) GetProcAddress(_dll, "NVSDK_NGX_VULKAN_CreateFeature1"); + _DLSSG_VULKAN_ReleaseFeature = + (PFN_VULKAN_ReleaseFeature) GetProcAddress(_dll, "NVSDK_NGX_VULKAN_ReleaseFeature"); + _DLSSG_VULKAN_GetFeatureRequirements = + (PFN_VULKAN_GetFeatureRequirements) GetProcAddress(_dll, "NVSDK_NGX_VULKAN_GetFeatureRequirements"); + _DLSSG_VULKAN_EvaluateFeature = + (PFN_VULKAN_EvaluateFeature) GetProcAddress(_dll, "NVSDK_NGX_VULKAN_EvaluateFeature"); + _DLSSG_VULKAN_PopulateParameters_Impl = + (PFN_VULKAN_PopulateParameters_Impl) GetProcAddress(_dll, "NVSDK_NGX_VULKAN_PopulateParameters_Impl"); + _refreshGlobalConfiguration = + (PFN_RefreshGlobalConfiguration) GetProcAddress(_dll, "RefreshGlobalConfiguration"); + _fsrDebugView = (PFN_EnableDebugView) GetProcAddress(_dll, "FSRDebugView"); + _vulkan_inited = true; - LOG_INFO("DLSSG Mod initialized for Vulkan"); - } - else - { - LOG_INFO("DLSSG Mod enabled but cannot be loaded"); - } + LOG_INFO("DLSSG Mod initialized for Vulkan"); + } + else + { + LOG_INFO("DLSSG Mod enabled but cannot be loaded"); } } @@ -252,14 +248,103 @@ class DLSSGMod static inline NVSDK_NGX_Result D3D12_EvaluateFeature(ID3D12GraphicsCommandList* InCmdList, const NVSDK_NGX_Handle* InFeatureHandle, - const NVSDK_NGX_Parameter* InParameters, + NVSDK_NGX_Parameter* InParameters, PFN_NVSDK_NGX_ProgressCallback InCallback) { if (isDx12Available() && InFeatureHandle->Id >= DLSSG_MOD_ID_OFFSET) { + if (!is120orNewer()) + { + // Workaround mostly for final fantasy xvi + uint32_t depthInverted = 0; + float cameraNear = 0; + float cameraFar = 0; + InParameters->Get("DLSSG.DepthInverted", &depthInverted); + InParameters->Get("DLSSG.CameraNear", &cameraNear); + InParameters->Get("DLSSG.CameraFar", &cameraFar); + + if (cameraNear == 0) + { + if (depthInverted) + cameraNear = 100000.0f; + else + cameraNear = 0.1f; + + InParameters->Set("DLSSG.CameraNear", cameraNear); + } + + if (cameraFar == 0) + { + if (depthInverted) + cameraFar = 0.1f; + else + cameraFar = 100000.0f; + + InParameters->Set("DLSSG.CameraFar", cameraFar); + } + else if (cameraFar == INFINITY) + { + cameraFar = 100000.0f; + InParameters->Set("DLSSG.CameraFar", cameraFar); + } + + // Workaround for a bug in Nukem's mod + // if (uint32_t LowresMvec = 0; InParameters->Get("DLSSG.run_lowres_mvec_pass", &LowresMvec) == + // NVSDK_NGX_Result_Success && LowresMvec == 1) { + InParameters->Set("DLSSG.MVecsSubrectWidth", 0U); + InParameters->Set("DLSSG.MVecsSubrectHeight", 0U); + //} + } + + // Make a copy of the depth going to the frame generator + // Fixes an issue with the depth being corrupted on AMD under Windows + ID3D12Resource* dlssgDepth = nullptr; + + if (Config::Instance()->MakeDepthCopy.value_or_default()) + InParameters->Get("DLSSG.Depth", &dlssgDepth); + + if (dlssgDepth) + { + D3D12_RESOURCE_DESC desc = dlssgDepth->GetDesc(); + + D3D12_HEAP_PROPERTIES heapProperties; + D3D12_HEAP_FLAGS heapFlags; + + static ID3D12Resource* copiedDlssgDepth = nullptr; + if (copiedDlssgDepth != nullptr) + { + copiedDlssgDepth->Release(); + copiedDlssgDepth = nullptr; + } + + if (dlssgDepth->GetHeapProperties(&heapProperties, &heapFlags) == S_OK) + { + auto result = State::Instance().currentD3D12Device->CreateCommittedResource( + &heapProperties, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, + IID_PPV_ARGS(&copiedDlssgDepth)); + + if (result == S_OK) + { + InCmdList->CopyResource(copiedDlssgDepth, dlssgDepth); + InParameters->Set( + "DLSSG.Depth", + (void*) copiedDlssgDepth); // cast to make sure it's void*, otherwise dlssg cries + } + else + { + LOG_ERROR("Making a new resource for DLSSG Depth has failed"); + } + } + else + { + LOG_ERROR("Getting heap properties has failed"); + } + } + NVSDK_NGX_Handle TempHandle = { .Id = InFeatureHandle->Id - DLSSG_MOD_ID_OFFSET }; return _DLSSG_D3D12_EvaluateFeature(InCmdList, &TempHandle, InParameters, InCallback); } + return NVSDK_NGX_Result_Fail; } @@ -380,14 +465,58 @@ class DLSSGMod static inline NVSDK_NGX_Result VULKAN_EvaluateFeature(VkCommandBuffer InCmdList, const NVSDK_NGX_Handle* InFeatureHandle, - const NVSDK_NGX_Parameter* InParameters, + NVSDK_NGX_Parameter* InParameters, PFN_NVSDK_NGX_ProgressCallback InCallback) { if (isVulkanAvailable() && InFeatureHandle->Id >= DLSSG_MOD_ID_OFFSET) { + if (!is120orNewer()) + { + // Workaround mostly for final fantasy xvi, keeping it from DX12 + uint32_t depthInverted = 0; + float cameraNear = 0; + float cameraFar = 0; + InParameters->Get("DLSSG.DepthInverted", &depthInverted); + InParameters->Get("DLSSG.CameraNear", &cameraNear); + InParameters->Get("DLSSG.CameraFar", &cameraFar); + + if (cameraNear == 0) + { + if (depthInverted) + cameraNear = 100000.0f; + else + cameraNear = 0.1f; + + InParameters->Set("DLSSG.CameraNear", cameraNear); + } + + if (cameraFar == 0) + { + if (depthInverted) + cameraFar = 0.1f; + else + cameraFar = 100000.0f; + + InParameters->Set("DLSSG.CameraFar", cameraFar); + } + else if (cameraFar == INFINITY) + { + cameraFar = 10000; + InParameters->Set("DLSSG.CameraFar", cameraFar); + } + + // Workaround for a bug in Nukem's mod, keeping it from DX12 + // if (uint32_t LowresMvec = 0; InParameters->Get("DLSSG.run_lowres_mvec_pass", &LowresMvec) == + // NVSDK_NGX_Result_Success && LowresMvec == 1) { + InParameters->Set("DLSSG.MVecsSubrectWidth", 0U); + InParameters->Set("DLSSG.MVecsSubrectHeight", 0U); + //} + } + NVSDK_NGX_Handle TempHandle = { .Id = InFeatureHandle->Id - DLSSG_MOD_ID_OFFSET }; return _DLSSG_VULKAN_EvaluateFeature(InCmdList, &TempHandle, InParameters, InCallback); } + return NVSDK_NGX_Result_Fail; } diff --git a/OptiScaler/inputs/NVNGX_DLSS_Dx12.cpp b/OptiScaler/inputs/NVNGX_DLSS_Dx12.cpp index 8f66d04c..d1df6269 100644 --- a/OptiScaler/inputs/NVNGX_DLSS_Dx12.cpp +++ b/OptiScaler/inputs/NVNGX_DLSS_Dx12.cpp @@ -1,13 +1,13 @@ #include "Util.h" #include "Config.h" -#include "DLSSG_Mod.h" #include "NVNGX_DLSS.h" #include "NVNGX_Parameter.h" #include "proxies/NVNGX_Proxy.h" #include +#include "FG/DLSSG_Mod.h" #include "FG/Upscaler_Inputs_Dx12.h" #include "hooks/HooksDx.h" @@ -182,8 +182,11 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_Init_Ext(unsigned long long InApp } } - DLSSGMod::InitDLSSGMod_Dx12(); - DLSSGMod::D3D12_Init_Ext(InApplicationId, InApplicationDataPath, InDevice, InSDKVersion, InFeatureInfo); + if (State::Instance().activeFgInput == FGInput::Nukems) + { + DLSSGMod::InitDLSSGMod_Dx12(); + DLSSGMod::D3D12_Init_Ext(InApplicationId, InApplicationDataPath, InDevice, InSDKVersion, InFeatureInfo); + } LOG_INFO("AppId: {0}", InApplicationId); LOG_INFO("SDK: {0:x}", (unsigned int) InSDKVersion); @@ -305,8 +308,11 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_Init(unsigned long long InApplica } } - DLSSGMod::InitDLSSGMod_Dx12(); - DLSSGMod::D3D12_Init(InApplicationId, InApplicationDataPath, InDevice, InFeatureInfo, InSDKVersion); + // if (State::Instance().activeFgInput == FGInput::Nukems) + //{ + // DLSSGMod::InitDLSSGMod_Dx12(); + // DLSSGMod::D3D12_Init(InApplicationId, InApplicationDataPath, InDevice, InFeatureInfo, InSDKVersion); + // } auto result = NVSDK_NGX_D3D12_Init_Ext(InApplicationId, InApplicationDataPath, InDevice, InSDKVersion, InFeatureInfo); @@ -430,7 +436,8 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_Shutdown(void) shutdown = false; - DLSSGMod::D3D12_Shutdown(); + if (State::Instance().activeFgInput == FGInput::Nukems) + DLSSGMod::D3D12_Shutdown(); State::Instance().NvngxDx12Inited = false; @@ -442,7 +449,8 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_Shutdown1(ID3D12Device* InDevice) shutdown = true; State::Instance().NvngxDx12Inited = false; - DLSSGMod::D3D12_Shutdown1(InDevice); + if (State::Instance().activeFgInput == FGInput::Nukems) + DLSSGMod::D3D12_Shutdown1(InDevice); // Added `&& !State::Instance().isShuttingDown` hack for crash on exit if (Config::Instance()->DLSSEnabled.value_or_default() && NVNGXProxy::IsDx12Inited() && @@ -538,7 +546,8 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_PopulateParameters_Impl(NVSDK_NGX InitNGXParameters(InParameters); - DLSSGMod::D3D12_PopulateParameters_Impl(InParameters); + if (State::Instance().activeFgInput == FGInput::Nukems) + DLSSGMod::D3D12_PopulateParameters_Impl(InParameters); return NVSDK_NGX_Result_Success; } @@ -579,7 +588,8 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_CreateFeature(ID3D12GraphicsComma if (InCmdList != nullptr) HookToCommandList(InCmdList); - if (DLSSGMod::isDx12Available() && InFeatureID == NVSDK_NGX_Feature_FrameGeneration) + if (State::Instance().activeFgInput == FGInput::Nukems && DLSSGMod::isDx12Available() && + InFeatureID == NVSDK_NGX_Feature_FrameGeneration) { auto result = DLSSGMod::D3D12_CreateFeature(InCmdList, InFeatureID, InParameters, OutHandle); LOG_INFO("Creating new modded DLSSG feature with HandleId: {0}", (*OutHandle)->Id); @@ -768,7 +778,7 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_ReleaseFeature(NVSDK_NGX_Handle* return NVSDK_NGX_Result_FAIL_FeatureNotFound; } } - else if (handleId >= DLSSG_MOD_ID_OFFSET) + else if (State::Instance().activeFgInput == FGInput::Nukems && handleId >= DLSSG_MOD_ID_OFFSET) { LOG_INFO("D3D12_ReleaseFeature modded DLSSG with HandleId: {0}", handleId); return DLSSGMod::D3D12_ReleaseFeature(InHandle); @@ -802,7 +812,8 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_GetFeatureRequirements( { LOG_DEBUG("for ({0})", (int) FeatureDiscoveryInfo->FeatureID); - DLSSGMod::InitDLSSGMod_Dx12(); + if (State::Instance().activeFgInput == FGInput::Nukems) + DLSSGMod::InitDLSSGMod_Dx12(); if (FeatureDiscoveryInfo->FeatureID == NVSDK_NGX_Feature_SuperSampling || ((DLSSGMod::isDx12Available() || Config::Instance()->FGInput == FGInput::DLSSG) && @@ -874,94 +885,8 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_EvaluateFeature(ID3D12GraphicsCom return NVSDK_NGX_Result_FAIL_FeatureNotFound; } } - else if (handleId >= DLSSG_MOD_ID_OFFSET) + else if (State::Instance().activeFgInput == FGInput::Nukems && handleId >= DLSSG_MOD_ID_OFFSET) { - if (!DLSSGMod::is120orNewer()) - { - // Workaround mostly for final fantasy xvi - uint32_t depthInverted = 0; - float cameraNear = 0; - float cameraFar = 0; - InParameters->Get("DLSSG.DepthInverted", &depthInverted); - InParameters->Get("DLSSG.CameraNear", &cameraNear); - InParameters->Get("DLSSG.CameraFar", &cameraFar); - - if (cameraNear == 0) - { - if (depthInverted) - cameraNear = 100000.0f; - else - cameraNear = 0.1f; - - InParameters->Set("DLSSG.CameraNear", cameraNear); - } - - if (cameraFar == 0) - { - if (depthInverted) - cameraFar = 0.1f; - else - cameraFar = 100000.0f; - - InParameters->Set("DLSSG.CameraFar", cameraFar); - } - else if (cameraFar == INFINITY) - { - cameraFar = 100000.0f; - InParameters->Set("DLSSG.CameraFar", cameraFar); - } - - // Workaround for a bug in Nukem's mod - // if (uint32_t LowresMvec = 0; InParameters->Get("DLSSG.run_lowres_mvec_pass", &LowresMvec) == - // NVSDK_NGX_Result_Success && LowresMvec == 1) { - InParameters->Set("DLSSG.MVecsSubrectWidth", 0U); - InParameters->Set("DLSSG.MVecsSubrectHeight", 0U); - //} - } - - // Make a copy of the depth going to the frame generator - // Fixes an issue with the depth being corrupted on AMD under Windows - ID3D12Resource* dlssgDepth = nullptr; - - if (Config::Instance()->MakeDepthCopy.value_or_default()) - InParameters->Get("DLSSG.Depth", &dlssgDepth); - - if (dlssgDepth) - { - D3D12_RESOURCE_DESC desc = dlssgDepth->GetDesc(); - - D3D12_HEAP_PROPERTIES heapProperties; - D3D12_HEAP_FLAGS heapFlags; - - static ID3D12Resource* copiedDlssgDepth = nullptr; - if (copiedDlssgDepth != nullptr) - { - copiedDlssgDepth->Release(); - copiedDlssgDepth = nullptr; - } - - if (dlssgDepth->GetHeapProperties(&heapProperties, &heapFlags) == S_OK) - { - auto result = D3D12Device->CreateCommittedResource(&heapProperties, D3D12_HEAP_FLAG_NONE, &desc, - D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, - IID_PPV_ARGS(&copiedDlssgDepth)); - if (result == S_OK) - { - InCmdList->CopyResource(copiedDlssgDepth, dlssgDepth); - InParameters->Set("DLSSG.Depth", - (void*) copiedDlssgDepth); // cast to make sure it's void*, otherwise dlssg cries - } - else - { - LOG_ERROR("Making a new resource for DLSSG Depth has failed"); - } - } - else - { - LOG_ERROR("Getting heap properties has failed"); - } - } - return DLSSGMod::D3D12_EvaluateFeature(InCmdList, InFeatureHandle, InParameters, InCallback); } @@ -1103,7 +1028,8 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_GetScratchBufferSize(NVSDK_NGX_Fe const NVSDK_NGX_Parameter* InParameters, size_t* OutSizeInBytes) { - if (DLSSGMod::isDx12Available() && InFeatureId == NVSDK_NGX_Feature_FrameGeneration) + if (State::Instance().activeFgInput == FGInput::Nukems && DLSSGMod::isDx12Available() && + InFeatureId == NVSDK_NGX_Feature_FrameGeneration) { return DLSSGMod::D3D12_GetScratchBufferSize(InFeatureId, InParameters, OutSizeInBytes); } diff --git a/OptiScaler/inputs/NVNGX_DLSS_Vk.cpp b/OptiScaler/inputs/NVNGX_DLSS_Vk.cpp index e1899136..ebfef234 100644 --- a/OptiScaler/inputs/NVNGX_DLSS_Vk.cpp +++ b/OptiScaler/inputs/NVNGX_DLSS_Vk.cpp @@ -1,13 +1,13 @@ #include "pch.h" #include "Util.h" +#include "Config.h" #include "resource.h" -#include "NVNGX_Parameter.h" #include "NVNGX_DLSS.h" +#include "FG/DLSSG_Mod.h" +#include "NVNGX_Parameter.h" #include "proxies/NVNGX_Proxy.h" -#include "DLSSG_Mod.h" -#include "Config.h" #include "upscalers/fsr2/FSR2Feature_Vk.h" #include "upscalers/dlss/DLSSFeature_Vk.h" #include "upscalers/dlssd/DLSSDFeature_Vk.h" @@ -17,8 +17,8 @@ #include "hooks/HooksVk.h" -#include #include +#include VkInstance vkInstance; VkPhysicalDevice vkPD; @@ -953,49 +953,6 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_VULKAN_EvaluateFeature(VkCommandBuffer } else if (handleId >= DLSSG_MOD_ID_OFFSET) { - if (!DLSSGMod::is120orNewer()) - { - // Workaround mostly for final fantasy xvi, keeping it from DX12 - uint32_t depthInverted = 0; - float cameraNear = 0; - float cameraFar = 0; - InParameters->Get("DLSSG.DepthInverted", &depthInverted); - InParameters->Get("DLSSG.CameraNear", &cameraNear); - InParameters->Get("DLSSG.CameraFar", &cameraFar); - - if (cameraNear == 0) - { - if (depthInverted) - cameraNear = 100000.0f; - else - cameraNear = 0.1f; - - InParameters->Set("DLSSG.CameraNear", cameraNear); - } - - if (cameraFar == 0) - { - if (depthInverted) - cameraFar = 0.1f; - else - cameraFar = 100000.0f; - - InParameters->Set("DLSSG.CameraFar", cameraFar); - } - else if (cameraFar == INFINITY) - { - cameraFar = 10000; - InParameters->Set("DLSSG.CameraFar", cameraFar); - } - - // Workaround for a bug in Nukem's mod, keeping it from DX12 - // if (uint32_t LowresMvec = 0; InParameters->Get("DLSSG.run_lowres_mvec_pass", &LowresMvec) == - // NVSDK_NGX_Result_Success && LowresMvec == 1) { - InParameters->Set("DLSSG.MVecsSubrectWidth", 0U); - InParameters->Set("DLSSG.MVecsSubrectHeight", 0U); - //} - } - return DLSSGMod::VULKAN_EvaluateFeature(InCmdList, InFeatureHandle, InParameters, InCallback); } diff --git a/OptiScaler/menu/menu_common.cpp b/OptiScaler/menu/menu_common.cpp index 01da7f1a..dec9dd16 100644 --- a/OptiScaler/menu/menu_common.cpp +++ b/OptiScaler/menu/menu_common.cpp @@ -8,7 +8,7 @@ #include #include -#include "DLSSG_Mod.h" +#include #include