Add support for dynamic indices to IFixedCountList<T>
このコミットが含まれているのは:
1 親
ec2e1e15f0
コミット
7cf711cf59
3ファイル変更
+43
-9
検索条件に一致するファイルはありません
@@ -25,12 +25,12 @@ internal static class FixedCountList<T>
|
||||
|
||||
Span<T> 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<T>
|
||||
|
||||
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<T>
|
||||
/// <returns>An <see cref="IEnumerable{T}"/> instance for <paramref name="list"/>.</returns>
|
||||
public static IEnumerator<T> GetEnumerator(IFixedCountList<T> 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<T>
|
||||
/// </returns>
|
||||
public static int IndexOf(IFixedCountList<T> list, T value)
|
||||
{
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
foreach (int i in list.Indices)
|
||||
{
|
||||
if (EqualityComparer<T>.Default.Equals(list[i], value))
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
/// <typeparam name="T">The type of elements in the list.</typeparam>
|
||||
interface IFixedCountList<T>
|
||||
{
|
||||
/// <inheritdoc cref="ICollection.Count"/>
|
||||
int Count { get; }
|
||||
/// <summary>
|
||||
/// Gets the collection of valid indices for the current effect.
|
||||
/// </summary>
|
||||
ImmutableArray<int> Indices { get; }
|
||||
|
||||
/// <inheritdoc cref="IList{T}.this"/>
|
||||
T this[int index] { get; set; }
|
||||
|
||||
@@ -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<T>
|
||||
/// </summary>
|
||||
public sealed class SourceCollection : IList<IGraphicsEffectSource?>, IReadOnlyList<IGraphicsEffectSource?>, IList, IFixedCountList<IGraphicsEffectSource?>
|
||||
{
|
||||
/// <summary>
|
||||
/// The collection of valid resource texture indices for the current effect.
|
||||
/// </summary>
|
||||
private static readonly ImmutableArray<int> Indices = GetIndices();
|
||||
|
||||
/// <summary>
|
||||
/// The fixed buffer of <see cref="IGraphicsEffectSource"/> instances.
|
||||
/// </summary>
|
||||
@@ -72,6 +78,9 @@ partial class PixelShaderEffect<T>
|
||||
/// </summary>
|
||||
internal ref GraphicsEffectSourceBuffer Storage => ref this.fixedBuffer;
|
||||
|
||||
/// <inheritdoc/>
|
||||
ImmutableArray<int> IFixedCountList<IGraphicsEffectSource?>.Indices => Indices;
|
||||
|
||||
/// <inheritdoc/>
|
||||
bool ICollection<IGraphicsEffectSource?>.IsReadOnly => false;
|
||||
|
||||
@@ -208,5 +217,28 @@ partial class PixelShaderEffect<T>
|
||||
ThrowHelper.ThrowArgumentOutOfRangeException(nameof(index), "The input index is not a valid source index for the current effect.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of valid indices for the current effect.
|
||||
/// </summary>
|
||||
/// <returns>The collection of valid indices for the current effect.</returns>
|
||||
private static unsafe ImmutableArray<int> GetIndices()
|
||||
{
|
||||
int inputCount = D2D1PixelShader.GetInputCount<T>();
|
||||
|
||||
if (inputCount == 0)
|
||||
{
|
||||
return ImmutableArray<int>.Empty;
|
||||
}
|
||||
|
||||
int[] indices = new int[inputCount];
|
||||
|
||||
for (int i = 0; i < indices.Length; i++)
|
||||
{
|
||||
indices[i] = i;
|
||||
}
|
||||
|
||||
return *(ImmutableArray<int>*)&indices;
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする