diff options
author | Christian König <[email protected]> | 2011-03-03 00:59:12 +0100 |
---|---|---|
committer | Christian König <[email protected]> | 2011-03-03 00:59:12 +0100 |
commit | 0eccb1038a620bc76ba45ac00c293b3e88427510 (patch) | |
tree | 4bd9209ac6e9b824284d47799b13a99a401c6963 /src/gallium/state_trackers | |
parent | ed12c29bc45b100b758c9affe2cebe8c8498e25e (diff) | |
parent | 2e756f3d6f15d61297a3bb4efe6a88c29081a5eb (diff) |
Merge remote branch 'origin/master' into pipe-video
Diffstat (limited to 'src/gallium/state_trackers')
-rw-r--r-- | src/gallium/state_trackers/dri/drm/dri2.c | 2 | ||||
-rw-r--r-- | src/gallium/state_trackers/egl/Makefile | 1 | ||||
-rw-r--r-- | src/gallium/state_trackers/egl/common/egl_g3d.c | 3 | ||||
-rw-r--r-- | src/gallium/state_trackers/egl/common/egl_g3d.h | 1 | ||||
-rw-r--r-- | src/gallium/state_trackers/egl/common/egl_g3d_api.c | 15 | ||||
-rw-r--r-- | src/gallium/state_trackers/egl/common/egl_g3d_image.c | 1 | ||||
-rw-r--r-- | src/gallium/state_trackers/egl/common/native.h | 28 | ||||
-rw-r--r-- | src/gallium/state_trackers/egl/common/native_helper.c | 142 | ||||
-rw-r--r-- | src/gallium/state_trackers/egl/common/native_helper.h | 31 | ||||
-rw-r--r-- | src/gallium/state_trackers/egl/drm/modeset.c | 48 | ||||
-rw-r--r-- | src/gallium/state_trackers/egl/drm/native_drm.c | 3 | ||||
-rw-r--r-- | src/gallium/state_trackers/egl/drm/native_drm.h | 2 | ||||
-rw-r--r-- | src/gallium/state_trackers/egl/fbdev/native_fbdev.c | 2 | ||||
-rw-r--r-- | src/gallium/state_trackers/egl/gdi/native_gdi.c | 2 | ||||
-rw-r--r-- | src/gallium/state_trackers/egl/wayland/native_wayland.c | 4 | ||||
-rw-r--r-- | src/gallium/state_trackers/egl/x11/native_ximage.c | 2 |
16 files changed, 259 insertions, 28 deletions
diff --git a/src/gallium/state_trackers/dri/drm/dri2.c b/src/gallium/state_trackers/dri/drm/dri2.c index 0181588096d..a5c94b4166b 100644 --- a/src/gallium/state_trackers/dri/drm/dri2.c +++ b/src/gallium/state_trackers/dri/drm/dri2.c @@ -317,6 +317,7 @@ dri2_allocate_buffer(__DRIscreen *sPriv, templ.width0 = width; templ.height0 = height; templ.depth0 = 1; + templ.array_size = 1; buffer->resource = screen->base.screen->resource_create(screen->base.screen, &templ); @@ -510,6 +511,7 @@ dri2_create_image(__DRIscreen *_screen, templ.width0 = width; templ.height0 = height; templ.depth0 = 1; + templ.array_size = 1; img->texture = screen->base.screen->resource_create(screen->base.screen, &templ); if (!img->texture) { diff --git a/src/gallium/state_trackers/egl/Makefile b/src/gallium/state_trackers/egl/Makefile index 98167cceeb3..68643214060 100644 --- a/src/gallium/state_trackers/egl/Makefile +++ b/src/gallium/state_trackers/egl/Makefile @@ -26,6 +26,7 @@ x11_OBJECTS = $(x11_SOURCES:.c=.o) wayland_INCLUDES = \ -I$(TOP)/src/gallium/winsys \ -I$(TOP)/src/egl/wayland \ + -I$(TOP)/src/egl/wayland/wayland-drm \ $(shell pkg-config --cflags-only-I libdrm wayland-client) wayland_SOURCES = $(wildcard wayland/*.c) diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c b/src/gallium/state_trackers/egl/common/egl_g3d.c index 6107df48822..e60a56074dd 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d.c @@ -455,9 +455,6 @@ egl_g3d_terminate(_EGLDriver *drv, _EGLDisplay *dpy) _eglReleaseDisplayResources(drv, dpy); - if (gdpy->pipe) - gdpy->pipe->destroy(gdpy->pipe); - if (dpy->Configs) { _eglDestroyArray(dpy->Configs, egl_g3d_free_config); dpy->Configs = NULL; diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.h b/src/gallium/state_trackers/egl/common/egl_g3d.h index 9873fee6ec2..301db3128ff 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d.h +++ b/src/gallium/state_trackers/egl/common/egl_g3d.h @@ -56,7 +56,6 @@ struct egl_g3d_display { const struct egl_g3d_loader *loader; struct st_manager *smapi; - struct pipe_context *pipe; }; struct egl_g3d_context { diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_api.c b/src/gallium/state_trackers/egl/common/egl_g3d_api.c index c9f94a3c498..2068256dff2 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d_api.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d_api.c @@ -640,6 +640,7 @@ egl_g3d_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, _EGLContext *ctx = _eglGetCurrentContext(); struct native_surface *nsurf; struct pipe_resource *ptex; + struct pipe_context *pipe; if (!gsurf->render_texture) return EGL_TRUE; @@ -655,22 +656,18 @@ egl_g3d_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL); } - /* create a pipe context to copy surfaces */ - if (!gdpy->pipe) { - gdpy->pipe = - gdpy->native->screen->context_create(gdpy->native->screen, NULL); - if (!gdpy->pipe) - return EGL_FALSE; - } + pipe = ndpy_get_copy_context(gdpy->native); + if (!pipe) + return EGL_FALSE; ptex = get_pipe_resource(gdpy->native, nsurf, NATIVE_ATTACHMENT_FRONT_LEFT); if (ptex) { struct pipe_box src_box; u_box_origin_2d(ptex->width0, ptex->height0, &src_box); - gdpy->pipe->resource_copy_region(gdpy->pipe, ptex, 0, 0, 0, 0, + pipe->resource_copy_region(pipe, ptex, 0, 0, 0, 0, gsurf->render_texture, 0, &src_box); - gdpy->pipe->flush(gdpy->pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); nsurf->present(nsurf, NATIVE_ATTACHMENT_FRONT_LEFT, FALSE, 0); pipe_resource_reference(&ptex, NULL); diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_image.c b/src/gallium/state_trackers/egl/common/egl_g3d_image.c index 81ce7ab45c7..e1c83168b3a 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d_image.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d_image.c @@ -111,6 +111,7 @@ egl_g3d_create_drm_buffer(_EGLDisplay *dpy, _EGLImage *img, templ.width0 = attrs.Width; templ.height0 = attrs.Height; templ.depth0 = 1; + templ.array_size = 1; /* * XXX fix apps (e.g. wayland) and pipe drivers (e.g. i915) and remove the diff --git a/src/gallium/state_trackers/egl/common/native.h b/src/gallium/state_trackers/egl/common/native.h index 42889075a39..9246f8c32a4 100644 --- a/src/gallium/state_trackers/egl/common/native.h +++ b/src/gallium/state_trackers/egl/common/native.h @@ -142,6 +142,11 @@ struct native_display { struct pipe_screen *screen; /** + * Context used for copy operations. + */ + struct pipe_context *pipe; + + /** * Available for caller's use. */ void *user_data; @@ -223,6 +228,29 @@ native_attachment_mask_test(uint mask, enum native_attachment att) return !!(mask & (1 << att)); } +/** + * Get the display copy context + */ +static INLINE struct pipe_context * +ndpy_get_copy_context(struct native_display *ndpy) +{ + if (!ndpy->pipe) + ndpy->pipe = ndpy->screen->context_create(ndpy->screen, NULL); + return ndpy->pipe; +} + +/** + * Free display screen and context resources + */ +static INLINE void +ndpy_uninit(struct native_display *ndpy) +{ + if (ndpy->pipe) + ndpy->pipe->destroy(ndpy->pipe); + if (ndpy->screen) + ndpy->screen->destroy(ndpy->screen); +} + struct native_platform { const char *name; diff --git a/src/gallium/state_trackers/egl/common/native_helper.c b/src/gallium/state_trackers/egl/common/native_helper.c index a9d8f32e007..be6713d03a8 100644 --- a/src/gallium/state_trackers/egl/common/native_helper.c +++ b/src/gallium/state_trackers/egl/common/native_helper.c @@ -3,6 +3,7 @@ * Version: 7.9 * * Copyright (C) 2010 LunarG Inc. + * Copyright (C) 2011 VMware Inc. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -24,6 +25,7 @@ * * Authors: * Chia-I Wu <[email protected]> + * Thomas Hellstrom <[email protected]> */ #include "util/u_inlines.h" @@ -34,6 +36,14 @@ #include "native_helper.h" +/** + * Number of swap fences and mask + */ + +#define EGL_SWAP_FENCES_MAX 4 +#define EGL_SWAP_FENCES_MASK 3 +#define EGL_SWAP_FENCES_DEFAULT 1 + struct resource_surface { struct pipe_screen *screen; enum pipe_format format; @@ -42,6 +52,15 @@ struct resource_surface { struct pipe_resource *resources[NUM_NATIVE_ATTACHMENTS]; uint resource_mask; uint width, height; + + /** + * Swap fences. + */ + struct pipe_fence_handle *swap_fences[EGL_SWAP_FENCES_MAX]; + unsigned int cur_fences; + unsigned int head; + unsigned int tail; + unsigned int desired_fences; }; struct resource_surface * @@ -49,11 +68,16 @@ resource_surface_create(struct pipe_screen *screen, enum pipe_format format, uint bind) { struct resource_surface *rsurf = CALLOC_STRUCT(resource_surface); + char *swap_fences = getenv("EGL_THROTTLE_FENCES"); if (rsurf) { rsurf->screen = screen; rsurf->format = format; rsurf->bind = bind; + rsurf->desired_fences = (swap_fences) ? atoi(swap_fences) : + EGL_SWAP_FENCES_DEFAULT; + if (rsurf->desired_fences > EGL_SWAP_FENCES_MAX) + rsurf->desired_fences = EGL_SWAP_FENCES_MAX; } return rsurf; @@ -225,3 +249,121 @@ resource_surface_present(struct resource_surface *rsurf, return TRUE; } + +/** + * Schedule a copy swap from the back to the front buffer using the + * native display's copy context. + */ +boolean +resource_surface_copy_swap(struct resource_surface *rsurf, + struct native_display *ndpy) +{ + struct pipe_resource *ftex; + struct pipe_resource *btex; + struct pipe_context *pipe; + struct pipe_box src_box; + boolean ret = FALSE; + + pipe = ndpy_get_copy_context(ndpy); + if (!pipe) + return FALSE; + + ftex = resource_surface_get_single_resource(rsurf, + NATIVE_ATTACHMENT_FRONT_LEFT); + if (!ftex) + goto out_no_ftex; + btex = resource_surface_get_single_resource(rsurf, + NATIVE_ATTACHMENT_BACK_LEFT); + if (!btex) + goto out_no_btex; + + u_box_origin_2d(ftex->width0, ftex->height0, &src_box); + pipe->resource_copy_region(pipe, ftex, 0, 0, 0, 0, + btex, 0, &src_box); + ret = TRUE; + + out_no_ftex: + pipe_resource_reference(&btex, NULL); + out_no_btex: + pipe_resource_reference(&ftex, NULL); + + return ret; +} + +static struct pipe_fence_handle * +swap_fences_pop_front(struct resource_surface *rsurf) +{ + struct pipe_screen *screen = rsurf->screen; + struct pipe_fence_handle *fence = NULL; + + if (rsurf->desired_fences == 0) + return NULL; + + if (rsurf->cur_fences >= rsurf->desired_fences) { + screen->fence_reference(screen, &fence, rsurf->swap_fences[rsurf->tail]); + screen->fence_reference(screen, &rsurf->swap_fences[rsurf->tail++], NULL); + rsurf->tail &= EGL_SWAP_FENCES_MASK; + --rsurf->cur_fences; + } + return fence; +} + +static void +swap_fences_push_back(struct resource_surface *rsurf, + struct pipe_fence_handle *fence) +{ + struct pipe_screen *screen = rsurf->screen; + + if (!fence || rsurf->desired_fences == 0) + return; + + while(rsurf->cur_fences == rsurf->desired_fences) + swap_fences_pop_front(rsurf); + + rsurf->cur_fences++; + screen->fence_reference(screen, &rsurf->swap_fences[rsurf->head++], + fence); + rsurf->head &= EGL_SWAP_FENCES_MASK; +} + +boolean +resource_surface_throttle(struct resource_surface *rsurf) +{ + struct pipe_screen *screen = rsurf->screen; + struct pipe_fence_handle *fence = swap_fences_pop_front(rsurf); + + if (fence) { + (void) screen->fence_finish(screen, fence, 0); + screen->fence_reference(screen, &fence, NULL); + return TRUE; + } + + return FALSE; +} + +boolean +resource_surface_flush(struct resource_surface *rsurf, + struct native_display *ndpy) +{ + struct pipe_fence_handle *fence = NULL; + struct pipe_screen *screen = rsurf->screen; + struct pipe_context *pipe= ndpy_get_copy_context(ndpy); + + if (!pipe) + return FALSE; + + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, &fence); + if (fence == NULL) + return FALSE; + + swap_fences_push_back(rsurf, fence); + screen->fence_reference(screen, &fence, NULL); + + return TRUE; +} + +void +resource_surface_wait(struct resource_surface *rsurf) +{ + while (resource_surface_throttle(rsurf)); +} diff --git a/src/gallium/state_trackers/egl/common/native_helper.h b/src/gallium/state_trackers/egl/common/native_helper.h index 03995de19ae..39564a04365 100644 --- a/src/gallium/state_trackers/egl/common/native_helper.h +++ b/src/gallium/state_trackers/egl/common/native_helper.h @@ -3,6 +3,7 @@ * Version: 7.9 * * Copyright (C) 2010 LunarG Inc. + * Copyright (C) 2011 VMware Inc. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -24,6 +25,7 @@ * * Authors: * Chia-I Wu <[email protected]> + * Thomas Hellstrom <[email protected]> */ #include "native.h" @@ -74,3 +76,32 @@ boolean resource_surface_present(struct resource_surface *rsurf, enum native_attachment which, void *winsys_drawable_handle); + +/** + * Perform a gallium copy blit between the back left and front left + * surfaces. Needs to be followed by a call to resource_surface_flush. + */ +boolean +resource_surface_copy_swap(struct resource_surface *rsurf, + struct native_display *ndpy); + +/** + * Throttle on outstanding rendering using the copy context. For example + * copy swaps. + */ +boolean +resource_surface_throttle(struct resource_surface *rsurf); + +/** + * Flush pending rendering using the copy context. This function saves a + * marker for upcoming throttles. + */ +boolean +resource_surface_flush(struct resource_surface *rsurf, + struct native_display *ndpy); +/** + * Wait for all rendering using the copy context to be complete. Frees all + * throttle markers saved using resource_surface_flush. + */ +void +resource_surface_wait(struct resource_surface *rsurf); diff --git a/src/gallium/state_trackers/egl/drm/modeset.c b/src/gallium/state_trackers/egl/drm/modeset.c index 0cc06caa2a1..3fff9540905 100644 --- a/src/gallium/state_trackers/egl/drm/modeset.c +++ b/src/gallium/state_trackers/egl/drm/modeset.c @@ -3,6 +3,7 @@ * Version: 7.9 * * Copyright (C) 2010 LunarG Inc. + * Copyright (C) 2011 VMware Inc. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -24,6 +25,7 @@ * * Authors: * Chia-I Wu <[email protected]> + * Thomas Hellstrom <[email protected]> */ #include "util/u_memory.h" @@ -131,6 +133,25 @@ drm_surface_flush_frontbuffer(struct native_surface *nsurf) } static boolean +drm_surface_copy_swap(struct native_surface *nsurf) +{ + struct drm_surface *drmsurf = drm_surface(nsurf); + struct drm_display *drmdpy = drmsurf->drmdpy; + + (void) resource_surface_throttle(drmsurf->rsurf); + if (!resource_surface_copy_swap(drmsurf->rsurf, &drmdpy->base)) + return FALSE; + + (void) resource_surface_flush(drmsurf->rsurf, &drmdpy->base); + if (!drm_surface_flush_frontbuffer(nsurf)) + return FALSE; + + drmsurf->sequence_number++; + + return TRUE; +} + +static boolean drm_surface_swap_buffers(struct native_surface *nsurf) { struct drm_surface *drmsurf = drm_surface(nsurf); @@ -139,17 +160,21 @@ drm_surface_swap_buffers(struct native_surface *nsurf) struct drm_framebuffer tmp_fb; int err; + if (!drmsurf->have_pageflip) + return drm_surface_copy_swap(nsurf); + if (!drmsurf->back_fb.buffer_id) { if (!drm_surface_init_framebuffers(&drmsurf->base, TRUE)) return FALSE; } if (drmsurf->is_shown && drmcrtc->crtc) { - err = drmModeSetCrtc(drmdpy->fd, drmcrtc->crtc->crtc_id, - drmsurf->back_fb.buffer_id, drmcrtc->crtc->x, drmcrtc->crtc->y, - drmcrtc->connectors, drmcrtc->num_connectors, &drmcrtc->crtc->mode); - if (err) - return FALSE; + err = drmModePageFlip(drmdpy->fd, drmcrtc->crtc->crtc_id, + drmsurf->back_fb.buffer_id, 0, NULL); + if (err) { + drmsurf->have_pageflip = FALSE; + return drm_surface_copy_swap(nsurf); + } } /* swap the buffers */ @@ -175,7 +200,7 @@ drm_surface_present(struct native_surface *nsurf, { boolean ret; - if (preserve || swap_interval) + if (swap_interval) return FALSE; switch (natt) { @@ -183,7 +208,10 @@ drm_surface_present(struct native_surface *nsurf, ret = drm_surface_flush_frontbuffer(nsurf); break; case NATIVE_ATTACHMENT_BACK_LEFT: - ret = drm_surface_swap_buffers(nsurf); + if (preserve) + ret = drm_surface_copy_swap(nsurf); + else + ret = drm_surface_swap_buffers(nsurf); break; default: ret = FALSE; @@ -196,7 +224,9 @@ drm_surface_present(struct native_surface *nsurf, static void drm_surface_wait(struct native_surface *nsurf) { - /* no-op */ + struct drm_surface *drmsurf = drm_surface(nsurf); + + resource_surface_wait(drmsurf->rsurf); } static void @@ -204,6 +234,7 @@ drm_surface_destroy(struct native_surface *nsurf) { struct drm_surface *drmsurf = drm_surface(nsurf); + resource_surface_wait(drmsurf->rsurf); if (drmsurf->current_crtc.crtc) drmModeFreeCrtc(drmsurf->current_crtc.crtc); @@ -236,6 +267,7 @@ drm_display_create_surface(struct native_display *ndpy, drmsurf->color_format = drmconf->base.color_format; drmsurf->width = width; drmsurf->height = height; + drmsurf->have_pageflip = TRUE; drmsurf->rsurf = resource_surface_create(drmdpy->base.screen, drmsurf->color_format, diff --git a/src/gallium/state_trackers/egl/drm/native_drm.c b/src/gallium/state_trackers/egl/drm/native_drm.c index 6932f30a6a4..cdbb304c5ee 100644 --- a/src/gallium/state_trackers/egl/drm/native_drm.c +++ b/src/gallium/state_trackers/egl/drm/native_drm.c @@ -124,8 +124,7 @@ drm_display_destroy(struct native_display *ndpy) drm_display_fini_modeset(&drmdpy->base); - if (drmdpy->base.screen) - drmdpy->base.screen->destroy(drmdpy->base.screen); + ndpy_uninit(ndpy); if (drmdpy->fd >= 0) close(drmdpy->fd); diff --git a/src/gallium/state_trackers/egl/drm/native_drm.h b/src/gallium/state_trackers/egl/drm/native_drm.h index 03c4fe01dc1..7da9b45f23e 100644 --- a/src/gallium/state_trackers/egl/drm/native_drm.h +++ b/src/gallium/state_trackers/egl/drm/native_drm.h @@ -91,6 +91,8 @@ struct drm_surface { boolean is_shown; struct drm_crtc current_crtc; + + boolean have_pageflip; }; struct drm_connector { diff --git a/src/gallium/state_trackers/egl/fbdev/native_fbdev.c b/src/gallium/state_trackers/egl/fbdev/native_fbdev.c index a1e91ba701c..4a96039ac39 100644 --- a/src/gallium/state_trackers/egl/fbdev/native_fbdev.c +++ b/src/gallium/state_trackers/egl/fbdev/native_fbdev.c @@ -320,7 +320,7 @@ fbdev_display_destroy(struct native_display *ndpy) { struct fbdev_display *fbdpy = fbdev_display(ndpy); - fbdpy->base.screen->destroy(fbdpy->base.screen); + ndpy_uninit(&fbdpy->base); close(fbdpy->fd); FREE(fbdpy); } diff --git a/src/gallium/state_trackers/egl/gdi/native_gdi.c b/src/gallium/state_trackers/egl/gdi/native_gdi.c index 3cc4aefa937..3c2475f84d8 100644 --- a/src/gallium/state_trackers/egl/gdi/native_gdi.c +++ b/src/gallium/state_trackers/egl/gdi/native_gdi.c @@ -363,7 +363,7 @@ gdi_display_destroy(struct native_display *ndpy) if (gdpy->configs) FREE(gdpy->configs); - gdpy->base.screen->destroy(gdpy->base.screen); + ndpy_uninit(ndpy); FREE(gdpy); } diff --git a/src/gallium/state_trackers/egl/wayland/native_wayland.c b/src/gallium/state_trackers/egl/wayland/native_wayland.c index d4d5f9c2ebb..068c3cd7c8e 100644 --- a/src/gallium/state_trackers/egl/wayland/native_wayland.c +++ b/src/gallium/state_trackers/egl/wayland/native_wayland.c @@ -41,6 +41,7 @@ #include "radeon/drm/radeon_drm_public.h" #include <wayland-client.h> +#include "wayland-drm-client-protocol.h" #include "wayland-egl-priv.h" #include <xf86drm.h> @@ -137,8 +138,7 @@ wayland_display_destroy(struct native_display *ndpy) if (display->config) FREE(display->config); - if (display->base.screen) - display->base.screen->destroy(display->base.screen); + ndpy_uninit(ndpy); FREE(display); } diff --git a/src/gallium/state_trackers/egl/x11/native_ximage.c b/src/gallium/state_trackers/egl/x11/native_ximage.c index d4f4dd04df4..8e32c6ff0c4 100644 --- a/src/gallium/state_trackers/egl/x11/native_ximage.c +++ b/src/gallium/state_trackers/egl/x11/native_ximage.c @@ -476,7 +476,7 @@ ximage_display_destroy(struct native_display *ndpy) if (xdpy->configs) FREE(xdpy->configs); - xdpy->base.screen->destroy(xdpy->base.screen); + ndpy_uninit(ndpy); x11_screen_destroy(xdpy->xscr); if (xdpy->own_dpy) |