Ejemplo n.º 1
0
        public IResultSet Compile(IShader sh, IBackendOptions options)
        {
            if (sh.Language != Languages.GLSL)
                return null;

            GLSLShader glShader = (GLSLShader)sh;
            IGLSLOptions glOpts = glShader.CompileOptions;
            string shader = glShader.Code;

            string shaderSwitch = "";
            switch (glOpts.ShaderType)
            {
                case GLSLShaderType.VERTEX:   shaderSwitch = "-v"; break;
                case GLSLShaderType.FRAGMENT: shaderSwitch = "-f"; break;
                case GLSLShaderType.COMPUTE:  shaderSwitch = "-c"; break;
                default:
                    return null;
            }

            string tmpFile         = Path.Combine(m_TempPath, "PYRAMID_pvr");
            string dummyOutputFile = Path.Combine(m_TempPath, "PYRAMID_pvr.out");
            string disasmFile      = Path.Combine(m_TempPath, "PYRAMID_pvr.disasm");
            try
            {
                StreamWriter stream = File.CreateText(tmpFile);
                stream.Write(shader);
                stream.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "uh-oh, couldn't create temp file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return null;
            }

            string args = String.Format("{0} {1} {2} -disasm", tmpFile, dummyOutputFile, shaderSwitch);

            PVRResultSet rs = new PVRResultSet();

            foreach (string s in m_Compilers)
            {
                ProcessStartInfo pi = new ProcessStartInfo();
                pi.RedirectStandardOutput = true;
                pi.RedirectStandardInput = true;
                pi.RedirectStandardError = true;
                pi.CreateNoWindow = true;
                pi.Arguments = args;
                pi.FileName  = s;
                pi.UseShellExecute = false;

                try
                {
                    Process p= Process.Start(pi);
                    p.WaitForExit();

                    string asm = "No Output";
                    string output = p.StandardError.ReadToEnd();
                    string compiler = Path.GetFileNameWithoutExtension(s);

                    if (File.Exists(disasmFile))
                    {
                        asm = File.ReadAllText(disasmFile);
                        File.Delete(disasmFile);
                    }

                    rs.PVRResultsPanel.AddResult(compiler, output, asm);
                }
                catch (System.Exception)
                {
                    continue;
                }
            }

            File.Delete(tmpFile);

            return rs;
        }
Ejemplo n.º 2
0
        public IResultSet Compile(IShader sh, IBackendOptions options)
        {
            if (sh.Language != Languages.GLSL)
            {
                return(null);
            }

            GLSLShader   glShader = (GLSLShader)sh;
            IGLSLOptions glOpts   = glShader.CompileOptions;
            string       shader   = glShader.Code;


            string shaderSwitch = "";

            switch (glOpts.ShaderType)
            {
            case GLSLShaderType.VERTEX:   shaderSwitch = "-v"; break;

            case GLSLShaderType.FRAGMENT: shaderSwitch = "-f"; break;

            case GLSLShaderType.COMPUTE:  shaderSwitch = "-c"; break;

            default:
                return(null);
            }

            string tmpFile         = Path.Combine(m_TempPath, "PYRAMID_pvr");
            string dummyOutputFile = Path.Combine(m_TempPath, "PYRAMID_pvr.out");
            string disasmFile      = Path.Combine(m_TempPath, "PYRAMID_pvr.disasm");

            try
            {
                StreamWriter stream = File.CreateText(tmpFile);
                stream.Write(shader);
                stream.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "uh-oh, couldn't create temp file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }

            string args = String.Format("{0} {1} {2} -disasm", tmpFile, dummyOutputFile, shaderSwitch);


            PVRResultSet rs = new PVRResultSet();

            foreach (string s in m_Compilers)
            {
                ProcessStartInfo pi = new ProcessStartInfo();
                pi.RedirectStandardOutput = true;
                pi.RedirectStandardInput  = true;
                pi.RedirectStandardError  = true;
                pi.CreateNoWindow         = true;
                pi.Arguments       = args;
                pi.FileName        = s;
                pi.UseShellExecute = false;

                try
                {
                    Process p = Process.Start(pi);

                    string asm      = "No Output";
                    string output   = p.StandardError.ReadToEnd();
                    string compiler = Path.GetFileNameWithoutExtension(s);

                    p.WaitForExit();

                    if (File.Exists(disasmFile))
                    {
                        asm = File.ReadAllText(disasmFile);
                        File.Delete(disasmFile);
                    }

                    rs.PVRResultsPanel.AddResult(compiler, output, asm);
                }
                catch (System.Exception)
                {
                    continue;
                }
            }

            File.Delete(tmpFile);

            return(rs);
        }