st/mesa: always inline the code setting non-64bit vertex elements
authorMarek Olšák <marek.olsak@amd.com>
Tue, 21 Jan 2020 03:14:11 +0000 (22:14 -0500)
committerMarek Olšák <marek.olsak@amd.com>
Fri, 14 Feb 2020 23:16:27 +0000 (18:16 -0500)
Reviewed-by: Mathias Fröhlich <mathias.froehlich@web.de>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3829>

src/mesa/state_tracker/st_atom_array.c

index be1729311e2e4bd4f083c3bf65a3d38ee3f1ef4d..bbbe0e236d303a3574d559c9b0c4c40dcd931393 100644 (file)
@@ -50,7 +50,7 @@
 #include "main/varray.h"
 #include "main/arrayobj.h"
 
-static void init_velement(struct pipe_vertex_element *velement,
+static void set_velement(struct pipe_vertex_element *velement,
                           int src_offset, int format,
                           int instance_divisor, int vbo_index)
 {
@@ -61,50 +61,67 @@ static void init_velement(struct pipe_vertex_element *velement,
    assert(velement->src_format);
 }
 
-static void init_velement_lowered(const struct st_vertex_program *vp,
-                                  struct pipe_vertex_element *velements,
-                                  const struct gl_vertex_format *vformat,
-                                  int src_offset, int instance_divisor,
-                                  int vbo_index, int idx)
+static void init_velement_64bit(const struct st_vertex_program *vp,
+                                struct pipe_vertex_element *velements,
+                                const struct gl_vertex_format *vformat,
+                                int src_offset, int instance_divisor,
+                                int vbo_index, int idx)
 {
    const GLubyte nr_components = vformat->Size;
-
-   if (vformat->Doubles) {
-      int lower_format;
-
-      if (nr_components < 2)
-         lower_format = PIPE_FORMAT_R32G32_UINT;
-      else
-         lower_format = PIPE_FORMAT_R32G32B32A32_UINT;
-
-      init_velement(&velements[idx], src_offset,
-                    lower_format, instance_divisor, vbo_index);
-      idx++;
-
-      if (idx < vp->num_inputs &&
-          vp->index_to_input[idx] == ST_DOUBLE_ATTRIB_PLACEHOLDER) {
-         if (nr_components >= 3) {
-            if (nr_components == 3)
-               lower_format = PIPE_FORMAT_R32G32_UINT;
-            else
-               lower_format = PIPE_FORMAT_R32G32B32A32_UINT;
-
-            init_velement(&velements[idx], src_offset + 4 * sizeof(float),
-                        lower_format, instance_divisor, vbo_index);
-         } else {
-            /* The values here are undefined. Fill in some conservative
-             * dummy values.
-             */
-            init_velement(&velements[idx], src_offset, PIPE_FORMAT_R32G32_UINT,
-                          instance_divisor, vbo_index);
-         }
+   int lower_format;
+
+   if (nr_components < 2)
+      lower_format = PIPE_FORMAT_R32G32_UINT;
+   else
+      lower_format = PIPE_FORMAT_R32G32B32A32_UINT;
+
+   set_velement(&velements[idx], src_offset,
+                lower_format, instance_divisor, vbo_index);
+   idx++;
+
+   if (idx < vp->num_inputs &&
+       vp->index_to_input[idx] == ST_DOUBLE_ATTRIB_PLACEHOLDER) {
+      if (nr_components >= 3) {
+         if (nr_components == 3)
+            lower_format = PIPE_FORMAT_R32G32_UINT;
+         else
+            lower_format = PIPE_FORMAT_R32G32B32A32_UINT;
+
+         set_velement(&velements[idx], src_offset + 4 * sizeof(float),
+                      lower_format, instance_divisor, vbo_index);
+      } else {
+         /* The values here are undefined. Fill in some conservative
+          * dummy values.
+          */
+         set_velement(&velements[idx], src_offset, PIPE_FORMAT_R32G32_UINT,
+                      instance_divisor, vbo_index);
       }
-   } else {
-      init_velement(&velements[idx], src_offset, vformat->_PipeFormat,
-                    instance_divisor, vbo_index);
    }
 }
 
+/* Always inline the non-64bit element code, so that the compiler can see
+ * that velements is on the stack.
+ */
+static void ALWAYS_INLINE
+init_velement(const struct st_vertex_program *vp,
+              struct pipe_vertex_element *velements,
+              const struct gl_vertex_format *vformat,
+              int src_offset, int instance_divisor,
+              int vbo_index, int idx)
+{
+   if (!vformat->Doubles) {
+      velements[idx].src_offset = src_offset;
+      velements[idx].src_format = vformat->_PipeFormat;
+      velements[idx].instance_divisor = instance_divisor;
+      velements[idx].vertex_buffer_index = vbo_index;
+      assert(velements[idx].src_format);
+      return;
+   }
+
+   init_velement_64bit(vp, velements, vformat, src_offset, instance_divisor,
+                       vbo_index, idx);
+}
+
 /* ALWAYS_INLINE helps the compiler realize that most of the parameters are
  * on the stack.
  */
@@ -163,9 +180,9 @@ st_setup_arrays(struct st_context *st,
          const struct gl_array_attributes *const attrib
             = _mesa_draw_array_attrib(vao, attr);
          const GLuint off = _mesa_draw_attributes_relative_offset(attrib);
-         init_velement_lowered(vp, velements, &attrib->Format, off,
-                               binding->InstanceDivisor, bufidx,
-                               input_to_index[attr]);
+         init_velement(vp, velements, &attrib->Format, off,
+                       binding->InstanceDivisor, bufidx,
+                       input_to_index[attr]);
       }
    }
    *has_user_vertex_buffers = uses_user_vertex_buffers;
@@ -205,8 +222,8 @@ st_setup_current(struct st_context *st,
          if (alignment != size)
             memset(cursor + size, 0, alignment - size);
 
-         init_velement_lowered(vp, velements, &attrib->Format, cursor - data, 0,
-                               bufidx, input_to_index[attr]);
+         init_velement(vp, velements, &attrib->Format, cursor - data, 0,
+                       bufidx, input_to_index[attr]);
 
          cursor += alignment;
       }
@@ -254,8 +271,8 @@ st_setup_current_user(struct st_context *st,
          = _mesa_draw_current_attrib(ctx, attr);
       const unsigned bufidx = (*num_vbuffers)++;
 
-      init_velement_lowered(vp, velements, &attrib->Format, 0, 0,
-                            bufidx, input_to_index[attr]);
+      init_velement(vp, velements, &attrib->Format, 0, 0,
+                    bufidx, input_to_index[attr]);
 
       vbuffer[bufidx].is_user_buffer = true;
       vbuffer[bufidx].buffer.user = attrib->Ptr;