Skip to content

Commit

Permalink
steamcompmgr, commit: Add support for pre-emptive upscaling for focus…
Browse files Browse the repository at this point in the history
…ed windows using FIFO commits

Only available with explicit sync
  • Loading branch information
misyltoad committed Aug 13, 2024
1 parent df52e61 commit 4550ded
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 70 deletions.
25 changes: 25 additions & 0 deletions src/commit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,28 @@ void commit_t::SetFence( int nFence, bool bMangoNudge, CommitDoneList_t *pDoneCo
m_pDoneCommits = pDoneCommits;
}

void calc_scale_factor(float &out_scale_x, float &out_scale_y, float sourceWidth, float sourceHeight);

bool commit_t::ShouldPreemptivelyUpscale()
{
// Don't pre-emptively upscale if we are not a FIFO commit.
// Don't want to FSR upscale 1000fps content.
if ( !fifo )
return false;

// If we support the upscaling filter in hardware, don't
// pre-emptively do it via shaders.
if ( DoesHardwareSupportUpscaleFilter( g_upscaleFilter ) )
return false;

if ( !vulkanTex )
return false;

float flScaleX = 1.0f;
float flScaleY = 1.0f;
// I wish this function was more programatic with its inputs, but it does do exactly what we want right now...
// It should also return a std::pair or a glm uvec
calc_scale_factor( flScaleX, flScaleY, vulkanTex->width(), vulkanTex->height() );

return !close_enough( flScaleX, 1.0f ) || !close_enough( flScaleY, 1.0f );
}
33 changes: 32 additions & 1 deletion src/commit.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
#include "steamcompmgr_shared.hpp"
#include "Utils/NonCopyable.h"

struct commit_t final : public gamescope::RcObject, public gamescope::IWaitable
#include <optional>
#include "main.hpp"

class CVulkanTexture;

struct UpscaledTexture_t
{
GamescopeUpscaleFilter eFilter{};
GamescopeUpscaleScaler eScaler{};
uint32_t uOutputWidth = 0;
uint32_t uOutputHeight = 0;
gamescope::Rc<CVulkanTexture> pTexture;
};

struct commit_t final : public gamescope::RcObject, public gamescope::IWaitable, public gamescope::NonCopyable
{
commit_t();
~commit_t();
Expand All @@ -19,8 +34,24 @@ struct commit_t final : public gamescope::RcObject, public gamescope::IWaitable
bool CloseFenceInternal();
void SetFence( int nFence, bool bMangoNudge, CommitDoneList_t *pDoneCommits );

bool ShouldPreemptivelyUpscale();

struct wlr_buffer *buf = nullptr;
gamescope::Rc<CVulkanTexture> vulkanTex;
std::optional<UpscaledTexture_t> upscaledTexture;

gamescope::Rc<CVulkanTexture> GetTexture( GamescopeUpscaleFilter eFilter, GamescopeUpscaleScaler eScaler )
{
if ( upscaledTexture &&
upscaledTexture->eFilter == eFilter &&
upscaledTexture->eScaler == eScaler &&
upscaledTexture->uOutputWidth == g_nOutputWidth &&
upscaledTexture->uOutputHeight == g_nOutputHeight )
return upscaledTexture->pTexture;

return vulkanTex;
}

uint64_t commitID = 0;
bool done = false;
bool async = false;
Expand Down
7 changes: 7 additions & 0 deletions src/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ enum class GamescopeUpscaleFilter : uint32_t
FROM_VIEW = 0xF, // internal
};

static constexpr bool DoesHardwareSupportUpscaleFilter( GamescopeUpscaleFilter eFilter )
{
// Could do nearest someday... AMDGPU DC supports custom tap placement to an extent.

return eFilter == GamescopeUpscaleFilter::LINEAR;
}

enum class GamescopeUpscaleScaler : uint32_t
{
AUTO,
Expand Down
Loading

0 comments on commit 4550ded

Please sign in to comment.