Advertisement
Guest User

Untitled

a guest
Jun 18th, 2015
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.35 KB | None | 0 0
  1. diff --git a/src/glsl/nir/nir_lower_io.c b/src/glsl/nir/nir_lower_io.c
  2. index 6761d5b..fadd25a 100644
  3. --- a/src/glsl/nir/nir_lower_io.c
  4. +++ b/src/glsl/nir/nir_lower_io.c
  5. @@ -38,8 +38,49 @@
  6.  
  7.  struct lower_io_state {
  8.     void *mem_ctx;
  9. +   int stage;
  10.  };
  11.  
  12. +static int
  13. +type_size_vec4(const struct glsl_type *type)
  14. +{
  15. +   unsigned int i;
  16. +   int size;
  17. +
  18. +   switch (glsl_get_base_type(type)) {
  19. +   case GLSL_TYPE_UINT:
  20. +   case GLSL_TYPE_INT:
  21. +   case GLSL_TYPE_FLOAT:
  22. +   case GLSL_TYPE_BOOL:
  23. +      if (glsl_type_is_matrix(type)) {
  24. +         return glsl_get_matrix_columns(type);
  25. +      } else {
  26. +         return 1;
  27. +      }
  28. +   case GLSL_TYPE_ARRAY:
  29. +      assert(glsl_get_length(type) > 0);
  30. +      return type_size_vec4(glsl_get_array_element(type)) * glsl_get_length(type);
  31. +   case GLSL_TYPE_STRUCT:
  32. +      size = 0;
  33. +      for (i = 0; i <  glsl_get_length(type); i++) {
  34. +         size += type_size_vec4(glsl_get_struct_field(type, i));
  35. +      }
  36. +      return size;
  37. +   case GLSL_TYPE_SAMPLER:
  38. +      return 0;
  39. +   case GLSL_TYPE_ATOMIC_UINT:
  40. +      return 0;
  41. +   case GLSL_TYPE_IMAGE:
  42. +   case GLSL_TYPE_VOID:
  43. +   case GLSL_TYPE_DOUBLE:
  44. +   case GLSL_TYPE_ERROR:
  45. +   case GLSL_TYPE_INTERFACE:
  46. +      unreachable("not reached");
  47. +   }
  48. +
  49. +   return 0;
  50. +}
  51. +
  52.  static unsigned
  53.  type_size(const struct glsl_type *type)
  54.  {
  55. @@ -187,6 +228,7 @@ get_io_offset(nir_deref_var *deref, nir_instr *instr, nir_src *indirect,
  56.  {
  57.     bool found_indirect = false;
  58.     unsigned base_offset = 0;
  59. +   bool is_vertex_stage = state->stage != MESA_SHADER_FRAGMENT;
  60.  
  61.     nir_deref *tail = &deref->deref;
  62.     while (tail->child != NULL) {
  63. @@ -202,7 +244,18 @@ get_io_offset(nir_deref_var *deref, nir_instr *instr, nir_src *indirect,
  64.           if (deref_array->deref_array_type == nir_deref_array_type_indirect) {
  65.              nir_load_const_instr *load_const =
  66.                 nir_load_const_instr_create(state->mem_ctx, 1);
  67. +
  68. +            /* For vertex shaders we expect individual uniform elements to
  69. +             * be a vec4, we need to consider that when emitting the code
  70. +             * to compute the indirect part of the offset. Notice that the
  71. +             * constant part accumulated in base_offset would need the same
  72. +             * treatment, but that can be handled by the backend in
  73. +             * the implementation of the intrinsic operation.
  74. +             */
  75. +            if (is_vertex_stage)
  76. +               size = type_size_vec4(tail->type);
  77.              load_const->value.u[0] = size;
  78.              nir_instr_insert_before(instr, &load_const->instr);
  79.  
  80.              nir_alu_instr *mul = nir_alu_instr_create(state->mem_ctx,
  81. @@ -350,11 +402,12 @@ nir_lower_io_block(nir_block *block, void *void_state)
  82.  }
  83.  
  84.  static void
  85. -nir_lower_io_impl(nir_function_impl *impl)
  86. +nir_lower_io_impl(nir_function_impl *impl, int stage)
  87.  {
  88.     struct lower_io_state state;
  89.  
  90.     state.mem_ctx = ralloc_parent(impl);
  91. +   state.stage = stage;
  92.  
  93.     nir_foreach_block(impl, nir_lower_io_block, &state);
  94.  
  95. @@ -363,10 +416,10 @@ nir_lower_io_impl(nir_function_impl *impl)
  96.  }
  97.  
  98.  void
  99. -nir_lower_io(nir_shader *shader)
  100. +nir_lower_io(nir_shader *shader, int stage)
  101.  {
  102.     nir_foreach_overload(shader, overload) {
  103.        if (overload->impl)
  104. -         nir_lower_io_impl(overload->impl);
  105. +         nir_lower_io_impl(overload->impl, stage);
  106.     }
  107.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement