Merge remote branch 'origin/master' into pipe-video
[mesa.git] / src / mesa / drivers / dri / i965 / brw_fs.cpp
index 5f6deb841cd5fc39c99ca983384baf4466f99b31..283d5aad496fc1e431fc896838b5f0acc725ca2e 100644 (file)
@@ -89,8 +89,6 @@ brw_compile_shader(struct gl_context *ctx, struct gl_shader *shader)
 GLboolean
 brw_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
 {
-   struct intel_context *intel = intel_context(ctx);
-
    struct brw_shader *shader =
       (struct brw_shader *)prog->_LinkedShaders[MESA_SHADER_FRAGMENT];
    if (shader != NULL) {
@@ -132,9 +130,6 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
                                                GL_TRUE, /* temp */
                                                GL_TRUE /* uniform */
                                                ) || progress;
-        if (intel->gen == 6) {
-           progress = do_if_to_cond_assign(shader->ir) || progress;
-        }
       } while (progress);
 
       validate_ir_tree(shader->ir);
@@ -228,6 +223,7 @@ brw_type_for_base_type(const struct glsl_type *type)
       return BRW_REGISTER_TYPE_UD;
    case GLSL_TYPE_ARRAY:
    case GLSL_TYPE_STRUCT:
+   case GLSL_TYPE_SAMPLER:
       /* These should be overridden with the type of the member when
        * dereferenced into.  BRW_REGISTER_TYPE_UD seems like a likely
        * way to trip up if we don't.
@@ -286,8 +282,26 @@ fs_visitor::setup_uniform_values(int loc, const glsl_type *type)
    case GLSL_TYPE_BOOL:
       vec_values = fp->Base.Parameters->ParameterValues[loc];
       for (unsigned int i = 0; i < type->vector_elements; i++) {
-        assert(c->prog_data.nr_params < ARRAY_SIZE(c->prog_data.param));
-        c->prog_data.param[c->prog_data.nr_params++] = &vec_values[i];
+        unsigned int param = c->prog_data.nr_params++;
+
+        assert(param < ARRAY_SIZE(c->prog_data.param));
+
+        switch (type->base_type) {
+        case GLSL_TYPE_FLOAT:
+           c->prog_data.param_convert[param] = PARAM_NO_CONVERT;
+           break;
+        case GLSL_TYPE_UINT:
+           c->prog_data.param_convert[param] = PARAM_CONVERT_F2U;
+           break;
+        case GLSL_TYPE_INT:
+           c->prog_data.param_convert[param] = PARAM_CONVERT_F2I;
+           break;
+        case GLSL_TYPE_BOOL:
+           c->prog_data.param_convert[param] = PARAM_CONVERT_F2B;
+           break;
+        }
+
+        c->prog_data.param[param] = &vec_values[i];
       }
       return 1;
 
@@ -371,6 +385,8 @@ fs_visitor::setup_builtin_uniform_values(ir_variable *ir)
               break;
            last_swiz = swiz;
 
+           c->prog_data.param_convert[c->prog_data.nr_params] =
+              PARAM_NO_CONVERT;
            c->prog_data.param[c->prog_data.nr_params++] = &vec_values[swiz];
         }
       }
@@ -625,6 +641,7 @@ fs_visitor::visit(ir_variable *ir)
       }
 
       reg = new(this->mem_ctx) fs_reg(UNIFORM, param_index);
+      reg->type = brw_type_for_base_type(ir->type);
    }
 
    if (!reg)
@@ -901,12 +918,21 @@ fs_visitor::visit(ir_expression *ir)
       break;
 
    case ir_unop_bit_not:
-   case ir_unop_u2f:
-   case ir_binop_lshift:
-   case ir_binop_rshift:
+      inst = emit(fs_inst(BRW_OPCODE_NOT, this->result, op[0]));
+      break;
    case ir_binop_bit_and:
+      inst = emit(fs_inst(BRW_OPCODE_AND, this->result, op[0], op[1]));
+      break;
    case ir_binop_bit_xor:
+      inst = emit(fs_inst(BRW_OPCODE_XOR, this->result, op[0], op[1]));
+      break;
    case ir_binop_bit_or:
+      inst = emit(fs_inst(BRW_OPCODE_OR, this->result, op[0], op[1]));
+      break;
+
+   case ir_unop_u2f:
+   case ir_binop_lshift:
+   case ir_binop_rshift:
       assert(!"GLSL 1.30 features unsupported");
       break;
    }
@@ -1204,6 +1230,11 @@ fs_visitor::visit(ir_texture *ir)
         0
       };
 
+      c->prog_data.param_convert[c->prog_data.nr_params] =
+        PARAM_NO_CONVERT;
+      c->prog_data.param_convert[c->prog_data.nr_params + 1] =
+        PARAM_NO_CONVERT;
+
       fs_reg scale_x = fs_reg(UNIFORM, c->prog_data.nr_params);
       fs_reg scale_y = fs_reg(UNIFORM, c->prog_data.nr_params + 1);
       GLuint index = _mesa_add_state_reference(params,
@@ -2359,7 +2390,7 @@ fs_visitor::assign_curb_setup()
                                                  constant_nr % 8);
 
            inst->src[i].file = FIXED_HW_REG;
-           inst->src[i].fixed_hw_reg = brw_reg;
+           inst->src[i].fixed_hw_reg = retype(brw_reg, inst->src[i].type);
         }
       }
    }
@@ -2566,6 +2597,8 @@ fs_visitor::setup_pull_constants()
 
    for (int i = 0; i < pull_uniform_count; i++) {
       c->prog_data.pull_param[i] = c->prog_data.param[pull_uniform_base + i];
+      c->prog_data.pull_param_convert[i] =
+        c->prog_data.param_convert[pull_uniform_base + i];
    }
    c->prog_data.nr_params -= pull_uniform_count;
    c->prog_data.nr_pull_params = pull_uniform_count;
@@ -3091,7 +3124,7 @@ fs_visitor::generate_code()
    const char *last_annotation_string = NULL;
    ir_instruction *last_annotation_ir = NULL;
 
-   if (INTEL_DEBUG & DEBUG_WM) {
+   if (unlikely(INTEL_DEBUG & DEBUG_WM)) {
       printf("Native code for fragment shader %d:\n",
             ctx->Shader.CurrentFragmentProgram->Name);
    }
@@ -3103,7 +3136,7 @@ fs_visitor::generate_code()
       fs_inst *inst = (fs_inst *)iter.get();
       struct brw_reg src[3], dst;
 
-      if (INTEL_DEBUG & DEBUG_WM) {
+      if (unlikely(INTEL_DEBUG & DEBUG_WM)) {
         if (last_annotation_ir != inst->ir) {
            last_annotation_ir = inst->ir;
            if (last_annotation_ir) {
@@ -3297,7 +3330,7 @@ fs_visitor::generate_code()
         this->fail = true;
       }
 
-      if (INTEL_DEBUG & DEBUG_WM) {
+      if (unlikely(INTEL_DEBUG & DEBUG_WM)) {
         for (unsigned int i = last_native_inst; i < p->nr_insn; i++) {
            if (0) {
               printf("0x%08x 0x%08x 0x%08x 0x%08x ",
@@ -3338,7 +3371,7 @@ brw_wm_fs_emit(struct brw_context *brw, struct brw_wm_compile *c)
     */
    c->dispatch_width = 8;
 
-   if (INTEL_DEBUG & DEBUG_WM) {
+   if (unlikely(INTEL_DEBUG & DEBUG_WM)) {
       printf("GLSL IR for native fragment shader %d:\n", prog->Name);
       _mesa_print_ir(shader->ir, NULL);
       printf("\n");