Changeset 8b823e7 in opengl-game for vulkan-game.cpp


Ignore:
Timestamp:
Jan 24, 2021, 11:38:43 PM (4 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
d8cf709
Parents:
ce9dc9f
Message:

Create an error-checking macro to check Vulkan function results, which will print a custom message, the error code, and the line number for all results besides VK_SUCCESS, and update the imgui error-checking callback with similar functionality.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.cpp

    rce9dc9f r8b823e7  
    3838 */
    3939
    40 // Put in here to use for IMGUI, but I might use something similar in other places as well
    41 static void check_vk_result(VkResult result) {
    42    if (result == VK_SUCCESS)
     40static void check_imgui_vk_result(VkResult res) {
     41   if (res == VK_SUCCESS) {
    4342      return;
    44    fprintf(stderr, "[vulkan] Error: VkResult = %d\n", result);
    45    if (result < 0)
    46       abort();
     43   }
     44
     45   ostringstream oss;
     46   oss << "[imgui] Vulkan error! VkResult is \"" << VulkanUtils::resultString(res) << "\"" << __LINE__;
     47   if (res < 0) {
     48      throw runtime_error("Fatal: " + oss.str());
     49   } else {
     50      cerr << oss.str();
     51   }
    4752}
    4853
     
    251256   init_info.MinImageCount = this->swapChainMinImageCount;
    252257   init_info.ImageCount = this->swapChainImageCount;
    253    init_info.CheckVkResultFn = check_vk_result;
     258   init_info.CheckVkResultFn = check_imgui_vk_result;
    254259   ImGui_ImplVulkan_Init(&init_info, this->renderPass);
    255260
     
    261266   // Upload Fonts
    262267   {
    263       VkResult err;
    264 
    265268      VkCommandBuffer command_buffer;
    266269
     
    271274      info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
    272275      info.commandBufferCount = 1;
    273       err = vkAllocateCommandBuffers(this->device, &info, &command_buffer);
    274       check_vk_result(err);
     276
     277      VKUTIL_CHECK_RESULT(vkAllocateCommandBuffers(this->device, &info, &command_buffer),
     278         "failed to allocate command buffers!");
    275279
    276280      //err = vkResetCommandPool(this->device, command_pool, 0); // Probably not really needed here since the command pool is never used before this
     
    279283      begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
    280284      begin_info.flags |= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
    281       err = vkBeginCommandBuffer(command_buffer, &begin_info);
    282       check_vk_result(err);
     285      VKUTIL_CHECK_RESULT(vkBeginCommandBuffer(command_buffer, &begin_info),
     286         "failed to begin recording command buffer!");
    283287
    284288      ImGui_ImplVulkan_CreateFontsTexture(command_buffer);
     
    288292      end_info.commandBufferCount = 1;
    289293      end_info.pCommandBuffers = &command_buffer;
    290       err = vkEndCommandBuffer(command_buffer);
    291       check_vk_result(err);
    292       err = vkQueueSubmit(this->graphicsQueue, 1, &end_info, VK_NULL_HANDLE);
    293       check_vk_result(err);
     294
     295      VKUTIL_CHECK_RESULT(vkEndCommandBuffer(command_buffer),
     296         "failed to record command buffer!");
     297
     298      VKUTIL_CHECK_RESULT(vkQueueSubmit(this->graphicsQueue, 1, &end_info, VK_NULL_HANDLE),
     299         "failed to submit draw command buffer!");
    294300
    295301      if (vkDeviceWaitIdle(this->device) != VK_SUCCESS) {
     
    300306
    301307      // This should make the command pool reusable for later
    302       err = vkResetCommandPool(this->device, resourceCommandPool, 0);
    303       check_vk_result(err);
     308      VKUTIL_CHECK_RESULT(vkResetCommandPool(this->device, resourceCommandPool, 0),
     309         "failed to reset command pool!");
    304310   }
    305311
Note: See TracChangeset for help on using the changeset viewer.