diff --git a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownSizes.cs b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownSizes.cs index 75d2be8f..78d2aed8 100644 --- a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownSizes.cs +++ b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownSizes.cs @@ -3,7 +3,6 @@ using System.Diagnostics.Contracts; using System.Linq; using System.Numerics; using System.Reflection; -using System.Runtime.InteropServices; using System.Text.RegularExpressions; namespace ComputeSharp.SourceGenerators.Mappings diff --git a/src/ComputeSharp/Shaders/Translation/Mappings/HlslKnownTypes.cs b/src/ComputeSharp/Shaders/Translation/Mappings/HlslKnownTypes.cs index 5776c971..90aae996 100644 --- a/src/ComputeSharp/Shaders/Translation/Mappings/HlslKnownTypes.cs +++ b/src/ComputeSharp/Shaders/Translation/Mappings/HlslKnownTypes.cs @@ -10,7 +10,10 @@ namespace ComputeSharp.Shaders.Mappings /// internal static class HlslKnownTypes { - private static HashSet _HlslMappedVectorTypes { get; } = new HashSet(new[] + /// + /// The set of HLSL vector types. + /// + private static HashSet HlslMappedVectorTypes { get; } = new(new[] { typeof(Bool2), typeof(Bool3), typeof(Bool4), typeof(Int2), typeof(Int3), typeof(Int4), @@ -19,6 +22,33 @@ namespace ComputeSharp.Shaders.Mappings typeof(Double2), typeof(Double3), typeof(Double4) }); + /// + /// The set of HLSL matrix types. + /// + private static HashSet HlslMappedMatrixTypes { get; } = new(new[] + { + typeof(Bool1x1), typeof(Bool1x2), typeof(Bool1x3), typeof(Bool1x4), + typeof(Bool2x1), typeof(Bool2x2), typeof(Bool2x3), typeof(Bool2x4), + typeof(Bool3x1), typeof(Bool3x2), typeof(Bool3x3), typeof(Bool3x4), + typeof(Bool4x1), typeof(Bool4x2), typeof(Bool4x3), typeof(Bool4x4), + typeof(Int1x1), typeof(Int1x2), typeof(Int1x3), typeof(Int1x4), + typeof(Int2x1), typeof(Int2x2), typeof(Int2x3), typeof(Int2x4), + typeof(Int3x1), typeof(Int3x2), typeof(Int3x3), typeof(Int3x4), + typeof(Int4x1), typeof(Int4x2), typeof(Int4x3), typeof(Int4x4), + typeof(UInt1x1), typeof(UInt1x2), typeof(UInt1x3), typeof(UInt1x4), + typeof(UInt2x1), typeof(UInt2x2), typeof(UInt2x3), typeof(UInt2x4), + typeof(UInt3x1), typeof(UInt3x2), typeof(UInt3x3), typeof(UInt3x4), + typeof(UInt4x1), typeof(UInt4x2), typeof(UInt4x3), typeof(UInt4x4), + typeof(Float1x1), typeof(Float1x2), typeof(Float1x3), typeof(Float1x4), + typeof(Float2x1), typeof(Float2x2), typeof(Float2x3), typeof(Float2x4), + typeof(Float3x1), typeof(Float3x2), typeof(Float3x3), typeof(Float3x4), + typeof(Float4x1), typeof(Float4x2), typeof(Float4x3), typeof(Float4x4), + typeof(Double1x1), typeof(Double1x2), typeof(Double1x3), typeof(Double1x4), + typeof(Double2x1), typeof(Double2x2), typeof(Double2x3), typeof(Double2x4), + typeof(Double3x1), typeof(Double3x2), typeof(Double3x3), typeof(Double3x4), + typeof(Double4x1), typeof(Double4x2), typeof(Double4x3), typeof(Double4x4) + }); + /// /// Checks whether or not the input type is a known scalar type. /// @@ -38,11 +68,19 @@ namespace ComputeSharp.Shaders.Mappings /// 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) => _HlslMappedVectorTypes.Contains(type) || + public static bool IsKnownVectorType(Type type) => HlslMappedVectorTypes.Contains(type) || type == typeof(Vector2) || type == typeof(Vector3) || type == typeof(Vector4); + /// + /// Checks whether or not the input type is a known matrix type. + /// + /// The input instance to check. + /// A indicating whether the input is in fact a known HLSL matrix type. + [Pure] + public static bool IsKnownMatrixType(Type type) => HlslMappedMatrixTypes.Contains(type); + /// /// Checks whether or not the input type is a known buffer type. /// diff --git a/src/ComputeSharp/Shaders/Translation/ShaderLoader{T}.cs b/src/ComputeSharp/Shaders/Translation/ShaderLoader{T}.cs index a04b9b61..de9cfcef 100644 --- a/src/ComputeSharp/Shaders/Translation/ShaderLoader{T}.cs +++ b/src/ComputeSharp/Shaders/Translation/ShaderLoader{T}.cs @@ -217,7 +217,7 @@ namespace ComputeSharp.Shaders.Translation this.hlslResourceInfo.Add(new HlslResourceInfo.ReadWrite(hlslType, hlslName, (int)this.readWriteBuffersCount++)); this.totalResourceCount++; } - else if (HlslKnownTypes.IsKnownScalarType(fieldType) || HlslKnownTypes.IsKnownVectorType(fieldType)) + else if (HlslKnownTypes.IsKnownScalarType(fieldType) || HlslKnownTypes.IsKnownVectorType(fieldType) || HlslKnownTypes.IsKnownMatrixType(fieldType)) { this.capturedFields.Add(fieldInfo); this.fieldsInfo.Add(new CapturedFieldInfo(hlslType, hlslName));