示例#1
0
        /// <summary>
        /// Compile Runtime the shader
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="entryPoint"></param>
        public ComputeShader( String Name, String entryPoint , String IncludePath =  null)
        {
            Device dev = Engine.g_device;

            // init the include class and subpath
            IncludeFX includeFX = new IncludeFX();
            if ( IncludePath == null ) {
                includeFX.IncludeDirectory = System.Windows.Forms.Application.StartupPath + "\\ComputeHLSL\\";
            } else {
                includeFX.IncludeDirectory = IncludePath;
            }
            ShaderBytecode bytecode= null;

            ShaderFlags sf;

            // select the shaders flags for
            if ( Settings.Debug ) {
                sf = ShaderFlags.SkipOptimization | ShaderFlags.Debug | ShaderFlags.PreferFlowControl;
            } else {
                sf = ShaderFlags.OptimizationLevel3;
            }

            // set the compile level base on running Feature level.
            String CompileLevelCS;
            if (Settings.FeatureLevel == FeatureLevel.Level_11_0)
            {
                CompileLevelCS = "cs_5_0";
            }
            else
            {
                CompileLevelCS = "cs_4_0";
            }

            /// compile the shader to byte code
            bytecode = ShaderBytecode.CompileFromFile(
                                        ShaderRootPath + Name,               /// File Path of the file containing the code
                                        entryPoint,                          /// The name of the executable function
                                        CompileLevelCS,                      /// What specifications (shader version) to compile with cs_4_0 for directX10 and cs_5_0 for directx11
                                        sf, EffectFlags.None, null, includeFX);

            // init effect
            m_effect = new FXEffect( dev, csByteCode: bytecode );
        }
示例#2
0
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            List<String> logs = new List<string>();
            //Parallel.ForEach(shader_list, shader =>
            foreach (ShaderDesc shader in shader_list)
            {

                WriteLog("Start Building :" + shader.ToString());
                logs.Add("Start Building :" + shader.ToString());

                // init the include class and subpath
                IncludeFX includeFX = new IncludeFX();
                if (shader.IncludePath == null)
                {
                    includeFX.IncludeDirectory = System.Windows.Forms.Application.StartupPath + "\\ComputeHLSL\\";
                }
                else
                {
                    includeFX.IncludeDirectory = shader.IncludePath;
                }

                // init the include class and subpath
                ShaderBytecode bytecode = null;

                // set the compile level base on running Feature level.
                String CompileLevelCS;
                if (shader.BuildLevel == FeatureLevel.Level_11_0)
                {
                    CompileLevelCS = "cs_5_0";
                }
                else
                {
                    CompileLevelCS = "cs_4_0";
                }

                foreach (String entryPoint in shader.EntryPoint)
                {
                    try
                    {
                        /// compile the shader to byte code
                        bytecode = ShaderBytecode.CompileFromFile(
                                                    shader.ShaderPath,               /// File Path of the file containing the code
                                                    entryPoint,               /// The name of the executable function
                                                    CompileLevelCS,                  /// What specifications (shader version) to compile with cs_4_0 for directX10 and cs_5_0 for directx11
                                                    shader.Flags, EffectFlags.None, null, includeFX);
                    }
                    catch (Exception ex)
                    {
                        WriteLog("Error:" + ex.Message);
                        logs.Add("Error:" + ex.Message);
                        break;
                    }

                    WriteLog("Entry Point:" + entryPoint + " builded");
                    logs.Add("Entry Point:" + entryPoint + " builded");
                    bytecode.Save(shader.OutputPath + "\\" + Path.GetFileNameWithoutExtension(shader.ShaderPath) + "." + entryPoint + ".fxo");
                }
                WriteLog("Building Completed of" + shader.ToString());
                logs.Add("Building Completed of" + shader.ToString());
                //});
            }
            //foreach (String str in logs)
              //  WriteLog(str);
        }
示例#3
0
        /// <summary>
        /// Precompile the shader
        /// </summary>
        /// <param name="Name"></param>
        public ComputeShader( String Name )
        {
            Device dev = Engine.g_device;

            IncludeFX includeFX = new IncludeFX();
            ShaderBytecode bytecode= null;

            // check that the shader is exist
            if ( File.Exists( ShaderRootPath + Name ) ) {
                // open the file to read it
                FileStream fileStream = new FileStream( ShaderRootPath + Name, FileMode.Open );

                // allocate the byte stream
                byte []fileByte = new byte[fileStream.Length];

                // read the file stream
                fileStream.Read( fileByte, 0, (int)fileStream.Length );

                // close the file stream
                fileStream.Close();

                bytecode = new ShaderBytecode(fileByte);

            } else {
                System.Windows.Forms.MessageBox.Show( "Shader:" + ShaderRootPath + Name + "   is not exist " );

                return;
            }

            // init effect
            m_effect = new FXEffect( dev, csByteCode: bytecode );
        }
示例#4
0
        /// <summary>
        /// Compile in runtime the shader that 
        /// get from the memory
        /// </summary>
        /// <param name="Shader"></param>
        /// <returns>The errors from the building</returns>
        public virtual String RunTimeCompile(String Shader)
        {
            ShaderBytecode bytecode = null;

            try {
                IncludeFX includeFX = new IncludeFX();
                /// compile the shader to byte code
                bytecode = ShaderBytecode.Compile(
                                            Shader,     /// string buffer that containing the code
                                            "fx_5_0",   /// What specifications (shader version) to compile with
                                            ShaderFlags.None, EffectFlags.None, null, includeFX);

            } catch (Exception ex) {
                return ex.Message;
            }

            /// check if the shader compile correct
            if (bytecode != null) {
                /// create the effect variable
                //m_effect = new Effect(Engine.g_device, bytecode);

                /// init all the variables
                InitVariables();
            }

            return "";
        }
示例#5
0
        public Shader(String Name, String VS_EntryPoint = "VS_Main", String PS_EntryPoint = "PS_Main", String GS_EntryPoint = "GS_Main", Boolean PreCompiled = false)
        {
            Device dev = Engine.g_device;

            IncludeFX includeFX = new IncludeFX();

            if ( PreCompiled ) {
                // check that the shader is exist
                if ( File.Exists( ShaderRootPath + Name + "o" ) ) {
                    // open the file to read it
                    FileStream fileStream = new FileStream( ShaderRootPath + Name + "o", FileMode.Open );

                    // allocate the byte stream
                    byte[] fileByte = new byte[fileStream.Length];

                    // read the file stream
                    fileStream.Read( fileByte, 0, (int)fileStream.Length );

                    // close the file stream
                    fileStream.Close();

                    DataStream preBuildShaderStream = new DataStream( fileByte.Length, true, true );
                    preBuildShaderStream.Write(fileByte, 0, fileByte.Length);

                    m_PixelShaderByteCode = new ShaderBytecode( preBuildShaderStream );
                    m_VertexShaderByteCode = new ShaderBytecode( preBuildShaderStream );
                } else {
                    System.Windows.Forms.MessageBox.Show( "Shader:" + ShaderRootPath + Name + "o" + "   is not exist " );

                    return;
                }

            } else {
                // set the shader flags base on the debugging
                ShaderFlags sf;
                if ( Settings.Debug ) {
                    sf = ShaderFlags.SkipOptimization | ShaderFlags.Debug | ShaderFlags.PreferFlowControl;
                } else {
                    sf = ShaderFlags.OptimizationLevel3;
                }

                // set the compile feature
                String CompileLevelPS;
                String CompileLevelVS;
                String CompileLevelGS;

                if (Settings.FeatureLevel == FeatureLevel.Level_11_0)
                {
                    CompileLevelPS = "ps_5_0";
                    CompileLevelVS = "vs_5_0";
                    CompileLevelGS = "gs_5_0";
                }
                else
                {
                    CompileLevelPS = "ps_4_0";
                    CompileLevelVS = "vs_4_0";
                    CompileLevelGS = "gs_4_0";
                }

                try
                {
                    /// compile the shader to byte code
                    m_PixelShaderByteCode = ShaderBytecode.CompileFromFile(
                                                ShaderRootPath + Name,       /// File Path of the file containing the code
                                                PS_EntryPoint,               /// The entry point for the shader
                                                CompileLevelPS,              /// What specifications (shader version) to compile with
                                                sf, EffectFlags.None, null, includeFX);

                    /// compile the shader to byte code
                    m_VertexShaderByteCode = ShaderBytecode.CompileFromFile(
                                                ShaderRootPath + Name,       /// File Path of the file containing the code
                                                VS_EntryPoint,               /// The entry point for the shader
                                                CompileLevelVS,              /// What specifications (shader version) to compile with
                                                sf, EffectFlags.None, null, includeFX);

                    try
                    {
                        /// compile the shader to byte code
                        m_GeometryShaderByteCode = ShaderBytecode.CompileFromFile(
                                                    ShaderRootPath + Name,       /// File Path of the file containing the code
                                                    GS_EntryPoint,               /// The entry point for the shader
                                                    CompileLevelGS,              /// What specifications (shader version) to compile with
                                                    sf, EffectFlags.None, null, includeFX);
                    }catch(Exception ex)
                    {
                        // the geometry shader is not mandatory
                    }
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);

                }
            }

            /// init effect
            m_effect = new FXEffect( dev, m_PixelShaderByteCode, m_VertexShaderByteCode, null, m_GeometryShaderByteCode );

            /// init all the variables
            InitVariables();
        }