public static CompilerSettings GetCompilerSettings(string source)
 {
     var regex = new Regex(CompilerSettingsRegex, RegexOptions.IgnoreCase);
     var match = regex.Match(source);
     if (match.Success)
     {
         var matches = new Regex(AttributeRegex, RegexOptions.IgnoreCase).Matches(match.Groups["Content"].Value);
         var settings = new CompilerSettings();
         foreach (Match m in matches)
         {
             var attributeName = m.Groups["Attribute"].Value;
             var value = m.Groups["Value"].Value;
             switch (attributeName.ToLower())
             {
                 case "direct3d":
                     settings.Direct3D = value;
                     break;
                 case "profile":
                     settings.Profile = value;
                     break;
                 case "entrypoint":
                     settings.EntryPoint = value;
                     break;
                 case "shaderflags":
                     settings.ShaderFlags = ParseShaderFlags(value);
                     break;
                 case "effectflags":
                     settings.EffectFlags = ParseEffectFlags(value);
                     break;
             }
         }
         return settings;
     }
     return null;
 }
        public CompilerSettings GetCompilerSettings()
        {
            var settings = new CompilerSettings();
            settings.Direct3D = (comboBox1.SelectedItem as DirectX).Version;
            settings.Profile = (comboBox2.SelectedItem as Profile).Name;

            settings.ShaderFlags = ShaderFlags.None;
            if (checkBoxAvoidFlowControl.IsChecked.Value) settings.ShaderFlags |= ShaderFlags.AvoidFlowControl;
            if (checkBoxDebug.IsChecked.Value) settings.ShaderFlags |= ShaderFlags.Debug;
            if (checkBoxEnableBackwardsCompatibility.IsChecked.Value) settings.ShaderFlags |= ShaderFlags.EnableBackwardsCompatibility;
            if (checkBoxEnableIEEEStrictness.IsChecked.Value) settings.ShaderFlags |= ShaderFlags.EnableIEEEStrictness;
            if (checkBoxEnableStrictness.IsChecked.Value) settings.ShaderFlags |= ShaderFlags.EnableStrictness;
            if (checkBoxForceSoftwarePixelShader.IsChecked.Value) settings.ShaderFlags |= ShaderFlags.ForceSoftwarePixelShader;
            if (checkBoxForceSoftwareVertexShader.IsChecked.Value) settings.ShaderFlags |= ShaderFlags.ForceSoftwareVertexShader;
            if (checkBoxNoPreshader.IsChecked.Value) settings.ShaderFlags |= ShaderFlags.NoPreshader;
            if (checkBoxOptimizationLevel0.IsChecked.Value) settings.ShaderFlags |= ShaderFlags.OptimizationLevel0;
            //if (checkBoxOptimizationLevel1.IsChecked.Value) settings.ShaderFlags |= ShaderFlags.OptimizationLevel1;
            if (checkBoxOptimizationLevel2.IsChecked.Value) settings.ShaderFlags |= ShaderFlags.OptimizationLevel2;
            if (checkBoxOptimizationLevel3.IsChecked.Value) settings.ShaderFlags |= ShaderFlags.OptimizationLevel3;
            if (checkBoxPackMatrixColumnMajor.IsChecked.Value) settings.ShaderFlags |= ShaderFlags.PackMatrixColumnMajor;
            if (checkBoxPackMatrixRowMajor.IsChecked.Value) settings.ShaderFlags |= ShaderFlags.PackMatrixRowMajor;
            if (checkBoxPartialPrecision.IsChecked.Value) settings.ShaderFlags |= ShaderFlags.PartialPrecision;
            if (checkBoxPreferFlowControl.IsChecked.Value) settings.ShaderFlags |= ShaderFlags.PreferFlowControl;
            if (checkBoxSkipOptimization.IsChecked.Value) settings.ShaderFlags |= ShaderFlags.SkipOptimization;
            if (checkBoxSkipValidation.IsChecked.Value) settings.ShaderFlags |= ShaderFlags.SkipValidation;
            if (checkBoxWarningsAreErrors.IsChecked.Value) settings.ShaderFlags |= ShaderFlags.WarningsAreErrors;

            settings.EffectFlags = EffectFlags.None;
            if (checkBoxAllowSlowOperations.IsChecked.Value) settings.EffectFlags |= EffectFlags.AllowSlowOperations;
            if (checkBoxChildEffect.IsChecked.Value) settings.EffectFlags |= EffectFlags.ChildEffect;
            if (checkBoxSingleThreaded.IsChecked.Value) settings.EffectFlags |= EffectFlags.SingleThreaded;

            return settings;
        }
        public void SetCompilerSettings(CompilerSettings settings)
        {
            comboBox1.SelectedValue = settings.Direct3D;
            comboBox2.SelectedValue = settings.Profile;
            textBox1.Text = settings.EntryPoint;
            checkBoxAvoidFlowControl.IsChecked = settings.ShaderFlags.HasFlag(ShaderFlags.AvoidFlowControl);
            checkBoxDebug.IsChecked = settings.ShaderFlags.HasFlag(ShaderFlags.Debug);
            checkBoxEnableBackwardsCompatibility.IsChecked = settings.ShaderFlags.HasFlag(ShaderFlags.EnableBackwardsCompatibility);
            checkBoxEnableIEEEStrictness.IsChecked = settings.ShaderFlags.HasFlag(ShaderFlags.EnableIEEEStrictness);
            checkBoxEnableStrictness.IsChecked = settings.ShaderFlags.HasFlag(ShaderFlags.EnableStrictness);
            checkBoxForceSoftwarePixelShader.IsChecked = settings.ShaderFlags.HasFlag(ShaderFlags.ForceSoftwarePixelShader);
            checkBoxForceSoftwareVertexShader.IsChecked = settings.ShaderFlags.HasFlag(ShaderFlags.ForceSoftwareVertexShader);
            checkBoxNoPreshader.IsChecked = settings.ShaderFlags.HasFlag(ShaderFlags.NoPreshader);
            checkBoxOptimizationLevel0.IsChecked = settings.ShaderFlags.HasFlag(ShaderFlags.OptimizationLevel0);
            //checkBoxOptimizationLevel1.IsChecked = settings.ShaderFlags.HasFlag(ShaderFlags.OptimizationLevel1);
            checkBoxOptimizationLevel2.IsChecked = settings.ShaderFlags.HasFlag(ShaderFlags.OptimizationLevel2);
            checkBoxOptimizationLevel3.IsChecked = settings.ShaderFlags.HasFlag(ShaderFlags.OptimizationLevel3);
            checkBoxPackMatrixColumnMajor.IsChecked = settings.ShaderFlags.HasFlag(ShaderFlags.PackMatrixColumnMajor);
            checkBoxPackMatrixRowMajor.IsChecked = settings.ShaderFlags.HasFlag(ShaderFlags.PackMatrixRowMajor);
            checkBoxPartialPrecision.IsChecked = settings.ShaderFlags.HasFlag(ShaderFlags.PartialPrecision);
            checkBoxPreferFlowControl.IsChecked = settings.ShaderFlags.HasFlag(ShaderFlags.PreferFlowControl);
            checkBoxSkipOptimization.IsChecked = settings.ShaderFlags.HasFlag(ShaderFlags.SkipOptimization);
            checkBoxSkipValidation.IsChecked = settings.ShaderFlags.HasFlag(ShaderFlags.SkipValidation);
            checkBoxWarningsAreErrors.IsChecked = settings.ShaderFlags.HasFlag(ShaderFlags.WarningsAreErrors);

            checkBoxAllowSlowOperations.IsChecked = settings.EffectFlags.HasFlag(EffectFlags.AllowSlowOperations);
            checkBoxChildEffect.IsChecked = settings.EffectFlags.HasFlag(EffectFlags.ChildEffect);
            checkBoxSingleThreaded.IsChecked = settings.EffectFlags.HasFlag(EffectFlags.SingleThreaded);
        }
 private static string FormatCompilerSettings(CompilerSettings settings)
 {
     var optionals = new StringBuilder();
     if (!string.IsNullOrWhiteSpace(settings.EntryPoint)) optionals.AppendFormat(@" entryPoint=""{0}""", settings.EntryPoint);
     if (settings.ShaderFlags != ShaderFlags.None) optionals.AppendFormat(@" shaderFlags=""{0}""", GetShaderFlagsString(settings.ShaderFlags));
     if (settings.EffectFlags != EffectFlags.None) optionals.AppendFormat(@" effectFlags=""{0}""", GetEffectFlagsString(settings.EffectFlags));
     if (!string.IsNullOrWhiteSpace(settings.EntryPoint)) optionals.AppendFormat(@" entryPoint=""{0}""", settings.EntryPoint);
     return string.Format(@"<effectEd direct3D=""{0}"" profile=""{1}""{2} />", settings.Direct3D, settings.Profile, optionals);
 }
 public static string SetCompilerSettings(string source, CompilerSettings compilerSettings)
 {
     var compilerSettingsString = FormatCompilerSettings(compilerSettings);
     var regex = new Regex(CompilerSettingsRegex, RegexOptions.IgnoreCase);
     var match = regex.Match(source);
     if (match.Success)
     {
         return source.Remove(match.Index, match.Length).Insert(match.Index, compilerSettingsString);
     }
     return source.Insert(0, String.Format("// {0}\r\n", FormatCompilerSettings(compilerSettings)));
 }
Beispiel #6
0
 /// <summary>
 /// Compiles the source code using the given compiler settings.
 /// </summary>
 /// <param name="source"> </param>
 /// <param name="settings"></param>
 /// <returns></returns>
 public static List<Feedback> Compile(string source, CompilerSettings settings)
 {
     try
     {
         return GetCompiler(settings).Compile(source, settings);
     }
     catch (Exception e)
     {
         return new List<Feedback>() { new Feedback() { Message = e.Message}};
     }
 }
Beispiel #7
0
        public List<Feedback> Compile(string code, CompilerSettings settings)
        {
            var compilationErrors = string.Empty;
            try
            {
                ShaderBytecode.Compile(code, settings.EntryPoint, settings.Profile, settings.ShaderFlags, settings.EffectFlags, null, null, out compilationErrors);
            }
            catch (Exception)
            {

            }
            return FeedbackParser.Parse(compilationErrors);
        }
Beispiel #8
0
 private string GetFeedback(string code,CompilerSettings settings)
 {
     try
     {
         if (string.IsNullOrWhiteSpace(code)) throw new Exception("There is no code to compile.");
         Effect.FromString(Device, code, settings.Profile, settings.ShaderFlags, settings.EffectFlags);
     }
     catch (Exception exception)
     {
         if (string.IsNullOrWhiteSpace(exception.Message)) return "Unspecified compilation error.";
         return exception.Message;
     }
     return null;
 }
Beispiel #9
0
 /// <summary>
 /// Returns the specific compiler for the requested Direct3D version.
 /// </summary>
 /// <param name="settings"></param>
 /// <returns></returns>
 private static ICompiler GetCompiler(CompilerSettings settings)
 {
     switch (settings.Direct3D)
     {
         case "9":
             return new Compiler09();
         case "10":
         case "10.1":
             return new Compiler10();
         case "11":
             return new Compiler11();
         default:
             throw new ArgumentException(string.Format("Direct3D version {0} is not supported.", settings.Direct3D));
     }
 }
Beispiel #10
0
 public List<Feedback> Compile(string code, CompilerSettings settings)
 {
     var feedback = GetFeedback(code, settings);
     return feedback != null ? FeedbackParser.Parse(feedback) : null;
 }
Beispiel #11
0
 public List<Feedback> Compile(string code, CompilerSettings settings)
 {
     throw new Exception("Currently, EffectEd does not support DirectX 9 compilation.");
 }
 public void SetCompilerSettings(CompilerSettings compilerSettings)
 {
     compilerSettingsControl1.SetCompilerSettings(compilerSettings);
 }