diff options
author | Kristian Høgsberg <krh@kisame.bos.redhat.com> | 2009-06-08 16:04:53 -0400 |
---|---|---|
committer | Kristian Høgsberg <krh@redhat.com> | 2009-06-08 16:14:31 -0400 |
commit | 433faebf56ad3057cf49886ce6cefc949aef1362 (patch) | |
tree | 813c30787955c9e2c0791dc0f9cef6f01f9933a6 | |
parent | e41c5426348028363617d6f0e43b21914e7bb738 (diff) |
Consolidate native gem code a bit, sneak in another radeon attempt
-rw-r--r-- | Makefile.in | 7 | ||||
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | eagle-internal.h | 1 | ||||
-rw-r--r-- | eagle.c | 4 | ||||
-rw-r--r-- | glapi/glapi.c | 2 | ||||
-rw-r--r-- | glapi/glapi.h | 2 | ||||
-rw-r--r-- | glapi/glapi_getproc.c | 2 | ||||
-rw-r--r-- | glapi/glthread.c | 25 | ||||
-rw-r--r-- | native.c (renamed from intel.c) | 240 | ||||
-rw-r--r-- | radeon.c | 213 | ||||
-rw-r--r-- | x11-dri2.c | 4 |
11 files changed, 176 insertions, 327 deletions
diff --git a/Makefile.in b/Makefile.in index a20fc80..5c2d79f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,4 +1,4 @@ -CFLAGS = -fPIC -g @GCC_CFLAGS@ @EAGLE_CFLAGS@ +CFLAGS = -DEAGLE_DRIVER_PATH=\"@EAGLE_DRIVER_PATH@\" -fPIC -g @GCC_CFLAGS@ @EAGLE_CFLAGS@ LDLIBS = @EAGLE_LIBS@ -ldl prefix = @prefix@ @@ -8,12 +8,9 @@ all : libeagle.so x11_dri2_objs = x11-dri2.o libdri2.o -intel_objs = intel.o -radeon_objs = radeon.o - objs = \ eagle.o \ - intel.o \ + native.o \ $(x11_dri2_objs) \ glapi/glapi.o \ glapi/dispatch.o \ diff --git a/configure.ac b/configure.ac index 19db90d..9ae3af4 100644 --- a/configure.ac +++ b/configure.ac @@ -11,5 +11,8 @@ if test $CC = gcc; then fi AC_SUBST(GCC_CFLAGS) +EAGLE_DRIVER_PATH=$libdir/dri +AC_SUBST(EAGLE_DRIVER_PATH) + AC_CONFIG_FILES([Makefile eagle.pc test/Makefile]) AC_OUTPUT
\ No newline at end of file diff --git a/eagle-internal.h b/eagle-internal.h index 6adc18d..b52c136 100644 --- a/eagle-internal.h +++ b/eagle-internal.h @@ -60,7 +60,6 @@ struct EGLDisplay { __DRI2flushExtension *flush; const struct EagleBackend *backend; - void *backendPrivate; }; struct EGLSurface { @@ -103,7 +103,7 @@ static const __DRIextension *eglLoaderExtensions[] = { NULL }; -static const char driDriverPath[] = "/usr/lib/dri"; +static const char driDriverPath[] = EAGLE_DRIVER_PATH; static int eglLoadDriver(EGLDisplay display, const char *driverName) @@ -273,6 +273,8 @@ static const struct dri_driver_entry driver_map[] = { { 0x8086, 0x2e22, i965CreateDisplay }, /* PCI_CHIP_G45_G */ { 0x8086, 0x2e32, i965CreateDisplay }, /* PCI_CHIP_G41_G */ + { 0x1002, 0x7249, r300CreateDisplay }, /* X1900 XT */ + { 0, } }; diff --git a/glapi/glapi.c b/glapi/glapi.c index 17fa11a..24fe52a 100644 --- a/glapi/glapi.c +++ b/glapi/glapi.c @@ -50,8 +50,6 @@ -#define PUBLIC - #include <stdlib.h> #include <string.h> #ifdef DEBUG diff --git a/glapi/glapi.h b/glapi/glapi.h index 8f2cf66..f0492d9 100644 --- a/glapi/glapi.h +++ b/glapi/glapi.h @@ -48,9 +48,9 @@ #include "GL/gl.h" #include "GL/glext.h" +#include "glheader.h" #include "glthread.h" - struct _glapi_table; typedef void (*_glapi_proc)(void); /* generic function pointer */ diff --git a/glapi/glapi_getproc.c b/glapi/glapi_getproc.c index 68adfe5..e4c4791 100644 --- a/glapi/glapi_getproc.c +++ b/glapi/glapi_getproc.c @@ -36,8 +36,6 @@ #include "glapioffsets.h" #include "glapitable.h" -#define PUBLIC - static void fill_in_entrypoint_offset(_glapi_proc entrypoint, GLuint offset); diff --git a/glapi/glthread.c b/glapi/glthread.c index b818f4e..48f4505 100644 --- a/glapi/glthread.c +++ b/glapi/glthread.c @@ -35,6 +35,7 @@ #include <stdlib.h> #include <stdio.h> +#include "glheader.h" #include "glthread.h" @@ -71,14 +72,14 @@ */ #ifdef PTHREADS -unsigned long +PUBLIC unsigned long _glthread_GetID(void) { return (unsigned long) pthread_self(); } -void +PUBLIC void _glthread_InitTSD(_glthread_TSD *tsd) { if (pthread_key_create(&tsd->key, NULL/*free*/) != 0) { @@ -89,7 +90,7 @@ _glthread_InitTSD(_glthread_TSD *tsd) } -void * +PUBLIC void * _glthread_GetTSD(_glthread_TSD *tsd) { if (tsd->initMagic != (int) INIT_MAGIC) { @@ -99,7 +100,7 @@ _glthread_GetTSD(_glthread_TSD *tsd) } -void +PUBLIC void _glthread_SetTSD(_glthread_TSD *tsd, void *ptr) { if (tsd->initMagic != (int) INIT_MAGIC) { @@ -125,7 +126,7 @@ _glthread_SetTSD(_glthread_TSD *tsd, void *ptr) #define USE_LOCK_FOR_KEY /* undef this to try a version without lock for the global key... */ -unsigned long +PUBLIC unsigned long _glthread_GetID(void) { abort(); /* XXX not implemented yet */ @@ -133,7 +134,7 @@ _glthread_GetID(void) } -void +PUBLIC void _glthread_InitTSD(_glthread_TSD *tsd) { if ((errno = mutex_init(&tsd->keylock, 0, NULL)) != 0 || @@ -145,7 +146,7 @@ _glthread_InitTSD(_glthread_TSD *tsd) } -void * +PUBLIC void * _glthread_GetTSD(_glthread_TSD *tsd) { void* ret; @@ -166,7 +167,7 @@ _glthread_GetTSD(_glthread_TSD *tsd) } -void +PUBLIC void _glthread_SetTSD(_glthread_TSD *tsd, void *ptr) { if (tsd->initMagic != INIT_MAGIC) { @@ -346,21 +347,21 @@ _glthread_SetTSD(_glthread_TSD *tsd, void *ptr) * no-op functions */ -unsigned long +PUBLIC unsigned long _glthread_GetID(void) { return 0; } -void +PUBLIC void _glthread_InitTSD(_glthread_TSD *tsd) { (void) tsd; } -void * +PUBLIC void * _glthread_GetTSD(_glthread_TSD *tsd) { (void) tsd; @@ -368,7 +369,7 @@ _glthread_GetTSD(_glthread_TSD *tsd) } -void +PUBLIC void _glthread_SetTSD(_glthread_TSD *tsd, void *ptr) { (void) tsd; @@ -29,11 +29,18 @@ #include <fcntl.h> #include <unistd.h> #include <i915_drm.h> +#include <radeon_drm.h> #include <GL/gl.h> /* dri_interface.h uses some GL integer types... */ #include "eagle-internal.h" #define INTEL_STRIDE_ALIGNMENT 64 +struct EagleBackendNative { + struct EagleBackend base; + int (*createBuffer)(int fd, + GLint width, GLint height, __DRIbuffer *buffer); +}; + typedef struct EGLSurfaceNative *EGLSurfaceNative; struct EGLSurfaceNative { struct EGLSurface base; @@ -50,6 +57,100 @@ align_to(uint32_t value, uint32_t align) return (value + align - 1) & ~(align - 1); } +static void +nativeGetBuffers(EGLSurface surface, unsigned int *attachments, int count) +{ + EGLSurfaceNative nativeSurface = (EGLSurfaceNative) surface; + struct EagleBackendNative *backend = + (struct EagleBackendNative *) surface->display->backend; + __DRIbuffer *buffer; + int i; + + buffer = &surface->buffers[0]; + buffer->pitch = nativeSurface->current->pitch; + buffer->name = nativeSurface->current->name; + buffer->cpp = nativeSurface->current->cpp; + + if (count == surface->count) + return; + + for (i = 0; i < count; i++) { + if (attachments[i] == __DRI_BUFFER_DEPTH) + surface->depth = i; + + buffer = &surface->buffers[i]; + buffer->attachment = attachments[i]; + + if (buffer->attachment == __DRI_BUFFER_FRONT_LEFT) { + buffer->pitch = nativeSurface->current->pitch; + buffer->name = nativeSurface->current->name; + buffer->cpp = nativeSurface->current->cpp; + continue; + } + + if (attachments[i] == __DRI_BUFFER_STENCIL) { + buffer->name = surface->buffers[surface->depth].name; + nativeSurface->handles[i] = + nativeSurface->handles[surface->depth]; + continue; + } + + nativeSurface->handles[i] = + backend->createBuffer(surface->display->fd, + surface->width, + surface->height, + buffer); + } + + surface->count = count; +} + +static EGLBoolean +nativeDestroySurface(EGLDisplay display, EGLSurface surface) +{ + EGLSurfaceNative nativeSurface = (EGLSurfaceNative) surface; + struct drm_gem_close close; + int i; + + for (i = 0; i < nativeSurface->colorBufferCount; i++) { + close.handle = nativeSurface->colorBufferHandles[i]; + if (ioctl(surface->display->fd, DRM_IOCTL_GEM_CLOSE, &close) < 0) + fprintf(stderr, "close of bo %d failed\n", close.handle); + } + + for (i = 0; i < surface->count; i++) { + close.handle = nativeSurface->handles[i]; + if (ioctl(surface->display->fd, DRM_IOCTL_GEM_CLOSE, &close) < 0) + fprintf(stderr, "close of bo %d failed\n", close.handle); + } + + free(surface); + + return EGL_TRUE; +} + +static EGLDisplay +nativeCreateDisplay(struct udev_device *device, + const char *driver, const struct EagleBackend *backend) +{ + EGLDisplay display; + const char *path; + + display = malloc(sizeof *display); + if (display == NULL) + return NULL; + + path = udev_device_get_devnode(device); + if (eglInitDisplay(display, path, driver) < 0) { + free(display); + return NULL; + } + + display->backend = backend; + + return display; +} + /* Look at xf86-video-intel/src/common.h for the full horror of device * identification. */ @@ -175,112 +276,75 @@ intelCreateBuffer(int fd, GLint width, GLint height, __DRIbuffer *buffer) return create.handle; } -static void -intelGetBuffers(EGLSurface surface, unsigned int *attachments, int count) -{ - EGLSurfaceNative nativeSurface = (EGLSurfaceNative) surface; - __DRIbuffer *buffer; - int i; - - buffer = &surface->buffers[0]; - buffer->pitch = nativeSurface->current->pitch; - buffer->name = nativeSurface->current->name; - buffer->cpp = nativeSurface->current->cpp; - - if (count == surface->count) - return; - - for (i = 0; i < count; i++) { - if (attachments[i] == __DRI_BUFFER_DEPTH) - surface->depth = i; - - buffer = &surface->buffers[i]; - buffer->attachment = attachments[i]; - - if (buffer->attachment == __DRI_BUFFER_FRONT_LEFT) { - buffer->pitch = nativeSurface->current->pitch; - buffer->name = nativeSurface->current->name; - buffer->cpp = nativeSurface->current->cpp; - continue; - } - - if (attachments[i] == __DRI_BUFFER_STENCIL) { - buffer->name = surface->buffers[surface->depth].name; - nativeSurface->handles[i] = - nativeSurface->handles[surface->depth]; - continue; - } - - nativeSurface->handles[i] = - intelCreateBuffer(surface->display->fd, - surface->width, - surface->height, - buffer); - } +static const struct EagleBackendNative intelBackend = { + { + nativeGetBuffers, + nativeDestroySurface, + }, + intelCreateBuffer +}; - surface->count = count; +EGLDisplay +i915CreateDisplay(struct udev_device *device) +{ + return nativeCreateDisplay(device, "i915", &intelBackend.base); } -static EGLBoolean -intelDestroySurface(EGLDisplay display, EGLSurface surface) +EGLDisplay +i965CreateDisplay(struct udev_device *device) { - EGLSurfaceNative nativeSurface = (EGLSurfaceNative) surface; - struct drm_gem_close close; - int i; + return nativeCreateDisplay(device, "i965", &intelBackend.base); +} - for (i = 0; i < nativeSurface->colorBufferCount; i++) { - close.handle = nativeSurface->colorBufferHandles[i]; - if (ioctl(surface->display->fd, DRM_IOCTL_GEM_CLOSE, &close) < 0) - fprintf(stderr, "close of bo %d failed\n", close.handle); - } +#define RADEON_ALIGNMENT 64 - for (i = 0; i < surface->count; i++) { - close.handle = nativeSurface->handles[i]; - if (ioctl(surface->display->fd, DRM_IOCTL_GEM_CLOSE, &close) < 0) - fprintf(stderr, "close of bo %d failed\n", close.handle); - } - - free(surface); +static int +radeonCreateBuffer(int fd, GLint width, GLint height, __DRIbuffer *buffer) +{ +#ifdef DRM_IOCTL_RADEON_GEM_CREATE + struct drm_radeon_gem_create create; + struct drm_gem_flink flink; - return EGL_TRUE; -} + buffer->pitch = align_to(width * 4, RADEON_ALIGNMENT); + buffer->cpp = 4; -static const struct EagleBackend intelBackend = { - intelGetBuffers, - intelDestroySurface, -}; + create.size = buffer->pitch * height; + create.alignment = 4096; + create.initial_domain = RADEON_GEM_DOMAIN_VRAM; + create.flags = RADEON_GEM_NO_BACKING_STORE; -static EGLDisplay -intelCreateDisplay(struct udev_device *device, const char *driver) -{ - EGLDisplay display; - const char *path; + if (ioctl(fd, DRM_IOCTL_RADEON_GEM_CREATE, &create)) { + fprintf(stderr, "failed to create buffer\n"); + return -1; + } - display = malloc(sizeof *display); - if (display == NULL) - return NULL; - - path = udev_device_get_devnode(device); - if (eglInitDisplay(display, path, driver) < 0) { - free(display); - return NULL; + flink.handle = create.handle; + if (ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink) < 0) { + fprintf(stderr, "failed to create buffer\n"); + return -1; } - display->backend = &intelBackend; + buffer->name = flink.name; - return display; + return create.handle; +#else + return -1; +#endif } -EGLDisplay -i915CreateDisplay(struct udev_device *device) -{ - return intelCreateDisplay(device, "i915"); -} +static const struct EagleBackendNative radeonBackend = { + { + nativeGetBuffers, + nativeDestroySurface, + }, + + radeonCreateBuffer +}; EGLDisplay -i965CreateDisplay(struct udev_device *device) +r300CreateDisplay(struct udev_device *device) { - return intelCreateDisplay(device, "i965"); + return nativeCreateDisplay(device, "r300", &radeonBackend.base); } EAGLE_EXPORT EGLSurface diff --git a/radeon.c b/radeon.c deleted file mode 100644 index 6e968b9..0000000 --- a/radeon.c +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright © 2008 Kristian Høgsberg - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <stdint.h> -#include <sys/ioctl.h> -#include <sys/mman.h> -#include <fcntl.h> -#include <unistd.h> -#include <drm.h> -#include <radeon_drm.h> -#include <GL/gl.h> /* dri_interface.h uses some GL integer types... */ -#include "eagle-internal.h" - -typedef struct EGLSurfaceNative *EGLSurfaceNative; -struct EGLSurfaceNative { - struct EGLSurface base; - uint32_t handles[10]; - EGLBoolean backBuffer; - __DRIbuffer front; - uint32_t frontHandle; -}; - -static inline uint32_t -align_to(uint32_t value, uint32_t align) -{ - return (value + align - 1) & ~(align - 1); -} - -#define RADEON_ALIGNMENT 64 - -static void -r300GetBuffers(EGLSurface surface, unsigned int *attachments, int count) -{ - EGLSurfaceNative nativeSurface = (EGLSurfaceNative) surface; - struct drm_radeon_gem_create create; - struct drm_gem_flink flink; - struct drm_gem_open open_arg; - __DRIbuffer *buffer; - uint32_t size; - int fd, i, ret; - - if (count == surface->count) - return; - - for (i = 0; i < count; i++) { - if (attachments[i] == __DRI_BUFFER_DEPTH) - surface->depth = i; - - buffer = &surface->buffers[i]; - buffer->attachment = attachments[i]; - buffer->pitch = align_to(surface->width * 4, - RADEON_ALIGNMENT); - buffer->cpp = 4; - - if (buffer->attachment == __DRI_BUFFER_FRONT_LEFT && - nativeSurface->front.name != ~0 && - !nativeSurface->backBuffer) { - buffer->name = nativeSurface->front.name; - buffer->pitch = nativeSurface->front.pitch; - open_arg.name = buffer->name; - ret = ioctl(surface->display->fd, - DRM_IOCTL_GEM_OPEN, &open_arg); - nativeSurface->handles[i] = open_arg.handle; - continue; - } - - if (attachments[i] == __DRI_BUFFER_STENCIL) { - buffer->name = surface->buffers[surface->depth].name; - nativeSurface->handles[i] = - nativeSurface->handles[surface->depth]; - continue; - } - - size = buffer->pitch * surface->height; - fd = surface->display->fd; - - create.size = size; - create.alignment = 4096; - create.initial_domain = RADEON_GEM_DOMAIN_VRAM; - create.no_backing_store = 1; - - if (ioctl(fd, DRM_IOCTL_RADEON_GEM_CREATE, &create)) { - fprintf(stderr, "failed to create buffer\n"); - return; - } - nativeSurface->handles[i] = create.handle; - - flink.handle = create.handle; - if (ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink) < 0) { - fprintf(stderr, "failed to create buffer\n"); - return; - } - - buffer->name = flink.name; - } - - surface->count = count; -} - -static EGLBoolean -r300DestroySurface(EGLDisplay display, EGLSurface surface) -{ - free(surface); - - return EGL_TRUE; -} - -static EGLBoolean -r300SwapBuffers(EGLDisplay display, EGLSurface surface) -{ - EGLSurfaceNative nativeSurface = (EGLSurfaceNative) surface; - EGLContext context; - __DRIbuffer *back; - - if (!nativeSurface->backBuffer) - return EGL_TRUE; - - context = eglGetCurrentContext(); - - back = &surface->buffers[0]; - - display->copyBuffer->copyBuffer(context->driContext, - &nativeSurface->front, - 0, 0, - back, - 0, 0, - surface->width, - surface->height); - - glFlush(); - - return EGL_TRUE; -} - -static EGLSurface -r300CreateSurfaceForName(EGLDisplay display, EGLConfig config, - uint32_t name, uint32_t width, - uint32_t height, uint32_t stride, const EGLint *attribList) -{ - EGLSurfaceNative nativeSurface; - int i; - - nativeSurface = malloc(sizeof *nativeSurface); - if (nativeSurface == NULL) - return NULL; - - nativeSurface->backBuffer = EGL_FALSE; - - nativeSurface->front.attachment = __DRI_BUFFER_FRONT_LEFT; - nativeSurface->front.name = name; - nativeSurface->front.pitch = stride; - nativeSurface->front.cpp = 4; - nativeSurface->front.flags = 0; - nativeSurface->frontHandle = 0; - - eglInitSurface(&nativeSurface->base, display, config, width, height); - - for (i = 0; attribList && attribList[i] != EGL_NONE; i += 2) { - if (attribList[i] == EGL_RENDER_BUFFER && - attribList[i + 1] == EGL_BACK_BUFFER) - nativeSurface->backBuffer = EGL_TRUE; - } - - return &nativeSurface->base; -} - -static const struct EagleBackend r300Backend = { - r300GetBuffers, - r300SwapBuffers, - r300DestroySurface, - r300CreateSurfaceForName -}; - -EGLDisplay -r300CreateDisplay(struct udev_device *device) -{ - EGLDisplay display; - - display = malloc(sizeof *display); - if (display == NULL) - return NULL; - - if (eglInitDisplay(display, device, "r300") < 0) { - free(display); - return NULL; - } - - display->backend = &r300Backend; - - return display; -} @@ -118,7 +118,7 @@ static const struct EagleBackend x11Backend = { x11DestroySurface }; -EGLDisplay +EAGLE_EXPORT EGLDisplay eglCreateDisplayX11(Display *display, Window root) { EGLDisplayX11 x11Display; @@ -161,7 +161,7 @@ eglCreateDisplayX11(Display *display, Window root) return &x11Display->base; } -EGLSurface +EAGLE_EXPORT EGLSurface eglCreateSurfaceX11(EGLDisplay display, EGLConfig config, Window window, int width, int height) { |