mesa: add/update comments in _mesa_copy_buffer_subdata()
[mesa.git] / src / mesa / drivers / dri / i965 / brw_shader.cpp
index 3ff6bbaed47eb555989bc4fb72c0327283f384b8..1845c3d7618f1440acdd177697654a453dd65406 100644 (file)
@@ -27,8 +27,8 @@ extern "C" {
 #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)
@@ -65,7 +65,9 @@ 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))
@@ -81,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];
@@ -119,7 +124,7 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
       bool input = true;
       bool output = stage == MESA_SHADER_FRAGMENT;
       bool temp = stage == MESA_SHADER_FRAGMENT;
-      bool uniform = true;
+      bool uniform = stage == MESA_SHADER_FRAGMENT;
 
       lower_variable_index_to_cond_assign(shader->ir,
                                          input, output, temp, uniform);
@@ -138,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);
@@ -147,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;
 }
 
 
@@ -169,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
@@ -226,8 +230,35 @@ brw_math_function(enum opcode op)
       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;
+}