[Mesa-dev] [PATCH v2 2/6] mesa: refactor _mesa_compute_max_transform_feedback_vertices from i965.

Brian Paul brian.e.paul at gmail.com
Sun Dec 16 07:43:35 PST 2012


On Sat, Dec 15, 2012 at 11:09 PM, Paul Berry <stereotype441 at gmail.com> wrote:
> Previously, the i965 driver contained code to compute the maximum
> number of vertices that could be written without overflowing any
> transform feedback buffers.  This code wasn't driver-specific, and for
> GLES3 support we're going to need to use it in core mesa.  So this
> patch moves the code into a core mesa function,
> _mesa_compute_max_transform_feedback_vertices().
>
> Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
>
> v2: Eliminate C++-style variable declarations, since these won't work
> with MSVC.
> ---
>  src/mesa/drivers/dri/i965/gen6_sol.c | 16 ++++------------
>  src/mesa/main/transformfeedback.c    | 28 ++++++++++++++++++++++++++++
>  src/mesa/main/transformfeedback.h    |  5 +++++
>  3 files changed, 37 insertions(+), 12 deletions(-)
>
> diff --git a/src/mesa/drivers/dri/i965/gen6_sol.c b/src/mesa/drivers/dri/i965/gen6_sol.c
> index 07316c8..7aa6140 100644
> --- a/src/mesa/drivers/dri/i965/gen6_sol.c
> +++ b/src/mesa/drivers/dri/i965/gen6_sol.c
> @@ -31,6 +31,7 @@
>  #include "intel_batchbuffer.h"
>  #include "brw_defines.h"
>  #include "brw_state.h"
> +#include "main/transformfeedback.h"
>
>  static void
>  gen6_update_sol_surfaces(struct brw_context *brw)
> @@ -165,21 +166,12 @@ brw_begin_transform_feedback(struct gl_context *ctx, GLenum mode,
>     struct gl_transform_feedback_object *xfb_obj =
>        ctx->TransformFeedback.CurrentObject;
>
> -   unsigned max_index = 0xffffffff;
> -
>     /* Compute the maximum number of vertices that we can write without
>      * overflowing any of the buffers currently being used for feedback.
>      */
> -   for (int i = 0; i < BRW_MAX_SOL_BUFFERS; ++i) {
> -      unsigned stride = linked_xfb_info->BufferStride[i];
> -
> -      /* Skip any inactive buffers, which have a stride of 0. */
> -      if (stride == 0)
> -        continue;
> -
> -      unsigned max_for_this_buffer = xfb_obj->Size[i] / (4 * stride);
> -      max_index = MIN2(max_index, max_for_this_buffer);
> -   }
> +   unsigned max_index
> +      = _mesa_compute_max_transform_feedback_vertices(xfb_obj,
> +                                                      linked_xfb_info);
>
>     /* Initialize the SVBI 0 register to zero and set the maximum index.
>      * These values will be sent to the hardware on the next draw.
> diff --git a/src/mesa/main/transformfeedback.c b/src/mesa/main/transformfeedback.c
> index 22060c3..bf161bb 100644
> --- a/src/mesa/main/transformfeedback.c
> +++ b/src/mesa/main/transformfeedback.c
> @@ -34,6 +34,7 @@
>  #include "bufferobj.h"
>  #include "context.h"
>  #include "hash.h"
> +#include "macros.h"
>  #include "mfeatures.h"
>  #include "mtypes.h"
>  #include "transformfeedback.h"
> @@ -246,6 +247,33 @@ _mesa_init_transform_feedback_functions(struct dd_function_table *driver)
>
>
>  /**
> + * Compute the maximum number of vertices that can be written to the currently
> + * enabled transform feedback buffers without overflowing any of them.
> + */
> +unsigned
> +_mesa_compute_max_transform_feedback_vertices(
> +      const struct gl_transform_feedback_object *obj,
> +      const struct gl_transform_feedback_info *info)
> +{
> +   unsigned max_index = 0xffffffff;
> +
> +   for (int i = 0; i < info->NumBuffers; ++i) {

You'll have to move the 'int i' decl before the loop.  And it should
be unsigned.


> +      unsigned stride = info->BufferStride[i];
> +      unsigned max_for_this_buffer;
> +
> +      /* Skip any inactive buffers, which have a stride of 0. */
> +      if (stride == 0)
> +        continue;
> +
> +      max_for_this_buffer = obj->Size[i] / (4 * stride);
> +      max_index = MIN2(max_index, max_for_this_buffer);
> +   }
> +
> +   return max_index;
> +}
> +
> +
> +/**
>   ** Begin API functions
>   **/
>
> diff --git a/src/mesa/main/transformfeedback.h b/src/mesa/main/transformfeedback.h
> index 01c2af3..3c03b7a 100644
> --- a/src/mesa/main/transformfeedback.h
> +++ b/src/mesa/main/transformfeedback.h
> @@ -46,6 +46,11 @@ _mesa_validate_transform_feedback_buffers(struct gl_context *ctx);
>  extern void
>  _mesa_init_transform_feedback_functions(struct dd_function_table *driver);
>
> +extern unsigned
> +_mesa_compute_max_transform_feedback_vertices(
> +      const struct gl_transform_feedback_object *obj,
> +      const struct gl_transform_feedback_info *info);
> +
>
>  /*** GL_EXT_transform_feedback ***/
>

Reviewed-by: Brian Paul <brianp at vmware.com>


More information about the mesa-dev mailing list