private IntrinsicObjectTypeSymbol BindObjectType(PredefinedObjectTypeSyntax node) { if (node.ObjectTypeToken.ContextualKind == SyntaxKind.ConstantBufferKeyword) { var valueTypeSyntax = (TypeSyntax)node.TemplateArgumentList.Arguments[0]; var valueType = Bind(valueTypeSyntax, x => BindType(x, null)); return(IntrinsicTypes.CreateConstantBufferType(valueType.TypeSymbol)); } var predefinedObjectType = SyntaxFacts.GetPredefinedObjectType(node.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; GetTextureValueAndScalarType(node, out valueType, out scalarType); return(IntrinsicTypes.CreateTextureType(predefinedObjectType, valueType, scalarType)); } case PredefinedObjectType.RWBuffer: case PredefinedObjectType.RasterizerOrderedBuffer: case PredefinedObjectType.RWTexture1D: case PredefinedObjectType.RWTexture1DArray: case PredefinedObjectType.RWTexture2D: case PredefinedObjectType.RWTexture2DArray: case PredefinedObjectType.RWTexture3D: case PredefinedObjectType.RasterizerOrderedTexture1D: case PredefinedObjectType.RasterizerOrderedTexture1DArray: case PredefinedObjectType.RasterizerOrderedTexture2D: case PredefinedObjectType.RasterizerOrderedTexture2DArray: case PredefinedObjectType.RasterizerOrderedTexture3D: { TypeSymbol valueType; ScalarType scalarType; GetTextureValueAndScalarType(node, out valueType, out scalarType); return(IntrinsicTypes.CreateRWTextureType(predefinedObjectType, valueType, scalarType)); } case PredefinedObjectType.AppendStructuredBuffer: case PredefinedObjectType.ConsumeStructuredBuffer: case PredefinedObjectType.StructuredBuffer: case PredefinedObjectType.RWStructuredBuffer: case PredefinedObjectType.RasterizerOrderedStructuredBuffer: case PredefinedObjectType.InputPatch: case PredefinedObjectType.OutputPatch: case PredefinedObjectType.PointStream: case PredefinedObjectType.LineStream: case PredefinedObjectType.TriangleStream: { var valueTypeSyntax = (TypeSyntax)node.TemplateArgumentList.Arguments[0]; var valueType = Bind(valueTypeSyntax, x => BindType(x, null)).TypeSymbol; switch (predefinedObjectType) { case PredefinedObjectType.AppendStructuredBuffer: return(IntrinsicTypes.CreateAppendStructuredBufferType(valueType)); case PredefinedObjectType.ConsumeStructuredBuffer: return(IntrinsicTypes.CreateConsumeStructuredBufferType(valueType)); case PredefinedObjectType.StructuredBuffer: return(IntrinsicTypes.CreateStructuredBufferType(valueType)); case PredefinedObjectType.RWStructuredBuffer: return(IntrinsicTypes.CreateRWStructuredBufferType(valueType)); case PredefinedObjectType.RasterizerOrderedStructuredBuffer: return(IntrinsicTypes.CreateRasterizerOrderedStructuredBufferType(valueType)); case PredefinedObjectType.InputPatch: return(IntrinsicTypes.CreateInputPatchType(valueType)); case PredefinedObjectType.OutputPatch: return(IntrinsicTypes.CreateOutputPatchType(valueType)); case PredefinedObjectType.PointStream: case PredefinedObjectType.LineStream: case PredefinedObjectType.TriangleStream: return(IntrinsicTypes.CreateStreamOutputType(predefinedObjectType, valueType)); default: throw new ArgumentOutOfRangeException(); } } case PredefinedObjectType.ByteAddressBuffer: return(IntrinsicTypes.ByteAddressBuffer); case PredefinedObjectType.BlendState: return(IntrinsicTypes.BlendState); case PredefinedObjectType.DepthStencilState: return(IntrinsicTypes.DepthStencilState); case PredefinedObjectType.RasterizerState: return(IntrinsicTypes.RasterizerState); case PredefinedObjectType.RasterizerOrderedByteAddressBuffer: return(IntrinsicTypes.RasterizerOrderedByteAddressBuffer); case PredefinedObjectType.RWByteAddressBuffer: return(IntrinsicTypes.RWByteAddressBuffer); case PredefinedObjectType.Sampler: return(IntrinsicTypes.Sampler); case PredefinedObjectType.Sampler1D: return(IntrinsicTypes.Sampler1D); case PredefinedObjectType.Sampler2D: return(IntrinsicTypes.Sampler2D); case PredefinedObjectType.Sampler3D: return(IntrinsicTypes.Sampler3D); case PredefinedObjectType.SamplerCube: return(IntrinsicTypes.SamplerCube); case PredefinedObjectType.SamplerState: return(IntrinsicTypes.SamplerState); case PredefinedObjectType.SamplerComparisonState: return(IntrinsicTypes.SamplerComparisonState); case PredefinedObjectType.Texture: return(IntrinsicTypes.LegacyTexture); case PredefinedObjectType.GeometryShader: return(IntrinsicTypes.GeometryShader); case PredefinedObjectType.PixelShader: return(IntrinsicTypes.PixelShader); case PredefinedObjectType.VertexShader: return(IntrinsicTypes.VertexShader); default: throw new InvalidOperationException(predefinedObjectType.ToString()); } }
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(); } }