Fixed internal unit tests
このコミットが含まれているのは:
1 親
3f87743427
コミット
625a9d05f0
4ファイル変更
+36
-161
検索条件に一致するファイルはありません
@@ -13,24 +13,8 @@ namespace ComputeSharp.Tests.Internals
|
||||
{
|
||||
Func<int, int> square = DynamicMethod<Func<int, int>>.New(il =>
|
||||
{
|
||||
il.Emit(OpCodes.Ldarg_1);
|
||||
il.Emit(OpCodes.Dup);
|
||||
il.Emit(OpCodes.Mul);
|
||||
il.Emit(OpCodes.Ret);
|
||||
});
|
||||
|
||||
int result = square(2); // result = 2 * 2
|
||||
|
||||
Assert.IsTrue(result == 4);
|
||||
}
|
||||
|
||||
public delegate int Square(int x);
|
||||
|
||||
[TestMethod]
|
||||
public void TestSquare()
|
||||
{
|
||||
Square square = DynamicMethod<Square>.New(il =>
|
||||
{
|
||||
// Due to the instance method trick, the first parameter is at offset 1.
|
||||
// See the docs on DynamicMethod<T>.New for more info on how this works.
|
||||
il.Emit(OpCodes.Ldarg_1);
|
||||
il.Emit(OpCodes.Dup);
|
||||
il.Emit(OpCodes.Mul);
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System.Numerics;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ComputeSharp.Tests.Internals
|
||||
{
|
||||
/// <summary>
|
||||
/// A container <see langword="class"/> for static fields and properties to test
|
||||
/// </summary>
|
||||
public sealed class StaticMembersContainer
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="static"/> <see langword="readonly"/> <see langword="int"/> field
|
||||
/// </summary>
|
||||
public static readonly int Field = 7;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="static"/> <see langword="int"/> property
|
||||
/// </summary>
|
||||
public static int Property { get; } = 44;
|
||||
}
|
||||
|
||||
[TestClass]
|
||||
[TestCategory("ReadableMembers")]
|
||||
public class ReadableMemberTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void PropertyGetter()
|
||||
{
|
||||
string text = "Hello world";
|
||||
|
||||
ReadableMember member = typeof(string).GetProperty(nameof(string.Length));
|
||||
|
||||
object value = member.GetValue(text);
|
||||
|
||||
Assert.IsTrue((int)value == text.Length);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void FieldGetter()
|
||||
{
|
||||
Vector4 vector = new Vector4(7, 0, 0, 0);
|
||||
|
||||
ReadableMember member = typeof(Vector4).GetField(nameof(Vector4.X));
|
||||
|
||||
object value = member.GetValue(vector);
|
||||
|
||||
Assert.IsTrue((int)(float)value == (int)vector.X);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void StaticFieldGetter()
|
||||
{
|
||||
ReadableMember member = typeof(StaticMembersContainer).GetField(nameof(StaticMembersContainer.Field), BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
|
||||
|
||||
object value = member.GetValue(null);
|
||||
|
||||
Assert.IsTrue((int)value == StaticMembersContainer.Field);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void StaticPropertyGetter()
|
||||
{
|
||||
ReadableMember member = typeof(StaticMembersContainer).GetProperty(nameof(StaticMembersContainer.Property), BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
|
||||
|
||||
object value = member.GetValue(null);
|
||||
|
||||
Assert.IsTrue((int)value == StaticMembersContainer.Property);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using ComputeSharp.Shaders.Translation;
|
||||
using ComputeSharp.Exceptions;
|
||||
using ComputeSharp.Shaders.Translation;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using TerraFX.Interop;
|
||||
|
||||
@@ -9,43 +10,37 @@ namespace ComputeSharp.Tests.Internals
|
||||
public class ShaderCompilerTests
|
||||
{
|
||||
private const string ShaderSource = @"
|
||||
/* ===============
|
||||
* AUTO GENERATED
|
||||
* ===============
|
||||
* This shader was created by ComputeSharp.
|
||||
* For info or issues: https://github.com/Sergio0694/ComputeSharp */
|
||||
|
||||
// Scalar/vector variables
|
||||
cbuffer _ : register(b0)
|
||||
{
|
||||
uint __x__; // Target X iterations
|
||||
uint __y__; // Target Y iterations
|
||||
uint __z__; // Target Z iterations
|
||||
int width;
|
||||
uint __x;
|
||||
uint __y;
|
||||
uint __z;
|
||||
}
|
||||
|
||||
// ReadWriteBuffer<float> buffer ""buffer""
|
||||
RWStructuredBuffer<float> buffer : register(u1);
|
||||
RWStructuredBuffer<float> buffer : register(u0);
|
||||
|
||||
// Shader body
|
||||
[Shader(""compute"")]
|
||||
[NumThreads(32, 1, 1)]
|
||||
void CSMain(uint3 ids : SV_DispatchThreadId)
|
||||
void Execute(uint3 ids : SV_DispatchThreadId)
|
||||
{
|
||||
if (ids.x < __x__ &&
|
||||
ids.y < __y__ &&
|
||||
ids.z < __z__) // Automatic bounds check
|
||||
if (ids.x < __x && ids.y < __y && ids.z < __z)
|
||||
{
|
||||
int i = ids.x + ids.y * width;
|
||||
buffer[i] *= 2;
|
||||
buffer[ids.x] *= 2;
|
||||
}
|
||||
}
|
||||
";
|
||||
}";
|
||||
|
||||
[TestMethod]
|
||||
public void CompileTest()
|
||||
public void CompileTest_Ok()
|
||||
{
|
||||
using ComPtr<IDxcBlob> dxcBlob = ShaderCompiler.CompileShader(ShaderSource);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(HlslCompilationException))]
|
||||
public void CompileTest_Fail()
|
||||
{
|
||||
var faultyShader = ShaderSource.Replace("ids.x", "ids.X");
|
||||
|
||||
using ComPtr<IDxcBlob> dxcBlob = ShaderCompiler.CompileShader(faultyShader);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,33 +18,11 @@ namespace ComputeSharp.Tests.Internals
|
||||
{
|
||||
string source = @"
|
||||
using System.Numerics;
|
||||
using MyLibrary;
|
||||
using ComputeSharp;
|
||||
|
||||
namespace ComputeSharp
|
||||
{
|
||||
public readonly struct ThreadIds
|
||||
{
|
||||
public int X => throw null;
|
||||
public int Y => throw null;
|
||||
public int Z => throw null;
|
||||
}
|
||||
|
||||
public interface IComputeShader
|
||||
{
|
||||
void Execute((int X, int Y, int Z) ids);
|
||||
}
|
||||
}
|
||||
|
||||
namespace MyLibrary
|
||||
{
|
||||
public class Buffer<T>
|
||||
{
|
||||
}
|
||||
|
||||
public interface IFluff
|
||||
{
|
||||
}
|
||||
public class ReadWriteBuffer<T> { }
|
||||
}
|
||||
|
||||
namespace MyFancyApp.Sample
|
||||
@@ -55,50 +33,39 @@ namespace ComputeSharp.Tests.Internals
|
||||
public partial class Foo
|
||||
{
|
||||
[AutoConstructor]
|
||||
public readonly partial struct MyShader : IComputeShader
|
||||
public readonly partial struct Test
|
||||
{
|
||||
private readonly Buffer<Vector4> A;
|
||||
private readonly Vector4 B;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(ThreadIds ids)
|
||||
{
|
||||
Vector4 foo = default;
|
||||
Vector4 bar = default(Vector4);
|
||||
Vector4 baz = B;
|
||||
A[ids.X] = (Vector4)foo + bar + baz;
|
||||
}
|
||||
private readonly float a;
|
||||
private readonly Vector2 b;
|
||||
public readonly ReadWriteBuffer<Vector4> c;
|
||||
public readonly ReadWriteBuffer<int> d;
|
||||
}
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
string expectedForAutoConstructor = @"
|
||||
string expected = @"
|
||||
namespace MyFancyApp.Sample
|
||||
{
|
||||
public partial interface IFoo<T>
|
||||
{
|
||||
public partial class Foo
|
||||
{
|
||||
public readonly partial struct MyShader
|
||||
public readonly partial struct Test
|
||||
{
|
||||
public MyShader(MyLibrary.Buffer<System.Numerics.Vector4> A, System.Numerics.Vector4 B)
|
||||
public Test(float a, System.Numerics.Vector2 b, ComputeSharp.ReadWriteBuffer<System.Numerics.Vector4> c, ComputeSharp.ReadWriteBuffer<int> d)
|
||||
{
|
||||
this.A = A;
|
||||
this.B = B;
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
this.c = c;
|
||||
this.d = d;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
VerifyGeneratedMethodLines<AutoConstructorAttributeGenerator>(source, 0, expectedForAutoConstructor);
|
||||
|
||||
string expectedForShaderSource = @"
|
||||
#pragma warning disable
|
||||
[assembly: ComputeSharp.IComputeShaderSource(""MyFancyApp.Sample.IFoo`1+Foo+MyShader"", ""Execute"", ""void CSMain(uint3 ids : SV_DispatchThreadId)\r\n{\r\n if (ids.x < __x && ids.y < __y && ids.z < __z)\r\n {\r\n float4 foo = (float4)0;\r\n float4 bar = (float4)0;\r\n float4 baz = B;\r\n A[ids.x] = (float4)foo + bar + baz;\r\n }\r\n}"")]";
|
||||
|
||||
VerifyGeneratedMethodLines<IComputeShaderSourceAttributeGenerator>(source, 0, expectedForShaderSource);
|
||||
VerifyGeneratedMethodLines<AutoConstructorGenerator>(source, 0, expected);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする