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);
                        }
                    }
                }
            }
        }
        private bool drawHeader(AnalyzedBase analyzed, EDataType type, string index, string name)
        {
            string subshaderFolderName     = string.Format("{0} {1} {2}", type.ToString(), index, name);
            AnalyzedShaderDataBase shader  = analyzed as AnalyzedShaderDataBase;
            GUIContent             content = new GUIContent(subshaderFolderName, shader != null ? shader.SourceCode : string.Empty);

            m_FolderMap[analyzed] = GUITools.DrawHeader(content, false, m_FolderMap[analyzed], true);

            return(m_FolderMap[analyzed]);
        }
        /// <summary>
        /// 序列化之前被Unity自动调用,将Shaders中存储的AnalyzedShaderDataBase基类序列化成Json存储在m_ShaderSerialized数组中
        /// </summary>
        public void OnBeforeSerialize()
        {
            if (Shaders == null)
            {
                return;
            }
            m_ShaderSerialized = new string[Shaders.Count];

            for (int i = 0; i < Shaders.Count; i++)
            {
                AnalyzedShaderDataBase asdb = Shaders[i];
                string json = JsonUtility.ToJson(asdb);
                m_ShaderSerialized[i] = json;
            }
        }
Пример #4
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
                            });
                        }
                    }
                }
            }
        }
Пример #5
0
        public override bool Draw(AnalyzedShaderDataBase data)
        {
            MaliAnalyzedShaderData maliShader = data as MaliAnalyzedShaderData;

            if (maliShader == null)
            {
                Debug.LogError("数据无法转换成 MaliAnalyzedShaderData !");
                return(false);
            }

            EditorGUILayout.LabelField("工作寄存器使用情况 : ", maliShader.WorkRegisterUsed.ToString());
            EditorGUILayout.LabelField("Uniform寄存器使用情况 : ", maliShader.UniformRegistersUsed.ToString());
            EditorGUILayout.LabelField("溢出到栈 : ", maliShader.StackSpilling.ToString());

            drawCycles("总指令周期 : ", maliShader.TotalArithmeticCycles, maliShader.TotalLoad_StoreCycles, maliShader.TotalVaryingCycles, maliShader.TotalTextureCycles, maliShader.TotalBound);
            drawCycles("最短路径指令周期 : ", maliShader.ShortestPathArithmeticCycles, maliShader.ShortestPathLoad_StoreCycles, maliShader.ShortestPathVaryingCycles, maliShader.ShortestPathTextureCycles, maliShader.ShortestPathBound);
            drawCycles("最长路径指令周期 : ", maliShader.LongestPathArithmeticCycles, maliShader.LongestPathLoad_StoreCycles, maliShader.LongestPathVaryingCycles, maliShader.LongestPathTextureCycles, maliShader.LongestPathBound);

            EditorGUILayout.LabelField("存在Uniform计算 : ", maliShader.UniformComputation.ToString());

            return(true);
        }
        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();
                }
            }
        }
Пример #7
0
        public override void Draw()
        {
            GUITools.BeginContents(GUITools.Styles.WizardBoxStyle);

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button(m_CurrentSortField != null ? "着色器类型" : (m_DescendingOrder ? "着色器类型 ▼" : "着色器类型 ▲"), GUILayout.MinWidth(m_MINWIDTH)))
            {
                if (m_CurrentSortField != null)
                {
                    m_DescendingOrder  = false;
                    m_CurrentSortField = null;
                }
                else
                {
                    m_DescendingOrder = !m_DescendingOrder;
                }

                m_List.Sort(sort);
            }
            GUILayout.Button(new GUIContent("源代码", "点击着色器代码可以复制到剪贴板"), GUILayout.MinWidth(m_MINWIDTH));

            foreach (var item in m_FieldInfoMap)
            {
                bool click = false;

                GUIContent buttonText;
                if (item.Value != null)
                {
                    buttonText = new GUIContent(item.Value.Abbreviate, item.Value.Tooltip);
                }
                else
                {
                    buttonText = new GUIContent(item.Key.Name);
                }

                if (m_CurrentSortField == item.Key)
                {
                    buttonText.text = buttonText.text + (m_DescendingOrder ? " ▼" : " ▲");
                }

                click = GUILayout.Button(buttonText, GUILayout.MinWidth(m_MINWIDTH));

                if (click)
                {
                    if (m_CurrentSortField != item.Key)
                    {
                        m_DescendingOrder = true;
                    }
                    else
                    {
                        m_DescendingOrder = !m_DescendingOrder;
                    }

                    m_CurrentSortField = item.Key;
                    m_List.Sort(sort);
                }
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginVertical();
            for (int i = 0; i < m_List.Count; i++)
            {
                //TODO 这里需要分页,避免着色器过多导致GUI卡顿

                AnalyzedShaderDataBase shader = m_List[i];
                if (!string.IsNullOrEmpty(shader.ERROR))
                {
                    GUILayout.Button(shader.ERROR);
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();

                    ShaderParem param = m_ParamMap[shader];
                    GUILayout.Button(new GUIContent(shader.ShaderType.ToString(), getTooltip(param)), GUILayout.MinWidth(m_MINWIDTH));

                    if (GUILayout.Button(new GUIContent("着色器代码", shader.SourceCode), GUILayout.MinWidth(m_MINWIDTH)))
                    {
                        GUIUtility.systemCopyBuffer = shader.SourceCode;
                    }

                    foreach (var item in m_FieldInfoMap)
                    {
                        FieldInfo field = item.Key;
                        GUILayout.Button(field.GetValue(shader).ToString(), GUILayout.MinWidth(m_MINWIDTH));
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
            EditorGUILayout.EndVertical();
            GUITools.EndContents();
        }
Пример #8
0
        private int sort(AnalyzedShaderDataBase s0, AnalyzedShaderDataBase s1)
        {
            bool greater = false;

            if (m_CurrentSortField == null)
            {
                ShaderParem param0 = m_ParamMap[s0];
                ShaderParem param1 = m_ParamMap[s1];

                if (param0.SubshaderIndex == param1.SubshaderIndex)
                {
                    if (param0.PassIndex == param1.PassIndex)
                    {
                        if (param0.VariantIndex == param1.VariantIndex)
                        {
                            return(0);
                        }
                        else
                        {
                            greater = param0.VariantIndex > param1.VariantIndex;
                        }
                    }
                    else
                    {
                        greater = param0.PassIndex > param1.PassIndex;
                    }
                }
                else
                {
                    greater = param0.SubshaderIndex > param1.SubshaderIndex;
                }
            }
            else
            {
                object value0 = m_CurrentSortField.GetValue(s0);
                object value1 = m_CurrentSortField.GetValue(s1);
                if (m_CurrentSortField.FieldType == typeof(int))
                {
                    int intValue0 = (int)value0;
                    int intValue1 = (int)value1;
                    if (intValue0 == intValue1)
                    {
                        return(0);
                    }
                    greater = intValue0 > intValue1;
                }
                else if (m_CurrentSortField.FieldType == typeof(float))
                {
                    float floatValue0 = (float)value0;
                    float floatValue1 = (float)value1;
                    if (floatValue0 == floatValue1)
                    {
                        return(0);
                    }
                    greater = floatValue0 > floatValue1;
                }
                else if (m_CurrentSortField.FieldType == typeof(long))
                {
                    long longValue0 = (long)value0;
                    long longValue1 = (long)value1;
                    if (longValue0 == longValue1)
                    {
                        return(0);
                    }
                    greater = longValue0 > longValue1;
                }
                else if (m_CurrentSortField.FieldType == typeof(double))
                {
                    double doubleValue0 = (double)value0;
                    double doubleValue1 = (double)value1;
                    if (doubleValue0 == doubleValue1)
                    {
                        return(0);
                    }
                    greater = doubleValue0 > doubleValue1;
                }
                else if (m_CurrentSortField.FieldType == typeof(short))
                {
                    short shortValue0 = (short)value0;
                    short shortValue1 = (short)value1;
                    if (shortValue0 == shortValue1)
                    {
                        return(0);
                    }
                    greater = shortValue0 > shortValue1;
                }
                else if (m_CurrentSortField.FieldType == typeof(bool))
                {
                    bool boolValue0 = (bool)value0;
                    bool boolValue1 = (bool)value1;
                    if (boolValue0 == boolValue1)
                    {
                        return(0);
                    }
                    greater = boolValue0;
                }
                else if (m_CurrentSortField.FieldType.IsEnum)
                {
                    int enumValue0 = (int)value0;
                    int enumValue1 = (int)value1;
                    if (enumValue0 == enumValue1)
                    {
                        return(0);
                    }
                    greater = enumValue0 > enumValue1;
                }
                else if (m_CurrentSortField.FieldType == typeof(string))
                {
                    string stringValue0 = (string)value0;
                    string stringValue1 = (string)value1;
                    if (string.Compare(stringValue0, stringValue1, StringComparison.Ordinal) == 0)
                    {
                        return(0);
                    }

                    greater = string.Compare(stringValue0, stringValue1, StringComparison.Ordinal) > 0;
                }
            }

            if (!m_DescendingOrder)
            {
                return(greater ? 1 : -1);
            }
            else
            {
                return(greater ? -1 : 1);
            }
        }