mesa: add/update comments in _mesa_copy_buffer_subdata()
[mesa.git] / src / mesa / drivers / dri / i965 / brw_shader.cpp
index f4005f800559632060f19efc268f836cae2139cf..1845c3d7618f1440acdd177697654a453dd65406 100644 (file)
 extern "C" {
 #include "main/macros.h"
 #include "brw_context.h"
+#include "brw_vs.h"
 }
 #include "brw_fs.h"
-#include "../glsl/ir_optimization.h"
-#include "../glsl/ir_print_visitor.h"
+#include "glsl/ir_optimization.h"
+#include "glsl/ir_print_visitor.h"
 
 struct gl_shader *
 brw_new_shader(struct gl_context *ctx, GLuint name, GLuint type)
@@ -64,7 +65,12 @@ brw_new_shader_program(struct gl_context *ctx, GLuint name)
 bool
 brw_shader_precompile(struct gl_context *ctx, struct gl_shader_program *prog)
 {
-   if (!brw_fs_precompile(ctx, prog))
+   struct brw_context *brw = brw_context(ctx);
+
+   if (brw->precompile && !brw_fs_precompile(ctx, prog))
+      return false;
+
+   if (!brw_vs_precompile(ctx, prog))
       return false;
 
    return true;
@@ -77,6 +83,9 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
    struct intel_context *intel = &brw->intel;
    unsigned int stage;
 
+   if (!_mesa_ir_link_shader(ctx, prog))
+      return false;
+
    for (stage = 0; stage < ARRAY_SIZE(prog->_LinkedShaders); stage++) {
       struct brw_shader *shader =
         (struct brw_shader *)prog->_LinkedShaders[stage];
@@ -111,12 +120,14 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
       brw_do_cubemap_normalize(shader->ir);
       lower_noise(shader->ir);
       lower_quadop_vector(shader->ir, false);
+
+      bool input = true;
+      bool output = stage == MESA_SHADER_FRAGMENT;
+      bool temp = stage == MESA_SHADER_FRAGMENT;
+      bool uniform = stage == MESA_SHADER_FRAGMENT;
+
       lower_variable_index_to_cond_assign(shader->ir,
-                                         GL_TRUE, /* input */
-                                         GL_TRUE, /* output */
-                                         GL_TRUE, /* temp */
-                                         GL_TRUE /* uniform */
-                                         );
+                                         input, output, temp, uniform);
 
       do {
         progress = false;
@@ -132,7 +143,8 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
                                   false /* loops */
                                   ) || progress;
 
-        progress = do_common_optimization(shader->ir, true, 32) || progress;
+        progress = do_common_optimization(shader->ir, true, true, 32)
+          || progress;
       } while (progress);
 
       validate_ir_tree(shader->ir);
@@ -141,13 +153,10 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
       ralloc_free(mem_ctx);
    }
 
-   if (!_mesa_ir_link_shader(ctx, prog))
-      return GL_FALSE;
-
    if (!brw_shader_precompile(ctx, prog))
-      return GL_FALSE;
+      return false;
 
-   return GL_TRUE;
+   return true;
 }
 
 
@@ -163,6 +172,7 @@ brw_type_for_base_type(const struct glsl_type *type)
    case GLSL_TYPE_UINT:
       return BRW_REGISTER_TYPE_UD;
    case GLSL_TYPE_ARRAY:
+      return brw_type_for_base_type(type->fields.array);
    case GLSL_TYPE_STRUCT:
    case GLSL_TYPE_SAMPLER:
       /* These should be overridden with the type of the member when
@@ -199,3 +209,56 @@ brw_conditional_for_comparison(unsigned int op)
       return BRW_CONDITIONAL_NZ;
    }
 }
+
+uint32_t
+brw_math_function(enum opcode op)
+{
+   switch (op) {
+   case SHADER_OPCODE_RCP:
+      return BRW_MATH_FUNCTION_INV;
+   case SHADER_OPCODE_RSQ:
+      return BRW_MATH_FUNCTION_RSQ;
+   case SHADER_OPCODE_SQRT:
+      return BRW_MATH_FUNCTION_SQRT;
+   case SHADER_OPCODE_EXP2:
+      return BRW_MATH_FUNCTION_EXP;
+   case SHADER_OPCODE_LOG2:
+      return BRW_MATH_FUNCTION_LOG;
+   case SHADER_OPCODE_POW:
+      return BRW_MATH_FUNCTION_POW;
+   case SHADER_OPCODE_SIN:
+      return BRW_MATH_FUNCTION_SIN;
+   case SHADER_OPCODE_COS:
+      return BRW_MATH_FUNCTION_COS;
+   case SHADER_OPCODE_INT_QUOTIENT:
+      return BRW_MATH_FUNCTION_INT_DIV_QUOTIENT;
+   case SHADER_OPCODE_INT_REMAINDER:
+      return BRW_MATH_FUNCTION_INT_DIV_REMAINDER;
+   default:
+      assert(!"not reached: unknown math function");
+      return 0;
+   }
+}
+
+uint32_t
+brw_texture_offset(ir_constant *offset)
+{
+   assert(offset != NULL);
+
+   signed char offsets[3];
+   for (unsigned i = 0; i < offset->type->vector_elements; i++)
+      offsets[i] = (signed char) offset->value.i[i];
+
+   /* Combine all three offsets into a single unsigned dword:
+    *
+    *    bits 11:8 - U Offset (X component)
+    *    bits  7:4 - V Offset (Y component)
+    *    bits  3:0 - R Offset (Z component)
+    */
+   unsigned offset_bits = 0;
+   for (unsigned i = 0; i < offset->type->vector_elements; i++) {
+      const unsigned shift = 4 * (2 - i);
+      offset_bits |= (offsets[i] << shift) & (0xF << shift);
+   }
+   return offset_bits;
+}