Squashed commit of the following:
[mesa.git] / src / gallium / drivers / i965 / brw_wm.c
index 90780272da57cfac47780af7fe7a4f1447037682..5d66e61fbc1384e9ed9f62aad1ccb912b87957ef 100644 (file)
   * Authors:
   *   Keith Whitwell <keith@tungstengraphics.com>
   */
-#include "pipe/p_error.h"
-
 #include "tgsi/tgsi_info.h"
 
 #include "brw_context.h"
 #include "brw_screen.h"
-#include "brw_util.h"
 #include "brw_wm.h"
 #include "brw_state.h"
 #include "brw_debug.h"
+#include "brw_resource.h"
 #include "brw_pipe_rast.h"
 
 
@@ -58,6 +56,15 @@ GLuint brw_wm_nr_args( GLuint opcode )
    case WM_FB_WRITE:
    case WM_PINTERP:
       return 3;
+   case TGSI_OPCODE_TEX:
+   case TGSI_OPCODE_TXP:
+   case TGSI_OPCODE_TXB:
+   case TGSI_OPCODE_TXD:
+      /* sampler arg is held as a field in the instruction, not in an
+       * actual register:
+       */
+      return tgsi_get_opcode_info(opcode)->num_src - 1;
+
    default:
       assert(opcode < MAX_OPCODE);
       return tgsi_get_opcode_info(opcode)->num_src;
@@ -139,38 +146,31 @@ brw_wm_linear_shader_emit(struct brw_context *brw, struct brw_wm_compile *c)
  * Depending on the instructions used (i.e. flow control instructions)
  * we'll use one of two code generators.
  */
-static int do_wm_prog( struct brw_context *brw,
-                       struct brw_fragment_shader *fp, 
-                       struct brw_wm_prog_key *key)
+static enum pipe_error do_wm_prog( struct brw_context *brw,
+                                   struct brw_fragment_shader *fp, 
+                                   struct brw_wm_prog_key *key,
+                                   struct brw_winsys_buffer **bo_out)
 {
+   enum pipe_error ret;
    struct brw_wm_compile *c;
    const GLuint *program;
    GLuint program_size;
 
-   c = brw->wm.compile_data;
-   if (c == NULL) {
-      brw->wm.compile_data = calloc(1, sizeof(*brw->wm.compile_data));
-      c = brw->wm.compile_data;
-      if (c == NULL) {
-         /* Ouch - big out of memory problem.  Can't continue
-          * without triggering a segfault, no way to signal,
-          * so just return.
-          */
+   if (brw->wm.compile_data == NULL) {
+      brw->wm.compile_data = MALLOC(sizeof(*brw->wm.compile_data));
+      if (!brw->wm.compile_data) 
          return PIPE_ERROR_OUT_OF_MEMORY;
-      }
-   } else {
-      memset(c, 0, sizeof(*brw->wm.compile_data));
    }
-   memcpy(&c->key, key, sizeof(*key));
 
+   c = brw->wm.compile_data;
+   memset(c, 0, sizeof *c);
+
+   c->key = *key;
    c->fp = fp;
    c->env_param = NULL; /*brw->intel.ctx.FragmentProgram.Parameters;*/
 
    brw_init_compile(brw, &c->func);
 
-   /* temporary sanity check assertion */
-   assert(fp->has_flow_control == brw_wm_has_flow_control(c->fp));
-
    /*
     * Shader which use GLSL features such as flow control are handled
     * differently from "simple" shaders.
@@ -180,7 +180,7 @@ static int do_wm_prog( struct brw_context *brw,
       /* XXX: GLSL support
        */
       exit(1);
-      //brw_wm_branching_shader_emit(brw, c);
+      /* brw_wm_branching_shader_emit(brw, c); */
    }
    else {
       c->dispatch_width = 16;
@@ -192,17 +192,21 @@ static int do_wm_prog( struct brw_context *brw,
 
    /* get the program
     */
-   program = brw_get_program(&c->func, &program_size);
-
-   brw->sws->bo_unreference(brw->wm.prog_bo);
-   brw->wm.prog_bo = brw_upload_cache( &brw->cache, BRW_WM_PROG,
-                                      &c->key, sizeof(c->key),
-                                      NULL, 0,
-                                      program, program_size,
-                                      &c->prog_data,
-                                      &brw->wm.prog_data );
-
-   return 0;
+   ret = brw_get_program(&c->func, &program, &program_size);
+   if (ret)
+      return ret;
+
+   ret = brw_upload_cache( &brw->cache, BRW_WM_PROG,
+                           &c->key, sizeof(c->key),
+                           NULL, 0,
+                           program, program_size,
+                           &c->prog_data,
+                           &brw->wm.prog_data,
+                           bo_out );
+   if (ret)
+      return ret;
+
+   return PIPE_OK;
 }
 
 
@@ -230,7 +234,8 @@ static void brw_wm_populate_key( struct brw_context *brw,
       line_aa = AA_NEVER;
       break;
    case PIPE_PRIM_LINES:
-      line_aa = AA_ALWAYS;
+      line_aa = (brw->curr.rast->templ.line_smooth ? 
+                 AA_ALWAYS : AA_NEVER);
       break;
    default:
       line_aa = brw->curr.rast->unfilled_aa_line;
@@ -247,13 +252,13 @@ static void brw_wm_populate_key( struct brw_context *brw,
 
 
    /* PIPE_NEW_BOUND_TEXTURES */
-   for (i = 0; i < brw->curr.num_textures; i++) {
-      const struct brw_texture *tex = brw_texture(brw->curr.texture[i]);
+   for (i = 0; i < brw->curr.num_fragment_sampler_views; i++) {
+      const struct brw_texture *tex = brw_texture(brw->curr.fragment_sampler_views[i]->texture);
         
-      if (tex->base.format == PIPE_FORMAT_YCBCR)
+      if (tex->b.b.format == PIPE_FORMAT_UYVY)
         key->yuvtex_mask |= 1 << i;
 
-      if (tex->base.format == PIPE_FORMAT_YCBCR_REV)
+      if (tex->b.b.format == PIPE_FORMAT_YUYV)
         key->yuvtex_swap_mask |= 1 << i;
 
       /* XXX: shadow texture
@@ -264,29 +269,37 @@ static void brw_wm_populate_key( struct brw_context *brw,
    /* CACHE_NEW_VS_PROG */
    key->vp_nr_outputs = brw->vs.prog_data->nr_outputs;
 
+   key->nr_cbufs = brw->curr.fb.nr_cbufs;
+
+   key->nr_inputs = brw->curr.fragment_shader->info.num_inputs;
+
    /* The unique fragment program ID */
    key->program_string_id = brw->curr.fragment_shader->id;
 }
 
 
-static int brw_prepare_wm_prog(struct brw_context *brw)
+static enum pipe_error brw_prepare_wm_prog(struct brw_context *brw)
 {
    struct brw_wm_prog_key key;
    struct brw_fragment_shader *fs = brw->curr.fragment_shader;
+   enum pipe_error ret;
      
    brw_wm_populate_key(brw, &key);
 
    /* Make an early check for the key.
     */
-   brw->sws->bo_unreference(brw->wm.prog_bo);
-   brw->wm.prog_bo = brw_search_cache(&brw->cache, BRW_WM_PROG,
-                                     &key, sizeof(key),
-                                     NULL, 0,
-                                     &brw->wm.prog_data);
-   if (brw->wm.prog_bo == NULL)
-      return do_wm_prog(brw, fs, &key);
-
-   return 0;
+   if (brw_search_cache(&brw->cache, BRW_WM_PROG,
+                        &key, sizeof(key),
+                        NULL, 0,
+                        &brw->wm.prog_data,
+                        &brw->wm.prog_bo))
+      return PIPE_OK;
+
+   ret = do_wm_prog(brw, fs, &key, &brw->wm.prog_bo);
+   if (ret)
+      return ret;
+
+   return PIPE_OK;
 }
 
 
@@ -295,6 +308,7 @@ const struct brw_tracked_state brw_wm_prog = {
       .mesa  = (PIPE_NEW_FRAGMENT_SHADER |
                PIPE_NEW_DEPTH_STENCIL_ALPHA |
                PIPE_NEW_RAST |
+               PIPE_NEW_NR_CBUFS |
                PIPE_NEW_BOUND_TEXTURES),
       .brw   = (BRW_NEW_WM_INPUT_DIMENSIONS |
                BRW_NEW_REDUCED_PRIMITIVE),