Beispiel #1
0
        private static void GenerateCombo(MyStringId materialId, MyStringId passId, MyShaderUnifiedFlags additionalFlags, MyShaderUnifiedFlags unsupportedFlags, MatCombos.Combo[] comboList1, MatCombos.Combo[] comboList2,
                                          float progress, OnShaderCacheProgressDelegate onShaderCacheProgress)
        {
            if (comboList1 == null || comboList1.Length == 0)
            {
                comboList1 = new[] { new MatCombos.Combo() }
            }
            ;
            if (comboList2 == null || comboList2.Length == 0)
            {
                comboList2 = new[] { new MatCombos.Combo() }
            }
            ;
            for (int k = 0; k < comboList1.Length; k++)
            {
                MyVertexInputComponentType[] vertexInput1 = comboList1[k].VertexInput;
                if (vertexInput1 == null)
                {
                    vertexInput1 = new MyVertexInputComponentType[0];
                }
                int[] vertexInputOrder1 = comboList1[k].VertexInputOrder;
                if (vertexInputOrder1 == null || vertexInputOrder1.Length != vertexInput1.Length)
                {
                    vertexInputOrder1 = new int[vertexInput1.Length];
                    for (int x = 0; x < vertexInput1.Length; x++)
                    {
                        vertexInputOrder1[x] = x;
                    }
                }
                MyShaderUnifiedFlags flags1 = ParseFlags(comboList1[k].FlagNames);
                if ((flags1 & unsupportedFlags) != 0)
                {
                    continue;
                }

                // go through all combinations of shader flags
                for (int l = 0; l < comboList2.Length; l++)
                {
                    MyVertexInputComponentType[] vertexInput2 = comboList2[l].VertexInput;
                    if (vertexInput2 == null)
                    {
                        vertexInput2 = new MyVertexInputComponentType[0];
                    }
                    int[] vertexInputOrder2 = comboList2[l].VertexInputOrder;
                    if (vertexInputOrder2 == null || vertexInputOrder2.Length != vertexInput2.Length)
                    {
                        vertexInputOrder2 = new int[vertexInput2.Length];
                        for (int x = 0; x < vertexInput2.Length; x++)
                        {
                            vertexInputOrder2[x] = x;
                        }
                    }
                    var vertexInput      = vertexInput1.Concat(vertexInput2).ToArray();
                    var vertexInputOrder = vertexInputOrder1.Concat(vertexInputOrder2).ToArray();
                    Array.Sort(vertexInputOrder, vertexInput, m_intComparer);
                    VertexLayoutId vertexLayout;
                    if (vertexInput.Length != 0)
                    {
                        vertexLayout = MyVertexLayouts.GetLayout(vertexInput);
                    }
                    else
                    {
                        vertexLayout = MyVertexLayouts.Empty;
                    }

                    // return errors & skipped info
                    string vsSource;
                    string psSource;
                    MyMaterialShaders.Preprocess(materialId, passId, vertexLayout.Info, out vsSource, out psSource);

                    MyShaderUnifiedFlags flags = ParseFlags(comboList2[l].FlagNames) | flags1 | additionalFlags;
                    if ((flags & unsupportedFlags) != 0)
                    {
                        continue;
                    }

                    var macros             = MyMaterialShaders.GenerateMaterialShaderFlagMacros(flags);
                    var descriptor         = String.Format("{0}_{1}", materialId.ToString(), passId.ToString());
                    var vertexLayoutString = vertexLayout.Info.Components.GetString();

                    PreCompile(vsSource, macros, MyShadersDefines.Profiles.vs_5_0, descriptor, vertexLayoutString, progress, onShaderCacheProgress);
                    PreCompile(psSource, macros, MyShadersDefines.Profiles.ps_5_0, descriptor, vertexLayoutString, progress, onShaderCacheProgress);
                    macros.Add(m_globalMacros[0]);
                    for (int m = 0; m < m_globalMacros.Length; m++)
                    {
                        macros[macros.Count - 1] = m_globalMacros[m];
                        //PreCompile(vsSource, macros, MyShadersDefines.Profiles.vs_5_0, descriptor, vertexLayoutString, progress, onShaderCacheProgress);
                        PreCompile(psSource, macros, MyShadersDefines.Profiles.ps_5_0, descriptor, vertexLayoutString, progress, onShaderCacheProgress);
                    }
                }
            }
        }
        private static void GenerateCombo(MyStringId materialId, MyStringId passId, MyShaderUnifiedFlags additionalFlags, MyShaderUnifiedFlags unsupportedFlags, CacheGenerator.Combo[] comboList1, CacheGenerator.Combo[] comboList2,
                                          float progress, OnShaderCacheProgressDelegate onShaderCacheProgress)
        {
            if (comboList1 == null || comboList1.Length == 0)
            {
                comboList1 = new[] { new CacheGenerator.Combo() }
            }
            ;
            if (comboList2 == null || comboList2.Length == 0)
            {
                comboList2 = new[] { new CacheGenerator.Combo() }
            }
            ;
            for (int k = 0; k < comboList1.Length; k++)
            {
                MyVertexInputComponentType[] vertexInput1 = comboList1[k].VertexInput;
                if (vertexInput1 == null)
                {
                    vertexInput1 = new MyVertexInputComponentType[0];
                }
                int[] vertexInputOrder1 = comboList1[k].VertexInputOrder;
                if (vertexInputOrder1 == null || vertexInputOrder1.Length != vertexInput1.Length)
                {
                    vertexInputOrder1 = new int[vertexInput1.Length];
                    for (int x = 0; x < vertexInput1.Length; x++)
                    {
                        vertexInputOrder1[x] = x;
                    }
                }
                MyShaderUnifiedFlags flags1 = ParseFlags(comboList1[k].FlagNames);
                if ((flags1 & unsupportedFlags) != 0)
                {
                    continue;
                }

                // go through all combinations of shader flags
                for (int l = 0; l < comboList2.Length; l++)
                {
                    MyVertexInputComponentType[] vertexInput2 = comboList2[l].VertexInput;
                    if (vertexInput2 == null)
                    {
                        vertexInput2 = new MyVertexInputComponentType[0];
                    }
                    int[] vertexInputOrder2 = comboList2[l].VertexInputOrder;
                    if (vertexInputOrder2 == null || vertexInputOrder2.Length != vertexInput2.Length)
                    {
                        vertexInputOrder2 = new int[vertexInput2.Length];
                        for (int x = 0; x < vertexInput2.Length; x++)
                        {
                            vertexInputOrder2[x] = x;
                        }
                    }
                    var vertexInput      = vertexInput1.Concat(vertexInput2).ToArray();
                    var vertexInputOrder = vertexInputOrder1.Concat(vertexInputOrder2).ToArray();
                    Array.Sort(vertexInputOrder, vertexInput, m_intComparer);
                    VertexLayoutId vertexLayout;
                    if (vertexInput.Length != 0)
                    {
                        vertexLayout = MyVertexLayouts.GetLayout(vertexInput);
                    }
                    else
                    {
                        vertexLayout = MyVertexLayouts.Empty;
                    }

                    MyShaderUnifiedFlags flags = ParseFlags(comboList2[l].FlagNames) | flags1 | additionalFlags;
                    var macros = new List <ShaderMacro>();
                    macros.Add(MyMaterialShaders.GetRenderingPassMacro(passId.String));
                    MyMaterialShaders.AddMaterialShaderFlagMacrosTo(macros, flags);
                    macros.AddRange(vertexLayout.Info.Macros);

                    // return errors & skipped info
                    MyMaterialShaderInfo sources;
                    MyMaterialShaders.GetMaterialSources(materialId, out sources);

                    if ((flags & unsupportedFlags) != 0)
                    {
                        continue;
                    }

                    var vertexLayoutString = vertexLayout.Info.Components.GetString();

                    string vsDescriptor = MyMaterialShaders.GetShaderDescriptor(sources.VertexShaderFilename, materialId.String, passId.String, vertexLayout);
                    PreCompile(sources.VertexShaderFilepath, macros, MyShaderProfile.vs_5_0, vsDescriptor, vertexLayoutString, progress, onShaderCacheProgress);

                    string psDescriptor = MyMaterialShaders.GetShaderDescriptor(sources.PixelShaderFilename, materialId.String, passId.String, vertexLayout);
                    PreCompile(sources.PixelShaderFilepath, macros, MyShaderProfile.ps_5_0, psDescriptor, vertexLayoutString, progress, onShaderCacheProgress);
                    macros.Add(m_globalMacros[0]);
                    for (int m = 0; m < m_globalMacros.Length; m++)
                    {
                        macros[macros.Count - 1] = m_globalMacros[m];
                        //PreCompile(sources.VertexShaderFilepath, macros, MyShadersDefines.Profiles.vs_5_0, vsDescriptor, vertexLayoutString, progress, onShaderCacheProgress);
                        PreCompile(sources.PixelShaderFilepath, macros, MyShaderProfile.ps_5_0, psDescriptor, vertexLayoutString, progress, onShaderCacheProgress);
                    }
                }
            }
        }