678 Commits

Author SHA1 Message Date
Michel Dänzer
0732f81a2c glamor: Make pixmap scanout compatible if its dimensions are
Namely, if its dimensions match those of the screen pixmap (enough that
it could stand in for it). When that's the case, the pixmap may end up
being scanned out directly due to page flipping via the Present
extension, e.g. with xfwm4 --vblank=xpresent .

v2:
* Use AMDGPU_CREATE_PIXMAP_SCANOUT instead of second-guessing in
  amdgpu_alloc_pixmap_bo, fixes corruption when resizing from smaller
  to larger virtual size via RandR.

Closes: https://gitlab.freedesktop.org/xorg/driver/xf86-video-amdgpu/-/issues/10
2020-04-21 10:54:47 +02:00
Michel Dänzer
cb27a5b112 Handle NULL fb_ptr in pixmap_get_fb
This can happen when HW acceleration is disabled.

Fixes https://gitlab.freedesktop.org/xorg/driver/xf86-video-ati/issues/188
(ported from radeon commit 4d84cf438e7f1bebf0053035ef0292e9fed257d1)
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2020-03-18 17:47:15 +01:00
Michel Dänzer
e2cd67abb4 Bail from amdgpu_pixmap_get_handle with ShadowFB
There's no pixmap private in that case. The callers handle this
gracefully.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2020-03-16 17:44:36 +01:00
Emil Velikov
42a3148ae1 Factor out common code to amdgpu_probe()
Keep the distinct pci/platform screen management in the separate probe
entry point and fold the rest into a single function.

v2: Rebase

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
2020-03-16 14:25:40 +00:00
Emil Velikov
eeaaf37085 Introduce amdgpu_device_setup helper
It folds the device specifics (open fd, device init) into a single
place.

v2:
 - Rebase
 - Pass pAMDGPUEnt to amdgpu_device_setup (Michel)

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
2020-03-16 14:25:37 +00:00
Emil Velikov
1c9742e304 Kill off drmOpen/Close/drmSetInterfaceVersion in favour of drmDevices
The former has very subtle semantics (see the implementation in libdrm
for details) which were required in the UMS days.

With drmDevices around, we have enough information to build our
heuristics and avoid drmOpen all together.

In the odd case drmGetDevices2() can take a few extra cycles, so use a
reasonably sized local array.

v2:
 - Rebase
 - Rework now that amdgpu_kernel_mode_enabled() is staying
 - Keep amdgpu_bus_id()
 - Use local drmDevice array.

v3:
 - Correct error handling (Michel)
 - Preserve the "am I master" check (Michel)
 - Always initialise the fd variable

v4:
 - Don't print "-1" on drmGetDevices2 failure (Michel)
 - Use uppercase DRM (Michel)

v5:
 - Rebase on top of amdgpu_bus_id() rework
 - Pass both pci and platform dev to amdgpu_kernel_open_fd() (Michel)
 - Indent local_drmIsMaster() with tabs (Michel)

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
2020-03-16 14:25:26 +00:00
Emil Velikov
2dd730784e Use the device_id straight from gpu_info
This way we can remove the PciInfo and Chipset from the AMDGPUInfoRec.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
2020-03-16 14:25:23 +00:00
Emil Velikov
655b3c55b9 Reuse the existing busid string
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
2020-03-16 14:25:19 +00:00
Emil Velikov
b357a84740 Store the busid string in AMDGPUEnt
This way we can reuse it, instead of redoing it later on.

v2: Pass the AMDGPUEnt as argument.
v3: free() the string at AMDGPUFreeRec (Michel)
v4: Inline amdgpu_bus_id, move at top of mdgpu_kernel_open_fd (Michel)

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com> (v3)
Acked-by: Alex Deucher <alexander.deucher@amd.com>
2020-03-16 14:25:16 +00:00
Emil Velikov
2c0c154a83 Remove NULL check after a "cannot fail" function
XNFasprintf cannot fail - aka busid cannot be NULL.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
2020-03-16 14:25:13 +00:00
Emil Velikov
16ae0d06c6 Fixup the amdgpu_bus_id() string format
The func is a u, instead of a signed int.

v2: Drop the precision - s/1u/u/ (Michel)

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
2020-03-16 14:25:10 +00:00
Emil Velikov
abbe23fae7 Remove drmCheckModesettingSupported and kernel module loading, on Linux
The former of these is a UMS artefact which gives incorrect and
misleading promise whether KMS is supported. Not to mention that
AMDGPU is a only KMS driver.

In a similar fashion xf86LoadKernelModule() is a relic of the times,
where platforms had no scheme of detecting and loading the appropriate
kernel module.

Notes:
 - Since there is no reply from Robert the code is still around, behind
a FreeBSD guard.
 - If FreeBSD still needs this they should look and fix it ASAP, as:
   - wayland itself or compositors do _not_ load kernel modules
   - the kernel module should be loaded early to control the clocks/fan,
hence temperature of the card

v2: Keep the code as FreeBSD only, add 'Notes' in the commit message.

Cc: Robert Millan <rmh@freebsd.org>
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
2020-03-16 14:25:06 +00:00
Emil Velikov
0b3bc7addf Use ODEV_ATTRIB_PATH where possible for the device node.
Use the device node path, if the server knows it.

Note:
ODEV_ATTRIB_PATH was introduced with xserver 1.13 - the minimum version
required to build amdgpu. Yet it's defined in xf86platformBus.h. With
the header included only when XSERVER_PLATFORM_BUS is set.

Keep things obvious and use a ODEV_ATTRIB_PATH guard.

v2: Rebase, add commit message

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
2020-03-16 14:24:50 +00:00
Adam Jackson
edcbe5f52d Fix link failure with gcc 10
Without the 'extern' this looks like a definition not just a
declaration, in every file that includes the header. gcc 10 is stricter
about this kind of multiple definition.
2020-02-05 11:08:33 -05:00
Adam Jackson
fd66f5c0be kms: Handle changes to SourceValidate call chain in xserver 19
xserver 19 expects the SourceValidate hook to always be filled in with
something valid. For earlier servers it's harmless to simply fill this
in with a do-nothing function instead of NULL.

Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2019-11-22 17:29:37 +01:00
Michel Dänzer
b467d2569a Bump version for the 19.1.0 release xf86-video-amdgpu-19.1.0 2019-10-11 17:10:10 +02:00
Michel Dänzer
a1b7263277 Don't unreference FBs of pixmaps from different screens in LeaveVT
FindClientResourcesByType finds pixmaps from all screens, but trying to
process ones from other screens here makes no sense and likely results
in a crash or memory corruption.

Fixes: c16ff42f92 ("Make all active CRTCs scan out an all-black
                      framebuffer in LeaveVT")
(Ported from radeon commit 2faaecc69b127248718e759c6c98c84d56dd1b6b)
2019-09-26 15:56:59 +02:00
Michel Dänzer
5b8bc9fc50 Don't set up black scanout buffer if LeaveVT is called from CloseScreen
Avoids a crash described in
https://gitlab.freedesktop.org/xorg/driver/xf86-video-amdgpu/merge_requests/43#note_223718

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2019-09-18 12:55:45 +02:00
Michel Dänzer
e6fce59a07 present: Don't check pixmap pitch in check_flip with non-DC >= 3.34
The current non-DC kernel driver also handles flipping between different
pitches correctly.

Reviewed-by: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
2019-08-07 18:11:54 +02:00
Michel Dänzer
5bb2580b26 present: Don't check pixmap pitch in check_flip with current DC
Current DC handles flipping between different pitches correctly.

Reviewed-by: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
2019-08-07 18:11:20 +02:00
Michel Dänzer
ac66086613 present: Also check pixmap pitch in check_flip with current xserver
The corresponding check in the xserver Present code was removed again,
because flipping between different pitches can work in some cases.

Reviewed-by: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
2019-08-07 18:04:52 +02:00
Michel Dänzer
98f172eb2d gitlab-ci: Use templates from wayland/ci-templates
These are already used by xserver, Mesa and some other projects.

Current Debian testing brings e.g. GCC 8.3.0 and clang 7.0.1.
2019-07-30 09:43:31 +02:00
Michel Dänzer
87f41ace49 Don't disable page flipping completely with SW cursor
Even with SW cursor, page flipping can be used while no X cursor is
visible.

Occurred to me in the context of xorg/xserver#828.
2019-07-05 12:43:53 +02:00
Michel Dänzer
7d3fef72e0 present: Check that we can get a KMS FB for flipping
This can legitimately fail if the pixmap's storage is shared from
another device, e.g. when using PRIME render offloading.
2019-06-25 15:28:36 +00:00
Michel Dänzer
ea19a52070 Remove dri2_drawable_crtc parameter consider_disabled
All callers were passing TRUE.

Reviewed-and-tested-by: Flora Cui <flora.cui@amd.com>
2019-06-14 11:09:19 +02:00
Michel Dänzer
3109f088fd dri2: Re-use previous CRTC when possible if pick_best_crtc returns NULL
This way, the MSC will continue ticking at the rate of (the last mode
which was enabled for) that CRTC, instead of the client running
unthrottled.

Reviewed-and-tested-by: Flora Cui <flora.cui@amd.com>
2019-06-14 11:07:32 +02:00
Flora Cui
fb06fb8147 dri2: reply to client for WaitMSC request in any case
otherwise client would wait for reply forever and desktop appears hang.

Signed-off-by: Flora Cui <flora.cui@amd.com>
Acked-by: Feifei Xu <Feifei.Xu@amd.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
2019-06-10 09:45:03 +08:00
Michel Dänzer
4b17533fcb dri3: Always flush glamor before sharing pixmap storage with clients
Even if glamor_gbm_bo_from_pixmap / glamor_fd_from_pixmap themselves
don't trigger any drawing, there could already be unflushed drawing to
the pixmap whose storage we share with a client.
2019-04-30 17:50:15 +02:00
Michel Dänzer
bf61e6d7ac Retry get_fb_ptr in get_fb
If get_fb_ptr returns NULL, try again after pixmap_get_handle, it should
work then.

Fixes spurious Present page flipping failures using "normal" pixmaps
which aren't shared with direct rendering clients, e.g. with a
compositor using the RENDER extension.

Bugzilla: https://bugs.freedesktop.org/110417
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2019-04-18 19:21:40 +02:00
Michel Dänzer
bd4ffd4ebb Bump version for the 19.0.1 release xf86-video-amdgpu-19.0.1 2019-03-19 18:44:31 +01:00
Dave Airlie
6ee8577261 modesetting: add tile property support
This adds tiling support to the driver, it retrieves the tile info from
the kernel and translates it into the server format and exposes the
property.

(Ported from xserver commits 8fb8bbb3062f1a06621ab7030a9e89d5e8367b35
 and 6abdb54a11dac4e8854ff94ecdcb90a14321ab31)
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2019-03-07 16:25:19 +01:00
Michel Dänzer
9534bf3bb3 Bump version for the 19.0.0 release xf86-video-amdgpu-19.0.0 2019-03-06 12:05:49 +01:00
Michel Dänzer
a2b32e72fd present: Don't check tiling parameters with DC & DRM minor version >= 31
Current DC handles any changes of tiling parameters for flips.

v2:
* Just check all tiling bits if DRM minor < 31 or DC is disabled.

Reviewed-by: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
2019-03-04 17:39:27 +01:00
Michel Dänzer
2798244be7 Make drmmode_cm_enabled an inline function
So that it can be used outside of drmmode_display.c as well.

Reviewed-by: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
2019-03-04 17:39:12 +01:00
Michel Dänzer
72653455e4 Revert "Remove set but unused amdgpu_dri2::pKernelDRMVersion"
This reverts commit 720a61000a.

We're going to make use of it now.

Reviewed-by: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
2019-03-04 17:31:45 +01:00
Michel Dänzer
28cd209ebf Revert "gitlab-ci: Only run docker-image stage if relevant source files change"
This reverts commit 9c23076b9e.

Some scenarios have come to light where this failed to ensure the docker
image exists:

* If the master branch of a forked repository is used for an MR which
  doesn't modify .gitlab-ci.yml, the docker-image job may not run.
* If the docker-image job of the first pipeline in a forked repository
  is cancelled or fails for any reason, and .gitlab-ci.yml isn't
  modified for the next pipeline run.
2019-03-01 10:09:21 +00:00
Michel Dänzer
09be74a3d1 dri2: Call drm_queue_handle_deferred in dri2_deferred_event
drm_queue_handler just puts the event on the signalled list; without
calling drm_queue_handle_deferred, actual processing of the event may be
delayed indefinitely, e.g. until another event arrives from the kernel.

This could result in DRI2 clients hanging during DPMS off.

Fixes: 739181c8d3 "Add amdgpu_drm_handle_event wrapper for
                      drmHandleEvent"
Reviewed-by: Aaron Liu <aaron.liu@amd.com>
Tested-by: Aaron Liu <aaron.liu@amd.com>
2019-03-01 09:53:38 +00:00
Michel Dänzer
a636f42b49 present: Check that flip and screen pixmap pitches match
If they don't, flipping will result in corrupted display.

Test case:

* Run Xorg at 1920x1080 with no window manager
* glxgears -geometry 2048x1080

The Present extension code in xserver 1.21 will check for this.

Tested-by: Jax Lin <jax.lin@amd.com>
2019-02-27 18:43:27 +01:00
Michel Dänzer
bd090f389f Call amdgpu_present_set_screen_vrr from amdgpu_vrr_property_update
If the window is currently flipping.

This might make a difference when the property gets disabled: Variable
refresh will now be disabled immediately in that case, instead of only
when the window can no longer use page flipping at all.

Reviewed-by: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
2019-02-22 17:45:04 +01:00
Michel Dänzer
d9be5d712d Make use of property request wrappers for VRR property
Instead of scanning for PropertyNotify events. Reasons:

* Works even if no client listens to PropertyNotify events for the
  window.
* No overhead on delivery of unrelated events, and no overhead at all
  if Option "VariableRefresh" is disabled.

v2:
* Use shorter variable name amdgpu_vrr_atom.
* Call MakeAtom regardless of info->instance_id, for robustness vs VRR
  being enabled in some but not all AMDGPU screens.

Reviewed-by: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
2019-02-22 17:44:30 +01:00
Michel Dänzer
ef8fbe33b7 Wrap change/delete window property request handlers
Preparation for the following change.

v2:
* Add comments explaining what the wrappers are wrapping.
* Use global amdgpu_property_vectors_wrapped to keep track of whether
  the vectors need to be (un)wrapped, for robustness against VRR being
  enabled in some but not all AMDGPU screens.

Reviewed-by: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
2019-02-20 17:57:16 +01:00
Michel Dänzer
09a45ff8fe Don't enable the VRR support code for GPU screens
Windows aren't associated with GPU screens, and amdgpu_present_flip is
never called for them, so VRR can never actually be enabled for them.

Reviewed-by: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
2019-02-20 16:37:13 +01:00
Michel Dänzer
2a3d00dc7e Don't register a window private if VRR is disabled
It's not used in that case.

Reviewed-by: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
2019-02-12 18:58:23 +01:00
Michel Dänzer
5f91be77e0 gitlab-ci: Don't rely on $CI_PROJECT_NAME
The name of a forked repository can be changed later, in which case this
would fail to refer to the main repository.

Pointed out by Eric Engestrom in
https://gitlab.freedesktop.org/mesa/mesa/merge_requests/224 .
2019-02-11 18:32:07 +01:00
Michel Dänzer
9c23076b9e gitlab-ci: Only run docker-image stage if relevant source files change
Otherwise there's normally no need to run it. It will also run when a
new branch is created, which ensures that the docker image always exists
(e.g. in a newly forked repository).

Inspired by https://gitlab.freedesktop.org/mesa/mesa/merge_requests/143
2019-02-07 17:35:13 +01:00
Michel Dänzer
9045fb310f Keep waiting for a pending flip if drm_handle_event returns 0
drm_wait_pending_flip stopped waiting if drm_handle_event returned 0,
but that might have processed only some unrelated DRM events. As long as
the flip is pending, we have to keep waiting for its completion event.

Noticed while working on the previous fix.

Acked-by: Alex Deucher <alexander.deucher@amd.com>
2019-01-25 17:54:53 +01:00
Michel Dänzer
3ff2cc225f Call drmHandleEvent again if it was interrupted by a signal
drmHandleEvent can be interrupted by a signal in read(), in which case
it doesn't process any events but returns -1, which
drm_handle_event propagated to its callers. This could cause the
following failure cascade:

1. drm_wait_pending_flip stopped waiting for a pending flip.
2. Its caller cleared drmmode_crtc->flip_pending before the flip
   completed.
3. Another flip was attempted but got an unexpected EBUSY error because
   the previous flip was still pending.
4. TearFree was disabled due to the error.

The solution is to call drmHandleEvent if it was interrupted by a
signal. We can do that in drm_handle_event, because when that is called,
either it is known that there are events ready to be processed, or the
caller has to wait for events to arrive anyway.

v2:
* Use ErrorF instead of xf86DrvMsg with hard-coded screen 0.

Bugzilla: https://bugs.freedesktop.org/109364
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> # v1
2019-01-25 17:49:52 +01:00
Michel Dänzer
e72a02ba1d Only update drmmode_crtc->flip_pending after actually submitting a flip
And only clear it if it matches the framebuffer of the completed flip
being processed.

Fixes

 (WW) AMDGPU(0): flip queue failed: Device or resource busy
 (WW) AMDGPU(0): Page flip failed: Device or resource busy
 (EE) AMDGPU(0): present flip failed

due to clobbering drmmode_crtc->flip_pending.

Reproducer: Enable TearFree, run warzone2100 fullscreen, toggle
Vertical sync on/off under Video Options. Discovered while investigating
https://bugs.freedesktop.org/109364 .

Acked-by: Alex Deucher <alexander.deucher@amd.com>
2019-01-17 11:34:04 +01:00
Michel Dänzer
a1b479c7d0 Don't allow TearFree scanout flips to complete in the same vblank period
We were using a relative target of 0, meaning "complete the flip ASAP".
This could result in the flip sometimes, but not always completing in
the same vertical blank period where the corresponding drawing occurred,
potentially causing judder artifacts with applications updating their
window contents synchronized to the display refresh. A good way to test
this is the vsynctester.com site in a windowed browser, where the judder
results in the large "VSYNC" text intermittently appearing red or cyan
instead of the expected gray.

To avoid this, use a relative target MSC of 1, meaning that if a
vertical blank period is in progress, the flip will only complete in the
next one.

Reported by Julian Tempel and Brandon Wright in
https://bugs.freedesktop.org/106175 .

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2019-01-16 18:39:56 +01:00
Michel Dänzer
bf326f2ea1 glamor: Avoid glamor_create_pixmap for pixmaps backing windows
If the compositing manager uses direct rendering (as is usually the case
these days), the storage of a pixmap allocated by glamor_create_pixmap
needs to be reallocated for sharing it with the compositing manager.
Instead, allocate pixmap storage which can be shared directly.

Acked-by: Alex Deucher <alexander.deucher@amd.com>
2019-01-16 18:39:11 +01:00