Ejemplo n.º 1
0
        protected override int init(AnalyzeWrap wrap, ShaderAnalyzeParams param)
        {
            createFolder(Constant.SAWorkSpace);
            for (int i = 0; i < wrap.Subshaders.Count; i++)
            {
                AnalyzedSubshaderData subshader = wrap.Subshaders[i];

                string subshaderFolder = Constant.SAWorkSpace + "/Subshader_" + i.ToString();

                createFolder(subshaderFolder);
                for (int j = 0; j < subshader.Passes.Count; j++)
                {
                    AnalyzedPassData pass = subshader.Passes[j];

                    string passFolder = subshaderFolder + "/Pass_" + j.ToString();

                    createFolder(passFolder);

                    for (int k = 0; k < pass.Variants.Count; k++)
                    {
                        AnalyzedVariantData variant = pass.Variants[k];

                        string variantFolder = passFolder + "/" + ShaderAnalyzerUtil.ReplaceBadCharOfFileName(variant.VariantName);

                        createFolder(variantFolder);

                        wrap.VariantDirectory.Add(variant, variantFolder);
                    }
                }
            }

            return(wrap.Variants.Count);
        }
Ejemplo n.º 2
0
        protected override void init()
        {
            m_FolderMap = new Dictionary <AnalyzedBase, bool>();

            for (int i = 0; i < m_AnalyzedData.Subshaders.Count; i++)
            {
                AnalyzedSubshaderData subshader = m_AnalyzedData.Subshaders[i];

                m_FolderMap.Add(subshader, true);

                for (int j = 0; j < subshader.Passes.Count; j++)
                {
                    AnalyzedPassData pass = subshader.Passes[j];

                    m_FolderMap.Add(pass, true);

                    for (int k = 0; k < pass.Variants.Count; k++)
                    {
                        AnalyzedVariantData variant = pass.Variants[k];

                        m_FolderMap.Add(variant, true);

                        for (int l = 0; l < variant.Shaders.Count; l++)
                        {
                            AnalyzedShaderDataBase shader = variant.Shaders[l];

                            m_FolderMap.Add(shader, true);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        protected override void init()
        {
            m_List     = new List <AnalyzedShaderDataBase>();
            m_ParamMap = new Dictionary <AnalyzedShaderDataBase, ShaderParem>();

            for (int i = 0; i < m_AnalyzedData.Subshaders.Count; i++)
            {
                AnalyzedSubshaderData subshader = m_AnalyzedData.Subshaders[i];

                for (int j = 0; j < subshader.Passes.Count; j++)
                {
                    AnalyzedPassData pass = subshader.Passes[j];

                    for (int k = 0; k < pass.Variants.Count; k++)
                    {
                        AnalyzedVariantData variant = pass.Variants[k];

                        for (int l = 0; l < variant.Shaders.Count; l++)
                        {
                            AnalyzedShaderDataBase shader = variant.Shaders[l];

                            if (m_FieldInfoMap == null)
                            {
                                m_FieldInfoMap = new Dictionary <FieldInfo, ShaderAnalyzedDataTooltipAttribute>();

                                Type type = shader.GetType();

                                FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);

                                for (int n = 0; n < fields.Length; n++)
                                {
                                    FieldInfo field = fields[n];
                                    ShaderAnalyzedDataTooltipAttribute attribute = field.GetCustomAttribute <ShaderAnalyzedDataTooltipAttribute>();
                                    m_FieldInfoMap.Add(field, attribute);
                                }
                            }

                            m_List.Add(shader);

                            m_ParamMap.Add(shader, new ShaderParem()
                            {
                                Subshader = subshader, SubshaderIndex = i, Pass = pass, PassIndex = j, Variant = variant, VariantIndex = k
                            });
                        }
                    }
                }
            }
        }
        protected override int init(AnalyzeWrap wrap, ShaderAnalyzeParams param)
        {
            int  count             = 0;
            bool shaderDisassembly = false;

            AnalyzedSubshaderData currentSubshader = null;
            AnalyzedPassData      currentPass      = null;
            AnalyzedVariantData   currentVariant   = null;

            using (StreamReader sr = new StreamReader(wrap.CompiledShaderFilePath))
            {
                string line      = string.Empty;
                int    lineCount = 0;
                while ((line = sr.ReadLine()) != null)
                {
                    lineCount++;
                    //wrap.SourceCode.Add(line);
                    if (Regex.IsMatch(line, "^Shader \"\\S+\" {$"))
                    {
                        m_BraceStack.AddLast(EBraceRegionType.ShaderMain);
                        currentSubshader = new AnalyzedSubshaderData();
                        wrap.Subshaders.Add(currentSubshader);
                        wrap.AnalyzedData.Subshaders.Add(currentSubshader);
                    }
                    else if (line == "Properties {")
                    {
                        m_BraceStack.AddLast(EBraceRegionType.Properties);
                    }
                    else if (line == "SubShader { ")
                    {
                        m_BraceStack.AddLast(EBraceRegionType.SubShader);
                    }
                    else if (line == " Pass {")
                    {
                        m_BraceStack.AddLast(EBraceRegionType.Pass);

                        currentPass = new AnalyzedPassData();
                        currentSubshader.Passes.Add(currentPass);
                        wrap.Passes.Add(currentPass);
                    }
                    else if (line.StartsWith("Global Keywords: "))
                    {
                        m_BraceStack.AddLast(EBraceRegionType.Variant);

                        currentVariant = new AnalyzedVariantData();
                        currentPass.Variants.Add(currentVariant);
                        wrap.Variants.Add(currentVariant);
                        count++;
                    }
                    else if (line.StartsWith("Constant Buffer "))
                    {
                        m_BraceStack.AddLast(EBraceRegionType.Constant);
                    }
                    else if (line == "{")
                    {
                        m_BraceStack.AddLast(EBraceRegionType.Function);
                    }
                    else if (line == "}")
                    {
                        m_BraceStack.RemoveLast();
                    }
                    else if (line == "Shader Disassembly:")
                    {
                        if (shaderDisassembly)
                        {
                            m_BraceStack.RemoveLast();
                        }

                        shaderDisassembly = !shaderDisassembly;
                    }

                    if (m_BraceStack.Count > 0)
                    {
                        switch (m_BraceStack.Last.Value)
                        {
                        case EBraceRegionType.SubShader:
                            currentSubshader.SourceCodeLines.Add(line);
                            break;

                        case EBraceRegionType.Pass:
                            currentSubshader.SourceCodeLines.Add(line);
                            currentPass.SourceCodeLines.Add(line);
                            break;

                        case EBraceRegionType.Variant:
                        case EBraceRegionType.Constant:
                        case EBraceRegionType.Function:
                            currentSubshader.SourceCodeLines.Add(line);
                            currentPass.SourceCodeLines.Add(line);
                            currentVariant.SourceCodeLines.Add(line);
                            break;
                        }
                    }
                }
            }

            //TODO 这里可以改为逐帧读取
            return(InitFinish);
        }
Ejemplo n.º 5
0
        public override void Draw()
        {
            for (int i = 0; i < m_AnalyzedData.Subshaders.Count; i++)
            {
                AnalyzedSubshaderData subshader = m_AnalyzedData.Subshaders[i];

                if (drawHeader(subshader, EDataType.Subshader, i.ToString(), string.Empty))
                {
                    EditorGUILayout.BeginVertical();
                    GUITools.BeginContents(GUITools.Styles.HelpBoxStyle);
                    EditorGUILayout.LabelField("LOD : ", subshader.LOD.ToString());

                    for (int j = 0; j < subshader.Passes.Count; j++)
                    {
                        AnalyzedPassData pass = subshader.Passes[j];

                        if (drawHeader(pass, EDataType.Pass, j.ToString(), pass.PassName))
                        {
                            GUITools.BeginContents(GUITools.Styles.HelpBoxStyle);

                            EditorGUILayout.LabelField("Name : ", pass.PassName);

                            for (int k = 0; k < pass.Variants.Count; k++)
                            {
                                AnalyzedVariantData variant = pass.Variants[k];

                                //TODO 这里需要分页,避免变体过多导致GUI卡顿

                                if (drawHeader(variant, EDataType.Variant, k.ToString(), getShortVariantName(variant.VariantName)))
                                {
                                    GUITools.BeginContents(GUITools.Styles.HelpBoxStyle);
                                    EditorGUILayout.LabelField("Name : ", variant.VariantName);

                                    ShaderDataDrawerBase drawer;
                                    if (!ShaderDrawer.TryGetValue(variant.GPUVendorType, out drawer))
                                    {
                                        Debug.LogError("无法获取到" + variant.GPUVendorType.ToString() + "的绘制器");
                                    }
                                    else
                                    {
                                        for (int l = 0; l < variant.Shaders.Count; l++)
                                        {
                                            AnalyzedShaderDataBase shader = variant.Shaders[l];

                                            if (drawHeader(shader, EDataType.Shader, shader.ShaderType.ToString(), string.Empty))
                                            {
                                                GUITools.BeginContents(GUITools.Styles.HelpBoxStyle);

                                                if (!string.IsNullOrEmpty(shader.ERROR))
                                                {
                                                    EditorGUILayout.HelpBox(shader.ERROR, MessageType.Error);
                                                }
                                                else
                                                {
                                                    drawer.Draw(shader);
                                                }

                                                GUITools.EndContents();
                                            }
                                        }
                                    }
                                    GUITools.EndContents();
                                }
                            }

                            GUITools.EndContents();
                        }
                    }
                    GUITools.EndContents();
                    EditorGUILayout.EndVertical();
                }
            }
        }