Example #1
0
        public IResultSet Compile(IShader shader, IBackendOptions options)
        {
            if (!(shader is GLSLShader))
            {
                return(null);
            }

            GLSLShader   sh     = (GLSLShader)shader;
            IGLSLOptions glOpts = sh.CompileOptions;

            GLSlangOptions slangOpts = new GLSlangOptions();

            slangOpts.ShaderType = glOpts.ShaderType;
            slangOpts.Config     = m_Config;
            GLSlang.IShader result = m_Compiler.Compile(sh.Code, slangOpts);
            return(new GLSLangResultSet(result));
        }
Example #2
0
        public IResultSet Compile(IShader shader, IBackendOptions options)
        {
            if (!(shader is GLSLShader))
            {
                return(null);
            }

            GLSLShader   sh     = (GLSLShader)shader;
            IGLSLOptions glOpts = sh.CompileOptions;

            if (glOpts.OptimizerOptions == null)
            {
                return(null);
            }

            GLSLOptimizer.IOptimizer optimizer = m_Optimizers[glOpts.OptimizerTarget];
            return(new GLSLOptimizerResultSet(optimizer.Optimize(sh.Code, glOpts.OptimizerOptions)));
        }
Example #3
0
 GLSlang.IShader CompileShader(IShader shader)
 {
     if (shader is HLSLShader)
     {
         // pass the shader through GLSLang's hlsl front end
         HLSLShader hlsl = shader as HLSLShader;
         return(m_GLSLang.CompileHLSL(shader.Code, hlsl.CompileOptions, m_GLSLangConfig, shader.SourceFilePath));
     }
     else if (shader is GLSLShader)
     {
         GLSLShader glsl = shader as GLSLShader;
         return(m_GLSLang.Compile(shader.Code, glsl.CompileOptions.ShaderType, m_GLSLangConfig, glsl.SourceFilePath));
     }
     else
     {
         throw new System.Exception("Bad shader type?!?");
     }
 }
Example #4
0
        public IResultSet Compile(IShader shader, IBackendOptions options)
        {
            if (shader is GLSLShader)
            {
                GLSLShader   sh     = (GLSLShader)shader;
                IGLSLOptions glOpts = sh.CompileOptions;

                GLSlang.IShader result = m_Compiler.Compile(sh.Code, glOpts.ShaderType, m_Config, shader.SourceFilePath);
                return(new GLSLangResultSet(result));
            }
            else if (shader is HLSLShader)
            {
                HLSLShader   sh       = (HLSLShader)shader;
                IHLSLOptions hlslOpts = sh.CompileOptions;

                GLSlang.IShader result = m_Compiler.CompileHLSL(sh.Code, hlslOpts, m_Config, shader.SourceFilePath);
                return(new GLSLangResultSet(result));
            }
            else
            {
                return(null);
            }
        }
Example #5
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 shaderType = "";

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

            case GLSLShaderType.FRAGMENT: shaderType = "--fragment"; break;

            case GLSLShaderType.COMPUTE:  shaderType = "--compute";  break;

            default:
                return(null);
            }

            string tmpFile = Path.Combine(m_TempPath, "PYRAMID_mali");

            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);
            }

            MaliSCResultSet rs = new MaliSCResultSet();

            try
            {
                foreach (string asic in m_Asics)
                {
                    string           commandline = String.Format("-V {0} -c {1} {2}", shaderType, asic, tmpFile);
                    ProcessStartInfo pi          = new ProcessStartInfo();
                    pi.RedirectStandardOutput = true;
                    pi.RedirectStandardInput  = true;
                    pi.RedirectStandardError  = true;
                    pi.EnvironmentVariables.Add("MALICM_LOCATION", m_MaliRoot);
                    pi.CreateNoWindow  = true;
                    pi.Arguments       = commandline;
                    pi.FileName        = Path.Combine(m_MaliRoot, "malisc.exe");
                    pi.UseShellExecute = false;

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

                    string output = p.StandardOutput.ReadToEnd();
                    rs.Add(asic, output);
                }
            }
            catch (System.Exception e)
            {
                MessageBox.Show(e.Message, "uh-oh, couldn't run MaliSC", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            File.Delete(tmpFile);

            return(rs);
        }
Example #6
0
        private void btnCompile_Click(object sender, EventArgs e)
        {
            if (m_CompileOptionsPanel == null)
            {
                return;
            }

            this.UseWaitCursor = true;

            ClearResults();

            IResultSet SelectedResultSet = null;

            ICompileOptions opts = m_CompileOptionsPanel.ReadOptions();

            IShader shader = null;

            switch (opts.Language)
            {
            case Languages.GLSL:
                shader = new GLSLShader(txtCode.Text, opts as IGLSLOptions); break;

            case Languages.HLSL:
                shader = new HLSLShader(txtCode.Text, opts as IHLSLOptions); break;

            default:
                throw new System.Exception("Unsupported language");
            }

            foreach (IBackend backend in m_Backends)
            {
                if (m_Options.IsBackendDisabled(backend.Name))
                {
                    continue;
                }

                IBackendOptions options = null;

                if (backend is AMDDriverBackend)
                {
                    AMDDriverBackend amdBackend     = backend as AMDDriverBackend;
                    List <string>    requestedAsics = new List <string>();
                    foreach (string asic in amdBackend.Asics)
                    {
                        if (!m_Options.IsAMDAsicDisabled(asic))
                        {
                            requestedAsics.Add(asic);
                        }
                    }
                    AMDDriverBackendOptions backendOptions = new AMDDriverBackendOptions(requestedAsics);
                    options = backendOptions;
                }
                else if (backend is CodeXLBackend)
                {
                    CodeXLBackend codeXLBackend  = backend as CodeXLBackend;
                    List <string> requestedAsics = new List <string>();
                    foreach (string asic in codeXLBackend.Asics)
                    {
                        if (!m_Options.IsCodeXLAsicDisabled(asic))
                        {
                            requestedAsics.Add(asic);
                        }
                    }
                    CodeXLBackendOptions backendOptions = new CodeXLBackendOptions(requestedAsics);
                    options = backendOptions;
                }

                IResultSet r = backend.Compile(shader, options);
                if (r != null)
                {
                    if (r.Name.Equals(m_LastBackend))
                    {
                        SelectedResultSet = r;
                    }
                    cmbBackend.Items.Add(r);
                }
            }

            if (cmbBackend.Items.Count > 0)
            {
                if (SelectedResultSet != null)
                {
                    cmbBackend.SelectedIndex = cmbBackend.Items.IndexOf(SelectedResultSet);
                }
                else
                {
                    cmbBackend.SelectedIndex = 0;
                }
            }
            else
            {
                m_LastBackend = "";
            }

            this.UseWaitCursor = false;
        }
Example #7
0
        private void btnCompile_Click(object sender, EventArgs e)
        {
            if( m_CompileOptionsPanel == null )
                return;

            this.UseWaitCursor = true;

            ClearResults();

            IResultSet SelectedResultSet = null;

            ICompileOptions opts = m_CompileOptionsPanel.ReadOptions();

            IShader shader = null;
            switch (opts.Language)
            {
                case Languages.GLSL:
                    shader = new GLSLShader(txtCode.Text, opts as IGLSLOptions); break;
                case Languages.HLSL:
                    shader = new HLSLShader(txtCode.Text, opts as IHLSLOptions); break;
                default:
                    throw new System.Exception("Unsupported language");
            }

            foreach (IBackend backend in m_Backends)
            {
                if (m_Options.IsBackendDisabled(backend.Name))
                    continue;

                IBackendOptions options = null;

                if (backend is AMDDriverBackend)
                {
                    AMDDriverBackend amdBackend = backend as AMDDriverBackend;
                    List<string> requestedAsics = new List<string>();
                    foreach (string asic in amdBackend.Asics)
                    {
                        if (!m_Options.IsAMDAsicDisabled(asic))
                        {
                            requestedAsics.Add(asic);
                        }
                    }
                    AMDDriverBackendOptions backendOptions = new AMDDriverBackendOptions(requestedAsics);
                    options = backendOptions;
                }
                else if (backend is CodeXLBackend)
                {
                    CodeXLBackend codeXLBackend = backend as CodeXLBackend;
                    List<string> requestedAsics = new List<string>();
                    foreach (string asic in codeXLBackend.Asics)
                    {
                        if (!m_Options.IsCodeXLAsicDisabled(asic))
                        {
                            requestedAsics.Add(asic);
                        }
                    }
                    CodeXLBackendOptions backendOptions = new CodeXLBackendOptions(requestedAsics);
                    options = backendOptions;
                }

                IResultSet r = backend.Compile(shader, options);
                if (r != null)
                {
                    if (r.Name.Equals(m_LastBackend))
                        SelectedResultSet = r;
                    cmbBackend.Items.Add(r);
                }
            }

            if (cmbBackend.Items.Count > 0)
            {
                if (SelectedResultSet != null)
                    cmbBackend.SelectedIndex = cmbBackend.Items.IndexOf(SelectedResultSet);
                else
                    cmbBackend.SelectedIndex = 0;
            }
            else
            {
                m_LastBackend = "";
            }

            this.UseWaitCursor = false;
        }
Example #8
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);
        }
Example #9
0
        public IResultSet Compile(IShader shader, IBackendOptions options)
        {
            if (shader is GLSLShader)
            {
                GLSLShader   sh     = (GLSLShader)shader;
                IGLSLOptions glOpts = sh.CompileOptions;

                GLSlangOptions slangOpts = new GLSlangOptions();
                slangOpts.ShaderType = glOpts.ShaderType;
                slangOpts.Config     = m_Config;
                GLSlang.IShader result = m_Compiler.Compile(sh.Code, slangOpts);
                return(new GLSLangResultSet(result));
            }
            else if (shader is HLSLShader)
            {
                HLSLShader   sh       = (HLSLShader)shader;
                IHLSLOptions hlslOpts = sh.CompileOptions;

                // turn HLSL shader profile into GLSL shader type
                GLSLShaderType eShaderType;
                string         profile = hlslOpts.Target.ToString();
                if (profile.StartsWith("vs"))
                {
                    eShaderType = GLSLShaderType.VERTEX;
                }
                else if (profile.StartsWith("ps"))
                {
                    eShaderType = GLSLShaderType.FRAGMENT;
                }
                else if (profile.StartsWith("gs"))
                {
                    eShaderType = GLSLShaderType.GEOMETRY;
                }
                else if (profile.StartsWith("hs"))
                {
                    eShaderType = GLSLShaderType.TESS_CONTROL;
                }
                else if (profile.StartsWith("ds"))
                {
                    eShaderType = GLSLShaderType.TESS_EVALUATION;
                }
                else if (profile.StartsWith("cs"))
                {
                    eShaderType = GLSLShaderType.COMPUTE;
                }
                else
                {
                    throw new System.Exception("Don't know what this shader profile is");
                }

                string EntryPoint = hlslOpts.EntryPoint;

                GLSlangOptions slangOpts = new GLSlangOptions();
                slangOpts.ShaderType = eShaderType;
                slangOpts.Config     = m_Config;
                GLSlang.IShader result = m_Compiler.CompileHLSL(sh.Code, slangOpts, EntryPoint);
                return(new GLSLangResultSet(result));
            }
            else
            {
                return(null);
            }
        }