i965: fixes for JMPI
[mesa.git] / src / mesa / drivers / dri / i965 / brw_sf_emit.c
index afbb90a9a8244f1d4770121cd88b69e449f57e50..42726d4da487a30b4a3e97145f491aa0ad8c92ab 100644 (file)
@@ -30,9 +30,9 @@
   */
    
 
-#include "glheader.h"
-#include "macros.h"
-#include "enums.h"
+#include "main/glheader.h"
+#include "main/macros.h"
+#include "main/enums.h"
 
 #include "intel_batchbuffer.h"
 
@@ -59,8 +59,6 @@ static GLboolean have_attr(struct brw_sf_compile *c,
    return (c->key.attrs & (1<<attr)) ? 1 : 0;
 }
 
-
-                        
 /*********************************************************************** 
  * Twoside lighting
  */
@@ -163,16 +161,16 @@ static void do_flatshade_triangle( struct brw_sf_compile *c )
 
    brw_push_insn_state(p);
    
-   brw_MUL(p, c->pv, c->pv, brw_imm_ud(nr*2+1));
+   brw_MUL(p, c->pv, c->pv, brw_imm_d(nr*2+1));
    brw_JMPI(p, ip, ip, c->pv);
 
    copy_colors(c, c->vert[1], c->vert[0]);
    copy_colors(c, c->vert[2], c->vert[0]);
-   brw_JMPI(p, ip, ip, brw_imm_ud(nr*4+1));
+   brw_JMPI(p, ip, ip, brw_imm_d(nr*4+1));
 
    copy_colors(c, c->vert[0], c->vert[1]);
    copy_colors(c, c->vert[2], c->vert[1]);
-   brw_JMPI(p, ip, ip, brw_imm_ud(nr*2));
+   brw_JMPI(p, ip, ip, brw_imm_d(nr*2));
 
    copy_colors(c, c->vert[0], c->vert[2]);
    copy_colors(c, c->vert[1], c->vert[2]);
@@ -197,11 +195,11 @@ static void do_flatshade_line( struct brw_sf_compile *c )
 
    brw_push_insn_state(p);
    
-   brw_MUL(p, c->pv, c->pv, brw_imm_ud(nr+1));
+   brw_MUL(p, c->pv, c->pv, brw_imm_d(nr+1));
    brw_JMPI(p, ip, ip, c->pv);
    copy_colors(c, c->vert[1], c->vert[0]);
 
-   brw_JMPI(p, ip, ip, brw_imm_ud(nr));
+   brw_JMPI(p, ip, ip, brw_imm_d(nr));
    copy_colors(c, c->vert[0], c->vert[1]);
 
    brw_pop_insn_state(p);
@@ -220,7 +218,7 @@ static void alloc_regs( struct brw_sf_compile *c )
 
    /* Values computed by fixed function unit:
     */
-   c->pv  = retype(brw_vec1_grf(1, 1), BRW_REGISTER_TYPE_UD);
+   c->pv  = retype(brw_vec1_grf(1, 1), BRW_REGISTER_TYPE_D);
    c->det = brw_vec1_grf(1, 2);
    c->dx0 = brw_vec1_grf(1, 3);
    c->dx2 = brw_vec1_grf(1, 4);
@@ -297,9 +295,6 @@ static void invert_det( struct brw_sf_compile *c)
 
 }
 
-#define NON_PERPECTIVE_ATTRS  (FRAG_BIT_WPOS | \
-                               FRAG_BIT_COL0 | \
-                              FRAG_BIT_COL1)
 
 static GLboolean calculate_masks( struct brw_sf_compile *c,
                                  GLuint reg,
@@ -308,9 +303,16 @@ static GLboolean calculate_masks( struct brw_sf_compile *c,
                                  GLushort *pc_linear)
 {
    GLboolean is_last_attr = (reg == c->nr_setup_regs - 1);
-   GLuint persp_mask = c->key.attrs & ~NON_PERPECTIVE_ATTRS;
+   GLuint persp_mask;
    GLuint linear_mask;
 
+   if (c->key.do_flat_shading || c->key.linear_color)
+      persp_mask = c->key.attrs & ~(FRAG_BIT_WPOS |
+                                    FRAG_BIT_COL0 |
+                                    FRAG_BIT_COL1);
+   else
+      persp_mask = c->key.attrs & ~(FRAG_BIT_WPOS);
+
    if (c->key.do_flat_shading)
       linear_mask = c->key.attrs & ~(FRAG_BIT_COL0|FRAG_BIT_COL1);
    else
@@ -343,13 +345,16 @@ static GLboolean calculate_masks( struct brw_sf_compile *c,
 
 
 
-void brw_emit_tri_setup( struct brw_sf_compile *c )
+void brw_emit_tri_setup( struct brw_sf_compile *c, GLboolean allocate)
 {
    struct brw_compile *p = &c->func;
    GLuint i;
 
    c->nr_verts = 3;
-   alloc_regs(c);
+
+   if (allocate)
+      alloc_regs(c);
+
    invert_det(c);
    copy_z_inv_w(c);
 
@@ -428,14 +433,17 @@ void brw_emit_tri_setup( struct brw_sf_compile *c )
 
 
 
-void brw_emit_line_setup( struct brw_sf_compile *c )
+void brw_emit_line_setup( struct brw_sf_compile *c, GLboolean allocate)
 {
    struct brw_compile *p = &c->func;
    GLuint i;
 
 
    c->nr_verts = 2;
-   alloc_regs(c);
+
+   if (allocate)
+      alloc_regs(c);
+
    invert_det(c);
    copy_z_inv_w(c);
 
@@ -497,13 +505,16 @@ void brw_emit_line_setup( struct brw_sf_compile *c )
    } 
 }
 
-void brw_emit_point_sprite_setup( struct brw_sf_compile *c )
+void brw_emit_point_sprite_setup( struct brw_sf_compile *c, GLboolean allocate)
 {
    struct brw_compile *p = &c->func;
    GLuint i;
 
    c->nr_verts = 1;
-   alloc_regs(c);
+
+   if (allocate)
+      alloc_regs(c);
+
    copy_z_inv_w(c);
    for (i = 0; i < c->nr_setup_regs; i++)
    {
@@ -531,7 +542,7 @@ void brw_emit_point_sprite_setup( struct brw_sf_compile *c )
                  BRW_MATH_DATA_SCALAR,
                  BRW_MATH_PRECISION_FULL);
 
-         if (c->key.SpriteOrigin == GL_UPPER_LEFT) {
+         if (c->key.SpriteOrigin == GL_LOWER_LEFT) {
                brw_MUL(p, c->m1Cx, c->tmp, c->inv_w[0]);
                brw_MOV(p, vec1(suboffset(c->m1Cx, 1)), brw_imm_f(0.0));
                brw_MUL(p, c->m2Cy, c->tmp, negate(c->inv_w[0]));
@@ -550,7 +561,7 @@ void brw_emit_point_sprite_setup( struct brw_sf_compile *c )
       {
         brw_set_predicate_control_flag_value(p, pc); 
         if (tex->CoordReplace) {
-            if (c->key.SpriteOrigin == GL_UPPER_LEFT) {
+            if (c->key.SpriteOrigin == GL_LOWER_LEFT) {
                 brw_MUL(p, c->m3C0, c->inv_w[0], brw_imm_f(1.0));
                 brw_MOV(p, vec1(suboffset(c->m3C0, 0)), brw_imm_f(0.0));
             }
@@ -581,13 +592,16 @@ void brw_emit_point_sprite_setup( struct brw_sf_compile *c )
 /* Points setup - several simplifications as all attributes are
  * constant across the face of the point (point sprites excluded!)
  */
-void brw_emit_point_setup( struct brw_sf_compile *c )
+void brw_emit_point_setup( struct brw_sf_compile *c, GLboolean allocate)
 {
    struct brw_compile *p = &c->func;
    GLuint i;
 
    c->nr_verts = 1;
-   alloc_regs(c);
+   
+   if (allocate)
+      alloc_regs(c);
+
    copy_z_inv_w(c);
 
    brw_MOV(p, c->m1Cx, brw_imm_ud(0)); /* zero - move out of loop */
@@ -648,6 +662,7 @@ void brw_emit_anyprim_setup( struct brw_sf_compile *c )
    
    GLuint saveflag;
 
+   c->nr_verts = 3;
    alloc_regs(c);
 
    primmask = retype(get_element(c->tmp, 0), BRW_REGISTER_TYPE_UD);
@@ -663,11 +678,11 @@ void brw_emit_anyprim_setup( struct brw_sf_compile *c )
                                               (1<<_3DPRIM_POLYGON) |
                                               (1<<_3DPRIM_RECTLIST) |
                                               (1<<_3DPRIM_TRIFAN_NOSTIPPLE)));
-   jmp = brw_JMPI(p, ip, ip, brw_imm_w(0));
+   jmp = brw_JMPI(p, ip, ip, brw_imm_d(0));
    {
       saveflag = p->flag_value;
       brw_push_insn_state(p); 
-      brw_emit_tri_setup( c );
+      brw_emit_tri_setup( c, GL_FALSE );
       brw_pop_insn_state(p);
       p->flag_value = saveflag;
       /* note - thread killed in subroutine, so must
@@ -684,11 +699,11 @@ void brw_emit_anyprim_setup( struct brw_sf_compile *c )
                                               (1<<_3DPRIM_LINESTRIP_CONT) |
                                               (1<<_3DPRIM_LINESTRIP_BF) |
                                               (1<<_3DPRIM_LINESTRIP_CONT_BF)));
-   jmp = brw_JMPI(p, ip, ip, brw_imm_w(0));
+   jmp = brw_JMPI(p, ip, ip, brw_imm_d(0));
    {
       saveflag = p->flag_value;
       brw_push_insn_state(p); 
-      brw_emit_line_setup( c );
+      brw_emit_line_setup( c, GL_FALSE );
       brw_pop_insn_state(p);
       p->flag_value = saveflag;
       /* note - thread killed in subroutine */
@@ -697,17 +712,17 @@ void brw_emit_anyprim_setup( struct brw_sf_compile *c )
 
    brw_set_conditionalmod(p, BRW_CONDITIONAL_Z);
    brw_AND(p, v1_null_ud, payload_attr, brw_imm_ud(1<<BRW_SPRITE_POINT_ENABLE));
-   jmp = brw_JMPI(p, ip, ip, brw_imm_w(0));
+   jmp = brw_JMPI(p, ip, ip, brw_imm_d(0));
    {
       saveflag = p->flag_value;
       brw_push_insn_state(p); 
-      brw_emit_point_sprite_setup( c );
+      brw_emit_point_sprite_setup( c, GL_FALSE );
       brw_pop_insn_state(p);
       p->flag_value = saveflag;
    }
    brw_land_fwd_jump(p, jmp); 
 
-   brw_emit_point_setup( c );
+   brw_emit_point_setup( c, GL_FALSE );
 }