diff --git a/src/ComputeSharp.Graphics/Helpers/__Internals/GraphicsResourceHelper.cs b/src/ComputeSharp.Graphics/Helpers/__Internals/GraphicsResourceHelper.cs index 9abde184..fdf9a066 100644 --- a/src/ComputeSharp.Graphics/Helpers/__Internals/GraphicsResourceHelper.cs +++ b/src/ComputeSharp.Graphics/Helpers/__Internals/GraphicsResourceHelper.cs @@ -50,13 +50,32 @@ namespace ComputeSharp.__Internals /// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle. /// /// The type of values stored in the input texture. - /// The input instance to check. + /// The input instance to check. /// The target instance in use. /// The GPU descriptor handle for the texture. [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("This method is not intended to be called directly by user code")] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ulong ValidateAndGetGpuDescriptorHandle(Texture2D texture, GraphicsDevice device) + public static ulong ValidateAndGetGpuDescriptorHandle(ReadOnlyTexture2D texture, GraphicsDevice device) + where T : unmanaged + { + texture.ThrowIfDisposed(); + texture.ThrowIfDeviceMismatch(device); + + return Unsafe.As(ref Unsafe.AsRef(in texture.D3D12GpuDescriptorHandle)); + } + + /// + /// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle. + /// + /// The type of values stored in the input texture. + /// The input instance to check. + /// The target instance in use. + /// The GPU descriptor handle for the texture. + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be called directly by user code")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ulong ValidateAndGetGpuDescriptorHandle(ReadWriteTexture2D texture, GraphicsDevice device) where T : unmanaged { texture.ThrowIfDisposed(); @@ -115,13 +134,32 @@ namespace ComputeSharp.__Internals /// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle. /// /// The type of values stored in the input texture. - /// The input instance to check. + /// The input instance to check. /// The target instance in use. /// The GPU descriptor handle for the texture. [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("This method is not intended to be called directly by user code")] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ulong ValidateAndGetGpuDescriptorHandle(Texture3D texture, GraphicsDevice device) + public static ulong ValidateAndGetGpuDescriptorHandle(ReadOnlyTexture3D texture, GraphicsDevice device) + where T : unmanaged + { + texture.ThrowIfDisposed(); + texture.ThrowIfDeviceMismatch(device); + + return Unsafe.As(ref Unsafe.AsRef(in texture.D3D12GpuDescriptorHandle)); + } + + /// + /// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle. + /// + /// The type of values stored in the input texture. + /// The input instance to check. + /// The target instance in use. + /// The GPU descriptor handle for the texture. + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be called directly by user code")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ulong ValidateAndGetGpuDescriptorHandle(ReadWriteTexture3D texture, GraphicsDevice device) where T : unmanaged { texture.ThrowIfDisposed(); diff --git a/src/ComputeSharp.Shaders/Translation/Mappings/HlslKnownTypes.cs b/src/ComputeSharp.Shaders/Translation/Mappings/HlslKnownTypes.cs index b2c84d86..5776c971 100644 --- a/src/ComputeSharp.Shaders/Translation/Mappings/HlslKnownTypes.cs +++ b/src/ComputeSharp.Shaders/Translation/Mappings/HlslKnownTypes.cs @@ -79,7 +79,9 @@ namespace ComputeSharp.Shaders.Mappings genericType == typeof(ReadOnlyTexture2D<>) || genericType == typeof(ReadOnlyTexture2D<,>) || genericType == typeof(ReadOnlyTexture3D<>) || - genericType == typeof(ReadOnlyTexture3D<,>); + genericType == typeof(ReadOnlyTexture3D<,>) || + genericType == typeof(IReadOnlyTexture2D<>) || + genericType == typeof(IReadOnlyTexture3D<>); } /// @@ -99,7 +101,9 @@ namespace ComputeSharp.Shaders.Mappings genericType == typeof(ReadWriteTexture2D<>) || genericType == typeof(ReadWriteTexture2D<,>) || genericType == typeof(ReadWriteTexture3D<>) || - genericType == typeof(ReadWriteTexture3D<,>); + genericType == typeof(ReadWriteTexture3D<,>) || + genericType == typeof(IReadWriteTexture2D<>) || + genericType == typeof(IReadWriteTexture3D<>); ; } } } diff --git a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs index e3751ef4..45200de1 100644 --- a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs +++ b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs @@ -21,10 +21,14 @@ namespace ComputeSharp.SourceGenerators.Mappings [$"ComputeSharp.ReadOnlyTexture2D`2.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2", [$"ComputeSharp.ReadWriteTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2", [$"ComputeSharp.ReadWriteTexture2D`2.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2", + [$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2", + [$"ComputeSharp.IReadWriteTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2", [$"ComputeSharp.ReadOnlyTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3", [$"ComputeSharp.ReadOnlyTexture3D`2.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3", [$"ComputeSharp.ReadWriteTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3", - [$"ComputeSharp.ReadWriteTexture3D`2.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3" + [$"ComputeSharp.ReadWriteTexture3D`2.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3", + [$"ComputeSharp.IReadOnlyTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3", + [$"ComputeSharp.IReadWriteTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3" }; /// diff --git a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs index 2bc27d99..22aefe96 100644 --- a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs +++ b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs @@ -78,6 +78,10 @@ namespace ComputeSharp.SourceGenerators.Mappings case "ComputeSharp.ReadOnlyTexture3D`2": case "ComputeSharp.ReadWriteTexture3D`1": case "ComputeSharp.ReadWriteTexture3D`2": + case "ComputeSharp.IReadOnlyTexture2D`1": + case "ComputeSharp.IReadWriteTexture2D`1": + case "ComputeSharp.IReadOnlyTexture3D`1": + case "ComputeSharp.IReadWriteTexture3D`1": return true; default: return false; }; @@ -134,6 +138,10 @@ namespace ComputeSharp.SourceGenerators.Mappings "ComputeSharp.ReadOnlyTexture3D`2" => $"Texture3D", "ComputeSharp.ReadWriteTexture3D`1" => $"RWTexture3D<{mapped}>", "ComputeSharp.ReadWriteTexture3D`2" => $"RWTexture3D", + "ComputeSharp.IReadOnlyTexture2D`1" => $"Texture2D", + "ComputeSharp.IReadWriteTexture2D`1" => $"RWTexture2D", + "ComputeSharp.IReadOnlyTexture3D`1" => $"Texture3D", + "ComputeSharp.IReadWriteTexture3D`1" => $"RWTexture3D", _ => throw new ArgumentException() }; }