Esempio n. 1
0
 public HLSLShader(string code, IHLSLOptions opts, string path)
 {
     CompileOptions = opts;
     Code           = code;
     WasCompiled    = false;
     SourceFilePath = path;
 }
Esempio n. 2
0
        public IResultSet Compile(IShader shaderObj, IBackendOptions options)
        {
            if ( !(shaderObj is HLSLShader ) )
                return null;

            HLSLShader shaderHLSL = shaderObj as HLSLShader;
            IHLSLOptions hlslOpts = shaderHLSL.CompileOptions;
            AMDDriverBackendOptions backendOptions = options as AMDDriverBackendOptions;
            string shader = shaderObj.Code;

            if (shaderHLSL.WasCompiledWithErrors)
                return null;

            try
            {
                // compile here if we must.  Recycle existing blob if we can
                IDXShaderBlob blob = shaderHLSL.CompiledBlob;
                if ( blob == null )
                {
                    if (!shaderHLSL.Compile(m_FXC))
                        return null;
                    blob = shaderHLSL.CompiledBlob;
                }

                IDXShaderReflection reflect = blob.Reflect();

                IDXShaderBlob exe = blob.GetExecutableBlob();
                if (exe == null)
                    return null;

                byte[] bytes = exe.ReadBytes();

                AMDDriverResultSet rs = new AMDDriverResultSet(reflect );

                foreach (IAMDAsic a in m_Driver.Asics)
                {
                    if (CompileForAsic(backendOptions.Asics, a.Name))
                    {
                        IAMDShader sh = m_Driver.CompileDXBlob(a, bytes, reflect);
                        rs.Add(sh);
                    }
                }

                return rs;
            }
            catch( System.Exception ex )
            {
                MessageBox.Show(ex.Message);
                return null;
            }
        }
Esempio n. 3
0
        public IResultSet Compile(IShader shader, IBackendOptions options)
        {
            if (!(shader is HLSLShader))
            {
                return(null);
            }

            HLSLShader   hlsl     = (HLSLShader)shader;
            IHLSLOptions hlslOpts = hlsl.CompileOptions;
            string       text     = hlsl.Code;

            if (!hlsl.WasCompiled)
            {
                hlsl.Compile(m_Compiler);
            }

            return(new FXCResultSet(hlsl.Messages, hlsl.CompiledBlob));
        }
Esempio n. 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);
            }
        }
Esempio n. 5
0
        public IResultSet Compile(IShader shader, IBackendOptions options)
        {
            if (!(shader is HLSLShader))
            {
                return(null);
            }

            HLSLShader   hlsl     = (HLSLShader)shader;
            IHLSLOptions hlslOpts = hlsl.CompileOptions;
            string       text     = hlsl.Code;

            if (!hlsl.WasCompiled)
            {
                hlsl.Compile(m_Compiler, m_DXIL);
            }

            if (!hlsl.RootSigWasCompiled)
            {
                hlsl.CompileRootSignature(m_DXIL);
            }

            return(new FXCResultSet(hlsl));
        }
Esempio n. 6
0
 public HLSLShader(string code, IHLSLOptions opts)
 {
     CompileOptions = opts;
     Code           = code;
     WasCompiled    = false;
 }
Esempio n. 7
0
 public HLSLShader(string code, IHLSLOptions opts)
 {
     CompileOptions = opts;
     Code = code;
     WasCompiled = false;
 }
Esempio n. 8
0
        public IResultSet Compile(IShader shader, IBackendOptions options)
        {
            if (!(shader is HLSLShader) || !(options is CodeXLBackendOptions))
            {
                return(null);
            }

            // TODO: Modify CodeXL backend so that it re-uses blob from
            //    FXC backend where available.  It'd be nice not to have to
            //    have CodeXL recompile it for us
            HLSLShader           shaderHLSL     = shader as HLSLShader;
            IHLSLOptions         hlslOpts       = shaderHLSL.CompileOptions;
            CodeXLBackendOptions backendOptions = options as CodeXLBackendOptions;
            string text = shader.Code;

            if (shaderHLSL.WasCompiledWithErrors)
            {
                return(null);
            }

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

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

            string isaPath      = Path.Combine(m_TempPath, "pyramid.isa");
            string analysisPath = Path.Combine(m_TempPath, "analysis");
            string CommandLine  = "-s \"HLSL\"";

            CommandLine = String.Concat(CommandLine, String.Format(" -p {0}", hlslOpts.Target.ToString()));
            CommandLine = String.Concat(CommandLine, String.Format(" -f {0} ", hlslOpts.EntryPoint));
            CommandLine = String.Concat(CommandLine, String.Format(" --DXLocation \"{0}\"", m_D3DCompiler));
            CommandLine = String.Concat(CommandLine, String.Format(" --isa \"{0}\"", isaPath));
            CommandLine = String.Concat(CommandLine, String.Format(" -a \"{0}\"", analysisPath));
            CommandLine = String.Concat(CommandLine, String.Format(" --DXFlags {0} ", hlslOpts.GetD3DCompileFlagBits()));

            CommandLine = String.Concat(CommandLine, tmpFile);

            foreach (string asic in m_SupportedAsics)
            {
                if (CompileForAsic(backendOptions.Asics, asic))
                {
                    CommandLine = String.Concat(CommandLine, " -c ", asic, " ");
                }
            }

            ProcessStartInfo pi = new ProcessStartInfo();

            pi.RedirectStandardOutput = true;
            pi.RedirectStandardInput  = true;
            pi.RedirectStandardError  = true;
            pi.CreateNoWindow         = true;
            pi.Arguments       = CommandLine;
            pi.FileName        = m_CodeXL;
            pi.UseShellExecute = false;

            string output;

            try
            {
                int     TimeOut = 15000; // TODO: Put in options
                Process p       = Process.Start(pi);
                output = p.StandardOutput.ReadToEnd();
                if (p.WaitForExit(TimeOut))
                {
                    MessageBox.Show("CodeXL took more than 15 seconds");
                }
                p.Close();
                File.Delete(tmpFile);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "uh-oh, couldn't run CodeXL", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }

            // Compile results are emitted in one set of files per asic
            string          defaultAsic = "";
            CodeXLResultSet results     = new CodeXLResultSet();

            foreach (string asic in m_SupportedAsics)
            {
                if (!CompileForAsic(backendOptions.Asics, asic))
                {
                    continue;
                }

                if (defaultAsic == "")
                {
                    defaultAsic = asic;
                }

                string isaFile = Path.Combine(m_TempPath, String.Format("{0}_pyramid.isa", asic));

                try
                {
                    string isa = File.ReadAllText(isaFile);
                    results.AddCompileResult(asic, "CodeXL doesn't support IL output for HLSL", isa);

                    File.Delete(isaFile);
                }
                catch (Exception)
                {
                    // may occur in the event of a compile error.
                }
            }

            // Analysis results are emitted in a big CSV file
            try
            {
                string[] lines = File.ReadAllLines(analysisPath);
                File.Delete(analysisPath);

                try
                {
                    // first line is column names
                    string   columns = lines[0];
                    string[] cols    = columns.Split(',');

                    // first column is asic, remaining columns are fields we want to display
                    for (int i = 1; i < lines.Length; i++)
                    {
                        string[] data = lines[i].Split(',');
                        string   asic = data[0];
                        Dictionary <string, string> vals = new Dictionary <string, string>();
                        for (int j = 1; j < cols.Length; j++)
                        {
                            if (!String.IsNullOrEmpty(data[j]) && !String.IsNullOrEmpty(cols[j]))
                            {
                                vals.Add(cols[j], data[j]);
                            }
                        }

                        results.AddAnalysisResult(asic, vals);
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "uh-oh. Couldn't parse CodeXL analysis file.  Did it change?", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception)
            {
                // compile error
            }

            if (results.ResultCount > 0)
            {
                results.DisplayAsic(defaultAsic);
                return(results);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 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);
            }
        }