summaryrefslogtreecommitdiffstats
path: root/src/mesa/vbo/vbo_save_api.c
diff options
context:
space:
mode:
authorMathias Fröhlich <[email protected]>2016-05-22 14:10:19 +0200
committerMathias Fröhlich <[email protected]>2016-06-16 05:50:55 +0200
commit0e73d9454d626f4ac96be51733d3d3db4b77392c (patch)
tree08e171c55dc3a550b7d6e6ce7974bd073c7acae8 /src/mesa/vbo/vbo_save_api.c
parentbc4e0c486874ee8c6f2e616b91589a1da63164d8 (diff)
vbo: Use a bitmask to track the active arrays in vbo_save*.
The use of a bitmask makes functions iterating only active attributes less visible in profiles. v2: Use _mesa_bit_scan{,64} instead of open coding. v3: Use u_bit_scan{,64} instead of _mesa_bit_scan{,64}. Reviewed-by: Brian Paul <[email protected]> Signed-off-by: Mathias Fröhlich <[email protected]>
Diffstat (limited to 'src/mesa/vbo/vbo_save_api.c')
-rw-r--r--src/mesa/vbo/vbo_save_api.c67
1 files changed, 38 insertions, 29 deletions
diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c
index 97a1dfdeb3f..650c9b6b411 100644
--- a/src/mesa/vbo/vbo_save_api.c
+++ b/src/mesa/vbo/vbo_save_api.c
@@ -78,6 +78,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "main/api_arrayelt.h"
#include "main/vtxfmt.h"
#include "main/dispatch.h"
+#include "util/bitscan.h"
#include "vbo_context.h"
#include "vbo_noop.h"
@@ -429,6 +430,7 @@ _save_compile_vertex_list(struct gl_context *ctx)
/* Duplicate our template, increment refcounts to the storage structs:
*/
+ node->enabled = save->enabled;
memcpy(node->attrsz, save->attrsz, sizeof(node->attrsz));
memcpy(node->attrtype, save->attrtype, sizeof(node->attrtype));
node->vertex_size = save->vertex_size;
@@ -624,14 +626,15 @@ static void
_save_copy_to_current(struct gl_context *ctx)
{
struct vbo_save_context *save = &vbo_context(ctx)->save;
- GLuint i;
+ GLbitfield64 enabled = save->enabled & (~BITFIELD64_BIT(VBO_ATTRIB_POS));
- for (i = VBO_ATTRIB_POS + 1; i < VBO_ATTRIB_MAX; i++) {
- if (save->attrsz[i]) {
- save->currentsz[i][0] = save->attrsz[i];
- COPY_CLEAN_4V_TYPE_AS_UNION(save->current[i], save->attrsz[i],
- save->attrptr[i], save->attrtype[i]);
- }
+ while (enabled) {
+ const int i = u_bit_scan64(&enabled);
+ assert(save->attrsz[i]);
+
+ save->currentsz[i][0] = save->attrsz[i];
+ COPY_CLEAN_4V_TYPE_AS_UNION(save->current[i], save->attrsz[i],
+ save->attrptr[i], save->attrtype[i]);
}
}
@@ -640,9 +643,11 @@ static void
_save_copy_from_current(struct gl_context *ctx)
{
struct vbo_save_context *save = &vbo_context(ctx)->save;
- GLint i;
+ GLbitfield64 enabled = save->enabled & (~BITFIELD64_BIT(VBO_ATTRIB_POS));
+
+ while (enabled) {
+ const int i = u_bit_scan64(&enabled);
- for (i = VBO_ATTRIB_POS + 1; i < VBO_ATTRIB_MAX; i++) {
switch (save->attrsz[i]) {
case 4:
save->attrptr[i][3] = save->current[i][3];
@@ -652,7 +657,9 @@ _save_copy_from_current(struct gl_context *ctx)
save->attrptr[i][1] = save->current[i][1];
case 1:
save->attrptr[i][0] = save->current[i][0];
+ break;
case 0:
+ assert(0);
break;
}
}
@@ -691,6 +698,7 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint attr, GLuint newsz)
*/
oldsz = save->attrsz[attr];
save->attrsz[attr] = newsz;
+ save->enabled |= BITFIELD64_BIT(attr);
save->vertex_size += newsz - oldsz;
save->max_vert = ((VBO_SAVE_BUFFER_SIZE - save->vertex_store->used) /
@@ -723,7 +731,6 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint attr, GLuint newsz)
if (save->copied.nr) {
const fi_type *data = save->copied.buffer;
fi_type *dest = save->buffer;
- GLuint j;
/* Need to note this and fix up at runtime (or loopback):
*/
@@ -733,27 +740,28 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint attr, GLuint newsz)
}
for (i = 0; i < save->copied.nr; i++) {
- for (j = 0; j < VBO_ATTRIB_MAX; j++) {
- if (save->attrsz[j]) {
- if (j == attr) {
- if (oldsz) {
- COPY_CLEAN_4V_TYPE_AS_UNION(dest, oldsz, data,
- save->attrtype[j]);
- data += oldsz;
- dest += newsz;
- }
- else {
- COPY_SZ_4V(dest, newsz, save->current[attr]);
- dest += newsz;
- }
+ GLbitfield64 enabled = save->enabled;
+ while (enabled) {
+ const int j = u_bit_scan64(&enabled);
+ assert(save->attrsz[j]);
+ if (j == attr) {
+ if (oldsz) {
+ COPY_CLEAN_4V_TYPE_AS_UNION(dest, oldsz, data,
+ save->attrtype[j]);
+ data += oldsz;
+ dest += newsz;
}
else {
- GLint sz = save->attrsz[j];
- COPY_SZ_4V(dest, sz, data);
- data += sz;
- dest += sz;
+ COPY_SZ_4V(dest, newsz, save->current[attr]);
+ dest += newsz;
}
}
+ else {
+ GLint sz = save->attrsz[j];
+ COPY_SZ_4V(dest, sz, data);
+ data += sz;
+ dest += sz;
+ }
}
}
@@ -803,9 +811,10 @@ static void
_save_reset_vertex(struct gl_context *ctx)
{
struct vbo_save_context *save = &vbo_context(ctx)->save;
- GLuint i;
- for (i = 0; i < VBO_ATTRIB_MAX; i++) {
+ while (save->enabled) {
+ const int i = u_bit_scan64(&save->enabled);
+ assert(save->attrsz[i]);
save->attrsz[i] = 0;
save->active_sz[i] = 0;
}