From f5516e0fc0e6c22b25f9dca2b9b24ebd7618332a Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham Linden)" Date: Wed, 27 Feb 2013 06:46:53 -0800 Subject: For MAINT-2404 Fixes detection of VRAM on OSX removed along with other AGL code. Code Review: callum --- indra/llwindow/llopenglview-objc.h | 5 +++++ indra/llwindow/llopenglview-objc.mm | 22 ++++++++++++++++++++++ indra/llwindow/llwindowmacosx-objc.h | 1 + indra/llwindow/llwindowmacosx-objc.mm | 5 +++++ indra/llwindow/llwindowmacosx.cpp | 2 ++ 5 files changed, 35 insertions(+) (limited to 'indra') diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h index b344bed2ef..c3ae34ea50 100644 --- a/indra/llwindow/llopenglview-objc.h +++ b/indra/llwindow/llopenglview-objc.h @@ -7,6 +7,9 @@ // #import +#import +#import +#import #include "llwindowmacosx-objc.h" // Some nasty shovelling of LLOpenGLView from LLNativeBindings to prevent any C++ <-> Obj-C interop oddities. @@ -33,6 +36,8 @@ - (CGLContextObj) getCGLContextObj; - (CGLPixelFormatObj*)getCGLPixelFormatObj; +- (unsigned long) getVramSize; + @end @interface LLNSWindow : NSWindow { diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index e89c9267d5..a1dece54f4 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -39,6 +39,28 @@ @implementation LLOpenGLView +- (unsigned long)getVramSize +{ + unsigned long vram_bytes = 0; + + io_service_t display_port = CGDisplayIOServicePort(kCGDirectMainDisplay); + + const void* type_code = IORegistryEntryCreateCFProperty(display_port, CFSTR(kIOFBMemorySizeKey), kCFAllocatorDefault, kNilOptions); + + // Ensure we have valid data from IOKit + if(type_code && CFGetTypeID(type_code) == CFNumberGetTypeID()) + { + long val; + // Retrieve actual number...is Apple ever embarrassed by this nonsense? + // + CFNumberGetValue((const __CFNumber*)type_code, kCFNumberSInt32Type, &val); + vram_bytes = (unsigned long)val; + CFRelease(type_code); + } + + return vram_bytes; +} + - (void)viewDidMoveToWindow { [[NSNotificationCenter defaultCenter] addObserver:self diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index a0eab61e7c..1724b85724 100644 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -62,6 +62,7 @@ NSWindowRef createNSWindow(int x, int y, int width, int height); GLViewRef createOpenGLView(NSWindowRef window, unsigned int samples, bool vsync); void glSwapBuffers(void* context); CGLContextObj getCGLContextObj(GLViewRef view); +unsigned long getVramSize(GLViewRef view); void getContentViewBounds(NSWindowRef window, float* bounds); void getWindowSize(NSWindowRef window, float* size); void setWindowSize(NSWindowRef window, int width, int height); diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index b288671219..9b57cd27cd 100644 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -237,6 +237,11 @@ CGLPixelFormatObj* getCGLPixelFormatObj(NSWindowRef window) return [glview getCGLPixelFormatObj]; } +unsigned long getVramSize(GLViewRef view) +{ + return [(LLOpenGLView *)view getVramSize]; +} + void getContentViewBounds(NSWindowRef window, float* bounds) { bounds[0] = [[(LLNSWindow*)window contentView] bounds].origin.x; diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index ac0fa54a68..abb3c1e50c 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -408,6 +408,8 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits mContext = getCGLContextObj(mGLView); // Since we just created the context, it needs to be set up. glNeedsInit = TRUE; + + gGLManager.mVRAM = getVramSize(mGLView); } // Hook up the context to a drawable -- cgit v1.2.3 From a0de7a5ca77fbbaba4cafacfce9befbdf42c47b2 Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham Linden)" Date: Wed, 27 Feb 2013 08:04:20 -0800 Subject: Added missing IOKit lib dep to llui_libtest integration test cmake --- indra/integration_tests/llui_libtest/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra') diff --git a/indra/integration_tests/llui_libtest/CMakeLists.txt b/indra/integration_tests/llui_libtest/CMakeLists.txt index 91c9f20c10..06389ff871 100644 --- a/indra/integration_tests/llui_libtest/CMakeLists.txt +++ b/indra/integration_tests/llui_libtest/CMakeLists.txt @@ -56,7 +56,8 @@ add_executable(llui_libtest ${llui_libtest_SOURCE_FILES}) # Link with OS-specific libraries for LLWindow dependency if (DARWIN) find_library(COCOA_LIBRARY Cocoa) - set(OS_LIBRARIES ${COCOA_LIBRARY}) + find_library(IOKIT_LIBRARY IOKit) + set(OS_LIBRARIES ${COCOA_LIBRARY} ${IOKIT_LIBRARY}) elseif (WINDOWS) #ll_stack_trace needs this now... list(APPEND WINDOWS_LIBRARIES dbghelp) -- cgit v1.2.3 From d046e606575b2c3714a88e321c88e05441cba4a8 Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham Linden)" Date: Wed, 27 Feb 2013 14:39:26 -0800 Subject: Fix max VRAM detection on some cards and issues with sequencing of application of mem multiplier --- indra/llwindow/llopenglview-objc.mm | 32 +++++++++++++---------------- indra/llwindow/llwindowmacosx.cpp | 5 +++-- indra/newview/llfloaterhardwaresettings.cpp | 4 +++- indra/newview/llviewertexturelist.cpp | 14 ++++++------- indra/newview/llviewertexturelist.h | 2 +- 5 files changed, 28 insertions(+), 29 deletions(-) (limited to 'indra') diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index a1dece54f4..735ef77cce 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -41,24 +41,20 @@ - (unsigned long)getVramSize { - unsigned long vram_bytes = 0; - - io_service_t display_port = CGDisplayIOServicePort(kCGDirectMainDisplay); - - const void* type_code = IORegistryEntryCreateCFProperty(display_port, CFSTR(kIOFBMemorySizeKey), kCFAllocatorDefault, kNilOptions); - - // Ensure we have valid data from IOKit - if(type_code && CFGetTypeID(type_code) == CFNumberGetTypeID()) - { - long val; - // Retrieve actual number...is Apple ever embarrassed by this nonsense? - // - CFNumberGetValue((const __CFNumber*)type_code, kCFNumberSInt32Type, &val); - vram_bytes = (unsigned long)val; - CFRelease(type_code); - } - - return vram_bytes; + CGLRendererInfoObj info = 0; + GLint vram_bytes = 0; + int num_renderers = 0; + CGLError the_err = CGLQueryRendererInfo (CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDisplay), &info, &num_renderers); + if(0 == the_err) + { + CGLDescribeRenderer (info, 0, kCGLRPTextureMemory, &vram_bytes); + CGLDestroyRendererInfo (info); + } + else + { + vram_bytes = (256 << 20); + } + return (unsigned long)vram_bytes; } - (void)viewDidMoveToWindow diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index abb3c1e50c..2faebe5dd9 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -511,8 +511,9 @@ void LLWindowMacOSX::destroyContext() // Close the window if(mWindow != NULL) { - closeWindow(mWindow); - mWindow = NULL; + NSWindowRef dead_window = mWindow; + mWindow = NULL; + closeWindow(dead_window); } } diff --git a/indra/newview/llfloaterhardwaresettings.cpp b/indra/newview/llfloaterhardwaresettings.cpp index 116bd241c4..664f7d4fd6 100644 --- a/indra/newview/llfloaterhardwaresettings.cpp +++ b/indra/newview/llfloaterhardwaresettings.cpp @@ -89,8 +89,10 @@ void LLFloaterHardwareSettings::refresh() void LLFloaterHardwareSettings::refreshEnabledState() { + F32 mem_multiplier = gSavedSettings.getF32("RenderTextureMemoryMultiple"); + S32 min_tex_mem = LLViewerTextureList::getMinVideoRamSetting(); - S32 max_tex_mem = LLViewerTextureList::getMaxVideoRamSetting(); + S32 max_tex_mem = LLViewerTextureList::getMaxVideoRamSetting(false, mem_multiplier); getChild("GraphicsCardTextureMemory")->setMinValue(min_tex_mem); getChild("GraphicsCardTextureMemory")->setMaxValue(max_tex_mem); diff --git a/indra/newview/llviewertexturelist.cpp b/indra/newview/llviewertexturelist.cpp index b9f5c432d0..82d990cf97 100644 --- a/indra/newview/llviewertexturelist.cpp +++ b/indra/newview/llviewertexturelist.cpp @@ -1191,7 +1191,7 @@ S32 LLViewerTextureList::getMinVideoRamSetting() //static // Returns max setting for TextureMemory (in MB) -S32 LLViewerTextureList::getMaxVideoRamSetting(bool get_recommended) +S32 LLViewerTextureList::getMaxVideoRamSetting(bool get_recommended, float mem_multiplier) { S32 max_texmem; if (gGLManager.mVRAM != 0) @@ -1235,7 +1235,10 @@ S32 LLViewerTextureList::getMaxVideoRamSetting(bool get_recommended) max_texmem = llmin(max_texmem, (S32)(system_ram/2)); else max_texmem = llmin(max_texmem, (S32)(system_ram)); - + + // limit the texture memory to a multiple of the default if we've found some cards to behave poorly otherwise + max_texmem = llmin(max_texmem, (S32) (mem_multiplier * (F32) max_texmem)); + max_texmem = llclamp(max_texmem, getMinVideoRamSetting(), MAX_VIDEO_RAM_IN_MEGA_BYTES); return max_texmem; @@ -1248,7 +1251,7 @@ void LLViewerTextureList::updateMaxResidentTexMem(S32 mem) // Initialize the image pipeline VRAM settings S32 cur_mem = gSavedSettings.getS32("TextureMemory"); F32 mem_multiplier = gSavedSettings.getF32("RenderTextureMemoryMultiple"); - S32 default_mem = getMaxVideoRamSetting(true); // recommended default + S32 default_mem = getMaxVideoRamSetting(true, mem_multiplier); // recommended default if (mem == 0) { mem = cur_mem > 0 ? cur_mem : default_mem; @@ -1258,10 +1261,7 @@ void LLViewerTextureList::updateMaxResidentTexMem(S32 mem) mem = default_mem; } - // limit the texture memory to a multiple of the default if we've found some cards to behave poorly otherwise - mem = llmin(mem, (S32) (mem_multiplier * (F32) default_mem)); - - mem = llclamp(mem, getMinVideoRamSetting(), getMaxVideoRamSetting()); + mem = llclamp(mem, getMinVideoRamSetting(), getMaxVideoRamSetting(false, mem_multiplier)); if (mem != cur_mem) { gSavedSettings.setS32("TextureMemory", mem); diff --git a/indra/newview/llviewertexturelist.h b/indra/newview/llviewertexturelist.h index 3dda973d3f..88dea4448b 100644 --- a/indra/newview/llviewertexturelist.h +++ b/indra/newview/llviewertexturelist.h @@ -114,7 +114,7 @@ public: void setDebugFetching(LLViewerFetchedTexture* tex, S32 debug_level); static S32 getMinVideoRamSetting(); - static S32 getMaxVideoRamSetting(bool get_recommended = false); + static S32 getMaxVideoRamSetting(bool get_recommended, float mem_multiplier); private: void updateImagesDecodePriorities(); -- cgit v1.2.3