Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="buildContext"></param>
        /// <param name="sourceFile"></param>
        /// <param name="profile"></param>
        /// <param name="entryPoint"></param>
        /// <param name="defines"></param>
        /// <param name="output"></param>
        /// <param name="listing"></param>
        /// <returns></returns>
        byte[] Compile(Parameters buildContext, string sourceFile, string profile, string entryPoint, string defines, string output, string listing)
        {
            //Log.Debug("{0} {1} {2} {3}", sourceFile, profile, entryPoint, defines );

            var flags = FX.ShaderFlags.None;

            if (DisableOptimization)
            {
                flags |= FX.ShaderFlags.OptimizationLevel0;
            }
            // (!DisableOptimization)	flags |= FX.ShaderFlags.OptimizationLevel3;
            if (PreferFlowControl)
            {
                flags |= FX.ShaderFlags.PreferFlowControl;
            }
            if (AvoidFlowControl)
            {
                flags |= FX.ShaderFlags.AvoidFlowControl;
            }

            if (MatrixPacking == ShaderMatrixPacking.ColumnMajor)
            {
                flags |= FX.ShaderFlags.PackMatrixColumnMajor;
            }
            if (MatrixPacking == ShaderMatrixPacking.RowMajor)
            {
                flags |= FX.ShaderFlags.PackMatrixRowMajor;
            }

            var defs = defines.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
                       .Select(entry => new SharpDX.Direct3D.ShaderMacro(entry, "1"))
                       .ToArray();

            sourceFile = buildContext.Resolve(sourceFile);

            try {
                var result = FX.ShaderBytecode.CompileFromFile(sourceFile, entryPoint, profile, flags, FX.EffectFlags.None, defs, new IncludeHandler(buildContext));

                if (result.Message != null)
                {
                    Log.Warning(result.Message);
                }

                File.WriteAllText(listing, result.Bytecode.Disassemble(FX.DisassemblyFlags.EnableColorCode, ""));

                return(result.Bytecode.Data);
            } catch (Exception ex) {
                if (ex.Message.Contains("error X3501"))
                {
                    Log.Debug("No entry point '{0}'. It's ok", entryPoint);
                    return(new byte[0]);
                }

                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="buildContext"></param>
        /// <param name="sourceFile"></param>
        /// <param name="profile"></param>
        /// <param name="entryPoint"></param>
        /// <param name="defines"></param>
        /// <param name="output"></param>
        /// <param name="listing"></param>
        /// <returns></returns>
        byte[] Compile( Parameters buildContext, string sourceFile, string profile, string entryPoint, string defines, string output, string listing )
        {
            //Log.Debug("{0} {1} {2} {3}", sourceFile, profile, entryPoint, defines );

            var	flags	=	FX.ShaderFlags.None;

            if ( DisableOptimization)	flags |= FX.ShaderFlags.OptimizationLevel0;
            // (!DisableOptimization)	flags |= FX.ShaderFlags.OptimizationLevel3;
            if ( PreferFlowControl)		flags |= FX.ShaderFlags.PreferFlowControl;
            if ( AvoidFlowControl)		flags |= FX.ShaderFlags.AvoidFlowControl;

            if ( MatrixPacking==ShaderMatrixPacking.ColumnMajor )	flags |= FX.ShaderFlags.PackMatrixColumnMajor;
            if ( MatrixPacking==ShaderMatrixPacking.RowMajor )		flags |= FX.ShaderFlags.PackMatrixRowMajor;

            var defs = defines.Split(new[]{' ','\t'}, StringSplitOptions.RemoveEmptyEntries)
                        .Select( entry => new SharpDX.Direct3D.ShaderMacro( entry, "1" ) )
                        .ToArray();

            sourceFile	=	buildContext.Resolve( sourceFile );

            try {

                var result = FX.ShaderBytecode.CompileFromFile( sourceFile, entryPoint, profile, flags, FX.EffectFlags.None, defs, new IncludeHandler(buildContext) );

                if ( result.Message!=null ) {
                    Log.Warning( result.Message );
                }

                File.WriteAllText( listing, result.Bytecode.Disassemble( FX.DisassemblyFlags.EnableColorCode, "" ) );

                return result.Bytecode.Data;

            } catch ( Exception ex ) {

                if (ex.Message.Contains("error X3501")) {
                    Log.Debug("No entry point '{0}'. It's ok", entryPoint );
                    return new byte[0];
                }

                throw;
            }
        }
Exemplo n.º 3
0
            public Stream Open(IncludeType type, string fileName, Stream parentStream)
            {
                //Log.Information("{0} {1} {2}", type, fileName, parentStream );

                return(File.OpenRead(buildContext.Resolve(fileName)));
            }