示例#1
0
        private static TypeSymbol ResolveIntrinsicVectorType(VectorTypeSyntax type)
        {
            var vectorType    = SyntaxFacts.GetVectorType(type.TypeToken.Kind);
            var scalarType    = vectorType.Item1;
            var numComponents = vectorType.Item2;

            return(IntrinsicTypes.GetVectorType(scalarType, numComponents));
        }
示例#2
0
        private TypeSymbol ResolveIntrinsicObjectType(PredefinedObjectTypeSyntax type, ISymbolTable symbolTable, Symbol contextSymbol)
        {
            var predefinedObjectType = SyntaxFacts.GetPredefinedObjectType(type.ObjectTypeToken.Kind);

            switch (predefinedObjectType)
            {
            case PredefinedObjectType.Buffer:
            case PredefinedObjectType.Texture1D:
            case PredefinedObjectType.Texture1DArray:
            case PredefinedObjectType.Texture2D:
            case PredefinedObjectType.Texture2DArray:
            case PredefinedObjectType.Texture3D:
            case PredefinedObjectType.TextureCube:
            case PredefinedObjectType.TextureCubeArray:
            case PredefinedObjectType.Texture2DMS:
            case PredefinedObjectType.Texture2DMSArray:
            {
                TypeSymbol valueType;
                ScalarType scalarType;
                if (type.TemplateArgumentList != null)
                {
                    var valueTypeSyntax = type.TemplateArgumentList.Arguments[0];
                    valueType = ResolveIntrinsicType((PredefinedTypeSyntax)valueTypeSyntax, symbolTable, contextSymbol);
                    switch (valueTypeSyntax.Kind)
                    {
                    case SyntaxKind.PredefinedScalarType:
                        scalarType = SyntaxFacts.GetScalarType(((ScalarTypeSyntax)valueTypeSyntax).TypeTokens.Select(x => x.Kind).ToArray());
                        break;

                    case SyntaxKind.PredefinedVectorType:
                        scalarType = SyntaxFacts.GetVectorType(((VectorTypeSyntax)valueTypeSyntax).TypeToken.Kind).Item1;
                        break;

                    case SyntaxKind.PredefinedGenericVectorType:
                        scalarType = SyntaxFacts.GetScalarType(((GenericVectorTypeSyntax)valueTypeSyntax).ScalarType.TypeTokens.Select(x => x.Kind).ToArray());
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
                else
                {
                    valueType  = IntrinsicTypes.Float4;
                    scalarType = ScalarType.Float;
                }
                return(IntrinsicTypes.CreateTextureType(predefinedObjectType, valueType, scalarType));
            }

            case PredefinedObjectType.RWBuffer:
            case PredefinedObjectType.RWTexture1D:
            case PredefinedObjectType.RWTexture1DArray:
            case PredefinedObjectType.RWTexture2D:
            case PredefinedObjectType.RWTexture2DArray:
            case PredefinedObjectType.RWTexture3D:
                throw new NotImplementedException();

            case PredefinedObjectType.AppendStructuredBuffer:
            case PredefinedObjectType.ConsumeStructuredBuffer:
            case PredefinedObjectType.StructuredBuffer:
            {
                var valueTypeSyntax = (TypeSyntax)type.TemplateArgumentList.Arguments[0];
                var valueType       = ResolveType(valueTypeSyntax, symbolTable, contextSymbol);
                switch (predefinedObjectType)
                {
                case PredefinedObjectType.AppendStructuredBuffer:
                    return(IntrinsicTypes.CreateAppendStructuredBufferType(valueType));

                case PredefinedObjectType.ConsumeStructuredBuffer:
                    return(IntrinsicTypes.CreateConsumeStructuredBufferType(valueType));

                case PredefinedObjectType.StructuredBuffer:
                    return(IntrinsicTypes.CreateStructuredBufferType(valueType));

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            case PredefinedObjectType.ByteAddressBuffer:
                return(IntrinsicTypes.CreateByteAddressBufferType());

            case PredefinedObjectType.RWByteAddressBuffer:
            case PredefinedObjectType.RWStructuredBuffer:
            case PredefinedObjectType.InputPatch:
            case PredefinedObjectType.OutputPatch:
            case PredefinedObjectType.PointStream:
            case PredefinedObjectType.LineStream:
            case PredefinedObjectType.TriangleStream:
                throw new NotImplementedException();

            case PredefinedObjectType.Sampler:
            case PredefinedObjectType.SamplerState:
                return(IntrinsicTypes.SamplerState);

            case PredefinedObjectType.SamplerComparisonState:
                return(IntrinsicTypes.SamplerComparisonState);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }