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

vkCmdCopyBuffer error #3

Closed
quixoticaxis opened this issue May 14, 2020 · 5 comments
Closed

vkCmdCopyBuffer error #3

quixoticaxis opened this issue May 14, 2020 · 5 comments

Comments

@quixoticaxis
Copy link

Hello. Sorry to bother you again, but in the chapter that describes the staging buffer implementation (this commit), there's an error emitted to the log (everything works though):

vulkan_tutorial_ash::debug] BUFFER - " [ VUID-vkCmdCopyBuffer-size-00115 ] Object: 0x51b3510000000014 (Type = 9) | vkCmdCopyBuffer(): pRegions[0].size (256) is greater than the source buffer size (60) minus pRegions[0].srcOffset (0). The Vulkan spec states: The size member of each element of pRegions must be less than or equal to the size of srcBuffer minus srcOffset (https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VUID-vkCmdCopyBuffer-size-00115)"

It looks like mem_requirements.size is 256, while the size is 3 * 20 = 60. Although everything works, I cannot wrap my mind around this error and why it is emitted.

I've tried changing the code like this:

 Self::copy_buffer(
            physical_device,
            command_pool,
            transfer_queue,
            staging_buffer,
            buffer,
            /*staging_mem_size*/ size,
        );

and the error is gone.

Could you please provide some guidance on this one?
As far as I understand, the source buffer is 60 bytes but requires 256, so it looks like [information in 0- 59 | 60 - 255 filled with any values], and the destination buffer is also 60 bytes long with 256 bytes needed and has the very same structure. So the validation layer is upset when we copy more than 60 bytes, but it works because bytes from 60 to 255 do not matter anyway. Do I understand this correctly?

@adrien-ben
Copy link
Owner

Hi !

Yeah the correct one is the one you have now. I think the version of the validation layers I used did not pick this up since I fixed that in another project.

The error is emitted because the spec of cmd_copy_buffer says :

The size member of each element of pRegions must be less than or equal to the size of srcBuffer minus srcOffset

and

The size member of each element of pRegions must be less than or equal to the size of dstBuffer minus dstOffset

Yes, the buffer size is 60 but requires 256 bytes of allocated memory. From what I understand about it, the additional memory is related to the layout of these 60 bytes in memory.

"but it works because bytes from 60 to 255 do not matter anyway"

I think that the fact that this works is mostly due to a bit of luck given the fact that we use the api incorrectly. Maybe the driver just clamp it to 60. But most of the time not respecting the specs rules lead to unspecified behavior, so it might or might not work.

I'm not exactly an expert on Vulkan and I'm still learning about it, so I might be wrong but this is my understanding of the issue :)

@adrien-ben
Copy link
Owner

I fixed it on the master branch :)

@quixoticaxis
Copy link
Author

Cool, thanks, I'll be closing this issue then.

@quixoticaxis
Copy link
Author

quixoticaxis commented May 14, 2020

I suppose it's not about allignment in this case: my guess is that the minimum required memory for our GPU is 256 bytes long. As for alligment changes (at least as far I understood the Vulkan docs) we should use the value that is returned in "requirements" structure (in case of ash, pass it to the helper "Align" struct). And GPU "knows" its own aligment requirements and adhers to them with respect to the format we specify for the attachement.

Does it make any sense?

@adrien-ben
Copy link
Owner

I suppose it's not about allignment in this case: my guess is that the minimum required memory for our GPU is 256 bytes long.

That could be just that yes. I could not find any information about the mimimum memory size for my gpu though so could not confirm.

As for alligment changes (at least as far I understood the Vulkan docs) we should use the value that is returned in "requirements" structure (in case of ash, pass it to the helper "Align" struct). And GPU "knows" its own aligment requirements and adhers to them with respect to the format we specify for the attachement.

Yes that is how I understand it too.

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

No branches or pull requests

2 participants