Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UpdateBuffer not checking zero size #524

Merged

Conversation

Helco
Copy link
Contributor

@Helco Helco commented Feb 21, 2024

Calling GraphicsDevice.UpdateBuffer with sizeInBytes == 0 on Vulkan with a recent validation layer (e.g. SDK 1.3.275.0) causes the validation error VUID-VkBufferCopy-size-01988.
This validation error is also reproduced by the Veldrid.Tests.VulkanBufferTests.UpdateBuffer_ZeroSize unit test.

The CommandList.UpdateBuffer methods have this check already in place so I guess this was a small oversight.

@@ -718,6 +718,10 @@ public void Unmap(MappableResource resource, uint subresource)
throw new VeldridException(
$"The data size given to UpdateBuffer is too large. The given buffer can only hold {buffer.SizeInBytes} total bytes. The requested update would require {bufferOffsetInBytes + sizeInBytes} bytes.");
}
if (sizeInBytes == 0)
{
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If one graphics device already fails (vulkan) when performing an "update buffer" call with zero bytes, then this should probably throw a VeldridException instead of just silently returning. Especially since this is at the surface of the API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would disagree here. This check is already implemented for the other rather similar APIs like CommandList.UpdateBuffer, CopyBuffer etc. and was discussed in #117

For the user ignoring the call for sizeInBytes==0 is not an error, all data supposed to be updated was updated, just that all data is no data in this case.

Copy link
Contributor

@smoogipoo smoogipoo Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with it not throwing an exception. I don't think one device failing is a good reason for all devices to fail, as Veldrid is itself opinionated on how operations are performed so that they conform to the requirements set by the device (the D3D buffer update process as an example).

Also, the D3D11 implementation duplicates this check.

@smoogipoo smoogipoo merged commit fa4032d into veldrid:master Feb 22, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants