protected override int init(AnalyzeWrap wrap, ShaderAnalyzeParams param)
        {
            m_CompiledShaderPath   = ShaderAnalyzerUtil.GetCompiledShaderPath(param);
            m_AnalyzedDataFilePath = ShaderAnalyzerUtil.GetChacheFileName(param);
            m_MD5 = ShaderAnalyzerUtil.GenerateMD5(m_CompiledShaderPath);

            if (!Directory.Exists(Constant.CacheFolder))
            {
                Directory.CreateDirectory(Constant.CacheFolder);
                return(create());
            }
            else
            {
                if (!File.Exists(m_AnalyzedDataFilePath))
                {
                    return(create());
                }
                else
                {
                    CacheHead head = ShaderAnalyzerUtil.GetHeadFromCache(m_AnalyzedDataFilePath);
                    if (head == null || Constant.Version != head.Version || head.MD5 != m_MD5)
                    {
                        return(create());
                    }
                    else
                    {
                        return(loadFromCache(head));
                    }
                }
            }
        }
        protected override int init(AnalyzeWrap wrap, ShaderAnalyzeParams param)
        {
            ShaderAnalyzerUtil.ChangeIDEToBridge();

            ShaderCompilerPlatform platform = ShaderCompilerPlatform.GLES3x;

            switch (param.APIType)
            {
            case EAPIType.OpenGLES:
                platform = ShaderCompilerPlatform.GLES3x;
                break;

            case EAPIType.Vulkan:
                platform = ShaderCompilerPlatform.Vulkan;
                break;
            }

            ShaderAnalyzerUtil.OpenCompiledShader.Invoke(null, new object[] { param.Shader, 3, 1 << (int)platform, !param.SkipUnusedVariant });

            ShaderAnalyzerUtil.RevertIDESettings();

            Thread thread = new Thread(new ThreadStart(supervisor));

            thread.Start();

            return(InitUnknown);
        }
Пример #3
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);
        }
Пример #4
0
        /// <summary>
        /// 解析着色器
        /// </summary>
        /// <param name="param">解析参数</param>
        /// <param name="callback">解析完成回调</param>
        public void Analyze(ShaderAnalyzeParams param, AnalyzeFinish callback)
        {
            if (m_CurrentStageType != EAnalyzeStageType.None)
            {
                Debug.LogError("当前正在进行解析,请耐心等待。");
                return;
            }
            if (param.Shader == null)
            {
                Debug.LogError("请指定要解析的着色器。");
                return;
            }
            if (callback == null)
            {
                Debug.LogError("请指定解析完整的回调函数。");
                return;
            }


            m_Params        = param;
            m_AnalyzeFinish = callback;

            m_AnalyzeWrap = new AnalyzeWrap();

            executeNext();

            EditorApplication.update += update;
        }
        private ShaderAnalyzeParams getAnalyzeParams()
        {
            ShaderAnalyzeParams param = new ShaderAnalyzeParams()
            {
                Shader            = m_CurrentShader,
                APIType           = m_APIType,
                SkipUnusedVariant = m_SkipUnused,
                Vendor            = m_CurrentVendor != null ? m_CurrentVendor.VendorType : EGPUVendorType.Mali,
                GPUModel          = m_CurrentVendor != null ? m_CurrentVendor.Models[m_GPUModelsSelected] : null
            };

            return(param);
        }
Пример #6
0
        protected override int init(AnalyzeWrap wrap, ShaderAnalyzeParams param)
        {
            if (Directory.Exists(Constant.SAWorkSpace))
            {
                Directory.Delete(Constant.SAWorkSpace, true);
            }

            string json = JsonUtility.ToJson(m_AnalyzeWrap.AnalyzedData, true);

            using (StreamWriter sw = new StreamWriter(wrap.AnalyzedDataCacheFilePath))
            {
                sw.WriteLine(wrap.Head.Head);
                sw.WriteLine(json);
            }
            return(InitComplete);
        }
Пример #7
0
 private void Clear()
 {
     EditorUtility.ClearProgressBar();
     EditorApplication.update -= update;
     m_CurrentStageType        = EAnalyzeStageType.None;
     m_CurrentStage            = null;
     m_AnalyzeWrap             = null;
     m_Params        = null;
     m_AnalyzeFinish = null;
     foreach (var item in AnalyzedStageMap)
     {
         foreach (var item1 in item.Value)
         {
             item1.Value.Clear();
         }
     }
 }
 protected override int init(AnalyzeWrap wrap, ShaderAnalyzeParams param)
 {
     return(wrap.Variants.Count);
 }
        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);
        }
Пример #10
0
        /// <summary>
        /// 获取解析数据缓存文件名
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public static string GetChacheFileName(ShaderAnalyzeParams param)
        {
            string shaderName = param.Shader.name.Replace("/", "-");

            return(string.Format(Constant.AnalyzedDataCachePathFormat, shaderName, param.APIType, param.Vendor, param.GPUModel, param.SkipUnusedVariant));
        }
Пример #11
0
 /// <summary>
 /// 获取编译后着色器的路径
 /// </summary>
 /// <param name="param"></param>
 /// <returns></returns>
 public static string GetCompiledShaderPath(ShaderAnalyzeParams param)
 {
     return(string.Format(Constant.CompiledShaderPathFormat, param.Shader.name.Replace('/', '-')));
 }