Changeset c7fb883 in opengl-game


Ignore:
Timestamp:
Jul 25, 2019, 3:22:59 AM (5 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
eea05dd
Parents:
de32fda
Message:

Create a descriptor pool and descriptor sets for the mvp matrix ubo, to successfully render a rotating square

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.cpp

    rde32fda rc7fb883  
    171171      VkPipeline graphicsPipeline;
    172172      VkCommandPool commandPool;
     173      VkDescriptorPool descriptorPool;
     174      vector<VkDescriptorSet> descriptorSets;
    173175
    174176      VkBuffer vertexBuffer;
     
    224226         createIndexBuffer();
    225227         createUniformBuffers();
     228         createDescriptorPool();
     229         createDescriptorSets();
    226230         createCommandBuffers();
    227231         createSyncObjects();
     
    248252         createFramebuffers();
    249253         createUniformBuffers();
     254         createDescriptorPool();
     255         createDescriptorSets();
    250256         createCommandBuffers();
    251257      }
     
    272278            vkFreeMemory(device, uniformBuffersMemory[i], nullptr);
    273279         }
     280
     281         vkDestroyDescriptorPool(device, descriptorPool, nullptr);
    274282      }
    275283
     
    802810         rasterizer.lineWidth = 1.0f;
    803811         rasterizer.cullMode = VK_CULL_MODE_BACK_BIT;
    804          rasterizer.frontFace = VK_FRONT_FACE_CLOCKWISE;
     812         rasterizer.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
    805813         rasterizer.depthBiasEnable = false;
    806814
     
    957965      }
    958966
    959       void createUniformBuffers() {
    960          VkDeviceSize bufferSize = sizeof(UniformBufferObject);
    961 
    962          uniformBuffers.resize(swapChainImages.size());
    963          uniformBuffersMemory.resize(swapChainImages.size());
    964 
    965          for (size_t i = 0; i < swapChainImages.size(); i++) {
    966             createBuffer(bufferSize, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    967                VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
    968                uniformBuffers[i], uniformBuffersMemory[i]);
    969          }
    970       }
    971 
    972967      void createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties,
    973968            VkBuffer& buffer, VkDeviceMemory& bufferMemory) {
     
    10461041      }
    10471042
     1043      void createUniformBuffers() {
     1044         VkDeviceSize bufferSize = sizeof(UniformBufferObject);
     1045
     1046         uniformBuffers.resize(swapChainImages.size());
     1047         uniformBuffersMemory.resize(swapChainImages.size());
     1048
     1049         for (size_t i = 0; i < swapChainImages.size(); i++) {
     1050            createBuffer(bufferSize, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
     1051               VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     1052               uniformBuffers[i], uniformBuffersMemory[i]);
     1053         }
     1054      }
     1055
     1056      void createDescriptorPool() {
     1057         VkDescriptorPoolSize poolSize = {};
     1058         poolSize.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
     1059         poolSize.descriptorCount = static_cast<uint32_t>(swapChainImages.size());
     1060
     1061         VkDescriptorPoolCreateInfo poolInfo = {};
     1062         poolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
     1063         poolInfo.poolSizeCount = 1;
     1064         poolInfo.pPoolSizes = &poolSize;
     1065         poolInfo.maxSets = static_cast<uint32_t>(swapChainImages.size());
     1066
     1067         if (vkCreateDescriptorPool(device, &poolInfo, nullptr, &descriptorPool) != VK_SUCCESS) {
     1068            throw runtime_error("failed to create descriptor pool!");
     1069         }
     1070      }
     1071
     1072      void createDescriptorSets() {
     1073         vector<VkDescriptorSetLayout> layouts(swapChainImages.size(), descriptorSetLayout);
     1074         VkDescriptorSetAllocateInfo allocInfo = {};
     1075         allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
     1076         allocInfo.descriptorPool = descriptorPool;
     1077         allocInfo.descriptorSetCount = static_cast<uint32_t>(swapChainImages.size());
     1078         allocInfo.pSetLayouts = layouts.data();
     1079
     1080         descriptorSets.resize(swapChainImages.size());
     1081         if (vkAllocateDescriptorSets(device, &allocInfo, descriptorSets.data()) != VK_SUCCESS) {
     1082            throw runtime_error("failed to allocate descriptor sets!");
     1083         }
     1084
     1085         for (size_t i = 0; i < swapChainImages.size(); i++) {
     1086            VkDescriptorBufferInfo bufferInfo = {};
     1087            bufferInfo.buffer = uniformBuffers[i];
     1088            bufferInfo.offset = 0;
     1089            bufferInfo.range = sizeof(UniformBufferObject);
     1090
     1091            VkWriteDescriptorSet descriptorWrite = {};
     1092            descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
     1093            descriptorWrite.dstSet = descriptorSets[i];
     1094            descriptorWrite.dstBinding = 0;
     1095            descriptorWrite.dstArrayElement = 0;
     1096            descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
     1097            descriptorWrite.descriptorCount = 1;
     1098            descriptorWrite.pBufferInfo = &bufferInfo;
     1099            descriptorWrite.pImageInfo = nullptr;
     1100            descriptorWrite.pTexelBufferView = nullptr;
     1101
     1102            vkUpdateDescriptorSets(device, 1, &descriptorWrite, 0, nullptr);
     1103         }
     1104      }
     1105
    10481106      void createCommandBuffers() {
    10491107         commandBuffers.resize(swapChainFramebuffers.size());
     
    10881146
    10891147            vkCmdBindIndexBuffer(commandBuffers[i], indexBuffer, 0, VK_INDEX_TYPE_UINT16);
     1148            vkCmdBindDescriptorSets(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets[i], 0, nullptr);
    10901149
    10911150            vkCmdDrawIndexed(commandBuffers[i], static_cast<uint32_t>(indices.size()), 1, 0, 0, 0);
Note: See TracChangeset for help on using the changeset viewer.