From 46f7250f087645eb6ea1a1f32213f21ba283dcc5 Mon Sep 17 00:00:00 2001 From: Shyotl Date: Sun, 15 Jul 2012 21:12:31 -0500 Subject: [PATCH] Fixup multisample rbos. Samplecount validation all done in LLMultisampleBuffer::allocate, and falls back to non-multisample safely if multisampled rbos cannot/shouldn't be used. --- indra/llrender/llgl.cpp | 38 ++----------------------- indra/llrender/llgl.h | 5 ---- indra/llrender/llrendertarget.cpp | 44 +++++++++++++++++------------ indra/newview/llviewershadermgr.cpp | 2 +- indra/newview/pipeline.cpp | 7 ----- 5 files changed, 29 insertions(+), 67 deletions(-) diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp index 92d095b80..cf287f98c 100644 --- a/indra/llrender/llgl.cpp +++ b/indra/llrender/llgl.cpp @@ -435,11 +435,7 @@ LLGLManager::LLGLManager() : mHasPointParameters(FALSE), mHasDrawBuffers(FALSE), mHasTextureRectangle(FALSE), - mHasTextureMultisample(FALSE), mHasTransformFeedback(FALSE), - mMaxSampleMaskWords(0), - mMaxColorTextureSamples(0), - mMaxDepthTextureSamples(0), mMaxIntegerSamples(0), mHasAnisotropic(FALSE), @@ -732,12 +728,10 @@ bool LLGLManager::initGL() stop_glerror(); - if (mHasTextureMultisample) + if (mHasFramebufferMultisample) { - glGetIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, &mMaxColorTextureSamples); - glGetIntegerv(GL_MAX_DEPTH_TEXTURE_SAMPLES, &mMaxDepthTextureSamples); glGetIntegerv(GL_MAX_INTEGER_SAMPLES, &mMaxIntegerSamples); - glGetIntegerv(GL_MAX_SAMPLE_MASK_WORDS, &mMaxSampleMaskWords); + glGetIntegerv(GL_MAX_SAMPLES, &mMaxSamples); } stop_glerror(); @@ -749,24 +743,12 @@ bool LLGLManager::initGL() } #endif stop_glerror(); - mHasTextureMultisample = FALSE; -#if LL_WINDOWS - if (mIsATI) - { //using multisample textures on ATI results in black screen for some reason - mHasTextureMultisample = FALSE; - } -#endif if (mIsIntel && mGLVersion <= 3.f) { //never try to use framebuffer objects on older intel drivers (crashy) mHasFramebufferObject = FALSE; } - if (mHasFramebufferObject) - { - glGetIntegerv(GL_MAX_SAMPLES, &mMaxSamples); - } - stop_glerror(); setToDebugGPU(); @@ -847,14 +829,6 @@ std::string LLGLManager::getRawGLString() return gl_string; } -U32 LLGLManager::getNumFBOFSAASamples(U32 samples) -{ - samples = llmin(samples, (U32) mMaxColorTextureSamples); - samples = llmin(samples, (U32) mMaxDepthTextureSamples); - samples = llmin(samples, (U32) 4); - return samples; -} - void LLGLManager::shutdownGL() { if (mInited) @@ -960,7 +934,6 @@ void LLGLManager::initExtensions() mHasDrawBuffers = ExtensionExists("GL_ARB_draw_buffers", gGLHExts.mSysExts); mHasBlendFuncSeparate = ExtensionExists("GL_EXT_blend_func_separate", gGLHExts.mSysExts); mHasTextureRectangle = ExtensionExists("GL_ARB_texture_rectangle", gGLHExts.mSysExts); - mHasTextureMultisample = ExtensionExists("GL_ARB_texture_multisample", gGLHExts.mSysExts); mHasDebugOutput = ExtensionExists("GL_ARB_debug_output", gGLHExts.mSysExts); mHasTransformFeedback = mGLVersion >= 4.f ? TRUE : FALSE; #if !LL_DARWIN @@ -1198,13 +1171,6 @@ void LLGLManager::initExtensions() { glBlendFuncSeparateEXT = (PFNGLBLENDFUNCSEPARATEEXTPROC) GLH_EXT_GET_PROC_ADDRESS("glBlendFuncSeparateEXT"); } - if (mHasTextureMultisample) - { - glTexImage2DMultisample = (PFNGLTEXIMAGE2DMULTISAMPLEPROC) GLH_EXT_GET_PROC_ADDRESS("glTexImage2DMultisample"); - glTexImage3DMultisample = (PFNGLTEXIMAGE3DMULTISAMPLEPROC) GLH_EXT_GET_PROC_ADDRESS("glTexImage3DMultisample"); - glGetMultisamplefv = (PFNGLGETMULTISAMPLEFVPROC) GLH_EXT_GET_PROC_ADDRESS("glGetMultisamplefv"); - glSampleMaski = (PFNGLSAMPLEMASKIPROC) GLH_EXT_GET_PROC_ADDRESS("glSampleMaski"); - } if (mHasTransformFeedback) { glBeginTransformFeedback = (PFNGLBEGINTRANSFORMFEEDBACKPROC) GLH_EXT_GET_PROC_ADDRESS("glBeginTransformFeedback"); diff --git a/indra/llrender/llgl.h b/indra/llrender/llgl.h index c7e58aff9..f877834e9 100644 --- a/indra/llrender/llgl.h +++ b/indra/llrender/llgl.h @@ -104,11 +104,7 @@ public: BOOL mHasDrawBuffers; BOOL mHasDepthClamp; BOOL mHasTextureRectangle; - BOOL mHasTextureMultisample; BOOL mHasTransformFeedback; - S32 mMaxSampleMaskWords; - S32 mMaxColorTextureSamples; - S32 mMaxDepthTextureSamples; S32 mMaxIntegerSamples; // Other extensions. @@ -155,7 +151,6 @@ public: void printGLInfoString(); void getGLInfo(LLSD& info); - U32 getNumFBOFSAASamples(U32 desired_samples = 32); // In ALL CAPS std::string mGLVendor; std::string mGLVendorShort; diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index ceb865ad1..589c0dc0d 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -699,6 +699,28 @@ bool LLMultisampleBuffer::allocate(U32 resx, U32 resy, U32 color_fmt, bool depth release(); stop_glerror(); + if (!gGLManager.mHasFramebufferMultisample || !gGLManager.mHasFramebufferObject || !(sUseFBO || use_fbo)) + return false; + + if(color_fmt != GL_RGBA) + { + llwarns << "Unsupported color format: " << color_fmt << llendl; + return false; + } + + //Restrict to valid sample count + { + mSamples = samples; + mSamples = llmin(mSamples, (U32)4); //Cap to prevent memory bloat. + mSamples = llmin(mSamples, (U32) gGLManager.mMaxIntegerSamples);//GL_RGBA + + if(depth && !stencil) + mSamples = llmin(mSamples, (U32) gGLManager.mMaxSamples); //GL_DEPTH_COMPONENT16_ARB + } + + if (mSamples <= 1) + return false; + mResX = resx; mResY = resy; @@ -706,30 +728,16 @@ bool LLMultisampleBuffer::allocate(U32 resx, U32 resy, U32 color_fmt, bool depth mUseDepth = depth; mStencil = stencil; - if (!gGLManager.mHasFramebufferMultisample) - { - llerrs << "Attempting to allocate unsupported render target type!" << llendl; - return false; - } - - mSamples = gGLManager.getNumFBOFSAASamples(samples); - - if (mSamples <= 1) - { - llerrs << "Cannot create a multisample buffer with less than 2 samples." << llendl; - return false; - } - - stop_glerror(); - - if ((sUseFBO || use_fbo) && gGLManager.mHasFramebufferObject) { if (depth) { stop_glerror(); if(!allocateDepth()) + { + release(); return false; + } stop_glerror(); } glGenFramebuffers(1, (GLuint *) &mFBO); @@ -779,6 +787,7 @@ bool LLMultisampleBuffer::addColorAttachment(U32 color_fmt) if (glGetError() != GL_NO_ERROR) { llwarns << "Unable to allocate color buffer for multisample render target." << llendl; + release(); return false; } @@ -793,7 +802,6 @@ bool LLMultisampleBuffer::addColorAttachment(U32 color_fmt) } mTex.push_back(tex); - mInternalFormat.push_back(color_fmt); return true; } diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 0eb0b3cc2..6ab2cfd17 100644 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -343,7 +343,7 @@ void LLViewerShaderMgr::setShaders() //setup preprocessor definitions LLShaderMgr::instance()->mDefinitions.clear(); - LLShaderMgr::instance()->mDefinitions["samples"] = llformat("%d", gSavedSettings.getU32("RenderFSAASamples")/*gGLManager.getNumFBOFSAASamples(gSavedSettings.getU32("RenderFSAASamples"))*/); + LLShaderMgr::instance()->mDefinitions["samples"] = llformat("%d", gSavedSettings.getU32("RenderFSAASamples")); LLShaderMgr::instance()->mDefinitions["NUM_TEX_UNITS"] = llformat("%d", gGLManager.mNumTextureImageUnits); initAttribsAndUniforms(); diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index f71adc331..27632dcfc 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -632,12 +632,6 @@ void LLPipeline::allocateScreenBuffer(U32 resX, U32 resY) static const LLCachedControl RenderFSAASamples("RenderFSAASamples",0); U32 samples = RenderFSAASamples.get() - RenderFSAASamples.get() % 2; //Must be multipe of 2. - //Don't multisample if not using FXAA, or if fbos are disabled, or if multisampled fbos are not supported. - if(!LLPipeline::sRenderDeferred && (!LLRenderTarget::sUseFBO || !gGLManager.mHasFramebufferMultisample)) - { - samples = 0; - } - //try to allocate screen buffers at requested resolution and samples // - on failure, shrink number of samples and try again // - if not multisampled, shrink resolution and try again (favor X resolution over Y) @@ -791,7 +785,6 @@ bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples) if (!mScreen.allocate(resX, resY, GL_RGBA, TRUE, TRUE, LLTexUnit::TT_RECT_TEXTURE, FALSE)) return false; if(samples > 1) { - if(mSampleBuffer.allocate(resX,resY,GL_RGBA,TRUE,TRUE,LLTexUnit::TT_RECT_TEXTURE,FALSE,samples)) mScreen.setSampleBuffer(&mSampleBuffer); else