Skip to content
Open
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
42 changes: 38 additions & 4 deletions OptiScaler/dlssnr/DlssNrFeature_Vk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ using PFN_VkInit = int(__cdecl*)(const wchar_t*, const wchar_t*, void*, void*, v
using PFN_VkCreate = void*(__cdecl*)(void*, void*, unsigned int, unsigned int, int, float, int, float, float, float,
int, int);
using PFN_VkEvaluate = int(__cdecl*)(void*, void*, void*, void*, void*, void*, void*, unsigned int, unsigned int,
unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
unsigned int, unsigned int, int, int, float, int, float, float, float, int, float,
float);
using PFN_VkRelease = void(__cdecl*)(void*);
Expand Down Expand Up @@ -602,8 +603,10 @@ void EvaluateAfterUpscaleVk(VkCommandBuffer cmdBuffer, NVSDK_NGX_Parameter* para

const uint32_t width = colour->Resource.ImageViewInfo.Width;
const uint32_t height = colour->Resource.ImageViewInfo.Height;
const uint32_t guideWidth = depth->Resource.ImageViewInfo.Width;
const uint32_t guideHeight = depth->Resource.ImageViewInfo.Height;
uint32_t guideWidth = depth->Resource.ImageViewInfo.Width;
uint32_t guideHeight = depth->Resource.ImageViewInfo.Height;
const uint32_t motionAllocationWidth = motion->Resource.ImageViewInfo.Width;
const uint32_t motionAllocationHeight = motion->Resource.ImageViewInfo.Height;

if (width == 0 || height == 0)
return;
Expand Down Expand Up @@ -801,6 +804,33 @@ void EvaluateAfterUpscaleVk(VkCommandBuffer cmdBuffer, NVSDK_NGX_Parameter* para
const unsigned int createFlags = GameCreateFlags(params);
const bool gameSaysHdr = (createFlags & NVSDK_NGX_DLSS_Feature_Flags_IsHDR) != 0;
const bool depthInverted = (createFlags & NVSDK_NGX_DLSS_Feature_Flags_DepthInverted) != 0;
const bool lowResolutionMotion = (createFlags & NVSDK_NGX_DLSS_Feature_Flags_MVLowRes) != 0;

uint32_t renderWidth = guideWidth;
uint32_t renderHeight = guideHeight;
params->Get(NVSDK_NGX_Parameter_DLSS_Render_Subrect_Dimensions_Width, &renderWidth);
params->Get(NVSDK_NGX_Parameter_DLSS_Render_Subrect_Dimensions_Height, &renderHeight);

uint32_t depthBaseX = 0, depthBaseY = 0, motionBaseX = 0, motionBaseY = 0;
params->Get(NVSDK_NGX_Parameter_DLSS_Input_Depth_Subrect_Base_X, &depthBaseX);
params->Get(NVSDK_NGX_Parameter_DLSS_Input_Depth_Subrect_Base_Y, &depthBaseY);
params->Get(NVSDK_NGX_Parameter_DLSS_Input_MV_SubrectBase_X, &motionBaseX);
params->Get(NVSDK_NGX_Parameter_DLSS_Input_MV_SubrectBase_Y, &motionBaseY);

depthBaseX = std::min(depthBaseX, guideWidth);
depthBaseY = std::min(depthBaseY, guideHeight);
guideWidth = std::min(renderWidth, guideWidth - depthBaseX);
guideHeight = std::min(renderHeight, guideHeight - depthBaseY);
motionBaseX = std::min(motionBaseX, motionAllocationWidth);
motionBaseY = std::min(motionBaseY, motionAllocationHeight);
const uint32_t motionWidth = std::min(lowResolutionMotion ? renderWidth : width,
motionAllocationWidth - motionBaseX);
const uint32_t motionHeight = std::min(lowResolutionMotion ? renderHeight : height,
motionAllocationHeight - motionBaseY);

float mvScaleX = 1.0f, mvScaleY = 1.0f;
params->Get(NVSDK_NGX_Parameter_MV_Scale_X, &mvScaleX);
params->Get(NVSDK_NGX_Parameter_MV_Scale_Y, &mvScaleY);

// The game asking the upscaler to forget its history -- a cut, a teleport, a load. Same omission
// as the D3D12 path had: the model's history was only ever reset by things that happened to us,
Expand Down Expand Up @@ -1045,12 +1075,16 @@ void EvaluateAfterUpscaleVk(VkCommandBuffer cmdBuffer, NVSDK_NGX_Parameter* para

Transition(cmdBuffer, g_vk.output, VK_IMAGE_LAYOUT_GENERAL);

const float mvToWorkX = width != 0 ? (float) workWidth / (float) width : 1.0f;
const float mvToWorkY = height != 0 ? (float) workHeight / (float) height : 1.0f;
const int evaluated = g_vk.evaluate(
(void*) cmdBuffer, g_vk.feature, g_vk.capabilityParams, &modelInput->ngx, depth, motion, &g_vk.output.ngx,
workWidth, workHeight, guideWidth, guideHeight, depthInverted ? 1 : 0, g_vk.reset ? 1 : 0,
workWidth, workHeight, guideWidth, guideHeight, motionWidth, motionHeight, depthBaseX, depthBaseY,
motionBaseX, motionBaseY, depthInverted ? 1 : 0, g_vk.reset ? 1 : 0,
cfg.DlssNrIntensity.value_or_default(), (int) cfg.DlssNrStyle.value_or_default(),
cfg.DlssNrLocalStructure.value_or_default(), cfg.DlssNrLocalTone.value_or_default(),
cfg.DlssNrSkinStructure.value_or_default(), cfg.DlssNrAutoMask.value_or_default() ? 1 : 0, 1.0f, 1.0f);
cfg.DlssNrSkinStructure.value_or_default(), cfg.DlssNrAutoMask.value_or_default() ? 1 : 0,
mvScaleX * mvToWorkX, mvScaleY * mvToWorkY);

g_vk.reset = false;
g_vk.frames++;
Expand Down
17 changes: 9 additions & 8 deletions OptiScaler/dlssnr/DlssNr_Proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ void Release()
unsigned int Run(ID3D12GraphicsCommandList* cmdList, ID3D12Device* device, ID3D12Resource* color,
ID3D12Resource* depth, ID3D12Resource* motion, ID3D12Resource* output,
unsigned int width, unsigned int height, unsigned int guideWidth,
unsigned int guideHeight, bool depthInverted, bool reset, float mvScaleX,
float mvScaleY)
unsigned int guideHeight, unsigned int motionWidth, unsigned int motionHeight,
unsigned int depthBaseX, unsigned int depthBaseY, unsigned int motionBaseX,
unsigned int motionBaseY, bool depthInverted, bool reset, float mvScaleX, float mvScaleY)
{
if (g_proxy.failed || !Available())
return 0;
Expand Down Expand Up @@ -266,14 +267,14 @@ unsigned int Run(ID3D12GraphicsCommandList* cmdList, ID3D12Device* device, ID3D1
SetUInt(params, "DLSSNR.OutputSubrectBaseY", 0u);
SetUInt(params, "DLSSNR.OutputSubrectWidth", width);
SetUInt(params, "DLSSNR.OutputSubrectHeight", height);
SetUInt(params, "DLSSNR.DepthSubrectBaseX", 0u);
SetUInt(params, "DLSSNR.DepthSubrectBaseY", 0u);
SetUInt(params, "DLSSNR.DepthSubrectBaseX", depthBaseX);
SetUInt(params, "DLSSNR.DepthSubrectBaseY", depthBaseY);
SetUInt(params, "DLSSNR.DepthSubrectWidth", guideWidth);
SetUInt(params, "DLSSNR.DepthSubrectHeight", guideHeight);
SetUInt(params, "DLSSNR.MVecSubrectBaseX", 0u);
SetUInt(params, "DLSSNR.MVecSubrectBaseY", 0u);
SetUInt(params, "DLSSNR.MVecSubrectWidth", guideWidth);
SetUInt(params, "DLSSNR.MVecSubrectHeight", guideHeight);
SetUInt(params, "DLSSNR.MVecSubrectBaseX", motionBaseX);
SetUInt(params, "DLSSNR.MVecSubrectBaseY", motionBaseY);
SetUInt(params, "DLSSNR.MVecSubrectWidth", motionWidth);
SetUInt(params, "DLSSNR.MVecSubrectHeight", motionHeight);

// The game's own encoding, passed through. Deriving this from the resolutions was a guess, and
// at native resolution it came out as exactly 1.0 -- so a game using normalised vectors was
Expand Down
5 changes: 3 additions & 2 deletions OptiScaler/dlssnr/DlssNr_Proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ bool Available();
unsigned int Run(ID3D12GraphicsCommandList* cmdList, ID3D12Device* device, ID3D12Resource* color,
ID3D12Resource* depth, ID3D12Resource* motion, ID3D12Resource* output,
unsigned int width, unsigned int height, unsigned int guideWidth,
unsigned int guideHeight, bool depthInverted, bool reset, float mvScaleX,
float mvScaleY);
unsigned int guideHeight, unsigned int motionWidth, unsigned int motionHeight,
unsigned int depthBaseX, unsigned int depthBaseY, unsigned int motionBaseX,
unsigned int motionBaseY, bool depthInverted, bool reset, float mvScaleX, float mvScaleY);

// Drops the feature and its parameter block, for a resolution change or shutdown.
void Release();
Expand Down
32 changes: 19 additions & 13 deletions OptiScaler/dlssnr/forwarder/dlssnr_forwarder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,9 @@ __declspec(dllexport) int dlssnr_vk_evaluate(void *cmdBuffer, void *feature, voi
void *color, void *depth, void *motion, void *output,
unsigned int width, unsigned int height,
unsigned int guideWidth, unsigned int guideHeight,
unsigned int motionWidth, unsigned int motionHeight,
unsigned int depthBaseX, unsigned int depthBaseY,
unsigned int motionBaseX, unsigned int motionBaseY,
int depthInverted, int reset, float intensity, int style,
float localStructure, float localTone, float skinStructure,
int useAutoMask, float mvScaleX, float mvScaleY) {
Expand Down Expand Up @@ -696,14 +699,14 @@ __declspec(dllexport) int dlssnr_vk_evaluate(void *cmdBuffer, void *feature, voi
setUInt(capabilityParams, "DLSSNR.OutputSubrectBaseY", 0);
setUInt(capabilityParams, "DLSSNR.OutputSubrectWidth", width);
setUInt(capabilityParams, "DLSSNR.OutputSubrectHeight", height);
setUInt(capabilityParams, "DLSSNR.DepthSubrectBaseX", 0);
setUInt(capabilityParams, "DLSSNR.DepthSubrectBaseY", 0);
setUInt(capabilityParams, "DLSSNR.DepthSubrectBaseX", depthBaseX);
setUInt(capabilityParams, "DLSSNR.DepthSubrectBaseY", depthBaseY);
setUInt(capabilityParams, "DLSSNR.DepthSubrectWidth", guideWidth);
setUInt(capabilityParams, "DLSSNR.DepthSubrectHeight", guideHeight);
setUInt(capabilityParams, "DLSSNR.MVecSubrectBaseX", 0);
setUInt(capabilityParams, "DLSSNR.MVecSubrectBaseY", 0);
setUInt(capabilityParams, "DLSSNR.MVecSubrectWidth", guideWidth);
setUInt(capabilityParams, "DLSSNR.MVecSubrectHeight", guideHeight);
setUInt(capabilityParams, "DLSSNR.MVecSubrectBaseX", motionBaseX);
setUInt(capabilityParams, "DLSSNR.MVecSubrectBaseY", motionBaseY);
setUInt(capabilityParams, "DLSSNR.MVecSubrectWidth", motionWidth);
setUInt(capabilityParams, "DLSSNR.MVecSubrectHeight", motionHeight);

// The game's own encoding, passed through rather than derived. Deriving it from the resolutions
// came out as exactly 1.0 at native, which told the model almost nothing had moved.
Expand Down Expand Up @@ -785,7 +788,10 @@ __declspec(dllexport) int dlssnr_call_evaluate(ID3D12GraphicsCommandList *cmd, v
ID3D12Resource *depth, ID3D12Resource *motion,
ID3D12Resource *output, unsigned int width,
unsigned int height, unsigned int guideWidth,
unsigned int guideHeight, int depthInverted, int reset,
unsigned int guideHeight, unsigned int motionWidth,
unsigned int motionHeight, unsigned int depthBaseX,
unsigned int depthBaseY, unsigned int motionBaseX,
unsigned int motionBaseY, int depthInverted, int reset,
float intensity, int style, float localStructure,
float localTone, float skinStructure, int useAutoMask,
float mvScaleX, float mvScaleY) {
Expand Down Expand Up @@ -813,14 +819,14 @@ __declspec(dllexport) int dlssnr_call_evaluate(ID3D12GraphicsCommandList *cmd, v
setUInt(capabilityParams, "DLSSNR.OutputSubrectBaseY", 0);
setUInt(capabilityParams, "DLSSNR.OutputSubrectWidth", width);
setUInt(capabilityParams, "DLSSNR.OutputSubrectHeight", height);
setUInt(capabilityParams, "DLSSNR.DepthSubrectBaseX", 0);
setUInt(capabilityParams, "DLSSNR.DepthSubrectBaseY", 0);
setUInt(capabilityParams, "DLSSNR.DepthSubrectBaseX", depthBaseX);
setUInt(capabilityParams, "DLSSNR.DepthSubrectBaseY", depthBaseY);
setUInt(capabilityParams, "DLSSNR.DepthSubrectWidth", guideWidth);
setUInt(capabilityParams, "DLSSNR.DepthSubrectHeight", guideHeight);
setUInt(capabilityParams, "DLSSNR.MVecSubrectBaseX", 0);
setUInt(capabilityParams, "DLSSNR.MVecSubrectBaseY", 0);
setUInt(capabilityParams, "DLSSNR.MVecSubrectWidth", guideWidth);
setUInt(capabilityParams, "DLSSNR.MVecSubrectHeight", guideHeight);
setUInt(capabilityParams, "DLSSNR.MVecSubrectBaseX", motionBaseX);
setUInt(capabilityParams, "DLSSNR.MVecSubrectBaseY", motionBaseY);
setUInt(capabilityParams, "DLSSNR.MVecSubrectWidth", motionWidth);
setUInt(capabilityParams, "DLSSNR.MVecSubrectHeight", motionHeight);

// The game's own encoding, passed through. Deriving this from the resolutions was a guess, and at
// native resolution it came out as exactly 1.0 -- so a game using normalised vectors was telling
Expand Down
9 changes: 9 additions & 0 deletions OptiScaler/shaders/dlssnr/DlssNr_Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ struct DlssNrFrameInfo
// available and is what gets used.
unsigned int RenderSubrectWidth = 0;
unsigned int RenderSubrectHeight = 0;

unsigned int DepthSubrectBaseX = 0;
unsigned int DepthSubrectBaseY = 0;
unsigned int MotionSubrectBaseX = 0;
unsigned int MotionSubrectBaseY = 0;

// DLSS permits motion vectors at either render or output resolution. This flag comes from the
// feature-create flags and decides which valid-region dimensions apply to the motion texture.
bool MotionVectorsLowResolution = false;
};

struct alignas(256) DlssNrConstants
Expand Down
Loading