示例#1
0
        /// <summary>
        /// 通过着色器类型获取着色器文件扩展名
        /// </summary>
        /// <param name="type">着色器类型</param>
        /// <returns>着色器文件扩展名</returns>
        public static string GetFileExtensionByShaderType(EShaderType type)
        {
            string extension = string.Empty;

            switch (type)
            {
            case EShaderType.Vertex:
                extension = ".vert";
                break;

            case EShaderType.Fragment:
                extension = ".frag";
                break;

            case EShaderType.Compute:
                extension = ".comp";
                break;

            case EShaderType.Geometry:
                extension = ".geom";
                break;

            case EShaderType.Tessellation_Control:
                extension = ".tesc";
                break;

            case EShaderType.Tessellation_Evaluation:
                extension = ".tese";
                break;
            }
            return(extension);
        }
        public SortedList <string, GUID> ShaderSortedByName(EShaderType shaderType)
        {
            switch (shaderType)
            {
            case EShaderType.ClosestHit:
                return(closestHitDataTable.ShaderSortByName);

            case EShaderType.Intersect:
                return(intersectDataTable.ShaderSortByName);

            default:
                return(new SortedList <string, GUID>());
            }
        }
        public string[] ShaderNameList(EShaderType shaderType)
        {
            switch (shaderType)
            {
            case EShaderType.ClosestHit:
                return(closestHitDataTable.ShaderNameList);

            case EShaderType.Intersect:
                return(intersectDataTable.ShaderNameList);

            default:
                return(new string[0]);
            }
        }
        public SortedList <GUID, CustomShaderMeta> ShaderMetaList(EShaderType shaderType)
        {
            switch (shaderType)
            {
            case EShaderType.ClosestHit:
                return(closestHitDataTable.ShaderMetaList);

            case EShaderType.Intersect:
                return(intersectDataTable.ShaderMetaList);

            default:
                return(new SortedList <GUID, CustomShaderMeta>());
            }
        }
        public string ShaderNameToGUID(string shaderName, EShaderType shaderType)
        {
            switch (shaderType)
            {
            case EShaderType.ClosestHit:
                return(closestHitDataTable.ShaderNameToGUID(shaderName));

            case EShaderType.Intersect:
                return(intersectDataTable.ShaderNameToGUID(shaderName));

            default:
                return(string.Empty);
            }
        }
        public int GUIDToShaderIndex(GUID guid, EShaderType shaderType)
        {
            switch (shaderType)
            {
            case EShaderType.ClosestHit:
                return(closestHitDataTable.GUIDToShaderIndex(guid));

            case EShaderType.Intersect:
                return(intersectDataTable.GUIDToShaderIndex(guid));

            default:
                return(-1);
            }
        }
        public bool IsShaderTableDirty(EShaderType shaderType)
        {
            switch (shaderType)
            {
            case EShaderType.ClosestHit:
                return(closestHitDataTable.IsDirty());

            case EShaderType.Intersect:
                return(intersectDataTable.IsDirty());

            default:
                Debug.LogWarning($"TODO: Support adding shaders of type {shaderType}");
                return(false);
            }
        }
        public void SetShaderTableClean(EShaderType shaderType)
        {
            switch (shaderType)
            {
            case EShaderType.ClosestHit:
                closestHitDataTable.Clean();
                break;

            case EShaderType.Intersect:
                intersectDataTable.Clean();
                break;

            default:
                Debug.LogWarning($"TODO: Support adding shaders of type {shaderType}");
                break;
            }
        }
    public bool ContainsThisShader(EShaderType shaderType, string shaderName)
    {
        switch (shaderType)
        {
        case EShaderType.CloestHit:
            return(m_closetHitShaderMetaList.Any((item) => {
                return item.name == shaderName;
            }));

        case EShaderType.Intersect:
            return(m_closetHitShaderMetaList.Any((item) => {
                return item.name == shaderName;
            }));

        default:
            Debug.LogWarning($"Unsupported shader type {shaderType}");
            return(false);
        }
    }
示例#10
0
 public CShaderDesc(EShaderType type)
 {
     mCoreObject = NewNativeObjectByName <NativePointer>($"{CEngine.NativeNS}::IShaderDesc");
     SDK_IShaderDesc_SetShaderType(CoreObject, type);
 }
示例#11
0
 public extern static void SDK_IShaderDesc_SetShaderType(NativePointer self, EShaderType type);
示例#12
0
        public CShaderDesc CreateShaderDesc(RName shader, string entry, EShaderType type, CShaderDefinitions defines, EPlatformType platforms)
        {
            string cachedName = "";
            string sm         = "vs_5_0";
            var    shaderHash = UniHash.APHash(shader.Name + entry + defines.ToString());
            var    macro      = defines.GetHash64().ToString();

            switch (type)
            {
            case EShaderType.EST_ComputeShader:
                cachedName = $"cs/{shaderHash}_{macro}.cshader";
                sm         = "cs_5_0";
                if (ShaderModel == 3)
                {
                    return(null);
                }
                break;

            case EShaderType.EST_VertexShader:
                cachedName = $"vs/{shaderHash}_{macro}.vshader";
                sm         = "vs_5_0";
                break;

            case EShaderType.EST_PixelShader:
                cachedName = $"ps/{shaderHash}_{macro}.pshader";
                sm         = "ps_5_0";
                break;
            }
            var smStr      = CRenderContext.ShaderModelString;
            var shaderFile = CEngine.Instance.FileManager.DDCDirectory + smStr + "/" + cachedName;

            using (var xnd = IO.XndHolder.SyncLoadXND(shaderFile))
            {
                if (xnd != null)
                {
                    bool needCompile = false;
                    var  fileDesc    = CEngine.Instance.FileManager.HLSLFileDescManager.FindFileDesc(shader.Address);
                    if (fileDesc != null)
                    {
                        var hashAttr = xnd.Node.FindAttrib("HashCode");
                        if (hashAttr != null)
                        {
                            hashAttr.BeginRead();
                            string savedHash;
                            hashAttr.Read(out savedHash);
                            hashAttr.EndRead();
                            if (savedHash != fileDesc.HashCode.ToString())
                            {
                                needCompile = true;
                            }
                        }
                    }
                    if (needCompile == false)
                    {
                        CShaderDesc desc = new CShaderDesc(type);
                        desc.LoadXnd(xnd.Node);
                        return(desc);
                    }
                }

                {
                    var xml = IO.XmlHolder.NewXMLHolder($"{type.ToString()}", "");
                    xml.RootNode.AddAttrib("Shader", shader.ToString());
                    xml.RootNode.AddAttrib("Entry", entry);
                    var node = xml.RootNode.AddNode("Macro", "", xml);
                    foreach (var i in defines.mShaderMacroArray)
                    {
                        node.AddAttrib(i.Name, i.Definition);
                    }
                    var fileDesc = CEngine.Instance.FileManager.HLSLFileDescManager.FindFileDesc(shader.Address);
                    if (fileDesc != null)
                    {
                        xml.RootNode.AddAttrib("HashCode", fileDesc.HashCode.ToString());
                    }

                    var shaderDescFile = CEngine.Instance.FileManager.DDCDirectory + "shaderinfo/" + cachedName + ".shaderxml";
                    IO.XmlHolder.SaveXML(shaderDescFile, xml);

                    var desc  = CompileHLSLFromFile(shader.Address, entry, sm, defines, platforms);
                    var saved = IO.XndHolder.NewXNDHolder();

                    if (fileDesc != null)
                    {
                        var hashAttr = saved.Node.AddAttrib("HashCode");
                        hashAttr.BeginWrite();
                        hashAttr.Write(fileDesc.HashCode.ToString());
                        hashAttr.EndWrite();
                    }

                    desc.Save2Xnd(saved.Node, platforms);

                    IO.XndHolder.SaveXND(shaderFile, saved);

                    return(desc);
                }
            }
        }
示例#13
0
        public void CookShaderDesc(RName shader, string entry, EShaderType type, CShaderDefinitions defines, int ShaderModel, EPlatformType platforms)
        {
            string cachedName = "";
            string sm         = "vs_5_0";
            var    shaderHash = UniHash.APHash(shader.Name + entry + defines.ToString());
            var    macro      = defines.GetHash64().ToString();

            switch (type)
            {
            case EShaderType.EST_ComputeShader:
                cachedName = $"cs/{shaderHash}_{macro}.cshader";
                sm         = "cs_5_0";
                if (ShaderModel == 3)
                {
                    return;
                }
                break;

            case EShaderType.EST_VertexShader:
                cachedName = $"vs/{shaderHash}_{macro}.vshader";
                sm         = "vs_5_0";
                break;

            case EShaderType.EST_PixelShader:
                cachedName = $"ps/{shaderHash}_{macro}.pshader";
                sm         = "ps_5_0";
                break;
            }
            var shaderFile = "";

            switch (CIPlatform.Instance.PlayMode)
            {
            case CIPlatform.enPlayMode.Cook:
                shaderFile = CEngine.Instance.FileManager.CookingRoot + "deriveddatacache/" + $"sm{ShaderModel}/" + cachedName;
                break;

            case CIPlatform.enPlayMode.Game:
            case CIPlatform.enPlayMode.Editor:
            case CIPlatform.enPlayMode.PlayerInEditor:
                shaderFile = CEngine.Instance.FileManager.DDCDirectory + $"sm{ShaderModel}/" + cachedName;
                break;
            }
            using (var xnd = IO.XndHolder.SyncLoadXND(shaderFile))
            {
                if (xnd != null)
                {
                    bool needCompile = false;
                    var  fileDesc    = CEngine.Instance.FileManager.HLSLFileDescManager.FindFileDesc(shader.Address);
                    if (fileDesc != null)
                    {
                        var hashAttr = xnd.Node.FindAttrib("HashCode");
                        if (hashAttr != null)
                        {
                            hashAttr.BeginRead();
                            string savedHash;
                            hashAttr.Read(out savedHash);
                            hashAttr.EndRead();
                            if (savedHash != fileDesc.HashCode.ToString())
                            {
                                needCompile = true;
                            }
                        }
                    }
                    if (needCompile == false)
                    {
                        CShaderDesc desc = new CShaderDesc(type);
                        desc.LoadXnd(xnd.Node);
                        return;
                    }
                }

                {
                    var desc  = CompileHLSLFromFile(shader.Address, entry, sm, defines, platforms);
                    var saved = IO.XndHolder.NewXNDHolder();

                    var fileDesc = CEngine.Instance.FileManager.HLSLFileDescManager.FindFileDesc(shader.Address);
                    if (fileDesc != null)
                    {
                        var hashAttr = saved.Node.AddAttrib("HashCode");
                        hashAttr.BeginWrite();
                        hashAttr.Write(fileDesc.HashCode.ToString());
                        hashAttr.EndWrite();
                        desc.Save2Xnd(saved.Node, platforms);
                    }

                    IO.XndHolder.SaveXND(shaderFile, saved);
                }
            }
        }
示例#14
0
        static async System.Threading.Tasks.Task CookShadersWithFilter(string[] args, string smStr, EPlatformType platforms, HashSet <RName> MaterialAssets)
        {
            var rc = CEngine.Instance.RenderContext;

            int ShaderModel = System.Convert.ToInt32(smStr);

            string targetDir = CEngine.Instance.FileManager.CookingRoot + "deriveddatacache/" + "/sm" + smStr + "/";

            if (FindArgument(args, "recompile") != null)
            {
                if (CEngine.Instance.FileManager.DirectoryExists(targetDir))
                {
                    CEngine.Instance.FileManager.DeleteDirectory(targetDir, true);
                }
            }
            CEngine.Instance.FileManager.CreateDirectory(targetDir);
            CEngine.Instance.FileManager.CreateDirectory(targetDir + "cs/");
            CEngine.Instance.FileManager.CreateDirectory(targetDir + "vs/");
            CEngine.Instance.FileManager.CreateDirectory(targetDir + "ps/");
            EngineNS.CRenderContext.ShaderModel = ShaderModel;
            var shaderPath   = CEngine.Instance.FileManager.DDCDirectory + "shaderinfo/";
            var shaders      = CEngine.Instance.FileManager.GetFiles(shaderPath, "*.xml");
            int NumOfFailed  = 0;
            int NumOfNotUsed = 0;

            foreach (var i in shaders)
            {
                using (var xml = EngineNS.IO.XmlHolder.LoadXML(i))
                {
                    EngineNS.Graphics.CGfxEffectDesc desc = await EngineNS.Graphics.CGfxEffectDesc.LoadEffectDescFromXml(rc, xml.RootNode, false);

                    if (desc == null)
                    {
                        EngineNS.Profiler.Log.WriteLine(EngineNS.Profiler.ELogTag.Warning, "CookShader", $"CookShader Failed: {xml.GetTextString()}");
                        NumOfFailed++;
                        continue;
                    }
                    if (MaterialAssets.Contains(desc.MtlShaderPatch.Name) == false)
                    {
                        NumOfNotUsed++;
                        continue;
                    }
                    var effect = new EngineNS.Graphics.CGfxEffect(desc);
                    await effect.CookEffect(rc, desc, ShaderModel, platforms);
                }
            }
            shaders = CEngine.Instance.FileManager.GetFiles(shaderPath, "*.shaderxml");
            foreach (var i in shaders)
            {
                using (var xml = EngineNS.IO.XmlHolder.LoadXML(i))
                {
                    RName       shaderName = RName.GetRName(xml.RootNode.FindAttrib("Shader").Value, RName.enRNameType.Engine);
                    EShaderType type       = EShaderType.EST_UnknownShader;
                    switch (xml.RootNode.Name)
                    {
                    case "EST_ComputeShader":
                        type = EShaderType.EST_ComputeShader;
                        break;

                    case "EST_VertexShader":
                        type = EShaderType.EST_VertexShader;
                        break;

                    case "EST_PixelShader":
                        type = EShaderType.EST_PixelShader;
                        break;
                    }

                    string             entry   = xml.RootNode.FindAttrib("Entry").Value;
                    var                node    = xml.RootNode.FindNode("Macro");
                    var                attrs   = node.GetAttribs();
                    CShaderDefinitions defines = new CShaderDefinitions();
                    foreach (var j in attrs)
                    {
                        defines.SetDefine(j.Name, j.Value);
                    }

                    CEngine.Instance.RenderContext.CookShaderDesc(shaderName, entry, type, defines, ShaderModel, platforms);
                }
            }
        }
        protected override EAnalyzeStageStatus execute(int index)
        {
            AnalyzedVariantData variant = m_AnalyzeWrap.Variants[index];

            int currentLine = 0;

            bool        afterEmpty        = false;
            EShaderType currentShaderType = EShaderType.None;

            while (currentLine < variant.SourceCodeLines.Count)
            {
                string line = variant.SourceCodeLines[currentLine++];

                if (string.IsNullOrEmpty(line))
                {
                    afterEmpty = true;
                    continue;
                }
                else
                {
                    if (afterEmpty && line == "//////////////////////////////////////////////////////")
                    {
                        currentShaderType = EShaderType.None;
                        break;
                    }
                    else if (string.IsNullOrEmpty(variant.VariantName))
                    {
                        if (line.StartsWith("Global Keywords: "))
                        {
                            variant.VariantName = line.Replace("Global Keywords: ", string.Empty);
                            continue;
                        }
                    }
                    else if (currentShaderType == EShaderType.None)
                    {
                        for (int i = 0; i < ShaderBeginFlag.Length; i++)
                        {
                            if (line == ShaderBeginFlag[i])
                            {
                                currentShaderType = (EShaderType)i;
                                break;
                            }
                        }
                    }
                    else if (currentShaderType != EShaderType.None)
                    {
                        if (afterEmpty && line == ShaderEndFlag)
                        {
                            variant.ShaderSourceCodes.Add(currentShaderType, m_TextContainer.ToString());
                            m_TextContainer.Clear();
                            currentShaderType = EShaderType.None;
                            continue;
                        }

                        m_TextContainer.AppendLine(line);
                    }

                    afterEmpty = false;
                }
            }

            return(EAnalyzeStageStatus.Success);
        }
示例#16
0
 public void RT_SetShaderQuality(EShaderType eST, EShaderQuality eSQ) => throw new NotImplementedException();