Exemplo n.º 1
0
bool UpdateShaders()
{
    if(ShaderFiles.Count() == 0)
        return false;

    static uint64 currFile = 0;
    currFile = (currFile + 1) % uint64(ShaderFiles.Count());

    ShaderFile* file = ShaderFiles[currFile];
    const uint64 newTimeStamp = GetFileTimestamp(file->FilePath.c_str());
    if(file->TimeStamp == 0)
    {
        file->TimeStamp = newTimeStamp;
        return false;
    }

    if(file->TimeStamp < newTimeStamp)
    {
        WriteLog("Hot-swapping shaders for %ls\n", file->FilePath.c_str());
        file->TimeStamp = newTimeStamp;
        for(uint64 i = 0; i < file->Shaders.Count(); ++i)
        {
            // Retry a few times to avoid file conflicts with text editors
            const uint64 NumRetries = 10;
            for(uint64 retryCount = 0; retryCount < NumRetries; ++retryCount)
            {
                try
                {
                    CompiledShader* shader = file->Shaders[i];
                    CompileShader(shader);
                    break;
                }
                catch(Win32Exception& exception)
                {
                    if(retryCount == NumRetries - 1)
                        throw exception;
                    Sleep(15);
                }
            }
        }

        return true;
    }

    return false;
}
Exemplo n.º 2
0
void UpdateShaders(ID3D11Device* device)
{
    if(ShaderFiles.size() == 0)
        return;

    static uint64 currFrame = 0;
    currFrame = (currFrame + 1) % 10;
    if(currFrame != 0)
        return;

    static uint64 currFile = 0;
    currFile = (currFile + 1) % uint64(ShaderFiles.size());

    ShaderFile* file = ShaderFiles[currFile];
    const uint64 newTimeStamp = GetFileTimestamp(file->FilePath.c_str());
    if(file->TimeStamp == 0)
    {
        file->TimeStamp = newTimeStamp;
        return;
    }

    if(file->TimeStamp < newTimeStamp)
    {
        file->TimeStamp = newTimeStamp;
        for(uint64 i = 0; i < file->Shaders.size(); ++i)
        {
            CompiledShader* shader = file->Shaders[i];
            if(*shader->Type == typeid(ID3D11VertexShader))
                CompileShader<ID3D11VertexShader>(device, shader);
            else if(*shader->Type == typeid(ID3D11HullShader))
                CompileShader<ID3D11HullShader>(device, shader);
            else if(*shader->Type == typeid(ID3D11DomainShader))
                CompileShader<ID3D11DomainShader>(device, shader);
            else if(*shader->Type == typeid(ID3D11GeometryShader))
                CompileShader<ID3D11GeometryShader>(device, shader);
            else if(*shader->Type == typeid(ID3D11PixelShader))
                CompileShader<ID3D11PixelShader>(device, shader);
            else if(*shader->Type == typeid(ID3D11ComputeShader))
                CompileShader<ID3D11ComputeShader>(device, shader);
            else
                AssertFail_("Invalid shader type");
        }
    }
}
Exemplo n.º 3
0
bool compile_file(const char *path)
{
        string fname(path);
        string filename_src = fname, ext("");

	    string::size_type pos = fname.rfind(".");
	    if ( pos != string::npos )
		    ext = fname.substr(pos);

        if (!ext.compare(".inc"))
        {
            compile_inc( path );
            return true;
        }

        if (ext.compare(".src") != 0 &&
		    ext.compare(".hsr") != 0 &&
		    ext.compare(".asp") != 0)
        {
            cout << "Didn't find '.src', '.hsr', or '.asp' extension on source filename '"
                << path << "'!" << endl;
            throw runtime_error( "Error in source filename" );
        }
        string filename_ecl = fname.replace(pos, 4, ".ecl");
        string filename_lst = fname.replace(pos, 4, ".lst");
        string filename_dep = fname.replace(pos, 4, ".dep");
        string filename_dbg = fname.replace(pos, 4, ".dbg");

        if (compilercfg.OnlyCompileUpdatedScripts && !force_update)
        {
            bool all_old = true;
            unsigned long ecl_timestamp = GetFileTimestamp( filename_ecl.c_str() );
            if (GetFileTimestamp( filename_src.c_str() ) >= ecl_timestamp)
            {
                if (verbose)
                    cout << filename_src << " is newer than " << filename_ecl << endl;
                all_old = false;
            }

            if (all_old)
            {
                ifstream ifs( filename_dep.c_str() );
                // if the file doesn't exist, gotta build.
                if (ifs.is_open())
                {
                    string depname;
                    while (getline( ifs, depname ))
                    {
                        if (GetFileTimestamp( depname.c_str() ) >= ecl_timestamp )
                        {
                            if (verbose)
                                cout << depname << " is newer than " << filename_ecl << endl;
                            all_old = false;
                            break;
                        }
                    }
                }
                else
                {
                    if (verbose)
                        cout << filename_dep << " does not exist." << endl;
                    all_old = false;
                }
            }
            if (all_old)
            {
			    if (!quiet && compilercfg.DisplayUpToDateScripts)
				    cout << filename_ecl << " is up-to-date." << endl;
                return false;
            }

        }

        {
            if (!quiet)
                cout << "Compiling: " << path << endl;

            Compiler C(cout);

            C.setQuiet(!debug);
            int res = C.compileFile(path);
        
            if (expect_compile_failure)
            {
                if (res)        // good, it failed
                {
                    if (!quiet)
                        cout << "Compilation failed as expected." << endl;
                    return true;
                }
                else
                {
                    throw runtime_error( "Compilation succeeded (-e indicates failure was expected)" );
                }
            }

            if (res) 
                throw runtime_error( "Error compiling file" );
        


            if (!quiet)
                cout << "Writing:   " << filename_ecl << endl;

            if (C.write(filename_ecl.c_str()))
            {
                throw runtime_error( "Error writing output file" );
            }

            if (compilercfg.GenerateListing)
            {
                if (!quiet)
                    cout << "Writing:   " << filename_lst << endl;
                ofstream ofs( filename_lst.c_str() );
                C.dump( ofs );
            }
            else if (FileExists( filename_lst.c_str() ) )
            {
                if (!quiet) cout << "Deleting:  " << filename_lst << endl;
                RemoveFile( filename_lst.c_str() );
            }

            if (compilercfg.GenerateDebugInfo)
            {
                if (!quiet)
                {
                    cout << "Writing:   " << filename_dbg << endl;
                    if (compilercfg.GenerateDebugTextInfo)
                        cout << "Writing:   " << filename_dbg << ".txt" << endl;
                }
                C.write_dbg( filename_dbg.c_str(), compilercfg.GenerateDebugTextInfo );
            }
            else if (FileExists( filename_dbg.c_str() ) )
            {
                if (!quiet) cout << "Deleting:  " << filename_dbg << endl;
                RemoveFile( filename_dbg.c_str() );
            }

            if (compilercfg.GenerateDependencyInfo)
            {
                if (!quiet)
                    cout << "Writing:   " << filename_dep << endl;
                C.writeIncludedFilenames( filename_dep.c_str() );
            }
            else if (FileExists( filename_dep.c_str() ) )
            {
                if (!quiet) cout << "Deleting:  " << filename_dep << endl;
                RemoveFile( filename_dep.c_str() );
            }

        }
    return true;
}