[Bf-blender-cvs] [61978bb] GPU_data_request: add GPUxBatch size query

Mike Erwin noreply at git.blender.org
Tue Apr 21 08:29:30 CEST 2015


Commit: 61978bbf32f1af14f0d730c344d3add6bd6ee281
Author: Mike Erwin
Date:   Sun Apr 19 03:06:52 2015 -0400
Branches: GPU_data_request
https://developer.blender.org/rB61978bbf32f1af14f0d730c344d3add6bd6ee281

add GPUxBatch size query

How much VRAM does our draw data use? Or process memory for client-side
data.

Note: right now data is stored in *both* places, but the code will be
smarter about storage in the future.

===================================================================

M	source/blender/gpu/GPUx_draw.h
M	source/blender/gpu/GPUx_element.h
M	source/blender/gpu/GPUx_vbo.h
M	source/blender/gpu/intern/gpux_draw.c
M	source/blender/gpu/intern/gpux_element.c
M	source/blender/gpu/intern/gpux_vbo.c

===================================================================

diff --git a/source/blender/gpu/GPUx_draw.h b/source/blender/gpu/GPUx_draw.h
index 8c2317c..ceeab42 100644
--- a/source/blender/gpu/GPUx_draw.h
+++ b/source/blender/gpu/GPUx_draw.h
@@ -28,6 +28,8 @@ typedef struct GPUxBatch {
 GPUxBatch *GPUx_batch_create(void);
 void GPUx_batch_discard(GPUxBatch*);
 
+unsigned GPUx_batch_size(const GPUxBatch*); /* total, in bytes */
+
 void GPUx_draw_batch(const GPUxBatch*);
 
 #endif /* BLENDER_GL_DRAW_PRIMITIVES */
diff --git a/source/blender/gpu/GPUx_element.h b/source/blender/gpu/GPUx_element.h
index 8007dab7..a1c942a 100644
--- a/source/blender/gpu/GPUx_element.h
+++ b/source/blender/gpu/GPUx_element.h
@@ -15,6 +15,8 @@ typedef struct ElementList ElementList;
 ElementList *GPUx_element_list_create(GLenum prim_type, unsigned prim_ct, unsigned max_index);
 void GPUx_element_list_discard(ElementList*);
 
+unsigned GPUx_element_list_size(const ElementList*);
+
 void GPUx_set_point_vertex(ElementList*, unsigned prim_idx, unsigned v1);
 void GPUx_set_line_vertices(ElementList*, unsigned prim_idx, unsigned v1, unsigned v2);
 void GPUx_set_triangle_vertices(ElementList*, unsigned prim_idx, unsigned v1, unsigned v2, unsigned v3);
diff --git a/source/blender/gpu/GPUx_vbo.h b/source/blender/gpu/GPUx_vbo.h
index 27c0f16..eec2841 100644
--- a/source/blender/gpu/GPUx_vbo.h
+++ b/source/blender/gpu/GPUx_vbo.h
@@ -26,6 +26,7 @@ VertexBuffer* GPUx_vertex_buffer_create(unsigned attrib_ct, unsigned GPUx_vertex
 void GPUx_vertex_buffer_discard(VertexBuffer*);
 
 unsigned GPUx_vertex_ct(const VertexBuffer*);
+unsigned GPUx_vertex_buffer_size(const VertexBuffer*); /* of all vertex attrib data, in bytes */
 
 #ifdef PRINT
 void GPUx_attrib_print(const VertexBuffer*, unsigned attrib_num);
diff --git a/source/blender/gpu/intern/gpux_draw.c b/source/blender/gpu/intern/gpux_draw.c
index 0d0662a..4ae596a 100644
--- a/source/blender/gpu/intern/gpux_draw.c
+++ b/source/blender/gpu/intern/gpux_draw.c
@@ -158,6 +158,14 @@ void GPUx_batch_discard(GPUxBatch *batch)
 	free(batch);
 }
 
+unsigned GPUx_batch_size(const GPUxBatch *batch)
+{
+	unsigned sz = GPUx_vertex_buffer_size(batch->buff);
+	if (batch->elem)
+		sz += GPUx_element_list_size(batch->elem);
+	return sz;
+}
+
 void GPUx_draw_batch(const GPUxBatch *batch)
 {
 	int vert_per_prim = 0;
diff --git a/source/blender/gpu/intern/gpux_element.c b/source/blender/gpu/intern/gpux_element.c
index 527e169..4cf2412 100644
--- a/source/blender/gpu/intern/gpux_element.c
+++ b/source/blender/gpu/intern/gpux_element.c
@@ -49,20 +49,10 @@ const void *index_ptr(const ElementList *el)
 ElementList *GPUx_element_list_create(GLenum prim_type, unsigned prim_ct, unsigned max_index)
 {
 	ElementList *el;
-	unsigned index_size, prim_vertex_ct;
 
-	if (prim_type == GL_POINTS)
-		prim_vertex_ct = 1;
-	else if (prim_type == GL_LINES)
-		prim_vertex_ct = 2;
-	else if (prim_type == GL_TRIANGLES)
-		prim_vertex_ct = 3;
-	else {
 #ifdef TRUST_NO_ONE
-		assert(false);
+	assert(prim_type == GL_POINTS || prim_type == GL_LINES || prim_type == GL_TRIANGLES);
 #endif /* TRUST_NO_ONE */
-		return NULL;
-	}
 
 	el = calloc(1, sizeof(ElementList));
 
@@ -70,25 +60,19 @@ ElementList *GPUx_element_list_create(GLenum prim_type, unsigned prim_ct, unsign
 	el->prim_ct = prim_ct;
 	el->max_allowed_index = max_index;
 
-	if (max_index <= 255) {
+	if (max_index <= 255)
 		el->index_type = GL_UNSIGNED_BYTE;
-		index_size = sizeof(GLubyte);
-	}
-	else if (max_index <= 65535) {
+	else if (max_index <= 65535)
 		el->index_type = GL_UNSIGNED_SHORT;
-		index_size = sizeof(GLushort);
-	}
-	else {
+	else
 		el->index_type = GL_UNSIGNED_INT;
-		index_size = sizeof(GLuint);
-	}
 
 #ifdef TRACK_INDEX_RANGE
 	el->min_observed_index = max_index + 1; /* any valid index will be < this */
 	el->max_observed_index = 0;
 #endif /* TRACK_INDEX_RANGE */
 
-	el->indices = calloc(prim_ct * prim_vertex_ct, index_size);
+	el->indices = calloc(1, GPUx_element_list_size(el));
 	/* TODO: use only one calloc, not two */
 
 	return el;
@@ -105,6 +89,27 @@ void GPUx_element_list_discard(ElementList *el)
 	free(el);
 }
 
+unsigned GPUx_element_list_size(const ElementList *el)
+{
+	unsigned prim_vertex_ct = 0, index_size = 0;
+
+	if (el->prim_type == GL_POINTS)
+		prim_vertex_ct = 1;
+	else if (el->prim_type == GL_LINES)
+		prim_vertex_ct = 2;
+	else if (el->prim_type == GL_TRIANGLES)
+		prim_vertex_ct = 3;
+
+	if (el->index_type == GL_UNSIGNED_BYTE)
+		index_size = sizeof(GLubyte);
+	else if (el->index_type == GL_UNSIGNED_SHORT)
+		index_size = sizeof(GLushort);
+	else if (el->index_type == GL_UNSIGNED_INT)
+		index_size = sizeof(GLuint);
+
+	return prim_vertex_ct * el->prim_ct * index_size;
+}
+
 void GPUx_set_point_vertex(ElementList *el, unsigned prim_idx, unsigned v1)
 {
 	const unsigned offset = prim_idx;
@@ -239,32 +244,13 @@ void GPUx_optimize(ElementList *el)
 void GPUx_element_list_prime(ElementList *el)
 {
 #ifdef USE_ELEM_VBO
-	int prim_vertex_ct = 0, index_size = 0, total_size;
-
-#ifdef TRUST_NO_ONE
+  #ifdef TRUST_NO_ONE
 	assert(el->vbo_id == 0);
   #endif /* TRUST_NO_ONE */
-
-	if (el->prim_type == GL_POINTS)
-		prim_vertex_ct = 1;
-	else if (el->prim_type == GL_LINES)
-		prim_vertex_ct = 2;
-	else if (el->prim_type == GL_TRIANGLES)
-		prim_vertex_ct = 3;
-
-	if (el->index_type == GL_UNSIGNED_BYTE)
-		index_size = sizeof(GLubyte);
-	else if (el->index_type == GL_UNSIGNED_SHORT)
-		index_size = sizeof(GLushort);
-	else if (el->index_type == GL_UNSIGNED_INT)
-		index_size = sizeof(GLuint);
-
-	total_size = prim_vertex_ct * el->prim_ct * index_size;
-
 	glGenBuffers(1, &el->vbo_id);
 	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, el->vbo_id);
 	/* fill with delicious data & send to GPU the first time only */
-	glBufferData(GL_ELEMENT_ARRAY_BUFFER, total_size, el->indices, GL_STATIC_DRAW);
+	glBufferData(GL_ELEMENT_ARRAY_BUFFER, GPUx_element_list_size(el), el->indices, GL_STATIC_DRAW);
 	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
 #else
 	(void)el;
diff --git a/source/blender/gpu/intern/gpux_vbo.c b/source/blender/gpu/intern/gpux_vbo.c
index 7f80738..06b2387 100644
--- a/source/blender/gpu/intern/gpux_vbo.c
+++ b/source/blender/gpu/intern/gpux_vbo.c
@@ -193,6 +193,15 @@ static unsigned attrib_total_size(const VertexBuffer *buff, unsigned attrib_num)
 #endif /*  MESA_WORKAROUND */
 }
 
+unsigned GPUx_vertex_buffer_size(const VertexBuffer *buff)
+{
+	unsigned sz = 0;
+	unsigned a_idx;
+	for (a_idx = 0; a_idx < buff->attrib_ct; ++a_idx)
+		sz += attrib_total_size(buff, a_idx);
+	return sz;
+}
+
 void GPUx_specify_attrib(VertexBuffer *buff, unsigned attrib_num,
 #ifdef GENERIC_ATTRIB
                     const char *name,




More information about the Bf-blender-cvs mailing list