forked from teamnwah/openmw-tes3coop
extern/shiny update: made caching more robust
This commit is contained in:
parent
bf037b7d29
commit
a7d910614f
5 changed files with 40 additions and 27 deletions
43
extern/shiny/Main/Factory.cpp
vendored
43
extern/shiny/Main/Factory.cpp
vendored
|
@ -191,15 +191,48 @@ namespace sh
|
|||
&mGlobalSettings);
|
||||
|
||||
int lastModified = boost::filesystem::last_write_time (boost::filesystem::path(sourceFile));
|
||||
mShadersLastModifiedNew[sourceFile] = lastModified;
|
||||
if (mShadersLastModified.find(sourceFile) != mShadersLastModified.end()
|
||||
&& mShadersLastModified[sourceFile] != lastModified)
|
||||
{
|
||||
newSet.markDirty ();
|
||||
// delete any outdated shaders based on this shader set.
|
||||
if ( boost::filesystem::exists(mPlatform->getCacheFolder())
|
||||
&& boost::filesystem::is_directory(mPlatform->getCacheFolder()))
|
||||
{
|
||||
boost::filesystem::directory_iterator end_iter;
|
||||
for( boost::filesystem::directory_iterator dir_iter(mPlatform->getCacheFolder()) ; dir_iter != end_iter ; ++dir_iter)
|
||||
{
|
||||
if (boost::filesystem::is_regular_file(dir_iter->status()) )
|
||||
{
|
||||
boost::filesystem::path file = dir_iter->path();
|
||||
|
||||
std::string pathname = file.filename().string();
|
||||
|
||||
// get first part of filename, e.g. main_fragment_546457654 -> main_fragment
|
||||
// there is probably a better method for this...
|
||||
std::vector<std::string> tokens;
|
||||
boost::split(tokens, pathname, boost::is_any_of("_"));
|
||||
tokens.erase(--tokens.end());
|
||||
std::string shaderName;
|
||||
for (std::vector<std::string>::const_iterator vector_iter = tokens.begin(); vector_iter != tokens.end();)
|
||||
{
|
||||
shaderName += *(vector_iter++);
|
||||
if (vector_iter != tokens.end())
|
||||
shaderName += "_";
|
||||
}
|
||||
|
||||
if (shaderName == it->first)
|
||||
{
|
||||
boost::filesystem::remove(file);
|
||||
std::cout << "Removing outdated file: " << file << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
anyShaderDirty = true;
|
||||
}
|
||||
|
||||
mShadersLastModified[sourceFile] = lastModified;
|
||||
|
||||
mShaderSets.insert(std::make_pair(it->first, newSet));
|
||||
}
|
||||
}
|
||||
|
@ -313,11 +346,11 @@ namespace sh
|
|||
|
||||
if (mReadSourceCache)
|
||||
{
|
||||
// save the last modified time of shader sources
|
||||
// save the last modified time of shader sources (as of when they were loaded)
|
||||
std::ofstream file;
|
||||
file.open(std::string(mPlatform->getCacheFolder () + "/lastModified.txt").c_str());
|
||||
|
||||
for (LastModifiedMap::const_iterator it = mShadersLastModified.begin(); it != mShadersLastModified.end(); ++it)
|
||||
for (LastModifiedMap::const_iterator it = mShadersLastModifiedNew.begin(); it != mShadersLastModifiedNew.end(); ++it)
|
||||
{
|
||||
file << it->first << "\n" << it->second << std::endl;
|
||||
}
|
||||
|
|
1
extern/shiny/Main/Factory.hpp
vendored
1
extern/shiny/Main/Factory.hpp
vendored
|
@ -185,6 +185,7 @@ namespace sh
|
|||
ConfigurationMap mConfigurations;
|
||||
LodConfigurationMap mLodConfigurations;
|
||||
LastModifiedMap mShadersLastModified;
|
||||
LastModifiedMap mShadersLastModifiedNew;
|
||||
|
||||
PropertySetGet mGlobalSettings;
|
||||
|
||||
|
|
15
extern/shiny/Main/ShaderInstance.cpp
vendored
15
extern/shiny/Main/ShaderInstance.cpp
vendored
|
@ -337,8 +337,7 @@ namespace sh
|
|||
size_t pos;
|
||||
|
||||
bool readCache = Factory::getInstance ().getReadSourceCache () && boost::filesystem::exists(
|
||||
Factory::getInstance ().getCacheFolder () + "/" + mName)
|
||||
&& !mParent->isDirty ();
|
||||
Factory::getInstance ().getCacheFolder () + "/" + mName);
|
||||
bool writeCache = Factory::getInstance ().getWriteSourceCache ();
|
||||
|
||||
|
||||
|
@ -363,12 +362,6 @@ namespace sh
|
|||
|
||||
if (Factory::getInstance ().getShaderDebugOutputEnabled ())
|
||||
writeDebugFile(source, name + ".pre");
|
||||
else
|
||||
{
|
||||
#ifdef SHINY_WRITE_SHADER_DEBUG
|
||||
writeDebugFile(source, name + ".pre");
|
||||
#endif
|
||||
}
|
||||
|
||||
// why do we need our own preprocessor? there are several custom commands available in the shader files
|
||||
// (for example for binding uniforms to properties or auto constants) - more below. it is important that these
|
||||
|
@ -648,12 +641,6 @@ namespace sh
|
|||
|
||||
if (Factory::getInstance ().getShaderDebugOutputEnabled ())
|
||||
writeDebugFile(source, name);
|
||||
else
|
||||
{
|
||||
#ifdef SHINY_WRITE_SHADER_DEBUG
|
||||
writeDebugFile(source, name);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!mProgram->getSupported())
|
||||
{
|
||||
|
|
1
extern/shiny/Main/ShaderSet.cpp
vendored
1
extern/shiny/Main/ShaderSet.cpp
vendored
|
@ -17,7 +17,6 @@ namespace sh
|
|||
, mName(name)
|
||||
, mCgProfile(cgProfile)
|
||||
, mHlslProfile(hlslProfile)
|
||||
, mIsDirty(false)
|
||||
{
|
||||
if (type == "vertex")
|
||||
mType = GPT_Vertex;
|
||||
|
|
7
extern/shiny/Main/ShaderSet.hpp
vendored
7
extern/shiny/Main/ShaderSet.hpp
vendored
|
@ -30,9 +30,6 @@ namespace sh
|
|||
/// so it does not matter if you pass any extra properties that the shader does not care about.
|
||||
ShaderInstance* getInstance (PropertySetGet* properties);
|
||||
|
||||
void markDirty() { mIsDirty = true; }
|
||||
///< Signals that the cache is out of date, and thus should not be used this time
|
||||
|
||||
private:
|
||||
PropertySetGet* getCurrentGlobalSettings() const;
|
||||
std::string getBasePath() const;
|
||||
|
@ -41,12 +38,8 @@ namespace sh
|
|||
std::string getHlslProfile() const;
|
||||
int getType() const;
|
||||
|
||||
bool isDirty() { return mIsDirty; }
|
||||
|
||||
friend class ShaderInstance;
|
||||
|
||||
bool mIsDirty;
|
||||
|
||||
private:
|
||||
GpuProgramType mType;
|
||||
std::string mSource;
|
||||
|
|
Loading…
Reference in a new issue