I was able to update my vertex buffer using the vkCmdUpdateBuffer
method, while following the solution to a similar problem asked in this stack thread. However, I am struggling to implement the solution utilizing a staging buffer and the vkCmdCopyBuffer
method, and I don't quite understand how the synchronization would work. My attempts so far have only crashed my application and have not triggered any validation layers.
The error code in the command prompt is (process 27240) exited with code -1073741819.
My current render-loop looks like this:
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
std::jthread t1(glfwSetKeyCallback, window, userInput);
uniforms.update(window, Extent); //updates uniform values
ubo.update(currentFrame, &uniforms); //updates uniform buffer with new values
uint32_t imageIndex;
vkAquireImage(imageIndex);
// Compute Queue
vkComputeSync();
computePpln.computeCommand(computeBuffers[currentFrame], setCount, sets);
vkSubmitComputeQueue();
// Render Queue
//pipeline.model.update(testVtx.data()); // Line where I had my various different update functions
// the size required to update the buffer is unchanged, testVtx is the same size as the original vector<Vertex> content
beginRender(commandBuffers[currentFrame], swapChainFramebuffers[imageIndex]); //Begins recording of render commands
ptclPpln.render(commandBuffers[currentFrame], ssbo.Buffer[currentFrame], setCount, sets); // Draws points indexed
pipeline.render(commandBuffers[currentFrame], setCount, sets); // Draws pipeline.model
endRender(commandBuffers[currentFrame]); //ends recording of render commands
VkSemaphore waitSemaphores[] = { computeFinishedSemaphores[currentFrame], imageAvailableSemaphores[currentFrame]};
VkPipelineStageFlags waitStages[] = { VK_PIPELINE_STAGE_VERTEX_INPUT_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT };
vkSubmitGraphicsQueue<2>(waitSemaphores, waitStages); // submits render commands
vkPresentImage(imageIndex);
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
}
vkDeviceWaitIdle(device);
All of the attempts that I made to the model.update()
function have not worked except for unmapping the memory used by the buffer and remapping the memory to void* data[0]
:
void updateVTX(VkCPU& CPU, uint32_t currentFrame, const void* content) {
vkUnmapMemory(VkGPU::device, map[0][1].mMemory);
vkMapMemory(VkGPU::device, map[0][1].mMemory, 0, map[0][1].mSize, 0, &data[0]);
memcpy(data[0], content, (size_t)map[0][1].mSize);
CPU.beginSingleTimeCommands(CPU.commandBuffers[currentFrame]);
VkBufferCopy copyRegion{};
copyRegion.size = map[0][1].mSize;
copyRegion.srcOffset = 0; //Tried implementing something like the solution in the other thread here, but could not get it to work without remapping the memory
copyRegion.dstOffset = 0;
vkCmdCopyBuffer(CPU.commandBuffers[currentFrame], map[0][1].mBuffer, map[0][0].mBuffer, 1, ©Region);
vkEndCommandBuffer(CPU.commandBuffers[currentFrame]);
VkSubmitInfo submitInfo
{ VK_STRUCTURE_TYPE_SUBMIT_INFO };
submitInfo.commandBufferCount = 1;
submitInfo.pCommandBuffers = &CPU.commandBuffers[currentFrame];
vkQueueSubmit(VkGPU::graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE);
vkQueueWaitIdle(VkGPU::graphicsQueue);
}
As other threads have made me aware of, unmapping and remapping memory unnecessarily should be avoided, so I am really trying to avoid using this method. Adapting the update method used by my UBO class to my VBO results in the application crashing without triggering any validation layers.
My only clue into the solution is how I am creating my buffers. My UBO is created by:
// Staging Buffer
createBuffer(stagingBuffer, stagingBufferMemory, bufferSize,
VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
// Buffer
createBuffer(Buffer[i], Memory[i], bufferSize,
VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Whereas my VBO buffers are created by:
// Staging Buffer
createBuffer(stagingBuffer, stagingBufferMemory, bufferSize,
VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
// Buffer
createBuffer(Buffer, BufferMemory, bufferSize,
VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
I tried changing the memory properties for the VBO buffer to match the UBO buffer, but that did not fix the problem. Please help, I am at a complete loss for a solution.