Changeset 34bdf3a in opengl-game


Ignore:
Timestamp:
Oct 24, 2019, 3:35:49 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
87c8f1a
Parents:
603b5bc
Message:

In vulkangame, create Vulkan synchronization objects for rendering

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main-vulkan.cpp

    r603b5bc r34bdf3a  
    1717
    1818int __main(int argc, char* argv[]) {
     19   const int MAX_FRAMES_IN_FLIGHT = 2;
     20
    1921   cout << "Starting Vulkan Game..." << endl;
    2022
    21    VulkanGame game;
     23   VulkanGame game(MAX_FRAMES_IN_FLIGHT);
    2224
    2325   try {
  • vulkan-game.cpp

    r603b5bc r34bdf3a  
    1818};
    1919
    20 VulkanGame::VulkanGame() {
     20VulkanGame::VulkanGame(int maxFramesInFlight) : MAX_FRAMES_IN_FLIGHT(maxFramesInFlight) {
    2121   gui = nullptr;
    2222   window = nullptr;
     
    169169   graphicsPipelines.back().createDescriptorSets(swapChainImages);
    170170
    171    createCommandBuffers();
    172 
    173171   // TODO: Creating the descriptor pool and descriptor sets might need to be redone when the
    174172   // swap chain is recreated
    175173
    176174   cout << "Created " << graphicsPipelines.size() << " graphics pipelines" << endl;
     175
     176   createCommandBuffers();
     177
     178   createSyncObjects();
    177179}
    178180
     
    250252   }
    251253
     254   for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
     255      vkDestroySemaphore(device, renderFinishedSemaphores[i], nullptr);
     256      vkDestroySemaphore(device, imageAvailableSemaphores[i], nullptr);
     257      vkDestroyFence(device, inFlightFences[i], nullptr);
     258   }
     259
    252260   vkDestroyCommandPool(device, commandPool, nullptr);
    253261   vkDestroyDevice(device, nullptr);
     
    741749}
    742750
     751void VulkanGame::createSyncObjects() {
     752   imageAvailableSemaphores.resize(MAX_FRAMES_IN_FLIGHT);
     753   renderFinishedSemaphores.resize(MAX_FRAMES_IN_FLIGHT);
     754   inFlightFences.resize(MAX_FRAMES_IN_FLIGHT);
     755
     756   VkSemaphoreCreateInfo semaphoreInfo = {};
     757   semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
     758
     759   VkFenceCreateInfo fenceInfo = {};
     760   fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
     761   fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
     762
     763   for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
     764      if (vkCreateSemaphore(device, &semaphoreInfo, nullptr, &imageAvailableSemaphores[i]) != VK_SUCCESS ||
     765            vkCreateSemaphore(device, &semaphoreInfo, nullptr, &renderFinishedSemaphores[i]) != VK_SUCCESS ||
     766            vkCreateFence(device, &fenceInfo, nullptr, &inFlightFences[i]) != VK_SUCCESS) {
     767         throw runtime_error("failed to create synchronization objects for a frame!");
     768      }
     769   }
     770}
     771
    743772void VulkanGame::cleanupSwapChain() {
    744773   VulkanUtils::destroyVulkanImage(device, depthImage);
  • vulkan-game.hpp

    r603b5bc r34bdf3a  
    3030class VulkanGame {
    3131   public:
    32       VulkanGame();
     32      VulkanGame(int maxFramesInFlight);
    3333      ~VulkanGame();
    3434
     
    3636
    3737   private:
     38      const int MAX_FRAMES_IN_FLIGHT;
     39
    3840      GameGui* gui;
    3941
     
    8587      VkDescriptorImageInfo sdlOverlayImageDescriptor;
    8688
     89      vector<VkSemaphore> imageAvailableSemaphores;
     90      vector<VkSemaphore> renderFinishedSemaphores;
     91      vector<VkFence> inFlightFences;
     92
    8793      bool framebufferResized = false;
    8894
     
    114120      void createUniformBuffers();
    115121      void createCommandBuffers();
     122      void createSyncObjects();
    116123
    117124      void cleanupSwapChain();
  • vulkan-ref.cpp

    r603b5bc r34bdf3a  
    2727using namespace glm;
    2828
     29/*** START OF REFACTORED CODE ***/
    2930const int SCREEN_WIDTH = 800;
    3031const int SCREEN_HEIGHT = 600;
     
    3233const int MAX_FRAMES_IN_FLIGHT = 2;
    3334
    34 /*** START OF REFACTORED CODE ***/
    3535#ifdef NDEBUG
    3636   const bool enableValidationLayers = false;
     
    219219      GraphicsPipelineInfo scenePipeline;
    220220      GraphicsPipelineInfo overlayPipeline;
    221 /*** END OF REFACTORED CODE ***/
    222221
    223222      vector<VkSemaphore> imageAvailableSemaphores;
    224223      vector<VkSemaphore> renderFinishedSemaphores;
    225224      vector<VkFence> inFlightFences;
     225/*** END OF REFACTORED CODE ***/
    226226
    227227      size_t currentFrame = 0;
     
    400400
    401401         createBufferResources();
    402 /*** END OF REFACTORED CODE ***/
    403402
    404403         createSyncObjects();
     
    475474      }
    476475
    477 /*** START OF REFACTORED CODE ***/
    478476      vector<const char*> getRequiredExtensions() {
    479477         vector<const char*> extensions = gui->getRequiredExtensions();
     
    16961694/*** START OF REFACTORED CODE ***/
    16971695      }
    1698 /*** END OF REFACTORED CODE ***/
    16991696
    17001697      void createSyncObjects() {
     
    17181715         }
    17191716      }
     1717/*** END OF REFACTORED CODE ***/
    17201718
    17211719      bool addObjectToScene(GraphicsPipelineInfo& info,
     
    19701968         cleanupPipelineBuffers(scenePipeline);
    19711969         cleanupPipelineBuffers(overlayPipeline);
    1972  /*** END OF REFACTORED CODE ***/
    19731970
    19741971         for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
     
    19781975         }
    19791976
    1980 /*** START OF REFACTORED CODE ***/
    19811977         vkDestroyCommandPool(device, commandPool, nullptr);
    19821978         vkDestroyDevice(device, nullptr);
Note: See TracChangeset for help on using the changeset viewer.