summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mesa/sources4
-rw-r--r--src/mesa/tnl/t_context.h60
-rw-r--r--src/mesa/tnl/t_pipeline.c16
-rw-r--r--src/mesa/tnl/t_vertex.c1338
-rw-r--r--src/mesa/tnl/t_vertex.h62
-rw-r--r--src/mesa/tnl/t_vertex_c.c267
-rw-r--r--src/mesa/tnl/t_vertex_codegen.c510
-rw-r--r--src/mesa/tnl/t_vertex_generic.c1119
-rw-r--r--src/mesa/tnl/t_vertex_sse.c9
9 files changed, 1398 insertions, 1987 deletions
diff --git a/src/mesa/sources b/src/mesa/sources
index f2f3b6b642c..c3165594bc6 100644
--- a/src/mesa/sources
+++ b/src/mesa/sources
@@ -133,8 +133,8 @@ TNL_SOURCES = \
tnl/t_vb_points.c \
tnl/t_vp_build.c \
tnl/t_vertex.c \
- tnl/t_vertex_c.c \
- tnl/t_vertex_codegen.c \
+ tnl/t_vertex_sse.c \
+ tnl/t_vertex_generic.c \
tnl/t_vtx_api.c \
tnl/t_vtx_generic.c \
tnl/t_vtx_x86.c \
diff --git a/src/mesa/tnl/t_context.h b/src/mesa/tnl/t_context.h
index e8a3c259822..1d94174b7d9 100644
--- a/src/mesa/tnl/t_context.h
+++ b/src/mesa/tnl/t_context.h
@@ -536,6 +536,7 @@ struct tnl_clipspace_attr
GLuint vertattrsize; /* size of the attribute in bytes */
GLubyte *inputptr;
GLuint inputstride;
+ GLuint inputsize;
const tnl_insert_func *insert;
tnl_insert_func emit;
tnl_extract_func extract;
@@ -543,39 +544,6 @@ struct tnl_clipspace_attr
};
-struct tnl_clipspace_codegen {
- GLboolean (*emit_header)( struct tnl_clipspace_codegen *,
- struct tnl_clipspace *);
- GLboolean (*emit_footer)( struct tnl_clipspace_codegen * );
- GLboolean (*emit_attr_header)( struct tnl_clipspace_codegen *,
- struct tnl_clipspace_attr *,
- GLint j, GLenum out_type,
- GLboolean need_vp );
- GLboolean (*emit_attr_footer)( struct tnl_clipspace_codegen * );
- GLboolean (*emit_mov)( struct tnl_clipspace_codegen *,
- GLint, GLint );
- GLboolean (*emit_const)( struct tnl_clipspace_codegen *,
- GLint, GLfloat );
- GLboolean (*emit_mad)( struct tnl_clipspace_codegen *,
- GLint, GLint, GLint, GLint );
- GLboolean (*emit_float_to_chan)( struct tnl_clipspace_codegen *,
- GLint, GLint );
- GLboolean (*emit_const_chan)( struct tnl_clipspace_codegen *,
- GLint, GLchan );
- GLboolean (*emit_float_to_ubyte)( struct tnl_clipspace_codegen *,
- GLint, GLint );
- GLboolean (*emit_const_ubyte)( struct tnl_clipspace_codegen *,
- GLint, GLubyte );
- tnl_emit_func (*emit_store_func)( struct tnl_clipspace_codegen * );
-
- struct _tnl_dynfn codegen_list;
-
- char *buf;
- int buf_size;
- int buf_used;
- int out_offset;
-};
-
typedef void (*tnl_points_func)( GLcontext *ctx, GLuint first, GLuint last );
@@ -595,6 +563,20 @@ typedef void (*tnl_setup_func)( GLcontext *ctx,
GLuint new_inputs);
+struct tnl_clipspace_fastpath {
+ GLuint vertex_size;
+ GLuint attr_count;
+ GLboolean match_strides;
+
+ struct {
+ GLuint format;
+ GLuint stride;
+ } *attr;
+
+ tnl_emit_func func;
+ struct tnl_clipspace_fastpath *next;
+};
+
/**
* Used to describe conversion of vertex arrays to vertex structures.
* I.e. Structure of arrays to arrays of structs.
@@ -616,7 +598,17 @@ struct tnl_clipspace
tnl_interp_func interp;
tnl_copy_pv_func copy_pv;
- struct tnl_clipspace_codegen codegen;
+ /* Parameters and constants for codegen:
+ */
+ GLboolean need_viewport;
+ GLfloat vp_scale[4];
+ GLfloat vp_xlate[4];
+ GLfloat chan_scale[4];
+ GLfloat identity[4];
+
+ struct tnl_clipspace_fastpath *fastpath;
+
+ void (*codegen_emit)( GLcontext *ctx );
};
diff --git a/src/mesa/tnl/t_pipeline.c b/src/mesa/tnl/t_pipeline.c
index 82867605218..6b0ea815e2b 100644
--- a/src/mesa/tnl/t_pipeline.c
+++ b/src/mesa/tnl/t_pipeline.c
@@ -38,6 +38,7 @@
#include "t_context.h"
#include "t_pipeline.h"
#include "t_vp_build.h"
+#include "t_vertex.h"
void _tnl_install_pipeline( GLcontext *ctx,
const struct tnl_pipeline_stage **stages )
@@ -93,7 +94,7 @@ static GLuint check_input_changes( GLcontext *ctx )
}
-static void check_output_changes( GLcontext *ctx )
+static GLuint check_output_changes( GLcontext *ctx )
{
#if 0
TNLcontext *tnl = TNL_CONTEXT(ctx);
@@ -109,6 +110,10 @@ static void check_output_changes( GLcontext *ctx )
if (tnl->pipeline.output_changes)
tnl->Driver.NotifyOutputChanges( ctx, tnl->pipeline.output_changes );
+
+ return tnl->pipeline.output_changes;
+#else
+ return ~0;
#endif
}
@@ -138,10 +143,15 @@ void _tnl_run_pipeline( GLcontext *ctx )
tnl->pipeline.new_state = 0;
tnl->pipeline.input_changes = 0;
- check_output_changes( ctx );
+
+ /* Pipeline can only change its output in response to either a
+ * statechange or an input size/stride change. No other changes
+ * are allowed.
+ */
+ if (check_output_changes( ctx ))
+ _tnl_notify_pipeline_output_change( ctx );
}
-
START_FAST_MATH(__tmp);
for (i = 0; i < tnl->pipeline.nr_stages ; i++) {
diff --git a/src/mesa/tnl/t_vertex.c b/src/mesa/tnl/t_vertex.c
index 2df2a0ac0df..7732425dd16 100644
--- a/src/mesa/tnl/t_vertex.c
+++ b/src/mesa/tnl/t_vertex.c
@@ -32,1133 +32,113 @@
#include "t_context.h"
#include "t_vertex.h"
+#define DBG 0
/* Build and manage clipspace/ndc/window vertices.
- *
- * Another new mechanism designed and crying out for codegen. Before
- * that, it would be very interesting to investigate the merger of
- * these vertices and those built in t_vtx_*.
*/
-
-
-
-
-
-/*
- * These functions take the NDC coordinates pointed to by 'in', apply the
- * NDC->Viewport mapping and store the results at 'v'.
- */
-
-static INLINE void insert_4f_viewport_4( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- GLfloat *out = (GLfloat *)v;
- const GLfloat * const vp = a->vp;
-
- out[0] = vp[0] * in[0] + vp[12];
- out[1] = vp[5] * in[1] + vp[13];
- out[2] = vp[10] * in[2] + vp[14];
- out[3] = in[3];
-}
-
-static INLINE void insert_4f_viewport_3( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- GLfloat *out = (GLfloat *)v;
- const GLfloat * const vp = a->vp;
-
- out[0] = vp[0] * in[0] + vp[12];
- out[1] = vp[5] * in[1] + vp[13];
- out[2] = vp[10] * in[2] + vp[14];
- out[3] = 1;
-}
-
-static INLINE void insert_4f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- GLfloat *out = (GLfloat *)v;
- const GLfloat * const vp = a->vp;
-
- out[0] = vp[0] * in[0] + vp[12];
- out[1] = vp[5] * in[1] + vp[13];
- out[2] = vp[14];
- out[3] = 1;
-}
-
-static INLINE void insert_4f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- GLfloat *out = (GLfloat *)v;
- const GLfloat * const vp = a->vp;
-
- out[0] = vp[0] * in[0] + vp[12];
- out[1] = vp[13];
- out[2] = vp[14];
- out[3] = 1;
-}
-
-static INLINE void insert_3f_viewport_3( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- GLfloat *out = (GLfloat *)v;
- const GLfloat * const vp = a->vp;
-
- out[0] = vp[0] * in[0] + vp[12];
- out[1] = vp[5] * in[1] + vp[13];
- out[2] = vp[10] * in[2] + vp[14];
-}
-
-static INLINE void insert_3f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- GLfloat *out = (GLfloat *)v;
- const GLfloat * const vp = a->vp;
-
- out[0] = vp[0] * in[0] + vp[12];
- out[1] = vp[5] * in[1] + vp[13];
- out[2] = vp[10] * in[2] + vp[14];
-}
-
-static INLINE void insert_3f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- GLfloat *out = (GLfloat *)v;
- const GLfloat * const vp = a->vp;
-
- out[0] = vp[0] * in[0] + vp[12];
- out[1] = vp[13];
- out[2] = vp[14];
-}
-
-static INLINE void insert_2f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- GLfloat *out = (GLfloat *)v;
- const GLfloat * const vp = a->vp;
-
- out[0] = vp[0] * in[0] + vp[12];
- out[1] = vp[5] * in[1] + vp[13];
-}
-
-static INLINE void insert_2f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- GLfloat *out = (GLfloat *)v;
- const GLfloat * const vp = a->vp;
-
- out[0] = vp[0] * in[0] + vp[12];
- out[1] = vp[13];
-}
-
-
-/*
- * These functions do the same as above, except for the viewport mapping.
- */
-
-static INLINE void insert_4f_4( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
-{
- GLfloat *out = (GLfloat *)(v);
- (void) a;
-
- out[0] = in[0];
- out[1] = in[1];
- out[2] = in[2];
- out[3] = in[3];
-}
-
-static INLINE void insert_4f_3( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
-{
- GLfloat *out = (GLfloat *)(v);
- (void) a;
-
- out[0] = in[0];
- out[1] = in[1];
- out[2] = in[2];
- out[3] = 1;
-}
-
-static INLINE void insert_4f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
-{
- GLfloat *out = (GLfloat *)(v);
- (void) a;
-
- out[0] = in[0];
- out[1] = in[1];
- out[2] = 0;
- out[3] = 1;
-}
-
-static INLINE void insert_4f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
-{
- GLfloat *out = (GLfloat *)(v);
- (void) a;
-
- out[0] = in[0];
- out[1] = 0;
- out[2] = 0;
- out[3] = 1;
-}
-
-static INLINE void insert_3f_xyw_4( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
+static GLboolean match_fastpath( struct tnl_clipspace *vtx,
+ const struct tnl_clipspace_fastpath *fp)
{
- GLfloat *out = (GLfloat *)(v);
- (void) a;
-
- out[0] = in[0];
- out[1] = in[1];
- out[2] = in[3];
-}
-
-static INLINE void insert_3f_xyw_err( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
-{
- (void) a; (void) v; (void) in;
- abort();
-}
-
-static INLINE void insert_3f_3( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
-{
- GLfloat *out = (GLfloat *)(v);
- (void) a;
-
- out[0] = in[0];
- out[1] = in[1];
- out[2] = in[2];
-}
-
-static INLINE void insert_3f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
-{
- GLfloat *out = (GLfloat *)(v);
- (void) a;
-
- out[0] = in[0];
- out[1] = in[1];
- out[2] = 0;
-}
-
-static INLINE void insert_3f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
-{
- GLfloat *out = (GLfloat *)(v);
- (void) a;
-
- out[0] = in[0];
- out[1] = 0;
- out[2] = 0;
-}
-
-
-static INLINE void insert_2f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
-{
- GLfloat *out = (GLfloat *)(v);
- (void) a;
-
- out[0] = in[0];
- out[1] = in[1];
-}
-
-static INLINE void insert_2f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
-{
- GLfloat *out = (GLfloat *)(v);
- (void) a;
-
- out[0] = in[0];
- out[1] = 0;
-}
-
-static INLINE void insert_1f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
-{
- GLfloat *out = (GLfloat *)(v);
- (void) a;
-
- out[0] = in[0];
-}
-
-static INLINE void insert_null( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
-{
- (void) a; (void) v; (void) in;
-}
-
-static INLINE void insert_4chan_4f_rgba_4( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- GLchan *c = (GLchan *)v;
- (void) a;
- UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
- UNCLAMPED_FLOAT_TO_CHAN(c[1], in[1]);
- UNCLAMPED_FLOAT_TO_CHAN(c[2], in[2]);
- UNCLAMPED_FLOAT_TO_CHAN(c[3], in[3]);
-}
-
-static INLINE void insert_4chan_4f_rgba_3( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- GLchan *c = (GLchan *)v;
- (void) a;
- UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
- UNCLAMPED_FLOAT_TO_CHAN(c[1], in[1]);
- UNCLAMPED_FLOAT_TO_CHAN(c[2], in[2]);
- c[3] = CHAN_MAX;
-}
-
-static INLINE void insert_4chan_4f_rgba_2( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- GLchan *c = (GLchan *)v;
- (void) a;
- UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
- UNCLAMPED_FLOAT_TO_CHAN(c[1], in[1]);
- c[2] = 0;
- c[3] = CHAN_MAX;
-}
-
-static INLINE void insert_4chan_4f_rgba_1( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- GLchan *c = (GLchan *)v;
- (void) a;
- UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
- c[1] = 0;
- c[2] = 0;
- c[3] = CHAN_MAX;
-}
-
-static INLINE void insert_4ub_4f_rgba_4( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- (void) a;
- UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[2]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[3]);
-}
-
-static INLINE void insert_4ub_4f_rgba_3( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- (void) a;
- UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[2]);
- v[3] = 0xff;
-}
-
-static INLINE void insert_4ub_4f_rgba_2( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- (void) a;
- UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
- v[2] = 0;
- v[3] = 0xff;
-}
-
-static INLINE void insert_4ub_4f_rgba_1( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- (void) a;
- UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
- v[1] = 0;
- v[2] = 0;
- v[3] = 0xff;
-}
-
-static INLINE void insert_4ub_4f_bgra_4( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- (void) a;
- UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[2]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[3]);
-}
-
-static INLINE void insert_4ub_4f_bgra_3( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- (void) a;
- UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[2]);
- v[3] = 0xff;
-}
-
-static INLINE void insert_4ub_4f_bgra_2( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- (void) a;
- UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
- v[0] = 0;
- v[3] = 0xff;
-}
-
-static INLINE void insert_4ub_4f_bgra_1( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- (void) a;
- UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
- v[1] = 0;
- v[0] = 0;
- v[3] = 0xff;
-}
-
-static INLINE void insert_4ub_4f_argb_4( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- (void) a;
- UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[0]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[2]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[3]);
-}
-
-static INLINE void insert_4ub_4f_argb_3( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- (void) a;
- UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[0]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[2]);
- v[0] = 0xff;
-}
-
-static INLINE void insert_4ub_4f_argb_2( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- (void) a;
- UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[0]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
- v[3] = 0x00;
- v[0] = 0xff;
-}
-
-static INLINE void insert_4ub_4f_argb_1( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- (void) a;
- UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[0]);
- v[2] = 0x00;
- v[3] = 0x00;
- v[0] = 0xff;
-}
-
-static INLINE void insert_4ub_4f_abgr_4( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- (void) a;
- UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[0]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[2]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[3]);
-}
-
-static INLINE void insert_4ub_4f_abgr_3( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- (void) a;
- UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[0]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[2]);
- v[0] = 0xff;
-}
-
-static INLINE void insert_4ub_4f_abgr_2( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- (void) a;
- UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[0]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
- v[1] = 0x00;
- v[0] = 0xff;
-}
-
-static INLINE void insert_4ub_4f_abgr_1( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- (void) a;
- UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[0]);
- v[2] = 0x00;
- v[1] = 0x00;
- v[0] = 0xff;
-}
-
-static INLINE void insert_3ub_3f_rgb_3( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- (void) a;
- UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[2]);
-}
-
-static INLINE void insert_3ub_3f_rgb_2( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- (void) a;
- UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
- v[2] = 0;
-}
-
-static INLINE void insert_3ub_3f_rgb_1( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- (void) a;
- UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
- v[1] = 0;
- v[2] = 0;
-}
-
-static INLINE void insert_3ub_3f_bgr_3( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- (void) a;
- UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[2]);
-}
-
-static INLINE void insert_3ub_3f_bgr_2( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- (void) a;
- UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
- UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
- v[0] = 0;
-}
-
-static INLINE void insert_3ub_3f_bgr_1( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- (void) a;
- UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
- v[1] = 0;
- v[0] = 0;
-}
-
-
-static INLINE void insert_1ub_1f_1( const struct tnl_clipspace_attr *a, GLubyte *v,
- const GLfloat *in )
-{
- (void) a;
- UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
-}
-
-
-/***********************************************************************
- * Functions to perform the reverse operations to the above, for
- * swrast translation and clip-interpolation.
- *
- * Currently always extracts a full 4 floats.
- */
-
-static void extract_4f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out,
- const GLubyte *v )
-{
- const GLfloat *in = (const GLfloat *)v;
- const GLfloat * const vp = a->vp;
-
- /* Although included for completeness, the position coordinate is
- * usually handled differently during clipping.
- */
- out[0] = (in[0] - vp[12]) / vp[0];
- out[1] = (in[1] - vp[13]) / vp[5];
- out[2] = (in[2] - vp[14]) / vp[10];
- out[3] = in[3];
-}
-
-static void extract_3f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out,
- const GLubyte *v )
-{
- const GLfloat *in = (const GLfloat *)v;
- const GLfloat * const vp = a->vp;
-
- out[0] = (in[0] - vp[12]) / vp[0];
- out[1] = (in[1] - vp[13]) / vp[5];
- out[2] = (in[2] - vp[14]) / vp[10];
- out[3] = 1;
-}
-
-
-static void extract_2f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out,
- const GLubyte *v )
-{
- const GLfloat *in = (const GLfloat *)v;
- const GLfloat * const vp = a->vp;
-
- out[0] = (in[0] - vp[12]) / vp[0];
- out[1] = (in[1] - vp[13]) / vp[5];
- out[2] = 0;
- out[3] = 1;
-}
-
-
-static void extract_4f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
-{
- const GLfloat *in = (const GLfloat *)v;
- (void) a;
-
- out[0] = in[0];
- out[1] = in[1];
- out[2] = in[2];
- out[3] = in[3];
-}
-
-static void extract_3f_xyw( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
-{
- const GLfloat *in = (const GLfloat *)v;
- (void) a;
-
- out[0] = in[0];
- out[1] = in[1];
- out[2] = 0;
- out[3] = in[2];
-}
-
-
-static void extract_3f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
-{
- const GLfloat *in = (const GLfloat *)v;
- (void) a;
-
- out[0] = in[0];
- out[1] = in[1];
- out[2] = in[2];
- out[3] = 1;
-}
+ GLuint j;
+ if (vtx->attr_count != fp->attr_count)
+ return GL_FALSE;
-static void extract_2f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
-{
- const GLfloat *in = (const GLfloat *)v;
- (void) a;
-
- out[0] = in[0];
- out[1] = in[1];
- out[2] = 0;
- out[3] = 1;
-}
+ for (j = 0; j < vtx->attr_count; j++)
+ if (vtx->attr[j].format != fp->attr[j].format)
+ return GL_FALSE;
+
+ if (fp->match_strides) {
+ if (vtx->vertex_size != fp->vertex_size)
+ return GL_FALSE;
-static void extract_1f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
-{
- const GLfloat *in = (const GLfloat *)v;
- (void) a;
+ for (j = 0; j < vtx->attr_count; j++)
+ if (vtx->attr[j].inputstride != fp->attr[j].stride)
+ return GL_FALSE;
+ }
- out[0] = in[0];
- out[1] = 0;
- out[2] = 0;
- out[3] = 1;
+ return GL_TRUE;
}
-static void extract_4chan_4f_rgba( const struct tnl_clipspace_attr *a, GLfloat *out,
- const GLubyte *v )
+static GLboolean search_fastpath_emit( struct tnl_clipspace *vtx )
{
- GLchan *c = (GLchan *)v;
- (void) a;
+ struct tnl_clipspace_fastpath *fp = vtx->fastpath;
- out[0] = CHAN_TO_FLOAT(c[0]);
- out[1] = CHAN_TO_FLOAT(c[1]);
- out[2] = CHAN_TO_FLOAT(c[2]);
- out[3] = CHAN_TO_FLOAT(c[3]);
-}
-
-static void extract_4ub_4f_rgba( const struct tnl_clipspace_attr *a, GLfloat *out,
- const GLubyte *v )
-{
- (void) a;
- out[0] = UBYTE_TO_FLOAT(v[0]);
- out[1] = UBYTE_TO_FLOAT(v[1]);
- out[2] = UBYTE_TO_FLOAT(v[2]);
- out[3] = UBYTE_TO_FLOAT(v[3]);
-}
-
-static void extract_4ub_4f_bgra( const struct tnl_clipspace_attr *a, GLfloat *out,
- const GLubyte *v )
-{
- (void) a;
- out[2] = UBYTE_TO_FLOAT(v[0]);
- out[1] = UBYTE_TO_FLOAT(v[1]);
- out[0] = UBYTE_TO_FLOAT(v[2]);
- out[3] = UBYTE_TO_FLOAT(v[3]);
-}
-
-static void extract_4ub_4f_argb( const struct tnl_clipspace_attr *a, GLfloat *out,
- const GLubyte *v )
-{
- (void) a;
- out[3] = UBYTE_TO_FLOAT(v[0]);
- out[0] = UBYTE_TO_FLOAT(v[1]);
- out[1] = UBYTE_TO_FLOAT(v[2]);
- out[2] = UBYTE_TO_FLOAT(v[3]);
-}
+ for ( ; fp ; fp = fp->next) {
+ if (match_fastpath(vtx, fp)) {
+ vtx->emit = fp->func;
+ return GL_TRUE;
+ }
+ }
-static void extract_4ub_4f_abgr( const struct tnl_clipspace_attr *a, GLfloat *out,
- const GLubyte *v )
-{
- (void) a;
- out[3] = UBYTE_TO_FLOAT(v[0]);
- out[2] = UBYTE_TO_FLOAT(v[1]);
- out[1] = UBYTE_TO_FLOAT(v[2]);
- out[0] = UBYTE_TO_FLOAT(v[3]);
+ return GL_FALSE;
}
-static void extract_3ub_3f_rgb( const struct tnl_clipspace_attr *a, GLfloat *out,
- const GLubyte *v )
+void _tnl_register_fastpath( struct tnl_clipspace *vtx,
+ GLboolean match_strides )
{
- (void) a;
- out[0] = UBYTE_TO_FLOAT(v[0]);
- out[1] = UBYTE_TO_FLOAT(v[1]);
- out[2] = UBYTE_TO_FLOAT(v[2]);
- out[3] = 1;
-}
+ struct tnl_clipspace_fastpath *fastpath = CALLOC_STRUCT(tnl_clipspace_fastpath);
+ GLuint i;
-static void extract_3ub_3f_bgr( const struct tnl_clipspace_attr *a, GLfloat *out,
- const GLubyte *v )
-{
- (void) a;
- out[2] = UBYTE_TO_FLOAT(v[0]);
- out[1] = UBYTE_TO_FLOAT(v[1]);
- out[0] = UBYTE_TO_FLOAT(v[2]);
- out[3] = 1;
-}
-
-static void extract_1ub_1f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
-{
- (void) a;
- out[0] = UBYTE_TO_FLOAT(v[0]);
- out[1] = 0;
- out[2] = 0;
- out[3] = 1;
-}
+ fastpath->vertex_size = vtx->vertex_size;
+ fastpath->attr_count = vtx->attr_count;
+ fastpath->match_strides = match_strides;
+ fastpath->func = vtx->emit;
+ fastpath->attr = MALLOC(vtx->attr_count * sizeof(fastpath->attr[0]));
+ for (i = 0; i < vtx->attr_count; i++) {
+ fastpath->attr[i].format = vtx->attr[i].format;
+ fastpath->attr[i].stride = vtx->attr[i].inputstride;
+ }
-static const struct {
- const char *name;
- tnl_extract_func extract;
- tnl_insert_func insert[4];
- const GLuint attrsize;
-} format_info[EMIT_MAX] = {
-
- { "1f",
- extract_1f,
- { insert_1f_1, insert_1f_1, insert_1f_1, insert_1f_1 },
- sizeof(GLfloat) },
-
- { "2f",
- extract_2f,
- { insert_2f_1, insert_2f_2, insert_2f_2, insert_2f_2 },
- 2 * sizeof(GLfloat) },
-
- { "3f",
- extract_3f,
- { insert_3f_1, insert_3f_2, insert_3f_3, insert_3f_3 },
- 3 * sizeof(GLfloat) },
-
- { "4f",
- extract_4f,
- { insert_4f_1, insert_4f_2, insert_4f_3, insert_4f_4 },
- 4 * sizeof(GLfloat) },
-
- { "2f_viewport",
- extract_2f_viewport,
- { insert_2f_viewport_1, insert_2f_viewport_2, insert_2f_viewport_2,
- insert_2f_viewport_2 },
- 2 * sizeof(GLfloat) },
-
- { "3f_viewport",
- extract_3f_viewport,
- { insert_3f_viewport_1, insert_3f_viewport_2, insert_3f_viewport_3,
- insert_3f_viewport_3 },
- 3 * sizeof(GLfloat) },
-
- { "4f_viewport",
- extract_4f_viewport,
- { insert_4f_viewport_1, insert_4f_viewport_2, insert_4f_viewport_3,
- insert_4f_viewport_4 },
- 4 * sizeof(GLfloat) },
-
- { "3f_xyw",
- extract_3f_xyw,
- { insert_3f_xyw_err, insert_3f_xyw_err, insert_3f_xyw_err,
- insert_3f_xyw_4 },
- 3 * sizeof(GLfloat) },
-
- { "1ub_1f",
- extract_1ub_1f,
- { insert_1ub_1f_1, insert_1ub_1f_1, insert_1ub_1f_1, insert_1ub_1f_1 },
- sizeof(GLubyte) },
-
- { "3ub_3f_rgb",
- extract_3ub_3f_rgb,
- { insert_3ub_3f_rgb_1, insert_3ub_3f_rgb_2, insert_3ub_3f_rgb_3,
- insert_3ub_3f_rgb_3 },
- 3 * sizeof(GLubyte) },
-
- { "3ub_3f_bgr",
- extract_3ub_3f_bgr,
- { insert_3ub_3f_bgr_1, insert_3ub_3f_bgr_2, insert_3ub_3f_bgr_3,
- insert_3ub_3f_bgr_3 },
- 3 * sizeof(GLubyte) },
-
- { "4ub_4f_rgba",
- extract_4ub_4f_rgba,
- { insert_4ub_4f_rgba_1, insert_4ub_4f_rgba_2, insert_4ub_4f_rgba_3,
- insert_4ub_4f_rgba_4 },
- 4 * sizeof(GLubyte) },
-
- { "4ub_4f_bgra",
- extract_4ub_4f_bgra,
- { insert_4ub_4f_bgra_1, insert_4ub_4f_bgra_2, insert_4ub_4f_bgra_3,
- insert_4ub_4f_bgra_4 },
- 4 * sizeof(GLubyte) },
-
- { "4ub_4f_argb",
- extract_4ub_4f_argb,
- { insert_4ub_4f_argb_1, insert_4ub_4f_argb_2, insert_4ub_4f_argb_3,
- insert_4ub_4f_argb_4 },
- 4 * sizeof(GLubyte) },
-
- { "4ub_4f_abgr",
- extract_4ub_4f_abgr,
- { insert_4ub_4f_abgr_1, insert_4ub_4f_abgr_2, insert_4ub_4f_abgr_3,
- insert_4ub_4f_abgr_4 },
- 4 * sizeof(GLubyte) },
-
- { "4chan_4f_rgba",
- extract_4chan_4f_rgba,
- { insert_4chan_4f_rgba_1, insert_4chan_4f_rgba_2, insert_4chan_4f_rgba_3,
- insert_4chan_4f_rgba_4 },
- 4 * sizeof(GLchan) },
-
- { "pad",
- NULL,
- { NULL, NULL, NULL, NULL },
- 0 }
-
-};
-
-
-
-
-/***********************************************************************
- * Hardwired fastpaths for emitting whole vertices or groups of
- * vertices
- */
-static void choose_emit_func( GLcontext *ctx, GLuint count, GLubyte *dest);
-
-
-#define EMIT5(NR, F0, F1, F2, F3, F4, NAME) \
-static void NAME( GLcontext *ctx, \
- GLuint count, \
- GLubyte *v ) \
-{ \
- struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); \
- struct tnl_clipspace_attr *a = vtx->attr; \
- GLuint i; \
- \
- if (vtx->attr_count != NR || \
- (NR > 0 && a[0].emit != F0) || \
- (NR > 1 && a[1].emit != F1) || \
- (NR > 2 && a[2].emit != F2) || \
- (NR > 3 && a[3].emit != F3) || \
- (NR > 4 && a[4].emit != F4)) { \
- choose_emit_func( ctx, count, v ); \
- return; \
- } \
- \
- for (i = 0 ; i < count ; i++, v += vtx->vertex_size) { \
- if (NR > 0) { \
- F0( &a[0], v + a[0].vertoffset, (GLfloat *)a[0].inputptr ); \
- a[0].inputptr += a[0].inputstride; \
- } \
- \
- if (NR > 1) { \
- F1( &a[1], v + a[1].vertoffset, (GLfloat *)a[1].inputptr ); \
- a[1].inputptr += a[1].inputstride; \
- } \
- \
- if (NR > 2) { \
- F2( &a[2], v + a[2].vertoffset, (GLfloat *)a[2].inputptr ); \
- a[2].inputptr += a[2].inputstride; \
- } \
- \
- if (NR > 3) { \
- F3( &a[3], v + a[3].vertoffset, (GLfloat *)a[3].inputptr ); \
- a[3].inputptr += a[3].inputstride; \
- } \
- \
- if (NR > 4) { \
- F4( &a[4], v + a[4].vertoffset, (GLfloat *)a[4].inputptr ); \
- a[4].inputptr += a[4].inputstride; \
- } \
- } \
+ fastpath->next = vtx->fastpath;
+ vtx->fastpath = fastpath;
}
-
-#define EMIT2(F0, F1, NAME) EMIT5(2, F0, F1, insert_null, \
- insert_null, insert_null, NAME)
-
-#define EMIT3(F0, F1, F2, NAME) EMIT5(3, F0, F1, F2, insert_null, \
- insert_null, NAME)
-
-#define EMIT4(F0, F1, F2, F3, NAME) EMIT5(4, F0, F1, F2, F3, \
- insert_null, NAME)
-
-
-EMIT2(insert_3f_viewport_3, insert_4ub_4f_rgba_4, emit_viewport3_rgba4)
-EMIT2(insert_3f_viewport_3, insert_4ub_4f_bgra_4, emit_viewport3_bgra4)
-EMIT2(insert_3f_3, insert_4ub_4f_rgba_4, emit_xyz3_rgba4)
-
-EMIT3(insert_4f_viewport_4, insert_4ub_4f_rgba_4, insert_2f_2, emit_viewport4_rgba4_st2)
-EMIT3(insert_4f_viewport_4, insert_4ub_4f_bgra_4, insert_2f_2, emit_viewport4_bgra4_st2)
-EMIT3(insert_4f_4, insert_4ub_4f_rgba_4, insert_2f_2, emit_xyzw4_rgba4_st2)
-
-EMIT4(insert_4f_viewport_4, insert_4ub_4f_rgba_4, insert_2f_2, insert_2f_2, emit_viewport4_rgba4_st2_st2)
-EMIT4(insert_4f_viewport_4, insert_4ub_4f_bgra_4, insert_2f_2, insert_2f_2, emit_viewport4_bgra4_st2_st2)
-EMIT4(insert_4f_4, insert_4ub_4f_rgba_4, insert_2f_2, insert_2f_2, emit_xyzw4_rgba4_st2_st2)
-
-
-
/***********************************************************************
- * Generic (non-codegen) functions for whole vertices or groups of
- * vertices
+ * Build codegen functions or return generic ones:
*/
-
-static void generic_emit( GLcontext *ctx,
- GLuint count,
- GLubyte *v )
+static void choose_emit_func( GLcontext *ctx, GLuint count, GLubyte *dest)
{
+ struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
struct tnl_clipspace_attr *a = vtx->attr;
const GLuint attr_count = vtx->attr_count;
- const GLuint stride = vtx->vertex_size;
- GLuint i, j;
-
- for (i = 0 ; i < count ; i++, v += stride) {
- for (j = 0; j < attr_count; j++) {
- GLfloat *in = (GLfloat *)a[j].inputptr;
- a[j].inputptr += a[j].inputstride;
- a[j].emit( &a[j], v + a[j].vertoffset, in );
- }
- }
-}
-
-
-static void generic_interp( GLcontext *ctx,
- GLfloat t,
- GLuint edst, GLuint eout, GLuint ein,
- GLboolean force_boundary )
-{
- TNLcontext *tnl = TNL_CONTEXT(ctx);
- struct vertex_buffer *VB = &tnl->vb;
- struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
- const GLubyte *vin = vtx->vertex_buf + ein * vtx->vertex_size;
- const GLubyte *vout = vtx->vertex_buf + eout * vtx->vertex_size;
- GLubyte *vdst = vtx->vertex_buf + edst * vtx->vertex_size;
- const struct tnl_clipspace_attr *a = vtx->attr;
- const GLuint attr_count = vtx->attr_count;
- GLuint j;
- (void) force_boundary;
-
- if (tnl->NeedNdcCoords) {
- const GLfloat *dstclip = VB->ClipPtr->data[edst];
- if (dstclip[3] != 0.0) {
- const GLfloat w = 1.0f / dstclip[3];
- GLfloat pos[4];
-
- pos[0] = dstclip[0] * w;
- pos[1] = dstclip[1] * w;
- pos[2] = dstclip[2] * w;
- pos[3] = w;
-
- a[0].insert[4-1]( &a[0], vdst, pos );
- }
- }
- else {
- a[0].insert[4-1]( &a[0], vdst, VB->ClipPtr->data[edst] );
- }
-
-
- for (j = 1; j < attr_count; j++) {
- GLfloat fin[4], fout[4], fdst[4];
-
- a[j].extract( &a[j], fin, vin + a[j].vertoffset );
- a[j].extract( &a[j], fout, vout + a[j].vertoffset );
-
- INTERP_F( t, fdst[3], fout[3], fin[3] );
- INTERP_F( t, fdst[2], fout[2], fin[2] );
- INTERP_F( t, fdst[1], fout[1], fin[1] );
- INTERP_F( t, fdst[0], fout[0], fin[0] );
-
- a[j].insert[4-1]( &a[j], vdst + a[j].vertoffset, fdst );
- }
-}
-
-
-/* Extract color attributes from one vertex and insert them into
- * another. (Shortcircuit extract/insert with memcpy).
- */
-static void generic_copy_pv( GLcontext *ctx, GLuint edst, GLuint esrc )
-{
- struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
- GLubyte *vsrc = vtx->vertex_buf + esrc * vtx->vertex_size;
- GLubyte *vdst = vtx->vertex_buf + edst * vtx->vertex_size;
- const struct tnl_clipspace_attr *a = vtx->attr;
- const GLuint attr_count = vtx->attr_count;
GLuint j;
for (j = 0; j < attr_count; j++) {
- if (a[j].attrib == VERT_ATTRIB_COLOR0 ||
- a[j].attrib == VERT_ATTRIB_COLOR1) {
-
- _mesa_memcpy( vdst + a[j].vertoffset,
- vsrc + a[j].vertoffset,
- a[j].vertattrsize );
- }
- }
-}
-
-
-/* Helper functions for hardware which doesn't put back colors and/or
- * edgeflags into vertices.
- */
-static void generic_interp_extras( GLcontext *ctx,
- GLfloat t,
- GLuint dst, GLuint out, GLuint in,
- GLboolean force_boundary )
-{
- struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
-
- /* If stride is zero, ColorPtr[1] is constant across the VB, so
- * there is no point interpolating between two values as they will
- * be identical. In all other cases, this value is generated by
- * t_vb_lighttmp.h and has a stride of 4 dwords.
- */
- if (VB->ColorPtr[1] && VB->ColorPtr[1]->stride) {
- assert(VB->ColorPtr[1]->stride == 4 * sizeof(GLfloat));
-
- INTERP_4F( t,
- VB->ColorPtr[1]->data[dst],
- VB->ColorPtr[1]->data[out],
- VB->ColorPtr[1]->data[in] );
+ GLvector4f *vptr = VB->AttribPtr[a[j].attrib];
+ a[j].inputstride = vptr->stride;
+ a[j].inputsize = vptr->size;
+ a[j].emit = a[j].insert[vptr->size - 1]; /* not always used */
}
- if (VB->SecondaryColorPtr[1]) {
- assert(VB->SecondaryColorPtr[1]->stride == 4 * sizeof(GLfloat));
-
- INTERP_3F( t,
- VB->SecondaryColorPtr[1]->data[dst],
- VB->SecondaryColorPtr[1]->data[out],
- VB->SecondaryColorPtr[1]->data[in] );
- }
+ vtx->emit = NULL;
- if (VB->IndexPtr[1]) {
- VB->IndexPtr[1]->data[dst][0] = LINTERP( t,
- VB->IndexPtr[1]->data[out][0],
- VB->IndexPtr[1]->data[in][0] );
- }
-
- if (VB->EdgeFlag) {
- VB->EdgeFlag[dst] = VB->EdgeFlag[out] || force_boundary;
- }
-
- generic_interp(ctx, t, dst, out, in, force_boundary);
-}
-
-static void generic_copy_pv_extras( GLcontext *ctx,
- GLuint dst, GLuint src )
-{
- struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
-
- /* See above comment:
+ /* Does this match an existing (hardwired, codegen or known-bad)
+ * fastpath?
*/
- if (VB->ColorPtr[1] && VB->ColorPtr[1]->stride) {
- COPY_4FV( VB->ColorPtr[1]->data[dst],
- VB->ColorPtr[1]->data[src] );
+ if (search_fastpath_emit(vtx)) {
+ /* Use this result. If it is null, then it is already known
+ * that the current state will fail for codegen and there is no
+ * point trying again.
+ */
}
-
- if (VB->SecondaryColorPtr[1]) {
- COPY_4FV( VB->SecondaryColorPtr[1]->data[dst],
- VB->SecondaryColorPtr[1]->data[src] );
+ else if (vtx->codegen_emit) {
+ vtx->codegen_emit(ctx);
}
- if (VB->IndexPtr[1]) {
- VB->IndexPtr[1]->data[dst][0] = VB->IndexPtr[1]->data[src][0];
+ if (!vtx->emit) {
+ _tnl_generate_hardwired_emit(ctx);
}
- generic_copy_pv(ctx, dst, src);
-}
-
-
-
-
-/***********************************************************************
- * Build codegen functions or return generic ones:
- */
-
-
-static void choose_emit_func( GLcontext *ctx, GLuint count, GLubyte *dest)
-{
- struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
- struct tnl_clipspace_attr *a = vtx->attr;
- const GLuint attr_count = vtx->attr_count;
-
- vtx->emit = NULL;
-
- if (0)
- vtx->emit = _tnl_codegen_emit(ctx);
-
- /* Does it fit a hardwired fastpath? Help! this is growing out of
- * control!
- */
- switch (attr_count) {
- case 2:
- if (a[0].emit == insert_3f_viewport_3) {
- if (a[1].emit == insert_4ub_4f_bgra_4)
- vtx->emit = emit_viewport3_bgra4;
- else if (a[1].emit == insert_4ub_4f_rgba_4)
- vtx->emit = emit_viewport3_rgba4;
- }
- else if (a[0].emit == insert_3f_3 &&
- a[1].emit == insert_4ub_4f_rgba_4) {
- vtx->emit = emit_xyz3_rgba4;
- }
- break;
- case 3:
- if (a[2].emit == insert_2f_2) {
- if (a[1].emit == insert_4ub_4f_rgba_4) {
- if (a[0].emit == insert_4f_viewport_4)
- vtx->emit = emit_viewport4_rgba4_st2;
- else if (a[0].emit == insert_4f_4)
- vtx->emit = emit_xyzw4_rgba4_st2;
- }
- else if (a[1].emit == insert_4ub_4f_bgra_4 &&
- a[0].emit == insert_4f_viewport_4)
- vtx->emit = emit_viewport4_bgra4_st2;
- }
- break;
- case 4:
- if (a[2].emit == insert_2f_2 &&
- a[3].emit == insert_2f_2) {
- if (a[1].emit == insert_4ub_4f_rgba_4) {
- if (a[0].emit == insert_4f_viewport_4)
- vtx->emit = emit_viewport4_rgba4_st2_st2;
- else if (a[0].emit == insert_4f_4)
- vtx->emit = emit_xyzw4_rgba4_st2_st2;
- }
- else if (a[1].emit == insert_4ub_4f_bgra_4 &&
- a[0].emit == insert_4f_viewport_4)
- vtx->emit = emit_viewport4_bgra4_st2_st2;
- }
- break;
- }
-
/* Otherwise use the generic version:
*/
if (!vtx->emit)
- vtx->emit = generic_emit;
+ vtx->emit = _tnl_generic_emit;
vtx->emit( ctx, count, dest );
}
@@ -1174,9 +154,9 @@ static void choose_interp_func( GLcontext *ctx,
if (vtx->need_extras &&
(ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) {
- vtx->interp = generic_interp_extras;
+ vtx->interp = _tnl_generic_interp_extras;
} else {
- vtx->interp = generic_interp;
+ vtx->interp = _tnl_generic_interp;
}
vtx->interp( ctx, t, edst, eout, ein, force_boundary );
@@ -1189,9 +169,9 @@ static void choose_copy_pv_func( GLcontext *ctx, GLuint edst, GLuint esrc )
if (vtx->need_extras &&
(ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) {
- vtx->copy_pv = generic_copy_pv_extras;
+ vtx->copy_pv = _tnl_generic_copy_pv_extras;
} else {
- vtx->copy_pv = generic_copy_pv;
+ vtx->copy_pv = _tnl_generic_copy_pv;
}
vtx->copy_pv( ctx, edst, esrc );
@@ -1284,6 +264,13 @@ void _tnl_invalidate_vertex_state( GLcontext *ctx, GLuint new_state )
}
}
+static void invalidate_funcs( struct tnl_clipspace *vtx )
+{
+ vtx->emit = choose_emit_func;
+ vtx->interp = choose_interp_func;
+ vtx->copy_pv = choose_copy_pv_func;
+ vtx->new_inputs = ~0;
+}
GLuint _tnl_install_attrs( GLcontext *ctx, const struct tnl_attr_map *map,
GLuint nr, const GLfloat *vp,
@@ -1296,42 +283,61 @@ GLuint _tnl_install_attrs( GLcontext *ctx, const struct tnl_attr_map *map,
assert(nr < _TNL_ATTRIB_MAX);
assert(nr == 0 || map[0].attrib == VERT_ATTRIB_POS);
- if (vtx->emit == generic_emit)
- vtx->emit = choose_emit_func;
-
- vtx->interp = choose_interp_func;
- vtx->copy_pv = choose_copy_pv_func;
vtx->new_inputs = ~0;
+ vtx->need_viewport = GL_FALSE;
+
+ if (vp) {
+ vtx->need_viewport = GL_TRUE;
+ vtx->vp_scale[0] = vp[MAT_SX];
+ vtx->vp_scale[1] = vp[MAT_SY];
+ vtx->vp_scale[2] = vp[MAT_SZ];
+ vtx->vp_scale[3] = 1.0;
+ vtx->vp_xlate[0] = vp[MAT_TX];
+ vtx->vp_xlate[1] = vp[MAT_TY];
+ vtx->vp_xlate[2] = vp[MAT_TZ];
+ vtx->vp_xlate[3] = 0.0;
+ }
for (j = 0, i = 0; i < nr; i++) {
const GLuint format = map[i].format;
if (format == EMIT_PAD) {
- /*
- fprintf(stderr, "%d: pad %d, offset %d\n", i,
- map[i].offset, offset);
- */
+ if (DBG)
+ _mesa_printf("%d: pad %d, offset %d\n", i,
+ map[i].offset, offset);
+
offset += map[i].offset;
}
else {
- vtx->attr[j].attrib = map[i].attrib;
- vtx->attr[j].format = format;
- vtx->attr[j].vp = vp;
- vtx->attr[j].insert = format_info[format].insert;
- vtx->attr[j].extract = format_info[format].extract;
- vtx->attr[j].vertattrsize = format_info[format].attrsize;
+ GLuint tmpoffset;
if (unpacked_size)
- vtx->attr[j].vertoffset = map[i].offset;
+ tmpoffset = map[i].offset;
else
- vtx->attr[j].vertoffset = offset;
+ tmpoffset = offset;
+
+ if (vtx->attr_count != j ||
+ vtx->attr[j].attrib != map[i].attrib ||
+ vtx->attr[j].format != format ||
+ vtx->attr[j].vertoffset != tmpoffset) {
+ invalidate_funcs(vtx);
+
+ vtx->attr[j].attrib = map[i].attrib;
+ vtx->attr[j].format = format;
+ vtx->attr[j].vp = vp;
+ vtx->attr[j].insert = _tnl_format_info[format].insert;
+ vtx->attr[j].extract = _tnl_format_info[format].extract;
+ vtx->attr[j].vertattrsize = _tnl_format_info[format].attrsize;
+ vtx->attr[j].vertoffset = tmpoffset;
+ }
+
- /*
- fprintf(stderr, "%d: %s, vp %p, offset %d\n", i,
- format_info[format].name, (void *)vp,
- vtx->attr[j].vertoffset);
- */
- offset += format_info[format].attrsize;
+ if (DBG)
+ _mesa_printf("%d: %s, vp %p, offset %d\n", i,
+ _tnl_format_info[format].name, (void *)vp,
+ vtx->attr[j].vertoffset);
+
+ offset += _tnl_format_info[format].attrsize;
j++;
}
}
@@ -1344,7 +350,6 @@ GLuint _tnl_install_attrs( GLcontext *ctx, const struct tnl_attr_map *map,
vtx->vertex_size = offset;
assert(vtx->vertex_size <= vtx->max_vertex_size);
-
return vtx->vertex_size;
}
@@ -1357,35 +362,48 @@ void _tnl_invalidate_vertices( GLcontext *ctx, GLuint newinputs )
}
-void _tnl_build_vertices( GLcontext *ctx,
- GLuint start,
- GLuint end,
- GLuint newinputs )
+/* This event has broader use beyond this file - will move elsewhere
+ * and probably invoke a driver callback.
+ */
+void _tnl_notify_pipeline_output_change( GLcontext *ctx )
{
struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
+ invalidate_funcs(vtx);
+}
+
+static void update_input_ptrs( GLcontext *ctx, GLuint start )
+{
+ struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
+ struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
+ struct tnl_clipspace_attr *a = vtx->attr;
+ const GLuint count = vtx->attr_count;
+ GLuint j;
- newinputs |= vtx->new_inputs;
- vtx->new_inputs = 0;
-
- if (newinputs) {
- struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
- struct tnl_clipspace_attr *a = vtx->attr;
- const GLuint stride = vtx->vertex_size;
- const GLuint count = vtx->attr_count;
- GLuint j;
-
- for (j = 0; j < count; j++) {
- GLvector4f *vptr = VB->AttribPtr[a[j].attrib];
- a[j].inputstride = vptr->stride;
- a[j].inputptr = ((GLubyte *)vptr->data) + start * vptr->stride;
- a[j].emit = a[j].insert[vptr->size - 1];
+ for (j = 0; j < count; j++) {
+ GLvector4f *vptr = VB->AttribPtr[a[j].attrib];
+
+ if (vtx->emit != choose_emit_func) {
+ assert(a[j].inputstride == vptr->stride);
+ assert(a[j].inputsize == vptr->size);
}
- vtx->emit( ctx, end - start,
- (GLubyte *)vtx->vertex_buf + start * stride );
+ a[j].inputptr = ((GLubyte *)vptr->data) + start * vptr->stride;
}
}
+
+void _tnl_build_vertices( GLcontext *ctx,
+ GLuint start,
+ GLuint end,
+ GLuint newinputs )
+{
+ struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
+ update_input_ptrs( ctx, start );
+ vtx->emit( ctx, end - start,
+ (GLubyte *)(vtx->vertex_buf +
+ start * vtx->vertex_size));
+}
+
/* Emit VB vertices start..end to dest. Note that VB vertex at
* postion start will be emitted to dest at position zero.
*/
@@ -1395,22 +413,12 @@ void *_tnl_emit_vertices_to_buffer( GLcontext *ctx,
void *dest )
{
struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
- struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
- struct tnl_clipspace_attr *a = vtx->attr;
- const GLuint count = vtx->attr_count;
- GLuint j;
- for (j = 0; j < count; j++) {
- GLvector4f *vptr = VB->AttribPtr[a[j].attrib];
- a[j].inputstride = vptr->stride;
- a[j].inputptr = ((GLubyte *)vptr->data) + start * vptr->stride;
- a[j].emit = a[j].insert[vptr->size - 1];
- }
+ update_input_ptrs(ctx, start);
/* Note: dest should not be adjusted for non-zero 'start' values:
*/
vtx->emit( ctx, end - start, dest );
-
return (void *)((GLubyte *)dest + vtx->vertex_size * (end - start));
}
@@ -1428,20 +436,60 @@ void _tnl_init_vertices( GLcontext *ctx,
_tnl_free_vertices( ctx );
vtx->max_vertex_size = max_vertex_size;
vtx->vertex_buf = (GLubyte *)ALIGN_CALLOC(vb_size * max_vertex_size, 32 );
- vtx->emit = choose_emit_func;
+ invalidate_funcs(vtx);
+ }
+
+ switch(CHAN_TYPE) {
+ case GL_UNSIGNED_BYTE:
+ vtx->chan_scale[0] = 255.0;
+ vtx->chan_scale[1] = 255.0;
+ vtx->chan_scale[2] = 255.0;
+ vtx->chan_scale[3] = 255.0;
+ break;
+ case GL_UNSIGNED_SHORT:
+ vtx->chan_scale[0] = 65535.0;
+ vtx->chan_scale[1] = 65535.0;
+ vtx->chan_scale[2] = 65535.0;
+ vtx->chan_scale[3] = 65535.0;
+ break;
+ default:
+ vtx->chan_scale[0] = 1.0;
+ vtx->chan_scale[1] = 1.0;
+ vtx->chan_scale[2] = 1.0;
+ vtx->chan_scale[3] = 1.0;
+ break;
}
- _tnl_init_c_codegen( &vtx->codegen );
+ vtx->identity[0] = 0.0;
+ vtx->identity[1] = 0.0;
+ vtx->identity[2] = 0.0;
+ vtx->identity[3] = 1.0;
+
+ vtx->codegen_emit = NULL;
+
+#ifdef __i386__
+ if (getenv("MESA_EXPERIMENTAL"))
+ vtx->codegen_emit = _tnl_generate_sse_emit;
+#endif
}
void _tnl_free_vertices( GLcontext *ctx )
{
struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
+ struct tnl_clipspace_fastpath *fp, *tmp;
+
if (vtx->vertex_buf) {
ALIGN_FREE(vtx->vertex_buf);
vtx->vertex_buf = NULL;
}
- _tnl_free_c_codegen( &vtx->codegen );
+ for (fp = vtx->fastpath ; fp ; fp = tmp) {
+ tmp = fp->next;
+ FREE(fp->attr);
+ FREE((void *)fp->func);
+ FREE(fp);
+ }
+
+ vtx->fastpath = NULL;
}
diff --git a/src/mesa/tnl/t_vertex.h b/src/mesa/tnl/t_vertex.h
index 615bbdb4e45..fda8f151d3e 100644
--- a/src/mesa/tnl/t_vertex.h
+++ b/src/mesa/tnl/t_vertex.h
@@ -65,7 +65,15 @@ struct tnl_attr_map {
enum tnl_attr_format format;
GLuint offset;
};
-
+
+struct tnl_format_info {
+ const char *name;
+ tnl_extract_func extract;
+ tnl_insert_func insert[4];
+ const GLuint attrsize;
+};
+
+extern const struct tnl_format_info _tnl_format_info[EMIT_MAX];
/* Interpolate between two vertices to produce a third:
@@ -95,18 +103,11 @@ extern void _tnl_set_attr( GLcontext *ctx, void *vout, GLenum attrib,
extern void *_tnl_get_vertex( GLcontext *ctx, GLuint nr );
-
-/*
- */
extern GLuint _tnl_install_attrs( GLcontext *ctx,
const struct tnl_attr_map *map,
GLuint nr, const GLfloat *vp,
GLuint unpacked_size );
-
-
-
-
extern void _tnl_free_vertices( GLcontext *ctx );
extern void _tnl_init_vertices( GLcontext *ctx,
@@ -127,25 +128,42 @@ extern void _tnl_invalidate_vertices( GLcontext *ctx, GLuint newinputs );
extern void _tnl_invalidate_vertex_state( GLcontext *ctx, GLuint new_state );
-extern tnl_emit_func _tnl_codegen_emit( GLcontext *ctx );
+extern void _tnl_notify_pipeline_output_change( GLcontext *ctx );
-#define REG_IN (0<<16)
-#define REG_OUT (1<<16)
-#define REG_VP (2<<16)
-#define REG_TMP (3<<16)
-#define REG_MASK (3<<16)
-#define REG_OFFSET_MASK 0xffff
+#define GET_VERTEX_STATE(ctx) &(TNL_CONTEXT(ctx)->clipspace)
-#define in( offset ) (REG_IN | (offset))
-#define out( offset ) (REG_OUT | (offset))
-#define vp( offset ) (REG_VP | (offset))
-#define tmp( offset ) (REG_TMP | (offset))
+/* Internal function:
+ */
+void _tnl_register_fastpath( struct tnl_clipspace *vtx,
+ GLboolean match_strides );
-extern void _tnl_init_c_codegen( struct tnl_clipspace_codegen *p );
-extern void _tnl_free_c_codegen( struct tnl_clipspace_codegen *p );
+/* t_vertex_generic.c -- Internal functions for t_vertex.c
+ */
+void _tnl_generic_copy_pv_extras( GLcontext *ctx,
+ GLuint dst, GLuint src );
-#define GET_VERTEX_STATE(ctx) &(TNL_CONTEXT(ctx)->clipspace)
+void _tnl_generic_interp_extras( GLcontext *ctx,
+ GLfloat t,
+ GLuint dst, GLuint out, GLuint in,
+ GLboolean force_boundary );
+
+void _tnl_generic_copy_pv( GLcontext *ctx, GLuint edst, GLuint esrc );
+
+void _tnl_generic_interp( GLcontext *ctx,
+ GLfloat t,
+ GLuint edst, GLuint eout, GLuint ein,
+ GLboolean force_boundary );
+
+void _tnl_generic_emit( GLcontext *ctx,
+ GLuint count,
+ GLubyte *v );
+
+void _tnl_generate_hardwired_emit( GLcontext *ctx );
+
+/* t_vertex_sse.c -- Internal functions for t_vertex.c
+ */
+void _tnl_generate_sse_emit( GLcontext *ctx );
#endif
diff --git a/src/mesa/tnl/t_vertex_c.c b/src/mesa/tnl/t_vertex_c.c
deleted file mode 100644
index d7e1a0375f7..00000000000
--- a/src/mesa/tnl/t_vertex_c.c
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
- * Copyright 2003 Tungsten Graphics, inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * on 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 THEIR 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.
- *
- * Authors:
- * Keith Whitwell <[email protected]>
- */
-
-#include "glheader.h"
-#include "context.h"
-#include "colormac.h"
-
-#include "t_context.h"
-#include "t_vertex.h"
-
-#include "simple_list.h"
-
-#ifdef WIN32
-#define vsnprintf _vsnprintf
-#endif
-
-/* A version of code generation for t_clipspace_codegen.c which prints
- * out 'c' code to implement the generated function. A useful
- * debugging tool, and in concert with something like tcc or a
- * library-ized gcc, could do the whole job.
- */
-
-
-static GLboolean emit( struct tnl_clipspace_codegen *p,
- const char *fmt,
- ... )
-{
- if (p->buf_used < p->buf_size) {
- va_list ap;
- va_start( ap, fmt );
- p->buf_used += vsnprintf( p->buf + p->buf_used,
- p->buf_size - p->buf_used,
- fmt, ap );
- va_end( ap );
- }
-
- return p->buf_used < p->buf_size;
-}
-
-
-static GLboolean print_header( struct tnl_clipspace_codegen *p,
- struct tnl_clipspace *vtx )
-{
- p->buf_used = 0;
- p->out_offset = 0;
-
- return
- emit(p,
- "struct tnl_clipspace_attr\n"
- "{\n"
- " unsigned int attrib; \n"
- " unsigned int format;\n"
- " unsigned int vertoffset; \n"
- " unsigned int vertattrsize; \n"
- " char *inputptr;\n"
- " unsigned int inputstride;\n"
- " void *insert;\n"
- " void *emit;\n"
- " void * extract;\n"
- " const float *vp; \n"
- "};\n"
- "\n"
- ) &&
- emit(p,
- "void emit_vertices( int start, int end, char *dest, \n"
- " struct tnl_clipspace_attr *a) \n"
- "{\n"
- " int i;"
- " for (i = start ; i < end ; i++, dest += %d) {\n",
- vtx->vertex_size);
-
-}
-
-static GLboolean print_footer( struct tnl_clipspace_codegen *p )
-{
- return
- emit(p,
- " }\n"
- "}\n"
- );
-}
-
-static GLboolean emit_reg( struct tnl_clipspace_codegen *p, GLint reg )
-{
- int idx = reg & REG_OFFSET_MASK;
-
- switch (reg & REG_MASK) {
- case REG_IN: return emit(p, "in[%d]", idx);
- case REG_VP: return emit(p, "vp[%d]", idx);
- case REG_TMP: return emit(p, "temp[%d]", idx); /* not used? */
- case REG_OUT: return emit(p, "out[%d]", idx);
- }
-
- return GL_FALSE;
-}
-
-static GLboolean print_mov( struct tnl_clipspace_codegen *p, GLint dest, GLint src )
-{
- return
- emit(p, " ") &&
- emit_reg(p, dest) &&
- emit(p, " = ") &&
- emit_reg(p, src) &&
- emit(p, ";\n");
-}
-
-
-static GLboolean print_const( struct tnl_clipspace_codegen *p,
- GLint dest, GLfloat c )
-{
- return
- emit(p, " ") &&
- emit_reg(p, dest) &&
- emit(p, " = %g;\n", c);
-}
-
-static GLboolean print_const_chan( struct tnl_clipspace_codegen *p,
- GLint dest, GLchan c )
-{
- return
- emit(p, " ") &&
- emit_reg(p, dest) &&
- emit(p, " = ") &&
-#if CHAN_TYPE == GL_FLOAT
- emit(p, "%f", c) &&
-#else
- emit(p, "%d", c) &&
-#endif
- emit(p, ";\n");
-}
-
-static GLboolean print_const_ubyte( struct tnl_clipspace_codegen *p,
- GLint dest, GLubyte c )
-{
- return
- emit(p, " ") &&
- emit_reg(p, dest) &&
- emit(p, " = %x;\n", c);
-}
-
-static GLboolean print_mad( struct tnl_clipspace_codegen *p,
- GLint dest, GLint src0, GLint src1, GLint src2 )
-{
- return
- emit(p, " ") &&
- emit_reg(p, dest) &&
- emit(p, " = ") &&
- emit_reg(p, src0) &&
- emit(p, " * ") &&
- emit_reg(p, src1) &&
- emit(p, " + ") &&
- emit_reg(p, src2) &&
- emit(p, ";\n");
-}
-
-static GLboolean print_float_to_ubyte( struct tnl_clipspace_codegen *p,
- GLint dest, GLint src )
-{
- return
- emit(p, " ") &&
- emit(p, "UNCLAMPED_FLOAT_TO_UBYTE(") &&
- emit_reg(p, dest) &&
- emit(p, ", ") &&
- emit_reg(p, src) &&
- emit(p, ");\n");
-}
-
-static GLboolean print_float_to_chan( struct tnl_clipspace_codegen *p,
- GLint dest, GLint src )
-{
- return
- emit(p, " ") &&
- emit(p, "UNCLAMPED_FLOAT_TO_CHAN(") &&
- emit_reg(p, dest) &&
- emit(p, ", ") &&
- emit_reg(p, src) &&
- emit(p, ");\n");
-}
-
-
-static GLboolean print_attr_header( struct tnl_clipspace_codegen *p,
- struct tnl_clipspace_attr *a,
- GLint j,
- GLenum out_type,
- GLboolean need_vp)
-{
- char *out_type_str = "void";
-
- switch(out_type) {
- case GL_FLOAT: out_type_str = "float"; break;
- case GL_UNSIGNED_BYTE: out_type_str = "unsigned char"; break;
- case GL_UNSIGNED_SHORT: out_type_str = "unsigned short"; break;
- }
-
- return
- emit(p, " {\n") &&
- (need_vp ? emit(p, " const float *vp = a[%d].vp;\n", j) : 1) &&
- emit(p, " %s *out = (%s *)(dest + %d);\n",
- out_type_str, out_type_str, a[j].vertoffset) &&
- emit(p, " const float *in = (const float *)a[%d].inputptr;\n",
- j) &&
- emit(p, " a[%d].inputptr += a[%d].inputstride;\n", j, j);
-}
-
-static GLboolean print_attr_footer( struct tnl_clipspace_codegen *p )
-{
- return emit(p, " }\n");
-}
-
-static tnl_emit_func print_store_func( struct tnl_clipspace_codegen *p )
-{
- fprintf(stderr, "print_store_func: emitted:\n%s\n", p->buf);
- return NULL;
-}
-
-void _tnl_init_c_codegen( struct tnl_clipspace_codegen *p )
-{
- p->emit_header = print_header;
- p->emit_footer = print_footer;
- p->emit_attr_header = print_attr_header;
- p->emit_attr_footer = print_attr_footer;
- p->emit_mov = print_mov;
- p->emit_const = print_const;
- p->emit_mad = print_mad;
- p->emit_float_to_chan = print_float_to_chan;
- p->emit_const_chan = print_const_chan;
- p->emit_float_to_ubyte = print_float_to_ubyte;
- p->emit_const_ubyte = print_const_ubyte;
- p->emit_store_func = print_store_func;
-
- make_empty_list(&p->codegen_list);
-
- p->buf_size = 2048;
- p->buf = (char *) MALLOC(p->buf_size);
-}
-
-void _tnl_free_c_codegen( struct tnl_clipspace_codegen *p )
-{
- if (p->buf) {
- FREE(p->buf);
- p->buf = NULL;
- }
-}
diff --git a/src/mesa/tnl/t_vertex_codegen.c b/src/mesa/tnl/t_vertex_codegen.c
deleted file mode 100644
index e3d9a0a8295..00000000000
--- a/src/mesa/tnl/t_vertex_codegen.c
+++ /dev/null
@@ -1,510 +0,0 @@
-/*
- * Copyright 2003 Tungsten Graphics, inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * on 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 THEIR 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.
- *
- * Authors:
- * Keith Whitwell <[email protected]>
- */
-
-#include "glheader.h"
-#include "context.h"
-#include "colormac.h"
-
-#include "t_context.h"
-#include "t_vertex.h"
-
-#include "simple_list.h"
-
-/* Another codegen scheme, hopefully portable to a few different
- * architectures without too much work.
- */
-
-
-
-
-static GLboolean emit_4f_viewport_4( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_mad(p, out(0), vp(0), in(0), vp(12)) &&
- p->emit_mad(p, out(1), vp(5), in(1), vp(13)) &&
- p->emit_mad(p, out(2), vp(10), in(2), vp(14)) &&
- p->emit_mov(p, out(3), in(3));
-}
-
-static GLboolean emit_4f_viewport_3( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_mad(p, out(0), vp(0), in(0), vp(12)) &&
- p->emit_mad(p, out(1), vp(5), in(1), vp(13)) &&
- p->emit_mad(p, out(2), vp(10), in(2), vp(14)) &&
- p->emit_const(p, out(3), 1.0);
-}
-
-static GLboolean emit_4f_viewport_2( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_mad(p, out(0), vp(0), in(0), vp(12)) &&
- p->emit_mad(p, out(1), vp(5), in(1), vp(13)) &&
- p->emit_mov(p, out(2), vp(14)) &&
- p->emit_const(p, out(3), 1.0);
-}
-
-static GLboolean emit_4f_viewport_1( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_mad(p, out(0), vp(0), in(0), vp(12)) &&
- p->emit_mov(p, out(1), vp(13)) &&
- p->emit_mov(p, out(2), vp(14)) &&
- p->emit_const(p, out(3), 1.0);
-}
-
-static GLboolean emit_3f_viewport_3( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_mad(p, out(0), vp(0), in(0), vp(12)) &&
- p->emit_mad(p, out(1), vp(5), in(1), vp(13)) &&
- p->emit_mad(p, out(2), vp(10), in(2), vp(14));
-}
-
-static GLboolean emit_3f_viewport_2( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_mad(p, out(0), vp(0), in(0), vp(12)) &&
- p->emit_mad(p, out(1), vp(5), in(1), vp(13)) &&
- p->emit_mov(p, out(2), vp(14));
-}
-
-static GLboolean emit_3f_viewport_1( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_mad(p, out(0), vp(0), in(0), vp(12)) &&
- p->emit_mov(p, out(1), vp(13)) &&
- p->emit_mov(p, out(2), vp(14));
-}
-
-static GLboolean emit_2f_viewport_2( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_mad(p, out(0), vp(0), in(0), vp(12)) &&
- p->emit_mad(p, out(1), vp(5), in(1), vp(13));
-}
-
-static GLboolean emit_2f_viewport_1( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_mad(p, out(0), vp(0), in(0), vp(12));
-}
-
-
-static GLboolean emit_4f_4( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_mov(p, out(0), in(0)) &&
- p->emit_mov(p, out(1), in(1)) &&
- p->emit_mov(p, out(2), in(2)) &&
- p->emit_mov(p, out(3), in(3));
-}
-
-static GLboolean emit_4f_3( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_mov(p, out(0), in(0)) &&
- p->emit_mov(p, out(1), in(1)) &&
- p->emit_mov(p, out(2), in(2)) &&
- p->emit_const(p, out(3), 1.0);
-}
-
-static GLboolean emit_4f_2( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_mov(p, out(0), in(0)) &&
- p->emit_mov(p, out(1), in(1)) &&
- p->emit_const(p, out(2), 0.0) &&
- p->emit_const(p, out(3), 1.0);
-}
-
-static GLboolean emit_4f_1( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_mov(p, out(0), in(0)) &&
- p->emit_const(p, out(1), 0.0) &&
- p->emit_const(p, out(2), 0.0) &&
- p->emit_const(p, out(3), 1.0);
-}
-
-static GLboolean emit_3f_xyw_4( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_mov(p, out(0), in(0)) &&
- p->emit_mov(p, out(1), in(1)) &&
- p->emit_mov(p, out(2), in(3));
-}
-
-static GLboolean emit_3f_xyw_err( struct tnl_clipspace_codegen *p )
-{
- (void) p;
- assert(0);
- return GL_FALSE;
-}
-
-static GLboolean emit_3f_3( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_mov(p, out(0), in(0)) &&
- p->emit_mov(p, out(1), in(1)) &&
- p->emit_mov(p, out(2), in(2));
-}
-
-static GLboolean emit_3f_2( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_mov(p, out(0), in(0)) &&
- p->emit_mov(p, out(1), in(1)) &&
- p->emit_const(p, out(2), 0.0);
-}
-
-static GLboolean emit_3f_1( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_mov(p, out(0), in(0)) &&
- p->emit_const(p, out(1), 0.0) &&
- p->emit_const(p, out(2), 0.0);
-}
-
-
-static GLboolean emit_2f_2( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_mov(p, out(0), in(0)) &&
- p->emit_mov(p, out(1), in(1));
-}
-
-static GLboolean emit_2f_1( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_mov(p, out(0), in(0)) &&
- p->emit_const(p, out(1), 0.0);
-}
-
-static GLboolean emit_1f_1( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_mov(p, out(0), in(0));
-}
-
-static GLboolean emit_4chan_4f_rgba_4( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_float_to_chan(p, out(0), in(0)) &&
- p->emit_float_to_chan(p, out(1), in(1)) &&
- p->emit_float_to_chan(p, out(2), in(2)) &&
- p->emit_float_to_chan(p, out(3), in(3));
-}
-
-static GLboolean emit_4chan_4f_rgba_3( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_float_to_chan(p, out(0), in(0)) &&
- p->emit_float_to_chan(p, out(1), in(1)) &&
- p->emit_float_to_chan(p, out(2), in(2)) &&
- p->emit_const_chan(p, out(3), CHAN_MAX);
-}
-
-static GLboolean emit_4chan_4f_rgba_2( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_float_to_chan(p, out(0), in(0)) &&
- p->emit_float_to_chan(p, out(1), in(1)) &&
- p->emit_const_chan(p, out(2), 0) &&
- p->emit_const_chan(p, out(3), CHAN_MAX);
-}
-
-static GLboolean emit_4chan_4f_rgba_1( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_float_to_chan(p, out(0), in(0)) &&
- p->emit_const_chan(p, out(1), 0) &&
- p->emit_const_chan(p, out(2), 0) &&
- p->emit_const_chan(p, out(3), CHAN_MAX);
-}
-
-static GLboolean emit_4ub_4f_rgba_4( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_float_to_ubyte(p, out(0), in(0)) &&
- p->emit_float_to_ubyte(p, out(1), in(1)) &&
- p->emit_float_to_ubyte(p, out(2), in(2)) &&
- p->emit_float_to_ubyte(p, out(3), in(3));
-}
-
-static GLboolean emit_4ub_4f_rgba_3( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_float_to_ubyte(p, out(0), in(0)) &&
- p->emit_float_to_ubyte(p, out(1), in(1)) &&
- p->emit_float_to_ubyte(p, out(2), in(2)) &&
- p->emit_const_ubyte(p, out(3), 0xff);
-}
-
-static GLboolean emit_4ub_4f_rgba_2( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_float_to_ubyte(p, out(0), in(0)) &&
- p->emit_float_to_ubyte(p, out(1), in(1)) &&
- p->emit_const_ubyte(p, out(2), 0) &&
- p->emit_const_ubyte(p, out(3), 0xff);
-}
-
-static GLboolean emit_4ub_4f_rgba_1( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_float_to_ubyte(p, out(0), in(0)) &&
- p->emit_const_ubyte(p, out(1), 0) &&
- p->emit_const_ubyte(p, out(2), 0) &&
- p->emit_const_ubyte(p, out(3), 0xff);
-}
-
-static GLboolean emit_4ub_4f_bgra_4( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_float_to_ubyte(p, out(2), in(0)) &&
- p->emit_float_to_ubyte(p, out(1), in(1)) &&
- p->emit_float_to_ubyte(p, out(0), in(2)) &&
- p->emit_float_to_ubyte(p, out(3), in(3));
-}
-
-static GLboolean emit_4ub_4f_bgra_3( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_float_to_ubyte(p, out(2), in(0)) &&
- p->emit_float_to_ubyte(p, out(1), in(1)) &&
- p->emit_float_to_ubyte(p, out(0), in(2)) &&
- p->emit_const_ubyte(p, out(3), 0xff);
-}
-
-static GLboolean emit_4ub_4f_bgra_2( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_float_to_ubyte(p, out(2), in(0)) &&
- p->emit_float_to_ubyte(p, out(1), in(1)) &&
- p->emit_const_ubyte(p, out(0), 0) &&
- p->emit_const_ubyte(p, out(3), 0xff);
-}
-
-static GLboolean emit_4ub_4f_bgra_1( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_float_to_ubyte(p, out(2), in(0)) &&
- p->emit_const_ubyte(p, out(1), 0) &&
- p->emit_const_ubyte(p, out(0), 0) &&
- p->emit_const_ubyte(p, out(3), 0xff);
-}
-
-static GLboolean emit_3ub_3f_rgb_3( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_float_to_ubyte(p, out(0), in(0)) &&
- p->emit_float_to_ubyte(p, out(1), in(1)) &&
- p->emit_float_to_ubyte(p, out(2), in(2));
-}
-
-static GLboolean emit_3ub_3f_rgb_2( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_float_to_ubyte(p, out(0), in(0)) &&
- p->emit_float_to_ubyte(p, out(1), in(1)) &&
- p->emit_const_ubyte(p, out(2), 0);
-}
-
-static GLboolean emit_3ub_3f_rgb_1( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_float_to_ubyte(p, out(0), in(0)) &&
- p->emit_const_ubyte(p, out(1), 0) &&
- p->emit_const_ubyte(p, out(2), 0);
-}
-
-static GLboolean emit_3ub_3f_bgr_3( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_float_to_ubyte(p, out(2), in(0)) &&
- p->emit_float_to_ubyte(p, out(1), in(1)) &&
- p->emit_float_to_ubyte(p, out(0), in(2));
-}
-
-static GLboolean emit_3ub_3f_bgr_2( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_float_to_ubyte(p, out(2), in(0)) &&
- p->emit_float_to_ubyte(p, out(1), in(1)) &&
- p->emit_const_ubyte(p, out(0), 0);
-}
-
-static GLboolean emit_3ub_3f_bgr_1( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_float_to_ubyte(p, out(2), in(0)) &&
- p->emit_const_ubyte(p, out(1), 0) &&
- p->emit_const_ubyte(p, out(0), 0);
-}
-
-
-static GLboolean emit_1ub_1f_1( struct tnl_clipspace_codegen *p )
-{
- return
- p->emit_float_to_ubyte(p, out(0), in(0));
-}
-
-
-
-
-static struct {
- const char *name;
- GLenum out_type;
- GLboolean need_vp;
- GLboolean (*emit[4])( struct tnl_clipspace_codegen * );
-} emit_info[EMIT_MAX] = {
-
- { "1f", GL_FLOAT, GL_FALSE,
- { emit_1f_1, emit_1f_1, emit_1f_1, emit_1f_1 } },
-
- { "2f", GL_FLOAT, GL_FALSE,
- { emit_2f_1, emit_2f_2, emit_2f_2, emit_2f_2 } },
-
- { "3f", GL_FLOAT, GL_FALSE,
- { emit_3f_1, emit_3f_2, emit_3f_3, emit_3f_3 } },
-
- { "4f", GL_FLOAT, GL_FALSE,
- { emit_4f_1, emit_4f_2, emit_4f_3, emit_4f_4 } },
-
- { "2f_viewport", GL_FLOAT, GL_TRUE,
- { emit_2f_viewport_1, emit_2f_viewport_2, emit_2f_viewport_2,
- emit_2f_viewport_2 } },
-
- { "3f_viewport", GL_FLOAT, GL_TRUE,
- { emit_3f_viewport_1, emit_3f_viewport_2, emit_3f_viewport_3,
- emit_3f_viewport_3 } },
-
- { "4f_viewport", GL_FLOAT, GL_TRUE,
- { emit_4f_viewport_1, emit_4f_viewport_2, emit_4f_viewport_3,
- emit_4f_viewport_4 } },
-
- { "3f_xyw", GL_FLOAT, GL_FALSE,
- { emit_3f_xyw_err, emit_3f_xyw_err, emit_3f_xyw_err,
- emit_3f_xyw_4 } },
-
- { "1ub_1f", GL_UNSIGNED_BYTE, GL_FALSE,
- { emit_1ub_1f_1, emit_1ub_1f_1, emit_1ub_1f_1, emit_1ub_1f_1 } },
-
- { "3ub_3f_rgb", GL_UNSIGNED_BYTE, GL_FALSE,
- { emit_3ub_3f_rgb_1, emit_3ub_3f_rgb_2, emit_3ub_3f_rgb_3,
- emit_3ub_3f_rgb_3 } },
-
- { "3ub_3f_bgr", GL_UNSIGNED_BYTE, GL_FALSE,
- { emit_3ub_3f_bgr_1, emit_3ub_3f_bgr_2, emit_3ub_3f_bgr_3,
- emit_3ub_3f_bgr_3 } },
-
- { "4ub_4f_rgba", GL_UNSIGNED_BYTE, GL_FALSE,
- { emit_4ub_4f_rgba_1, emit_4ub_4f_rgba_2, emit_4ub_4f_rgba_3,
- emit_4ub_4f_rgba_4 } },
-
- { "4ub_4f_bgra", GL_UNSIGNED_BYTE, GL_FALSE,
- { emit_4ub_4f_bgra_1, emit_4ub_4f_bgra_2, emit_4ub_4f_bgra_3,
- emit_4ub_4f_bgra_4 } },
-
- { "4chan_4f_rgba", CHAN_TYPE, GL_FALSE,
- { emit_4chan_4f_rgba_1, emit_4chan_4f_rgba_2, emit_4chan_4f_rgba_3,
- emit_4chan_4f_rgba_4 } },
-
- { "pad", 0, 0,
- { NULL, NULL, NULL, NULL } }
-
-};
-
-
-/***********************************************************************
- * list(attrib, size) --> function
- *
- * Because of the dependence of size, this all has to take place after
- * the pipeline has been run.
- */
-
-tnl_emit_func _tnl_codegen_emit( GLcontext *ctx )
-{
- struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
- struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
- struct tnl_clipspace_attr *a = vtx->attr;
- struct tnl_clipspace_codegen *p = &vtx->codegen;
- const GLuint count = vtx->attr_count;
- GLuint j;
-
- /* Need a faster lookup, or is this linear scan of an MRU list good
- * enough? MRU chosen based on the guess that consecutive VB's are
- * likely to be of the same format. A hash of attributes and sizes
- * might be a better technique.
- *
- * With the vtx code now in place, it should be possible to track
- * changes to the sizes of input arrays (and state, of course) and
- * only invalidate this function when those sizes have changed.
- */
-#if 0
- foreach (l, p->codegen_list) {
- if (l->attr_count != count)
- continue;
-
- /* Assumptions:
- * a[j].vp will not change for a given attrib
- * a[j].vertex_offset will not change nothing else has changed.
- */
- for (j = 0; j < count; j++)
- if (a[j].attrib != l->a[j].attrib ||
- a[j].sz != l->a[j].sz)
- break;
-
- if (j == count) {
- move_to_head(l, p->codegen_list);
- return l->func;
- }
- }
-#endif
-
- p->emit_header( p, vtx );
-
- for (j = 0; j < count; j++) {
- GLuint sz = VB->AttribPtr[a[j].attrib]->size - 1;
- p->emit_attr_header( p, a, j,
- emit_info[a[j].format].out_type,
- emit_info[a[j].format].need_vp );
-
- if (!emit_info[a[j].format].emit[sz]( p )) {
- fprintf(stderr, "codegen failed\n");
- return NULL;
- }
-
- p->emit_attr_footer( p );
- }
-
- p->emit_footer( p );
-
- return p->emit_store_func( p );
-}
-
diff --git a/src/mesa/tnl/t_vertex_generic.c b/src/mesa/tnl/t_vertex_generic.c
new file mode 100644
index 00000000000..3f944580538
--- /dev/null
+++ b/src/mesa/tnl/t_vertex_generic.c
@@ -0,0 +1,1119 @@
+
+/*
+ * Copyright 2003 Tungsten Graphics, inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on 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 THEIR 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.
+ *
+ * Authors:
+ * Keith Whitwell <[email protected]>
+ */
+
+#include "glheader.h"
+#include "context.h"
+#include "colormac.h"
+#include "t_context.h"
+#include "t_vertex.h"
+#include "simple_list.h"
+
+
+
+/*
+ * These functions take the NDC coordinates pointed to by 'in', apply the
+ * NDC->Viewport mapping and store the results at 'v'.
+ */
+
+static INLINE void insert_4f_viewport_4( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ GLfloat *out = (GLfloat *)v;
+ const GLfloat * const vp = a->vp;
+
+ out[0] = vp[0] * in[0] + vp[12];
+ out[1] = vp[5] * in[1] + vp[13];
+ out[2] = vp[10] * in[2] + vp[14];
+ out[3] = in[3];
+}
+
+static INLINE void insert_4f_viewport_3( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ GLfloat *out = (GLfloat *)v;
+ const GLfloat * const vp = a->vp;
+
+ out[0] = vp[0] * in[0] + vp[12];
+ out[1] = vp[5] * in[1] + vp[13];
+ out[2] = vp[10] * in[2] + vp[14];
+ out[3] = 1;
+}
+
+static INLINE void insert_4f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ GLfloat *out = (GLfloat *)v;
+ const GLfloat * const vp = a->vp;
+
+ out[0] = vp[0] * in[0] + vp[12];
+ out[1] = vp[5] * in[1] + vp[13];
+ out[2] = vp[14];
+ out[3] = 1;
+}
+
+static INLINE void insert_4f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ GLfloat *out = (GLfloat *)v;
+ const GLfloat * const vp = a->vp;
+
+ out[0] = vp[0] * in[0] + vp[12];
+ out[1] = vp[13];
+ out[2] = vp[14];
+ out[3] = 1;
+}
+
+static INLINE void insert_3f_viewport_3( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ GLfloat *out = (GLfloat *)v;
+ const GLfloat * const vp = a->vp;
+
+ out[0] = vp[0] * in[0] + vp[12];
+ out[1] = vp[5] * in[1] + vp[13];
+ out[2] = vp[10] * in[2] + vp[14];
+}
+
+static INLINE void insert_3f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ GLfloat *out = (GLfloat *)v;
+ const GLfloat * const vp = a->vp;
+
+ out[0] = vp[0] * in[0] + vp[12];
+ out[1] = vp[5] * in[1] + vp[13];
+ out[2] = vp[10] * in[2] + vp[14];
+}
+
+static INLINE void insert_3f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ GLfloat *out = (GLfloat *)v;
+ const GLfloat * const vp = a->vp;
+
+ out[0] = vp[0] * in[0] + vp[12];
+ out[1] = vp[13];
+ out[2] = vp[14];
+}
+
+static INLINE void insert_2f_viewport_2( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ GLfloat *out = (GLfloat *)v;
+ const GLfloat * const vp = a->vp;
+
+ out[0] = vp[0] * in[0] + vp[12];
+ out[1] = vp[5] * in[1] + vp[13];
+}
+
+static INLINE void insert_2f_viewport_1( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ GLfloat *out = (GLfloat *)v;
+ const GLfloat * const vp = a->vp;
+
+ out[0] = vp[0] * in[0] + vp[12];
+ out[1] = vp[13];
+}
+
+
+/*
+ * These functions do the same as above, except for the viewport mapping.
+ */
+
+static INLINE void insert_4f_4( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
+{
+ GLfloat *out = (GLfloat *)(v);
+ (void) a;
+
+ out[0] = in[0];
+ out[1] = in[1];
+ out[2] = in[2];
+ out[3] = in[3];
+}
+
+static INLINE void insert_4f_3( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
+{
+ GLfloat *out = (GLfloat *)(v);
+ (void) a;
+
+ out[0] = in[0];
+ out[1] = in[1];
+ out[2] = in[2];
+ out[3] = 1;
+}
+
+static INLINE void insert_4f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
+{
+ GLfloat *out = (GLfloat *)(v);
+ (void) a;
+
+ out[0] = in[0];
+ out[1] = in[1];
+ out[2] = 0;
+ out[3] = 1;
+}
+
+static INLINE void insert_4f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
+{
+ GLfloat *out = (GLfloat *)(v);
+ (void) a;
+
+ out[0] = in[0];
+ out[1] = 0;
+ out[2] = 0;
+ out[3] = 1;
+}
+
+static INLINE void insert_3f_xyw_4( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
+{
+ GLfloat *out = (GLfloat *)(v);
+ (void) a;
+
+ out[0] = in[0];
+ out[1] = in[1];
+ out[2] = in[3];
+}
+
+static INLINE void insert_3f_xyw_err( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
+{
+ (void) a; (void) v; (void) in;
+ abort();
+}
+
+static INLINE void insert_3f_3( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
+{
+ GLfloat *out = (GLfloat *)(v);
+ (void) a;
+
+ out[0] = in[0];
+ out[1] = in[1];
+ out[2] = in[2];
+}
+
+static INLINE void insert_3f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
+{
+ GLfloat *out = (GLfloat *)(v);
+ (void) a;
+
+ out[0] = in[0];
+ out[1] = in[1];
+ out[2] = 0;
+}
+
+static INLINE void insert_3f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
+{
+ GLfloat *out = (GLfloat *)(v);
+ (void) a;
+
+ out[0] = in[0];
+ out[1] = 0;
+ out[2] = 0;
+}
+
+
+static INLINE void insert_2f_2( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
+{
+ GLfloat *out = (GLfloat *)(v);
+ (void) a;
+
+ out[0] = in[0];
+ out[1] = in[1];
+}
+
+static INLINE void insert_2f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
+{
+ GLfloat *out = (GLfloat *)(v);
+ (void) a;
+
+ out[0] = in[0];
+ out[1] = 0;
+}
+
+static INLINE void insert_1f_1( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
+{
+ GLfloat *out = (GLfloat *)(v);
+ (void) a;
+
+ out[0] = in[0];
+}
+
+static INLINE void insert_null( const struct tnl_clipspace_attr *a, GLubyte *v, const GLfloat *in )
+{
+ (void) a; (void) v; (void) in;
+}
+
+static INLINE void insert_4chan_4f_rgba_4( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ GLchan *c = (GLchan *)v;
+ (void) a;
+ UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
+ UNCLAMPED_FLOAT_TO_CHAN(c[1], in[1]);
+ UNCLAMPED_FLOAT_TO_CHAN(c[2], in[2]);
+ UNCLAMPED_FLOAT_TO_CHAN(c[3], in[3]);
+}
+
+static INLINE void insert_4chan_4f_rgba_3( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ GLchan *c = (GLchan *)v;
+ (void) a;
+ UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
+ UNCLAMPED_FLOAT_TO_CHAN(c[1], in[1]);
+ UNCLAMPED_FLOAT_TO_CHAN(c[2], in[2]);
+ c[3] = CHAN_MAX;
+}
+
+static INLINE void insert_4chan_4f_rgba_2( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ GLchan *c = (GLchan *)v;
+ (void) a;
+ UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
+ UNCLAMPED_FLOAT_TO_CHAN(c[1], in[1]);
+ c[2] = 0;
+ c[3] = CHAN_MAX;
+}
+
+static INLINE void insert_4chan_4f_rgba_1( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ GLchan *c = (GLchan *)v;
+ (void) a;
+ UNCLAMPED_FLOAT_TO_CHAN(c[0], in[0]);
+ c[1] = 0;
+ c[2] = 0;
+ c[3] = CHAN_MAX;
+}
+
+static INLINE void insert_4ub_4f_rgba_4( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ (void) a;
+ UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[2]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[3]);
+}
+
+static INLINE void insert_4ub_4f_rgba_3( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ (void) a;
+ UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[2]);
+ v[3] = 0xff;
+}
+
+static INLINE void insert_4ub_4f_rgba_2( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ (void) a;
+ UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
+ v[2] = 0;
+ v[3] = 0xff;
+}
+
+static INLINE void insert_4ub_4f_rgba_1( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ (void) a;
+ UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
+ v[1] = 0;
+ v[2] = 0;
+ v[3] = 0xff;
+}
+
+static INLINE void insert_4ub_4f_bgra_4( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ (void) a;
+ UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[2]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[3]);
+}
+
+static INLINE void insert_4ub_4f_bgra_3( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ (void) a;
+ UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[2]);
+ v[3] = 0xff;
+}
+
+static INLINE void insert_4ub_4f_bgra_2( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ (void) a;
+ UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
+ v[0] = 0;
+ v[3] = 0xff;
+}
+
+static INLINE void insert_4ub_4f_bgra_1( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ (void) a;
+ UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
+ v[1] = 0;
+ v[0] = 0;
+ v[3] = 0xff;
+}
+
+static INLINE void insert_4ub_4f_argb_4( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ (void) a;
+ UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[0]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[2]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[3]);
+}
+
+static INLINE void insert_4ub_4f_argb_3( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ (void) a;
+ UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[0]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[2]);
+ v[0] = 0xff;
+}
+
+static INLINE void insert_4ub_4f_argb_2( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ (void) a;
+ UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[0]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
+ v[3] = 0x00;
+ v[0] = 0xff;
+}
+
+static INLINE void insert_4ub_4f_argb_1( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ (void) a;
+ UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[0]);
+ v[2] = 0x00;
+ v[3] = 0x00;
+ v[0] = 0xff;
+}
+
+static INLINE void insert_4ub_4f_abgr_4( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ (void) a;
+ UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[0]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[2]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[3]);
+}
+
+static INLINE void insert_4ub_4f_abgr_3( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ (void) a;
+ UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[0]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[2]);
+ v[0] = 0xff;
+}
+
+static INLINE void insert_4ub_4f_abgr_2( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ (void) a;
+ UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[0]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[1]);
+ v[1] = 0x00;
+ v[0] = 0xff;
+}
+
+static INLINE void insert_4ub_4f_abgr_1( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ (void) a;
+ UNCLAMPED_FLOAT_TO_UBYTE(v[3], in[0]);
+ v[2] = 0x00;
+ v[1] = 0x00;
+ v[0] = 0xff;
+}
+
+static INLINE void insert_3ub_3f_rgb_3( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ (void) a;
+ UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[2]);
+}
+
+static INLINE void insert_3ub_3f_rgb_2( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ (void) a;
+ UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
+ v[2] = 0;
+}
+
+static INLINE void insert_3ub_3f_rgb_1( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ (void) a;
+ UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
+ v[1] = 0;
+ v[2] = 0;
+}
+
+static INLINE void insert_3ub_3f_bgr_3( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ (void) a;
+ UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[2]);
+}
+
+static INLINE void insert_3ub_3f_bgr_2( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ (void) a;
+ UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
+ UNCLAMPED_FLOAT_TO_UBYTE(v[1], in[1]);
+ v[0] = 0;
+}
+
+static INLINE void insert_3ub_3f_bgr_1( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ (void) a;
+ UNCLAMPED_FLOAT_TO_UBYTE(v[2], in[0]);
+ v[1] = 0;
+ v[0] = 0;
+}
+
+
+static INLINE void insert_1ub_1f_1( const struct tnl_clipspace_attr *a, GLubyte *v,
+ const GLfloat *in )
+{
+ (void) a;
+ UNCLAMPED_FLOAT_TO_UBYTE(v[0], in[0]);
+}
+
+
+/***********************************************************************
+ * Functions to perform the reverse operations to the above, for
+ * swrast translation and clip-interpolation.
+ *
+ * Currently always extracts a full 4 floats.
+ */
+
+static void extract_4f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out,
+ const GLubyte *v )
+{
+ const GLfloat *in = (const GLfloat *)v;
+ const GLfloat * const vp = a->vp;
+
+ /* Although included for completeness, the position coordinate is
+ * usually handled differently during clipping.
+ */
+ out[0] = (in[0] - vp[12]) / vp[0];
+ out[1] = (in[1] - vp[13]) / vp[5];
+ out[2] = (in[2] - vp[14]) / vp[10];
+ out[3] = in[3];
+}
+
+static void extract_3f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out,
+ const GLubyte *v )
+{
+ const GLfloat *in = (const GLfloat *)v;
+ const GLfloat * const vp = a->vp;
+
+ out[0] = (in[0] - vp[12]) / vp[0];
+ out[1] = (in[1] - vp[13]) / vp[5];
+ out[2] = (in[2] - vp[14]) / vp[10];
+ out[3] = 1;
+}
+
+
+static void extract_2f_viewport( const struct tnl_clipspace_attr *a, GLfloat *out,
+ const GLubyte *v )
+{
+ const GLfloat *in = (const GLfloat *)v;
+ const GLfloat * const vp = a->vp;
+
+ out[0] = (in[0] - vp[12]) / vp[0];
+ out[1] = (in[1] - vp[13]) / vp[5];
+ out[2] = 0;
+ out[3] = 1;
+}
+
+
+static void extract_4f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
+{
+ const GLfloat *in = (const GLfloat *)v;
+ (void) a;
+
+ out[0] = in[0];
+ out[1] = in[1];
+ out[2] = in[2];
+ out[3] = in[3];
+}
+
+static void extract_3f_xyw( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
+{
+ const GLfloat *in = (const GLfloat *)v;
+ (void) a;
+
+ out[0] = in[0];
+ out[1] = in[1];
+ out[2] = 0;
+ out[3] = in[2];
+}
+
+
+static void extract_3f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
+{
+ const GLfloat *in = (const GLfloat *)v;
+ (void) a;
+
+ out[0] = in[0];
+ out[1] = in[1];
+ out[2] = in[2];
+ out[3] = 1;
+}
+
+
+static void extract_2f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
+{
+ const GLfloat *in = (const GLfloat *)v;
+ (void) a;
+
+ out[0] = in[0];
+ out[1] = in[1];
+ out[2] = 0;
+ out[3] = 1;
+}
+
+static void extract_1f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
+{
+ const GLfloat *in = (const GLfloat *)v;
+ (void) a;
+
+ out[0] = in[0];
+ out[1] = 0;
+ out[2] = 0;
+ out[3] = 1;
+}
+
+static void extract_4chan_4f_rgba( const struct tnl_clipspace_attr *a, GLfloat *out,
+ const GLubyte *v )
+{
+ GLchan *c = (GLchan *)v;
+ (void) a;
+
+ out[0] = CHAN_TO_FLOAT(c[0]);
+ out[1] = CHAN_TO_FLOAT(c[1]);
+ out[2] = CHAN_TO_FLOAT(c[2]);
+ out[3] = CHAN_TO_FLOAT(c[3]);
+}
+
+static void extract_4ub_4f_rgba( const struct tnl_clipspace_attr *a, GLfloat *out,
+ const GLubyte *v )
+{
+ (void) a;
+ out[0] = UBYTE_TO_FLOAT(v[0]);
+ out[1] = UBYTE_TO_FLOAT(v[1]);
+ out[2] = UBYTE_TO_FLOAT(v[2]);
+ out[3] = UBYTE_TO_FLOAT(v[3]);
+}
+
+static void extract_4ub_4f_bgra( const struct tnl_clipspace_attr *a, GLfloat *out,
+ const GLubyte *v )
+{
+ (void) a;
+ out[2] = UBYTE_TO_FLOAT(v[0]);
+ out[1] = UBYTE_TO_FLOAT(v[1]);
+ out[0] = UBYTE_TO_FLOAT(v[2]);
+ out[3] = UBYTE_TO_FLOAT(v[3]);
+}
+
+static void extract_4ub_4f_argb( const struct tnl_clipspace_attr *a, GLfloat *out,
+ const GLubyte *v )
+{
+ (void) a;
+ out[3] = UBYTE_TO_FLOAT(v[0]);
+ out[0] = UBYTE_TO_FLOAT(v[1]);
+ out[1] = UBYTE_TO_FLOAT(v[2]);
+ out[2] = UBYTE_TO_FLOAT(v[3]);
+}
+
+static void extract_4ub_4f_abgr( const struct tnl_clipspace_attr *a, GLfloat *out,
+ const GLubyte *v )
+{
+ (void) a;
+ out[3] = UBYTE_TO_FLOAT(v[0]);
+ out[2] = UBYTE_TO_FLOAT(v[1]);
+ out[1] = UBYTE_TO_FLOAT(v[2]);
+ out[0] = UBYTE_TO_FLOAT(v[3]);
+}
+
+static void extract_3ub_3f_rgb( const struct tnl_clipspace_attr *a, GLfloat *out,
+ const GLubyte *v )
+{
+ (void) a;
+ out[0] = UBYTE_TO_FLOAT(v[0]);
+ out[1] = UBYTE_TO_FLOAT(v[1]);
+ out[2] = UBYTE_TO_FLOAT(v[2]);
+ out[3] = 1;
+}
+
+static void extract_3ub_3f_bgr( const struct tnl_clipspace_attr *a, GLfloat *out,
+ const GLubyte *v )
+{
+ (void) a;
+ out[2] = UBYTE_TO_FLOAT(v[0]);
+ out[1] = UBYTE_TO_FLOAT(v[1]);
+ out[0] = UBYTE_TO_FLOAT(v[2]);
+ out[3] = 1;
+}
+
+static void extract_1ub_1f( const struct tnl_clipspace_attr *a, GLfloat *out, const GLubyte *v )
+{
+ (void) a;
+ out[0] = UBYTE_TO_FLOAT(v[0]);
+ out[1] = 0;
+ out[2] = 0;
+ out[3] = 1;
+}
+
+
+const struct tnl_format_info _tnl_format_info[EMIT_MAX] =
+{
+ { "1f",
+ extract_1f,
+ { insert_1f_1, insert_1f_1, insert_1f_1, insert_1f_1 },
+ sizeof(GLfloat) },
+
+ { "2f",
+ extract_2f,
+ { insert_2f_1, insert_2f_2, insert_2f_2, insert_2f_2 },
+ 2 * sizeof(GLfloat) },
+
+ { "3f",
+ extract_3f,
+ { insert_3f_1, insert_3f_2, insert_3f_3, insert_3f_3 },
+ 3 * sizeof(GLfloat) },
+
+ { "4f",
+ extract_4f,
+ { insert_4f_1, insert_4f_2, insert_4f_3, insert_4f_4 },
+ 4 * sizeof(GLfloat) },
+
+ { "2f_viewport",
+ extract_2f_viewport,
+ { insert_2f_viewport_1, insert_2f_viewport_2, insert_2f_viewport_2,
+ insert_2f_viewport_2 },
+ 2 * sizeof(GLfloat) },
+
+ { "3f_viewport",
+ extract_3f_viewport,
+ { insert_3f_viewport_1, insert_3f_viewport_2, insert_3f_viewport_3,
+ insert_3f_viewport_3 },
+ 3 * sizeof(GLfloat) },
+
+ { "4f_viewport",
+ extract_4f_viewport,
+ { insert_4f_viewport_1, insert_4f_viewport_2, insert_4f_viewport_3,
+ insert_4f_viewport_4 },
+ 4 * sizeof(GLfloat) },
+
+ { "3f_xyw",
+ extract_3f_xyw,
+ { insert_3f_xyw_err, insert_3f_xyw_err, insert_3f_xyw_err,
+ insert_3f_xyw_4 },
+ 3 * sizeof(GLfloat) },
+
+ { "1ub_1f",
+ extract_1ub_1f,
+ { insert_1ub_1f_1, insert_1ub_1f_1, insert_1ub_1f_1, insert_1ub_1f_1 },
+ sizeof(GLubyte) },
+
+ { "3ub_3f_rgb",
+ extract_3ub_3f_rgb,
+ { insert_3ub_3f_rgb_1, insert_3ub_3f_rgb_2, insert_3ub_3f_rgb_3,
+ insert_3ub_3f_rgb_3 },
+ 3 * sizeof(GLubyte) },
+
+ { "3ub_3f_bgr",
+ extract_3ub_3f_bgr,
+ { insert_3ub_3f_bgr_1, insert_3ub_3f_bgr_2, insert_3ub_3f_bgr_3,
+ insert_3ub_3f_bgr_3 },
+ 3 * sizeof(GLubyte) },
+
+ { "4ub_4f_rgba",
+ extract_4ub_4f_rgba,
+ { insert_4ub_4f_rgba_1, insert_4ub_4f_rgba_2, insert_4ub_4f_rgba_3,
+ insert_4ub_4f_rgba_4 },
+ 4 * sizeof(GLubyte) },
+
+ { "4ub_4f_bgra",
+ extract_4ub_4f_bgra,
+ { insert_4ub_4f_bgra_1, insert_4ub_4f_bgra_2, insert_4ub_4f_bgra_3,
+ insert_4ub_4f_bgra_4 },
+ 4 * sizeof(GLubyte) },
+
+ { "4ub_4f_argb",
+ extract_4ub_4f_argb,
+ { insert_4ub_4f_argb_1, insert_4ub_4f_argb_2, insert_4ub_4f_argb_3,
+ insert_4ub_4f_argb_4 },
+ 4 * sizeof(GLubyte) },
+
+ { "4ub_4f_abgr",
+ extract_4ub_4f_abgr,
+ { insert_4ub_4f_abgr_1, insert_4ub_4f_abgr_2, insert_4ub_4f_abgr_3,
+ insert_4ub_4f_abgr_4 },
+ 4 * sizeof(GLubyte) },
+
+ { "4chan_4f_rgba",
+ extract_4chan_4f_rgba,
+ { insert_4chan_4f_rgba_1, insert_4chan_4f_rgba_2, insert_4chan_4f_rgba_3,
+ insert_4chan_4f_rgba_4 },
+ 4 * sizeof(GLchan) },
+
+ { "pad",
+ NULL,
+ { NULL, NULL, NULL, NULL },
+ 0 }
+
+};
+
+
+
+
+/***********************************************************************
+ * Hardwired fastpaths for emitting whole vertices or groups of
+ * vertices
+ */
+#define EMIT5(NR, F0, F1, F2, F3, F4, NAME) \
+static void NAME( GLcontext *ctx, \
+ GLuint count, \
+ GLubyte *v ) \
+{ \
+ struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); \
+ struct tnl_clipspace_attr *a = vtx->attr; \
+ GLuint i; \
+ \
+ for (i = 0 ; i < count ; i++, v += vtx->vertex_size) { \
+ if (NR > 0) { \
+ F0( &a[0], v + a[0].vertoffset, (GLfloat *)a[0].inputptr ); \
+ a[0].inputptr += a[0].inputstride; \
+ } \
+ \
+ if (NR > 1) { \
+ F1( &a[1], v + a[1].vertoffset, (GLfloat *)a[1].inputptr ); \
+ a[1].inputptr += a[1].inputstride; \
+ } \
+ \
+ if (NR > 2) { \
+ F2( &a[2], v + a[2].vertoffset, (GLfloat *)a[2].inputptr ); \
+ a[2].inputptr += a[2].inputstride; \
+ } \
+ \
+ if (NR > 3) { \
+ F3( &a[3], v + a[3].vertoffset, (GLfloat *)a[3].inputptr ); \
+ a[3].inputptr += a[3].inputstride; \
+ } \
+ \
+ if (NR > 4) { \
+ F4( &a[4], v + a[4].vertoffset, (GLfloat *)a[4].inputptr ); \
+ a[4].inputptr += a[4].inputstride; \
+ } \
+ } \
+}
+
+
+#define EMIT2(F0, F1, NAME) EMIT5(2, F0, F1, insert_null, \
+ insert_null, insert_null, NAME)
+
+#define EMIT3(F0, F1, F2, NAME) EMIT5(3, F0, F1, F2, insert_null, \
+ insert_null, NAME)
+
+#define EMIT4(F0, F1, F2, F3, NAME) EMIT5(4, F0, F1, F2, F3, \
+ insert_null, NAME)
+
+
+EMIT2(insert_3f_viewport_3, insert_4ub_4f_rgba_4, emit_viewport3_rgba4)
+EMIT2(insert_3f_viewport_3, insert_4ub_4f_bgra_4, emit_viewport3_bgra4)
+EMIT2(insert_3f_3, insert_4ub_4f_rgba_4, emit_xyz3_rgba4)
+
+EMIT3(insert_4f_viewport_4, insert_4ub_4f_rgba_4, insert_2f_2, emit_viewport4_rgba4_st2)
+EMIT3(insert_4f_viewport_4, insert_4ub_4f_bgra_4, insert_2f_2, emit_viewport4_bgra4_st2)
+EMIT3(insert_4f_4, insert_4ub_4f_rgba_4, insert_2f_2, emit_xyzw4_rgba4_st2)
+
+EMIT4(insert_4f_viewport_4, insert_4ub_4f_rgba_4, insert_2f_2, insert_2f_2, emit_viewport4_rgba4_st2_st2)
+EMIT4(insert_4f_viewport_4, insert_4ub_4f_bgra_4, insert_2f_2, insert_2f_2, emit_viewport4_bgra4_st2_st2)
+EMIT4(insert_4f_4, insert_4ub_4f_rgba_4, insert_2f_2, insert_2f_2, emit_xyzw4_rgba4_st2_st2)
+
+
+/* Use the codegen paths to select one of a number of hardwired
+ * fastpaths.
+ */
+void _tnl_generate_hardwired_emit( GLcontext *ctx )
+{
+ struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
+ tnl_emit_func func = NULL;
+
+ /* Does it fit a hardwired fastpath? Help! this is growing out of
+ * control!
+ */
+ switch (vtx->attr_count) {
+ case 2:
+ if (vtx->attr[0].emit == insert_3f_viewport_3) {
+ if (vtx->attr[1].emit == insert_4ub_4f_bgra_4)
+ func = emit_viewport3_bgra4;
+ else if (vtx->attr[1].emit == insert_4ub_4f_rgba_4)
+ func = emit_viewport3_rgba4;
+ }
+ else if (vtx->attr[0].emit == insert_3f_3 &&
+ vtx->attr[1].emit == insert_4ub_4f_rgba_4) {
+ func = emit_xyz3_rgba4;
+ }
+ break;
+ case 3:
+ if (vtx->attr[2].emit == insert_2f_2) {
+ if (vtx->attr[1].emit == insert_4ub_4f_rgba_4) {
+ if (vtx->attr[0].emit == insert_4f_viewport_4)
+ func = emit_viewport4_rgba4_st2;
+ else if (vtx->attr[0].emit == insert_4f_4)
+ func = emit_xyzw4_rgba4_st2;
+ }
+ else if (vtx->attr[1].emit == insert_4ub_4f_bgra_4 &&
+ vtx->attr[0].emit == insert_4f_viewport_4)
+ func = emit_viewport4_bgra4_st2;
+ }
+ break;
+ case 4:
+ if (vtx->attr[2].emit == insert_2f_2 &&
+ vtx->attr[3].emit == insert_2f_2) {
+ if (vtx->attr[1].emit == insert_4ub_4f_rgba_4) {
+ if (vtx->attr[0].emit == insert_4f_viewport_4)
+ func = emit_viewport4_rgba4_st2_st2;
+ else if (vtx->attr[0].emit == insert_4f_4)
+ func = emit_xyzw4_rgba4_st2_st2;
+ }
+ else if (vtx->attr[1].emit == insert_4ub_4f_bgra_4 &&
+ vtx->attr[0].emit == insert_4f_viewport_4)
+ func = emit_viewport4_bgra4_st2_st2;
+ }
+ break;
+ }
+
+ vtx->emit = func;
+}
+
+/***********************************************************************
+ * Generic (non-codegen) functions for whole vertices or groups of
+ * vertices
+ */
+
+void _tnl_generic_emit( GLcontext *ctx,
+ GLuint count,
+ GLubyte *v )
+{
+ struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
+ struct tnl_clipspace_attr *a = vtx->attr;
+ const GLuint attr_count = vtx->attr_count;
+ const GLuint stride = vtx->vertex_size;
+ GLuint i, j;
+
+ for (i = 0 ; i < count ; i++, v += stride) {
+ for (j = 0; j < attr_count; j++) {
+ GLfloat *in = (GLfloat *)a[j].inputptr;
+ a[j].inputptr += a[j].inputstride;
+ a[j].emit( &a[j], v + a[j].vertoffset, in );
+ }
+ }
+}
+
+
+void _tnl_generic_interp( GLcontext *ctx,
+ GLfloat t,
+ GLuint edst, GLuint eout, GLuint ein,
+ GLboolean force_boundary )
+{
+ TNLcontext *tnl = TNL_CONTEXT(ctx);
+ struct vertex_buffer *VB = &tnl->vb;
+ struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
+ const GLubyte *vin = vtx->vertex_buf + ein * vtx->vertex_size;
+ const GLubyte *vout = vtx->vertex_buf + eout * vtx->vertex_size;
+ GLubyte *vdst = vtx->vertex_buf + edst * vtx->vertex_size;
+ const struct tnl_clipspace_attr *a = vtx->attr;
+ const GLuint attr_count = vtx->attr_count;
+ GLuint j;
+ (void) force_boundary;
+
+ if (tnl->NeedNdcCoords) {
+ const GLfloat *dstclip = VB->ClipPtr->data[edst];
+ if (dstclip[3] != 0.0) {
+ const GLfloat w = 1.0f / dstclip[3];
+ GLfloat pos[4];
+
+ pos[0] = dstclip[0] * w;
+ pos[1] = dstclip[1] * w;
+ pos[2] = dstclip[2] * w;
+ pos[3] = w;
+
+ a[0].insert[4-1]( &a[0], vdst, pos );
+ }
+ }
+ else {
+ a[0].insert[4-1]( &a[0], vdst, VB->ClipPtr->data[edst] );
+ }
+
+
+ for (j = 1; j < attr_count; j++) {
+ GLfloat fin[4], fout[4], fdst[4];
+
+ a[j].extract( &a[j], fin, vin + a[j].vertoffset );
+ a[j].extract( &a[j], fout, vout + a[j].vertoffset );
+
+ INTERP_F( t, fdst[3], fout[3], fin[3] );
+ INTERP_F( t, fdst[2], fout[2], fin[2] );
+ INTERP_F( t, fdst[1], fout[1], fin[1] );
+ INTERP_F( t, fdst[0], fout[0], fin[0] );
+
+ a[j].insert[4-1]( &a[j], vdst + a[j].vertoffset, fdst );
+ }
+}
+
+
+/* Extract color attributes from one vertex and insert them into
+ * another. (Shortcircuit extract/insert with memcpy).
+ */
+void _tnl_generic_copy_pv( GLcontext *ctx, GLuint edst, GLuint esrc )
+{
+ struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
+ GLubyte *vsrc = vtx->vertex_buf + esrc * vtx->vertex_size;
+ GLubyte *vdst = vtx->vertex_buf + edst * vtx->vertex_size;
+ const struct tnl_clipspace_attr *a = vtx->attr;
+ const GLuint attr_count = vtx->attr_count;
+ GLuint j;
+
+ for (j = 0; j < attr_count; j++) {
+ if (a[j].attrib == VERT_ATTRIB_COLOR0 ||
+ a[j].attrib == VERT_ATTRIB_COLOR1) {
+
+ _mesa_memcpy( vdst + a[j].vertoffset,
+ vsrc + a[j].vertoffset,
+ a[j].vertattrsize );
+ }
+ }
+}
+
+
+/* Helper functions for hardware which doesn't put back colors and/or
+ * edgeflags into vertices.
+ */
+void _tnl_generic_interp_extras( GLcontext *ctx,
+ GLfloat t,
+ GLuint dst, GLuint out, GLuint in,
+ GLboolean force_boundary )
+{
+ struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
+
+ /* If stride is zero, ColorPtr[1] is constant across the VB, so
+ * there is no point interpolating between two values as they will
+ * be identical. In all other cases, this value is generated by
+ * t_vb_lighttmp.h and has a stride of 4 dwords.
+ */
+ if (VB->ColorPtr[1] && VB->ColorPtr[1]->stride) {
+ assert(VB->ColorPtr[1]->stride == 4 * sizeof(GLfloat));
+
+ INTERP_4F( t,
+ VB->ColorPtr[1]->data[dst],
+ VB->ColorPtr[1]->data[out],
+ VB->ColorPtr[1]->data[in] );
+ }
+
+ if (VB->SecondaryColorPtr[1]) {
+ assert(VB->SecondaryColorPtr[1]->stride == 4 * sizeof(GLfloat));
+
+ INTERP_3F( t,
+ VB->SecondaryColorPtr[1]->data[dst],
+ VB->SecondaryColorPtr[1]->data[out],
+ VB->SecondaryColorPtr[1]->data[in] );
+ }
+
+ if (VB->IndexPtr[1]) {
+ VB->IndexPtr[1]->data[dst][0] = LINTERP( t,
+ VB->IndexPtr[1]->data[out][0],
+ VB->IndexPtr[1]->data[in][0] );
+ }
+
+ if (VB->EdgeFlag) {
+ VB->EdgeFlag[dst] = VB->EdgeFlag[out] || force_boundary;
+ }
+
+ _tnl_generic_interp(ctx, t, dst, out, in, force_boundary);
+}
+
+void _tnl_generic_copy_pv_extras( GLcontext *ctx,
+ GLuint dst, GLuint src )
+{
+ struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
+
+ /* See above comment:
+ */
+ if (VB->ColorPtr[1] && VB->ColorPtr[1]->stride) {
+ COPY_4FV( VB->ColorPtr[1]->data[dst],
+ VB->ColorPtr[1]->data[src] );
+ }
+
+ if (VB->SecondaryColorPtr[1]) {
+ COPY_4FV( VB->SecondaryColorPtr[1]->data[dst],
+ VB->SecondaryColorPtr[1]->data[src] );
+ }
+
+ if (VB->IndexPtr[1]) {
+ VB->IndexPtr[1]->data[dst][0] = VB->IndexPtr[1]->data[src][0];
+ }
+
+ _tnl_generic_copy_pv(ctx, dst, src);
+}
+
+
diff --git a/src/mesa/tnl/t_vertex_sse.c b/src/mesa/tnl/t_vertex_sse.c
index 33ae622a264..d6c1f08280d 100644
--- a/src/mesa/tnl/t_vertex_sse.c
+++ b/src/mesa/tnl/t_vertex_sse.c
@@ -603,10 +603,8 @@ static void emit_load3f_3( struct x86_program *p,
struct x86_reg dest,
struct x86_reg arg0 )
{
- /* Over-reads by 1 dword - potential SEGV... Deal with in
- * array_cache by treating size-3 arrays specially, copying to
- * temporary storage if last element (how can you tell?) falls on a
- * 4k boundary.
+ /* Over-reads by 1 dword - potential SEGV if input is a vertex
+ * array.
*/
if (p->inputs_safe) {
emit_movups(p, dest, arg0);
@@ -1003,6 +1001,9 @@ void _tnl_generate_sse_emit( GLcontext *ctx )
_mesa_printf("disassemble 0x%x 0x%x\n", p.store, p.csr);
}
else {
+ /* Note the failure:
+ */
+ _tnl_register_fastpath( vtx, GL_FALSE );
FREE(p.store);
}