summaryrefslogtreecommitdiff
path: root/indra/newview
diff options
context:
space:
mode:
authorDave Parks <davep@lindenlab.com>2021-10-19 02:26:41 +0000
committerDave Parks <davep@lindenlab.com>2021-10-19 02:26:41 +0000
commitd2dce17803a545378407d6b7c62fdcd3007a92bc (patch)
treeefc7f17fb435b7dca9fc6a9438848bb2ce8724ab /indra/newview
parent02f813d17bcf4592f6425e207e9fe487275b9354 (diff)
SL-16197 Optimize LLEnvironment handling of shader uniforms. Instrument LLSD. Enable Fast Timers when Tracy is enabled to catch Fast Timer overhead.
Diffstat (limited to 'indra/newview')
-rw-r--r--indra/newview/lldrawpoolbump.cpp1
-rw-r--r--indra/newview/lldrawpoolterrain.cpp2
-rw-r--r--indra/newview/lldrawpoolwlsky.cpp6
-rw-r--r--indra/newview/llenvironment.cpp39
-rw-r--r--indra/newview/llenvironment.h18
-rw-r--r--indra/newview/llsettingsvo.cpp68
-rw-r--r--indra/newview/llsettingsvo.h4
-rw-r--r--indra/newview/pipeline.cpp2
8 files changed, 83 insertions, 57 deletions
diff --git a/indra/newview/lldrawpoolbump.cpp b/indra/newview/lldrawpoolbump.cpp
index f316d121ab..d75884cc16 100644
--- a/indra/newview/lldrawpoolbump.cpp
+++ b/indra/newview/lldrawpoolbump.cpp
@@ -1062,6 +1062,7 @@ void LLBumpImageList::updateImages()
// Note: the caller SHOULD NOT keep the pointer that this function returns. It may be updated as more data arrives.
LLViewerTexture* LLBumpImageList::getBrightnessDarknessImage(LLViewerFetchedTexture* src_image, U8 bump_code )
{
+ LL_PROFILE_ZONE_SCOPED;
llassert( (bump_code == BE_BRIGHTNESS) || (bump_code == BE_DARKNESS) );
LLViewerTexture* bump = NULL;
diff --git a/indra/newview/lldrawpoolterrain.cpp b/indra/newview/lldrawpoolterrain.cpp
index 37dc80e2b7..34a8b6b2cc 100644
--- a/indra/newview/lldrawpoolterrain.cpp
+++ b/indra/newview/lldrawpoolterrain.cpp
@@ -343,8 +343,6 @@ void LLDrawPoolTerrain::renderFullShader()
LLSettingsWater::ptr_t pwater = LLEnvironment::instance().getCurrentWater();
- ((LLSettingsVOWater*)pwater.get())->updateShader(shader);
-
//
// detail texture 1
//
diff --git a/indra/newview/lldrawpoolwlsky.cpp b/indra/newview/lldrawpoolwlsky.cpp
index 0c3d8f3098..8c8dc3f3d2 100644
--- a/indra/newview/lldrawpoolwlsky.cpp
+++ b/indra/newview/lldrawpoolwlsky.cpp
@@ -182,8 +182,6 @@ void LLDrawPoolWLSky::renderSkyHazeDeferred(const LLVector3& camPosLocal, F32 ca
sky_shader->bindTexture(LLShaderMgr::RAINBOW_MAP, rainbow_tex);
sky_shader->bindTexture(LLShaderMgr::HALO_MAP, halo_tex);
- ((LLSettingsVOSky*)psky.get())->updateShader(sky_shader);
-
F32 moisture_level = (float)psky->getSkyMoistureLevel();
F32 droplet_radius = (float)psky->getSkyDropletRadius();
F32 ice_level = (float)psky->getSkyIceLevel();
@@ -406,8 +404,6 @@ void LLDrawPoolWLSky::renderSkyCloudsDeferred(const LLVector3& camPosLocal, F32
cloudshader->uniform1f(LLShaderMgr::CLOUD_VARIANCE, cloud_variance);
cloudshader->uniform1f(LLShaderMgr::SUN_MOON_GLOW_FACTOR, psky->getSunMoonGlowFactor());
- ((LLSettingsVOSky*)psky.get())->updateShader(cloudshader);
-
/// Render the skydome
renderDome(camPosLocal, camHeightLocal, cloudshader);
@@ -462,8 +458,6 @@ void LLDrawPoolWLSky::renderSkyClouds(const LLVector3& camPosLocal, F32 camHeigh
cloudshader->uniform1f(LLShaderMgr::CLOUD_VARIANCE, cloud_variance);
cloudshader->uniform1f(LLShaderMgr::SUN_MOON_GLOW_FACTOR, psky->getSunMoonGlowFactor());
- ((LLSettingsVOSky*)psky.get())->updateShader(cloudshader);
-
/// Render the skydome
renderDome(camPosLocal, camHeightLocal, cloudshader);
diff --git a/indra/newview/llenvironment.cpp b/indra/newview/llenvironment.cpp
index 8881d11802..69d3075928 100644
--- a/indra/newview/llenvironment.cpp
+++ b/indra/newview/llenvironment.cpp
@@ -1471,6 +1471,7 @@ LLEnvironment::DayInstance::ptr_t LLEnvironment::getSharedEnvironmentInstance()
void LLEnvironment::updateEnvironment(LLSettingsBase::Seconds transition, bool forced)
{
+ LL_PROFILE_ZONE_SCOPED;
DayInstance::ptr_t pinstance = getSelectedEnvironmentInstance();
if ((mCurrentEnvironment != pinstance) || forced)
@@ -1488,6 +1489,8 @@ void LLEnvironment::updateEnvironment(LLSettingsBase::Seconds transition, bool f
{
mCurrentEnvironment = pinstance;
}
+
+ updateSettingsUniforms();
}
}
@@ -1614,6 +1617,8 @@ void LLEnvironment::update(const LLViewerCamera * cam)
stop_glerror();
+ updateSettingsUniforms();
+
// *TODO: potential optimization - this block may only need to be
// executed some of the time. For example for water shaders only.
{
@@ -1648,10 +1653,16 @@ void LLEnvironment::updateCloudScroll()
}
// static
-void LLEnvironment::updateGLVariablesForSettings(LLGLSLShader *shader, const LLSettingsBase::ptr_t &psetting)
+void LLEnvironment::updateGLVariablesForSettings(LLShaderUniforms* uniforms, const LLSettingsBase::ptr_t &psetting)
{
LL_RECORD_BLOCK_TIME(FTM_SHADER_PARAM_UPDATE);
+ for (int i = 0; i < LLGLSLShader::SG_COUNT; ++i)
+ {
+ uniforms[i].clear();
+ }
+
+ LLShaderUniforms* shader = &uniforms[LLGLSLShader::SG_ANY];
//_WARNS("RIDER") << "----------------------------------------------------------------" << LL_ENDL;
LLSettingsBase::parammapping_t params = psetting->getParameterMap();
for (auto &it: params)
@@ -1694,7 +1705,7 @@ void LLEnvironment::updateGLVariablesForSettings(LLGLSLShader *shader, const LLS
{
LLVector4 vect4(value);
//_WARNS("RIDER") << "pushing '" << (*it).first << "' as " << vect4 << LL_ENDL;
- shader->uniform4fv(it.second.getShaderKey(), 1, vect4.mV);
+ shader->uniform4fv(it.second.getShaderKey(), vect4 );
break;
}
@@ -1707,17 +1718,30 @@ void LLEnvironment::updateGLVariablesForSettings(LLGLSLShader *shader, const LLS
default:
break;
}
- stop_glerror();
}
//_WARNS("RIDER") << "----------------------------------------------------------------" << LL_ENDL;
- psetting->applySpecial(shader);
+ psetting->applySpecial(uniforms);
+}
+
+void LLEnvironment::updateShaderUniforms(LLGLSLShader* shader)
+{
+ LL_PROFILE_ZONE_SCOPED;
+
+ // apply uniforms that should be applied to all shaders
+ mSkyUniforms[LLGLSLShader::SG_ANY].apply(shader);
+ mWaterUniforms[LLGLSLShader::SG_ANY].apply(shader);
+
+ // apply uniforms specific to the given shader's shader group
+ auto group = shader->mShaderGroup;
+ mSkyUniforms[group].apply(shader);
+ mWaterUniforms[group].apply(shader);
}
-void LLEnvironment::updateShaderUniforms(LLGLSLShader *shader)
+void LLEnvironment::updateSettingsUniforms()
{
- updateGLVariablesForSettings(shader, mCurrentEnvironment->getWater());
- updateGLVariablesForSettings(shader, mCurrentEnvironment->getSky());
+ updateGLVariablesForSettings(mWaterUniforms, mCurrentEnvironment->getWater());
+ updateGLVariablesForSettings(mSkyUniforms, mCurrentEnvironment->getSky());
}
void LLEnvironment::recordEnvironment(S32 parcel_id, LLEnvironment::EnvironmentInfo::ptr_t envinfo, LLSettingsBase::Seconds transition)
@@ -2618,6 +2642,7 @@ LLEnvironment::DayInstance::ptr_t LLEnvironment::DayInstance::clone() const
bool LLEnvironment::DayInstance::applyTimeDelta(const LLSettingsBase::Seconds& delta)
{
+ LL_PROFILE_ZONE_SCOPED;
ptr_t keeper(shared_from_this()); // makes sure that this does not go away while it is being worked on.
bool changed(false);
diff --git a/indra/newview/llenvironment.h b/indra/newview/llenvironment.h
index 7cbf2d25bb..3568fbcfd1 100644
--- a/indra/newview/llenvironment.h
+++ b/indra/newview/llenvironment.h
@@ -38,11 +38,12 @@
#include "llatmosphere.h"
+#include "llglslshader.h"
+
#include <boost/signals2.hpp>
//-------------------------------------------------------------------------
class LLViewerCamera;
-class LLGLSLShader;
class LLParcel;
//-------------------------------------------------------------------------
@@ -50,8 +51,8 @@ class LLEnvironment : public LLSingleton<LLEnvironment>
{
LLSINGLETON_C11(LLEnvironment);
LOG_CLASS(LLEnvironment);
-
public:
+
static const F64Seconds TRANSITION_INSTANT;
static const F64Seconds TRANSITION_FAST;
static const F64Seconds TRANSITION_DEFAULT;
@@ -131,9 +132,14 @@ public:
void update(const LLViewerCamera * cam);
- static void updateGLVariablesForSettings(LLGLSLShader *shader, const LLSettingsBase::ptr_t &psetting);
+ static void updateGLVariablesForSettings(LLShaderUniforms* uniforms, const LLSettingsBase::ptr_t &psetting);
+
+ // apply current sky settings to given shader
void updateShaderUniforms(LLGLSLShader *shader);
+ // prepare settings to be applied to shaders (call whenever settings are updated)
+ void updateSettingsUniforms();
+
void setSelectedEnvironment(EnvSelection_t env, LLSettingsBase::Seconds transition = TRANSITION_DEFAULT, bool forced = false);
EnvSelection_t getSelectedEnvironment() const { return mSelectedEnvironment; }
@@ -234,6 +240,11 @@ public:
void handleEnvironmentPush(LLSD &message);
+ //cached uniform values from LLSD values
+ LLShaderUniforms mWaterUniforms[LLGLSLShader::SG_COUNT];
+ LLShaderUniforms mSkyUniforms[LLGLSLShader::SG_COUNT];
+ // =======================================================================================
+
class DayInstance: public std::enable_shared_from_this<DayInstance>
{
public:
@@ -288,6 +299,7 @@ public:
LLSettingsDay::ptr_t mDayCycle;
LLSettingsSky::ptr_t mSky;
LLSettingsWater::ptr_t mWater;
+
S32 mSkyTrack;
bool mInitialized;
diff --git a/indra/newview/llsettingsvo.cpp b/indra/newview/llsettingsvo.cpp
index 1e5b893cbc..6a88a8ef2c 100644
--- a/indra/newview/llsettingsvo.cpp
+++ b/indra/newview/llsettingsvo.cpp
@@ -637,6 +637,7 @@ LLSD LLSettingsVOSky::convertToLegacy(const LLSettingsSky::ptr_t &psky, bool isA
//-------------------------------------------------------------------------
void LLSettingsVOSky::updateSettings()
{
+ LL_PROFILE_ZONE_SCOPED;
LLSettingsSky::updateSettings();
LLVector3 sun_direction = getSunDirection();
LLVector3 moon_direction = getMoonDirection();
@@ -665,55 +666,55 @@ void LLSettingsVOSky::updateSettings()
void LLSettingsVOSky::applySpecial(void *ptarget, bool force)
{
- LLGLSLShader *shader = (LLGLSLShader *)ptarget;
-
LLVector4 light_direction = LLEnvironment::instance().getClampedLightNorm();
- if (shader->mShaderGroup == LLGLSLShader::SG_DEFAULT)
+ LLShaderUniforms* shader = &((LLShaderUniforms*)ptarget)[LLGLSLShader::SG_DEFAULT];
{
- shader->uniform4fv(LLViewerShaderMgr::LIGHTNORM, 1, light_direction.mV);
- shader->uniform3fv(LLShaderMgr::WL_CAMPOSLOCAL, 1, LLViewerCamera::getInstance()->getOrigin().mV);
+ shader->uniform4fv(LLViewerShaderMgr::LIGHTNORM, light_direction);
+ shader->uniform3fv(LLShaderMgr::WL_CAMPOSLOCAL, LLViewerCamera::getInstance()->getOrigin());
}
- else if (shader->mShaderGroup == LLGLSLShader::SG_SKY)
+
+ shader = &((LLShaderUniforms*)ptarget)[LLGLSLShader::SG_SKY];
{
- shader->uniform4fv(LLViewerShaderMgr::LIGHTNORM, 1, light_direction.mV);
+ shader->uniform4fv(LLViewerShaderMgr::LIGHTNORM, light_direction);
- // Legacy? SETTING_CLOUD_SCROLL_RATE("cloud_scroll_rate")
- LLVector4 vect_c_p_d1(mSettings[SETTING_CLOUD_POS_DENSITY1]);
- LLVector4 cloud_scroll( LLEnvironment::instance().getCloudScrollDelta() );
+ // Legacy? SETTING_CLOUD_SCROLL_RATE("cloud_scroll_rate")
+ LLVector4 vect_c_p_d1(mSettings[SETTING_CLOUD_POS_DENSITY1]);
+ LLVector4 cloud_scroll( LLEnvironment::instance().getCloudScrollDelta() );
- // SL-13084 EEP added support for custom cloud textures -- flip them horizontally to match the preview of Clouds > Cloud Scroll
- // Keep in Sync!
- // * indra\newview\llsettingsvo.cpp
- // * indra\newview\app_settings\shaders\class2\windlight\cloudsV.glsl
- // * indra\newview\app_settings\shaders\class1\deferred\cloudsV.glsl
- cloud_scroll[0] = -cloud_scroll[0];
- vect_c_p_d1 += cloud_scroll;
- shader->uniform4fv(LLShaderMgr::CLOUD_POS_DENSITY1, 1, vect_c_p_d1.mV);
+ // SL-13084 EEP added support for custom cloud textures -- flip them horizontally to match the preview of Clouds > Cloud Scroll
+ // Keep in Sync!
+ // * indra\newview\llsettingsvo.cpp
+ // * indra\newview\app_settings\shaders\class2\windlight\cloudsV.glsl
+ // * indra\newview\app_settings\shaders\class1\deferred\cloudsV.glsl
+ cloud_scroll[0] = -cloud_scroll[0];
+ vect_c_p_d1 += cloud_scroll;
+ shader->uniform4fv(LLShaderMgr::CLOUD_POS_DENSITY1, vect_c_p_d1);
- LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
+ LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
- LLColor4 sunDiffuse = psky->getSunlightColor();
- LLColor4 moonDiffuse = psky->getMoonlightColor();
+ LLVector4 sunDiffuse = LLVector4(psky->getSunlightColor().mV);
+ LLVector4 moonDiffuse = LLVector4(psky->getMoonlightColor().mV);
- shader->uniform4fv(LLShaderMgr::SUNLIGHT_COLOR, 1, sunDiffuse.mV);
- shader->uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, moonDiffuse.mV);
+ shader->uniform4fv(LLShaderMgr::SUNLIGHT_COLOR, sunDiffuse);
+ shader->uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, moonDiffuse);
- LLColor4 cloud_color(psky->getCloudColor(), 1.0);
- shader->uniform4fv(LLShaderMgr::CLOUD_COLOR, 1, cloud_color.mV);
+ LLVector4 cloud_color(LLVector3(psky->getCloudColor().mV), 1.0);
+ shader->uniform4fv(LLShaderMgr::CLOUD_COLOR, cloud_color);
}
+ shader = &((LLShaderUniforms*)ptarget)[LLGLSLShader::SG_ANY];
shader->uniform1f(LLShaderMgr::SCENE_LIGHT_STRENGTH, mSceneLightStrength);
LLColor4 ambient(getTotalAmbient());
- shader->uniform4fv(LLShaderMgr::AMBIENT, 1, ambient.mV);
+ shader->uniform4fv(LLShaderMgr::AMBIENT, LLVector4(ambient.mV));
shader->uniform1i(LLShaderMgr::SUN_UP_FACTOR, getIsSunUp() ? 1 : 0);
shader->uniform1f(LLShaderMgr::SUN_MOON_GLOW_FACTOR, getSunMoonGlowFactor());
shader->uniform1f(LLShaderMgr::DENSITY_MULTIPLIER, getDensityMultiplier());
shader->uniform1f(LLShaderMgr::DISTANCE_MULTIPLIER, getDistanceMultiplier());
- F32 g = getGamma();
+ F32 g = getGamma();
F32 display_gamma = gSavedSettings.getF32("RenderDeferredDisplayGamma");
shader->uniform1f(LLShaderMgr::GAMMA, g);
@@ -907,11 +908,11 @@ LLSD LLSettingsVOWater::convertToLegacy(const LLSettingsWater::ptr_t &pwater)
//-------------------------------------------------------------------------
void LLSettingsVOWater::applySpecial(void *ptarget, bool force)
{
- LLGLSLShader *shader = (LLGLSLShader *)ptarget;
-
LLEnvironment& env = LLEnvironment::instance();
- if (force || (shader->mShaderGroup == LLGLSLShader::SG_WATER))
+ auto group = LLGLSLShader::SG_WATER;
+ LLShaderUniforms* shader = &((LLShaderUniforms*)ptarget)[group];
+
{
F32 water_height = env.getWaterHeight();
@@ -935,7 +936,7 @@ void LLSettingsVOWater::applySpecial(void *ptarget, bool force)
LLVector4 waterPlane(enorm.v[0], enorm.v[1], enorm.v[2], -ep.dot(enorm));
- shader->uniform4fv(LLShaderMgr::WATER_WATERPLANE, 1, waterPlane.mV);
+ shader->uniform4fv(LLShaderMgr::WATER_WATERPLANE, waterPlane.mV);
LLVector4 light_direction = env.getClampedLightNorm();
@@ -950,18 +951,19 @@ void LLSettingsVOWater::applySpecial(void *ptarget, bool force)
shader->uniform1f(LLShaderMgr::WATER_FOGDENSITY, waterFogDensity);
LLColor4 fog_color(env.getCurrentWater()->getWaterFogColor(), 0.0f);
- shader->uniform4fv(LLShaderMgr::WATER_FOGCOLOR, 1, fog_color.mV);
+ shader->uniform4fv(LLShaderMgr::WATER_FOGCOLOR, fog_color.mV);
F32 blend_factor = env.getCurrentWater()->getBlendFactor();
shader->uniform1f(LLShaderMgr::BLEND_FACTOR, blend_factor);
// update to normal lightnorm, water shader itself will use rotated lightnorm as necessary
- shader->uniform4fv(LLShaderMgr::LIGHTNORM, 1, light_direction.mV);
+ shader->uniform4fv(LLShaderMgr::LIGHTNORM, light_direction.mV);
}
}
void LLSettingsVOWater::updateSettings()
{
+ LL_PROFILE_ZONE_SCOPED;
// base class clears dirty flag so as to not trigger recursive update
LLSettingsBase::updateSettings();
diff --git a/indra/newview/llsettingsvo.h b/indra/newview/llsettingsvo.h
index 65136ad2f5..caa3ac18d3 100644
--- a/indra/newview/llsettingsvo.h
+++ b/indra/newview/llsettingsvo.h
@@ -102,8 +102,6 @@ public:
bool isAdvanced() const { return m_isAdvanced; }
- virtual void updateShader(LLGLSLShader* shader) { applySpecial(shader, true); }
-
protected:
LLSettingsVOSky();
@@ -136,8 +134,6 @@ public:
static LLSD convertToLegacy(const ptr_t &);
- virtual void updateShader(LLGLSLShader* shader) { applySpecial(shader, true); }
-
protected:
LLSettingsVOWater();
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index 5ef3819de4..c4976c4bbc 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -8427,8 +8427,6 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* light_
LLEnvironment& environment = LLEnvironment::instance();
LLSettingsSky::ptr_t sky = environment.getCurrentSky();
-
- static_cast<LLSettingsVOSky*>(sky.get())->updateShader(&shader);
}
LLColor3 pow3f(LLColor3 v, F32 f)