diff --git a/src/application.cpp b/src/application.cpp index b0e5994..7259c8a 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -364,32 +364,16 @@ void Application::drawFrame(float dt) { vertexBufferBarrier.size = vertexBuffers[currentDrawVertexBuffer]->size; vertexBufferBarrier.offset = 0; vertexBufferBarrier.buffer = vertexBuffers[currentDrawVertexBuffer]->handle; - vertexBufferBarrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; + vertexBufferBarrier.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT; vertexBufferBarrier.dstAccessMask = VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT; - vkCmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_VERTEX_INPUT_BIT, 0, 0, - nullptr, 1, &vertexBufferBarrier, 0, nullptr); - - VkBufferMemoryBarrier uniformBufferBarrier {}; - uniformBufferBarrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; - uniformBufferBarrier.size = cameraUniformBuffer->size; - uniformBufferBarrier.offset = 0; - uniformBufferBarrier.buffer = cameraUniformBuffer->handle; - uniformBufferBarrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; - uniformBufferBarrier.dstAccessMask = VK_ACCESS_UNIFORM_READ_BIT; - - vkCmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, - 0, nullptr, 1, &uniformBufferBarrier, 0, nullptr); - VkMemoryBarrier barrier {}; barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; - barrier.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_MEMORY_WRITE_BIT; + barrier.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT; barrier.dstAccessMask = VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT; - vkCmdPipelineBarrier(cmdBuffer, - VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, 0, 1, &barrier, - 0, nullptr, 0, nullptr); + vkCmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_VERTEX_INPUT_BIT, 0, 1, + &barrier, 1, &vertexBufferBarrier, 0, nullptr); VkRenderPassBeginInfo renderPassInfo{}; renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; @@ -523,7 +507,7 @@ void Application::update() { vkBeginCommandBuffer(cmdBuffer, &beginInfo); VkBufferCopy copyRegion {}; - copyRegion.size = vertexBuffers[0]->size; + copyRegion.size = vertexBuffers[1 - currentDrawVertexBuffer]->size; copyRegion.srcOffset = 0; copyRegion.dstOffset = 0; @@ -681,7 +665,9 @@ void Application::recordNormalCommands(VkCommandBuffer cmdBuffer) { state = 2; vkCmdPushConstants(cmdBuffer, normalPipeline->layout, VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(uint32_t), &state); vkCmdDispatch(cmdBuffer, vertexGroupCount, 1, 1); - vkCmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 1, &barrier, 0, nullptr, 0, nullptr); + + barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; + vkCmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 1, &barrier, 0, nullptr, 0, nullptr); }