svga: implement support for signed byte vertex attributes
[mesa.git] / src / gallium / drivers / svga / svga_swtnl_state.c
index a75923829364190c4a1c8f2812c3c442c2e39078..e62698e11f4d76eb51414dd1627403968ffc6516 100644 (file)
 #include "svga_context.h"
 #include "svga_swtnl.h"
 #include "svga_state.h"
-
+#include "svga_tgsi.h"
 #include "svga_swtnl_private.h"
 
 
-#define SVGA_POINT_ADJ_X -0.375
-#define SVGA_POINT_ADJ_Y -0.5
+#define SVGA_POINT_ADJ_X -0.375f
+#define SVGA_POINT_ADJ_Y -0.5f
 
-#define SVGA_LINE_ADJ_X -0.5
-#define SVGA_LINE_ADJ_Y -0.5
+#define SVGA_LINE_ADJ_X -0.5f
+#define SVGA_LINE_ADJ_Y -0.5f
 
-#define SVGA_TRIANGLE_ADJ_X -0.375
-#define SVGA_TRIANGLE_ADJ_Y -0.5
+#define SVGA_TRIANGLE_ADJ_X -0.375f
+#define SVGA_TRIANGLE_ADJ_Y -0.5f
 
 
 static void set_draw_viewport( struct svga_context *svga )
 {
    struct pipe_viewport_state vp = svga->curr.viewport;
-   float adjx = 0;
-   float adjy = 0;
+   float adjx = 0.0f;
+   float adjy = 0.0f;
 
    switch (svga->curr.reduced_prim) {
    case PIPE_PRIM_POINTS:
@@ -61,10 +61,10 @@ static void set_draw_viewport( struct svga_context *svga )
        * going to be drawn with triangles, but we're not catching all
        * cases where that will happen.
        */
-      if (svga->curr.rast->templ.line_width > 1.0) 
+      if (svga->curr.rast->need_pipeline & SVGA_PIPELINE_FLAG_LINES)
       {
-         adjx = SVGA_LINE_ADJ_X + 0.175;
-         adjy = SVGA_LINE_ADJ_Y - 0.175;
+         adjx = SVGA_LINE_ADJ_X + 0.175f;
+         adjy = SVGA_LINE_ADJ_Y - 0.175f;
       }
       else {
          adjx = SVGA_LINE_ADJ_X;
@@ -80,11 +80,12 @@ static void set_draw_viewport( struct svga_context *svga )
    vp.translate[0] += adjx;
    vp.translate[1] += adjy;
 
-   draw_set_viewport_state(svga->swtnl.draw, &vp);
+   draw_set_viewport_states(svga->swtnl.draw, 0, 1, &vp);
 }
 
-static int update_swtnl_draw( struct svga_context *svga,
-                              unsigned dirty )
+static enum pipe_error
+update_swtnl_draw( struct svga_context *svga,
+                   unsigned dirty )
 {
    draw_flush( svga->swtnl.draw );
 
@@ -92,8 +93,12 @@ static int update_swtnl_draw( struct svga_context *svga,
       draw_bind_vertex_shader(svga->swtnl.draw,
                               svga->curr.vs->draw_shader);
 
+   if (dirty & SVGA_NEW_FS) 
+      draw_bind_fragment_shader(svga->swtnl.draw,
+                                svga->curr.fs->draw_shader);
+
    if (dirty & SVGA_NEW_VBUFFER)
-      draw_set_vertex_buffers(svga->swtnl.draw, 
+      draw_set_vertex_buffers(svga->swtnl.draw, 0,
                               svga->curr.num_vertex_buffers, 
                               svga->curr.vb);
 
@@ -116,11 +121,17 @@ static int update_swtnl_draw( struct svga_context *svga,
                                 &svga->curr.rast->templ,
                                 (void *) svga->curr.rast);
 
+   /* Tell the draw module how deep the Z/depth buffer is.
+    *
+    * If no depth buffer is bound, send the utility function the
+    * format for no bound depth (PIPE_FORMAT_NONE).
+    */
    if (dirty & SVGA_NEW_FRAME_BUFFER)
-      draw_set_mrd(svga->swtnl.draw, 
-                   svga->curr.depthscale);
+      draw_set_zs_format(svga->swtnl.draw, 
+         (svga->curr.framebuffer.zsbuf) ?
+             svga->curr.framebuffer.zsbuf->format : PIPE_FORMAT_NONE);
 
-   return 0;
+   return PIPE_OK;
 }
 
 
@@ -139,7 +150,8 @@ struct svga_tracked_state svga_update_swtnl_draw =
 };
 
 
-int svga_swtnl_update_vdecl( struct svga_context *svga )
+enum pipe_error
+svga_swtnl_update_vdecl( struct svga_context *svga )
 {
    struct svga_vbuf_render *svga_render = svga_vbuf_render(svga->swtnl.backend);
    struct draw_context *draw = svga->swtnl.draw;
@@ -147,14 +159,16 @@ int svga_swtnl_update_vdecl( struct svga_context *svga )
    SVGA3dVertexDecl vdecl[PIPE_MAX_ATTRIBS];
    const enum interp_mode colorInterp =
       svga->curr.rast->templ.flatshade ? INTERP_CONSTANT : INTERP_LINEAR;
-   const struct svga_fragment_shader *fs = svga->curr.fs;
+   struct svga_fragment_shader *fs = svga->curr.fs;
    int offset = 0;
    int nr_decls = 0;
-   int src, i;
+   int src;
+   unsigned i;
 
    memset(vinfo, 0, sizeof(*vinfo));
    memset(vdecl, 0, sizeof(vdecl));
 
+   draw_prepare_shader_outputs(draw);
    /* always add position */
    src = draw_find_shader_output(draw, TGSI_SEMANTIC_POSITION, 0);
    draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_LINEAR, src);
@@ -167,13 +181,15 @@ int svga_swtnl_update_vdecl( struct svga_context *svga )
    nr_decls++;
 
    for (i = 0; i < fs->base.info.num_inputs; i++) {
-      unsigned name = fs->base.info.input_semantic_name[i];
-      unsigned index = fs->base.info.input_semantic_index[i];
-      src = draw_find_shader_output(draw, name, index);
+      const unsigned sem_name = fs->base.info.input_semantic_name[i];
+      const unsigned sem_index = fs->base.info.input_semantic_index[i];
+
+      src = draw_find_shader_output(draw, sem_name, sem_index);
+
       vdecl[nr_decls].array.offset = offset;
-      vdecl[nr_decls].identity.usageIndex = fs->base.info.input_semantic_index[i];
+      vdecl[nr_decls].identity.usageIndex = sem_index;
 
-      switch (name) {
+      switch (sem_name) {
       case TGSI_SEMANTIC_COLOR:
          draw_emit_vertex_attr(vinfo, EMIT_4F, colorInterp, src);
          vdecl[nr_decls].identity.usage = SVGA3D_DECLUSAGE_COLOR;
@@ -185,7 +201,8 @@ int svga_swtnl_update_vdecl( struct svga_context *svga )
          draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, src);
          vdecl[nr_decls].identity.usage = SVGA3D_DECLUSAGE_TEXCOORD;
          vdecl[nr_decls].identity.type = SVGA3D_DECLTYPE_FLOAT4;
-         vdecl[nr_decls].identity.usageIndex += 1;
+         vdecl[nr_decls].identity.usageIndex =
+            svga_remap_generic_index(fs->generic_remap_table, sem_index);
          offset += 16;
          nr_decls++;
          break;
@@ -212,17 +229,18 @@ int svga_swtnl_update_vdecl( struct svga_context *svga )
       vdecl[i].array.stride = offset;
 
    if (memcmp(svga_render->vdecl, vdecl, sizeof(vdecl)) == 0)
-      return 0;
+      return PIPE_OK;
 
    memcpy(svga_render->vdecl, vdecl, sizeof(vdecl));
    svga->swtnl.new_vdecl = TRUE;
 
-   return 0;
+   return PIPE_OK;
 }
 
 
-static int update_swtnl_vdecl( struct svga_context *svga,
-                               unsigned dirty )
+static enum pipe_error
+update_swtnl_vdecl( struct svga_context *svga,
+                    unsigned dirty )
 {
    return svga_swtnl_update_vdecl( svga );
 }