Move AlignmentHelper type to Graphics folder
このコミットが含まれているのは:
1 親
c18f833c67
コミット
b44504e1e7
8ファイル変更
+24
-9
検索条件に一致するファイルはありません
@@ -65,7 +65,7 @@
|
||||
<Compile Include="..\ComputeSharp.Core\Primitives\MatrixIndex.cs" Link="ComputeSharp.Core\Primitives\MatrixIndex.cs" />
|
||||
|
||||
<!-- ComputeSharp APIs -->
|
||||
<Compile Include="..\ComputeSharp\Core\Helpers\AlignmentHelper.cs" Link="ComputeSharp\Core\Helpers\AlignmentHelper.cs" />
|
||||
<Compile Include="..\ComputeSharp\Graphics\Helpers\AlignmentHelper.cs" Link="ComputeSharp\Graphics\Helpers\AlignmentHelper.cs" />
|
||||
|
||||
<!-- ComputeSharp.D2D1 APIs -->
|
||||
<Compile Include="..\ComputeSharp.D2D1\Attributes\Enums\D2D1ShaderProfile.cs" Link="ComputeSharp.D2D1\Attributes\Enums\D2D1ShaderProfile.cs" />
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.RegularExpressions;
|
||||
using ComputeSharp.Core.Helpers;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
using ComputeSharp.SourceGeneration.Mappings;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Collections.Immutable;
|
||||
using ComputeSharp.Core.Helpers;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
using ComputeSharp.SourceGeneration.Models;
|
||||
|
||||
@@ -67,9 +67,9 @@
|
||||
<Compile Include="..\ComputeSharp\Core\Dispatch\GroupSize.cs" Link="ComputeSharp\Core\Dispatch\GroupSize.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Dispatch\ThreadIds.cs" Link="ComputeSharp\Core\Dispatch\ThreadIds.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Dispatch\ThreadIds.Normalized.cs" Link="ComputeSharp\Core\Dispatch\ThreadIds.Normalized.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Helpers\AlignmentHelper.cs" Link="ComputeSharp\Core\Helpers\AlignmentHelper.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Interfaces\IComputeShader.cs" Link="ComputeSharp\Core\Interfaces\IComputeShader.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Interfaces\IComputeShader{TPixel}.cs" Link="ComputeSharp\Core\Interfaces\IComputeShader{TPixel}.cs" />
|
||||
<Compile Include="..\ComputeSharp\Graphics\Helpers\AlignmentHelper.cs" Link="ComputeSharp\Graphics\Helpers\AlignmentHelper.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
+5
-1
@@ -1,6 +1,6 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ComputeSharp.Core.Helpers;
|
||||
namespace ComputeSharp.Graphics.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> with helper methods to work with alignment and padding.
|
||||
@@ -31,6 +31,7 @@ internal static class AlignmentHelper
|
||||
return (size + alignment - 1) & ~(alignment - 1);
|
||||
}
|
||||
|
||||
#if SOURCE_GENERATOR
|
||||
/// <summary>
|
||||
/// Aligns a given offset to a specified boundary, if a given size increment would have crossed it.
|
||||
/// </summary>
|
||||
@@ -41,6 +42,8 @@ internal static class AlignmentHelper
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int AlignToBoundary(int offset, int size, int alignment)
|
||||
{
|
||||
// This method is mirrored in AlignmentHelperTests, so it can be tested individually
|
||||
// as well. Any changes done here should be applied to that standalone copy as well.
|
||||
if ((uint)offset / (uint)alignment == (uint)(offset + size - 1) / (uint)alignment)
|
||||
{
|
||||
return offset;
|
||||
@@ -48,4 +51,5 @@ internal static class AlignmentHelper
|
||||
|
||||
return (offset + alignment - 1) & ~(alignment - 1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -3,7 +3,6 @@ using System.Buffers;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.Core.Helpers;
|
||||
using ComputeSharp.Graphics.Commands.Interop;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
|
||||
@@ -2,7 +2,6 @@ using System;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.Core.Helpers;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using ComputeSharp.Graphics.Resources.Interop;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using ComputeSharp.Core.Helpers;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ComputeSharp.Tests.Internals;
|
||||
@@ -33,7 +33,20 @@ public class AlignmentHelperTests
|
||||
[DataRow(24, 8, 16, 24)]
|
||||
public void AlignToBoundary(int offset, int size, int alignment, int expected)
|
||||
{
|
||||
int result = AlignmentHelper.AlignToBoundary(offset, size, alignment);
|
||||
// Note: this method is defined in AlignmentHelper, but it's only compiled when referenced
|
||||
// by the source generator, so it's not available here. Just for the sake of the additional
|
||||
// testing, and because the method is very small, it's just mirrored here for validation.
|
||||
static int AlignToBoundary(int offset, int size, int alignment)
|
||||
{
|
||||
if ((uint)offset / (uint)alignment == (uint)(offset + size - 1) / (uint)alignment)
|
||||
{
|
||||
return offset;
|
||||
}
|
||||
|
||||
return (offset + alignment - 1) & ~(alignment - 1);
|
||||
}
|
||||
|
||||
int result = AlignToBoundary(offset, size, alignment);
|
||||
|
||||
Assert.AreEqual(result, expected);
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする