From 0d6aa3c0fe184ae00899304cb3f71315f5c73314 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 17 Feb 2022 22:52:23 +0000 Subject: SL-16815 Remove frame stalls from occlusion queries, bumpmap updates, and querying for available video memory. --- indra/newview/lldrawpoolbump.cpp | 203 ++++++++++++++++++++++++--------------- 1 file changed, 127 insertions(+), 76 deletions(-) (limited to 'indra/newview/lldrawpoolbump.cpp') diff --git a/indra/newview/lldrawpoolbump.cpp b/indra/newview/lldrawpoolbump.cpp index 471b0e2c48..20287a7777 100644 --- a/indra/newview/lldrawpoolbump.cpp +++ b/indra/newview/lldrawpoolbump.cpp @@ -54,6 +54,8 @@ // static LLStandardBumpmap gStandardBumpmapList[TEM_BUMPMAP_COUNT]; +LL::WorkQueue::weak_t LLBumpImageList::sMainQueue; +LL::WorkQueue::weak_t LLBumpImageList::sTexUpdateQueue; // static U32 LLStandardBumpmap::sStandardBumpmapCount = 0; @@ -761,6 +763,8 @@ void LLBumpImageList::init() LLStandardBumpmap::init(); LLStandardBumpmap::restoreGL(); + sMainQueue = LL::WorkQueue::getInstance("mainloop"); + sTexUpdateQueue = LL::WorkQueue::getInstance("LLImageGL"); // Share work queue with tex loader. } void LLBumpImageList::clear() @@ -909,10 +913,7 @@ LLViewerTexture* LLBumpImageList::getBrightnessDarknessImage(LLViewerFetchedText } else { - LLPointer raw = new LLImageRaw(1,1,1); - raw->clear(0x77, 0x77, 0xFF, 0xFF); - - (*entries_list)[src_image->getID()] = LLViewerTextureManager::getLocalTexture( raw.get(), TRUE); + (*entries_list)[src_image->getID()] = LLViewerTextureManager::getLocalTexture( TRUE ); bump = (*entries_list)[src_image->getID()]; // In case callback was called immediately and replaced the image } @@ -1043,10 +1044,7 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerTexture *src_vi, LLI iter->second->getWidth() != src->getWidth() || iter->second->getHeight() != src->getHeight()) // bump not cached yet or has changed resolution { //make sure an entry exists for this image - LLPointer raw = new LLImageRaw(1,1,1); - raw->clear(0x77, 0x77, 0xFF, 0xFF); - - entries_list[src_vi->getID()] = LLViewerTextureManager::getLocalTexture( raw.get(), TRUE); + entries_list[src_vi->getID()] = LLViewerTextureManager::getLocalTexture(TRUE); iter = entries_list.find(src_vi->getID()); } } @@ -1166,108 +1164,161 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerTexture *src_vi, LLI } //--------------------------------------------------- - // immediately assign bump to a global smart pointer in case some local smart pointer + // immediately assign bump to a smart pointer in case some local smart pointer // accidentally releases it. - LLPointer bump = LLViewerTextureManager::getLocalTexture( TRUE ); + LLPointer bump = iter->second; if (!LLPipeline::sRenderDeferred) { bump->setExplicitFormat(GL_ALPHA8, GL_ALPHA); - bump->createGLTexture(0, dst_image); + + auto tex_queue = LLImageGLThread::sEnabled ? sTexUpdateQueue.lock() : nullptr; + + if (tex_queue) + { //dispatch creation to background thread + LLImageRaw* dst_ptr = dst_image; + LLViewerTexture* bump_ptr = bump; + dst_ptr->ref(); + bump_ptr->ref(); + tex_queue->post( + [=]() + { + LL_PROFILE_ZONE_NAMED("bil - create texture"); + bump_ptr->createGLTexture(0, dst_ptr); + bump_ptr->unref(); + dst_ptr->unref(); + }); + } + else + { + bump->createGLTexture(0, dst_image); + } } else { //convert to normal map //disable compression on normal maps to prevent errors below bump->getGLTexture()->setAllowCompression(false); + bump->getGLTexture()->setUseMipMaps(TRUE); - { - bump->setExplicitFormat(GL_RGBA8, GL_ALPHA); - bump->createGLTexture(0, dst_image); - } + auto* bump_ptr = bump.get(); + auto* dst_ptr = dst_image.get(); - { - gPipeline.mScreen.bindTarget(); - - LLGLDepthTest depth(GL_FALSE); - LLGLDisable cull(GL_CULL_FACE); - LLGLDisable blend(GL_BLEND); - gGL.setColorMask(TRUE, TRUE); - gNormalMapGenProgram.bind(); + bump_ptr->ref(); + dst_ptr->ref(); - static LLStaticHashedString sNormScale("norm_scale"); - static LLStaticHashedString sStepX("stepX"); - static LLStaticHashedString sStepY("stepY"); + bump_ptr->setExplicitFormat(GL_RGBA8, GL_ALPHA); - gNormalMapGenProgram.uniform1f(sNormScale, gSavedSettings.getF32("RenderNormalMapScale")); - gNormalMapGenProgram.uniform1f(sStepX, 1.f/bump->getWidth()); - gNormalMapGenProgram.uniform1f(sStepY, 1.f/bump->getHeight()); + auto create_texture = [bump_ptr, dst_ptr]() + { + LL_PROFILE_ZONE_NAMED("bil - create texture deferred"); + bump_ptr->createGLTexture(0, dst_ptr); + }; - LLVector2 v((F32) bump->getWidth()/gPipeline.mScreen.getWidth(), - (F32) bump->getHeight()/gPipeline.mScreen.getHeight()); + auto gen_normal_map = [bump_ptr, dst_ptr]() + { + LL_PROFILE_ZONE_NAMED("bil - generate normal map"); + gPipeline.mScreen.bindTarget(); - gGL.getTexUnit(0)->bind(bump); - - S32 width = bump->getWidth(); - S32 height = bump->getHeight(); + LLGLDepthTest depth(GL_FALSE); + LLGLDisable cull(GL_CULL_FACE); + LLGLDisable blend(GL_BLEND); + gGL.setColorMask(TRUE, TRUE); + gNormalMapGenProgram.bind(); - S32 screen_width = gPipeline.mScreen.getWidth(); - S32 screen_height = gPipeline.mScreen.getHeight(); + static LLStaticHashedString sNormScale("norm_scale"); + static LLStaticHashedString sStepX("stepX"); + static LLStaticHashedString sStepY("stepY"); - glViewport(0, 0, screen_width, screen_height); + gNormalMapGenProgram.uniform1f(sNormScale, gSavedSettings.getF32("RenderNormalMapScale")); + gNormalMapGenProgram.uniform1f(sStepX, 1.f / bump_ptr->getWidth()); + gNormalMapGenProgram.uniform1f(sStepY, 1.f / bump_ptr->getHeight()); - for (S32 left = 0; left < width; left += screen_width) - { - S32 right = left + screen_width; - right = llmin(right, width); - - F32 left_tc = (F32) left/ width; - F32 right_tc = (F32) right/width; + LLVector2 v((F32)bump_ptr->getWidth() / gPipeline.mScreen.getWidth(), + (F32)bump_ptr->getHeight() / gPipeline.mScreen.getHeight()); - for (S32 bottom = 0; bottom < height; bottom += screen_height) - { - S32 top = bottom+screen_height; - top = llmin(top, height); + gGL.getTexUnit(0)->bind(bump_ptr); - F32 bottom_tc = (F32) bottom/height; - F32 top_tc = (F32)(bottom+screen_height)/height; - top_tc = llmin(top_tc, 1.f); + S32 width = bump_ptr->getWidth(); + S32 height = bump_ptr->getHeight(); - F32 screen_right = (F32) (right-left)/screen_width; - F32 screen_top = (F32) (top-bottom)/screen_height; + S32 screen_width = gPipeline.mScreen.getWidth(); + S32 screen_height = gPipeline.mScreen.getHeight(); - gGL.begin(LLRender::TRIANGLE_STRIP); - gGL.texCoord2f(left_tc, bottom_tc); - gGL.vertex2f(0, 0); + glViewport(0, 0, screen_width, screen_height); - gGL.texCoord2f(left_tc, top_tc); - gGL.vertex2f(0, screen_top); + for (S32 left = 0; left < width; left += screen_width) + { + S32 right = left + screen_width; + right = llmin(right, width); - gGL.texCoord2f(right_tc, bottom_tc); - gGL.vertex2f(screen_right, 0); + F32 left_tc = (F32)left / width; + F32 right_tc = (F32)right / width; - gGL.texCoord2f(right_tc, top_tc); - gGL.vertex2f(screen_right, screen_top); + for (S32 bottom = 0; bottom < height; bottom += screen_height) + { + S32 top = bottom + screen_height; + top = llmin(top, height); - gGL.end(); + F32 bottom_tc = (F32)bottom / height; + F32 top_tc = (F32)(bottom + screen_height) / height; + top_tc = llmin(top_tc, 1.f); - gGL.flush(); + F32 screen_right = (F32)(right - left) / screen_width; + F32 screen_top = (F32)(top - bottom) / screen_height; - S32 w = right-left; - S32 h = top-bottom; + gGL.begin(LLRender::TRIANGLE_STRIP); + gGL.texCoord2f(left_tc, bottom_tc); + gGL.vertex2f(0, 0); - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, left, bottom, 0, 0, w, h); - } - } + gGL.texCoord2f(left_tc, top_tc); + gGL.vertex2f(0, screen_top); - glGenerateMipmap(GL_TEXTURE_2D); + gGL.texCoord2f(right_tc, bottom_tc); + gGL.vertex2f(screen_right, 0); - gPipeline.mScreen.flush(); + gGL.texCoord2f(right_tc, top_tc); + gGL.vertex2f(screen_right, screen_top); - gNormalMapGenProgram.unbind(); - - //generateNormalMapFromAlpha(dst_image, nrm_image); - } + gGL.end(); + + gGL.flush(); + + S32 w = right - left; + S32 h = top - bottom; + + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, left, bottom, 0, 0, w, h); + } + } + + glGenerateMipmap(GL_TEXTURE_2D); + + gPipeline.mScreen.flush(); + + gNormalMapGenProgram.unbind(); + + //generateNormalMapFromAlpha(dst_image, nrm_image); + + bump_ptr->unref(); + dst_ptr->unref(); + }; + + auto main_queue = LLImageGLThread::sEnabled ? sMainQueue.lock() : nullptr; + + if (main_queue) + { //dispatch creation to background thread + LLImageRaw* dst_ptr = dst_image; + LLViewerTexture* bump_ptr = bump; + dst_ptr->ref(); + bump_ptr->ref(); + + main_queue->postTo(sTexUpdateQueue, create_texture, gen_normal_map); + } + else + { + create_texture(); + gen_normal_map(); + } } iter->second = bump; // derefs (and deletes) old image -- cgit v1.2.3 From 1461e4d437996784cc8afe5d4b3bfa873d3dbfa1 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 18 Feb 2022 15:52:24 -0600 Subject: SL-16815 Fix for crash when disabling ALM. --- indra/newview/lldrawpoolbump.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indra/newview/lldrawpoolbump.cpp') diff --git a/indra/newview/lldrawpoolbump.cpp b/indra/newview/lldrawpoolbump.cpp index 20287a7777..7d03cb7609 100644 --- a/indra/newview/lldrawpoolbump.cpp +++ b/indra/newview/lldrawpoolbump.cpp @@ -1218,6 +1218,10 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerTexture *src_vi, LLI auto gen_normal_map = [bump_ptr, dst_ptr]() { LL_PROFILE_ZONE_NAMED("bil - generate normal map"); + if (gNormalMapGenProgram.mProgramObject == 0) + { + return; + } gPipeline.mScreen.bindTarget(); LLGLDepthTest depth(GL_FALSE); -- cgit v1.2.3 From 1c5c45f27317d6ee7c2c30de11f43aeee3855434 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 22 Feb 2022 14:58:50 -0600 Subject: SL-16815 Fix for broken media texture updates when multithreaded GL is disabled. --- indra/newview/lldrawpoolbump.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'indra/newview/lldrawpoolbump.cpp') diff --git a/indra/newview/lldrawpoolbump.cpp b/indra/newview/lldrawpoolbump.cpp index 7d03cb7609..0a0cfc5cdf 100644 --- a/indra/newview/lldrawpoolbump.cpp +++ b/indra/newview/lldrawpoolbump.cpp @@ -1311,11 +1311,6 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerTexture *src_vi, LLI if (main_queue) { //dispatch creation to background thread - LLImageRaw* dst_ptr = dst_image; - LLViewerTexture* bump_ptr = bump; - dst_ptr->ref(); - bump_ptr->ref(); - main_queue->postTo(sTexUpdateQueue, create_texture, gen_normal_map); } else -- cgit v1.2.3 From 74641a121316a13e106d525fb1684c517791766d Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 22 Feb 2022 19:48:01 -0600 Subject: SL-16815 Cleanup -- disable multithreaded bumpmap generation while tracking down loading issues, fix sync issue in single threaded mode in media textures, restore LL_IMAGEGL_THREAD_CHECK functionality --- indra/newview/lldrawpoolbump.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'indra/newview/lldrawpoolbump.cpp') diff --git a/indra/newview/lldrawpoolbump.cpp b/indra/newview/lldrawpoolbump.cpp index 0a0cfc5cdf..ce4177d1f8 100644 --- a/indra/newview/lldrawpoolbump.cpp +++ b/indra/newview/lldrawpoolbump.cpp @@ -76,6 +76,8 @@ static S32 cube_channel = -1; static S32 diffuse_channel = -1; static S32 bump_channel = -1; +#define LL_BUMPLIST_MULTITHREADED 0 + // static void LLStandardBumpmap::init() { @@ -1172,6 +1174,7 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerTexture *src_vi, LLI { bump->setExplicitFormat(GL_ALPHA8, GL_ALPHA); +#if LL_BUMPLIST_MULTITHREADED auto tex_queue = LLImageGLThread::sEnabled ? sTexUpdateQueue.lock() : nullptr; if (tex_queue) @@ -1188,8 +1191,10 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerTexture *src_vi, LLI bump_ptr->unref(); dst_ptr->unref(); }); + } else +#endif { bump->createGLTexture(0, dst_image); } @@ -1204,22 +1209,34 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerTexture *src_vi, LLI auto* bump_ptr = bump.get(); auto* dst_ptr = dst_image.get(); +#if LL_BUMPLIST_MULTITHREADED bump_ptr->ref(); dst_ptr->ref(); +#endif bump_ptr->setExplicitFormat(GL_RGBA8, GL_ALPHA); auto create_texture = [bump_ptr, dst_ptr]() { +#if LL_IMAGEGL_THREAD_CHECK + bump_ptr->getGLTexture()->mActiveThread = LLThread::currentID(); +#endif LL_PROFILE_ZONE_NAMED("bil - create texture deferred"); bump_ptr->createGLTexture(0, dst_ptr); }; auto gen_normal_map = [bump_ptr, dst_ptr]() { +#if LL_IMAGEGL_THREAD_CHECK + bump_ptr->getGLTexture()->mActiveThread = LLThread::currentID(); +#endif LL_PROFILE_ZONE_NAMED("bil - generate normal map"); if (gNormalMapGenProgram.mProgramObject == 0) { +#if LL_BUMPLIST_MULTITHREADED + bump_ptr->unref(); + dst_ptr->unref(); +#endif return; } gPipeline.mScreen.bindTarget(); @@ -1302,18 +1319,21 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerTexture *src_vi, LLI gNormalMapGenProgram.unbind(); //generateNormalMapFromAlpha(dst_image, nrm_image); - +#if LL_BUMPLIST_MULTITHREADED bump_ptr->unref(); dst_ptr->unref(); +#endif }; - auto main_queue = LLImageGLThread::sEnabled ? sMainQueue.lock() : nullptr; +#if LL_BUMPLIST_MULTITHREADED + auto main_queue = sMainQueue.lock(); - if (main_queue) + if (LLImageGLThread::sEnabled) { //dispatch creation to background thread main_queue->postTo(sTexUpdateQueue, create_texture, gen_normal_map); } else +#endif { create_texture(); gen_normal_map(); -- cgit v1.2.3 From 8ffe3b7b3047381f9c17d0f09757e921ffc246cb Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 23 Feb 2022 16:04:31 -0600 Subject: Fix for mac build --- indra/newview/lldrawpoolbump.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/lldrawpoolbump.cpp') diff --git a/indra/newview/lldrawpoolbump.cpp b/indra/newview/lldrawpoolbump.cpp index ce4177d1f8..2b151487fd 100644 --- a/indra/newview/lldrawpoolbump.cpp +++ b/indra/newview/lldrawpoolbump.cpp @@ -1216,7 +1216,7 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerTexture *src_vi, LLI bump_ptr->setExplicitFormat(GL_RGBA8, GL_ALPHA); - auto create_texture = [bump_ptr, dst_ptr]() + auto create_texture = [=]() { #if LL_IMAGEGL_THREAD_CHECK bump_ptr->getGLTexture()->mActiveThread = LLThread::currentID(); @@ -1225,7 +1225,7 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerTexture *src_vi, LLI bump_ptr->createGLTexture(0, dst_ptr); }; - auto gen_normal_map = [bump_ptr, dst_ptr]() + auto gen_normal_map = [=]() { #if LL_IMAGEGL_THREAD_CHECK bump_ptr->getGLTexture()->mActiveThread = LLThread::currentID(); -- cgit v1.2.3 From d9a68339d5aa18af349e347d6ed74bc01824cec7 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 23 Feb 2022 16:51:33 -0600 Subject: SL-16815 and SL-16906 Avoid redundant bumpmap generation, add some assertions around ref counting and (hack) fix crash on shutdown from dangling texture reference (reduced to 1 dangling texture from several hundred, can't find the remaining reference). --- indra/newview/lldrawpoolbump.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/lldrawpoolbump.cpp') diff --git a/indra/newview/lldrawpoolbump.cpp b/indra/newview/lldrawpoolbump.cpp index 2b151487fd..1d5419b515 100644 --- a/indra/newview/lldrawpoolbump.cpp +++ b/indra/newview/lldrawpoolbump.cpp @@ -1051,8 +1051,8 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerTexture *src_vi, LLI } } - //if (iter->second->getWidth() != src->getWidth() || - // iter->second->getHeight() != src->getHeight()) // bump not cached yet or has changed resolution + if (iter->second->getWidth() != src->getWidth() || + iter->second->getHeight() != src->getHeight()) // bump not cached yet or has changed resolution { LLPointer dst_image = new LLImageRaw(src->getWidth(), src->getHeight(), 1); U8* dst_data = dst_image->getData(); -- cgit v1.2.3