Merge branch '7.8'
[mesa.git] / src / gallium / drivers / i915 / i915_state.c
index 7d48e6e84d58a00c795d9699db05e43ce3d31fdc..377d8425a5cb11238969c7fe30ed63b76fddff78 100644 (file)
 
 
 #include "draw/draw_context.h"
-#include "pipe/internal/p_winsys_screen.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
 #include "tgsi/tgsi_parse.h"
 
 #include "i915_context.h"
 #include "i915_reg.h"
-#include "i915_state.h"
 #include "i915_state_inlines.h"
 #include "i915_fpc.h"
 
@@ -58,8 +56,10 @@ translate_wrap_mode(unsigned wrap)
       return TEXCOORDMODE_CLAMP_EDGE;
    case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
       return TEXCOORDMODE_CLAMP_BORDER;
-//   case PIPE_TEX_WRAP_MIRRORED_REPEAT:
-//      return TEXCOORDMODE_MIRROR;
+   /*         
+   case PIPE_TEX_WRAP_MIRRORED_REPEAT:
+      return TEXCOORDMODE_MIRROR;
+    */
    default:
       return TEXCOORDMODE_WRAP;
    }
@@ -72,8 +72,6 @@ static unsigned translate_img_filter( unsigned filter )
       return FILTER_NEAREST;
    case PIPE_TEX_FILTER_LINEAR:
       return FILTER_LINEAR;
-   case PIPE_TEX_FILTER_ANISO:
-      return FILTER_ANISOTROPIC;
    default:
       assert(0);
       return FILTER_NEAREST;
@@ -105,13 +103,13 @@ i915_create_blend_state(struct pipe_context *pipe,
    struct i915_blend_state *cso_data = CALLOC_STRUCT( i915_blend_state );
 
    {
-      unsigned eqRGB  = blend->rgb_func;
-      unsigned srcRGB = blend->rgb_src_factor;
-      unsigned dstRGB = blend->rgb_dst_factor;
+      unsigned eqRGB  = blend->rt[0].rgb_func;
+      unsigned srcRGB = blend->rt[0].rgb_src_factor;
+      unsigned dstRGB = blend->rt[0].rgb_dst_factor;
 
-      unsigned eqA    = blend->alpha_func;
-      unsigned srcA   = blend->alpha_src_factor;
-      unsigned dstA   = blend->alpha_dst_factor;
+      unsigned eqA    = blend->rt[0].alpha_func;
+      unsigned srcA   = blend->rt[0].alpha_src_factor;
+      unsigned dstA   = blend->rt[0].alpha_dst_factor;
 
       /* Special handling for MIN/MAX filter modes handled at
        * state_tracker level.
@@ -148,22 +146,22 @@ i915_create_blend_state(struct pipe_context *pipe,
    if (blend->dither)
       cso_data->LIS5 |= S5_COLOR_DITHER_ENABLE;
 
-   if ((blend->colormask & PIPE_MASK_R) == 0)
+   if ((blend->rt[0].colormask & PIPE_MASK_R) == 0)
       cso_data->LIS5 |= S5_WRITEDISABLE_RED;
 
-   if ((blend->colormask & PIPE_MASK_G) == 0)
+   if ((blend->rt[0].colormask & PIPE_MASK_G) == 0)
       cso_data->LIS5 |= S5_WRITEDISABLE_GREEN;
 
-   if ((blend->colormask & PIPE_MASK_B) == 0)
+   if ((blend->rt[0].colormask & PIPE_MASK_B) == 0)
       cso_data->LIS5 |= S5_WRITEDISABLE_BLUE;
 
-   if ((blend->colormask & PIPE_MASK_A) == 0)
+   if ((blend->rt[0].colormask & PIPE_MASK_A) == 0)
       cso_data->LIS5 |= S5_WRITEDISABLE_ALPHA;
 
-   if (blend->blend_enable) {
-      unsigned funcRGB = blend->rgb_func;
-      unsigned srcRGB  = blend->rgb_src_factor;
-      unsigned dstRGB  = blend->rgb_dst_factor;
+   if (blend->rt[0].blend_enable) {
+      unsigned funcRGB = blend->rt[0].rgb_func;
+      unsigned srcRGB  = blend->rt[0].rgb_src_factor;
+      unsigned dstRGB  = blend->rt[0].rgb_dst_factor;
 
       cso_data->LIS6 |= (S6_CBUF_BLEND_ENABLE |
                          SRC_BLND_FACT(i915_translate_blend_factor(srcRGB)) |
@@ -192,7 +190,7 @@ static void i915_delete_blend_state(struct pipe_context *pipe, void *blend)
 }
 
 static void i915_set_blend_color( struct pipe_context *pipe,
-                            const struct pipe_blend_color *blend_color )
+                                  const struct pipe_blend_color *blend_color )
 {
    struct i915_context *i915 = i915_context(pipe);
    draw_flush(i915->draw);
@@ -202,6 +200,17 @@ static void i915_set_blend_color( struct pipe_context *pipe,
    i915->dirty |= I915_NEW_BLEND;
 }
 
+static void i915_set_stencil_ref( struct pipe_context *pipe,
+                                  const struct pipe_stencil_ref *stencil_ref )
+{
+   struct i915_context *i915 = i915_context(pipe);
+   draw_flush(i915->draw);
+
+   i915->stencil_ref = *stencil_ref;
+
+   i915->dirty |= I915_NEW_DEPTH_STENCIL;
+}
+
 static void *
 i915_create_sampler_state(struct pipe_context *pipe,
                           const struct pipe_sampler_state *sampler)
@@ -219,7 +228,10 @@ i915_create_sampler_state(struct pipe_context *pipe,
    minFilt = translate_img_filter( sampler->min_img_filter );
    magFilt = translate_img_filter( sampler->mag_img_filter );
    
-   if (sampler->max_anisotropy > 2.0) {
+   if (sampler->max_anisotropy > 1)
+      minFilt = magFilt = FILTER_ANISOTROPIC;
+
+   if (sampler->max_anisotropy > 2) {
       cso->state[0] |= SS2_MAX_ANISO_4;
    }
 
@@ -333,11 +345,9 @@ i915_create_depth_stencil_state(struct pipe_context *pipe,
       int fop  = i915_translate_stencil_op(depth_stencil->stencil[0].fail_op);
       int dfop = i915_translate_stencil_op(depth_stencil->stencil[0].zfail_op);
       int dpop = i915_translate_stencil_op(depth_stencil->stencil[0].zpass_op);
-      int ref  = depth_stencil->stencil[0].ref_value & 0xff;
 
       cso->stencil_LIS5 |= (S5_STENCIL_TEST_ENABLE |
                             S5_STENCIL_WRITE_ENABLE |
-                            (ref  << S5_STENCIL_REF_SHIFT) |
                             (test << S5_STENCIL_TEST_FUNC_SHIFT) |
                             (fop  << S5_STENCIL_FAIL_SHIFT) |
                             (dfop << S5_STENCIL_PASS_Z_FAIL_SHIFT) |
@@ -349,7 +359,6 @@ i915_create_depth_stencil_state(struct pipe_context *pipe,
       int fop   = i915_translate_stencil_op(depth_stencil->stencil[1].fail_op);
       int dfop  = i915_translate_stencil_op(depth_stencil->stencil[1].zfail_op);
       int dpop  = i915_translate_stencil_op(depth_stencil->stencil[1].zpass_op);
-      int ref   = depth_stencil->stencil[1].ref_value & 0xff;
       int tmask = depth_stencil->stencil[1].valuemask & 0xff;
       int wmask = depth_stencil->stencil[1].writemask & 0xff;
 
@@ -358,7 +367,6 @@ i915_create_depth_stencil_state(struct pipe_context *pipe,
                      BFO_ENABLE_STENCIL_TWO_SIDE |
                      BFO_ENABLE_STENCIL_REF |
                      BFO_STENCIL_TWO_SIDE |
-                     (ref  << BFO_STENCIL_REF_SHIFT) |
                      (test << BFO_STENCIL_TEST_SHIFT) |
                      (fop  << BFO_STENCIL_FAIL_SHIFT) |
                      (dfop << BFO_STENCIL_PASS_Z_FAIL_SHIFT) |
@@ -515,7 +523,7 @@ static void i915_delete_vs_state(struct pipe_context *pipe, void *shader)
 
 static void i915_set_constant_buffer(struct pipe_context *pipe,
                                      uint shader, uint index,
-                                     const struct pipe_constant_buffer *buf)
+                                     struct pipe_buffer *buf)
 {
    struct i915_context *i915 = i915_context(pipe);
    struct pipe_screen *screen = pipe->screen;
@@ -535,13 +543,13 @@ static void i915_set_constant_buffer(struct pipe_context *pipe,
     */
    if (buf) {
       void *mapped;
-      if (buf->buffer && buf->buffer->size &&
-          (mapped = pipe_buffer_map(screen, buf->buffer,
+      if (buf->size &&
+          (mapped = pipe_buffer_map(screen, buf,
                                     PIPE_BUFFER_USAGE_CPU_READ))) {
-         memcpy(i915->current.constants[shader], mapped, buf->buffer->size);
-         pipe_buffer_unmap(screen, buf->buffer);
+         memcpy(i915->current.constants[shader], mapped, buf->size);
+         pipe_buffer_unmap(screen, buf);
          i915->current.num_user_constants[shader]
-            = buf->buffer->size / (4 * sizeof(float));
+            = buf->size / (4 * sizeof(float));
       }
       else {
          i915->current.num_user_constants[shader] = 0;
@@ -734,38 +742,55 @@ static void i915_set_vertex_buffers(struct pipe_context *pipe,
    draw_set_vertex_buffers(i915->draw, count, buffers);
 }
 
-static void i915_set_vertex_elements(struct pipe_context *pipe,
-                                     unsigned count,
-                                     const struct pipe_vertex_element *elements)
+static void *
+i915_create_vertex_elements_state(struct pipe_context *pipe,
+                                  unsigned count,
+                                  const struct pipe_vertex_element *attribs)
+{
+   struct i915_velems_state *velems;
+   assert(count <= PIPE_MAX_ATTRIBS);
+   velems = (struct i915_velems_state *) MALLOC(sizeof(struct i915_velems_state));
+   if (velems) {
+      velems->count = count;
+      memcpy(velems->velem, attribs, sizeof(*attribs) * count);
+   }
+   return velems;
+}
+
+static void
+i915_bind_vertex_elements_state(struct pipe_context *pipe,
+                                void *velems)
 {
    struct i915_context *i915 = i915_context(pipe);
+   struct i915_velems_state *i915_velems = (struct i915_velems_state *) velems;
+
    /* Because we change state before the draw_set_vertex_buffers call
     * we need a flush here, just to be sure.
     */
    draw_flush(i915->draw);
 
-   i915->num_vertex_elements = count;
    /* pass-through to draw module */
-   draw_set_vertex_elements(i915->draw, count, elements);
+   if (i915_velems) {
+      draw_set_vertex_elements(i915->draw,
+            i915_velems->count, i915_velems->velem);
+   }
 }
 
-
-static void i915_set_edgeflags(struct pipe_context *pipe,
-                               const unsigned *bitfield)
+static void
+i915_delete_vertex_elements_state(struct pipe_context *pipe, void *velems)
 {
-   /* TODO do something here */
+   FREE( velems );
 }
 
 void
 i915_init_state_functions( struct i915_context *i915 )
 {
-   i915->base.set_edgeflags = i915_set_edgeflags;
    i915->base.create_blend_state = i915_create_blend_state;
    i915->base.bind_blend_state = i915_bind_blend_state;
    i915->base.delete_blend_state = i915_delete_blend_state;
 
    i915->base.create_sampler_state = i915_create_sampler_state;
-   i915->base.bind_sampler_states = i915_bind_sampler_states;
+   i915->base.bind_fragment_sampler_states = i915_bind_sampler_states;
    i915->base.delete_sampler_state = i915_delete_sampler_state;
 
    i915->base.create_depth_stencil_alpha_state = i915_create_depth_stencil_state;
@@ -781,16 +806,19 @@ i915_init_state_functions( struct i915_context *i915 )
    i915->base.create_vs_state = i915_create_vs_state;
    i915->base.bind_vs_state = i915_bind_vs_state;
    i915->base.delete_vs_state = i915_delete_vs_state;
+   i915->base.create_vertex_elements_state = i915_create_vertex_elements_state;
+   i915->base.bind_vertex_elements_state = i915_bind_vertex_elements_state;
+   i915->base.delete_vertex_elements_state = i915_delete_vertex_elements_state;
 
    i915->base.set_blend_color = i915_set_blend_color;
+   i915->base.set_stencil_ref = i915_set_stencil_ref;
    i915->base.set_clip_state = i915_set_clip_state;
    i915->base.set_constant_buffer = i915_set_constant_buffer;
    i915->base.set_framebuffer_state = i915_set_framebuffer_state;
 
    i915->base.set_polygon_stipple = i915_set_polygon_stipple;
    i915->base.set_scissor_state = i915_set_scissor_state;
-   i915->base.set_sampler_textures = i915_set_sampler_textures;
+   i915->base.set_fragment_sampler_textures = i915_set_sampler_textures;
    i915->base.set_viewport_state = i915_set_viewport_state;
    i915->base.set_vertex_buffers = i915_set_vertex_buffers;
-   i915->base.set_vertex_elements = i915_set_vertex_elements;
 }