Add test project for embedded bytecode shaders
このコミットが含まれているのは:
1 親
9b2518cd54
コミット
980aec572e
4ファイル変更
+223
検索条件に一致するファイルはありません
+52
@@ -0,0 +1,52 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net472;netcoreapp3.1;net6.0</TargetFrameworks>
|
||||
<IsPackable>false</IsPackable>
|
||||
<Platforms>AnyCPU;x64;ARM64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
|
||||
<PackageReference Include="Microsoft.Toolkit.HighPerformance" Version="7.1.2" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\ComputeSharp\ComputeSharp.csproj" />
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.SourceGenerators\ComputeSharp.SourceGenerators.csproj"
|
||||
OutputItemType="Analyzer"
|
||||
ReferenceOutputAssembly="false"
|
||||
PrivateAssets="contentfiles;build" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Define DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT if requested -->
|
||||
<PropertyGroup Condition="'$(DisableShaderCompilationSupport)' == 'true'">
|
||||
<DefineConstants>$(DefineConstants);DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- When the .NET Standard 2.0 version of ComputeSharp is resolved, the TerraFX APIs are internal, as they
|
||||
are referenced from the shared project. The same reference is needed here to make all tests build fine. -->
|
||||
<Import Condition="'$(TargetFramework)' != 'net6.0'" Project="..\..\src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.projitems" />
|
||||
<Import Condition="'$(TargetFramework)' != 'net6.0'" Project="..\..\src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems" />
|
||||
|
||||
<!-- Only when the local TerraFX is referenced, ignore warnings from there -->
|
||||
<PropertyGroup Condition="'$(TargetFramework)' != 'net6.0'">
|
||||
<NoWarn>$(NoWarn);CS0649</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\ComputeSharp.Tests\Attributes\AdditionalDataAttribute.cs" Link="Attributes\AdditionalDataAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Tests\Attributes\AdditionalResourceAttribute.cs" Link="Attributes\AdditionalResourceAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Tests\Attributes\AllDevicesAttribute.cs" Link="Attributes\AllDevicesAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Tests\Attributes\CombinatorialTestMethodAttribute.cs" Link="Attributes\CombinatorialTestMethodAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Tests\Attributes\DataAttribute.cs" Link="Attributes\DataAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Tests\Attributes\DeviceAttribute.cs" Link="Attributes\DeviceAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Tests\Attributes\ResourceAttribute.cs" Link="Attributes\ResourceAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Tests\Extensions\DeviceExtensions.cs" Link="Extensions\DeviceExtensions.cs" />
|
||||
<Compile Include="..\ComputeSharp.Tests\Extensions\GraphicsDeviceExtensions.cs" Link="Extensions\GraphicsDeviceExtensions.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,147 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using ComputeSharp.Interop;
|
||||
using ComputeSharp.Tests.Attributes;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ComputeSharp.Tests.DisableDynamicCompilation;
|
||||
|
||||
[TestClass]
|
||||
[TestCategory("Dispatch")]
|
||||
public partial class DispatchTests
|
||||
{
|
||||
private static readonly bool IsDynamicCompilationDisabled =
|
||||
#if DISABLE_RUNTIME_SHADER_COMPILATION_SUPPORT
|
||||
true;
|
||||
#else
|
||||
false;
|
||||
#endif
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void ComputeShader_Test_Ok(Device device)
|
||||
{
|
||||
if (!IsDynamicCompilationDisabled)
|
||||
{
|
||||
Assert.Inconclusive();
|
||||
}
|
||||
|
||||
float[] array = Enumerable.Range(0, 128).Select(static i => (float)i).ToArray();
|
||||
|
||||
using ReadWriteBuffer<float> buffer = device.Get().AllocateReadWriteBuffer(array);
|
||||
|
||||
device.Get().For(128, 1, 1, 32, 1, 1, new ComputeShader(buffer, 2.0f));
|
||||
|
||||
float[] result = buffer.ToArray();
|
||||
|
||||
foreach (ref float value in array.AsSpan())
|
||||
{
|
||||
value *= 2.0f;
|
||||
}
|
||||
|
||||
CollectionAssert.AreEqual(result, array);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[ExpectedException(typeof(NotSupportedException))]
|
||||
public void ComputeShader_Test_Fail(Device device)
|
||||
{
|
||||
if (!IsDynamicCompilationDisabled)
|
||||
{
|
||||
Assert.Inconclusive();
|
||||
}
|
||||
|
||||
using ReadWriteBuffer<float> buffer = device.Get().AllocateReadWriteBuffer<float>(128);
|
||||
|
||||
device.Get().For(128, 1, 1, 64, 1, 1, new ComputeShader(buffer, 2.0f));
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
[EmbeddedBytecode(32, 1, 1)]
|
||||
internal readonly partial struct ComputeShader : IComputeShader
|
||||
{
|
||||
public readonly ReadWriteBuffer<float> buffer;
|
||||
public readonly float factor;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute()
|
||||
{
|
||||
buffer[ThreadIds.X] *= factor;
|
||||
}
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void PixelShader_Test_Ok(Device device)
|
||||
{
|
||||
if (!IsDynamicCompilationDisabled)
|
||||
{
|
||||
Assert.Inconclusive();
|
||||
}
|
||||
|
||||
using ReadWriteTexture2D<Rgba32, float4> texture = device.Get().AllocateReadWriteTexture2D<Rgba32, float4>(128, 128);
|
||||
|
||||
device.Get().ForEach(texture, new PixelShader(0.3f, 0.6f));
|
||||
|
||||
Rgba32[,] result = texture.ToArray();
|
||||
|
||||
for (int i = 0; i < texture.Height; i++)
|
||||
{
|
||||
for (int j = 0; j < texture.Width; j++)
|
||||
{
|
||||
byte r = (byte)(j / (float)texture.Width * 255f);
|
||||
byte g = (byte)(i / (float)texture.Height * 255f);
|
||||
const byte b = (byte)(0.3f * 255f);
|
||||
const byte a = (byte)(0.6f * 255f);
|
||||
Rgba32 pixel = result[i, j];
|
||||
|
||||
// Use a delta of 1 to account for small differences of precision when rounding. This test is just
|
||||
// about validating the shader runs anyway, the actual accuracy is tested in other shader tests.
|
||||
Assert.IsTrue(Math.Abs(r - pixel.R) <= 1);
|
||||
Assert.IsTrue(Math.Abs(g - pixel.G) <= 1);
|
||||
Assert.AreEqual(pixel.B, b);
|
||||
Assert.AreEqual(pixel.A, a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
[EmbeddedBytecode(8, 8, 1)]
|
||||
internal readonly partial struct PixelShader : IPixelShader<float4>
|
||||
{
|
||||
private readonly float b;
|
||||
private readonly float a;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
{
|
||||
return new(ThreadIds.Normalized.X, ThreadIds.Normalized.Y, b, a);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(NotSupportedException))]
|
||||
public void ReflectionService_ComputeShader()
|
||||
{
|
||||
if (!IsDynamicCompilationDisabled)
|
||||
{
|
||||
Assert.Inconclusive();
|
||||
}
|
||||
|
||||
ReflectionServices.GetShaderInfo<ComputeShader>(out _);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(NotSupportedException))]
|
||||
public void ReflectionService_PixelShader()
|
||||
{
|
||||
if (!IsDynamicCompilationDisabled)
|
||||
{
|
||||
Assert.Inconclusive();
|
||||
}
|
||||
|
||||
ReflectionServices.GetShaderInfo<PixelShader, float4>(out _);
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする