public ConstantDeclaration FindConstant(uint index)
 {
     return(ConstantDeclarations.FirstOrDefault(c => c.ContainsIndex(index)));
 }
 public ConstantDeclaration FindConstant(ParameterType type, uint index)
 {
     return(ConstantDeclarations.FirstOrDefault(c =>
                                                c.ParameterType == type &&
                                                c.ContainsIndex(index)));
 }
Example #3
0
        string GetSourceName(Instruction instruction, int srcIndex)
        {
            string sourceRegisterName;

            var registerType = instruction.GetParamRegisterType(srcIndex);

            switch (registerType)
            {
            case RegisterType.Const:
            case RegisterType.Const2:
            case RegisterType.Const3:
            case RegisterType.Const4:
            case RegisterType.ConstBool:
            case RegisterType.ConstInt:
                sourceRegisterName = GetSourceConstantName(instruction, srcIndex);
                if (sourceRegisterName != null)
                {
                    return(sourceRegisterName);
                }

                ParameterType parameterType;
                switch (registerType)
                {
                case RegisterType.Const:
                case RegisterType.Const2:
                case RegisterType.Const3:
                case RegisterType.Const4:
                    parameterType = ParameterType.Float;
                    break;

                case RegisterType.ConstBool:
                    parameterType = ParameterType.Bool;
                    break;

                case RegisterType.ConstInt:
                    parameterType = ParameterType.Int;
                    break;

                default:
                    throw new NotImplementedException();
                }
                int registerNumber = instruction.GetParamRegisterNumber(srcIndex);
                var decl           = ConstantDeclarations.FirstOrDefault(
                    x => x.ParameterType == parameterType && x.ContainsIndex(registerNumber));
                if (decl == null)
                {
                    // Constant register not found in def statements nor the constant table
                    throw new NotImplementedException();
                }

                if (decl.ParameterClass == ParameterClass.MatrixRows)
                {
                    sourceRegisterName = string.Format("{0}[{1}]", decl.Name, registerNumber - decl.RegisterIndex);
                }
                else
                {
                    sourceRegisterName = decl.Name;
                }
                break;

            default:
                sourceRegisterName = GetRegisterName(instruction, srcIndex);
                break;
            }

            sourceRegisterName = sourceRegisterName ?? instruction.GetParamRegisterName(srcIndex);

            sourceRegisterName += instruction.GetSourceSwizzleName(srcIndex);
            return(ApplyModifier(instruction.GetSourceModifier(srcIndex), sourceRegisterName));
        }
 public ConstantDeclaration FindConstant(RegisterSet set, uint index)
 {
     return(ConstantDeclarations.FirstOrDefault(c =>
                                                c.RegisterSet == set &&
                                                c.ContainsIndex(index)));
 }
Example #5
0
        string GetRegisterName(Instruction instruction, int paramIndex)
        {
            RegisterType registerType   = instruction.GetParamRegisterType(paramIndex);
            int          registerNumber = instruction.GetParamRegisterNumber(paramIndex);

            var decl = RegisterDeclarations.FirstOrDefault(x => x.RegisterType == registerType && x.RegisterNumber == registerNumber);

            if (decl != null)
            {
                switch (registerType)
                {
                case RegisterType.Texture:
                    return(decl.Name);

                case RegisterType.Input:
                    return((numInputs == 1) ? decl.Name : ("i." + decl.Name));

                case RegisterType.Output:
                    return((numOutputs == 1) ? "o" : ("o." + decl.Name));

                case RegisterType.Sampler:
                    var samplerDecl = ConstantDeclarations.FirstOrDefault(x => x.RegisterSet == RegisterSet.Sampler && x.RegisterIndex == registerNumber);
                    if (samplerDecl != null)
                    {
                        return(samplerDecl.Name);
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }

                case RegisterType.MiscType:
                    if (registerNumber == 0)
                    {
                        return("vFace");
                    }
                    else if (registerNumber == 1)
                    {
                        return("vPos");
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }

                default:
                    throw new NotImplementedException();
                }
            }

            switch (registerType)
            {
            case RegisterType.Const:
                var constDecl = ConstantDeclarations.FirstOrDefault(x => x.ContainsIndex(registerNumber));
                if (constDecl != null)
                {
                    throw new NotImplementedException();
                }
                break;

            case RegisterType.ColorOut:
                return("o");
            }

            return(null);
        }