Added pixel shader dispatch test, minor bug fix

このコミットが含まれているのは:
Sergio Pedri committed 2021-05-11 01:54:37 +02:00
1 親 76d2f7d83e
コミット 877b32befc
2ファイル変更
+41 -5

検索条件に一致するファイルはありません

+5 -5
ファイルの表示
@@ -174,11 +174,6 @@ namespace ComputeSharp.Shaders.Translation
BindingFlags.Public |
BindingFlags.NonPublic).ToArray();
if (shaderFields.Count == 0)
{
ThrowHelper.ThrowInvalidOperationException("The shader body must contain at least one field");
}
List<D3D12_DESCRIPTOR_RANGE1> d3D12DescriptorRanges1 = new();
// Add the implicit texture descriptor if the shader is a pixel shader
@@ -198,6 +193,11 @@ namespace ComputeSharp.Shaders.Translation
}
}
if (shaderFields.Count == 0 && d3D12DescriptorRanges1.Count == 0)
{
ThrowHelper.ThrowInvalidOperationException("The shader body must contain at least one field");
}
// Inspect the captured fields
foreach (FieldInfo fieldInfo in shaderFields)
{
+36
ファイルの表示
@@ -262,5 +262,41 @@ namespace ComputeSharp.Tests
buffer[5] = (int)Hlsl.Dot(DispatchSize.XYZ, Float3.One);
}
}
[CombinatorialTestMethod]
[AllDevices]
public void Verify_DispatchAsPixelShader(Device device)
{
using ReadWriteTexture2D<Rgba32, Float4> texture = device.Get().AllocateReadWriteTexture2D<Rgba32, Float4>(256, 256);
device.Get().ForEach<DispatchPixelShader, Float4>(texture);
Rgba32[,] data = texture.ToArray();
for (int y = 0; y < texture.Height; y++)
{
for (int x = 0; x < texture.Width; x++)
{
Rgba32 pixel = data[y, x];
Assert.AreEqual((float)pixel.R / 255, (float)x / texture.Width, 0.1f);
Assert.AreEqual((float)pixel.G / 255, (float)y / texture.Height, 0.1f);
Assert.AreEqual(pixel.B, 255);
Assert.AreEqual(pixel.A, 255);
}
}
}
internal readonly partial struct DispatchPixelShader : IPixelShader<Float4>
{
public Float4 Execute()
{
return new(
(float)ThreadIds.X / DispatchSize.X,
(float)ThreadIds.Y / DispatchSize.Y,
1,
1);
}
}
}
}