From 93260cfeff2382dd1ffeecaef208d37bf21c2a01 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 4 May 2022 16:07:50 +0000 Subject: SL-17283 LLReflectionMapManager prototype. Remove snapshot code related overhead from reflection map renders. Add parallax correction and support for multiple reflection maps. --- indra/llrender/llrendertarget.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indra/llrender/llrendertarget.cpp') diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index 0408010513..0a4cc1bcf5 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -119,6 +119,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) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY; resx = llmin(resx, (U32) gGLManager.mGLMaxTextureSize); resy = llmin(resy, (U32) gGLManager.mGLMaxTextureSize); @@ -219,6 +220,7 @@ void LLRenderTarget::releaseColorAttachment() bool LLRenderTarget::addColorAttachment(U32 color_fmt) { + LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY; if (color_fmt == 0) { return true; @@ -315,6 +317,7 @@ bool LLRenderTarget::addColorAttachment(U32 color_fmt) bool LLRenderTarget::allocateDepth() { + LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY; if (mStencil) { //use render buffers where stencil buffers are in play @@ -395,6 +398,7 @@ void LLRenderTarget::shareDepthBuffer(LLRenderTarget& target) void LLRenderTarget::release() { + LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY; if (mDepth) { if (mStencil) -- cgit v1.2.3 From 6c6d9a10f830e264cf75603949b54a12256cab78 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 20 May 2022 13:31:18 -0500 Subject: SL-17287 Update Tracy to 0.8.1. Clean up GPU instrumentation. --- indra/llrender/llrendertarget.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'indra/llrender/llrendertarget.cpp') diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index 0a4cc1bcf5..85c2a48279 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -488,13 +488,11 @@ void LLRenderTarget::bindTarget() GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3}; - LL_PROFILER_GPU_ZONEC( "gl.DrawBuffersARB", 0x4000FF ) glDrawBuffersARB(mTex.size(), drawbuffers); } if (mTex.empty()) { //no color buffer to draw to - LL_PROFILER_GPU_ZONEC( "gl.DrawBuffer", 0x0000FF ) glDrawBuffer(GL_NONE); glReadBuffer(GL_NONE); } -- cgit v1.2.3 From 6eaf8521abae0deeb1162f9c61747183110176b0 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 20 May 2022 19:05:28 -0500 Subject: SL-17287 Instrument and optimize cubemap render. Fix for cubemap snapshots doing a full resolution render instead of a 512x512 render. --- indra/llrender/llrendertarget.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/llrender/llrendertarget.cpp') diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index 85c2a48279..85d6209964 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -513,6 +513,7 @@ void LLRenderTarget::bindTarget() void LLRenderTarget::clear(U32 mask_in) { + LL_PROFILE_GPU_ZONE("clear"); U32 mask = GL_COLOR_BUFFER_BIT; if (mUseDepth) { @@ -677,6 +678,7 @@ void LLRenderTarget::copyContentsToFramebuffer(LLRenderTarget& source, S32 srcX0 } { + LL_PROFILE_GPU_ZONE("copyContentsToFramebuffer"); GLboolean write_depth = mask & GL_DEPTH_BUFFER_BIT ? TRUE : FALSE; LLGLDepthTest depth(write_depth, write_depth); -- cgit v1.2.3 From 509476f95ed75ce8289ecd69b4c94d9912e1d3df Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 10 Jun 2022 01:13:41 -0500 Subject: SL-17574 Add probe detail combo box to advanced graphics preferences. Fix spot light shadows not working in probes. --- indra/llrender/llrendertarget.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indra/llrender/llrendertarget.cpp') diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index 85d6209964..fa46e0f7d0 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -473,6 +473,8 @@ void LLRenderTarget::release() void LLRenderTarget::bindTarget() { + llassert(mFBO); + if (mFBO) { stop_glerror(); @@ -514,6 +516,7 @@ void LLRenderTarget::bindTarget() void LLRenderTarget::clear(U32 mask_in) { LL_PROFILE_GPU_ZONE("clear"); + llassert(mFBO); U32 mask = GL_COLOR_BUFFER_BIT; if (mUseDepth) { @@ -579,6 +582,7 @@ void LLRenderTarget::bindTexture(U32 index, S32 channel, LLTexUnit::eTextureFilt void LLRenderTarget::flush(bool fetch_depth) { gGL.flush(); + llassert(mFBO); if (!mFBO) { gGL.getTexUnit(0)->bind(this); -- cgit v1.2.3 From 2082443220fe344bb027c3acbf50fea0a99159c3 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Thu, 1 Sep 2022 10:58:27 -0700 Subject: SL-17967 - Git rid of ARB that is in core --- indra/llrender/llrendertarget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llrender/llrendertarget.cpp') diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index fa46e0f7d0..fa23654978 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -490,7 +490,7 @@ void LLRenderTarget::bindTarget() GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3}; - glDrawBuffersARB(mTex.size(), drawbuffers); + glDrawBuffers(mTex.size(), drawbuffers); } if (mTex.empty()) -- cgit v1.2.3 From 8dc59e5ef37836b15d478fb0d04e3043a9f986de Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 16 Sep 2022 16:25:26 -0500 Subject: SL-18128 Clear out much OpenGL cruft and switch to core profile on AMD --- indra/llrender/llrendertarget.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'indra/llrender/llrendertarget.cpp') diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index fa23654978..015312e570 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -134,7 +134,7 @@ bool LLRenderTarget::allocate(U32 resx, U32 resy, U32 color_fmt, bool depth, boo mUsage = usage; mUseDepth = depth; - if ((sUseFBO || use_fbo) && gGLManager.mHasFramebufferObject) + if ((sUseFBO || use_fbo)) { if (depth) { @@ -234,11 +234,9 @@ bool LLRenderTarget::addColorAttachment(U32 color_fmt) llassert( offset < 4 ); return false; } - if( offset > 0 && (mFBO == 0 || !gGLManager.mHasDrawBuffers) ) + if( offset > 0 && (mFBO == 0) ) { - LL_WARNS() << "FBO not used or no drawbuffers available; mFBO=" << (U32)mFBO << " gGLManager.mHasDrawBuffers=" << (U32)gGLManager.mHasDrawBuffers << LL_ENDL; llassert( mFBO != 0 ); - llassert( gGLManager.mHasDrawBuffers ); return false; } @@ -484,14 +482,12 @@ void LLRenderTarget::bindTarget() sCurFBO = mFBO; stop_glerror(); - if (gGLManager.mHasDrawBuffers) - { //setup multiple render targets - GLenum drawbuffers[] = {GL_COLOR_ATTACHMENT0, - GL_COLOR_ATTACHMENT1, - GL_COLOR_ATTACHMENT2, - GL_COLOR_ATTACHMENT3}; - glDrawBuffers(mTex.size(), drawbuffers); - } + //setup multiple render targets + GLenum drawbuffers[] = {GL_COLOR_ATTACHMENT0, + GL_COLOR_ATTACHMENT1, + GL_COLOR_ATTACHMENT2, + GL_COLOR_ATTACHMENT3}; + glDrawBuffers(mTex.size(), drawbuffers); if (mTex.empty()) { //no color buffer to draw to -- cgit v1.2.3 From 718073717c70b1f7e7284a02641c0a0a7bf50367 Mon Sep 17 00:00:00 2001 From: "Howard (Aech Linden) Stearns" Date: Mon, 19 Sep 2022 12:16:49 -0700 Subject: SL-18128, SL-18128 - No glerror on Mac! --- indra/llrender/llrendertarget.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'indra/llrender/llrendertarget.cpp') diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index 015312e570..01e0b4336c 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -301,13 +301,11 @@ bool LLRenderTarget::addColorAttachment(U32 color_fmt) mTex.push_back(tex); mInternalFormat.push_back(color_fmt); -#if !LL_DARWIN if (gDebugGL) { //bind and unbind to validate target bindTarget(); flush(); } -#endif return true; -- cgit v1.2.3 From 04d3a29a699cd0a4c08ab096bfbab153e65c1fd1 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 19 Sep 2022 17:27:33 -0500 Subject: SL-18190 Faster better stronger radiance/irradiance maps --- indra/llrender/llrendertarget.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/llrender/llrendertarget.cpp') diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index 015312e570..2179b441e5 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -471,6 +471,7 @@ void LLRenderTarget::release() void LLRenderTarget::bindTarget() { + LL_PROFILE_GPU_ZONE("bindTarget"); llassert(mFBO); if (mFBO) @@ -577,6 +578,7 @@ void LLRenderTarget::bindTexture(U32 index, S32 channel, LLTexUnit::eTextureFilt void LLRenderTarget::flush(bool fetch_depth) { + LL_PROFILE_GPU_ZONE("rt flush"); gGL.flush(); llassert(mFBO); if (!mFBO) -- cgit v1.2.3 From 30bcc7d6d5fa4ceedfec28cc0973c253364c555e Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 5 Oct 2022 08:11:33 -0500 Subject: SL-18190 WIP - Add refraction to water without splitting scene between above and below water --- indra/llrender/llrendertarget.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/llrender/llrendertarget.cpp') diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index b0da054d76..7fcb130ac6 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -623,6 +623,8 @@ 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); -- cgit v1.2.3 From 9448db5d4af7bba094e5bc51f85e5c2491d3f5a1 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 6 Oct 2022 18:40:01 -0500 Subject: SL-18190 Water shader WIP. Better parallax correction for sphere probes. Reduce probe memory footprint. Remove framebuffer copies and move to deprecate stencil buffer usage. --- indra/llrender/llrendertarget.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'indra/llrender/llrendertarget.cpp') diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index 7fcb130ac6..01ccf3d314 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -150,6 +150,7 @@ 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) { glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mDepth); @@ -370,6 +371,7 @@ void LLRenderTarget::shareDepthBuffer(LLRenderTarget& target) glBindFramebuffer(GL_FRAMEBUFFER, target.mFBO); stop_glerror(); + llassert(!mStencil); // deprecated -- performance penalty if (mStencil) { glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mDepth); @@ -417,6 +419,7 @@ void LLRenderTarget::release() if (mUseDepth) { //detach shared depth buffer + llassert(!mStencil); //deprecated, performance penalty if (mStencil) { //attached as a renderbuffer glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0); @@ -515,7 +518,8 @@ void LLRenderTarget::clear(U32 mask_in) U32 mask = GL_COLOR_BUFFER_BIT; if (mUseDepth) { - mask |= GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT; + mask |= GL_DEPTH_BUFFER_BIT; // stencil buffer is deprecated, performance pnealty | GL_STENCIL_BUFFER_BIT; + } if (mFBO) { -- cgit v1.2.3 From a2d17d3c1e5a62f10ab3922b6b12f909f1cd4682 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 9 Jan 2023 18:12:54 -0600 Subject: SL-18869 Optimizations -- Decruftify LLRenderTarget, use a shader to copy color/depth instead of glCopyTexSubImage or glBlitFrameBuffer --- indra/llrender/llrendertarget.cpp | 128 +++++--------------------------------- 1 file changed, 16 insertions(+), 112 deletions(-) (limited to 'indra/llrender/llrendertarget.cpp') 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; -- cgit v1.2.3 From 3ef31cb9b28f7b026e109eab69d383dddc922850 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Fri, 27 Jan 2023 17:24:22 -0600 Subject: SL-19203 et al -- Integrate SSR with reflection probes, tweak probe blending. (#63) * SL-19203 WIP -- Integrate SSR with reflection probes. Decruft LLRenderTarget. * SL-19203 WIP -- Re-integrate SSR. Incidental decruft. * SL-19203 WIP -- SSR frame delta correction (still broken for Z) * SL-19203 WIP -- SSR frame delta Z fix * SL-19203 WIP -- Make SSR toggleable again and disable SSR in cube snapshots. * SL-19203 WIP -- Soften sphere probe transitions and fix reflections on void water (make fallback probe a simple terrain+water+sky probe). Remove parallax correction for automatic probes to reduce artifacts. * SL-19203 Tune probe blending. * SL-19203 Cleanup. --- indra/llrender/llrendertarget.cpp | 786 +++++++++++++++++--------------------- 1 file changed, 360 insertions(+), 426 deletions(-) (limited to 'indra/llrender/llrendertarget.cpp') diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index 9827db8084..6dac614eea 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -35,19 +35,19 @@ U32 LLRenderTarget::sBytesAllocated = 0; void check_framebuffer_status() { - if (gDebugGL) - { - GLenum status = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER); - switch (status) - { - case GL_FRAMEBUFFER_COMPLETE: - break; - default: - LL_WARNS() << "check_framebuffer_status failed -- " << std::hex << status << LL_ENDL; - ll_fail("check_framebuffer_status failed"); - break; - } - } + if (gDebugGL) + { + GLenum status = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER); + switch (status) + { + case GL_FRAMEBUFFER_COMPLETE: + break; + default: + LL_WARNS() << "check_framebuffer_status failed -- " << std::hex << status << LL_ENDL; + ll_fail("check_framebuffer_status failed"); + break; + } + } } bool LLRenderTarget::sUseFBO = false; @@ -60,112 +60,86 @@ U32 LLRenderTarget::sCurResX = 0; U32 LLRenderTarget::sCurResY = 0; LLRenderTarget::LLRenderTarget() : - mResX(0), - mResY(0), - mFBO(0), - mPreviousFBO(0), - mPreviousResX(0), - mPreviousResY(0), - mDepth(0), - mUseDepth(false), - mSampleDepth(false), - mUsage(LLTexUnit::TT_TEXTURE) + mResX(0), + mResY(0), + mFBO(0), + mDepth(0), + mUseDepth(false), + mUsage(LLTexUnit::TT_TEXTURE) { } LLRenderTarget::~LLRenderTarget() { - release(); + release(); } void LLRenderTarget::resize(U32 resx, U32 resy) { - //for accounting, get the number of pixels added/subtracted - S32 pix_diff = (resx*resy)-(mResX*mResY); - - mResX = resx; - mResY = resy; - - llassert(mInternalFormat.size() == mTex.size()); - - for (U32 i = 0; i < mTex.size(); ++i) - { //resize color attachments - gGL.getTexUnit(0)->bindManual(mUsage, mTex[i]); - LLImageGL::setManualImage(LLTexUnit::getInternalType(mUsage), 0, mInternalFormat[i], mResX, mResY, GL_RGBA, GL_UNSIGNED_BYTE, NULL, false); - sBytesAllocated += pix_diff*4; - } - - if (mDepth) - { //resize depth attachment - if (!mSampleDepth) - { - //use render buffers where stencil buffers are in play - glBindRenderbuffer(GL_RENDERBUFFER, mDepth); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, mResX, mResY); - glBindRenderbuffer(GL_RENDERBUFFER, 0); - } - else - { - gGL.getTexUnit(0)->bindManual(mUsage, mDepth); - U32 internal_type = LLTexUnit::getInternalType(mUsage); - LLImageGL::setManualImage(internal_type, 0, GL_DEPTH_COMPONENT24, mResX, mResY, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL, false); - } - - sBytesAllocated += pix_diff*4; - } + //for accounting, get the number of pixels added/subtracted + S32 pix_diff = (resx*resy)-(mResX*mResY); + + mResX = resx; + mResY = resy; + + llassert(mInternalFormat.size() == mTex.size()); + + for (U32 i = 0; i < mTex.size(); ++i) + { //resize color attachments + gGL.getTexUnit(0)->bindManual(mUsage, mTex[i]); + LLImageGL::setManualImage(LLTexUnit::getInternalType(mUsage), 0, mInternalFormat[i], mResX, mResY, GL_RGBA, GL_UNSIGNED_BYTE, NULL, false); + sBytesAllocated += pix_diff*4; + } + + if (mDepth) + { + gGL.getTexUnit(0)->bindManual(mUsage, mDepth); + U32 internal_type = LLTexUnit::getInternalType(mUsage); + LLImageGL::setManualImage(internal_type, 0, GL_DEPTH_COMPONENT24, mResX, mResY, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL, false); + + sBytesAllocated += pix_diff*4; + } } - + -bool LLRenderTarget::allocate(U32 resx, U32 resy, U32 color_fmt, bool depth, bool sample_depth, LLTexUnit::eTextureType usage, bool use_fbo, S32 samples) +bool LLRenderTarget::allocate(U32 resx, U32 resy, U32 color_fmt, bool depth, LLTexUnit::eTextureType usage) { LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY; - resx = llmin(resx, (U32) gGLManager.mGLMaxTextureSize); - resy = llmin(resy, (U32) gGLManager.mGLMaxTextureSize); + llassert(usage == LLTexUnit::TT_TEXTURE); + llassert(!isBoundInStack()); - stop_glerror(); - release(); - stop_glerror(); + resx = llmin(resx, (U32) gGLManager.mGLMaxTextureSize); + resy = llmin(resy, (U32) gGLManager.mGLMaxTextureSize); - mResX = resx; - mResY = resy; + release(); + + mResX = resx; + mResY = resy; - mUsage = usage; + mUsage = usage; mUseDepth = depth; - mSampleDepth = sample_depth; - - if ((sUseFBO || use_fbo)) - { - if (depth) - { - if (!allocateDepth()) - { - LL_WARNS() << "Failed to allocate depth buffer for render target." << LL_ENDL; - return false; - } - } - - glGenFramebuffers(1, (GLuint *) &mFBO); - - if (mDepth) - { - glBindFramebuffer(GL_FRAMEBUFFER, mFBO); + + if (depth) + { + if (!allocateDepth()) + { + LL_WARNS() << "Failed to allocate depth buffer for render target." << LL_ENDL; + return false; + } + } + + glGenFramebuffers(1, (GLuint *) &mFBO); + + if (mDepth) + { + glBindFramebuffer(GL_FRAMEBUFFER, mFBO); - if (!canSampleDepth()) - { - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mDepth); - } - else - { - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, LLTexUnit::getInternalType(mUsage), mDepth, 0); - stop_glerror(); - } - glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO); - } - - stop_glerror(); - } - - return addColorAttachment(color_fmt); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, LLTexUnit::getInternalType(mUsage), mDepth, 0); + + glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO); + } + + return addColorAttachment(color_fmt); } void LLRenderTarget::setColorAttachment(LLImageGL* img, LLGLuint use_name) @@ -175,6 +149,7 @@ void LLRenderTarget::setColorAttachment(LLImageGL* img, LLGLuint use_name) llassert(sUseFBO); // FBO support must be enabled llassert(mDepth == 0); // depth buffers not supported with this mode llassert(mTex.empty()); // mTex must be empty with this mode (binding target should be done via LLImageGL) + llassert(!isBoundInStack()); if (mFBO == 0) { @@ -205,6 +180,7 @@ void LLRenderTarget::setColorAttachment(LLImageGL* img, LLGLuint use_name) void LLRenderTarget::releaseColorAttachment() { LL_PROFILE_ZONE_SCOPED; + llassert(!isBoundInStack()); llassert(mTex.size() == 1); //cannot use releaseColorAttachment with LLRenderTarget managed color targets llassert(mFBO != 0); // mFBO must be valid @@ -218,323 +194,291 @@ void LLRenderTarget::releaseColorAttachment() bool LLRenderTarget::addColorAttachment(U32 color_fmt) { LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY; - if (color_fmt == 0) - { - return true; - } - - U32 offset = mTex.size(); - - if( offset >= 4 ) - { - LL_WARNS() << "Too many color attachments" << LL_ENDL; - llassert( offset < 4 ); - return false; - } - if( offset > 0 && (mFBO == 0) ) - { - llassert( mFBO != 0 ); - return false; - } - - U32 tex; - LLImageGL::generateTextures(1, &tex); - gGL.getTexUnit(0)->bindManual(mUsage, tex); - - stop_glerror(); - - - { - clear_glerror(); - LLImageGL::setManualImage(LLTexUnit::getInternalType(mUsage), 0, color_fmt, mResX, mResY, GL_RGBA, GL_UNSIGNED_BYTE, NULL, false); - if (glGetError() != GL_NO_ERROR) - { - LL_WARNS() << "Could not allocate color buffer for render target." << LL_ENDL; - return false; - } - } - - sBytesAllocated += mResX*mResY*4; - - stop_glerror(); - - - if (offset == 0) - { //use bilinear filtering on single texture render targets that aren't multisampled - gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR); - stop_glerror(); - } - else - { //don't filter data attachments - gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT); - stop_glerror(); - } - - if (mUsage != LLTexUnit::TT_RECT_TEXTURE) - { - gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_MIRROR); - stop_glerror(); - } - else - { - // ATI doesn't support mirrored repeat for rectangular textures. - gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP); - stop_glerror(); - } - - if (mFBO) - { - stop_glerror(); - glBindFramebuffer(GL_FRAMEBUFFER, mFBO); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+offset, - LLTexUnit::getInternalType(mUsage), tex, 0); - stop_glerror(); - - check_framebuffer_status(); - - glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO); - } - - mTex.push_back(tex); - mInternalFormat.push_back(color_fmt); - - if (gDebugGL) - { //bind and unbind to validate target - bindTarget(); - flush(); - } + llassert(!isBoundInStack()); + + if (color_fmt == 0) + { + return true; + } + + U32 offset = mTex.size(); + + if( offset >= 4 ) + { + LL_WARNS() << "Too many color attachments" << LL_ENDL; + llassert( offset < 4 ); + return false; + } + if( offset > 0 && (mFBO == 0) ) + { + llassert( mFBO != 0 ); + return false; + } + + U32 tex; + LLImageGL::generateTextures(1, &tex); + gGL.getTexUnit(0)->bindManual(mUsage, tex); + + stop_glerror(); + + + { + clear_glerror(); + LLImageGL::setManualImage(LLTexUnit::getInternalType(mUsage), 0, color_fmt, mResX, mResY, GL_RGBA, GL_UNSIGNED_BYTE, NULL, false); + if (glGetError() != GL_NO_ERROR) + { + LL_WARNS() << "Could not allocate color buffer for render target." << LL_ENDL; + return false; + } + } + + sBytesAllocated += mResX*mResY*4; + + stop_glerror(); + + + if (offset == 0) + { //use bilinear filtering on single texture render targets that aren't multisampled + gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR); + stop_glerror(); + } + else + { //don't filter data attachments + gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT); + stop_glerror(); + } + + if (mUsage != LLTexUnit::TT_RECT_TEXTURE) + { + gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_MIRROR); + stop_glerror(); + } + else + { + // ATI doesn't support mirrored repeat for rectangular textures. + gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP); + stop_glerror(); + } + + if (mFBO) + { + glBindFramebuffer(GL_FRAMEBUFFER, mFBO); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+offset, + LLTexUnit::getInternalType(mUsage), tex, 0); + + check_framebuffer_status(); + + glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO); + } + + mTex.push_back(tex); + mInternalFormat.push_back(color_fmt); + + if (gDebugGL) + { //bind and unbind to validate target + bindTarget(); + flush(); + } - return true; + return true; } bool LLRenderTarget::allocateDepth() { LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY; - if (!mSampleDepth) - { - //use render buffers if depth buffer won't be sampled - glGenRenderbuffers(1, (GLuint *) &mDepth); - glBindRenderbuffer(GL_RENDERBUFFER, mDepth); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, mResX, mResY); - glBindRenderbuffer(GL_RENDERBUFFER, 0); - } - else - { - LLImageGL::generateTextures(1, &mDepth); - gGL.getTexUnit(0)->bindManual(mUsage, mDepth); - - U32 internal_type = LLTexUnit::getInternalType(mUsage); - stop_glerror(); - clear_glerror(); - LLImageGL::setManualImage(internal_type, 0, GL_DEPTH_COMPONENT24, mResX, mResY, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL, false); - gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT); - } - - sBytesAllocated += mResX*mResY*4; - - if (glGetError() != GL_NO_ERROR) - { - LL_WARNS() << "Unable to allocate depth buffer for render target." << LL_ENDL; - return false; - } - - return true; + LLImageGL::generateTextures(1, &mDepth); + gGL.getTexUnit(0)->bindManual(mUsage, mDepth); + + U32 internal_type = LLTexUnit::getInternalType(mUsage); + stop_glerror(); + clear_glerror(); + LLImageGL::setManualImage(internal_type, 0, GL_DEPTH_COMPONENT24, mResX, mResY, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL, false); + gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT); + + sBytesAllocated += mResX*mResY*4; + + if (glGetError() != GL_NO_ERROR) + { + LL_WARNS() << "Unable to allocate depth buffer for render target." << LL_ENDL; + return false; + } + + return true; } void LLRenderTarget::shareDepthBuffer(LLRenderTarget& target) { - if (!mFBO || !target.mFBO) - { - LL_ERRS() << "Cannot share depth buffer between non FBO render targets." << LL_ENDL; - } - - if (target.mDepth) - { - LL_ERRS() << "Attempting to override existing depth buffer. Detach existing buffer first." << LL_ENDL; - } - - if (target.mUseDepth) - { - LL_ERRS() << "Attempting to override existing shared depth buffer. Detach existing buffer first." << LL_ENDL; - } - - if (mDepth) - { - glBindFramebuffer(GL_FRAMEBUFFER, target.mFBO); - - if (!mSampleDepth) - { - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mDepth); - } - else - { - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, LLTexUnit::getInternalType(mUsage), mDepth, 0); - } - - check_framebuffer_status(); - - glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO); - - target.mUseDepth = true; - } + llassert(!isBoundInStack()); + + if (!mFBO || !target.mFBO) + { + LL_ERRS() << "Cannot share depth buffer between non FBO render targets." << LL_ENDL; + } + + if (target.mDepth) + { + LL_ERRS() << "Attempting to override existing depth buffer. Detach existing buffer first." << LL_ENDL; + } + + if (target.mUseDepth) + { + LL_ERRS() << "Attempting to override existing shared depth buffer. Detach existing buffer first." << LL_ENDL; + } + + if (mDepth) + { + glBindFramebuffer(GL_FRAMEBUFFER, target.mFBO); + + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, LLTexUnit::getInternalType(mUsage), mDepth, 0); + + check_framebuffer_status(); + + glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO); + + target.mUseDepth = true; + } } void LLRenderTarget::release() { LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY; - if (mDepth) - { - if (!mSampleDepth) - { - glDeleteRenderbuffers(1, (GLuint*) &mDepth); - } - else - { - LLImageGL::deleteTextures(1, &mDepth); - } - mDepth = 0; - - sBytesAllocated -= mResX*mResY*4; - } - else if (mFBO) - { - glBindFramebuffer(GL_FRAMEBUFFER, mFBO); - - if (mUseDepth) - { //detach shared depth buffer - if (!mSampleDepth) - { //attached as a renderbuffer - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0); - mSampleDepth = false; - } - else - { //attached as a texture - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, LLTexUnit::getInternalType(mUsage), 0, 0); - } - mUseDepth = false; - } - } - - // Detach any extra color buffers (e.g. SRGB spec buffers) - // - if (mFBO && (mTex.size() > 1)) - { - glBindFramebuffer(GL_FRAMEBUFFER, mFBO); - S32 z; - for (z = mTex.size() - 1; z >= 1; z--) - { - sBytesAllocated -= mResX*mResY*4; - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+z, LLTexUnit::getInternalType(mUsage), 0, 0); - stop_glerror(); - LLImageGL::deleteTextures(1, &mTex[z]); - } - } - - if (mFBO) - { - glDeleteFramebuffers(1, (GLuint *) &mFBO); - stop_glerror(); - mFBO = 0; - } - - if (mTex.size() > 0) - { - sBytesAllocated -= mResX*mResY*4; - LLImageGL::deleteTextures(1, &mTex[0]); - } - - mTex.clear(); - mInternalFormat.clear(); - - mResX = mResY = 0; - - sBoundTarget = NULL; + llassert(!isBoundInStack()); + + if (mDepth) + { + LLImageGL::deleteTextures(1, &mDepth); + + mDepth = 0; + + sBytesAllocated -= mResX*mResY*4; + } + else if (mFBO) + { + glBindFramebuffer(GL_FRAMEBUFFER, mFBO); + + if (mUseDepth) + { //detach shared depth buffer + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, LLTexUnit::getInternalType(mUsage), 0, 0); + mUseDepth = false; + } + + glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO); + } + + // Detach any extra color buffers (e.g. SRGB spec buffers) + // + if (mFBO && (mTex.size() > 1)) + { + glBindFramebuffer(GL_FRAMEBUFFER, mFBO); + S32 z; + for (z = mTex.size() - 1; z >= 1; z--) + { + sBytesAllocated -= mResX*mResY*4; + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+z, LLTexUnit::getInternalType(mUsage), 0, 0); + LLImageGL::deleteTextures(1, &mTex[z]); + } + glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO); + } + + if (mFBO == sCurFBO) + { + sCurFBO = 0; + glBindFramebuffer(GL_FRAMEBUFFER, 0); + } + + if (mFBO) + { + glDeleteFramebuffers(1, (GLuint *) &mFBO); + mFBO = 0; + } + + if (mTex.size() > 0) + { + sBytesAllocated -= mResX*mResY*4; + LLImageGL::deleteTextures(1, &mTex[0]); + } + + mTex.clear(); + mInternalFormat.clear(); + + mResX = mResY = 0; } void LLRenderTarget::bindTarget() { LL_PROFILE_GPU_ZONE("bindTarget"); llassert(mFBO); + llassert(!isBoundInStack()); + + glBindFramebuffer(GL_FRAMEBUFFER, mFBO); + sCurFBO = mFBO; + + //setup multiple render targets + GLenum drawbuffers[] = {GL_COLOR_ATTACHMENT0, + GL_COLOR_ATTACHMENT1, + GL_COLOR_ATTACHMENT2, + GL_COLOR_ATTACHMENT3}; + glDrawBuffers(mTex.size(), drawbuffers); + + if (mTex.empty()) + { //no color buffer to draw to + glDrawBuffer(GL_NONE); + glReadBuffer(GL_NONE); + } - if (mFBO) - { - stop_glerror(); - - mPreviousFBO = sCurFBO; - glBindFramebuffer(GL_FRAMEBUFFER, mFBO); - sCurFBO = mFBO; - - stop_glerror(); - //setup multiple render targets - GLenum drawbuffers[] = {GL_COLOR_ATTACHMENT0, - GL_COLOR_ATTACHMENT1, - GL_COLOR_ATTACHMENT2, - GL_COLOR_ATTACHMENT3}; - glDrawBuffers(mTex.size(), drawbuffers); - - if (mTex.empty()) - { //no color buffer to draw to - glDrawBuffer(GL_NONE); - glReadBuffer(GL_NONE); - } - - check_framebuffer_status(); - - stop_glerror(); - } - - mPreviousResX = sCurResX; - mPreviousResY = sCurResY; - glViewport(0, 0, mResX, mResY); - sCurResX = mResX; - sCurResY = mResY; - - sBoundTarget = this; + check_framebuffer_status(); + + glViewport(0, 0, mResX, mResY); + sCurResX = mResX; + sCurResY = mResY; + + mPreviousRT = sBoundTarget; + sBoundTarget = this; } void LLRenderTarget::clear(U32 mask_in) { LL_PROFILE_GPU_ZONE("clear"); llassert(mFBO); - U32 mask = GL_COLOR_BUFFER_BIT; - if (mUseDepth) - { - mask |= GL_DEPTH_BUFFER_BIT; // stencil buffer is deprecated, performance pnealty | GL_STENCIL_BUFFER_BIT; + U32 mask = GL_COLOR_BUFFER_BIT; + if (mUseDepth) + { + mask |= GL_DEPTH_BUFFER_BIT; - } - if (mFBO) - { - check_framebuffer_status(); - stop_glerror(); - glClear(mask & mask_in); - stop_glerror(); - } - else - { - LLGLEnable scissor(GL_SCISSOR_TEST); - glScissor(0, 0, mResX, mResY); - stop_glerror(); - glClear(mask & mask_in); - } + } + if (mFBO) + { + check_framebuffer_status(); + stop_glerror(); + glClear(mask & mask_in); + stop_glerror(); + } + else + { + LLGLEnable scissor(GL_SCISSOR_TEST); + glScissor(0, 0, mResX, mResY); + stop_glerror(); + glClear(mask & mask_in); + } } U32 LLRenderTarget::getTexture(U32 attachment) const { - if (attachment > mTex.size()-1) - { - LL_ERRS() << "Invalid attachment index." << LL_ENDL; - } - if (mTex.empty()) - { - return 0; - } - return mTex[attachment]; + if (attachment > mTex.size()-1) + { + LL_ERRS() << "Invalid attachment index." << LL_ENDL; + } + if (mTex.empty()) + { + return 0; + } + return mTex[attachment]; } U32 LLRenderTarget::getNumTextures() const { - return mTex.size(); + return mTex.size(); } void LLRenderTarget::bindTexture(U32 index, S32 channel, LLTexUnit::eTextureFilterOptions filter_options) @@ -560,64 +504,54 @@ void LLRenderTarget::bindTexture(U32 index, S32 channel, LLTexUnit::eTextureFilt gGL.getTexUnit(channel)->setTextureColorSpace(isSRGB ? LLTexUnit::TCS_SRGB : LLTexUnit::TCS_LINEAR); } -void LLRenderTarget::flush(bool fetch_depth) +void LLRenderTarget::flush() { LL_PROFILE_GPU_ZONE("rt flush"); - gGL.flush(); + gGL.flush(); llassert(mFBO); - if (!mFBO) - { - gGL.getTexUnit(0)->bind(this); - glCopyTexSubImage2D(LLTexUnit::getInternalType(mUsage), 0, 0, 0, 0, 0, mResX, mResY); - - if (fetch_depth) - { - if (!mDepth) - { - allocateDepth(); - } - - gGL.getTexUnit(0)->bind(this); - glCopyTexImage2D(LLTexUnit::getInternalType(mUsage), 0, GL_DEPTH24_STENCIL8, 0, 0, mResX, mResY, 0); - } - - gGL.getTexUnit(0)->disable(); - } - else - { - stop_glerror(); - glBindFramebuffer(GL_FRAMEBUFFER, mPreviousFBO); - sCurFBO = mPreviousFBO; - - if (mPreviousFBO) - { - glViewport(0, 0, mPreviousResX, mPreviousResY); - sCurResX = mPreviousResX; - sCurResY = mPreviousResY; - } - else - { - glViewport(gGLViewport[0],gGLViewport[1],gGLViewport[2],gGLViewport[3]); - sCurResX = gGLViewport[2]; - sCurResY = gGLViewport[3]; - } - - stop_glerror(); - } + llassert(sCurFBO == mFBO); + llassert(sBoundTarget == this); + + if (mPreviousRT) + { + // a bit hacky -- pop the RT stack back two frames and push + // the previous frame back on to play nice with the GL state machine + sBoundTarget = mPreviousRT->mPreviousRT; + mPreviousRT->bindTarget(); + } + else + { + sBoundTarget = nullptr; + glBindFramebuffer(GL_FRAMEBUFFER, 0); + sCurFBO = 0; + glViewport(gGLViewport[0], gGLViewport[1], gGLViewport[2], gGLViewport[3]); + sCurResX = gGLViewport[2]; + sCurResY = gGLViewport[3]; + } } bool LLRenderTarget::isComplete() const { - return (!mTex.empty() || mDepth) ? true : false; + return (!mTex.empty() || mDepth) ? true : false; } void LLRenderTarget::getViewport(S32* viewport) { - viewport[0] = 0; - viewport[1] = 0; - viewport[2] = mResX; - viewport[3] = mResY; + viewport[0] = 0; + viewport[1] = 0; + viewport[2] = mResX; + viewport[3] = mResY; } +bool LLRenderTarget::isBoundInStack() const +{ + LLRenderTarget* cur = sBoundTarget; + while (cur && cur != this) + { + cur = cur->mPreviousRT; + } + + return cur == this; +} -- cgit v1.2.3 From 5bf60f5d9e722f6210572fd92e79e9994abd2ec1 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Wed, 5 Apr 2023 16:48:34 -0500 Subject: =?UTF-8?q?SL-19538=20Followup=20--=20fix=20for=20dynamic=20exposu?= =?UTF-8?q?re=20having=20large=20gaps=20in=20it=E2=80=A6=20(#157)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * SL-19538 Followup -- fix for dynamic exposure having large gaps in its luminance sampling. * SL-19538 Followup -- review feedback changes. --- indra/llrender/llrendertarget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llrender/llrendertarget.cpp') diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index 6dac614eea..7f507a0b58 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -483,7 +483,7 @@ U32 LLRenderTarget::getNumTextures() const void LLRenderTarget::bindTexture(U32 index, S32 channel, LLTexUnit::eTextureFilterOptions filter_options) { - gGL.getTexUnit(channel)->bindManual(mUsage, getTexture(index)); + gGL.getTexUnit(channel)->bindManual(mUsage, getTexture(index), filter_options == LLTexUnit::TFO_TRILINEAR || filter_options == LLTexUnit::TFO_ANISOTROPIC); bool isSRGB = false; llassert(mInternalFormat.size() > index); -- cgit v1.2.3 From f4274ba64e40b487dea2e7c0bfaee47232b55736 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Fri, 14 Apr 2023 03:08:28 -0700 Subject: Move mipmap generation into LLRenderTarget. DRTVWR-583 --- indra/llrender/llrendertarget.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'indra/llrender/llrendertarget.cpp') diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index 7f507a0b58..629664b76d 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -102,7 +102,7 @@ void LLRenderTarget::resize(U32 resx, U32 resy) } -bool LLRenderTarget::allocate(U32 resx, U32 resy, U32 color_fmt, bool depth, LLTexUnit::eTextureType usage) +bool LLRenderTarget::allocate(U32 resx, U32 resy, U32 color_fmt, bool depth, LLTexUnit::eTextureType usage, LLTexUnit::eTextureMipGeneration generateMipMaps) { LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY; llassert(usage == LLTexUnit::TT_TEXTURE); @@ -118,6 +118,13 @@ bool LLRenderTarget::allocate(U32 resx, U32 resy, U32 color_fmt, bool depth, LLT mUsage = usage; mUseDepth = depth; + + mGenerateMipMaps = generateMipMaps; + + if (mGenerateMipMaps != LLTexUnit::TMG_NONE) { + // Calculate the number of mip levels based upon resolution that we should have. + mMipLevels = 1 + floor(log10((float)llmax(mResX, mResY))/log10(2.0)); + } if (depth) { @@ -512,6 +519,12 @@ void LLRenderTarget::flush() llassert(sCurFBO == mFBO); llassert(sBoundTarget == this); + if (mGenerateMipMaps == LLTexUnit::TMG_AUTO) { + LL_PROFILE_GPU_ZONE("rt generate mipmaps"); + bindTexture(0, 0, LLTexUnit::TFO_TRILINEAR); + glGenerateMipmap(GL_TEXTURE_2D); + } + if (mPreviousRT) { // a bit hacky -- pop the RT stack back two frames and push -- cgit v1.2.3 From a3b1d0beb610338d9f7c9c6618bc15bc7e9be40d Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 27 Apr 2023 16:05:07 -0500 Subject: SL-19197 Fix for crash in LLRenderTarget::release --- indra/llrender/llrendertarget.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'indra/llrender/llrendertarget.cpp') diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index 629664b76d..88c48e5166 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -388,14 +388,14 @@ void LLRenderTarget::release() glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO); } - if (mFBO == sCurFBO) - { - sCurFBO = 0; - glBindFramebuffer(GL_FRAMEBUFFER, 0); - } - if (mFBO) { + if (mFBO == sCurFBO) + { + sCurFBO = 0; + glBindFramebuffer(GL_FRAMEBUFFER, 0); + } + glDeleteFramebuffers(1, (GLuint *) &mFBO); mFBO = 0; } -- cgit v1.2.3