All data is 0 in dst buffer after vkCmdCopyBuffer

All data is 0 in dst buffer after vkCmdCopyBuffer. This is the code to copy staging buffer to device local buffer

bool VulkanBuffer::CopyToBuffer(VulkanBuffer* pVulkanBuffer)
{
	if (mDesc.usage & vk::BufferUsageFlagBits::eTransferSrc && pVulkanBuffer->mDesc.usage & vk::BufferUsageFlagBits::eTransferDst)
	{
		vk::CommandPool cmdPool;
		
		vk::CommandPoolCreateInfo cmdPoolCreateInfo = {};
		cmdPoolCreateInfo.queueFamilyIndex = mpVulkanDevice->GetGraphicsQueueFamilyIndex();

		CHECK_VK_RESULT(mpVulkanDevice->GetDevicePtr()->createCommandPool(&cmdPoolCreateInfo, nullptr, &cmdPool));

		vk::CommandBufferAllocateInfo cmdBufferAllocInfo;
		cmdBufferAllocInfo.commandPool = cmdPool;
		cmdBufferAllocInfo.commandBufferCount = 1;
		cmdBufferAllocInfo.level = vk::CommandBufferLevel::ePrimary;

		vk::CommandBuffer cmdBuffer;

		CHECK_VK_RESULT(mpVulkanDevice->GetDevicePtr()->allocateCommandBuffers(&cmdBufferAllocInfo, &cmdBuffer));

		vk::CommandBufferBeginInfo cmdBufferBeginInfo = {};
		cmdBufferBeginInfo.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit;

		CHECK_VK_RESULT(cmdBuffer.begin(&cmdBufferBeginInfo));

		vk::BufferCopy bufferCopy = {};
		bufferCopy.size = pVulkanBuffer->mDesc.size;

		cmdBuffer.copyBuffer(mBuffer, pVulkanBuffer->GetBuffer(), 1, &bufferCopy);
		cmdBuffer.end();

		vk::SubmitInfo submitInfo = {};
		submitInfo.commandBufferCount = 1;
		submitInfo.pCommandBuffers = &cmdBuffer;

		CHECK_RESULT(mpVulkanDevice->SubmitToQueue(submitInfo));
		mpVulkanDevice->QueueIdle();

		mpVulkanDevice->GetDevicePtr()->destroyCommandPool(cmdPool);

		return true;
	}
	return false;
}

Did i do sumething wrong?!

Untitled|690x388

I can’t tell you why you find that the data is zero, but overall, your code is going about this in a pretty terrible-for-performance way. Creating a command pool just for a buffer, submitting the copy command immediately upon its creation, and the waiting until the queue is idle. These all add up to making Vulkan execute slower than OpenGL. Which is probably not the reason you’re using Vulkan.

If this is all just a test to see if copying works, that’s fine though.

I am beginner. what is best way to do it?

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.