freedreno: a bit of micro-optimization
authorRob Clark <robdclark@gmail.com>
Thu, 14 Jul 2016 20:44:34 +0000 (16:44 -0400)
committerRob Clark <robdclark@gmail.com>
Sat, 30 Jul 2016 13:23:42 +0000 (09:23 -0400)
Signed-off-by: Rob Clark <robdclark@gmail.com>
src/gallium/drivers/freedreno/freedreno_draw.c
src/gallium/drivers/freedreno/freedreno_util.h

index dd4a720dd0ed700eb15ec26dbc98cf71fb97de55..e371d2bf7dca4ca28b62c865df4e7da48f79b3f8 100644 (file)
@@ -134,14 +134,13 @@ fd_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
                        batch->gmem_reason |= FD_GMEM_BLEND_ENABLED;
        }
 
-       /* Skip over buffer 0, that is sent along with the command stream */
-       for (i = 1; i < PIPE_MAX_CONSTANT_BUFFERS; i++) {
+       foreach_bit(i, ctx->constbuf[PIPE_SHADER_VERTEX].enabled_mask)
                resource_read(batch, ctx->constbuf[PIPE_SHADER_VERTEX].cb[i].buffer);
+       foreach_bit(i, ctx->constbuf[PIPE_SHADER_FRAGMENT].enabled_mask)
                resource_read(batch, ctx->constbuf[PIPE_SHADER_FRAGMENT].cb[i].buffer);
-       }
 
        /* Mark VBOs as being read */
-       for (i = 0; i < ctx->vtx.vertexbuf.count; i++) {
+       foreach_bit(i, ctx->vtx.vertexbuf.enabled_mask) {
                assert(!ctx->vtx.vertexbuf.vb[i].user_buffer);
                resource_read(batch, ctx->vtx.vertexbuf.vb[i].buffer);
        }
@@ -150,12 +149,10 @@ fd_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
        resource_read(batch, ctx->indexbuf.buffer);
 
        /* Mark textures as being read */
-       for (i = 0; i < ctx->verttex.num_textures; i++)
-               if (ctx->verttex.textures[i])
-                       resource_read(batch, ctx->verttex.textures[i]->texture);
-       for (i = 0; i < ctx->fragtex.num_textures; i++)
-               if (ctx->fragtex.textures[i])
-                       resource_read(batch, ctx->fragtex.textures[i]->texture);
+       foreach_bit(i, ctx->verttex.valid_textures)
+               resource_read(batch, ctx->verttex.textures[i]->texture);
+       foreach_bit(i, ctx->fragtex.valid_textures)
+               resource_read(batch, ctx->fragtex.textures[i]->texture);
 
        /* Mark streamout buffers as being written.. */
        for (i = 0; i < ctx->streamout.num_targets; i++)
index 6321cd7b4cd7d832a8760340bed1d149122938ea..30097008e2afcc3f2640c775d20eb27ef9a2e9a0 100644 (file)
@@ -338,4 +338,7 @@ pack_rgba(enum pipe_format format, const float *rgba)
 #define swap(a, b) \
        do { __typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
 
+#define foreach_bit(b, mask) \
+       for (uint32_t _m = (mask); _m && ({(b) = u_bit_scan(&_m); 1;});)
+
 #endif /* FREEDRENO_UTIL_H_ */