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

steamcompmgr cleanups #1503

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
e0114be
steamcompmgr: remove dead code
sharkautarch Sep 2, 2024
efbd2ae
steamcompmgr, commit.cpp: cleanup some stuff
sharkautarch Sep 3, 2024
a8b9435
make currentOutputWidth/Height a glm::uvec2
sharkautarch Sep 3, 2024
871acb1
calc_scale_factor_scaler: ternary back to if else
sharkautarch Sep 3, 2024
f2a87fd
steamcompmgr: change a pair of offset vars to glm::ivec2
sharkautarch Sep 3, 2024
df805ad
steamcompmgr: misc cleanups
sharkautarch Sep 3, 2024
f951f0f
steamcompmgr: remove some unused includes + some other cleanups
sharkautarch Sep 3, 2024
580b3ad
steamcompmgr: replace pre-c++20 "poor man's semaphore" w/ c++20 std::…
sharkautarch Sep 3, 2024
2d687e8
steamcompmgr: Even moar tidying
sharkautarch Sep 4, 2024
d59c2d6
steamcompmgr, rc, commit: introduce make_rc() function + use it to cl…
sharkautarch Sep 4, 2024
3f9d985
fix uninitialized pointer
sharkautarch Sep 5, 2024
6edf7f1
steamcompmgr: reduce the number of lines taken up by the range based …
sharkautarch Sep 5, 2024
3346c40
steamcompmgr, wayland, etc: attempt to fix regressions
sharkautarch Sep 5, 2024
bc0e276
commit: mark in-place constructor as explicit
sharkautarch Sep 5, 2024
81f4303
fix weird wlserver_is_lock_held() assert
sharkautarch Sep 6, 2024
2e799b2
steamcompmgr: initialize glm::vec2 currentScaleRatio to [1.0f 1.0f].
sharkautarch Sep 6, 2024
761b73f
rc: make_rc(): ensure function can only be used for in-place construc…
sharkautarch Sep 6, 2024
60b39a3
steamcompmgr, etc: {g_nNestedWidth, g_nNestedHeight} -> g_ivNestedRes…
sharkautarch Sep 6, 2024
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
2 changes: 1 addition & 1 deletion src/Backends/OpenVRBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ namespace gamescope

bool UpdateEdid()
{
m_FakeEdid = GenerateSimpleEdid( g_nNestedWidth, g_nNestedHeight );
m_FakeEdid = GenerateSimpleEdid( g_ivNestedResolution.x, g_ivNestedResolution.y );

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Backends/WaylandBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ namespace gamescope

bool CWaylandConnector::UpdateEdid()
{
m_FakeEdid = GenerateSimpleEdid( g_nNestedWidth, g_nNestedHeight );
m_FakeEdid = GenerateSimpleEdid( g_ivNestedResolution.x, g_ivNestedResolution.y );

return true;
}
Expand Down
50 changes: 50 additions & 0 deletions src/color_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,56 @@
#include <glm/vec3.hpp> // glm::vec3
#include <glm/mat3x3.hpp> // glm::mat3
#include <glm/gtx/component_wise.hpp>
/////////////////////////////////////////////////////////
// Stuff for using structured bindings with glm::vec: //
/////////////////////////////////////////////////////////
namespace std
{
#define MK_TUPLE_SIZE(size, type) \
template<> \
struct tuple_size< ::glm::vec<size, type, glm::defaultp> > : \
std::integral_constant<size_t, size> { }

# define MK_TUPLE_ELEMENT(size) \
template<std::size_t I, class T> \
struct tuple_element<I, ::glm::vec<size, T, glm::defaultp>> : std::type_identity<T> {}

MK_TUPLE_SIZE(2, int);
MK_TUPLE_SIZE(2, float);
MK_TUPLE_SIZE(2, unsigned);

MK_TUPLE_SIZE(3, int);
MK_TUPLE_SIZE(3, float);
MK_TUPLE_SIZE(3, unsigned);

MK_TUPLE_SIZE(4, int);
MK_TUPLE_SIZE(4, float);
MK_TUPLE_SIZE(4, unsigned);

MK_TUPLE_ELEMENT(2);
MK_TUPLE_ELEMENT(3);
MK_TUPLE_ELEMENT(4);
}

namespace glm {
# define INSTANTIATE(qualifier) \
template< std::size_t I > \
auto qualifier \
get( auto qualifier v ) noexcept { \
if constexpr (I == 0) return v.x; \
if constexpr (I == 1) return v.y; \
if constexpr (I == 2) return v.z; \
if constexpr (I == 3) return v.w; \
}

INSTANTIATE(&)
INSTANTIATE(const&)
INSTANTIATE(&&)
INSTANTIATE(const&&)
}
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////


// Color utils
inline int quantize( float fVal, float fMaxVal )
Expand Down
38 changes: 29 additions & 9 deletions src/commit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,35 @@

extern gamescope::CAsyncWaiter<gamescope::Rc<commit_t>> g_ImageWaiter;

uint64_t commit_t::getCommitID()
{
static uint64_t maxCommmitID = 1;
return maxCommmitID++;
}

commit_t::commit_t()
{
static uint64_t maxCommmitID = 0;
commitID = ++maxCommmitID;
commitID = getCommitID();;
}

commit_t::commit_t(std::in_place_t tag, ResListEntry_t& reslistentry, struct wlr_buffer* buf, bool is_steam, uint64_t seq)
: RcObject(tag),
buf{buf},
async{reslistentry.async},
fifo{reslistentry.fifo},
is_steam{is_steam},
feedback( reslistentry.feedback
? std::optional<wlserver_vk_swapchain_feedback>(std::in_place_t{}, *reslistentry.feedback)
: std::nullopt ),
win_seq{seq},
surf{reslistentry.surf},
presentation_feedbacks{std::move(reslistentry.presentation_feedbacks)},
present_id{reslistentry.present_id},
desired_present_time{reslistentry.desired_present_time}
{
commitID = getCommitID();
}

commit_t::~commit_t()
{
{
Expand Down Expand Up @@ -126,7 +150,7 @@ 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);
glm::vec2 calc_scale_factor(float sourceWidth, float sourceHeight);

bool commit_t::ShouldPreemptivelyUpscale()
{
Expand All @@ -143,11 +167,7 @@ bool commit_t::ShouldPreemptivelyUpscale()
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() );
glm::vec2 flScale = calc_scale_factor( vulkanTex->width(), vulkanTex->height() );

return !close_enough( flScaleX, 1.0f ) || !close_enough( flScaleY, 1.0f );
return !close_enough( flScale.x, 1.0f ) || !close_enough( flScale.y, 1.0f );
}
8 changes: 7 additions & 1 deletion src/commit.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ struct UpscaledTexture_t

struct commit_t final : public gamescope::RcObject, public gamescope::IWaitable, public gamescope::NonCopyable
{
protected:
ENABLE_IN_PLACE_RC
explicit commit_t(std::in_place_t tag, ResListEntry_t& reslistentry, struct wlr_buffer* buf, bool is_steam, uint64_t seq);

uint64_t getCommitID();
public:
commit_t();
~commit_t();
~commit_t();

GamescopeAppTextureColorspace colorspace() const;

Expand Down
18 changes: 8 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,7 @@ const char usage[] =

std::atomic< bool > g_bRun{true};

int g_nNestedWidth = 0;
int g_nNestedHeight = 0;
glm::ivec2 g_ivNestedResolution {};
int g_nNestedRefresh = 0;
int g_nNestedUnfocusedRefresh = 0;
int g_nNestedDisplayIndex = 0;
Expand Down Expand Up @@ -678,10 +677,10 @@ int main(int argc, char **argv)
const char *opt_name;
switch (o) {
case 'w':
g_nNestedWidth = atoi( optarg );
g_ivNestedResolution.x = atoi( optarg );
break;
case 'h':
g_nNestedHeight = atoi( optarg );
g_ivNestedResolution.y = atoi( optarg );
break;
case 'r':
g_nNestedRefresh = gamescope::ConvertHztomHz( atoi( optarg ) );
Expand Down Expand Up @@ -918,18 +917,17 @@ int main(int argc, char **argv)
}
}

if ( g_nNestedHeight == 0 )
if ( g_ivNestedResolution.y == 0 )
{
if ( g_nNestedWidth != 0 )
if ( g_ivNestedResolution.x != 0 )
{
fprintf( stderr, "Cannot specify -w without -h\n" );
return 1;
}
g_nNestedWidth = g_nOutputWidth;
g_nNestedHeight = g_nOutputHeight;
g_ivNestedResolution = glm::ivec2 { g_nOutputWidth, g_nOutputHeight };
}
if ( g_nNestedWidth == 0 )
g_nNestedWidth = g_nNestedHeight * 16 / 9;
if ( g_ivNestedResolution.x == 0 )
g_ivNestedResolution.x = g_ivNestedResolution.y * 16 / 9;

if ( !wlserver_init() )
{
Expand Down
4 changes: 2 additions & 2 deletions src/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ extern const char *gamescope_optstring;
extern const struct option *gamescope_options;

extern std::atomic< bool > g_bRun;
#include <glm/fwd.hpp>

extern int g_nNestedWidth;
extern int g_nNestedHeight;
extern glm::ivec2 g_ivNestedResolution;
extern int g_nNestedRefresh; // mHz
extern int g_nNestedUnfocusedRefresh; // mHz
extern int g_nNestedDisplayIndex;
Expand Down
30 changes: 30 additions & 0 deletions src/rc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,27 @@

#include <cstdint>
#include <atomic>
#include <utility>

namespace gamescope
{
template <typename T, bool Public>
class Rc;

template <typename A, typename B>
concept NotTheSameAs = !std::is_same<std::remove_cvref_t<std::remove_pointer_t<A>>, std::remove_cvref_t<std::remove_pointer_t<B>>>::value;

#define ENABLE_IN_PLACE_RC using gamescope::RcObject::RcObject; \
template <class T, gamescope::NotTheSameAs<T>... Args> \
friend gamescope::Rc<T, true> gamescope::make_rc(Args&&... args);
class RcObject
{
template <class T, NotTheSameAs<T>... Args>
friend gamescope::Rc<T, true> make_rc(Args&&... args);
protected:
explicit constexpr RcObject(std::in_place_t) : m_uRefCount{1}, m_uRefPrivate{1} {}
public:
RcObject() = default;
virtual ~RcObject()
{
}
Expand Down Expand Up @@ -93,13 +108,28 @@ namespace gamescope
static void DecRef( T* pObject ) { pObject->DecRefPrivate(); }
};

template <class T, NotTheSameAs<T>... Args>
Rc<T, true> make_rc(Args&&... args) {
T* pObj = new T(std::in_place_t{}, std::forward<Args>(args)...);
return Rc<T, true>{std::in_place_t{}, pObj};
}

template <typename T, bool Public = true>
class Rc
{
template <typename Tx, bool Publicx>
friend class Rc;

template <class Tx, NotTheSameAs<Tx>... Args>
friend Rc<Tx, true> gamescope::make_rc(Args&&... args);

using RcRef = RcRef_<T, Public>;

protected:
explicit constexpr Rc( std::in_place_t tag, T* pObject )
: m_pObject{ pObject } {} //no IncRef here, because this constructor is used w/ in-place RcObject construction via friend function make_rc()
//this is locked behind protected access, to avoid any unintended use

public:
Rc() { }
Rc( std::nullptr_t ) { }
Expand Down
14 changes: 7 additions & 7 deletions src/rendervulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3824,7 +3824,7 @@ std::optional<uint64_t> vulkan_screenshot( const struct FrameInfo_t *frameInfo,

const int pixelsPerGroup = 8;

cmdBuffer->dispatch(div_roundup(currentOutputWidth, pixelsPerGroup), div_roundup(currentOutputHeight, pixelsPerGroup));
cmdBuffer->dispatch(div_roundup(currentOutputResolution.x, pixelsPerGroup), div_roundup(currentOutputResolution.y, pixelsPerGroup));

if ( pYUVOutTexture != nullptr )
{
Expand Down Expand Up @@ -3939,7 +3939,7 @@ std::optional<uint64_t> vulkan_composite( struct FrameInfo_t *frameInfo, gamesco
cmdBuffer->bindTarget(compositeImage);
cmdBuffer->uploadConstants<RcasPushData_t>(frameInfo, g_upscaleFilterSharpness / 10.0f);

cmdBuffer->dispatch(div_roundup(currentOutputWidth, pixelsPerGroup), div_roundup(currentOutputHeight, pixelsPerGroup));
cmdBuffer->dispatch(div_roundup(currentOutputResolution.x, pixelsPerGroup), div_roundup(currentOutputResolution.y, pixelsPerGroup));
}
else if ( frameInfo->useNISLayer0 )
{
Expand Down Expand Up @@ -3984,11 +3984,11 @@ std::optional<uint64_t> vulkan_composite( struct FrameInfo_t *frameInfo, gamesco

int pixelsPerGroup = 8;

cmdBuffer->dispatch(div_roundup(currentOutputWidth, pixelsPerGroup), div_roundup(currentOutputHeight, pixelsPerGroup));
cmdBuffer->dispatch(div_roundup(currentOutputResolution.x, pixelsPerGroup), div_roundup(currentOutputResolution.y, pixelsPerGroup));
}
else if ( frameInfo->blurLayer0 )
{
update_tmp_images(currentOutputWidth, currentOutputHeight);
update_tmp_images(currentOutputResolution.x, currentOutputResolution.y);

ShaderType type = SHADER_TYPE_BLUR_FIRST_PASS;

Expand All @@ -4010,7 +4010,7 @@ std::optional<uint64_t> vulkan_composite( struct FrameInfo_t *frameInfo, gamesco

int pixelsPerGroup = 8;

cmdBuffer->dispatch(div_roundup(currentOutputWidth, pixelsPerGroup), div_roundup(currentOutputHeight, pixelsPerGroup));
cmdBuffer->dispatch(div_roundup(currentOutputResolution.x, pixelsPerGroup), div_roundup(currentOutputResolution.y, pixelsPerGroup));

bool useSrgbView = frameInfo->layers[0].colorspace == GAMESCOPE_APP_TEXTURE_COLORSPACE_LINEAR;

Expand All @@ -4023,7 +4023,7 @@ std::optional<uint64_t> vulkan_composite( struct FrameInfo_t *frameInfo, gamesco
cmdBuffer->setSamplerUnnormalized(VKR_BLUR_EXTRA_SLOT, true);
cmdBuffer->setSamplerNearest(VKR_BLUR_EXTRA_SLOT, false);

cmdBuffer->dispatch(div_roundup(currentOutputWidth, pixelsPerGroup), div_roundup(currentOutputHeight, pixelsPerGroup));
cmdBuffer->dispatch(div_roundup(currentOutputResolution.x, pixelsPerGroup), div_roundup(currentOutputResolution.y, pixelsPerGroup));
}
else
{
Expand All @@ -4034,7 +4034,7 @@ std::optional<uint64_t> vulkan_composite( struct FrameInfo_t *frameInfo, gamesco

const int pixelsPerGroup = 8;

cmdBuffer->dispatch(div_roundup(currentOutputWidth, pixelsPerGroup), div_roundup(currentOutputHeight, pixelsPerGroup));
cmdBuffer->dispatch(div_roundup(currentOutputResolution.x, pixelsPerGroup), div_roundup(currentOutputResolution.y, pixelsPerGroup));
}

if ( pPipewireTexture != nullptr )
Expand Down
Loading
Loading