104 行
2.8 KiB
C#
104 行
2.8 KiB
C#
using System.Threading;
|
|
using ComputeSharp.Interop;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
namespace ComputeSharp.Tests
|
|
{
|
|
[TestClass]
|
|
[TestCategory("ShaderCompiler")]
|
|
public partial class ShaderCompilerTests
|
|
{
|
|
[TestMethod]
|
|
public void ReservedKeywords()
|
|
{
|
|
ReflectionServices.GetShaderInfo<ReservedKeywordsShader>(out _);
|
|
}
|
|
|
|
[AutoConstructor]
|
|
public readonly partial struct ReservedKeywordsShader : IComputeShader
|
|
{
|
|
public readonly ReadWriteBuffer<float> row_major;
|
|
public readonly float dword;
|
|
|
|
public void Execute()
|
|
{
|
|
float exp = Hlsl.Exp(dword * row_major[ThreadIds.X]);
|
|
float log = Hlsl.Log(1 + exp);
|
|
|
|
row_major[ThreadIds.X] = log / dword;
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void SpecialTypeAsReturnType()
|
|
{
|
|
ReflectionServices.GetShaderInfo<SpecialTypeAsReturnTypeShader>(out _);
|
|
}
|
|
|
|
[AutoConstructor]
|
|
public readonly partial struct SpecialTypeAsReturnTypeShader : IComputeShader
|
|
{
|
|
public readonly ReadWriteBuffer<Float2> buffer;
|
|
|
|
Float2 Foo(float x) => x;
|
|
|
|
public void Execute()
|
|
{
|
|
static Float3 Bar(float x) => x;
|
|
|
|
buffer[ThreadIds.X] = Foo(ThreadIds.X) + Bar(ThreadIds.X).XY;
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void LocalFunctionInExternalMethods()
|
|
{
|
|
ReflectionServices.GetShaderInfo<LocalFunctionInExternalMethodsShader>(out _);
|
|
}
|
|
|
|
[AutoConstructor]
|
|
public readonly partial struct LocalFunctionInExternalMethodsShader : IComputeShader
|
|
{
|
|
public readonly ReadWriteBuffer<Float2> buffer;
|
|
|
|
Float2 Foo(float x)
|
|
{
|
|
static Float2 Baz(float y) => y;
|
|
|
|
return Baz(x);
|
|
}
|
|
|
|
public void Execute()
|
|
{
|
|
buffer[ThreadIds.X] = Foo(ThreadIds.X);
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void CapturedNestedStructType()
|
|
{
|
|
ReflectionServices.GetShaderInfo<CapturedNestedStructTypeShader>(out _);
|
|
}
|
|
|
|
[AutoConstructor]
|
|
public partial struct CustomStructType
|
|
{
|
|
public Float2 a;
|
|
public int b;
|
|
}
|
|
|
|
[AutoConstructor]
|
|
public readonly partial struct CapturedNestedStructTypeShader : IComputeShader
|
|
{
|
|
public readonly ReadWriteBuffer<float> buffer;
|
|
public readonly CustomStructType foo;
|
|
|
|
/// <inheritdoc/>
|
|
public void Execute()
|
|
{
|
|
buffer[ThreadIds.X] *= foo.a.X + foo.b;
|
|
}
|
|
}
|
|
}
|
|
}
|