Skip to content

Commit

Permalink
Add two tests which cover partial uniform buffer updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
mellinoe committed Mar 19, 2018
1 parent 4062b7f commit e3b50f1
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/Veldrid.Tests/BufferTests.cs
Expand Up @@ -380,6 +380,43 @@ public void CommandList_UpdateNonStaging_Unaligned(BufferUsage usage, uint buffe
GD.Unmap(readback);
}

[Fact]
public void UpdateUniform_Offset_NonStaging_GraphicsDevice()
{
DeviceBuffer buffer = CreateBuffer(128, BufferUsage.UniformBuffer);
Matrix4x4 mat1 = new Matrix4x4(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
GD.UpdateBuffer(buffer, 0, ref mat1);
Matrix4x4 mat2 = new Matrix4x4(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2);
GD.UpdateBuffer(buffer, 64, ref mat2);

DeviceBuffer readback = GetReadback(buffer);
MappedResourceView<Matrix4x4> readView = GD.Map<Matrix4x4>(readback, MapMode.Read);
Assert.Equal(mat1, readView[0]);
Assert.Equal(mat2, readView[1]);
GD.Unmap(readback);
}

[Fact]
public void UpdateUniform_Offset_NonStaging_CommandList()
{
DeviceBuffer buffer = CreateBuffer(128, BufferUsage.UniformBuffer);
CommandList cl = RF.CreateCommandList();
cl.Begin();
Matrix4x4 mat1 = new Matrix4x4(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
cl.UpdateBuffer(buffer, 0, ref mat1);
Matrix4x4 mat2 = new Matrix4x4(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2);
cl.UpdateBuffer(buffer, 64, ref mat2);
cl.End();
GD.SubmitCommands(cl);
GD.WaitForIdle();

DeviceBuffer readback = GetReadback(buffer);
MappedResourceView<Matrix4x4> readView = GD.Map<Matrix4x4>(readback, MapMode.Read);
Assert.Equal(mat1, readView[0]);
Assert.Equal(mat2, readView[1]);
GD.Unmap(readback);
}

private DeviceBuffer CreateBuffer(uint size, BufferUsage usage)
{
return RF.CreateBuffer(new BufferDescription(size, usage));
Expand Down

0 comments on commit e3b50f1

Please sign in to comment.