Skip to content
Snippets Groups Projects
Commit dfda8826 authored by Graham Madarasz (Graham)'s avatar Graham Madarasz (Graham)
Browse files

Make WL updates use pre-hashed strings for uniform sets

parent ae1aa461
No related branches found
No related tags found
No related merge requests found
......@@ -236,6 +236,7 @@ set(llcommon_HEADER_FILES
llstrider.h
llstring.h
llstringtable.h
llstaticstringtable.h
llsys.h
llthread.h
llthreadsafequeue.h
......
......@@ -33,7 +33,6 @@
#include "llstl.h"
#include <list>
#include <set>
#include <hash_map>
#if LL_WINDOWS
# if (_MSC_VER >= 1300 && _MSC_VER < 1400)
......@@ -43,59 +42,6 @@
//# define STRING_TABLE_HASH_MAP 1
#endif
#if STRING_TABLE_HASH_MAP
# if LL_WINDOWS
# include <hash_map>
# else
# include <ext/hash_map>
# endif
#endif
class LLStaticHashedString
{
public:
LLStaticHashedString(const std::string& s)
{
string_hash = makehash(s);
string = s;
}
const std::string& String() const { return string; }
size_t Hash() const { return string_hash; }
protected:
size_t makehash(const std::string& s)
{
size_t len = s.size();
const char* c = s.c_str();
size_t hashval = 0;
for (size_t i=0; i<len; i++)
{
hashval = ((hashval<<5) + hashval) + *c++;
}
return hashval;
}
std::string string;
size_t string_hash;
};
template<class T>
struct LLStaticStringHasher
{
enum { bucket_size = 8 };
size_t operator()(const T& key_value) const { return key_value.Hash(); }
bool operator()(const T& left, const T& right) const { return left.Hash() < right.Hash(); }
};
template< typename MappedObject >
class LL_COMMON_API LLStaticStringTable
: public std::hash_map< LLStaticHashedString , MappedObject, LLStaticStringHasher< LLStaticHashedString > >
{
};
const U32 MAX_STRINGS_LENGTH = 256;
class LL_COMMON_API LLStringTableEntry
......
......@@ -262,9 +262,9 @@ public:
// so that two threads who get into the if in parallel
// don't both attempt to the delete.
//
if (mRef == 1)
delete this;
mRef--;
if (mRef == 0)
delete this;
if (sMutex) sMutex->unlock();
return 0;
}
......
......@@ -29,6 +29,7 @@
#include "llgl.h"
#include "llrender.h"
#include "llstaticstringtable.h"
class LLShaderFeatures
{
......
......@@ -31,6 +31,7 @@
#include <fstream>
#include "llgl.h"
#include "llglheaders.h"
#include "llstaticstringtable.h"
class LLPostProcess
{
......
......@@ -33,6 +33,7 @@
#include "v4math.h"
#include "v4color.h"
#include "llviewershadermgr.h"
#include "llstringtable.h"
class LLWaterParamSet;
......@@ -47,6 +48,9 @@ public:
private:
LLSD mParamValues;
std::vector<LLStaticHashedString> mParamHashedNames;
void updateHashedNames();
public:
......@@ -140,6 +144,17 @@ inline void LLWaterParamSet::setAll(const LLSD& val)
mParamValues[mIt->first] = mIt->second;
}
}
updateHashedNames();
}
inline void LLWaterParamSet::updateHashedNames()
{
mParamHashedNames.clear();
// Iterate through values
for(LLSD::map_iterator iter = mParamValues.beginMap(); iter != mParamValues.endMap(); ++iter)
{
mParamHashedNames.push_back(LLStaticHashedString(iter->first));
}
}
inline const LLSD& LLWaterParamSet::getAll()
......
......@@ -38,6 +38,22 @@
#include <sstream>
static LLStaticHashedString sStarBrightness("star_brightness");
static LLStaticHashedString sPresetNum("preset_num");
static LLStaticHashedString sSunAngle("sun_angle");
static LLStaticHashedString sEastAngle("east_angle");
static LLStaticHashedString sEnableCloudScroll("enable_cloud_scroll");
static LLStaticHashedString sCloudScrollRate("cloud_scroll_rate");
static LLStaticHashedString sLightNorm("lightnorm");
static LLStaticHashedString sCloudDensity("cloud_pos_density1");
static LLStaticHashedString sCloudScale("cloud_scale");
static LLStaticHashedString sCloudShadow("cloud_shadow");
static LLStaticHashedString sDensityMultiplier("density_multiplier");
static LLStaticHashedString sDistanceMultiplier("distance_multiplier");
static LLStaticHashedString sHazeDensity("haze_density");
static LLStaticHashedString sHazeHorizon("haze_horizon");
static LLStaticHashedString sMaxY("max_y");
LLWLParamSet::LLWLParamSet(void) :
mName("Unnamed Preset"),
mCloudScrollXOffset(0.f), mCloudScrollYOffset(0.f)
......@@ -48,21 +64,24 @@ static LLFastTimer::DeclareTimer FTM_WL_PARAM_UPDATE("WL Param Update");
void LLWLParamSet::update(LLGLSLShader * shader) const
{
LLFastTimer t(FTM_WL_PARAM_UPDATE);
for(LLSD::map_const_iterator i = mParamValues.beginMap();
i != mParamValues.endMap();
++i)
LLSD::map_const_iterator i = mParamValues.beginMap();
std::vector<LLStaticHashedString>::const_iterator n = mParamHashedNames.begin();
for(;(i != mParamValues.endMap()) && (n != mParamHashedNames.end());++i, n++)
{
const std::string& param = i->first;
const LLStaticHashedString& param = *n;
// check that our pre-hashed names are still tracking the mParamValues map correctly
//
llassert(param.String() == i->first);
if (param == "star_brightness" || param == "preset_num" || param == "sun_angle" ||
param == "east_angle" || param == "enable_cloud_scroll" ||
param == "cloud_scroll_rate" || param == "lightnorm" )
if (param == sStarBrightness || param == sPresetNum || param == sSunAngle ||
param == sEastAngle || param == sEnableCloudScroll ||
param == sCloudScrollRate || param == sLightNorm )
{
continue;
}
if (param == "cloud_pos_density1")
if (param == sCloudDensity)
{
LLVector4 val;
val.mV[0] = F32(i->second[0].asReal()) + mCloudScrollXOffset;
......@@ -74,10 +93,10 @@ void LLWLParamSet::update(LLGLSLShader * shader) const
shader->uniform4fv(param, 1, val.mV);
stop_glerror();
}
else if (param == "cloud_scale" || param == "cloud_shadow" ||
param == "density_multiplier" || param == "distance_multiplier" ||
param == "haze_density" || param == "haze_horizon" ||
param == "max_y" )
else if (param == sCloudScale || param == sCloudShadow ||
param == sDensityMultiplier || param == sDistanceMultiplier ||
param == sHazeDensity || param == sHazeHorizon ||
param == sMaxY )
{
F32 val = (F32) i->second[0].asReal();
......@@ -378,3 +397,13 @@ void LLWLParamSet::updateCloudScrolling(void)
mCloudScrollYOffset += F32(delta_t * (getCloudScrollY() - 10.f) / 100.f);
}
}
void LLWLParamSet::updateHashedNames()
{
mParamHashedNames.clear();
// Iterate through values
for(LLSD::map_iterator iter = mParamValues.beginMap(); iter != mParamValues.endMap(); ++iter)
{
mParamHashedNames.push_back(LLStaticHashedString(iter->first));
}
}
\ No newline at end of file
......@@ -29,9 +29,11 @@
#include <string>
#include <map>
#include <vector>
#include "v4math.h"
#include "v4color.h"
#include "llstaticstringtable.h"
class LLWLParamSet;
class LLGLSLShader;
......@@ -47,9 +49,12 @@ public:
private:
LLSD mParamValues;
std::vector<LLStaticHashedString> mParamHashedNames;
float mCloudScrollXOffset, mCloudScrollYOffset;
void updateHashedNames();
public:
LLWLParamSet();
......@@ -177,6 +182,8 @@ inline void LLWLParamSet::setAll(const LLSD& val)
if(val.isMap()) {
mParamValues = val;
}
updateHashedNames();
}
inline const LLSD& LLWLParamSet::getAll()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment