[Mesa-dev] [PATCH 17/18] t_dd_dmatmp: Use C99 mixed code and declarations

Ian Romanick idr at freedesktop.org
Wed Sep 30 13:58:05 PDT 2015


From: Ian Romanick <ian.d.romanick at intel.com>

While this file lives in src/mesa/tnl_dd, it is built only in drivers
that live in src/mesa/drivers/dri.  We don't generally allow C99-isms in
common code, but we have allowed C99-isms in src/mesa/drivers/dri for
quite some time.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/mesa/tnl_dd/t_dd_dmatmp.h | 77 ++++++++++++++++---------------------------
 1 file changed, 29 insertions(+), 48 deletions(-)

diff --git a/src/mesa/tnl_dd/t_dd_dmatmp.h b/src/mesa/tnl_dd/t_dd_dmatmp.h
index 228555c..4eff883 100644
--- a/src/mesa/tnl_dd/t_dd_dmatmp.h
+++ b/src/mesa/tnl_dd/t_dd_dmatmp.h
@@ -69,16 +69,15 @@ static void TAG(render_points_verts)(struct gl_context *ctx,
 {
    LOCAL_VARS;
    const unsigned dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
-   unsigned currentsz;
-   GLuint j, nr;
 
    INIT(GL_POINTS);
 
-   currentsz = GET_CURRENT_VB_MAX_VERTS();
+   unsigned currentsz = GET_CURRENT_VB_MAX_VERTS();
    if (currentsz < 8)
       currentsz = dmasz;
 
-   for (j = 0; j < count; j += nr) {
+   unsigned nr;
+   for (unsigned j = 0; j < count; j += nr) {
       nr = MIN2(currentsz, count - j);
       TAG(emit_verts)(ctx, start + j, nr, ALLOC_VERTS(nr));
       currentsz = dmasz;
@@ -92,21 +91,19 @@ static void TAG(render_lines_verts)(struct gl_context *ctx,
 {
    LOCAL_VARS;
    const unsigned dmasz = GET_SUBSEQUENT_VB_MAX_VERTS() & ~1;
-   unsigned currentsz;
-   GLuint j, nr;
 
    INIT(GL_LINES);
 
    /* Emit whole number of lines in total and in each buffer:
     */
    count -= count & 1;
-   currentsz = GET_CURRENT_VB_MAX_VERTS();
-   currentsz -= currentsz & 1;
 
+   unsigned currentsz = GET_CURRENT_VB_MAX_VERTS() & ~1;
    if (currentsz < 8)
       currentsz = dmasz;
 
-   for (j = 0; j < count; j += nr) {
+   unsigned nr;
+   for (unsigned j = 0; j < count; j += nr) {
       nr = MIN2(currentsz, count - j);
       TAG(emit_verts)(ctx, start + j, nr, ALLOC_VERTS(nr));
       currentsz = dmasz;
@@ -121,16 +118,15 @@ static void TAG(render_line_strip_verts)(struct gl_context *ctx,
 {
    LOCAL_VARS;
    const unsigned dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
-   unsigned currentsz;
-   GLuint j, nr;
 
    INIT(GL_LINE_STRIP);
 
-   currentsz = GET_CURRENT_VB_MAX_VERTS();
+   unsigned currentsz = GET_CURRENT_VB_MAX_VERTS();
    if (currentsz < 8)
       currentsz = dmasz;
 
-   for (j = 0; j + 1 < count; j += nr - 1) {
+   unsigned nr;
+   for (unsigned j = 0; j + 1 < count; j += nr - 1) {
       nr = MIN2(currentsz, count - j);
       TAG(emit_verts)(ctx, start + j, nr, ALLOC_VERTS(nr));
       currentsz = dmasz;
@@ -147,22 +143,18 @@ static void TAG(render_line_loop_verts)(struct gl_context *ctx,
 {
    LOCAL_VARS;
    const unsigned dmasz = GET_SUBSEQUENT_VB_MAX_VERTS() - 1;
-   unsigned currentsz;
-   GLuint j, nr;
+   unsigned j = (flags & PRIM_BEGIN) ? 0 : 1;
 
    INIT(GL_LINE_STRIP);
 
-   j = (flags & PRIM_BEGIN) ? 0 : 1;
-
    /* Ensure last vertex won't wrap buffers:
     */
-   currentsz = GET_CURRENT_VB_MAX_VERTS();
-   currentsz--;
-
+   unsigned currentsz = GET_CURRENT_VB_MAX_VERTS() - 1;
    if (currentsz < 8)
       currentsz = dmasz;
 
    if (j + 1 < count) {
+      unsigned nr;
       for (/* empty */; j + 1 < count; j += nr - 1) {
          nr = MIN2(currentsz, count - j);
 
@@ -198,12 +190,10 @@ static void TAG(render_triangles_verts)(struct gl_context *ctx,
 {
    LOCAL_VARS;
    const unsigned dmasz = (GET_SUBSEQUENT_VB_MAX_VERTS() / 3) * 3;
-   unsigned currentsz;
-   GLuint j, nr;
 
    INIT(GL_TRIANGLES);
 
-   currentsz = (GET_CURRENT_VB_MAX_VERTS() / 3) * 3;
+   unsigned currentsz = (GET_CURRENT_VB_MAX_VERTS() / 3) * 3;
 
    /* Emit whole number of tris in total.  dmasz is already a multiple
     * of 3.
@@ -213,7 +203,8 @@ static void TAG(render_triangles_verts)(struct gl_context *ctx,
    if (currentsz < 8)
       currentsz = dmasz;
 
-   for (j = 0; j < count; j += nr) {
+   unsigned nr;
+   for (unsigned j = 0; j < count; j += nr) {
       nr = MIN2(currentsz, count - j);
       TAG(emit_verts)(ctx, start + j, nr, ALLOC_VERTS(nr));
       currentsz = dmasz;
@@ -228,14 +219,11 @@ static void TAG(render_tri_strip_verts)(struct gl_context *ctx,
                                         GLuint flags)
 {
    LOCAL_VARS;
-   GLuint j, nr;
    const unsigned dmasz = GET_SUBSEQUENT_VB_MAX_VERTS() & ~1;
-   unsigned currentsz;
 
    INIT(GL_TRIANGLE_STRIP);
 
-   currentsz = GET_CURRENT_VB_MAX_VERTS();
-
+   unsigned currentsz = GET_CURRENT_VB_MAX_VERTS();
    if (currentsz < 8)
       currentsz = dmasz;
 
@@ -243,7 +231,8 @@ static void TAG(render_tri_strip_verts)(struct gl_context *ctx,
     */
    currentsz -= (currentsz & 1);
 
-   for (j = 0; j + 2 < count; j += nr - 2) {
+   unsigned nr;
+   for (unsigned j = 0; j + 2 < count; j += nr - 2) {
       nr = MIN2(currentsz, count - j);
       TAG(emit_verts)(ctx, start + j, nr, ALLOC_VERTS(nr));
       currentsz = dmasz;
@@ -258,17 +247,16 @@ static void TAG(render_tri_fan_verts)(struct gl_context *ctx,
                                       GLuint flags)
 {
    LOCAL_VARS;
-   GLuint j, nr;
    const unsigned dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
-   unsigned currentsz;
 
    INIT(GL_TRIANGLE_FAN);
 
-   currentsz = GET_CURRENT_VB_MAX_VERTS();
+   unsigned currentsz = GET_CURRENT_VB_MAX_VERTS();
    if (currentsz < 8)
       currentsz = dmasz;
 
-   for (j = 1; j + 1 < count; j += nr - 2) {
+   unsigned nr;
+   for (unsigned j = 1; j + 1 < count; j += nr - 2) {
       void *tmp;
       nr = MIN2(currentsz, count - j + 1);
       tmp = ALLOC_VERTS(nr);
@@ -289,18 +277,17 @@ static void TAG(render_poly_verts)(struct gl_context *ctx,
 {
    if (HAVE_POLYGONS) {
       LOCAL_VARS;
-      GLuint j, nr;
       const unsigned dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
-      unsigned currentsz;
 
       INIT(GL_POLYGON);
 
-      currentsz = GET_CURRENT_VB_MAX_VERTS();
+      unsigned currentsz = GET_CURRENT_VB_MAX_VERTS();
       if (currentsz < 8) {
          currentsz = dmasz;
       }
 
-      for (j = 1; j + 1 < count; j += nr - 2) {
+      unsigned nr;
+      for (unsigned j = 1; j + 1 < count; j += nr - 2) {
          void *tmp;
          nr = MIN2(currentsz, count - j + 1);
          tmp = ALLOC_VERTS(nr);
@@ -324,12 +311,9 @@ static void TAG(render_quad_strip_verts)(struct gl_context *ctx,
                                          GLuint count,
                                          GLuint flags)
 {
-   GLuint j, nr;
-
    if (ctx->Light.ShadeModel == GL_SMOOTH) {
       LOCAL_VARS;
       const unsigned dmasz = GET_SUBSEQUENT_VB_MAX_VERTS() & ~1;
-      unsigned currentsz;
 
       /* Emit smooth-shaded quadstrips as tristrips:
        */
@@ -338,14 +322,14 @@ static void TAG(render_quad_strip_verts)(struct gl_context *ctx,
 
       /* Emit whole number of quads in total, and in each buffer.
        */
-      currentsz = GET_CURRENT_VB_MAX_VERTS();
-      currentsz -= currentsz & 1;
       count -= count & 1;
 
+      unsigned currentsz = GET_CURRENT_VB_MAX_VERTS() & ~1;
       if (currentsz < 8)
          currentsz = dmasz;
 
-      for (j = 0; j + 3 < count; j += nr - 2) {
+      unsigned nr;
+      for (unsigned j = 0; j + 3 < count; j += nr - 2) {
          nr = MIN2(currentsz, count - j);
          TAG(emit_verts)(ctx, start + j, nr, ALLOC_VERTS(nr));
          currentsz = dmasz;
@@ -366,7 +350,6 @@ static void TAG(render_quads_verts)(struct gl_context *ctx,
    if (ctx->Light.ShadeModel == GL_SMOOTH ||
        ctx->Light.ProvokingVertex == GL_LAST_VERTEX_CONVENTION) {
       LOCAL_VARS;
-      GLuint j;
 
       /* Emit whole number of quads in total. */
       count -= count & 3;
@@ -377,7 +360,7 @@ static void TAG(render_quads_verts)(struct gl_context *ctx,
        */
       INIT(GL_TRIANGLES);
 
-      for (j = 0; j + 3 < count; j += 4) {
+      for (unsigned j = 0; j + 3 < count; j += 4) {
          void *tmp = ALLOC_VERTS(6);
          /* Send v0, v1, v3
           */
@@ -425,15 +408,13 @@ static const tnl_render_func TAG(render_tab_verts)[GL_POLYGON+2] =
 static bool TAG(validate_render)(struct gl_context *ctx,
                                  struct vertex_buffer *VB)
 {
-   GLint i;
-
    if (VB->ClipOrMask & ~CLIP_CULL_BIT)
       return false;
 
    if (VB->Elts)
       return false;
 
-   for (i = 0 ; i < VB->PrimitiveCount ; i++) {
+   for (unsigned i = 0; i < VB->PrimitiveCount; i++) {
       GLuint prim = VB->Primitive[i].mode;
       GLuint count = VB->Primitive[i].count;
       bool ok = false;
-- 
2.1.0



More information about the mesa-dev mailing list