more r500 vs r300 kickin
[mesa.git] / src / mesa / drivers / dri / r300 / r300_context.h
index 9bda2409bd0e47d3dc1546d374886e5920b42cd9..4f8b7591c20972495e7b52319cefb7a1bd8b22cd 100644 (file)
@@ -27,10 +27,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 **************************************************************************/
 
-/*
- * Authors:
- *   Keith Whitwell <keith@tungstengraphics.com>
- *   Nicolai Haehnle <prefect_@gmx.net>
+/**
+ * \file
+ *
+ * \author Keith Whitwell <keith@tungstengraphics.com>
+ * \author Nicolai Haehnle <prefect_@gmx.net>
  */
 
 #ifndef __R300_CONTEXT_H__
@@ -45,17 +46,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "macros.h"
 #include "mtypes.h"
 #include "colormac.h"
-#include "radeon_context.h"
 
 #define USER_BUFFERS
 
-/* We don't handle 16 bits elts swapping yet */
-#ifdef MESA_BIG_ENDIAN
-#define FORCE_32BITS_ELTS
-#endif
-
-//#define OPTIMIZE_ELTS
-
 struct r300_context;
 typedef struct r300_context r300ContextRec;
 typedef struct r300_context *r300ContextPtr;
@@ -63,13 +56,10 @@ typedef struct r300_context *r300ContextPtr;
 #include "radeon_lock.h"
 #include "mm.h"
 
-/* Checkpoint.. for convenience */
-#define CPT    { fprintf(stderr, "%s:%s line %d\n", __FILE__, __FUNCTION__, __LINE__); }
 /* From http://gcc.gnu.org/onlinedocs/gcc-3.2.3/gcc/Variadic-Macros.html .
    I suppose we could inline this and use macro to fetch out __LINE__ and stuff in case we run into trouble
    with other compilers ... GLUE!
 */
-#if 1
 #define WARN_ONCE(a, ...)      { \
        static int warn##__LINE__=1; \
        if(warn##__LINE__){ \
@@ -81,14 +71,14 @@ typedef struct r300_context *r300ContextPtr;
                warn##__LINE__=0;\
                } \
        }
-#else
-#define WARN_ONCE(a, ...) {}
-#endif
 
 #include "r300_vertprog.h"
 #include "r300_fragprog.h"
 
-static __inline__ uint32_t r300PackFloat32(float fl)
+/**
+ * This function takes a float and packs it into a uint32_t
+ */
+static inline uint32_t r300PackFloat32(float fl)
 {
        union {
                float fl;
@@ -99,12 +89,43 @@ static __inline__ uint32_t r300PackFloat32(float fl)
        return u.u;
 }
 
+/* This is probably wrong for some values, I need to test this
+ * some more.  Range checking would be a good idea also..
+ *
+ * But it works for most things.  I'll fix it later if someone
+ * else with a better clue doesn't
+ */
+static inline uint32_t r300PackFloat24(float f)
+{
+       float mantissa;
+       int exponent;
+       uint32_t float24 = 0;
+
+       if (f == 0.0)
+               return 0;
+
+       mantissa = frexpf(f, &exponent);
+
+       /* Handle -ve */
+       if (mantissa < 0) {
+               float24 |= (1 << 23);
+               mantissa = mantissa * -1.0;
+       }
+       /* Handle exponent, bias of 63 */
+       exponent += 62;
+       float24 |= (exponent << 16);
+       /* Kill 7 LSB of mantissa */
+       float24 |= (r300PackFloat32(mantissa) & 0x7FFFFF) >> 7;
+
+       return float24;
+}
+
 /************ DMA BUFFERS **************/
 
 /* Need refcounting on dma buffers:
  */
 struct r300_dma_buffer {
-       int refcount;           /* the number of retained regions in buf */
+       int refcount;           /**< the number of retained regions in buf */
        drmBufPtr buf;
        int id;
 };
@@ -126,7 +147,6 @@ struct r300_dma_region {
        int aos_offset;         /* address in GART memory */
        int aos_stride;         /* distance between elements, in dwords */
        int aos_size;           /* number of components (1-4) */
-       int aos_reg;            /* VAP register assignment */
 };
 
 struct r300_dma {
@@ -168,6 +188,8 @@ struct r300_tex_obj {
        drm_radeon_tex_image_t image[6][RADEON_MAX_TEXTURE_LEVELS];
        /* Six, for the cube faces */
 
+       GLboolean image_override;       /* Image overridden by GLX_EXT_tfp */
+
        GLuint pitch;           /* this isn't sent to hardware just used in calculations */
        /* hardware register values */
        /* Note that R200 has 8 registers per texture and R300 only 7 */
@@ -308,6 +330,8 @@ struct r300_state_atom {
 #define R300_RI_INTERP_7       8
 #define R300_RI_CMDSIZE                9
 
+#define R500_RI_CMDSIZE               17
+
 #define R300_RR_CMD_0          0       /* rr is variable size (at least 1) */
 #define R300_RR_ROUTE_0                1
 #define R300_RR_ROUTE_1                2
@@ -396,6 +420,13 @@ struct r300_state_atom {
 #define R300_VPP_PARAM_0       1
 #define R300_VPP_CMDSIZE       1025    /* 256 4-component parameters */
 
+#define R300_VPUCP_CMD_0               0
+#define R300_VPUCP_X            1
+#define R300_VPUCP_Y            2
+#define R300_VPUCP_Z            3
+#define R300_VPUCP_W            4
+#define R300_VPUCP_CMDSIZE     5       /* 256 4-component parameters */
+
 #define R300_VPS_CMD_0         0
 #define R300_VPS_ZERO_0                1
 #define R300_VPS_ZERO_1                2
@@ -424,23 +455,23 @@ struct r300_hw_state {
        struct r300_state_atom vap_cntl;
        struct r300_state_atom vof;     /* VAP output format register 0x2090 */
        struct r300_state_atom vte;     /* (20B0) */
-       struct r300_state_atom unk2134; /* (2134) */
+       struct r300_state_atom vap_vf_max_vtx_indx;     /* Maximum Vertex Indx Clamp (2134) */
        struct r300_state_atom vap_cntl_status;
        struct r300_state_atom vir[2];  /* vap input route (2150/21E0) */
        struct r300_state_atom vic;     /* vap input control (2180) */
-       struct r300_state_atom unk21DC; /* (21DC) */
-       struct r300_state_atom unk221C; /* (221C) */
-       struct r300_state_atom unk2220; /* (2220) */
-       struct r300_state_atom unk2288; /* (2288) */
+       struct r300_state_atom vap_psc_sgn_norm_cntl; /* Programmable Stream Control Signed Normalize Control (21DC) */
+       struct r300_state_atom vap_clip_cntl;
+       struct r300_state_atom vap_clip;
+       struct r300_state_atom vap_pvs_vtx_timeout_reg; /* Vertex timeout register (2288) */
        struct r300_state_atom pvs;     /* pvs_cntl (22D0) */
        struct r300_state_atom gb_enable;       /* (4008) */
        struct r300_state_atom gb_misc; /* Multisampling position shifts ? (4010) */
-       struct r300_state_atom unk4200; /* (4200) */
-       struct r300_state_atom unk4214; /* (4214) */
+       struct r300_state_atom ga_point_s0;     /* S Texture Coordinate of Vertex 0 for Point texture stuffing (LLC) (4200) */
+       struct r300_state_atom ga_triangle_stipple;     /* (4214) */
        struct r300_state_atom ps;      /* pointsize (421C) */
-       struct r300_state_atom unk4230; /* (4230) */
+       struct r300_state_atom ga_point_minmax; /* (4230) */
        struct r300_state_atom lcntl;   /* line control */
-       struct r300_state_atom unk4260; /* (4260) */
+       struct r300_state_atom ga_line_stipple; /* (4260) */
        struct r300_state_atom shade;
        struct r300_state_atom polygon_mode;
        struct r300_state_atom fogp;    /* fog parameters (4294) */
@@ -449,40 +480,42 @@ struct r300_hw_state {
        struct r300_state_atom zbs;     /* zbias (42A4) */
        struct r300_state_atom occlusion_cntl;
        struct r300_state_atom cul;     /* cull cntl (42B8) */
-       struct r300_state_atom unk42C0; /* (42C0) */
+       struct r300_state_atom su_depth_scale;  /* (42C0) */
        struct r300_state_atom rc;      /* rs control (4300) */
        struct r300_state_atom ri;      /* rs interpolators (4310) */
        struct r300_state_atom rr;      /* rs route (4330) */
-       struct r300_state_atom unk43A4; /* (43A4) */
-       struct r300_state_atom unk43E8; /* (43E8) */
+       struct r300_state_atom sc_hyperz;       /* (43A4) */
+       struct r300_state_atom sc_screendoor;   /* (43E8) */
        struct r300_state_atom fp;      /* fragment program cntl + nodes (4600) */
        struct r300_state_atom fpt;     /* texi - (4620) */
-       struct r300_state_atom unk46A4; /* (46A4) */
+       struct r300_state_atom us_out_fmt;      /* (46A4) */
+       struct r300_state_atom r500fp;  /* r500 fp instructions */
        struct r300_state_atom fpi[4];  /* fp instructions (46C0/47C0/48C0/49C0) */
        struct r300_state_atom fogs;    /* fog state (4BC0) */
        struct r300_state_atom fogc;    /* fog color (4BC8) */
        struct r300_state_atom at;      /* alpha test (4BD4) */
-       struct r300_state_atom unk4BD8; /* (4BD8) */
+       struct r300_state_atom fg_depth_src;    /* (4BD8) */
        struct r300_state_atom fpp;     /* 0x4C00 and following */
-       struct r300_state_atom unk4E00; /* (4E00) */
+       struct r300_state_atom rb3d_cctl;       /* (4E00) */
        struct r300_state_atom bld;     /* blending (4E04) */
        struct r300_state_atom cmk;     /* colormask (4E0C) */
        struct r300_state_atom blend_color;     /* constant blend color */
        struct r300_state_atom cb;      /* colorbuffer (4E28) */
-       struct r300_state_atom unk4E50; /* (4E50) */
-       struct r300_state_atom unk4E88; /* (4E88) */
-       struct r300_state_atom unk4EA0; /* (4E88) I saw it only written on RV350 hardware..  */
+       struct r300_state_atom rb3d_dither_ctl; /* (4E50) */
+       struct r300_state_atom rb3d_aaresolve_ctl;      /* (4E88) */
+       struct r300_state_atom rb3d_discard_src_pixel_lte_threshold;    /* (4E88) I saw it only written on RV350 hardware..  */
        struct r300_state_atom zs;      /* zstencil control (4F00) */
        struct r300_state_atom zstencil_format;
        struct r300_state_atom zb;      /* z buffer (4F20) */
-       struct r300_state_atom unk4F28; /* (4F28) */
+       struct r300_state_atom zb_depthclearvalue;      /* (4F28) */
        struct r300_state_atom unk4F30; /* (4F30) */
-       struct r300_state_atom unk4F44; /* (4F44) */
-       struct r300_state_atom unk4F54; /* (4F54) */
+       struct r300_state_atom zb_hiz_offset;   /* (4F44) */
+       struct r300_state_atom zb_hiz_pitch;    /* (4F54) */
 
        struct r300_state_atom vpi;     /* vp instructions */
        struct r300_state_atom vpp;     /* vp parameters */
        struct r300_state_atom vps;     /* vertex point size (?) */
+       struct r300_state_atom vpucp[6];        /* vp user clip plane - 6 */
        /* 8 texture units */
        /* the state is grouped by function and not by
           texture unit. This makes single unit updates
@@ -546,38 +579,21 @@ struct r300_vertex_shader_fragment {
        union {
                GLuint d[VSF_MAX_FRAGMENT_LENGTH];
                float f[VSF_MAX_FRAGMENT_LENGTH];
-               VERTEX_SHADER_INSTRUCTION i[VSF_MAX_FRAGMENT_LENGTH / 4];
+               GLuint i[VSF_MAX_FRAGMENT_LENGTH];
        } body;
 };
 
-#define VSF_DEST_PROGRAM       0x0
-#define VSF_DEST_MATRIX0       0x200
-#define VSF_DEST_MATRIX1       0x204
-#define VSF_DEST_MATRIX2       0x208
-#define VSF_DEST_VECTOR0       0x20c
-#define VSF_DEST_VECTOR1       0x20d
-#define VSF_DEST_UNKNOWN1      0x400
-#define VSF_DEST_UNKNOWN2      0x406
-
 struct r300_vertex_shader_state {
        struct r300_vertex_shader_fragment program;
-
-       struct r300_vertex_shader_fragment unknown1;
-       struct r300_vertex_shader_fragment unknown2;
-
-       int program_start;
-       int unknown_ptr1;       /* pointer within program space */
-       int program_end;
-
-       int param_offset;
-       int param_count;
-
-       int unknown_ptr2;       /* pointer within program space */
-       int unknown_ptr3;       /* pointer within program space */
 };
 
 extern int hw_tcl_on;
 
+#define COLOR_IS_RGBA
+#define TAG(x) r300##x
+#include "tnl_dd/t_dd_vertex.h"
+#undef TAG
+
 //#define CURRENT_VERTEX_SHADER(ctx) (ctx->VertexProgram._Current)
 #define CURRENT_VERTEX_SHADER(ctx) (R300_CONTEXT(ctx)->selected_vp)
 
@@ -591,6 +607,7 @@ extern int hw_tcl_on;
 struct r300_vertex_program_key {
        GLuint InputsRead;
        GLuint OutputsWritten;
+       GLuint OutputsAdded;
 };
 
 struct r300_vertex_program {
@@ -758,50 +775,10 @@ struct r300_fragment_program {
 
 #define R300_MAX_AOS_ARRAYS            16
 
-#define AOS_FORMAT_USHORT      0
-#define AOS_FORMAT_FLOAT       1
-#define AOS_FORMAT_UBYTE       2
-#define AOS_FORMAT_FLOAT_COLOR 3
-
 #define REG_COORDS     0
 #define REG_COLOR0     1
 #define REG_TEX0       2
 
-struct dt {
-       GLint size;
-       GLenum type;
-       GLsizei stride;
-       void *data;
-};
-
-struct radeon_vertex_buffer {
-       int Count;
-       void *Elts;
-       int elt_size;
-       int elt_min, elt_max;   /* debug */
-
-       struct dt AttribPtr[VERT_ATTRIB_MAX];
-
-       const struct _mesa_prim *Primitive;
-       GLuint PrimitiveCount;
-       GLint LockFirst;
-       GLsizei LockCount;
-       int lock_uptodate;
-};
-
-struct r300_aos_rec {
-       GLuint offset;
-       int element_size;       /* in dwords */
-       int stride;             /* distance between elements, in dwords */
-
-       int format;
-
-       int ncomponents;        /* number of components - between 1 and 4, inclusive */
-
-       int reg;                /* which register they are assigned to. */
-
-};
-
 struct r300_state {
        struct r300_depthbuffer_state depth;
        struct r300_texture_state texture;
@@ -810,18 +787,14 @@ struct r300_state {
        struct r300_pfs_compile_state pfs_compile;
        struct r300_dma_region aos[R300_MAX_AOS_ARRAYS];
        int aos_count;
-       struct radeon_vertex_buffer VB;
 
        GLuint *Elts;
        struct r300_dma_region elt_dma;
 
-        DECLARE_RENDERINPUTS(render_inputs_bitset);    /* actual render inputs that R300 was configured for.
+       struct r300_dma_region swtcl_dma;
+       DECLARE_RENDERINPUTS(render_inputs_bitset);     /* actual render inputs that R300 was configured for.
                                                           They are the same as tnl->render_inputs for fixed pipeline */
 
-       struct {
-               int transform_offset;   /* Transform matrix offset, -1 if none */
-       } vap_param;            /* vertex processor parameter allocation - tells where to write parameters */
-
        struct r300_stencilbuffer_state stencil;
 
 };
@@ -830,8 +803,64 @@ struct r300_state {
 #define R300_FALLBACK_TCL 1
 #define R300_FALLBACK_RAST 2
 
+/* r300_swtcl.c
+ */
+struct r300_swtcl_info {
+   GLuint RenderIndex;
+   
+   /**
+    * Size of a hardware vertex.  This is calculated when \c ::vertex_attrs is
+    * installed in the Mesa state vector.
+    */
+   GLuint vertex_size;
+
+   /**
+    * Attributes instructing the Mesa TCL pipeline where / how to put vertex
+    * data in the hardware buffer.
+    */
+   struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
+
+   /**
+    * Number of elements of \c ::vertex_attrs that are actually used.
+    */
+   GLuint vertex_attr_count;
+
+   /**
+    * Cached pointer to the buffer where Mesa will store vertex data.
+    */
+   GLubyte *verts;
+
+   /* Fallback rasterization functions
+    */
+  //   r200_point_func draw_point;
+  //   r200_line_func draw_line;
+  //   r200_tri_func draw_tri;
+
+   GLuint hw_primitive;
+   GLenum render_primitive;
+   GLuint numverts;
+
+   /**
+    * Offset of the 4UB color data within a hardware (swtcl) vertex.
+    */
+   GLuint coloroffset;
+
+   /**
+    * Offset of the 3UB specular color data within a hardware (swtcl) vertex.
+    */
+   GLuint specoffset;
+
+   /**
+    * Should Mesa project vertex data or will the hardware do it?
+    */
+   GLboolean needproj;
+
+   struct r300_dma_region indexed_verts;
+};
+
+
 /**
- * R300 context structure.
+ * \brief R300 context structure.
  */
 struct r300_context {
        struct radeon_context radeon;   /* parent class, must be first */
@@ -861,14 +890,16 @@ struct r300_context {
        GLuint prefer_gart_client_texturing;
 
 #ifdef USER_BUFFERS
-       struct radeon_memory_manager *rmm;
+       struct r300_memory_manager *rmm;
+#endif
+
        GLvector4f dummy_attrib[_TNL_ATTRIB_MAX];
        GLvector4f *temp_attrib[_TNL_ATTRIB_MAX];
-#endif
 
-       GLboolean texmicrotile;
-       GLboolean span_dlocking;
        GLboolean disable_lowimpact_fallback;
+
+       DECLARE_RENDERINPUTS(tnl_index_bitset); /* index of bits for last tnl_install_attrs */
+       struct r300_swtcl_info swtcl;
 };
 
 struct r300_buffer_object {
@@ -878,34 +909,16 @@ struct r300_buffer_object {
 
 #define R300_CONTEXT(ctx)              ((r300ContextPtr)(ctx->DriverCtx))
 
-static __inline GLuint r300PackColor(GLuint cpp,
-                                    GLubyte r, GLubyte g, GLubyte b, GLubyte a)
-{
-       switch (cpp) {
-       case 2:
-               return PACK_COLOR_565(r, g, b);
-       case 4:
-               return PACK_COLOR_8888(r, g, b, a);
-       default:
-               return 0;
-       }
-}
 extern void r300DestroyContext(__DRIcontextPrivate * driContextPriv);
 extern GLboolean r300CreateContext(const __GLcontextModes * glVisual,
                                   __DRIcontextPrivate * driContextPriv,
                                   void *sharedContextPrivate);
 
-extern int r300NumVerts(r300ContextPtr rmesa, int num_verts, int prim);
-
 extern void r300SelectVertexShader(r300ContextPtr r300);
 extern void r300InitShaderFuncs(struct dd_function_table *functions);
 extern int r300VertexProgUpdateParams(GLcontext * ctx,
                                      struct r300_vertex_program_cont *vp,
                                      float *dst);
-extern int r300Fallback(GLcontext * ctx);
-
-extern GLboolean r300RunRender(GLcontext * ctx,
-                              struct tnl_pipeline_stage *stage);
 
 #define RADEON_D_CAPTURE 0
 #define RADEON_D_PLAYBACK 1