Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add dlss support WIP #555

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 52 additions & 6 deletions src/Streamline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,23 @@ void Streamline::Initialize_preDevice()

sl::Preferences pref;

sl::Feature featuresToLoad[] = { sl::kFeatureDLSS_G, sl::kFeatureReflex };
sl::Feature featuresToLoad[] = { sl::kFeatureDLSS, sl::kFeatureDLSS_G, sl::kFeatureReflex };
// sl::Feature featuresToLoad[] = { sl::kFeatureDLSS };
pref.featuresToLoad = featuresToLoad;
pref.numFeaturesToLoad = _countof(featuresToLoad);

pref.logLevel = sl::LogLevel::eOff;
pref.logLevel = sl::LogLevel::eVerbose;
pref.logMessageCallback = LoggingCallback;
pref.showConsole = true;

const wchar_t* pathsToPlugins[] = { L"Data/SKSE/Plugins/Streamline" };
pref.pathsToPlugins = pathsToPlugins;
pref.numPathsToPlugins = _countof(pathsToPlugins);
// const wchar_t* pathsToPlugins[] = { L"Data/SKSE/Plugins/Streamline" };
// pref.pathsToPlugins = pathsToPlugins;
// pref.numPathsToPlugins = _countof(pathsToPlugins);

pref.engine = sl::EngineType::eCustom;
pref.engineVersion = "1.0.0";
pref.projectId = "f8776929-c969-43bd-ac2b-294b4de58aac";
pref.flags |= sl::PreferenceFlags::eUseManualHooking;

pref.renderAPI = sl::RenderAPI::eD3D11;

Expand Down Expand Up @@ -107,6 +110,10 @@ void Streamline::Initialize_preDevice()
void Streamline::Initialize_postDevice()
{
// Hook up all of the feature functions using the sl function slGetFeatureFunction
slGetFeatureFunction(sl::kFeatureDLSS, "slDLSSGetOptimalSettings", (void*&)slDLSSGetOptimalSettings);
slGetFeatureFunction(sl::kFeatureDLSS, "slDLSSGetState", (void*&)slDLSSGetState);
slGetFeatureFunction(sl::kFeatureDLSS, "slDLSSSetOptions", (void*&)slDLSSSetOptions);

slGetFeatureFunction(sl::kFeatureDLSS_G, "slDLSSGGetState", (void*&)slDLSSGGetState);
slGetFeatureFunction(sl::kFeatureDLSS_G, "slDLSSGSetOptions", (void*&)slDLSSGSetOptions);

Expand All @@ -127,6 +134,25 @@ void Streamline::Initialize_postDevice()
} else {
logger::info("[Streamline] Sucessfully set reflex options");
}

sl::DLSSOptimalSettings dlssSettings;
sl::DLSSOptions dlssOptions;
// These are populated based on user selection in the UI
dlssOptions.mode = sl::DLSSMode::eBalanced; //myUI->getDLSSMode(); // e.g. sl::eDLSSModeBalanced;
dlssOptions.outputWidth = 1920; // e.g 1920;
dlssOptions.outputHeight = 1080; // e.g. 1080;
// Now let's check what should our rendering resolution be
if (SL_FAILED(result, slDLSSGetOptimalSettings(dlssOptions, dlssSettings))) {
logger::error("[Streamline] Failed to get optimal DLSS options");
} else {
logger::error("[Streamline] Sucessfully fetched optimal DLSS options");
}

if (SL_FAILED(result, slDLSSSetOptions(viewport, dlssOptions))) {
logger::error("[Streamline] Could not enable DLSS");
} else {
logger::error("[Streamline] Successfully enabled DLSS");
}
}

HRESULT Streamline::CreateDXGIFactory(REFIID riid, void** ppFactory)
Expand Down Expand Up @@ -164,7 +190,21 @@ HRESULT Streamline::CreateDeviceAndSwapChain(IDXGIAdapter* pAdapter,
return S_OK;
}

bool featureLoaded = false;
bool dlssLoaded = false;
slIsFeatureLoaded(sl::kFeatureDLSS, dlssLoaded);
if (dlssLoaded) {
logger::info("[Streamline] DLSS feature is loaded");
} else {
logger::info("[Streamline] DLSS feature is not loaded");

sl::FeatureRequirements dlss_requirements;
sl::Result result = slGetFeatureRequirements(sl::kFeatureDLSS, dlss_requirements);
if (result != sl::Result::eOk) {
logger::info("[Streamline] DLSS feature failed to load due to: {}", magic_enum::enum_name(result));
}
}

bool featureLoaded = true;
slIsFeatureLoaded(sl::kFeatureDLSS_G, featureLoaded);

if (featureLoaded) {
Expand All @@ -187,6 +227,12 @@ HRESULT Streamline::CreateDeviceAndSwapChain(IDXGIAdapter* pAdapter,
adapterInfo.deviceLUID = (uint8_t*)&adapterDesc.AdapterLuid;
adapterInfo.deviceLUIDSizeInBytes = sizeof(LUID);

if (slIsFeatureSupported(sl::kFeatureDLSS, adapterInfo) == sl::Result::eOk) {
logger::info("[Streamline] DLSS is supported on this adapter");
} else {
logger::info("[Streamline] DLSS is not supported on this adapter");
}

if (slIsFeatureSupported(sl::kFeatureDLSS_G, adapterInfo) == sl::Result::eOk) {
logger::info("[Streamline] Frame generation is supported on this adapter");
} else {
Expand Down
6 changes: 6 additions & 0 deletions src/Streamline.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Buffer.h"
#include "State.h"

#define NV_WINDOWS
#include <sl.h>
#include <sl_consts.h>
#include <sl_dlss.h>
Expand Down Expand Up @@ -48,6 +49,11 @@ class Streamline
PFun_slGetNewFrameToken* slGetNewFrameToken{};
PFun_slSetD3DDevice* slSetD3DDevice{};

// DLSS specific functions
PFun_slDLSSGetOptimalSettings* slDLSSGetOptimalSettings{};
PFun_slDLSSGetState* slDLSSGetState{};
PFun_slDLSSSetOptions* slDLSSSetOptions{};

// DLSSG specific functions
PFun_slDLSSGGetState* slDLSSGGetState{};
PFun_slDLSSGSetOptions* slDLSSGSetOptions{};
Expand Down
Loading