From 54d7cb53e2fab848ffad06b64313ca9ccfe1da26 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 8 May 2022 14:17:55 +0200 Subject: [PATCH] Add D2D1 input description types --- .../ComputeSharp.D2D1.SourceGenerators.csproj | 1 + .../D2DInputDescriptionAttribute.cs | 41 +++++++++++++ .../Attributes/Enums/D2D1Filter.cs | 57 +++++++++++++++++++ .../ID2D1InputDescriptionsLoader.cs | 18 ++++++ .../Interfaces/__Internals/ID2D1Shader.cs | 10 ++++ .../Shaders/Interop/D2D1InputDescription.cs | 41 +++++++++++++ .../um/d2d1effectauthor/D2D1_FILTER.cs | 21 +++++++ .../TerraFX.Interop.Windows.D2D1.projitems | 1 + 8 files changed, 190 insertions(+) create mode 100644 src/ComputeSharp.D2D1/Attributes/D2DInputDescriptionAttribute.cs create mode 100644 src/ComputeSharp.D2D1/Attributes/Enums/D2D1Filter.cs create mode 100644 src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1InputDescriptionsLoader.cs create mode 100644 src/ComputeSharp.D2D1/Shaders/Interop/D2D1InputDescription.cs create mode 100644 src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1effectauthor/D2D1_FILTER.cs diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj index 3ca380e3..2716303d 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj +++ b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj @@ -77,6 +77,7 @@ + diff --git a/src/ComputeSharp.D2D1/Attributes/D2DInputDescriptionAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DInputDescriptionAttribute.cs new file mode 100644 index 00000000..8bafd59e --- /dev/null +++ b/src/ComputeSharp.D2D1/Attributes/D2DInputDescriptionAttribute.cs @@ -0,0 +1,41 @@ +using System; + +namespace ComputeSharp.D2D1; + +/// +/// An attribute for a D2D1 shader indicating the description of a given input resource. +/// This attribute is optional, and not using it will cause no description to be declared. +/// +/// +/// This attribute exposes the options that can be set via D2D1_INPUT_DESCRIPTION. +/// For more info, see . +/// +[AttributeUsage(AttributeTargets.Struct, AllowMultiple = true)] +public sealed class D2DInputDescriptionAttribute : Attribute +{ + /// + /// Creates a new instance of the type with the specified arguments. + /// + /// The index of the resource to declare the description for. + /// The type of filter to apply to the input texture. + public D2DInputDescriptionAttribute(int index, D2D1Filter filter) + { + Index = index; + Filter = filter; + } + + /// + /// Gets the index of the resource to declare the description for. + /// + public int Index { get; } + + /// + /// Gets the type of filter to apply to the input texture. + /// + public D2D1Filter Filter { get; } + + /// + /// Gets the mip level to retrieve from the upstream transform, if specified. + /// + public int LevelOfDetail { get; init; } +} diff --git a/src/ComputeSharp.D2D1/Attributes/Enums/D2D1Filter.cs b/src/ComputeSharp.D2D1/Attributes/Enums/D2D1Filter.cs new file mode 100644 index 00000000..29a6b9fa --- /dev/null +++ b/src/ComputeSharp.D2D1/Attributes/Enums/D2D1Filter.cs @@ -0,0 +1,57 @@ +using static TerraFX.Interop.DirectX.D2D1_FILTER; + +namespace ComputeSharp.D2D1; + +/// +/// Represents the filtering mode that a transform may select to use on input textures. +/// +/// +/// This type exposes the available values in . +/// +public enum D2D1Filter +{ + /// + /// Use point sampling for minification, magnification, and mip-level sampling. + /// + MinMagMipPoint = (int)D2D1_FILTER_MIN_MAG_MIP_POINT, + + /// + /// Use point sampling for minification and magnification, use linear interpolation for mip-level sampling. + /// + MinMagPointMipLinear = (int)D2D1_FILTER_MIN_MAG_POINT_MIP_LINEAR, + + /// + /// Use point sampling for minification, use linear interpolation for magnification, use point sampling for mip-level sampling. + /// + MinPointMagLinearMipPoint = (int)D2D1_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, + + /// + /// Use point sampling for minification, use linear interpolation for magnification and mip-level sampling. + /// + MinPointMagMipLinear = (int)D2D1_FILTER_MIN_POINT_MAG_MIP_LINEAR, + + /// + /// Use linear interpolation for minification, use point sampling for magnification and mip-level sampling. + /// + MinLinearMagMipPoint = (int)D2D1_FILTER_MIN_LINEAR_MAG_MIP_POINT, + + /// + /// Use linear interpolation for minification, use point sampling for magnification, use linear interpolation for mip-level sampling. + /// + MinLinearMagPointMinLinear = (int)D2D1_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, + + /// + /// Use linear interpolation for minification and magnification, use point sampling for mip-level sampling. + /// + MinMagLinearMipPoint = (int)D2D1_FILTER_MIN_MAG_LINEAR_MIP_POINT, + + /// + /// Use linear interpolation for minification, magnification, and mip-level sampling. + /// + MinMagMipLinear = (int)D2D1_FILTER_MIN_MAG_MIP_LINEAR, + + /// + /// Use anisotropic interpolation for minification, magnification, and mip-level sampling. + /// + Anisotropic = (int)D2D1_FILTER_ANISOTROPIC +} diff --git a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1InputDescriptionsLoader.cs b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1InputDescriptionsLoader.cs new file mode 100644 index 00000000..b5ebd493 --- /dev/null +++ b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1InputDescriptionsLoader.cs @@ -0,0 +1,18 @@ +using System; +using System.ComponentModel; + +namespace ComputeSharp.D2D1.__Internals; + +/// +/// A base representing a loader for input descriptions in a D2D1 shader. +/// +[EditorBrowsable(EditorBrowsableState.Never)] +[Obsolete("This interface is not intended to be used directly by user code")] +public interface ID2D1InputDescriptionsLoader +{ + /// + /// Loads the available input descriptions for the shader. + /// + /// The sequence of serialized input descriptions. + void LoadInputDescriptions(ReadOnlySpan data); +} diff --git a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs index 035d7b52..11cd5ae3 100644 --- a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs +++ b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs @@ -37,6 +37,16 @@ public interface ID2D1Shader [Obsolete("This method is not intended to be used directly by user code")] uint GetInputType(uint index); + /// + /// Loads the input descriptions for the shader, if any. + /// + /// The type of input descriptions loader being used. + /// The instance to use to load the input descriptions. + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method is not intended to be used directly by user code")] + void LoadInputDescriptions(ref TLoader loader) + where TLoader : struct, ID2D1InputDescriptionsLoader; + /// /// Gets the output buffer precision and depth for the shader. /// diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1InputDescription.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1InputDescription.cs new file mode 100644 index 00000000..4566f288 --- /dev/null +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1InputDescription.cs @@ -0,0 +1,41 @@ +using System; + +namespace ComputeSharp.D2D1.Interop; + +/// +/// A type containing info on a description for a given D2D1 pixel shader input resource. +/// +/// +/// This type exposes the values that can be set via ID2D1RenderInfo::SetInputDescription. +/// For more info, see . +/// +public readonly struct D2D1InputDescription +{ + /// + /// Creates a new instance with the specified parameters. + /// + /// The index of the resource the description belongs to. + /// The type of filter to apply to the input texture. + /// The mip level to retrieve from the upstream transform, if specified. + internal D2D1InputDescription(int index, D2D1Filter filter, int levelOfDetail) + { + Index = index; + Filter = filter; + LevelOfDetail = levelOfDetail; + } + + /// + /// Gets the index of the resource the description belongs to. + /// + public int Index { get; } + + /// + /// Gets the type of filter to apply to the input texture. + /// + public D2D1Filter Filter { get; } + + /// + /// Gets the mip level to retrieve from the upstream transform, if specified. + /// + public int LevelOfDetail { get; } +} diff --git a/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1effectauthor/D2D1_FILTER.cs b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1effectauthor/D2D1_FILTER.cs new file mode 100644 index 00000000..7f6d604c --- /dev/null +++ b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1effectauthor/D2D1_FILTER.cs @@ -0,0 +1,21 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +// Ported from um/d2d1effectauthor.h in the Windows SDK for Windows 10.0.22000.0 +// Original source is Copyright © Microsoft. All rights reserved. + +namespace TerraFX.Interop.DirectX +{ + internal enum D2D1_FILTER : uint + { + D2D1_FILTER_MIN_MAG_MIP_POINT = 0x00, + D2D1_FILTER_MIN_MAG_POINT_MIP_LINEAR = 0x01, + D2D1_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT = 0x04, + D2D1_FILTER_MIN_POINT_MAG_MIP_LINEAR = 0x05, + D2D1_FILTER_MIN_LINEAR_MAG_MIP_POINT = 0x10, + D2D1_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR = 0x11, + D2D1_FILTER_MIN_MAG_LINEAR_MIP_POINT = 0x14, + D2D1_FILTER_MIN_MAG_MIP_LINEAR = 0x15, + D2D1_FILTER_ANISOTROPIC = 0x55, + D2D1_FILTER_FORCE_DWORD = 0xffffffff + } +} \ No newline at end of file diff --git a/src/TerraFX.Interop.Windows.D2D1/TerraFX.Interop.Windows.D2D1.projitems b/src/TerraFX.Interop.Windows.D2D1/TerraFX.Interop.Windows.D2D1.projitems index 70a7135d..da6f98fe 100644 --- a/src/TerraFX.Interop.Windows.D2D1/TerraFX.Interop.Windows.D2D1.projitems +++ b/src/TerraFX.Interop.Windows.D2D1/TerraFX.Interop.Windows.D2D1.projitems @@ -11,6 +11,7 @@ +