summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Parks <davep@lindenlab.com>2022-02-22 14:58:50 -0600
committerDave Parks <davep@lindenlab.com>2022-02-22 14:58:50 -0600
commit1c5c45f27317d6ee7c2c30de11f43aeee3855434 (patch)
tree2b62d6c4bbc228db6788ddf54f55d4e2a42a2fba
parent1461e4d437996784cc8afe5d4b3bfa873d3dbfa1 (diff)
SL-16815 Fix for broken media texture updates when multithreaded GL is disabled.
-rw-r--r--indra/llrender/llimagegl.cpp86
-rw-r--r--indra/llrender/llimagegl.h3
-rw-r--r--indra/newview/lldrawpoolbump.cpp5
-rw-r--r--indra/newview/llviewerdisplay.cpp2
4 files changed, 53 insertions, 43 deletions
diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp
index 110074bdc0..10fdd7c9a9 100644
--- a/indra/llrender/llimagegl.cpp
+++ b/indra/llrender/llimagegl.cpp
@@ -1480,7 +1480,7 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S
}
BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_hasmips, S32 usename, bool defer_copy, LLGLuint* tex_name)
- // Call with void data, vmem is allocated but unitialized
+// Call with void data, vmem is allocated but unitialized
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
checkActiveThread();
@@ -1505,7 +1505,8 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_
}
discard_level = llclamp(discard_level, 0, (S32)mMaxDiscardLevel);
- if (main_thread // <--- always force creation of mNewTexName when not on main thread
+ if (main_thread // <--- always force creation of new_texname when not on main thread ...
+ && !defer_copy // <--- ... or defer copy is set
&& mTexName != 0 && discard_level == mCurrentDiscardLevel)
{
LL_PROFILE_ZONE_NAMED("cglt - early setImage");
@@ -1533,7 +1534,7 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_
glTexParameteri(LLTexUnit::getInternalType(mBindTarget), GL_TEXTURE_MAX_LEVEL, mMaxDiscardLevel - discard_level);
}
}
-
+
if (tex_name != nullptr)
{
*tex_name = new_texname;
@@ -1568,22 +1569,23 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_
}
//if we're on the image loading thread, be sure to delete old_texname and update mTexName on the main thread
- if (!main_thread)
+ if (!defer_copy)
{
- if (!defer_copy)
+ if (!main_thread)
{
syncToMainThread(new_texname);
}
- }
- else
- {
- //not on background thread, immediately set mTexName
- if (old_texname != 0)
+ else
{
- LLImageGL::deleteTextures(1, &old_texname);
+ //not on background thread, immediately set mTexName
+ if (old_texname != 0 && old_texname != new_texname)
+ {
+ LLImageGL::deleteTextures(1, &old_texname);
+ }
+ mTexName = new_texname;
}
- mTexName = new_texname;
}
+
mTextureMemory = (S32Bytes)getMipBytes(mCurrentDiscardLevel);
sGlobalTextureMemory += mTextureMemory;
@@ -1596,22 +1598,46 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_
return TRUE;
}
-void update_free_vram()
+void LLImageGLThread::updateClass()
{
LL_PROFILE_ZONE_SCOPED;
- if (gGLManager.mHasATIMemInfo)
+ // update available vram one per second
+ static LLFrameTimer sTimer;
+
+ if (sTimer.getElapsedSeconds() < 1.f)
{
- S32 meminfo[4];
- glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, meminfo);
- LLImageGLThread::sFreeVRAMMegabytes = meminfo[0];
+ return;
+ }
+
+ sTimer.reset();
+
+ auto func = []()
+ {
+ if (gGLManager.mHasATIMemInfo)
+ {
+ S32 meminfo[4];
+ glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, meminfo);
+ LLImageGLThread::sFreeVRAMMegabytes = meminfo[0];
+ }
+ else if (gGLManager.mHasNVXMemInfo)
+ {
+ S32 free_memory;
+ glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &free_memory);
+ LLImageGLThread::sFreeVRAMMegabytes = free_memory / 1024;
+ }
+ };
+
+ // post update to background thread if available, otherwise execute immediately
+ auto queue = LLImageGLThread::sEnabled ? LL::WorkQueue::getInstance("LLImageGL") : nullptr;
+ if (queue)
+ {
+ queue->post(func);
}
- else if (gGLManager.mHasNVXMemInfo)
+ else
{
- S32 free_memory;
- glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &free_memory);
- LLImageGLThread::sFreeVRAMMegabytes = free_memory / 1024;
+ func();
}
}
@@ -1657,7 +1683,7 @@ void LLImageGL::syncToMainThread(LLGLuint new_tex_name)
LL_PROFILE_ZONE_NAMED("cglt - delete callback");
if (new_tex_name != 0)
{
- if (mTexName != 0)
+ if (mTexName != 0 && mTexName != new_tex_name)
{
LLImageGL::deleteTextures(1, &mTexName);
}
@@ -1665,17 +1691,6 @@ void LLImageGL::syncToMainThread(LLGLuint new_tex_name)
unref();
}
});
-
-
- //update free vram periodically
- static LLFrameTimer timer;
-
- if (timer.getElapsedTimeF32() > 1.f) //call this once per second.
- {
- update_free_vram();
- timer.reset();
- }
-
}
BOOL LLImageGL::readBackRaw(S32 discard_level, LLImageRaw* imageraw, bool compressed_ok) const
@@ -2379,11 +2394,6 @@ void LLImageGLThread::run()
S32 LLImageGLThread::getFreeVRAMMegabytes()
{
- if (!sEnabled)
- {
- update_free_vram();
- }
-
return sFreeVRAMMegabytes;
}
diff --git a/indra/llrender/llimagegl.h b/indra/llrender/llimagegl.h
index 50706890f9..574d83c37e 100644
--- a/indra/llrender/llimagegl.h
+++ b/indra/llrender/llimagegl.h
@@ -323,6 +323,9 @@ class LLImageGLThread : public LLSimpleton<LLImageGLThread>, LL::ThreadPool
public:
// follows gSavedSettings "RenderGLMultiThreaded"
static bool sEnabled;
+
+ // app should call this function periodically
+ static void updateClass();
// free video memory in megabytes
static std::atomic<S32> sFreeVRAMMegabytes;
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
diff --git a/indra/newview/llviewerdisplay.cpp b/indra/newview/llviewerdisplay.cpp
index 4fc1bdbec3..6a2b06d9b5 100644
--- a/indra/newview/llviewerdisplay.cpp
+++ b/indra/newview/llviewerdisplay.cpp
@@ -788,6 +788,8 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot)
LLViewerTexture::updateClass();
}
+ LLImageGLThread::updateClass();
+
{
LL_RECORD_BLOCK_TIME(FTM_IMAGE_UPDATE_BUMP);
gBumpImageList.updateImages(); // must be called before gTextureList version so that it's textures are thrown out first.