Fix D2D1PixelShader.GetConstantBuffer with stateless shaders
このコミットが含まれているのは:
1 親
b42a250701
コミット
a6209491c9
2ファイル変更
+66
-3
検索条件に一致するファイルはありません
@@ -38,7 +38,7 @@ internal unsafe struct D2D1ByteBufferDispatchDataLoader : ID2D1DispatchDataLoade
|
||||
{
|
||||
this.buffer = buffer;
|
||||
this.length = length;
|
||||
this.writtenBytes = 0;
|
||||
this.writtenBytes = -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -49,7 +49,20 @@ internal unsafe struct D2D1ByteBufferDispatchDataLoader : ID2D1DispatchDataLoade
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool TryGetWrittenBytes(out int writtenBytes)
|
||||
{
|
||||
return (writtenBytes = this.writtenBytes) != 0;
|
||||
// If the -1 marker is present, it means copying to the target span failed.
|
||||
// In this case, the returned number of written bytes is still reported as 0.
|
||||
// But, the actual load operation is marked as failed. This allows the data loader
|
||||
// to both handle calls with a destination too short and with an empty source buffer.
|
||||
if (this.writtenBytes == -1)
|
||||
{
|
||||
writtenBytes = 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
writtenBytes = this.writtenBytes;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -276,6 +276,56 @@ public partial class D2D1PixelShaderTests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void GetConstantBufferSize_Empty()
|
||||
{
|
||||
int size = D2D1PixelShader.GetConstantBufferSize<ShaderWithNoCapturedValues>();
|
||||
|
||||
Assert.AreEqual(size, 0);
|
||||
|
||||
// Repeated calls always return the same result
|
||||
size = D2D1PixelShader.GetConstantBufferSize<ShaderWithNoCapturedValues>();
|
||||
|
||||
Assert.AreEqual(size, 0);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void GetConstantBuffer_Empty_ReadOnlyMemory()
|
||||
{
|
||||
ShaderWithNoCapturedValues shader = default;
|
||||
|
||||
ReadOnlyMemory<byte> constantBuffer = D2D1PixelShader.GetConstantBuffer(in shader);
|
||||
|
||||
Assert.AreEqual(constantBuffer.Length, 0);
|
||||
}
|
||||
|
||||
// See https://github.com/Sergio0694/ComputeSharp/issues/323
|
||||
[TestMethod]
|
||||
public unsafe void GetConstantBuffer_Empty_Span()
|
||||
{
|
||||
ShaderWithNoCapturedValues shader = default;
|
||||
|
||||
byte[] buffer = Array.Empty<byte>();
|
||||
|
||||
int bytesWritten = D2D1PixelShader.GetConstantBuffer(in shader, buffer);
|
||||
|
||||
Assert.AreEqual(bytesWritten, 0);
|
||||
}
|
||||
|
||||
[D2DInputCount(1)]
|
||||
[D2DInputSimple(0)]
|
||||
[D2DInputDescription(0, D2D1Filter.MinMagMipPoint)]
|
||||
[D2DPixelOptions(D2D1PixelOptions.TrivialSampling)]
|
||||
private readonly partial struct ShaderWithNoCapturedValues : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
{
|
||||
float4 color = D2D.GetInput(0);
|
||||
|
||||
return color * color;
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void GetConstantBufferSize()
|
||||
{
|
||||
@@ -283,7 +333,7 @@ public partial class D2D1PixelShaderTests
|
||||
|
||||
Assert.AreEqual(size, 124);
|
||||
|
||||
// Repeated calls always return the same result
|
||||
// Same as above: repeated calls always return the same result
|
||||
size = D2D1PixelShader.GetConstantBufferSize<ShaderWithScalarVectorAndMatrixTypes>();
|
||||
|
||||
Assert.AreEqual(size, 124);
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする