extern/shiny update: made caching more robust

actorid
scrawl 12 years ago
parent bf037b7d29
commit a7d910614f

@ -191,15 +191,48 @@ namespace sh
&mGlobalSettings); &mGlobalSettings);
int lastModified = boost::filesystem::last_write_time (boost::filesystem::path(sourceFile)); int lastModified = boost::filesystem::last_write_time (boost::filesystem::path(sourceFile));
mShadersLastModifiedNew[sourceFile] = lastModified;
if (mShadersLastModified.find(sourceFile) != mShadersLastModified.end() if (mShadersLastModified.find(sourceFile) != mShadersLastModified.end()
&& mShadersLastModified[sourceFile] != lastModified) && 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; anyShaderDirty = true;
} }
mShadersLastModified[sourceFile] = lastModified;
mShaderSets.insert(std::make_pair(it->first, newSet)); mShaderSets.insert(std::make_pair(it->first, newSet));
} }
} }
@ -313,11 +346,11 @@ namespace sh
if (mReadSourceCache) 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; std::ofstream file;
file.open(std::string(mPlatform->getCacheFolder () + "/lastModified.txt").c_str()); 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; file << it->first << "\n" << it->second << std::endl;
} }

@ -185,6 +185,7 @@ namespace sh
ConfigurationMap mConfigurations; ConfigurationMap mConfigurations;
LodConfigurationMap mLodConfigurations; LodConfigurationMap mLodConfigurations;
LastModifiedMap mShadersLastModified; LastModifiedMap mShadersLastModified;
LastModifiedMap mShadersLastModifiedNew;
PropertySetGet mGlobalSettings; PropertySetGet mGlobalSettings;

@ -337,8 +337,7 @@ namespace sh
size_t pos; size_t pos;
bool readCache = Factory::getInstance ().getReadSourceCache () && boost::filesystem::exists( bool readCache = Factory::getInstance ().getReadSourceCache () && boost::filesystem::exists(
Factory::getInstance ().getCacheFolder () + "/" + mName) Factory::getInstance ().getCacheFolder () + "/" + mName);
&& !mParent->isDirty ();
bool writeCache = Factory::getInstance ().getWriteSourceCache (); bool writeCache = Factory::getInstance ().getWriteSourceCache ();
@ -363,12 +362,6 @@ namespace sh
if (Factory::getInstance ().getShaderDebugOutputEnabled ()) if (Factory::getInstance ().getShaderDebugOutputEnabled ())
writeDebugFile(source, name + ".pre"); 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 // 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 // (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 ()) if (Factory::getInstance ().getShaderDebugOutputEnabled ())
writeDebugFile(source, name); writeDebugFile(source, name);
else
{
#ifdef SHINY_WRITE_SHADER_DEBUG
writeDebugFile(source, name);
#endif
}
if (!mProgram->getSupported()) if (!mProgram->getSupported())
{ {

@ -17,7 +17,6 @@ namespace sh
, mName(name) , mName(name)
, mCgProfile(cgProfile) , mCgProfile(cgProfile)
, mHlslProfile(hlslProfile) , mHlslProfile(hlslProfile)
, mIsDirty(false)
{ {
if (type == "vertex") if (type == "vertex")
mType = GPT_Vertex; mType = GPT_Vertex;

@ -30,9 +30,6 @@ namespace sh
/// so it does not matter if you pass any extra properties that the shader does not care about. /// so it does not matter if you pass any extra properties that the shader does not care about.
ShaderInstance* getInstance (PropertySetGet* properties); 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: private:
PropertySetGet* getCurrentGlobalSettings() const; PropertySetGet* getCurrentGlobalSettings() const;
std::string getBasePath() const; std::string getBasePath() const;
@ -41,12 +38,8 @@ namespace sh
std::string getHlslProfile() const; std::string getHlslProfile() const;
int getType() const; int getType() const;
bool isDirty() { return mIsDirty; }
friend class ShaderInstance; friend class ShaderInstance;
bool mIsDirty;
private: private:
GpuProgramType mType; GpuProgramType mType;
std::string mSource; std::string mSource;

Loading…
Cancel
Save