gallium: Add support for multiple viewports
[mesa.git] / src / gallium / drivers / svga / svga_swtnl_state.c
index 246d34e649efe1bba1d4a21de27663c0073e47ad..d744f18ee72fc3845a423ea49710448314a54047 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);
 
@@ -113,7 +118,8 @@ static int update_swtnl_draw( struct svga_context *svga,
 
    if (dirty & SVGA_NEW_RAST)
       draw_set_rasterizer_state(svga->swtnl.draw,
-                                &svga->curr.rast->templ);
+                                &svga->curr.rast->templ,
+                                (void *) svga->curr.rast);
 
    if (dirty & SVGA_NEW_FRAME_BUFFER)
       draw_set_mrd(svga->swtnl.draw, 
@@ -138,7 +144,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;
@@ -146,10 +153,11 @@ 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));
@@ -166,13 +174,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;
@@ -184,7 +194,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;
@@ -220,8 +231,9 @@ int svga_swtnl_update_vdecl( struct svga_context *svga )
 }
 
 
-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 );
 }