From 0f9ba36a622070c9a79f1b44f2c5d1ec34a9fec3 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 12 Aug 2019 00:48:08 +0200 Subject: [PATCH] Added new APIs to the HlslKnownTypes class --- .../Mappings/HlslKnownTypes.cs | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/DirectX12GameEngine.Shaders/Mappings/HlslKnownTypes.cs b/src/DirectX12GameEngine.Shaders/Mappings/HlslKnownTypes.cs index 25a7f9bf..85c64e7e 100644 --- a/src/DirectX12GameEngine.Shaders/Mappings/HlslKnownTypes.cs +++ b/src/DirectX12GameEngine.Shaders/Mappings/HlslKnownTypes.cs @@ -18,10 +18,10 @@ namespace DirectX12GameEngine.Shaders.Mappings private static readonly IReadOnlyDictionary KnownTypes = new Dictionary { [typeof(bool).FullName] = "bool", - [typeof(uint).FullName] = "uint", [typeof(int).FullName] = "int", - [typeof(double).FullName] = "double", + [typeof(uint).FullName] = "uint", [typeof(float).FullName] = "float", + [typeof(double).FullName] = "double", [typeof(Vector2).FullName] = "float2", [typeof(Vector3).FullName] = "float3", [typeof(Vector4).FullName] = "float4", @@ -30,11 +30,43 @@ namespace DirectX12GameEngine.Shaders.Mappings [typeof(RWBufferResource<>).FullName] = "RWBuffer" }; + /// + /// Checks whether or not the input type is a known scalar type + /// + /// The input instance to check + /// A indicating whether the input is in fact a known HLSL scalar type + [Pure] + public static bool IsKnownScalarType(Type type) => type == typeof(bool) || + type == typeof(int) || + type == typeof(uint) || + type == typeof(float) || + type == typeof(double); + + /// + /// Checks whether or not the input type is a known vector type + /// + /// The input instance to check + /// A indicating whether the input is in fact a known HLSL vector type + [Pure] + public static bool IsKnownVectorType(Type type) => type == typeof(Vector2) || + type == typeof(Vector3) || + type == typeof(Vector4) || + type == typeof(Matrix4x4); + + /// + /// Checks whether or not the input type is a value + /// + /// The input instance to check + /// A indicating whether the input is in fact a instance + [Pure] + public static bool IsReadWriteBufferType(Type type) => type.IsGenericType && + type.GetGenericTypeDefinition() == typeof(RWBufferResource<>); + /// /// Checks whether or not a given is an HLSL known type /// /// The input instance to check - /// A indicating whether the input is in fact an HLSL known type + /// A indicating whether the input is in fact a known HLSL type [Pure] public static bool IsKnownType(Type type) {