-
Notifications
You must be signed in to change notification settings - Fork 2k
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 barrier issues in computecloth #1103
base: master
Are you sure you want to change the base?
Conversation
std::array<VkBufferMemoryBarrier, 2> bufferBarriers; | ||
bufferBarriers[0] = vks::initializers::bufferMemoryBarrier(); | ||
bufferBarriers[0].srcAccessMask = VK_ACCESS_SHADER_READ_BIT; | ||
bufferBarriers[0].dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT; | ||
bufferBarriers[0].buffer = storageBuffers.input.buffer; | ||
bufferBarriers[1] = vks::initializers::bufferMemoryBarrier(); | ||
bufferBarriers[1].srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT; | ||
bufferBarriers[1].dstAccessMask = VK_ACCESS_SHADER_READ_BIT; | ||
bufferBarriers[1].buffer = storageBuffers.output.buffer; | ||
if (reverse) { | ||
std::swap(bufferBarriers[0].buffer, bufferBarriers[1].buffer); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main bug fix for #1097
The dispatch loop uses the descriptor sets to alternate between between reading from input and writing to output and vice versa, but the original barriers don't match that. They always moved both buffers from write to read mode.
Assuming the most recent data is in input at the start of every frame, and it's in read mode while the output buffer is in write mode, then on even dispatches we want to move input to write and output to read. On odd dispatches we want to move them back to the original state.
vulkanDevice->createBuffer( | ||
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, | ||
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted, storageBuffers.input
is never accessed on the graphics queue, so no need for the vertex buffer bit, but I do need to copy from it to the output buffer in the compute queue, so added the transfer src bit.
6584315
to
aa41296
Compare
This is to fix #1097
Notes inline
The updated sample passes with the Vulkan Configurator set to enable the validation profile and with it set to the synchronization profile, with no errors or warnings.