amdgpu_glamor.c revision 24b90cf4
1d6c0b56eSmrg/* 2d6c0b56eSmrg * Copyright © 2011 Intel Corporation. 3d6c0b56eSmrg * 2012 Advanced Micro Devices, Inc. 4d6c0b56eSmrg * 5d6c0b56eSmrg * Permission is hereby granted, free of charge, to any person 6d6c0b56eSmrg * obtaining a copy of this software and associated documentation 7d6c0b56eSmrg * files (the "Software"), to deal in the Software without 8d6c0b56eSmrg * restriction, including without limitation the rights to use, copy, 9d6c0b56eSmrg * modify, merge, publish, distribute, sublicense, and/or sell copies 10d6c0b56eSmrg * of the Software, and to permit persons to whom the Software is 11d6c0b56eSmrg * furnished to do so, subject to the following conditions: 12d6c0b56eSmrg * 13d6c0b56eSmrg * The above copyright notice and this permission notice (including 14d6c0b56eSmrg * the next paragraph) shall be included in all copies or substantial 15d6c0b56eSmrg * portions of the Software. 16d6c0b56eSmrg * 17d6c0b56eSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18d6c0b56eSmrg * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19d6c0b56eSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20d6c0b56eSmrg * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21d6c0b56eSmrg * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22d6c0b56eSmrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23d6c0b56eSmrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24d6c0b56eSmrg * DEALINGS IN THE SOFTWARE. 25d6c0b56eSmrg */ 26d6c0b56eSmrg 27d6c0b56eSmrg#ifdef HAVE_CONFIG_H 28d6c0b56eSmrg#include "config.h" 29d6c0b56eSmrg#endif 30d6c0b56eSmrg 31d6c0b56eSmrg#include <xf86.h> 32d6c0b56eSmrg 33d6c0b56eSmrg#include "amdgpu_bo_helper.h" 34d6c0b56eSmrg#include "amdgpu_pixmap.h" 35d6c0b56eSmrg#include "amdgpu_glamor.h" 36d6c0b56eSmrg 37d6c0b56eSmrg#include <gbm.h> 38d6c0b56eSmrg 3911bf0794Smrg#ifndef HAVE_GLAMOR_FINISH 40d6c0b56eSmrg#include <GL/gl.h> 4111bf0794Smrg#endif 42d6c0b56eSmrg 43d6c0b56eSmrgDevPrivateKeyRec amdgpu_pixmap_index; 44d6c0b56eSmrg 45d6c0b56eSmrgvoid amdgpu_glamor_exchange_buffers(PixmapPtr src, PixmapPtr dst) 46d6c0b56eSmrg{ 47d6c0b56eSmrg AMDGPUInfoPtr info = AMDGPUPTR(xf86ScreenToScrn(dst->drawable.pScreen)); 48d6c0b56eSmrg 49d6c0b56eSmrg if (!info->use_glamor) 50d6c0b56eSmrg return; 51d6c0b56eSmrg glamor_egl_exchange_buffers(src, dst); 52d6c0b56eSmrg} 53d6c0b56eSmrg 54d6c0b56eSmrgBool amdgpu_glamor_create_screen_resources(ScreenPtr screen) 55d6c0b56eSmrg{ 56d6c0b56eSmrg ScrnInfoPtr scrn = xf86ScreenToScrn(screen); 57d6c0b56eSmrg AMDGPUInfoPtr info = AMDGPUPTR(scrn); 58d6c0b56eSmrg uint32_t bo_handle; 59d6c0b56eSmrg 60d6c0b56eSmrg if (!info->use_glamor) 61d6c0b56eSmrg return TRUE; 62d6c0b56eSmrg 63d6c0b56eSmrg#ifdef HAVE_GLAMOR_GLYPHS_INIT 64d6c0b56eSmrg if (!glamor_glyphs_init(screen)) 65d6c0b56eSmrg return FALSE; 66d6c0b56eSmrg#endif 67d6c0b56eSmrg 68d6c0b56eSmrg if (!amdgpu_bo_get_handle(info->front_buffer, &bo_handle) || 6924b90cf4Smrg !glamor_egl_create_textured_screen(screen, bo_handle, 7024b90cf4Smrg scrn->displayWidth * 7124b90cf4Smrg info->pixel_bytes)) { 72d6c0b56eSmrg return FALSE; 73d6c0b56eSmrg } 74d6c0b56eSmrg 75d6c0b56eSmrg return TRUE; 76d6c0b56eSmrg} 77d6c0b56eSmrg 78d6c0b56eSmrgBool amdgpu_glamor_pre_init(ScrnInfoPtr scrn) 79d6c0b56eSmrg{ 80d6c0b56eSmrg AMDGPUInfoPtr info = AMDGPUPTR(scrn); 81d6c0b56eSmrg pointer glamor_module; 82d6c0b56eSmrg CARD32 version; 83d6c0b56eSmrg 84d6c0b56eSmrg if (scrn->depth < 24) { 85d6c0b56eSmrg xf86DrvMsg(scrn->scrnIndex, X_ERROR, 86d6c0b56eSmrg "glamor requires depth >= 24, disabling.\n"); 87d6c0b56eSmrg return FALSE; 88d6c0b56eSmrg } 89d6c0b56eSmrg#if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(1,15,0,0,0) 90d6c0b56eSmrg if (!xf86LoaderCheckSymbol("glamor_egl_init")) { 91d6c0b56eSmrg xf86DrvMsg(scrn->scrnIndex, X_ERROR, 92d6c0b56eSmrg "glamor requires Load \"glamoregl\" in " 93d6c0b56eSmrg "Section \"Module\", disabling.\n"); 94d6c0b56eSmrg return FALSE; 95d6c0b56eSmrg } 96d6c0b56eSmrg#endif 97d6c0b56eSmrg 98d6c0b56eSmrg /* Load glamor module */ 99d6c0b56eSmrg if ((glamor_module = xf86LoadSubModule(scrn, GLAMOR_EGL_MODULE_NAME))) { 100d6c0b56eSmrg version = xf86GetModuleVersion(glamor_module); 101d6c0b56eSmrg if (version < MODULE_VERSION_NUMERIC(0, 3, 1)) { 102d6c0b56eSmrg xf86DrvMsg(scrn->scrnIndex, X_ERROR, 103d6c0b56eSmrg "Incompatible glamor version, required >= 0.3.0.\n"); 104d6c0b56eSmrg return FALSE; 105d6c0b56eSmrg } else { 106d6c0b56eSmrg AMDGPUEntPtr pAMDGPUEnt = AMDGPUEntPriv(scrn); 107d6c0b56eSmrg 108d6c0b56eSmrg if (glamor_egl_init(scrn, pAMDGPUEnt->fd)) { 109d6c0b56eSmrg xf86DrvMsg(scrn->scrnIndex, X_INFO, 110d6c0b56eSmrg "glamor detected, initialising EGL layer.\n"); 111d6c0b56eSmrg } else { 112d6c0b56eSmrg xf86DrvMsg(scrn->scrnIndex, X_ERROR, 113d6c0b56eSmrg "glamor detected, failed to initialize EGL.\n"); 114d6c0b56eSmrg return FALSE; 115d6c0b56eSmrg } 116d6c0b56eSmrg } 117d6c0b56eSmrg } else { 118d6c0b56eSmrg xf86DrvMsg(scrn->scrnIndex, X_ERROR, "glamor not available\n"); 119d6c0b56eSmrg return FALSE; 120d6c0b56eSmrg } 121d6c0b56eSmrg 122d6c0b56eSmrg info->use_glamor = TRUE; 123d6c0b56eSmrg 124d6c0b56eSmrg return TRUE; 125d6c0b56eSmrg} 126d6c0b56eSmrg 127d6c0b56eSmrgBool 128504d986fSmrgamdgpu_glamor_create_textured_pixmap(PixmapPtr pixmap, struct amdgpu_buffer *bo) 129d6c0b56eSmrg{ 130d6c0b56eSmrg ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen); 131d6c0b56eSmrg AMDGPUInfoPtr info = AMDGPUPTR(scrn); 132d6c0b56eSmrg uint32_t bo_handle; 133d6c0b56eSmrg 134d6c0b56eSmrg if ((info->use_glamor) == 0) 135d6c0b56eSmrg return TRUE; 136d6c0b56eSmrg 137504d986fSmrg if (!amdgpu_bo_get_handle(bo, &bo_handle)) 138d6c0b56eSmrg return FALSE; 139d6c0b56eSmrg 140d6c0b56eSmrg return glamor_egl_create_textured_pixmap(pixmap, bo_handle, 141d6c0b56eSmrg pixmap->devKind); 142d6c0b56eSmrg} 143d6c0b56eSmrg 144d6c0b56eSmrgstatic Bool amdgpu_glamor_destroy_pixmap(PixmapPtr pixmap) 145d6c0b56eSmrg{ 146d6c0b56eSmrg#ifndef HAVE_GLAMOR_EGL_DESTROY_TEXTURED_PIXMAP 147d6c0b56eSmrg ScreenPtr screen = pixmap->drawable.pScreen; 148d6c0b56eSmrg AMDGPUInfoPtr info = AMDGPUPTR(xf86ScreenToScrn(screen)); 149d6c0b56eSmrg Bool ret; 150d6c0b56eSmrg#endif 151d6c0b56eSmrg 152d6c0b56eSmrg if (pixmap->refcnt == 1) { 153d6c0b56eSmrg if (pixmap->devPrivate.ptr) { 154d6c0b56eSmrg struct amdgpu_buffer *bo = amdgpu_get_pixmap_bo(pixmap); 155d6c0b56eSmrg 156d6c0b56eSmrg if (bo) 157d6c0b56eSmrg amdgpu_bo_unmap(bo); 158d6c0b56eSmrg } 159d6c0b56eSmrg 160d6c0b56eSmrg#ifdef HAVE_GLAMOR_EGL_DESTROY_TEXTURED_PIXMAP 161d6c0b56eSmrg glamor_egl_destroy_textured_pixmap(pixmap); 162d6c0b56eSmrg#endif 163d6c0b56eSmrg amdgpu_set_pixmap_bo(pixmap, NULL); 164d6c0b56eSmrg } 165d6c0b56eSmrg 166d6c0b56eSmrg#ifdef HAVE_GLAMOR_EGL_DESTROY_TEXTURED_PIXMAP 167d6c0b56eSmrg fbDestroyPixmap(pixmap); 168d6c0b56eSmrg return TRUE; 169d6c0b56eSmrg#else 170d6c0b56eSmrg screen->DestroyPixmap = info->glamor.SavedDestroyPixmap; 171d6c0b56eSmrg ret = screen->DestroyPixmap(pixmap); 172d6c0b56eSmrg info->glamor.SavedDestroyPixmap = screen->DestroyPixmap; 173d6c0b56eSmrg screen->DestroyPixmap = amdgpu_glamor_destroy_pixmap; 174d6c0b56eSmrg 175d6c0b56eSmrg return ret; 176d6c0b56eSmrg#endif 177d6c0b56eSmrg} 178d6c0b56eSmrg 179d6c0b56eSmrgstatic PixmapPtr 180d6c0b56eSmrgamdgpu_glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth, 181d6c0b56eSmrg unsigned usage) 182d6c0b56eSmrg{ 183d6c0b56eSmrg ScrnInfoPtr scrn = xf86ScreenToScrn(screen); 184d6c0b56eSmrg AMDGPUInfoPtr info = AMDGPUPTR(scrn); 185d6c0b56eSmrg struct amdgpu_pixmap *priv; 186d6c0b56eSmrg PixmapPtr pixmap, new_pixmap = NULL; 187d6c0b56eSmrg 188d6c0b56eSmrg if (!AMDGPU_CREATE_PIXMAP_SHARED(usage)) { 189d6c0b56eSmrg if (info->shadow_primary) { 190d6c0b56eSmrg if (usage != CREATE_PIXMAP_USAGE_BACKING_PIXMAP) 191d6c0b56eSmrg return fbCreatePixmap(screen, w, h, depth, usage); 192d6c0b56eSmrg 193d6c0b56eSmrg usage |= AMDGPU_CREATE_PIXMAP_LINEAR | 194d6c0b56eSmrg AMDGPU_CREATE_PIXMAP_GTT; 195d6c0b56eSmrg } else { 196d6c0b56eSmrg pixmap = glamor_create_pixmap(screen, w, h, depth, usage); 197d6c0b56eSmrg if (pixmap) 198d6c0b56eSmrg return pixmap; 199d6c0b56eSmrg } 200d6c0b56eSmrg } 201d6c0b56eSmrg 202d6c0b56eSmrg if (w > 32767 || h > 32767) 203d6c0b56eSmrg return NullPixmap; 204d6c0b56eSmrg 205d6c0b56eSmrg if (depth == 1) 206d6c0b56eSmrg return fbCreatePixmap(screen, w, h, depth, usage); 207d6c0b56eSmrg 208d6c0b56eSmrg if (usage == CREATE_PIXMAP_USAGE_GLYPH_PICTURE && w <= 32 && h <= 32) 209d6c0b56eSmrg return fbCreatePixmap(screen, w, h, depth, usage); 210d6c0b56eSmrg 211d6c0b56eSmrg pixmap = fbCreatePixmap(screen, 0, 0, depth, usage); 212d6c0b56eSmrg if (pixmap == NullPixmap) 213d6c0b56eSmrg return pixmap; 214d6c0b56eSmrg 215d6c0b56eSmrg if (w && h) { 216d6c0b56eSmrg int stride; 217d6c0b56eSmrg 218d6c0b56eSmrg priv = calloc(1, sizeof(struct amdgpu_pixmap)); 219d6c0b56eSmrg if (priv == NULL) 220d6c0b56eSmrg goto fallback_pixmap; 221d6c0b56eSmrg 222d6c0b56eSmrg priv->bo = amdgpu_alloc_pixmap_bo(scrn, w, h, depth, usage, 223d6c0b56eSmrg pixmap->drawable.bitsPerPixel, 224d6c0b56eSmrg &stride); 225d6c0b56eSmrg if (!priv->bo) 226d6c0b56eSmrg goto fallback_priv; 227d6c0b56eSmrg 228d6c0b56eSmrg amdgpu_set_pixmap_private(pixmap, priv); 229d6c0b56eSmrg 230d6c0b56eSmrg screen->ModifyPixmapHeader(pixmap, w, h, 0, 0, stride, NULL); 231d6c0b56eSmrg 232d6c0b56eSmrg pixmap->devPrivate.ptr = NULL; 233d6c0b56eSmrg 234504d986fSmrg if (!amdgpu_glamor_create_textured_pixmap(pixmap, priv->bo)) 235d6c0b56eSmrg goto fallback_glamor; 236d6c0b56eSmrg } 237d6c0b56eSmrg 238d6c0b56eSmrg return pixmap; 239d6c0b56eSmrg 240d6c0b56eSmrgfallback_glamor: 241d6c0b56eSmrg if (AMDGPU_CREATE_PIXMAP_SHARED(usage)) { 242d6c0b56eSmrg /* XXX need further work to handle the DRI2 failure case. 243d6c0b56eSmrg * Glamor don't know how to handle a BO only pixmap. Put 244d6c0b56eSmrg * a warning indicator here. 245d6c0b56eSmrg */ 246d6c0b56eSmrg xf86DrvMsg(scrn->scrnIndex, X_WARNING, 247d6c0b56eSmrg "Failed to create textured DRI2/PRIME pixmap."); 248d6c0b56eSmrg 249d6c0b56eSmrg amdgpu_glamor_destroy_pixmap(pixmap); 250d6c0b56eSmrg return NullPixmap; 251d6c0b56eSmrg } 252d6c0b56eSmrg /* Create textured pixmap failed means glamor failed to 253d6c0b56eSmrg * create a texture from current BO for some reasons. We turn 254d6c0b56eSmrg * to create a new glamor pixmap and clean up current one. 255d6c0b56eSmrg * One thing need to be noted, this new pixmap doesn't 256d6c0b56eSmrg * has a priv and bo attached to it. It's glamor's responsbility 257d6c0b56eSmrg * to take care of it. Glamor will mark this new pixmap as a 258d6c0b56eSmrg * texture only pixmap and will never fallback to DDX layer 259d6c0b56eSmrg * afterwards. 260d6c0b56eSmrg */ 261d6c0b56eSmrg new_pixmap = glamor_create_pixmap(screen, w, h, depth, usage); 262d6c0b56eSmrg amdgpu_bo_unref(&priv->bo); 263d6c0b56eSmrgfallback_priv: 264d6c0b56eSmrg free(priv); 265d6c0b56eSmrgfallback_pixmap: 266d6c0b56eSmrg fbDestroyPixmap(pixmap); 267d6c0b56eSmrg if (new_pixmap) 268d6c0b56eSmrg return new_pixmap; 269d6c0b56eSmrg else 270d6c0b56eSmrg return fbCreatePixmap(screen, w, h, depth, usage); 271d6c0b56eSmrg} 272d6c0b56eSmrg 273504d986fSmrgPixmapPtr 274504d986fSmrgamdgpu_glamor_set_pixmap_bo(DrawablePtr drawable, PixmapPtr pixmap) 275504d986fSmrg{ 276504d986fSmrg PixmapPtr old = get_drawable_pixmap(drawable); 277504d986fSmrg ScreenPtr screen = drawable->pScreen; 278504d986fSmrg struct amdgpu_pixmap *priv = amdgpu_get_pixmap_private(pixmap); 279504d986fSmrg GCPtr gc; 280504d986fSmrg 281504d986fSmrg /* With a glamor pixmap, 2D pixmaps are created in texture 282504d986fSmrg * and without a static BO attached to it. To support DRI, 283504d986fSmrg * we need to create a new textured-drm pixmap and 284504d986fSmrg * need to copy the original content to this new textured-drm 285504d986fSmrg * pixmap, and then convert the old pixmap to a coherent 286504d986fSmrg * textured-drm pixmap which has a valid BO attached to it 287504d986fSmrg * and also has a valid texture, thus both glamor and DRI2 288504d986fSmrg * can access it. 289504d986fSmrg * 290504d986fSmrg */ 291504d986fSmrg 292504d986fSmrg /* Copy the current contents of the pixmap to the bo. */ 293504d986fSmrg gc = GetScratchGC(drawable->depth, screen); 294504d986fSmrg if (gc) { 295504d986fSmrg ValidateGC(&pixmap->drawable, gc); 296504d986fSmrg gc->ops->CopyArea(&old->drawable, &pixmap->drawable, 297504d986fSmrg gc, 298504d986fSmrg 0, 0, 299504d986fSmrg old->drawable.width, 300504d986fSmrg old->drawable.height, 0, 0); 301504d986fSmrg FreeScratchGC(gc); 302504d986fSmrg } 303504d986fSmrg 304504d986fSmrg /* And redirect the pixmap to the new bo (for 3D). */ 305504d986fSmrg glamor_egl_exchange_buffers(old, pixmap); 306504d986fSmrg amdgpu_set_pixmap_private(pixmap, amdgpu_get_pixmap_private(old)); 307504d986fSmrg amdgpu_set_pixmap_private(old, priv); 308504d986fSmrg 309504d986fSmrg screen->ModifyPixmapHeader(old, 310504d986fSmrg old->drawable.width, 311504d986fSmrg old->drawable.height, 312504d986fSmrg 0, 0, pixmap->devKind, NULL); 313504d986fSmrg old->devPrivate.ptr = NULL; 314504d986fSmrg 315504d986fSmrg screen->DestroyPixmap(pixmap); 316504d986fSmrg 317504d986fSmrg return old; 318504d986fSmrg} 319504d986fSmrg 320d6c0b56eSmrg 321d6c0b56eSmrgstatic Bool 322d6c0b56eSmrgamdgpu_glamor_share_pixmap_backing(PixmapPtr pixmap, ScreenPtr slave, 323d6c0b56eSmrg void **handle_p) 324d6c0b56eSmrg{ 325504d986fSmrg ScreenPtr screen = pixmap->drawable.pScreen; 32624b90cf4Smrg AMDGPUInfoPtr info = AMDGPUPTR(xf86ScreenToScrn(screen)); 327504d986fSmrg uint64_t tiling_info; 328504d986fSmrg CARD16 stride; 329504d986fSmrg CARD32 size; 33024b90cf4Smrg Bool is_linear; 331504d986fSmrg int fd; 332504d986fSmrg 333504d986fSmrg tiling_info = amdgpu_pixmap_get_tiling_info(pixmap); 33424b90cf4Smrg 33524b90cf4Smrg if (info->family >= AMDGPU_FAMILY_AI) 33624b90cf4Smrg is_linear = AMDGPU_TILING_GET(tiling_info, SWIZZLE_MODE) == 0; 33724b90cf4Smrg else 33824b90cf4Smrg is_linear = AMDGPU_TILING_GET(tiling_info, ARRAY_MODE) == 1; 33924b90cf4Smrg 34024b90cf4Smrg if (!is_linear) { 341504d986fSmrg PixmapPtr linear; 342504d986fSmrg 343504d986fSmrg /* We don't want to re-allocate the screen pixmap as 344504d986fSmrg * linear, to avoid trouble with page flipping 345504d986fSmrg */ 346504d986fSmrg if (screen->GetScreenPixmap(screen) == pixmap) 347504d986fSmrg return FALSE; 348d6c0b56eSmrg 349504d986fSmrg linear = screen->CreatePixmap(screen, pixmap->drawable.width, 350504d986fSmrg pixmap->drawable.height, 351504d986fSmrg pixmap->drawable.depth, 352504d986fSmrg CREATE_PIXMAP_USAGE_SHARED); 353504d986fSmrg if (!linear) 354504d986fSmrg return FALSE; 355504d986fSmrg 356504d986fSmrg amdgpu_glamor_set_pixmap_bo(&pixmap->drawable, linear); 357504d986fSmrg } 358504d986fSmrg 359504d986fSmrg fd = glamor_fd_from_pixmap(screen, pixmap, &stride, &size); 360504d986fSmrg if (fd < 0) 361d6c0b56eSmrg return FALSE; 362d6c0b56eSmrg 363504d986fSmrg *handle_p = (void *)(long)fd; 364504d986fSmrg return TRUE; 365d6c0b56eSmrg} 366d6c0b56eSmrg 367d6c0b56eSmrgstatic Bool 368d6c0b56eSmrgamdgpu_glamor_set_shared_pixmap_backing(PixmapPtr pixmap, void *handle) 369d6c0b56eSmrg{ 370d6c0b56eSmrg ScreenPtr screen = pixmap->drawable.pScreen; 371d6c0b56eSmrg ScrnInfoPtr scrn = xf86ScreenToScrn(screen); 372d6c0b56eSmrg struct amdgpu_pixmap *priv; 373d6c0b56eSmrg 374d6c0b56eSmrg if (!amdgpu_set_shared_pixmap_backing(pixmap, handle)) 375d6c0b56eSmrg return FALSE; 376d6c0b56eSmrg 377d6c0b56eSmrg priv = amdgpu_get_pixmap_private(pixmap); 378d6c0b56eSmrg 379504d986fSmrg if (!amdgpu_glamor_create_textured_pixmap(pixmap, priv->bo)) { 380d6c0b56eSmrg xf86DrvMsg(scrn->scrnIndex, X_ERROR, 381d6c0b56eSmrg "Failed to get PRIME drawable for glamor pixmap.\n"); 382d6c0b56eSmrg return FALSE; 383d6c0b56eSmrg } 384d6c0b56eSmrg 385d6c0b56eSmrg screen->ModifyPixmapHeader(pixmap, 386d6c0b56eSmrg pixmap->drawable.width, 387d6c0b56eSmrg pixmap->drawable.height, 388d6c0b56eSmrg 0, 0, 0, NULL); 389d6c0b56eSmrg 390d6c0b56eSmrg return TRUE; 391d6c0b56eSmrg} 392d6c0b56eSmrg 393d6c0b56eSmrg 394d6c0b56eSmrgBool amdgpu_glamor_init(ScreenPtr screen) 395d6c0b56eSmrg{ 396d6c0b56eSmrg ScrnInfoPtr scrn = xf86ScreenToScrn(screen); 397d6c0b56eSmrg AMDGPUInfoPtr info = AMDGPUPTR(scrn); 398d6c0b56eSmrg#ifdef RENDER 399d6c0b56eSmrg#ifdef HAVE_FBGLYPHS 400d6c0b56eSmrg UnrealizeGlyphProcPtr SavedUnrealizeGlyph = NULL; 401d6c0b56eSmrg#endif 402d6c0b56eSmrg PictureScreenPtr ps = NULL; 403d6c0b56eSmrg 404d6c0b56eSmrg if (info->shadow_primary) { 405d6c0b56eSmrg ps = GetPictureScreenIfSet(screen); 406d6c0b56eSmrg 407d6c0b56eSmrg if (ps) { 408d6c0b56eSmrg#ifdef HAVE_FBGLYPHS 409d6c0b56eSmrg SavedUnrealizeGlyph = ps->UnrealizeGlyph; 410d6c0b56eSmrg#endif 411d6c0b56eSmrg info->glamor.SavedGlyphs = ps->Glyphs; 412d6c0b56eSmrg info->glamor.SavedTriangles = ps->Triangles; 413d6c0b56eSmrg info->glamor.SavedTrapezoids = ps->Trapezoids; 414d6c0b56eSmrg } 415d6c0b56eSmrg } 416d6c0b56eSmrg#endif /* RENDER */ 417d6c0b56eSmrg 418d6c0b56eSmrg if (!glamor_init(screen, GLAMOR_USE_EGL_SCREEN | GLAMOR_USE_SCREEN | 419d6c0b56eSmrg GLAMOR_USE_PICTURE_SCREEN | GLAMOR_INVERTED_Y_AXIS | 420d6c0b56eSmrg GLAMOR_NO_DRI3)) { 421d6c0b56eSmrg xf86DrvMsg(scrn->scrnIndex, X_ERROR, 422d6c0b56eSmrg "Failed to initialize glamor.\n"); 423d6c0b56eSmrg return FALSE; 424d6c0b56eSmrg } 425d6c0b56eSmrg 426d6c0b56eSmrg if (!glamor_egl_init_textured_pixmap(screen)) { 427d6c0b56eSmrg xf86DrvMsg(scrn->scrnIndex, X_ERROR, 428d6c0b56eSmrg "Failed to initialize textured pixmap of screen for glamor.\n"); 429d6c0b56eSmrg return FALSE; 430d6c0b56eSmrg } 431d6c0b56eSmrg if (!dixRegisterPrivateKey(&amdgpu_pixmap_index, PRIVATE_PIXMAP, 0)) 432d6c0b56eSmrg return FALSE; 433d6c0b56eSmrg 434d6c0b56eSmrg if (info->shadow_primary) 435d6c0b56eSmrg amdgpu_glamor_screen_init(screen); 436d6c0b56eSmrg 437d6c0b56eSmrg#if defined(RENDER) && defined(HAVE_FBGLYPHS) 438d6c0b56eSmrg /* For ShadowPrimary, we need fbUnrealizeGlyph instead of 439d6c0b56eSmrg * glamor_unrealize_glyph 440d6c0b56eSmrg */ 441d6c0b56eSmrg if (ps) 442d6c0b56eSmrg ps->UnrealizeGlyph = SavedUnrealizeGlyph; 443d6c0b56eSmrg#endif 444d6c0b56eSmrg 445d6c0b56eSmrg info->glamor.SavedCreatePixmap = screen->CreatePixmap; 446d6c0b56eSmrg screen->CreatePixmap = amdgpu_glamor_create_pixmap; 447d6c0b56eSmrg info->glamor.SavedDestroyPixmap = screen->DestroyPixmap; 448d6c0b56eSmrg screen->DestroyPixmap = amdgpu_glamor_destroy_pixmap; 449d6c0b56eSmrg info->glamor.SavedSharePixmapBacking = screen->SharePixmapBacking; 450d6c0b56eSmrg screen->SharePixmapBacking = amdgpu_glamor_share_pixmap_backing; 451d6c0b56eSmrg info->glamor.SavedSetSharedPixmapBacking = screen->SetSharedPixmapBacking; 452d6c0b56eSmrg screen->SetSharedPixmapBacking = 453d6c0b56eSmrg amdgpu_glamor_set_shared_pixmap_backing; 454d6c0b56eSmrg 455d6c0b56eSmrg xf86DrvMsg(scrn->scrnIndex, X_INFO, "Use GLAMOR acceleration.\n"); 456d6c0b56eSmrg return TRUE; 457d6c0b56eSmrg} 458d6c0b56eSmrg 459d6c0b56eSmrgvoid amdgpu_glamor_flush(ScrnInfoPtr pScrn) 460d6c0b56eSmrg{ 461d6c0b56eSmrg AMDGPUInfoPtr info = AMDGPUPTR(pScrn); 462d6c0b56eSmrg 463d6c0b56eSmrg if (info->use_glamor) { 464d6c0b56eSmrg glamor_block_handler(pScrn->pScreen); 465d6c0b56eSmrg } 466504d986fSmrg 467504d986fSmrg info->gpu_flushed++; 468d6c0b56eSmrg} 469d6c0b56eSmrg 470d6c0b56eSmrgvoid amdgpu_glamor_finish(ScrnInfoPtr pScrn) 471d6c0b56eSmrg{ 472d6c0b56eSmrg AMDGPUInfoPtr info = AMDGPUPTR(pScrn); 473d6c0b56eSmrg 474d6c0b56eSmrg if (info->use_glamor) { 47511bf0794Smrg#if HAVE_GLAMOR_FINISH 47611bf0794Smrg glamor_finish(pScrn->pScreen); 47711bf0794Smrg info->gpu_flushed++; 47811bf0794Smrg#else 479d6c0b56eSmrg amdgpu_glamor_flush(pScrn); 480d6c0b56eSmrg glFinish(); 48111bf0794Smrg#endif 482d6c0b56eSmrg } 483d6c0b56eSmrg} 484d6c0b56eSmrg 485d6c0b56eSmrgvoid 486d6c0b56eSmrgamdgpu_glamor_fini(ScreenPtr screen) 487d6c0b56eSmrg{ 488d6c0b56eSmrg AMDGPUInfoPtr info = AMDGPUPTR(xf86ScreenToScrn(screen)); 489d6c0b56eSmrg 490d6c0b56eSmrg if (!info->use_glamor) 491d6c0b56eSmrg return; 492d6c0b56eSmrg 493d6c0b56eSmrg screen->CreatePixmap = info->glamor.SavedCreatePixmap; 494d6c0b56eSmrg screen->DestroyPixmap = info->glamor.SavedDestroyPixmap; 495d6c0b56eSmrg screen->SharePixmapBacking = info->glamor.SavedSharePixmapBacking; 496d6c0b56eSmrg screen->SetSharedPixmapBacking = info->glamor.SavedSetSharedPixmapBacking; 497d6c0b56eSmrg} 498d6c0b56eSmrg 499d6c0b56eSmrgXF86VideoAdaptorPtr amdgpu_glamor_xv_init(ScreenPtr pScreen, int num_adapt) 500d6c0b56eSmrg{ 501d6c0b56eSmrg return glamor_xv_init(pScreen, num_adapt); 502d6c0b56eSmrg} 503