Skip to content

Commit

Permalink
still cleaning leftovers from cas
Browse files Browse the repository at this point in the history
  • Loading branch information
cdozdil committed May 9, 2024
1 parent 8f1534b commit f76b6b0
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 11 deletions.
1 change: 1 addition & 0 deletions OptiScaler/OptiScaler.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ copy $(SolutionDir)nvngx.ini $(SolutionDir)x64\Release\a\</Command>
<ClCompile Include="imgui\Imgui_Dx11.cpp" />
<ClCompile Include="imgui\Imgui_Dx12.cpp" />
<ClCompile Include="Logger.cpp" />
<ClCompile Include="NVNGX.cpp" />
<ClCompile Include="NVNGX_DLSS_Dx11.cpp" />
<ClCompile Include="NVNGX_DLSS_Dx12.cpp" />
<ClCompile Include="dllmain.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions OptiScaler/OptiScaler.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@
<ClCompile Include="rcas\RCAS_Dx12.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="NVNGX.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Library Include="vulkan\vulkan-1.lib" />
Expand Down
59 changes: 56 additions & 3 deletions OptiScaler/backends/dlss/DLSSFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "../../Config.h"
#include "../../Util.h"
#include "../../pch.h"
#include "../../detours/detours.h"


#pragma region spoofing hooks for 16xx

Expand Down Expand Up @@ -105,7 +107,6 @@ NVSDK_NGX_Result __stdcall Hooked_Dx11_GetFeatureRequirements(IDXGIAdapter* Adap
return result;
}


void HookNvApi()
{
if (OriginalNvAPI_QueryInterface != nullptr)
Expand Down Expand Up @@ -746,6 +747,58 @@ void DLSSFeature::GetFeatureCommonInfo(NVSDK_NGX_FeatureCommonInfo* fcInfo)
fcInfo->PathListInfo.Length = static_cast<unsigned int>(Config::Instance()->NVNGX_FeatureInfo_Paths.size());
}

void DLSSFeature::ReadVersion()
{
PFN_NVSDK_NGX_GetSnippetVersion _GetSnippetVersion = nullptr;

_GetSnippetVersion = (PFN_NVSDK_NGX_GetSnippetVersion)DetourFindFunction("nvngx_dlss.dll", "NVSDK_NGX_GetSnippetVersion");

if (_GetSnippetVersion != nullptr)
{
auto result = _GetSnippetVersion();

_version.major = (result & 0x00FF0000) / 0x00010000;
_version.minor = (result & 0x0000FF00) / 0x00000100;
_version.patch = result & 0x000000FF / 0x00000001;

spdlog::info("DLSSFeature::ReadVersion DLSS v{0}.{1}.{2} loaded.", _version.major, _version.minor, _version.patch);
return;
}

for (size_t i = 0; i < Config::Instance()->NVNGX_FeatureInfo_Paths.size(); ++i)
{
auto path = std::filesystem::path(Config::Instance()->NVNGX_FeatureInfo_Paths[i].c_str());
auto file = path.parent_path() / L"nvngx_dlss.dll";

auto dlssModule = LoadLibraryW(file.wstring().c_str());

if (dlssModule)
{

_GetSnippetVersion = (PFN_NVSDK_NGX_GetSnippetVersion)GetProcAddress(dlssModule, "NVSDK_NGX_GetSnippetVersion");

if (_GetSnippetVersion != nullptr)
{
auto result = _GetSnippetVersion();

_version.major = (result & 0x00FF0000) / 0x00010000;
_version.minor = (result & 0x0000FF00) / 0x00000100;
_version.patch = result & 0x000000FF / 0x00000001;

spdlog::info("DLSSFeature::ReadVersion DLSS v{0}.{1}.{2} loaded.", _version.major, _version.minor, _version.patch);
}

_GetSnippetVersion = nullptr;
FreeLibrary(dlssModule);

if (_version.major != 0)
return;
}
}

spdlog::info("DLSSFeature::ReadVersion GetProcAddress for NVSDK_NGX_GetSnippetVersion failed!");
}

DLSSFeature::DLSSFeature(unsigned int handleId, const NVSDK_NGX_Parameter* InParameters) : IFeature(handleId, InParameters)
{
if (_nvngx == nullptr)
Expand All @@ -767,7 +820,7 @@ DLSSFeature::DLSSFeature(unsigned int handleId, const NVSDK_NGX_Parameter* InPar
{
spdlog::info("DLSSFeature::DLSSFeature _nvngx.dll loaded from {0}", path.string());
_moduleLoaded = true;
return;
break;
}

path = cfgPath / L"nvngx.dll";
Expand All @@ -778,7 +831,7 @@ DLSSFeature::DLSSFeature(unsigned int handleId, const NVSDK_NGX_Parameter* InPar
{
spdlog::info("DLSSFeature::DLSSFeature nvngx.dll loaded from {0}", path.string());
_moduleLoaded = true;
return;
break;
}
}

Expand Down
5 changes: 4 additions & 1 deletion OptiScaler/backends/dlss/DLSSFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
#include "../../pch.h"
#include <string>

typedef uint32_t(*PFN_NVSDK_NGX_GetSnippetVersion)(void);

class DLSSFeature : public virtual IFeature
{
private:
feature_version _version = { 0, 0, 0 };
inline static HMODULE _nvngx = nullptr;

protected:
NVSDK_NGX_Parameter* Parameters = nullptr;
NVSDK_NGX_Handle _dlssHandle = {};
Expand All @@ -27,6 +29,7 @@ class DLSSFeature : public virtual IFeature
public:
feature_version Version() final { return feature_version{ _version.major, _version.minor, _version.patch }; }
const char* Name() override { return "DLSS"; }
void ReadVersion();

DLSSFeature(unsigned int handleId, const NVSDK_NGX_Parameter* InParameters);

Expand Down
2 changes: 2 additions & 0 deletions OptiScaler/backends/dlss/DLSSFeature_Dx11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ bool DLSSFeatureDx11::Init(ID3D11Device* InDevice, ID3D11DeviceContext* InContex
break;
}

ReadVersion();

initResult = true;

} while (false);
Expand Down
15 changes: 14 additions & 1 deletion OptiScaler/backends/dlss/DLSSFeature_Dx12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ bool DLSSFeatureDx12::Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* In

//delay between init and create feature
std::this_thread::sleep_for(std::chrono::milliseconds(500));


}

if (_AllocateParameters != nullptr)
Expand Down Expand Up @@ -109,6 +111,8 @@ bool DLSSFeatureDx12::Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* In
break;
}

ReadVersion();

initResult = true;

} while (false);
Expand Down Expand Up @@ -137,6 +141,12 @@ bool DLSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, const N
return false;
}

if (!IsInited())
{
spdlog::error("DLSSFeatureDx12::Evaluate Not inited!");
return false;
}

NVSDK_NGX_Result nvResult;

if (_EvaluateFeature != nullptr)
Expand Down Expand Up @@ -342,12 +352,15 @@ DLSSFeatureDx12::~DLSSFeatureDx12()

if (_ReleaseFeature != nullptr)
_ReleaseFeature(_p_dlssHandle);

if (RCAS != nullptr && RCAS.get() != nullptr)
RCAS.reset();
}

float DLSSFeatureDx12::GetSharpness(const NVSDK_NGX_Parameter* InParameters)
{
if (Config::Instance()->OverrideSharpness.value_or(false))
return Config::Instance()->Sharpness.value_or(0.3);
return Config::Instance()->Sharpness.value_or(0.3f);

float sharpness = 0.0f;
InParameters->Get(NVSDK_NGX_Parameter_Sharpness, &sharpness);
Expand Down
2 changes: 2 additions & 0 deletions OptiScaler/backends/dlss/DLSSFeature_Vk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ bool DLSSFeatureVk::Init(VkInstance InInstance, VkPhysicalDevice InPD, VkDevice
break;
}

ReadVersion();

initResult = true;

} while (false);
Expand Down
7 changes: 1 addition & 6 deletions OptiScaler/backends/xess/XeSSFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,6 @@ XeSSFeature::~XeSSFeature()
if (RCAS != nullptr && RCAS.get() != nullptr)
RCAS.reset();

//if (CAS != nullptr && CAS.get() != nullptr)
// CAS.reset();

if (_localPipeline != nullptr)
{
_localPipeline->Release();
Expand All @@ -458,15 +455,13 @@ XeSSFeature::~XeSSFeature()
}

if (_moduleLoaded && _libxess != nullptr)
{
FreeLibrary(_libxess);
}
}

float XeSSFeature::GetSharpness(const NVSDK_NGX_Parameter* InParameters)
{
if (Config::Instance()->OverrideSharpness.value_or(false))
return Config::Instance()->Sharpness.value_or(0.3);
return Config::Instance()->Sharpness.value_or(0.3f);

float sharpness = 0.0f;
InParameters->Get(NVSDK_NGX_Parameter_Sharpness, &sharpness);
Expand Down

0 comments on commit f76b6b0

Please sign in to comment.