protonscr

Incorrectly Sized Buffer Clears

dxvkclosed
doitsujin/dxvk#4641 · opened 2025-01-24 by anon-apple · updated 2025-02-05 · 2 comments · github
Aanon-apple 2025-01-24 github

System information

  • GPU: RTX 4090
  • Driver: 566.36
  • DXVK version: 2.5.3

Log files

err:   VUID-vkCmdFillBuffer-size-00027:
err:   Validation Error: [ VUID-vkCmdFillBuffer-size-00027 ] Object 0: handle = 0x1c8b4957140, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0x4e4775000000006e, name = Buffer (50), type = VK_OBJECT_TYPE_BUFFER; | MessageID = 0xdd944df9 | vkCmdFillBuffer(): size (37288) is greater than dstBuffer (VkBuffer 0x4e4775000000006e[Buffer (50)]) size (37286) minus dstOffset (0). The Vulkan spec states: If size is not equal to VK_WHOLE_SIZE, size must be less than or equal to the size of dstBuffer minus dstOffset (https://vulkan.lunarg.com/doc/view/1.3.275.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdFillBuffer-size-00027)

Issue description

This validation error is caused by trying to clear a buffer with a non-multiple of 4 size (as a multiple of 4 is required by vkCmdFillBuffer) which happens in some games. Currently DXVK attempts to mitigate this by aligning the size to 4 here, but aligning upwards violates another requirement of vkCmdFillBuffer, specifically that the clear size must be smaller than the buffer size, leading to this validation error.

Unfortunately Vulkan seems to have no good way to clear a buffer like this with the fill command, even using VK_WHOLE_SIZE will only fill to the nearest smaller multiple of 4, leaving a few bytes at the end uncleared potentially. As such the best fix to this is probably to use alignDown instead of align to mimic the behavior of VK_WHOLE_SIZE and to eliminate this validation error. This buffer clearing seems to be only done for compatibility anyways (e.g. for games erroneously relying on buffers to be initialized with zeroed contents even though it's meant to be undefined), so missing clearing a few bytes at the end of the buffer probably isn't the end of the world, but maybe there's a better solution than this.

Ddoitsujin maintainer 2025-01-24 github

Thanks for the detailed report. Is there any real app that even runs into this, and is this causing real issues right now? Don't think I've ever seen this.

I have some ideas; 99.99% of the time we suballocate buffers from something larger anyway so in those cases we can just use the backing storage and round up to the nearest multiple of 4 (or even all the way up to 256, since that's our minimum allocation alignment), and if for whatever reason we have a dedicated VkBuffer with a weird size we can just copy from the zero buffer.

Aanon-apple 2025-01-27 github

Hi, sorry for taking a bit of time to respond. Yes, this does happen in some games I was testing with DXVK (Flat Out 2 to name one). It's not causing any visual issues as far as I know, just validation errors which I noticed while going through them.

Nothing extracted yet.