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 barrier issues in computecloth #1103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jherico
Copy link
Contributor

@jherico jherico commented Feb 5, 2024

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.

base/VulkanDevice.cpp Outdated Show resolved Hide resolved
base/VulkanInitializers.hpp Outdated Show resolved Hide resolved
Comment on lines 174 to 189
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);
}
Copy link
Contributor Author

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,
Copy link
Contributor Author

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.

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.

Unnecessary barrier + possibly incorrect barriers?
2 participants