public AsmToHlslAsmConverter(AsmListing asmSource, Microsoft.Xna.Framework.TargetPlatform platform, int shaderMaxConstants, int shaderMaxBooleanConstants, bool throwOnError)
        {
            maxConstant = -1;
            if (shaderMaxConstants != 0)
            {
                maxConstant = shaderMaxConstants;
            }
            maxBoolean = -1;
            if (shaderMaxBooleanConstants != 0)
            {
                maxBoolean = shaderMaxBooleanConstants;
            }
            maxRegister = -1;

            this.samplers              = new List <InputOutput>();
            this.inputs                = new List <InputOutput>();
            this.outputs               = new List <InputOutput>();
            this.assignedConstants     = new Dictionary <int, bool>();
            this.localConstants        = new Dictionary <int, string>();
            this.localBooleanConstants = new Dictionary <int, string>();
            this.localIntegerConstants = new Dictionary <int, string>();

            for (int i = 0; i < 256; i++)
            {
                assignedConstants.Add(i, false);
            }

            this.source = new StringBuilder();

            this.listing = asmSource;

            if (listing.GetCommandCount() > 0)
            {
                //attempt to decode the shader
                if (DetectProfile())
                {
                    List <Command> commands = new List <Command>();
                    for (int i = 1; i < listing.GetCommandCount(); i++)
                    {
                        //extract the commands
                        Command cmd = new Command(listing.GetCommand(i));
                        if (cmd.name != null)
                        {
                            commands.Add(cmd);
                        }
                    }

                    List <Command> allCommands = new List <Command>();

                    List <Command> newCommands = new List <Command>();
                    foreach (Command command in commands)
                    {
                        newCommands.Clear();
                        GenerateCode(command, newCommands);
                        allCommands.AddRange(newCommands);
                    }
                    commands = allCommands;

                    bool isAsm = false;

                    foreach (Command cmd in commands)
                    {
                        if (cmd.isAsm != isAsm)
                        {
                            if (isAsm)
                            {
                                this.source.Append("};");
                                this.source.AppendLine();
                            }
                            else
                            {
                                this.source.Append("asm{");
                                this.source.AppendLine();
                            }
                            isAsm = cmd.isAsm;
                        }

                        this.source.Append(cmd.name);
                        for (int i = 0; i < cmd.args.Length; i++)
                        {
                            this.source.Append(' ');
                            if (i != 0)
                            {
                                this.source.Append(',');
                            }
                            for (int a = 0; a < cmd.args[i].Length; a++)
                            {
                                this.source.Append(cmd.args[i][a]);
                            }
                        }
                        this.source.AppendLine();
                    }
                    if (isAsm)
                    {
                        this.source.Append("};");
                    }
                }
            }

            BuildMethod();

            CompiledShader shader =
                ShaderCompiler.CompileFromSource(
                    this.source.ToString(),
                    null, null, CompilerOptions.AvoidFlowControl, "Main",
                    profile, platform);

            if (throwOnError && !shader.Success)
            {
                Common.ThrowError("An error occured running the Xbox shader HLSL/ASM preprocessor", shader.ErrorsAndWarnings, asmSource.ToString());
            }

            if (!shader.Success)
            {
                //tried the best.. if it failed, ohh well, go back to AssembleFromSource
                //probably used complex flow control?
                string rawAsm = asmSource.ToString();

                shader = ShaderCompiler.AssembleFromSource(rawAsm, null, null, CompilerOptions.None, platform);

                if (!shader.Success)
                {
                    Common.ThrowError(shader.ErrorsAndWarnings, rawAsm);
                }
            }

            output = shader.GetShaderCode();
        }
Beispiel #2
0
 public override string GetRuntimeReader(Microsoft.Xna.Framework.TargetPlatform targetPlatform)
 {
     return(typeof(FlatRedBall.Content.LightReader).AssemblyQualifiedName);
 }
Beispiel #3
0
        /*public override string GetRuntimeType(TargetPlatform targetPlatform)
         * {
         *      return typeof(KeyboardLayout).AssemblyQualifiedName;
         * }*/

        public override string GetRuntimeReader(Microsoft.Xna.Framework.TargetPlatform targetPlatform)
        {
            return(typeof(KeyboardLayoutReader).AssemblyQualifiedName);
        }
Beispiel #4
0
 public override string GetRuntimeType(Microsoft.Xna.Framework.TargetPlatform targetPlatform)
 {
     return(typeof(FlatRedBall.Graphics.Lighting.LightCollection).AssemblyQualifiedName);
 }