Commit adbdabb8 authored by Jakob Bornecrantz's avatar Jakob Bornecrantz

i915: Moved pipe_buffer and i915_winsys functions to a common folder

parent 18953a87
......@@ -71,6 +71,7 @@ PROGRAM_DIRS = demos redbook samples glsl xdemos
GALLIUM_AUXILIARY_DIRS = draw cso_cache pipebuffer tgsi sct translate rtasm util
GALLIUM_AUXILIARIES = $(foreach DIR,$(GALLIUM_AUXILIARY_DIRS),$(TOP)/src/gallium/auxiliary/$(DIR)/lib$(DIR).a)
GALLIUM_DRIVER_DIRS = softpipe i915simple i965simple failover
GALLIUM_WINSYS_COMMON_DIRS = intel_drm
GALLIUM_DRIVERS = $(foreach DIR,$(GALLIUM_DRIVER_DIRS),$(TOP)/src/gallium/drivers/$(DIR)/lib$(DIR).a)
GALLIUM_WINSYS_DIRS = xlib egl_xlib
......
......@@ -2,7 +2,7 @@ TOP = ../..
include $(TOP)/configs/current
SUBDIRS = auxiliary drivers
SUBDIRS = auxiliary drivers winsys/common
default: subdirs
......
TOP = ../../../..
include $(TOP)/configs/current
SUBDIRS = $(GALLIUM_WINSYS_COMMON_DIRS)
default: subdirs
subdirs:
@for dir in $(SUBDIRS) ; do \
if [ -d $$dir ] ; then \
(cd $$dir && $(MAKE)) || exit 1 ; \
fi \
done
clean:
rm -f `find . -name \*.[oa]`
# -*-makefile-*-
# We still have a dependency on the "dri" buffer manager. Most likely
# the interface can be reused in non-dri environments, and also as a
# frontend to simpler memory managers.
#
COMMON_SOURCES =
OBJECTS = $(C_SOURCES:.c=.o) \
$(CPP_SOURCES:.cpp=.o) \
$(ASM_SOURCES:.S=.o)
### Include directories
INCLUDES = \
-I. \
-I$(TOP)/src/gallium/include \
-I$(TOP)/src/gallium/auxiliary \
-I$(TOP)/src/gallium/drivers \
-I$(TOP)/include \
$(DRIVER_INCLUDES)
##### RULES #####
.c.o:
$(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@
.cpp.o:
$(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DRIVER_DEFINES) $< -o $@
.S.o:
$(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@
##### TARGETS #####
default: depend symlinks $(LIBNAME)
$(LIBNAME): $(OBJECTS) Makefile $(TOP)/src/gallium/winsys/common/Makefile.template
$(TOP)/bin/mklib -o $@ -static $(OBJECTS) $(DRIVER_LIBS)
depend: $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(SYMLINKS)
rm -f depend
touch depend
$(MKDEP) $(MKDEP_OPTIONS) $(DRIVER_DEFINES) $(INCLUDES) $(C_SOURCES) $(CPP_SOURCES) \
$(ASM_SOURCES) 2> /dev/null
# Emacs tags
tags:
etags `find . -name \*.[ch]` `find ../include`
# Remove .o and backup files
clean::
-rm -f *.o */*.o *~ *.so *~ server/*.o $(SYMLINKS)
-rm -f depend depend.bak
include depend
TOP = ../../../../..
include $(TOP)/configs/current
LIBNAME = inteldrm
C_SOURCES = \
intel_be_batchbuffer.c \
intel_be_context.c \
intel_be_device.c \
ws_dri_bufmgr.c \
ws_dri_drmpool.c \
ws_dri_fencemgr.c \
ws_dri_mallocpool.c \
ws_dri_slabpool.c
include ../Makefile.template
DRIVER_DEFINES = $(shell pkg-config libdrm --cflags \
&& pkg-config libdrm --atleast-version=2.3.1 \
&& echo "-DDRM_VBLANK_FLIP=DRM_VBLANK_FLIP")
symlinks:
/*
* Mesa 3-D graphics library
* Version: 6.5.2
*
* Copyright (C) 1999-2006 Brian Paul 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"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* Thread support for gl dispatch.
*
* Initial version by John Stone (j.stone@acm.org) (johns@cs.umr.edu)
* and Christoph Poliwoda (poliwoda@volumegraphics.com)
* Revised by Keith Whitwell
* Adapted for new gl dispatcher by Brian Paul
*
*
*
* DOCUMENTATION
*
* This thread module exports the following types:
* _glthread_TSD Thread-specific data area
* _glthread_Thread Thread datatype
* _glthread_Mutex Mutual exclusion lock
*
* Macros:
* _glthread_DECLARE_STATIC_MUTEX(name) Declare a non-local mutex
* _glthread_INIT_MUTEX(name) Initialize a mutex
* _glthread_LOCK_MUTEX(name) Lock a mutex
* _glthread_UNLOCK_MUTEX(name) Unlock a mutex
*
* Functions:
* _glthread_GetID(v) Get integer thread ID
* _glthread_InitTSD() Initialize thread-specific data
* _glthread_GetTSD() Get thread-specific data
* _glthread_SetTSD() Set thread-specific data
*
*/
/*
* If this file is accidentally included by a non-threaded build,
* it should not cause the build to fail, or otherwise cause problems.
* In general, it should only be included when needed however.
*/
#ifndef GLTHREAD_H
#define GLTHREAD_H
#if defined(USE_MGL_NAMESPACE)
#define _glapi_Dispatch _mglapi_Dispatch
#endif
#if (defined(PTHREADS) || defined(SOLARIS_THREADS) ||\
defined(WIN32_THREADS) || defined(USE_XTHREADS) || defined(BEOS_THREADS)) \
&& !defined(THREADS)
# define THREADS
#endif
#ifdef VMS
#include <GL/vms_x_fix.h>
#endif
/*
* POSIX threads. This should be your choice in the Unix world
* whenever possible. When building with POSIX threads, be sure
* to enable any compiler flags which will cause the MT-safe
* libc (if one exists) to be used when linking, as well as any
* header macros for MT-safe errno, etc. For Solaris, this is the -mt
* compiler flag. On Solaris with gcc, use -D_REENTRANT to enable
* proper compiling for MT-safe libc etc.
*/
#if defined(PTHREADS)
#include <pthread.h> /* POSIX threads headers */
typedef struct {
pthread_key_t key;
int initMagic;
} _glthread_TSD;
typedef pthread_t _glthread_Thread;
typedef pthread_mutex_t _glthread_Mutex;
#define _glthread_DECLARE_STATIC_MUTEX(name) \
static _glthread_Mutex name = PTHREAD_MUTEX_INITIALIZER
#define _glthread_INIT_MUTEX(name) \
pthread_mutex_init(&(name), NULL)
#define _glthread_DESTROY_MUTEX(name) \
pthread_mutex_destroy(&(name))
#define _glthread_LOCK_MUTEX(name) \
(void) pthread_mutex_lock(&(name))
#define _glthread_UNLOCK_MUTEX(name) \
(void) pthread_mutex_unlock(&(name))
typedef pthread_cond_t _glthread_Cond;
#define _glthread_DECLARE_STATIC_COND(name) \
static _glthread_Cond name = PTHREAD_COND_INITIALIZER
#define _glthread_INIT_COND(cond) \
pthread_cond_init(&(cond), NULL)
#define _glthread_DESTROY_COND(name) \
pthread_cond_destroy(&(name))
#define _glthread_COND_WAIT(cond, mutex) \
pthread_cond_wait(&(cond), &(mutex))
#define _glthread_COND_SIGNAL(cond) \
pthread_cond_signal(&(cond))
#define _glthread_COND_BROADCAST(cond) \
pthread_cond_broadcast(&(cond))
#else /* PTHREADS */
typedef unsigned int _glthread_Cond;
#define _glthread_DECLARE_STATIC_COND(name) \
// #warning Condition variables not implemented.
#define _glthread_INIT_COND(cond) \
abort();
#define _glthread_DESTROY_COND(name) \
abort();
#define _glthread_COND_WAIT(cond, mutex) \
abort();
#define _glthread_COND_SIGNAL(cond) \
abort();
#define _glthread_COND_BROADCAST(cond) \
abort();
#endif
/*
* Solaris threads. Use only up to Solaris 2.4.
* Solaris 2.5 and higher provide POSIX threads.
* Be sure to compile with -mt on the Solaris compilers, or
* use -D_REENTRANT if using gcc.
*/
#ifdef SOLARIS_THREADS
#include <thread.h>
typedef struct {
thread_key_t key;
mutex_t keylock;
int initMagic;
} _glthread_TSD;
typedef thread_t _glthread_Thread;
typedef mutex_t _glthread_Mutex;
/* XXX need to really implement mutex-related macros */
#define _glthread_DECLARE_STATIC_MUTEX(name) static _glthread_Mutex name = 0
#define _glthread_INIT_MUTEX(name) (void) name
#define _glthread_DESTROY_MUTEX(name) (void) name
#define _glthread_LOCK_MUTEX(name) (void) name
#define _glthread_UNLOCK_MUTEX(name) (void) name
#endif /* SOLARIS_THREADS */
/*
* Windows threads. Should work with Windows NT and 95.
* IMPORTANT: Link with multithreaded runtime library when THREADS are
* used!
*/
#ifdef WIN32_THREADS
#include <windows.h>
typedef struct {
DWORD key;
int initMagic;
} _glthread_TSD;
typedef HANDLE _glthread_Thread;
typedef CRITICAL_SECTION _glthread_Mutex;
#define _glthread_DECLARE_STATIC_MUTEX(name) /*static*/ _glthread_Mutex name = {0,0,0,0,0,0}
#define _glthread_INIT_MUTEX(name) InitializeCriticalSection(&name)
#define _glthread_DESTROY_MUTEX(name) DeleteCriticalSection(&name)
#define _glthread_LOCK_MUTEX(name) EnterCriticalSection(&name)
#define _glthread_UNLOCK_MUTEX(name) LeaveCriticalSection(&name)
#endif /* WIN32_THREADS */
/*
* XFree86 has its own thread wrapper, Xthreads.h
* We wrap it again for GL.
*/
#ifdef USE_XTHREADS
#include <X11/Xthreads.h>
typedef struct {
xthread_key_t key;
int initMagic;
} _glthread_TSD;
typedef xthread_t _glthread_Thread;
typedef xmutex_rec _glthread_Mutex;
#ifdef XMUTEX_INITIALIZER
#define _glthread_DECLARE_STATIC_MUTEX(name) \
static _glthread_Mutex name = XMUTEX_INITIALIZER
#else
#define _glthread_DECLARE_STATIC_MUTEX(name) \
static _glthread_Mutex name
#endif
#define _glthread_INIT_MUTEX(name) \
xmutex_init(&(name))
#define _glthread_DESTROY_MUTEX(name) \
xmutex_clear(&(name))
#define _glthread_LOCK_MUTEX(name) \
(void) xmutex_lock(&(name))
#define _glthread_UNLOCK_MUTEX(name) \
(void) xmutex_unlock(&(name))
#endif /* USE_XTHREADS */
/*
* BeOS threads. R5.x required.
*/
#ifdef BEOS_THREADS
#include <kernel/OS.h>
#include <support/TLS.h>
typedef struct {
int32 key;
int initMagic;
} _glthread_TSD;
typedef thread_id _glthread_Thread;
/* Use Benaphore, aka speeder semaphore */
typedef struct {
int32 lock;
sem_id sem;
} benaphore;
typedef benaphore _glthread_Mutex;
#define _glthread_DECLARE_STATIC_MUTEX(name) static _glthread_Mutex name = { 0, 0 }
#define _glthread_INIT_MUTEX(name) name.sem = create_sem(0, #name"_benaphore"), name.lock = 0
#define _glthread_DESTROY_MUTEX(name) delete_sem(name.sem), name.lock = 0
#define _glthread_LOCK_MUTEX(name) if (name.sem == 0) _glthread_INIT_MUTEX(name); \
if (atomic_add(&(name.lock), 1) >= 1) acquire_sem(name.sem)
#define _glthread_UNLOCK_MUTEX(name) if (atomic_add(&(name.lock), -1) > 1) release_sem(name.sem)
#endif /* BEOS_THREADS */
#ifndef THREADS
/*
* THREADS not defined
*/
typedef GLuint _glthread_TSD;
typedef GLuint _glthread_Thread;
typedef GLuint _glthread_Mutex;
#define _glthread_DECLARE_STATIC_MUTEX(name) static _glthread_Mutex name = 0
#define _glthread_INIT_MUTEX(name) (void) name
#define _glthread_DESTROY_MUTEX(name) (void) name
#define _glthread_LOCK_MUTEX(name) (void) name
#define _glthread_UNLOCK_MUTEX(name) (void) name
#endif /* THREADS */
/*
* Platform independent thread specific data API.
*/
extern unsigned long
_glthread_GetID(void);
extern void
_glthread_InitTSD(_glthread_TSD *);
extern void *
_glthread_GetTSD(_glthread_TSD *);
extern void
_glthread_SetTSD(_glthread_TSD *, void *);
#if defined(GLX_USE_TLS)
extern __thread struct _glapi_table * _glapi_tls_Dispatch
__attribute__((tls_model("initial-exec")));
#define GET_DISPATCH() _glapi_tls_Dispatch
#elif !defined(GL_CALL)
# if defined(THREADS)
# define GET_DISPATCH() \
((__builtin_expect( _glapi_Dispatch != NULL, 1 )) \
? _glapi_Dispatch : _glapi_get_dispatch())
# else
# define GET_DISPATCH() _glapi_Dispatch
# endif /* defined(THREADS) */
#endif /* ndef GL_CALL */
#endif /* THREADS_H */
/**************************************************************************
*
* Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
* 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"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#include "intel_batchbuffer.h"
#include "intel_context.h"
#include "intel_be_batchbuffer.h"
#include "intel_be_context.h"
#include "intel_be_device.h"
#include <errno.h>
#if 0
static void
intel_dump_batchbuffer(GLuint offset, GLuint * ptr, GLuint count)
{
int i;
fprintf(stderr, "\n\n\nSTART BATCH (%d dwords):\n", count / 4);
for (i = 0; i < count / 4; i += 4)
fprintf(stderr, "0x%x:\t0x%08x 0x%08x 0x%08x 0x%08x\n",
offset + i * 4, ptr[i], ptr[i + 1], ptr[i + 2], ptr[i + 3]);
fprintf(stderr, "END BATCH\n\n\n");
}
#endif
#include "xf86drm.h"
static void
intel_realloc_relocs(struct intel_batchbuffer *batch, int num_relocs)
static void
intel_realloc_relocs(struct intel_be_batchbuffer *batch, int num_relocs)
{
unsigned long size = num_relocs * I915_RELOC0_STRIDE + I915_RELOC_HEADER;
size *= sizeof(uint32_t);
batch->reloc = realloc(batch->reloc, size);
batch->reloc_size = num_relocs;
......@@ -54,20 +18,20 @@ intel_realloc_relocs(struct intel_batchbuffer *batch, int num_relocs)
void
intel_batchbuffer_reset(struct intel_batchbuffer *batch)
intel_be_batchbuffer_reset(struct intel_be_batchbuffer *batch)
{
/*
* Get a new, free batchbuffer.
*/
drmBO *bo;
struct drm_bo_info_req *req;
driBOUnrefUserList(batch->list);
driBOResetList(batch->list);
/* base.size is the size available to the i915simple driver */
batch->base.size = batch->intel->intelScreen->max_batch_size - BATCH_RESERVED;
batch->base.actual_size = batch->intel->intelScreen->max_batch_size;
batch->base.size = batch->device->max_batch_size - BATCH_RESERVED;
batch->base.actual_size = batch->device->max_batch_size;
driBOData(batch->buffer, batch->base.actual_size, NULL, NULL, 0);
/*
......@@ -98,9 +62,9 @@ intel_batchbuffer_reset(struct intel_batchbuffer *batch)
*/
if (batch->reloc_size > INTEL_MAX_RELOCS ||
batch->reloc == NULL)
batch->reloc == NULL)
intel_realloc_relocs(batch, INTEL_DEFAULT_RELOCS);
assert(batch->reloc != NULL);
batch->reloc[0] = 0; /* No relocs yet. */
batch->reloc[1] = 1; /* Reloc type 1 */
......@@ -119,29 +83,30 @@ intel_batchbuffer_reset(struct intel_batchbuffer *batch)
/*======================================================================
* Public functions
*/
struct intel_batchbuffer *
intel_batchbuffer_alloc(struct intel_context *intel)
struct intel_be_batchbuffer *
intel_be_batchbuffer_alloc(struct intel_be_context *intel)
{
struct intel_batchbuffer *batch = calloc(sizeof(*batch), 1);
struct intel_be_batchbuffer *batch = calloc(sizeof(*batch), 1);
batch->intel = intel;
batch->device = intel->device;
driGenBuffers(intel->intelScreen->batchPool, "batchbuffer", 1,
driGenBuffers(intel->device->batchPool, "batchbuffer", 1,
&batch->buffer, 4096,
DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_EXE, 0);
batch->last_fence = NULL;
batch->list = driBOCreateList(20);
batch->reloc = NULL;
intel_batchbuffer_reset(batch);
intel_be_batchbuffer_reset(batch);
return batch;
}
void
intel_batchbuffer_free(struct intel_batchbuffer *batch)
intel_be_batchbuffer_free(struct intel_be_batchbuffer *batch)