コード例 #1
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;
            }
        }
コード例 #2
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;
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: waykohler/Pyramid
        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;
        }