Changeset e8445f0 in opengl-game
- Timestamp:
- Apr 22, 2021, 1:54:17 AM (4 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- b8072d3
- Parents:
- 4a777d2
- git-author:
- Dmitry Portnoy <dportnoy@…> (04/22/21 01:54:07)
- git-committer:
- Dmitry Portnoy <dportnoy@…> (04/22/21 01:54:17)
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
graphics-pipeline_vulkan.hpp
r4a777d2 re8445f0 32 32 }; 33 33 34 // TODO: Use this struct for uniform buffers as well (maybe move it to VulkanUtils) 34 // TODO: Use this struct for uniform buffers as well and rename it to VulkanBuffer (maybe move it to VulkanUtils) 35 // Also, probably better to make this a vector of structs where each struct 36 // has a VkBuffer, VkDeviceMemory, and VkDescriptorBufferInfo 35 37 struct StorageBufferSet { 36 38 vector<VkBuffer> buffers; … … 64 66 void addStorageDescriptor(VkShaderStageFlags stageFlags); 65 67 66 void addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, vector<VkDescriptorBufferInfo>* bufferData); 68 // TODO: I might be able to use a single VkDescriptorBufferInfo here and reuse it when creating the descriptor sets 69 void addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, 70 vector<VkDescriptorBufferInfo>* bufferData); 67 71 void addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, VkDescriptorImageInfo* imageData); 68 72 … … 75 79 76 80 bool addObject(const vector<VertexType>& vertices, vector<uint16_t> indices, SSBOType& ssbo, 77 VkCommandPool commandPool, VkQueue graphicsQueue);81 VkCommandPool commandPool, VkQueue graphicsQueue); 78 82 79 83 void updateObject(size_t objIndex, SSBOType& ssbo); 80 84 81 85 void updateObjectVertices(size_t objIndex, const vector<VertexType>& vertices, VkCommandPool commandPool, 82 VkQueue graphicsQueue);86 VkQueue graphicsQueue); 83 87 84 88 void cleanup(); … … 456 460 switch (descriptorWrites[j].descriptorType) { 457 461 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: 462 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: 458 463 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: 459 464 descriptorWrites[j].pBufferInfo = &(*this->descriptorInfoList[j].bufferDataList)[i]; … … 474 479 void GraphicsPipeline_Vulkan<VertexType, SSBOType>::createRenderCommands(VkCommandBuffer& commandBuffer, 475 480 uint32_t currentImage) { 481 476 482 vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); 483 477 484 vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, 478 485 &descriptorSets[currentImage], 0, nullptr); … … 543 550 } 544 551 552 // TODO: Allow a swapchain index to be passed in instead of updating all of them 553 // Actually, since I'm in the process of replacing SSBOs with dynamic UBOs, I can ignore that for this function 545 554 template<class VertexType, class SSBOType> 546 555 void GraphicsPipeline_Vulkan<VertexType, SSBOType>::updateObject(size_t objIndex, SSBOType& ssbo) { 547 556 if (!is_same_v<SSBOType, void*>) { 548 557 for (size_t i = 0; i < storageBufferSet.memory.size(); i++) { 549 VulkanUtils::copyDataToMemory(this->device, s torageBufferSet.memory[i], objIndex * sizeof(SSBOType), ssbo);558 VulkanUtils::copyDataToMemory(this->device, ssbo, storageBufferSet.memory[i], objIndex * sizeof(SSBOType)); 550 559 } 551 560 } -
sdl-game.cpp
r4a777d2 re8445f0 446 446 } 447 447 448 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_modelPipeline[imageIndex], 0, object_VP_mats);448 VulkanUtils::copyDataToMemory(device, object_VP_mats, uniformBuffersMemory_modelPipeline[imageIndex], 0); 449 449 } 450 450 -
vulkan-game.cpp
r4a777d2 re8445f0 92 92 seedRandomNums(); 93 93 94 cout << "Vulkan Game" << endl; 95 94 96 cout << "DEBUGGING IS " << (ENABLE_VALIDATION_LAYERS ? "ON" : "OFF") << endl; 95 96 cout << "Vulkan Game" << endl;97 97 98 98 if (initUI(width, height, guiFlags) == RTWO_ERROR) { … … 1049 1049 explosion_UBO.cur_time = curTime; 1050 1050 1051 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_modelPipeline[imageIndex], 0, object_VP_mats);1052 1053 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_shipPipeline[imageIndex], 0, ship_VP_mats);1054 1055 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_asteroidPipeline[imageIndex], 0, asteroid_VP_mats);1056 1057 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_laserPipeline[imageIndex], 0, laser_VP_mats);1058 1059 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_explosionPipeline[imageIndex], 0, explosion_UBO);1051 VulkanUtils::copyDataToMemory(device, object_VP_mats, uniformBuffersMemory_modelPipeline[imageIndex], 0); 1052 1053 VulkanUtils::copyDataToMemory(device, ship_VP_mats, uniformBuffersMemory_shipPipeline[imageIndex], 0); 1054 1055 VulkanUtils::copyDataToMemory(device, asteroid_VP_mats, uniformBuffersMemory_asteroidPipeline[imageIndex], 0); 1056 1057 VulkanUtils::copyDataToMemory(device, laser_VP_mats, uniformBuffersMemory_laserPipeline[imageIndex], 0); 1058 1059 VulkanUtils::copyDataToMemory(device, explosion_UBO, uniformBuffersMemory_explosionPipeline[imageIndex], 0); 1060 1060 } 1061 1061 -
vulkan-game.hpp
r4a777d2 re8445f0 198 198 UIValue(UIValueType _type, string _label, void* _value) : type(_type), label(_label), value(_value) {} 199 199 }; 200 201 /* TODO: The following syntax (note the const keyword) means the function will not modify 202 * its params. I should use this where appropriate 203 * 204 * [return-type] [func-name](params...) const { ... } 205 */ 200 206 201 207 class VulkanGame { -
vulkan-utils.hpp
r4a777d2 re8445f0 39 39 40 40 static VkResult createDebugUtilsMessengerEXT(VkInstance instance, 41 const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo,42 const VkAllocationCallbacks* pAllocator,43 VkDebugUtilsMessengerEXT* pDebugMessenger);41 const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, 42 const VkAllocationCallbacks* pAllocator, 43 VkDebugUtilsMessengerEXT* pDebugMessenger); 44 44 45 45 static void destroyDebugUtilsMessengerEXT(VkInstance instance, 46 VkDebugUtilsMessengerEXT debugMessenger,47 const VkAllocationCallbacks* pAllocator);46 VkDebugUtilsMessengerEXT debugMessenger, 47 const VkAllocationCallbacks* pAllocator); 48 48 49 49 static QueueFamilyIndices findQueueFamilies(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface); 50 50 static bool checkDeviceExtensionSupport(VkPhysicalDevice physicalDevice, 51 const vector<const char*>& deviceExtensions);51 const vector<const char*>& deviceExtensions); 52 52 static VkSurfaceCapabilitiesKHR querySwapChainCapabilities(VkPhysicalDevice physicalDevice, 53 VkSurfaceKHR surface);53 VkSurfaceKHR surface); 54 54 static vector<VkSurfaceFormatKHR> querySwapChainFormats(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface); 55 55 static vector<VkPresentModeKHR> querySwapChainPresentModes(VkPhysicalDevice physicalDevice, 56 VkSurfaceKHR surface);56 VkSurfaceKHR surface); 57 57 static VkSurfaceFormatKHR chooseSwapSurfaceFormat(const vector<VkSurfaceFormatKHR>& availableFormats, 58 const vector<VkFormat>& requestedFormats, VkColorSpaceKHR requestedColorSpace);58 const vector<VkFormat>& requestedFormats, VkColorSpaceKHR requestedColorSpace); 59 59 static VkPresentModeKHR chooseSwapPresentMode(const vector<VkPresentModeKHR>& availablePresentModes, 60 const vector<VkPresentModeKHR>& requestedPresentModes);60 const vector<VkPresentModeKHR>& requestedPresentModes); 61 61 static VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities, int width, int height); 62 62 static VkImageView createImageView(VkDevice device, VkImage image, VkFormat format, 63 VkImageAspectFlags aspectFlags);63 VkImageAspectFlags aspectFlags); 64 64 static VkFormat findSupportedFormat(VkPhysicalDevice physicalDevice, const vector<VkFormat>& candidates, 65 VkImageTiling tiling, VkFormatFeatureFlags features);65 VkImageTiling tiling, VkFormatFeatureFlags features); 66 66 static void createBuffer(VkDevice device, VkPhysicalDevice physicalDevice, VkDeviceSize size, 67 VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer& buffer,68 VkDeviceMemory& bufferMemory);67 VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer& buffer, 68 VkDeviceMemory& bufferMemory); 69 69 static uint32_t findMemoryType(VkPhysicalDevice physicalDevice, uint32_t typeFilter, 70 VkMemoryPropertyFlags properties);70 VkMemoryPropertyFlags properties); 71 71 72 72 static void createVulkanImageFromFile(VkDevice device, VkPhysicalDevice physicalDevice, 73 VkCommandPool commandPool, string filename, VulkanImage& image, VkQueue graphicsQueue); 73 VkCommandPool commandPool, string filename, VulkanImage& image, 74 VkQueue graphicsQueue); 74 75 static void createVulkanImageFromSDLTexture(VkDevice device, VkPhysicalDevice physicalDevice, 75 SDL_Texture* texture, VulkanImage& image);76 SDL_Texture* texture, VulkanImage& image); 76 77 static void populateVulkanImageFromSDLTexture(VkDevice device, VkPhysicalDevice physicalDevice, 77 VkCommandPool commandPool, SDL_Texture* texture, SDL_Renderer* renderer, VulkanImage& image,78 VkQueue graphicsQueue);78 VkCommandPool commandPool, SDL_Texture* texture, 79 SDL_Renderer* renderer, VulkanImage& image, VkQueue graphicsQueue); 79 80 static void createDepthImage(VkDevice device, VkPhysicalDevice physicalDevice, VkCommandPool commandPool, 80 VkFormat depthFormat, VkExtent2D extent, VulkanImage& image, VkQueue graphicsQueue);81 VkFormat depthFormat, VkExtent2D extent, VulkanImage& image, VkQueue graphicsQueue); 81 82 static void createImage(VkDevice device, VkPhysicalDevice physicalDevice, uint32_t width, uint32_t height, 82 VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties,83 VulkanImage& image);83 VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, 84 VkMemoryPropertyFlags properties, VulkanImage& image); 84 85 85 86 static void transitionImageLayout(VkDevice device, VkCommandPool commandPool, VkImage image, 86 VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout, VkQueue graphicsQueue); 87 VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout, 88 VkQueue graphicsQueue); 87 89 static VkCommandBuffer beginSingleTimeCommands(VkDevice device, VkCommandPool commandPool); 88 90 static void endSingleTimeCommands(VkDevice device, VkCommandPool commandPool, 89 VkCommandBuffer commandBuffer, VkQueue graphicsQueue);91 VkCommandBuffer commandBuffer, VkQueue graphicsQueue); 90 92 static void copyBufferToImage(VkDevice device, VkCommandPool commandPool, VkBuffer buffer, VkImage image, 91 uint32_t width, uint32_t height, VkQueue graphicsQueue);93 uint32_t width, uint32_t height, VkQueue graphicsQueue); 92 94 93 95 template<class DataType> 94 96 static void copyDataToBuffer(VkDevice device, VkPhysicalDevice physicalDevice, VkCommandPool commandPool, 95 const vector<DataType>& srcData, VkBuffer dstBuffer, size_t dstVertexOffset, VkQueue graphicsQueue); 97 const vector<DataType>& srcData, VkBuffer dstBuffer, size_t dstVertexOffset, 98 VkQueue graphicsQueue); 96 99 97 100 static void copyBuffer(VkDevice device, VkCommandPool commandPool, VkBuffer srcBuffer, VkBuffer dstBuffer, 98 VkDeviceSize srcOffset, VkDeviceSize dstOffset, VkDeviceSize size, VkQueue graphicsQueue); 101 VkDeviceSize srcOffset, VkDeviceSize dstOffset, VkDeviceSize size, 102 VkQueue graphicsQueue); 99 103 100 104 template<class DataType> 101 static void copyDataToMemory(VkDevice device, VkDeviceMemory bufferMemory, VkDeviceSize offset, 102 const DataType& srcData); 105 static void copyDataToMemory(VkDevice device, const DataType& srcData, VkDeviceMemory bufferMemory, 106 VkDeviceSize offset); 107 108 template<class DataType> 109 static void copyDataToMemory(VkDevice device, const DataType& srcData, VkDeviceMemory bufferMemory, 110 VkDeviceSize offset, VkDeviceSize size); 103 111 104 112 static bool hasStencilComponent(VkFormat format); … … 131 139 132 140 template<class DataType> 133 void VulkanUtils::copyDataToMemory(VkDevice device, VkDeviceMemory bufferMemory, VkDeviceSize offset, 134 const DataType& srcData) { 141 void VulkanUtils::copyDataToMemory(VkDevice device, const DataType& srcData, VkDeviceMemory bufferMemory, 142 VkDeviceSize offset) { 143 copyDataToMemory(device, srcData, bufferMemory, offset, sizeof(DataType)); 144 } 145 146 template<class DataType> 147 void VulkanUtils::copyDataToMemory(VkDevice device, const DataType& srcData, VkDeviceMemory bufferMemory, 148 VkDeviceSize offset, VkDeviceSize size) { 135 149 void* data; 136 150 137 vkMapMemory(device, bufferMemory, offset, size of(DataType), 0, &data);138 memcpy(data, &srcData, size of(DataType));151 vkMapMemory(device, bufferMemory, offset, size, 0, &data); 152 memcpy(data, &srcData, size); 139 153 vkUnmapMemory(device, bufferMemory); 140 154 } 141 155 156 // TODO: Use this in vulkan-utils itself as well 142 157 #define VKUTIL_CHECK_RESULT(f, msg) { \ 143 158 VkResult res = (f); \
Note:
See TracChangeset
for help on using the changeset viewer.