From 1df7760d315430766bba44d4d4c64480b4a6138f Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 14 Sep 2018 21:52:52 +0100 Subject: SL-9632 add uniform and code to supress atmospherics in all shaders that could be used by HUDs Make sky and cloud shaders use common scaleSoftClip implementation in gammaF.glsl --- indra/newview/lldrawpoolalpha.cpp | 51 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) (limited to 'indra/newview/lldrawpoolalpha.cpp') diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 0873300cd2..7679d44826 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -117,6 +117,14 @@ void LLDrawPoolAlpha::beginPostDeferredPass(S32 pass) fullbright_shader->uniform1f(LLShaderMgr::DISPLAY_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); fullbright_shader->unbind(); + if (LLPipeline::sRenderingHUDs) + { + fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); + } + else + { + fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); + } //prime simple shader (loads shadow relevant uniforms) gPipeline.bindDeferredShader(*simple_shader); @@ -260,17 +268,49 @@ void LLDrawPoolAlpha::render(S32 pass) { if (LLPipeline::sImpostorRender) { - fullbright_shader->bind(); + fullbright_shader->bind(); fullbright_shader->setMinimumAlpha(0.5f); + if (LLPipeline::sRenderingHUDs) + { + fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); + } + else + { + fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); + } simple_shader->bind(); simple_shader->setMinimumAlpha(0.5f); + if (LLPipeline::sRenderingHUDs) + { + simple_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); + } + else + { + simple_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); + } } else { fullbright_shader->bind(); fullbright_shader->setMinimumAlpha(0.f); + if (LLPipeline::sRenderingHUDs) + { + fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); + } + else + { + fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); + } simple_shader->bind(); simple_shader->setMinimumAlpha(0.f); + if (LLPipeline::sRenderingHUDs) + { + simple_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); + } + else + { + simple_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); + } } } else @@ -610,7 +650,14 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) LLRender::BF_ONE, LLRender::BF_ONE); // add to alpha (glow) emissive_shader->bind(); - + if (LLPipeline::sRenderingHUDs) + { + emissive_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); + } + else + { + emissive_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); + } params.mVertexBuffer->setBuffer((mask & ~LLVertexBuffer::MAP_COLOR) | LLVertexBuffer::MAP_EMISSIVE); // do the actual drawing, again -- cgit v1.2.3 From 7e9033821a96a9d6e80b58fafb4c7da63807b9d4 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 6 Dec 2018 10:59:11 -0800 Subject: De-duplicate deferred gbuffer access for getPosition/getNorm. De-duplicate ambient occlusion shader code and move to new aoUtil.glsl Split shared shadow tap funcs into shadowUtil.glsl --- indra/newview/lldrawpoolalpha.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'indra/newview/lldrawpoolalpha.cpp') diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 7679d44826..73582e2345 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -69,7 +69,7 @@ LLDrawPoolAlpha::~LLDrawPoolAlpha() void LLDrawPoolAlpha::prerender() { - mVertexShaderLevel = LLViewerShaderMgr::instance()->getVertexShaderLevel(LLViewerShaderMgr::SHADER_OBJECT); + mShaderLevel = LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_OBJECT); } S32 LLDrawPoolAlpha::getNumPostDeferredPasses() @@ -160,7 +160,7 @@ void LLDrawPoolAlpha::beginPostDeferredPass(S32 pass) } deferred_render = TRUE; - if (mVertexShaderLevel > 0) + if (mShaderLevel > 0) { // Start out with no shaders. current_shader = target_shader = NULL; @@ -209,7 +209,7 @@ void LLDrawPoolAlpha::beginRenderPass(S32 pass) emissive_shader = &gObjectEmissiveProgram; } - if (mVertexShaderLevel > 0) + if (mShaderLevel > 0) { // Start out with no shaders. current_shader = target_shader = NULL; @@ -264,7 +264,7 @@ void LLDrawPoolAlpha::render(S32 pass) mAlphaDFactor = LLRender::BF_ONE_MINUS_SOURCE_ALPHA; // } gGL.blendFunc(mColorSFactor, mColorDFactor, mAlphaSFactor, mAlphaDFactor); - if (mVertexShaderLevel > 0) + if (mShaderLevel > 0) { if (LLPipeline::sImpostorRender) { @@ -326,7 +326,7 @@ void LLDrawPoolAlpha::render(S32 pass) } } - if (mVertexShaderLevel > 0) + if (mShaderLevel > 0) { renderAlpha(getVertexDataMask() | LLVertexBuffer::MAP_TEXTURE_INDEX | LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2, pass); } @@ -432,7 +432,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) bool is_particle_or_hud_particle = group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_PARTICLE || group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_HUD_PARTICLE; - bool draw_glow_for_this_partition = mVertexShaderLevel > 0; // no shaders = no glow. + bool draw_glow_for_this_partition = mShaderLevel > 0; // no shaders = no glow. LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_GROUP_LOOP); -- cgit v1.2.3 From d7ad30a2d4dfd83f93b0150464214f2df776eb9c Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 27 Feb 2019 17:07:31 -0800 Subject: SL-10566 part the fourth Fix water rendering causing distortion map update very frame. Reduce binds in alpha draw pool for HUD atmo suppression (may regress HUD lighting weirdness). Add ability to retrieve current user clip plane so it can be saved/restored around water map gen. Leave render type masks as is after reflection map render to get detail filtering applied to distortion map again. Re-enable occlusion in distortion map rendering. --- indra/newview/lldrawpoolalpha.cpp | 121 ++++++++++++-------------------------- 1 file changed, 36 insertions(+), 85 deletions(-) (limited to 'indra/newview/lldrawpoolalpha.cpp') diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 73582e2345..b896ecde30 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -90,7 +90,7 @@ S32 LLDrawPoolAlpha::getNumPostDeferredPasses() void LLDrawPoolAlpha::beginPostDeferredPass(S32 pass) { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA); + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED); if (pass == 0) { @@ -115,20 +115,14 @@ void LLDrawPoolAlpha::beginPostDeferredPass(S32 pass) fullbright_shader->bind(); fullbright_shader->uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); fullbright_shader->uniform1f(LLShaderMgr::DISPLAY_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); - fullbright_shader->unbind(); + fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, LLPipeline::sRenderingHUDs ? 1 : 0); + fullbright_shader->setMinimumAlpha(LLPipeline::sImpostorRender ? 0.5f : 0.0f); + fullbright_shader->unbind(); - if (LLPipeline::sRenderingHUDs) - { - fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); - } - else - { - fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); - } //prime simple shader (loads shadow relevant uniforms) gPipeline.bindDeferredShader(*simple_shader); - - simple_shader->uniform1f(LLShaderMgr::DISPLAY_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); + simple_shader->uniform1f(LLShaderMgr::DISPLAY_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); + simple_shader->setMinimumAlpha(LLPipeline::sImpostorRender ? 0.5f : 0.0f); } else if (!LLPipeline::sImpostorRender) { @@ -170,6 +164,8 @@ void LLDrawPoolAlpha::beginPostDeferredPass(S32 pass) void LLDrawPoolAlpha::endPostDeferredPass(S32 pass) { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED); + if (pass == 1 && !LLPipeline::sImpostorRender) { gPipeline.mDeferredDepth.flush(); @@ -183,6 +179,7 @@ void LLDrawPoolAlpha::endPostDeferredPass(S32 pass) void LLDrawPoolAlpha::renderPostDeferred(S32 pass) { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED); render(pass); } @@ -195,6 +192,18 @@ void LLDrawPoolAlpha::beginRenderPass(S32 pass) simple_shader = &gObjectSimpleImpostorProgram; fullbright_shader = &gObjectFullbrightProgram; emissive_shader = &gObjectEmissiveProgram; + + if (mShaderLevel > 0) + { + fullbright_shader->bind(); + fullbright_shader->setMinimumAlpha(0.5f); + simple_shader->bind(); + simple_shader->setMinimumAlpha(0.5f); + } + else + { + gGL.setAlphaRejectSettings(LLRender::CF_GREATER, 0.5f); //OK + } } else if (LLPipeline::sUnderWaterRender) { @@ -209,12 +218,20 @@ void LLDrawPoolAlpha::beginRenderPass(S32 pass) emissive_shader = &gObjectEmissiveProgram; } - if (mShaderLevel > 0) + if (!LLPipeline::sImpostorRender) { - // Start out with no shaders. - current_shader = target_shader = NULL; - LLGLSLShader::bindNoShader(); - } + if (mShaderLevel > 0) + { + fullbright_shader->bind(); + fullbright_shader->setMinimumAlpha(0.f); + simple_shader->bind(); + simple_shader->setMinimumAlpha(0.f); + } + else + { + gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT); //OK + } + } gPipeline.enableLightsDynamic(); } @@ -264,66 +281,7 @@ void LLDrawPoolAlpha::render(S32 pass) mAlphaDFactor = LLRender::BF_ONE_MINUS_SOURCE_ALPHA; // } gGL.blendFunc(mColorSFactor, mColorDFactor, mAlphaSFactor, mAlphaDFactor); - if (mShaderLevel > 0) - { - if (LLPipeline::sImpostorRender) - { - fullbright_shader->bind(); - fullbright_shader->setMinimumAlpha(0.5f); - if (LLPipeline::sRenderingHUDs) - { - fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); - } - else - { - fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); - } - simple_shader->bind(); - simple_shader->setMinimumAlpha(0.5f); - if (LLPipeline::sRenderingHUDs) - { - simple_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); - } - else - { - simple_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); - } - } - else - { - fullbright_shader->bind(); - fullbright_shader->setMinimumAlpha(0.f); - if (LLPipeline::sRenderingHUDs) - { - fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); - } - else - { - fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); - } - simple_shader->bind(); - simple_shader->setMinimumAlpha(0.f); - if (LLPipeline::sRenderingHUDs) - { - simple_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); - } - else - { - simple_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); - } - } - } - else - { - if (LLPipeline::sImpostorRender) - { - gGL.setAlphaRejectSettings(LLRender::CF_GREATER, 0.5f); //OK - } - else - { - gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT); //OK - } - } + } if (mShaderLevel > 0) @@ -650,14 +608,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) LLRender::BF_ONE, LLRender::BF_ONE); // add to alpha (glow) emissive_shader->bind(); - if (LLPipeline::sRenderingHUDs) - { - emissive_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); - } - else - { - emissive_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); - } + params.mVertexBuffer->setBuffer((mask & ~LLVertexBuffer::MAP_COLOR) | LLVertexBuffer::MAP_EMISSIVE); // do the actual drawing, again -- cgit v1.2.3 From c1d2416826406631807f153e7de9d2b790b0caa5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 28 Feb 2019 14:06:19 -0800 Subject: EEP performance WIP Mods to improve alpha obj render performance. Removes hacky fix for HUD elements getting atmospherics. Re-orders rendering of glow to remove ~10ms/frame of shader re-re-rebinding. Fix up default classes and basic shader loading (remove unused shared modules). --- indra/newview/lldrawpoolalpha.cpp | 621 +++++++++++++++++++++----------------- 1 file changed, 350 insertions(+), 271 deletions(-) (limited to 'indra/newview/lldrawpoolalpha.cpp') diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index b896ecde30..5396a8fdd2 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -53,6 +53,19 @@ BOOL LLDrawPoolAlpha::sShowDebugAlpha = FALSE; static BOOL deferred_render = FALSE; +static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_SETUP("Alpha Setup"); +static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_GROUP_LOOP("Alpha Group"); +static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_PUSH("Alpha Push Verts"); +static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_DEFERRED("Alpha Deferred"); +static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_SETBUFFER("Alpha SetBuffer"); +static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_DRAW("Alpha Draw"); +static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_TEX_BINDS("Alpha Tex Binds"); +static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_MATS("Alpha Mat Tex Binds"); +static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_GLOW("Alpha Glow Binds"); +static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_SHADER_BINDS("Alpha Shader Binds"); +static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_DEFERRED_SHADER_BINDS("Alpha Def Binds"); +static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_MESH_REBUILD("Alpha Mesh Rebuild"); + LLDrawPoolAlpha::LLDrawPoolAlpha(U32 type) : LLRenderPass(type), current_shader(NULL), target_shader(NULL), simple_shader(NULL), fullbright_shader(NULL), emissive_shader(NULL), @@ -115,7 +128,6 @@ void LLDrawPoolAlpha::beginPostDeferredPass(S32 pass) fullbright_shader->bind(); fullbright_shader->uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); fullbright_shader->uniform1f(LLShaderMgr::DISPLAY_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); - fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, LLPipeline::sRenderingHUDs ? 1 : 0); fullbright_shader->setMinimumAlpha(LLPipeline::sImpostorRender ? 0.5f : 0.0f); fullbright_shader->unbind(); @@ -185,25 +197,13 @@ void LLDrawPoolAlpha::renderPostDeferred(S32 pass) void LLDrawPoolAlpha::beginRenderPass(S32 pass) { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA); + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_SETUP); if (LLPipeline::sImpostorRender) { simple_shader = &gObjectSimpleImpostorProgram; fullbright_shader = &gObjectFullbrightProgram; emissive_shader = &gObjectEmissiveProgram; - - if (mShaderLevel > 0) - { - fullbright_shader->bind(); - fullbright_shader->setMinimumAlpha(0.5f); - simple_shader->bind(); - simple_shader->setMinimumAlpha(0.5f); - } - else - { - gGL.setAlphaRejectSettings(LLRender::CF_GREATER, 0.5f); //OK - } } else if (LLPipeline::sUnderWaterRender) { @@ -218,26 +218,18 @@ void LLDrawPoolAlpha::beginRenderPass(S32 pass) emissive_shader = &gObjectEmissiveProgram; } - if (!LLPipeline::sImpostorRender) + if (mShaderLevel > 0) { - if (mShaderLevel > 0) - { - fullbright_shader->bind(); - fullbright_shader->setMinimumAlpha(0.f); - simple_shader->bind(); - simple_shader->setMinimumAlpha(0.f); - } - else - { - gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT); //OK - } - } + // Start out with no shaders. + current_shader = target_shader = NULL; + LLGLSLShader::bindNoShader(); + } gPipeline.enableLightsDynamic(); } void LLDrawPoolAlpha::endRenderPass( S32 pass ) { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA); + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_SETUP); LLRenderPass::endRenderPass(pass); if(gPipeline.canUseWindLightShaders()) @@ -281,7 +273,34 @@ void LLDrawPoolAlpha::render(S32 pass) mAlphaDFactor = LLRender::BF_ONE_MINUS_SOURCE_ALPHA; // } gGL.blendFunc(mColorSFactor, mColorDFactor, mAlphaSFactor, mAlphaDFactor); - + if (mShaderLevel > 0) + { + if (LLPipeline::sImpostorRender) + { + fullbright_shader->bind(); + fullbright_shader->setMinimumAlpha(0.5f); + simple_shader->bind(); + simple_shader->setMinimumAlpha(0.5f); + } + else + { + fullbright_shader->bind(); + fullbright_shader->setMinimumAlpha(0.f); + simple_shader->bind(); + simple_shader->setMinimumAlpha(0.f); + } + } + else + { + if (LLPipeline::sImpostorRender) + { + gGL.setAlphaRejectSettings(LLRender::CF_GREATER, 0.5f); //OK + } + else + { + gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT); //OK + } + } } if (mShaderLevel > 0) @@ -368,268 +387,328 @@ void LLDrawPoolAlpha::renderAlphaHighlight(U32 mask) } } -static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_GROUP_LOOP("Alpha Group"); -static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_PUSH("Alpha Push Verts"); - void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA); + BOOL initialized_lighting = FALSE; BOOL light_enabled = TRUE; BOOL use_shaders = gPipeline.canUseVertexShaders(); - - for (LLCullResult::sg_iterator i = gPipeline.beginAlphaGroups(); i != gPipeline.endAlphaGroups(); ++i) - { - LLSpatialGroup* group = *i; - llassert(group); - llassert(group->getSpatialPartition()); - - if (group->getSpatialPartition()->mRenderByGroup && - !group->isDead()) - { - bool is_particle_or_hud_particle = group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_PARTICLE - || group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_HUD_PARTICLE; - - bool draw_glow_for_this_partition = mShaderLevel > 0; // no shaders = no glow. - - - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_GROUP_LOOP); - - bool disable_cull = is_particle_or_hud_particle; - LLGLDisable cull(disable_cull ? GL_CULL_FACE : 0); - - LLSpatialGroup::drawmap_elem_t& draw_info = group->mDrawMap[LLRenderPass::PASS_ALPHA]; - - for (LLSpatialGroup::drawmap_elem_t::iterator k = draw_info.begin(); k != draw_info.end(); ++k) - { - LLDrawInfo& params = **k; - - if ((params.mVertexBuffer->getTypeMask() & mask) != mask) - { //FIXME! - LL_WARNS_ONCE() << "Missing required components, expected mask: " << mask - << " present: " << (params.mVertexBuffer->getTypeMask() & mask) - << ". Skipping render batch." << LL_ENDL; - continue; - } - - // Fix for bug - NORSPEC-271 - // If the face is more than 90% transparent, then don't update the Depth buffer for Dof - // We don't want the nearly invisible objects to cause of DoF effects - if(pass == 1 && !LLPipeline::sImpostorRender) - { - LLFace* face = params.mFace; - if(face) - { - const LLTextureEntry* tep = face->getTextureEntry(); - if(tep) - { - if(tep->getColor().mV[3] < 0.1f) - continue; - } - } - } - LLRenderPass::applyModelMatrix(params); - - LLMaterial* mat = NULL; + { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_GROUP_LOOP); - if (deferred_render) - { - mat = params.mMaterial; - } + for (LLCullResult::sg_iterator i = gPipeline.beginAlphaGroups(); i != gPipeline.endAlphaGroups(); ++i) + { + LLSpatialGroup* group = *i; + llassert(group); + llassert(group->getSpatialPartition()); + + if (group->getSpatialPartition()->mRenderByGroup && + !group->isDead()) + { + bool is_particle_or_hud_particle = group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_PARTICLE + || group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_HUD_PARTICLE; + + bool disable_cull = is_particle_or_hud_particle; + LLGLDisable cull(disable_cull ? GL_CULL_FACE : 0); + + LLSpatialGroup::drawmap_elem_t& draw_info = group->mDrawMap[LLRenderPass::PASS_ALPHA]; + + for (LLSpatialGroup::drawmap_elem_t::iterator k = draw_info.begin(); k != draw_info.end(); ++k) + { + LLDrawInfo& params = **k; + + if ((params.mVertexBuffer->getTypeMask() & mask) != mask) + { //FIXME! + LL_WARNS_ONCE() << "Missing required components, expected mask: " << mask + << " present: " << (params.mVertexBuffer->getTypeMask() & mask) + << ". Skipping render batch." << LL_ENDL; + continue; + } + + // Fix for bug - NORSPEC-271 + // If the face is more than 90% transparent, then don't update the Depth buffer for Dof + // We don't want the nearly invisible objects to cause of DoF effects + if(pass == 1 && !LLPipeline::sImpostorRender) + { + LLFace* face = params.mFace; + if(face) + { + const LLTextureEntry* tep = face->getTextureEntry(); + if(tep) + { + if(tep->getColor().mV[3] < 0.1f) + continue; + } + } + } + + LLRenderPass::applyModelMatrix(params); + + LLMaterial* mat = NULL; + + if (deferred_render) + { + mat = params.mMaterial; + } - if (params.mFullbright) - { - // Turn off lighting if it hasn't already been so. - if (light_enabled || !initialized_lighting) - { - initialized_lighting = TRUE; - if (use_shaders) - { - target_shader = fullbright_shader; - } - else - { - gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); - } - light_enabled = FALSE; - } - } - // Turn on lighting if it isn't already. - else if (!light_enabled || !initialized_lighting) - { - initialized_lighting = TRUE; - if (use_shaders) - { - target_shader = simple_shader; - } - else - { - gPipeline.enableLightsDynamic(); - } - light_enabled = TRUE; - } - - if (deferred_render && mat) - { - U32 mask = params.mShaderMask; - - llassert(mask < LLMaterial::SHADER_COUNT); - target_shader = &(gDeferredMaterialProgram[mask]); - - if (LLPipeline::sUnderWaterRender) - { - target_shader = &(gDeferredMaterialWaterProgram[mask]); - } - - if (current_shader != target_shader) - { - gPipeline.bindDeferredShader(*target_shader); - } - } - else if (!params.mFullbright) - { - target_shader = simple_shader; - } - else - { - target_shader = fullbright_shader; - } + if (params.mFullbright) + { + // Turn off lighting if it hasn't already been so. + if (light_enabled || !initialized_lighting) + { + initialized_lighting = TRUE; + if (use_shaders) + { + target_shader = fullbright_shader; + } + else + { + gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); + } + light_enabled = FALSE; + } + } + // Turn on lighting if it isn't already. + else if (!light_enabled || !initialized_lighting) + { + initialized_lighting = TRUE; + if (use_shaders) + { + target_shader = simple_shader; + } + else + { + gPipeline.enableLightsDynamic(); + } + light_enabled = TRUE; + } + + if (deferred_render && mat) + { + U32 mask = params.mShaderMask; + + llassert(mask < LLMaterial::SHADER_COUNT); + target_shader = &(gDeferredMaterialProgram[mask]); + + if (LLPipeline::sUnderWaterRender) + { + target_shader = &(gDeferredMaterialWaterProgram[mask]); + } + + if (current_shader != target_shader) + { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED_SHADER_BINDS); + gPipeline.bindDeferredShader(*target_shader); + current_shader = target_shader; + } + } + else if (!params.mFullbright) + { + target_shader = simple_shader; + } + else + { + target_shader = fullbright_shader; + } - if(use_shaders && (current_shader != target_shader)) - {// If we need shaders, and we're not ALREADY using the proper shader, then bind it - // (this way we won't rebind shaders unnecessarily). - current_shader = target_shader; - current_shader->bind(); - } - else if (!use_shaders && current_shader != NULL) - { - LLGLSLShader::bindNoShader(); - current_shader = NULL; - } - - if (use_shaders && mat) - { - // We have a material. Supply the appropriate data here. - if (LLPipeline::sRenderDeferred) - { - current_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, params.mSpecColor.mV[0], params.mSpecColor.mV[1], params.mSpecColor.mV[2], params.mSpecColor.mV[3]); - current_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, params.mEnvIntensity); - current_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, params.mFullbright ? 1.f : 0.f); - - if (params.mNormalMap) - { - params.mNormalMap->addTextureStats(params.mVSize); - current_shader->bindTexture(LLShaderMgr::BUMP_MAP, params.mNormalMap); - } + if(use_shaders && (current_shader != target_shader)) + {// If we need shaders, and we're not ALREADY using the proper shader, then bind it + // (this way we won't rebind shaders unnecessarily). + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_SHADER_BINDS); + + current_shader = target_shader; + current_shader->bind(); + } + else if (!use_shaders && current_shader != NULL) + { + LLGLSLShader::bindNoShader(); + current_shader = NULL; + } + + if (use_shaders && mat) + { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_MATS); + + // We have a material. Supply the appropriate data here. + if (LLPipeline::sRenderDeferred) + { + current_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, params.mSpecColor.mV[0], params.mSpecColor.mV[1], params.mSpecColor.mV[2], params.mSpecColor.mV[3]); + current_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, params.mEnvIntensity); + current_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, params.mFullbright ? 1.f : 0.f); + + if (params.mNormalMap) + { + params.mNormalMap->addTextureStats(params.mVSize); + current_shader->bindTexture(LLShaderMgr::BUMP_MAP, params.mNormalMap); + } - if (params.mSpecularMap) - { - params.mSpecularMap->addTextureStats(params.mVSize); - current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, params.mSpecularMap); - } - } - - } else if (LLPipeline::sRenderDeferred && current_shader && (current_shader == simple_shader)) - { - current_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, 1.0f, 1.0f, 1.0f, 1.0f); - current_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, 0.0f); - LLViewerFetchedTexture::sFlatNormalImagep->addTextureStats(params.mVSize); - current_shader->bindTexture(LLShaderMgr::BUMP_MAP, LLViewerFetchedTexture::sFlatNormalImagep); - LLViewerFetchedTexture::sWhiteImagep->addTextureStats(params.mVSize); - current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, LLViewerFetchedTexture::sWhiteImagep); - } - - if (params.mGroup) - { - params.mGroup->rebuildMesh(); - } + if (params.mSpecularMap) + { + params.mSpecularMap->addTextureStats(params.mVSize); + current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, params.mSpecularMap); + } + } + + } + else if (LLPipeline::sRenderDeferred && current_shader && (current_shader == simple_shader)) + { + current_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, 1.0f, 1.0f, 1.0f, 1.0f); + current_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, 0.0f); + LLViewerFetchedTexture::sFlatNormalImagep->addTextureStats(params.mVSize); + current_shader->bindTexture(LLShaderMgr::BUMP_MAP, LLViewerFetchedTexture::sFlatNormalImagep); + LLViewerFetchedTexture::sWhiteImagep->addTextureStats(params.mVSize); + current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, LLViewerFetchedTexture::sWhiteImagep); + } + + if (params.mGroup) + { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_MESH_REBUILD); + + params.mGroup->rebuildMesh(); + } + + bool tex_setup = false; + + if (use_shaders && params.mTextureList.size() > 1) + { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_TEX_BINDS); + for (U32 i = 0; i < params.mTextureList.size(); ++i) + { + if (params.mTextureList[i].notNull()) + { + gGL.getTexUnit(i)->bind(params.mTextureList[i], TRUE); + } + } + } + else + { //not batching textures or batch has only 1 texture -- might need a texture matrix + if (params.mTexture.notNull()) + { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_TEX_BINDS); + + params.mTexture->addTextureStats(params.mVSize); + if (use_shaders && mat) + { + current_shader->bindTexture(LLShaderMgr::DIFFUSE_MAP, params.mTexture); + } + else + { + gGL.getTexUnit(0)->bind(params.mTexture, TRUE) ; + } + + if (params.mTextureMatrix) + { + tex_setup = true; + gGL.getTexUnit(0)->activate(); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadMatrix((GLfloat*) params.mTextureMatrix->mMatrix); + gPipeline.mTextureMatrixOps++; + } + } + else + { + gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); + } + } + + { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_PUSH); + + LLGLEnableFunc stencil_test(GL_STENCIL_TEST, params.mSelected, &LLGLCommonFunc::selected_stencil_test); + + { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_SETBUFFER); + gGL.blendFunc((LLRender::eBlendFactor) params.mBlendFuncSrc, (LLRender::eBlendFactor) params.mBlendFuncDst, mAlphaSFactor, mAlphaDFactor); + params.mVertexBuffer->setBuffer(mask & ~(params.mFullbright ? (LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2) : 0)); + } + + { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DRAW); + params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); + } + + gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); + } + + if (tex_setup) + { + gGL.getTexUnit(0)->activate(); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_MODELVIEW); + } + } + } + } + + bool draw_glow_for_this_partition = mShaderLevel > 0; // no shaders = no glow. + + if (use_shaders && draw_glow_for_this_partition) + { + // install glow-accumulating blend mode + gGL.blendFunc(LLRender::BF_ZERO, LLRender::BF_ONE, // don't touch color + LLRender::BF_ONE, LLRender::BF_ONE); // add to alpha (glow) - bool tex_setup = false; + emissive_shader->bind(); - if (use_shaders && params.mTextureList.size() > 1) - { - for (U32 i = 0; i < params.mTextureList.size(); ++i) - { - if (params.mTextureList[i].notNull()) - { - gGL.getTexUnit(i)->bind(params.mTextureList[i], TRUE); - } - } - } - else - { //not batching textures or batch has only 1 texture -- might need a texture matrix - if (params.mTexture.notNull()) - { - params.mTexture->addTextureStats(params.mVSize); - if (use_shaders && mat) - { - current_shader->bindTexture(LLShaderMgr::DIFFUSE_MAP, params.mTexture); - } - else - { - gGL.getTexUnit(0)->bind(params.mTexture, TRUE) ; - } - - if (params.mTextureMatrix) - { - tex_setup = true; - gGL.getTexUnit(0)->activate(); - gGL.matrixMode(LLRender::MM_TEXTURE); - gGL.loadMatrix((GLfloat*) params.mTextureMatrix->mMatrix); - gPipeline.mTextureMatrixOps++; - } - } - else - { - gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - } - } + for (LLCullResult::sg_iterator i = gPipeline.beginAlphaGroups(); i != gPipeline.endAlphaGroups(); ++i) + { + LLSpatialGroup* group = *i; + llassert(group); + llassert(group->getSpatialPartition()); - { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_PUSH); + if (group->getSpatialPartition()->mRenderByGroup && + !group->isDead()) + { + bool is_particle_or_hud_particle = group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_PARTICLE + || group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_HUD_PARTICLE; - LLGLEnableFunc stencil_test(GL_STENCIL_TEST, params.mSelected, &LLGLCommonFunc::selected_stencil_test); + - gGL.blendFunc((LLRender::eBlendFactor) params.mBlendFuncSrc, (LLRender::eBlendFactor) params.mBlendFuncDst, mAlphaSFactor, mAlphaDFactor); - params.mVertexBuffer->setBuffer(mask & ~(params.mFullbright ? (LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2) : 0)); + bool disable_cull = is_particle_or_hud_particle; + LLGLDisable cull(disable_cull ? GL_CULL_FACE : 0); - params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); - gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); - } - - // If this alpha mesh has glow, then draw it a second time to add the destination-alpha (=glow). Interleaving these state-changing calls could be expensive, but glow must be drawn Z-sorted with alpha. - if (current_shader && - draw_glow_for_this_partition && - params.mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE)) - { - // install glow-accumulating blend mode - gGL.blendFunc(LLRender::BF_ZERO, LLRender::BF_ONE, // don't touch color - LLRender::BF_ONE, LLRender::BF_ONE); // add to alpha (glow) + LLSpatialGroup::drawmap_elem_t& draw_info = group->mDrawMap[LLRenderPass::PASS_ALPHA]; - emissive_shader->bind(); - - params.mVertexBuffer->setBuffer((mask & ~LLVertexBuffer::MAP_COLOR) | LLVertexBuffer::MAP_EMISSIVE); - - // do the actual drawing, again - params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); - gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); + for (LLSpatialGroup::drawmap_elem_t::iterator k = draw_info.begin(); k != draw_info.end(); ++k) + { + LLDrawInfo& params = **k; - // restore our alpha blend mode - gGL.blendFunc(mColorSFactor, mColorDFactor, mAlphaSFactor, mAlphaDFactor); + if ((params.mVertexBuffer->getTypeMask() & mask) != mask) + { //FIXME! + LL_WARNS_ONCE() << "Missing required components, expected mask: " << mask + << " present: " << (params.mVertexBuffer->getTypeMask() & mask) + << ". Skipping render batch." << LL_ENDL; + continue; + } - current_shader->bind(); - } - - if (tex_setup) - { - gGL.getTexUnit(0)->activate(); - gGL.loadIdentity(); - gGL.matrixMode(LLRender::MM_MODELVIEW); - } - } - } - } + LLRenderPass::applyModelMatrix(params); + + // If this alpha mesh has glow, then draw it a second time to add the destination-alpha (=glow). Interleaving these state-changing calls could be expensive, but glow must be drawn Z-sorted with alpha. + if (emissive_shader && + draw_glow_for_this_partition && + params.mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE)) + { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_GLOW); + + params.mVertexBuffer->setBuffer((mask & ~LLVertexBuffer::MAP_COLOR) | LLVertexBuffer::MAP_EMISSIVE); + + // do the actual drawing, again + params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); + gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); + } + } + } + } + + // restore our alpha blend mode + gGL.blendFunc(mColorSFactor, mColorDFactor, mAlphaSFactor, mAlphaDFactor); + + emissive_shader->unbind(); + } + } gGL.setSceneBlendType(LLRender::BT_ALPHA); -- cgit v1.2.3 From 4c3050a3953153aa8753fc10706ad2ef464f3e3d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Sun, 3 Mar 2019 10:42:19 -0800 Subject: SL-10664, SL-10666 Fix up culling issues from perf work and fix Depth of Field rendering to get depth values properly. Baseline for performance work. --- indra/newview/lldrawpoolalpha.cpp | 632 +++++++++++++++++++------------------- 1 file changed, 310 insertions(+), 322 deletions(-) (limited to 'indra/newview/lldrawpoolalpha.cpp') diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 5396a8fdd2..be57e5afde 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -105,6 +105,32 @@ void LLDrawPoolAlpha::beginPostDeferredPass(S32 pass) { LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED); + if (LLPipeline::sRenderDeferred) + { + emissive_shader = &gDeferredEmissiveProgram; + } + else + { + if (LLPipeline::sUnderWaterRender) + { + emissive_shader = &gObjectEmissiveWaterProgram; + } + else + { + emissive_shader = &gObjectEmissiveProgram; + } + } + + emissive_shader->bind(); + if (LLPipeline::sRenderingHUDs) + { + emissive_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); + } + else + { + emissive_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); + } + if (pass == 0) { if (LLPipeline::sImpostorRender) @@ -128,13 +154,13 @@ void LLDrawPoolAlpha::beginPostDeferredPass(S32 pass) fullbright_shader->bind(); fullbright_shader->uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); fullbright_shader->uniform1f(LLShaderMgr::DISPLAY_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); - fullbright_shader->setMinimumAlpha(LLPipeline::sImpostorRender ? 0.5f : 0.0f); - fullbright_shader->unbind(); + fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, LLPipeline::sRenderingHUDs ? 1 : 0); + fullbright_shader->unbind(); //prime simple shader (loads shadow relevant uniforms) gPipeline.bindDeferredShader(*simple_shader); - simple_shader->uniform1f(LLShaderMgr::DISPLAY_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); - simple_shader->setMinimumAlpha(LLPipeline::sImpostorRender ? 0.5f : 0.0f); + + simple_shader->uniform1f(LLShaderMgr::DISPLAY_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); } else if (!LLPipeline::sImpostorRender) { @@ -148,23 +174,6 @@ void LLDrawPoolAlpha::beginPostDeferredPass(S32 pass) gObjectFullbrightAlphaMaskProgram.setMinimumAlpha(0.33f); } - - if (LLPipeline::sRenderDeferred) - { - emissive_shader = &gDeferredEmissiveProgram; - } - else - { - if (LLPipeline::sUnderWaterRender) - { - emissive_shader = &gObjectEmissiveWaterProgram; - } - else - { - emissive_shader = &gObjectEmissiveProgram; - } - } - deferred_render = TRUE; if (mShaderLevel > 0) { @@ -279,15 +288,47 @@ void LLDrawPoolAlpha::render(S32 pass) { fullbright_shader->bind(); fullbright_shader->setMinimumAlpha(0.5f); + if (LLPipeline::sRenderingHUDs) + { + fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); + } + else + { + fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); + } simple_shader->bind(); simple_shader->setMinimumAlpha(0.5f); + if (LLPipeline::sRenderingHUDs) + { + simple_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); + } + else + { + simple_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); + } } else { fullbright_shader->bind(); fullbright_shader->setMinimumAlpha(0.f); + if (LLPipeline::sRenderingHUDs) + { + fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); + } + else + { + fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); + } simple_shader->bind(); simple_shader->setMinimumAlpha(0.f); + if (LLPipeline::sRenderingHUDs) + { + simple_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); + } + else + { + simple_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); + } } } else @@ -395,320 +436,267 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) BOOL light_enabled = TRUE; BOOL use_shaders = gPipeline.canUseVertexShaders(); + + for (LLCullResult::sg_iterator i = gPipeline.beginAlphaGroups(); i != gPipeline.endAlphaGroups(); ++i) + { + LLSpatialGroup* group = *i; + llassert(group); + if (!group) + { + continue; + } + LLSpatialPartition* partition = group->getSpatialPartition(); + llassert(partition); + if (!partition) + { + continue; + } - { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_GROUP_LOOP); - - for (LLCullResult::sg_iterator i = gPipeline.beginAlphaGroups(); i != gPipeline.endAlphaGroups(); ++i) - { - LLSpatialGroup* group = *i; - llassert(group); - llassert(group->getSpatialPartition()); - - if (group->getSpatialPartition()->mRenderByGroup && - !group->isDead()) - { - bool is_particle_or_hud_particle = group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_PARTICLE - || group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_HUD_PARTICLE; - - bool disable_cull = is_particle_or_hud_particle; - LLGLDisable cull(disable_cull ? GL_CULL_FACE : 0); - - LLSpatialGroup::drawmap_elem_t& draw_info = group->mDrawMap[LLRenderPass::PASS_ALPHA]; - - for (LLSpatialGroup::drawmap_elem_t::iterator k = draw_info.begin(); k != draw_info.end(); ++k) - { - LLDrawInfo& params = **k; - - if ((params.mVertexBuffer->getTypeMask() & mask) != mask) - { //FIXME! - LL_WARNS_ONCE() << "Missing required components, expected mask: " << mask - << " present: " << (params.mVertexBuffer->getTypeMask() & mask) - << ". Skipping render batch." << LL_ENDL; - continue; - } - - // Fix for bug - NORSPEC-271 - // If the face is more than 90% transparent, then don't update the Depth buffer for Dof - // We don't want the nearly invisible objects to cause of DoF effects - if(pass == 1 && !LLPipeline::sImpostorRender) - { - LLFace* face = params.mFace; - if(face) - { - const LLTextureEntry* tep = face->getTextureEntry(); - if(tep) - { - if(tep->getColor().mV[3] < 0.1f) - continue; - } - } - } - - LLRenderPass::applyModelMatrix(params); - - LLMaterial* mat = NULL; - - if (deferred_render) - { - mat = params.mMaterial; - } + if (partition->mRenderByGroup && + !group->isDead()) + { + bool is_particle_or_hud_particle = partition->mPartitionType == LLViewerRegion::PARTITION_PARTICLE + || partition->mPartitionType == LLViewerRegion::PARTITION_HUD_PARTICLE; + + bool draw_glow_for_this_partition = mShaderLevel > 0; // no shaders = no glow. + + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_GROUP_LOOP); + + bool disable_cull = is_particle_or_hud_particle; + LLGLDisable cull(disable_cull ? GL_CULL_FACE : 0); + + LLSpatialGroup::drawmap_elem_t& draw_info = group->mDrawMap[LLRenderPass::PASS_ALPHA]; + + for (LLSpatialGroup::drawmap_elem_t::iterator k = draw_info.begin(); k != draw_info.end(); ++k) + { + LLDrawInfo& params = **k; + + if ((params.mVertexBuffer->getTypeMask() & mask) != mask) + { //FIXME! + LL_WARNS_ONCE() << "Missing required components, expected mask: " << mask + << " present: " << (params.mVertexBuffer->getTypeMask() & mask) + << ". Skipping render batch." << LL_ENDL; + continue; + } + + // Fix for bug - NORSPEC-271 + // If the face is more than 90% transparent, then don't update the Depth buffer for Dof + // We don't want the nearly invisible objects to cause of DoF effects + if(pass == 1 && !LLPipeline::sImpostorRender) + { + LLFace* face = params.mFace; + if(face) + { + const LLTextureEntry* tep = face->getTextureEntry(); + if(tep) + { + if(tep->getColor().mV[3] < 0.1f) + continue; + } + } + } + + LLRenderPass::applyModelMatrix(params); + + LLMaterial* mat = NULL; + + if (deferred_render) + { + mat = params.mMaterial; + } - if (params.mFullbright) - { - // Turn off lighting if it hasn't already been so. - if (light_enabled || !initialized_lighting) - { - initialized_lighting = TRUE; - if (use_shaders) - { - target_shader = fullbright_shader; - } - else - { - gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); - } - light_enabled = FALSE; - } - } - // Turn on lighting if it isn't already. - else if (!light_enabled || !initialized_lighting) - { - initialized_lighting = TRUE; - if (use_shaders) - { - target_shader = simple_shader; - } - else - { - gPipeline.enableLightsDynamic(); - } - light_enabled = TRUE; - } - - if (deferred_render && mat) - { - U32 mask = params.mShaderMask; - - llassert(mask < LLMaterial::SHADER_COUNT); - target_shader = &(gDeferredMaterialProgram[mask]); - - if (LLPipeline::sUnderWaterRender) - { - target_shader = &(gDeferredMaterialWaterProgram[mask]); - } - - if (current_shader != target_shader) - { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED_SHADER_BINDS); - gPipeline.bindDeferredShader(*target_shader); - current_shader = target_shader; - } - } - else if (!params.mFullbright) - { - target_shader = simple_shader; - } - else - { - target_shader = fullbright_shader; - } + if (params.mFullbright) + { + // Turn off lighting if it hasn't already been so. + if (light_enabled || !initialized_lighting) + { + initialized_lighting = TRUE; + if (use_shaders) + { + target_shader = fullbright_shader; + } + else + { + gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); + } + light_enabled = FALSE; + } + } + // Turn on lighting if it isn't already. + else if (!light_enabled || !initialized_lighting) + { + initialized_lighting = TRUE; + if (use_shaders) + { + target_shader = simple_shader; + } + else + { + gPipeline.enableLightsDynamic(); + } + light_enabled = TRUE; + } + + if (deferred_render && mat) + { + U32 mask = params.mShaderMask; + + llassert(mask < LLMaterial::SHADER_COUNT); + target_shader = &(gDeferredMaterialProgram[mask]); + + if (LLPipeline::sUnderWaterRender) + { + target_shader = &(gDeferredMaterialWaterProgram[mask]); + } + + if (current_shader != target_shader) + { + gPipeline.bindDeferredShader(*target_shader); + } + } + else if (!params.mFullbright) + { + target_shader = simple_shader; + } + else + { + target_shader = fullbright_shader; + } - if(use_shaders && (current_shader != target_shader)) - {// If we need shaders, and we're not ALREADY using the proper shader, then bind it - // (this way we won't rebind shaders unnecessarily). - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_SHADER_BINDS); - - current_shader = target_shader; - current_shader->bind(); - } - else if (!use_shaders && current_shader != NULL) - { - LLGLSLShader::bindNoShader(); - current_shader = NULL; - } - - if (use_shaders && mat) - { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_MATS); - - // We have a material. Supply the appropriate data here. - if (LLPipeline::sRenderDeferred) - { - current_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, params.mSpecColor.mV[0], params.mSpecColor.mV[1], params.mSpecColor.mV[2], params.mSpecColor.mV[3]); - current_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, params.mEnvIntensity); - current_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, params.mFullbright ? 1.f : 0.f); - - if (params.mNormalMap) - { - params.mNormalMap->addTextureStats(params.mVSize); - current_shader->bindTexture(LLShaderMgr::BUMP_MAP, params.mNormalMap); - } - - if (params.mSpecularMap) - { - params.mSpecularMap->addTextureStats(params.mVSize); - current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, params.mSpecularMap); - } - } - - } - else if (LLPipeline::sRenderDeferred && current_shader && (current_shader == simple_shader)) - { - current_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, 1.0f, 1.0f, 1.0f, 1.0f); - current_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, 0.0f); - LLViewerFetchedTexture::sFlatNormalImagep->addTextureStats(params.mVSize); - current_shader->bindTexture(LLShaderMgr::BUMP_MAP, LLViewerFetchedTexture::sFlatNormalImagep); - LLViewerFetchedTexture::sWhiteImagep->addTextureStats(params.mVSize); - current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, LLViewerFetchedTexture::sWhiteImagep); - } - - if (params.mGroup) - { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_MESH_REBUILD); - - params.mGroup->rebuildMesh(); - } - - bool tex_setup = false; - - if (use_shaders && params.mTextureList.size() > 1) - { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_TEX_BINDS); - for (U32 i = 0; i < params.mTextureList.size(); ++i) - { - if (params.mTextureList[i].notNull()) - { - gGL.getTexUnit(i)->bind(params.mTextureList[i], TRUE); - } - } - } - else - { //not batching textures or batch has only 1 texture -- might need a texture matrix - if (params.mTexture.notNull()) - { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_TEX_BINDS); - - params.mTexture->addTextureStats(params.mVSize); - if (use_shaders && mat) - { - current_shader->bindTexture(LLShaderMgr::DIFFUSE_MAP, params.mTexture); - } - else - { - gGL.getTexUnit(0)->bind(params.mTexture, TRUE) ; - } + if(use_shaders && (current_shader != target_shader)) + {// If we need shaders, and we're not ALREADY using the proper shader, then bind it + // (this way we won't rebind shaders unnecessarily). + current_shader = target_shader; + current_shader->bind(); + } + else if (!use_shaders && current_shader != NULL) + { + LLGLSLShader::bindNoShader(); + current_shader = NULL; + } + + if (use_shaders && mat) + { + // We have a material. Supply the appropriate data here. + if (LLPipeline::sRenderDeferred) + { + current_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, params.mSpecColor.mV[0], params.mSpecColor.mV[1], params.mSpecColor.mV[2], params.mSpecColor.mV[3]); + current_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, params.mEnvIntensity); + current_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, params.mFullbright ? 1.f : 0.f); + + if (params.mNormalMap) + { + params.mNormalMap->addTextureStats(params.mVSize); + current_shader->bindTexture(LLShaderMgr::BUMP_MAP, params.mNormalMap); + } - if (params.mTextureMatrix) - { - tex_setup = true; - gGL.getTexUnit(0)->activate(); - gGL.matrixMode(LLRender::MM_TEXTURE); - gGL.loadMatrix((GLfloat*) params.mTextureMatrix->mMatrix); - gPipeline.mTextureMatrixOps++; - } - } - else - { - gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - } - } - - { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_PUSH); - - LLGLEnableFunc stencil_test(GL_STENCIL_TEST, params.mSelected, &LLGLCommonFunc::selected_stencil_test); - - { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_SETBUFFER); - gGL.blendFunc((LLRender::eBlendFactor) params.mBlendFuncSrc, (LLRender::eBlendFactor) params.mBlendFuncDst, mAlphaSFactor, mAlphaDFactor); - params.mVertexBuffer->setBuffer(mask & ~(params.mFullbright ? (LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2) : 0)); - } - - { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DRAW); - params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); - } - - gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); - } - - if (tex_setup) - { - gGL.getTexUnit(0)->activate(); - gGL.loadIdentity(); - gGL.matrixMode(LLRender::MM_MODELVIEW); - } - } - } - } - - bool draw_glow_for_this_partition = mShaderLevel > 0; // no shaders = no glow. - - if (use_shaders && draw_glow_for_this_partition) - { - // install glow-accumulating blend mode - gGL.blendFunc(LLRender::BF_ZERO, LLRender::BF_ONE, // don't touch color - LLRender::BF_ONE, LLRender::BF_ONE); // add to alpha (glow) + if (params.mSpecularMap) + { + params.mSpecularMap->addTextureStats(params.mVSize); + current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, params.mSpecularMap); + } + } + + } else if (LLPipeline::sRenderDeferred && current_shader && (current_shader == simple_shader)) + { + current_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, 1.0f, 1.0f, 1.0f, 1.0f); + current_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, 0.0f); + LLViewerFetchedTexture::sFlatNormalImagep->addTextureStats(params.mVSize); + current_shader->bindTexture(LLShaderMgr::BUMP_MAP, LLViewerFetchedTexture::sFlatNormalImagep); + LLViewerFetchedTexture::sWhiteImagep->addTextureStats(params.mVSize); + current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, LLViewerFetchedTexture::sWhiteImagep); + } - emissive_shader->bind(); + if (params.mGroup) + { + params.mGroup->rebuildMesh(); + } - for (LLCullResult::sg_iterator i = gPipeline.beginAlphaGroups(); i != gPipeline.endAlphaGroups(); ++i) - { - LLSpatialGroup* group = *i; - llassert(group); - llassert(group->getSpatialPartition()); + bool tex_setup = false; - if (group->getSpatialPartition()->mRenderByGroup && - !group->isDead()) - { - bool is_particle_or_hud_particle = group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_PARTICLE - || group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_HUD_PARTICLE; + if (use_shaders && params.mTextureList.size() > 1) + { + for (U32 i = 0; i < params.mTextureList.size(); ++i) + { + if (params.mTextureList[i].notNull()) + { + gGL.getTexUnit(i)->bind(params.mTextureList[i], TRUE); + } + } + } + else + { //not batching textures or batch has only 1 texture -- might need a texture matrix + if (params.mTexture.notNull()) + { + params.mTexture->addTextureStats(params.mVSize); + if (use_shaders && mat) + { + current_shader->bindTexture(LLShaderMgr::DIFFUSE_MAP, params.mTexture); + } + else + { + gGL.getTexUnit(0)->bind(params.mTexture, TRUE) ; + } + + if (params.mTextureMatrix) + { + tex_setup = true; + gGL.getTexUnit(0)->activate(); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadMatrix((GLfloat*) params.mTextureMatrix->mMatrix); + gPipeline.mTextureMatrixOps++; + } + } + else + { + gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); + } + } - + { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_PUSH); - bool disable_cull = is_particle_or_hud_particle; - LLGLDisable cull(disable_cull ? GL_CULL_FACE : 0); + LLGLEnableFunc stencil_test(GL_STENCIL_TEST, params.mSelected, &LLGLCommonFunc::selected_stencil_test); - LLSpatialGroup::drawmap_elem_t& draw_info = group->mDrawMap[LLRenderPass::PASS_ALPHA]; + gGL.blendFunc((LLRender::eBlendFactor) params.mBlendFuncSrc, (LLRender::eBlendFactor) params.mBlendFuncDst, mAlphaSFactor, mAlphaDFactor); + params.mVertexBuffer->setBuffer(mask & ~(params.mFullbright ? (LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2) : 0)); - for (LLSpatialGroup::drawmap_elem_t::iterator k = draw_info.begin(); k != draw_info.end(); ++k) - { - LLDrawInfo& params = **k; + params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); + gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); + } + + // If this alpha mesh has glow, then draw it a second time to add the destination-alpha (=glow). Interleaving these state-changing calls could be expensive, but glow must be drawn Z-sorted with alpha. + if (current_shader && + emissive_shader && + draw_glow_for_this_partition && + params.mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE)) + { + // install glow-accumulating blend mode + gGL.blendFunc(LLRender::BF_ZERO, LLRender::BF_ONE, // don't touch color + LLRender::BF_ONE, LLRender::BF_ONE); // add to alpha (glow) - if ((params.mVertexBuffer->getTypeMask() & mask) != mask) - { //FIXME! - LL_WARNS_ONCE() << "Missing required components, expected mask: " << mask - << " present: " << (params.mVertexBuffer->getTypeMask() & mask) - << ". Skipping render batch." << LL_ENDL; - continue; - } + emissive_shader->bind(); + params.mVertexBuffer->setBuffer((mask & ~LLVertexBuffer::MAP_COLOR) | LLVertexBuffer::MAP_EMISSIVE); - LLRenderPass::applyModelMatrix(params); - - // If this alpha mesh has glow, then draw it a second time to add the destination-alpha (=glow). Interleaving these state-changing calls could be expensive, but glow must be drawn Z-sorted with alpha. - if (emissive_shader && - draw_glow_for_this_partition && - params.mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE)) - { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_GLOW); - - params.mVertexBuffer->setBuffer((mask & ~LLVertexBuffer::MAP_COLOR) | LLVertexBuffer::MAP_EMISSIVE); - - // do the actual drawing, again - params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); - gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); - } - } - } - } - - // restore our alpha blend mode - gGL.blendFunc(mColorSFactor, mColorDFactor, mAlphaSFactor, mAlphaDFactor); - - emissive_shader->unbind(); - } - } + // do the actual drawing, again + params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); + gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); + + // restore our alpha blend mode + gGL.blendFunc(mColorSFactor, mColorDFactor, mAlphaSFactor, mAlphaDFactor); + + current_shader->bind(); + } + + if (tex_setup) + { + gGL.getTexUnit(0)->activate(); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_MODELVIEW); + } + } + } + } gGL.setSceneBlendType(LLRender::BT_ALPHA); -- cgit v1.2.3 From 45a541d2d5ccff4279441c715d3f80890e71beb9 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 4 Mar 2019 08:04:18 -0800 Subject: SL-10566 Disable pre-cull of water causing refraction/reflection map generation more than is necessary. Re-org alpha draws to limit state changes based on render type. --- indra/newview/lldrawpoolalpha.cpp | 621 ++++++++++++++++---------------------- 1 file changed, 258 insertions(+), 363 deletions(-) (limited to 'indra/newview/lldrawpoolalpha.cpp') diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index be57e5afde..84f94d4497 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -64,6 +64,7 @@ static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_MATS("Alpha Mat Tex Binds" static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_GLOW("Alpha Glow Binds"); static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_SHADER_BINDS("Alpha Shader Binds"); static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_DEFERRED_SHADER_BINDS("Alpha Def Binds"); +static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_DEFERRED_TEX_BINDS("Alpha Def Tex Binds"); static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_MESH_REBUILD("Alpha Mesh Rebuild"); LLDrawPoolAlpha::LLDrawPoolAlpha(U32 type) : @@ -103,53 +104,22 @@ S32 LLDrawPoolAlpha::getNumPostDeferredPasses() void LLDrawPoolAlpha::beginPostDeferredPass(S32 pass) { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED); + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED); - if (LLPipeline::sRenderDeferred) - { - emissive_shader = &gDeferredEmissiveProgram; - } - else - { - if (LLPipeline::sUnderWaterRender) - { - emissive_shader = &gObjectEmissiveWaterProgram; - } - else - { - emissive_shader = &gObjectEmissiveProgram; - } - } + F32 gamma = gSavedSettings.getF32("RenderDeferredDisplayGamma"); + + emissive_shader = (LLPipeline::sRenderDeferred) ? &gDeferredEmissiveProgram : + (LLPipeline::sUnderWaterRender) ? &gObjectEmissiveWaterProgram : &gObjectEmissiveProgram; emissive_shader->bind(); - if (LLPipeline::sRenderingHUDs) - { - emissive_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); - } - else - { - emissive_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); - } + emissive_shader->uniform1i(LLShaderMgr::NO_ATMO, (LLPipeline::sRenderingHUDs) ? 1 : 0); + emissive_shader->uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); + emissive_shader->uniform1f(LLShaderMgr::DISPLAY_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); if (pass == 0) { - if (LLPipeline::sImpostorRender) - { - simple_shader = &gDeferredAlphaImpostorProgram; - fullbright_shader = &gDeferredFullbrightProgram; - } - else if (LLPipeline::sUnderWaterRender) - { - simple_shader = &gDeferredAlphaWaterProgram; - fullbright_shader = &gDeferredFullbrightWaterProgram; - } - else - { - simple_shader = &gDeferredAlphaProgram; - fullbright_shader = &gDeferredFullbrightProgram; - } - - F32 gamma = gSavedSettings.getF32("RenderDeferredDisplayGamma"); + fullbright_shader = (LLPipeline::sImpostorRender) ? &gDeferredFullbrightProgram : + (LLPipeline::sUnderWaterRender) ? &gDeferredFullbrightWaterProgram : &gDeferredFullbrightProgram; fullbright_shader->bind(); fullbright_shader->uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); @@ -157,10 +127,14 @@ void LLDrawPoolAlpha::beginPostDeferredPass(S32 pass) fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, LLPipeline::sRenderingHUDs ? 1 : 0); fullbright_shader->unbind(); + simple_shader = (LLPipeline::sImpostorRender) ? &gDeferredAlphaImpostorProgram : + (LLPipeline::sUnderWaterRender) ? &gDeferredAlphaWaterProgram : &gDeferredAlphaProgram; + //prime simple shader (loads shadow relevant uniforms) gPipeline.bindDeferredShader(*simple_shader); simple_shader->uniform1f(LLShaderMgr::DISPLAY_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); + simple_shader->uniform1i(LLShaderMgr::NO_ATMO, LLPipeline::sRenderingHUDs ? 1 : 0); } else if (!LLPipeline::sImpostorRender) { @@ -208,31 +182,47 @@ void LLDrawPoolAlpha::beginRenderPass(S32 pass) { LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_SETUP); - if (LLPipeline::sImpostorRender) - { - simple_shader = &gObjectSimpleImpostorProgram; - fullbright_shader = &gObjectFullbrightProgram; - emissive_shader = &gObjectEmissiveProgram; - } - else if (LLPipeline::sUnderWaterRender) - { - simple_shader = &gObjectSimpleWaterProgram; - fullbright_shader = &gObjectFullbrightWaterProgram; - emissive_shader = &gObjectEmissiveWaterProgram; - } - else - { - simple_shader = &gObjectSimpleProgram; - fullbright_shader = &gObjectFullbrightProgram; - emissive_shader = &gObjectEmissiveProgram; - } + simple_shader = (LLPipeline::sImpostorRender) ? &gObjectSimpleImpostorProgram : + (LLPipeline::sUnderWaterRender) ? &gObjectSimpleWaterProgram : &gObjectSimpleProgram; - if (mShaderLevel > 0) + fullbright_shader = (LLPipeline::sImpostorRender) ? &gObjectFullbrightProgram : + (LLPipeline::sUnderWaterRender) ? &gObjectFullbrightWaterProgram : &gObjectFullbrightProgram; + + emissive_shader = (LLPipeline::sImpostorRender) ? &gObjectEmissiveProgram : + (LLPipeline::sUnderWaterRender) ? &gObjectEmissiveWaterProgram : &gObjectEmissiveProgram; + + if (LLPipeline::sImpostorRender) { - // Start out with no shaders. - current_shader = target_shader = NULL; - LLGLSLShader::bindNoShader(); + if (mShaderLevel > 0) + { + fullbright_shader->bind(); + fullbright_shader->setMinimumAlpha(0.5f); + fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, LLPipeline::sRenderingHUDs ? 1 : 0); + simple_shader->bind(); + simple_shader->setMinimumAlpha(0.5f); + simple_shader->uniform1i(LLShaderMgr::NO_ATMO, LLPipeline::sRenderingHUDs ? 1 : 0); + } + else + { + gGL.setAlphaRejectSettings(LLRender::CF_GREATER, 0.5f); //OK + } } + else + { + if (mShaderLevel > 0) + { + fullbright_shader->bind(); + fullbright_shader->setMinimumAlpha(0.f); + fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, LLPipeline::sRenderingHUDs ? 1 : 0); + simple_shader->bind(); + simple_shader->setMinimumAlpha(0.f); + simple_shader->uniform1i(LLShaderMgr::NO_ATMO, LLPipeline::sRenderingHUDs ? 1 : 0); + } + else + { + gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT); //OK + } + } gPipeline.enableLightsDynamic(); } @@ -281,67 +271,6 @@ void LLDrawPoolAlpha::render(S32 pass) mAlphaSFactor = LLRender::BF_ZERO; // } glow suppression mAlphaDFactor = LLRender::BF_ONE_MINUS_SOURCE_ALPHA; // } gGL.blendFunc(mColorSFactor, mColorDFactor, mAlphaSFactor, mAlphaDFactor); - - if (mShaderLevel > 0) - { - if (LLPipeline::sImpostorRender) - { - fullbright_shader->bind(); - fullbright_shader->setMinimumAlpha(0.5f); - if (LLPipeline::sRenderingHUDs) - { - fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); - } - else - { - fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); - } - simple_shader->bind(); - simple_shader->setMinimumAlpha(0.5f); - if (LLPipeline::sRenderingHUDs) - { - simple_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); - } - else - { - simple_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); - } - } - else - { - fullbright_shader->bind(); - fullbright_shader->setMinimumAlpha(0.f); - if (LLPipeline::sRenderingHUDs) - { - fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); - } - else - { - fullbright_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); - } - simple_shader->bind(); - simple_shader->setMinimumAlpha(0.f); - if (LLPipeline::sRenderingHUDs) - { - simple_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); - } - else - { - simple_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); - } - } - } - else - { - if (LLPipeline::sImpostorRender) - { - gGL.setAlphaRejectSettings(LLRender::CF_GREATER, 0.5f); //OK - } - else - { - gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT); //OK - } - } } if (mShaderLevel > 0) @@ -428,282 +357,248 @@ void LLDrawPoolAlpha::renderAlphaHighlight(U32 mask) } } -void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) +inline bool IsFullbright(LLDrawInfo& params) { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA); + return params.mFullbright; +} - BOOL initialized_lighting = FALSE; - BOOL light_enabled = TRUE; - - BOOL use_shaders = gPipeline.canUseVertexShaders(); - - for (LLCullResult::sg_iterator i = gPipeline.beginAlphaGroups(); i != gPipeline.endAlphaGroups(); ++i) +inline bool IsMaterial(LLDrawInfo& params) +{ + return params.mMaterial != nullptr; +} + +inline bool IsEmissive(LLDrawInfo& params) +{ + return params.mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE); +} + +inline void Draw(LLDrawInfo* draw, U32 mask) +{ + draw->mVertexBuffer->setBuffer(mask); + LLRenderPass::applyModelMatrix(*draw); + draw->mVertexBuffer->drawRange(draw->mDrawMode, draw->mStart, draw->mEnd, draw->mCount, draw->mOffset); + gPipeline.addTrianglesDrawn(draw->mCount, draw->mDrawMode); +} + +inline bool TexSetup(LLDrawInfo* draw) +{ + bool tex_setup = false; + + if (draw->mTextureMatrix) { - LLSpatialGroup* group = *i; - llassert(group); - if (!group) - { - continue; - } - LLSpatialPartition* partition = group->getSpatialPartition(); - llassert(partition); - if (!partition) + tex_setup = true; + gGL.getTexUnit(0)->activate(); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadMatrix((GLfloat*) draw->mTextureMatrix->mMatrix); + gPipeline.mTextureMatrixOps++; + } + + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_TEX_BINDS); + for (U32 i = 0; i < draw->mTextureList.size(); ++i) + { + if (draw->mTextureList[i].notNull()) { - continue; + gGL.getTexUnit(i)->bind(draw->mTextureList[i], TRUE); } + } - if (partition->mRenderByGroup && - !group->isDead()) - { - bool is_particle_or_hud_particle = partition->mPartitionType == LLViewerRegion::PARTITION_PARTICLE - || partition->mPartitionType == LLViewerRegion::PARTITION_HUD_PARTICLE; - - bool draw_glow_for_this_partition = mShaderLevel > 0; // no shaders = no glow. + return tex_setup; +} - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_GROUP_LOOP); +inline void RestoreTexSetup(bool tex_setup) +{ + if (tex_setup) + { + gGL.getTexUnit(0)->activate(); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_MODELVIEW); + } +} - bool disable_cull = is_particle_or_hud_particle; - LLGLDisable cull(disable_cull ? GL_CULL_FACE : 0); +void LLDrawPoolAlpha::renderSimples(U32 mask, std::vector& simples) +{ + gPipeline.enableLightsDynamic(); + simple_shader->bind(); + simple_shader->bindTexture(LLShaderMgr::BUMP_MAP, LLViewerFetchedTexture::sFlatNormalImagep); + simple_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, LLViewerFetchedTexture::sWhiteImagep); + simple_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, 1.0f, 1.0f, 1.0f, 1.0f); + simple_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, 0.0f); + + for (LLDrawInfo* draw : simples) + { + bool tex_setup = TexSetup(draw); + Draw(draw, mask); + RestoreTexSetup(tex_setup); + } + simple_shader->unbind(); +} - LLSpatialGroup::drawmap_elem_t& draw_info = group->mDrawMap[LLRenderPass::PASS_ALPHA]; +void LLDrawPoolAlpha::renderFullbrights(U32 mask, std::vector& fullbrights) +{ + gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); + fullbright_shader->bind(); + fullbright_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, 1.0f); + for (LLDrawInfo* draw : fullbrights) + { + bool tex_setup = TexSetup(draw); + Draw(draw, mask & ~(LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2)); + RestoreTexSetup(tex_setup); + } + fullbright_shader->unbind(); +} - for (LLSpatialGroup::drawmap_elem_t::iterator k = draw_info.begin(); k != draw_info.end(); ++k) - { - LLDrawInfo& params = **k; +void LLDrawPoolAlpha::renderMaterials(U32 mask, std::vector& materials) +{ + LLGLSLShader::bindNoShader(); + current_shader = NULL; - if ((params.mVertexBuffer->getTypeMask() & mask) != mask) - { //FIXME! - LL_WARNS_ONCE() << "Missing required components, expected mask: " << mask - << " present: " << (params.mVertexBuffer->getTypeMask() & mask) - << ". Skipping render batch." << LL_ENDL; - continue; - } + for (LLDrawInfo* draw : materials) + { + U32 mask = draw->mShaderMask; - // Fix for bug - NORSPEC-271 - // If the face is more than 90% transparent, then don't update the Depth buffer for Dof - // We don't want the nearly invisible objects to cause of DoF effects - if(pass == 1 && !LLPipeline::sImpostorRender) - { - LLFace* face = params.mFace; - if(face) - { - const LLTextureEntry* tep = face->getTextureEntry(); - if(tep) - { - if(tep->getColor().mV[3] < 0.1f) - continue; - } - } - } + llassert(mask < LLMaterial::SHADER_COUNT); + target_shader = (LLPipeline::sUnderWaterRender) ? &(gDeferredMaterialWaterProgram[mask]) : &(gDeferredMaterialProgram[mask]); - LLRenderPass::applyModelMatrix(params); + if (current_shader != target_shader) + { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED_SHADER_BINDS); + if (current_shader) + { + gPipeline.unbindDeferredShader(*current_shader); + } + gPipeline.bindDeferredShader(*target_shader); + current_shader = target_shader; + } + + bool tex_setup = TexSetup(draw); + if (!draw->mTexture.isNull()) + { + current_shader->bindTexture(LLShaderMgr::DIFFUSE_MAP, draw->mTexture); + } - LLMaterial* mat = NULL; + current_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, draw->mSpecColor.mV[0], draw->mSpecColor.mV[1], draw->mSpecColor.mV[2], draw->mSpecColor.mV[3]); + current_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, draw->mEnvIntensity); + current_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, draw->mFullbright ? 1.f : 0.f); - if (deferred_render) - { - mat = params.mMaterial; - } - - if (params.mFullbright) - { - // Turn off lighting if it hasn't already been so. - if (light_enabled || !initialized_lighting) - { - initialized_lighting = TRUE; - if (use_shaders) - { - target_shader = fullbright_shader; - } - else - { - gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); - } - light_enabled = FALSE; - } - } - // Turn on lighting if it isn't already. - else if (!light_enabled || !initialized_lighting) - { - initialized_lighting = TRUE; - if (use_shaders) - { - target_shader = simple_shader; - } - else - { - gPipeline.enableLightsDynamic(); - } - light_enabled = TRUE; - } + { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED_TEX_BINDS); + if (draw->mNormalMap) + { + draw->mNormalMap->addTextureStats(draw->mVSize); + current_shader->bindTexture(LLShaderMgr::BUMP_MAP, draw->mNormalMap); + } + + if (draw->mSpecularMap) + { + draw->mSpecularMap->addTextureStats(draw->mVSize); + current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, draw->mSpecularMap); + } + } - if (deferred_render && mat) - { - U32 mask = params.mShaderMask; + Draw(draw, mask); + RestoreTexSetup(tex_setup); + } +} - llassert(mask < LLMaterial::SHADER_COUNT); - target_shader = &(gDeferredMaterialProgram[mask]); +void LLDrawPoolAlpha::renderEmissives(U32 mask, std::vector& emissives) +{ + emissive_shader->bind(); - if (LLPipeline::sUnderWaterRender) - { - target_shader = &(gDeferredMaterialWaterProgram[mask]); - } + // install glow-accumulating blend mode + // don't touch color, add to alpha (glow) + gGL.blendFunc(LLRender::BF_ZERO, LLRender::BF_ONE, LLRender::BF_ONE, LLRender::BF_ONE); - if (current_shader != target_shader) - { - gPipeline.bindDeferredShader(*target_shader); - } - } - else if (!params.mFullbright) - { - target_shader = simple_shader; - } - else - { - target_shader = fullbright_shader; - } - - if(use_shaders && (current_shader != target_shader)) - {// If we need shaders, and we're not ALREADY using the proper shader, then bind it - // (this way we won't rebind shaders unnecessarily). - current_shader = target_shader; - current_shader->bind(); - } - else if (!use_shaders && current_shader != NULL) - { - LLGLSLShader::bindNoShader(); - current_shader = NULL; - } + for (LLDrawInfo* draw : emissives) + { + bool tex_setup = TexSetup(draw); + Draw(draw, (mask & ~LLVertexBuffer::MAP_COLOR) | LLVertexBuffer::MAP_EMISSIVE); + RestoreTexSetup(tex_setup); + } - if (use_shaders && mat) - { - // We have a material. Supply the appropriate data here. - if (LLPipeline::sRenderDeferred) - { - current_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, params.mSpecColor.mV[0], params.mSpecColor.mV[1], params.mSpecColor.mV[2], params.mSpecColor.mV[3]); - current_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, params.mEnvIntensity); - current_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, params.mFullbright ? 1.f : 0.f); - - if (params.mNormalMap) - { - params.mNormalMap->addTextureStats(params.mVSize); - current_shader->bindTexture(LLShaderMgr::BUMP_MAP, params.mNormalMap); - } - - if (params.mSpecularMap) - { - params.mSpecularMap->addTextureStats(params.mVSize); - current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, params.mSpecularMap); - } - } - - } else if (LLPipeline::sRenderDeferred && current_shader && (current_shader == simple_shader)) - { - current_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, 1.0f, 1.0f, 1.0f, 1.0f); - current_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, 0.0f); - LLViewerFetchedTexture::sFlatNormalImagep->addTextureStats(params.mVSize); - current_shader->bindTexture(LLShaderMgr::BUMP_MAP, LLViewerFetchedTexture::sFlatNormalImagep); - LLViewerFetchedTexture::sWhiteImagep->addTextureStats(params.mVSize); - current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, LLViewerFetchedTexture::sWhiteImagep); - } + // restore our alpha blend mode + gGL.blendFunc(mColorSFactor, mColorDFactor, mAlphaSFactor, mAlphaDFactor); - if (params.mGroup) - { - params.mGroup->rebuildMesh(); - } + emissive_shader->unbind(); +} - bool tex_setup = false; +void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) +{ + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA); - if (use_shaders && params.mTextureList.size() > 1) - { - for (U32 i = 0; i < params.mTextureList.size(); ++i) - { - if (params.mTextureList[i].notNull()) - { - gGL.getTexUnit(i)->bind(params.mTextureList[i], TRUE); - } - } - } - else - { //not batching textures or batch has only 1 texture -- might need a texture matrix - if (params.mTexture.notNull()) - { - params.mTexture->addTextureStats(params.mVSize); - if (use_shaders && mat) - { - current_shader->bindTexture(LLShaderMgr::DIFFUSE_MAP, params.mTexture); - } - else - { - gGL.getTexUnit(0)->bind(params.mTexture, TRUE) ; - } - - if (params.mTextureMatrix) - { - tex_setup = true; - gGL.getTexUnit(0)->activate(); - gGL.matrixMode(LLRender::MM_TEXTURE); - gGL.loadMatrix((GLfloat*) params.mTextureMatrix->mMatrix); - gPipeline.mTextureMatrixOps++; - } - } - else - { - gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - } - } + std::vector simples_3d; + std::vector fullbrights_3d; + std::vector materials_3d; + std::vector emissives_3d; + std::vector simples_hud; + std::vector fullbrights_hud; + std::vector materials_hud; + std::vector emissives_hud; - { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_PUSH); + for (LLCullResult::sg_iterator i = gPipeline.beginAlphaGroups(); i != gPipeline.endAlphaGroups(); ++i) + { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_GROUP_LOOP); - LLGLEnableFunc stencil_test(GL_STENCIL_TEST, params.mSelected, &LLGLCommonFunc::selected_stencil_test); + LLSpatialGroup* group = *i; + llassert(group); - gGL.blendFunc((LLRender::eBlendFactor) params.mBlendFuncSrc, (LLRender::eBlendFactor) params.mBlendFuncDst, mAlphaSFactor, mAlphaDFactor); - params.mVertexBuffer->setBuffer(mask & ~(params.mFullbright ? (LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2) : 0)); + LLSpatialPartition* partition = group->getSpatialPartition(); + llassert(partition); - params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); - gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); - } - - // If this alpha mesh has glow, then draw it a second time to add the destination-alpha (=glow). Interleaving these state-changing calls could be expensive, but glow must be drawn Z-sorted with alpha. - if (current_shader && - emissive_shader && - draw_glow_for_this_partition && - params.mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE)) - { - // install glow-accumulating blend mode - gGL.blendFunc(LLRender::BF_ZERO, LLRender::BF_ONE, // don't touch color - LLRender::BF_ONE, LLRender::BF_ONE); // add to alpha (glow) + if (group->getSpatialPartition()->mRenderByGroup && !group->isDead()) + { + bool is_particle_or_hud_particle = group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_PARTICLE + || group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_HUD_PARTICLE; - emissive_shader->bind(); - params.mVertexBuffer->setBuffer((mask & ~LLVertexBuffer::MAP_COLOR) | LLVertexBuffer::MAP_EMISSIVE); + std::vector* fullbrights = is_particle_or_hud_particle ? &fullbrights_hud : &fullbrights_3d; + std::vector* materials = is_particle_or_hud_particle ? &materials_hud : &materials_3d; + std::vector* simples = is_particle_or_hud_particle ? &simples_hud : &simples_3d; + std::vector* emissives = is_particle_or_hud_particle ? &emissives_hud : &emissives_3d; - // do the actual drawing, again - params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); - gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); + LLSpatialGroup::drawmap_elem_t& draw_info = group->mDrawMap[LLRenderPass::PASS_ALPHA]; - // restore our alpha blend mode - gGL.blendFunc(mColorSFactor, mColorDFactor, mAlphaSFactor, mAlphaDFactor); + for (LLSpatialGroup::drawmap_elem_t::iterator k = draw_info.begin(); k != draw_info.end(); ++k) + { + LLDrawInfo& params = **k; - current_shader->bind(); - } - - if (tex_setup) + if (params.mGroup) { - gGL.getTexUnit(0)->activate(); - gGL.loadIdentity(); - gGL.matrixMode(LLRender::MM_MODELVIEW); + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_MESH_REBUILD); + params.mGroup->rebuildMesh(); } - } - } + + (IsMaterial(params) ? materials : + IsFullbright(params) ? fullbrights : + simples)->push_back(¶ms); + + if (IsEmissive(params)) + { + emissives->push_back(¶ms); + } + } + } } + renderSimples(mask, simples_3d); + renderFullbrights(mask, fullbrights_3d); + renderMaterials(mask, materials_3d); + renderEmissives(mask, emissives_3d); + + LLGLDisable cull(GL_CULL_FACE); + + renderSimples(mask, simples_hud); + renderFullbrights(mask, fullbrights_hud); + renderMaterials(mask, materials_hud); + renderEmissives(mask, emissives_hud); + + LLGLSLShader::bindNoShader(); + current_shader = NULL; + gGL.setSceneBlendType(LLRender::BT_ALPHA); + gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); + LLVertexBuffer::unbind(); - if (!light_enabled) - { - gPipeline.enableLightsDynamic(); - } + gPipeline.enableLightsDynamic(); } -- cgit v1.2.3 From 552267f1c9e95a9b10f03421aa8a37a1048c661c Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 4 Mar 2019 09:50:11 -0800 Subject: Fix unused local var 'partition' and avoid assert in rendering highlights. --- indra/newview/lldrawpoolalpha.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'indra/newview/lldrawpoolalpha.cpp') diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 84f94d4497..82a95ac7a8 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -545,10 +545,10 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) LLSpatialPartition* partition = group->getSpatialPartition(); llassert(partition); - if (group->getSpatialPartition()->mRenderByGroup && !group->isDead()) + if (partition->mRenderByGroup && !group->isDead()) { - bool is_particle_or_hud_particle = group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_PARTICLE - || group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_HUD_PARTICLE; + bool is_particle_or_hud_particle = partition->mPartitionType == LLViewerRegion::PARTITION_PARTICLE + || partition->mPartitionType == LLViewerRegion::PARTITION_HUD_PARTICLE; std::vector* fullbrights = is_particle_or_hud_particle ? &fullbrights_hud : &fullbrights_3d; std::vector* materials = is_particle_or_hud_particle ? &materials_hud : &materials_3d; @@ -590,9 +590,9 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) renderFullbrights(mask, fullbrights_hud); renderMaterials(mask, materials_hud); renderEmissives(mask, emissives_hud); - - LLGLSLShader::bindNoShader(); - current_shader = NULL; + + simple_shader->bind(); + current_shader = simple_shader; gGL.setSceneBlendType(LLRender::BT_ALPHA); -- cgit v1.2.3 From 0b4982ac897fcc1f38a18934a42836a4d2eecb29 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 4 Mar 2019 10:31:55 -0800 Subject: Roll back optimizations to lldrawpoolalpha causing emissive strangeness and alpha materials lighting errors. --- indra/newview/lldrawpoolalpha.cpp | 303 +++++++++++++++++++++++++++++++------- 1 file changed, 251 insertions(+), 52 deletions(-) (limited to 'indra/newview/lldrawpoolalpha.cpp') diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 82a95ac7a8..7945c950db 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -424,6 +424,7 @@ void LLDrawPoolAlpha::renderSimples(U32 mask, std::vector& simples) simple_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, LLViewerFetchedTexture::sWhiteImagep); simple_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, 1.0f, 1.0f, 1.0f, 1.0f); simple_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, 0.0f); + simple_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, 0.0f); for (LLDrawInfo* draw : simples) { @@ -438,7 +439,7 @@ void LLDrawPoolAlpha::renderFullbrights(U32 mask, std::vector& full { gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); fullbright_shader->bind(); - fullbright_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, 1.0f); + fullbright_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, 0.0f); for (LLDrawInfo* draw : fullbrights) { bool tex_setup = TexSetup(draw); @@ -453,6 +454,7 @@ void LLDrawPoolAlpha::renderMaterials(U32 mask, std::vector& materi LLGLSLShader::bindNoShader(); current_shader = NULL; + gPipeline.enableLightsDynamic(); for (LLDrawInfo* draw : materials) { U32 mask = draw->mShaderMask; @@ -504,6 +506,7 @@ void LLDrawPoolAlpha::renderMaterials(U32 mask, std::vector& materi void LLDrawPoolAlpha::renderEmissives(U32 mask, std::vector& emissives) { emissive_shader->bind(); + emissive_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, 1.f); // install glow-accumulating blend mode // don't touch color, add to alpha (glow) @@ -524,36 +527,30 @@ void LLDrawPoolAlpha::renderEmissives(U32 mask, std::vector& emissi void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA); - - std::vector simples_3d; - std::vector fullbrights_3d; - std::vector materials_3d; - std::vector emissives_3d; - std::vector simples_hud; - std::vector fullbrights_hud; - std::vector materials_hud; - std::vector emissives_hud; - - for (LLCullResult::sg_iterator i = gPipeline.beginAlphaGroups(); i != gPipeline.endAlphaGroups(); ++i) + BOOL initialized_lighting = FALSE; + BOOL light_enabled = TRUE; + + BOOL use_shaders = gPipeline.canUseVertexShaders(); + + for (LLCullResult::sg_iterator i = gPipeline.beginAlphaGroups(); i != gPipeline.endAlphaGroups(); ++i) { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_GROUP_LOOP); - LLSpatialGroup* group = *i; llassert(group); + llassert(group->getSpatialPartition()); - LLSpatialPartition* partition = group->getSpatialPartition(); - llassert(partition); - - if (partition->mRenderByGroup && !group->isDead()) + if (group->getSpatialPartition()->mRenderByGroup && + !group->isDead()) { - bool is_particle_or_hud_particle = partition->mPartitionType == LLViewerRegion::PARTITION_PARTICLE - || partition->mPartitionType == LLViewerRegion::PARTITION_HUD_PARTICLE; + bool is_particle_or_hud_particle = group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_PARTICLE + || group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_HUD_PARTICLE; + + bool draw_glow_for_this_partition = mShaderLevel > 0; // no shaders = no glow. - std::vector* fullbrights = is_particle_or_hud_particle ? &fullbrights_hud : &fullbrights_3d; - std::vector* materials = is_particle_or_hud_particle ? &materials_hud : &materials_3d; - std::vector* simples = is_particle_or_hud_particle ? &simples_hud : &simples_3d; - std::vector* emissives = is_particle_or_hud_particle ? &emissives_hud : &emissives_3d; + + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_GROUP_LOOP); + + bool disable_cull = is_particle_or_hud_particle; + LLGLDisable cull(disable_cull ? GL_CULL_FACE : 0); LLSpatialGroup::drawmap_elem_t& draw_info = group->mDrawMap[LLRenderPass::PASS_ALPHA]; @@ -561,44 +558,246 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) { LLDrawInfo& params = **k; - if (params.mGroup) + if ((params.mVertexBuffer->getTypeMask() & mask) != mask) + { //FIXME! + LL_WARNS_ONCE() << "Missing required components, expected mask: " << mask + << " present: " << (params.mVertexBuffer->getTypeMask() & mask) + << ". Skipping render batch." << LL_ENDL; + continue; + } + + // Fix for bug - NORSPEC-271 + // If the face is more than 90% transparent, then don't update the Depth buffer for Dof + // We don't want the nearly invisible objects to cause of DoF effects + if(pass == 1 && !LLPipeline::sImpostorRender) + { + LLFace* face = params.mFace; + if(face) + { + const LLTextureEntry* tep = face->getTextureEntry(); + if(tep) + { + if(tep->getColor().mV[3] < 0.1f) + continue; + } + } + } + + LLRenderPass::applyModelMatrix(params); + + LLMaterial* mat = NULL; + + if (deferred_render) + { + mat = params.mMaterial; + } + + if (params.mFullbright) + { + // Turn off lighting if it hasn't already been so. + if (light_enabled || !initialized_lighting) + { + initialized_lighting = TRUE; + if (use_shaders) + { + target_shader = fullbright_shader; + } + else + { + gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); + } + light_enabled = FALSE; + } + } + // Turn on lighting if it isn't already. + else if (!light_enabled || !initialized_lighting) + { + initialized_lighting = TRUE; + if (use_shaders) + { + target_shader = simple_shader; + } + else + { + gPipeline.enableLightsDynamic(); + } + light_enabled = TRUE; + } + + if (deferred_render && mat) + { + U32 mask = params.mShaderMask; + + llassert(mask < LLMaterial::SHADER_COUNT); + target_shader = &(gDeferredMaterialProgram[mask]); + + if (LLPipeline::sUnderWaterRender) + { + target_shader = &(gDeferredMaterialWaterProgram[mask]); + } + + if (current_shader != target_shader) + { + gPipeline.bindDeferredShader(*target_shader); + } + } + else if (!params.mFullbright) + { + target_shader = simple_shader; + } + else + { + target_shader = fullbright_shader; + } + + if(use_shaders && (current_shader != target_shader)) + {// If we need shaders, and we're not ALREADY using the proper shader, then bind it + // (this way we won't rebind shaders unnecessarily). + current_shader = target_shader; + current_shader->bind(); + } + else if (!use_shaders && current_shader != NULL) + { + LLGLSLShader::bindNoShader(); + current_shader = NULL; + } + + if (use_shaders && mat) + { + // We have a material. Supply the appropriate data here. + if (LLPipeline::sRenderDeferred) + { + current_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, params.mSpecColor.mV[0], params.mSpecColor.mV[1], params.mSpecColor.mV[2], params.mSpecColor.mV[3]); + current_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, params.mEnvIntensity); + current_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, params.mFullbright ? 1.f : 0.f); + + if (params.mNormalMap) + { + params.mNormalMap->addTextureStats(params.mVSize); + current_shader->bindTexture(LLShaderMgr::BUMP_MAP, params.mNormalMap); + } + + if (params.mSpecularMap) + { + params.mSpecularMap->addTextureStats(params.mVSize); + current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, params.mSpecularMap); + } + } + + } else if (LLPipeline::sRenderDeferred && current_shader && (current_shader == simple_shader)) + { + current_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, 1.0f, 1.0f, 1.0f, 1.0f); + current_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, 0.0f); + LLViewerFetchedTexture::sFlatNormalImagep->addTextureStats(params.mVSize); + current_shader->bindTexture(LLShaderMgr::BUMP_MAP, LLViewerFetchedTexture::sFlatNormalImagep); + LLViewerFetchedTexture::sWhiteImagep->addTextureStats(params.mVSize); + current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, LLViewerFetchedTexture::sWhiteImagep); + } + + if (params.mGroup) { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_MESH_REBUILD); params.mGroup->rebuildMesh(); } - (IsMaterial(params) ? materials : - IsFullbright(params) ? fullbrights : - simples)->push_back(¶ms); + bool tex_setup = false; - if (IsEmissive(params)) - { - emissives->push_back(¶ms); - } - } - } - } + if (use_shaders && params.mTextureList.size() > 1) + { + for (U32 i = 0; i < params.mTextureList.size(); ++i) + { + if (params.mTextureList[i].notNull()) + { + gGL.getTexUnit(i)->bind(params.mTextureList[i], TRUE); + } + } + } + else + { //not batching textures or batch has only 1 texture -- might need a texture matrix + if (params.mTexture.notNull()) + { + params.mTexture->addTextureStats(params.mVSize); + if (use_shaders && mat) + { + current_shader->bindTexture(LLShaderMgr::DIFFUSE_MAP, params.mTexture); + } + else + { + gGL.getTexUnit(0)->bind(params.mTexture, TRUE) ; + } + + if (params.mTextureMatrix) + { + tex_setup = true; + gGL.getTexUnit(0)->activate(); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadMatrix((GLfloat*) params.mTextureMatrix->mMatrix); + gPipeline.mTextureMatrixOps++; + } + } + else + { + gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); + } + } - renderSimples(mask, simples_3d); - renderFullbrights(mask, fullbrights_3d); - renderMaterials(mask, materials_3d); - renderEmissives(mask, emissives_3d); + { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_PUSH); - LLGLDisable cull(GL_CULL_FACE); + LLGLEnableFunc stencil_test(GL_STENCIL_TEST, params.mSelected, &LLGLCommonFunc::selected_stencil_test); - renderSimples(mask, simples_hud); - renderFullbrights(mask, fullbrights_hud); - renderMaterials(mask, materials_hud); - renderEmissives(mask, emissives_hud); - - simple_shader->bind(); - current_shader = simple_shader; + gGL.blendFunc((LLRender::eBlendFactor) params.mBlendFuncSrc, (LLRender::eBlendFactor) params.mBlendFuncDst, mAlphaSFactor, mAlphaDFactor); + params.mVertexBuffer->setBuffer(mask & ~(params.mFullbright ? (LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2) : 0)); - gGL.setSceneBlendType(LLRender::BT_ALPHA); + params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); + gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); + } + + // If this alpha mesh has glow, then draw it a second time to add the destination-alpha (=glow). Interleaving these state-changing calls could be expensive, but glow must be drawn Z-sorted with alpha. + if (current_shader && + draw_glow_for_this_partition && + params.mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE)) + { + // install glow-accumulating blend mode + gGL.blendFunc(LLRender::BF_ZERO, LLRender::BF_ONE, // don't touch color + LLRender::BF_ONE, LLRender::BF_ONE); // add to alpha (glow) + + emissive_shader->bind(); + if (LLPipeline::sRenderingHUDs) + { + emissive_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); + } + else + { + emissive_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); + } + params.mVertexBuffer->setBuffer((mask & ~LLVertexBuffer::MAP_COLOR) | LLVertexBuffer::MAP_EMISSIVE); + + // do the actual drawing, again + params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); + gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); + + // restore our alpha blend mode + gGL.blendFunc(mColorSFactor, mColorDFactor, mAlphaSFactor, mAlphaDFactor); + + current_shader->bind(); + } + + if (tex_setup) + { + gGL.getTexUnit(0)->activate(); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_MODELVIEW); + } + } + } + } - gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); + gGL.setSceneBlendType(LLRender::BT_ALPHA); LLVertexBuffer::unbind(); - gPipeline.enableLightsDynamic(); + if (!light_enabled) + { + gPipeline.enableLightsDynamic(); + } } -- cgit v1.2.3 From f1fe689e18c31f37b517347f22adc328c0d31f5f Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 4 Mar 2019 13:19:39 -0800 Subject: SL-10566 Put back old alpha pool draw loop with option to render emissives out of order to save state changes. --- indra/newview/lldrawpoolalpha.cpp | 75 +++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 19 deletions(-) (limited to 'indra/newview/lldrawpoolalpha.cpp') diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 7945c950db..9ec893d910 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -49,6 +49,8 @@ #include "llspatialpartition.h" #include "llglcommonfunc.h" +#define RENDER_EMISSIVE_OUT_OF_ORDER 1 // faster, but technically different draw order than prev revisions + BOOL LLDrawPoolAlpha::sShowDebugAlpha = FALSE; static BOOL deferred_render = FALSE; @@ -66,6 +68,7 @@ static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_SHADER_BINDS("Alpha Shader static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_DEFERRED_SHADER_BINDS("Alpha Def Binds"); static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_DEFERRED_TEX_BINDS("Alpha Def Tex Binds"); static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_MESH_REBUILD("Alpha Mesh Rebuild"); +static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_EMISSIVE("Alpha Emissive"); LLDrawPoolAlpha::LLDrawPoolAlpha(U32 type) : LLRenderPass(type), current_shader(NULL), target_shader(NULL), @@ -531,7 +534,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) BOOL light_enabled = TRUE; BOOL use_shaders = gPipeline.canUseVertexShaders(); - + for (LLCullResult::sg_iterator i = gPipeline.beginAlphaGroups(); i != gPipeline.endAlphaGroups(); ++i) { LLSpatialGroup* group = *i; @@ -541,6 +544,8 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) if (group->getSpatialPartition()->mRenderByGroup && !group->isDead()) { + std::vector emissives; + bool is_particle_or_hud_particle = group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_PARTICLE || group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_HUD_PARTICLE; @@ -638,6 +643,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) if (current_shader != target_shader) { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED_SHADER_BINDS); gPipeline.bindDeferredShader(*target_shader); } } @@ -653,6 +659,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) if(use_shaders && (current_shader != target_shader)) {// If we need shaders, and we're not ALREADY using the proper shader, then bind it // (this way we won't rebind shaders unnecessarily). + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_SHADER_BINDS); current_shader = target_shader; current_shader->bind(); } @@ -673,12 +680,14 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) if (params.mNormalMap) { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED_TEX_BINDS); params.mNormalMap->addTextureStats(params.mVSize); current_shader->bindTexture(LLShaderMgr::BUMP_MAP, params.mNormalMap); } if (params.mSpecularMap) { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED_TEX_BINDS); params.mSpecularMap->addTextureStats(params.mVSize); current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, params.mSpecularMap); } @@ -703,6 +712,8 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) if (use_shaders && params.mTextureList.size() > 1) { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_TEX_BINDS); + for (U32 i = 0; i < params.mTextureList.size(); ++i) { if (params.mTextureList[i].notNull()) @@ -715,6 +726,8 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) { //not batching textures or batch has only 1 texture -- might need a texture matrix if (params.mTexture.notNull()) { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_TEX_BINDS); + params.mTexture->addTextureStats(params.mVSize); if (use_shaders && mat) { @@ -748,48 +761,72 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) gGL.blendFunc((LLRender::eBlendFactor) params.mBlendFuncSrc, (LLRender::eBlendFactor) params.mBlendFuncDst, mAlphaSFactor, mAlphaDFactor); params.mVertexBuffer->setBuffer(mask & ~(params.mFullbright ? (LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2) : 0)); - params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); - gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); + { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DRAW); + params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); + gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); + } } - + // If this alpha mesh has glow, then draw it a second time to add the destination-alpha (=glow). Interleaving these state-changing calls could be expensive, but glow must be drawn Z-sorted with alpha. if (current_shader && draw_glow_for_this_partition && params.mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE)) { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_EMISSIVE); + + #if RENDER_EMISSIVE_OUT_OF_ORDER + emissives.push_back(¶ms); + #else // install glow-accumulating blend mode gGL.blendFunc(LLRender::BF_ZERO, LLRender::BF_ONE, // don't touch color LLRender::BF_ONE, LLRender::BF_ONE); // add to alpha (glow) - emissive_shader->bind(); - if (LLPipeline::sRenderingHUDs) - { - emissive_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); - } - else - { - emissive_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); - } - params.mVertexBuffer->setBuffer((mask & ~LLVertexBuffer::MAP_COLOR) | LLVertexBuffer::MAP_EMISSIVE); - - // do the actual drawing, again - params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); - gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); + { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_GLOW); + emissive_shader->bind(); + if (LLPipeline::sRenderingHUDs) + { + emissive_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); + } + else + { + emissive_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); + } + + params.mVertexBuffer->setBuffer((mask & ~LLVertexBuffer::MAP_COLOR) | LLVertexBuffer::MAP_EMISSIVE); + } + + { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DRAW); + // do the actual drawing, again + params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); + gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); + } // restore our alpha blend mode gGL.blendFunc(mColorSFactor, mColorDFactor, mAlphaSFactor, mAlphaDFactor); current_shader->bind(); + #endif + } if (tex_setup) { gGL.getTexUnit(0)->activate(); + gGL.matrixMode(LLRender::MM_TEXTURE); gGL.loadIdentity(); gGL.matrixMode(LLRender::MM_MODELVIEW); } } - } + + #if RENDER_EMISSIVE_OUT_OF_ORDER + renderEmissives(mask, emissives); + #endif + + current_shader->bind(); + } } gGL.setSceneBlendType(LLRender::BT_ALPHA); -- cgit v1.2.3 From cc43bee5b185fe6c1945c096dfc914931de158a5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 4 Mar 2019 14:13:27 -0800 Subject: Factor emissives and fullbrights out of alpha draw pool loop of death. --- indra/newview/lldrawpoolalpha.cpp | 179 ++++++++++++-------------------------- 1 file changed, 54 insertions(+), 125 deletions(-) (limited to 'indra/newview/lldrawpoolalpha.cpp') diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 9ec893d910..c6605a7b2e 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -49,8 +49,6 @@ #include "llspatialpartition.h" #include "llglcommonfunc.h" -#define RENDER_EMISSIVE_OUT_OF_ORDER 1 // faster, but technically different draw order than prev revisions - BOOL LLDrawPoolAlpha::sShowDebugAlpha = FALSE; static BOOL deferred_render = FALSE; @@ -432,6 +430,10 @@ void LLDrawPoolAlpha::renderSimples(U32 mask, std::vector& simples) for (LLDrawInfo* draw : simples) { bool tex_setup = TexSetup(draw); + + LLGLEnableFunc stencil_test(GL_STENCIL_TEST, draw->mSelected, &LLGLCommonFunc::selected_stencil_test); + gGL.blendFunc((LLRender::eBlendFactor) draw->mBlendFuncSrc, (LLRender::eBlendFactor) draw->mBlendFuncDst, mAlphaSFactor, mAlphaDFactor); + Draw(draw, mask); RestoreTexSetup(tex_setup); } @@ -442,10 +444,14 @@ void LLDrawPoolAlpha::renderFullbrights(U32 mask, std::vector& full { gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); fullbright_shader->bind(); - fullbright_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, 0.0f); + fullbright_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, 1.0f); for (LLDrawInfo* draw : fullbrights) { bool tex_setup = TexSetup(draw); + + LLGLEnableFunc stencil_test(GL_STENCIL_TEST, draw->mSelected, &LLGLCommonFunc::selected_stencil_test); + gGL.blendFunc((LLRender::eBlendFactor) draw->mBlendFuncSrc, (LLRender::eBlendFactor) draw->mBlendFuncDst, mAlphaSFactor, mAlphaDFactor); + Draw(draw, mask & ~(LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2)); RestoreTexSetup(tex_setup); } @@ -501,6 +507,9 @@ void LLDrawPoolAlpha::renderMaterials(U32 mask, std::vector& materi } } + LLGLEnableFunc stencil_test(GL_STENCIL_TEST, draw->mSelected, &LLGLCommonFunc::selected_stencil_test); + gGL.blendFunc((LLRender::eBlendFactor) draw->mBlendFuncSrc, (LLRender::eBlendFactor) draw->mBlendFuncDst, mAlphaSFactor, mAlphaDFactor); + Draw(draw, mask); RestoreTexSetup(tex_setup); } @@ -530,10 +539,10 @@ void LLDrawPoolAlpha::renderEmissives(U32 mask, std::vector& emissi void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) { - BOOL initialized_lighting = FALSE; - BOOL light_enabled = TRUE; - - BOOL use_shaders = gPipeline.canUseVertexShaders(); + + BOOL use_shaders = gPipeline.canUseVertexShaders(); + + gPipeline.enableLightsDynamic(); for (LLCullResult::sg_iterator i = gPipeline.beginAlphaGroups(); i != gPipeline.endAlphaGroups(); ++i) { @@ -545,6 +554,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) !group->isDead()) { std::vector emissives; + std::vector fullbrights; bool is_particle_or_hud_particle = group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_PARTICLE || group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_HUD_PARTICLE; @@ -588,48 +598,22 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) } } + if (params.mFullbright) + { + fullbrights.push_back(¶ms); + continue; + } + LLRenderPass::applyModelMatrix(params); LLMaterial* mat = NULL; - if (deferred_render) + if (deferred_render && use_shaders) { mat = params.mMaterial; } - - if (params.mFullbright) - { - // Turn off lighting if it hasn't already been so. - if (light_enabled || !initialized_lighting) - { - initialized_lighting = TRUE; - if (use_shaders) - { - target_shader = fullbright_shader; - } - else - { - gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); - } - light_enabled = FALSE; - } - } - // Turn on lighting if it isn't already. - else if (!light_enabled || !initialized_lighting) - { - initialized_lighting = TRUE; - if (use_shaders) - { - target_shader = simple_shader; - } - else - { - gPipeline.enableLightsDynamic(); - } - light_enabled = TRUE; - } - - if (deferred_render && mat) + + if (mat) { U32 mask = params.mShaderMask; @@ -645,15 +629,30 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) { LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED_SHADER_BINDS); gPipeline.bindDeferredShader(*target_shader); + current_shader = target_shader; + } + + current_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, params.mSpecColor.mV[0], params.mSpecColor.mV[1], params.mSpecColor.mV[2], params.mSpecColor.mV[3]); + current_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, params.mEnvIntensity); + current_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, params.mFullbright ? 1.f : 0.f); + + if (params.mNormalMap) + { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED_TEX_BINDS); + params.mNormalMap->addTextureStats(params.mVSize); + current_shader->bindTexture(LLShaderMgr::BUMP_MAP, params.mNormalMap); + } + + if (params.mSpecularMap) + { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED_TEX_BINDS); + params.mSpecularMap->addTextureStats(params.mVSize); + current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, params.mSpecularMap); } - } - else if (!params.mFullbright) - { - target_shader = simple_shader; } else { - target_shader = fullbright_shader; + target_shader = simple_shader; } if(use_shaders && (current_shader != target_shader)) @@ -669,40 +668,6 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) current_shader = NULL; } - if (use_shaders && mat) - { - // We have a material. Supply the appropriate data here. - if (LLPipeline::sRenderDeferred) - { - current_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, params.mSpecColor.mV[0], params.mSpecColor.mV[1], params.mSpecColor.mV[2], params.mSpecColor.mV[3]); - current_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, params.mEnvIntensity); - current_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, params.mFullbright ? 1.f : 0.f); - - if (params.mNormalMap) - { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED_TEX_BINDS); - params.mNormalMap->addTextureStats(params.mVSize); - current_shader->bindTexture(LLShaderMgr::BUMP_MAP, params.mNormalMap); - } - - if (params.mSpecularMap) - { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED_TEX_BINDS); - params.mSpecularMap->addTextureStats(params.mVSize); - current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, params.mSpecularMap); - } - } - - } else if (LLPipeline::sRenderDeferred && current_shader && (current_shader == simple_shader)) - { - current_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, 1.0f, 1.0f, 1.0f, 1.0f); - current_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, 0.0f); - LLViewerFetchedTexture::sFlatNormalImagep->addTextureStats(params.mVSize); - current_shader->bindTexture(LLShaderMgr::BUMP_MAP, LLViewerFetchedTexture::sFlatNormalImagep); - LLViewerFetchedTexture::sWhiteImagep->addTextureStats(params.mVSize); - current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, LLViewerFetchedTexture::sWhiteImagep); - } - if (params.mGroup) { params.mGroup->rebuildMesh(); @@ -735,7 +700,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) } else { - gGL.getTexUnit(0)->bind(params.mTexture, TRUE) ; + gGL.getTexUnit(0)->bind(params.mTexture, TRUE) ; } if (params.mTextureMatrix) @@ -774,42 +739,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) params.mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE)) { LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_EMISSIVE); - - #if RENDER_EMISSIVE_OUT_OF_ORDER emissives.push_back(¶ms); - #else - // install glow-accumulating blend mode - gGL.blendFunc(LLRender::BF_ZERO, LLRender::BF_ONE, // don't touch color - LLRender::BF_ONE, LLRender::BF_ONE); // add to alpha (glow) - - { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_GLOW); - emissive_shader->bind(); - if (LLPipeline::sRenderingHUDs) - { - emissive_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); - } - else - { - emissive_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); - } - - params.mVertexBuffer->setBuffer((mask & ~LLVertexBuffer::MAP_COLOR) | LLVertexBuffer::MAP_EMISSIVE); - } - - { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DRAW); - // do the actual drawing, again - params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); - gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); - } - - // restore our alpha blend mode - gGL.blendFunc(mColorSFactor, mColorDFactor, mAlphaSFactor, mAlphaDFactor); - - current_shader->bind(); - #endif - } if (tex_setup) @@ -821,20 +751,19 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) } } - #if RENDER_EMISSIVE_OUT_OF_ORDER + renderFullbrights(mask, fullbrights); renderEmissives(mask, emissives); - #endif - current_shader->bind(); + if (current_shader) + { + current_shader->bind(); + } } } + gPipeline.enableLightsDynamic(); + gGL.setSceneBlendType(LLRender::BT_ALPHA); LLVertexBuffer::unbind(); - - if (!light_enabled) - { - gPipeline.enableLightsDynamic(); - } } -- cgit v1.2.3 From 659eaf045ef7ada77192baa0a353ad2af2e2b029 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 4 Mar 2019 15:40:07 -0800 Subject: Fix line-endings. --- indra/newview/lldrawpoolalpha.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'indra/newview/lldrawpoolalpha.cpp') diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index c6605a7b2e..ea8a1c62a1 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -431,7 +431,7 @@ void LLDrawPoolAlpha::renderSimples(U32 mask, std::vector& simples) { bool tex_setup = TexSetup(draw); - LLGLEnableFunc stencil_test(GL_STENCIL_TEST, draw->mSelected, &LLGLCommonFunc::selected_stencil_test); + LLGLEnableFunc stencil_test(GL_STENCIL_TEST, draw->mSelected, &LLGLCommonFunc::selected_stencil_test); gGL.blendFunc((LLRender::eBlendFactor) draw->mBlendFuncSrc, (LLRender::eBlendFactor) draw->mBlendFuncDst, mAlphaSFactor, mAlphaDFactor); Draw(draw, mask); @@ -449,7 +449,7 @@ void LLDrawPoolAlpha::renderFullbrights(U32 mask, std::vector& full { bool tex_setup = TexSetup(draw); - LLGLEnableFunc stencil_test(GL_STENCIL_TEST, draw->mSelected, &LLGLCommonFunc::selected_stencil_test); + LLGLEnableFunc stencil_test(GL_STENCIL_TEST, draw->mSelected, &LLGLCommonFunc::selected_stencil_test); gGL.blendFunc((LLRender::eBlendFactor) draw->mBlendFuncSrc, (LLRender::eBlendFactor) draw->mBlendFuncDst, mAlphaSFactor, mAlphaDFactor); Draw(draw, mask & ~(LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2)); @@ -507,7 +507,7 @@ void LLDrawPoolAlpha::renderMaterials(U32 mask, std::vector& materi } } - LLGLEnableFunc stencil_test(GL_STENCIL_TEST, draw->mSelected, &LLGLCommonFunc::selected_stencil_test); + LLGLEnableFunc stencil_test(GL_STENCIL_TEST, draw->mSelected, &LLGLCommonFunc::selected_stencil_test); gGL.blendFunc((LLRender::eBlendFactor) draw->mBlendFuncSrc, (LLRender::eBlendFactor) draw->mBlendFuncDst, mAlphaSFactor, mAlphaDFactor); Draw(draw, mask); @@ -572,11 +572,11 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) for (LLSpatialGroup::drawmap_elem_t::iterator k = draw_info.begin(); k != draw_info.end(); ++k) { LLDrawInfo& params = **k; - - if ((params.mVertexBuffer->getTypeMask() & mask) != mask) + U32 have_mask = params.mVertexBuffer->getTypeMask() & mask; + if (have_mask != mask) { //FIXME! LL_WARNS_ONCE() << "Missing required components, expected mask: " << mask - << " present: " << (params.mVertexBuffer->getTypeMask() & mask) + << " present: " << have_mask << ". Skipping render batch." << LL_ENDL; continue; } -- cgit v1.2.3 From f3303654a5ded57fab73e8303a508ecf13cf4651 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 4 Mar 2019 16:20:31 -0800 Subject: Roll back even more alpha draw pool optimizations that break particles. --- indra/newview/lldrawpoolalpha.cpp | 180 ++++++++++++++++++++++++-------------- 1 file changed, 113 insertions(+), 67 deletions(-) (limited to 'indra/newview/lldrawpoolalpha.cpp') diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index ea8a1c62a1..555664bdd3 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -539,11 +539,11 @@ void LLDrawPoolAlpha::renderEmissives(U32 mask, std::vector& emissi void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) { - - BOOL use_shaders = gPipeline.canUseVertexShaders(); - - gPipeline.enableLightsDynamic(); - + BOOL initialized_lighting = FALSE; + BOOL light_enabled = TRUE; + + BOOL use_shaders = gPipeline.canUseVertexShaders(); + for (LLCullResult::sg_iterator i = gPipeline.beginAlphaGroups(); i != gPipeline.endAlphaGroups(); ++i) { LLSpatialGroup* group = *i; @@ -553,9 +553,6 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) if (group->getSpatialPartition()->mRenderByGroup && !group->isDead()) { - std::vector emissives; - std::vector fullbrights; - bool is_particle_or_hud_particle = group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_PARTICLE || group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_HUD_PARTICLE; @@ -572,11 +569,11 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) for (LLSpatialGroup::drawmap_elem_t::iterator k = draw_info.begin(); k != draw_info.end(); ++k) { LLDrawInfo& params = **k; - U32 have_mask = params.mVertexBuffer->getTypeMask() & mask; - if (have_mask != mask) + + if ((params.mVertexBuffer->getTypeMask() & mask) != mask) { //FIXME! LL_WARNS_ONCE() << "Missing required components, expected mask: " << mask - << " present: " << have_mask + << " present: " << (params.mVertexBuffer->getTypeMask() & mask) << ". Skipping render batch." << LL_ENDL; continue; } @@ -598,22 +595,48 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) } } - if (params.mFullbright) - { - fullbrights.push_back(¶ms); - continue; - } - LLRenderPass::applyModelMatrix(params); LLMaterial* mat = NULL; - if (deferred_render && use_shaders) + if (deferred_render) { mat = params.mMaterial; } - - if (mat) + + if (params.mFullbright) + { + // Turn off lighting if it hasn't already been so. + if (light_enabled || !initialized_lighting) + { + initialized_lighting = TRUE; + if (use_shaders) + { + target_shader = fullbright_shader; + } + else + { + gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); + } + light_enabled = FALSE; + } + } + // Turn on lighting if it isn't already. + else if (!light_enabled || !initialized_lighting) + { + initialized_lighting = TRUE; + if (use_shaders) + { + target_shader = simple_shader; + } + else + { + gPipeline.enableLightsDynamic(); + } + light_enabled = TRUE; + } + + if (deferred_render && mat) { U32 mask = params.mShaderMask; @@ -627,38 +650,21 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) if (current_shader != target_shader) { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED_SHADER_BINDS); gPipeline.bindDeferredShader(*target_shader); - current_shader = target_shader; - } - - current_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, params.mSpecColor.mV[0], params.mSpecColor.mV[1], params.mSpecColor.mV[2], params.mSpecColor.mV[3]); - current_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, params.mEnvIntensity); - current_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, params.mFullbright ? 1.f : 0.f); - - if (params.mNormalMap) - { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED_TEX_BINDS); - params.mNormalMap->addTextureStats(params.mVSize); - current_shader->bindTexture(LLShaderMgr::BUMP_MAP, params.mNormalMap); - } - - if (params.mSpecularMap) - { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED_TEX_BINDS); - params.mSpecularMap->addTextureStats(params.mVSize); - current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, params.mSpecularMap); } } - else + else if (!params.mFullbright) { target_shader = simple_shader; } + else + { + target_shader = fullbright_shader; + } if(use_shaders && (current_shader != target_shader)) {// If we need shaders, and we're not ALREADY using the proper shader, then bind it // (this way we won't rebind shaders unnecessarily). - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_SHADER_BINDS); current_shader = target_shader; current_shader->bind(); } @@ -668,6 +674,38 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) current_shader = NULL; } + if (use_shaders && mat) + { + // We have a material. Supply the appropriate data here. + if (LLPipeline::sRenderDeferred) + { + current_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, params.mSpecColor.mV[0], params.mSpecColor.mV[1], params.mSpecColor.mV[2], params.mSpecColor.mV[3]); + current_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, params.mEnvIntensity); + current_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, params.mFullbright ? 1.f : 0.f); + + if (params.mNormalMap) + { + params.mNormalMap->addTextureStats(params.mVSize); + current_shader->bindTexture(LLShaderMgr::BUMP_MAP, params.mNormalMap); + } + + if (params.mSpecularMap) + { + params.mSpecularMap->addTextureStats(params.mVSize); + current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, params.mSpecularMap); + } + } + + } else if (LLPipeline::sRenderDeferred && current_shader && (current_shader == simple_shader)) + { + current_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, 1.0f, 1.0f, 1.0f, 1.0f); + current_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, 0.0f); + LLViewerFetchedTexture::sFlatNormalImagep->addTextureStats(params.mVSize); + current_shader->bindTexture(LLShaderMgr::BUMP_MAP, LLViewerFetchedTexture::sFlatNormalImagep); + LLViewerFetchedTexture::sWhiteImagep->addTextureStats(params.mVSize); + current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, LLViewerFetchedTexture::sWhiteImagep); + } + if (params.mGroup) { params.mGroup->rebuildMesh(); @@ -677,8 +715,6 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) if (use_shaders && params.mTextureList.size() > 1) { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_TEX_BINDS); - for (U32 i = 0; i < params.mTextureList.size(); ++i) { if (params.mTextureList[i].notNull()) @@ -691,8 +727,6 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) { //not batching textures or batch has only 1 texture -- might need a texture matrix if (params.mTexture.notNull()) { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_TEX_BINDS); - params.mTexture->addTextureStats(params.mVSize); if (use_shaders && mat) { @@ -700,7 +734,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) } else { - gGL.getTexUnit(0)->bind(params.mTexture, TRUE) ; + gGL.getTexUnit(0)->bind(params.mTexture, TRUE) ; } if (params.mTextureMatrix) @@ -726,44 +760,56 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) gGL.blendFunc((LLRender::eBlendFactor) params.mBlendFuncSrc, (LLRender::eBlendFactor) params.mBlendFuncDst, mAlphaSFactor, mAlphaDFactor); params.mVertexBuffer->setBuffer(mask & ~(params.mFullbright ? (LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2) : 0)); - { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DRAW); - params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); - gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); - } + params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); + gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); } - + // If this alpha mesh has glow, then draw it a second time to add the destination-alpha (=glow). Interleaving these state-changing calls could be expensive, but glow must be drawn Z-sorted with alpha. if (current_shader && draw_glow_for_this_partition && params.mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE)) { - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_EMISSIVE); - emissives.push_back(¶ms); + // install glow-accumulating blend mode + gGL.blendFunc(LLRender::BF_ZERO, LLRender::BF_ONE, // don't touch color + LLRender::BF_ONE, LLRender::BF_ONE); // add to alpha (glow) + + emissive_shader->bind(); + if (LLPipeline::sRenderingHUDs) + { + emissive_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); + } + else + { + emissive_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); + } + params.mVertexBuffer->setBuffer((mask & ~LLVertexBuffer::MAP_COLOR) | LLVertexBuffer::MAP_EMISSIVE); + + // do the actual drawing, again + params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); + gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); + + // restore our alpha blend mode + gGL.blendFunc(mColorSFactor, mColorDFactor, mAlphaSFactor, mAlphaDFactor); + + current_shader->bind(); } if (tex_setup) { gGL.getTexUnit(0)->activate(); - gGL.matrixMode(LLRender::MM_TEXTURE); gGL.loadIdentity(); gGL.matrixMode(LLRender::MM_MODELVIEW); } } - - renderFullbrights(mask, fullbrights); - renderEmissives(mask, emissives); - - if (current_shader) - { - current_shader->bind(); - } - } + } } - gPipeline.enableLightsDynamic(); - gGL.setSceneBlendType(LLRender::BT_ALPHA); LLVertexBuffer::unbind(); + + if (!light_enabled) + { + gPipeline.enableLightsDynamic(); + } } -- cgit v1.2.3 From 3396b728d2167c41a6ce4a6ba9dfa1fc13db2333 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 5 Mar 2019 09:35:04 -0800 Subject: Don't rebuild reflection when only edge water patches are in play. Use (Restore)TexSetup for tex binding (should be equivalent now). Simplify uniform management in alpha drawpool loop. Fix wrong modelview mat being used for distortion map gen. --- indra/newview/lldrawpoolalpha.cpp | 276 +++++++++++++++++--------------------- 1 file changed, 124 insertions(+), 152 deletions(-) (limited to 'indra/newview/lldrawpoolalpha.cpp') diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 555664bdd3..7aaab2e3af 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -381,32 +381,77 @@ inline void Draw(LLDrawInfo* draw, U32 mask) gPipeline.addTrianglesDrawn(draw->mCount, draw->mDrawMode); } -inline bool TexSetup(LLDrawInfo* draw) +bool LLDrawPoolAlpha::TexSetup(LLDrawInfo* draw, bool use_shaders, bool use_material, LLGLSLShader* current_shader) { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_TEX_BINDS); + bool tex_setup = false; - if (draw->mTextureMatrix) + if (use_shaders && use_material && current_shader) + { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED_TEX_BINDS); + if (draw->mNormalMap) + { + draw->mNormalMap->addTextureStats(draw->mVSize); + current_shader->bindTexture(LLShaderMgr::BUMP_MAP, draw->mNormalMap); + } + + if (draw->mSpecularMap) + { + draw->mSpecularMap->addTextureStats(draw->mVSize); + current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, draw->mSpecularMap); + } + } + else if (current_shader == simple_shader) + { + LLViewerFetchedTexture::sFlatNormalImagep->addTextureStats(draw->mVSize); + LLViewerFetchedTexture::sWhiteImagep->addTextureStats(draw->mVSize); + current_shader->bindTexture(LLShaderMgr::BUMP_MAP, LLViewerFetchedTexture::sFlatNormalImagep); + current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, LLViewerFetchedTexture::sWhiteImagep); + } + if (use_shaders && draw->mTextureList.size() > 1) { - tex_setup = true; - gGL.getTexUnit(0)->activate(); - gGL.matrixMode(LLRender::MM_TEXTURE); - gGL.loadMatrix((GLfloat*) draw->mTextureMatrix->mMatrix); - gPipeline.mTextureMatrixOps++; + for (U32 i = 0; i < draw->mTextureList.size(); ++i) + { + if (draw->mTextureList[i].notNull()) + { + gGL.getTexUnit(i)->bind(draw->mTextureList[i], TRUE); + } + } } - - LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_TEX_BINDS); - for (U32 i = 0; i < draw->mTextureList.size(); ++i) - { - if (draw->mTextureList[i].notNull()) - { - gGL.getTexUnit(i)->bind(draw->mTextureList[i], TRUE); - } + else + { //not batching textures or batch has only 1 texture -- might need a texture matrix + if (draw->mTexture.notNull()) + { + draw->mTexture->addTextureStats(draw->mVSize); + if (use_shaders && use_material) + { + current_shader->bindTexture(LLShaderMgr::DIFFUSE_MAP, draw->mTexture); + } + else + { + gGL.getTexUnit(0)->bind(draw->mTexture, TRUE) ; + } + + if (draw->mTextureMatrix) + { + tex_setup = true; + gGL.getTexUnit(0)->activate(); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadMatrix((GLfloat*) draw->mTextureMatrix->mMatrix); + gPipeline.mTextureMatrixOps++; + } + } + else + { + gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); + } } - + return tex_setup; } -inline void RestoreTexSetup(bool tex_setup) +void LLDrawPoolAlpha::RestoreTexSetup(bool tex_setup) { if (tex_setup) { @@ -426,11 +471,10 @@ void LLDrawPoolAlpha::renderSimples(U32 mask, std::vector& simples) simple_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, 1.0f, 1.0f, 1.0f, 1.0f); simple_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, 0.0f); simple_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, 0.0f); - + bool use_shaders = gPipeline.canUseVertexShaders(); for (LLDrawInfo* draw : simples) { - bool tex_setup = TexSetup(draw); - + bool tex_setup = TexSetup(draw, use_shaders, false, simple_shader); LLGLEnableFunc stencil_test(GL_STENCIL_TEST, draw->mSelected, &LLGLCommonFunc::selected_stencil_test); gGL.blendFunc((LLRender::eBlendFactor) draw->mBlendFuncSrc, (LLRender::eBlendFactor) draw->mBlendFuncDst, mAlphaSFactor, mAlphaDFactor); @@ -445,9 +489,10 @@ void LLDrawPoolAlpha::renderFullbrights(U32 mask, std::vector& full gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); fullbright_shader->bind(); fullbright_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, 1.0f); + bool use_shaders = gPipeline.canUseVertexShaders(); for (LLDrawInfo* draw : fullbrights) { - bool tex_setup = TexSetup(draw); + bool tex_setup = TexSetup(draw, use_shaders, false, fullbright_shader); LLGLEnableFunc stencil_test(GL_STENCIL_TEST, draw->mSelected, &LLGLCommonFunc::selected_stencil_test); gGL.blendFunc((LLRender::eBlendFactor) draw->mBlendFuncSrc, (LLRender::eBlendFactor) draw->mBlendFuncDst, mAlphaSFactor, mAlphaDFactor); @@ -463,7 +508,8 @@ void LLDrawPoolAlpha::renderMaterials(U32 mask, std::vector& materi LLGLSLShader::bindNoShader(); current_shader = NULL; - gPipeline.enableLightsDynamic(); + gPipeline.enableLightsDynamic(); + bool use_shaders = gPipeline.canUseVertexShaders(); for (LLDrawInfo* draw : materials) { U32 mask = draw->mShaderMask; @@ -482,11 +528,7 @@ void LLDrawPoolAlpha::renderMaterials(U32 mask, std::vector& materi current_shader = target_shader; } - bool tex_setup = TexSetup(draw); - if (!draw->mTexture.isNull()) - { - current_shader->bindTexture(LLShaderMgr::DIFFUSE_MAP, draw->mTexture); - } + bool tex_setup = TexSetup(draw, use_shaders, true, current_shader); current_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, draw->mSpecColor.mV[0], draw->mSpecColor.mV[1], draw->mSpecColor.mV[2], draw->mSpecColor.mV[3]); current_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, draw->mEnvIntensity); @@ -523,10 +565,10 @@ void LLDrawPoolAlpha::renderEmissives(U32 mask, std::vector& emissi // install glow-accumulating blend mode // don't touch color, add to alpha (glow) gGL.blendFunc(LLRender::BF_ZERO, LLRender::BF_ONE, LLRender::BF_ONE, LLRender::BF_ONE); - + bool use_shaders = gPipeline.canUseVertexShaders(); for (LLDrawInfo* draw : emissives) { - bool tex_setup = TexSetup(draw); + bool tex_setup = TexSetup(draw, use_shaders, false, emissive_shader); Draw(draw, (mask & ~LLVertexBuffer::MAP_COLOR) | LLVertexBuffer::MAP_EMISSIVE); RestoreTexSetup(tex_setup); } @@ -553,6 +595,9 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) if (group->getSpatialPartition()->mRenderByGroup && !group->isDead()) { + std::vector emissives; + std::vector fullbrights; + bool is_particle_or_hud_particle = group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_PARTICLE || group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_HUD_PARTICLE; @@ -569,11 +614,11 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) for (LLSpatialGroup::drawmap_elem_t::iterator k = draw_info.begin(); k != draw_info.end(); ++k) { LLDrawInfo& params = **k; - - if ((params.mVertexBuffer->getTypeMask() & mask) != mask) + U32 have_mask = params.mVertexBuffer->getTypeMask() & mask; + if (have_mask != mask) { //FIXME! LL_WARNS_ONCE() << "Missing required components, expected mask: " << mask - << " present: " << (params.mVertexBuffer->getTypeMask() & mask) + << " present: " << have_mask << ". Skipping render batch." << LL_ENDL; continue; } @@ -595,6 +640,12 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) } } + if (params.mFullbright) + { + fullbrights.push_back(¶ms); + continue; + } + LLRenderPass::applyModelMatrix(params); LLMaterial* mat = NULL; @@ -603,26 +654,9 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) { mat = params.mMaterial; } - - if (params.mFullbright) - { - // Turn off lighting if it hasn't already been so. - if (light_enabled || !initialized_lighting) - { - initialized_lighting = TRUE; - if (use_shaders) - { - target_shader = fullbright_shader; - } - else - { - gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); - } - light_enabled = FALSE; - } - } + // Turn on lighting if it isn't already. - else if (!light_enabled || !initialized_lighting) + if (!light_enabled || !initialized_lighting) { initialized_lighting = TRUE; if (use_shaders) @@ -650,21 +684,20 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) if (current_shader != target_shader) { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED_SHADER_BINDS); gPipeline.bindDeferredShader(*target_shader); + current_shader = target_shader; } } - else if (!params.mFullbright) - { - target_shader = simple_shader; - } else { - target_shader = fullbright_shader; + target_shader = simple_shader; } if(use_shaders && (current_shader != target_shader)) {// If we need shaders, and we're not ALREADY using the proper shader, then bind it // (this way we won't rebind shaders unnecessarily). + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_SHADER_BINDS); current_shader = target_shader; current_shader->bind(); } @@ -674,83 +707,31 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) current_shader = NULL; } - if (use_shaders && mat) - { - // We have a material. Supply the appropriate data here. - if (LLPipeline::sRenderDeferred) - { - current_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, params.mSpecColor.mV[0], params.mSpecColor.mV[1], params.mSpecColor.mV[2], params.mSpecColor.mV[3]); - current_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, params.mEnvIntensity); - current_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, params.mFullbright ? 1.f : 0.f); - - if (params.mNormalMap) - { - params.mNormalMap->addTextureStats(params.mVSize); - current_shader->bindTexture(LLShaderMgr::BUMP_MAP, params.mNormalMap); - } - - if (params.mSpecularMap) - { - params.mSpecularMap->addTextureStats(params.mVSize); - current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, params.mSpecularMap); - } - } + LLVector4 spec_color(1, 1, 1, 1); + F32 env_intensity = 0.0f; + F32 brightness = 1.0f; - } else if (LLPipeline::sRenderDeferred && current_shader && (current_shader == simple_shader)) + // We have a material. Supply the appropriate data here. + if (use_shaders && mat && LLPipeline::sRenderDeferred) { - current_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, 1.0f, 1.0f, 1.0f, 1.0f); - current_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, 0.0f); - LLViewerFetchedTexture::sFlatNormalImagep->addTextureStats(params.mVSize); - current_shader->bindTexture(LLShaderMgr::BUMP_MAP, LLViewerFetchedTexture::sFlatNormalImagep); - LLViewerFetchedTexture::sWhiteImagep->addTextureStats(params.mVSize); - current_shader->bindTexture(LLShaderMgr::SPECULAR_MAP, LLViewerFetchedTexture::sWhiteImagep); - } + spec_color = params.mSpecColor; + env_intensity = params.mEnvIntensity; + brightness = params.mFullbright ? 1.f : 0.f; + } + + if (current_shader) + { + current_shader->uniform4f(LLShaderMgr::SPECULAR_COLOR, spec_color.mV[0], spec_color.mV[1], spec_color.mV[2], spec_color.mV[3]); + current_shader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, env_intensity); + current_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, brightness); + } if (params.mGroup) { params.mGroup->rebuildMesh(); } - bool tex_setup = false; - - if (use_shaders && params.mTextureList.size() > 1) - { - for (U32 i = 0; i < params.mTextureList.size(); ++i) - { - if (params.mTextureList[i].notNull()) - { - gGL.getTexUnit(i)->bind(params.mTextureList[i], TRUE); - } - } - } - else - { //not batching textures or batch has only 1 texture -- might need a texture matrix - if (params.mTexture.notNull()) - { - params.mTexture->addTextureStats(params.mVSize); - if (use_shaders && mat) - { - current_shader->bindTexture(LLShaderMgr::DIFFUSE_MAP, params.mTexture); - } - else - { - gGL.getTexUnit(0)->bind(params.mTexture, TRUE) ; - } - - if (params.mTextureMatrix) - { - tex_setup = true; - gGL.getTexUnit(0)->activate(); - gGL.matrixMode(LLRender::MM_TEXTURE); - gGL.loadMatrix((GLfloat*) params.mTextureMatrix->mMatrix); - gPipeline.mTextureMatrixOps++; - } - } - else - { - gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - } - } + bool tex_setup = TexSetup(¶ms, use_shaders, mat != nullptr, current_shader); { LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_PUSH); @@ -760,48 +741,39 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) gGL.blendFunc((LLRender::eBlendFactor) params.mBlendFuncSrc, (LLRender::eBlendFactor) params.mBlendFuncDst, mAlphaSFactor, mAlphaDFactor); params.mVertexBuffer->setBuffer(mask & ~(params.mFullbright ? (LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2) : 0)); - params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); - gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); + { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DRAW); + params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); + gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); + } } - + // If this alpha mesh has glow, then draw it a second time to add the destination-alpha (=glow). Interleaving these state-changing calls could be expensive, but glow must be drawn Z-sorted with alpha. if (current_shader && draw_glow_for_this_partition && params.mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE)) { - // install glow-accumulating blend mode - gGL.blendFunc(LLRender::BF_ZERO, LLRender::BF_ONE, // don't touch color - LLRender::BF_ONE, LLRender::BF_ONE); // add to alpha (glow) - - emissive_shader->bind(); - if (LLPipeline::sRenderingHUDs) - { - emissive_shader->uniform1i(LLShaderMgr::NO_ATMO, 1); - } - else - { - emissive_shader->uniform1i(LLShaderMgr::NO_ATMO, 0); - } - params.mVertexBuffer->setBuffer((mask & ~LLVertexBuffer::MAP_COLOR) | LLVertexBuffer::MAP_EMISSIVE); - - // do the actual drawing, again - params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); - gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); - - // restore our alpha blend mode - gGL.blendFunc(mColorSFactor, mColorDFactor, mAlphaSFactor, mAlphaDFactor); - - current_shader->bind(); + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_EMISSIVE); + emissives.push_back(¶ms); } if (tex_setup) { gGL.getTexUnit(0)->activate(); + gGL.matrixMode(LLRender::MM_TEXTURE); gGL.loadIdentity(); gGL.matrixMode(LLRender::MM_MODELVIEW); } } - } + + renderFullbrights(mask, fullbrights); + renderEmissives(mask, emissives); + + if (current_shader) + { + current_shader->bind(); + } + } } gGL.setSceneBlendType(LLRender::BT_ALPHA); -- cgit v1.2.3 From a10ec81e82d79bd79d5b058fda1b370073bfb480 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 15 Mar 2019 08:13:04 -0700 Subject: SL-10743, SL-10744 Don't step on SUNLIGHT_COLOR uniform w/ syncLightState competing set. Put drawpool alpha render loop lighting setup changes as they were (this will give back some performance and possibly require reopening 10566). --- indra/newview/lldrawpoolalpha.cpp | 59 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 4 deletions(-) (limited to 'indra/newview/lldrawpoolalpha.cpp') diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 7aaab2e3af..4c625eb684 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -67,6 +67,7 @@ static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_DEFERRED_SHADER_BINDS("Alp static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_DEFERRED_TEX_BINDS("Alpha Def Tex Binds"); static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_MESH_REBUILD("Alpha Mesh Rebuild"); static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_EMISSIVE("Alpha Emissive"); +static LLTrace::BlockTimerStatHandle FTM_RENDER_ALPHA_LIGHT_SETUP("Alpha Light Setup"); LLDrawPoolAlpha::LLDrawPoolAlpha(U32 type) : LLRenderPass(type), current_shader(NULL), target_shader(NULL), @@ -640,11 +641,13 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) } } +#if BATCH_FULLBRIGHTS if (params.mFullbright) { fullbrights.push_back(¶ms); continue; } +#endif LLRenderPass::applyModelMatrix(params); @@ -654,10 +657,31 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) { mat = params.mMaterial; } - + + if (params.mFullbright) + { + // Turn off lighting if it hasn't already been so. + if (light_enabled || !initialized_lighting) + { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_LIGHT_SETUP); + + initialized_lighting = TRUE; + if (use_shaders) + { + target_shader = fullbright_shader; + } + else + { + gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); + } + light_enabled = FALSE; + } + } // Turn on lighting if it isn't already. - if (!light_enabled || !initialized_lighting) + else if (!light_enabled || !initialized_lighting) { + LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_LIGHT_SETUP); + initialized_lighting = TRUE; if (use_shaders) { @@ -689,10 +713,14 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) current_shader = target_shader; } } - else + else if (!params.mFullbright) { target_shader = simple_shader; } + else + { + target_shader = fullbright_shader; + } if(use_shaders && (current_shader != target_shader)) {// If we need shaders, and we're not ALREADY using the proper shader, then bind it @@ -754,7 +782,26 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) params.mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE)) { LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_EMISSIVE); +#if BATCH_EMISSIVES emissives.push_back(¶ms); +#else +// install glow-accumulating blend mode + gGL.blendFunc(LLRender::BF_ZERO, LLRender::BF_ONE, // don't touch color + LLRender::BF_ONE, LLRender::BF_ONE); // add to alpha (glow) + + emissive_shader->bind(); + + params.mVertexBuffer->setBuffer((mask & ~LLVertexBuffer::MAP_COLOR) | LLVertexBuffer::MAP_EMISSIVE); + + // do the actual drawing, again + params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); + gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); + + // restore our alpha blend mode + gGL.blendFunc(mColorSFactor, mColorDFactor, mAlphaSFactor, mAlphaDFactor); + + current_shader->bind(); +#endif } if (tex_setup) @@ -766,9 +813,13 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) } } +#if BATCH_FULLBRIGHTS renderFullbrights(mask, fullbrights); - renderEmissives(mask, emissives); +#endif +#if BATCH_EMISSIVES + renderEmissives(mask, emissives); +#endif if (current_shader) { current_shader->bind(); -- cgit v1.2.3 From 83941a5ec67bc006092f71664d213ecfa6ccf2b8 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 15 Mar 2019 13:05:56 -0700 Subject: Restore optimizations for fullbright/emissives with changes to fix lighting breakage when they're in play. --- indra/newview/lldrawpoolalpha.cpp | 74 ++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 28 deletions(-) (limited to 'indra/newview/lldrawpoolalpha.cpp') diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 4c625eb684..ae050c0c1b 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -49,6 +49,10 @@ #include "llspatialpartition.h" #include "llglcommonfunc.h" +// These optimizations may induce lighting, texturing, and/or GL state bugs +#define BATCH_FULLBRIGHTS 1 +#define BATCH_EMISSIVES 1 + BOOL LLDrawPoolAlpha::sShowDebugAlpha = FALSE; static BOOL deferred_render = FALSE; @@ -558,11 +562,37 @@ void LLDrawPoolAlpha::renderMaterials(U32 mask, std::vector& materi } } +void LLDrawPoolAlpha::drawEmissive(U32 mask, LLDrawInfo* draw) +{ + draw->mVertexBuffer->setBuffer((mask & ~LLVertexBuffer::MAP_COLOR) | LLVertexBuffer::MAP_EMISSIVE); + draw->mVertexBuffer->drawRange(draw->mDrawMode, draw->mStart, draw->mEnd, draw->mCount, draw->mOffset); + gPipeline.addTrianglesDrawn(draw->mCount, draw->mDrawMode); +} + +void LLDrawPoolAlpha::drawEmissiveInline(U32 mask, LLDrawInfo* draw) +{ + // install glow-accumulating blend mode + gGL.blendFunc( + LLRender::BF_ZERO, LLRender::BF_ONE, // don't touch color + LLRender::BF_ONE, LLRender::BF_ONE); // add to alpha (glow) + + emissive_shader->bind(); + + drawEmissive(mask, draw); + + // restore our alpha blend mode + gGL.blendFunc(mColorSFactor, mColorDFactor, mAlphaSFactor, mAlphaDFactor); + + current_shader->bind(); +} + void LLDrawPoolAlpha::renderEmissives(U32 mask, std::vector& emissives) { emissive_shader->bind(); emissive_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, 1.f); + gPipeline.enableLightsDynamic(); + // install glow-accumulating blend mode // don't touch color, add to alpha (glow) gGL.blendFunc(LLRender::BF_ZERO, LLRender::BF_ONE, LLRender::BF_ONE, LLRender::BF_ONE); @@ -570,7 +600,7 @@ void LLDrawPoolAlpha::renderEmissives(U32 mask, std::vector& emissi for (LLDrawInfo* draw : emissives) { bool tex_setup = TexSetup(draw, use_shaders, false, emissive_shader); - Draw(draw, (mask & ~LLVertexBuffer::MAP_COLOR) | LLVertexBuffer::MAP_EMISSIVE); + drawEmissive(mask, draw); RestoreTexSetup(tex_setup); } @@ -641,13 +671,13 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) } } -#if BATCH_FULLBRIGHTS + #if BATCH_FULLBRIGHTS if (params.mFullbright) { fullbrights.push_back(¶ms); continue; } -#endif + #endif LLRenderPass::applyModelMatrix(params); @@ -782,26 +812,11 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) params.mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE)) { LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_EMISSIVE); -#if BATCH_EMISSIVES + #if BATCH_EMISSIVES emissives.push_back(¶ms); -#else -// install glow-accumulating blend mode - gGL.blendFunc(LLRender::BF_ZERO, LLRender::BF_ONE, // don't touch color - LLRender::BF_ONE, LLRender::BF_ONE); // add to alpha (glow) - - emissive_shader->bind(); - - params.mVertexBuffer->setBuffer((mask & ~LLVertexBuffer::MAP_COLOR) | LLVertexBuffer::MAP_EMISSIVE); - - // do the actual drawing, again - params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); - gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); - - // restore our alpha blend mode - gGL.blendFunc(mColorSFactor, mColorDFactor, mAlphaSFactor, mAlphaDFactor); - - current_shader->bind(); -#endif + #else + drawEmissiveInline(mask, ¶ms); + #endif } if (tex_setup) @@ -813,13 +828,16 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) } } -#if BATCH_FULLBRIGHTS - renderFullbrights(mask, fullbrights); -#endif + #if BATCH_FULLBRIGHTS + light_enabled = false; + renderFullbrights(mask, fullbrights); + #endif + + #if BATCH_EMISSIVES + light_enabled = true; + renderEmissives(mask, emissives); + #endif -#if BATCH_EMISSIVES - renderEmissives(mask, emissives); -#endif if (current_shader) { current_shader->bind(); -- cgit v1.2.3 From d5f3e7f28e5ce0f7f1af611759a743c511e250c9 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 15 Mar 2019 14:09:23 -0700 Subject: Disable optimizations to batch fullbright and emissive draws together to minimize GL blend state changes. --- indra/newview/lldrawpoolalpha.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/lldrawpoolalpha.cpp') diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index ae050c0c1b..9f65a70a86 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -49,9 +49,9 @@ #include "llspatialpartition.h" #include "llglcommonfunc.h" -// These optimizations may induce lighting, texturing, and/or GL state bugs -#define BATCH_FULLBRIGHTS 1 -#define BATCH_EMISSIVES 1 +// These optimizations can and will induce lighting, texturing, and/or GL state bugs +#define BATCH_FULLBRIGHTS 0 +#define BATCH_EMISSIVES 0 BOOL LLDrawPoolAlpha::sShowDebugAlpha = FALSE; -- cgit v1.2.3 From 69f5ab9004124a58e202425ab253a119e8e63e4b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 15 Mar 2019 14:31:32 -0700 Subject: Make alpha drawpool optimizations an opt-in render debug setting for the adventurous. --- indra/newview/lldrawpoolalpha.cpp | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'indra/newview/lldrawpoolalpha.cpp') diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 9f65a70a86..2efa208017 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -49,10 +49,6 @@ #include "llspatialpartition.h" #include "llglcommonfunc.h" -// These optimizations can and will induce lighting, texturing, and/or GL state bugs -#define BATCH_FULLBRIGHTS 0 -#define BATCH_EMISSIVES 0 - BOOL LLDrawPoolAlpha::sShowDebugAlpha = FALSE; static BOOL deferred_render = FALSE; @@ -612,6 +608,8 @@ void LLDrawPoolAlpha::renderEmissives(U32 mask, std::vector& emissi void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) { + BOOL batch_fullbrights = gSavedSettings.getBOOL("RenderAlphaBatchFullbrights"); + BOOL batch_emissives = gSavedSettings.getBOOL("RenderAlphaBatchEmissives"); BOOL initialized_lighting = FALSE; BOOL light_enabled = TRUE; @@ -671,13 +669,11 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) } } - #if BATCH_FULLBRIGHTS - if (params.mFullbright) + if (params.mFullbright && batch_fullbrights) { fullbrights.push_back(¶ms); continue; } - #endif LLRenderPass::applyModelMatrix(params); @@ -812,11 +808,15 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) params.mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE)) { LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_EMISSIVE); - #if BATCH_EMISSIVES - emissives.push_back(¶ms); - #else - drawEmissiveInline(mask, ¶ms); - #endif + + if (batch_emissives) + { + emissives.push_back(¶ms); + } + else + { + drawEmissiveInline(mask, ¶ms); + } } if (tex_setup) @@ -828,15 +828,17 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) } } - #if BATCH_FULLBRIGHTS + if (batch_fullbrights) + { light_enabled = false; renderFullbrights(mask, fullbrights); - #endif + } - #if BATCH_EMISSIVES + if (batch_emissives) + { light_enabled = true; renderEmissives(mask, emissives); - #endif + } if (current_shader) { -- cgit v1.2.3 From 2d514e4b10025dc37c20db7db821e621dcdcaaf1 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 19 Mar 2019 17:24:16 -0700 Subject: SL-10763 Fix broken logic for alpha drawpool when rendering with basic shaders off. Force unbind of 2nd tex unit that we use during water rendering. --- indra/newview/lldrawpoolalpha.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/newview/lldrawpoolalpha.cpp') diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 2efa208017..9d80853ba3 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -388,7 +388,7 @@ bool LLDrawPoolAlpha::TexSetup(LLDrawInfo* draw, bool use_shaders, bool use_mate bool tex_setup = false; - if (use_shaders && use_material && current_shader) + if (deferred_render && use_material && current_shader) { LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_DEFERRED_TEX_BINDS); if (draw->mNormalMap) @@ -766,7 +766,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) F32 brightness = 1.0f; // We have a material. Supply the appropriate data here. - if (use_shaders && mat && LLPipeline::sRenderDeferred) + if (use_shaders && mat && deferred_render) { spec_color = params.mSpecColor; env_intensity = params.mEnvIntensity; @@ -785,7 +785,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) params.mGroup->rebuildMesh(); } - bool tex_setup = TexSetup(¶ms, use_shaders, mat != nullptr, current_shader); + bool tex_setup = TexSetup(¶ms, use_shaders, use_shaders && (mat != nullptr), current_shader); { LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_PUSH); @@ -802,7 +802,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) } } - // If this alpha mesh has glow, then draw it a second time to add the destination-alpha (=glow). Interleaving these state-changing calls could be expensive, but glow must be drawn Z-sorted with alpha. + // If this alpha mesh has glow, then draw it a second time to add the destination-alpha (=glow). Interleaving these state-changing calls is expensive, but glow must be drawn Z-sorted with alpha. if (current_shader && draw_glow_for_this_partition && params.mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE)) -- cgit v1.2.3 From 58f7b981bdb415311f23dfffc39e7a841b3017a0 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 31 May 2019 13:47:44 -0700 Subject: SL-11337 Fix handling of ambient (was getting reset to 1,1,1,1 unintentionally). Modify shaders to balance ambient across render modes again. --- indra/newview/lldrawpoolalpha.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/lldrawpoolalpha.cpp') diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 9d80853ba3..d671a5968f 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -300,7 +300,7 @@ void LLDrawPoolAlpha::render(S32 pass) } else { - gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); + gPipeline.enableLightsFullbright(); } gGL.diffuseColor4f(1,0,0,1); @@ -487,7 +487,7 @@ void LLDrawPoolAlpha::renderSimples(U32 mask, std::vector& simples) void LLDrawPoolAlpha::renderFullbrights(U32 mask, std::vector& fullbrights) { - gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); + gPipeline.enableLightsFullbright(); fullbright_shader->bind(); fullbright_shader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, 1.0f); bool use_shaders = gPipeline.canUseVertexShaders(); @@ -698,7 +698,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) } else { - gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); + gPipeline.enableLightsFullbright(); } light_enabled = FALSE; } -- cgit v1.2.3 From 7f24395889832c9ce51bae69054c7d081d77f65a Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 19 Jun 2019 08:31:43 -0700 Subject: SL-11318 Make alpha pass start with no shader bound. Make diffuse mode alpha-blended fullbrights get into alpha pass properly. --- indra/newview/lldrawpoolalpha.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'indra/newview/lldrawpoolalpha.cpp') diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index d671a5968f..da0467315f 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -226,6 +226,9 @@ void LLDrawPoolAlpha::beginRenderPass(S32 pass) } } gPipeline.enableLightsDynamic(); + + LLGLSLShader::bindNoShader(); + current_shader = NULL; } void LLDrawPoolAlpha::endRenderPass( S32 pass ) -- cgit v1.2.3