summaryrefslogtreecommitdiff
path: root/src/gallium/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/include')
-rw-r--r--src/gallium/include/pipe/p_compiler.h12
-rw-r--r--src/gallium/include/pipe/p_context.h48
-rw-r--r--src/gallium/include/pipe/p_defines.h10
-rw-r--r--src/gallium/include/pipe/p_format.h10
-rw-r--r--src/gallium/include/pipe/p_inlines.h28
-rw-r--r--src/gallium/include/pipe/p_pointer.h95
-rw-r--r--src/gallium/include/pipe/p_screen.h98
-rw-r--r--src/gallium/include/pipe/p_shader_tokens.h16
-rw-r--r--src/gallium/include/pipe/p_state.h71
-rw-r--r--src/gallium/include/pipe/p_thread.h327
-rw-r--r--src/gallium/include/pipe/p_util.h44
-rw-r--r--src/gallium/include/pipe/p_winsys.h20
12 files changed, 642 insertions, 137 deletions
diff --git a/src/gallium/include/pipe/p_compiler.h b/src/gallium/include/pipe/p_compiler.h
index 30cd729c56..91f3d2ac2d 100644
--- a/src/gallium/include/pipe/p_compiler.h
+++ b/src/gallium/include/pipe/p_compiler.h
@@ -1,6 +1,6 @@
/**************************************************************************
*
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -42,6 +42,14 @@
#endif
+#if defined(__MSC__)
+
+/* Avoid 'expression is always true' warning */
+#pragma warning(disable: 4296)
+
+#endif /* __MSC__ */
+
+
typedef unsigned int uint;
typedef unsigned char ubyte;
typedef unsigned char boolean;
@@ -61,8 +69,10 @@ typedef long long int64_t;
typedef unsigned long long uint64_t;
#if defined(_WIN64)
+typedef __int64 intptr_t;
typedef unsigned __int64 uintptr_t;
#else
+typedef int intptr_t;
typedef unsigned int uintptr_t;
#endif
diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h
index 39f95695fb..1501b52f3e 100644
--- a/src/gallium/include/pipe/p_context.h
+++ b/src/gallium/include/pipe/p_context.h
@@ -31,6 +31,13 @@
#include "p_state.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+struct pipe_screen;
+
struct pipe_state_cache;
/* Opaque driver handles:
@@ -46,27 +53,14 @@ struct pipe_query;
*/
struct pipe_context {
struct pipe_winsys *winsys;
+ struct pipe_screen *screen;
void *priv; /** context private data (for DRI for example) */
+ void *draw; /** private, for draw module (temporary? */
void (*destroy)( struct pipe_context * );
/*
- * Queries
- */
- /** type is one of PIPE_SURFACE, PIPE_TEXTURE, etc. */
- boolean (*is_format_supported)( struct pipe_context *pipe,
- enum pipe_format format, uint type );
-
- const char *(*get_name)( struct pipe_context *pipe );
-
- const char *(*get_vendor)( struct pipe_context *pipe );
-
- int (*get_param)( struct pipe_context *pipe, int param );
- float (*get_paramf)( struct pipe_context *pipe, int param );
-
-
- /*
* Drawing.
* Return false on fallbacks (temporary??)
*/
@@ -196,21 +190,16 @@ struct pipe_context {
struct pipe_surface *ps,
unsigned clearValue);
-
- /*
- * Texture functions
+ /**
+ * Called when texture data is changed.
+ * Note: we could pass some hints about which mip levels or cube faces
+ * have changed...
+ * XXX this may go away - could pass a 'write' flag to get_tex_surface()
*/
- struct pipe_texture * (*texture_create)(struct pipe_context *pipe,
- const struct pipe_texture *templat);
+ void (*texture_update)(struct pipe_context *pipe,
+ struct pipe_texture *texture);
- void (*texture_release)(struct pipe_context *pipe,
- struct pipe_texture **pt);
- /** Get a surface which is a "view" into a texture */
- struct pipe_surface *(*get_tex_surface)(struct pipe_context *pipe,
- struct pipe_texture *texture,
- unsigned face, unsigned level,
- unsigned zslice);
/* Flush rendering:
*/
@@ -218,4 +207,9 @@ struct pipe_context {
unsigned flags );
};
+
+#ifdef __cplusplus
+}
+#endif
+
#endif /* PIPE_CONTEXT_H */
diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h
index 0bf53ecb79..0c662d6517 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -30,6 +30,10 @@
#include "p_format.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#define PIPE_BLENDFACTOR_ONE 0x1
#define PIPE_BLENDFACTOR_SRC_COLOR 0x2
#define PIPE_BLENDFACTOR_SRC_ALPHA 0x3
@@ -148,7 +152,7 @@ enum pipe_texture_target {
*/
#define PIPE_TEX_FILTER_NEAREST 0
#define PIPE_TEX_FILTER_LINEAR 1
-//#define PIPE_TEX_FILTER_ANISO 2
+/* #define PIPE_TEX_FILTER_ANISO 2 */
#define PIPE_TEX_COMPARE_NONE 0
@@ -267,4 +271,8 @@ enum pipe_texture_target {
#define PIPE_CAP_MAX_TEXTURE_LOD_BIAS 19
#define PIPE_CAP_BITMAP_TEXCOORD_BIAS 20
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/src/gallium/include/pipe/p_format.h b/src/gallium/include/pipe/p_format.h
index c9ad324315..f90087b3c9 100644
--- a/src/gallium/include/pipe/p_format.h
+++ b/src/gallium/include/pipe/p_format.h
@@ -28,11 +28,15 @@
#ifndef PIPE_FORMAT_H
#define PIPE_FORMAT_H
-#include <stdio.h> // for sprintf
+#include <stdio.h> /* for sprintf */
#include "p_compiler.h"
#include "p_debug.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/**
* The PIPE_FORMAT is a 32-bit wide bitfield that encodes all the information
* needed to uniquely describe a pixel format.
@@ -418,4 +422,8 @@ static INLINE uint pf_get_size( enum pipe_format format ) {
return pf_get_bits(format) / 8;
}
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/src/gallium/include/pipe/p_inlines.h b/src/gallium/include/pipe/p_inlines.h
index ebf6ed86bc..274f76a383 100644
--- a/src/gallium/include/pipe/p_inlines.h
+++ b/src/gallium/include/pipe/p_inlines.h
@@ -30,9 +30,15 @@
#include "p_context.h"
#include "p_defines.h"
+#include "p_screen.h"
#include "p_winsys.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
static INLINE void *
pipe_surface_map(struct pipe_surface *surface)
{
@@ -92,7 +98,7 @@ pipe_buffer_reference(struct pipe_winsys *winsys,
* \sa pipe_surface_reference
*/
static INLINE void
-pipe_texture_reference(struct pipe_context *pipe, struct pipe_texture **ptr,
+pipe_texture_reference(struct pipe_texture **ptr,
struct pipe_texture *pt)
{
assert(ptr);
@@ -101,7 +107,10 @@ pipe_texture_reference(struct pipe_context *pipe, struct pipe_texture **ptr,
pt->refcount++;
if (*ptr) {
- pipe->texture_release(pipe, ptr);
+ struct pipe_screen *screen = (*ptr)->screen;
+ assert(screen);
+ screen->texture_release(screen, ptr);
+
assert(!*ptr);
}
@@ -109,4 +118,19 @@ pipe_texture_reference(struct pipe_context *pipe, struct pipe_texture **ptr,
}
+static INLINE void
+pipe_texture_release(struct pipe_texture **ptr)
+{
+ struct pipe_screen *screen;
+ assert(ptr);
+ screen = (*ptr)->screen;
+ screen->texture_release(screen, ptr);
+ *ptr = NULL;
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+
#endif /* P_INLINES_H */
diff --git a/src/gallium/include/pipe/p_pointer.h b/src/gallium/include/pipe/p_pointer.h
new file mode 100644
index 0000000000..3a1e6be88e
--- /dev/null
+++ b/src/gallium/include/pipe/p_pointer.h
@@ -0,0 +1,95 @@
+/**************************************************************************
+ *
+ * Copyright 2007-2008 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.
+ *
+ **************************************************************************/
+
+#ifndef P_POINTER_H
+#define P_POINTER_H
+
+#include "p_compiler.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static INLINE intptr_t
+pointer_to_intptr( const void *p )
+{
+ union {
+ const void *p;
+ intptr_t i;
+ } pi;
+ pi.p = p;
+ return pi.i;
+}
+
+static INLINE void *
+intptr_to_pointer( intptr_t i )
+{
+ union {
+ void *p;
+ intptr_t i;
+ } pi;
+ pi.i = i;
+ return pi.p;
+}
+
+static INLINE uintptr_t
+pointer_to_uintptr( const void *ptr )
+{
+ union {
+ const void *p;
+ uintptr_t u;
+ } pu;
+ pu.p = ptr;
+ return pu.u;
+}
+
+static INLINE void *
+uintptr_to_pointer( uintptr_t u )
+{
+ union {
+ void *p;
+ uintptr_t u;
+ } pu;
+ pu.u = u;
+ return pu.p;
+}
+
+/**
+ * Return a pointer aligned to next multiple of N bytes.
+ */
+static INLINE void *
+align_pointer( const void *unaligned, uintptr_t alignment )
+{
+ uintptr_t aligned = (pointer_to_uintptr( unaligned ) + alignment - 1) & ~(alignment - 1);
+ return uintptr_to_pointer( aligned );
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* P_POINTER_H */
diff --git a/src/gallium/include/pipe/p_screen.h b/src/gallium/include/pipe/p_screen.h
new file mode 100644
index 0000000000..6be9a82b68
--- /dev/null
+++ b/src/gallium/include/pipe/p_screen.h
@@ -0,0 +1,98 @@
+/**************************************************************************
+ *
+ * Copyright 2007 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.
+ *
+ **************************************************************************/
+
+/**
+ * Screen, Adapter or GPU
+ *
+ * These are driver functions/facilities that are context independent.
+ */
+
+
+#ifndef P_SCREEN_H
+#define P_SCREEN_H
+
+
+#include "pipe/p_compiler.h"
+#include "pipe/p_state.h"
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+/**
+ * Gallium screen/adapter context. Basically everything
+ * hardware-specific that doesn't actually require a rendering
+ * context.
+ */
+struct pipe_screen {
+ struct pipe_winsys *winsys;
+
+ void (*destroy)( struct pipe_screen * );
+
+
+ /*
+ * Capability queries
+ */
+ const char *(*get_name)( struct pipe_screen * );
+
+ const char *(*get_vendor)( struct pipe_screen * );
+
+ int (*get_param)( struct pipe_screen *, int param );
+
+ float (*get_paramf)( struct pipe_screen *, int param );
+
+ boolean (*is_format_supported)( struct pipe_screen *,
+ enum pipe_format format,
+ uint type );
+
+
+ /*
+ * Texture functions
+ */
+ struct pipe_texture * (*texture_create)(struct pipe_screen *,
+ const struct pipe_texture *templat);
+
+ void (*texture_release)(struct pipe_screen *,
+ struct pipe_texture **pt);
+
+ /** Get a surface which is a "view" into a texture */
+ struct pipe_surface *(*get_tex_surface)(struct pipe_screen *,
+ struct pipe_texture *texture,
+ unsigned face, unsigned level,
+ unsigned zslice);
+};
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* P_SCREEN_H */
diff --git a/src/gallium/include/pipe/p_shader_tokens.h b/src/gallium/include/pipe/p_shader_tokens.h
index 3ce35310f6..0a6145a6bf 100644
--- a/src/gallium/include/pipe/p_shader_tokens.h
+++ b/src/gallium/include/pipe/p_shader_tokens.h
@@ -1,9 +1,11 @@
#if !defined TGSI_TOKEN_H
#define TGSI_TOKEN_H
-#if defined __cplusplus
+#ifdef __cplusplus
extern "C" {
-#endif // defined __cplusplus
+#endif
+
+#include "p_compiler.h"
struct tgsi_version
{
@@ -48,6 +50,8 @@ struct tgsi_token
#define TGSI_FILE_SAMPLER 5
#define TGSI_FILE_ADDRESS 6
#define TGSI_FILE_IMMEDIATE 7
+#define TGSI_FILE_COUNT 8 /**< how many TGSI_FILE_ types */
+
#define TGSI_DECLARE_RANGE 0
#define TGSI_DECLARE_MASK 1
@@ -798,9 +802,9 @@ struct tgsi_dst_register_ext_predicate
};
-#if defined __cplusplus
-} // extern "C"
-#endif // defined __cplusplus
+#ifdef __cplusplus
+}
+#endif
-#endif // !defined TGSI_TOKEN_H
+#endif /* TGSI_TOKEN_H */
diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h
index 1082343e2f..5fab41acbd 100644
--- a/src/gallium/include/pipe/p_state.h
+++ b/src/gallium/include/pipe/p_state.h
@@ -42,6 +42,12 @@
#include "p_defines.h"
#include "p_format.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
/**
* Implementation limits
*/
@@ -57,6 +63,7 @@
/* fwd decls */
+struct pipe_screen;
struct pipe_surface;
struct pipe_winsys;
@@ -66,7 +73,8 @@ struct pipe_winsys;
* The driver will certainly subclass this to include actual memory
* management information.
*/
-struct pipe_buffer {
+struct pipe_buffer
+{
unsigned alignment;
unsigned usage;
unsigned size;
@@ -76,8 +84,6 @@ struct pipe_buffer {
};
-
-
/**
* Primitive (point/line/tri) rasterization info
*/
@@ -113,18 +119,21 @@ struct pipe_rasterizer_state
};
-struct pipe_poly_stipple {
+struct pipe_poly_stipple
+{
unsigned stipple[32];
};
-struct pipe_viewport_state {
+struct pipe_viewport_state
+{
float scale[4];
float translate[4];
};
-struct pipe_scissor_state {
+struct pipe_scissor_state
+{
unsigned minx:16;
unsigned miny:16;
unsigned maxx:16;
@@ -132,7 +141,8 @@ struct pipe_scissor_state {
};
-struct pipe_clip_state {
+struct pipe_clip_state
+{
float ucp[PIPE_MAX_CLIP_PLANES][4];
unsigned nr;
};
@@ -141,17 +151,19 @@ struct pipe_clip_state {
/**
* Constants for vertex/fragment shaders
*/
-struct pipe_constant_buffer {
+struct pipe_constant_buffer
+{
struct pipe_buffer *buffer;
unsigned size; /** in bytes */
};
-struct pipe_shader_state {
+struct pipe_shader_state
+{
const struct tgsi_token *tokens;
+ /* XXX these are going away */
ubyte num_inputs;
ubyte num_outputs;
- ubyte input_map[PIPE_MAX_SHADER_INPUTS]; /* XXX this may be temporary */
ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS]; /**< TGSI_SEMANTIC_x */
ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS];
ubyte output_semantic_name[PIPE_MAX_SHADER_OUTPUTS]; /**< TGSI_SEMANTIC_x */
@@ -185,7 +197,8 @@ struct pipe_depth_stencil_alpha_state
};
-struct pipe_blend_state {
+struct pipe_blend_state
+{
unsigned blend_enable:1;
unsigned rgb_func:3; /**< PIPE_BLEND_x */
@@ -204,7 +217,8 @@ struct pipe_blend_state {
};
-struct pipe_blend_color {
+struct pipe_blend_color
+{
float color[4];
};
@@ -224,19 +238,19 @@ struct pipe_framebuffer_state
*/
struct pipe_sampler_state
{
- unsigned wrap_s:3; /**< PIPE_TEX_WRAP_x */
- unsigned wrap_t:3; /**< PIPE_TEX_WRAP_x */
- unsigned wrap_r:3; /**< PIPE_TEX_WRAP_x */
+ unsigned wrap_s:3; /**< PIPE_TEX_WRAP_x */
+ unsigned wrap_t:3; /**< PIPE_TEX_WRAP_x */
+ unsigned wrap_r:3; /**< PIPE_TEX_WRAP_x */
unsigned min_img_filter:2; /**< PIPE_TEX_FILTER_x */
unsigned min_mip_filter:2; /**< PIPE_TEX_MIPFILTER_x */
unsigned mag_img_filter:2; /**< PIPE_TEX_FILTER_x */
- unsigned compare:1; /**< shadow/depth compare enabled? */
- unsigned compare_mode:1; /**< PIPE_TEX_COMPARE_x */
- unsigned compare_func:3; /**< PIPE_FUNC_x */
- unsigned normalized_coords:1; /**< Are coords normalized to [0,1]? */
- float shadow_ambient; /**< shadow test fail color/intensity */
- float lod_bias; /**< LOD/lambda bias */
- float min_lod, max_lod; /**< LOD clamp range, after bias */
+ unsigned compare:1; /**< shadow/depth compare enabled? */
+ unsigned compare_mode:1; /**< PIPE_TEX_COMPARE_x */
+ unsigned compare_func:3; /**< PIPE_FUNC_x */
+ unsigned normalized_coords:1; /**< Are coords normalized to [0,1]? */
+ float shadow_ambient; /**< shadow test fail color/intensity */
+ float lod_bias; /**< LOD/lambda bias */
+ float min_lod, max_lod; /**< LOD clamp range, after bias */
float border_color[4];
float max_anisotropy;
};
@@ -248,10 +262,10 @@ struct pipe_sampler_state
*/
struct pipe_surface
{
- struct pipe_buffer *buffer; /**< driver private buffer handle */
+ struct pipe_buffer *buffer; /**< surface's buffer/memory */
enum pipe_format format; /**< PIPE_FORMAT_x */
unsigned status; /**< PIPE_SURFACE_STATUS_x */
- unsigned clear_value; /**< may be temporary */
+ unsigned clear_value; /**< XXX may be temporary */
unsigned cpp; /**< bytes per pixel */
unsigned width;
unsigned height;
@@ -263,8 +277,7 @@ struct pipe_surface
/**
- * Texture. Represents one or several texture images on one or several mipmap
- * levels.
+ * Texture object.
*/
struct pipe_texture
{
@@ -284,6 +297,8 @@ struct pipe_texture
/* These are also refcounted:
*/
unsigned refcount;
+
+ struct pipe_screen *screen; /**< screen that this texture belongs to */
};
@@ -319,4 +334,8 @@ struct pipe_vertex_element
};
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/src/gallium/include/pipe/p_thread.h b/src/gallium/include/pipe/p_thread.h
index cd432c547c..4325abc951 100644
--- a/src/gallium/include/pipe/p_thread.h
+++ b/src/gallium/include/pipe/p_thread.h
@@ -1,54 +1,317 @@
/**************************************************************************
*
+ * Copyright 1999-2006 Brian Paul
* Copyright 2008 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.
- *
+ * 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 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.
+ * 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.
*
**************************************************************************/
-#ifndef P_THREAD_H
-#define P_THREAD_H
+/**
+ * @file
+ * Thread
+ *
+ * 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 _P_THREAD_H_
+#define _P_THREAD_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))
+
+#endif /* PTHREADS */
+
+
+
+
+/*
+ * 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 */
+
+
-#include "p_compiler.h"
/*
- * XXX: We should come up with a system-independent thread definitions.
- * XXX: Patching glthread defs for now.
+ * 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 unsigned _glthread_TSD;
+
+typedef unsigned _glthread_Thread;
+
+typedef unsigned _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 *);
-#ifndef __MSC__
-#include "glapi/glthread.h"
+extern void
+_glthread_SetTSD(_glthread_TSD *, void *);
-#else /* __MSC__ */
+#if defined(GLX_USE_TLS)
-typedef int _glthread_Mutex;
+extern __thread struct _glapi_table * _glapi_tls_Dispatch
+ __attribute__((tls_model("initial-exec")));
-#define _glthread_INIT_MUTEX( M ) ((void) (M))
-#define _glthread_LOCK_MUTEX( M ) ((void) (M))
-#define _glthread_UNLOCK_MUTEX( M ) ((void) (M))
+#define GET_DISPATCH() _glapi_tls_Dispatch
-#define sched_yield() ((void) 0)
+#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 /* __MSC__ */
-#endif /* P_THREAD_H */
+#endif /* _P_THREAD_H_ */
diff --git a/src/gallium/include/pipe/p_util.h b/src/gallium/include/pipe/p_util.h
index d7da2801c9..3b32ba1d24 100644
--- a/src/gallium/include/pipe/p_util.h
+++ b/src/gallium/include/pipe/p_util.h
@@ -30,16 +30,17 @@
#include "p_compiler.h"
#include "p_debug.h"
+#include "p_pointer.h"
#include <math.h>
-#ifdef WIN32
-
#ifdef __cplusplus
-extern "C"
-{
+extern "C" {
#endif
+
+#ifdef WIN32
+
void * __stdcall
EngAllocMem(
unsigned long Flags,
@@ -50,10 +51,6 @@ void __stdcall
EngFreeMem(
void *Mem );
-#ifdef __cplusplus
-}
-#endif
-
static INLINE void *
MALLOC( unsigned size )
{
@@ -115,33 +112,6 @@ REALLOC( void *old_ptr, unsigned old_size, unsigned new_size )
/**
- * Return a pointer aligned to next multiple of N bytes.
- */
-static INLINE void *
-align_pointer( void *unaligned, uint alignment )
-{
- if (sizeof(void *) == 64) {
- union {
- void *p;
- uint64 u;
- } pu;
- pu.p = unaligned;
- pu.u = (pu.u + alignment - 1) & ~(uint64) (alignment - 1);
- return pu.p;
- }
- else {
- /* 32-bit pointers */
- union {
- void *p;
- uint u;
- } pu;
- pu.p = unaligned;
- pu.u = (pu.u + alignment - 1) & ~(alignment - 1);
- return pu.p;
- }
-}
-
-/**
* Return memory on given byte alignment
*/
static INLINE void *
@@ -405,4 +375,8 @@ extern void pipe_copy_rect(ubyte * dst, unsigned cpp, unsigned dst_pitch,
int src_pitch, unsigned src_x, int src_y);
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/src/gallium/include/pipe/p_winsys.h b/src/gallium/include/pipe/p_winsys.h
index 1e81eebd78..e784c92491 100644
--- a/src/gallium/include/pipe/p_winsys.h
+++ b/src/gallium/include/pipe/p_winsys.h
@@ -25,12 +25,6 @@
*
**************************************************************************/
-#ifndef P_WINSYS_H
-#define P_WINSYS_H
-
-
-#include "p_format.h"
-
/**
* \file
* This is the interface that Gallium3D requires any window system
@@ -38,6 +32,17 @@
* which is public.
*/
+#ifndef P_WINSYS_H
+#define P_WINSYS_H
+
+
+#include "p_format.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/** Opaque type */
struct pipe_fence_handle;
@@ -156,5 +161,8 @@ struct pipe_winsys
};
+#ifdef __cplusplus
+}
+#endif
#endif /* P_WINSYS_H */