示例#1
0
        static IrShaderType ParseShaderReturnType(ResourceBinding binding)
        {
            var returnType = new IrShaderType();

            switch (binding.ReturnType)
            {
            case ResourceReturnType.Float:
                returnType.VariableType = IrShaderVariableType.F32;
                break;

            case ResourceReturnType.Double:
                returnType.VariableType = IrShaderVariableType.F64;
                break;

            case ResourceReturnType.SInt:
                returnType.VariableType = IrShaderVariableType.I32;
                break;

            case ResourceReturnType.UInt:
                returnType.VariableType = IrShaderVariableType.U32;
                break;

            case ResourceReturnType.UNorm:
                returnType.VariableType = IrShaderVariableType.UNormF32;
                break;

            case ResourceReturnType.SNorm:
                returnType.VariableType = IrShaderVariableType.SNormF32;
                break;

            case ResourceReturnType.Mixed:
                switch (binding.Type)
                {
                case ShaderInputType.Structured:
                case ShaderInputType.UavRwStructured:
                case ShaderInputType.UavAppendStructured:
                case ShaderInputType.UavConsumeStructured:
                case ShaderInputType.UavRwStructuredWithCounter:
                    break;

                case ShaderInputType.ByteAddress:
                case ShaderInputType.UavRwByteAddress:
                    //TODO: Byte type?
                    break;

                default:
                    throw new NotImplementedException();
                }
                break;

            default:
                throw new NotImplementedException();
            }
            switch (binding.Type)
            {
            case ShaderInputType.Structured:
            case ShaderInputType.UavRwStructured:
            case ShaderInputType.UavAppendStructured:
            case ShaderInputType.UavConsumeStructured:
            case ShaderInputType.UavRwStructuredWithCounter:
                returnType.VariableClass = ShaderVariableClass.Struct;
                returnType.BaseTypeName  = "TODO";
                break;

            default:
                ushort componentCount = 1;
                if (binding.Flags.HasFlag(ShaderInputFlags.TextureComponent0))
                {
                    componentCount += 1;
                }
                if (binding.Flags.HasFlag(ShaderInputFlags.TextureComponent1))
                {
                    componentCount += 2;
                }
                returnType.Columns       = componentCount;
                returnType.VariableClass = componentCount == 1 ?
                                           ShaderVariableClass.Scalar :
                                           ShaderVariableClass.Vector;
                break;
            }
            return(returnType);
        }
示例#2
0
        string GetShaderTypeDeclaration(IrShaderType type, int indent = 0, string overrideName = null, bool root = true)
        {
            var    sb           = new StringBuilder();
            string indentString = new string(' ', indent * 4);
            string baseTypeName = overrideName == null ? type.BaseTypeName : overrideName;

            switch (type.VariableClass)
            {
            case ShaderVariableClass.InterfacePointer:
                sb.Append(indentString);
                sb.Append(string.Format("{0}{1}", type.VariableClass.GetDescription(), type.BaseTypeName));
                break;

            case ShaderVariableClass.MatrixColumns:
            case ShaderVariableClass.MatrixRows:
            {
                sb.Append(indentString);
                sb.Append(type.VariableClass.GetDescription());
                sb.Append(type.VariableType.GetVariableTypeName());
                sb.Append(type.Rows);
                sb.Append("x" + type.Columns);
                break;
            }

            case ShaderVariableClass.Vector:
            {
                sb.Append(indentString + type.VariableType.GetVariableTypeName());
                sb.Append(type.Columns);
                break;
            }

            case ShaderVariableClass.Struct:
            {
                //SM4 doesn't include typenames, check by signature
                //TODO
                if (!MergeStructDefinitions || root || baseTypeName == null || baseTypeName.EndsWith("<unnamed>"))
                {
                    sb.Append(indentString + "struct ");
                    if (baseTypeName == null || baseTypeName.EndsWith("<unnamed>"))
                    {
                    }
                    else
                    {
                        sb.Append(baseTypeName);
                    }
                    sb.AppendLine("");
                    sb.AppendLine(indentString + "{");
                    foreach (var member in type.Members)
                    {
                        sb.AppendLine(GetShaderMemberDeclaration(member, indent + 1));
                    }
                    sb.Append(indentString + "}");
                }
                else
                {
                    sb.Append(indentString + "struct " + baseTypeName);                                     //struct keyword optional
                }
                break;
            }

            case ShaderVariableClass.Scalar:
            {
                sb.Append(indentString + type.VariableType.GetVariableTypeName());
                break;
            }

            default:
                throw new InvalidOperationException(string.Format("Variable class '{0}' is not currently supported.", type.VariableClass));
            }
            return(sb.ToString());
        }