Revision: 46990 http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46990 Author: jwilkins Date: 2012-05-25 01:26:20 +0000 (Fri, 25 May 2012) Log Message: ----------- Optimization (after Profiling), and refactoring of gpuImmediate.
Added gpuImmediateLock/gpuImmediateUnlock so that gpuBegin/gpuEnd have less to do so it is faster to send multiple batches. Profiled the code using the text renderer as a pathological case. Modified Paths: -------------- branches/soc-2012-swiss_cheese/source/blender/gpu/CMakeLists.txt branches/soc-2012-swiss_cheese/source/blender/gpu/GPU_compatibility.h branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate.c Added Paths: ----------- branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate.h branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate_gl11.c branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate_inline.h branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate_internal.h branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate_vbo.c Removed Paths: ------------- branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate.h Modified: branches/soc-2012-swiss_cheese/source/blender/gpu/CMakeLists.txt =================================================================== --- branches/soc-2012-swiss_cheese/source/blender/gpu/CMakeLists.txt 2012-05-24 23:50:20 UTC (rev 46989) +++ branches/soc-2012-swiss_cheese/source/blender/gpu/CMakeLists.txt 2012-05-25 01:26:20 UTC (rev 46990) @@ -50,6 +50,8 @@ intern/gpu_draw.c intern/gpu_extensions.c intern/gpu_immediate.c + intern/gpu_immediate_gl11.c + intern/gpu_immediate_vbo.c intern/gpu_material.c shaders/gpu_shader_material.glsl.c @@ -67,6 +69,8 @@ intern/gpu_codegen.h intern/gpu_deprecated.h intern/gpu_immediate.h + intern/gpu_immediate_inline.h + intern/gpu_immediate_internal.h ) if(WITH_MOD_SMOKE) Modified: branches/soc-2012-swiss_cheese/source/blender/gpu/GPU_compatibility.h =================================================================== --- branches/soc-2012-swiss_cheese/source/blender/gpu/GPU_compatibility.h 2012-05-24 23:50:20 UTC (rev 46989) +++ branches/soc-2012-swiss_cheese/source/blender/gpu/GPU_compatibility.h 2012-05-25 01:26:20 UTC (rev 46990) @@ -32,7 +32,7 @@ #ifndef __GPU_COMPATIBILITY_H__ #define __GPU_COMPATIBILITY_H__ -#include "intern/gpu_immediate.h" +#include "intern/gpu_immediate_inline.h" #include "intern/gpu_deprecated.h" #ifdef __cplusplus Modified: branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate.c =================================================================== --- branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate.c 2012-05-24 23:50:20 UTC (rev 46989) +++ branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_immediate.c 2012-05-25 01:26:20 UTC (rev 46990) @@ -29,66 +29,60 @@ * \ingroup gpu */ -#include "GPU_immediate.h" +#include "GPU_immediate_internal.h" #include "MEM_guardedalloc.h" + /* global symbol needed because the immediate drawing functons are inline */ GPUimmediate* GPU_IMMEDIATE; -static GLsizei calcStride() +GLsizei gpu_calc_stride() { size_t i; size_t stride = 0; /* vertex */ - if (GPU_IMMEDIATE->vertexSize > 0) { + if (GPU_IMMEDIATE->vertexSize != 0) { stride += (size_t)(GPU_IMMEDIATE->vertexSize) * sizeof(GLfloat); } /* normal */ - if (GPU_IMMEDIATE->normalSize == 3) { + if (GPU_IMMEDIATE->normalSize != 0) { + /* normals always have 3 components */ stride += 3 * sizeof(GLfloat); } /* color */ - if (GPU_IMMEDIATE->colorSize > 0) { - /* 4 bytes are always reserved for color, for efficient memory alignment */ - stride += 4 * sizeof(GLubyte); + if (GPU_IMMEDIATE->colorSize != 0) { + /* color always get 4 bytes for efficient memory alignment */ + stride += 4; } /* texture coordinate */ for (i = 0; i < GPU_IMMEDIATE->textureUnitCount; i++) { - if (GPU_IMMEDIATE->texCoordSize[i] > 0) { - stride += - (size_t)(GPU_IMMEDIATE->texCoordSize[i]) * sizeof(GLfloat); - } + stride += (size_t)(GPU_IMMEDIATE->texCoordSize[i]) * sizeof(GLfloat); } /* float vertex attribute */ for (i = 0; i < GPU_IMMEDIATE->attribCount_f; i++) { - if (GPU_IMMEDIATE->attribSize_f[i] > 0) { - stride += - (size_t)(GPU_IMMEDIATE->attribSize_f[i]) * sizeof(GLfloat); - } + stride += (size_t)(GPU_IMMEDIATE->attribSize_f[i]) * sizeof(GLfloat); } /* byte vertex attribute */ for (i = 0; i < GPU_IMMEDIATE->attribCount_ub; i++) { - if (GPU_IMMEDIATE->attribSize_ub[i] > 0) { - stride += - (size_t)(GPU_IMMEDIATE->attribSize_ub[i]) * sizeof(GLfloat); - } + /* byte attributes always get 4 bytes for efficient memory alignment */ + stride += (size_t)(GPU_IMMEDIATE->attribSize_ub[i]) * sizeof(GLfloat); } return (GLsizei)stride; @@ -96,252 +90,58 @@ -typedef struct bufferDataVBO { - GLint bufferObject; -} bufferDataVBO; - -void beginBufferVBO(void) +void gpuImmediateLock(void) { -} + GPU_CHECK_NO_BEGIN(); -void endBufferVBO(void) -{ -} + if (GPU_IMMEDIATE->lockCount == 0) { + assert(GPU_IMMEDIATE->lockBuffer); -void shutdownBufferVBO(GPUimmediate *restrict immediate) -{ -} - - - -typedef struct bufferDataGL11 { - size_t size; - GLubyte* ptr; - GLsizei stride; -} bufferDataGL11; - -void beginBufferGL11(void) -{ - const GLsizei stride = calcStride(); - bufferDataGL11* bufferData; - size_t newSize; - size_t offset; - GLint savedActiveTexture; - size_t i; - - newSize = (size_t)(stride * GPU_IMMEDIATE->maxVertexCount); - - if (GPU_IMMEDIATE->bufferData) { - bufferData = (bufferDataGL11*)(GPU_IMMEDIATE->bufferData); - - if (newSize > bufferData->size) { - MEM_reallocN(bufferData->ptr, newSize); - bufferData->size = newSize; + if (GPU_IMMEDIATE->lockBuffer) { + GPU_IMMEDIATE->lockBuffer(); } } - else { - bufferData = - (bufferDataGL11*)MEM_mallocN( - sizeof(bufferDataGL11), - "bufferDataGL11"); - assert(bufferData); + GPU_IMMEDIATE->lockCount++; +} - bufferData->ptr = MEM_mallocN(newSize, "bufferDataGL11->ptr"); - assert(bufferData->ptr); - bufferData->size = newSize; - } - bufferData->stride = stride; +void gpuImmediateUnlock(void) +{ + GPU_CHECK_NO_BEGIN(); - /* Assume that vertex arrays have been disabled for everything - and only enable what is needed */ + assert(GPU_IMMEDIATE->lockCount > 0); - offset = 0; + if (GPU_IMMEDIATE->lockCount == 1) { + assert(GPU_IMMEDIATE->unlockBuffer); - /* vertex */ - - glVertexPointer( - GPU_IMMEDIATE->vertexSize, - GL_FLOAT, - stride, - bufferData->ptr + offset); - - offset += (size_t)(GPU_IMMEDIATE->vertexSize) * sizeof(GLfloat); - - glEnableClientState(GL_VERTEX_ARRAY); - - /* normal */ - - if (GPU_IMMEDIATE->normalSize == 3) { - glNormalPointer( - GL_FLOAT, - stride, - bufferData->ptr + offset); - - offset += 3 * sizeof(GLfloat); - - glEnableClientState(GL_NORMAL_ARRAY); - } - - /* color */ - - if (GPU_IMMEDIATE->colorSize > 0) { - glColorPointer( - GPU_IMMEDIATE->colorSize, - GL_UNSIGNED_BYTE, - stride, - bufferData->ptr + offset); - - /* 4 bytes are always reserved for color, for efficient memory alignment */ - offset += 4 * sizeof(GLubyte); - - glEnableClientState(GL_COLOR_ARRAY); - } - - /* texture coordinate */ - - glGetIntegerv(GL_ACTIVE_TEXTURE, &savedActiveTexture); - - for (i = 0; i < GPU_IMMEDIATE->textureUnitCount; i++) { - if (GPU_IMMEDIATE->texCoordSize[i] > 0) { - glActiveTexture(GPU_IMMEDIATE->textureUnitMap[i]); - - glTexCoordPointer( - GPU_IMMEDIATE->texCoordSize[i], - GL_FLOAT, - stride, - bufferData->ptr + offset); - - offset += - (size_t)(GPU_IMMEDIATE->texCoordSize[i]) * sizeof(GLfloat); - - glEnableClientState(GL_TEXTURE_COORD_ARRAY); + if (GPU_IMMEDIATE->unlockBuffer) { + GPU_IMMEDIATE->unlockBuffer(); } } - glActiveTexture(savedActiveTexture); - - /* float vertex attribute */ - - for (i = 0; i < GPU_IMMEDIATE->attribCount_f; i++) { - if (GPU_IMMEDIATE->attribSize_f[i] > 0) { - glVertexAttribPointer( - GPU_IMMEDIATE->attribIndexMap_f[i], - GPU_IMMEDIATE->attribSize_f[i], - GL_FLOAT, - GPU_IMMEDIATE->attribNormalized_f[i], - stride, - bufferData->ptr + offset); - - offset += - (size_t)(GPU_IMMEDIATE->attribSize_f[i]) * sizeof(GLfloat); - - glEnableVertexAttribArray( - GPU_IMMEDIATE->attribIndexMap_f[i]); - } + if (GPU_IMMEDIATE->lockCount > 0) { + GPU_IMMEDIATE->lockCount--; } +} - /* byte vertex attribute */ - for (i = 0; i < GPU_IMMEDIATE->attribCount_ub; i++) { - if (GPU_IMMEDIATE->attribSize_ub[i] > 0) { - glVertexAttribPointer( - GPU_IMMEDIATE->attribIndexMap_ub[i], - GPU_IMMEDIATE->attribSize_ub[i], - GL_FLOAT, - GPU_IMMEDIATE->attribNormalized_ub[i], - stride, - bufferData->ptr + offset); - offset += - (size_t)(GPU_IMMEDIATE->attribSize_ub[i]) * sizeof(GLfloat); - - glEnableVertexAttribArray( - GPU_IMMEDIATE->attribIndexMap_ub[i]); - } - } - - GPU_IMMEDIATE->buffer = bufferData->ptr; - GPU_IMMEDIATE->bufferData = bufferData; -} - -void endBufferGL11(void) +GLboolean gpuImmediateIsLocked(void) { - GLint savedActiveTexture; - size_t i; + assert(GPU_IMMEDIATE); - glDrawArrays(GPU_IMMEDIATE->mode, 0, GPU_IMMEDIATE->count); - - /* Disable any arrays that were used so that everything is off again. */ - - /* vertex */ - - glDisableClientState(GL_VERTEX_ARRAY); - - /* normal */ - - if (GPU_IMMEDIATE->normalSize == 3) { - glDisableClientState(GL_NORMAL_ARRAY); + if (!GPU_IMMEDIATE) { + return GL_FALSE; } - /* color */ - - if (GPU_IMMEDIATE->colorSize > 0) { - glDisableClientState(GL_COLOR_ARRAY); - } - - /* texture coordinate */ - - glGetIntegerv(GL_ACTIVE_TEXTURE, &savedActiveTexture); - - for (i = 0; i < GPU_IMMEDIATE->textureUnitCount; i++) { - if (GPU_IMMEDIATE->texCoordSize[i] > 0) { - glActiveTexture(GPU_IMMEDIATE->textureUnitMap[i]); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - } - } - - glActiveTexture(savedActiveTexture); - - /* float vertex attribute */ - - for (i = 0; i < GPU_IMMEDIATE->attribCount_f; i++) { - if (GPU_IMMEDIATE->attribSize_f[i] > 0) { - glDisableVertexAttribArray( - GPU_IMMEDIATE->attribIndexMap_f[i]); - } - } - - /* byte vertex attribute */ - - for (i = 0; i < GPU_IMMEDIATE->attribCount_ub; i++) { - if (GPU_IMMEDIATE->attribSize_ub[i] > 0) { - glDisableVertexAttribArray( - GPU_IMMEDIATE->attribIndexMap_ub[i]); - } - } + return GPU_IMMEDIATE->lockCount > 0; } -void shutdownBufferGL11(GPUimmediate *restrict immediate) -{ - if (immediate->bufferData) { - bufferDataGL11* bufferData = - (bufferDataGL11*)(immediate->bufferData); - if (bufferData->ptr) { - MEM_freeN(bufferData->ptr); - bufferData->ptr = NULL; - } - MEM_freeN(immediate->bufferData); - immediate->bufferData = NULL; - } -} - - -static calcLastTexture(GPUimmediate* immediate) +static void calc_last_texture(GPUimmediate* immediate) { GLint maxTextureCoords; GLint maxCombinedTextureImageUnits; @@ -358,6 +158,8 @@ GL_TEXTURE0 + MAX2(maxTextureCoords, maxCombinedTextureImageUnits) - 1; } + + GPUimmediate* gpuNewImmediate(void) { GPUimmediate* immediate = @@ -368,28 +170,38 @@ immediate->vertexSize = 3; //if (GLEW_ARB_vertex_buffer_object) { - // immediate->beginBuffer = beginBufferVBO; - // immediate->endBuffer = endBufferVBO; - // immediate->shutdownBuffer = shutdownBufferVBO; + // immediate->lockBuffer = gpu_lock_buffer_vbo; + // immediate->beginBuffer = gpu_begin_buffer_vbo; + // immediate->endBuffer = gpu_end_buffer_vbo; + // immediate->unlockBuffer = gpu_unlock_buffer_vbo; + // immediate->shutdownBuffer = gpu_shutdown_buffer_vbo; //} //else { - immediate->beginBuffer = beginBufferGL11; @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs