diff options
author | Dave Parks <davep@lindenlab.com> | 2023-01-09 18:12:54 -0600 |
---|---|---|
committer | Dave Parks <davep@lindenlab.com> | 2023-01-09 18:12:54 -0600 |
commit | a2d17d3c1e5a62f10ab3922b6b12f909f1cd4682 (patch) | |
tree | 1010a8f928b2e25bd06cff12b83c9b8be39cd9b0 /indra/llrender | |
parent | a710bf9067bd4c4217b9febc0ad277a1636ec882 (diff) |
SL-18869 Optimizations -- Decruftify LLRenderTarget, use a shader to copy color/depth instead of glCopyTexSubImage or glBlitFrameBuffer
Diffstat (limited to 'indra/llrender')
-rw-r--r-- | indra/llrender/llgl.cpp | 4 | ||||
-rw-r--r-- | indra/llrender/llrender.cpp | 5 | ||||
-rw-r--r-- | indra/llrender/llrendertarget.cpp | 128 | ||||
-rw-r--r-- | indra/llrender/llrendertarget.h | 16 |
4 files changed, 26 insertions, 127 deletions
diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp index e15157af05..67bd9e277e 100644 --- a/indra/llrender/llgl.cpp +++ b/indra/llrender/llgl.cpp @@ -2413,7 +2413,7 @@ void LLGLState::checkStates(const std::string& msg) BOOL error = FALSE; - if (src != GL_SRC_ALPHA || dst != GL_ONE_MINUS_SRC_ALPHA) + /*if (src != GL_SRC_ALPHA || dst != GL_ONE_MINUS_SRC_ALPHA) { if (gDebugSession) { @@ -2424,7 +2424,7 @@ void LLGLState::checkStates(const std::string& msg) { LL_GL_ERRS << "Blend function corrupted: " << std::hex << src << " " << std::hex << dst << " " << msg << std::dec << LL_ENDL; } - } + }*/ for (boost::unordered_map<LLGLenum, LLGLboolean>::iterator iter = sStateMap.begin(); iter != sStateMap.end(); ++iter) diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index c58fbe6c8e..8ab8d3151b 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -370,9 +370,10 @@ bool LLTexUnit::bind(LLRenderTarget* renderTarget, bool bindDepth) if (bindDepth) { - if (renderTarget->hasStencil()) + + if (renderTarget->getDepth() && !renderTarget->canSampleDepth()) { - LL_ERRS() << "Cannot bind a render buffer for sampling. Allocate render target without a stencil buffer if sampling of depth buffer is required." << LL_ENDL; + LL_ERRS() << "Cannot bind a render buffer for sampling. Allocate render target with depth buffer sampling enabled." << LL_ENDL; } bindManual(renderTarget->getUsage(), renderTarget->getDepth()); diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index 01ccf3d314..9827db8084 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -67,9 +67,8 @@ LLRenderTarget::LLRenderTarget() : mPreviousResX(0), mPreviousResY(0), mDepth(0), - mStencil(0), mUseDepth(false), - mRenderDepth(false), + mSampleDepth(false), mUsage(LLTexUnit::TT_TEXTURE) { } @@ -98,11 +97,11 @@ void LLRenderTarget::resize(U32 resx, U32 resy) if (mDepth) { //resize depth attachment - if (mStencil) + if (!mSampleDepth) { //use render buffers where stencil buffers are in play glBindRenderbuffer(GL_RENDERBUFFER, mDepth); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, mResX, mResY); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, mResX, mResY); glBindRenderbuffer(GL_RENDERBUFFER, 0); } else @@ -117,7 +116,7 @@ void LLRenderTarget::resize(U32 resx, U32 resy) } -bool LLRenderTarget::allocate(U32 resx, U32 resy, U32 color_fmt, bool depth, bool stencil, LLTexUnit::eTextureType usage, bool use_fbo, S32 samples) +bool LLRenderTarget::allocate(U32 resx, U32 resy, U32 color_fmt, bool depth, bool sample_depth, LLTexUnit::eTextureType usage, bool use_fbo, S32 samples) { LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY; resx = llmin(resx, (U32) gGLManager.mGLMaxTextureSize); @@ -130,9 +129,9 @@ bool LLRenderTarget::allocate(U32 resx, U32 resy, U32 color_fmt, bool depth, boo mResX = resx; mResY = resy; - mStencil = stencil; mUsage = usage; - mUseDepth = depth; + mUseDepth = depth; + mSampleDepth = sample_depth; if ((sUseFBO || use_fbo)) { @@ -150,13 +149,10 @@ bool LLRenderTarget::allocate(U32 resx, U32 resy, U32 color_fmt, bool depth, boo if (mDepth) { glBindFramebuffer(GL_FRAMEBUFFER, mFBO); - llassert(!mStencil); // use of stencil buffer is deprecated (performance penalty) - if (mStencil) + + if (!canSampleDepth()) { glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mDepth); - stop_glerror(); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, mDepth); - stop_glerror(); } else { @@ -315,14 +311,12 @@ bool LLRenderTarget::addColorAttachment(U32 color_fmt) bool LLRenderTarget::allocateDepth() { LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY; - if (mStencil) + if (!mSampleDepth) { - //use render buffers where stencil buffers are in play + //use render buffers if depth buffer won't be sampled glGenRenderbuffers(1, (GLuint *) &mDepth); glBindRenderbuffer(GL_RENDERBUFFER, mDepth); - stop_glerror(); - clear_glerror(); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, mResX, mResY); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, mResX, mResY); glBindRenderbuffer(GL_RENDERBUFFER, 0); } else @@ -367,23 +361,15 @@ void LLRenderTarget::shareDepthBuffer(LLRenderTarget& target) if (mDepth) { - stop_glerror(); glBindFramebuffer(GL_FRAMEBUFFER, target.mFBO); - stop_glerror(); - - llassert(!mStencil); // deprecated -- performance penalty - if (mStencil) + + if (!mSampleDepth) { glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mDepth); - stop_glerror(); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, mDepth); - stop_glerror(); - target.mStencil = true; } else { glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, LLTexUnit::getInternalType(mUsage), mDepth, 0); - stop_glerror(); } check_framebuffer_status(); @@ -399,15 +385,13 @@ void LLRenderTarget::release() LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY; if (mDepth) { - if (mStencil) + if (!mSampleDepth) { glDeleteRenderbuffers(1, (GLuint*) &mDepth); - stop_glerror(); } else { LLImageGL::deleteTextures(1, &mDepth); - stop_glerror(); } mDepth = 0; @@ -419,12 +403,10 @@ void LLRenderTarget::release() if (mUseDepth) { //detach shared depth buffer - llassert(!mStencil); //deprecated, performance penalty - if (mStencil) + if (!mSampleDepth) { //attached as a renderbuffer - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0); - mStencil = false; + mSampleDepth = false; } else { //attached as a texture @@ -624,84 +606,6 @@ void LLRenderTarget::flush(bool fetch_depth) } } -void LLRenderTarget::copyContents(LLRenderTarget& source, S32 srcX0, S32 srcY0, S32 srcX1, S32 srcY1, - S32 dstX0, S32 dstY0, S32 dstX1, S32 dstY1, U32 mask, U32 filter) -{ - LL_PROFILE_GPU_ZONE("LLRenderTarget::copyContents"); - - GLboolean write_depth = mask & GL_DEPTH_BUFFER_BIT ? TRUE : FALSE; - - LLGLDepthTest depth(write_depth, write_depth); - - gGL.flush(); - if (!source.mFBO || !mFBO) - { - LL_WARNS() << "Cannot copy framebuffer contents for non FBO render targets." << LL_ENDL; - return; - } - - - if (mask == GL_DEPTH_BUFFER_BIT && source.mStencil != mStencil) - { - stop_glerror(); - - glBindFramebuffer(GL_FRAMEBUFFER, source.mFBO); - check_framebuffer_status(); - gGL.getTexUnit(0)->bind(this, true); - stop_glerror(); - glCopyTexSubImage2D(LLTexUnit::getInternalType(mUsage), 0, srcX0, srcY0, dstX0, dstY0, dstX1, dstY1); - stop_glerror(); - glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO); - stop_glerror(); - } - else - { - glBindFramebuffer(GL_READ_FRAMEBUFFER, source.mFBO); - stop_glerror(); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mFBO); - stop_glerror(); - check_framebuffer_status(); - stop_glerror(); - glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); - stop_glerror(); - glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); - stop_glerror(); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); - stop_glerror(); - glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO); - stop_glerror(); - } -} - -//static -void LLRenderTarget::copyContentsToFramebuffer(LLRenderTarget& source, S32 srcX0, S32 srcY0, S32 srcX1, S32 srcY1, - S32 dstX0, S32 dstY0, S32 dstX1, S32 dstY1, U32 mask, U32 filter) -{ - if (!source.mFBO) - { - LL_WARNS() << "Cannot copy framebuffer contents for non FBO render targets." << LL_ENDL; - return; - } - - { - LL_PROFILE_GPU_ZONE("copyContentsToFramebuffer"); - GLboolean write_depth = mask & GL_DEPTH_BUFFER_BIT ? TRUE : FALSE; - - LLGLDepthTest depth(write_depth, write_depth); - - glBindFramebuffer(GL_READ_FRAMEBUFFER, source.mFBO); - stop_glerror(); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); - stop_glerror(); - check_framebuffer_status(); - stop_glerror(); - glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); - stop_glerror(); - glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO); - stop_glerror(); - } -} - bool LLRenderTarget::isComplete() const { return (!mTex.empty() || mDepth) ? true : false; diff --git a/indra/llrender/llrendertarget.h b/indra/llrender/llrendertarget.h index 584f224dca..5f3214add3 100644 --- a/indra/llrender/llrendertarget.h +++ b/indra/llrender/llrendertarget.h @@ -73,7 +73,7 @@ public: //allocate resources for rendering //must be called before use //multiple calls will release previously allocated resources - bool allocate(U32 resx, U32 resy, U32 color_fmt, bool depth, bool stencil, LLTexUnit::eTextureType usage = LLTexUnit::TT_TEXTURE, bool use_fbo = false, S32 samples = 0); + bool allocate(U32 resx, U32 resy, U32 color_fmt, bool depth, bool sample_depth, LLTexUnit::eTextureType usage = LLTexUnit::TT_TEXTURE, bool use_fbo = false, S32 samples = 0); //resize existing attachments to use new resolution and color format // CAUTION: if the GL runs out of memory attempting to resize, this render target will be undefined @@ -136,7 +136,7 @@ public: U32 getNumTextures() const; U32 getDepth(void) const { return mDepth; } - bool hasStencil() const { return mStencil; } + bool canSampleDepth() const { return mSampleDepth; } void bindTexture(U32 index, S32 channel, LLTexUnit::eTextureFilterOptions filter_options = LLTexUnit::TFO_BILINEAR); @@ -148,12 +148,6 @@ public: // the current depth texture. A depth texture will be allocated if needed. void flush(bool fetch_depth = FALSE); - void copyContents(LLRenderTarget& source, S32 srcX0, S32 srcY0, S32 srcX1, S32 srcY1, - S32 dstX0, S32 dstY0, S32 dstX1, S32 dstY1, U32 mask, U32 filter); - - static void copyContentsToFramebuffer(LLRenderTarget& source, S32 srcX0, S32 srcY0, S32 srcX1, S32 srcY1, - S32 dstX0, S32 dstY0, S32 dstX1, S32 dstY1, U32 mask, U32 filter); - //Returns TRUE if target is ready to be rendered into. //That is, if the target has been allocated with at least //one renderable attachment (i.e. color buffer, depth buffer). @@ -172,9 +166,9 @@ protected: U32 mPreviousResY; U32 mDepth; - bool mStencil; - bool mUseDepth; - bool mRenderDepth; + bool mUseDepth; + bool mSampleDepth; + LLTexUnit::eTextureType mUsage; static LLRenderTarget* sBoundTarget; |