Commit graph

55 commits

Author SHA1 Message Date
Simon Ser
332f261c35 drm: generalize find_drm_node_by_devid for render nodes
We'll use this to open the DRM render node from a VkPhysicalDevice.
2021-09-15 12:12:06 +02:00
Simon Ser
e5faeaed68 Open DRM device from Vulkan physical device
Initialize Vulkan first to pick a physical device, then initialize
DRM or SDL. That way, DRM can open its own device depending on what
Vulkan is using. This avoids picking the wrong GPU on multi-GPU
setups.

This required rejiggering how initialization happens. In particular,
we need to get the SDL Vulkan instance extension list early. This is
supported since SDL 2.0.9 (by omitting the window in
SDL_Vulkan_GetInstanceExtensions).
2021-09-14 18:16:53 +02:00
Simon Ser
7198851e98 Unify init functions return types a bit
We had both int and bool, let's try to end up with only bools.
2021-09-14 16:59:46 +02:00
Simon Ser
1d528be605 Untangle preferred mode and current mode
g_nOutput* stored two different values: preferred values taken from
the CLI at init-time, then current values after init. This results
in some tricky logic because depending on when code is executed it'd
access one or the other.

Introduce two separate sets of variables instead. DRM reads from the
preferred values, decides which DRM mode to enable, then writes to
the current values. SDL reads from the preferred values and makes
them current immediately.

This changes gamescope's behaviour so that native DRM modes are
picked when -w/-h isn't specified on the command line. When -w/-h are
specified, the DRM logic will try to pick a mode which matches.

When nested, the default output size still defaults to 720p, but
changes when the user resizes the window.

Closes: https://github.com/Plagman/gamescope/issues/258
2021-09-14 16:45:23 +02:00
Simon Ser
5ac5a1ea29 drm: don't use globals as inputs for find_mode
These globals are overwritten by drm_set_mode. Save the globals at
init time to remember what the user preference is.
2021-09-13 18:34:27 +02:00
Simon Ser
ff8c0b183b Introduce finish_drm
For now it just closes the DRM FD, but will do more soon.
2021-09-10 11:05:09 +02:00
Pierre-Loup A. Griffais
5d3a0eb078 Repaint on possible connector hotplug 2021-09-02 17:18:13 -07:00
Simon Ser
f18723d489 drm: compute per-connector CRTC mask 2021-09-01 13:23:12 +02:00
Simon Ser
51cfc0df06 Implement priority list for -O
e.g. `-O DP-1,VGA-1` will use DP-1 if possible, then fallback to
VGA-1, then to any other connector.
2021-08-25 16:22:14 +02:00
Simon Ser
6e1d4c2a7e drm: switch connector on hotplug
Refresh connector status and mode list on hotplug event. Then
execute the connector selection logic again to see if the
preferred connector has changed.

References: https://github.com/Plagman/gamescope/issues/211
2021-08-02 12:35:49 +02:00
Simon Ser
a314c3f0ba drm: plane -> primary 2021-07-28 19:27:51 +02:00
Simon Ser
a7ab8e7a1a drm: plane_formats -> primary_formats 2021-07-28 19:26:31 +02:00
Simon Ser
f15aafe478 drm: add drm_set_connector 2021-07-28 19:03:30 +02:00
Simon Ser
a978c54fff drm: stop recording drmModeModeInfo in state 2021-07-28 18:40:29 +02:00
Simon Ser
f1eb06d9b7 drm: add explicit needs_modeset flag 2021-07-28 18:17:07 +02:00
Simon Ser
3ffd29c23a drm: group current state 2021-07-28 18:09:52 +02:00
Simon Ser
fae6bfc411 drm: refresh props after VT switch 2021-07-28 17:47:41 +02:00
Simon Ser
2b975d14af drm: add CRTC state
This allows tracking whether we've previously disabled a CRTC.
2021-07-28 17:33:20 +02:00
Simon Ser
df6091a3b4 drm: de-duplicate drmModeGetProperty calls
A property can be attached to multiple objects.
2021-07-28 17:02:47 +02:00
Simon Ser
590d7129aa drm: add drm_set_resolution
Allows to easily switch the output resolution.
2021-07-28 16:40:51 +02:00
Simon Ser
c33ad217e1 Handle session switch events
Pause/resume our frame submission on VT switch.

Closes: https://github.com/Plagman/gamescope/issues/6
2021-07-27 14:11:00 +02:00
Simon Ser
e125a82914 Don't die on EACCES
EACCES is returned by the kernel when we're VT-switched away.
2021-07-27 13:54:47 +02:00
Simon Ser
e5e0ebf5a4 drm: allow selecting a connector via -O
References: https://github.com/Plagman/gamescope/issues/211
2021-07-22 16:50:16 +02:00
Simon Ser
593fe90695 drm: save initial object prop values 2021-07-20 21:32:02 +02:00
Simon Ser
b2f016dfe5 drm: drop {crtc,plane,connector}_id fields 2021-07-20 21:21:43 +02:00
Simon Ser
930ceb271b drm: fetch all connectors, CRTCs and planes on init
We need to fetch the props anyways to select the right objects.
2021-07-20 21:20:32 +02:00
Simon Ser
b380f3fbf2 drm: allow to switch refresh rate at runtime
References: https://github.com/Plagman/gamescope/issues/206
2021-07-20 17:53:38 +02:00
Simon Ser
852d3b12a9 drm: embed drm_t.mode
This will allow us to store a custom mode there, instead of a
mode that comes from the EDID.
2021-07-20 17:31:57 +02:00
Simon Ser
953c5ec377 drm: move mode selection to get_preferred_mode function 2021-07-20 15:59:35 +02:00
Simon Ser
af1ba566ba drm: remove mode_str and vrefresh args from init_drm
We'll change these at runtime, so let's stop taking them as init
args. They were unused.
2021-07-20 15:53:15 +02:00
Simon Ser
fa433a3ebc Include <wayland-server-core.h> outside of extern "C"
Closes: https://github.com/Plagman/gamescope/issues/190
2021-05-17 19:21:51 +02:00
Simon Ser
d1ff01c134 Make args const in drm_prepare 2021-04-30 16:18:29 +02:00
Simon Ser
f89f585cdd drm: build set of scanout capable formats 2021-03-05 14:26:30 +01:00
Simon Ser
706bdf849e drm: store KMS props in a map 2021-03-05 14:18:09 +01:00
Simon Ser
c7c917e39a Read DRM_CAP_ADDFB2_MODIFIERS 2021-02-01 15:52:48 +01:00
Simon Ser
b841139327 Collect plane modifiers
This will be useful once we implement support for modifiers.
2021-02-01 15:08:01 +01:00
Roman Gilg
ceeef3567d Use DRM_CAP_CURSOR_{WIDTH,HEIGTH} for cursor buffer
Hardware often has cursor plane limitations for the buffer size.

Co-authored-by: Simon Ser <contact@emersion.fr>
2020-12-11 12:39:00 +01:00
Simon Ser
a62740e393 Rename drm_can_avoid_composite to drm_prepare
drm_can_avoid_composite doesn't merely checks whether we can avoid
composition: it also prepares a pending atomic request. It's always
necessary to call this function before drm_atomic_commit.

Rename the function to make this clearer.
2020-11-12 20:48:15 -08:00
Simon Ser
aac57e7c75 Hold client buffers till KMS stops using them 2020-09-01 12:36:35 -07:00
Pierre-Loup A. Griffais
fb2fd1127a Revert "Hold client buffers till KMS stops using them"
This reverts commit c9e11ebdbf.
2020-07-24 15:01:28 -07:00
Simon Ser
c9e11ebdbf Hold client buffers till KMS stops using them 2020-07-23 22:26:06 +02:00
Simon Ser
bae255ee1a
Get rid of C_SIDE
wlroots headers can mostly be included with extern "C" blocks. Two
exceptions are the use of `static` for array args and `class` as a
struct field. These can be #define'ed to avoid C++ build errors.

This allows the whole project to be built as a single C++ codebase,
without having to maintain hybrid header files.
2020-06-11 12:44:36 +02:00
Simon Ser
9802890c93
Fix spurious assertions in page_flip_handler
This commit fixes two issues.

A first issue is that fbids_in_req was previously populated
drm_can_avoid_composite and read from in page_flip_handler. As a
result, calling drm_can_avoid_composite then page_flip_handler would
prevent drm_atomic_commit from referencing the right FBs
(page_flip_handler runs in a separate thread and clears fbids_in_req).

To fix this, add a new fbids_queued vector filled by drm_atomic_commit.
Make page_flip_handler read from this new vector instead of
fbids_in_req. As a bonus, this fixes a data race since fbids_queued is
now protected by flip_lock.

The second issue is that drm_can_avoid_composite assumes all layers made
it into a hw plane when liftoff_output_apply succeeds. That's not the
case because libliftoff supports mixed hw plane + composition (where
some layers make it into a hw plane and the others get composited).

To fix this, make drm_can_avoid_composite fail if some but not all
layers make it into a hw plane. In the future, we'll want to support the
mixed mode too.

Closes: https://github.com/Plagman/gamescope/issues/65
References: https://github.com/Plagman/gamescope/issues/41
2020-05-26 16:29:50 +02:00
Simon Ser
bcc7cf3b55
Fix memory leak in drm_can_avoid_composite
We were creating a new DRM blob each page-flip and never destroying it.
Instead, create the mode blob once on startup.
2020-05-26 10:57:57 +02:00
Simon Ser
2062141c49
Introduce drm_free_fb
This function takes care of calling drmModeRmFB. In the future it'll
also take care of releasing the client buffer when using direct
scan-out.
2020-05-19 14:25:59 +02:00
Simon Ser
0ee8d451e4
Replace map_fbid_inflightflips pair with a struct
This makes it explicit what "first" and "second" are. This also allows
to add more fields.
2020-05-19 14:05:52 +02:00
Roman Gilg
8833e07618 feat: add layer debugging via libliftoff log
Activate libliftoff's internal log when layers are enabled and the parameter
'd' is provided.

Note: this needs some patches to libliftoff to make the debug readable that I
have proposed upstream.
2020-03-10 02:02:40 +01:00
Pierre-Loup A. Griffais
56b2aa2d92 wlserver: wire kb+mouse+touch input coming from wlr, mainly libinput.
Add the concept of a cursor coordinate when that initializes when focusing
a surface.

Put some super primitive tap to left-click emulation in there for now.
2020-01-17 02:36:53 -08:00
Pierre-Loup A. Griffais
94ecdfdc6e drm: more logging. 2020-01-13 20:57:39 -08:00
Pierre-Loup A. Griffais
4d6602ba4b DRM: Make liftoff layers conditional for now.
Can't get them to be useful, might need library and amdgpu DC fixes.
2020-01-06 19:36:20 -08:00