예제 #1
0
        private static string GetSourceName(D3D9Instruction instruction, int srcIndex)
        {
            string sourceName = instruction.GetParamRegisterName(srcIndex);

            if (instruction.Opcode != Opcode.Loop)
            {
                sourceName += instruction.GetSourceSwizzleName(srcIndex);
                sourceName  = ApplyModifier(instruction.GetSourceModifier(srcIndex), sourceName);
            }
            return(sourceName);
        }
예제 #2
0
        private void WriteInstruction(D3D9Instruction instruction)
        {
            switch (instruction.Opcode)
            {
            case Opcode.Abs:
                WriteLine("abs{0} {1}, {2}", GetModifier(instruction), GetDestinationName(instruction),
                          GetSourceName(instruction, 1));
                break;

            case Opcode.Add:
                WriteLine("add{0} {1}, {2}, {3}", GetModifier(instruction), GetDestinationName(instruction),
                          GetSourceName(instruction, 1), GetSourceName(instruction, 2));
                break;

            case Opcode.Cmp:
                WriteLine("cmp{0} {1}, {2}, {3}, {4}", GetModifier(instruction), GetDestinationName(instruction),
                          GetSourceName(instruction, 1), GetSourceName(instruction, 2), GetSourceName(instruction, 3));
                break;

            case Opcode.Dcl:
                string dclInstruction = "dcl";
                if (instruction.GetParamRegisterType(1) != RegisterType.MiscType)
                {
                    dclInstruction += "_" + instruction.GetDeclSemantic().ToLower();
                }
                WriteLine("{0} {1}", dclInstruction, GetDestinationName(instruction));
                break;

            case Opcode.Def:
            {
                string constRegisterName = instruction.GetParamRegisterName(0);
                string constValue0       = ConstantFormatter.Format(instruction.GetParamSingle(1));
                string constValue1       = ConstantFormatter.Format(instruction.GetParamSingle(2));
                string constValue2       = ConstantFormatter.Format(instruction.GetParamSingle(3));
                string constValue3       = ConstantFormatter.Format(instruction.GetParamSingle(4));
                WriteLine("def {0}, {1}, {2}, {3}, {4}", constRegisterName, constValue0, constValue1, constValue2, constValue3);
            }
            break;

            case Opcode.DefI:
            {
                string constRegisterName = instruction.GetParamRegisterName(0);
                WriteLine("defi {0}, {1}, {2}, {3}, {4}", constRegisterName,
                          instruction.Params[1], instruction.Params[2], instruction.Params[3], instruction.Params[4]);
            }
            break;

            case Opcode.DP2Add:
                WriteLine("dp2add {0}, {1}, {2}, {3}", GetDestinationName(instruction),
                          GetSourceName(instruction, 1), GetSourceName(instruction, 2), GetSourceName(instruction, 3));
                break;

            case Opcode.Dp3:
                WriteLine("dp3{0} {1}, {2}, {3}", GetModifier(instruction), GetDestinationName(instruction),
                          GetSourceName(instruction, 1), GetSourceName(instruction, 2));
                break;

            case Opcode.Dp4:
                WriteLine("dp4{0} {1}, {2}, {3}", GetModifier(instruction), GetDestinationName(instruction),
                          GetSourceName(instruction, 1), GetSourceName(instruction, 2));
                break;

            case Opcode.Else:
                WriteLine("else");
                break;

            case Opcode.Endif:
                WriteLine("endif");
                break;

            case Opcode.EndLoop:
                WriteLine("endloop");
                break;

            case Opcode.EndRep:
                WriteLine("endrep");
                break;

            case Opcode.Exp:
                WriteLine("exp{0} {1}, {2}", GetModifier(instruction), GetDestinationName(instruction),
                          GetSourceName(instruction, 1));
                break;

            case Opcode.Frc:
                WriteLine("frac {0}, {1}", GetDestinationName(instruction), GetSourceName(instruction, 1));
                break;

            case Opcode.If:
                WriteLine("if {0}", GetSourceName(instruction, 0));
                break;

            case Opcode.IfC:
                WriteLine("if_{0} {1}, {2}",
                          ((IfComparison)instruction.Modifier).ToString().ToLower(),
                          GetSourceName(instruction, 0), GetSourceName(instruction, 1));
                break;

            case Opcode.Log:
                WriteLine("log{0} {1}, {2}", GetModifier(instruction), GetDestinationName(instruction),
                          GetSourceName(instruction, 1));
                break;

            case Opcode.Loop:
                WriteLine("loop {0}, {1}", GetDestinationName(instruction),
                          GetSourceName(instruction, 1));
                break;

            case Opcode.Lrp:
                WriteLine("lrp{0} {1}, {2}, {3}, {4}", GetModifier(instruction), GetDestinationName(instruction),
                          GetSourceName(instruction, 1), GetSourceName(instruction, 2), GetSourceName(instruction, 3));
                break;

            case Opcode.Mad:
                WriteLine("mad{0} {1}, {2}, {3}, {4}", GetModifier(instruction), GetDestinationName(instruction),
                          GetSourceName(instruction, 1), GetSourceName(instruction, 2), GetSourceName(instruction, 3));
                break;

            case Opcode.Max:
                WriteLine("max{0} {1}, {2}, {3}", GetModifier(instruction), GetDestinationName(instruction),
                          GetSourceName(instruction, 1), GetSourceName(instruction, 2));
                break;

            case Opcode.Min:
                WriteLine("min{0} {1}, {2}, {3}", GetModifier(instruction), GetDestinationName(instruction),
                          GetSourceName(instruction, 1), GetSourceName(instruction, 2));
                break;

            case Opcode.Mov:
                WriteLine("mov{0} {1}, {2}", GetModifier(instruction), GetDestinationName(instruction),
                          GetSourceName(instruction, 1));
                break;

            case Opcode.MovA:
                WriteLine("mova{0} {1}, {2}", GetModifier(instruction), GetDestinationName(instruction),
                          GetSourceName(instruction, 1));
                break;

            case Opcode.Mul:
                WriteLine("mul{0} {1}, {2}, {3}", GetModifier(instruction), GetDestinationName(instruction),
                          GetSourceName(instruction, 1), GetSourceName(instruction, 2));
                break;

            case Opcode.Nop:
                WriteLine("nop");
                break;

            case Opcode.Nrm:
                WriteLine("nrm{0} {1}, {2}", GetModifier(instruction), GetDestinationName(instruction),
                          GetSourceName(instruction, 1));
                break;

            case Opcode.Pow:
                WriteLine("pow{0} {1}, {2}, {3}", GetModifier(instruction), GetDestinationName(instruction),
                          GetSourceName(instruction, 1), GetSourceName(instruction, 2));
                break;

            case Opcode.Rep:
                WriteLine("rep {0}", GetDestinationName(instruction));
                break;

            case Opcode.Rcp:
                WriteLine("rcp{0} {1}, {2}", GetModifier(instruction), GetDestinationName(instruction),
                          GetSourceName(instruction, 1));
                break;

            case Opcode.Rsq:
                WriteLine("rsq{0} {1}, {2}", GetModifier(instruction), GetDestinationName(instruction),
                          GetSourceName(instruction, 1));
                break;

            case Opcode.Sge:
                WriteLine("sge{0} {1}, {2}, {3}", GetModifier(instruction), GetDestinationName(instruction),
                          GetSourceName(instruction, 1), GetSourceName(instruction, 2));
                break;

            case Opcode.Slt:
                WriteLine("slt{0} {1}, {2}, {3}", GetModifier(instruction), GetDestinationName(instruction),
                          GetSourceName(instruction, 1), GetSourceName(instruction, 2));
                break;

            case Opcode.SinCos:
                if (shader.MajorVersion >= 3)
                {
                    WriteLine("sincos {0}, {1}", GetDestinationName(instruction),
                              GetSourceName(instruction, 1));
                }
                else
                {
                    WriteLine("sincos {0}, {1}, {2}, {3}", GetDestinationName(instruction),
                              GetSourceName(instruction, 1), GetSourceName(instruction, 2), GetSourceName(instruction, 3));
                }
                break;

            case Opcode.Sub:
                WriteLine("sub{0} {1}, {2}, {3}", GetModifier(instruction), GetDestinationName(instruction),
                          GetSourceName(instruction, 1), GetSourceName(instruction, 2));
                break;

            case Opcode.Tex:
                if ((shader.MajorVersion == 1 && shader.MinorVersion >= 4) || (shader.MajorVersion > 1))
                {
                    WriteLine("texld {0}, {1}, {2}", GetDestinationName(instruction),
                              GetSourceName(instruction, 1), GetSourceName(instruction, 2));
                }
                else
                {
                    WriteLine("tex {0}", GetDestinationName(instruction));
                }
                break;

            case Opcode.TexLDL:
                WriteLine("texldl {0}, {1}, {2}", GetDestinationName(instruction),
                          GetSourceName(instruction, 1), GetSourceName(instruction, 2));
                break;

            case Opcode.TexKill:
                WriteLine("texkill {0}", GetDestinationName(instruction));
                break;

            case Opcode.Comment:
            case Opcode.End:
                break;

            default:
                WriteLine(instruction.Opcode.ToString());
                Console.WriteLine(instruction.Opcode);
                //throw new NotImplementedException();
                break;
            }
        }