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

Shortcut for cycling scalers and filters / Output in MangoApp #895

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ meson install -C build/ --skip-subprojects
* **Super + O** : Decrease FSR sharpness by 1
* **Super + S** : Take screenshot (currently goes to `/tmp/gamescope_$DATE.png`)

* **Super + X** : Cycle upscalers (Auto, Integer, Fit, Fill, Stretch)
* **Super + Z** : Cycle upscaling filters (Linear, Nearest, FSR, NIS)

## Examples

On any X11 or Wayland desktop, you can set the Steam launch arguments of your game as follows:
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ GamescopeUpscaleScaler g_upscaleScaler = GamescopeUpscaleScaler::AUTO;

GamescopeUpscaleFilter g_wantedUpscaleFilter = GamescopeUpscaleFilter::LINEAR;
GamescopeUpscaleScaler g_wantedUpscaleScaler = GamescopeUpscaleScaler::AUTO;
int g_upscaleFilterSharpness = 2;
uint8_t g_upscaleFilterSharpness = 2;

bool g_bBorderlessOutputWindow = false;

Expand Down
14 changes: 10 additions & 4 deletions src/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,34 @@ extern bool g_bFullscreen;

extern bool g_bGrabbed;

enum class GamescopeUpscaleFilter : uint32_t
enum class GamescopeUpscaleFilter : uint8_t
{
LINEAR = 0,
NEAREST,
FSR,
NIS
NIS,

_FIRST = LINEAR,
_LAST = NIS
};

enum class GamescopeUpscaleScaler : uint32_t
enum class GamescopeUpscaleScaler : uint8_t
{
AUTO,
INTEGER,
FIT,
FILL,
STRETCH,

_FIRST = AUTO,
_LAST = STRETCH
};

extern GamescopeUpscaleFilter g_upscaleFilter;
extern GamescopeUpscaleScaler g_upscaleScaler;
extern GamescopeUpscaleFilter g_wantedUpscaleFilter;
extern GamescopeUpscaleScaler g_wantedUpscaleScaler;
extern int g_upscaleFilterSharpness;
extern uint8_t g_upscaleFilterSharpness;

extern bool g_bBorderlessOutputWindow;

Expand Down
10 changes: 8 additions & 2 deletions src/mangoapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ struct mangoapp_msg_v1 {

uint32_t pid;
uint64_t visible_frametime_ns;
uint8_t fsrUpscale;
uint8_t fsrSharpness;
uint8_t fsrUpscale; // deprecated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually showed whether FSR was doing anything not whether it was selected.

it 1280x800 game on 1280x800 output would show disabled here even if FSR was disabled.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I understand. With a quick look at the sources it seems to be only activated if upscaling is necessary.

gamescope/src/steamcompmgr.cpp

Lines 2263 to 2265 in 7a1fe2d

bool needsScaling = frameInfo.layers[0].scale.x < 0.999f && frameInfo.layers[0].scale.y < 0.999f;
frameInfo.useFSRLayer0 = g_upscaleFilter == GamescopeUpscaleFilter::FSR && needsScaling;
frameInfo.useNISLayer0 = g_upscaleFilter == GamescopeUpscaleFilter::NIS && needsScaling;

Off-topic: While I'm not knowledgeable in this matter, it might also be beneficial to filter / sharpen images that aren't (up-)scaled. #702


To be technology agnostic: The same behavior applies to NIS.

There isn't any feedback currently, as the g_bFSRActive flag and GAMESCOPE_FSR_FEEDBACK atom explicitly reference FSR and only get triggered if FSR is used. I know nothing about Xlib and how this atom is used, but we should consider refactoring these technology specific bits. I can't find any other tool / program online, that references this specific atom though.


Nevertheless, if there is a reason to only use the filters on upscaled frames and keep the flag, it might be better to add a scaler_filter_active and keep fsrUpscale deprecated.

BTW: fsrUpscale still gets populated at the moment, so we are able to check / show this in MangoApp.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be okay to repurprose this and the atom for a generic 'upscaling active'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding MangoApp, repurposing / renaming is denied (flightlessmango/MangoHud#1042 (comment)), adding fields would be the way to go for the IPC.

I can refactor the internal variables / logic though, so that it is generic.
You should decide if it is okay to rename the atom.

uint8_t fsrSharpness; // deprecated
uint64_t app_frametime_ns;
uint64_t latency_ns;
uint32_t outputWidth;
uint32_t outputHeight;
uint8_t scaler;
uint8_t scaler_filter;
uint8_t scaler_sharpness;
// WARNING: Always ADD fields, never remove or repurpose fields
} __attribute__((packed)) mangoapp_msg_v1;

Expand All @@ -50,5 +53,8 @@ void mangoapp_update( uint64_t visible_frametime, uint64_t app_frametime_ns, uin
mangoapp_msg_v1.pid = focusWindow_pid;
mangoapp_msg_v1.outputWidth = g_nOutputWidth;
mangoapp_msg_v1.outputHeight = g_nOutputHeight;
mangoapp_msg_v1.scaler = (uint8_t)g_upscaleScaler;
mangoapp_msg_v1.scaler_filter = (uint8_t)g_upscaleFilter;
mangoapp_msg_v1.scaler_sharpness = g_upscaleFilterSharpness;
msgsnd(msgid, &mangoapp_msg_v1, sizeof(mangoapp_msg_v1) - sizeof(mangoapp_msg_v1.hdr.msg_type), IPC_NOWAIT);
}
8 changes: 8 additions & 0 deletions src/sdlwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ void inputSDLThreadRun( void )
case KEY_B:
g_wantedUpscaleFilter = GamescopeUpscaleFilter::LINEAR;
break;
case KEY_X:
g_wantedUpscaleScaler = (g_wantedUpscaleScaler == GamescopeUpscaleScaler::_LAST) ?
GamescopeUpscaleScaler::_FIRST : (GamescopeUpscaleScaler)((int)g_wantedUpscaleScaler + 1);
break;
case KEY_Z:
g_wantedUpscaleFilter = (g_wantedUpscaleFilter == GamescopeUpscaleFilter::_LAST) ?
GamescopeUpscaleFilter::_FIRST : (GamescopeUpscaleFilter)((int)g_wantedUpscaleFilter + 1);
break;
case KEY_U:
g_wantedUpscaleFilter = (g_wantedUpscaleFilter == GamescopeUpscaleFilter::FSR) ?
GamescopeUpscaleFilter::LINEAR : GamescopeUpscaleFilter::FSR;
Expand Down