示例#1
0
        public void InitFiles()
        {
#if PWindow
            if (EngineNS.IO.FileManager.UseCooked != null)
            {
                return;
            }

            var files = CEngine.Instance.FileManager.GetFiles(RName.GetRName("Shaders", RName.enRNameType.Engine).Address, "*.*", SearchOption.AllDirectories);
            if (files == null)
            {
                return;
            }
            foreach (var f in files)
            {
                bool error = false;
                var  i     = CEngine.Instance.FileManager.NormalizePath(f, out error);
                if (error)
                {
                    continue;
                }
                if (i.EndsWith(".shaderinc") ||
                    i.EndsWith(".cginc") ||
                    i.EndsWith(".shadingenv") ||
                    i.EndsWith(".compute"))
                {
                    var desc = new HLSLFileDesc();
                    desc.Directory = CEngine.Instance.FileManager.GetPathFromFullName(i);
                    desc.FileName  = CEngine.Instance.FileManager.GetPureFileFromFullName(i);
                    desc.HLSLCode  = System.IO.File.ReadAllText(i);
                    Hash64.CalcHash64(ref desc.HashCode, desc.HLSLCode);
                    FileDescDict.Add(desc.Directory + desc.FileName, desc);
                }
            }
            foreach (var i in FileDescDict)
            {
                GetDepends(i.Value);
            }

            foreach (var i in FileDescDict)
            {
                if (i.Key.EndsWith(".shadingenv") || i.Key.EndsWith(".compute"))
                {
                    var allDepends = new List <HLSLFileDesc>();
                    CollectDependTree(i.Value, allDepends);
                    allDepends.Sort((left, right) =>
                    {
                        return(left.FullName.CompareTo(right.FullName));
                    });
                    string AllCode = i.Value.HLSLCode;
                    foreach (var j in allDepends)
                    {
                        AllCode += j.HLSLCode;
                    }
                    Hash64.CalcHash64(ref i.Value.HashWithDepends, AllCode);
                }
            }
#endif
        }
示例#2
0
 private void CollectDependTree(HLSLFileDesc cur, List <HLSLFileDesc> allDepends)
 {
     foreach (var i in cur.Depends)
     {
         if (allDepends.Contains(i.Value) == false)
         {
             allDepends.Add(i.Value);
             CollectDependTree(i.Value, allDepends);
         }
     }
 }
示例#3
0
        private void GetDepends(HLSLFileDesc desc)
        {
            var code          = desc.HLSLCode;
            int keywordLength = "#include".Length;
            int startPos      = 0;

            startPos = code.IndexOf("#include", startPos);
            while (startPos >= 0)
            {
                while (code[startPos + keywordLength] == ' ' || code[startPos + keywordLength] == '\t')
                {
                    startPos++;
                }
                int nameStrStart = startPos + keywordLength;
                if (code[nameStrStart] == '\"')
                {
                    if (startPos >= code.Length)
                    {
                        Profiler.Log.WriteLine(Profiler.ELogTag.Warning, "Shaders", $"HLSL({desc.FileName}) includer can't match character:\"");
                        return;
                    }
                    startPos++;
                    nameStrStart++;
                    int nameStrEnd = nameStrStart;
                    while (code[nameStrEnd] != '\"')
                    {
                        startPos++;
                        nameStrEnd++;
                    }
                    var dependAddress = code.Substring(nameStrStart, nameStrEnd - nameStrStart);

                    bool error = false;
                    var  f     = CEngine.Instance.FileManager.NormalizePath(desc.Directory + dependAddress, out error);
                    if (error)
                    {
                        Profiler.Log.WriteLine(Profiler.ELogTag.Warning, "Shaders", $"HLSL({desc.FileName}) include {dependAddress} is invalid");
                    }

                    var dependDesc = FindFileDesc(f);
                    if (dependDesc != null && desc.Depends.Keys.Contains(f) == false)
                    {
                        desc.Depends.Add(f, dependDesc);
                    }
                }

                startPos = code.IndexOf("#include", startPos);
            }
        }