From 0c50236a944898502405a31aa1f0b6ae61ae38ae Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 13 Nov 2009 08:59:12 -0600 Subject: CTS-26 Fix for LOD generation always using first file specified. --- indra/llrender/llvertexbuffer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index db4189dfea..6e77bb2aab 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -566,7 +566,7 @@ void LLVertexBuffer::destroyGLBuffer() } mGLBuffer = 0; - unbind(); + //unbind(); } void LLVertexBuffer::destroyGLIndices() @@ -593,7 +593,7 @@ void LLVertexBuffer::destroyGLIndices() } mGLIndices = 0; - unbind(); + //unbind(); } void LLVertexBuffer::updateNumVerts(S32 nverts) -- cgit v1.2.3 From 4ffac619945cafc9c7da357bf56c9bc92e318b1b Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 4 Mar 2010 15:30:15 -0600 Subject: Optimiziation pass. Added RenderUseStreamVBO to enable/disable usage of VBO's for streaming buffers. Faster traversal of LLCullResult members. Removal of llpushcallstacks from inner loops. Sprinkling in fast timers. --- indra/llrender/llvertexbuffer.cpp | 46 ++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 0f41e278b6..ae43915a9d 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -2,25 +2,31 @@ * @file llvertexbuffer.cpp * @brief LLVertexBuffer implementation * - * $LicenseInfo:firstyear=2003&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. + * $LicenseInfo:firstyear=2003&license=viewergpl$ + * + * Copyright (c) 2003-2009, Linden Research, Inc. * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. + * Second Life Viewer Source Code + * The source code in this file ("Source Code") is provided by Linden Lab + * to you under the terms of the GNU General Public License, version 2.0 + * ("GPL"), unless you have obtained a separate licensing agreement + * ("Other License"), formally executed by you and Linden Lab. Terms of + * the GPL can be found in doc/GPL-license.txt in this distribution, or + * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * There are special exceptions to the terms and conditions of the GPL as + * it is applied to this Source Code. View the full text of the exception + * in the file doc/FLOSS-exception.txt in this software distribution, or + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * By copying, modifying or distributing this software, you acknowledge + * that you have read and understood your obligations described above, + * and agree to abide by those obligations. * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO + * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, + * COMPLETENESS OR PERFORMANCE. * $/LicenseInfo$ */ @@ -376,12 +382,12 @@ LLVertexBuffer::LLVertexBuffer(U32 typemask, S32 usage) : { mUsage = 0 ; } - + if (mUsage == GL_STREAM_DRAW_ARB && !sUseStreamDraw) { mUsage = 0; } - + S32 stride = calcStride(typemask, mOffsets); mTypeMask = typemask; @@ -813,7 +819,7 @@ BOOL LLVertexBuffer::useVBOs() const return FALSE; } #endif - return TRUE; + return sEnableVBOs; } //---------------------------------------------------------------------------- @@ -1177,7 +1183,7 @@ void LLVertexBuffer::setBuffer(U32 data_mask) { if (mGLBuffer) { - if (sVBOActive) + if (sEnableVBOs && sVBOActive) { glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); sBindCount++; @@ -1189,7 +1195,7 @@ void LLVertexBuffer::setBuffer(U32 data_mask) setup = TRUE; // ... or a client memory pointer changed } } - if (mGLIndices && sIBOActive) + if (sEnableVBOs && mGLIndices && sIBOActive) { /*if (sMapped) { -- cgit v1.2.3 From b414b5067e3e47da7d9baf490d94534b4c65a8eb Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Sun, 28 Feb 2010 16:40:30 -0600 Subject: Remove some dead code. Add LH transform to LLVector3 Add DebugShowUploadCost Make LOD generation on model preview less finnicky. Remove error level based LOD generation. Better framing of model before upload. Better error handling for model uploader. Remove [COST] argument from model upload menu item. Remove L$ check from model upload menu item being enabled. --- indra/llrender/llvertexbuffer.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 116e265914..415d2f603b 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -668,6 +668,12 @@ void LLVertexBuffer::allocateBuffer(S32 nverts, S32 nindices, bool create) { LLMemType mt2(LLMemType::MTYPE_VERTEX_ALLOCATE_BUFFER); + if (nverts < 0 || nindices < 0 || + nverts > 65536) + { + llerrs << "Bad vertex buffer allocation: " << nverts << " : " << nindices << llendl; + } + updateNumVerts(nverts); updateNumIndices(nindices); -- cgit v1.2.3 From ea6397fe4990b73e190391d61781c609fbd1f8c1 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 4 Mar 2010 15:30:15 -0600 Subject: Optimiziation pass. Added RenderUseStreamVBO to enable/disable usage of VBO's for streaming buffers. Faster traversal of LLCullResult members. Removal of llpushcallstacks from inner loops. Sprinkling in fast timers. --- indra/llrender/llvertexbuffer.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 415d2f603b..4064e688e8 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -61,6 +61,7 @@ BOOL LLVertexBuffer::sVBOActive = FALSE; BOOL LLVertexBuffer::sIBOActive = FALSE; U32 LLVertexBuffer::sAllocatedBytes = 0; BOOL LLVertexBuffer::sMapped = FALSE; +BOOL LLVertexBuffer::sUseStreamDraw = TRUE; std::vector LLVertexBuffer::sDeleteList; @@ -381,6 +382,11 @@ LLVertexBuffer::LLVertexBuffer(U32 typemask, S32 usage) : { mUsage = 0 ; } + + if (mUsage == GL_STREAM_DRAW_ARB && !sUseStreamDraw) + { + mUsage = 0; + } S32 stride = calcStride(typemask, mOffsets); -- cgit v1.2.3 From fc0bbcbc26aa4fdd8770b9777c58f10d651136e9 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 25 Mar 2010 19:22:08 -0500 Subject: rigged attachments WIP --- indra/llrender/llvertexbuffer.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 4064e688e8..d5b00f27a7 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -62,6 +62,7 @@ BOOL LLVertexBuffer::sIBOActive = FALSE; U32 LLVertexBuffer::sAllocatedBytes = 0; BOOL LLVertexBuffer::sMapped = FALSE; BOOL LLVertexBuffer::sUseStreamDraw = TRUE; +S32 LLVertexBuffer::sWeight4Loc = -1; std::vector LLVertexBuffer::sDeleteList; @@ -76,6 +77,7 @@ S32 LLVertexBuffer::sTypeOffsets[LLVertexBuffer::TYPE_MAX] = sizeof(LLColor4U), // TYPE_COLOR, sizeof(LLVector3), // TYPE_BINORMAL, sizeof(F32), // TYPE_WEIGHT, + sizeof(LLVector4), // TYPE_WEIGHT4, sizeof(LLVector4), // TYPE_CLOTHWEIGHT, }; @@ -1015,6 +1017,12 @@ bool LLVertexBuffer::getWeightStrider(LLStrider& strider, S32 index) { return VertexBufferStrider::get(*this, strider, index); } + +bool LLVertexBuffer::getWeight4Strider(LLStrider& strider, S32 index) +{ + return VertexBufferStrider::get(*this, strider, index); +} + bool LLVertexBuffer::getClothWeightStrider(LLStrider& strider, S32 index) { return VertexBufferStrider::get(*this, strider, index); @@ -1284,6 +1292,12 @@ void LLVertexBuffer::setupVertexBuffer(U32 data_mask) const { glVertexAttribPointerARB(1, 1, GL_FLOAT, FALSE, stride, (void*)(base + mOffsets[TYPE_WEIGHT])); } + + if (data_mask & MAP_WEIGHT4 && sWeight4Loc != -1) + { + glVertexAttribPointerARB(sWeight4Loc, 4, GL_FLOAT, FALSE, stride, (void*)(base+mOffsets[TYPE_WEIGHT4])); + } + if (data_mask & MAP_CLOTHWEIGHT) { glVertexAttribPointerARB(4, 4, GL_FLOAT, TRUE, stride, (void*)(base + mOffsets[TYPE_CLOTHWEIGHT])); -- cgit v1.2.3 From 54dd30cc426e16aa99b4f7eea080bbeae0656843 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 15 Apr 2010 00:04:17 -0500 Subject: More rigged attachments work. --- indra/llrender/llvertexbuffer.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index d5b00f27a7..668e9e55f9 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -212,6 +212,27 @@ void LLVertexBuffer::setupClientArrays(U32 data_mask) glClientActiveTextureARB(GL_TEXTURE0_ARB); } + if (sLastMask & MAP_WEIGHT4) + { + if (sWeight4Loc < 0) + { + llerrs << "Weighting disabled but vertex buffer still bound!" << llendl; + } + + if (!(data_mask & MAP_WEIGHT4)) + { //disable 4-component skin weight + glDisableVertexAttribArrayARB(sWeight4Loc); + } + } + else if (data_mask & MAP_WEIGHT4) + { + if (sWeight4Loc >= 0) + { //enable 4-component skin weight + glEnableVertexAttribArrayARB(sWeight4Loc); + } + } + + sLastMask = data_mask; } } -- cgit v1.2.3 From c074404d9dbaa7ccdbd863e4a9e7e3eff97e7816 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 22 Apr 2010 14:44:34 -0500 Subject: Que? --- indra/llrender/llvertexbuffer.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 668e9e55f9..7fa47cd171 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -271,9 +271,22 @@ void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indi return; } + U16* idx = ((U16*) getIndicesPointer())+indices_offset; + + if (gDebugGL && !useVBOs()) + { + for (U32 i = 0; i < count; ++i) + { + if (idx[i] < start || idx[i] > end) + { + llerrs << "Index out of range: " << idx[i] << " not in [" << start << ", " << end << "]" << llendl; + } + } + } + stop_glerror(); glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT, - ((U16*) getIndicesPointer()) + indices_offset); + idx); stop_glerror(); } -- cgit v1.2.3 From 05a23f8dbaa45c64bcf6c55dd09a468ba2b1f144 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 21 May 2010 04:49:12 -0500 Subject: Vectorized memcpy. 16-byte aligned vertex buffers. (almost) fully vectorized avatar vertex buffer updating --- index buffers still need to be vectorized --- indra/llrender/llvertexbuffer.cpp | 195 +++++++++++++++++++++++++++++++++++++- 1 file changed, 190 insertions(+), 5 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 7fa47cd171..a50eb7211c 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -39,6 +39,7 @@ #include "llglheaders.h" #include "llmemtype.h" #include "llrender.h" +#include "llvector4a.h" //============================================================================ @@ -66,6 +67,27 @@ S32 LLVertexBuffer::sWeight4Loc = -1; std::vector LLVertexBuffer::sDeleteList; +#define LL_ALIGNED_VB 1 + +#if LL_ALIGNED_VB + +S32 LLVertexBuffer::sTypeOffsets[LLVertexBuffer::TYPE_MAX] = +{ + sizeof(LLVector4), // TYPE_VERTEX, + sizeof(LLVector4), // TYPE_NORMAL, + sizeof(LLVector2), // TYPE_TEXCOORD0, + sizeof(LLVector2), // TYPE_TEXCOORD1, + sizeof(LLVector2), // TYPE_TEXCOORD2, + sizeof(LLVector2), // TYPE_TEXCOORD3, + sizeof(LLColor4U), // TYPE_COLOR, + sizeof(LLVector4), // TYPE_BINORMAL, + sizeof(F32), // TYPE_WEIGHT, + sizeof(LLVector4), // TYPE_WEIGHT4, + sizeof(LLVector4), // TYPE_CLOTHWEIGHT, +}; + +#else + S32 LLVertexBuffer::sTypeOffsets[LLVertexBuffer::TYPE_MAX] = { sizeof(LLVector3), // TYPE_VERTEX, @@ -81,6 +103,8 @@ S32 LLVertexBuffer::sTypeOffsets[LLVertexBuffer::TYPE_MAX] = sizeof(LLVector4), // TYPE_CLOTHWEIGHT, }; +#endif + U32 LLVertexBuffer::sGLMode[LLRender::NUM_MODES] = { GL_TRIANGLES, @@ -428,11 +452,41 @@ LLVertexBuffer::LLVertexBuffer(U32 typemask, S32 usage) : mTypeMask = typemask; mStride = stride; + mAlignedOffset = 0; + sCount++; } +#if LL_ALIGNED_VB +//static +S32 LLVertexBuffer::calcStride(const U32& typemask, S32* offsets, S32 num_vertices) +{ + S32 offset = 0; + for (S32 i=0; i(src); + mAlignedOffset = mMappedData - src; + stop_glerror(); } { @@ -975,6 +1042,45 @@ void LLVertexBuffer::unmapBuffer() //---------------------------------------------------------------------------- +#if LL_ALIGNED_VB + +template struct VertexBufferStrider +{ + typedef LLStrider strider_t; + static bool get(LLVertexBuffer& vbo, + strider_t& strider, + S32 index) + { + if (vbo.mapBuffer() == NULL) + { + llwarns << "mapBuffer failed!" << llendl; + return FALSE; + } + + if (type == LLVertexBuffer::TYPE_INDEX) + { + S32 stride = sizeof(T); + strider = (T*)(vbo.getMappedIndices() + index*stride); + strider.setStride(0); + return TRUE; + } + else if (vbo.hasDataType(type)) + { + S32 stride = LLVertexBuffer::sTypeOffsets[type]; + strider = (T*)(vbo.getMappedData() + vbo.getOffset(type)+index*stride); + strider.setStride(stride); + return TRUE; + } + else + { + llerrs << "VertexBufferStrider could not find valid vertex data." << llendl; + } + return FALSE; + } +}; + +#else + template struct VertexBufferStrider { typedef LLStrider strider_t; @@ -1010,6 +1116,7 @@ template struct VertexBufferStrider } }; +#endif bool LLVertexBuffer::getVertexStrider(LLStrider& strider, S32 index) { @@ -1272,6 +1379,82 @@ void LLVertexBuffer::setBuffer(U32 data_mask) } } +#if LL_ALIGNED_VB + +// virtual (default) +void LLVertexBuffer::setupVertexBuffer(U32 data_mask) const +{ + LLMemType mt2(LLMemType::MTYPE_VERTEX_SETUP_VERTEX_BUFFER); + stop_glerror(); + U8* base = useVBOs() ? (U8*) mAlignedOffset : mMappedData; + + if ((data_mask & mTypeMask) != data_mask) + { + llerrs << "LLVertexBuffer::setupVertexBuffer missing required components for supplied data mask." << llendl; + } + + + if (data_mask & MAP_NORMAL) + { + glNormalPointer(GL_FLOAT, LLVertexBuffer::sTypeOffsets[TYPE_NORMAL], (void*)(base + mOffsets[TYPE_NORMAL])); + } + if (data_mask & MAP_TEXCOORD3) + { + glClientActiveTextureARB(GL_TEXTURE3_ARB); + glTexCoordPointer(2,GL_FLOAT, LLVertexBuffer::sTypeOffsets[TYPE_TEXCOORD3], (void*)(base + mOffsets[TYPE_TEXCOORD3])); + glClientActiveTextureARB(GL_TEXTURE0_ARB); + } + if (data_mask & MAP_TEXCOORD2) + { + glClientActiveTextureARB(GL_TEXTURE2_ARB); + glTexCoordPointer(2,GL_FLOAT, LLVertexBuffer::sTypeOffsets[TYPE_TEXCOORD2], (void*)(base + mOffsets[TYPE_TEXCOORD2])); + glClientActiveTextureARB(GL_TEXTURE0_ARB); + } + if (data_mask & MAP_TEXCOORD1) + { + glClientActiveTextureARB(GL_TEXTURE1_ARB); + glTexCoordPointer(2,GL_FLOAT, LLVertexBuffer::sTypeOffsets[TYPE_TEXCOORD1], (void*)(base + mOffsets[TYPE_TEXCOORD1])); + glClientActiveTextureARB(GL_TEXTURE0_ARB); + } + if (data_mask & MAP_BINORMAL) + { + glClientActiveTextureARB(GL_TEXTURE2_ARB); + glTexCoordPointer(3,GL_FLOAT, LLVertexBuffer::sTypeOffsets[TYPE_BINORMAL], (void*)(base + mOffsets[TYPE_BINORMAL])); + glClientActiveTextureARB(GL_TEXTURE0_ARB); + } + if (data_mask & MAP_TEXCOORD0) + { + glTexCoordPointer(2,GL_FLOAT, LLVertexBuffer::sTypeOffsets[TYPE_TEXCOORD0], (void*)(base + mOffsets[TYPE_TEXCOORD0])); + } + if (data_mask & MAP_COLOR) + { + glColorPointer(4, GL_UNSIGNED_BYTE, LLVertexBuffer::sTypeOffsets[TYPE_COLOR], (void*)(base + mOffsets[TYPE_COLOR])); + } + + if (data_mask & MAP_WEIGHT) + { + glVertexAttribPointerARB(1, 1, GL_FLOAT, FALSE, LLVertexBuffer::sTypeOffsets[TYPE_WEIGHT], (void*)(base + mOffsets[TYPE_WEIGHT])); + } + + if (data_mask & MAP_WEIGHT4 && sWeight4Loc != -1) + { + glVertexAttribPointerARB(sWeight4Loc, 4, GL_FLOAT, FALSE, LLVertexBuffer::sTypeOffsets[TYPE_WEIGHT4], (void*)(base+mOffsets[TYPE_WEIGHT4])); + } + + if (data_mask & MAP_CLOTHWEIGHT) + { + glVertexAttribPointerARB(4, 4, GL_FLOAT, TRUE, LLVertexBuffer::sTypeOffsets[TYPE_CLOTHWEIGHT], (void*)(base + mOffsets[TYPE_CLOTHWEIGHT])); + } + if (data_mask & MAP_VERTEX) + { + glVertexPointer(3,GL_FLOAT, LLVertexBuffer::sTypeOffsets[TYPE_VERTEX], (void*)(base + 0)); + } + + llglassertok(); +} + +#else + // virtual (default) void LLVertexBuffer::setupVertexBuffer(U32 data_mask) const { @@ -1344,6 +1527,8 @@ void LLVertexBuffer::setupVertexBuffer(U32 data_mask) const llglassertok(); } +#endif + void LLVertexBuffer::markDirty(U32 vert_index, U32 vert_count, U32 indices_index, U32 indices_count) { // TODO: use GL_APPLE_flush_buffer_range here -- cgit v1.2.3 From e90d2f88e5ce584b52b24315c85845a9e5113b50 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 21 May 2010 14:31:17 -0500 Subject: Aligned index buffers. --- indra/llrender/llvertexbuffer.cpp | 56 +++++++++++---------------------------- 1 file changed, 16 insertions(+), 40 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index a50eb7211c..0f3c900d2b 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -453,6 +453,7 @@ LLVertexBuffer::LLVertexBuffer(U32 typemask, S32 usage) : mTypeMask = typemask; mStride = stride; mAlignedOffset = 0; + mAlignedIndexOffset = 0; sCount++; } @@ -642,16 +643,20 @@ void LLVertexBuffer::createGLIndices() mEmpty = TRUE; + //pad by 16 bytes for aligned copies + size += 16; + if (useVBOs()) { + //pad by another 16 bytes for VBO pointer adjustment + size += 16; mMappedIndexData = NULL; genIndices(); mResized = TRUE; } else { - mMappedIndexData = new U8[size]; - memset(mMappedIndexData, 0, size); + mMappedIndexData = (U8*) _mm_malloc(size, 16); static int gl_buffer_idx = 0; mGLIndices = ++gl_buffer_idx; } @@ -699,7 +704,7 @@ void LLVertexBuffer::destroyGLIndices() } else { - delete [] mMappedIndexData; + _mm_free(mMappedIndexData); mMappedIndexData = NULL; mEmpty = TRUE; } @@ -836,26 +841,10 @@ void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) } else { - //delete old buffer, keep GL buffer for now if (!useVBOs()) { - U8* old = mMappedData; - mMappedData = new U8[newsize]; - if (old) - { - memcpy(mMappedData, old, llmin(newsize, oldsize)); - if (newsize > oldsize) - { - memset(mMappedData+oldsize, 0, newsize-oldsize); - } - - delete [] old; - } - else - { - memset(mMappedData, 0, newsize); - mEmpty = TRUE; - } + _mm_free(mMappedData); + mMappedData = (U8*) _mm_malloc(newsize, 16); } mResized = TRUE; } @@ -875,24 +864,8 @@ void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) { if (!useVBOs()) { - //delete old buffer, keep GL buffer for now - U8* old = mMappedIndexData; - mMappedIndexData = new U8[new_index_size]; - - if (old) - { - memcpy(mMappedIndexData, old, llmin(new_index_size, old_index_size)); - if (new_index_size > old_index_size) - { - memset(mMappedIndexData+old_index_size, 0, new_index_size - old_index_size); - } - delete [] old; - } - else - { - memset(mMappedIndexData, 0, new_index_size); - mEmpty = TRUE; - } + _mm_free(mMappedIndexData); + mMappedIndexData = (U8*) _mm_malloc(new_index_size, 16); } mResized = TRUE; } @@ -958,7 +931,10 @@ U8* LLVertexBuffer::mapBuffer(S32 access) } { LLMemType mt_v(LLMemType::MTYPE_VERTEX_MAP_BUFFER_INDICES); - mMappedIndexData = (U8*) glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + U8* src = (U8*) glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + mMappedIndexData = LL_NEXT_ALIGNED_ADDRESS(src); + mAlignedIndexOffset = mMappedIndexData - src; + stop_glerror(); } -- cgit v1.2.3 From a3075d8837d61ed4a9604c948bd8726c60ac2694 Mon Sep 17 00:00:00 2001 From: Tofu Linden Date: Mon, 24 May 2010 11:28:13 +0100 Subject: fix a tiny subset of the current build errors --- indra/llrender/llvertexbuffer.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 0f3c900d2b..23303b6d5c 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -822,9 +822,6 @@ void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) { sAllocatedBytes -= getSize() + getIndicesSize(); - S32 oldsize = getSize(); - S32 old_index_size = getIndicesSize(); - updateNumVerts(newnverts); updateNumIndices(newnindices); -- cgit v1.2.3 From 7eba473723a260a1025b5a865715573b2369298e Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 24 May 2010 14:01:18 -0500 Subject: Fix for bad indexes on cube faces. Extra validation on vertex buffers. --- indra/llrender/llvertexbuffer.cpp | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 0f3c900d2b..e6943cc551 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -261,10 +261,8 @@ void LLVertexBuffer::setupClientArrays(U32 data_mask) } } -void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indices_offset) const +void LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_offset) const { - llassert(mRequestedNumVerts >= 0); - if (start >= (U32) mRequestedNumVerts || end >= (U32) mRequestedNumVerts) { @@ -279,6 +277,25 @@ void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indi llerrs << "Bad index buffer draw range: [" << indices_offset << ", " << indices_offset+count << "]" << llendl; } + if (gDebugGL && !useVBOs()) + { + U16* idx = ((U16*) getIndicesPointer())+indices_offset; + for (U32 i = 0; i < count; ++i) + { + if (idx[i] < start || idx[i] > end) + { + llerrs << "Index out of range: " << idx[i] << " not in [" << start << ", " << end << "]" << llendl; + } + } + } +} + +void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indices_offset) const +{ + validateRange(start, end, count, indices_offset); + + llassert(mRequestedNumVerts >= 0); + if (mGLIndices != sGLRenderIndices) { llerrs << "Wrong index buffer bound." << llendl; @@ -297,17 +314,6 @@ void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indi U16* idx = ((U16*) getIndicesPointer())+indices_offset; - if (gDebugGL && !useVBOs()) - { - for (U32 i = 0; i < count; ++i) - { - if (idx[i] < start || idx[i] > end) - { - llerrs << "Index out of range: " << idx[i] << " not in [" << start << ", " << end << "]" << llendl; - } - } - } - stop_glerror(); glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT, idx); -- cgit v1.2.3 From 051d55e9e417d1f70e4a0dcee0035f6e2a413792 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 24 May 2010 23:34:50 -0500 Subject: Terrain is no longer mutilated. --- indra/llrender/llvertexbuffer.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 18f7557da9..7f14a8d5ac 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -1372,7 +1372,6 @@ void LLVertexBuffer::setupVertexBuffer(U32 data_mask) const llerrs << "LLVertexBuffer::setupVertexBuffer missing required components for supplied data mask." << llendl; } - if (data_mask & MAP_NORMAL) { glNormalPointer(GL_FLOAT, LLVertexBuffer::sTypeOffsets[TYPE_NORMAL], (void*)(base + mOffsets[TYPE_NORMAL])); -- cgit v1.2.3 From a4ce5c9eaa0d69ff7acf5fb710f0b9a601fb2a75 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 4 Jun 2010 00:09:52 -0500 Subject: Fix for useVBOs being busted when sEnableVBOs gets flipped. --- indra/llrender/llvertexbuffer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 7f14a8d5ac..4f2dae0cdf 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -900,7 +900,7 @@ BOOL LLVertexBuffer::useVBOs() const return FALSE; } #endif - return sEnableVBOs; + return TRUE; } //---------------------------------------------------------------------------- @@ -1317,7 +1317,7 @@ void LLVertexBuffer::setBuffer(U32 data_mask) { if (mGLBuffer) { - if (sEnableVBOs && sVBOActive) + if (useVBOs() && sVBOActive) { glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); sBindCount++; @@ -1329,7 +1329,7 @@ void LLVertexBuffer::setBuffer(U32 data_mask) setup = TRUE; // ... or a client memory pointer changed } } - if (sEnableVBOs && mGLIndices && sIBOActive) + if (useVBOs() && mGLIndices && sIBOActive) { /*if (sMapped) { -- cgit v1.2.3 From 697e7a3b0c6a6a014bbf4eebc801f15c0af0a235 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 4 Jun 2010 00:09:52 -0500 Subject: Fix for useVBOs being busted when sEnableVBOs gets flipped. (transplanted from 19717602f45950c058c8ddce792d57ef21f67c99) --- indra/llrender/llvertexbuffer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index ae43915a9d..4e94138746 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -819,7 +819,7 @@ BOOL LLVertexBuffer::useVBOs() const return FALSE; } #endif - return sEnableVBOs; + return TRUE; } //---------------------------------------------------------------------------- @@ -1183,7 +1183,7 @@ void LLVertexBuffer::setBuffer(U32 data_mask) { if (mGLBuffer) { - if (sEnableVBOs && sVBOActive) + if (useVBOs() && sVBOActive) { glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); sBindCount++; @@ -1195,7 +1195,7 @@ void LLVertexBuffer::setBuffer(U32 data_mask) setup = TRUE; // ... or a client memory pointer changed } } - if (sEnableVBOs && mGLIndices && sIBOActive) + if (useVBOs() && mGLIndices && sIBOActive) { /*if (sMapped) { -- cgit v1.2.3 From f40d07512ab54ba3da38c8a8b92cf0c6d1469bc6 Mon Sep 17 00:00:00 2001 From: Tofu Linden Date: Fri, 4 Jun 2010 09:04:36 +0100 Subject: finish conversion to ll_aligned_*() wrappers --- indra/llrender/llvertexbuffer.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 4f2dae0cdf..ff966f1e95 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -627,7 +627,7 @@ void LLVertexBuffer::createGLBuffer() { static int gl_buffer_idx = 0; mGLBuffer = ++gl_buffer_idx; - mMappedData = (U8*) _mm_malloc(size, 16); + mMappedData = (U8*) ll_aligned_malloc_16(size); memset(mMappedData, 0, size); } } @@ -662,7 +662,7 @@ void LLVertexBuffer::createGLIndices() } else { - mMappedIndexData = (U8*) _mm_malloc(size, 16); + mMappedIndexData = (U8*) ll_aligned_malloc_16(size); static int gl_buffer_idx = 0; mGLIndices = ++gl_buffer_idx; } @@ -683,7 +683,7 @@ void LLVertexBuffer::destroyGLBuffer() } else { - _mm_free(mMappedData); + ll_aligned_free_16(mMappedData); mMappedData = NULL; mEmpty = TRUE; } @@ -710,7 +710,7 @@ void LLVertexBuffer::destroyGLIndices() } else { - _mm_free(mMappedIndexData); + ll_aligned_free_16(mMappedIndexData); mMappedIndexData = NULL; mEmpty = TRUE; } @@ -846,8 +846,8 @@ void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) { if (!useVBOs()) { - _mm_free(mMappedData); - mMappedData = (U8*) _mm_malloc(newsize, 16); + ll_aligned_free_16(mMappedData); + mMappedData = (U8*) ll_aligned_malloc_16(newsize); } mResized = TRUE; } @@ -867,8 +867,8 @@ void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) { if (!useVBOs()) { - _mm_free(mMappedIndexData); - mMappedIndexData = (U8*) _mm_malloc(new_index_size, 16); + ll_aligned_free_16(mMappedIndexData); + mMappedIndexData = (U8*) ll_aligned_malloc_16(new_index_size); } mResized = TRUE; } -- cgit v1.2.3 From 9878c0240450ad3d580d0518762ae0db96c25eff Mon Sep 17 00:00:00 2001 From: Tofu Linden Date: Fri, 4 Jun 2010 09:07:25 +0100 Subject: add some #includes for our wrappers --- indra/llrender/llvertexbuffer.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index ff966f1e95..48c20b09a8 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -31,6 +31,7 @@ */ #include "linden_common.h" +#include "llmemory.h" #include -- cgit v1.2.3 From f9b13d8f8510b1f7f02fcf92685471461b79858e Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 10 Jun 2010 00:45:48 -0500 Subject: Add "LL_MESH_ENABLED" preprocessor flag for toggling mesh code. Couple of merge fixes. --- indra/llrender/llvertexbuffer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 48c20b09a8..514ca25aa0 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -1318,7 +1318,7 @@ void LLVertexBuffer::setBuffer(U32 data_mask) { if (mGLBuffer) { - if (useVBOs() && sVBOActive) + if (sVBOActive) { glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); sBindCount++; @@ -1330,7 +1330,7 @@ void LLVertexBuffer::setBuffer(U32 data_mask) setup = TRUE; // ... or a client memory pointer changed } } - if (useVBOs() && mGLIndices && sIBOActive) + if (mGLIndices && sIBOActive) { /*if (sMapped) { -- cgit v1.2.3 From 46768c3c6c263ec27a80c854734ce0b61d29686f Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 12 Jul 2010 07:39:23 -0500 Subject: Merge? --- indra/llrender/llvertexbuffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 514ca25aa0..1d02ca4f4c 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -267,7 +267,7 @@ void LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_of if (start >= (U32) mRequestedNumVerts || end >= (U32) mRequestedNumVerts) { - llerrs << "Bad vertex buffer draw range: [" << start << ", " << end << "]" << llendl; + llerrs << "Bad vertex buffer draw range: [" << start << ", " << end << "] vs " << mRequestedNumVerts << llendl; } llassert(mRequestedNumIndices >= 0); -- cgit v1.2.3 From 340a729d55983110a85cfc55f1ce0a952bfe15b4 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 12 Aug 2010 17:05:40 -0500 Subject: Vertex buffer cleanup, adding water shader to simple rigged attachments. Reviewed by Nyx. --- indra/llrender/llvertexbuffer.cpp | 232 +++++--------------------------------- 1 file changed, 30 insertions(+), 202 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 9783435e2f..71620feed3 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -68,11 +68,8 @@ S32 LLVertexBuffer::sWeight4Loc = -1; std::vector LLVertexBuffer::sDeleteList; -#define LL_ALIGNED_VB 1 -#if LL_ALIGNED_VB - -S32 LLVertexBuffer::sTypeOffsets[LLVertexBuffer::TYPE_MAX] = +S32 LLVertexBuffer::sTypeSize[LLVertexBuffer::TYPE_MAX] = { sizeof(LLVector4), // TYPE_VERTEX, sizeof(LLVector4), // TYPE_NORMAL, @@ -87,25 +84,6 @@ S32 LLVertexBuffer::sTypeOffsets[LLVertexBuffer::TYPE_MAX] = sizeof(LLVector4), // TYPE_CLOTHWEIGHT, }; -#else - -S32 LLVertexBuffer::sTypeOffsets[LLVertexBuffer::TYPE_MAX] = -{ - sizeof(LLVector3), // TYPE_VERTEX, - sizeof(LLVector3), // TYPE_NORMAL, - sizeof(LLVector2), // TYPE_TEXCOORD0, - sizeof(LLVector2), // TYPE_TEXCOORD1, - sizeof(LLVector2), // TYPE_TEXCOORD2, - sizeof(LLVector2), // TYPE_TEXCOORD3, - sizeof(LLColor4U), // TYPE_COLOR, - sizeof(LLVector3), // TYPE_BINORMAL, - sizeof(F32), // TYPE_WEIGHT, - sizeof(LLVector4), // TYPE_WEIGHT4, - sizeof(LLVector4), // TYPE_CLOTHWEIGHT, -}; - -#endif - U32 LLVertexBuffer::sGLMode[LLRender::NUM_MODES] = { GL_TRIANGLES, @@ -460,19 +438,22 @@ LLVertexBuffer::LLVertexBuffer(U32 typemask, S32 usage) : mUsage = 0; } - S32 stride = calcStride(typemask, mOffsets); + //zero out offsets + for (U32 i = 0; i < TYPE_MAX; i++) + { + mOffsets[i] = 0; + } mTypeMask = typemask; - mStride = stride; + mSize = 0; mAlignedOffset = 0; mAlignedIndexOffset = 0; sCount++; } -#if LL_ALIGNED_VB //static -S32 LLVertexBuffer::calcStride(const U32& typemask, S32* offsets, S32 num_vertices) +S32 LLVertexBuffer::calcOffsets(const U32& typemask, S32* offsets, S32 num_vertices) { S32 offset = 0; for (S32 i=0; i struct VertexBufferStrider { typedef LLStrider strider_t; @@ -1051,7 +1015,7 @@ template struct VertexBufferStrider } else if (vbo.hasDataType(type)) { - S32 stride = LLVertexBuffer::sTypeOffsets[type]; + S32 stride = LLVertexBuffer::sTypeSize[type]; strider = (T*)(vbo.getMappedData() + vbo.getOffset(type)+index*stride); strider.setStride(stride); return TRUE; @@ -1064,45 +1028,6 @@ template struct VertexBufferStrider } }; -#else - -template struct VertexBufferStrider -{ - typedef LLStrider strider_t; - static bool get(LLVertexBuffer& vbo, - strider_t& strider, - S32 index) - { - if (vbo.mapBuffer() == NULL) - { - llwarns << "mapBuffer failed!" << llendl; - return FALSE; - } - - if (type == LLVertexBuffer::TYPE_INDEX) - { - S32 stride = sizeof(T); - strider = (T*)(vbo.getMappedIndices() + index*stride); - strider.setStride(0); - return TRUE; - } - else if (vbo.hasDataType(type)) - { - S32 stride = vbo.getStride(); - strider = (T*)(vbo.getMappedData() + vbo.getOffset(type) + index*stride); - strider.setStride(stride); - return TRUE; - } - else - { - llerrs << "VertexBufferStrider could not find valid vertex data." << llendl; - } - return FALSE; - } -}; - -#endif - bool LLVertexBuffer::getVertexStrider(LLStrider& strider, S32 index) { return VertexBufferStrider::get(*this, strider, index); @@ -1154,25 +1079,6 @@ bool LLVertexBuffer::getClothWeightStrider(LLStrider& strider, S32 in return VertexBufferStrider::get(*this, strider, index); } -void LLVertexBuffer::setStride(S32 type, S32 new_stride) -{ - LLMemType mt2(LLMemType::MTYPE_VERTEX_SET_STRIDE); - if (mNumVerts) - { - llerrs << "LLVertexBuffer::setOffset called with mNumVerts = " << mNumVerts << llendl; - } - // This code assumes that setStride() will only be called once per VBO per type. - S32 delta = new_stride - sTypeOffsets[type]; - for (S32 i=type+1; i Date: Tue, 21 Sep 2010 13:26:52 -0400 Subject: Fix for build failures - disabling tcmalloc for now --- indra/llrender/llvertexbuffer.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 indra/llrender/llvertexbuffer.cpp (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp old mode 100644 new mode 100755 -- cgit v1.2.3 From 61257991ba915718f1d19947d72e7bb13139bb03 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 22 Sep 2010 01:43:22 -0500 Subject: Stop using aligned malloc in llvertexbuffer (tcmalloc is automagically aligned). --- indra/llrender/llvertexbuffer.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 71620feed3..66beb5f003 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -603,7 +603,7 @@ void LLVertexBuffer::createGLBuffer() { static int gl_buffer_idx = 0; mGLBuffer = ++gl_buffer_idx; - mMappedData = (U8*) ll_aligned_malloc_16(size); + mMappedData = (U8*) malloc(size); } } @@ -637,7 +637,7 @@ void LLVertexBuffer::createGLIndices() } else { - mMappedIndexData = (U8*) ll_aligned_malloc_16(size); + mMappedIndexData = (U8*) malloc(size); static int gl_buffer_idx = 0; mGLIndices = ++gl_buffer_idx; } @@ -658,7 +658,7 @@ void LLVertexBuffer::destroyGLBuffer() } else { - ll_aligned_free_16(mMappedData); + free(mMappedData); mMappedData = NULL; mEmpty = TRUE; } @@ -685,7 +685,7 @@ void LLVertexBuffer::destroyGLIndices() } else { - ll_aligned_free_16(mMappedIndexData); + free(mMappedIndexData); mMappedIndexData = NULL; mEmpty = TRUE; } @@ -818,8 +818,8 @@ void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) { if (!useVBOs()) { - ll_aligned_free_16(mMappedData); - mMappedData = (U8*) ll_aligned_malloc_16(newsize); + free(mMappedData); + mMappedData = (U8*) malloc(newsize); } mResized = TRUE; } @@ -839,8 +839,8 @@ void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) { if (!useVBOs()) { - ll_aligned_free_16(mMappedIndexData); - mMappedIndexData = (U8*) ll_aligned_malloc_16(new_index_size); + free(mMappedIndexData); + mMappedIndexData = (U8*) malloc(new_index_size); } mResized = TRUE; } -- cgit v1.2.3 From a5619d16f74863168f45b04b37cc6383e1a92263 Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Wed, 13 Oct 2010 07:24:37 -0400 Subject: correct licenses (fix problem with license change merge) --- indra/llrender/llvertexbuffer.cpp | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 66beb5f003..5ac5e2e8f4 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -2,31 +2,25 @@ * @file llvertexbuffer.cpp * @brief LLVertexBuffer implementation * - * $LicenseInfo:firstyear=2003&license=viewergpl$ - * - * Copyright (c) 2003-2009, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2003&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at - * http://secondlifegrid.net/programs/open_source/licensing/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ -- cgit v1.2.3 From 9e0ee4dff0109326c31425581437a44351d08344 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 17 Feb 2011 17:18:57 -0600 Subject: SH-1006 Quick pass at cutting down the number of redundant GL calls based on data from gDEBugger. Reviewed by Nyx. --- indra/llrender/llvertexbuffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 07ec31dbd5..51870515f2 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -143,7 +143,7 @@ void LLVertexBuffer::setupClientArrays(U32 data_mask) } else { //was disabled - if (data_mask & mask[i]) + if (data_mask & mask[i] && i > 0) { //needs to be enabled glEnableClientState(array[i]); } -- cgit v1.2.3 From e55e91a5a546832b79643fdcd2208b5e4f62b6df Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 22 Feb 2011 18:36:50 -0600 Subject: SH-874 Better VBO usage hints, most notably don't use VBOs for occlusion queries if GL is set to not use VBOs for stream draw. --- indra/llrender/llvertexbuffer.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 51870515f2..f5e85aecda 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -58,6 +58,7 @@ BOOL LLVertexBuffer::sIBOActive = FALSE; U32 LLVertexBuffer::sAllocatedBytes = 0; BOOL LLVertexBuffer::sMapped = FALSE; BOOL LLVertexBuffer::sUseStreamDraw = TRUE; +BOOL LLVertexBuffer::sPreferStreamDraw = FALSE; S32 LLVertexBuffer::sWeight4Loc = -1; std::vector LLVertexBuffer::sDeleteList; @@ -147,7 +148,7 @@ void LLVertexBuffer::setupClientArrays(U32 data_mask) { //needs to be enabled glEnableClientState(array[i]); } - else if (gDebugGL && glIsEnabled(array[i])) + else if (gDebugGL && i > 0 && glIsEnabled(array[i])) { //needs to be disabled, make sure it was (DEBUG TEMPORARY) if (gDebugSession) { @@ -427,9 +428,9 @@ LLVertexBuffer::LLVertexBuffer(U32 typemask, S32 usage) : mUsage = 0; } - if (mUsage == GL_STREAM_DRAW_ARB && !sUseStreamDraw) + if (mUsage == GL_DYNAMIC_DRAW_ARB && sPreferStreamDraw) { - mUsage = 0; + mUsage = GL_STREAM_DRAW_ARB; } //zero out offsets -- cgit v1.2.3 From 3d77dd6b5806bededd6b71402f71b9f0675c27c7 Mon Sep 17 00:00:00 2001 From: Loren Shih Date: Wed, 23 Feb 2011 16:24:47 -0500 Subject: Merge: Backed out changes for STORM-336 for merge due to complexity, will need to apply these manually. --- indra/llrender/llvertexbuffer.cpp | 160 ++++++++------------------------------ 1 file changed, 34 insertions(+), 126 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 7a1ccb0cb4..f5e85aecda 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -49,7 +49,6 @@ U32 LLVertexBuffer::sSetCount = 0; S32 LLVertexBuffer::sCount = 0; S32 LLVertexBuffer::sGLCount = 0; S32 LLVertexBuffer::sMappedCount = 0; -BOOL LLVertexBuffer::sDisableVBOMapping = FALSE ; BOOL LLVertexBuffer::sEnableVBOs = TRUE; U32 LLVertexBuffer::sGLRenderBuffer = 0; U32 LLVertexBuffer::sGLRenderIndices = 0; @@ -298,7 +297,6 @@ void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indi void LLVertexBuffer::draw(U32 mode, U32 count, U32 indices_offset) const { llassert(mRequestedNumIndices >= 0); - if (indices_offset >= (U32) mRequestedNumIndices || indices_offset + count > (U32) mRequestedNumIndices) { @@ -330,7 +328,6 @@ void LLVertexBuffer::draw(U32 mode, U32 count, U32 indices_offset) const void LLVertexBuffer::drawArrays(U32 mode, U32 first, U32 count) const { llassert(mRequestedNumVerts >= 0); - if (first >= (U32) mRequestedNumVerts || first + count > (U32) mRequestedNumVerts) { @@ -354,10 +351,9 @@ void LLVertexBuffer::drawArrays(U32 mode, U32 first, U32 count) const } //static -void LLVertexBuffer::initClass(bool use_vbo, bool no_vbo_mapping) +void LLVertexBuffer::initClass(bool use_vbo) { sEnableVBOs = use_vbo; - sDisableVBOMapping = sEnableVBOs && no_vbo_mapping ; LLGLNamePool::registerPool(&sDynamicVBOPool); LLGLNamePool::registerPool(&sDynamicIBOPool); LLGLNamePool::registerPool(&sStreamVBOPool); @@ -501,8 +497,6 @@ LLVertexBuffer::~LLVertexBuffer() destroyGLBuffer(); destroyGLIndices(); sCount--; - - llassert_always(!mMappedData && !mMappedIndexData) ; }; //---------------------------------------------------------------------------- @@ -651,8 +645,6 @@ void LLVertexBuffer::destroyGLBuffer() { if (useVBOs()) { - freeClientBuffer() ; - if (mMappedData || mMappedIndexData) { llerrs << "Vertex buffer destroyed while mapped!" << llendl; @@ -680,13 +672,11 @@ void LLVertexBuffer::destroyGLIndices() { if (useVBOs()) { - freeClientBuffer() ; - if (mMappedData || mMappedIndexData) { llerrs << "Vertex buffer destroyed while mapped." << llendl; } - releaseIndices(); + releaseIndices(); } else { @@ -858,7 +848,6 @@ void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) if (mResized && useVBOs()) { - freeClientBuffer() ; setBuffer(0); } } @@ -882,36 +871,6 @@ BOOL LLVertexBuffer::useVBOs() const } //---------------------------------------------------------------------------- -void LLVertexBuffer::freeClientBuffer() -{ - if(useVBOs() && sDisableVBOMapping && (mMappedData || mMappedIndexData)) - { - delete[] mMappedData ; - delete[] mMappedIndexData ; - mMappedData = NULL ; - mMappedIndexData = NULL ; - } -} - -void LLVertexBuffer::allocateClientVertexBuffer() -{ - if(!mMappedData) - { - U32 size = getSize() ; - mMappedData = new U8[size]; - memset(mMappedData, 0, size); - } -} - -void LLVertexBuffer::allocateClientIndexBuffer() -{ - if(!mMappedIndexData) - { - U32 size = getIndicesSize(); - mMappedIndexData = new U8[size]; - memset(mMappedIndexData, 0, size); - } -} // Map for data access U8* LLVertexBuffer::mapBuffer(S32 access) @@ -934,14 +893,10 @@ U8* LLVertexBuffer::mapBuffer(S32 access) mLocked = TRUE; stop_glerror(); - if(sDisableVBOMapping) - { - allocateClientVertexBuffer() ; - } - else - { - mMappedData = (U8*) glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); - } + U8* src = (U8*) glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + mMappedData = LL_NEXT_ALIGNED_ADDRESS(src); + mAlignedOffset = mMappedData - src; + stop_glerror(); } { @@ -950,14 +905,6 @@ U8* LLVertexBuffer::mapBuffer(S32 access) mMappedIndexData = LL_NEXT_ALIGNED_ADDRESS(src); mAlignedIndexOffset = mMappedIndexData - src; - if(sDisableVBOMapping) - { - allocateClientIndexBuffer() ; - } - else - { - mMappedIndexData = (U8*) glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); - } stop_glerror(); } @@ -971,51 +918,37 @@ U8* LLVertexBuffer::mapBuffer(S32 access) llinfos << "Available physical mwmory(KB): " << avail_phy_mem << llendl ; llinfos << "Available virtual memory(KB): " << avail_vir_mem << llendl; - if(!sDisableVBOMapping) - { - //-------------------- - //print out more debug info before crash - llinfos << "vertex buffer size: (num verts : num indices) = " << getNumVerts() << " : " << getNumIndices() << llendl ; - GLint size ; - glGetBufferParameterivARB(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SIZE_ARB, &size) ; - llinfos << "GL_ARRAY_BUFFER_ARB size is " << size << llendl ; - //-------------------- + //-------------------- + //print out more debug info before crash + llinfos << "vertex buffer size: (num verts : num indices) = " << getNumVerts() << " : " << getNumIndices() << llendl ; + GLint size ; + glGetBufferParameterivARB(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SIZE_ARB, &size) ; + llinfos << "GL_ARRAY_BUFFER_ARB size is " << size << llendl ; + //-------------------- - GLint buff; - glGetIntegerv(GL_ARRAY_BUFFER_BINDING_ARB, &buff); - if ((GLuint)buff != mGLBuffer) - { - llerrs << "Invalid GL vertex buffer bound: " << buff << llendl; - } - - - llerrs << "glMapBuffer returned NULL (no vertex data)" << llendl; - } - else + GLint buff; + glGetIntegerv(GL_ARRAY_BUFFER_BINDING_ARB, &buff); + if ((GLuint)buff != mGLBuffer) { - llerrs << "memory allocation for vertex data failed." << llendl ; + llerrs << "Invalid GL vertex buffer bound: " << buff << llendl; } + + + llerrs << "glMapBuffer returned NULL (no vertex data)" << llendl; } if (!mMappedIndexData) { log_glerror(); - if(!sDisableVBOMapping) - { - GLint buff; - glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, &buff); - if ((GLuint)buff != mGLIndices) - { - llerrs << "Invalid GL index buffer bound: " << buff << llendl; - } - - llerrs << "glMapBuffer returned NULL (no index data)" << llendl; - } - else + GLint buff; + glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, &buff); + if ((GLuint)buff != mGLIndices) { - llerrs << "memory allocation for Index data failed. " << llendl ; + llerrs << "Invalid GL index buffer bound: " << buff << llendl; } + + llerrs << "glMapBuffer returned NULL (no index data)" << llendl; } sMappedCount++; @@ -1031,29 +964,11 @@ void LLVertexBuffer::unmapBuffer() { if (useVBOs() && mLocked) { - if(sDisableVBOMapping) - { - if(mMappedData) - { - stop_glerror(); - glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, getSize(), mMappedData); - stop_glerror(); - } - if(mMappedIndexData) - { - stop_glerror(); - glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0, getIndicesSize(), mMappedIndexData); - stop_glerror(); - } - } - else - { - stop_glerror(); - glUnmapBufferARB(GL_ARRAY_BUFFER_ARB); - stop_glerror(); - glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB); - stop_glerror(); - } + stop_glerror(); + glUnmapBufferARB(GL_ARRAY_BUFFER_ARB); + stop_glerror(); + glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB); + stop_glerror(); /*if (!sMapped) { @@ -1067,22 +982,15 @@ void LLVertexBuffer::unmapBuffer() //throw out client data (we won't be using it again) mEmpty = TRUE; mFinal = TRUE; - - if(sDisableVBOMapping) - { - freeClientBuffer() ; - } } else { mEmpty = FALSE; } - if(!sDisableVBOMapping) - { - mMappedIndexData = NULL; - mMappedData = NULL; - } + mMappedIndexData = NULL; + mMappedData = NULL; + mLocked = FALSE; } } -- cgit v1.2.3 From 719610e68ba8275f08f51d127ab760799cb1d1c3 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 29 Mar 2011 11:50:02 -0500 Subject: SH-1225 Import convex hull data from .slm --- indra/llrender/llvertexbuffer.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 0d3f5b81bc..73efbfc999 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -236,6 +236,22 @@ void LLVertexBuffer::setupClientArrays(U32 data_mask) } } +//static +void LLVertexBuffer::drawArrays(U32 mode, const std::vector& pos, const std::vector& norm) +{ + U32 count = pos.size(); + llassert(norm.size() >= pos.size()); + + unbind(); + + setupClientArrays(MAP_VERTEX | MAP_NORMAL); + + glVertexPointer(3, GL_FLOAT, 0, pos[0].mV); + glNormalPointer(GL_FLOAT, 0, norm[0].mV); + + glDrawArrays(sGLMode[mode], 0, count); +} + void LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_offset) const { if (start >= (U32) mRequestedNumVerts || -- cgit v1.2.3 From 2a843e9a6bb5cb70f69794419ab4a7d16ee3c6cb Mon Sep 17 00:00:00 2001 From: brad kittenbrink Date: Thu, 12 May 2011 16:09:42 -0700 Subject: Fix up alignment problems for debug build. reviewed by davep. --- indra/llrender/llvertexbuffer.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 73efbfc999..94a04ba6ca 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -633,7 +633,7 @@ void LLVertexBuffer::createGLBuffer() { static int gl_buffer_idx = 0; mGLBuffer = ++gl_buffer_idx; - mMappedData = (U8*) malloc(size); + mMappedData = (U8*) ll_aligned_malloc_16(size); } } @@ -667,7 +667,7 @@ void LLVertexBuffer::createGLIndices() } else { - mMappedIndexData = (U8*) malloc(size); + mMappedIndexData = (U8*) ll_aligned_malloc_16(size); static int gl_buffer_idx = 0; mGLIndices = ++gl_buffer_idx; } @@ -690,7 +690,7 @@ void LLVertexBuffer::destroyGLBuffer() } else { - free(mMappedData); + ll_aligned_free_16(mMappedData); mMappedData = NULL; mEmpty = TRUE; } @@ -719,7 +719,7 @@ void LLVertexBuffer::destroyGLIndices() } else { - free(mMappedIndexData); + ll_aligned_free_16(mMappedIndexData); mMappedIndexData = NULL; mEmpty = TRUE; } @@ -852,8 +852,8 @@ void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) { if (!useVBOs()) { - free(mMappedData); - mMappedData = (U8*) malloc(newsize); + ll_aligned_free_16(mMappedData); + mMappedData = (U8*) ll_aligned_malloc_16(newsize); } mResized = TRUE; } @@ -873,8 +873,8 @@ void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) { if (!useVBOs()) { - free(mMappedIndexData); - mMappedIndexData = (U8*) malloc(new_index_size); + ll_aligned_free_16(mMappedIndexData); + mMappedIndexData = (U8*) ll_aligned_malloc_16(new_index_size); } mResized = TRUE; } @@ -915,8 +915,8 @@ void LLVertexBuffer::freeClientBuffer() { if(useVBOs() && sDisableVBOMapping && (mMappedData || mMappedIndexData)) { - free(mMappedData) ; - free(mMappedIndexData) ; + ll_aligned_free_16(mMappedData) ; + ll_aligned_free_16(mMappedIndexData) ; mMappedData = NULL ; mMappedIndexData = NULL ; } @@ -926,7 +926,7 @@ void LLVertexBuffer::allocateClientVertexBuffer() { if(!mMappedData) { - mMappedData = (U8*)malloc(getSize()); + mMappedData = (U8*)ll_aligned_malloc_16(getSize()); } } @@ -934,7 +934,7 @@ void LLVertexBuffer::allocateClientIndexBuffer() { if(!mMappedIndexData) { - mMappedIndexData = (U8*)malloc(getIndicesSize()); + mMappedIndexData = (U8*)ll_aligned_malloc_16(getIndicesSize()); } } -- cgit v1.2.3