Commit graph xf86-video-ati/src/radeon.h
Author SHA1 Message Date
Alan Coopersmith
3c9211e696 Strip trailing whitespace from source files
Performed with: `git ls-files | xargs perl -i -p -e 's{[ \t]+$}{}'`

`git diff -w` & `git diff -b` show no diffs from this change

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/driver/xf86-video-ati/-/merge_requests/32>
2025-12-15 15:36:42 +01:00
Enrico Weigelt, metux IT consult
6da5a33d54 bump minimal xorg version to 1.18
1.18 was released a decade ago, so it seems reasonable stop supporting
older ones.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-12-08 16:04:16 +01:00
Enrico Weigelt, metux IT consult
ca1779c468 drop support for xserver < 1.16.99.901
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-04 10:37:13 +02:00
nia
b65036af74 Avoid namespace collision: rename bswap_XX to radeon_bswap_XX
xorg-server includes its own bswap_16, bswap_32 etc macros in
its misc.h. This is transcluded after radeon.h in some files.

If the operating system defines bswap_XX in a way that is
unsuitable for a function name (e.g. on NetBSD), this results
in build failures.

Signed-off-by: Nia Alarie <nia@NetBSD.org>
Part-of: <https://gitlab.freedesktop.org/xorg/driver/xf86-video-ati/-/merge_requests/23>
2024-06-02 18:41:52 +00:00
Dave Airlie
8da3e4561e ati: cleanup terminology to use primary/secondary
The X server changed some API/ABIs here.

Based on amdgpu patch by Michel
2020-07-13 09:16:47 +10:00
Alexey Sheplyakov
c0eb5dbd9c Don't crash X server if GPU acceleration is not available
Commit d1d8e3c8d0 causes X server
to fail on startup when GPU acceleration is not working (or is
disabled). The reason is that `radeon_get_pixmap_bo` function
gets called too early (before EXA has been initialized) and
fails with an assert:

 #0  __GI_raise (sig=<optimized out>) at ../sysdeps/unix/sysv/linux/raise.c:50
 #1  0x76ab1c6c in __GI_abort () at abort.c:79
 #2  0x76ac0b64 in __assert_fail_base (fmt=0x76bfbce4 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x7658c80c "key->initialized", file=<optimized out>, line=121,
     function=0x7658d040 <__PRETTY_FUNCTION__.10607> "dixGetPrivateAddr") at assert.c:92
 #3  0x76ac0c0c in __GI___assert_fail (assertion=0x7658c80c "key->initialized", file=0x7658c9d0 "../include/privates.h", line=121,
     function=0x7658d040 <__PRETTY_FUNCTION__.10607> "dixGetPrivateAddr") at assert.c:101
 #4  0x76579e6c in dixGetPrivateAddr (key=<optimized out>, key=<optimized out>, privates=<optimized out>) at ../include/privates.h:121
 #5  0x7657a954 in dixGetPrivateAddr (key=<optimized out>, key=<optimized out>, privates=<optimized out>) at exa.c:70
 #6  dixGetPrivate (key=<optimized out>, privates=<optimized out>) at ../include/privates.h:136
 #7  exaGetPixmapDriverPrivate (pPix=<optimized out>) at exa.c:68
 #8  0x7623d460 in radeon_get_pixmap_bo (pPix=0x71c1b8) at radeon.h:804
 #9  radeon_get_pixmap_handle (pixmap=0x71c1b8, handle=0x7fa22328) at radeon_bo_helper.c:357
 #10 0x76244458 in radeon_pixmap_get_fb (pix=0x71c1b8) at radeon.h:886
 #11 drmmode_set_mode_major (crtc=0x691860, mode=0x69191c, rotation=<optimized out>, x=<optimized out>, y=<optimized out>) at drmmode_display.c:918
 #12 0x762467e8 in drmmode_set_desired_modes (pScrn=0x67c678, drmmode=<optimized out>, set_hw=1) at drmmode_display.c:3128
 #13 0x0047bfa4 in MapWindow (client=0x669ec8, pWin=0x7206c0) at window.c:2722
 #14 MapWindow (pWin=0x7206c0, client=0x669ec8) at window.c:2665
 #15 0x00449650 in dix_main (argc=3, argv=0x7fa22604, envp=<optimized out>) at main.c:247
 #16 0x76ab2198 in __libc_start_main (main=0x42db10 <main>, argc=3, argv=0x7fa22604, init=<optimized out>, fini=0x606434 <__libc_csu_fini>, rtld_fini=0x77229930 <_dl_fini>,
     stack_end=0x7fa225e0) at libc-start.c:308
 #17 0x0042db80 in __start () at ../sysdeps/mips/start.S:110

Don't call `exaGetPixmapDriverPrivate` if the acceleration (EXA) is not
enabled [yet] to avoid the problem.

Closes: https://gitlab.freedesktop.org/xorg/driver/xf86-video-ati/issues/188
Closes: https://bugzilla.altlinux.org/show_bug.cgi?id=37539
2020-02-10 15:55:37 +00:00
Michel Dänzer
4d84cf438e 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
2020-02-10 15:53:48 +00:00
Michel Dänzer
33803c85f7 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.

(Ported from amdgpu commit 7d3fef72e0c871e1677e9e544f4cae5e238b5c52)
2019-06-25 17:46:23 +02:00
Michel Dänzer
d1d8e3c8d0 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
(Ported from amdgpu commit bf61e6d7ac1a5754b1026d7f80acf25ef622c491)
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2019-04-24 12:25:39 +02:00
Michel Dänzer
e14c3d2f86 Drop RADEONInfoRec::cursor_bo array
Not needed or even useful for anything.

(Ported from amdgpu commit e95044e45350870fa7e237860e89ade91ac03550)
2018-12-28 12:08:41 +01:00
Michel Dänzer
5e6fa5c17a Allow up to six instances in Zaphod mode
Corresponding to up to six CRTCs being available in the hardware.

(Ported from amdgpu commit c9d43c1deb9a9cfc41a8d6439caf46d12d220853)
2018-10-24 18:22:05 +02:00
Michel Dänzer
3c42bd0480 EXA: Handle NULL BO pointer in radeon_set_pixmap_bo 2018-08-29 17:19:24 +02:00
Michel Dänzer
499d2f9d5d glamor: Invalidate cached GEM handle in radeon_set_pixmap_bo
We continued using the stale cached handle, causing issues e.g. when
resizing the screen via RandR.

Reported-by: iive on IRC
Acked-by: Alex Deucher <alexander.deucher@amd.com>
2018-07-17 11:43:12 +02:00
Michel Dänzer
4050b0ad51 Replace 'foo == NULL' with '!foo'
Shorter and sweeter. :)

(Ported from amdgpu commit e8e688f3852fb06b0c34ed5bce47c9493bcd1613)
Acked-by: Alex Deucher <alexander.deucher@amd.com>
2018-07-12 18:08:34 +02:00
Michel Dänzer
3c4c0213c1 glamor: Use GBM for BO allocation when possible
Inspired by amdgpu. This avoids various issues due to a GEM handle
lifetime conflict between us and Mesa with current glamor.

Bugzilla: https://bugs.freedesktop.org/105381
Tested-by: Konstantin Kharlamov <hi-angel@yandex.ru>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2018-07-09 18:28:21 +02:00
Michel Dänzer
b85b7b11f5 Add struct radeon_buffer
Inspired by amdgpu, preparation for the following change. For now, this
is mostly a wrapper around struct radeon_bo, no functional change
intended.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2018-07-09 18:28:05 +02:00
Michel Dänzer
37ba075b34 Refactor radeon_finish helper
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2018-07-09 18:27:45 +02:00
Michel Dänzer
5da2bf43e6 Factor out radeon_surface_initialize helper
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2018-07-09 18:26:57 +02:00
Michel Dänzer
ba5d5402b3 glamor: Don't store radeon_surfaces in pixmaps
Only EXA needs them.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2018-07-09 18:24:39 +02:00
Michel Dänzer
e0f5020117 Pass extents to radeon_scanout_do_update by value
radeon_scanout_extents_intersect could leave the scanout damage region
in an invalid state, triggering debugging checks in pixman:

*** BUG ***
In pixman_region_append_non_o: The expression r->x1 < r->x2 was false
Set a breakpoint on '_pixman_log_error' to debug

(Ported from amdgpu commit 8af989546907ad9fb491d940e1936d3bfc89276b)
2018-03-14 16:54:52 +01:00
Michel Dänzer
b915e8e6fb Wrap the whole miPointerScreenFuncRec, instead of only Set/MoveCursor
We were clobbering entries in mi's global miSpritePointerFuncs struct,
which cannot work correctly with multiple primary screens. Instead,
assign a pointer to our own wrapper struct to PointPriv->spriteFuncs.

Fixes crashes with multiple primary screens.

Fixes: 1fe8ca7597 ("Keep track of how many SW cursors are visible on
                      each screen")
Reported-by: Mario Kleiner <mario.kleiner.de@gmail.com>
2018-03-07 17:28:55 +01:00
Michel Dänzer
733f606dd6 Always use screen depth/bpp for KMS framebuffers
DRI clients can use depth 32 pixmaps while the screen is depth 24, in
which case page flipping would fail.

Reported-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Reviewed-and-Tested-by: Mario Kleiner <mario.kleiner.de@gmail.com>
2018-01-25 16:59:30 +01:00
Mario Kleiner
21f6753462 Define per x-screen individual drmmode_crtc_funcs
This allows to en-/disable some functions depending on individual screen
settings.

Prep work for more efficient depth 30 support.

Suggested-by: Michel Dänzer <michel.daenzer@amd.com>
Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
2018-01-22 12:05:51 +01:00
Michel Dänzer
1fe8ca7597 Keep track of how many SW cursors are visible on each screen
And use this to determine when we cannot use page flipping for DRI
clients. We previously did this based on whether the HW cursor cannot
be used on at least one CRTC, which had at least two issues:

* Even while the HW cursor cannot be used, no SW cursor may actually be
  visible (e.g. because all cursors are disabled), in which case we can
  use page flipping for DRI clients anyway
* Even while the HW cursor can be used, there may be SW cursors visible
  from non-core pointer devices, in which case we cannot use page
  flipping for DRI clients anyway

(Ported from amdgpu commit 69e20839bfeb3ee0b0a732d72de0a32d6c5435fc)
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2017-12-28 15:17:56 +01:00
Michel Dänzer
ee907e9b95 Add radeon_dirty_src_drawable helper
Allows tidying up radeon_dirty_src_equals and redisplay_dirty slightly.

(Cherry picked from amdgpu commit 1d65ac395971571094df21ca0408d5972c6b56ec)
Acked-by: Alex Deucher <alexander.deucher@amd.com>
2017-12-01 15:49:11 +01:00
Joakim Tjernlund
fccfd75ecf Fix non GLAMOR build
Non GLAMOR builds needs pRADEONEnt so move the USE_GLAMOR define
down to make pRADEONEnt defined in this case.

Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
2017-11-27 11:13:10 +01:00
Michel Dänzer
b93ae9b159 Unreference pixmap's FB with EXA as well in radeon_set_pixmap_bo
Not doing so resulted in DRI2 page flips not actually changing the FB
being scanned out, showing intermittent flicker of the "back" buffer
rendering.

Bugzilla: https://bugs.freedesktop.org/102643
Fixes: 55e513b978 "Use reference counting for tracking KMS framebuffer
                     lifetimes"
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2017-10-20 10:28:37 +02:00
Michel Dänzer
5cdd334b34 Require xserver >= 1.13
xserver 1.13.0 was released on September 6th, 2012, almost 5 years ago.

This allows cleaning up a bunch of backwards compatibility code.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2017-08-30 18:48:19 +09:00
Michel Dänzer
7f0cd68d1b Create radeon_master_screen helper
Preparatory, no functional change intended yet.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2017-08-29 16:35:16 +09:00
Michel Dänzer
20f6b56fdb Create radeon_pixmap_get_fb_ptr helper
Preparatory, no functional change intended yet.

Also inline radeon_pixmap_create_fb into radeon_pixmap_get_fb, since
there's only one call-site anymore.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2017-08-29 16:34:54 +09:00
Michel Dänzer
d822a0f470 Make radeon_scanout_do_update take a PixmapPtr instead of a DrawablePtr
All callers were already passing in a pixmap.

This allows simplifying the rotated scanout case slightly.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2017-08-17 16:20:52 +09:00
Michel Dänzer
65e0c5ea1b Pass extents to radeon_scanout_do_update
Preparation for following change, no functional change intended yet.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2017-08-17 15:51:43 +09:00
Michel Dänzer
1443270e52 Add source drawable parameter to radeon_scanout_do_update
Preparation for following changes, no functional change intended yet.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2017-08-17 15:49:01 +09:00
Michel Dänzer
99f1d7a474 Create drmmode_wait_vblank helper
Allows cleaning up the code considerably.

v2:
* Fix "drmWaiVBlank" typo, add blank line for readability (Slava Abramov)
* Rename in/out sequence parameters to "target_seq" and "result_seq",
  hopefully that will be clearer.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com> # v1
2017-08-17 15:24:22 +09:00
Michel Dänzer
01b040b4a8 Adapt to PixmapDirtyUpdateRec::src being a DrawablePtr 2017-08-15 17:15:27 +09:00
Michel Dänzer
df88d51c50 Use pRADEONEnt->fd exclusively for the DRM file descriptor
This brings us closer to amdgpu.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2017-06-30 17:40:12 +09:00
Michel Dänzer
55e513b978 Use reference counting for tracking KMS framebuffer lifetimes
References are held by the pixmaps corresponding to the FBs (so
the same KMS FB can be reused as long as the pixmap exists) and by the
CRTCs scanning out from them (so a KMS FB is only destroyed once it's
not being scanned out anymore, preventing intermittent black screens and
worse issues due to a CRTC turning off when it should be on).

v2:
* Only increase reference count in drmmode_fb_reference if it was sane
  before
* Make drmmode_fb_reference's indentation match the rest of
  drmmode_display.h

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2017-05-11 18:51:38 +09:00
Michel Dänzer
4c91f36d30 Don't set modes before RADEONWindowExposures_oneshot is called
The root window contents may be undefined before that, so we don't want
to show anything yet.

Fixes a crash on startup with rotation and virtual resolution set in
xorg.conf.

Bugzilla: https://bugs.freedesktop.org/100276
Fixes: cc9d6b7db9 ("Move DPMS check from radeon_scanout_do_update to
                      radeon_scanout_flip")
(Ported from amdgpu commit 981bac185cfd74ae50dffc28f57cf34623a9595f)
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2017-04-17 18:32:31 +09:00
Michel Dänzer
67ae5e00a7 Skip some initialization steps for GPU screens
Xorg doesn't use the following functionality of GPU screens, so don't
bother initializing it:

* DRI page flipping
* DRI3 / Present / SYNC fences
* XVideo / XvMC
* Root window with background None

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2017-03-08 11:20:30 +09:00
Michel Dänzer
0a12bf1085 Call drmmode_set_desired_modes from a WindowExposures hook
This is the earliest opportunity where the root window contents are
guaranteed to be initialized, and prevents drmmode_set_mode_major from
getting called before drmmode_set_desired_modes via RADEONUnblank ->
drmmode_crtc_dpms. Also, in contrast to the BlockHandler hook, this is
called when running Xorg with -pogo.

Fixes intermittently showing garbage on server startup or after server
reset.

As a bonus, this avoids trouble due to higher layers (e.g. the tigervnc
Xorg module) calling RADEONBlockHandler_oneshot repeatedly even after
we set pScreen->BlockHandler = RADEONBlockHandler_KMS.

v2:
* Drop spaces between XORG_VERSION_NUMERIC arguments
* Call radeon_bo_wait after radeon_cs_flush_indirect

Bugzilla: https://bugs.freedesktop.org/99457
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v1)
2017-03-02 16:05:55 +09:00
Michel Dänzer
58cd160005 Allow toggling TearFree at runtime via output property
Option "TearFree" now sets the default value of the output property.
See the manpage update for details.

TearFree is now enabled by default for outputs using rotation or other
RandR transforms, and for RandR 1.4 slave outputs.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2017-02-22 18:27:37 +09:00
Jochen Rollwagen
a89c0bced4 Calculate log base 2 in radeon.h based on clz for all platforms
This commit replaces the inline assembler code (for x86 platforms) and
loop (for non-x86 platforms) in RADEONLog2 with a one-liner version
based on clz (count leading zeroes).

Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
2016-12-05 11:06:28 +09:00
Michel Dänzer
e543ef3a2f Take current scanout_id into account everywhere involved with TearFree
Fixes various potential issues with TearFree enabled, e.g. outputs
freezing after display configuration changes.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2016-11-29 17:41:10 +09:00
Michel Dänzer
f130b10e63 Add radeon_is_gpu_screen helper
This will hopefully decrease the chance of accidentally breaking the
build against xserver < 1.13 in the future.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2016-11-25 18:12:40 +09:00
Michel Dänzer
5df36de399 Require xserver 1.10 or newer
1.10.0 was released in February 2011.

We've been accidentally requiring 1.10 or newer since 121a6de72d ("Keep
track of damage event related flushes per-client v2").

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2016-10-27 11:40:13 +09:00
Michel Dänzer
cf52c76484 Free priv in amdgpu_set_pixmap_bo also if priv->bo == NULL
Fixes memory leak when destroying pixmaps with priv->bo == NULL.

Reported-by: Qiang Yu <qiang.yu@amd.com>
(Ported from amdgpu commit 7f7f9825caf3983902491da27c16d14cd8bf9b7d)
2016-09-21 18:20:19 +09:00
Michel Dänzer
8523a733b6 Propagate failure from radeon_set_pixmap_bo
(Ported from amdgpu commits c315c00e44afc91a7c8e2eab5af836d9643ebb88
 and 0d42082108c264568e2aadd15ace70e72388bc65)
2016-09-21 16:25:25 +09:00
Michel Dänzer
80cc892ee1 Use local implementation of RegionDuplicate for older xserver
It was only added in xserver 1.15. Fixes build against older xserver.

Reported-by: Pali Rohár <pali.rohar@gmail.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2016-09-20 17:45:16 +09:00
Michel Dänzer
121a6de72d Keep track of damage event related flushes per-client v2
This further reduces the compositing slowdown due to flushing overhead,
by only flushing when the X server actually sends XDamageNotify events
to a client, and there hasn't been a flush yet in the meantime.

v2: Use ScreenPrivateKey, fixes invalid memory access with GPU screens
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2016-08-17 18:14:40 +09:00
Michel Dänzer
9a1afbf61f Use EventCallback to avoid flushing every time in the FlushCallback
We only need to flush for XDamageNotify events.

Significantly reduces compositing slowdown due to flushing overhead, in
particular with glamor.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2016-08-01 18:51:03 +09:00