From e2550a2b548a50a433a94f641f39de95269b52c8 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 2 Dec 2022 15:12:54 +0100 Subject: [PATCH] Add fixed buffer type for SourceCollection --- ...erties.ResourceTextureManagerCollection.cs | 20 +-- ...PixelShaderEffect{T}.Properties.Sources.cs | 163 ++++++++++++++++++ .../PixelShaderEffect{T}.Properties.cs | 33 ---- 3 files changed, 173 insertions(+), 43 deletions(-) create mode 100644 src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Sources.cs diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs index fed84087..65922e42 100644 --- a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs +++ b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs @@ -28,16 +28,6 @@ partial class PixelShaderEffect Owner = owner; } - /// - /// The owning instance. - /// - internal PixelShaderEffect Owner { get; } - - /// - /// Gets a reference to the value containing the available -s. - /// - internal ref FixedBuffer Storage => ref this.fixedBuffer; - /// /// Gets or sets the object at a specified index. /// @@ -52,6 +42,16 @@ partial class PixelShaderEffect set => Owner.SetResourceTextureManager(value, index); } + /// + /// The owning instance. + /// + internal PixelShaderEffect Owner { get; } + + /// + /// Gets a reference to the value containing the available -s. + /// + internal ref FixedBuffer Storage => ref this.fixedBuffer; + /// /// A fixed buffer type containing 16 fields. /// diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Sources.cs b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Sources.cs new file mode 100644 index 00000000..c1d9654a --- /dev/null +++ b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Sources.cs @@ -0,0 +1,163 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using ComputeSharp.D2D1.Helpers; +using Windows.Graphics.Effects; + +namespace ComputeSharp.D2D1.Uwp; + +/// +partial class PixelShaderEffect +{ + /// + /// Represents the collection of sources in a instance. + /// + public sealed class SourceCollection + { + /// + /// The fixed buffer of instances. + /// + private FixedBuffer fixedBuffer; + + /// + /// Creates a new instance with the specified parameters. + /// + /// The owning instance. + internal SourceCollection(PixelShaderEffect owner) + { + Owner = owner; + } + + /// + /// Gets or sets the source at a specified index. + /// + /// The index of the source to get or set. + /// The source at the specified index. + /// Thrown if is not a valid index for the current effect. + public IGraphicsEffectSource this[int index] + { + get => null!; + set { } + } + + /// + /// The owning instance. + /// + internal PixelShaderEffect Owner { get; } + + /// + /// Gets a reference to the value containing the available -s. + /// + internal ref FixedBuffer Storage => ref this.fixedBuffer; + + /// + /// A fixed buffer type containing 16 fields. + /// + internal struct FixedBuffer + { + /// + /// The instance at index 0. + /// + public IGraphicsEffectSource? Source0; + + /// + /// The instance at index 1. + /// + public IGraphicsEffectSource? Source1; + + /// + /// The instance at index 2. + /// + public IGraphicsEffectSource? Source2; + + /// + /// The instance at index 3. + /// + public IGraphicsEffectSource? Source3; + + /// + /// The instance at index 4. + /// + public IGraphicsEffectSource? Source4; + + /// + /// The instance at index 5. + /// + public IGraphicsEffectSource? Source5; + + /// + /// The instance at index 6. + /// + public IGraphicsEffectSource? Source6; + + /// + /// The instance at index 7. + /// + public IGraphicsEffectSource? Source7; + + /// + /// The instance at index 8. + /// + public IGraphicsEffectSource? Source8; + + /// + /// The instance at index 9. + /// + public IGraphicsEffectSource? Source9; + + /// + /// The instance at index 10. + /// + public IGraphicsEffectSource? Source10; + + /// + /// The instance at index 11. + /// + public IGraphicsEffectSource? Source11; + + /// + /// The instance at index 12. + /// + public IGraphicsEffectSource? Source12; + + /// + /// The instance at index 13. + /// + public IGraphicsEffectSource? Source13; + + /// + /// The instance at index 14. + /// + public IGraphicsEffectSource? Source14; + + /// + /// The instance at index 15. + /// + public IGraphicsEffectSource? Source15; + + /// + /// Gets a reference to the value at a given index. + /// + /// The index of the value to get a reference to. + /// A reference to the value at a given index. + /// Thrown if is not a valid index for the current effect. + [UnscopedRef] + public ref IGraphicsEffectSource? this[int index] + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + if ((uint)index >= 16) + { + ThrowHelper.ThrowArgumentOutOfRangeException(nameof(index), "The index must be in the [0, 15] range."); + } + + ref IGraphicsEffectSource? r0 = ref Unsafe.As(ref this); + ref IGraphicsEffectSource? r1 = ref Unsafe.Add(ref r0, index); + + return ref r1; + } + } + } + } +} \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.cs b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.cs index 15d321de..74954eda 100644 --- a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.cs +++ b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.cs @@ -2,7 +2,6 @@ using System; using System.Diagnostics.CodeAnalysis; using ComputeSharp.D2D1.Interop; using Microsoft.Graphics.Canvas; -using Windows.Graphics.Effects; namespace ComputeSharp.D2D1.Uwp; @@ -57,36 +56,4 @@ partial class PixelShaderEffect /// Gets the object associated with the current instance. /// public ResourceTextureManagerCollection ResourceTextureManagers { get; } - - /// - /// Represents the collection of sources in a instance. - /// - public sealed class SourceCollection - { - /// - /// Creates a new instance with the specified parameters. - /// - /// The owning instance. - internal SourceCollection(PixelShaderEffect owner) - { - Owner = owner; - } - - /// - /// The owning instance. - /// - internal PixelShaderEffect Owner { get; } - - /// - /// Gets or sets the source at a specified index. - /// - /// The index of the source to get or set. - /// The source at the specified index. - /// Thrown if is not a valid index for the current effect. - public IGraphicsEffectSource this[int index] - { - get => null!; - set { } - } - } } \ No newline at end of file