Add internal [EmbeddedBytecode] tests
このコミットが含まれているのは:
1 親
ca8e5da433
コミット
9b2518cd54
2ファイル変更
+80
-1
検索条件に一致するファイルはありません
@@ -228,7 +228,7 @@ internal static class ShaderRunner<T>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private static unsafe void LoadShader(int threadsX, int threadsY, int threadsZ, ref T shader, out ICachedShader shaderData)
|
||||
{
|
||||
if (shader.TryGetBytecode(threadsX, threadsY, threadsZ, out ReadOnlySpan<byte> bytecode))
|
||||
if (Unsafe.NullRef<T>().TryGetBytecode(threadsX, threadsY, threadsZ, out ReadOnlySpan<byte> bytecode))
|
||||
{
|
||||
shaderData = new ICachedShader.Embedded(bytecode);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.Tests.Internals;
|
||||
|
||||
[TestClass]
|
||||
[TestCategory("ShaderBytecode")]
|
||||
public partial class ShaderBytecodeTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void NonPrecompiledShader_Test()
|
||||
{
|
||||
Assert.IsFalse(((IComputeShader)default(NonPrecompiledShader)).TryGetBytecode(32, 1, 1, out ReadOnlySpan<byte> bytecode));
|
||||
Assert.IsFalse(bytecode.Length > 0);
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct NonPrecompiledShader : IComputeShader
|
||||
{
|
||||
public readonly ReadWriteBuffer<float> buffer;
|
||||
public readonly float factor;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute()
|
||||
{
|
||||
buffer[ThreadIds.X] *= factor;
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ComputeShader_Test()
|
||||
{
|
||||
Assert.IsTrue(((IComputeShader)default(ComputeShader)).TryGetBytecode(32, 1, 1, out ReadOnlySpan<byte> bytecode));
|
||||
Assert.IsTrue(bytecode.Length > 0);
|
||||
|
||||
Assert.IsFalse(((IComputeShader)default(ComputeShader)).TryGetBytecode(64, 1, 1, out bytecode));
|
||||
Assert.IsFalse(bytecode.Length > 0);
|
||||
}
|
||||
|
||||
[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;
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PixelShader_Test()
|
||||
{
|
||||
Assert.IsTrue(((IPixelShader<float4>)default(PixelShader)).TryGetBytecode(8, 8, 1, out ReadOnlySpan<byte> bytecode));
|
||||
Assert.IsTrue(bytecode.Length > 0);
|
||||
|
||||
Assert.IsFalse(((IPixelShader<float4>)default(PixelShader)).TryGetBytecode(32, 1, 1, out bytecode));
|
||||
Assert.IsFalse(bytecode.Length > 0);
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
[EmbeddedBytecode(8, 8, 1)]
|
||||
internal readonly partial struct PixelShader : IPixelShader<float4>
|
||||
{
|
||||
public readonly ReadWriteTexture2D<float> buffer;
|
||||
public readonly float factor;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
{
|
||||
return buffer[ThreadIds.XY] * factor;
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする