diff --git a/src/ComputeSharp/Extensions/FloatExtensions.cs b/src/ComputeSharp.Core/Extensions/FloatExtensions.cs similarity index 100% rename from src/ComputeSharp/Extensions/FloatExtensions.cs rename to src/ComputeSharp.Core/Extensions/FloatExtensions.cs diff --git a/src/ComputeSharp/Extensions/VectorExtensions.cs b/src/ComputeSharp.Core/Extensions/VectorExtensions.cs similarity index 100% rename from src/ComputeSharp/Extensions/VectorExtensions.cs rename to src/ComputeSharp.Core/Extensions/VectorExtensions.cs diff --git a/src/ComputeSharp.Core/Primitives/Float/FloatMxN.cs.cs b/src/ComputeSharp.Core/Primitives/Float/FloatMxN.cs.cs new file mode 100644 index 00000000..996e5e11 --- /dev/null +++ b/src/ComputeSharp.Core/Primitives/Float/FloatMxN.cs.cs @@ -0,0 +1,37 @@ +using System.Numerics; + +#pragma warning disable CS0660, CS0661 + +namespace ComputeSharp; + +/// +partial struct Float3x2 +{ + /// + /// Casts a value to a one. + /// + /// The input value to cast. + public static unsafe implicit operator Matrix3x2(Float3x2 xy) => *(Matrix3x2*)&xy; + + /// + /// Casts a value to a one. + /// + /// The input value to cast. + public static unsafe implicit operator Float3x2(Matrix3x2 xy) => *(Float3x2*)&xy; +} + +/// +partial struct Float4x4 +{ + /// + /// Casts a value to a one. + /// + /// The input value to cast. + public static unsafe implicit operator Matrix4x4(Float4x4 xy) => *(Matrix4x4*)&xy; + + /// + /// Casts a value to a one. + /// + /// The input value to cast. + public static unsafe implicit operator Float4x4(Matrix4x4 xy) => *(Float4x4*)&xy; +} \ No newline at end of file diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownTypes.cs b/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownTypes.cs index 6abf8faf..f3496cf5 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownTypes.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownTypes.cs @@ -365,7 +365,7 @@ internal static partial class HlslKnownTypes /// The same list as input, but in a valid HLSL declaration order. private static IEnumerable OrderByDependency(IEnumerable types, IReadOnlyCollection invalidTypes) { - Queue<(INamedTypeSymbol Type, HashSet Fields)> queue = new(); + Queue<(INamedTypeSymbol Type, HashSet Fields)> queue = []; // Build a mapping of type dependencies for all the captured types. A type depends on another // when the latter is a field in the first type. HLSL requires custom types to be declared in diff --git a/src/ComputeSharp.SourceGeneration/Helpers/DynamicCache{TKey,TValue}.cs b/src/ComputeSharp.SourceGeneration/Helpers/DynamicCache{TKey,TValue}.cs index f56ce3fe..9cb05fc2 100644 --- a/src/ComputeSharp.SourceGeneration/Helpers/DynamicCache{TKey,TValue}.cs +++ b/src/ComputeSharp.SourceGeneration/Helpers/DynamicCache{TKey,TValue}.cs @@ -20,7 +20,7 @@ internal sealed class DynamicCache /// /// The backing instance for the cache. /// - private readonly ConcurrentDictionary map = new(); + private readonly ConcurrentDictionary map = []; /// /// The tracking dead entries to remove. diff --git a/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs b/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs index 09336922..ed8e609b 100644 --- a/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs +++ b/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs @@ -16,7 +16,7 @@ internal readonly unsafe struct ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE d3 /// /// The queue of items with the available command lists. /// - private readonly Queue d3D12CommandListBundleQueue = new(); + private readonly Queue d3D12CommandListBundleQueue = []; /// /// Rents a and pair. diff --git a/src/ComputeSharp/Graphics/GraphicsDevice.Execute.cs b/src/ComputeSharp/Graphics/GraphicsDevice.Execute.cs index a92dfeea..a5beec31 100644 --- a/src/ComputeSharp/Graphics/GraphicsDevice.Execute.cs +++ b/src/ComputeSharp/Graphics/GraphicsDevice.Execute.cs @@ -228,7 +228,7 @@ unsafe partial class GraphicsDevice /// /// The shared holding the reusable instances. /// - private static readonly ConcurrentQueue ValueTaskSourceQueue = new(); + private static readonly ConcurrentQueue ValueTaskSourceQueue = []; /// /// The approximate count of currently enqueued instances in . diff --git a/tests/ComputeSharp.Tests/HlslPrimitiveTests.cs b/tests/ComputeSharp.Tests/HlslPrimitiveTests.cs new file mode 100644 index 00000000..7438b4a8 --- /dev/null +++ b/tests/ComputeSharp.Tests/HlslPrimitiveTests.cs @@ -0,0 +1,56 @@ +using System.Numerics; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace ComputeSharp.Tests; + +[TestClass] +public partial class HlslPrimitiveTests +{ + [TestMethod] + public void Float3x2_ImplicitConversions() + { + Matrix3x2 m3x2 = new(1, 2, 3, 4, 5, 6); + + float3x2 f3x2 = m3x2; + + Assert.AreEqual(m3x2.M11, f3x2.M11); + Assert.AreEqual(m3x2.M12, f3x2.M12); + Assert.AreEqual(m3x2.M21, f3x2.M21); + Assert.AreEqual(m3x2.M22, f3x2.M22); + Assert.AreEqual(m3x2.M31, f3x2.M31); + Assert.AreEqual(m3x2.M32, f3x2.M32); + + Matrix3x2 roundTrip3x2 = f3x2; + + Assert.AreEqual(m3x2, roundTrip3x2); + } + + [TestMethod] + public void Float4x4_ImplicitConversions() + { + Matrix4x4 m4x4 = new(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + + float4x4 f4x4 = m4x4; + + Assert.AreEqual(m4x4.M11, f4x4.M11); + Assert.AreEqual(m4x4.M12, f4x4.M12); + Assert.AreEqual(m4x4.M13, f4x4.M13); + Assert.AreEqual(m4x4.M14, f4x4.M14); + Assert.AreEqual(m4x4.M21, f4x4.M21); + Assert.AreEqual(m4x4.M22, f4x4.M22); + Assert.AreEqual(m4x4.M23, f4x4.M23); + Assert.AreEqual(m4x4.M24, f4x4.M24); + Assert.AreEqual(m4x4.M31, f4x4.M31); + Assert.AreEqual(m4x4.M32, f4x4.M32); + Assert.AreEqual(m4x4.M33, f4x4.M33); + Assert.AreEqual(m4x4.M34, f4x4.M34); + Assert.AreEqual(m4x4.M41, f4x4.M41); + Assert.AreEqual(m4x4.M42, f4x4.M42); + Assert.AreEqual(m4x4.M43, f4x4.M43); + Assert.AreEqual(m4x4.M44, f4x4.M44); + + Matrix4x4 roundTrip4x4 = f4x4; + + Assert.AreEqual(m4x4, roundTrip4x4); + } +} \ No newline at end of file