diff --git a/src/ComputeSharp.D2D1.Uwp/Buffers/FixedCountList{T}.cs b/src/ComputeSharp.D2D1.Uwp/Buffers/FixedCountList{T}.cs index 44204a5f..19026aca 100644 --- a/src/ComputeSharp.D2D1.Uwp/Buffers/FixedCountList{T}.cs +++ b/src/ComputeSharp.D2D1.Uwp/Buffers/FixedCountList{T}.cs @@ -25,12 +25,12 @@ internal static class FixedCountList Span span = array.AsSpan(index); - if (list.Count > span.Length) + if (list.Indices.Length > span.Length) { ThrowHelper.ThrowArgumentException(nameof(array), "The destination array range is smaller than the number of source items."); } - for (int i = 0; i < list.Count; i++) + foreach (int i in list.Indices) { span[i] = list[i]; } @@ -56,12 +56,12 @@ internal static class FixedCountList int remainingLength = array.Length - index; - if (list.Count > remainingLength) + if (list.Indices.Length > remainingLength) { ThrowHelper.ThrowArgumentException(nameof(array), "The destination array range is smaller than the number of source items."); } - for (int i = 0; i < list.Count; i++) + foreach (int i in list.Indices) { array.SetValue(list[i], i); } @@ -74,7 +74,7 @@ internal static class FixedCountList /// An instance for . public static IEnumerator GetEnumerator(IFixedCountList list) { - for (int i = 0; i < list.Count; i++) + foreach (int i in list.Indices) { yield return list[i]; } @@ -93,7 +93,7 @@ internal static class FixedCountList /// public static int IndexOf(IFixedCountList list, T value) { - for (int i = 0; i < list.Count; i++) + foreach (int i in list.Indices) { if (EqualityComparer.Default.Equals(list[i], value)) { diff --git a/src/ComputeSharp.D2D1.Uwp/Buffers/IFixedCountList{T}.cs b/src/ComputeSharp.D2D1.Uwp/Buffers/IFixedCountList{T}.cs index 73ebb200..175cb0a1 100644 --- a/src/ComputeSharp.D2D1.Uwp/Buffers/IFixedCountList{T}.cs +++ b/src/ComputeSharp.D2D1.Uwp/Buffers/IFixedCountList{T}.cs @@ -1,5 +1,5 @@ -using System.Collections; using System.Collections.Generic; +using System.Collections.Immutable; namespace ComputeSharp.D2D1.Uwp.Buffers; @@ -9,8 +9,10 @@ namespace ComputeSharp.D2D1.Uwp.Buffers; /// The type of elements in the list. interface IFixedCountList { - /// - int Count { get; } + /// + /// Gets the collection of valid indices for the current effect. + /// + ImmutableArray Indices { get; } /// T this[int index] { get; set; } diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Sources.cs b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Sources.cs index 83b54ca1..c2fb27de 100644 --- a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Sources.cs +++ b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Sources.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Collections.Immutable; using System.Runtime.CompilerServices; using ComputeSharp.D2D1.Helpers; using ComputeSharp.D2D1.Interop; @@ -17,6 +18,11 @@ partial class PixelShaderEffect /// public sealed class SourceCollection : IList, IReadOnlyList, IList, IFixedCountList { + /// + /// The collection of valid resource texture indices for the current effect. + /// + private static readonly ImmutableArray Indices = GetIndices(); + /// /// The fixed buffer of instances. /// @@ -72,6 +78,9 @@ partial class PixelShaderEffect /// internal ref GraphicsEffectSourceBuffer Storage => ref this.fixedBuffer; + /// + ImmutableArray IFixedCountList.Indices => Indices; + /// bool ICollection.IsReadOnly => false; @@ -208,5 +217,28 @@ partial class PixelShaderEffect ThrowHelper.ThrowArgumentOutOfRangeException(nameof(index), "The input index is not a valid source index for the current effect."); } } + + /// + /// Gets the collection of valid indices for the current effect. + /// + /// The collection of valid indices for the current effect. + private static unsafe ImmutableArray GetIndices() + { + int inputCount = D2D1PixelShader.GetInputCount(); + + if (inputCount == 0) + { + return ImmutableArray.Empty; + } + + int[] indices = new int[inputCount]; + + for (int i = 0; i < indices.Length; i++) + { + indices[i] = i; + } + + return *(ImmutableArray*)&indices; + } } } \ No newline at end of file