summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-09-17 11:12:19 -0400
committerJonathan Bradley <jcb@pikum.xyz>2025-09-17 11:12:19 -0400
commit2efdf2c04503e93722a9eb6536becd2b266ff029 (patch)
tree272b6c283d08eecadda34ef47fa770fd30989bfa
parent73c5e170260638cc566cba2689ea570caee39251 (diff)
pke: pkvk_texture_upload better error reporting
-rw-r--r--src/window.cpp110
1 files changed, 95 insertions, 15 deletions
diff --git a/src/window.cpp b/src/window.cpp
index d3a7234..e2cf9b4 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -557,14 +557,16 @@ void pkvk_texture_upload(pkvk_texture_upload_data *data, pkvk_texture_upload_dat
for (i = 0; i < data->n_textures; ++i) {
if(data->texture_assets[i]->type != PKE_ASSET_TYPE_TEXTURE) {
- fprintf(stderr, "[pkvk_texture_upload] Expected all passed assets to be textures, got: %hhu for idx#%i.", static_cast<AssetType_T>(data->texture_assets[i]->type), i);
+ fprintf(stderr, "[pkvk_texture_upload] Expected all passed assets to be textures, got: %hhu for idx#%i.\n", static_cast<AssetType_T>(data->texture_assets[i]->type), i);
return;
}
imageCreateInfo.extent.width = data->texture_assets[i]->details.texture.width;
imageCreateInfo.extent.height = data->texture_assets[i]->details.texture.height;
vkResult = vkCreateImage(vkDevice, &imageCreateInfo, vkAllocator, &tmpImage);
- assert(vkResult == VK_SUCCESS);
+ if (vkResult != VK_SUCCESS) {
+ fprintf(stderr, "[pkvk_texture_upload] Failed to create (prelim) VkImage for texture index: %i, got vkResult: %i\n", i, vkResult);
+ }
vkGetImageMemoryRequirements(vkDevice, tmpImage, &image_memory_requirements[i]);
vkDestroyImage(vkDevice, tmpImage, vkAllocator);
}
@@ -583,13 +585,21 @@ void pkvk_texture_upload(pkvk_texture_upload_data *data, pkvk_texture_upload_dat
if (vkMemoryAllocateInfo.memoryTypeIndex == 0) {
vkMemoryAllocateInfo.memoryTypeIndex = FindMemoryTypeIndex(combined_mem_reqs.memoryTypeBits, 0);
}
- vkAllocateMemory(vkDevice, &vkMemoryAllocateInfo, vkAllocator, &out->device_memory);
+ vkResult = vkAllocateMemory(vkDevice, &vkMemoryAllocateInfo, vkAllocator, &out->device_memory);
+ if (vkResult != VK_SUCCESS) {
+ fprintf(stderr, "[pkvk_texture_upload] failed to allocate device_memory, expected VK_SUCCESS, got vkResult: %i.\n", vkResult);
+ return;
+ }
/*
* buffer setup
*/
char *temp_buffer = (char *)malloc(combined_mem_reqs.size);
+ if (temp_buffer == nullptr) {
+ fprintf(stderr, "[pkvk_texture_upload] failed to malloc temp buffer.\n");
+ goto pkvk_texture_err_out;
+ }
// copy data to temp buffer
// 2025-08-06 - JCB - PERF TODO actually test performance
@@ -615,15 +625,24 @@ void pkvk_texture_upload(pkvk_texture_upload_data *data, pkvk_texture_upload_dat
imageCreateInfo.extent.width = data->texture_assets[i]->details.texture.width;
imageCreateInfo.extent.height = data->texture_assets[i]->details.texture.height;
vkResult = vkCreateImage(vkDevice, &imageCreateInfo, vkAllocator, &out->images[i]);
- assert(vkResult == VK_SUCCESS);
+ if (vkResult != VK_SUCCESS) {
+ fprintf(stderr, "[pkvk_texture_upload] Failed to create VkImage for texture index: %i, got vkResult: %i\n", i, vkResult);
+ goto pkvk_texture_err_out;
+ }
vkResult = vkBindImageMemory(vkDevice, out->images[i], out->device_memory, offset);
- assert(vkResult == VK_SUCCESS);
+ if (vkResult != VK_SUCCESS) {
+ fprintf(stderr, "[pkvk_texture_upload] Failed to bind image memory for texture index: %i, got vkResult: %i\n", i, vkResult);
+ goto pkvk_texture_err_out;
+ }
// create image view
vkImageViewCreateInfo.image = out->images[i];
vkResult = vkCreateImageView(vkDevice, &vkImageViewCreateInfo, vkAllocator, &out->image_views[i]);
- assert(vkResult == VK_SUCCESS);
+ if (vkResult != VK_SUCCESS) {
+ fprintf(stderr, "[pkvk_texture_upload] Failed to create vkImageView for texture index: %i, got vkResult: %i\n", i, vkResult);
+ goto pkvk_texture_err_out;
+ }
// set up image copy parameters
vkBufferImageCopies[i].bufferOffset = offset;
@@ -647,13 +666,18 @@ void pkvk_texture_upload(pkvk_texture_upload_data *data, pkvk_texture_upload_dat
// copy data to vulkan buffer
memcpy(tmpBufferDetails.deviceData, temp_buffer, combined_mem_reqs.size);
free(temp_buffer);
+ temp_buffer = nullptr;
VkCommandBufferBeginInfo vkCommandBufferBeginInfo;
vkCommandBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
vkCommandBufferBeginInfo.pNext = nullptr;
vkCommandBufferBeginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
vkCommandBufferBeginInfo.pInheritanceInfo = nullptr;
- vkBeginCommandBuffer(tmpBufferDetails.cmdBuffer, &vkCommandBufferBeginInfo);
+ vkResult = vkBeginCommandBuffer(tmpBufferDetails.cmdBuffer, &vkCommandBufferBeginInfo);
+ if (vkResult != VK_SUCCESS) {
+ fprintf(stderr, "[pkvk_texture_upload] Failed to begin command buffer (temp buffer), got vkResult: %i\n", vkResult);
+ goto pkvk_texture_err_out;
+ }
vkCmdPipelineBarrier(tmpBufferDetails.cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, (uint32_t)data->n_textures, vkImageMemoryBarriers);
@@ -663,7 +687,11 @@ void pkvk_texture_upload(pkvk_texture_upload_data *data, pkvk_texture_upload_dat
vkCmdCopyBufferToImage2(tmpBufferDetails.cmdBuffer, &copy_buffer_to_image_2s[i]);
}
- vkEndCommandBuffer(tmpBufferDetails.cmdBuffer);
+ vkResult = vkEndCommandBuffer(tmpBufferDetails.cmdBuffer);
+ if (vkResult != VK_SUCCESS) {
+ fprintf(stderr, "[pkvk_texture_upload] Failed to end command buffer (temp buffer), got vkResult: %i\n", vkResult);
+ goto pkvk_texture_err_out;
+ }
VkSubmitInfo submitInfo;
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
@@ -675,9 +703,21 @@ void pkvk_texture_upload(pkvk_texture_upload_data *data, pkvk_texture_upload_dat
submitInfo.pCommandBuffers = &tmpBufferDetails.cmdBuffer;
submitInfo.signalSemaphoreCount = 0;
submitInfo.pSignalSemaphores = nullptr;
- vkQueueSubmit(tmpBufferDetails.queue, 1, &submitInfo, nullptr);
- vkQueueWaitIdle(tmpBufferDetails.queue);
- vkResetCommandBuffer(tmpBufferDetails.cmdBuffer, 0);
+ vkResult = vkQueueSubmit(tmpBufferDetails.queue, 1, &submitInfo, nullptr);
+ if (vkResult != VK_SUCCESS) {
+ fprintf(stderr, "[pkvk_texture_upload] Failed to submit command buffer to queue (temp buffer), got vkResult: %i\n", vkResult);
+ goto pkvk_texture_err_out;
+ }
+ vkResult = vkQueueWaitIdle(tmpBufferDetails.queue);
+ if (vkResult != VK_SUCCESS) {
+ fprintf(stderr, "[pkvk_texture_upload] Failed to wait queue idle (temp buffer), got vkResult: %i\n", vkResult);
+ goto pkvk_texture_err_out;
+ }
+ vkResult = vkResetCommandBuffer(tmpBufferDetails.cmdBuffer, 0);
+ if (vkResult != VK_SUCCESS) {
+ fprintf(stderr, "[pkvk_texture_upload] Failed to reset command buffer (temp buffer), got vkResult: %i\n", vkResult);
+ goto pkvk_texture_err_out;
+ }
PKVK_EndBuffer(tmpBufferDetails);
@@ -699,11 +739,19 @@ void pkvk_texture_upload(pkvk_texture_upload_data *data, pkvk_texture_upload_dat
vkCommandBufferBeginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
vkCommandBufferBeginInfo.pInheritanceInfo = nullptr;
- vkBeginCommandBuffer(tmpBufferDetails.cmdBuffer, &vkCommandBufferBeginInfo);
+ vkResult = vkBeginCommandBuffer(tmpBufferDetails.cmdBuffer, &vkCommandBufferBeginInfo);
+ if (vkResult != VK_SUCCESS) {
+ fprintf(stderr, "[pkvk_texture_upload] Failed to begin command buffer, got vkResult: %i\n", vkResult);
+ goto pkvk_texture_err_out;
+ }
vkCmdPipelineBarrier(tmpBufferDetails.cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, nullptr, 0, nullptr, (uint32_t)data->n_textures, vkImageMemoryBarriers);
- vkEndCommandBuffer(tmpBufferDetails.cmdBuffer);
+ vkResult = vkEndCommandBuffer(tmpBufferDetails.cmdBuffer);
+ if (vkResult != VK_SUCCESS) {
+ fprintf(stderr, "[pkvk_texture_upload] Failed to end command buffer, got vkResult: %i\n", vkResult);
+ goto pkvk_texture_err_out;
+ }
VkSubmitInfo submitInfo;
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
@@ -715,10 +763,42 @@ void pkvk_texture_upload(pkvk_texture_upload_data *data, pkvk_texture_upload_dat
submitInfo.pCommandBuffers = &tmpBufferDetails.cmdBuffer;
submitInfo.signalSemaphoreCount = 0;
submitInfo.pSignalSemaphores = nullptr;
- vkQueueSubmit(tmpBufferDetails.queue, 1, &submitInfo, nullptr);
- vkQueueWaitIdle(tmpBufferDetails.queue);
+ vkResult = vkQueueSubmit(tmpBufferDetails.queue, 1, &submitInfo, nullptr);
+ if (vkResult != VK_SUCCESS) {
+ fprintf(stderr, "[pkvk_texture_upload] Failed to submit command buffer to queue, got vkResult: %i\n", vkResult);
+ goto pkvk_texture_err_out;
+ }
+ vkResult = vkQueueWaitIdle(tmpBufferDetails.queue);
+ if (vkResult != VK_SUCCESS) {
+ fprintf(stderr, "[pkvk_texture_upload] Failed to wait queue idle, got vkResult: %i\n", vkResult);
+ goto pkvk_texture_err_out;
+ }
+ vkResult = vkResetCommandBuffer(tmpBufferDetails.cmdBuffer, 0);
+ if (vkResult != VK_SUCCESS) {
+ fprintf(stderr, "[pkvk_texture_upload] Failed to reset command buffer , got vkResult: %i\n", vkResult);
+ goto pkvk_texture_err_out;
+ }
}
PKVK_EndBuffer(tmpBufferDetails);
+ return;
+pkvk_texture_err_out:
+ for (i = 0; i < data->n_textures; ++i) {
+ if (out->image_views[i] != VK_NULL_HANDLE) {
+ vkDestroyImageView(vkDevice, out->image_views[i], vkAllocator);
+ }
+ if (out->images[i] != VK_NULL_HANDLE) {
+ vkDestroyImage(vkDevice, out->images[i], vkAllocator);
+ }
+ }
+ if (out->device_memory != VK_NULL_HANDLE) {
+ vkFreeMemory(vkDevice, out->device_memory, vkAllocator);
+ }
+ if (temp_buffer != nullptr) {
+ free(temp_buffer);
+ }
+ // swallow vkResult
+ vkResetCommandBuffer(tmpBufferDetails.cmdBuffer, 0);
+ return;
}
void pkvk_texture_upload_array(pkvk_texture_upload_data *data, pkvk_texture_upload_data_out *out) {