diff options
author | cosmic-linden <111533034+cosmic-linden@users.noreply.github.com> | 2024-09-27 12:23:11 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-27 12:23:11 -0700 |
commit | 9e8cf72a355d5353564c0199990a6b5073f37fca (patch) | |
tree | 72b428f1ef946005c26e9479c459b6bcfe834d40 | |
parent | 199ace7e91431cc7198910ed48a9d45f8b5330d1 (diff) | |
parent | f6aca1044e2b8ab6d8bad9552355d92a91ca4991 (diff) |
Merge pull request #2713 from secondlife/v-2638
Don't clear big render target if all pixels will be replaced
-rw-r--r-- | indra/llrender/llrendertarget.cpp | 9 | ||||
-rw-r--r-- | indra/llrender/llrendertarget.h | 9 | ||||
-rw-r--r-- | indra/newview/app_settings/settings.xml | 11 | ||||
-rw-r--r-- | indra/newview/llviewerobject.cpp | 3 | ||||
-rw-r--r-- | indra/newview/pipeline.cpp | 24 |
5 files changed, 38 insertions, 18 deletions
diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index 38bc5ff331..c72f8fa2ba 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -51,6 +51,7 @@ void check_framebuffer_status() } bool LLRenderTarget::sUseFBO = false; +bool LLRenderTarget::sClearOnInvalidate = false; U32 LLRenderTarget::sCurFBO = 0; @@ -473,6 +474,13 @@ void LLRenderTarget::clear(U32 mask_in) } } +void LLRenderTarget::invalidate(U32 mask_in) +{ + LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY; + if (!sClearOnInvalidate) { return; } + clear(mask_in); +} + U32 LLRenderTarget::getTexture(U32 attachment) const { if (attachment >= mTex.size()) @@ -584,7 +592,6 @@ void LLRenderTarget::swapFBORefs(LLRenderTarget& other) llassert(!other.isBoundInStack()); // Must be same type - llassert(sUseFBO == other.sUseFBO); llassert(mResX == other.mResX); llassert(mResY == other.mResY); llassert(mInternalFormat == other.mInternalFormat); diff --git a/indra/llrender/llrendertarget.h b/indra/llrender/llrendertarget.h index cd3290cf66..f066534cf4 100644 --- a/indra/llrender/llrendertarget.h +++ b/indra/llrender/llrendertarget.h @@ -63,6 +63,7 @@ class LLRenderTarget public: // Whether or not to use FBO implementation static bool sUseFBO; + static bool sClearOnInvalidate; static U32 sBytesAllocated; static U32 sCurFBO; static U32 sCurResX; @@ -128,11 +129,17 @@ public: // Asserts that this target is not currently bound in the stack void bindTarget(); - //clear render targer, clears depth buffer if present, + //clear render target, clears depth buffer if present, //uses scissor rect if in copy-to-texture mode // asserts that this target is currently bound void clear(U32 mask = 0xFFFFFFFF); + //same as clear, except may be a no-op depending on configuration + //useful to indicate the buffer is about to be overwritten and we + //don't care about its previous contents + //depending on the GPU, one may be more expensive than the other + void invalidate(U32 mask = 0xFFFFFFFF); + //get applied viewport void getViewport(S32* viewport); diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index 6fe13d4665..ce6d9148c6 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -7413,6 +7413,17 @@ <key>Value</key> <integer>-1</integer> </map> + <key>RenderBufferClearOnInvalidate</key> + <map> + <key>Comment</key> + <string>Whether to call glClear on render buffers that will be fully overwritten with new contents</string> + <key>Persist</key> + <integer>1</integer> + <key>Type</key> + <string>Boolean</string> + <key>Value</key> + <integer>0</integer> + </map> <key>RenderCompressTextures</key> <map> <key>Comment</key> diff --git a/indra/newview/llviewerobject.cpp b/indra/newview/llviewerobject.cpp index 6456c98093..7741f1fbe7 100644 --- a/indra/newview/llviewerobject.cpp +++ b/indra/newview/llviewerobject.cpp @@ -5241,8 +5241,7 @@ void LLViewerObject::updateTEMaterialTextures(U8 te) LLUUID mat_id = getRenderMaterialID(te); if (mat == nullptr && mat_id.notNull()) { - mat = (LLFetchedGLTFMaterial*) gGLTFMaterialList.getMaterial(mat_id); - llassert(mat == nullptr || dynamic_cast<LLFetchedGLTFMaterial*>(gGLTFMaterialList.getMaterial(mat_id)) != nullptr); + mat = gGLTFMaterialList.getMaterial(mat_id); if (mat->isFetching()) { // material is not loaded yet, rebuild draw info when the object finishes loading mat->onMaterialComplete([id=getID()] diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 3a811f893e..eb353beb11 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -576,6 +576,7 @@ void LLPipeline::init() connectRefreshCachedSettingsSafe("RenderScreenSpaceReflectionAdaptiveStepMultiplier"); connectRefreshCachedSettingsSafe("RenderScreenSpaceReflectionGlossySamples"); connectRefreshCachedSettingsSafe("RenderBufferVisualization"); + connectRefreshCachedSettingsSafe("RenderBufferClearOnInvalidate"); connectRefreshCachedSettingsSafe("RenderMirrors"); connectRefreshCachedSettingsSafe("RenderHeroProbeUpdateRate"); connectRefreshCachedSettingsSafe("RenderHeroProbeConservativeUpdateMultiplier"); @@ -1084,6 +1085,7 @@ void LLPipeline::refreshCachedSettings() RenderScreenSpaceReflectionAdaptiveStepMultiplier = gSavedSettings.getF32("RenderScreenSpaceReflectionAdaptiveStepMultiplier"); RenderScreenSpaceReflectionGlossySamples = gSavedSettings.getS32("RenderScreenSpaceReflectionGlossySamples"); RenderBufferVisualization = gSavedSettings.getS32("RenderBufferVisualization"); + LLRenderTarget::sClearOnInvalidate = gSavedSettings.getBOOL("RenderBufferClearOnInvalidate"); RenderMirrors = gSavedSettings.getBOOL("RenderMirrors"); RenderHeroProbeUpdateRate = gSavedSettings.getS32("RenderHeroProbeUpdateRate"); RenderHeroProbeConservativeUpdateMultiplier = gSavedSettings.getS32("RenderHeroProbeConservativeUpdateMultiplier"); @@ -7147,7 +7149,7 @@ void LLPipeline::copyScreenSpaceReflections(LLRenderTarget* src, LLRenderTarget* LLRenderTarget& depth_src = mRT->deferredScreen; dst->bindTarget(); - dst->clear(); + dst->invalidate(); gCopyDepthProgram.bind(); S32 diff_map = gCopyDepthProgram.getTextureChannel(LLShaderMgr::DIFFUSE_MAP); @@ -7334,7 +7336,7 @@ void LLPipeline::applyFXAA(LLRenderTarget* src, LLRenderTarget* dst) // bake out texture2D with RGBL for FXAA shader mFXAAMap.bindTarget(); - mFXAAMap.clear(GL_COLOR_BUFFER_BIT); + mFXAAMap.invalidate(GL_COLOR_BUFFER_BIT); shader = &gGlowCombineFXAAProgram; shader->bind(); @@ -7433,6 +7435,7 @@ void LLPipeline::generateSMAABuffers(LLRenderTarget* src) LLGLSLShader& edge_shader = gSMAAEdgeDetectProgram[fsaa_quality]; dest.bindTarget(); + // SMAA utilizes discard, so the background color matters dest.clear(GL_COLOR_BUFFER_BIT); edge_shader.bind(); @@ -7476,7 +7479,7 @@ void LLPipeline::generateSMAABuffers(LLRenderTarget* src) LLGLSLShader& blend_weights_shader = gSMAABlendWeightsProgram[fsaa_quality]; dest.bindTarget(); - dest.clear(GL_COLOR_BUFFER_BIT); + dest.invalidate(GL_COLOR_BUFFER_BIT); blend_weights_shader.bind(); blend_weights_shader.uniform4fv(sSmaaRTMetrics, 1, rt_metrics); @@ -7552,7 +7555,7 @@ void LLPipeline::applySMAA(LLRenderTarget* src, LLRenderTarget* dst) LLGLSLShader& blend_shader = gSMAANeighborhoodBlendProgram[fsaa_quality]; bound_target->bindTarget(); - bound_target->clear(GL_COLOR_BUFFER_BIT); + bound_target->invalidate(GL_COLOR_BUFFER_BIT); blend_shader.bind(); blend_shader.uniform4fv(sSmaaRTMetrics, 1, rt_metrics); @@ -8330,9 +8333,7 @@ void LLPipeline::renderDeferredLighting() LLGLSLShader& sun_shader = gCubeSnapshot ? gDeferredSunProbeProgram : gDeferredSunProgram; bindDeferredShader(sun_shader, deferred_light_target); mScreenTriangleVB->setBuffer(); - glClearColor(1, 1, 1, 1); - deferred_light_target->clear(GL_COLOR_BUFFER_BIT); - glClearColor(0, 0, 0, 0); + deferred_light_target->invalidate(GL_COLOR_BUFFER_BIT); sun_shader.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, (GLfloat)deferred_light_target->getWidth(), @@ -8356,9 +8357,7 @@ void LLPipeline::renderDeferredLighting() LL_PROFILE_GPU_ZONE("soften shadow"); // blur lightmap screen_target->bindTarget(); - glClearColor(1, 1, 1, 1); - screen_target->clear(GL_COLOR_BUFFER_BIT); - glClearColor(0, 0, 0, 0); + screen_target->invalidate(GL_COLOR_BUFFER_BIT); bindDeferredShader(gDeferredBlurLightProgram); @@ -8410,11 +8409,8 @@ void LLPipeline::renderDeferredLighting() deferred_light_target->flush(); unbindDeferredShader(gDeferredBlurLightProgram); } - screen_target->bindTarget(); - // clear color buffer here - zeroing alpha (glow) is important or it will accumulate against sky - glClearColor(0, 0, 0, 0); - screen_target->clear(GL_COLOR_BUFFER_BIT); + screen_target->invalidate(GL_COLOR_BUFFER_BIT); if (RenderDeferredAtmospheric) { // apply sunlight contribution |