From 5da88f5a809fd6f29d7704cfd947226e23714bd1 Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Wed, 5 May 2021 13:09:16 -0600 Subject: SL-15221 add VBO dirty bit to avoid many per-frame checks --- indra/llrender/llvertexbuffer.cpp | 45 +++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 21 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 7d2b09ca4a..0d39d503d7 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -144,9 +144,10 @@ void LLVBOPool::deleteBuffer(U32 name) LLVBOPool::LLVBOPool(U32 vboUsage, U32 vboType) -: mUsage(vboUsage), mType(vboType) +: mUsage(vboUsage), mType(vboType), mMissCountDirty(true) { - mMissCount.resize(LL_VBO_POOL_SEED_COUNT); + mFreeList.resize(LL_VBO_POOL_SEED_COUNT); + mMissCount.resize(LL_VBO_POOL_SEED_COUNT); std::fill(mMissCount.begin(), mMissCount.end(), 0); } @@ -173,7 +174,8 @@ volatile U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) if (!for_seed && i < LL_VBO_POOL_SEED_COUNT) { //record this miss mMissCount[i]++; - } + mMissCountDirty = true; // signal to ::seedPool() + } if (mType == GL_ARRAY_BUFFER_ARB) { @@ -226,6 +228,7 @@ volatile U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) sIndexBytesPooled += size; } mFreeList[i].push_back(rec); + mMissCountDirty = true; // signal to ::seedPool() } } else @@ -243,6 +246,7 @@ volatile U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) } mFreeList[i].pop_front(); + mMissCountDirty = true; // signal to ::seedPool() } return ret; @@ -267,26 +271,25 @@ void LLVBOPool::release(U32 name, volatile U8* buffer, U32 size) void LLVBOPool::seedPool() { - U32 dummy_name = 0; + if (mMissCountDirty) + { + U32 dummy_name = 0; - if (mFreeList.size() < LL_VBO_POOL_SEED_COUNT) - { - mFreeList.resize(LL_VBO_POOL_SEED_COUNT); - } + for (U32 i = 0; i < LL_VBO_POOL_SEED_COUNT; i++) + { + if (mMissCount[i] > mFreeList[i].size()) + { + U32 size = i * LL_VBO_BLOCK_SIZE; - for (U32 i = 0; i < LL_VBO_POOL_SEED_COUNT; i++) - { - if (mMissCount[i] > mFreeList[i].size()) - { - U32 size = i*LL_VBO_BLOCK_SIZE; - - S32 count = mMissCount[i] - mFreeList[i].size(); - for (U32 j = 0; j < count; ++j) - { - allocate(dummy_name, size, true); - } - } - } + S32 count = mMissCount[i] - mFreeList[i].size(); + for (U32 j = 0; j < count; ++j) + { + allocate(dummy_name, size, true); + } + } + } + mMissCountDirty = false; + } } -- cgit v1.2.3 From fd9fc8e4a5d49d0d24e22c6cb2391f75bf0ea763 Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Wed, 5 May 2021 15:15:50 -0600 Subject: SL-15221 fixed off-by-one accounting error --- indra/llrender/llvertexbuffer.cpp | 107 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 103 insertions(+), 4 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 0d39d503d7..ebf0b2fe78 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -74,10 +74,12 @@ U32 vbo_block_size(U32 size) U32 vbo_block_index(U32 size) { - return vbo_block_size(size)/LL_VBO_BLOCK_SIZE; + U32 blocks = vbo_block_size(size)/LL_VBO_BLOCK_SIZE; // block count reqd + llassert(blocks > 0); + return blocks - 1; // Adj index, i.e. single-block allocations are at index 0, etc } -const U32 LL_VBO_POOL_SEED_COUNT = vbo_block_index(LL_VBO_POOL_MAX_SEED_SIZE); +const U32 LL_VBO_POOL_SEED_COUNT = vbo_block_index(LL_VBO_POOL_MAX_SEED_SIZE) + 1; //============================================================================ @@ -118,6 +120,97 @@ bool LLVertexBuffer::sUseStreamDraw = true; bool LLVertexBuffer::sUseVAO = false; bool LLVertexBuffer::sPreferStreamDraw = false; +// DEBUG, temporary +#include + +typedef struct +{ + U32 allocated_size; + void* memptr; +} glbufmem; + +static std::unordered_map buf_list; + +void add_buf(U32 name, U32 size, void* ptr) +{ + LL_WARNS("VBO_ACCOUNTING") << "ADD add_buf GLname " << name << ", size " << size << ", ptr " << ptr << LL_ENDL; + + if (0 < buf_list.count(name)) + { + if (buf_list[name].allocated_size > 0) + { + U32 a = buf_list[name].allocated_size; + LL_WARNS("VBO_ACC_ERROR") << "add_buf error, adding duplicate GLname " << name << ", size " << size << ", allocated " << a << LL_ENDL; + } + } + + buf_list[name].allocated_size = size; + buf_list[name].memptr = ptr; +} + +U32 find_buf_size(U32 name) +{ + if (buf_list.count(name) > 0) return buf_list[name].allocated_size; + return 0; +} + +bool clear_buf(U32 name, U32 size, void* ptr) +{ + LL_WARNS("VBO_ACCOUNTING") << "DEL clear_buf GLname " << name << ", size " << size << ", ptr " << ptr << LL_ENDL; + + if (0 == buf_list.count(name)) + { + LL_WARNS("VBO_ACC_ERROR") << "clear_buf error, attempt to remove unknown GLname " << name << ", size " << size << LL_ENDL; + return false; + } + + if (buf_list[name].allocated_size == 0) + { + LL_WARNS("VBO_ACC_ERROR") << "clear_buf error, attempt to remove empty GLname " << name << ", size " << size << LL_ENDL; + return false; + } + + if (buf_list[name].allocated_size != size) + { + U32 a = buf_list[name].allocated_size; + LL_WARNS("VBO_ACC_ERROR") << "clear_buf error, size mismatch " << name << ", size " << size << ", allocated " << a << LL_ENDL; + buf_list[name].allocated_size = 0; + buf_list[name].memptr = nullptr; + return false; + } + + if (buf_list[name].memptr != ptr) + { + void* p = buf_list[name].memptr; + LL_WARNS("VBO_ACC_ERROR") << "clear_buf error, ptr mismatch " << name << ", ptr " << ptr << ", saved ptr " << p << LL_ENDL; + buf_list[name].allocated_size = 0; + buf_list[name].memptr = nullptr; + return false; + } + + buf_list[name].allocated_size = 0; + buf_list[name].memptr = nullptr; + return true; +} + +#if 0 + // Find the GLname in the freelist +for (U32 i = 0; i < LL_VBO_POOL_SEED_COUNT; i++) +{ + for (auto &r : mFreeList[i]) + { + if (r.mGLName == name) + { + LL_WARNS() << "Release size " << size << ", found Name " << name << " in bucket " << i << LL_ENDL; + } + } +} + +// Remove the buffer record from the free record list, by GLname +U32 i = vbo_block_index(size); +mFreeList[i].remove_if([name](Record r) {return (name == r.mGLName); }); +i++; +#endif U32 LLVBOPool::genBuffer() { @@ -230,6 +323,8 @@ volatile U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) mFreeList[i].push_back(rec); mMissCountDirty = true; // signal to ::seedPool() } + + add_buf(name, size, (void*)ret); } else { @@ -267,6 +362,8 @@ void LLVBOPool::release(U32 name, volatile U8* buffer, U32 size) { LLVertexBuffer::sAllocatedIndexBytes -= size; } + + clear_buf(name, size, (void*)buffer); } void LLVBOPool::seedPool() @@ -274,19 +371,19 @@ void LLVBOPool::seedPool() if (mMissCountDirty) { U32 dummy_name = 0; + U32 size = LL_VBO_BLOCK_SIZE; for (U32 i = 0; i < LL_VBO_POOL_SEED_COUNT; i++) { if (mMissCount[i] > mFreeList[i].size()) { - U32 size = i * LL_VBO_BLOCK_SIZE; - S32 count = mMissCount[i] - mFreeList[i].size(); for (U32 j = 0; j < count; ++j) { allocate(dummy_name, size, true); } } + size += LL_VBO_BLOCK_SIZE; } mMissCountDirty = false; } @@ -313,6 +410,8 @@ void LLVBOPool::cleanup() ll_aligned_free<64>((void*) r.mClientData); } + clear_buf(r.mGLName, size, (void*)r.mClientData); + l.pop_front(); if (mType == GL_ARRAY_BUFFER_ARB) -- cgit v1.2.3 From 7131f8c46499b8f856c35137cda5ad4cb1bce527 Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Thu, 6 May 2021 14:50:26 -0600 Subject: SL-15221 strip debug code, add sanity asserts, format --- indra/llrender/llvertexbuffer.cpp | 275 +++++++++++++------------------------- 1 file changed, 90 insertions(+), 185 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index ebf0b2fe78..93967b128d 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -68,8 +68,8 @@ const U32 LL_VBO_POOL_MAX_SEED_SIZE = 256*1024; U32 vbo_block_size(U32 size) { //what block size will fit size? - U32 mod = size % LL_VBO_BLOCK_SIZE; - return mod == 0 ? size : size + (LL_VBO_BLOCK_SIZE-mod); + U32 mod = size % LL_VBO_BLOCK_SIZE; + return mod == 0 ? size : size + (LL_VBO_BLOCK_SIZE-mod); } U32 vbo_block_index(U32 size) @@ -120,98 +120,6 @@ bool LLVertexBuffer::sUseStreamDraw = true; bool LLVertexBuffer::sUseVAO = false; bool LLVertexBuffer::sPreferStreamDraw = false; -// DEBUG, temporary -#include - -typedef struct -{ - U32 allocated_size; - void* memptr; -} glbufmem; - -static std::unordered_map buf_list; - -void add_buf(U32 name, U32 size, void* ptr) -{ - LL_WARNS("VBO_ACCOUNTING") << "ADD add_buf GLname " << name << ", size " << size << ", ptr " << ptr << LL_ENDL; - - if (0 < buf_list.count(name)) - { - if (buf_list[name].allocated_size > 0) - { - U32 a = buf_list[name].allocated_size; - LL_WARNS("VBO_ACC_ERROR") << "add_buf error, adding duplicate GLname " << name << ", size " << size << ", allocated " << a << LL_ENDL; - } - } - - buf_list[name].allocated_size = size; - buf_list[name].memptr = ptr; -} - -U32 find_buf_size(U32 name) -{ - if (buf_list.count(name) > 0) return buf_list[name].allocated_size; - return 0; -} - -bool clear_buf(U32 name, U32 size, void* ptr) -{ - LL_WARNS("VBO_ACCOUNTING") << "DEL clear_buf GLname " << name << ", size " << size << ", ptr " << ptr << LL_ENDL; - - if (0 == buf_list.count(name)) - { - LL_WARNS("VBO_ACC_ERROR") << "clear_buf error, attempt to remove unknown GLname " << name << ", size " << size << LL_ENDL; - return false; - } - - if (buf_list[name].allocated_size == 0) - { - LL_WARNS("VBO_ACC_ERROR") << "clear_buf error, attempt to remove empty GLname " << name << ", size " << size << LL_ENDL; - return false; - } - - if (buf_list[name].allocated_size != size) - { - U32 a = buf_list[name].allocated_size; - LL_WARNS("VBO_ACC_ERROR") << "clear_buf error, size mismatch " << name << ", size " << size << ", allocated " << a << LL_ENDL; - buf_list[name].allocated_size = 0; - buf_list[name].memptr = nullptr; - return false; - } - - if (buf_list[name].memptr != ptr) - { - void* p = buf_list[name].memptr; - LL_WARNS("VBO_ACC_ERROR") << "clear_buf error, ptr mismatch " << name << ", ptr " << ptr << ", saved ptr " << p << LL_ENDL; - buf_list[name].allocated_size = 0; - buf_list[name].memptr = nullptr; - return false; - } - - buf_list[name].allocated_size = 0; - buf_list[name].memptr = nullptr; - return true; -} - -#if 0 - // Find the GLname in the freelist -for (U32 i = 0; i < LL_VBO_POOL_SEED_COUNT; i++) -{ - for (auto &r : mFreeList[i]) - { - if (r.mGLName == name) - { - LL_WARNS() << "Release size " << size << ", found Name " << name << " in bucket " << i << LL_ENDL; - } - } -} - -// Remove the buffer record from the free record list, by GLname -U32 i = vbo_block_index(size); -mFreeList[i].remove_if([name](Record r) {return (name == r.mGLName); }); -i++; -#endif - U32 LLVBOPool::genBuffer() { U32 ret = 0; @@ -244,107 +152,105 @@ LLVBOPool::LLVBOPool(U32 vboUsage, U32 vboType) std::fill(mMissCount.begin(), mMissCount.end(), 0); } -volatile U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) +volatile U8 *LLVBOPool::allocate(U32 &name, U32 size, bool for_seed) { - llassert(vbo_block_size(size) == size); - - volatile U8* ret = NULL; + llassert(vbo_block_size(size) == size); - U32 i = vbo_block_index(size); + volatile U8 *ret = NULL; - if (mFreeList.size() <= i) - { - mFreeList.resize(i+1); - } + U32 i = vbo_block_index(size); - if (mFreeList[i].empty() || for_seed) - { - //make a new buffer - name = genBuffer(); - - glBindBufferARB(mType, name); + if (mFreeList.size() <= i) + { + mFreeList.resize(i + 1); + } - if (!for_seed && i < LL_VBO_POOL_SEED_COUNT) - { //record this miss - mMissCount[i]++; + if (mFreeList[i].empty() || for_seed) + { + // make a new buffer + name = genBuffer(); + + glBindBufferARB(mType, name); + + if (!for_seed && i < LL_VBO_POOL_SEED_COUNT) + { // record this miss + mMissCount[i]++; mMissCountDirty = true; // signal to ::seedPool() } - if (mType == GL_ARRAY_BUFFER_ARB) - { - LLVertexBuffer::sAllocatedBytes += size; - } - else - { - LLVertexBuffer::sAllocatedIndexBytes += size; - } + if (mType == GL_ARRAY_BUFFER_ARB) + { + LLVertexBuffer::sAllocatedBytes += size; + } + else + { + LLVertexBuffer::sAllocatedIndexBytes += size; + } - if (LLVertexBuffer::sDisableVBOMapping || mUsage != GL_DYNAMIC_DRAW_ARB) - { - glBufferDataARB(mType, size, 0, mUsage); - if (mUsage != GL_DYNAMIC_COPY_ARB) - { //data will be provided by application - ret = (U8*) ll_aligned_malloc<64>(size); - if (!ret) - { - LL_ERRS() << "Failed to allocate "<< size << " bytes for LLVBOPool buffer " << name <<"." << LL_NEWLINE - << "Free list size: " << mFreeList.size() // this happens if we are out of memory so a solution might be to clear some from freelist - << " Allocated Bytes: " << LLVertexBuffer::sAllocatedBytes - << " Allocated Index Bytes: " << LLVertexBuffer::sAllocatedIndexBytes - << " Pooled Bytes: " << sBytesPooled - << " Pooled Index Bytes: " << sIndexBytesPooled - << LL_ENDL; - } - } - } - else - { //always use a true hint of static draw when allocating non-client-backed buffers - glBufferDataARB(mType, size, 0, GL_STATIC_DRAW_ARB); - } + if (LLVertexBuffer::sDisableVBOMapping || mUsage != GL_DYNAMIC_DRAW_ARB) + { + glBufferDataARB(mType, size, 0, mUsage); + if (mUsage != GL_DYNAMIC_COPY_ARB) + { // data will be provided by application + ret = (U8 *) ll_aligned_malloc<64>(size); + if (!ret) + { + LL_ERRS() + << "Failed to allocate " << size << " bytes for LLVBOPool buffer " << name << "." << LL_NEWLINE + << "Free list size: " + << mFreeList.size() // this happens if we are out of memory so a solution might be to clear some from freelist + << " Allocated Bytes: " << LLVertexBuffer::sAllocatedBytes + << " Allocated Index Bytes: " << LLVertexBuffer::sAllocatedIndexBytes << " Pooled Bytes: " << sBytesPooled + << " Pooled Index Bytes: " << sIndexBytesPooled << LL_ENDL; + } + } + } + else + { // always use a true hint of static draw when allocating non-client-backed buffers + glBufferDataARB(mType, size, 0, GL_STATIC_DRAW_ARB); + } - glBindBufferARB(mType, 0); + glBindBufferARB(mType, 0); - if (for_seed) - { //put into pool for future use - llassert(mFreeList.size() > i); + if (for_seed) + { // put into pool for future use + llassert(mFreeList.size() > i); - Record rec; - rec.mGLName = name; - rec.mClientData = ret; - - if (mType == GL_ARRAY_BUFFER_ARB) - { - sBytesPooled += size; - } - else - { - sIndexBytesPooled += size; - } - mFreeList[i].push_back(rec); - mMissCountDirty = true; // signal to ::seedPool() - } + Record rec; + rec.mGLName = name; + rec.mClientData = ret; - add_buf(name, size, (void*)ret); - } - else - { - name = mFreeList[i].front().mGLName; - ret = mFreeList[i].front().mClientData; + if (mType == GL_ARRAY_BUFFER_ARB) + { + sBytesPooled += size; + } + else + { + sIndexBytesPooled += size; + } + mFreeList[i].push_back(rec); + mMissCountDirty = true; // signal to ::seedPool() + } + } + else + { + name = mFreeList[i].front().mGLName; + ret = mFreeList[i].front().mClientData; - if (mType == GL_ARRAY_BUFFER_ARB) - { - sBytesPooled -= size; - } - else - { - sIndexBytesPooled -= size; - } + if (mType == GL_ARRAY_BUFFER_ARB) + { + sBytesPooled -= size; + } + else + { + sIndexBytesPooled -= size; + } - mFreeList[i].pop_front(); + mFreeList[i].pop_front(); mMissCountDirty = true; // signal to ::seedPool() - } + } - return ret; + return ret; } void LLVBOPool::release(U32 name, volatile U8* buffer, U32 size) @@ -362,8 +268,6 @@ void LLVBOPool::release(U32 name, volatile U8* buffer, U32 size) { LLVertexBuffer::sAllocatedIndexBytes -= size; } - - clear_buf(name, size, (void*)buffer); } void LLVBOPool::seedPool() @@ -371,7 +275,7 @@ void LLVBOPool::seedPool() if (mMissCountDirty) { U32 dummy_name = 0; - U32 size = LL_VBO_BLOCK_SIZE; + U32 size = LL_VBO_BLOCK_SIZE; for (U32 i = 0; i < LL_VBO_POOL_SEED_COUNT; i++) { @@ -389,8 +293,6 @@ void LLVBOPool::seedPool() } } - - void LLVBOPool::cleanup() { U32 size = LL_VBO_BLOCK_SIZE; @@ -410,8 +312,6 @@ void LLVBOPool::cleanup() ll_aligned_free<64>((void*) r.mClientData); } - clear_buf(r.mGLName, size, (void*)r.mClientData); - l.pop_front(); if (mType == GL_ARRAY_BUFFER_ARB) @@ -1019,6 +919,11 @@ void LLVertexBuffer::cleanupClass() sStreamVBOPool.cleanup(); sDynamicVBOPool.cleanup(); sDynamicCopyVBOPool.cleanup(); + + llassert(0 == LLVBOPool::sBytesPooled); + llassert(0 == LLVBOPool::sIndexBytesPooled); + llassert(0 == sAllocatedBytes); + llassert(0 == sAllocatedIndexBytes); } //---------------------------------------------------------------------------- -- cgit v1.2.3 From 6c6d9a10f830e264cf75603949b54a12256cab78 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 20 May 2022 13:31:18 -0500 Subject: SL-17287 Update Tracy to 0.8.1. Clean up GPU instrumentation. --- indra/llrender/llvertexbuffer.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 6338cab96a..b1b69f1508 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -624,7 +624,6 @@ void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indi stop_glerror(); LLGLSLShader::startProfile(); - LL_PROFILER_GPU_ZONEC( "gl.DrawRangeElements", 0xFFFF00 ) glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT, idx); LLGLSLShader::stopProfile(count, mode); @@ -642,7 +641,6 @@ void LLVertexBuffer::drawRangeFast(U32 mode, U32 start, U32 end, U32 count, U32 U16* idx = ((U16*)getIndicesPointer()) + indices_offset; - LL_PROFILER_GPU_ZONEC("gl.DrawRangeElements", 0xFFFF00) glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT, idx); } @@ -688,8 +686,7 @@ void LLVertexBuffer::draw(U32 mode, U32 count, U32 indices_offset) const stop_glerror(); LLGLSLShader::startProfile(); - LL_PROFILER_GPU_ZONEC( "gl.DrawElements", 0xA0FFA0 ) - glDrawElements(sGLMode[mode], count, GL_UNSIGNED_SHORT, + glDrawElements(sGLMode[mode], count, GL_UNSIGNED_SHORT, ((U16*) getIndicesPointer()) + indices_offset); LLGLSLShader::stopProfile(count, mode); stop_glerror(); @@ -736,7 +733,6 @@ void LLVertexBuffer::drawArrays(U32 mode, U32 first, U32 count) const LLGLSLShader::startProfile(); { - LL_PROFILER_GPU_ZONEC("gl.DrawArrays", 0xFF4040) glDrawArrays(sGLMode[mode], first, count); } LLGLSLShader::stopProfile(count, mode); -- cgit v1.2.3 From 2082443220fe344bb027c3acbf50fea0a99159c3 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Thu, 1 Sep 2022 10:58:27 -0700 Subject: SL-17967 - Git rid of ARB that is in core --- indra/llrender/llvertexbuffer.cpp | 128 +++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 64 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index b1b69f1508..f2c863d057 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -127,7 +127,7 @@ U32 LLVBOPool::genBuffer() if (sNameIdx == 0) { - glGenBuffersARB(1024, sNamePool); + glGenBuffers(1024, sNamePool); sNameIdx = 1024; } @@ -141,11 +141,11 @@ void LLVBOPool::deleteBuffer(U32 name) { LLVertexBuffer::unbind(); - glBindBufferARB(mType, name); - glBufferDataARB(mType, 0, NULL, mUsage); - glBindBufferARB(mType, 0); + glBindBuffer(mType, name); + glBufferData(mType, 0, NULL, mUsage); + glBindBuffer(mType, 0); - glDeleteBuffersARB(1, &name); + glDeleteBuffers(1, &name); } } @@ -176,7 +176,7 @@ U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) //make a new buffer name = genBuffer(); - glBindBufferARB(mType, name); + glBindBuffer(mType, name); if (!for_seed && i < LL_VBO_POOL_SEED_COUNT) { //record this miss @@ -194,7 +194,7 @@ U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) if (LLVertexBuffer::sDisableVBOMapping || mUsage != GL_DYNAMIC_DRAW_ARB) { - glBufferDataARB(mType, size, 0, mUsage); + glBufferData(mType, size, 0, mUsage); if (mUsage != GL_DYNAMIC_COPY_ARB) { //data will be provided by application ret = (U8*) ll_aligned_malloc<64>(size); @@ -212,10 +212,10 @@ U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) } else { //always use a true hint of static draw when allocating non-client-backed buffers - glBufferDataARB(mType, size, 0, GL_STATIC_DRAW_ARB); + glBufferData(mType, size, 0, GL_STATIC_DRAW_ARB); } - glBindBufferARB(mType, 0); + glBindBuffer(mType, 0); if (for_seed) { //put into pool for future use @@ -451,14 +451,14 @@ void LLVertexBuffer::setupClientArrays(U32 data_mask) { //was enabled if (!(data_mask & mask)) { //needs to be disabled - glDisableVertexAttribArrayARB(loc); + glDisableVertexAttribArray(loc); } } else { //was disabled if (data_mask & mask) { //needs to be enabled - glEnableVertexAttribArrayARB(loc); + glEnableVertexAttribArray(loc); } } } @@ -763,12 +763,12 @@ void LLVertexBuffer::unbind() if (sVBOActive) { - glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + glBindBuffer(GL_ARRAY_BUFFER_ARB, 0); sVBOActive = false; } if (sIBOActive) { - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); sIBOActive = false; } @@ -1334,7 +1334,7 @@ void LLVertexBuffer::setupVertexArray() { if (mTypeMask & (1 << i)) { - glEnableVertexAttribArrayARB(i); + glEnableVertexAttribArray(i); if (attrib_integer[i]) { @@ -1360,14 +1360,14 @@ void LLVertexBuffer::setupVertexArray() // pointer value. Ruslan asserts that in this case the last // param is interpreted as an array data offset within the VBO // rather than as an actual pointer, so it's okay. - glVertexAttribPointerARB(i, attrib_size[i], attrib_type[i], + glVertexAttribPointer(i, attrib_size[i], attrib_type[i], attrib_normalized[i], sTypeSize[i], reinterpret_cast(intptr_t(mOffsets[i]))); } } else { - glDisableVertexAttribArrayARB(i); + glDisableVertexAttribArray(i); } } @@ -1512,7 +1512,7 @@ U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_ran if (gDebugGL) { GLint size = 0; - glGetBufferParameterivARB(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SIZE_ARB, &size); + glGetBufferParameteriv(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SIZE_ARB, &size); if (size < mSize) { @@ -1534,17 +1534,17 @@ U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_ran glBufferParameteriAPPLE(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SERIALIZED_MODIFY_APPLE, GL_FALSE); glBufferParameteriAPPLE(GL_ARRAY_BUFFER_ARB, GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE); #endif - src = (U8*) glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + src = (U8*) glMapBuffer(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); } else { - src = (U8*) glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + src = (U8*) glMapBuffer(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); } } else { map_range = false; - src = (U8*) glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + src = (U8*) glMapBuffer(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); } llassert(src != NULL); @@ -1568,7 +1568,7 @@ U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_ran //print out more debug info before crash LL_INFOS() << "vertex buffer size: (num verts : num indices) = " << getNumVerts() << " : " << getNumIndices() << LL_ENDL; GLint size; - glGetBufferParameterivARB(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SIZE_ARB, &size); + glGetBufferParameteriv(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SIZE_ARB, &size); LL_INFOS() << "GL_ARRAY_BUFFER_ARB size is " << size << LL_ENDL; //-------------------- @@ -1707,17 +1707,17 @@ U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range) glBufferParameteriAPPLE(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_BUFFER_SERIALIZED_MODIFY_APPLE, GL_FALSE); glBufferParameteriAPPLE(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE); #endif - src = (U8*) glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + src = (U8*) glMapBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); } else { - src = (U8*) glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + src = (U8*) glMapBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); } } else { map_range = false; - src = (U8*) glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + src = (U8*) glMapBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); } llassert(src != NULL); @@ -1793,12 +1793,12 @@ void LLVertexBuffer::unmapBuffer() S32 length = sTypeSize[region.mType]*region.mCount; if (mSize >= length + offset) { - glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, offset, length, (U8*)mMappedData + offset); + glBufferSubData(GL_ARRAY_BUFFER_ARB, offset, length, (U8*)mMappedData + offset); } else { GLint size = 0; - glGetBufferParameterivARB(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SIZE_ARB, &size); + glGetBufferParameteriv(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SIZE_ARB, &size); LL_WARNS() << "Attempted to map regions to a buffer that is too small, " << "mapped size: " << mSize << ", gl buffer size: " << size @@ -1814,7 +1814,7 @@ void LLVertexBuffer::unmapBuffer() else { stop_glerror(); - glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, getSize(), (U8*) mMappedData); + glBufferSubData(GL_ARRAY_BUFFER_ARB, 0, getSize(), (U8*) mMappedData); stop_glerror(); } } @@ -1848,7 +1848,7 @@ void LLVertexBuffer::unmapBuffer() } } stop_glerror(); - glUnmapBufferARB(GL_ARRAY_BUFFER_ARB); + glUnmapBuffer(GL_ARRAY_BUFFER_ARB); stop_glerror(); mMappedData = NULL; @@ -1873,12 +1873,12 @@ void LLVertexBuffer::unmapBuffer() S32 length = sizeof(U16)*region.mCount; if (mIndicesSize >= length + offset) { - glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, offset, length, (U8*) mMappedIndexData+offset); + glBufferSubData(GL_ELEMENT_ARRAY_BUFFER_ARB, offset, length, (U8*) mMappedIndexData+offset); } else { GLint size = 0; - glGetBufferParameterivARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_BUFFER_SIZE_ARB, &size); + glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_BUFFER_SIZE_ARB, &size); LL_WARNS() << "Attempted to map regions to a buffer that is too small, " << "mapped size: " << mIndicesSize << ", gl buffer size: " << size @@ -1894,7 +1894,7 @@ void LLVertexBuffer::unmapBuffer() else { stop_glerror(); - glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0, getIndicesSize(), (U8*) mMappedIndexData); + glBufferSubData(GL_ELEMENT_ARRAY_BUFFER_ARB, 0, getIndicesSize(), (U8*) mMappedIndexData); stop_glerror(); } } @@ -1931,7 +1931,7 @@ void LLVertexBuffer::unmapBuffer() } } - glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB); + glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB); mMappedIndexData = NULL; } @@ -2085,7 +2085,7 @@ bool LLVertexBuffer::bindGLBuffer(bool force_bind) if (useVBOs() && (force_bind || (mGLBuffer && (mGLBuffer != sGLRenderBuffer || !sVBOActive)))) { LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; - glBindBufferARB(GL_ARRAY_BUFFER_ARB, mGLBuffer); + glBindBuffer(GL_ARRAY_BUFFER_ARB, mGLBuffer); sGLRenderBuffer = mGLBuffer; sBindCount++; sVBOActive = true; @@ -2102,7 +2102,7 @@ bool LLVertexBuffer::bindGLBufferFast() { if (mGLBuffer != sGLRenderBuffer || !sVBOActive) { - glBindBufferARB(GL_ARRAY_BUFFER_ARB, mGLBuffer); + glBindBuffer(GL_ARRAY_BUFFER_ARB, mGLBuffer); sGLRenderBuffer = mGLBuffer; sBindCount++; sVBOActive = true; @@ -2125,7 +2125,7 @@ bool LLVertexBuffer::bindGLIndices(bool force_bind) { LL_ERRS() << "VBO bound while another VBO mapped!" << LL_ENDL; }*/ - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, mGLIndices); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, mGLIndices); sGLRenderIndices = mGLIndices; stop_glerror(); sBindCount++; @@ -2140,7 +2140,7 @@ bool LLVertexBuffer::bindGLIndicesFast() { if (mGLIndices != sGLRenderIndices || !sIBOActive) { - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, mGLIndices); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, mGLIndices); sGLRenderIndices = mGLIndices; sBindCount++; sIBOActive = true; @@ -2302,7 +2302,7 @@ void LLVertexBuffer::setBuffer(U32 data_mask) { if (sVBOActive) { - glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + glBindBuffer(GL_ARRAY_BUFFER_ARB, 0); sBindCount++; sVBOActive = false; setup = true; // ... or a VBO is deactivated @@ -2317,7 +2317,7 @@ void LLVertexBuffer::setBuffer(U32 data_mask) { if (sIBOActive) { - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); sBindCount++; sIBOActive = false; } @@ -2392,74 +2392,74 @@ void LLVertexBuffer::setupVertexBuffer(U32 data_mask) { S32 loc = TYPE_NORMAL; void* ptr = (void*)(base + mOffsets[TYPE_NORMAL]); - glVertexAttribPointerARB(loc, 3, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_NORMAL], ptr); + glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_NORMAL], ptr); } if (data_mask & MAP_TEXCOORD3) { S32 loc = TYPE_TEXCOORD3; void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD3]); - glVertexAttribPointerARB(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD3], ptr); + glVertexAttribPointer(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD3], ptr); } if (data_mask & MAP_TEXCOORD2) { S32 loc = TYPE_TEXCOORD2; void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD2]); - glVertexAttribPointerARB(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD2], ptr); + glVertexAttribPointer(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD2], ptr); } if (data_mask & MAP_TEXCOORD1) { S32 loc = TYPE_TEXCOORD1; void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD1]); - glVertexAttribPointerARB(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD1], ptr); + glVertexAttribPointer(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD1], ptr); } if (data_mask & MAP_TANGENT) { S32 loc = TYPE_TANGENT; void* ptr = (void*)(base + mOffsets[TYPE_TANGENT]); - glVertexAttribPointerARB(loc, 4,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TANGENT], ptr); + glVertexAttribPointer(loc, 4,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TANGENT], ptr); } if (data_mask & MAP_TEXCOORD0) { S32 loc = TYPE_TEXCOORD0; void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD0]); - glVertexAttribPointerARB(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD0], ptr); + glVertexAttribPointer(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD0], ptr); } if (data_mask & MAP_COLOR) { S32 loc = TYPE_COLOR; //bind emissive instead of color pointer if emissive is present void* ptr = (data_mask & MAP_EMISSIVE) ? (void*)(base + mOffsets[TYPE_EMISSIVE]) : (void*)(base + mOffsets[TYPE_COLOR]); - glVertexAttribPointerARB(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_COLOR], ptr); + glVertexAttribPointer(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_COLOR], ptr); } if (data_mask & MAP_EMISSIVE) { S32 loc = TYPE_EMISSIVE; void* ptr = (void*)(base + mOffsets[TYPE_EMISSIVE]); - glVertexAttribPointerARB(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_EMISSIVE], ptr); + glVertexAttribPointer(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_EMISSIVE], ptr); if (!(data_mask & MAP_COLOR)) { //map emissive to color channel when color is not also being bound to avoid unnecessary shader swaps loc = TYPE_COLOR; - glVertexAttribPointerARB(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_EMISSIVE], ptr); + glVertexAttribPointer(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_EMISSIVE], ptr); } } if (data_mask & MAP_WEIGHT) { S32 loc = TYPE_WEIGHT; void* ptr = (void*)(base + mOffsets[TYPE_WEIGHT]); - glVertexAttribPointerARB(loc, 1, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_WEIGHT], ptr); + glVertexAttribPointer(loc, 1, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_WEIGHT], ptr); } if (data_mask & MAP_WEIGHT4) { S32 loc = TYPE_WEIGHT4; void* ptr = (void*)(base+mOffsets[TYPE_WEIGHT4]); - glVertexAttribPointerARB(loc, 4, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_WEIGHT4], ptr); + glVertexAttribPointer(loc, 4, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_WEIGHT4], ptr); } if (data_mask & MAP_CLOTHWEIGHT) { S32 loc = TYPE_CLOTHWEIGHT; void* ptr = (void*)(base + mOffsets[TYPE_CLOTHWEIGHT]); - glVertexAttribPointerARB(loc, 4, GL_FLOAT, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_CLOTHWEIGHT], ptr); + glVertexAttribPointer(loc, 4, GL_FLOAT, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_CLOTHWEIGHT], ptr); } if (data_mask & MAP_TEXTURE_INDEX && (gGLManager.mGLSLVersionMajor >= 2 || gGLManager.mGLSLVersionMinor >= 30)) //indexed texture rendering requires GLSL 1.30 or later @@ -2474,7 +2474,7 @@ void LLVertexBuffer::setupVertexBuffer(U32 data_mask) { S32 loc = TYPE_VERTEX; void* ptr = (void*)(base + mOffsets[TYPE_VERTEX]); - glVertexAttribPointerARB(loc, 3,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); + glVertexAttribPointer(loc, 3,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); } llglassertok(); @@ -2488,74 +2488,74 @@ void LLVertexBuffer::setupVertexBufferFast(U32 data_mask) { S32 loc = TYPE_NORMAL; void* ptr = (void*)(base + mOffsets[TYPE_NORMAL]); - glVertexAttribPointerARB(loc, 3, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_NORMAL], ptr); + glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_NORMAL], ptr); } if (data_mask & MAP_TEXCOORD3) { S32 loc = TYPE_TEXCOORD3; void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD3]); - glVertexAttribPointerARB(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD3], ptr); + glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD3], ptr); } if (data_mask & MAP_TEXCOORD2) { S32 loc = TYPE_TEXCOORD2; void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD2]); - glVertexAttribPointerARB(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD2], ptr); + glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD2], ptr); } if (data_mask & MAP_TEXCOORD1) { S32 loc = TYPE_TEXCOORD1; void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD1]); - glVertexAttribPointerARB(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD1], ptr); + glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD1], ptr); } if (data_mask & MAP_TANGENT) { S32 loc = TYPE_TANGENT; void* ptr = (void*)(base + mOffsets[TYPE_TANGENT]); - glVertexAttribPointerARB(loc, 4, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TANGENT], ptr); + glVertexAttribPointer(loc, 4, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TANGENT], ptr); } if (data_mask & MAP_TEXCOORD0) { S32 loc = TYPE_TEXCOORD0; void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD0]); - glVertexAttribPointerARB(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD0], ptr); + glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD0], ptr); } if (data_mask & MAP_COLOR) { S32 loc = TYPE_COLOR; //bind emissive instead of color pointer if emissive is present void* ptr = (data_mask & MAP_EMISSIVE) ? (void*)(base + mOffsets[TYPE_EMISSIVE]) : (void*)(base + mOffsets[TYPE_COLOR]); - glVertexAttribPointerARB(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_COLOR], ptr); + glVertexAttribPointer(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_COLOR], ptr); } if (data_mask & MAP_EMISSIVE) { S32 loc = TYPE_EMISSIVE; void* ptr = (void*)(base + mOffsets[TYPE_EMISSIVE]); - glVertexAttribPointerARB(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_EMISSIVE], ptr); + glVertexAttribPointer(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_EMISSIVE], ptr); if (!(data_mask & MAP_COLOR)) { //map emissive to color channel when color is not also being bound to avoid unnecessary shader swaps loc = TYPE_COLOR; - glVertexAttribPointerARB(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_EMISSIVE], ptr); + glVertexAttribPointer(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_EMISSIVE], ptr); } } if (data_mask & MAP_WEIGHT) { S32 loc = TYPE_WEIGHT; void* ptr = (void*)(base + mOffsets[TYPE_WEIGHT]); - glVertexAttribPointerARB(loc, 1, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_WEIGHT], ptr); + glVertexAttribPointer(loc, 1, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_WEIGHT], ptr); } if (data_mask & MAP_WEIGHT4) { S32 loc = TYPE_WEIGHT4; void* ptr = (void*)(base + mOffsets[TYPE_WEIGHT4]); - glVertexAttribPointerARB(loc, 4, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_WEIGHT4], ptr); + glVertexAttribPointer(loc, 4, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_WEIGHT4], ptr); } if (data_mask & MAP_CLOTHWEIGHT) { S32 loc = TYPE_CLOTHWEIGHT; void* ptr = (void*)(base + mOffsets[TYPE_CLOTHWEIGHT]); - glVertexAttribPointerARB(loc, 4, GL_FLOAT, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_CLOTHWEIGHT], ptr); + glVertexAttribPointer(loc, 4, GL_FLOAT, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_CLOTHWEIGHT], ptr); } if (data_mask & MAP_TEXTURE_INDEX) { @@ -2569,7 +2569,7 @@ void LLVertexBuffer::setupVertexBufferFast(U32 data_mask) { S32 loc = TYPE_VERTEX; void* ptr = (void*)(base + mOffsets[TYPE_VERTEX]); - glVertexAttribPointerARB(loc, 3, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); + glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); } } -- cgit v1.2.3 From 01d03edd8512580575da515401a42021577c3c57 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Thu, 1 Sep 2022 13:38:22 -0700 Subject: SL-17967 - _ARB constant removal --- indra/llrender/llvertexbuffer.cpp | 128 +++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 64 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index f2c863d057..4b639e9e84 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -83,11 +83,11 @@ const U32 LL_VBO_POOL_SEED_COUNT = vbo_block_index(LL_VBO_POOL_MAX_SEED_SIZE); //============================================================================ //static -LLVBOPool LLVertexBuffer::sStreamVBOPool(GL_STREAM_DRAW_ARB, GL_ARRAY_BUFFER_ARB); -LLVBOPool LLVertexBuffer::sDynamicVBOPool(GL_DYNAMIC_DRAW_ARB, GL_ARRAY_BUFFER_ARB); -LLVBOPool LLVertexBuffer::sDynamicCopyVBOPool(GL_DYNAMIC_COPY_ARB, GL_ARRAY_BUFFER_ARB); -LLVBOPool LLVertexBuffer::sStreamIBOPool(GL_STREAM_DRAW_ARB, GL_ELEMENT_ARRAY_BUFFER_ARB); -LLVBOPool LLVertexBuffer::sDynamicIBOPool(GL_DYNAMIC_DRAW_ARB, GL_ELEMENT_ARRAY_BUFFER_ARB); +LLVBOPool LLVertexBuffer::sStreamVBOPool(GL_STREAM_DRAW, GL_ARRAY_BUFFER); +LLVBOPool LLVertexBuffer::sDynamicVBOPool(GL_DYNAMIC_DRAW, GL_ARRAY_BUFFER); +LLVBOPool LLVertexBuffer::sDynamicCopyVBOPool(GL_DYNAMIC_COPY, GL_ARRAY_BUFFER); +LLVBOPool LLVertexBuffer::sStreamIBOPool(GL_STREAM_DRAW, GL_ELEMENT_ARRAY_BUFFER); +LLVBOPool LLVertexBuffer::sDynamicIBOPool(GL_DYNAMIC_DRAW, GL_ELEMENT_ARRAY_BUFFER); U32 LLVBOPool::sBytesPooled = 0; U32 LLVBOPool::sIndexBytesPooled = 0; @@ -183,7 +183,7 @@ U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) mMissCount[i]++; } - if (mType == GL_ARRAY_BUFFER_ARB) + if (mType == GL_ARRAY_BUFFER) { LLVertexBuffer::sAllocatedBytes += size; } @@ -192,10 +192,10 @@ U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) LLVertexBuffer::sAllocatedIndexBytes += size; } - if (LLVertexBuffer::sDisableVBOMapping || mUsage != GL_DYNAMIC_DRAW_ARB) + if (LLVertexBuffer::sDisableVBOMapping || mUsage != GL_DYNAMIC_DRAW) { glBufferData(mType, size, 0, mUsage); - if (mUsage != GL_DYNAMIC_COPY_ARB) + if (mUsage != GL_DYNAMIC_COPY) { //data will be provided by application ret = (U8*) ll_aligned_malloc<64>(size); if (!ret) @@ -212,7 +212,7 @@ U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) } else { //always use a true hint of static draw when allocating non-client-backed buffers - glBufferData(mType, size, 0, GL_STATIC_DRAW_ARB); + glBufferData(mType, size, 0, GL_STATIC_DRAW); } glBindBuffer(mType, 0); @@ -225,7 +225,7 @@ U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) rec.mGLName = name; rec.mClientData = ret; - if (mType == GL_ARRAY_BUFFER_ARB) + if (mType == GL_ARRAY_BUFFER) { sBytesPooled += size; } @@ -241,7 +241,7 @@ U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) name = mFreeList[i].front().mGLName; ret = mFreeList[i].front().mClientData; - if (mType == GL_ARRAY_BUFFER_ARB) + if (mType == GL_ARRAY_BUFFER) { sBytesPooled -= size; } @@ -263,7 +263,7 @@ void LLVBOPool::release(U32 name, U8* buffer, U32 size) deleteBuffer(name); ll_aligned_free_fallback((U8*) buffer); - if (mType == GL_ARRAY_BUFFER_ARB) + if (mType == GL_ARRAY_BUFFER) { LLVertexBuffer::sAllocatedBytes -= size; } @@ -322,7 +322,7 @@ void LLVBOPool::cleanup() l.pop_front(); - if (mType == GL_ARRAY_BUFFER_ARB) + if (mType == GL_ARRAY_BUFFER) { sBytesPooled -= size; LLVertexBuffer::sAllocatedBytes -= size; @@ -763,12 +763,12 @@ void LLVertexBuffer::unbind() if (sVBOActive) { - glBindBuffer(GL_ARRAY_BUFFER_ARB, 0); + glBindBuffer(GL_ARRAY_BUFFER, 0); sVBOActive = false; } if (sIBOActive) { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); sIBOActive = false; } @@ -801,32 +801,32 @@ S32 LLVertexBuffer::determineUsage(S32 usage) ret_usage = 0; } - if (ret_usage == GL_STREAM_DRAW_ARB && !sUseStreamDraw) + if (ret_usage == GL_STREAM_DRAW && !sUseStreamDraw) { ret_usage = 0; } - if (ret_usage == GL_DYNAMIC_DRAW_ARB && sPreferStreamDraw) + if (ret_usage == GL_DYNAMIC_DRAW && sPreferStreamDraw) { - ret_usage = GL_STREAM_DRAW_ARB; + ret_usage = GL_STREAM_DRAW; } if (ret_usage == 0 && LLRender::sGLCoreProfile) { //MUST use VBOs for all rendering - ret_usage = GL_STREAM_DRAW_ARB; + ret_usage = GL_STREAM_DRAW; } - if (ret_usage && ret_usage != GL_STREAM_DRAW_ARB) + if (ret_usage && ret_usage != GL_STREAM_DRAW) { //only stream_draw and dynamic_draw are supported when using VBOs, dynamic draw is the default - if (ret_usage != GL_DYNAMIC_COPY_ARB) + if (ret_usage != GL_DYNAMIC_COPY) { if (sDisableVBOMapping) { //always use stream draw if VBO mapping is disabled - ret_usage = GL_STREAM_DRAW_ARB; + ret_usage = GL_STREAM_DRAW; } else { - ret_usage = GL_DYNAMIC_DRAW_ARB; + ret_usage = GL_DYNAMIC_DRAW; } } } @@ -859,7 +859,7 @@ LLVertexBuffer::LLVertexBuffer(U32 typemask, S32 usage) mMappable(false), mFence(NULL) { - mMappable = (mUsage == GL_DYNAMIC_DRAW_ARB && !sDisableVBOMapping); + mMappable = (mUsage == GL_DYNAMIC_DRAW && !sDisableVBOMapping); //zero out offsets for (U32 i = 0; i < TYPE_MAX; i++) @@ -982,11 +982,11 @@ void LLVertexBuffer::genBuffer(U32 size) { mSize = vbo_block_size(size); - if (mUsage == GL_STREAM_DRAW_ARB) + if (mUsage == GL_STREAM_DRAW) { mMappedData = sStreamVBOPool.allocate(mGLBuffer, mSize); } - else if (mUsage == GL_DYNAMIC_DRAW_ARB) + else if (mUsage == GL_DYNAMIC_DRAW) { mMappedData = sDynamicVBOPool.allocate(mGLBuffer, mSize); } @@ -1003,7 +1003,7 @@ void LLVertexBuffer::genIndices(U32 size) { mIndicesSize = vbo_block_size(size); - if (mUsage == GL_STREAM_DRAW_ARB) + if (mUsage == GL_STREAM_DRAW) { mMappedIndexData = sStreamIBOPool.allocate(mGLIndices, mIndicesSize); } @@ -1017,7 +1017,7 @@ void LLVertexBuffer::genIndices(U32 size) void LLVertexBuffer::releaseBuffer() { - if (mUsage == GL_STREAM_DRAW_ARB) + if (mUsage == GL_STREAM_DRAW) { sStreamVBOPool.release(mGLBuffer, mMappedData, mSize); } @@ -1034,7 +1034,7 @@ void LLVertexBuffer::releaseBuffer() void LLVertexBuffer::releaseIndices() { - if (mUsage == GL_STREAM_DRAW_ARB) + if (mUsage == GL_STREAM_DRAW) { sStreamIBOPool.release(mGLIndices, mMappedIndexData, mIndicesSize); } @@ -1499,7 +1499,7 @@ U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_ran #ifdef GL_ARB_map_buffer_range S32 offset = mOffsets[type] + sTypeSize[type]*index; S32 length = (sTypeSize[type]*count+0xF) & ~0xF; - src = (U8*) glMapBufferRange(GL_ARRAY_BUFFER_ARB, offset, length, + src = (U8*) glMapBufferRange(GL_ARRAY_BUFFER, offset, length, GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_INVALIDATE_RANGE_BIT); @@ -1512,7 +1512,7 @@ U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_ran if (gDebugGL) { GLint size = 0; - glGetBufferParameteriv(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SIZE_ARB, &size); + glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); if (size < mSize) { @@ -1520,7 +1520,7 @@ U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_ran } } - src = (U8*) glMapBufferRange(GL_ARRAY_BUFFER_ARB, 0, mSize, + src = (U8*) glMapBufferRange(GL_ARRAY_BUFFER, 0, mSize, GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT); #endif @@ -1531,20 +1531,20 @@ U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_ran if (map_range) { #ifndef LL_MESA_HEADLESS - glBufferParameteriAPPLE(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SERIALIZED_MODIFY_APPLE, GL_FALSE); - glBufferParameteriAPPLE(GL_ARRAY_BUFFER_ARB, GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE); + glBufferParameteriAPPLE(GL_ARRAY_BUFFER, GL_BUFFER_SERIALIZED_MODIFY_APPLE, GL_FALSE); + glBufferParameteriAPPLE(GL_ARRAY_BUFFER, GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE); #endif - src = (U8*) glMapBuffer(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + src = (U8*) glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); } else { - src = (U8*) glMapBuffer(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + src = (U8*) glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); } } else { map_range = false; - src = (U8*) glMapBuffer(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + src = (U8*) glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); } llassert(src != NULL); @@ -1568,8 +1568,8 @@ U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_ran //print out more debug info before crash LL_INFOS() << "vertex buffer size: (num verts : num indices) = " << getNumVerts() << " : " << getNumIndices() << LL_ENDL; GLint size; - glGetBufferParameteriv(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SIZE_ARB, &size); - LL_INFOS() << "GL_ARRAY_BUFFER_ARB size is " << size << LL_ENDL; + glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); + LL_INFOS() << "GL_ARRAY_BUFFER size is " << size << LL_ENDL; //-------------------- GLint buff; @@ -1684,7 +1684,7 @@ U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range) #ifdef GL_ARB_map_buffer_range S32 offset = sizeof(U16)*index; S32 length = sizeof(U16)*count; - src = (U8*) glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER_ARB, offset, length, + src = (U8*) glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, offset, length, GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_INVALIDATE_RANGE_BIT); @@ -1693,7 +1693,7 @@ U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range) else { #ifdef GL_ARB_map_buffer_range - src = (U8*) glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER_ARB, 0, sizeof(U16)*mNumIndices, + src = (U8*) glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(U16)*mNumIndices, GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT); #endif @@ -1704,20 +1704,20 @@ U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range) if (map_range) { #ifndef LL_MESA_HEADLESS - glBufferParameteriAPPLE(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_BUFFER_SERIALIZED_MODIFY_APPLE, GL_FALSE); - glBufferParameteriAPPLE(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE); + glBufferParameteriAPPLE(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SERIALIZED_MODIFY_APPLE, GL_FALSE); + glBufferParameteriAPPLE(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE); #endif - src = (U8*) glMapBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + src = (U8*) glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY); } else { - src = (U8*) glMapBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + src = (U8*) glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY); } } else { map_range = false; - src = (U8*) glMapBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + src = (U8*) glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY); } llassert(src != NULL); @@ -1793,12 +1793,12 @@ void LLVertexBuffer::unmapBuffer() S32 length = sTypeSize[region.mType]*region.mCount; if (mSize >= length + offset) { - glBufferSubData(GL_ARRAY_BUFFER_ARB, offset, length, (U8*)mMappedData + offset); + glBufferSubData(GL_ARRAY_BUFFER, offset, length, (U8*)mMappedData + offset); } else { GLint size = 0; - glGetBufferParameteriv(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SIZE_ARB, &size); + glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); LL_WARNS() << "Attempted to map regions to a buffer that is too small, " << "mapped size: " << mSize << ", gl buffer size: " << size @@ -1814,7 +1814,7 @@ void LLVertexBuffer::unmapBuffer() else { stop_glerror(); - glBufferSubData(GL_ARRAY_BUFFER_ARB, 0, getSize(), (U8*) mMappedData); + glBufferSubData(GL_ARRAY_BUFFER, 0, getSize(), (U8*) mMappedData); stop_glerror(); } } @@ -1833,13 +1833,13 @@ void LLVertexBuffer::unmapBuffer() if (gGLManager.mHasMapBufferRange) { #ifdef GL_ARB_map_buffer_range - glFlushMappedBufferRange(GL_ARRAY_BUFFER_ARB, offset, length); + glFlushMappedBufferRange(GL_ARRAY_BUFFER, offset, length); #endif } else if (gGLManager.mHasFlushBufferRange) { #ifndef LL_MESA_HEADLESS - glFlushMappedBufferRangeAPPLE(GL_ARRAY_BUFFER_ARB, offset, length); + glFlushMappedBufferRangeAPPLE(GL_ARRAY_BUFFER, offset, length); #endif } } @@ -1848,7 +1848,7 @@ void LLVertexBuffer::unmapBuffer() } } stop_glerror(); - glUnmapBuffer(GL_ARRAY_BUFFER_ARB); + glUnmapBuffer(GL_ARRAY_BUFFER); stop_glerror(); mMappedData = NULL; @@ -1873,12 +1873,12 @@ void LLVertexBuffer::unmapBuffer() S32 length = sizeof(U16)*region.mCount; if (mIndicesSize >= length + offset) { - glBufferSubData(GL_ELEMENT_ARRAY_BUFFER_ARB, offset, length, (U8*) mMappedIndexData+offset); + glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, length, (U8*) mMappedIndexData+offset); } else { GLint size = 0; - glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_BUFFER_SIZE_ARB, &size); + glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); LL_WARNS() << "Attempted to map regions to a buffer that is too small, " << "mapped size: " << mIndicesSize << ", gl buffer size: " << size @@ -1894,7 +1894,7 @@ void LLVertexBuffer::unmapBuffer() else { stop_glerror(); - glBufferSubData(GL_ELEMENT_ARRAY_BUFFER_ARB, 0, getIndicesSize(), (U8*) mMappedIndexData); + glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, getIndicesSize(), (U8*) mMappedIndexData); stop_glerror(); } } @@ -1913,14 +1913,14 @@ void LLVertexBuffer::unmapBuffer() if (gGLManager.mHasMapBufferRange) { #ifdef GL_ARB_map_buffer_range - glFlushMappedBufferRange(GL_ELEMENT_ARRAY_BUFFER_ARB, offset, length); + glFlushMappedBufferRange(GL_ELEMENT_ARRAY_BUFFER, offset, length); #endif } else if (gGLManager.mHasFlushBufferRange) { #ifdef GL_APPLE_flush_buffer_range #ifndef LL_MESA_HEADLESS - glFlushMappedBufferRangeAPPLE(GL_ELEMENT_ARRAY_BUFFER_ARB, offset, length); + glFlushMappedBufferRangeAPPLE(GL_ELEMENT_ARRAY_BUFFER, offset, length); #endif #endif } @@ -1931,7 +1931,7 @@ void LLVertexBuffer::unmapBuffer() } } - glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB); + glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER); mMappedIndexData = NULL; } @@ -2085,7 +2085,7 @@ bool LLVertexBuffer::bindGLBuffer(bool force_bind) if (useVBOs() && (force_bind || (mGLBuffer && (mGLBuffer != sGLRenderBuffer || !sVBOActive)))) { LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; - glBindBuffer(GL_ARRAY_BUFFER_ARB, mGLBuffer); + glBindBuffer(GL_ARRAY_BUFFER, mGLBuffer); sGLRenderBuffer = mGLBuffer; sBindCount++; sVBOActive = true; @@ -2102,7 +2102,7 @@ bool LLVertexBuffer::bindGLBufferFast() { if (mGLBuffer != sGLRenderBuffer || !sVBOActive) { - glBindBuffer(GL_ARRAY_BUFFER_ARB, mGLBuffer); + glBindBuffer(GL_ARRAY_BUFFER, mGLBuffer); sGLRenderBuffer = mGLBuffer; sBindCount++; sVBOActive = true; @@ -2125,7 +2125,7 @@ bool LLVertexBuffer::bindGLIndices(bool force_bind) { LL_ERRS() << "VBO bound while another VBO mapped!" << LL_ENDL; }*/ - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, mGLIndices); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mGLIndices); sGLRenderIndices = mGLIndices; stop_glerror(); sBindCount++; @@ -2140,7 +2140,7 @@ bool LLVertexBuffer::bindGLIndicesFast() { if (mGLIndices != sGLRenderIndices || !sIBOActive) { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, mGLIndices); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mGLIndices); sGLRenderIndices = mGLIndices; sBindCount++; sIBOActive = true; @@ -2302,7 +2302,7 @@ void LLVertexBuffer::setBuffer(U32 data_mask) { if (sVBOActive) { - glBindBuffer(GL_ARRAY_BUFFER_ARB, 0); + glBindBuffer(GL_ARRAY_BUFFER, 0); sBindCount++; sVBOActive = false; setup = true; // ... or a VBO is deactivated @@ -2317,7 +2317,7 @@ void LLVertexBuffer::setBuffer(U32 data_mask) { if (sIBOActive) { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); sBindCount++; sIBOActive = false; } -- cgit v1.2.3 From 00b1fec9601c3618f12cebce551e4ce2b38d7e00 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 2 Sep 2022 19:53:56 -0500 Subject: SL-17967 Purge OpenGL extensions (use core API only) --- indra/llrender/llvertexbuffer.cpp | 26 -------------------------- 1 file changed, 26 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 4b639e9e84..a40ea2eb1e 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -1530,10 +1530,6 @@ U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_ran { if (map_range) { -#ifndef LL_MESA_HEADLESS - glBufferParameteriAPPLE(GL_ARRAY_BUFFER, GL_BUFFER_SERIALIZED_MODIFY_APPLE, GL_FALSE); - glBufferParameteriAPPLE(GL_ARRAY_BUFFER, GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE); -#endif src = (U8*) glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); } else @@ -1703,10 +1699,6 @@ U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range) { if (map_range) { -#ifndef LL_MESA_HEADLESS - glBufferParameteriAPPLE(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SERIALIZED_MODIFY_APPLE, GL_FALSE); - glBufferParameteriAPPLE(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE); -#endif src = (U8*) glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY); } else @@ -1832,15 +1824,7 @@ void LLVertexBuffer::unmapBuffer() S32 length = sTypeSize[region.mType]*region.mCount; if (gGLManager.mHasMapBufferRange) { -#ifdef GL_ARB_map_buffer_range glFlushMappedBufferRange(GL_ARRAY_BUFFER, offset, length); -#endif - } - else if (gGLManager.mHasFlushBufferRange) - { -#ifndef LL_MESA_HEADLESS - glFlushMappedBufferRangeAPPLE(GL_ARRAY_BUFFER, offset, length); -#endif } } @@ -1912,17 +1896,7 @@ void LLVertexBuffer::unmapBuffer() S32 length = sizeof(U16)*region.mCount; if (gGLManager.mHasMapBufferRange) { -#ifdef GL_ARB_map_buffer_range glFlushMappedBufferRange(GL_ELEMENT_ARRAY_BUFFER, offset, length); -#endif - } - else if (gGLManager.mHasFlushBufferRange) - { -#ifdef GL_APPLE_flush_buffer_range -#ifndef LL_MESA_HEADLESS - glFlushMappedBufferRangeAPPLE(GL_ELEMENT_ARRAY_BUFFER, offset, length); -#endif -#endif } stop_glerror(); } -- cgit v1.2.3 From 8dc59e5ef37836b15d478fb0d04e3043a9f986de Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 16 Sep 2022 16:25:26 -0500 Subject: SL-18128 Clear out much OpenGL cruft and switch to core profile on AMD --- indra/llrender/llvertexbuffer.cpp | 200 ++++++++++++-------------------------- 1 file changed, 63 insertions(+), 137 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index a40ea2eb1e..d05f916d95 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -744,7 +744,7 @@ void LLVertexBuffer::drawArrays(U32 mode, U32 first, U32 count) const //static void LLVertexBuffer::initClass(bool use_vbo, bool no_vbo_mapping) { - sEnableVBOs = use_vbo && gGLManager.mHasVertexBufferObject; + sEnableVBOs = use_vbo; sDisableVBOMapping = sEnableVBOs && no_vbo_mapping; } @@ -753,9 +753,7 @@ void LLVertexBuffer::unbind() { if (sGLRenderArray) { -#if GL_ARB_vertex_array_object glBindVertexArray(0); -#endif sGLRenderArray = 0; sGLRenderIndices = 0; sIBOActive = false; @@ -923,9 +921,7 @@ LLVertexBuffer::~LLVertexBuffer() if (mGLArray) { -#if GL_ARB_vertex_array_object releaseVAOName(mGLArray); -#endif } sCount--; @@ -956,10 +952,7 @@ void LLVertexBuffer::placeFence() const { /*if (!mFence && useVBOs()) { - if (gGLManager.mHasSync) - { - mFence = new LLGLSyncFence(); - } + mFence = new LLGLSyncFence(); } if (mFence) @@ -1234,11 +1227,9 @@ bool LLVertexBuffer::allocateBuffer(S32 nverts, S32 nindices, bool create) //actually allocate space for the vertex buffer if using VBO mapping flush(); //unmap - if (gGLManager.mHasVertexArrayObject && useVBOs() && sUseVAO) + if (useVBOs() && sUseVAO) { -#if GL_ARB_vertex_array_object mGLArray = getVAOName(); -#endif setupVertexArray(); } } @@ -1254,9 +1245,7 @@ void LLVertexBuffer::setupVertexArray() } LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; -#if GL_ARB_vertex_array_object glBindVertexArray(mGLArray); -#endif sGLRenderArray = mGLArray; static const U32 attrib_size[] = @@ -1443,7 +1432,7 @@ U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_ran if (useVBOs()) { - if (!mMappable || gGLManager.mHasMapBufferRange || gGLManager.mHasFlushBufferRange) + if (!mMappable) { if (count == -1) { @@ -1492,58 +1481,34 @@ U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_ran { U8* src = NULL; waitFence(); - if (gGLManager.mHasMapBufferRange) + if (map_range) { - if (map_range) - { -#ifdef GL_ARB_map_buffer_range - S32 offset = mOffsets[type] + sTypeSize[type]*index; - S32 length = (sTypeSize[type]*count+0xF) & ~0xF; - src = (U8*) glMapBufferRange(GL_ARRAY_BUFFER, offset, length, - GL_MAP_WRITE_BIT | - GL_MAP_FLUSH_EXPLICIT_BIT | - GL_MAP_INVALIDATE_RANGE_BIT); -#endif - } - else + S32 offset = mOffsets[type] + sTypeSize[type]*index; + S32 length = (sTypeSize[type]*count+0xF) & ~0xF; + src = (U8*) glMapBufferRange(GL_ARRAY_BUFFER, offset, length, + GL_MAP_WRITE_BIT | + GL_MAP_FLUSH_EXPLICIT_BIT | + GL_MAP_INVALIDATE_RANGE_BIT); + } + else + { + if (gDebugGL) { -#ifdef GL_ARB_map_buffer_range + GLint size = 0; + glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); - if (gDebugGL) + if (size < mSize) { - GLint size = 0; - glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); - - if (size < mSize) - { - LL_ERRS() << "Invalid buffer size." << LL_ENDL; - } + LL_ERRS() << "Invalid buffer size." << LL_ENDL; } - - src = (U8*) glMapBufferRange(GL_ARRAY_BUFFER, 0, mSize, - GL_MAP_WRITE_BIT | - GL_MAP_FLUSH_EXPLICIT_BIT); -#endif - } - } - else if (gGLManager.mHasFlushBufferRange) - { - if (map_range) - { - src = (U8*) glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); - } - else - { - src = (U8*) glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); } - } - else - { - map_range = false; - src = (U8*) glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); + + src = (U8*) glMapBufferRange(GL_ARRAY_BUFFER, 0, mSize, + GL_MAP_WRITE_BIT | + GL_MAP_FLUSH_EXPLICIT_BIT); } - llassert(src != NULL); + llassert(src != NULL); mMappedData = LL_NEXT_ALIGNED_ADDRESS(src); mAlignedOffset = mMappedData - src; @@ -1569,7 +1534,7 @@ U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_ran //-------------------- GLint buff; - glGetIntegerv(GL_ARRAY_BUFFER_BINDING_ARB, &buff); + glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &buff); if ((GLuint)buff != mGLBuffer) { LL_ERRS() << "Invalid GL vertex buffer bound: " << buff << LL_ENDL; @@ -1590,7 +1555,7 @@ U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_ran map_range = false; } - if (map_range && gGLManager.mHasMapBufferRange && mMappable) + if (map_range && mMappable) { return mMappedData; } @@ -1616,7 +1581,7 @@ U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range) if (useVBOs()) { - if (!mMappable || gGLManager.mHasMapBufferRange || gGLManager.mHasFlushBufferRange) + if (!mMappable) { if (count == -1) { @@ -1657,7 +1622,7 @@ U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range) if (gDebugGL && useVBOs()) { GLint elem = 0; - glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, &elem); + glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &elem); if (elem != mGLIndices) { @@ -1673,48 +1638,24 @@ U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range) { U8* src = NULL; waitFence(); - if (gGLManager.mHasMapBufferRange) + if (map_range) { - if (map_range) - { -#ifdef GL_ARB_map_buffer_range - S32 offset = sizeof(U16)*index; - S32 length = sizeof(U16)*count; - src = (U8*) glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, offset, length, - GL_MAP_WRITE_BIT | - GL_MAP_FLUSH_EXPLICIT_BIT | - GL_MAP_INVALIDATE_RANGE_BIT); -#endif - } - else - { -#ifdef GL_ARB_map_buffer_range - src = (U8*) glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(U16)*mNumIndices, - GL_MAP_WRITE_BIT | - GL_MAP_FLUSH_EXPLICIT_BIT); -#endif - } - } - else if (gGLManager.mHasFlushBufferRange) - { - if (map_range) - { - src = (U8*) glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY); - } - else - { - src = (U8*) glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY); - } + S32 offset = sizeof(U16)*index; + S32 length = sizeof(U16)*count; + src = (U8*) glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, offset, length, + GL_MAP_WRITE_BIT | + GL_MAP_FLUSH_EXPLICIT_BIT | + GL_MAP_INVALIDATE_RANGE_BIT); } else { - map_range = false; - src = (U8*) glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY); + src = (U8*) glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(U16)*mNumIndices, + GL_MAP_WRITE_BIT | + GL_MAP_FLUSH_EXPLICIT_BIT); } - + llassert(src != NULL); - mMappedIndexData = src; //LL_NEXT_ALIGNED_ADDRESS(src); mAlignedIndexOffset = mMappedIndexData - src; stop_glerror(); @@ -1729,7 +1670,7 @@ U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range) if(mMappable) { GLint buff; - glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, &buff); + glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &buff); if ((GLuint)buff != mGLIndices) { LL_ERRS() << "Invalid GL index buffer bound: " << buff << LL_ENDL; @@ -1748,7 +1689,7 @@ U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range) map_range = false; } - if (map_range && gGLManager.mHasMapBufferRange && mMappable) + if (map_range && mMappable) { return mMappedIndexData; } @@ -1812,25 +1753,20 @@ void LLVertexBuffer::unmapBuffer() } else { - if (gGLManager.mHasMapBufferRange || gGLManager.mHasFlushBufferRange) + if (!mMappedVertexRegions.empty()) { - if (!mMappedVertexRegions.empty()) + LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("unmapBuffer - flush vertex"); + for (U32 i = 0; i < mMappedVertexRegions.size(); ++i) { - LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("unmapBuffer - flush vertex"); - for (U32 i = 0; i < mMappedVertexRegions.size(); ++i) - { - const MappedRegion& region = mMappedVertexRegions[i]; - S32 offset = region.mIndex >= 0 ? mOffsets[region.mType]+sTypeSize[region.mType]*region.mIndex : 0; - S32 length = sTypeSize[region.mType]*region.mCount; - if (gGLManager.mHasMapBufferRange) - { - glFlushMappedBufferRange(GL_ARRAY_BUFFER, offset, length); - } - } - - mMappedVertexRegions.clear(); + const MappedRegion& region = mMappedVertexRegions[i]; + S32 offset = region.mIndex >= 0 ? mOffsets[region.mType]+sTypeSize[region.mType]*region.mIndex : 0; + S32 length = sTypeSize[region.mType]*region.mCount; + glFlushMappedBufferRange(GL_ARRAY_BUFFER, offset, length); } + + mMappedVertexRegions.clear(); } + stop_glerror(); glUnmapBuffer(GL_ARRAY_BUFFER); stop_glerror(); @@ -1884,25 +1820,19 @@ void LLVertexBuffer::unmapBuffer() } else { - if (gGLManager.mHasMapBufferRange || gGLManager.mHasFlushBufferRange) + if (!mMappedIndexRegions.empty()) { - if (!mMappedIndexRegions.empty()) + for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) { - for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) - { - LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("unmapBuffer - flush index"); - const MappedRegion& region = mMappedIndexRegions[i]; - S32 offset = region.mIndex >= 0 ? sizeof(U16)*region.mIndex : 0; - S32 length = sizeof(U16)*region.mCount; - if (gGLManager.mHasMapBufferRange) - { - glFlushMappedBufferRange(GL_ELEMENT_ARRAY_BUFFER, offset, length); - } - stop_glerror(); - } - - mMappedIndexRegions.clear(); + LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("unmapBuffer - flush index"); + const MappedRegion& region = mMappedIndexRegions[i]; + S32 offset = region.mIndex >= 0 ? sizeof(U16)*region.mIndex : 0; + S32 length = sizeof(U16)*region.mCount; + glFlushMappedBufferRange(GL_ELEMENT_ARRAY_BUFFER, offset, length); + stop_glerror(); } + + mMappedIndexRegions.clear(); } glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER); @@ -2034,9 +1964,7 @@ bool LLVertexBuffer::bindGLArray() { { LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; -#if GL_ARB_vertex_array_object glBindVertexArray(mGLArray); -#endif sGLRenderArray = mGLArray; } @@ -2228,7 +2156,7 @@ void LLVertexBuffer::setBuffer(U32 data_mask) if (gDebugGL && !mGLArray) { GLint buff; - glGetIntegerv(GL_ARRAY_BUFFER_BINDING_ARB, &buff); + glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &buff); if ((GLuint)buff != mGLBuffer) { if (gDebugSession) @@ -2243,7 +2171,7 @@ void LLVertexBuffer::setBuffer(U32 data_mask) if (mGLIndices) { - glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, &buff); + glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &buff); if ((GLuint)buff != mGLIndices) { if (gDebugSession) @@ -2264,9 +2192,7 @@ void LLVertexBuffer::setBuffer(U32 data_mask) { if (sGLRenderArray) { -#if GL_ARB_vertex_array_object glBindVertexArray(0); -#endif sGLRenderArray = 0; sGLRenderIndices = 0; sIBOActive = false; -- cgit v1.2.3 From 718073717c70b1f7e7284a02641c0a0a7bf50367 Mon Sep 17 00:00:00 2001 From: "Howard (Aech Linden) Stearns" Date: Mon, 19 Sep 2022 12:16:49 -0700 Subject: SL-18128, SL-18128 - No glerror on Mac! --- indra/llrender/llvertexbuffer.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index d05f916d95..981175d845 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -1327,7 +1327,6 @@ void LLVertexBuffer::setupVertexArray() if (attrib_integer[i]) { -#if !LL_DARWIN //glVertexattribIPointer requires GLSL 1.30 or later if (gGLManager.mGLSLVersionMajor > 1 || gGLManager.mGLSLVersionMinor >= 30) { @@ -1336,9 +1335,8 @@ void LLVertexBuffer::setupVertexArray() // Cast via intptr_t to make it painfully obvious to the // compiler that we're doing this intentionally. glVertexAttribIPointer(i, attrib_size[i], attrib_type[i], sTypeSize[i], - reinterpret_cast(intptr_t(mOffsets[i]))); + reinterpret_cast(intptr_t(mOffsets[i]))); } -#endif } else { @@ -2364,11 +2362,9 @@ void LLVertexBuffer::setupVertexBuffer(U32 data_mask) if (data_mask & MAP_TEXTURE_INDEX && (gGLManager.mGLSLVersionMajor >= 2 || gGLManager.mGLSLVersionMinor >= 30)) //indexed texture rendering requires GLSL 1.30 or later { -#if !LL_DARWIN S32 loc = TYPE_TEXTURE_INDEX; void *ptr = (void*) (base + mOffsets[TYPE_VERTEX] + 12); glVertexAttribIPointer(loc, 1, GL_UNSIGNED_INT, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); -#endif } if (data_mask & MAP_VERTEX) { @@ -2459,11 +2455,9 @@ void LLVertexBuffer::setupVertexBufferFast(U32 data_mask) } if (data_mask & MAP_TEXTURE_INDEX) { -#if !LL_DARWIN S32 loc = TYPE_TEXTURE_INDEX; void* ptr = (void*)(base + mOffsets[TYPE_VERTEX] + 12); glVertexAttribIPointer(loc, 1, GL_UNSIGNED_INT, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); -#endif } if (data_mask & MAP_VERTEX) { -- cgit v1.2.3 From be1cdc1aaa67eca71fee8cbbc16b4c85bcbdb258 Mon Sep 17 00:00:00 2001 From: Geenz Date: Wed, 5 Oct 2022 09:48:18 -0700 Subject: Initial pass at adding KHR_debug support This still needs some work - I'm not super satisfied with the overall structure of the code. Will continue to iterate as I add in proper RenderDoc support. --- indra/llrender/llvertexbuffer.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 981175d845..4ce04c17f6 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -175,7 +175,7 @@ U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) { //make a new buffer name = genBuffer(); - + glBindBuffer(mType, name); if (!for_seed && i < LL_VBO_POOL_SEED_COUNT) @@ -574,6 +574,10 @@ void LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_of } } +void LLVertexBuffer::setLabel(std::string label) { + LL_LABEL_OBJECT_GL(GL_BUFFER, mGLBuffer, label.length(), label.c_str()); +} + void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indices_offset) const { validateRange(start, end, count, indices_offset); @@ -1068,6 +1072,7 @@ bool LLVertexBuffer::createGLBuffer(U32 size) { static int gl_buffer_idx = 0; mGLBuffer = ++gl_buffer_idx; + mMappedData = (U8*)ll_aligned_malloc_16(size); mSize = size; } -- cgit v1.2.3 From db92f9564992b9910b21f3de57a584ccfa199e75 Mon Sep 17 00:00:00 2001 From: Geenz Linden Date: Thu, 6 Oct 2022 15:18:17 -0400 Subject: Switch away from std::string API expects const char* anyways. --- indra/llrender/llvertexbuffer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 4ce04c17f6..33dcd6c563 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -574,9 +574,11 @@ void LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_of } } -void LLVertexBuffer::setLabel(std::string label) { - LL_LABEL_OBJECT_GL(GL_BUFFER, mGLBuffer, label.length(), label.c_str()); +#ifdef LL_PROFILER_ENABLE_TRACY_OPENGL +void LLVertexBuffer::setLabel(const char* label) { + LL_LABEL_OBJECT_GL(GL_BUFFER, mGLBuffer, strlen(label), label); } +#endif void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indices_offset) const { -- cgit v1.2.3 From 9e7b725c15ea0bfea5246eb81dd7a100b7ac5b6b Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Mon, 31 Oct 2022 09:42:27 -0700 Subject: SL-18485: Render GLTF materials with extension KHR_texture_transform with approprate texture transforms --- indra/llrender/llvertexbuffer.cpp | 92 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index f51000b9a6..b33708cae6 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -358,6 +358,10 @@ const S32 LLVertexBuffer::sTypeSize[LLVertexBuffer::TYPE_MAX] = sizeof(LLVector4), // TYPE_WEIGHT4, sizeof(LLVector4), // TYPE_CLOTHWEIGHT, sizeof(LLVector4), // TYPE_TEXTURE_INDEX (actually exists as position.w), no extra data, but stride is 16 bytes + sizeof(LLVector2), // TYPE_BASECOLOR_TEXCOORD, + sizeof(LLVector2), // TYPE_NORMAL_TEXCOORD, + sizeof(LLVector2), // TYPE_METALLIC_ROUGHNESS_TEXCOORD, + sizeof(LLVector2), // TYPE_EMISSIVE_TEXCOORD, }; static const std::string vb_type_name[] = @@ -375,6 +379,10 @@ static const std::string vb_type_name[] = "TYPE_WEIGHT4", "TYPE_CLOTHWEIGHT", "TYPE_TEXTURE_INDEX", + "TYPE_BASECOLOR_TEXCOORD", + "TYPE_NORMAL_TEXCOORD", + "TYPE_METALLIC_ROUGHNESS_TEXCOORD", + "TYPE_EMISSIVE_TEXCOORD", "TYPE_MAX", "TYPE_INDEX", }; @@ -1270,6 +1278,10 @@ void LLVertexBuffer::setupVertexArray() 4, //TYPE_WEIGHT4, 4, //TYPE_CLOTHWEIGHT, 1, //TYPE_TEXTURE_INDEX + 2, // TYPE_BASECOLOR_TEXCOORD, + 2, // TYPE_NORMAL_TEXCOORD, + 2, // TYPE_METALLIC_ROUGHNESS_TEXCOORD, + 2, // TYPE_EMISSIVE_TEXCOORD, }; static const U32 attrib_type[] = @@ -1287,6 +1299,10 @@ void LLVertexBuffer::setupVertexArray() GL_FLOAT, //TYPE_WEIGHT4, GL_FLOAT, //TYPE_CLOTHWEIGHT, GL_UNSIGNED_INT, //TYPE_TEXTURE_INDEX + GL_FLOAT, // TYPE_BASECOLOR_TEXCOORD, + GL_FLOAT, // TYPE_NORMAL_TEXCOORD, + GL_FLOAT, // TYPE_METALLIC_ROUGHNESS_TEXCOORD, + GL_FLOAT, // TYPE_EMISSIVE_TEXCOORD, }; static const bool attrib_integer[] = @@ -1304,6 +1320,10 @@ void LLVertexBuffer::setupVertexArray() false, //TYPE_WEIGHT4, false, //TYPE_CLOTHWEIGHT, true, //TYPE_TEXTURE_INDEX + false, // TYPE_BASECOLOR_TEXCOORD, + false, // TYPE_NORMAL_TEXCOORD, + false, // TYPE_METALLIC_ROUGHNESS_TEXCOORD, + false, // TYPE_EMISSIVE_TEXCOORD, }; static const U32 attrib_normalized[] = @@ -1321,6 +1341,10 @@ void LLVertexBuffer::setupVertexArray() GL_FALSE, //TYPE_WEIGHT4, GL_FALSE, //TYPE_CLOTHWEIGHT, GL_FALSE, //TYPE_TEXTURE_INDEX + GL_FALSE, // TYPE_BASECOLOR_TEXCOORD, + GL_FALSE, // TYPE_NORMAL_TEXCOORD, + GL_FALSE, // TYPE_METALLIC_ROUGHNESS_TEXCOORD, + GL_FALSE, // TYPE_EMISSIVE_TEXCOORD, }; bindGLBuffer(true); @@ -1961,6 +1985,26 @@ bool LLVertexBuffer::getClothWeightStrider(LLStrider& strider, S32 in return VertexBufferStrider::get(*this, strider, index, count, map_range); } +bool LLVertexBuffer::getBasecolorTexcoordStrider(LLStrider& strider, S32 index, S32 count, bool map_range) +{ + return VertexBufferStrider::get(*this, strider, index, count, map_range); +} + +bool LLVertexBuffer::getNormalTexcoordStrider(LLStrider& strider, S32 index, S32 count, bool map_range) +{ + return VertexBufferStrider::get(*this, strider, index, count, map_range); +} + +bool LLVertexBuffer::getMetallicRoughnessTexcoordStrider(LLStrider& strider, S32 index, S32 count, bool map_range) +{ + return VertexBufferStrider::get(*this, strider, index, count, map_range); +} + +bool LLVertexBuffer::getEmissiveTexcoordStrider(LLStrider& strider, S32 index, S32 count, bool map_range) +{ + return VertexBufferStrider::get(*this, strider, index, count, map_range); +} + //---------------------------------------------------------------------------- bool LLVertexBuffer::bindGLArray() @@ -2379,6 +2423,30 @@ void LLVertexBuffer::setupVertexBuffer(U32 data_mask) void* ptr = (void*)(base + mOffsets[TYPE_VERTEX]); glVertexAttribPointer(loc, 3,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); } + if (data_mask & MAP_BASECOLOR_TEXCOORD) + { + S32 loc = TYPE_BASECOLOR_TEXCOORD; + void* ptr = (void*)(base + mOffsets[TYPE_BASECOLOR_TEXCOORD]); + glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_BASECOLOR_TEXCOORD], ptr); + } + if (data_mask & MAP_NORMAL_TEXCOORD) + { + S32 loc = TYPE_NORMAL_TEXCOORD; + void* ptr = (void*)(base + mOffsets[TYPE_NORMAL_TEXCOORD]); + glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_NORMAL_TEXCOORD], ptr); + } + if (data_mask & MAP_METALLIC_ROUGHNESS_TEXCOORD) + { + S32 loc = TYPE_METALLIC_ROUGHNESS_TEXCOORD; + void* ptr = (void*)(base + mOffsets[TYPE_METALLIC_ROUGHNESS_TEXCOORD]); + glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_METALLIC_ROUGHNESS_TEXCOORD], ptr); + } + if (data_mask & MAP_EMISSIVE_TEXCOORD) + { + S32 loc = TYPE_EMISSIVE_TEXCOORD; + void* ptr = (void*)(base + mOffsets[TYPE_EMISSIVE_TEXCOORD]); + glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_EMISSIVE_TEXCOORD], ptr); + } llglassertok(); } @@ -2472,6 +2540,30 @@ void LLVertexBuffer::setupVertexBufferFast(U32 data_mask) void* ptr = (void*)(base + mOffsets[TYPE_VERTEX]); glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); } + if (data_mask & MAP_BASECOLOR_TEXCOORD) + { + S32 loc = TYPE_BASECOLOR_TEXCOORD; + void* ptr = (void*)(base + mOffsets[TYPE_BASECOLOR_TEXCOORD]); + glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_BASECOLOR_TEXCOORD], ptr); + } + if (data_mask & MAP_NORMAL_TEXCOORD) + { + S32 loc = TYPE_NORMAL_TEXCOORD; + void* ptr = (void*)(base + mOffsets[TYPE_NORMAL_TEXCOORD]); + glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_NORMAL_TEXCOORD], ptr); + } + if (data_mask & MAP_METALLIC_ROUGHNESS_TEXCOORD) + { + S32 loc = TYPE_METALLIC_ROUGHNESS_TEXCOORD; + void* ptr = (void*)(base + mOffsets[TYPE_METALLIC_ROUGHNESS_TEXCOORD]); + glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_METALLIC_ROUGHNESS_TEXCOORD], ptr); + } + if (data_mask & MAP_EMISSIVE_TEXCOORD) + { + S32 loc = TYPE_EMISSIVE_TEXCOORD; + void* ptr = (void*)(base + mOffsets[TYPE_EMISSIVE_TEXCOORD]); + glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_EMISSIVE_TEXCOORD], ptr); + } } LLVertexBuffer::MappedRegion::MappedRegion(S32 type, S32 index, S32 count) -- cgit v1.2.3 From 843a5c287e34855fb7bd4882d8d0a106e987a9f7 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 14 Nov 2022 11:40:18 -0600 Subject: SL-18485 Cleanup -- remove unused GLTF specific vertex attributes from LLVertexBuffer (blows past 16-attribute limit) --- indra/llrender/llvertexbuffer.cpp | 92 --------------------------------------- 1 file changed, 92 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index b33708cae6..f51000b9a6 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -358,10 +358,6 @@ const S32 LLVertexBuffer::sTypeSize[LLVertexBuffer::TYPE_MAX] = sizeof(LLVector4), // TYPE_WEIGHT4, sizeof(LLVector4), // TYPE_CLOTHWEIGHT, sizeof(LLVector4), // TYPE_TEXTURE_INDEX (actually exists as position.w), no extra data, but stride is 16 bytes - sizeof(LLVector2), // TYPE_BASECOLOR_TEXCOORD, - sizeof(LLVector2), // TYPE_NORMAL_TEXCOORD, - sizeof(LLVector2), // TYPE_METALLIC_ROUGHNESS_TEXCOORD, - sizeof(LLVector2), // TYPE_EMISSIVE_TEXCOORD, }; static const std::string vb_type_name[] = @@ -379,10 +375,6 @@ static const std::string vb_type_name[] = "TYPE_WEIGHT4", "TYPE_CLOTHWEIGHT", "TYPE_TEXTURE_INDEX", - "TYPE_BASECOLOR_TEXCOORD", - "TYPE_NORMAL_TEXCOORD", - "TYPE_METALLIC_ROUGHNESS_TEXCOORD", - "TYPE_EMISSIVE_TEXCOORD", "TYPE_MAX", "TYPE_INDEX", }; @@ -1278,10 +1270,6 @@ void LLVertexBuffer::setupVertexArray() 4, //TYPE_WEIGHT4, 4, //TYPE_CLOTHWEIGHT, 1, //TYPE_TEXTURE_INDEX - 2, // TYPE_BASECOLOR_TEXCOORD, - 2, // TYPE_NORMAL_TEXCOORD, - 2, // TYPE_METALLIC_ROUGHNESS_TEXCOORD, - 2, // TYPE_EMISSIVE_TEXCOORD, }; static const U32 attrib_type[] = @@ -1299,10 +1287,6 @@ void LLVertexBuffer::setupVertexArray() GL_FLOAT, //TYPE_WEIGHT4, GL_FLOAT, //TYPE_CLOTHWEIGHT, GL_UNSIGNED_INT, //TYPE_TEXTURE_INDEX - GL_FLOAT, // TYPE_BASECOLOR_TEXCOORD, - GL_FLOAT, // TYPE_NORMAL_TEXCOORD, - GL_FLOAT, // TYPE_METALLIC_ROUGHNESS_TEXCOORD, - GL_FLOAT, // TYPE_EMISSIVE_TEXCOORD, }; static const bool attrib_integer[] = @@ -1320,10 +1304,6 @@ void LLVertexBuffer::setupVertexArray() false, //TYPE_WEIGHT4, false, //TYPE_CLOTHWEIGHT, true, //TYPE_TEXTURE_INDEX - false, // TYPE_BASECOLOR_TEXCOORD, - false, // TYPE_NORMAL_TEXCOORD, - false, // TYPE_METALLIC_ROUGHNESS_TEXCOORD, - false, // TYPE_EMISSIVE_TEXCOORD, }; static const U32 attrib_normalized[] = @@ -1341,10 +1321,6 @@ void LLVertexBuffer::setupVertexArray() GL_FALSE, //TYPE_WEIGHT4, GL_FALSE, //TYPE_CLOTHWEIGHT, GL_FALSE, //TYPE_TEXTURE_INDEX - GL_FALSE, // TYPE_BASECOLOR_TEXCOORD, - GL_FALSE, // TYPE_NORMAL_TEXCOORD, - GL_FALSE, // TYPE_METALLIC_ROUGHNESS_TEXCOORD, - GL_FALSE, // TYPE_EMISSIVE_TEXCOORD, }; bindGLBuffer(true); @@ -1985,26 +1961,6 @@ bool LLVertexBuffer::getClothWeightStrider(LLStrider& strider, S32 in return VertexBufferStrider::get(*this, strider, index, count, map_range); } -bool LLVertexBuffer::getBasecolorTexcoordStrider(LLStrider& strider, S32 index, S32 count, bool map_range) -{ - return VertexBufferStrider::get(*this, strider, index, count, map_range); -} - -bool LLVertexBuffer::getNormalTexcoordStrider(LLStrider& strider, S32 index, S32 count, bool map_range) -{ - return VertexBufferStrider::get(*this, strider, index, count, map_range); -} - -bool LLVertexBuffer::getMetallicRoughnessTexcoordStrider(LLStrider& strider, S32 index, S32 count, bool map_range) -{ - return VertexBufferStrider::get(*this, strider, index, count, map_range); -} - -bool LLVertexBuffer::getEmissiveTexcoordStrider(LLStrider& strider, S32 index, S32 count, bool map_range) -{ - return VertexBufferStrider::get(*this, strider, index, count, map_range); -} - //---------------------------------------------------------------------------- bool LLVertexBuffer::bindGLArray() @@ -2423,30 +2379,6 @@ void LLVertexBuffer::setupVertexBuffer(U32 data_mask) void* ptr = (void*)(base + mOffsets[TYPE_VERTEX]); glVertexAttribPointer(loc, 3,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); } - if (data_mask & MAP_BASECOLOR_TEXCOORD) - { - S32 loc = TYPE_BASECOLOR_TEXCOORD; - void* ptr = (void*)(base + mOffsets[TYPE_BASECOLOR_TEXCOORD]); - glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_BASECOLOR_TEXCOORD], ptr); - } - if (data_mask & MAP_NORMAL_TEXCOORD) - { - S32 loc = TYPE_NORMAL_TEXCOORD; - void* ptr = (void*)(base + mOffsets[TYPE_NORMAL_TEXCOORD]); - glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_NORMAL_TEXCOORD], ptr); - } - if (data_mask & MAP_METALLIC_ROUGHNESS_TEXCOORD) - { - S32 loc = TYPE_METALLIC_ROUGHNESS_TEXCOORD; - void* ptr = (void*)(base + mOffsets[TYPE_METALLIC_ROUGHNESS_TEXCOORD]); - glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_METALLIC_ROUGHNESS_TEXCOORD], ptr); - } - if (data_mask & MAP_EMISSIVE_TEXCOORD) - { - S32 loc = TYPE_EMISSIVE_TEXCOORD; - void* ptr = (void*)(base + mOffsets[TYPE_EMISSIVE_TEXCOORD]); - glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_EMISSIVE_TEXCOORD], ptr); - } llglassertok(); } @@ -2540,30 +2472,6 @@ void LLVertexBuffer::setupVertexBufferFast(U32 data_mask) void* ptr = (void*)(base + mOffsets[TYPE_VERTEX]); glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); } - if (data_mask & MAP_BASECOLOR_TEXCOORD) - { - S32 loc = TYPE_BASECOLOR_TEXCOORD; - void* ptr = (void*)(base + mOffsets[TYPE_BASECOLOR_TEXCOORD]); - glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_BASECOLOR_TEXCOORD], ptr); - } - if (data_mask & MAP_NORMAL_TEXCOORD) - { - S32 loc = TYPE_NORMAL_TEXCOORD; - void* ptr = (void*)(base + mOffsets[TYPE_NORMAL_TEXCOORD]); - glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_NORMAL_TEXCOORD], ptr); - } - if (data_mask & MAP_METALLIC_ROUGHNESS_TEXCOORD) - { - S32 loc = TYPE_METALLIC_ROUGHNESS_TEXCOORD; - void* ptr = (void*)(base + mOffsets[TYPE_METALLIC_ROUGHNESS_TEXCOORD]); - glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_METALLIC_ROUGHNESS_TEXCOORD], ptr); - } - if (data_mask & MAP_EMISSIVE_TEXCOORD) - { - S32 loc = TYPE_EMISSIVE_TEXCOORD; - void* ptr = (void*)(base + mOffsets[TYPE_EMISSIVE_TEXCOORD]); - glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_EMISSIVE_TEXCOORD], ptr); - } } LLVertexBuffer::MappedRegion::MappedRegion(S32 type, S32 index, S32 count) -- cgit v1.2.3 From 8d2ac419b22c8c9475f2efb312dd198ac8eb9fb7 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 16 Nov 2022 14:49:17 -0600 Subject: SL-18154 Profile guided optimizations vs release viewer. Trim some unused abilities and remove some more fast timers. --- 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 f51000b9a6..fc24c6846d 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -574,7 +574,7 @@ void LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_of } } -#ifdef LL_PROFILER_ENABLE_TRACY_OPENGL +#ifdef LL_PROFILER_ENABLE_RENDER_DOC void LLVertexBuffer::setLabel(const char* label) { LL_LABEL_OBJECT_GL(GL_BUFFER, mGLBuffer, strlen(label), label); } -- cgit v1.2.3 From c489481ec5edd0470553eca9b7c4cecfe994926c Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 6 Dec 2022 09:59:30 -0600 Subject: SL-18785 Fix for corrupt reflection probes on various preference changes. Add UI for Screen Space Reflections. --- 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 adb3d99553..6122681c09 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -796,8 +796,8 @@ void LLVertexBuffer::cleanupClass() llassert(0 == LLVBOPool::sBytesPooled); llassert(0 == LLVBOPool::sIndexBytesPooled); - llassert(0 == sAllocatedBytes); - llassert(0 == sAllocatedIndexBytes); + //llassert(0 == sAllocatedBytes); + //llassert(0 == sAllocatedIndexBytes); } //---------------------------------------------------------------------------- -- cgit v1.2.3 From b3fc82ff1da0c869f0b1dd841647a120a1ae56af Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 9 Jan 2023 13:05:32 -0600 Subject: SL-18869 Optimizations -- decruftify LLVertexBuffer and make an optimal "renderShadowSimple" utility function for pushing vertex buffers only. --- indra/llrender/llvertexbuffer.cpp | 667 +++++++------------------------------- 1 file changed, 116 insertions(+), 551 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 6122681c09..7b8f85acba 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -436,12 +436,6 @@ void LLVertexBuffer::setupClientArrays(U32 data_mask) if (sLastMask != data_mask) { - if (gGLManager.mGLSLVersionMajor < 2 && gGLManager.mGLSLVersionMinor < 30) - { - //make sure texture index is disabled - data_mask = data_mask & ~MAP_TEXTURE_INDEX; - } - for (U32 i = 0; i < TYPE_MAX; ++i) { S32 loc = i; @@ -584,33 +578,22 @@ void LLVertexBuffer::setLabel(const char* label) { void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indices_offset) const { validateRange(start, end, count, indices_offset); - mMappable = false; gGL.syncMatrices(); llassert(mNumVerts >= 0); llassert(LLGLSLShader::sCurBoundShaderPtr != NULL); - if (mGLArray) + if (mGLIndices != sGLRenderIndices) { - if (mGLArray != sGLRenderArray) - { - LL_ERRS() << "Wrong vertex array bound." << LL_ENDL; - } + LL_ERRS() << "Wrong index buffer bound." << LL_ENDL; } - else - { - if (mGLIndices != sGLRenderIndices) - { - LL_ERRS() << "Wrong index buffer bound." << LL_ENDL; - } - if (mGLBuffer != sGLRenderBuffer) - { - LL_ERRS() << "Wrong vertex buffer bound." << LL_ENDL; - } + if (mGLBuffer != sGLRenderBuffer) + { + LL_ERRS() << "Wrong vertex buffer bound." << LL_ENDL; } - if (gDebugGL && !mGLArray && useVBOs()) + if (gDebugGL && useVBOs()) { GLint elem = 0; glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, &elem); @@ -635,15 +618,10 @@ void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indi idx); LLGLSLShader::stopProfile(count, mode); stop_glerror(); - - - - placeFence(); } void LLVertexBuffer::drawRangeFast(U32 mode, U32 start, U32 end, U32 count, U32 indices_offset) const { - mMappable = false; gGL.syncMatrices(); U16* idx = ((U16*)getIndicesPointer()) + indices_offset; @@ -655,7 +633,6 @@ void LLVertexBuffer::drawRangeFast(U32 mode, U32 start, U32 end, U32 count, U32 void LLVertexBuffer::draw(U32 mode, U32 count, U32 indices_offset) const { llassert(LLGLSLShader::sCurBoundShaderPtr != NULL); - mMappable = false; gGL.syncMatrices(); llassert(mNumIndices >= 0); @@ -665,24 +642,15 @@ void LLVertexBuffer::draw(U32 mode, U32 count, U32 indices_offset) const LL_ERRS() << "Bad index buffer draw range: [" << indices_offset << ", " << indices_offset+count << "]" << LL_ENDL; } - if (mGLArray) + + if (mGLIndices != sGLRenderIndices) { - if (mGLArray != sGLRenderArray) - { - LL_ERRS() << "Wrong vertex array bound." << LL_ENDL; - } + LL_ERRS() << "Wrong index buffer bound." << LL_ENDL; } - else - { - if (mGLIndices != sGLRenderIndices) - { - LL_ERRS() << "Wrong index buffer bound." << LL_ENDL; - } - if (mGLBuffer != sGLRenderBuffer) - { - LL_ERRS() << "Wrong vertex buffer bound." << LL_ENDL; - } + if (mGLBuffer != sGLRenderBuffer) + { + LL_ERRS() << "Wrong vertex buffer bound." << LL_ENDL; } if (mode >= LLRender::NUM_MODES) @@ -697,7 +665,6 @@ void LLVertexBuffer::draw(U32 mode, U32 count, U32 indices_offset) const ((U16*) getIndicesPointer()) + indices_offset); LLGLSLShader::stopProfile(count, mode); stop_glerror(); - placeFence(); } @@ -705,7 +672,6 @@ void LLVertexBuffer::drawArrays(U32 mode, U32 first, U32 count) const { LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; llassert(LLGLSLShader::sCurBoundShaderPtr != NULL); - mMappable = false; gGL.syncMatrices(); #ifndef LL_RELEASE_FOR_DOWNLOAD @@ -716,19 +682,9 @@ void LLVertexBuffer::drawArrays(U32 mode, U32 first, U32 count) const LL_ERRS() << "Bad vertex buffer draw range: [" << first << ", " << first+count << "]" << LL_ENDL; } - if (mGLArray) + if (mGLBuffer != sGLRenderBuffer || useVBOs() != sVBOActive) { - if (mGLArray != sGLRenderArray) - { - LL_ERRS() << "Wrong vertex array bound." << LL_ENDL; - } - } - else - { - if (mGLBuffer != sGLRenderBuffer || useVBOs() != sVBOActive) - { - LL_ERRS() << "Wrong vertex buffer bound." << LL_ENDL; - } + LL_ERRS() << "Wrong vertex buffer bound." << LL_ENDL; } if (mode >= LLRender::NUM_MODES) @@ -745,7 +701,6 @@ void LLVertexBuffer::drawArrays(U32 mode, U32 first, U32 count) const LLGLSLShader::stopProfile(count, mode); stop_glerror(); - placeFence(); } //static @@ -849,15 +804,12 @@ LLVertexBuffer::LLVertexBuffer(U32 typemask, S32 usage) mNumVerts(0), mNumIndices(0), - mAlignedOffset(0), - mAlignedIndexOffset(0), mSize(0), mIndicesSize(0), mTypeMask(typemask), mUsage(LLVertexBuffer::determineUsage(usage)), mGLBuffer(0), mGLIndices(0), - mGLArray(0), mMappedData(NULL), mMappedIndexData(NULL), mMappedDataUsingVBOs(false), @@ -865,12 +817,8 @@ LLVertexBuffer::LLVertexBuffer(U32 typemask, S32 usage) mVertexLocked(false), mIndexLocked(false), mFinal(false), - mEmpty(true), - mMappable(false), - mFence(NULL) + mEmpty(true) { - mMappable = (mUsage == GL_DYNAMIC_DRAW && !sDisableVBOMapping); - //zero out offsets for (U32 i = 0; i < TYPE_MAX; i++) { @@ -931,22 +879,8 @@ LLVertexBuffer::~LLVertexBuffer() destroyGLBuffer(); destroyGLIndices(); - if (mGLArray) - { - releaseVAOName(mGLArray); - } - sCount--; - if (mFence) - { - // Sanity check. We have weird crashes in this destructor (on delete). Yet mFence is disabled. - // TODO: mFence was added in scope of SH-2038, but was never enabled, consider removing mFence. - LL_ERRS() << "LLVertexBuffer destruction failed" << LL_ENDL; - delete mFence; - mFence = NULL; - } - sVertexCount -= mNumVerts; sIndexCount -= mNumIndices; @@ -960,27 +894,6 @@ LLVertexBuffer::~LLVertexBuffer() } }; -void LLVertexBuffer::placeFence() const -{ - /*if (!mFence && useVBOs()) - { - mFence = new LLGLSyncFence(); - } - - if (mFence) - { - mFence->placeFence(); - }*/ -} - -void LLVertexBuffer::waitFence() const -{ - /*if (mFence) - { - mFence->wait(); - }*/ -} - //---------------------------------------------------------------------------- void LLVertexBuffer::genBuffer(U32 size) @@ -1239,144 +1152,11 @@ bool LLVertexBuffer::allocateBuffer(S32 nverts, S32 nindices, bool create) { //actually allocate space for the vertex buffer if using VBO mapping flush(); //unmap - - if (useVBOs() && sUseVAO) - { - mGLArray = getVAOName(); - setupVertexArray(); - } } return success; } -void LLVertexBuffer::setupVertexArray() -{ - if (!mGLArray) - { - return; - } - - LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; - glBindVertexArray(mGLArray); - sGLRenderArray = mGLArray; - - static const U32 attrib_size[] = - { - 3, //TYPE_VERTEX, - 3, //TYPE_NORMAL, - 2, //TYPE_TEXCOORD0, - 2, //TYPE_TEXCOORD1, - 2, //TYPE_TEXCOORD2, - 2, //TYPE_TEXCOORD3, - 4, //TYPE_COLOR, - 4, //TYPE_EMISSIVE, - 4, //TYPE_TANGENT, - 1, //TYPE_WEIGHT, - 4, //TYPE_WEIGHT4, - 4, //TYPE_CLOTHWEIGHT, - 1, //TYPE_TEXTURE_INDEX - }; - - static const U32 attrib_type[] = - { - GL_FLOAT, //TYPE_VERTEX, - GL_FLOAT, //TYPE_NORMAL, - GL_FLOAT, //TYPE_TEXCOORD0, - GL_FLOAT, //TYPE_TEXCOORD1, - GL_FLOAT, //TYPE_TEXCOORD2, - GL_FLOAT, //TYPE_TEXCOORD3, - GL_UNSIGNED_BYTE, //TYPE_COLOR, - GL_UNSIGNED_BYTE, //TYPE_EMISSIVE, - GL_FLOAT, //TYPE_TANGENT, - GL_FLOAT, //TYPE_WEIGHT, - GL_FLOAT, //TYPE_WEIGHT4, - GL_FLOAT, //TYPE_CLOTHWEIGHT, - GL_UNSIGNED_INT, //TYPE_TEXTURE_INDEX - }; - - static const bool attrib_integer[] = - { - false, //TYPE_VERTEX, - false, //TYPE_NORMAL, - false, //TYPE_TEXCOORD0, - false, //TYPE_TEXCOORD1, - false, //TYPE_TEXCOORD2, - false, //TYPE_TEXCOORD3, - false, //TYPE_COLOR, - false, //TYPE_EMISSIVE, - false, //TYPE_TANGENT, - false, //TYPE_WEIGHT, - false, //TYPE_WEIGHT4, - false, //TYPE_CLOTHWEIGHT, - true, //TYPE_TEXTURE_INDEX - }; - - static const U32 attrib_normalized[] = - { - GL_FALSE, //TYPE_VERTEX, - GL_FALSE, //TYPE_NORMAL, - GL_FALSE, //TYPE_TEXCOORD0, - GL_FALSE, //TYPE_TEXCOORD1, - GL_FALSE, //TYPE_TEXCOORD2, - GL_FALSE, //TYPE_TEXCOORD3, - GL_TRUE, //TYPE_COLOR, - GL_TRUE, //TYPE_EMISSIVE, - GL_FALSE, //TYPE_TANGENT, - GL_FALSE, //TYPE_WEIGHT, - GL_FALSE, //TYPE_WEIGHT4, - GL_FALSE, //TYPE_CLOTHWEIGHT, - GL_FALSE, //TYPE_TEXTURE_INDEX - }; - - bindGLBuffer(true); - bindGLIndices(true); - - for (U32 i = 0; i < TYPE_MAX; ++i) - { - if (mTypeMask & (1 << i)) - { - glEnableVertexAttribArray(i); - - if (attrib_integer[i]) - { - //glVertexattribIPointer requires GLSL 1.30 or later - if (gGLManager.mGLSLVersionMajor > 1 || gGLManager.mGLSLVersionMinor >= 30) - { - // nat 2018-10-24: VS 2017 also notices the issue - // described below, and warns even with reinterpret_cast. - // Cast via intptr_t to make it painfully obvious to the - // compiler that we're doing this intentionally. - glVertexAttribIPointer(i, attrib_size[i], attrib_type[i], sTypeSize[i], - reinterpret_cast(intptr_t(mOffsets[i]))); - } - } - else - { - // nat 2016-12-16: With 64-bit clang compile, the compiler - // produces an error if we simply cast mOffsets[i] -- an S32 - // -- to (GLvoid *), the type of the parameter. It correctly - // points out that there's no way an S32 could fit a real - // pointer value. Ruslan asserts that in this case the last - // param is interpreted as an array data offset within the VBO - // rather than as an actual pointer, so it's okay. - glVertexAttribPointer(i, attrib_size[i], attrib_type[i], - attrib_normalized[i], sTypeSize[i], - reinterpret_cast(intptr_t(mOffsets[i]))); - } - } - else - { - glDisableVertexAttribArray(i); - } - } - - //draw a dummy triangle to set index array pointer - //glDrawElements(GL_TRIANGLES, 0, GL_UNSIGNED_SHORT, NULL); - - unbind(); -} - bool LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) { llassert(newnverts >= 0); @@ -1390,11 +1170,6 @@ bool LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) if (useVBOs()) { flush(); //unmap - - if (mGLArray) - { //if size changed, offsets changed - setupVertexArray(); - } } return success; @@ -1443,34 +1218,31 @@ U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_ran if (useVBOs()) { - if (!mMappable) + if (count == -1) { - if (count == -1) - { - count = mNumVerts-index; - } + count = mNumVerts-index; + } - bool mapped = false; - //see if range is already mapped - for (U32 i = 0; i < mMappedVertexRegions.size(); ++i) + bool mapped = false; + //see if range is already mapped + for (U32 i = 0; i < mMappedVertexRegions.size(); ++i) + { + MappedRegion& region = mMappedVertexRegions[i]; + if (region.mType == type) { - MappedRegion& region = mMappedVertexRegions[i]; - if (region.mType == type) + if (expand_region(region, index, count)) { - if (expand_region(region, index, count)) - { - mapped = true; - break; - } + mapped = true; + break; } } + } - if (!mapped) - { - //not already mapped, map new region - MappedRegion region(type, mMappable && map_range ? -1 : index, count); - mMappedVertexRegions.push_back(region); - } + if (!mapped) + { + //not already mapped, map new region + MappedRegion region(type, index, count); + mMappedVertexRegions.push_back(region); } if (mVertexLocked && map_range) @@ -1484,48 +1256,7 @@ U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_ran sMappedCount++; stop_glerror(); - if(!mMappable) - { - map_range = false; - } - else - { - U8* src = NULL; - waitFence(); - if (map_range) - { - S32 offset = mOffsets[type] + sTypeSize[type]*index; - S32 length = (sTypeSize[type]*count+0xF) & ~0xF; - src = (U8*) glMapBufferRange(GL_ARRAY_BUFFER, offset, length, - GL_MAP_WRITE_BIT | - GL_MAP_FLUSH_EXPLICIT_BIT | - GL_MAP_INVALIDATE_RANGE_BIT); - } - else - { - if (gDebugGL) - { - GLint size = 0; - glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); - - if (size < mSize) - { - LL_ERRS() << "Invalid buffer size." << LL_ENDL; - } - } - - src = (U8*) glMapBufferRange(GL_ARRAY_BUFFER, 0, mSize, - GL_MAP_WRITE_BIT | - GL_MAP_FLUSH_EXPLICIT_BIT); - } - - llassert(src != NULL); - - mMappedData = LL_NEXT_ALIGNED_ADDRESS(src); - mAlignedOffset = mMappedData - src; - - stop_glerror(); - } + map_range = false; if (!mMappedData) { @@ -1533,31 +1264,9 @@ U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_ran //check the availability of memory LLMemory::logMemoryInfo(true); - - if(mMappable) - { - //-------------------- - //print out more debug info before crash - LL_INFOS() << "vertex buffer size: (num verts : num indices) = " << getNumVerts() << " : " << getNumIndices() << LL_ENDL; - GLint size; - glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); - LL_INFOS() << "GL_ARRAY_BUFFER size is " << size << LL_ENDL; - //-------------------- - - GLint buff; - glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &buff); - if ((GLuint)buff != mGLBuffer) - { - LL_ERRS() << "Invalid GL vertex buffer bound: " << buff << LL_ENDL; - } + + LL_ERRS() << "memory allocation for vertex data failed." << LL_ENDL; - - LL_ERRS() << "glMapBuffer returned NULL (no vertex data)" << LL_ENDL; - } - else - { - LL_ERRS() << "memory allocation for vertex data failed." << LL_ENDL; - } } } } @@ -1566,14 +1275,7 @@ U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_ran map_range = false; } - if (map_range && mMappable) - { - return mMappedData; - } - else - { - return mMappedData+mOffsets[type]+sTypeSize[type]*index; - } + return mMappedData+mOffsets[type]+sTypeSize[type]*index; } @@ -1592,32 +1294,30 @@ U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range) if (useVBOs()) { - if (!mMappable) + if (count == -1) { - if (count == -1) - { - count = mNumIndices-index; - } + count = mNumIndices-index; + } - bool mapped = false; - //see if range is already mapped - for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) + bool mapped = false; + //see if range is already mapped + for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) + { + MappedRegion& region = mMappedIndexRegions[i]; + if (expand_region(region, index, count)) { - MappedRegion& region = mMappedIndexRegions[i]; - if (expand_region(region, index, count)) - { - mapped = true; - break; - } + mapped = true; + break; } + } - if (!mapped) - { - //not already mapped, map new region - MappedRegion region(TYPE_INDEX, mMappable && map_range ? -1 : index, count); - mMappedIndexRegions.push_back(region); - } + if (!mapped) + { + //not already mapped, map new region + MappedRegion region(TYPE_INDEX, index, count); + mMappedIndexRegions.push_back(region); } + if (mIndexLocked && map_range) { @@ -1641,36 +1341,7 @@ U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range) } } - if(!mMappable) - { - map_range = false; - } - else - { - U8* src = NULL; - waitFence(); - if (map_range) - { - S32 offset = sizeof(U16)*index; - S32 length = sizeof(U16)*count; - src = (U8*) glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, offset, length, - GL_MAP_WRITE_BIT | - GL_MAP_FLUSH_EXPLICIT_BIT | - GL_MAP_INVALIDATE_RANGE_BIT); - } - else - { - src = (U8*) glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(U16)*mNumIndices, - GL_MAP_WRITE_BIT | - GL_MAP_FLUSH_EXPLICIT_BIT); - } - - llassert(src != NULL); - - mMappedIndexData = src; //LL_NEXT_ALIGNED_ADDRESS(src); - mAlignedIndexOffset = mMappedIndexData - src; - stop_glerror(); - } + map_range = false; } if (!mMappedIndexData) @@ -1678,21 +1349,7 @@ U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range) log_glerror(); LLMemory::logMemoryInfo(true); - if(mMappable) - { - GLint buff; - glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &buff); - if ((GLuint)buff != mGLIndices) - { - LL_ERRS() << "Invalid GL index buffer bound: " << buff << LL_ENDL; - } - - LL_ERRS() << "glMapBuffer returned NULL (no index data)" << LL_ENDL; - } - else - { - LL_ERRS() << "memory allocation for Index data failed. " << LL_ENDL; - } + LL_ERRS() << "memory allocation for Index data failed. " << LL_ENDL; } } else @@ -1700,14 +1357,7 @@ U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range) map_range = false; } - if (map_range && mMappable) - { - return mMappedIndexData; - } - else - { - return mMappedIndexData + sizeof(U16)*index; - } + return mMappedIndexData + sizeof(U16)*index; } void LLVertexBuffer::unmapBuffer() @@ -1725,66 +1375,41 @@ void LLVertexBuffer::unmapBuffer() bindGLBuffer(true); updated_all = mIndexLocked; //both vertex and index buffers done updating - if(!mMappable) + if (!mMappedVertexRegions.empty()) { - if (!mMappedVertexRegions.empty()) + stop_glerror(); + for (U32 i = 0; i < mMappedVertexRegions.size(); ++i) { - stop_glerror(); - for (U32 i = 0; i < mMappedVertexRegions.size(); ++i) + const MappedRegion& region = mMappedVertexRegions[i]; + S32 offset = region.mIndex >= 0 ? mOffsets[region.mType]+sTypeSize[region.mType]*region.mIndex : 0; + S32 length = sTypeSize[region.mType]*region.mCount; + if (mSize >= length + offset) { - const MappedRegion& region = mMappedVertexRegions[i]; - S32 offset = region.mIndex >= 0 ? mOffsets[region.mType]+sTypeSize[region.mType]*region.mIndex : 0; - S32 length = sTypeSize[region.mType]*region.mCount; - if (mSize >= length + offset) - { - glBufferSubData(GL_ARRAY_BUFFER, offset, length, (U8*)mMappedData + offset); - } - else - { - GLint size = 0; - glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); - LL_WARNS() << "Attempted to map regions to a buffer that is too small, " - << "mapped size: " << mSize - << ", gl buffer size: " << size - << ", length: " << length - << ", offset: " << offset - << LL_ENDL; - } - stop_glerror(); + glBufferSubData(GL_ARRAY_BUFFER, offset, length, (U8*)mMappedData + offset); + } + else + { + GLint size = 0; + glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); + LL_WARNS() << "Attempted to map regions to a buffer that is too small, " + << "mapped size: " << mSize + << ", gl buffer size: " << size + << ", length: " << length + << ", offset: " << offset + << LL_ENDL; } - - mMappedVertexRegions.clear(); - } - else - { - stop_glerror(); - glBufferSubData(GL_ARRAY_BUFFER, 0, getSize(), (U8*) mMappedData); stop_glerror(); } + + mMappedVertexRegions.clear(); } else { - if (!mMappedVertexRegions.empty()) - { - LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("unmapBuffer - flush vertex"); - for (U32 i = 0; i < mMappedVertexRegions.size(); ++i) - { - const MappedRegion& region = mMappedVertexRegions[i]; - S32 offset = region.mIndex >= 0 ? mOffsets[region.mType]+sTypeSize[region.mType]*region.mIndex : 0; - S32 length = sTypeSize[region.mType]*region.mCount; - glFlushMappedBufferRange(GL_ARRAY_BUFFER, offset, length); - } - - mMappedVertexRegions.clear(); - } - stop_glerror(); - glUnmapBuffer(GL_ARRAY_BUFFER); + glBufferSubData(GL_ARRAY_BUFFER, 0, getSize(), (U8*) mMappedData); stop_glerror(); - - mMappedData = NULL; } - + mVertexLocked = false; sMappedCount--; } @@ -1793,64 +1418,41 @@ void LLVertexBuffer::unmapBuffer() { LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("unmapBuffer - index"); bindGLIndices(); - if(!mMappable) + + if (!mMappedIndexRegions.empty()) { - if (!mMappedIndexRegions.empty()) + for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) { - for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) + const MappedRegion& region = mMappedIndexRegions[i]; + S32 offset = region.mIndex >= 0 ? sizeof(U16)*region.mIndex : 0; + S32 length = sizeof(U16)*region.mCount; + if (mIndicesSize >= length + offset) { - const MappedRegion& region = mMappedIndexRegions[i]; - S32 offset = region.mIndex >= 0 ? sizeof(U16)*region.mIndex : 0; - S32 length = sizeof(U16)*region.mCount; - if (mIndicesSize >= length + offset) - { - glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, length, (U8*) mMappedIndexData+offset); - } - else - { - GLint size = 0; - glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); - LL_WARNS() << "Attempted to map regions to a buffer that is too small, " - << "mapped size: " << mIndicesSize - << ", gl buffer size: " << size - << ", length: " << length - << ", offset: " << offset - << LL_ENDL; - } - stop_glerror(); + glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, length, (U8*) mMappedIndexData+offset); + } + else + { + GLint size = 0; + glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); + LL_WARNS() << "Attempted to map regions to a buffer that is too small, " + << "mapped size: " << mIndicesSize + << ", gl buffer size: " << size + << ", length: " << length + << ", offset: " << offset + << LL_ENDL; } - - mMappedIndexRegions.clear(); - } - else - { - stop_glerror(); - glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, getIndicesSize(), (U8*) mMappedIndexData); stop_glerror(); } + + mMappedIndexRegions.clear(); } else { - if (!mMappedIndexRegions.empty()) - { - for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) - { - LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("unmapBuffer - flush index"); - const MappedRegion& region = mMappedIndexRegions[i]; - S32 offset = region.mIndex >= 0 ? sizeof(U16)*region.mIndex : 0; - S32 length = sizeof(U16)*region.mCount; - glFlushMappedBufferRange(GL_ELEMENT_ARRAY_BUFFER, offset, length); - stop_glerror(); - } - - mMappedIndexRegions.clear(); - } - - glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER); - - mMappedIndexData = NULL; + stop_glerror(); + glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, getIndicesSize(), (U8*) mMappedIndexData); + stop_glerror(); } - + mIndexLocked = false; sMappedCount--; } @@ -1969,30 +1571,8 @@ bool LLVertexBuffer::getClothWeightStrider(LLStrider& strider, S32 in //---------------------------------------------------------------------------- -bool LLVertexBuffer::bindGLArray() -{ - if (mGLArray && sGLRenderArray != mGLArray) - { - { - LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; - glBindVertexArray(mGLArray); - sGLRenderArray = mGLArray; - } - - //really shouldn't be necessary, but some drivers don't properly restore the - //state of GL_ELEMENT_ARRAY_BUFFER_BINDING - bindGLIndices(); - - return true; - } - - return false; -} - bool LLVertexBuffer::bindGLBuffer(bool force_bind) { - bindGLArray(); - bool ret = false; if (useVBOs() && (force_bind || (mGLBuffer && (mGLBuffer != sGLRenderBuffer || !sVBOActive)))) @@ -2002,9 +1582,6 @@ bool LLVertexBuffer::bindGLBuffer(bool force_bind) sGLRenderBuffer = mGLBuffer; sBindCount++; sVBOActive = true; - - llassert(!mGLArray || sGLRenderArray == mGLArray); - ret = true; } @@ -2029,9 +1606,8 @@ bool LLVertexBuffer::bindGLBufferFast() bool LLVertexBuffer::bindGLIndices(bool force_bind) { LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; - bindGLArray(); - bool ret = false; + bool ret = false; if (useVBOs() && (force_bind || (mGLIndices && (mGLIndices != sGLRenderIndices || !sIBOActive)))) { /*if (sMapped) @@ -2151,20 +1727,12 @@ void LLVertexBuffer::setBuffer(U32 data_mask) if (useVBOs()) { - if (mGLArray) - { - bindGLArray(); - setup = false; //do NOT perform pointer setup if using VAO - } - else - { - const bool bindBuffer = bindGLBuffer(); - const bool bindIndices = bindGLIndices(); + const bool bindBuffer = bindGLBuffer(); + const bool bindIndices = bindGLIndices(); - setup = setup || bindBuffer || bindIndices; - } + setup = setup || bindBuffer || bindIndices; - if (gDebugGL && !mGLArray) + if (gDebugGL) { GLint buff; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &buff); @@ -2237,11 +1805,8 @@ void LLVertexBuffer::setBuffer(U32 data_mask) } } - if (!mGLArray) - { - setupClientArrays(data_mask); - } - + setupClientArrays(data_mask); + if (mGLBuffer) { if (data_mask && setup) @@ -2284,7 +1849,7 @@ void LLVertexBuffer::setBufferFast(U32 data_mask) void LLVertexBuffer::setupVertexBuffer(U32 data_mask) { stop_glerror(); - U8* base = useVBOs() ? (U8*) mAlignedOffset : mMappedData; + U8* base = useVBOs() ? nullptr: mMappedData; if (gDebugGL && ((data_mask & mTypeMask) != data_mask)) { @@ -2390,8 +1955,8 @@ void LLVertexBuffer::setupVertexBuffer(U32 data_mask) } void LLVertexBuffer::setupVertexBufferFast(U32 data_mask) - { - U8* base = (U8*)mAlignedOffset; +{ + U8* base = nullptr; if (data_mask & MAP_NORMAL) { -- cgit v1.2.3 From fdc0ea64f050ad09a84442f40396bb9e6497ce52 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 10 Jan 2023 17:36:05 -0600 Subject: SL-18869 Optimizations -- LLVertexBuffer overhaul and shuffle of shadow map rendering to a place where the main camera has taken a stab at object updates for this frame before shadow map rendering has at them. --- indra/llrender/llvertexbuffer.cpp | 825 +++++++++++++++++++------------------- 1 file changed, 423 insertions(+), 402 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 7b8f85acba..20261dcb8a 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -62,6 +62,14 @@ U32 wpo2(U32 i) return r; } +struct CompareMappedRegion +{ + bool operator()(const LLVertexBuffer::MappedRegion& lhs, const LLVertexBuffer::MappedRegion& rhs) + { + return lhs.mStart < rhs.mStart; + } +}; + const U32 LL_VBO_BLOCK_SIZE = 2048; const U32 LL_VBO_POOL_MAX_SEED_SIZE = 256*1024; @@ -81,266 +89,217 @@ U32 vbo_block_index(U32 size) const U32 LL_VBO_POOL_SEED_COUNT = vbo_block_index(LL_VBO_POOL_MAX_SEED_SIZE) + 1; +#define ENABLE_GL_WORK_QUEUE 0 + +#if ENABLE_GL_WORK_QUEUE + +#define THREAD_COUNT 1 //============================================================================ -//static -LLVBOPool LLVertexBuffer::sStreamVBOPool(GL_STREAM_DRAW, GL_ARRAY_BUFFER); -LLVBOPool LLVertexBuffer::sDynamicVBOPool(GL_DYNAMIC_DRAW, GL_ARRAY_BUFFER); -LLVBOPool LLVertexBuffer::sDynamicCopyVBOPool(GL_DYNAMIC_COPY, GL_ARRAY_BUFFER); -LLVBOPool LLVertexBuffer::sStreamIBOPool(GL_STREAM_DRAW, GL_ELEMENT_ARRAY_BUFFER); -LLVBOPool LLVertexBuffer::sDynamicIBOPool(GL_DYNAMIC_DRAW, GL_ELEMENT_ARRAY_BUFFER); +// High performance WorkQueue for usage in real-time rendering work +class GLWorkQueue +{ +public: + using Work = std::function; -U32 LLVBOPool::sBytesPooled = 0; -U32 LLVBOPool::sIndexBytesPooled = 0; -U32 LLVBOPool::sNameIdx = 0; -U32 LLVBOPool::sNamePool[1024]; + GLWorkQueue(); -std::list LLVertexBuffer::sAvailableVAOName; -U32 LLVertexBuffer::sCurVAOName = 1; + void post(const Work& value); -U32 LLVertexBuffer::sAllocatedIndexBytes = 0; -U32 LLVertexBuffer::sIndexCount = 0; + size_t size(); -U32 LLVertexBuffer::sBindCount = 0; -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::sGLRenderArray = 0; -U32 LLVertexBuffer::sGLRenderIndices = 0; -U32 LLVertexBuffer::sLastMask = 0; -bool LLVertexBuffer::sVBOActive = false; -bool LLVertexBuffer::sIBOActive = false; -U32 LLVertexBuffer::sAllocatedBytes = 0; -U32 LLVertexBuffer::sVertexCount = 0; -bool LLVertexBuffer::sMapped = false; -bool LLVertexBuffer::sUseStreamDraw = true; -bool LLVertexBuffer::sUseVAO = false; -bool LLVertexBuffer::sPreferStreamDraw = false; + bool done(); -U32 LLVBOPool::genBuffer() -{ - LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX + // Get the next element from the queue + Work pop(); - if (sNameIdx == 0) - { - glGenBuffers(1024, sNamePool); - sNameIdx = 1024; - } + void runOne(); - return sNamePool[--sNameIdx]; -} + bool runPending(); -void LLVBOPool::deleteBuffer(U32 name) -{ - LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX - if (gGLManager.mInited) - { - LLVertexBuffer::unbind(); + void runUntilClose(); - glBindBuffer(mType, name); - glBufferData(mType, 0, NULL, mUsage); - glBindBuffer(mType, 0); + void close(); - glDeleteBuffers(1, &name); - } -} + bool isClosed(); + void syncGL(); -LLVBOPool::LLVBOPool(U32 vboUsage, U32 vboType) -: mUsage(vboUsage), mType(vboType), mMissCountDirty(true) -{ - mFreeList.resize(LL_VBO_POOL_SEED_COUNT); - mMissCount.resize(LL_VBO_POOL_SEED_COUNT); - std::fill(mMissCount.begin(), mMissCount.end(), 0); -} +private: + std::mutex mMutex; + std::condition_variable mCondition; + std::queue mQueue; + bool mClosed = false; +}; -U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) +GLWorkQueue::GLWorkQueue() { - LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX - llassert(vbo_block_size(size) == size); - - U8* ret = NULL; - U32 i = vbo_block_index(size); +} - if (mFreeList.size() <= i) - { - mFreeList.resize(i+1); - } +void GLWorkQueue::syncGL() +{ + /*if (mSync) + { + std::lock_guard lock(mMutex); + glWaitSync(mSync, 0, GL_TIMEOUT_IGNORED); + mSync = 0; + }*/ +} - if (mFreeList[i].empty() || for_seed) - { - //make a new buffer - name = genBuffer(); +size_t GLWorkQueue::size() +{ + LL_PROFILE_ZONE_SCOPED_CATEGORY_THREAD; + std::lock_guard lock(mMutex); + return mQueue.size(); +} - glBindBuffer(mType, name); +bool GLWorkQueue::done() +{ + return size() == 0 && isClosed(); +} - if (!for_seed && i < LL_VBO_POOL_SEED_COUNT) - { //record this miss - mMissCount[i]++; - mMissCountDirty = true; // signal to ::seedPool() - } +void GLWorkQueue::post(const GLWorkQueue::Work& value) +{ + LL_PROFILE_ZONE_SCOPED_CATEGORY_THREAD; + { + std::lock_guard lock(mMutex); + mQueue.push(std::move(value)); + } - if (mType == GL_ARRAY_BUFFER) - { - LLVertexBuffer::sAllocatedBytes += size; - } - else - { - LLVertexBuffer::sAllocatedIndexBytes += size; - } + mCondition.notify_one(); +} - if (LLVertexBuffer::sDisableVBOMapping || mUsage != GL_DYNAMIC_DRAW) - { - glBufferData(mType, size, 0, mUsage); - if (mUsage != GL_DYNAMIC_COPY) - { //data will be provided by application - ret = (U8*) ll_aligned_malloc<64>(size); - if (!ret) - { - LL_ERRS() - << "Failed to allocate " << size << " bytes for LLVBOPool buffer " << name << "." << LL_NEWLINE - << "Free list size: " - << mFreeList.size() // this happens if we are out of memory so a solution might be to clear some from freelist - << " Allocated Bytes: " << LLVertexBuffer::sAllocatedBytes - << " Allocated Index Bytes: " << LLVertexBuffer::sAllocatedIndexBytes << " Pooled Bytes: " << sBytesPooled - << " Pooled Index Bytes: " << sIndexBytesPooled << LL_ENDL; - } - } - } - else - { //always use a true hint of static draw when allocating non-client-backed buffers - glBufferData(mType, size, 0, GL_STATIC_DRAW); - } +// Get the next element from the queue +GLWorkQueue::Work GLWorkQueue::pop() +{ + LL_PROFILE_ZONE_SCOPED_CATEGORY_THREAD; + // Lock the mutex + { + std::unique_lock lock(mMutex); - glBindBuffer(mType, 0); + // Wait for a new element to become available or for the queue to close + { + mCondition.wait(lock, [=] { return !mQueue.empty() || mClosed; }); + } + } - if (for_seed) - { //put into pool for future use - llassert(mFreeList.size() > i); + Work ret; - Record rec; - rec.mGLName = name; - rec.mClientData = ret; - - if (mType == GL_ARRAY_BUFFER) - { - sBytesPooled += size; - } - else - { - sIndexBytesPooled += size; - } - mFreeList[i].push_back(rec); - mMissCountDirty = true; // signal to ::seedPool() - } - } - else - { - name = mFreeList[i].front().mGLName; - ret = mFreeList[i].front().mClientData; + { + std::lock_guard lock(mMutex); - if (mType == GL_ARRAY_BUFFER) - { - sBytesPooled -= size; - } - else - { - sIndexBytesPooled -= size; - } + // Get the next element from the queue + if (mQueue.size() > 0) + { + ret = mQueue.front(); + mQueue.pop(); + } + else + { + ret = []() {}; + } + } - mFreeList[i].pop_front(); - mMissCountDirty = true; // signal to ::seedPool() - } + return ret; +} - return ret; +void GLWorkQueue::runOne() +{ + LL_PROFILE_ZONE_SCOPED_CATEGORY_THREAD; + Work w = pop(); + w(); + //mSync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); } -void LLVBOPool::release(U32 name, U8* buffer, U32 size) +void GLWorkQueue::runUntilClose() { - llassert(vbo_block_size(size) == size); + while (!isClosed()) + { + runOne(); + } +} - deleteBuffer(name); - ll_aligned_free_fallback((U8*) buffer); +void GLWorkQueue::close() +{ + LL_PROFILE_ZONE_SCOPED_CATEGORY_THREAD; + { + std::lock_guard lock(mMutex); + mClosed = true; + } - if (mType == GL_ARRAY_BUFFER) - { - LLVertexBuffer::sAllocatedBytes -= size; - } - else - { - LLVertexBuffer::sAllocatedIndexBytes -= size; - } + mCondition.notify_all(); } -void LLVBOPool::seedPool() +bool GLWorkQueue::isClosed() { - LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX - if (mMissCountDirty) - { - U32 dummy_name = 0; - U32 size = LL_VBO_BLOCK_SIZE; - - for (U32 i = 0; i < LL_VBO_POOL_SEED_COUNT; i++) - { - if (mMissCount[i] > mFreeList[i].size()) - { - S32 count = mMissCount[i] - mFreeList[i].size(); - for (U32 j = 0; j < count; ++j) - { - allocate(dummy_name, size, true); - } - } - size += LL_VBO_BLOCK_SIZE; - } - mMissCountDirty = false; - } + LL_PROFILE_ZONE_SCOPED_CATEGORY_THREAD; + std::lock_guard lock(mMutex); + return mClosed; } -void LLVBOPool::cleanup() +#include "llwindow.h" + +class LLGLWorkerThread : public LLThread { - U32 size = LL_VBO_BLOCK_SIZE; +public: + LLGLWorkerThread(const std::string& name, GLWorkQueue* queue, LLWindow* window) + : LLThread(name) + { + mWindow = window; + mContext = mWindow->createSharedContext(); + mQueue = queue; + } - for (U32 i = 0; i < mFreeList.size(); ++i) - { - record_list_t& l = mFreeList[i]; + void run() override + { + mWindow->makeContextCurrent(mContext); + gGL.init(false); + mQueue->runUntilClose(); + gGL.shutdown(); + mWindow->destroySharedContext(mContext); + } - while (!l.empty()) - { - Record& r = l.front(); + GLWorkQueue* mQueue; + LLWindow* mWindow; + void* mContext = nullptr; +}; - deleteBuffer(r.mGLName); - - if (r.mClientData) - { - ll_aligned_free<64>((void*) r.mClientData); - } - l.pop_front(); +static LLGLWorkerThread* sVBOThread[THREAD_COUNT]; +static GLWorkQueue* sQueue = nullptr; - if (mType == GL_ARRAY_BUFFER) - { - sBytesPooled -= size; - LLVertexBuffer::sAllocatedBytes -= size; - } - else - { - sIndexBytesPooled -= size; - LLVertexBuffer::sAllocatedIndexBytes -= size; - } - } +#endif - size += LL_VBO_BLOCK_SIZE; - } +//============================================================================ - //reset miss counts - std::fill(mMissCount.begin(), mMissCount.end(), 0); -} +//static +std::list LLVertexBuffer::sAvailableVAOName; +U32 LLVertexBuffer::sCurVAOName = 1; + +U32 LLVertexBuffer::sAllocatedIndexBytes = 0; +U32 LLVertexBuffer::sIndexCount = 0; + +U32 LLVertexBuffer::sBindCount = 0; +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::sGLRenderArray = 0; +U32 LLVertexBuffer::sGLRenderIndices = 0; +U32 LLVertexBuffer::sLastMask = 0; +bool LLVertexBuffer::sVBOActive = false; +bool LLVertexBuffer::sIBOActive = false; +U32 LLVertexBuffer::sAllocatedBytes = 0; +U32 LLVertexBuffer::sVertexCount = 0; +bool LLVertexBuffer::sMapped = false; +bool LLVertexBuffer::sUseStreamDraw = true; +bool LLVertexBuffer::sUseVAO = false; +bool LLVertexBuffer::sPreferStreamDraw = false; //NOTE: each component must be AT LEAST 4 bytes in size to avoid a performance penalty on AMD hardware @@ -419,17 +378,6 @@ void LLVertexBuffer::releaseVAOName(U32 name) } -//static -void LLVertexBuffer::seedPools() -{ - LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX - sStreamVBOPool.seedPool(); - sDynamicVBOPool.seedPool(); - sDynamicCopyVBOPool.seedPool(); - sStreamIBOPool.seedPool(); - sDynamicIBOPool.seedPool(); -} - //static void LLVertexBuffer::setupClientArrays(U32 data_mask) { @@ -473,7 +421,7 @@ void LLVertexBuffer::drawArrays(U32 mode, const std::vector& pos) } gGL.end(); gGL.flush(); - } +} //static void LLVertexBuffer::drawElements(U32 mode, const LLVector4a* pos, const LLVector2* tc, S32 num_indices, const U16* indicesp) @@ -704,10 +652,20 @@ void LLVertexBuffer::drawArrays(U32 mode, U32 first, U32 count) const } //static -void LLVertexBuffer::initClass(bool use_vbo, bool no_vbo_mapping) +void LLVertexBuffer::initClass(LLWindow* window) { - sEnableVBOs = use_vbo; - sDisableVBOMapping = sEnableVBOs && no_vbo_mapping; + sEnableVBOs = true; + sDisableVBOMapping = true; + +#if ENABLE_GL_WORK_QUEUE + sQueue = new GLWorkQueue(); + + for (int i = 0; i < THREAD_COUNT; ++i) + { + sVBOThread[i] = new LLGLWorkerThread("VBO Worker", sQueue, window); + sVBOThread[i]->start(); + } +#endif } //static @@ -743,14 +701,19 @@ void LLVertexBuffer::cleanupClass() { unbind(); - sStreamIBOPool.cleanup(); - sDynamicIBOPool.cleanup(); - sStreamVBOPool.cleanup(); - sDynamicVBOPool.cleanup(); - sDynamicCopyVBOPool.cleanup(); - - llassert(0 == LLVBOPool::sBytesPooled); - llassert(0 == LLVBOPool::sIndexBytesPooled); +#if ENABLE_GL_WORK_QUEUE + sQueue->close(); + for (int i = 0; i < THREAD_COUNT; ++i) + { + sVBOThread[i]->shutdown(); + delete sVBOThread[i]; + sVBOThread[i] = nullptr; + } + + delete sQueue; + sQueue = nullptr; +#endif + //llassert(0 == sAllocatedBytes); //llassert(0 == sAllocatedIndexBytes); } @@ -781,21 +744,6 @@ S32 LLVertexBuffer::determineUsage(S32 usage) ret_usage = GL_STREAM_DRAW; } - if (ret_usage && ret_usage != GL_STREAM_DRAW) - { //only stream_draw and dynamic_draw are supported when using VBOs, dynamic draw is the default - if (ret_usage != GL_DYNAMIC_COPY) - { - if (sDisableVBOMapping) - { //always use stream draw if VBO mapping is disabled - ret_usage = GL_STREAM_DRAW; - } - else - { - ret_usage = GL_DYNAMIC_DRAW; - } - } - } - return ret_usage; } @@ -848,7 +796,7 @@ S32 LLVertexBuffer::calcOffsets(const U32& typemask, S32* offsets, S32 num_verti offsets[TYPE_TEXTURE_INDEX] = offsets[TYPE_VERTEX] + 12; - return offset+16; + return offset; } //static @@ -896,74 +844,101 @@ LLVertexBuffer::~LLVertexBuffer() //---------------------------------------------------------------------------- +// batch glGenBuffers +static GLuint gen_buffer() +{ + LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; + constexpr U32 pool_size = 4096; + + thread_local static GLuint sNamePool[pool_size]; + thread_local static U32 sIndex = 0; + + if (sIndex == 0) + { + LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("gen ibo"); + sIndex = pool_size; + glGenBuffers(pool_size, sNamePool); + } + + return sNamePool[--sIndex]; +} + +// batch glDeleteBuffers +static void release_buffer(U32 buff) +{ + LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; +#if 0 + + constexpr U32 pool_size = 4096; + + thread_local static GLuint sNamePool[pool_size]; + thread_local static U32 sIndex = 0; + + if (sIndex == pool_size) + { + LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("gen ibo"); + sIndex = 0; + glDeleteBuffers(pool_size, sNamePool); + } + + sNamePool[sIndex++] = buff; +#else + glDeleteBuffers(1, &buff); +#endif +} + void LLVertexBuffer::genBuffer(U32 size) { - mSize = vbo_block_size(size); + LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; - if (mUsage == GL_STREAM_DRAW) - { - mMappedData = sStreamVBOPool.allocate(mGLBuffer, mSize); - } - else if (mUsage == GL_DYNAMIC_DRAW) - { - mMappedData = sDynamicVBOPool.allocate(mGLBuffer, mSize); - } - else - { - mMappedData = sDynamicCopyVBOPool.allocate(mGLBuffer, mSize); - } - - - sGLCount++; + mSize = size; + mMappedData = (U8*) ll_aligned_malloc_16(size); + mGLBuffer = gen_buffer(); + + glBindBuffer(GL_ARRAY_BUFFER, mGLBuffer); + glBufferData(GL_ARRAY_BUFFER, mSize, nullptr, mUsage); + glBindBuffer(GL_ARRAY_BUFFER, 0); + + sGLCount++; } void LLVertexBuffer::genIndices(U32 size) { - mIndicesSize = vbo_block_size(size); + LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; + + mIndicesSize = size; + mMappedIndexData = (U8*) ll_aligned_malloc_16(size); + + mGLIndices = gen_buffer(); + + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mGLIndices); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, mIndicesSize, nullptr, mUsage); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - if (mUsage == GL_STREAM_DRAW) - { - mMappedIndexData = sStreamIBOPool.allocate(mGLIndices, mIndicesSize); - } - else - { - mMappedIndexData = sDynamicIBOPool.allocate(mGLIndices, mIndicesSize); - } - sGLCount++; } void LLVertexBuffer::releaseBuffer() { - if (mUsage == GL_STREAM_DRAW) - { - sStreamVBOPool.release(mGLBuffer, mMappedData, mSize); - } - else - { - sDynamicVBOPool.release(mGLBuffer, mMappedData, mSize); - } - - mGLBuffer = 0; - mMappedData = NULL; + LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; + release_buffer(mGLBuffer); + mGLBuffer = 0; + ll_aligned_free_16(mMappedData); + mMappedData = nullptr; + sGLCount--; } void LLVertexBuffer::releaseIndices() { - if (mUsage == GL_STREAM_DRAW) - { - sStreamIBOPool.release(mGLIndices, mMappedIndexData, mIndicesSize); - } - else - { - sDynamicIBOPool.release(mGLIndices, mMappedIndexData, mIndicesSize); - } + LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; + release_buffer(mGLIndices); + mGLIndices = 0; + + ll_aligned_free_16(mMappedIndexData); + mMappedIndexData = nullptr; - mGLIndices = 0; - mMappedIndexData = NULL; - sGLCount--; } @@ -1183,21 +1158,20 @@ bool LLVertexBuffer::useVBOs() const //---------------------------------------------------------------------------- -bool expand_region(LLVertexBuffer::MappedRegion& region, S32 index, S32 count) +// if no gap between region and given range exists, expand region to cover given range and return true +// otherwise return false +bool expand_region(LLVertexBuffer::MappedRegion& region, S32 start, S32 end) { - S32 end = index+count; - S32 region_end = region.mIndex+region.mCount; - if (end < region.mIndex || - index > region_end) + if (end < region.mStart || + start > region.mEnd) { //gap exists, do not merge return false; } - S32 new_end = llmax(end, region_end); - S32 new_index = llmin(index, region.mIndex); - region.mIndex = new_index; - region.mCount = new_end-new_index; + region.mStart = llmin(region.mStart, start); + region.mEnd = llmax(region.mEnd, end); + return true; } @@ -1215,34 +1189,34 @@ U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_ran { LL_ERRS() << "LLVertexBuffer::mapVertexBuffer() called on unallocated buffer." << LL_ENDL; } - - if (useVBOs()) - { - if (count == -1) - { - count = mNumVerts-index; - } - bool mapped = false; - //see if range is already mapped + + if (useVBOs()) + { + if (count == -1) + { + count = mNumVerts - index; + } + + S32 start = mOffsets[type] + sTypeSize[type] * index; + S32 end = start + sTypeSize[type] * count; + + bool flagged = false; + // flag region as mapped for (U32 i = 0; i < mMappedVertexRegions.size(); ++i) { MappedRegion& region = mMappedVertexRegions[i]; - if (region.mType == type) - { - if (expand_region(region, index, count)) - { - mapped = true; - break; - } - } + if (expand_region(region, start, end)) + { + flagged = true; + break; + } } - if (!mapped) + if (!flagged) { - //not already mapped, map new region - MappedRegion region(type, index, count); - mMappedVertexRegions.push_back(region); + //didn't expand an existing region, make a new one + mMappedVertexRegions.push_back({ start, end }); } if (mVertexLocked && map_range) @@ -1299,25 +1273,26 @@ U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range) count = mNumIndices-index; } - bool mapped = false; - //see if range is already mapped - for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) - { - MappedRegion& region = mMappedIndexRegions[i]; - if (expand_region(region, index, count)) - { - mapped = true; - break; - } - } + S32 start = sizeof(U16) * index; + S32 end = start + sizeof(U16) * count; - if (!mapped) - { - //not already mapped, map new region - MappedRegion region(TYPE_INDEX, index, count); - mMappedIndexRegions.push_back(region); - } - + bool flagged = false; + // flag region as mapped + for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) + { + MappedRegion& region = mMappedIndexRegions[i]; + if (expand_region(region, start, end)) + { + flagged = true; + break; + } + } + + if (!flagged) + { + //didn't expand an existing region, make a new one + mMappedIndexRegions.push_back({ start, end }); + } if (mIndexLocked && map_range) { @@ -1360,6 +1335,27 @@ U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range) return mMappedIndexData + sizeof(U16)*index; } +static void flush_vbo(GLenum target, S32 start, S32 end, void* data) +{ + if (end != 0) + { + LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("glBufferSubData"); + LL_PROFILE_ZONE_NUM(start); + LL_PROFILE_ZONE_NUM(end); + LL_PROFILE_ZONE_NUM(end-start); + + constexpr S32 block_size = 65536; + + for (S32 i = start; i < end; i += block_size) + { + LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("glBufferSubData block"); + LL_PROFILE_GPU_ZONE("glBufferSubData"); + S32 tend = llmin(i + block_size, end); + glBufferSubData(target, i, tend - i, (U8*) data + (i-start)); + } + } +} + void LLVertexBuffer::unmapBuffer() { if (!useVBOs()) @@ -1377,37 +1373,31 @@ void LLVertexBuffer::unmapBuffer() if (!mMappedVertexRegions.empty()) { - stop_glerror(); + S32 start = 0; + S32 end = 0; + for (U32 i = 0; i < mMappedVertexRegions.size(); ++i) { const MappedRegion& region = mMappedVertexRegions[i]; - S32 offset = region.mIndex >= 0 ? mOffsets[region.mType]+sTypeSize[region.mType]*region.mIndex : 0; - S32 length = sTypeSize[region.mType]*region.mCount; - if (mSize >= length + offset) - { - glBufferSubData(GL_ARRAY_BUFFER, offset, length, (U8*)mMappedData + offset); - } - else - { - GLint size = 0; - glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); - LL_WARNS() << "Attempted to map regions to a buffer that is too small, " - << "mapped size: " << mSize - << ", gl buffer size: " << size - << ", length: " << length - << ", offset: " << offset - << LL_ENDL; - } - stop_glerror(); + if (region.mStart == end + 1) + { + end = region.mEnd; + } + else + { + flush_vbo(GL_ARRAY_BUFFER, start, end, (U8*)mMappedData + start); + start = region.mStart; + end = region.mEnd; + } } + flush_vbo(GL_ARRAY_BUFFER, start, end, (U8*)mMappedData + start); + mMappedVertexRegions.clear(); } else { - stop_glerror(); - glBufferSubData(GL_ARRAY_BUFFER, 0, getSize(), (U8*) mMappedData); - stop_glerror(); + llassert(false); // this shouldn't happen -- a buffer must always be explicitly mapped } mVertexLocked = false; @@ -1421,36 +1411,31 @@ void LLVertexBuffer::unmapBuffer() if (!mMappedIndexRegions.empty()) { - for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) - { - const MappedRegion& region = mMappedIndexRegions[i]; - S32 offset = region.mIndex >= 0 ? sizeof(U16)*region.mIndex : 0; - S32 length = sizeof(U16)*region.mCount; - if (mIndicesSize >= length + offset) - { - glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, length, (U8*) mMappedIndexData+offset); - } - else - { - GLint size = 0; - glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); - LL_WARNS() << "Attempted to map regions to a buffer that is too small, " - << "mapped size: " << mIndicesSize - << ", gl buffer size: " << size - << ", length: " << length - << ", offset: " << offset - << LL_ENDL; - } - stop_glerror(); - } + S32 start = 0; + S32 end = 0; + + for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) + { + const MappedRegion& region = mMappedIndexRegions[i]; + if (region.mStart == end + 1) + { + end = region.mEnd; + } + else + { + flush_vbo(GL_ELEMENT_ARRAY_BUFFER, start, end, (U8*)mMappedIndexData + start); + start = region.mStart; + end = region.mEnd; + } + } + + flush_vbo(GL_ELEMENT_ARRAY_BUFFER, start, end, (U8*)mMappedIndexData + start); mMappedIndexRegions.clear(); } else { - stop_glerror(); - glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, getIndicesSize(), (U8*) mMappedIndexData); - stop_glerror(); + llassert(false); // this shouldn't happen -- a buffer must always be explicitly mapped } mIndexLocked = false; @@ -1640,11 +1625,53 @@ bool LLVertexBuffer::bindGLIndicesFast() return false; } -void LLVertexBuffer::flush() +void LLVertexBuffer::flush(bool discard) { if (useVBOs()) { - unmapBuffer(); + if (discard) + { // discard existing VBO data if the buffer must be updated + + if (!mMappedVertexRegions.empty()) + { + LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("flush discard vbo"); + LL_PROFILE_ZONE_NUM(mSize); + release_buffer(mGLBuffer); + mGLBuffer = gen_buffer(); + bindGLBuffer(); + { + LL_PROFILE_GPU_ZONE("glBufferData"); + glBufferData(GL_ARRAY_BUFFER, mSize, nullptr, mUsage); + + for (int i = 0; i < mSize; i += 65536) + { + LL_PROFILE_GPU_ZONE("glBufferSubData"); + S32 end = llmin(i + 65536, mSize); + S32 count = end - i; + glBufferSubData(GL_ARRAY_BUFFER, i, count, mMappedData + i); + } + } + mMappedVertexRegions.clear(); + } + if (!mMappedIndexRegions.empty()) + { + LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("flush discard ibo"); + LL_PROFILE_ZONE_NUM(mIndicesSize); + release_buffer(mGLIndices); + mGLIndices = gen_buffer(); + bindGLIndices(); + { + LL_PROFILE_GPU_ZONE("glBufferData (ibo)"); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, mIndicesSize, mMappedIndexData, mUsage); + } + mMappedIndexRegions.clear(); + } + } + else + { + unmapBuffer(); + } + } } @@ -2045,10 +2072,4 @@ void LLVertexBuffer::setupVertexBufferFast(U32 data_mask) } } -LLVertexBuffer::MappedRegion::MappedRegion(S32 type, S32 index, S32 count) -: mType(type), mIndex(index), mCount(count) -{ - mEnd = mIndex+mCount; -} - -- cgit v1.2.3 From 68da705f3ba284928c7e23acd4164d56dea17af9 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 10 Jan 2023 18:42:09 -0600 Subject: SL-18869 Optimizations -- Quiet command buffer -- VBO cache for UI et al and remove many unneeded VBO binds. --- indra/llrender/llvertexbuffer.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 20261dcb8a..57be21cf6e 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -1180,7 +1180,6 @@ bool expand_region(LLVertexBuffer::MappedRegion& region, S32 start, S32 end) U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_range) { LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; - bindGLBuffer(true); if (mFinal) { LL_ERRS() << "LLVertexBuffer::mapVeretxBuffer() called on a finalized buffer." << LL_ENDL; @@ -1256,7 +1255,6 @@ U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_ran U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range) { LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; - bindGLIndices(true); if (mFinal) { LL_ERRS() << "LLVertexBuffer::mapIndexBuffer() called on a finalized buffer." << LL_ENDL; @@ -2070,6 +2068,24 @@ void LLVertexBuffer::setupVertexBufferFast(U32 data_mask) void* ptr = (void*)(base + mOffsets[TYPE_VERTEX]); glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); } - } +} + +void LLVertexBuffer::setPositionData(const LLVector4a* data) +{ + bindGLBuffer(); + flush_vbo(GL_ARRAY_BUFFER, 0, sizeof(LLVector4a) * getNumVerts(), (U8*) data); +} + +void LLVertexBuffer::setTexCoordData(const LLVector2* data) +{ + bindGLBuffer(); + flush_vbo(GL_ARRAY_BUFFER, mOffsets[TYPE_TEXCOORD0], mOffsets[TYPE_TEXCOORD0] + sTypeSize[TYPE_TEXCOORD0] * getNumVerts(), (U8*)data); +} + +void LLVertexBuffer::setColorData(const LLColor4U* data) +{ + bindGLBuffer(); + flush_vbo(GL_ARRAY_BUFFER, mOffsets[TYPE_COLOR], mOffsets[TYPE_COLOR] + sTypeSize[TYPE_COLOR] * getNumVerts(), (U8*) data); +} -- cgit v1.2.3 From 493d501cde13abf1ac4164cd77286f068da3a62c Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 10 Jan 2023 19:49:18 -0600 Subject: SL-18869 Optimizations -- Revive "Frame Profile" and GL_DEPTH_CLAMP. Remove usage of gl_FragDepth from shadow shaders. --- indra/llrender/llvertexbuffer.cpp | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 57be21cf6e..0dce5ed3a3 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -561,10 +561,8 @@ void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indi U16* idx = ((U16*) getIndicesPointer())+indices_offset; stop_glerror(); - LLGLSLShader::startProfile(); glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT, idx); - LLGLSLShader::stopProfile(count, mode); stop_glerror(); } @@ -608,10 +606,8 @@ void LLVertexBuffer::draw(U32 mode, U32 count, U32 indices_offset) const } stop_glerror(); - LLGLSLShader::startProfile(); - glDrawElements(sGLMode[mode], count, GL_UNSIGNED_SHORT, + glDrawElements(sGLMode[mode], count, GL_UNSIGNED_SHORT, ((U16*) getIndicesPointer()) + indices_offset); - LLGLSLShader::stopProfile(count, mode); stop_glerror(); } @@ -642,13 +638,7 @@ void LLVertexBuffer::drawArrays(U32 mode, U32 first, U32 count) const } #endif - LLGLSLShader::startProfile(); - { - glDrawArrays(sGLMode[mode], first, count); - } - LLGLSLShader::stopProfile(count, mode); - - stop_glerror(); + glDrawArrays(sGLMode[mode], first, count); } //static @@ -1347,7 +1337,6 @@ static void flush_vbo(GLenum target, S32 start, S32 end, void* data) for (S32 i = start; i < end; i += block_size) { LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("glBufferSubData block"); - LL_PROFILE_GPU_ZONE("glBufferSubData"); S32 tend = llmin(i + block_size, end); glBufferSubData(target, i, tend - i, (U8*) data + (i-start)); } -- cgit v1.2.3 From 3ac990e6ce962c2530a902d14a711d1ee996375c Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 11 Jan 2023 00:04:41 -0600 Subject: SL-18869 Touch up -- fix some Debug GL assertions and restore shadows. --- indra/llrender/llvertexbuffer.cpp | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 0dce5ed3a3..e1352691d4 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -560,10 +560,8 @@ void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indi U16* idx = ((U16*) getIndicesPointer())+indices_offset; - stop_glerror(); glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT, idx); - stop_glerror(); } void LLVertexBuffer::drawRangeFast(U32 mode, U32 start, U32 end, U32 count, U32 indices_offset) const @@ -605,10 +603,8 @@ void LLVertexBuffer::draw(U32 mode, U32 count, U32 indices_offset) const return; } - stop_glerror(); - glDrawElements(sGLMode[mode], count, GL_UNSIGNED_SHORT, + glDrawElements(sGLMode[mode], count, GL_UNSIGNED_SHORT, ((U16*) getIndicesPointer()) + indices_offset); - stop_glerror(); } @@ -888,6 +884,7 @@ void LLVertexBuffer::genBuffer(U32 size) glBindBuffer(GL_ARRAY_BUFFER, mGLBuffer); glBufferData(GL_ARRAY_BUFFER, mSize, nullptr, mUsage); glBindBuffer(GL_ARRAY_BUFFER, 0); + sGLRenderBuffer = 0; sGLCount++; } @@ -904,6 +901,7 @@ void LLVertexBuffer::genIndices(U32 size) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mGLIndices); glBufferData(GL_ELEMENT_ARRAY_BUFFER, mIndicesSize, nullptr, mUsage); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + sGLRenderIndices = 0; sGLCount++; } @@ -1293,17 +1291,6 @@ U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range) sMappedCount++; stop_glerror(); - if (gDebugGL && useVBOs()) - { - GLint elem = 0; - glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &elem); - - if (elem != mGLIndices) - { - LL_ERRS() << "Wrong index buffer bound!" << LL_ENDL; - } - } - map_range = false; } @@ -1337,6 +1324,7 @@ static void flush_vbo(GLenum target, S32 start, S32 end, void* data) for (S32 i = start; i < end; i += block_size) { LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("glBufferSubData block"); + LL_PROFILE_GPU_ZONE("glBufferSubData"); S32 tend = llmin(i + block_size, end); glBufferSubData(target, i, tend - i, (U8*) data + (i-start)); } -- cgit v1.2.3 From b9a4d81d5140b34199a6582b1189473b6a2e72fb Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 11 Jan 2023 16:20:24 -0600 Subject: SL-18869 Optimizations -- Revive LLVBOPool and fix silly typo in renderShadowSimple --- indra/llrender/llvertexbuffer.cpp | 326 ++++++++++++++++++++++++-------------- 1 file changed, 210 insertions(+), 116 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index e1352691d4..c1ffe6957a 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -273,7 +273,189 @@ static GLWorkQueue* sQueue = nullptr; #endif //============================================================================ +// Pool of reusable VertexBuffer state +// batch calls to glGenBuffers +static GLuint gen_buffer() +{ + LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; + constexpr U32 pool_size = 4096; + + thread_local static GLuint sNamePool[pool_size]; + thread_local static U32 sIndex = 0; + + if (sIndex == 0) + { + LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("gen buffer"); + sIndex = pool_size; + glGenBuffers(pool_size, sNamePool); + } + + return sNamePool[--sIndex]; +} + +class LLVBOPool +{ +public: + typedef std::chrono::steady_clock::time_point Time; + + struct Entry + { + U8* mData; + GLuint mGLName; + Time mAge; + }; + + ~LLVBOPool() + { + clear(); + } + + typedef std::unordered_map> Pool; + + Pool mVBOPool; + Pool mIBOPool; + + U32 mMissCount = 0; + + void allocate(GLenum type, U32 size, GLuint& name, U8*& data) + { + LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; + + size = nhpo2(size); + + auto& pool = type == GL_ELEMENT_ARRAY_BUFFER ? mIBOPool : mVBOPool; + + auto& iter = pool.find(size); + if (iter == pool.end()) + { // cache miss, allocate a new buffer + LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("vbo pool miss"); + LL_PROFILE_GPU_ZONE("vbo alloc"); + + ++mMissCount; + if (mMissCount > 1024) + { //clean cache on every 1024 misses + mMissCount = 0; + clean(); + } + + name = gen_buffer(); + glBindBuffer(type, name); + glBufferData(type, size, nullptr, GL_DYNAMIC_DRAW); + if (type == GL_ELEMENT_ARRAY_BUFFER) + { + LLVertexBuffer::sGLRenderIndices = name; + } + else + { + LLVertexBuffer::sGLRenderBuffer = name; + } + + data = (U8*)ll_aligned_malloc_16(size); + } + else + { + std::list& entries = iter->second; + Entry& entry = entries.back(); + name = entry.mGLName; + data = entry.mData; + + entries.pop_back(); + if (entries.empty()) + { + pool.erase(iter); + } + } + } + + void free(GLenum type, U32 size, GLuint name, U8* data) + { + size = nhpo2(size); + + auto& pool = type == GL_ELEMENT_ARRAY_BUFFER ? mIBOPool : mVBOPool; + + auto& iter = pool.find(size); + + if (iter == pool.end()) + { + std::list newlist; + newlist.push_front({ data, name, std::chrono::steady_clock::now() }); + pool[size] = newlist; + } + else + { + iter->second.push_front({ data, name, std::chrono::steady_clock::now() }); + } + } + + void clean() + { + LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; + + std::unordered_map>* pools[] = { &mVBOPool, &mIBOPool }; + + using namespace std::chrono_literals; + + Time cutoff = std::chrono::steady_clock::now() - 5s; + + for (auto* pool : pools) + { + for (Pool::iterator iter = pool->begin(); iter != pool->end(); ) + { + auto& entries = iter->second; + + while (!entries.empty() && entries.back().mAge < cutoff) + { + LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("vbo cache timeout"); + auto& entry = entries.back(); + ll_aligned_free_16(entry.mData); + glDeleteBuffers(1, &entry.mGLName); + entries.pop_back(); + } + + if (entries.empty()) + { + iter = pool->erase(iter); + } + else + { + ++iter; + } + } + } + } + + void clear() + { + for (auto& entries : mIBOPool) + { + for (auto& entry : entries.second) + { + ll_aligned_free_16(entry.mData); + glDeleteBuffers(1, &entry.mGLName); + } + } + + for (auto& entries : mVBOPool) + { + for (auto& entry : entries.second) + { + ll_aligned_free_16(entry.mData); + glDeleteBuffers(1, &entry.mGLName); + } + } + + mIBOPool.clear(); + mVBOPool.clear(); + } + + +}; + +static LLVBOPool* sVBOPool = nullptr; + +//============================================================================ +// //static std::list LLVertexBuffer::sAvailableVAOName; U32 LLVertexBuffer::sCurVAOName = 1; @@ -643,6 +825,8 @@ void LLVertexBuffer::initClass(LLWindow* window) sEnableVBOs = true; sDisableVBOMapping = true; + sVBOPool = new LLVBOPool(); + #if ENABLE_GL_WORK_QUEUE sQueue = new GLWorkQueue(); @@ -687,6 +871,9 @@ void LLVertexBuffer::cleanupClass() { unbind(); + delete sVBOPool; + sVBOPool = nullptr; + #if ENABLE_GL_WORK_QUEUE sQueue->close(); for (int i = 0; i < THREAD_COUNT; ++i) @@ -720,15 +907,8 @@ S32 LLVertexBuffer::determineUsage(S32 usage) ret_usage = 0; } - if (ret_usage == GL_DYNAMIC_DRAW && sPreferStreamDraw) - { - ret_usage = GL_STREAM_DRAW; - } - - if (ret_usage == 0 && LLRender::sGLCoreProfile) - { //MUST use VBOs for all rendering - ret_usage = GL_STREAM_DRAW; - } + // dynamic draw or nothing + ret_usage = GL_DYNAMIC_DRAW; return ret_usage; } @@ -830,62 +1010,17 @@ LLVertexBuffer::~LLVertexBuffer() //---------------------------------------------------------------------------- -// batch glGenBuffers -static GLuint gen_buffer() -{ - LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; - constexpr U32 pool_size = 4096; - - thread_local static GLuint sNamePool[pool_size]; - thread_local static U32 sIndex = 0; - - if (sIndex == 0) - { - LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("gen ibo"); - sIndex = pool_size; - glGenBuffers(pool_size, sNamePool); - } - - return sNamePool[--sIndex]; -} - -// batch glDeleteBuffers -static void release_buffer(U32 buff) -{ - LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; -#if 0 - - constexpr U32 pool_size = 4096; - - thread_local static GLuint sNamePool[pool_size]; - thread_local static U32 sIndex = 0; - - if (sIndex == pool_size) - { - LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("gen ibo"); - sIndex = 0; - glDeleteBuffers(pool_size, sNamePool); - } - - sNamePool[sIndex++] = buff; -#else - glDeleteBuffers(1, &buff); -#endif -} - void LLVertexBuffer::genBuffer(U32 size) { LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; mSize = size; - mMappedData = (U8*) ll_aligned_malloc_16(size); - mGLBuffer = gen_buffer(); - - glBindBuffer(GL_ARRAY_BUFFER, mGLBuffer); - glBufferData(GL_ARRAY_BUFFER, mSize, nullptr, mUsage); - glBindBuffer(GL_ARRAY_BUFFER, 0); - sGLRenderBuffer = 0; + if (sVBOPool) + { + sVBOPool->allocate(GL_ARRAY_BUFFER, size, mGLBuffer, mMappedData); + } + sGLCount++; } @@ -894,25 +1029,24 @@ void LLVertexBuffer::genIndices(U32 size) LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; mIndicesSize = size; - mMappedIndexData = (U8*) ll_aligned_malloc_16(size); - - mGLIndices = gen_buffer(); - - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mGLIndices); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, mIndicesSize, nullptr, mUsage); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - sGLRenderIndices = 0; + if (sVBOPool) + { + sVBOPool->allocate(GL_ELEMENT_ARRAY_BUFFER, size, mGLIndices, mMappedIndexData); + } sGLCount++; } void LLVertexBuffer::releaseBuffer() { LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; - release_buffer(mGLBuffer); - mGLBuffer = 0; - ll_aligned_free_16(mMappedData); + if (sVBOPool) + { + sVBOPool->free(GL_ARRAY_BUFFER, mSize, mGLBuffer, mMappedData); + } + + mGLBuffer = 0; mMappedData = nullptr; sGLCount--; @@ -921,10 +1055,12 @@ void LLVertexBuffer::releaseBuffer() void LLVertexBuffer::releaseIndices() { LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; - release_buffer(mGLIndices); - mGLIndices = 0; + + if (sVBOPool) + { + sVBOPool->free(GL_ELEMENT_ARRAY_BUFFER, mIndicesSize, mGLIndices, mMappedIndexData); + } - ll_aligned_free_16(mMappedIndexData); mMappedIndexData = nullptr; sGLCount--; @@ -1604,49 +1740,7 @@ void LLVertexBuffer::flush(bool discard) { if (useVBOs()) { - if (discard) - { // discard existing VBO data if the buffer must be updated - - if (!mMappedVertexRegions.empty()) - { - LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("flush discard vbo"); - LL_PROFILE_ZONE_NUM(mSize); - release_buffer(mGLBuffer); - mGLBuffer = gen_buffer(); - bindGLBuffer(); - { - LL_PROFILE_GPU_ZONE("glBufferData"); - glBufferData(GL_ARRAY_BUFFER, mSize, nullptr, mUsage); - - for (int i = 0; i < mSize; i += 65536) - { - LL_PROFILE_GPU_ZONE("glBufferSubData"); - S32 end = llmin(i + 65536, mSize); - S32 count = end - i; - glBufferSubData(GL_ARRAY_BUFFER, i, count, mMappedData + i); - } - } - mMappedVertexRegions.clear(); - } - if (!mMappedIndexRegions.empty()) - { - LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("flush discard ibo"); - LL_PROFILE_ZONE_NUM(mIndicesSize); - release_buffer(mGLIndices); - mGLIndices = gen_buffer(); - bindGLIndices(); - { - LL_PROFILE_GPU_ZONE("glBufferData (ibo)"); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, mIndicesSize, mMappedIndexData, mUsage); - } - mMappedIndexRegions.clear(); - } - } - else - { - unmapBuffer(); - } - + unmapBuffer(); } } -- cgit v1.2.3 From 1ff3b1ffa54db0f7aaca543e2565e1ac3087d1e0 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Thu, 12 Jan 2023 19:49:35 +0200 Subject: MacOS build fix --- 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 c1ffe6957a..bc33591ed7 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -326,7 +326,7 @@ public: auto& pool = type == GL_ELEMENT_ARRAY_BUFFER ? mIBOPool : mVBOPool; - auto& iter = pool.find(size); + Pool::iterator iter = pool.find(size); if (iter == pool.end()) { // cache miss, allocate a new buffer LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("vbo pool miss"); @@ -374,7 +374,7 @@ public: auto& pool = type == GL_ELEMENT_ARRAY_BUFFER ? mIBOPool : mVBOPool; - auto& iter = pool.find(size); + Pool::iterator iter = pool.find(size); if (iter == pool.end()) { -- cgit v1.2.3 From 7bd9d21e19b923096ba2b5ea3cbc8be3e13d7aa0 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 19 Jan 2023 09:13:45 -0600 Subject: Optimizations, decruft, and intel compatibility pass (#53) SL-18869, SL-18772 Overhaul VBO management, restore occlusion culling, intel compatibility pass, etc --- indra/llrender/llvertexbuffer.cpp | 1442 ++++++++++--------------------------- 1 file changed, 384 insertions(+), 1058 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index bc33591ed7..f1d71ec94d 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -70,25 +70,6 @@ struct CompareMappedRegion } }; - -const U32 LL_VBO_BLOCK_SIZE = 2048; -const U32 LL_VBO_POOL_MAX_SEED_SIZE = 256*1024; - -U32 vbo_block_size(U32 size) -{ //what block size will fit size? - U32 mod = size % LL_VBO_BLOCK_SIZE; - return mod == 0 ? size : size + (LL_VBO_BLOCK_SIZE-mod); -} - -U32 vbo_block_index(U32 size) -{ - U32 blocks = vbo_block_size(size)/LL_VBO_BLOCK_SIZE; // block count reqd - llassert(blocks > 0); - return blocks - 1; // Adj index, i.e. single-block allocations are at index 0, etc -} - -const U32 LL_VBO_POOL_SEED_COUNT = vbo_block_index(LL_VBO_POOL_MAX_SEED_SIZE) + 1; - #define ENABLE_GL_WORK_QUEUE 0 #if ENABLE_GL_WORK_QUEUE @@ -294,6 +275,8 @@ static GLuint gen_buffer() return sNamePool[--sIndex]; } +#define ANALYZE_VBO_POOL 0 + class LLVBOPool { public: @@ -316,13 +299,42 @@ public: Pool mVBOPool; Pool mIBOPool; - U32 mMissCount = 0; + U32 mTouchCount = 0; + +#if ANALYZE_VBO_POOL + U64 mDistributed = 0; + U64 mAllocated = 0; + U64 mReserved = 0; + U32 mMisses = 0; + U32 mHits = 0; +#endif + + // increase the size to some common value (e.g. a power of two) to increase hit rate + void adjustSize(U32& size) + { + // size = nhpo2(size); // (193/303)/580 MB (distributed/allocated)/reserved in VBO Pool. Overhead: 66 percent. Hit rate: 77 percent + + //(245/276)/385 MB (distributed/allocated)/reserved in VBO Pool. Overhead: 57 percent. Hit rate: 69 percent + //(187/209)/397 MB (distributed/allocated)/reserved in VBO Pool. Overhead: 112 percent. Hit rate: 76 percent + U32 block_size = llmax(nhpo2(size) / 8, (U32) 16); + size += block_size - (size % block_size); + } void allocate(GLenum type, U32 size, GLuint& name, U8*& data) { LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; - - size = nhpo2(size); + llassert(type == GL_ARRAY_BUFFER || type == GL_ELEMENT_ARRAY_BUFFER); + llassert(name == 0); // non zero name indicates a gl name that wasn't freed + llassert(data == nullptr); // non null data indicates a buffer that wasn't freed + llassert(size >= 2); // any buffer size smaller than a single index is nonsensical + +#if ANALYZE_VBO_POOL + mDistributed += size; + adjustSize(size); + mAllocated += size; +#else + adjustSize(size); +#endif auto& pool = type == GL_ELEMENT_ARRAY_BUFFER ? mIBOPool : mVBOPool; @@ -332,13 +344,9 @@ public: LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("vbo pool miss"); LL_PROFILE_GPU_ZONE("vbo alloc"); - ++mMissCount; - if (mMissCount > 1024) - { //clean cache on every 1024 misses - mMissCount = 0; - clean(); - } - +#if ANALYZE_VBO_POOL + mMisses++; +#endif name = gen_buffer(); glBindBuffer(type, name); glBufferData(type, size, nullptr, GL_DYNAMIC_DRAW); @@ -355,22 +363,47 @@ public: } else { +#if ANALYZE_VBO_POOL + mHits++; + llassert(mReserved >= size); // assert if accounting gets messed up + mReserved -= size; +#endif + std::list& entries = iter->second; Entry& entry = entries.back(); name = entry.mGLName; data = entry.mData; - + entries.pop_back(); if (entries.empty()) { pool.erase(iter); } } + + clean(); } void free(GLenum type, U32 size, GLuint name, U8* data) { - size = nhpo2(size); + LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; + llassert(type == GL_ARRAY_BUFFER || type == GL_ELEMENT_ARRAY_BUFFER); + llassert(size >= 2); + llassert(name != 0); + llassert(data != nullptr); + + clean(); + +#if ANALYZE_VBO_POOL + llassert(mDistributed >= size); + mDistributed -= size; + adjustSize(size); + llassert(mAllocated >= size); + mAllocated -= size; + mReserved += size; +#else + adjustSize(size); +#endif auto& pool = type == GL_ELEMENT_ARRAY_BUFFER ? mIBOPool : mVBOPool; @@ -386,10 +419,19 @@ public: { iter->second.push_front({ data, name, std::chrono::steady_clock::now() }); } + } + // clean periodically (clean gets called for every alloc/free) void clean() { + mTouchCount++; + if (mTouchCount < 1024) // clean every 1k touches + { + return; + } + mTouchCount = 0; + LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; std::unordered_map>* pools[] = { &mVBOPool, &mIBOPool }; @@ -410,7 +452,12 @@ public: auto& entry = entries.back(); ll_aligned_free_16(entry.mData); glDeleteBuffers(1, &entry.mGLName); +#if ANALYZE_VBO_POOL + llassert(mReserved >= iter->first); + mReserved -= iter->first; +#endif entries.pop_back(); + } if (entries.empty()) @@ -423,6 +470,16 @@ public: } } } + +#if ANALYZE_VBO_POOL + LL_INFOS() << llformat("(%d/%d)/%d MB (distributed/allocated)/total in VBO Pool. Overhead: %d percent. Hit rate: %d percent", + mDistributed / 1000000, + mAllocated / 1000000, + (mAllocated + mReserved) / 1000000, // total bytes + ((mAllocated+mReserved-mDistributed)*100)/llmax(mDistributed, (U64) 1), // overhead percent + (mHits*100)/llmax(mMisses+mHits, (U32)1)) // hit rate percent + << LL_ENDL; +#endif } void clear() @@ -445,6 +502,10 @@ public: } } +#if ANALYZE_VBO_POOL + mReserved = 0; +#endif + mIBOPool.clear(); mVBOPool.clear(); } @@ -457,35 +518,14 @@ static LLVBOPool* sVBOPool = nullptr; //============================================================================ // //static -std::list LLVertexBuffer::sAvailableVAOName; -U32 LLVertexBuffer::sCurVAOName = 1; - -U32 LLVertexBuffer::sAllocatedIndexBytes = 0; -U32 LLVertexBuffer::sIndexCount = 0; - -U32 LLVertexBuffer::sBindCount = 0; -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::sGLRenderArray = 0; U32 LLVertexBuffer::sGLRenderIndices = 0; U32 LLVertexBuffer::sLastMask = 0; -bool LLVertexBuffer::sVBOActive = false; -bool LLVertexBuffer::sIBOActive = false; -U32 LLVertexBuffer::sAllocatedBytes = 0; U32 LLVertexBuffer::sVertexCount = 0; -bool LLVertexBuffer::sMapped = false; -bool LLVertexBuffer::sUseStreamDraw = true; -bool LLVertexBuffer::sUseVAO = false; -bool LLVertexBuffer::sPreferStreamDraw = false; //NOTE: each component must be AT LEAST 4 bytes in size to avoid a performance penalty on AMD hardware -const S32 LLVertexBuffer::sTypeSize[LLVertexBuffer::TYPE_MAX] = +const U32 LLVertexBuffer::sTypeSize[LLVertexBuffer::TYPE_MAX] = { sizeof(LLVector4), // TYPE_VERTEX, sizeof(LLVector4), // TYPE_NORMAL, @@ -534,62 +574,34 @@ const U32 LLVertexBuffer::sGLMode[LLRender::NUM_MODES] = }; //static -U32 LLVertexBuffer::getVAOName() -{ - U32 ret = 0; - - if (!sAvailableVAOName.empty()) - { - ret = sAvailableVAOName.front(); - sAvailableVAOName.pop_front(); - } - else - { -#ifdef GL_ARB_vertex_array_object - glGenVertexArrays(1, &ret); -#endif - } - - return ret; -} - -//static -void LLVertexBuffer::releaseVAOName(U32 name) +void LLVertexBuffer::setupClientArrays(U32 data_mask) { - sAvailableVAOName.push_back(name); -} + if (sLastMask != data_mask) + { + for (U32 i = 0; i < TYPE_MAX; ++i) + { + S32 loc = i; + U32 mask = 1 << i; -//static -void LLVertexBuffer::setupClientArrays(U32 data_mask) -{ - if (sLastMask != data_mask) - { + if (sLastMask & (1 << i)) + { //was enabled + if (!(data_mask & mask)) + { //needs to be disabled + glDisableVertexAttribArray(loc); + } + } + else + { //was disabled + if (data_mask & mask) + { //needs to be enabled + glEnableVertexAttribArray(loc); + } + } + } + } - for (U32 i = 0; i < TYPE_MAX; ++i) - { - S32 loc = i; - - U32 mask = 1 << i; - - if (sLastMask & (1 << i)) - { //was enabled - if (!(data_mask & mask)) - { //needs to be disabled - glDisableVertexAttribArray(loc); - } - } - else - { //was disabled - if (data_mask & mask) - { //needs to be enabled - glEnableVertexAttribArray(loc); - } - } - } - - sLastMask = data_mask; - } + sLastMask = data_mask; } //static @@ -606,7 +618,7 @@ void LLVertexBuffer::drawArrays(U32 mode, const std::vector& pos) } //static -void LLVertexBuffer::drawElements(U32 mode, const LLVector4a* pos, const LLVector2* tc, S32 num_indices, const U16* indicesp) +void LLVertexBuffer::drawElements(U32 mode, const LLVector4a* pos, const LLVector2* tc, U32 num_indices, const U16* indicesp) { LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; llassert(LLGLSLShader::sCurBoundShaderPtr != NULL); @@ -644,8 +656,13 @@ void LLVertexBuffer::drawElements(U32 mode, const LLVector4a* pos, const LLVecto gGL.flush(); } -void LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_offset) const +bool LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_offset) const { + if (!gDebugGL) + { + return true; + } + llassert(start < (U32)mNumVerts); llassert(end < (U32)mNumVerts); @@ -663,9 +680,8 @@ void LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_of LL_ERRS() << "Bad index buffer draw range: [" << indices_offset << ", " << indices_offset+count << "]" << LL_ENDL; } - if (gDebugGL && !useVBOs()) { - U16* idx = ((U16*) getIndicesPointer())+indices_offset; + U16* idx = (U16*) mMappedIndexData+indices_offset; for (U32 i = 0; i < count; ++i) { llassert(idx[i] >= start); @@ -681,22 +697,20 @@ void LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_of if (shader && shader->mFeatures.mIndexedTextureChannels > 1) { - LLStrider v; - //hack to get non-const reference - LLVertexBuffer* vb = (LLVertexBuffer*) this; - vb->getVertexStrider(v); - + LLVector4a* v = (LLVector4a*) mMappedData; + for (U32 i = start; i < end; i++) { - S32 idx = (S32) (v[i][3]+0.25f); - llassert(idx >= 0); - if (idx < 0 || idx >= shader->mFeatures.mIndexedTextureChannels) + U32 idx = (U32) (v[i][3]+0.25f); + if (idx >= shader->mFeatures.mIndexedTextureChannels) { LL_ERRS() << "Bad texture index found in vertex data stream." << LL_ENDL; } } } } + + return true; } #ifdef LL_PROFILER_ENABLE_RENDER_DOC @@ -707,124 +721,35 @@ void LLVertexBuffer::setLabel(const char* label) { void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indices_offset) const { - validateRange(start, end, count, indices_offset); - gGL.syncMatrices(); - - llassert(mNumVerts >= 0); - llassert(LLGLSLShader::sCurBoundShaderPtr != NULL); - - if (mGLIndices != sGLRenderIndices) - { - LL_ERRS() << "Wrong index buffer bound." << LL_ENDL; - } - - if (mGLBuffer != sGLRenderBuffer) - { - LL_ERRS() << "Wrong vertex buffer bound." << LL_ENDL; - } - - if (gDebugGL && useVBOs()) - { - GLint elem = 0; - glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, &elem); - - if (elem != mGLIndices) - { - LL_ERRS() << "Wrong index buffer bound!" << LL_ENDL; - } - } - - if (mode >= LLRender::NUM_MODES) - { - LL_ERRS() << "Invalid draw mode: " << mode << LL_ENDL; - return; - } - - U16* idx = ((U16*) getIndicesPointer())+indices_offset; - - glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT, - idx); -} - -void LLVertexBuffer::drawRangeFast(U32 mode, U32 start, U32 end, U32 count, U32 indices_offset) const -{ + llassert(validateRange(start, end, count, indices_offset)); + llassert(mGLBuffer == sGLRenderBuffer); + llassert(mGLIndices == sGLRenderIndices); gGL.syncMatrices(); - U16* idx = ((U16*)getIndicesPointer()) + indices_offset; - - glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT, - idx); + glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT, + (GLvoid*) (indices_offset * sizeof(U16))); } void LLVertexBuffer::draw(U32 mode, U32 count, U32 indices_offset) const { - llassert(LLGLSLShader::sCurBoundShaderPtr != NULL); - gGL.syncMatrices(); - - llassert(mNumIndices >= 0); - if (indices_offset >= (U32) mNumIndices || - indices_offset + count > (U32) mNumIndices) - { - LL_ERRS() << "Bad index buffer draw range: [" << indices_offset << ", " << indices_offset+count << "]" << LL_ENDL; - } - - - if (mGLIndices != sGLRenderIndices) - { - LL_ERRS() << "Wrong index buffer bound." << LL_ENDL; - } - - if (mGLBuffer != sGLRenderBuffer) - { - LL_ERRS() << "Wrong vertex buffer bound." << LL_ENDL; - } - - if (mode >= LLRender::NUM_MODES) - { - LL_ERRS() << "Invalid draw mode: " << mode << LL_ENDL; - return; - } - - glDrawElements(sGLMode[mode], count, GL_UNSIGNED_SHORT, - ((U16*) getIndicesPointer()) + indices_offset); + drawRange(mode, 0, mNumVerts, count, indices_offset); } void LLVertexBuffer::drawArrays(U32 mode, U32 first, U32 count) const { - LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; - llassert(LLGLSLShader::sCurBoundShaderPtr != NULL); + llassert(first + count <= mNumVerts); + llassert(mGLBuffer == sGLRenderBuffer); + llassert(mGLIndices == sGLRenderIndices); + gGL.syncMatrices(); - -#ifndef LL_RELEASE_FOR_DOWNLOAD - llassert(mNumVerts >= 0); - if (first >= (U32) mNumVerts || - first + count > (U32) mNumVerts) - { - LL_ERRS() << "Bad vertex buffer draw range: [" << first << ", " << first+count << "]" << LL_ENDL; - } - - if (mGLBuffer != sGLRenderBuffer || useVBOs() != sVBOActive) - { - LL_ERRS() << "Wrong vertex buffer bound." << LL_ENDL; - } - - if (mode >= LLRender::NUM_MODES) - { - LL_ERRS() << "Invalid draw mode: " << mode << LL_ENDL; - return; - } -#endif - glDrawArrays(sGLMode[mode], first, count); } //static void LLVertexBuffer::initClass(LLWindow* window) { - sEnableVBOs = true; - sDisableVBOMapping = true; - + llassert(sVBOPool == nullptr); sVBOPool = new LLVBOPool(); #if ENABLE_GL_WORK_QUEUE @@ -841,29 +766,11 @@ void LLVertexBuffer::initClass(LLWindow* window) //static void LLVertexBuffer::unbind() { - if (sGLRenderArray) - { - glBindVertexArray(0); - sGLRenderArray = 0; - sGLRenderIndices = 0; - sIBOActive = false; - } - - if (sVBOActive) - { - glBindBuffer(GL_ARRAY_BUFFER, 0); - sVBOActive = false; - } - if (sIBOActive) - { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - sIBOActive = false; - } + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); sGLRenderBuffer = 0; sGLRenderIndices = 0; - - setupClientArrays(0); } //static @@ -886,67 +793,26 @@ void LLVertexBuffer::cleanupClass() delete sQueue; sQueue = nullptr; #endif - - //llassert(0 == sAllocatedBytes); - //llassert(0 == sAllocatedIndexBytes); } //---------------------------------------------------------------------------- -S32 LLVertexBuffer::determineUsage(S32 usage) -{ - S32 ret_usage = usage; - - if (!sEnableVBOs) - { - ret_usage = 0; - } - - if (ret_usage == GL_STREAM_DRAW && !sUseStreamDraw) - { - ret_usage = 0; - } - - // dynamic draw or nothing - ret_usage = GL_DYNAMIC_DRAW; - - return ret_usage; -} - -LLVertexBuffer::LLVertexBuffer(U32 typemask, S32 usage) +LLVertexBuffer::LLVertexBuffer(U32 typemask) : LLRefCount(), - - mNumVerts(0), - mNumIndices(0), - mSize(0), - mIndicesSize(0), - mTypeMask(typemask), - mUsage(LLVertexBuffer::determineUsage(usage)), - mGLBuffer(0), - mGLIndices(0), - mMappedData(NULL), - mMappedIndexData(NULL), - mMappedDataUsingVBOs(false), - mMappedIndexDataUsingVBOs(false), - mVertexLocked(false), - mIndexLocked(false), - mFinal(false), - mEmpty(true) + mTypeMask(typemask) { //zero out offsets for (U32 i = 0; i < TYPE_MAX; i++) { mOffsets[i] = 0; } - - sCount++; } //static -S32 LLVertexBuffer::calcOffsets(const U32& typemask, S32* offsets, S32 num_vertices) +U32 LLVertexBuffer::calcOffsets(const U32& typemask, U32* offsets, U32 num_vertices) { - S32 offset = 0; - for (S32 i=0; iallocate(GL_ARRAY_BUFFER, size, mGLBuffer, mMappedData); - } - - sGLCount++; -} - -void LLVertexBuffer::genIndices(U32 size) -{ - LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; - - mIndicesSize = size; + llassert(mSize == 0); + llassert(mGLBuffer == 0); + llassert(mMappedData == nullptr); - if (sVBOPool) - { - sVBOPool->allocate(GL_ELEMENT_ARRAY_BUFFER, size, mGLIndices, mMappedIndexData); + mSize = size; + sVBOPool->allocate(GL_ARRAY_BUFFER, mSize, mGLBuffer, mMappedData); } - sGLCount++; } -void LLVertexBuffer::releaseBuffer() +void LLVertexBuffer::genIndices(U32 size) { LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; + llassert(sVBOPool); if (sVBOPool) { - sVBOPool->free(GL_ARRAY_BUFFER, mSize, mGLBuffer, mMappedData); - } - - mGLBuffer = 0; - mMappedData = nullptr; - - sGLCount--; -} - -void LLVertexBuffer::releaseIndices() -{ - LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; - - if (sVBOPool) - { - sVBOPool->free(GL_ELEMENT_ARRAY_BUFFER, mIndicesSize, mGLIndices, mMappedIndexData); + llassert(mIndicesSize == 0); + llassert(mGLIndices == 0); + llassert(mMappedIndexData == nullptr); + mIndicesSize = size; + sVBOPool->allocate(GL_ELEMENT_ARRAY_BUFFER, mIndicesSize, mGLIndices, mMappedIndexData); } - - mMappedIndexData = nullptr; - - sGLCount--; } bool LLVertexBuffer::createGLBuffer(U32 size) @@ -1080,23 +911,8 @@ bool LLVertexBuffer::createGLBuffer(U32 size) bool success = true; - mEmpty = true; - - mMappedDataUsingVBOs = useVBOs(); + genBuffer(size); - if (mMappedDataUsingVBOs) - { - genBuffer(size); - } - else - { - static int gl_buffer_idx = 0; - mGLBuffer = ++gl_buffer_idx; - - mMappedData = (U8*)ll_aligned_malloc_16(size); - mSize = size; - } - if (!mMappedData) { success = false; @@ -1118,27 +934,8 @@ bool LLVertexBuffer::createGLIndices(U32 size) bool success = true; - mEmpty = true; - - //pad by 16 bytes for aligned copies - size += 16; - - mMappedIndexDataUsingVBOs = useVBOs(); - - if (mMappedIndexDataUsingVBOs) - { - //pad by another 16 bytes for VBO pointer adjustment - size += 16; - genIndices(size); - } - else - { - mMappedIndexData = (U8*)ll_aligned_malloc_16(size); - static int gl_buffer_idx = 0; - mGLIndices = ++gl_buffer_idx; - mIndicesSize = size; - } - + genIndices(size); + if (!mMappedIndexData) { success = false; @@ -1150,43 +947,37 @@ void LLVertexBuffer::destroyGLBuffer() { if (mGLBuffer || mMappedData) { - if (mMappedDataUsingVBOs) - { - releaseBuffer(); - } - else - { - ll_aligned_free_16((void*)mMappedData); - mMappedData = NULL; - mEmpty = true; - } + LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; + //llassert(sVBOPool); + if (sVBOPool) + { + sVBOPool->free(GL_ARRAY_BUFFER, mSize, mGLBuffer, mMappedData); + } + + mSize = 0; + mGLBuffer = 0; + mMappedData = nullptr; } - - mGLBuffer = 0; - //unbind(); } void LLVertexBuffer::destroyGLIndices() { if (mGLIndices || mMappedIndexData) { - if (mMappedIndexDataUsingVBOs) - { - releaseIndices(); - } - else - { - ll_aligned_free_16((void*)mMappedIndexData); - mMappedIndexData = NULL; - mEmpty = true; - } - } + LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; + //llassert(sVBOPool); + if (sVBOPool) + { + sVBOPool->free(GL_ELEMENT_ARRAY_BUFFER, mIndicesSize, mGLIndices, mMappedIndexData); + } - mGLIndices = 0; - //unbind(); + mIndicesSize = 0; + mGLIndices = 0; + mMappedIndexData = nullptr; + } } -bool LLVertexBuffer::updateNumVerts(S32 nverts) +bool LLVertexBuffer::updateNumVerts(U32 nverts) { llassert(nverts >= 0); @@ -1200,19 +991,17 @@ bool LLVertexBuffer::updateNumVerts(S32 nverts) U32 needed_size = calcOffsets(mTypeMask, mOffsets, nverts); - if (needed_size > mSize || needed_size <= mSize/2) - { - success &= createGLBuffer(needed_size); - } + if (needed_size != mSize) + { + success &= createGLBuffer(needed_size); + } - sVertexCount -= mNumVerts; + llassert(mSize == needed_size); mNumVerts = nverts; - sVertexCount += mNumVerts; - return success; } -bool LLVertexBuffer::updateNumIndices(S32 nindices) +bool LLVertexBuffer::updateNumIndices(U32 nindices) { llassert(nindices >= 0); @@ -1220,22 +1009,18 @@ bool LLVertexBuffer::updateNumIndices(S32 nindices) U32 needed_size = sizeof(U16) * nindices; - if (needed_size > mIndicesSize || needed_size <= mIndicesSize/2) + if (needed_size != mIndicesSize) { success &= createGLIndices(needed_size); } - sIndexCount -= mNumIndices; + llassert(mIndicesSize == needed_size); mNumIndices = nindices; - sIndexCount += mNumIndices; - return success; } -bool LLVertexBuffer::allocateBuffer(S32 nverts, S32 nindices, bool create) +bool LLVertexBuffer::allocateBuffer(U32 nverts, U32 nindices) { - stop_glerror(); - if (nverts < 0 || nindices < 0 || nverts > 65536) { @@ -1247,44 +1032,14 @@ bool LLVertexBuffer::allocateBuffer(S32 nverts, S32 nindices, bool create) success &= updateNumVerts(nverts); success &= updateNumIndices(nindices); - if (create && (nverts || nindices)) - { - //actually allocate space for the vertex buffer if using VBO mapping - flush(); //unmap - } - return success; } -bool LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) -{ - llassert(newnverts >= 0); - llassert(newnindices >= 0); - - bool success = true; - - success &= updateNumVerts(newnverts); - success &= updateNumIndices(newnindices); - - if (useVBOs()) - { - flush(); //unmap - } - - return success; -} - -bool LLVertexBuffer::useVBOs() const -{ - //it's generally ineffective to use VBO for things that are streaming on apple - return (mUsage != 0); -} - //---------------------------------------------------------------------------- // if no gap between region and given range exists, expand region to cover given range and return true // otherwise return false -bool expand_region(LLVertexBuffer::MappedRegion& region, S32 start, S32 end) +bool expand_region(LLVertexBuffer::MappedRegion& region, U32 start, U32 end) { if (end < region.mStart || @@ -1301,152 +1056,79 @@ bool expand_region(LLVertexBuffer::MappedRegion& region, S32 start, S32 end) // Map for data access -U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_range) +U8* LLVertexBuffer::mapVertexBuffer(LLVertexBuffer::AttributeType type, U32 index, S32 count) { LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; - if (mFinal) - { - LL_ERRS() << "LLVertexBuffer::mapVeretxBuffer() called on a finalized buffer." << LL_ENDL; - } - if (!useVBOs() && !mMappedData && !mMappedIndexData) - { - LL_ERRS() << "LLVertexBuffer::mapVertexBuffer() called on unallocated buffer." << LL_ENDL; - } + + if (count == -1) + { + count = mNumVerts - index; + } + U32 start = mOffsets[type] + sTypeSize[type] * index; + U32 end = start + sTypeSize[type] * count-1; - if (useVBOs()) - { - if (count == -1) + bool flagged = false; + // flag region as mapped + for (U32 i = 0; i < mMappedVertexRegions.size(); ++i) + { + MappedRegion& region = mMappedVertexRegions[i]; + if (expand_region(region, start, end)) { - count = mNumVerts - index; + flagged = true; + break; } - - S32 start = mOffsets[type] + sTypeSize[type] * index; - S32 end = start + sTypeSize[type] * count; - - bool flagged = false; - // flag region as mapped - for (U32 i = 0; i < mMappedVertexRegions.size(); ++i) - { - MappedRegion& region = mMappedVertexRegions[i]; - if (expand_region(region, start, end)) - { - flagged = true; - break; - } - } - - if (!flagged) - { - //didn't expand an existing region, make a new one - mMappedVertexRegions.push_back({ start, end }); - } - - if (mVertexLocked && map_range) - { - LL_ERRS() << "Attempted to map a specific range of a buffer that was already mapped." << LL_ENDL; - } - - if (!mVertexLocked) - { - mVertexLocked = true; - sMappedCount++; - stop_glerror(); - - map_range = false; - - if (!mMappedData) - { - log_glerror(); - - //check the availability of memory - LLMemory::logMemoryInfo(true); - - LL_ERRS() << "memory allocation for vertex data failed." << LL_ENDL; - - } - } } - else + + if (!flagged) { - map_range = false; + //didn't expand an existing region, make a new one + mMappedVertexRegions.push_back({ start, end }); } return mMappedData+mOffsets[type]+sTypeSize[type]*index; } -U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range) +U8* LLVertexBuffer::mapIndexBuffer(U32 index, S32 count) { LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; - if (mFinal) - { - LL_ERRS() << "LLVertexBuffer::mapIndexBuffer() called on a finalized buffer." << LL_ENDL; - } - if (!useVBOs() && !mMappedData && !mMappedIndexData) + + if (count == -1) { - LL_ERRS() << "LLVertexBuffer::mapIndexBuffer() called on unallocated buffer." << LL_ENDL; + count = mNumIndices-index; } - if (useVBOs()) - { - if (count == -1) - { - count = mNumIndices-index; - } - - S32 start = sizeof(U16) * index; - S32 end = start + sizeof(U16) * count; - - bool flagged = false; - // flag region as mapped - for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) - { - MappedRegion& region = mMappedIndexRegions[i]; - if (expand_region(region, start, end)) - { - flagged = true; - break; - } - } + U32 start = sizeof(U16) * index; + U32 end = start + sizeof(U16) * count-1; - if (!flagged) + bool flagged = false; + // flag region as mapped + for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) + { + MappedRegion& region = mMappedIndexRegions[i]; + if (expand_region(region, start, end)) { - //didn't expand an existing region, make a new one - mMappedIndexRegions.push_back({ start, end }); + flagged = true; + break; } + } - if (mIndexLocked && map_range) - { - LL_ERRS() << "Attempted to map a specific range of a buffer that was already mapped." << LL_ENDL; - } - - if (!mIndexLocked) - { - mIndexLocked = true; - sMappedCount++; - stop_glerror(); - - map_range = false; - } - - if (!mMappedIndexData) - { - log_glerror(); - LLMemory::logMemoryInfo(true); - - LL_ERRS() << "memory allocation for Index data failed. " << LL_ENDL; - } - } - else - { - map_range = false; - } + if (!flagged) + { + //didn't expand an existing region, make a new one + mMappedIndexRegions.push_back({ start, end }); + } return mMappedIndexData + sizeof(U16)*index; } -static void flush_vbo(GLenum target, S32 start, S32 end, void* data) +// flush the given byte range +// target -- "targret" parameter for glBufferSubData +// start -- first byte to copy +// end -- last byte to copy (NOT last byte + 1) +// data -- mMappedData or mMappedIndexData +static void flush_vbo(GLenum target, U32 start, U32 end, void* data) { if (end != 0) { @@ -1455,122 +1137,109 @@ static void flush_vbo(GLenum target, S32 start, S32 end, void* data) LL_PROFILE_ZONE_NUM(end); LL_PROFILE_ZONE_NUM(end-start); - constexpr S32 block_size = 65536; + constexpr U32 block_size = 8192; - for (S32 i = start; i < end; i += block_size) + for (U32 i = start; i <= end; i += block_size) { LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("glBufferSubData block"); - LL_PROFILE_GPU_ZONE("glBufferSubData"); - S32 tend = llmin(i + block_size, end); - glBufferSubData(target, i, tend - i, (U8*) data + (i-start)); + //LL_PROFILE_GPU_ZONE("glBufferSubData"); + U32 tend = llmin(i + block_size, end); + glBufferSubData(target, i, tend - i+1, (U8*) data + (i-start)); } } } void LLVertexBuffer::unmapBuffer() { - if (!useVBOs()) - { - return; //nothing to unmap - } + struct SortMappedRegion + { + bool operator()(const MappedRegion& lhs, const MappedRegion& rhs) + { + return lhs.mStart < rhs.mStart; + } + }; - bool updated_all = false; - LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; - if (mMappedData && mVertexLocked) + if (!mMappedVertexRegions.empty()) { LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("unmapBuffer - vertex"); - bindGLBuffer(true); - updated_all = mIndexLocked; //both vertex and index buffers done updating - - if (!mMappedVertexRegions.empty()) - { - S32 start = 0; - S32 end = 0; - - for (U32 i = 0; i < mMappedVertexRegions.size(); ++i) - { - const MappedRegion& region = mMappedVertexRegions[i]; - if (region.mStart == end + 1) - { - end = region.mEnd; - } - else - { - flush_vbo(GL_ARRAY_BUFFER, start, end, (U8*)mMappedData + start); - start = region.mStart; - end = region.mEnd; - } - } + if (sGLRenderBuffer != mGLBuffer) + { + glBindBuffer(GL_ARRAY_BUFFER, mGLBuffer); + sGLRenderBuffer = mGLBuffer; + } + + U32 start = 0; + U32 end = 0; - flush_vbo(GL_ARRAY_BUFFER, start, end, (U8*)mMappedData + start); + std::sort(mMappedVertexRegions.begin(), mMappedVertexRegions.end(), SortMappedRegion()); - mMappedVertexRegions.clear(); - } - else + for (U32 i = 0; i < mMappedVertexRegions.size(); ++i) { - llassert(false); // this shouldn't happen -- a buffer must always be explicitly mapped + const MappedRegion& region = mMappedVertexRegions[i]; + if (region.mStart == end + 1) + { + end = region.mEnd; + } + else + { + flush_vbo(GL_ARRAY_BUFFER, start, end, (U8*)mMappedData + start); + start = region.mStart; + end = region.mEnd; + } } - - mVertexLocked = false; - sMappedCount--; + + flush_vbo(GL_ARRAY_BUFFER, start, end, (U8*)mMappedData + start); + + mMappedVertexRegions.clear(); } - if (mMappedIndexData && mIndexLocked) + if (!mMappedIndexRegions.empty()) { LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("unmapBuffer - index"); - bindGLIndices(); - - if (!mMappedIndexRegions.empty()) - { - S32 start = 0; - S32 end = 0; - for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) + if (mGLIndices != sGLRenderIndices) + { + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mGLIndices); + sGLRenderIndices = mGLIndices; + } + U32 start = 0; + U32 end = 0; + + std::sort(mMappedIndexRegions.begin(), mMappedIndexRegions.end(), SortMappedRegion()); + + for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) + { + const MappedRegion& region = mMappedIndexRegions[i]; + if (region.mStart == end + 1) { - const MappedRegion& region = mMappedIndexRegions[i]; - if (region.mStart == end + 1) - { - end = region.mEnd; - } - else - { - flush_vbo(GL_ELEMENT_ARRAY_BUFFER, start, end, (U8*)mMappedIndexData + start); - start = region.mStart; - end = region.mEnd; - } + end = region.mEnd; } + else + { + flush_vbo(GL_ELEMENT_ARRAY_BUFFER, start, end, (U8*)mMappedIndexData + start); + start = region.mStart; + end = region.mEnd; + } + } - flush_vbo(GL_ELEMENT_ARRAY_BUFFER, start, end, (U8*)mMappedIndexData + start); - - mMappedIndexRegions.clear(); - } - else - { - llassert(false); // this shouldn't happen -- a buffer must always be explicitly mapped - } - - mIndexLocked = false; - sMappedCount--; - } + flush_vbo(GL_ELEMENT_ARRAY_BUFFER, start, end, (U8*)mMappedIndexData + start); - if(updated_all) - { - mEmpty = false; + mMappedIndexRegions.clear(); } } //---------------------------------------------------------------------------- -template struct VertexBufferStrider +template struct VertexBufferStrider { typedef LLStrider strider_t; static bool get(LLVertexBuffer& vbo, strider_t& strider, - S32 index, S32 count, bool map_range) + S32 index, S32 count) { if (type == LLVertexBuffer::TYPE_INDEX) { - U8* ptr = vbo.mapIndexBuffer(index, count, map_range); + U8* ptr = vbo.mapIndexBuffer(index, count); if (ptr == NULL) { @@ -1584,9 +1253,9 @@ template struct VertexBufferStrider } else if (vbo.hasDataType(type)) { - S32 stride = LLVertexBuffer::sTypeSize[type]; + U32 stride = LLVertexBuffer::sTypeSize[type]; - U8* ptr = vbo.mapVertexBuffer(type, index, count, map_range); + U8* ptr = vbo.mapVertexBuffer(type, index, count); if (ptr == NULL) { @@ -1606,500 +1275,157 @@ template struct VertexBufferStrider } }; -bool LLVertexBuffer::getVertexStrider(LLStrider& strider, S32 index, S32 count, bool map_range) +bool LLVertexBuffer::getVertexStrider(LLStrider& strider, U32 index, S32 count) { - return VertexBufferStrider::get(*this, strider, index, count, map_range); + return VertexBufferStrider::get(*this, strider, index, count); } -bool LLVertexBuffer::getVertexStrider(LLStrider& strider, S32 index, S32 count, bool map_range) +bool LLVertexBuffer::getVertexStrider(LLStrider& strider, U32 index, S32 count) { - return VertexBufferStrider::get(*this, strider, index, count, map_range); + return VertexBufferStrider::get(*this, strider, index, count); } -bool LLVertexBuffer::getIndexStrider(LLStrider& strider, S32 index, S32 count, bool map_range) +bool LLVertexBuffer::getIndexStrider(LLStrider& strider, U32 index, S32 count) { - return VertexBufferStrider::get(*this, strider, index, count, map_range); + return VertexBufferStrider::get(*this, strider, index, count); } -bool LLVertexBuffer::getTexCoord0Strider(LLStrider& strider, S32 index, S32 count, bool map_range) +bool LLVertexBuffer::getTexCoord0Strider(LLStrider& strider, U32 index, S32 count) { - return VertexBufferStrider::get(*this, strider, index, count, map_range); + return VertexBufferStrider::get(*this, strider, index, count); } -bool LLVertexBuffer::getTexCoord1Strider(LLStrider& strider, S32 index, S32 count, bool map_range) +bool LLVertexBuffer::getTexCoord1Strider(LLStrider& strider, U32 index, S32 count) { - return VertexBufferStrider::get(*this, strider, index, count, map_range); + return VertexBufferStrider::get(*this, strider, index, count); } -bool LLVertexBuffer::getTexCoord2Strider(LLStrider& strider, S32 index, S32 count, bool map_range) +bool LLVertexBuffer::getTexCoord2Strider(LLStrider& strider, U32 index, S32 count) { - return VertexBufferStrider::get(*this, strider, index, count, map_range); + return VertexBufferStrider::get(*this, strider, index, count); } -bool LLVertexBuffer::getNormalStrider(LLStrider& strider, S32 index, S32 count, bool map_range) +bool LLVertexBuffer::getNormalStrider(LLStrider& strider, U32 index, S32 count) { - return VertexBufferStrider::get(*this, strider, index, count, map_range); + return VertexBufferStrider::get(*this, strider, index, count); } -bool LLVertexBuffer::getTangentStrider(LLStrider& strider, S32 index, S32 count, bool map_range) +bool LLVertexBuffer::getTangentStrider(LLStrider& strider, U32 index, S32 count) { - return VertexBufferStrider::get(*this, strider, index, count, map_range); + return VertexBufferStrider::get(*this, strider, index, count); } -bool LLVertexBuffer::getTangentStrider(LLStrider& strider, S32 index, S32 count, bool map_range) +bool LLVertexBuffer::getTangentStrider(LLStrider& strider, U32 index, S32 count) { - return VertexBufferStrider::get(*this, strider, index, count, map_range); + return VertexBufferStrider::get(*this, strider, index, count); } -bool LLVertexBuffer::getColorStrider(LLStrider& strider, S32 index, S32 count, bool map_range) +bool LLVertexBuffer::getColorStrider(LLStrider& strider, U32 index, S32 count) { - return VertexBufferStrider::get(*this, strider, index, count, map_range); + return VertexBufferStrider::get(*this, strider, index, count); } -bool LLVertexBuffer::getEmissiveStrider(LLStrider& strider, S32 index, S32 count, bool map_range) +bool LLVertexBuffer::getEmissiveStrider(LLStrider& strider, U32 index, S32 count) { - return VertexBufferStrider::get(*this, strider, index, count, map_range); + return VertexBufferStrider::get(*this, strider, index, count); } -bool LLVertexBuffer::getWeightStrider(LLStrider& strider, S32 index, S32 count, bool map_range) +bool LLVertexBuffer::getWeightStrider(LLStrider& strider, U32 index, S32 count) { - return VertexBufferStrider::get(*this, strider, index, count, map_range); + return VertexBufferStrider::get(*this, strider, index, count); } -bool LLVertexBuffer::getWeight4Strider(LLStrider& strider, S32 index, S32 count, bool map_range) +bool LLVertexBuffer::getWeight4Strider(LLStrider& strider, U32 index, S32 count) { - return VertexBufferStrider::get(*this, strider, index, count, map_range); + return VertexBufferStrider::get(*this, strider, index, count); } -bool LLVertexBuffer::getClothWeightStrider(LLStrider& strider, S32 index, S32 count, bool map_range) +bool LLVertexBuffer::getClothWeightStrider(LLStrider& strider, U32 index, S32 count) { - return VertexBufferStrider::get(*this, strider, index, count, map_range); + return VertexBufferStrider::get(*this, strider, index, count); } //---------------------------------------------------------------------------- -bool LLVertexBuffer::bindGLBuffer(bool force_bind) + +// Set for rendering +void LLVertexBuffer::setBuffer() { - bool ret = false; + // no data may be pending + llassert(mMappedVertexRegions.empty()); + llassert(mMappedIndexRegions.empty()); - if (useVBOs() && (force_bind || (mGLBuffer && (mGLBuffer != sGLRenderBuffer || !sVBOActive)))) - { - LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; - glBindBuffer(GL_ARRAY_BUFFER, mGLBuffer); - sGLRenderBuffer = mGLBuffer; - sBindCount++; - sVBOActive = true; - ret = true; - } + // a shader must be bound + llassert(LLGLSLShader::sCurBoundShaderPtr); - return ret; -} + U32 data_mask = LLGLSLShader::sCurBoundShaderPtr->mAttributeMask; -bool LLVertexBuffer::bindGLBufferFast() -{ - if (mGLBuffer != sGLRenderBuffer || !sVBOActive) + // this Vertex Buffer must provide all necessary attributes for currently bound shader + llassert(((~data_mask & mTypeMask) > 0) || (mTypeMask == data_mask)); + + if (sGLRenderBuffer != mGLBuffer) { glBindBuffer(GL_ARRAY_BUFFER, mGLBuffer); sGLRenderBuffer = mGLBuffer; - sBindCount++; - sVBOActive = true; - return true; - } - - return false; -} - -bool LLVertexBuffer::bindGLIndices(bool force_bind) -{ - LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; - - bool ret = false; - if (useVBOs() && (force_bind || (mGLIndices && (mGLIndices != sGLRenderIndices || !sIBOActive)))) - { - /*if (sMapped) - { - LL_ERRS() << "VBO bound while another VBO mapped!" << LL_ENDL; - }*/ - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mGLIndices); - sGLRenderIndices = mGLIndices; - stop_glerror(); - sBindCount++; - sIBOActive = true; - ret = true; - } - - return ret; -} - -bool LLVertexBuffer::bindGLIndicesFast() -{ - if (mGLIndices != sGLRenderIndices || !sIBOActive) - { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mGLIndices); - sGLRenderIndices = mGLIndices; - sBindCount++; - sIBOActive = true; - - return true; + setupVertexBuffer(); } - - return false; -} - -void LLVertexBuffer::flush(bool discard) -{ - if (useVBOs()) - { - unmapBuffer(); - } -} - -// bind for transform feedback (quick 'n dirty) -void LLVertexBuffer::bindForFeedback(U32 channel, U32 type, U32 index, U32 count) -{ -#ifdef GL_TRANSFORM_FEEDBACK_BUFFER - U32 offset = mOffsets[type] + sTypeSize[type]*index; - U32 size= (sTypeSize[type]*count); - glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, channel, mGLBuffer, offset, size); -#endif -} - -// Set for rendering -void LLVertexBuffer::setBuffer(U32 data_mask) -{ - flush(); - - //set up pointers if the data mask is different ... - bool setup = (sLastMask != data_mask); - - if (gDebugGL && data_mask != 0) - { //make sure data requirements are fulfilled - LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr; - if (shader) - { - U32 required_mask = 0; - for (U32 i = 0; i < LLVertexBuffer::TYPE_TEXTURE_INDEX; ++i) - { - if (shader->getAttribLocation(i) > -1) - { - U32 required = 1 << i; - if ((data_mask & required) == 0) - { - LL_WARNS() << "Missing attribute: " << LLShaderMgr::instance()->mReservedAttribs[i] << LL_ENDL; - } - - required_mask |= required; - } - } - - if ((data_mask & required_mask) != required_mask) - { - - U32 unsatisfied_mask = (required_mask & ~data_mask); - - for (U32 i = 0; i < TYPE_MAX; i++) - { - U32 unsatisfied_flag = unsatisfied_mask & (1 << i); - switch (unsatisfied_flag) - { - case 0: break; - case MAP_VERTEX: LL_INFOS() << "Missing vert pos" << LL_ENDL; break; - case MAP_NORMAL: LL_INFOS() << "Missing normals" << LL_ENDL; break; - case MAP_TEXCOORD0: LL_INFOS() << "Missing TC 0" << LL_ENDL; break; - case MAP_TEXCOORD1: LL_INFOS() << "Missing TC 1" << LL_ENDL; break; - case MAP_TEXCOORD2: LL_INFOS() << "Missing TC 2" << LL_ENDL; break; - case MAP_TEXCOORD3: LL_INFOS() << "Missing TC 3" << LL_ENDL; break; - case MAP_COLOR: LL_INFOS() << "Missing vert color" << LL_ENDL; break; - case MAP_EMISSIVE: LL_INFOS() << "Missing emissive" << LL_ENDL; break; - case MAP_TANGENT: LL_INFOS() << "Missing tangent" << LL_ENDL; break; - case MAP_WEIGHT: LL_INFOS() << "Missing weight" << LL_ENDL; break; - case MAP_WEIGHT4: LL_INFOS() << "Missing weightx4" << LL_ENDL; break; - case MAP_CLOTHWEIGHT: LL_INFOS() << "Missing clothweight" << LL_ENDL; break; - case MAP_TEXTURE_INDEX: LL_INFOS() << "Missing tex index" << LL_ENDL; break; - default: LL_INFOS() << "Missing who effin knows: " << unsatisfied_flag << LL_ENDL; - } - } - - // TYPE_INDEX is beyond TYPE_MAX, so check for it individually - if (unsatisfied_mask & (1 << TYPE_INDEX)) - { - LL_INFOS() << "Missing indices" << LL_ENDL; - } - - LL_ERRS() << "Shader consumption mismatches data provision." << LL_ENDL; - } - } - } - - if (useVBOs()) - { - const bool bindBuffer = bindGLBuffer(); - const bool bindIndices = bindGLIndices(); - - setup = setup || bindBuffer || bindIndices; - - if (gDebugGL) - { - GLint buff; - glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &buff); - if ((GLuint)buff != mGLBuffer) - { - if (gDebugSession) - { - gFailLog << "Invalid GL vertex buffer bound: " << buff << std::endl; - } - else - { - LL_ERRS() << "Invalid GL vertex buffer bound: " << buff << LL_ENDL; - } - } - - if (mGLIndices) - { - glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &buff); - if ((GLuint)buff != mGLIndices) - { - if (gDebugSession) - { - gFailLog << "Invalid GL index buffer bound: " << buff << std::endl; - } - else - { - LL_ERRS() << "Invalid GL index buffer bound: " << buff << LL_ENDL; - } - } - } - } - - - } - else - { - if (sGLRenderArray) - { - glBindVertexArray(0); - sGLRenderArray = 0; - sGLRenderIndices = 0; - sIBOActive = false; - } - - if (mGLBuffer) - { - if (sVBOActive) - { - glBindBuffer(GL_ARRAY_BUFFER, 0); - sBindCount++; - sVBOActive = false; - setup = true; // ... or a VBO is deactivated - } - if (sGLRenderBuffer != mGLBuffer) - { - sGLRenderBuffer = mGLBuffer; - setup = true; // ... or a client memory pointer changed - } - } - if (mGLIndices) - { - if (sIBOActive) - { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - sBindCount++; - sIBOActive = false; - } - - sGLRenderIndices = mGLIndices; - } - } - - setupClientArrays(data_mask); - - if (mGLBuffer) - { - if (data_mask && setup) - { - setupVertexBuffer(data_mask); // subclass specific setup (virtual function) - sSetCount++; - } - } -} - -void LLVertexBuffer::setBufferFast(U32 data_mask) -{ - if (useVBOs()) + else if (sLastMask != data_mask) { - //set up pointers if the data mask is different ... - bool setup = (sLastMask != data_mask); - - const bool bindBuffer = bindGLBufferFast(); - const bool bindIndices = bindGLIndicesFast(); - - setup = setup || bindBuffer || bindIndices; - - setupClientArrays(data_mask); - - if (data_mask && setup) - { - setupVertexBufferFast(data_mask); - sSetCount++; - } + setupVertexBuffer(); + sLastMask = data_mask; } - else + + if (mGLIndices != sGLRenderIndices) { - //fallback to slow path when not using VBOs - setBuffer(data_mask); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mGLIndices); + sGLRenderIndices = mGLIndices; } } // virtual (default) -void LLVertexBuffer::setupVertexBuffer(U32 data_mask) -{ - stop_glerror(); - U8* base = useVBOs() ? nullptr: mMappedData; - - if (gDebugGL && ((data_mask & mTypeMask) != data_mask)) - { - for (U32 i = 0; i < LLVertexBuffer::TYPE_MAX; ++i) - { - U32 mask = 1 << i; - if (mask & data_mask && !(mask & mTypeMask)) - { //bit set in data_mask, but not set in mTypeMask - LL_WARNS() << "Missing required component " << vb_type_name[i] << LL_ENDL; - } - } - LL_ERRS() << "LLVertexBuffer::setupVertexBuffer missing required components for supplied data mask." << LL_ENDL; - } - - if (data_mask & MAP_NORMAL) - { - S32 loc = TYPE_NORMAL; - void* ptr = (void*)(base + mOffsets[TYPE_NORMAL]); - glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_NORMAL], ptr); - } - if (data_mask & MAP_TEXCOORD3) - { - S32 loc = TYPE_TEXCOORD3; - void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD3]); - glVertexAttribPointer(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD3], ptr); - } - if (data_mask & MAP_TEXCOORD2) - { - S32 loc = TYPE_TEXCOORD2; - void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD2]); - glVertexAttribPointer(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD2], ptr); - } - if (data_mask & MAP_TEXCOORD1) - { - S32 loc = TYPE_TEXCOORD1; - void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD1]); - glVertexAttribPointer(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD1], ptr); - } - if (data_mask & MAP_TANGENT) - { - S32 loc = TYPE_TANGENT; - void* ptr = (void*)(base + mOffsets[TYPE_TANGENT]); - glVertexAttribPointer(loc, 4,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TANGENT], ptr); - } - if (data_mask & MAP_TEXCOORD0) - { - S32 loc = TYPE_TEXCOORD0; - void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD0]); - glVertexAttribPointer(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD0], ptr); - } - if (data_mask & MAP_COLOR) - { - S32 loc = TYPE_COLOR; - //bind emissive instead of color pointer if emissive is present - void* ptr = (data_mask & MAP_EMISSIVE) ? (void*)(base + mOffsets[TYPE_EMISSIVE]) : (void*)(base + mOffsets[TYPE_COLOR]); - glVertexAttribPointer(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_COLOR], ptr); - } - if (data_mask & MAP_EMISSIVE) - { - S32 loc = TYPE_EMISSIVE; - void* ptr = (void*)(base + mOffsets[TYPE_EMISSIVE]); - glVertexAttribPointer(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_EMISSIVE], ptr); - - if (!(data_mask & MAP_COLOR)) - { //map emissive to color channel when color is not also being bound to avoid unnecessary shader swaps - loc = TYPE_COLOR; - glVertexAttribPointer(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_EMISSIVE], ptr); - } - } - if (data_mask & MAP_WEIGHT) - { - S32 loc = TYPE_WEIGHT; - void* ptr = (void*)(base + mOffsets[TYPE_WEIGHT]); - glVertexAttribPointer(loc, 1, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_WEIGHT], ptr); - } - if (data_mask & MAP_WEIGHT4) - { - S32 loc = TYPE_WEIGHT4; - void* ptr = (void*)(base+mOffsets[TYPE_WEIGHT4]); - glVertexAttribPointer(loc, 4, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_WEIGHT4], ptr); - } - if (data_mask & MAP_CLOTHWEIGHT) - { - S32 loc = TYPE_CLOTHWEIGHT; - void* ptr = (void*)(base + mOffsets[TYPE_CLOTHWEIGHT]); - glVertexAttribPointer(loc, 4, GL_FLOAT, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_CLOTHWEIGHT], ptr); - } - if (data_mask & MAP_TEXTURE_INDEX && - (gGLManager.mGLSLVersionMajor >= 2 || gGLManager.mGLSLVersionMinor >= 30)) //indexed texture rendering requires GLSL 1.30 or later - { - S32 loc = TYPE_TEXTURE_INDEX; - void *ptr = (void*) (base + mOffsets[TYPE_VERTEX] + 12); - glVertexAttribIPointer(loc, 1, GL_UNSIGNED_INT, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); - } - if (data_mask & MAP_VERTEX) - { - S32 loc = TYPE_VERTEX; - void* ptr = (void*)(base + mOffsets[TYPE_VERTEX]); - glVertexAttribPointer(loc, 3,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); - } - - llglassertok(); - } - -void LLVertexBuffer::setupVertexBufferFast(U32 data_mask) +void LLVertexBuffer::setupVertexBuffer() { U8* base = nullptr; + U32 data_mask = LLGLSLShader::sCurBoundShaderPtr->mAttributeMask; + if (data_mask & MAP_NORMAL) { - S32 loc = TYPE_NORMAL; + AttributeType loc = TYPE_NORMAL; void* ptr = (void*)(base + mOffsets[TYPE_NORMAL]); glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_NORMAL], ptr); } if (data_mask & MAP_TEXCOORD3) { - S32 loc = TYPE_TEXCOORD3; + AttributeType loc = TYPE_TEXCOORD3; void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD3]); glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD3], ptr); } if (data_mask & MAP_TEXCOORD2) { - S32 loc = TYPE_TEXCOORD2; + AttributeType loc = TYPE_TEXCOORD2; void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD2]); glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD2], ptr); } if (data_mask & MAP_TEXCOORD1) { - S32 loc = TYPE_TEXCOORD1; + AttributeType loc = TYPE_TEXCOORD1; void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD1]); glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD1], ptr); } if (data_mask & MAP_TANGENT) { - S32 loc = TYPE_TANGENT; + AttributeType loc = TYPE_TANGENT; void* ptr = (void*)(base + mOffsets[TYPE_TANGENT]); glVertexAttribPointer(loc, 4, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TANGENT], ptr); } if (data_mask & MAP_TEXCOORD0) { - S32 loc = TYPE_TEXCOORD0; + AttributeType loc = TYPE_TEXCOORD0; void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD0]); glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD0], ptr); } if (data_mask & MAP_COLOR) { - S32 loc = TYPE_COLOR; + AttributeType loc = TYPE_COLOR; //bind emissive instead of color pointer if emissive is present void* ptr = (data_mask & MAP_EMISSIVE) ? (void*)(base + mOffsets[TYPE_EMISSIVE]) : (void*)(base + mOffsets[TYPE_COLOR]); glVertexAttribPointer(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_COLOR], ptr); } if (data_mask & MAP_EMISSIVE) { - S32 loc = TYPE_EMISSIVE; + AttributeType loc = TYPE_EMISSIVE; void* ptr = (void*)(base + mOffsets[TYPE_EMISSIVE]); glVertexAttribPointer(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_EMISSIVE], ptr); @@ -2111,31 +1437,31 @@ void LLVertexBuffer::setupVertexBufferFast(U32 data_mask) } if (data_mask & MAP_WEIGHT) { - S32 loc = TYPE_WEIGHT; + AttributeType loc = TYPE_WEIGHT; void* ptr = (void*)(base + mOffsets[TYPE_WEIGHT]); glVertexAttribPointer(loc, 1, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_WEIGHT], ptr); } if (data_mask & MAP_WEIGHT4) { - S32 loc = TYPE_WEIGHT4; + AttributeType loc = TYPE_WEIGHT4; void* ptr = (void*)(base + mOffsets[TYPE_WEIGHT4]); glVertexAttribPointer(loc, 4, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_WEIGHT4], ptr); } if (data_mask & MAP_CLOTHWEIGHT) { - S32 loc = TYPE_CLOTHWEIGHT; + AttributeType loc = TYPE_CLOTHWEIGHT; void* ptr = (void*)(base + mOffsets[TYPE_CLOTHWEIGHT]); glVertexAttribPointer(loc, 4, GL_FLOAT, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_CLOTHWEIGHT], ptr); } if (data_mask & MAP_TEXTURE_INDEX) { - S32 loc = TYPE_TEXTURE_INDEX; + AttributeType loc = TYPE_TEXTURE_INDEX; void* ptr = (void*)(base + mOffsets[TYPE_VERTEX] + 12); glVertexAttribIPointer(loc, 1, GL_UNSIGNED_INT, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); } if (data_mask & MAP_VERTEX) { - S32 loc = TYPE_VERTEX; + AttributeType loc = TYPE_VERTEX; void* ptr = (void*)(base + mOffsets[TYPE_VERTEX]); glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); } @@ -2143,20 +1469,20 @@ void LLVertexBuffer::setupVertexBufferFast(U32 data_mask) void LLVertexBuffer::setPositionData(const LLVector4a* data) { - bindGLBuffer(); - flush_vbo(GL_ARRAY_BUFFER, 0, sizeof(LLVector4a) * getNumVerts(), (U8*) data); + llassert(sGLRenderBuffer == mGLBuffer); + flush_vbo(GL_ARRAY_BUFFER, 0, sizeof(LLVector4a) * getNumVerts()-1, (U8*) data); } void LLVertexBuffer::setTexCoordData(const LLVector2* data) { - bindGLBuffer(); - flush_vbo(GL_ARRAY_BUFFER, mOffsets[TYPE_TEXCOORD0], mOffsets[TYPE_TEXCOORD0] + sTypeSize[TYPE_TEXCOORD0] * getNumVerts(), (U8*)data); + llassert(sGLRenderBuffer == mGLBuffer); + flush_vbo(GL_ARRAY_BUFFER, mOffsets[TYPE_TEXCOORD0], mOffsets[TYPE_TEXCOORD0] + sTypeSize[TYPE_TEXCOORD0] * getNumVerts() - 1, (U8*)data); } void LLVertexBuffer::setColorData(const LLColor4U* data) { - bindGLBuffer(); - flush_vbo(GL_ARRAY_BUFFER, mOffsets[TYPE_COLOR], mOffsets[TYPE_COLOR] + sTypeSize[TYPE_COLOR] * getNumVerts(), (U8*) data); + llassert(sGLRenderBuffer == mGLBuffer); + flush_vbo(GL_ARRAY_BUFFER, mOffsets[TYPE_COLOR], mOffsets[TYPE_COLOR] + sTypeSize[TYPE_COLOR] * getNumVerts() - 1, (U8*) data); } -- cgit v1.2.3 From 984bdcd9d9622cedd17d3d33ecae6b726860dd94 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 20 Jan 2023 18:25:53 -0600 Subject: SL-18869 Followup -- AMD compatibility pass. --- indra/llrender/llvertexbuffer.cpp | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index f1d71ec94d..028db79566 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -260,19 +260,30 @@ static GLWorkQueue* sQueue = nullptr; static GLuint gen_buffer() { LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; - constexpr U32 pool_size = 4096; - thread_local static GLuint sNamePool[pool_size]; - thread_local static U32 sIndex = 0; + GLuint ret = 0; + if (!gGLManager.mIsAMD) + { + constexpr U32 pool_size = 4096; + + thread_local static GLuint sNamePool[pool_size]; + thread_local static U32 sIndex = 0; + + if (sIndex == 0) + { + LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("gen buffer"); + sIndex = pool_size; + glGenBuffers(pool_size, sNamePool); + } - if (sIndex == 0) + ret = sNamePool[--sIndex]; + } + else { - LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("gen buffer"); - sIndex = pool_size; - glGenBuffers(pool_size, sNamePool); + glGenBuffers(1, &ret); } - return sNamePool[--sIndex]; + return ret; } #define ANALYZE_VBO_POOL 0 @@ -725,7 +736,6 @@ void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indi llassert(mGLBuffer == sGLRenderBuffer); llassert(mGLIndices == sGLRenderIndices); gGL.syncMatrices(); - glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT, (GLvoid*) (indices_offset * sizeof(U16))); } @@ -1144,7 +1154,8 @@ static void flush_vbo(GLenum target, U32 start, U32 end, void* data) LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("glBufferSubData block"); //LL_PROFILE_GPU_ZONE("glBufferSubData"); U32 tend = llmin(i + block_size, end); - glBufferSubData(target, i, tend - i+1, (U8*) data + (i-start)); + U32 size = tend - i + 1; + glBufferSubData(target, i, size, (U8*) data + (i-start)); } } } -- cgit v1.2.3 From 274da636a00fd0469f7857dad7995cb11552e4ab Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 23 Jan 2023 11:48:43 -0600 Subject: SL-18869 Followup -- AMD optimization pass. --- indra/llrender/llvertexbuffer.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 028db79566..40ab4a2e0f 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -262,27 +262,29 @@ static GLuint gen_buffer() LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX; GLuint ret = 0; - if (!gGLManager.mIsAMD) - { - constexpr U32 pool_size = 4096; + constexpr U32 pool_size = 4096; - thread_local static GLuint sNamePool[pool_size]; - thread_local static U32 sIndex = 0; + thread_local static GLuint sNamePool[pool_size]; + thread_local static U32 sIndex = 0; - if (sIndex == 0) + if (sIndex == 0) + { + LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("gen buffer"); + sIndex = pool_size; + if (!gGLManager.mIsAMD) { - LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("gen buffer"); - sIndex = pool_size; glGenBuffers(pool_size, sNamePool); } - - ret = sNamePool[--sIndex]; - } - else - { - glGenBuffers(1, &ret); + else + { // work around for AMD driver bug + for (U32 i = 0; i < pool_size; ++i) + { + glGenBuffers(1, sNamePool + i); + } + } } + ret = sNamePool[--sIndex]; return ret; } -- cgit v1.2.3 From 3ef31cb9b28f7b026e109eab69d383dddc922850 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Fri, 27 Jan 2023 17:24:22 -0600 Subject: SL-19203 et al -- Integrate SSR with reflection probes, tweak probe blending. (#63) * SL-19203 WIP -- Integrate SSR with reflection probes. Decruft LLRenderTarget. * SL-19203 WIP -- Re-integrate SSR. Incidental decruft. * SL-19203 WIP -- SSR frame delta correction (still broken for Z) * SL-19203 WIP -- SSR frame delta Z fix * SL-19203 WIP -- Make SSR toggleable again and disable SSR in cube snapshots. * SL-19203 WIP -- Soften sphere probe transitions and fix reflections on void water (make fallback probe a simple terrain+water+sky probe). Remove parallax correction for automatic probes to reduce artifacts. * SL-19203 Tune probe blending. * SL-19203 Cleanup. --- 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 40ab4a2e0f..11e2b6e5c4 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -744,7 +744,7 @@ void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indi void LLVertexBuffer::draw(U32 mode, U32 count, U32 indices_offset) const { - drawRange(mode, 0, mNumVerts, count, indices_offset); + drawRange(mode, 0, mNumVerts-1, count, indices_offset); } -- cgit v1.2.3 From 78e7ada94bc48a7e42f96fa2b716e8f9ff8bc580 Mon Sep 17 00:00:00 2001 From: Brad Linden Date: Mon, 27 Feb 2023 16:39:11 -0800 Subject: Mac shader and assertion fixes for DRTVWR-559 --- 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 11e2b6e5c4..9fb5eef3a2 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -1363,7 +1363,7 @@ void LLVertexBuffer::setBuffer() U32 data_mask = LLGLSLShader::sCurBoundShaderPtr->mAttributeMask; // this Vertex Buffer must provide all necessary attributes for currently bound shader - llassert(((~data_mask & mTypeMask) > 0) || (mTypeMask == data_mask)); + llassert((data_mask & mTypeMask) == data_mask); if (sGLRenderBuffer != mGLBuffer) { -- cgit v1.2.3 From 8564da58315d015bc2cd60e5f15395e4173d9adc Mon Sep 17 00:00:00 2001 From: Brad Linden Date: Mon, 6 Mar 2023 11:31:29 -0800 Subject: Improved detail for llvertexbuffer attribute mask assertion failure in DRTVWR-559 --- indra/llrender/llvertexbuffer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 9fb5eef3a2..e5e6882ba1 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -1363,7 +1363,8 @@ void LLVertexBuffer::setBuffer() U32 data_mask = LLGLSLShader::sCurBoundShaderPtr->mAttributeMask; // this Vertex Buffer must provide all necessary attributes for currently bound shader - llassert((data_mask & mTypeMask) == data_mask); + llassert_msg((data_mask & mTypeMask) == data_mask, + "Attribute mask mismatch! mTypeMask should be a superset of data_mask. data_mask: 0x" << std::hex << data_mask << " mTypeMask: 0x" << mTypeMask << std::dec); if (sGLRenderBuffer != mGLBuffer) { -- cgit v1.2.3 From 25ede8638209fac8dde5b71bece4bc1dfa30ea16 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 10 Mar 2023 10:52:35 -0600 Subject: SL-19172 Texture streaming tune up. Incidental decruft. --- indra/llrender/llvertexbuffer.cpp | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index e5e6882ba1..cf4964169a 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -314,13 +314,16 @@ public: U32 mTouchCount = 0; -#if ANALYZE_VBO_POOL U64 mDistributed = 0; U64 mAllocated = 0; U64 mReserved = 0; U32 mMisses = 0; U32 mHits = 0; -#endif + + U64 getVramBytesUsed() + { + return mAllocated + mReserved; + } // increase the size to some common value (e.g. a power of two) to increase hit rate void adjustSize(U32& size) @@ -341,13 +344,9 @@ public: llassert(data == nullptr); // non null data indicates a buffer that wasn't freed llassert(size >= 2); // any buffer size smaller than a single index is nonsensical -#if ANALYZE_VBO_POOL mDistributed += size; adjustSize(size); mAllocated += size; -#else - adjustSize(size); -#endif auto& pool = type == GL_ELEMENT_ARRAY_BUFFER ? mIBOPool : mVBOPool; @@ -357,9 +356,7 @@ public: LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("vbo pool miss"); LL_PROFILE_GPU_ZONE("vbo alloc"); -#if ANALYZE_VBO_POOL mMisses++; -#endif name = gen_buffer(); glBindBuffer(type, name); glBufferData(type, size, nullptr, GL_DYNAMIC_DRAW); @@ -376,11 +373,9 @@ public: } else { -#if ANALYZE_VBO_POOL mHits++; llassert(mReserved >= size); // assert if accounting gets messed up mReserved -= size; -#endif std::list& entries = iter->second; Entry& entry = entries.back(); @@ -407,16 +402,12 @@ public: clean(); -#if ANALYZE_VBO_POOL llassert(mDistributed >= size); mDistributed -= size; adjustSize(size); llassert(mAllocated >= size); mAllocated -= size; mReserved += size; -#else - adjustSize(size); -#endif auto& pool = type == GL_ELEMENT_ARRAY_BUFFER ? mIBOPool : mVBOPool; @@ -465,10 +456,8 @@ public: auto& entry = entries.back(); ll_aligned_free_16(entry.mData); glDeleteBuffers(1, &entry.mGLName); -#if ANALYZE_VBO_POOL llassert(mReserved >= iter->first); mReserved -= iter->first; -#endif entries.pop_back(); } @@ -484,7 +473,7 @@ public: } } -#if ANALYZE_VBO_POOL +#if 0 LL_INFOS() << llformat("(%d/%d)/%d MB (distributed/allocated)/total in VBO Pool. Overhead: %d percent. Hit rate: %d percent", mDistributed / 1000000, mAllocated / 1000000, @@ -515,9 +504,7 @@ public: } } -#if ANALYZE_VBO_POOL mReserved = 0; -#endif mIBOPool.clear(); mVBOPool.clear(); @@ -528,6 +515,12 @@ public: static LLVBOPool* sVBOPool = nullptr; +//static +U64 LLVertexBuffer::getBytesAllocated() +{ + return sVBOPool ? sVBOPool->getVramBytesUsed() : 0; +} + //============================================================================ // //static -- cgit v1.2.3 From bd4b03de8b73ecb888f8e3111bada7c643f7fcfd Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 10 Mar 2023 13:33:36 -0600 Subject: DRTVWR-559 Fix for assert in LLVertexBuffer, incidental decruft. --- indra/llrender/llvertexbuffer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index cf4964169a..dd0ea0096c 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -1357,7 +1357,8 @@ void LLVertexBuffer::setBuffer() // this Vertex Buffer must provide all necessary attributes for currently bound shader llassert_msg((data_mask & mTypeMask) == data_mask, - "Attribute mask mismatch! mTypeMask should be a superset of data_mask. data_mask: 0x" << std::hex << data_mask << " mTypeMask: 0x" << mTypeMask << std::dec); + "Attribute mask mismatch! mTypeMask should be a superset of data_mask. data_mask: 0x" + << std::hex << data_mask << " mTypeMask: 0x" << mTypeMask << " Missing: 0x" << (data_mask & ~mTypeMask) << std::dec); if (sGLRenderBuffer != mGLBuffer) { -- cgit v1.2.3 From cdc9852f052d804f8b25564ab7d90eb2b79cddd4 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Mon, 15 May 2023 11:01:24 -0500 Subject: SL-19709 Fix for fullbright shiny not factoring out exposure and flickering fullbright alpha. Incidental decruft. --- indra/llrender/llvertexbuffer.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'indra/llrender/llvertexbuffer.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index dd0ea0096c..b5dda23828 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -699,6 +699,16 @@ bool LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_of } } + LLVector4a* v = (LLVector4a*)mMappedData; + + for (U32 i = start; i <= end; ++i) + { + if (!v->isFinite3()) + { + LL_ERRS() << "Non-finite vertex position data detected." << LL_ENDL; + } + } + LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr; if (shader && shader->mFeatures.mIndexedTextureChannels > 1) -- cgit v1.2.3 From 8d0af77d0b931781fd44e83e672f40fdb1ee458e Mon Sep 17 00:00:00 2001 From: Alexander Gavriliuk Date: Tue, 5 Sep 2023 16:54:03 +0200 Subject: SL-19709 Fix for fullbright shiny not factoring out exposure (update) --- 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 b5dda23828..de27636c33 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -703,7 +703,7 @@ bool LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_of for (U32 i = start; i <= end; ++i) { - if (!v->isFinite3()) + if (!v[i].isFinite3()) { LL_ERRS() << "Non-finite vertex position data detected." << LL_ENDL; } -- cgit v1.2.3