diff options
Diffstat (limited to 'src/gallium/include')
| -rw-r--r-- | src/gallium/include/pipe/p_compiler.h | 157 | ||||
| -rw-r--r-- | src/gallium/include/pipe/p_config.h | 148 | ||||
| -rw-r--r-- | src/gallium/include/pipe/p_context.h | 226 | ||||
| -rw-r--r-- | src/gallium/include/pipe/p_debug.h | 356 | ||||
| -rw-r--r-- | src/gallium/include/pipe/p_defines.h | 294 | ||||
| -rw-r--r-- | src/gallium/include/pipe/p_error.h | 65 | ||||
| -rw-r--r-- | src/gallium/include/pipe/p_format.h | 567 | ||||
| -rw-r--r-- | src/gallium/include/pipe/p_inlines.h | 216 | ||||
| -rw-r--r-- | src/gallium/include/pipe/p_screen.h | 139 | ||||
| -rw-r--r-- | src/gallium/include/pipe/p_shader_tokens.h | 809 | ||||
| -rw-r--r-- | src/gallium/include/pipe/p_state.h | 368 | ||||
| -rw-r--r-- | src/gallium/include/pipe/p_thread.h | 276 | ||||
| -rw-r--r-- | src/gallium/include/pipe/p_winsys.h | 186 | 
13 files changed, 3807 insertions, 0 deletions
diff --git a/src/gallium/include/pipe/p_compiler.h b/src/gallium/include/pipe/p_compiler.h new file mode 100644 index 0000000000..7bcebd3d6b --- /dev/null +++ b/src/gallium/include/pipe/p_compiler.h @@ -0,0 +1,157 @@ +/************************************************************************** + *  + * 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_COMPILER_H +#define P_COMPILER_H + + +#include "p_config.h" + +#ifndef XFree86Server +#include <stdlib.h> +#include <string.h> +#else +#include "xf86_ansic.h" +#include "xf86_libc.h" +#endif + + +#if defined(_WIN32) && !defined(__WIN32__) +#define __WIN32__ +#endif + +#if defined(_MSC_VER) + +/* Avoid 'expression is always true' warning */ +#pragma warning(disable: 4296) + +#endif /* _MSC_VER */ + + +#if defined(_MSC_VER) + +typedef __int8             int8_t; +typedef unsigned __int8    uint8_t; +typedef __int16            int16_t; +typedef unsigned __int16   uint16_t; +#ifndef __eglplatform_h_ +typedef __int32            int32_t; +#endif +typedef unsigned __int32   uint32_t; +typedef __int64            int64_t; +typedef unsigned __int64   uint64_t; + +#if defined(_WIN64) +typedef __int64            intptr_t; +typedef unsigned __int64   uintptr_t; +#else +typedef __int32            intptr_t; +typedef unsigned __int32   uintptr_t; +#endif + +#define INT64_C(__val) __val##i64 +#define UINT64_C(__val) __val##ui64 + +#ifndef __cplusplus +#define false   0 +#define true    1 +#define bool    _Bool +typedef int     _Bool; +#define __bool_true_false_are_defined   1 +#endif /* !__cplusplus */ + +#else +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif +#include <stdint.h> +#include <stdbool.h> +#endif + + +typedef unsigned int       uint; +typedef unsigned char      ubyte; +typedef unsigned short     ushort; +typedef uint64_t           uint64; + +#if 0 +#define boolean bool +#else +typedef unsigned char boolean; +#endif +#ifndef TRUE +#define TRUE  true +#endif +#ifndef FALSE +#define FALSE false +#endif + + +/* Function inlining */ +#ifdef __cplusplus +#  define INLINE inline +#elif defined(__GNUC__) +#  define INLINE __inline__ +#elif defined(_MSC_VER) +#  define INLINE __inline +#elif defined(__ICL) +#  define INLINE __inline +#elif defined(__INTEL_COMPILER) +#  define INLINE inline +#elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100) +#  define INLINE __inline +#else +#  define INLINE +#endif + + +/* This should match linux gcc cdecl semantics everywhere, so that we + * just codegen one calling convention on all platforms. + */ +#ifdef _MSC_VER +#define PIPE_CDECL __cdecl +#else +#define PIPE_CDECL +#endif + + + +#if defined(__GNUC__) +#define ALIGN16_DECL(TYPE, NAME, SIZE)  TYPE NAME##___aligned[SIZE] __attribute__(( aligned( 16 ) )) +#define ALIGN16_ASSIGN(NAME) NAME##___aligned +#define ALIGN16_ATTRIB  __attribute__(( aligned( 16 ) )) +#define ALIGN8_ATTRIB  __attribute__(( aligned( 8 ) )) +#else +#define ALIGN16_DECL(TYPE, NAME, SIZE)  TYPE NAME##___unaligned[SIZE + 1] +#define ALIGN16_ASSIGN(NAME) align16(NAME##___unaligned) +#define ALIGN16_ATTRIB +#define ALIGN8_ATTRIB +#endif + + + +#endif /* P_COMPILER_H */ diff --git a/src/gallium/include/pipe/p_config.h b/src/gallium/include/pipe/p_config.h new file mode 100644 index 0000000000..05cbd2fc4d --- /dev/null +++ b/src/gallium/include/pipe/p_config.h @@ -0,0 +1,148 @@ +/************************************************************************** + *  + * 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. + *  + * 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. + *  + **************************************************************************/ + +/** + * @file + * Gallium configuration defines. + *  + * This header file sets several defines based on the compiler, processor  + * architecture, and operating system being used. These defines should be used  + * throughout the code to facilitate porting to new platforms. It is likely that  + * this file is auto-generated by an autoconf-like tool at some point, as some  + * things cannot be determined by pre-defined environment alone.  + *  + * See also: + * - http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html + * - echo | gcc -dM -E - | sort + * - http://msdn.microsoft.com/en-us/library/b0084kay.aspx + *  + * @author José Fonseca <jrfonseca@tungstengraphics.com> + */ + +#ifndef P_CONFIG_H_ +#define P_CONFIG_H_ + + +/* + * Compiler + */ + +#if defined(__GNUC__) +#define PIPE_CC_GCC +#endif + +/* + * Meaning of _MSC_VER value: + * - 1400: Visual C++ 2005 + * - 1310: Visual C++ .NET 2003 + * - 1300: Visual C++ .NET 2002 + *  + * __MSC__ seems to be an old macro -- it is not pre-defined on recent MSVC  + * versions. + */ +#if defined(_MSC_VER) || defined(__MSC__) +#define PIPE_CC_MSVC +#endif + +#if defined(__ICL) +#define PIPE_CC_ICL +#endif + + +/* + * Processor architecture + */ + +#if defined(__i386__) /* gcc */ || defined(_M_IX86) /* msvc */ || defined(_X86_) || defined(__386__) || defined(i386) +#define PIPE_ARCH_X86 +#endif + +#if defined(__x86_64__) /* gcc */ || defined(_M_X64) /* msvc */ || defined(_M_AMD64) /* msvc */ +#define PIPE_ARCH_X86_64 +#endif + +#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) +#if defined(PIPE_CC_GCC) && !defined(__SSE2__) +/* #warning SSE2 support requires -msse -msse2 compiler options */ +#else +#define PIPE_ARCH_SSE +#endif +#endif + +#if defined(__PPC__) +#define PIPE_ARCH_PPC +#if defined(__PPC64__) +#define PIPE_ARCH_PPC_64 +#endif +#endif + + +/* + * Operating system family. + *  + * See subsystem below for a more fine-grained distinction. + */ + +#if defined(__linux__) +#define PIPE_OS_LINUX +#endif + +#if defined(_WIN32) || defined(WIN32) +#define PIPE_OS_WINDOWS +#endif + + +/* + * Subsystem. + *  + * NOTE: There is no way to auto-detect most of these. + */ + +#if defined(PIPE_OS_LINUX) +#define PIPE_SUBSYSTEM_DRI +#endif /* PIPE_OS_LINUX */ + +#if defined(PIPE_OS_WINDOWS) +#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) +/* Windows 2000/XP Display Driver */  +#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT) +/* Windows 2000/XP Miniport Driver */  +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) +/* Windows User-space Library */ +#elif defined(PIPE_SUBSYSTEM_WINDOWS_CE) +/* Windows CE 5.0/6.0 */ +#else +#ifdef _WIN32_WCE +#define PIPE_SUBSYSTEM_WINDOWS_CE +#else /* !_WIN32_WCE */ +#error No PIPE_SUBSYSTEM_WINDOWS_xxx subsystem defined.  +#endif /* !_WIN32_WCE */ +#endif +#endif /* PIPE_OS_WINDOWS */ + + +#endif /* P_CONFIG_H_ */ diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h new file mode 100644 index 0000000000..2646706ff2 --- /dev/null +++ b/src/gallium/include/pipe/p_context.h @@ -0,0 +1,226 @@ +/************************************************************************** + *  + * 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. + *  + **************************************************************************/ + +#ifndef PIPE_CONTEXT_H +#define PIPE_CONTEXT_H + +#include "p_state.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +    +struct pipe_screen; +struct pipe_fence_handle; +struct pipe_state_cache; +struct pipe_query; + + +/** + * Gallium rendering context.  Basically: + *  - state setting functions + *  - VBO drawing functions + *  - surface functions + */ +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 * ); + +    +   /* Possible interface for setting edgeflags.  These aren't really +    * vertex elements, so don't fit there. +    */ +   void (*set_edgeflags)( struct pipe_context *, +                          const unsigned *bitfield ); + + +   /** +    * VBO drawing (return false on fallbacks (temporary??)) +    */ +   /*@{*/ +   boolean (*draw_arrays)( struct pipe_context *pipe, +			   unsigned mode, unsigned start, unsigned count); + +   boolean (*draw_elements)( struct pipe_context *pipe, +			     struct pipe_buffer *indexBuffer, +			     unsigned indexSize, +			     unsigned mode, unsigned start, unsigned count); + +   /* XXX: this is (probably) a temporary entrypoint, as the range +    * information should be available from the vertex_buffer state. +    * Using this to quickly evaluate a specialized path in the draw +    * module. +    */ +   boolean (*draw_range_elements)( struct pipe_context *pipe, +                                   struct pipe_buffer *indexBuffer, +                                   unsigned indexSize, +                                   unsigned minIndex, +                                   unsigned maxIndex, +                                   unsigned mode,  +                                   unsigned start,  +                                   unsigned count); +   /*@}*/ + + +   /** +    * Query objects +    */ +   /*@{*/ +   struct pipe_query *(*create_query)( struct pipe_context *pipe, +                                              unsigned query_type ); + +   void (*destroy_query)(struct pipe_context *pipe, +                         struct pipe_query *q); + +   void (*begin_query)(struct pipe_context *pipe, struct pipe_query *q); +   void (*end_query)(struct pipe_context *pipe, struct pipe_query *q); + +   boolean (*get_query_result)(struct pipe_context *pipe,  +                               struct pipe_query *q, +                               boolean wait, +                               uint64 *result); +   /*@}*/ + +   /** +    * State functions (create/bind/destroy state objects) +    */ +   /*@{*/ +   void * (*create_blend_state)(struct pipe_context *, +                                const struct pipe_blend_state *); +   void   (*bind_blend_state)(struct pipe_context *, void *); +   void   (*delete_blend_state)(struct pipe_context *, void  *); + +   void * (*create_sampler_state)(struct pipe_context *, +                                  const struct pipe_sampler_state *); +   void   (*bind_sampler_states)(struct pipe_context *, unsigned num, void **); +   void   (*delete_sampler_state)(struct pipe_context *, void *); + +   void * (*create_rasterizer_state)(struct pipe_context *, +                                     const struct pipe_rasterizer_state *); +   void   (*bind_rasterizer_state)(struct pipe_context *, void *); +   void   (*delete_rasterizer_state)(struct pipe_context *, void *); + +   void * (*create_depth_stencil_alpha_state)(struct pipe_context *, +                                        const struct pipe_depth_stencil_alpha_state *); +   void   (*bind_depth_stencil_alpha_state)(struct pipe_context *, void *); +   void   (*delete_depth_stencil_alpha_state)(struct pipe_context *, void *); + +   void * (*create_fs_state)(struct pipe_context *, +                             const struct pipe_shader_state *); +   void   (*bind_fs_state)(struct pipe_context *, void *); +   void   (*delete_fs_state)(struct pipe_context *, void *); + +   void * (*create_vs_state)(struct pipe_context *, +                             const struct pipe_shader_state *); +   void   (*bind_vs_state)(struct pipe_context *, void *); +   void   (*delete_vs_state)(struct pipe_context *, void *); +   /*@}*/ + +   /** +    * Parameter-like state (or properties) +    */ +   /*@{*/ +   void (*set_blend_color)( struct pipe_context *, +                            const struct pipe_blend_color * ); + +   void (*set_clip_state)( struct pipe_context *, +			   const struct pipe_clip_state * ); + +   void (*set_constant_buffer)( struct pipe_context *, +                                uint shader, uint index, +                                const struct pipe_constant_buffer *buf ); + +   void (*set_framebuffer_state)( struct pipe_context *, +                                  const struct pipe_framebuffer_state * ); + +   void (*set_polygon_stipple)( struct pipe_context *, +				const struct pipe_poly_stipple * ); + +   void (*set_scissor_state)( struct pipe_context *, +                              const struct pipe_scissor_state * ); + +   void (*set_viewport_state)( struct pipe_context *, +                               const struct pipe_viewport_state * ); + +   void (*set_sampler_textures)( struct pipe_context *, +                                 unsigned num_textures, +                                 struct pipe_texture ** ); + +   void (*set_vertex_buffers)( struct pipe_context *, +                               unsigned num_buffers, +                               const struct pipe_vertex_buffer * ); + +   void (*set_vertex_elements)( struct pipe_context *, +                                unsigned num_elements, +                                const struct pipe_vertex_element * ); +   /*@}*/ + + +   /** +    * Surface functions +    */ +   /*@{*/ +   void (*surface_copy)(struct pipe_context *pipe, +                        boolean do_flip,/**< flip surface contents vertically */ +			struct pipe_surface *dest, +			unsigned destx, unsigned desty, +			struct pipe_surface *src, /* don't make this const -  +						     need to map/unmap */ +			unsigned srcx, unsigned srcy, +			unsigned width, unsigned height); + +   void (*surface_fill)(struct pipe_context *pipe, +			struct pipe_surface *dst, +			unsigned dstx, unsigned dsty, +			unsigned width, unsigned height, +			unsigned value); + +   void (*clear)(struct pipe_context *pipe,  +		 struct pipe_surface *ps, +		 unsigned clearValue); +   /*@}*/ + + +   /** Flush rendering (flags = bitmask of PIPE_FLUSH_x tokens) */ +   void (*flush)( struct pipe_context *pipe, +                  unsigned flags, +                  struct pipe_fence_handle **fence ); +}; + + +#ifdef __cplusplus +} +#endif + +#endif /* PIPE_CONTEXT_H */ diff --git a/src/gallium/include/pipe/p_debug.h b/src/gallium/include/pipe/p_debug.h new file mode 100644 index 0000000000..cb6196aa9f --- /dev/null +++ b/src/gallium/include/pipe/p_debug.h @@ -0,0 +1,356 @@ +/************************************************************************** + *  + * 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. + *  + * 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. + *  + **************************************************************************/ + +/** + * @file + * Cross-platform debugging helpers. + *  + * For now it just has assert and printf replacements, but it might be extended  + * with stack trace reports and more advanced logging in the near future.  + *  + * @author Jose Fonseca <jrfonseca@tungstengraphics.com> + */ + +#ifndef P_DEBUG_H_ +#define P_DEBUG_H_ + + +#include <stdarg.h> + +#include "p_compiler.h" + + +#ifdef	__cplusplus +extern "C" { +#endif + + +#ifdef DBG +#ifndef DEBUG +#define DEBUG 1 +#endif +#else +#ifndef NDEBUG +#define NDEBUG 1 +#endif +#endif + +    +/* MSVC bebore VC7 does not have the __FUNCTION__ macro */ +#if defined(_MSC_VER) && _MSC_VER < 1300 +#define __FUNCTION__ "???" +#endif + + +void _debug_vprintf(const char *format, va_list ap); +    + +static INLINE void +_debug_printf(const char *format, ...) +{ +   va_list ap; +   va_start(ap, format); +   _debug_vprintf(format, ap); +   va_end(ap); +} + + +/** + * Print debug messages. + * + * The actual channel used to output debug message is platform specific. To  + * avoid misformating or truncation, follow these rules of thumb:    + * - output whole lines + * - avoid outputing large strings (512 bytes is the current maximum length  + * that is guaranteed to be printed in all platforms) + */ +static INLINE void +debug_printf(const char *format, ...) +{ +#ifdef DEBUG +   va_list ap; +   va_start(ap, format); +   _debug_vprintf(format, ap); +   va_end(ap); +#else +   (void) format; /* silence warning */ +#endif +} + + +#ifdef DEBUG +#define debug_vprintf(_format, _ap) _debug_vprintf(_format, _ap) +#else +#define debug_vprintf(_format, _ap) ((void)0) +#endif + + +#ifdef DEBUG +/** + * Dump a blob in hex to the same place that debug_printf sends its + * messages. + */ +void debug_print_blob( const char *name, const void *blob, unsigned size ); + +/* Print a message along with a prettified format string + */ +void debug_print_format(const char *msg, unsigned fmt ); +#else +#define debug_print_blob(_name, _blob, _size) ((void)0) +#define debug_print_format(_msg, _fmt) ((void)0) +#endif + + +void _debug_break(void); + + +/** + * Hard-coded breakpoint. + */ +#ifdef DEBUG +#if defined(PIPE_ARCH_X86) && defined(PIPE_CC_GCC) +#define debug_break() __asm("int3") +#elif defined(PIPE_ARCH_X86) && defined(PIPE_CC_MSVC) +#define debug_break()  do { _asm {int 3} } while(0) +#else +#define debug_break() _debug_break() +#endif +#else /* !DEBUG */ +#define debug_break() ((void)0) +#endif /* !DEBUG */ + + +long +debug_get_num_option(const char *name, long dfault); + +void _debug_assert_fail(const char *expr,  +                        const char *file,  +                        unsigned line,  +                        const char *function); + + +/**  + * Assert macro + *  + * Do not expect that the assert call terminates -- errors must be handled  + * regardless of assert behavior. + */ +#ifdef DEBUG +#define debug_assert(expr) ((expr) ? (void)0 : _debug_assert_fail(#expr, __FILE__, __LINE__, __FUNCTION__)) +#else +#define debug_assert(expr) ((void)0) +#endif + + +/** Override standard assert macro */ +#ifdef assert +#undef assert +#endif +#define assert(expr) debug_assert(expr) + + +/** + * Output the current function name. + */ +#ifdef DEBUG +#define debug_checkpoint() \ +   _debug_printf("%s\n", __FUNCTION__) +#else +#define debug_checkpoint() \ +   ((void)0)  +#endif + + +/** + * Output the full source code position. + */ +#ifdef DEBUG +#define debug_checkpoint_full() \ +   _debug_printf("%s:%u:%s", __FILE__, __LINE__, __FUNCTION__)  +#else +#define debug_checkpoint_full() \ +   ((void)0)  +#endif + + +/** + * Output a warning message. Muted on release version. + */ +#ifdef DEBUG +#define debug_warning(__msg) \ +   _debug_printf("%s:%u:%s: warning: %s\n", __FILE__, __LINE__, __FUNCTION__, __msg) +#else +#define debug_warning(__msg) \ +   ((void)0)  +#endif + + +/** + * Output an error message. Not muted on release version. + */ +#ifdef DEBUG +#define debug_error(__msg) \ +   _debug_printf("%s:%u:%s: error: %s\n", __FILE__, __LINE__, __FUNCTION__, __msg)  +#else +#define debug_error(__msg) \ +   _debug_printf("error: %s\n", __msg) +#endif + + +/** + * Used by debug_dump_enum and debug_dump_flags to describe symbols. + */ +struct debug_named_value +{ +   const char *name; +   unsigned long value; +}; + + +/** + * Some C pre-processor magic to simplify creating named values. + *  + * Example: + * @code + * static const debug_named_value my_names[] = { + *    DEBUG_NAMED_VALUE(MY_ENUM_VALUE_X), + *    DEBUG_NAMED_VALUE(MY_ENUM_VALUE_Y), + *    DEBUG_NAMED_VALUE(MY_ENUM_VALUE_Z), + *    DEBUG_NAMED_VALUE_END + * }; + *  + *    ... + *    debug_printf("%s = %s\n",  + *                 name, + *                 debug_dump_enum(my_names, my_value)); + *    ... + * @endcode + */ +#define DEBUG_NAMED_VALUE(__symbol) {#__symbol, (unsigned long)__symbol}  +#define DEBUG_NAMED_VALUE_END {NULL, 0}  + + +/** + * Convert a enum value to a string. + */ +const char * +debug_dump_enum(const struct debug_named_value *names,  +                unsigned long value); + + +/** + * Convert binary flags value to a string. + */ +const char * +debug_dump_flags(const struct debug_named_value *names,  +                 unsigned long value); + + +/** + * Get option. + *  + * It is an alias for getenv on Linux.  + *  + * On Windows it reads C:\gallium.cfg, which is a text file with CR+LF line  + * endings with one option per line as + *   + *   NAME=value + *  + * This file must be terminated with an extra empty line. + */ +const char * +debug_get_option(const char *name, const char *dfault); + +boolean +debug_get_bool_option(const char *name, boolean dfault); + +long +debug_get_num_option(const char *name, long dfault); + +unsigned long +debug_get_flags_option(const char *name,  +                       const struct debug_named_value *flags, +                       unsigned long dfault); + + +void * +debug_malloc(const char *file, unsigned line, const char *function, +             size_t size); + +void +debug_free(const char *file, unsigned line, const char *function, +           void *ptr); + +void * +debug_calloc(const char *file, unsigned line, const char *function, +             size_t count, size_t size ); + +void * +debug_realloc(const char *file, unsigned line, const char *function, +              void *old_ptr, size_t old_size, size_t new_size ); + +unsigned long +debug_memory_begin(void); + +void  +debug_memory_end(unsigned long beginning); + + +#if defined(PROFILE) && defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) + +void +debug_profile_start(void); + +void  +debug_profile_stop(void); + +#endif + + +#ifdef DEBUG +struct pipe_surface; +void debug_dump_image(const char *prefix, +                      unsigned format, unsigned cpp, +                      unsigned width, unsigned height, +                      unsigned stride, +                      const void *data); +void debug_dump_surface(const char *prefix, +                        struct pipe_surface *surface);    +void debug_dump_surface_bmp(const char *filename, +                            struct pipe_surface *surface); +#else +#define debug_dump_image(prefix, format, cpp, width, height, stride, data) ((void)0) +#define debug_dump_surface(prefix, surface) ((void)0) +#define debug_dump_surface_bmp(filename, surface) ((void)0) +#endif + + +#ifdef	__cplusplus +} +#endif + +#endif /* P_DEBUG_H_ */ diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h new file mode 100644 index 0000000000..cda10a2f06 --- /dev/null +++ b/src/gallium/include/pipe/p_defines.h @@ -0,0 +1,294 @@ +/************************************************************************** + *  + * 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. + *  + **************************************************************************/ + +#ifndef PIPE_DEFINES_H +#define PIPE_DEFINES_H + +#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 +#define PIPE_BLENDFACTOR_DST_ALPHA           0x4 +#define PIPE_BLENDFACTOR_DST_COLOR           0x5 +#define PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE  0x6 +#define PIPE_BLENDFACTOR_CONST_COLOR         0x7 +#define PIPE_BLENDFACTOR_CONST_ALPHA         0x8 +#define PIPE_BLENDFACTOR_SRC1_COLOR          0x9 +#define PIPE_BLENDFACTOR_SRC1_ALPHA          0x0A +#define PIPE_BLENDFACTOR_ZERO                0x11 +#define PIPE_BLENDFACTOR_INV_SRC_COLOR       0x12 +#define PIPE_BLENDFACTOR_INV_SRC_ALPHA       0x13 +#define PIPE_BLENDFACTOR_INV_DST_ALPHA       0x14 +#define PIPE_BLENDFACTOR_INV_DST_COLOR       0x15 +#define PIPE_BLENDFACTOR_INV_CONST_COLOR     0x17 +#define PIPE_BLENDFACTOR_INV_CONST_ALPHA     0x18 +#define PIPE_BLENDFACTOR_INV_SRC1_COLOR      0x19 +#define PIPE_BLENDFACTOR_INV_SRC1_ALPHA      0x1A + +#define PIPE_BLEND_ADD               0 +#define PIPE_BLEND_SUBTRACT          1 +#define PIPE_BLEND_REVERSE_SUBTRACT  2 +#define PIPE_BLEND_MIN               3 +#define PIPE_BLEND_MAX               4 + +#define PIPE_LOGICOP_CLEAR            0 +#define PIPE_LOGICOP_NOR              1 +#define PIPE_LOGICOP_AND_INVERTED     2 +#define PIPE_LOGICOP_COPY_INVERTED    3 +#define PIPE_LOGICOP_AND_REVERSE      4 +#define PIPE_LOGICOP_INVERT           5 +#define PIPE_LOGICOP_XOR              6 +#define PIPE_LOGICOP_NAND             7 +#define PIPE_LOGICOP_AND              8 +#define PIPE_LOGICOP_EQUIV            9 +#define PIPE_LOGICOP_NOOP             10 +#define PIPE_LOGICOP_OR_INVERTED      11 +#define PIPE_LOGICOP_COPY             12 +#define PIPE_LOGICOP_OR_REVERSE       13 +#define PIPE_LOGICOP_OR               14 +#define PIPE_LOGICOP_SET              15   + +#define PIPE_MASK_R  0x1 +#define PIPE_MASK_G  0x2 +#define PIPE_MASK_B  0x4 +#define PIPE_MASK_A  0x8 +#define PIPE_MASK_RGBA 0xf + + +/** + * Inequality functions.  Used for depth test, stencil compare, alpha + * test, shadow compare, etc. + */ +#define PIPE_FUNC_NEVER    0 +#define PIPE_FUNC_LESS     1 +#define PIPE_FUNC_EQUAL    2 +#define PIPE_FUNC_LEQUAL   3 +#define PIPE_FUNC_GREATER  4 +#define PIPE_FUNC_NOTEQUAL 5 +#define PIPE_FUNC_GEQUAL   6 +#define PIPE_FUNC_ALWAYS   7 + +/** Polygon fill mode */ +#define PIPE_POLYGON_MODE_FILL  0 +#define PIPE_POLYGON_MODE_LINE  1 +#define PIPE_POLYGON_MODE_POINT 2 + +/** Polygon front/back window, also for culling */ +#define PIPE_WINDING_NONE 0 +#define PIPE_WINDING_CW   1 +#define PIPE_WINDING_CCW  2 +#define PIPE_WINDING_BOTH (PIPE_WINDING_CW | PIPE_WINDING_CCW) + +/** Stencil ops */ +#define PIPE_STENCIL_OP_KEEP       0 +#define PIPE_STENCIL_OP_ZERO       1 +#define PIPE_STENCIL_OP_REPLACE    2 +#define PIPE_STENCIL_OP_INCR       3 +#define PIPE_STENCIL_OP_DECR       4 +#define PIPE_STENCIL_OP_INCR_WRAP  5 +#define PIPE_STENCIL_OP_DECR_WRAP  6 +#define PIPE_STENCIL_OP_INVERT     7 + +/** Texture types */ +enum pipe_texture_target { +   PIPE_TEXTURE_1D   = 0, +   PIPE_TEXTURE_2D   = 1, +   PIPE_TEXTURE_3D   = 2, +   PIPE_TEXTURE_CUBE = 3 +}; + +#define PIPE_TEX_FACE_POS_X 0 +#define PIPE_TEX_FACE_NEG_X 1 +#define PIPE_TEX_FACE_POS_Y 2 +#define PIPE_TEX_FACE_NEG_Y 3 +#define PIPE_TEX_FACE_POS_Z 4 +#define PIPE_TEX_FACE_NEG_Z 5 + +#define PIPE_TEX_WRAP_REPEAT                   0 +#define PIPE_TEX_WRAP_CLAMP                    1 +#define PIPE_TEX_WRAP_CLAMP_TO_EDGE            2 +#define PIPE_TEX_WRAP_CLAMP_TO_BORDER          3 +#define PIPE_TEX_WRAP_MIRROR_REPEAT            4 +#define PIPE_TEX_WRAP_MIRROR_CLAMP             5 +#define PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE     6 +#define PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER   7 + +/* Between mipmaps, ie mipfilter + */ +#define PIPE_TEX_MIPFILTER_NEAREST  0 +#define PIPE_TEX_MIPFILTER_LINEAR   1 +#define PIPE_TEX_MIPFILTER_NONE     2 + +/* Within a mipmap, ie min/mag filter  + */ +#define PIPE_TEX_FILTER_NEAREST      0 +#define PIPE_TEX_FILTER_LINEAR       1 +#define PIPE_TEX_FILTER_ANISO        2  + + +#define PIPE_TEX_COMPARE_NONE          0 +#define PIPE_TEX_COMPARE_R_TO_TEXTURE  1 + +#define PIPE_TEX_FACE_POS_X   0 +#define PIPE_TEX_FACE_NEG_X   1 +#define PIPE_TEX_FACE_POS_Y   2 +#define PIPE_TEX_FACE_NEG_Y   3 +#define PIPE_TEX_FACE_POS_Z   4 +#define PIPE_TEX_FACE_NEG_Z   5 +#define PIPE_TEX_FACE_MAX     6 + +#define PIPE_TEXTURE_USAGE_RENDER_TARGET   0x1 +#define PIPE_TEXTURE_USAGE_DISPLAY_TARGET  0x2 /* ie a backbuffer */ +#define PIPE_TEXTURE_USAGE_PRIMARY         0x4 /* ie a frontbuffer */ +#define PIPE_TEXTURE_USAGE_DEPTH_STENCIL   0x8 +#define PIPE_TEXTURE_USAGE_SAMPLER         0x10 + +#define PIPE_TEXTURE_GEOM_NON_SQUARE       0x1 +#define PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO 0x2 + + +/** + * Surface layout + */ +#define PIPE_SURFACE_LAYOUT_LINEAR  0 + + +/** + * Surface status + */ +#define PIPE_SURFACE_STATUS_UNDEFINED  0 +#define PIPE_SURFACE_STATUS_DEFINED    1 +#define PIPE_SURFACE_STATUS_CLEAR      2 + + +/** + * Buffer usage flags + */ +#define PIPE_BUFFER_USAGE_CPU_READ  (1 << 0) +#define PIPE_BUFFER_USAGE_CPU_WRITE (1 << 1) +#define PIPE_BUFFER_USAGE_GPU_READ  (1 << 2) +#define PIPE_BUFFER_USAGE_GPU_WRITE (1 << 3) +#define PIPE_BUFFER_USAGE_PIXEL     (1 << 4) +#define PIPE_BUFFER_USAGE_VERTEX    (1 << 5) +#define PIPE_BUFFER_USAGE_INDEX     (1 << 6) +#define PIPE_BUFFER_USAGE_CONSTANT  (1 << 7) +/** Pipe driver custom usage flags should be greater or equal to this value */ +#define PIPE_BUFFER_USAGE_CUSTOM    (1 << 16) + + +/**  + * Flush types: + */ +#define PIPE_FLUSH_RENDER_CACHE   0x1 +#define PIPE_FLUSH_TEXTURE_CACHE  0x2 +#define PIPE_FLUSH_SWAPBUFFERS    0x4 +#define PIPE_FLUSH_FRAME          0x8 /**< Mark the end of a frame */ + + +/** + * Shaders + */ +#define PIPE_SHADER_VERTEX   0 +#define PIPE_SHADER_FRAGMENT 1 +#define PIPE_SHADER_TYPES    2 + + +/** + * Primitive types: + */ +#define PIPE_PRIM_POINTS          0 +#define PIPE_PRIM_LINES           1 +#define PIPE_PRIM_LINE_LOOP       2 +#define PIPE_PRIM_LINE_STRIP      3 +#define PIPE_PRIM_TRIANGLES       4 +#define PIPE_PRIM_TRIANGLE_STRIP  5 +#define PIPE_PRIM_TRIANGLE_FAN    6 +#define PIPE_PRIM_QUADS           7 +#define PIPE_PRIM_QUAD_STRIP      8 +#define PIPE_PRIM_POLYGON         9 + + +/** + * Query object types + */ +#define PIPE_QUERY_OCCLUSION_COUNTER     0 +#define PIPE_QUERY_PRIMITIVES_GENERATED  1 +#define PIPE_QUERY_PRIMITIVES_EMITTED    2 +#define PIPE_QUERY_TYPES                 3 + + +/** + * Point sprite coord modes + */ +#define PIPE_SPRITE_COORD_NONE       0 +#define PIPE_SPRITE_COORD_UPPER_LEFT 1 +#define PIPE_SPRITE_COORD_LOWER_LEFT 2 + + +/** + * Implementation capabilities/limits + * Passed to pipe->get_param() + * XXX this will need some fine tuning... + */ +#define PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS 1 +#define PIPE_CAP_NPOT_TEXTURES           2 +#define PIPE_CAP_TWO_SIDED_STENCIL       3 +#define PIPE_CAP_GLSL                    4  /* XXX need something better */ +#define PIPE_CAP_S3TC                    5 +#define PIPE_CAP_ANISOTROPIC_FILTER      6 +#define PIPE_CAP_POINT_SPRITE            7 +#define PIPE_CAP_MAX_RENDER_TARGETS      8 +#define PIPE_CAP_OCCLUSION_QUERY         9 +#define PIPE_CAP_TEXTURE_SHADOW_MAP      10 +#define PIPE_CAP_MAX_TEXTURE_2D_LEVELS   11 +#define PIPE_CAP_MAX_TEXTURE_3D_LEVELS   12 +#define PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS 13 +#define PIPE_CAP_MAX_LINE_WIDTH          14 +#define PIPE_CAP_MAX_LINE_WIDTH_AA       15 +#define PIPE_CAP_MAX_POINT_WIDTH         16 +#define PIPE_CAP_MAX_POINT_WIDTH_AA      17 +#define PIPE_CAP_MAX_TEXTURE_ANISOTROPY  18 +#define PIPE_CAP_MAX_TEXTURE_LOD_BIAS    19 +#define PIPE_CAP_GUARD_BAND_LEFT         20  /*< float */ +#define PIPE_CAP_GUARD_BAND_TOP          21  /*< float */ +#define PIPE_CAP_GUARD_BAND_RIGHT        22  /*< float */ +#define PIPE_CAP_GUARD_BAND_BOTTOM       23  /*< float */ +#define PIPE_CAP_TEXTURE_MIRROR_CLAMP    24 +#define PIPE_CAP_TEXTURE_MIRROR_REPEAT   25 + + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/gallium/include/pipe/p_error.h b/src/gallium/include/pipe/p_error.h new file mode 100644 index 0000000000..b865b22635 --- /dev/null +++ b/src/gallium/include/pipe/p_error.h @@ -0,0 +1,65 @@ +/************************************************************************** + *  + * 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. + *  + * 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. + *  + **************************************************************************/ + +/** + * @file + * Gallium error codes. + *  + * @author José Fonseca <jrfonseca@tungstengraphics.com> + */ + +#ifndef P_ERROR_H_ +#define P_ERROR_H_ + + +#ifdef	__cplusplus +extern "C" { +#endif + +    +/** + * Gallium error codes. + *  + * - A zero value always means success. + * - A negative value always means failure. + * - The meaning of a positive value is function dependent.  + */ +enum pipe_error { +   PIPE_OK = 0, +   PIPE_ERROR = -1,    /**< Generic error */ +   PIPE_ERROR_BAD_INPUT = -2,  +   PIPE_ERROR_OUT_OF_MEMORY = -3, +   PIPE_ERROR_RETRY = -4 +   /* TODO */ +}; + + +#ifdef	__cplusplus +} +#endif + +#endif /* P_ERROR_H_ */ diff --git a/src/gallium/include/pipe/p_format.h b/src/gallium/include/pipe/p_format.h new file mode 100644 index 0000000000..97a4c8c510 --- /dev/null +++ b/src/gallium/include/pipe/p_format.h @@ -0,0 +1,567 @@ +/************************************************************************** + *  + * 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. + *  + **************************************************************************/ + +#ifndef PIPE_FORMAT_H +#define PIPE_FORMAT_H + +#include "p_compiler.h" +#include "p_debug.h" + +#include "util/u_string.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * The pipe_format enum is a 32-bit wide bitfield that encodes all the + * information needed to uniquely describe a pixel format. + */ + +/** + * Possible format layouts are encoded in the first 2 bits. + * The interpretation of the remaining 30 bits depends on a particular + * format layout. + */ +#define PIPE_FORMAT_LAYOUT_RGBAZS   0 +#define PIPE_FORMAT_LAYOUT_YCBCR    1 +#define PIPE_FORMAT_LAYOUT_DXT      2  /**< XXX temporary? */ +#define PIPE_FORMAT_LAYOUT_MIXED    3 + +static INLINE uint pf_layout(uint f)  /**< PIPE_FORMAT_LAYOUT_ */ +{ +   return f & 0x3; +} + +/** + * RGBAZS Format Layout. + */ + +/** + * Format component selectors for RGBAZS & MIXED layout. + */ +#define PIPE_FORMAT_COMP_R    0 +#define PIPE_FORMAT_COMP_G    1 +#define PIPE_FORMAT_COMP_B    2 +#define PIPE_FORMAT_COMP_A    3 +#define PIPE_FORMAT_COMP_0    4 +#define PIPE_FORMAT_COMP_1    5 +#define PIPE_FORMAT_COMP_Z    6 +#define PIPE_FORMAT_COMP_S    7 + +/** + * Format types for RGBAZS layout. + */ +#define PIPE_FORMAT_TYPE_UNKNOWN 0 +#define PIPE_FORMAT_TYPE_FLOAT   1  /**< 16/32/64-bit/channel formats */ +#define PIPE_FORMAT_TYPE_UNORM   2  /**< uints, normalized to [0,1] */ +#define PIPE_FORMAT_TYPE_SNORM   3  /**< ints, normalized to [-1,1] */ +#define PIPE_FORMAT_TYPE_USCALED 4  /**< uints, not normalized */ +#define PIPE_FORMAT_TYPE_SSCALED 5  /**< ints, not normalized */ +#define PIPE_FORMAT_TYPE_SRGB    6  /**< sRGB colorspace */ +#define PIPE_FORMAT_TYPE_FIXED   7  /**< 16.16 fixed point */ + + +/** + * Because the destination vector is assumed to be RGBA FLOAT, we + * need to know how to swizzle and expand components from the source + * vector. + * Let's take U_A1_R5_G5_B5 as an example. X swizzle is A, X size + * is 1 bit and type is UNORM. So we take the most significant bit + * from source vector, convert 0 to 0.0 and 1 to 1.0 and save it + * in the last component of the destination RGBA component. + * Next, Y swizzle is R, Y size is 5 and type is UNORM. We normalize + * those 5 bits into [0.0; 1.0] range and put it into second + * component of the destination vector. Rinse and repeat for + * components Z and W. + * If any of size fields is zero, it means the source format contains + * less than four components. + * If any swizzle is 0 or 1, the corresponding destination component + * should be filled with 0.0 and 1.0, respectively. + */ +typedef uint pipe_format_rgbazs_t; + +static INLINE uint pf_get(pipe_format_rgbazs_t f, uint shift, uint mask) +{ +   return (f >> shift) & mask; +} + +#define pf_swizzle_x(f)       pf_get(f, 2, 0x7)  /**< PIPE_FORMAT_COMP_ */ +#define pf_swizzle_y(f)       pf_get(f, 5, 0x7)  /**< PIPE_FORMAT_COMP_ */ +#define pf_swizzle_z(f)       pf_get(f, 8, 0x7)  /**< PIPE_FORMAT_COMP_ */ +#define pf_swizzle_w(f)       pf_get(f, 11, 0x7) /**< PIPE_FORMAT_COMP_ */ +#define pf_swizzle_xyzw(f,i)  pf_get(f, 2+((i)*3), 0x7) +#define pf_size_x(f)          pf_get(f, 14, 0x7) /**< Size of X */ +#define pf_size_y(f)          pf_get(f, 17, 0x7) /**< Size of Y */ +#define pf_size_z(f)          pf_get(f, 20, 0x7) /**< Size of Z */ +#define pf_size_w(f)          pf_get(f, 23, 0x7) /**< Size of W */ +#define pf_size_xyzw(f,i)     pf_get(f, 14+((i)*3), 0x7) +#define pf_exp2(f)            pf_get(f, 26, 0x7) /**< Scale size by 2 ^ exp2 */ +#define pf_type(f)            pf_get(f, 29, 0x7) /**< PIPE_FORMAT_TYPE_ */ + +/** + * Helper macro to encode the above structure into a 32-bit value. + */ +#define _PIPE_FORMAT_RGBAZS( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, EXP2, TYPE ) (\ +   (PIPE_FORMAT_LAYOUT_RGBAZS << 0) |\ +   ((SWZ) << 2) |\ +   ((SIZEX) << 14) |\ +   ((SIZEY) << 17) |\ +   ((SIZEZ) << 20) |\ +   ((SIZEW) << 23) |\ +   ((EXP2) << 26) |\ +   ((TYPE) << 29) ) + +/** + * Helper macro to encode the swizzle part of the structure above. + */ +#define _PIPE_FORMAT_SWZ( SWZX, SWZY, SWZZ, SWZW ) (((SWZX) << 0) | ((SWZY) << 3) | ((SWZZ) << 6) | ((SWZW) << 9)) + +/** + * Shorthand macro for RGBAZS layout with component sizes in 1-bit units. + */ +#define _PIPE_FORMAT_RGBAZS_1( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, TYPE )\ +   _PIPE_FORMAT_RGBAZS( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, 0, TYPE ) + +/** + * Shorthand macro for RGBAZS layout with component sizes in 2-bit units. + */ +#define _PIPE_FORMAT_RGBAZS_2( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, TYPE )\ +   _PIPE_FORMAT_RGBAZS( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, 1, TYPE ) + +/** + * Shorthand macro for RGBAZS layout with component sizes in 8-bit units. + */ +#define _PIPE_FORMAT_RGBAZS_8( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, TYPE )\ +   _PIPE_FORMAT_RGBAZS( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, 3, TYPE ) + +/** + * Shorthand macro for RGBAZS layout with component sizes in 64-bit units. + */ +#define _PIPE_FORMAT_RGBAZS_64( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, TYPE )\ +   _PIPE_FORMAT_RGBAZS( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, 6, TYPE ) + +typedef uint pipe_format_mixed_t; + +/* NOTE: Use pf_swizzle_* and pf_size_* macros for swizzles and sizes. + */ + +#define pf_mixed_sign_x(f)       pf_get( f, 26, 0x1 )       /*< Sign of X */ +#define pf_mixed_sign_y(f)       pf_get( f, 27, 0x1 )       /*< Sign of Y */ +#define pf_mixed_sign_z(f)       pf_get( f, 28, 0x1 )       /*< Sign of Z */ +#define pf_mixed_sign_w(f)       pf_get( f, 29, 0x1 )       /*< Sign of W */ +#define pf_mixed_sign_xyzw(f, i) pf_get( f, 26 + (i), 0x1 ) +#define pf_mixed_normalized(f)   pf_get( f, 30, 0x1 )       /*< Type is NORM (1) or SCALED (0) */ +#define pf_mixed_scale8(f)       pf_get( f, 31, 0x1 )       /*< Scale size by either one (0) or eight (1) */ + +/** + * Helper macro to encode the above structure into a 32-bit value. + */ +#define _PIPE_FORMAT_MIXED( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, SIGNX, SIGNY, SIGNZ, SIGNW, NORMALIZED, SCALE8 ) (\ +   (PIPE_FORMAT_LAYOUT_MIXED << 0) |\ +   ((SWZ) << 2) |\ +   ((SIZEX) << 14) |\ +   ((SIZEY) << 17) |\ +   ((SIZEZ) << 20) |\ +   ((SIZEW) << 23) |\ +   ((SIGNX) << 26) |\ +   ((SIGNY) << 27) |\ +   ((SIGNZ) << 28) |\ +   ((SIGNW) << 29) |\ +   ((NORMALIZED) << 30) |\ +   ((SCALE8) << 31) ) + +/** + * Shorthand macro for common format swizzles. + */ +#define _PIPE_FORMAT_R001 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_1 ) +#define _PIPE_FORMAT_RG01 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_1 ) +#define _PIPE_FORMAT_RGB1 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_B, PIPE_FORMAT_COMP_1 ) +#define _PIPE_FORMAT_RGBA _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_B, PIPE_FORMAT_COMP_A ) +#define _PIPE_FORMAT_ARGB _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_A, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_B ) +#define _PIPE_FORMAT_ABGR _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_A, PIPE_FORMAT_COMP_B, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_R ) +#define _PIPE_FORMAT_BGRA _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_B, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_A ) +#define _PIPE_FORMAT_1RGB _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_1, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_B ) +#define _PIPE_FORMAT_1BGR _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_1, PIPE_FORMAT_COMP_B, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_R ) +#define _PIPE_FORMAT_BGR1 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_B, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_1 ) +#define _PIPE_FORMAT_0000 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 ) +#define _PIPE_FORMAT_000R _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_R ) +#define _PIPE_FORMAT_RRR1 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_1 ) +#define _PIPE_FORMAT_RRRR _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R ) +#define _PIPE_FORMAT_RRRG _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_G ) +#define _PIPE_FORMAT_Z000 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_Z, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 ) +#define _PIPE_FORMAT_0Z00 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_Z, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 ) +#define _PIPE_FORMAT_SZ00 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_S, PIPE_FORMAT_COMP_Z, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 ) +#define _PIPE_FORMAT_ZS00 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_Z, PIPE_FORMAT_COMP_S, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 ) +#define _PIPE_FORMAT_S000 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_S, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 ) + +/** + * YCBCR Format Layout. + */ + +/** + * This only contains a flag that indicates whether the format is reversed or + * not. + */ +typedef uint pipe_format_ycbcr_t; + +/** + * Helper macro to encode the above structure into a 32-bit value. + */ +#define _PIPE_FORMAT_YCBCR( REV ) (\ +   (PIPE_FORMAT_LAYOUT_YCBCR << 0) |\ +   ((REV) << 2) ) + +static INLINE uint pf_rev(pipe_format_ycbcr_t f) +{ +   return (f >> 2) & 0x1; +} + + +/** +  * Compresssed format layouts (this will probably change) +  */ +#define _PIPE_FORMAT_DXT( LEVEL, RSIZE, GSIZE, BSIZE, ASIZE ) \ +   ((PIPE_FORMAT_LAYOUT_DXT << 0) | \ +    ((LEVEL) << 2) | \ +    ((RSIZE) << 5) | \ +    ((GSIZE) << 8) | \ +    ((BSIZE) << 11) | \ +    ((ASIZE) << 14) ) + + + +/** + * Texture/surface image formats (preliminary) + */ + +/* KW: Added lots of surface formats to support vertex element layout + * definitions, and eventually render-to-vertex-buffer.  Could + * consider making float/int/uint/scaled/normalized a separate + * parameter, but on the other hand there are special cases like + * z24s8, compressed textures, ycbcr, etc that won't fit that model. + */ + +enum pipe_format { +   PIPE_FORMAT_NONE                  = _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_0000, 0, 0, 0, 0, PIPE_FORMAT_TYPE_UNKNOWN ), +   PIPE_FORMAT_A8R8G8B8_UNORM        = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_ARGB, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_X8R8G8B8_UNORM        = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_1RGB, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_B8G8R8A8_UNORM        = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_BGRA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_B8G8R8X8_UNORM        = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_BGR1, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_A1R5G5B5_UNORM        = _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_ARGB, 1, 5, 5, 5, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_A4R4G4B4_UNORM        = _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_ARGB, 4, 4, 4, 4, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_R5G6B5_UNORM          = _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_RGB1, 5, 6, 5, 0, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_A2B10G10R10_UNORM     = _PIPE_FORMAT_RGBAZS_2 ( _PIPE_FORMAT_ABGR, 1, 5, 5, 5, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_L8_UNORM              = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRR1, 1, 1, 1, 0, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte luminance */ +   PIPE_FORMAT_A8_UNORM              = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_000R, 0, 0, 0, 1, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte alpha */ +   PIPE_FORMAT_I8_UNORM              = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRRR, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte intensity */ +   PIPE_FORMAT_A8L8_UNORM            = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRRG, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte alpha, luminance */ +   PIPE_FORMAT_L16_UNORM             = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRR1, 2, 2, 2, 0, PIPE_FORMAT_TYPE_UNORM ), /**< ushort luminance */ +   PIPE_FORMAT_YCBCR                 = _PIPE_FORMAT_YCBCR( 0 ), +   PIPE_FORMAT_YCBCR_REV             = _PIPE_FORMAT_YCBCR( 1 ), +   PIPE_FORMAT_Z16_UNORM             = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_Z32_UNORM             = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_Z32_FLOAT             = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), +   PIPE_FORMAT_S8Z24_UNORM           = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_SZ00, 1, 3, 0, 0, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_Z24S8_UNORM           = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_ZS00, 3, 1, 0, 0, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_X8Z24_UNORM           = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_0Z00, 1, 3, 0, 0, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_Z24X8_UNORM           = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000, 3, 1, 0, 0, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_S8_UNORM              = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_S000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte stencil */ +   PIPE_FORMAT_R64_FLOAT             = _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_R001, 1, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), +   PIPE_FORMAT_R64G64_FLOAT          = _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RG01, 1, 1, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), +   PIPE_FORMAT_R64G64B64_FLOAT       = _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RGB1, 1, 1, 1, 0, PIPE_FORMAT_TYPE_FLOAT ), +   PIPE_FORMAT_R64G64B64A64_FLOAT    = _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_FLOAT ), +   PIPE_FORMAT_R32_FLOAT             = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 4, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), +   PIPE_FORMAT_R32G32_FLOAT          = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 4, 4, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), +   PIPE_FORMAT_R32G32B32_FLOAT       = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 4, 4, 4, 0, PIPE_FORMAT_TYPE_FLOAT ), +   PIPE_FORMAT_R32G32B32A32_FLOAT    = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_FLOAT ), +   PIPE_FORMAT_R32_UNORM             = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 4, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_R32G32_UNORM          = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 4, 4, 0, 0, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_R32G32B32_UNORM       = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 4, 4, 4, 0, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_R32G32B32A32_UNORM    = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_R32_USCALED           = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 4, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ), +   PIPE_FORMAT_R32G32_USCALED        = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 4, 4, 0, 0, PIPE_FORMAT_TYPE_USCALED ), +   PIPE_FORMAT_R32G32B32_USCALED     = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 4, 4, 4, 0, PIPE_FORMAT_TYPE_USCALED ), +   PIPE_FORMAT_R32G32B32A32_USCALED  = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_USCALED ), +   PIPE_FORMAT_R32_SNORM             = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 4, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ), +   PIPE_FORMAT_R32G32_SNORM          = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 4, 4, 0, 0, PIPE_FORMAT_TYPE_SNORM ), +   PIPE_FORMAT_R32G32B32_SNORM       = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 4, 4, 4, 0, PIPE_FORMAT_TYPE_SNORM ), +   PIPE_FORMAT_R32G32B32A32_SNORM    = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_SNORM ), +   PIPE_FORMAT_R32_SSCALED           = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 4, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), +   PIPE_FORMAT_R32G32_SSCALED        = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 4, 4, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), +   PIPE_FORMAT_R32G32B32_SSCALED     = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 4, 4, 4, 0, PIPE_FORMAT_TYPE_SSCALED ), +   PIPE_FORMAT_R32G32B32A32_SSCALED  = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_SSCALED ), +   PIPE_FORMAT_R16_UNORM             = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 2, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_R16G16_UNORM          = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 2, 2, 0, 0, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_R16G16B16_UNORM       = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 2, 2, 2, 0, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_R16G16B16A16_UNORM    = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_R16_USCALED           = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 2, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ), +   PIPE_FORMAT_R16G16_USCALED        = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 2, 2, 0, 0, PIPE_FORMAT_TYPE_USCALED ), +   PIPE_FORMAT_R16G16B16_USCALED     = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 2, 2, 2, 0, PIPE_FORMAT_TYPE_USCALED ), +   PIPE_FORMAT_R16G16B16A16_USCALED  = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_USCALED ), +   PIPE_FORMAT_R16_SNORM             = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 2, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ), +   PIPE_FORMAT_R16G16_SNORM          = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 2, 2, 0, 0, PIPE_FORMAT_TYPE_SNORM ), +   PIPE_FORMAT_R16G16B16_SNORM       = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 2, 2, 2, 0, PIPE_FORMAT_TYPE_SNORM ), +   PIPE_FORMAT_R16G16B16A16_SNORM    = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_SNORM ), +   PIPE_FORMAT_R16_SSCALED           = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 2, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), +   PIPE_FORMAT_R16G16_SSCALED        = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 2, 2, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), +   PIPE_FORMAT_R16G16B16_SSCALED     = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 2, 2, 2, 0, PIPE_FORMAT_TYPE_SSCALED ), +   PIPE_FORMAT_R16G16B16A16_SSCALED  = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_SSCALED ), +   PIPE_FORMAT_R8_UNORM              = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 1, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_R8G8_UNORM            = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 1, 1, 0, 0, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_R8G8B8_UNORM          = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 1, 1, 1, 0, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_R8G8B8A8_UNORM        = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_R8G8B8X8_UNORM        = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), +   PIPE_FORMAT_R8_USCALED            = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 1, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ), +   PIPE_FORMAT_R8G8_USCALED          = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 1, 1, 0, 0, PIPE_FORMAT_TYPE_USCALED ), +   PIPE_FORMAT_R8G8B8_USCALED        = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 1, 1, 1, 0, PIPE_FORMAT_TYPE_USCALED ), +   PIPE_FORMAT_R8G8B8A8_USCALED      = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_USCALED ), +   PIPE_FORMAT_R8G8B8X8_USCALED      = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 1, 1, 1, 1, PIPE_FORMAT_TYPE_USCALED ), +   PIPE_FORMAT_R8_SNORM              = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 1, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ), +   PIPE_FORMAT_R8G8_SNORM            = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 1, 1, 0, 0, PIPE_FORMAT_TYPE_SNORM ), +   PIPE_FORMAT_R8G8B8_SNORM          = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SNORM ), +   PIPE_FORMAT_R8G8B8A8_SNORM        = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SNORM ), +   PIPE_FORMAT_R8G8B8X8_SNORM        = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SNORM ), +   PIPE_FORMAT_B6G5R5_SNORM          = _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_BGR1, 6, 5, 5, 0, PIPE_FORMAT_TYPE_SNORM ), +   PIPE_FORMAT_A8B8G8R8_SNORM        = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_BGRA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SNORM ), +   PIPE_FORMAT_X8B8G8R8_SNORM        = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SNORM ), +   PIPE_FORMAT_R8_SSCALED            = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 1, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), +   PIPE_FORMAT_R8G8_SSCALED          = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 1, 1, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), +   PIPE_FORMAT_R8G8B8_SSCALED        = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SSCALED ), +   PIPE_FORMAT_R8G8B8A8_SSCALED      = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SSCALED ), +   PIPE_FORMAT_R8G8B8X8_SSCALED      = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SSCALED ), +   PIPE_FORMAT_R32_FIXED             = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 4, 0, 0, 0, PIPE_FORMAT_TYPE_FIXED ), +   PIPE_FORMAT_R32G32_FIXED          = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 4, 4, 0, 0, PIPE_FORMAT_TYPE_FIXED ), +   PIPE_FORMAT_R32G32B32_FIXED       = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 4, 4, 4, 0, PIPE_FORMAT_TYPE_FIXED ), +   PIPE_FORMAT_R32G32B32A32_FIXED    = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_FIXED ), +   /* sRGB formats */ +   PIPE_FORMAT_L8_SRGB               = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRR1, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SRGB ), +   PIPE_FORMAT_A8_L8_SRGB            = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRRG, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SRGB ), +   PIPE_FORMAT_R8G8B8_SRGB           = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SRGB ), +   PIPE_FORMAT_R8G8B8A8_SRGB         = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SRGB ), +   PIPE_FORMAT_R8G8B8X8_SRGB         = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SRGB ), + +   /* mixed formats */ +   PIPE_FORMAT_X8UB8UG8SR8S_NORM     = _PIPE_FORMAT_MIXED( _PIPE_FORMAT_1BGR, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1 ), +   PIPE_FORMAT_B6UG5SR5S_NORM        = _PIPE_FORMAT_MIXED( _PIPE_FORMAT_BGR1, 6, 5, 5, 0, 0, 1, 1, 0, 1, 0 ), + +   /* compressed formats */ +   PIPE_FORMAT_DXT1_RGB              = _PIPE_FORMAT_DXT( 1, 8, 8, 8, 0 ), +   PIPE_FORMAT_DXT1_RGBA             = _PIPE_FORMAT_DXT( 1, 8, 8, 8, 8 ), +   PIPE_FORMAT_DXT3_RGBA             = _PIPE_FORMAT_DXT( 3, 8, 8, 8, 8 ), +   PIPE_FORMAT_DXT5_RGBA             = _PIPE_FORMAT_DXT( 5, 8, 8, 8, 8 ) +}; + +/** + * Builds pipe format name from format token. + */ +extern const char *pf_name( enum pipe_format format ); + +/** + * Return bits for a particular component. + * \param comp  component index, starting at 0 + */ +static INLINE uint pf_get_component_bits( enum pipe_format format, uint comp ) +{ +   uint size; + +   if (pf_swizzle_x(format) == comp) { +      size = pf_size_x(format); +   } +   else if (pf_swizzle_y(format) == comp) { +      size = pf_size_y(format); +   } +   else if (pf_swizzle_z(format) == comp) { +      size = pf_size_z(format); +   } +   else if (pf_swizzle_w(format) == comp) { +      size = pf_size_w(format); +   } +   else { +      size = 0; +   } +   if (pf_layout( format ) == PIPE_FORMAT_LAYOUT_RGBAZS) +      return size << pf_exp2( format ); +   return size << (pf_mixed_scale8( format ) * 3); +} + +/** + * Return total bits needed for the pixel format. + */ +static INLINE uint pf_get_bits( enum pipe_format format ) +{ +   switch (pf_layout(format)) { +   case PIPE_FORMAT_LAYOUT_RGBAZS: +   case PIPE_FORMAT_LAYOUT_MIXED: +      return +         pf_get_component_bits( format, PIPE_FORMAT_COMP_0 ) + +         pf_get_component_bits( format, PIPE_FORMAT_COMP_1 ) + +         pf_get_component_bits( format, PIPE_FORMAT_COMP_R ) + +         pf_get_component_bits( format, PIPE_FORMAT_COMP_G ) + +         pf_get_component_bits( format, PIPE_FORMAT_COMP_B ) + +         pf_get_component_bits( format, PIPE_FORMAT_COMP_A ) + +         pf_get_component_bits( format, PIPE_FORMAT_COMP_Z ) + +         pf_get_component_bits( format, PIPE_FORMAT_COMP_S ); +   case PIPE_FORMAT_LAYOUT_YCBCR: +      assert( format == PIPE_FORMAT_YCBCR || format == PIPE_FORMAT_YCBCR_REV ); +      /* return effective bits per pixel */ +      return 16;  +   default: +      assert( 0 ); +      return 0; +   } +} + +/** + * Return bytes per pixel for the given format. + */ +static INLINE uint pf_get_size( enum pipe_format format ) +{ +   assert(pf_get_bits(format) % 8 == 0); +   return pf_get_bits(format) / 8; +} + +/** + * Describe accurately the pixel format. + *  + * The chars-per-pixel concept falls apart with compressed and yuv images, where + * more than one pixel are coded in a single data block. This structure  + * describes that block. + *  + * Simple pixel formats are effectively a 1x1xcpp block. + */ +struct pipe_format_block +{ +   /** Block size in bytes */ +   unsigned size; +    +   /** Block width in pixels */ +   unsigned width; +    +   /** Block height in pixels */ +   unsigned height; +}; + +/** + * Describe pixel format's block.    + *  + * @sa http://msdn2.microsoft.com/en-us/library/ms796147.aspx + */ +static INLINE void  +pf_get_block(enum pipe_format format, struct pipe_format_block *block) +{ +   switch(format) { +   case PIPE_FORMAT_DXT1_RGBA: +   case PIPE_FORMAT_DXT1_RGB: +      block->size = 8; +      block->width = 4; +      block->height = 4; +      break; +   case PIPE_FORMAT_DXT3_RGBA: +   case PIPE_FORMAT_DXT5_RGBA: +      block->size = 16; +      block->width = 4; +      block->height = 4; +      break; +   case PIPE_FORMAT_YCBCR: +   case PIPE_FORMAT_YCBCR_REV: +      block->size = 4; /* 2*cpp */ +      block->width = 2; +      block->height = 1; +      break; +   default: +      block->size = pf_get_size(format); +      block->width = 1; +      block->height = 1; +      break; +   } +} + +static INLINE unsigned +pf_get_nblocksx(const struct pipe_format_block *block, unsigned x) +{ +   return (x + block->width - 1)/block->width; +} + +static INLINE unsigned +pf_get_nblocksy(const struct pipe_format_block *block, unsigned y) +{ +   return (y + block->height - 1)/block->height; +} + +static INLINE unsigned +pf_get_nblocks(const struct pipe_format_block *block, unsigned width, unsigned height) +{ +   return pf_get_nblocksx(block, width)*pf_get_nblocksy(block, height); +} + +static INLINE boolean  +pf_is_compressed( enum pipe_format format ) +{ +   return pf_layout(format) == PIPE_FORMAT_LAYOUT_DXT ? TRUE : FALSE; +} + +static INLINE boolean  +pf_is_ycbcr( enum pipe_format format ) +{ +   return pf_layout(format) == PIPE_FORMAT_LAYOUT_YCBCR ? TRUE : FALSE; +} + +static INLINE boolean  +pf_has_alpha( enum pipe_format format ) +{ +   switch (pf_layout(format)) { +   case PIPE_FORMAT_LAYOUT_RGBAZS: +   case PIPE_FORMAT_LAYOUT_MIXED: +      /* FIXME: pf_get_component_bits( PIPE_FORMAT_A8L8_UNORM, PIPE_FORMAT_COMP_A ) should not return 0 right? */ +      if(format == PIPE_FORMAT_A8_UNORM ||  +         format == PIPE_FORMAT_A8L8_UNORM ||  +         format == PIPE_FORMAT_A8_L8_SRGB) +         return TRUE; +      return pf_get_component_bits( format, PIPE_FORMAT_COMP_A ) ? TRUE : FALSE; +   case PIPE_FORMAT_LAYOUT_YCBCR: +      return FALSE;  +   case PIPE_FORMAT_LAYOUT_DXT: +      switch (format) { +      case PIPE_FORMAT_DXT1_RGBA: +      case PIPE_FORMAT_DXT3_RGBA: +      case PIPE_FORMAT_DXT5_RGBA: +         return TRUE; +      default: +         return FALSE; +      } +   default: +      assert( 0 ); +      return FALSE; +   } +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/gallium/include/pipe/p_inlines.h b/src/gallium/include/pipe/p_inlines.h new file mode 100644 index 0000000000..d70de8e301 --- /dev/null +++ b/src/gallium/include/pipe/p_inlines.h @@ -0,0 +1,216 @@ +/************************************************************************** + *  + * 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. + *  + **************************************************************************/ + +#ifndef P_INLINES_H +#define P_INLINES_H + +#include "p_context.h" +#include "p_defines.h" +#include "p_screen.h" +#include "p_winsys.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* XXX: these are a kludge.  will fix when all surfaces are views into + * textures, and free-floating winsys surfaces go away. + */ +static INLINE void * +pipe_surface_map( struct pipe_surface *surf, unsigned flags ) +{ +   if (surf->texture) { +      struct pipe_screen *screen = surf->texture->screen; +      return surf->texture->screen->surface_map( screen, surf, flags ); +   } +   else { +      struct pipe_winsys *winsys = surf->winsys; +      char *map = (char *)winsys->buffer_map( winsys, surf->buffer, flags ); +      if (map == NULL) +         return NULL; +      return (void *)(map + surf->offset); +   } +} + +static INLINE void +pipe_surface_unmap( struct pipe_surface *surf ) +{ +   if (surf->texture) { +      struct pipe_screen *screen = surf->texture->screen; +      surf->texture->screen->surface_unmap( screen, surf ); +   } +   else { +      struct pipe_winsys *winsys = surf->winsys; +      winsys->buffer_unmap( winsys, surf->buffer ); +   } +} + + + +/** + * Set 'ptr' to point to 'surf' and update reference counting. + * The old thing pointed to, if any, will be unreferenced first. + * 'surf' may be NULL. + */ +static INLINE void +pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) +{ +   /* bump the refcount first */ +   if (surf)  +      surf->refcount++; + +   if (*ptr) { + +      /* There are currently two sorts of surfaces... This needs to be +       * fixed so that all surfaces are views into a texture. +       */ +      if ((*ptr)->texture) { +         struct pipe_screen *screen = (*ptr)->texture->screen; +         screen->tex_surface_release( screen, ptr ); +      } +      else { +         struct pipe_winsys *winsys = (*ptr)->winsys; +         winsys->surface_release(winsys, ptr); +      } + +      assert(!*ptr); +   } + +   *ptr = surf; +} + + +/* XXX: thread safety issues! + */ +static INLINE void +winsys_buffer_reference(struct pipe_winsys *winsys, +		      struct pipe_buffer **ptr, +		      struct pipe_buffer *buf) +{ +   if (buf)  +      buf->refcount++; + +   if (*ptr && --(*ptr)->refcount == 0) +      winsys->buffer_destroy( winsys, *ptr ); + +   *ptr = buf; +} + + + +/** + * \sa pipe_surface_reference + */ +static INLINE void +pipe_texture_reference(struct pipe_texture **ptr, +		       struct pipe_texture *pt) +{ +   assert(ptr); + +   if (pt)  +      pt->refcount++; + +   if (*ptr) { +      struct pipe_screen *screen = (*ptr)->screen; +      assert(screen); +      screen->texture_release(screen, ptr); + +      assert(!*ptr); +   } + +   *ptr = pt; +} + + +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; +} + + +/** + * Convenience wrappers for winsys buffer functions. + */ + +static INLINE struct pipe_buffer * +pipe_buffer_create( struct pipe_screen *screen, +                    unsigned alignment, unsigned usage, unsigned size ) +{ +   return screen->winsys->buffer_create(screen->winsys, alignment, usage, size); +} + +static INLINE struct pipe_buffer * +pipe_user_buffer_create( struct pipe_screen *screen, void *ptr, unsigned size ) +{ +   return screen->winsys->user_buffer_create(screen->winsys, ptr, size); +} + +static INLINE void +pipe_buffer_destroy( struct pipe_screen *screen, struct pipe_buffer *buf ) +{ +   screen->winsys->buffer_destroy(screen->winsys, buf); +} + +static INLINE void * +pipe_buffer_map(struct pipe_screen *screen, +                struct pipe_buffer *buf, +                unsigned usage) +{ +   return screen->winsys->buffer_map(screen->winsys, buf, usage); +} + +static INLINE void +pipe_buffer_unmap(struct pipe_screen *screen, +                  struct pipe_buffer *buf) +{ +   screen->winsys->buffer_unmap(screen->winsys, buf); +} + +/* XXX when we're using this everywhere, get rid of + * winsys_buffer_reference() above. + */ +static INLINE void +pipe_buffer_reference(struct pipe_screen *screen, +		      struct pipe_buffer **ptr, +		      struct pipe_buffer *buf) +{ +   winsys_buffer_reference(screen->winsys, ptr, buf); +} + + +#ifdef __cplusplus +} +#endif + +#endif /* P_INLINES_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..3bedc75294 --- /dev/null +++ b/src/gallium/include/pipe/p_screen.h @@ -0,0 +1,139 @@ +/************************************************************************** + *  + * 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. + *  + **************************************************************************/ + +/** + * @file + *  + * 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 * ); + + +   const char *(*get_name)( struct pipe_screen * ); + +   const char *(*get_vendor)( struct pipe_screen * ); + +   /** +    * Query an integer-valued capability/parameter/limit +    * \param param  one of PIPE_CAP_x +    */ +   int (*get_param)( struct pipe_screen *, int param ); + +   /** +    * Query a float-valued capability/parameter/limit +    * \param param  one of PIPE_CAP_x +    */ +   float (*get_paramf)( struct pipe_screen *, int param ); + +   /** +    * Check if the given pipe_format is supported as a texture or +    * drawing surface. +    * \param tex_usage  bitmask of PIPE_TEXTURE_USAGE_* +    * \param flags  bitmask of PIPE_TEXTURE_GEOM_* +    */ +   boolean (*is_format_supported)( struct pipe_screen *, +                                   enum pipe_format format, +                                   enum pipe_texture_target target, +                                   unsigned tex_usage,  +                                   unsigned geom_flags ); + +   /** +    * Create a new texture object, using the given template info. +    */ +   struct pipe_texture * (*texture_create)(struct pipe_screen *, +                                           const struct pipe_texture *templat); + +   /** +    * Create a new texture object, using the given template info, but on top of  +    * existing memory. +    *  +    * It is assumed that the buffer data is layed out according to the expected +    * by the hardware. NULL will be returned if any inconsistency is found.   +    */ +   struct pipe_texture * (*texture_blanket)(struct pipe_screen *, +                                            const struct pipe_texture *templat, +                                            const unsigned *pitch, +                                            struct pipe_buffer *buffer); + +   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, +                                           unsigned usage ); + +   /* Surfaces allocated by the above must be released here: +    */ +   void (*tex_surface_release)( struct pipe_screen *, +                                struct pipe_surface ** ); +    + +   void *(*surface_map)( struct pipe_screen *, +                         struct pipe_surface *surface, +                         unsigned flags ); + +   void (*surface_unmap)( struct pipe_screen *, +                          struct pipe_surface *surface ); +    +}; + + +#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 new file mode 100644 index 0000000000..78c20de3e2 --- /dev/null +++ b/src/gallium/include/pipe/p_shader_tokens.h @@ -0,0 +1,809 @@ +/************************************************************************** + *  + * 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. + *  + * 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 TGSI_TOKEN_H +#define TGSI_TOKEN_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "p_compiler.h" + +struct tgsi_version +{ +   unsigned MajorVersion  : 8; +   unsigned MinorVersion  : 8; +   unsigned Padding       : 16; +}; + +struct tgsi_header +{ +   unsigned HeaderSize : 8; +   unsigned BodySize   : 24; +}; + +#define TGSI_PROCESSOR_FRAGMENT  0 +#define TGSI_PROCESSOR_VERTEX    1 +#define TGSI_PROCESSOR_GEOMETRY  2 + +struct tgsi_processor +{ +   unsigned Processor  : 4;  /* TGSI_PROCESSOR_ */ +   unsigned Padding    : 28; +}; + +#define TGSI_TOKEN_TYPE_DECLARATION    0 +#define TGSI_TOKEN_TYPE_IMMEDIATE      1 +#define TGSI_TOKEN_TYPE_INSTRUCTION    2 + +struct tgsi_token +{ +   unsigned Type       : 4;  /* TGSI_TOKEN_TYPE_ */ +   unsigned Size       : 8;  /* UINT */ +   unsigned Padding    : 19; +   unsigned Extended   : 1;  /* BOOL */ +}; + +enum tgsi_file_type { +   TGSI_FILE_NULL        =0, +   TGSI_FILE_CONSTANT    =1, +   TGSI_FILE_INPUT       =2, +   TGSI_FILE_OUTPUT      =3, +   TGSI_FILE_TEMPORARY   =4, +   TGSI_FILE_SAMPLER     =5, +   TGSI_FILE_ADDRESS     =6, +   TGSI_FILE_IMMEDIATE   =7, +   TGSI_FILE_COUNT      /**< how many TGSI_FILE_ types */ +}; + + +#define TGSI_WRITEMASK_NONE     0x00 +#define TGSI_WRITEMASK_X        0x01 +#define TGSI_WRITEMASK_Y        0x02 +#define TGSI_WRITEMASK_XY       0x03 +#define TGSI_WRITEMASK_Z        0x04 +#define TGSI_WRITEMASK_XZ       0x05 +#define TGSI_WRITEMASK_YZ       0x06 +#define TGSI_WRITEMASK_XYZ      0x07 +#define TGSI_WRITEMASK_W        0x08 +#define TGSI_WRITEMASK_XW       0x09 +#define TGSI_WRITEMASK_YW       0x0A +#define TGSI_WRITEMASK_XYW      0x0B +#define TGSI_WRITEMASK_ZW       0x0C +#define TGSI_WRITEMASK_XZW      0x0D +#define TGSI_WRITEMASK_YZW      0x0E +#define TGSI_WRITEMASK_XYZW     0x0F + +#define TGSI_INTERPOLATE_CONSTANT      0 +#define TGSI_INTERPOLATE_LINEAR        1 +#define TGSI_INTERPOLATE_PERSPECTIVE   2 +#define TGSI_INTERPOLATE_COUNT         3 + +struct tgsi_declaration +{ +   unsigned Type        : 4;  /* TGSI_TOKEN_TYPE_DECLARATION */ +   unsigned Size        : 8;  /* UINT */ +   unsigned File        : 4;  /* one of TGSI_FILE_x */ +   unsigned UsageMask   : 4;  /* bitmask of TGSI_WRITEMASK_x flags */ +   unsigned Interpolate : 4;  /* TGSI_INTERPOLATE_ */ +   unsigned Semantic    : 1;  /* BOOL, any semantic info? */ +   unsigned Padding     : 6; +   unsigned Extended    : 1;  /* BOOL */ +}; + +struct tgsi_declaration_range +{ +   unsigned First   : 16; /* UINT */ +   unsigned Last    : 16; /* UINT */ +}; + +#define TGSI_SEMANTIC_POSITION 0 +#define TGSI_SEMANTIC_COLOR    1 +#define TGSI_SEMANTIC_BCOLOR   2 /**< back-face color */ +#define TGSI_SEMANTIC_FOG      3 +#define TGSI_SEMANTIC_PSIZE    4 +#define TGSI_SEMANTIC_GENERIC  5 +#define TGSI_SEMANTIC_NORMAL   6 +#define TGSI_SEMANTIC_COUNT    7 /**< number of semantic values */ + +struct tgsi_declaration_semantic +{ +   unsigned SemanticName   : 8;  /* one of TGSI_SEMANTIC_ */ +   unsigned SemanticIndex  : 16; /* UINT */ +   unsigned Padding        : 8; +}; + +#define TGSI_IMM_FLOAT32   0 + +struct tgsi_immediate +{ +   unsigned Type       : 4;  /* TGSI_TOKEN_TYPE_IMMEDIATE */ +   unsigned Size       : 8;  /* UINT */ +   unsigned DataType   : 4;  /* TGSI_IMM_ */ +   unsigned Padding    : 15; +   unsigned Extended   : 1;  /* BOOL */ +}; + +struct tgsi_immediate_float32 +{ +   float Float; +}; + +/* + * GL_NV_vertex_program + */ +#define TGSI_OPCODE_ARL                 0 +#define TGSI_OPCODE_MOV                 1 +#define TGSI_OPCODE_LIT                 2 +#define TGSI_OPCODE_RCP                 3 +#define TGSI_OPCODE_RSQ                 4 +#define TGSI_OPCODE_EXP                 5 +#define TGSI_OPCODE_LOG                 6 +#define TGSI_OPCODE_MUL                 7 +#define TGSI_OPCODE_ADD                 8 +#define TGSI_OPCODE_DP3                 9 +#define TGSI_OPCODE_DP4                 10 +#define TGSI_OPCODE_DST                 11 +#define TGSI_OPCODE_MIN                 12 +#define TGSI_OPCODE_MAX                 13 +#define TGSI_OPCODE_SLT                 14 +#define TGSI_OPCODE_SGE                 15 +#define TGSI_OPCODE_MAD                 16 + +/* + * GL_ATI_fragment_shader + */ +#define TGSI_OPCODE_SUB                 17 +#define TGSI_OPCODE_DOT3                TGSI_OPCODE_DP3 +#define TGSI_OPCODE_DOT4                TGSI_OPCODE_DP4 +#define TGSI_OPCODE_LERP                18 +#define TGSI_OPCODE_CND                 19 +#define TGSI_OPCODE_CND0                20 +#define TGSI_OPCODE_DOT2ADD             21 + +/* + * GL_EXT_vertex_shader + */ +#define TGSI_OPCODE_INDEX               22 +#define TGSI_OPCODE_NEGATE              23 +#define TGSI_OPCODE_MADD                TGSI_OPCODE_MAD +#define TGSI_OPCODE_FRAC                24 +#define TGSI_OPCODE_SETGE               TGSI_OPCODE_SGE +#define TGSI_OPCODE_SETLT               TGSI_OPCODE_SLT +#define TGSI_OPCODE_CLAMP               25 +#define TGSI_OPCODE_FLOOR               26 +#define TGSI_OPCODE_ROUND               27 +#define TGSI_OPCODE_EXPBASE2            28 +#define TGSI_OPCODE_LOGBASE2            29 +#define TGSI_OPCODE_POWER               30 +#define TGSI_OPCODE_RECIP               TGSI_OPCODE_RCP +#define TGSI_OPCODE_RECIPSQRT           TGSI_OPCODE_RSQ +#define TGSI_OPCODE_CROSSPRODUCT        31 +#define TGSI_OPCODE_MULTIPLYMATRIX      32 + +/* + * GL_NV_vertex_program1_1 + */ +#define TGSI_OPCODE_ABS                 33 +#define TGSI_OPCODE_RCC                 34 +#define TGSI_OPCODE_DPH                 35 + +/* + * GL_NV_fragment_program + */ +#define TGSI_OPCODE_COS                 36 +#define TGSI_OPCODE_DDX                 37 +#define TGSI_OPCODE_DDY                 38 +#define TGSI_OPCODE_EX2                 TGSI_OPCODE_EXPBASE2 +#define TGSI_OPCODE_FLR                 TGSI_OPCODE_FLOOR +#define TGSI_OPCODE_FRC                 TGSI_OPCODE_FRAC +#define TGSI_OPCODE_KILP                39  /* predicated kill */ +#define TGSI_OPCODE_LG2                 TGSI_OPCODE_LOGBASE2 +#define TGSI_OPCODE_LRP                 TGSI_OPCODE_LERP +#define TGSI_OPCODE_PK2H                40 +#define TGSI_OPCODE_PK2US               41 +#define TGSI_OPCODE_PK4B                42 +#define TGSI_OPCODE_PK4UB               43 +#define TGSI_OPCODE_POW                 TGSI_OPCODE_POWER +#define TGSI_OPCODE_RFL                 44 +#define TGSI_OPCODE_SEQ                 45 +#define TGSI_OPCODE_SFL                 46 +#define TGSI_OPCODE_SGT                 47 +#define TGSI_OPCODE_SIN                 48 +#define TGSI_OPCODE_SLE                 49 +#define TGSI_OPCODE_SNE                 50 +#define TGSI_OPCODE_STR                 51 +#define TGSI_OPCODE_TEX                 52 +#define TGSI_OPCODE_TXD                 53 +#define TGSI_OPCODE_TXP                 54 +#define TGSI_OPCODE_UP2H                55 +#define TGSI_OPCODE_UP2US               56 +#define TGSI_OPCODE_UP4B                57 +#define TGSI_OPCODE_UP4UB               58 +#define TGSI_OPCODE_X2D                 59 + +/* + * GL_NV_vertex_program2 + */ +#define TGSI_OPCODE_ARA                 60 +#define TGSI_OPCODE_ARR                 61 +#define TGSI_OPCODE_BRA                 62 +#define TGSI_OPCODE_CAL                 63 +#define TGSI_OPCODE_RET                 64 +#define TGSI_OPCODE_SSG                 65 + +/* + * GL_ARB_vertex_program + */ +#define TGSI_OPCODE_SWZ                 118 +#define TGSI_OPCODE_XPD                 TGSI_OPCODE_CROSSPRODUCT + +/* + * GL_ARB_fragment_program + */ +#define TGSI_OPCODE_CMP                 66 +#define TGSI_OPCODE_KIL                 116  /* conditional kill */ +#define TGSI_OPCODE_SCS                 67 +#define TGSI_OPCODE_TXB                 68 + +/* + * GL_NV_fragment_program_option + */ +/* No new opcode */ + +/* + * GL_NV_fragment_program2 + */ +#define TGSI_OPCODE_NRM                 69 +#define TGSI_OPCODE_DIV                 70 +#define TGSI_OPCODE_DP2                 71 +#define TGSI_OPCODE_DP2A                TGSI_OPCODE_DOT2ADD +#define TGSI_OPCODE_TXL                 72 +#define TGSI_OPCODE_BRK                 73 +#define TGSI_OPCODE_IF                  74 +#define TGSI_OPCODE_LOOP                75 +#define TGSI_OPCODE_REP                 76 +#define TGSI_OPCODE_ELSE                77 +#define TGSI_OPCODE_ENDIF               78 +#define TGSI_OPCODE_ENDLOOP             79 +#define TGSI_OPCODE_ENDREP              80 + +/* + * GL_NV_vertex_program2_option + */ + +/* + * GL_NV_vertex_program3 + */ +#define TGSI_OPCODE_PUSHA               81 +#define TGSI_OPCODE_POPA                82 + +/* + * GL_NV_gpu_program4 + */ +#define TGSI_OPCODE_CEIL                83 +#define TGSI_OPCODE_I2F                 84 +#define TGSI_OPCODE_NOT                 85 +#define TGSI_OPCODE_TRUNC               86 +#define TGSI_OPCODE_SHL                 87 +#define TGSI_OPCODE_SHR                 88 +#define TGSI_OPCODE_AND                 89 +#define TGSI_OPCODE_OR                  90 +#define TGSI_OPCODE_MOD                 91 +#define TGSI_OPCODE_XOR                 92 +#define TGSI_OPCODE_SAD                 93 +#define TGSI_OPCODE_TXF                 94 +#define TGSI_OPCODE_TXQ                 95 +#define TGSI_OPCODE_CONT                96 + +/* + * GL_NV_vertex_program4 + */ +/* Same as GL_NV_gpu_program4 */ + +/* + * GL_NV_fragment_program4 + */ +/* Same as GL_NV_gpu_program4 */ + +/* + * GL_NV_geometry_program4 + */ +/* Same as GL_NV_gpu_program4 */ +#define TGSI_OPCODE_EMIT                97 +#define TGSI_OPCODE_ENDPRIM             98 + +/* + * GLSL + */ +#define TGSI_OPCODE_BGNLOOP2            99 +#define TGSI_OPCODE_BGNSUB              100 +#define TGSI_OPCODE_ENDLOOP2            101 +#define TGSI_OPCODE_ENDSUB              102 +#define TGSI_OPCODE_INT                 TGSI_OPCODE_TRUNC +#define TGSI_OPCODE_NOISE1              103 +#define TGSI_OPCODE_NOISE2              104 +#define TGSI_OPCODE_NOISE3              105 +#define TGSI_OPCODE_NOISE4              106 +#define TGSI_OPCODE_NOP                 107 + +/* + * ps_1_1 + */ +#define TGSI_OPCODE_TEXKILL             TGSI_OPCODE_KIL + +/* + * ps_1_2 + */ +/* CMP - use TGSI_OPCODE_CND0 */ + +/* + * ps_1_3 + */ +/* CMP - use TGSI_OPCODE_CND0 */ + +/* + * ps_1_4 + */ +#define TGSI_OPCODE_TEXLD               TGSI_OPCODE_TEX + +/* + * ps_2_0 + */ +#define TGSI_OPCODE_M4X4                TGSI_OPCODE_MULTIPLYMATRIX +#define TGSI_OPCODE_M4X3                108 +#define TGSI_OPCODE_M3X4                109 +#define TGSI_OPCODE_M3X3                110 +#define TGSI_OPCODE_M3X2                111 +#define TGSI_OPCODE_CRS                 TGSI_OPCODE_XPD +#define TGSI_OPCODE_NRM4                112 +#define TGSI_OPCODE_SINCOS              TGSI_OPCODE_SCS +#define TGSI_OPCODE_TEXLDB              TGSI_OPCODE_TXB +#define TGSI_OPCODE_DP2ADD              TGSI_OPCODE_DP2A + +/* + * ps_2_x + */ +#define TGSI_OPCODE_CALL                TGSI_OPCODE_CAL +#define TGSI_OPCODE_CALLNZ              113 +#define TGSI_OPCODE_IFC                 114 +#define TGSI_OPCODE_BREAK               TGSI_OPCODE_BRK +#define TGSI_OPCODE_BREAKC              115 +#define TGSI_OPCODE_DSX                 TGSI_OPCODE_DDX +#define TGSI_OPCODE_DSY                 TGSI_OPCODE_DDY +#define TGSI_OPCODE_TEXLDD              TGSI_OPCODE_TXD + +/* + * vs_1_1 + */ +#define TGSI_OPCODE_EXPP                TGSI_OPCODE_EXP +#define TGSI_OPCODE_LOGP                TGSI_OPCODE_LG2 + +/* + * vs_2_0 + */ +#define TGSI_OPCODE_SGN                 TGSI_OPCODE_SSG +#define TGSI_OPCODE_MOVA                TGSI_OPCODE_ARR +/* EXPP - use TGSI_OPCODE_EX2 */ + +/* + * vs_2_x + */ + +#define TGSI_OPCODE_END                 117  /* aka HALT */ + +#define TGSI_OPCODE_LAST                119 + +#define TGSI_SAT_NONE            0  /* do not saturate */ +#define TGSI_SAT_ZERO_ONE        1  /* clamp to [0,1] */ +#define TGSI_SAT_MINUS_PLUS_ONE  2  /* clamp to [-1,1] */ + +/** + * Opcode is the operation code to execute. A given operation defines the + * semantics how the source registers (if any) are interpreted and what is + * written to the destination registers (if any) as a result of execution. + * + * NumDstRegs and NumSrcRegs is the number of destination and source registers, + * respectively. For a given operation code, those numbers are fixed and are + * present here only for convenience. + * + * If Extended is TRUE, it is now executed. + * + * Saturate controls how are final results in destination registers modified. + */ + +struct tgsi_instruction +{ +   unsigned Type       : 4;  /* TGSI_TOKEN_TYPE_INSTRUCTION */ +   unsigned Size       : 8;  /* UINT */ +   unsigned Opcode     : 8;  /* TGSI_OPCODE_ */ +   unsigned Saturate   : 2;  /* TGSI_SAT_ */ +   unsigned NumDstRegs : 2;  /* UINT */ +   unsigned NumSrcRegs : 4;  /* UINT */ +   unsigned Padding    : 3; +   unsigned Extended   : 1;  /* BOOL */ +}; + +/* + * If tgsi_instruction::Extended is TRUE, tgsi_instruction_ext follows. + *  + * Then, tgsi_instruction::NumDstRegs of tgsi_dst_register follow. + *  + * Then, tgsi_instruction::NumSrcRegs of tgsi_src_register follow. + * + * tgsi_instruction::Size contains the total number of words that make the + * instruction, including the instruction word. + */ + +#define TGSI_INSTRUCTION_EXT_TYPE_NV        0 +#define TGSI_INSTRUCTION_EXT_TYPE_LABEL     1 +#define TGSI_INSTRUCTION_EXT_TYPE_TEXTURE   2 +#define TGSI_INSTRUCTION_EXT_TYPE_PREDICATE 3 + +struct tgsi_instruction_ext +{ +   unsigned Type       : 4;  /* TGSI_INSTRUCTION_EXT_TYPE_ */ +   unsigned Padding    : 27; +   unsigned Extended   : 1;  /* BOOL */ +}; + +/* + * If tgsi_instruction_ext::Type is TGSI_INSTRUCTION_EXT_TYPE_NV, it should + * be cast to tgsi_instruction_ext_nv. + *  + * If tgsi_instruction_ext::Type is TGSI_INSTRUCTION_EXT_TYPE_LABEL, it + * should be cast to tgsi_instruction_ext_label. + *  + * If tgsi_instruction_ext::Type is TGSI_INSTRUCTION_EXT_TYPE_TEXTURE, it + * should be cast to tgsi_instruction_ext_texture. + *  + * If tgsi_instruction_ext::Type is TGSI_INSTRUCTION_EXT_TYPE_PREDICATE, it + * should be cast to tgsi_instruction_ext_predicate. + *  + * If tgsi_instruction_ext::Extended is TRUE, another tgsi_instruction_ext + * follows. + */ + +#define TGSI_PRECISION_DEFAULT      0 +#define TGSI_PRECISION_FLOAT32      1 +#define TGSI_PRECISION_FLOAT16      2 +#define TGSI_PRECISION_FIXED12      3 + +#define TGSI_CC_GT      0 +#define TGSI_CC_EQ      1 +#define TGSI_CC_LT      2 +#define TGSI_CC_GE      3 +#define TGSI_CC_LE      4 +#define TGSI_CC_NE      5 +#define TGSI_CC_TR      6 +#define TGSI_CC_FL      7 + +#define TGSI_SWIZZLE_X      0 +#define TGSI_SWIZZLE_Y      1 +#define TGSI_SWIZZLE_Z      2 +#define TGSI_SWIZZLE_W      3 + +/** + * Precision controls the precision at which the operation should be executed. + * + * CondDstUpdate enables condition code register writes. When this field is + * TRUE, CondDstIndex specifies the index of the condition code register to + * update. + * + * CondFlowEnable enables conditional execution of the operation. When this + * field is TRUE, CondFlowIndex specifies the index of the condition code + * register to test against CondMask with component swizzle controled by + * CondSwizzleX, CondSwizzleY, CondSwizzleZ and CondSwizzleW. If the test fails, + * the operation is not executed. + */ + +struct tgsi_instruction_ext_nv +{ +   unsigned Type             : 4;    /* TGSI_INSTRUCTION_EXT_TYPE_NV */ +   unsigned Precision        : 4;    /* TGSI_PRECISION_ */ +   unsigned CondDstIndex     : 4;    /* UINT */ +   unsigned CondFlowIndex    : 4;    /* UINT */ +   unsigned CondMask         : 4;    /* TGSI_CC_ */ +   unsigned CondSwizzleX     : 2;    /* TGSI_SWIZZLE_ */ +   unsigned CondSwizzleY     : 2;    /* TGSI_SWIZZLE_ */ +   unsigned CondSwizzleZ     : 2;    /* TGSI_SWIZZLE_ */ +   unsigned CondSwizzleW     : 2;    /* TGSI_SWIZZLE_ */ +   unsigned CondDstUpdate    : 1;    /* BOOL */ +   unsigned CondFlowEnable   : 1;    /* BOOL */ +   unsigned Padding          : 1; +   unsigned Extended         : 1;    /* BOOL */ +}; + +struct tgsi_instruction_ext_label +{ +   unsigned Type     : 4;    /* TGSI_INSTRUCTION_EXT_TYPE_LABEL */ +   unsigned Label    : 24;   /* UINT */ +   unsigned Padding  : 3; +   unsigned Extended : 1;    /* BOOL */ +}; + +#define TGSI_TEXTURE_UNKNOWN        0 +#define TGSI_TEXTURE_1D             1 +#define TGSI_TEXTURE_2D             2 +#define TGSI_TEXTURE_3D             3 +#define TGSI_TEXTURE_CUBE           4 +#define TGSI_TEXTURE_RECT           5 +#define TGSI_TEXTURE_SHADOW1D       6 +#define TGSI_TEXTURE_SHADOW2D       7 +#define TGSI_TEXTURE_SHADOWRECT     8 +#define TGSI_TEXTURE_COUNT          9 + +struct tgsi_instruction_ext_texture +{ +   unsigned Type     : 4;    /* TGSI_INSTRUCTION_EXT_TYPE_TEXTURE */ +   unsigned Texture  : 8;    /* TGSI_TEXTURE_ */ +   unsigned Padding  : 19; +   unsigned Extended : 1;    /* BOOL */ +}; + +struct tgsi_instruction_ext_predicate +{ +   unsigned Type             : 4;    /* TGSI_INSTRUCTION_EXT_TYPE_PREDICATE */ +   unsigned PredDstIndex     : 4;    /* UINT */ +   unsigned PredWriteMask    : 4;    /* TGSI_WRITEMASK_ */ +   unsigned Padding          : 19; +   unsigned Extended         : 1;    /* BOOL */ +}; + +/** + * File specifies the register array to access. + * + * Index specifies the element number of a register in the register file. + * + * If Indirect is TRUE, Index should be offset by the X component of a source + * register that follows. The register can be now fetched into local storage + * for further processing. + * + * If Negate is TRUE, all components of the fetched register are negated. + * + * The fetched register components are swizzled according to SwizzleX, SwizzleY, + * SwizzleZ and SwizzleW. + * + * If Extended is TRUE, any further modifications to the source register are + * made to this temporary storage. + */ + +struct tgsi_src_register +{ +   unsigned File        : 4;  /* TGSI_FILE_ */ +   unsigned SwizzleX    : 2;  /* TGSI_SWIZZLE_ */ +   unsigned SwizzleY    : 2;  /* TGSI_SWIZZLE_ */ +   unsigned SwizzleZ    : 2;  /* TGSI_SWIZZLE_ */ +   unsigned SwizzleW    : 2;  /* TGSI_SWIZZLE_ */ +   unsigned Negate      : 1;  /* BOOL */ +   unsigned Indirect    : 1;  /* BOOL */ +   unsigned Dimension   : 1;  /* BOOL */ +   int      Index       : 16; /* SINT */ +   unsigned Extended    : 1;  /* BOOL */ +}; + +/** + * If tgsi_src_register::Extended is TRUE, tgsi_src_register_ext follows. + *  + * Then, if tgsi_src_register::Indirect is TRUE, another tgsi_src_register + * follows. + * + * Then, if tgsi_src_register::Dimension is TRUE, tgsi_dimension follows. + */ + +#define TGSI_SRC_REGISTER_EXT_TYPE_SWZ      0 +#define TGSI_SRC_REGISTER_EXT_TYPE_MOD      1 + +struct tgsi_src_register_ext +{ +   unsigned Type     : 4;    /* TGSI_SRC_REGISTER_EXT_TYPE_ */ +   unsigned Padding  : 27; +   unsigned Extended : 1;    /* BOOL */ +}; + +/** + * If tgsi_src_register_ext::Type is TGSI_SRC_REGISTER_EXT_TYPE_SWZ, + * it should be cast to tgsi_src_register_ext_swz. + *  + * If tgsi_src_register_ext::Type is TGSI_SRC_REGISTER_EXT_TYPE_MOD, + * it should be cast to tgsi_src_register_ext_mod. + *  + * If tgsi_dst_register_ext::Extended is TRUE, another tgsi_dst_register_ext + * follows. + */ + +#define TGSI_EXTSWIZZLE_X       TGSI_SWIZZLE_X +#define TGSI_EXTSWIZZLE_Y       TGSI_SWIZZLE_Y +#define TGSI_EXTSWIZZLE_Z       TGSI_SWIZZLE_Z +#define TGSI_EXTSWIZZLE_W       TGSI_SWIZZLE_W +#define TGSI_EXTSWIZZLE_ZERO    4 +#define TGSI_EXTSWIZZLE_ONE     5 + +/** + * ExtSwizzleX, ExtSwizzleY, ExtSwizzleZ and ExtSwizzleW swizzle the source + * register in an extended manner. + * + * NegateX, NegateY, NegateZ and NegateW negate individual components of the + * source register. + * + * NOTE: To simplify matter, if this token is present, the corresponding Swizzle + *       and Negate fields in tgsi_src_register should be set to X,Y,Z,W + *       and FALSE, respectively. + */ + +struct tgsi_src_register_ext_swz +{ +   unsigned Type         : 4;    /* TGSI_SRC_REGISTER_EXT_TYPE_SWZ */ +   unsigned ExtSwizzleX  : 4;    /* TGSI_EXTSWIZZLE_ */ +   unsigned ExtSwizzleY  : 4;    /* TGSI_EXTSWIZZLE_ */ +   unsigned ExtSwizzleZ  : 4;    /* TGSI_EXTSWIZZLE_ */ +   unsigned ExtSwizzleW  : 4;    /* TGSI_EXTSWIZZLE_ */ +   unsigned NegateX      : 1;    /* BOOL */ +   unsigned NegateY      : 1;    /* BOOL */ +   unsigned NegateZ      : 1;    /* BOOL */ +   unsigned NegateW      : 1;    /* BOOL */ +   unsigned Padding      : 7; +   unsigned Extended     : 1;    /* BOOL */ +}; + +/** + * Extra src register modifiers + * + * If Complement is TRUE, the source register is modified by subtracting it + * from 1.0. + * + * If Bias is TRUE, the source register is modified by subtracting 0.5 from it. + * + * If Scale2X is TRUE, the source register is modified by multiplying it by 2.0. + * + * If Absolute is TRUE, the source register is modified by removing the sign. + * + * If Negate is TRUE, the source register is modified by negating it. + */ + +struct tgsi_src_register_ext_mod +{ +   unsigned Type         : 4;    /* TGSI_SRC_REGISTER_EXT_TYPE_MOD */ +   unsigned Complement   : 1;    /* BOOL */ +   unsigned Bias         : 1;    /* BOOL */ +   unsigned Scale2X      : 1;    /* BOOL */ +   unsigned Absolute     : 1;    /* BOOL */ +   unsigned Negate       : 1;    /* BOOL */ +   unsigned Padding      : 22; +   unsigned Extended     : 1;    /* BOOL */ +}; + +struct tgsi_dimension +{ +   unsigned Indirect    : 1;  /* BOOL */ +   unsigned Dimension   : 1;  /* BOOL */ +   unsigned Padding     : 13; +   int      Index       : 16; /* SINT */ +   unsigned Extended    : 1;  /* BOOL */ +}; + +struct tgsi_dst_register +{ +   unsigned File        : 4;  /* TGSI_FILE_ */ +   unsigned WriteMask   : 4;  /* TGSI_WRITEMASK_ */ +   unsigned Indirect    : 1;  /* BOOL */ +   unsigned Dimension   : 1;  /* BOOL */ +   int      Index       : 16; /* SINT */ +   unsigned Padding     : 5; +   unsigned Extended    : 1;  /* BOOL */ +}; + +/* + * If tgsi_dst_register::Extended is TRUE, tgsi_dst_register_ext follows. + *  + * Then, if tgsi_dst_register::Indirect is TRUE, tgsi_src_register follows. + */ + +#define TGSI_DST_REGISTER_EXT_TYPE_CONDCODE     0 +#define TGSI_DST_REGISTER_EXT_TYPE_MODULATE     1 +#define TGSI_DST_REGISTER_EXT_TYPE_PREDICATE    2 + +struct tgsi_dst_register_ext +{ +   unsigned Type     : 4;    /* TGSI_DST_REGISTER_EXT_TYPE_ */ +   unsigned Padding  : 27; +   unsigned Extended : 1;    /* BOOL */ +}; + +/** + * Extra destination register modifiers + * + * If tgsi_dst_register_ext::Type is TGSI_DST_REGISTER_EXT_TYPE_CONDCODE, + * it should be cast to tgsi_dst_register_ext_condcode. + *  + * If tgsi_dst_register_ext::Type is TGSI_DST_REGISTER_EXT_TYPE_MODULATE, + * it should be cast to tgsi_dst_register_ext_modulate. + *  + * If tgsi_dst_register_ext::Type is TGSI_DST_REGISTER_EXT_TYPE_PREDICATE, + * it should be cast to tgsi_dst_register_ext_predicate. + *  + * If tgsi_dst_register_ext::Extended is TRUE, another tgsi_dst_register_ext + * follows. + */ +struct tgsi_dst_register_ext_concode +{ +   unsigned Type         : 4;    /* TGSI_DST_REGISTER_EXT_TYPE_CONDCODE */ +   unsigned CondMask     : 4;    /* TGSI_CC_ */ +   unsigned CondSwizzleX : 2;    /* TGSI_SWIZZLE_ */ +   unsigned CondSwizzleY : 2;    /* TGSI_SWIZZLE_ */ +   unsigned CondSwizzleZ : 2;    /* TGSI_SWIZZLE_ */ +   unsigned CondSwizzleW : 2;    /* TGSI_SWIZZLE_ */ +   unsigned CondSrcIndex : 4;    /* UINT */ +   unsigned Padding      : 11; +   unsigned Extended     : 1;    /* BOOL */ +}; + +#define TGSI_MODULATE_1X        0 +#define TGSI_MODULATE_2X        1 +#define TGSI_MODULATE_4X        2 +#define TGSI_MODULATE_8X        3 +#define TGSI_MODULATE_HALF      4 +#define TGSI_MODULATE_QUARTER   5 +#define TGSI_MODULATE_EIGHTH    6 +#define TGSI_MODULATE_COUNT     7 + +struct tgsi_dst_register_ext_modulate +{ +   unsigned Type     : 4;    /* TGSI_DST_REGISTER_EXT_TYPE_MODULATE */ +   unsigned Modulate : 4;    /* TGSI_MODULATE_ */ +   unsigned Padding  : 23; +   unsigned Extended : 1;    /* BOOL */ +}; + +/* + * Currently, the following constraints apply. + * + * - PredSwizzleXYZW is either set to identity or replicate. + * - PredSrcIndex is 0. + */ + +struct tgsi_dst_register_ext_predicate +{ +   unsigned Type         : 4;    /* TGSI_DST_REGISTER_EXT_TYPE_PREDICATE */ +   unsigned PredSwizzleX : 2;    /* TGSI_SWIZZLE_ */ +   unsigned PredSwizzleY : 2;    /* TGSI_SWIZZLE_ */ +   unsigned PredSwizzleZ : 2;    /* TGSI_SWIZZLE_ */ +   unsigned PredSwizzleW : 2;    /* TGSI_SWIZZLE_ */ +   unsigned PredSrcIndex : 4;    /* UINT */ +   unsigned Negate       : 1;    /* BOOL */ +   unsigned Padding      : 14; +   unsigned Extended     : 1;    /* BOOL */ +}; + + +#ifdef __cplusplus +} +#endif + +#endif /* TGSI_TOKEN_H */ + diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h new file mode 100644 index 0000000000..342f17260a --- /dev/null +++ b/src/gallium/include/pipe/p_state.h @@ -0,0 +1,368 @@ +/************************************************************************** + *  + * 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. + *  + **************************************************************************/ + + +/** + * @file + *  + * Abstract graphics pipe state objects. + * + * Basic notes: + *   1. Want compact representations, so we use bitfields. + *   2. Put bitfields before other (GLfloat) fields. + */ + + +#ifndef PIPE_STATE_H +#define PIPE_STATE_H + +#include "p_compiler.h" +#include "p_defines.h" +#include "p_format.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * Implementation limits + */ +#define PIPE_MAX_ATTRIBS          32 +#define PIPE_MAX_CLIP_PLANES       6 +#define PIPE_MAX_COLOR_BUFS        8 +#define PIPE_MAX_CONSTANT         32 +#define PIPE_MAX_SAMPLERS         16 +#define PIPE_MAX_SHADER_INPUTS    16 +#define PIPE_MAX_SHADER_OUTPUTS   16 +#define PIPE_MAX_TEXTURE_LEVELS   16 + + +/* fwd decls */ +struct pipe_screen; +struct pipe_surface; +struct pipe_winsys; + + + +/** + * The driver will certainly subclass this to include actual memory + * management information. + */ +struct pipe_buffer +{ +   unsigned alignment; +   unsigned usage; +   unsigned size; + +   /** Reference count */ +   unsigned refcount; +}; + + +/** + * Primitive (point/line/tri) rasterization info + */ +struct pipe_rasterizer_state +{ +   unsigned flatshade:1; +   unsigned light_twoside:1; +   unsigned front_winding:2;  /**< PIPE_WINDING_x */ +   unsigned cull_mode:2;      /**< PIPE_WINDING_x */ +   unsigned fill_cw:2;        /**< PIPE_POLYGON_MODE_x */ +   unsigned fill_ccw:2;       /**< PIPE_POLYGON_MODE_x */ +   unsigned offset_cw:1; +   unsigned offset_ccw:1; +   unsigned scissor:1; +   unsigned poly_smooth:1; +   unsigned poly_stipple_enable:1; +   unsigned point_smooth:1; +   unsigned point_sprite:1; +   unsigned point_size_per_vertex:1; /**< size computed in vertex shader */ +   unsigned multisample:1;         /* XXX maybe more ms state in future */ +   unsigned line_smooth:1; +   unsigned line_stipple_enable:1; +   unsigned line_stipple_factor:8;  /**< [1..256] actually */ +   unsigned line_stipple_pattern:16; +   unsigned line_last_pixel:1; +   unsigned bypass_clipping:1; +   unsigned bypass_vs:1; /**< Skip the vertex shader.  Note that the shader is +                            still needed though, to indicate inputs/outputs */ +   unsigned origin_lower_left:1;  /**< Is (0,0) the lower-left corner? */ +   unsigned flatshade_first:1;   /**< take color attribute from the first vertex of a primitive */ +   unsigned gl_rasterization_rules:1; /**< enable tweaks for GL rasterization?  */ + +   float line_width; +   float point_size;           /**< used when no per-vertex size */ +   float point_size_min;        /* XXX - temporary, will go away */ +   float point_size_max;        /* XXX - temporary, will go away */ +   float offset_units; +   float offset_scale; +   ubyte sprite_coord_mode[PIPE_MAX_SHADER_OUTPUTS]; /**< PIPE_SPRITE_COORD_ */ +}; + + +struct pipe_poly_stipple +{ +   unsigned stipple[32]; +}; + + +struct pipe_viewport_state +{ +   float scale[4]; +   float translate[4]; +}; + + +struct pipe_scissor_state +{ +   unsigned minx:16; +   unsigned miny:16; +   unsigned maxx:16; +   unsigned maxy:16; +}; + + +struct pipe_clip_state +{ +   float ucp[PIPE_MAX_CLIP_PLANES][4]; +   unsigned nr; +}; + + +/** + * Constants for vertex/fragment shaders + */ +struct pipe_constant_buffer +{ +   struct pipe_buffer *buffer; +   unsigned size;    /** in bytes (XXX: redundant!) */ +}; + + +struct pipe_shader_state +{ +   const struct tgsi_token *tokens; +}; + + +struct pipe_depth_state { +   unsigned enabled:1;         /**< depth test enabled? */ +   unsigned writemask:1;       /**< allow depth buffer writes? */ +   unsigned func:3;            /**< depth test func (PIPE_FUNC_x) */ +   unsigned occlusion_count:1; /**< do occlusion counting? */ +}; + + +struct pipe_stencil_state { +   unsigned enabled:1;  /**< stencil[0]: stencil enabled, stencil[1]: two-side enabled */ +   unsigned func:3;     /**< PIPE_FUNC_x */ +   unsigned fail_op:3;  /**< PIPE_STENCIL_OP_x */ +   unsigned zpass_op:3; /**< PIPE_STENCIL_OP_x */ +   unsigned zfail_op:3; /**< PIPE_STENCIL_OP_x */ +   ubyte ref_value;     +   ubyte value_mask; +   ubyte write_mask; +}; + + +struct pipe_alpha_state { +   unsigned enabled:1; +   unsigned func:3;     /**< PIPE_FUNC_x */ +   float ref;           /**< reference value */ +}; + + +struct pipe_depth_stencil_alpha_state +{ +   struct pipe_depth_state depth; +   struct pipe_stencil_state stencil[2]; /**< [0] = front, [1] = back */ +   struct pipe_alpha_state alpha; +}; + + +struct pipe_blend_state +{ +   unsigned blend_enable:1; + +   unsigned rgb_func:3;          /**< PIPE_BLEND_x */ +   unsigned rgb_src_factor:5;    /**< PIPE_BLENDFACTOR_x */ +   unsigned rgb_dst_factor:5;    /**< PIPE_BLENDFACTOR_x */ + +   unsigned alpha_func:3;        /**< PIPE_BLEND_x */ +   unsigned alpha_src_factor:5;  /**< PIPE_BLENDFACTOR_x */ +   unsigned alpha_dst_factor:5;  /**< PIPE_BLENDFACTOR_x */ + +   unsigned logicop_enable:1; +   unsigned logicop_func:4;      /**< PIPE_LOGICOP_x */ + +   unsigned colormask:4;         /**< bitmask of PIPE_MASK_R/G/B/A */ +   unsigned dither:1; +}; + + +struct pipe_blend_color +{ +   float color[4]; +}; + + +struct pipe_framebuffer_state +{ +   unsigned width, height; + +   /** multiple colorbuffers for multiple render targets */ +   unsigned num_cbufs; +   struct pipe_surface *cbufs[PIPE_MAX_COLOR_BUFS]; + +   struct pipe_surface *zsbuf;      /**< Z/stencil buffer */ +}; + + +/** + * Texture sampler 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 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_mode:1;      /**< PIPE_TEX_COMPARE_x */ +   unsigned compare_func:3;      /**< PIPE_FUNC_x */ +   unsigned normalized_coords:1; /**< Are coords normalized to [0,1]? */ +   unsigned prefilter:4;         /**< Wierd sampling state exposed by some api's */ +   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; +}; + + +/** + * 2D surface.  This is basically a view into a memory buffer. + * May be a renderbuffer, texture mipmap level, etc. + */ +struct pipe_surface +{ +   struct pipe_buffer *buffer;   /**< surface's buffer/memory */ +   enum pipe_format format;      /**< PIPE_FORMAT_x */ +   unsigned status;              /**< PIPE_SURFACE_STATUS_x */ +   unsigned clear_value;         /**< XXX may be temporary */ +   unsigned width;               /**< logical width in pixels */ +   unsigned height;              /**< logical height in pixels */ +   struct pipe_format_block block; +   unsigned nblocksx;            /**< allocated width in blocks */ +   unsigned nblocksy;            /**< allocated height in blocks */ +   unsigned stride;              /**< stride in bytes between rows of blocks */ +   unsigned layout;              /**< PIPE_SURFACE_LAYOUT_x */ +   unsigned offset;              /**< offset from start of buffer, in bytes */ +   unsigned refcount; +   unsigned usage;               /**< PIPE_BUFFER_USAGE_*  */ + +   struct pipe_winsys *winsys;   /**< winsys which owns/created the surface */ + +   struct pipe_texture *texture; /**< optional texture into which this is a view  */ +   unsigned face; +   unsigned level; +   unsigned zslice; +}; + + +/** + * Texture object. + */ +struct pipe_texture +{  +   enum pipe_texture_target target; /**< PIPE_TEXTURE_x */ +   enum pipe_format format;         /**< PIPE_FORMAT_x */ + +   unsigned width[PIPE_MAX_TEXTURE_LEVELS]; +   unsigned height[PIPE_MAX_TEXTURE_LEVELS]; +   unsigned depth[PIPE_MAX_TEXTURE_LEVELS]; + +   struct pipe_format_block block; +   unsigned nblocksx[PIPE_MAX_TEXTURE_LEVELS]; /**< allocated width in blocks */ +   unsigned nblocksy[PIPE_MAX_TEXTURE_LEVELS]; /**< allocated height in blocks */ + +   unsigned last_level:8;    /**< Index of last mipmap level present/defined */ +   unsigned compressed:1; + +   unsigned nr_samples:8;          /**< for multisampled surfaces, nr of samples */ + +   unsigned tex_usage;          /* PIPE_TEXTURE_USAGE_* */ + +   /* These are also refcounted: +    */ +   unsigned refcount; + +   struct pipe_screen *screen; /**< screen that this texture belongs to */ +}; + + +/** + * A vertex buffer.  Typically, all the vertex data/attributes for + * drawing something will be in one buffer.  But it's also possible, for + * example, to put colors in one buffer and texcoords in another. + */ +struct pipe_vertex_buffer +{ +   unsigned pitch;    /**< stride to same attrib in next vertex, in bytes */ +   unsigned max_index;   /**< number of vertices in this buffer */ +   unsigned buffer_offset;  /**< offset to start of data in buffer, in bytes */ +   struct pipe_buffer *buffer;  /**< the actual buffer */ +}; + + +/** + * Information to describe a vertex attribute (position, color, etc) + */ +struct pipe_vertex_element +{ +   /** Offset of this attribute, in bytes, from the start of the vertex */ +   unsigned src_offset; + +   /** Which vertex_buffer (as given to pipe->set_vertex_buffer()) does +    * this attribute live in? +    */ +   unsigned vertex_buffer_index:8; +   unsigned nr_components:8; +  +   enum pipe_format src_format; 	   /**< PIPE_FORMAT_* */ +}; + + +#ifdef __cplusplus +} +#endif +    +#endif diff --git a/src/gallium/include/pipe/p_thread.h b/src/gallium/include/pipe/p_thread.h new file mode 100644 index 0000000000..8af3cd958b --- /dev/null +++ b/src/gallium/include/pipe/p_thread.h @@ -0,0 +1,276 @@ +/************************************************************************** + *  + * 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, 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. + *  + **************************************************************************/ + + +/** + * @file + *  + * Thread, mutex, condition var and thread-specific data functions. + */ + + +#ifndef _P_THREAD2_H_ +#define _P_THREAD2_H_ + + +#include "pipe/p_compiler.h" + + +#if defined(PIPE_OS_LINUX) + +#include <pthread.h> /* POSIX threads headers */ +#include <stdio.h> /* for perror() */ + +typedef pthread_t pipe_thread; + +#define PIPE_THREAD_ROUTINE( name, param ) \ +   void *name( void *param ) + +static INLINE pipe_thread pipe_thread_create( void *(* routine)( void *), void *param ) +{ +   pipe_thread thread; +   if (pthread_create( &thread, NULL, routine, param )) +      return 0; +   return thread; +} + +static INLINE int pipe_thread_wait( pipe_thread thread ) +{ +   return pthread_join( thread, NULL ); +} + +static INLINE int pipe_thread_destroy( pipe_thread thread ) +{ +   return pthread_detach( thread ); +} + +typedef pthread_mutex_t pipe_mutex; +typedef pthread_cond_t pipe_condvar; + +#define pipe_static_mutex(mutex) \ +   static pipe_mutex mutex = PTHREAD_MUTEX_INITIALIZER + +#define pipe_mutex_init(mutex) \ +   pthread_mutex_init(&(mutex), NULL) + +#define pipe_mutex_destroy(mutex) \ +   pthread_mutex_destroy(&(mutex)) + +#define pipe_mutex_lock(mutex) \ +   (void) pthread_mutex_lock(&(mutex)) + +#define pipe_mutex_unlock(mutex) \ +   (void) pthread_mutex_unlock(&(mutex)) + +#define pipe_static_condvar(mutex) \ +   static pipe_condvar mutex = PTHREAD_COND_INITIALIZER + +#define pipe_condvar_init(cond)	\ +   pthread_cond_init(&(cond), NULL) + +#define pipe_condvar_destroy(cond) \ +   pthread_cond_destroy(&(cond)) + +#define pipe_condvar_wait(cond, mutex) \ +  pthread_cond_wait(&(cond), &(mutex)) + +#define pipe_condvar_signal(cond) \ +  pthread_cond_signal(&(cond)) + +#define pipe_condvar_broadcast(cond) \ +  pthread_cond_broadcast(&(cond)) + + +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) + +#include <windows.h> + +typedef HANDLE pipe_thread; + +#define PIPE_THREAD_ROUTINE( name, param ) \ +   void * WINAPI name( void *param ) + +static INLINE pipe_thread pipe_thread_create( void *(WINAPI * routine)( void *), void *param ) +{ +   DWORD id; +   return CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE) routine, param, 0, &id ); +} + +static INLINE int pipe_thread_wait( pipe_thread thread ) +{ +   if (WaitForSingleObject( thread, INFINITE ) == WAIT_OBJECT_0) +      return 0; +   return -1; +} + +static INLINE int pipe_thread_destroy( pipe_thread thread ) +{ +   if (CloseHandle( thread )) +      return 0; +   return -1; +} + +typedef CRITICAL_SECTION pipe_mutex; + +#define pipe_static_mutex(name) \ +   /*static*/ pipe_mutex name = {0,0,0,0,0,0} + +#define pipe_mutex_init(name) \ +   InitializeCriticalSection(&name) + +#define pipe_mutex_destroy(name) \ +   DeleteCriticalSection(&name) + +#define pipe_mutex_lock(name) \ +   EnterCriticalSection(&name) + +#define pipe_mutex_unlock(name) \ +   LeaveCriticalSection(&name) + +/* XXX: dummy definitions, make it compile */ + +typedef unsigned pipe_condvar; + +#define pipe_condvar_init(condvar) \ +   (void) condvar + +#define pipe_condvar_broadcast(condvar) \ +   (void) condvar + +#else + +/** Dummy definitions */ + +typedef unsigned pipe_thread; +typedef unsigned pipe_mutex; +typedef unsigned pipe_condvar; + +#define pipe_static_mutex(mutex) \ +   static pipe_mutex mutex = 0 + +#define pipe_mutex_init(mutex) \ +   (void) mutex + +#define pipe_mutex_destroy(mutex) \ +   (void) mutex + +#define pipe_mutex_lock(mutex) \ +   (void) mutex + +#define pipe_mutex_unlock(mutex) \ +   (void) mutex + +#define pipe_static_condvar(condvar) \ +   static unsigned condvar = 0 + +#define pipe_condvar_init(condvar) \ +   (void) condvar + +#define pipe_condvar_destroy(condvar) \ +   (void) condvar + +#define pipe_condvar_wait(condvar, mutex) \ +   (void) condvar + +#define pipe_condvar_signal(condvar) \ +   (void) condvar + +#define pipe_condvar_broadcast(condvar) \ +   (void) condvar + + +#endif  /* PIPE_OS_? */ + + + +/* + * Thread-specific data. + */ + +typedef struct { +#if defined(PIPE_OS_LINUX) +   pthread_key_t key; +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) +   DWORD key; +#endif +   int initMagic; +} pipe_tsd; + + +#define PIPE_TSD_INIT_MAGIC 0xff8adc98 + + +static INLINE void +pipe_tsd_init(pipe_tsd *tsd) +{ +#if defined(PIPE_OS_LINUX) +   if (pthread_key_create(&tsd->key, NULL/*free*/) != 0) { +      perror("pthread_key_create(): failed to allocate key for thread specific data"); +      exit(-1); +   } +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) +   assert(0); +#endif +   tsd->initMagic = PIPE_TSD_INIT_MAGIC; +} + +static INLINE void * +pipe_tsd_get(pipe_tsd *tsd) +{ +   if (tsd->initMagic != (int) PIPE_TSD_INIT_MAGIC) { +      pipe_tsd_init(tsd); +   } +#if defined(PIPE_OS_LINUX) +   return pthread_getspecific(tsd->key); +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) +   assert(0); +   return NULL; +#else +   assert(0); +   return NULL; +#endif +} + +static INLINE void +pipe_tsd_set(pipe_tsd *tsd, void *value) +{ +   if (tsd->initMagic != (int) PIPE_TSD_INIT_MAGIC) { +      pipe_tsd_init(tsd); +   } +#if defined(PIPE_OS_LINUX) +   if (pthread_setspecific(tsd->key, value) != 0) { +      perror("pthread_set_specific() failed"); +      exit(-1); +   } +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) +   assert(0); +#else +   assert(0); +#endif +} + + + +#endif /* _P_THREAD2_H_ */ diff --git a/src/gallium/include/pipe/p_winsys.h b/src/gallium/include/pipe/p_winsys.h new file mode 100644 index 0000000000..5d18291dc6 --- /dev/null +++ b/src/gallium/include/pipe/p_winsys.h @@ -0,0 +1,186 @@ + /************************************************************************** + *  + * 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. + *  + **************************************************************************/ + +/** + * \file + * This is the interface that Gallium3D requires any window system + * hosting it to implement.  This is the only include file in Gallium3D + * 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; + +struct pipe_surface; + + +/** + * Gallium3D drivers are (meant to be!) independent of both GL and the + * window system.  The window system provides a buffer manager and a + * set of additional hooks for things like command buffer submission, + * etc. + * + * There clearly has to be some agreement between the window system + * driver and the hardware driver about the format of command buffers, + * etc. + */ +struct pipe_winsys +{ +   void (*destroy)( struct pipe_winsys *ws ); + +   /** Returns name of this winsys interface */ +   const char *(*get_name)( struct pipe_winsys *ws ); + +   /** +    * Do any special operations to ensure frontbuffer contents are +    * displayed, eg copy fake frontbuffer. +    */ +   void (*flush_frontbuffer)( struct pipe_winsys *ws, +                              struct pipe_surface *surf, +                              void *context_private ); + + +   /** allocate a new surface (no context dependency) */ +   struct pipe_surface *(*surface_alloc)(struct pipe_winsys *ws); + +   /** +    * Allocate storage for a pipe_surface. +    * \param flags XXX unused, remove someday +    * \return  0 if succeeds. +    */ +   int (*surface_alloc_storage)(struct pipe_winsys *ws, +                                struct pipe_surface *surf, +                                unsigned width, unsigned height, +                                enum pipe_format format, +                                unsigned flags, +                                unsigned tex_usage); +    +   void (*surface_release)(struct pipe_winsys *ws, struct pipe_surface **s); + + +   /** +    * Buffer management. Buffer attributes are mostly fixed over its lifetime. +    * +    * Remember that gallium gets to choose the interface it needs, and the +    * window systems must then implement that interface (rather than the +    * other way around...). +    * +    * usage is a bitmask of PIPE_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This +    * usage argument is only an optimization hint, not a guarantee, therefore  +    * proper behavior must be observed in all circumstances. +    * +    * alignment indicates the client's alignment requirements, eg for +    * SSE instructions. +    */ +   struct pipe_buffer *(*buffer_create)( struct pipe_winsys *ws,  +                                         unsigned alignment,  +                                         unsigned usage, +                                         unsigned size ); + +   /**  +    * Create a buffer that wraps user-space data. +    * +    * Effectively this schedules a delayed call to buffer_create +    * followed by an upload of the data at *some point in the future*, +    * or perhaps never.  Basically the allocate/upload is delayed +    * until the buffer is actually passed to hardware. +    * +    * The intention is to provide a quick way to turn regular data +    * into a buffer, and secondly to avoid a copy operation if that +    * data subsequently turns out to be only accessed by the CPU.   +    * +    * Common example is OpenGL vertex buffers that are subsequently +    * processed either by software TNL in the driver or by passing to +    * hardware. +    * +    * XXX: What happens if the delayed call to buffer_create() fails? +    * +    * Note that ptr may be accessed at any time upto the time when the +    * buffer is destroyed, so the data must not be freed before then. +    */ +   struct pipe_buffer *(*user_buffer_create)(struct pipe_winsys *ws,  +                                                    void *ptr, +                                                    unsigned bytes); + +   /**  +    * Map the entire data store of a buffer object into the client's address. +    * flags is bitmask of PIPE_BUFFER_USAGE_CPU_READ/WRITE flags.  +    */ +   void *(*buffer_map)( struct pipe_winsys *ws,  +			struct pipe_buffer *buf, +			unsigned usage ); +    +   void (*buffer_unmap)( struct pipe_winsys *ws,  +			 struct pipe_buffer *buf ); + +   void (*buffer_destroy)( struct pipe_winsys *ws, +			   struct pipe_buffer *buf ); + + +   /** Set ptr = fence, with reference counting */ +   void (*fence_reference)( struct pipe_winsys *ws, +                            struct pipe_fence_handle **ptr, +                            struct pipe_fence_handle *fence ); + +   /** +    * Checks whether the fence has been signalled. +    * \param flags  driver-specific meaning +    * \return zero on success. +    */ +   int (*fence_signalled)( struct pipe_winsys *ws, +                           struct pipe_fence_handle *fence, +                           unsigned flag ); + +   /** +    * Wait for the fence to finish. +    * \param flags  driver-specific meaning +    * \return zero on success. +    */ +   int (*fence_finish)( struct pipe_winsys *ws, +                        struct pipe_fence_handle *fence, +                        unsigned flag ); + +}; + + +#ifdef __cplusplus +} +#endif + +#endif /* P_WINSYS_H */  | 
