summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2010-01-27 00:56:18 +0100
committerMartin Jansa <Martin.Jansa@gmail.com>2010-02-18 15:39:27 +0100
commitfe7bf228fbb80bd0df0634f702b228a6be6a05ee (patch)
tree76f5433022f2cb1e3d8654dadaf07dbef2febf47
parentff382db49061697cc978ad8549cf78c310d88ff6 (diff)
Upload matrix state
-rw-r--r--src/mesa/drivers/dri/glamo/glamo_context.c32
-rw-r--r--src/mesa/drivers/dri/glamo/glamo_context.h3
-rw-r--r--src/mesa/drivers/dri/glamo/glamo_regs.h10
-rw-r--r--src/mesa/drivers/dri/glamo/glamo_render.c15
-rw-r--r--src/mesa/drivers/dri/glamo/glamo_state.c75
5 files changed, 135 insertions, 0 deletions
diff --git a/src/mesa/drivers/dri/glamo/glamo_context.c b/src/mesa/drivers/dri/glamo/glamo_context.c
index 5f435028b7..47241ae9b8 100644
--- a/src/mesa/drivers/dri/glamo/glamo_context.c
+++ b/src/mesa/drivers/dri/glamo/glamo_context.c
@@ -326,3 +326,35 @@ GLboolean glamoUnbindContext(__DRIcontext *driContextPriv)
{
return GL_TRUE;
}
+
+
+/* Convert IEEE754 32-bit float to Glamo's signed 24-bit float */
+uint32_t float7s16(GLfloat in)
+{
+ uint32_t a, b;
+ uint32_t sign, expo, mant; /* Sign, exponent, significand */
+
+ a = *(uint32_t *)&in;
+
+ /* This is bad */
+ if ( a & 0x40000000 ) {
+ printf(stderr, "Warning: Exponent won't fit into 7 bits\n");
+ }
+
+ /* This hopefully isn't a big problem */
+ if ( a & 0x0000007f ) {
+ printf(stderr, "Warning: Precision lost in FP conversion\n");
+ }
+
+ /* Separate out the right bits */
+ mant = a & 0x007fff80; /* Bits 7-22 (bits 0-6 are lost) */
+ expo = a & 0x3f800000; /* Bits 23-29 (bit 30 is lost) */
+ sign = a & 0x80000000; /* Bit 31 */
+
+ /* Shift and recombine */
+ b = sign >> 8; /* Fills bit 23 */
+ b |= expo >> 7; /* Fills bits 16-22 */
+ b |= mant >> 7; /* Fills bits 0-15 */
+
+ return b;
+}
diff --git a/src/mesa/drivers/dri/glamo/glamo_context.h b/src/mesa/drivers/dri/glamo/glamo_context.h
index 0cedbb233b..3372708ec2 100644
--- a/src/mesa/drivers/dri/glamo/glamo_context.h
+++ b/src/mesa/drivers/dri/glamo/glamo_context.h
@@ -73,6 +73,8 @@ struct glamo_context {
int vertex_size;
struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
+ /* State */
+ GLuint new_state; /* State which must be updated */
uint16_t col_clear;
};
@@ -99,5 +101,6 @@ extern void glamo_update_renderbuffers(__DRIcontext *context,
| (((g) & 0xfc) << 3) \
| (((b) & 0xf8) >> 3))
+extern uint32_t float7s16(GLfloat in);
#endif /* __GLAMO_CONTEXT_H */
diff --git a/src/mesa/drivers/dri/glamo/glamo_regs.h b/src/mesa/drivers/dri/glamo/glamo_regs.h
index 2ba3036802..02b229449b 100644
--- a/src/mesa/drivers/dri/glamo/glamo_regs.h
+++ b/src/mesa/drivers/dri/glamo/glamo_regs.h
@@ -159,6 +159,16 @@ enum glamo_register_3d
G3D_STREAM_BASE_6 = REG_3D(0x1f44),
G3D_STREAM_MODE_7 = REG_3D(0x1f48),
G3D_STREAM_BASE_7 = REG_3D(0x1f4c),
+
+ /* Modelview*projection matrix */
+ G3D_MATRIX_MVP = REG_3D(0x26a0), /* .. 0x27df */
+
+ /* Modelview matrix */
+ G3D_MATRIX_MV = REG_3D(0x26e0), /* .. 0x270f */
+
+ /* Inverse MVP, 3x3 only */
+ G3D_MATRIX_IMVP = REG_3D(0x2710), /* .. 0x2733 */
+
};
#endif /* _GLAMO_REGS_H */
diff --git a/src/mesa/drivers/dri/glamo/glamo_render.c b/src/mesa/drivers/dri/glamo/glamo_render.c
index 850df598cc..fd52418956 100644
--- a/src/mesa/drivers/dri/glamo/glamo_render.c
+++ b/src/mesa/drivers/dri/glamo/glamo_render.c
@@ -149,11 +149,19 @@ static inline GLuint glamoGetCurrentMax(struct glamo_context *gCtx)
/* Render pipeline stage */
/**********************************************************************/
+static void glamoFireEngine(struct glamo_context *gCtx)
+{
+ glamoDRMStartBurst(gCtx, G3D_FIRE);
+ glamoDRMAddData(gCtx, 0, 2); /* Fire! */
+ glamoDRMDispatch(gCtx);
+}
+
static GLboolean glamoRunRender(GLcontext *ctx,
struct tnl_pipeline_stage *stage)
{
TNLcontext *tnl = TNL_CONTEXT(ctx);
+ struct glamo_context *gCtx = GLAMO_CONTEXT(ctx);
struct vertex_buffer *VB = &tnl->vb;
GLuint i;
@@ -164,6 +172,13 @@ static GLboolean glamoRunRender(GLcontext *ctx,
return GL_TRUE; /* Failed */
}
+ /* Validate GPU state */
+ if ( gCtx->new_state ) {
+ if ( !glamoValidateState(ctx, gCtx->new_state) ) {
+ printf("Couldn't validate state...\n");
+ }
+ } /* else nothing to update */
+
tnl->clipspace.new_inputs |= VERT_BIT_POS;
tnl->Driver.Render.Start(ctx);
diff --git a/src/mesa/drivers/dri/glamo/glamo_state.c b/src/mesa/drivers/dri/glamo/glamo_state.c
index 0bd585a3f3..4046c24aaf 100644
--- a/src/mesa/drivers/dri/glamo/glamo_state.c
+++ b/src/mesa/drivers/dri/glamo/glamo_state.c
@@ -51,6 +51,10 @@
#include "main/context.h"
#include "main/framebuffer.h"
+#include "main/api_arrayelt.h"
+#include "swrast/swrast.h"
+#include "swrast_setup/swrast_setup.h"
+#include "tnl/tnl.h"
#include "glamo_fbo.h"
#include "glamo_state.h"
@@ -183,9 +187,80 @@ static void glamoViewport(GLcontext *ctx, GLint x, GLint y,
}
+static void glamoUploadMatrix(struct glamo_context *gCtx, uint16_t mreg,
+ GLfloat *matrix)
+{
+ int i;
+ char *type;
+
+ switch ( mreg ) {
+ case G3D_MATRIX_MVP :
+ type = "MVP"; break;
+ case G3D_MATRIX_MV :
+ type = "MV"; break;
+ case G3D_MATRIX_IMVP :
+ type = "inverse MVP"; break;
+ default :
+ type = "unknown"; break;
+ }
+ printf("Uploading %s matrix...\n", type);
+
+ glamoDRMStartBurst(gCtx, mreg);
+ if ( mreg != G3D_MATRIX_IMVP ) {
+ for ( i=0; i<16; i++ ) {
+ glamoDRMAddData(gCtx, float7s16(matrix[i]), 4);
+ }
+ } else {
+ /* Normal matrix needs special treatment */
+ for ( i=0; i<3; i++ ) {
+ glamoDRMAddData(gCtx, float7s16(matrix[4*i]), 4);
+ glamoDRMAddData(gCtx, float7s16(matrix[4*i+1]), 4);
+ glamoDRMAddData(gCtx, float7s16(matrix[4*i+2]), 4);
+ }
+ }
+ glamoDRMDispatch(gCtx);
+}
+
+
+GLboolean glamoValidateState(GLcontext *ctx, GLuint new_state)
+{
+ struct glamo_context *gCtx = GLAMO_CONTEXT(ctx);
+
+ if ( new_state & (_NEW_MODELVIEW|_NEW_PROJECTION) ) {
+
+ glamoUploadMatrix(gCtx, G3D_MATRIX_MVP,
+ ctx->_ModelProjectMatrix.m);
+
+ /* FIXME: The following two aren't needed unless lighting
+ * is in use... */
+ glamoUploadMatrix(gCtx, G3D_MATRIX_MV,
+ ctx->ModelviewMatrixStack.Top->m);
+ _math_matrix_alloc_inv(&(ctx->_ModelProjectMatrix));
+ _math_matrix_analyse(&(ctx->_ModelProjectMatrix));
+ glamoUploadMatrix(gCtx, G3D_MATRIX_IMVP,
+ ctx->_ModelProjectMatrix.inv);
+ }
+
+ gCtx->new_state = 0;
+ return GL_TRUE;
+}
+
+
static void glamoUpdateState(GLcontext *ctx, GLbitfield new_state)
{
+ struct glamo_context *gCtx = GLAMO_CONTEXT(ctx);
+
printf("glamoUpdateState\n");
+
+ _swrast_InvalidateState(ctx, new_state);
+ _swsetup_InvalidateState(ctx, new_state);
+ _vbo_InvalidateState(ctx, new_state);
+ _tnl_InvalidateState(ctx, new_state);
+ _ae_invalidate_state(ctx, new_state);
+
+ /* Make a note that some state has changed,
+ * so that it can be sent to the GPU later. */
+ gCtx->new_state |= new_state;
}