Changes in / [756162f:cb6fabb] in opengl-game
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
compile.sh
r756162f rcb6fabb 1 1 # TODO: Figure out why calling this from a makefile gives an error about shopt not being found 2 2 3 cd shaders 3 OS=$(uname) 4 4 5 5 shopt -s nullglob … … 16 16 glslangValidator -V $f -o $fOut 17 17 done 18 19 cd .. -
docs/README.txt
r756162f rcb6fabb 1 --------------------2 CONTROLS3 --------------------4 5 Use left and right arrow keys to move your ship6 Use Z and X to fire your left and right lasers at the cubes (asteroids)7 8 1 -------------------- 9 2 VULKAN INSTRUCTIOS -
graphics-pipeline_vulkan.hpp
r756162f rcb6fabb 32 32 }; 33 33 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 34 // TODO: Use this struct for uniform buffers as well (maybe move it to VulkanUtils) 37 35 struct StorageBufferSet { 38 36 vector<VkBuffer> buffers; … … 66 64 void addStorageDescriptor(VkShaderStageFlags stageFlags); 67 65 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); 66 void addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, vector<VkDescriptorBufferInfo>* bufferData); 71 67 void addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, VkDescriptorImageInfo* imageData); 72 68 … … 79 75 80 76 bool addObject(const vector<VertexType>& vertices, vector<uint16_t> indices, SSBOType& ssbo, 81 77 VkCommandPool commandPool, VkQueue graphicsQueue); 82 78 83 79 void updateObject(size_t objIndex, SSBOType& ssbo); 84 80 85 81 void updateObjectVertices(size_t objIndex, const vector<VertexType>& vertices, VkCommandPool commandPool, 86 82 VkQueue graphicsQueue); 87 83 88 84 void cleanup(); … … 460 456 switch (descriptorWrites[j].descriptorType) { 461 457 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: 462 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:463 458 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: 464 459 descriptorWrites[j].pBufferInfo = &(*this->descriptorInfoList[j].bufferDataList)[i]; … … 479 474 void GraphicsPipeline_Vulkan<VertexType, SSBOType>::createRenderCommands(VkCommandBuffer& commandBuffer, 480 475 uint32_t currentImage) { 481 482 476 vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); 483 484 477 vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, 485 478 &descriptorSets[currentImage], 0, nullptr); … … 550 543 } 551 544 552 // TODO: Allow a swapchain index to be passed in instead of updating all of them553 // Actually, since I'm in the process of replacing SSBOs with dynamic UBOs, I can ignore that for this function554 545 template<class VertexType, class SSBOType> 555 546 void GraphicsPipeline_Vulkan<VertexType, SSBOType>::updateObject(size_t objIndex, SSBOType& ssbo) { 556 547 if (!is_same_v<SSBOType, void*>) { 557 548 for (size_t i = 0; i < storageBufferSet.memory.size(); i++) { 558 VulkanUtils::copyDataToMemory(this->device, s sbo, storageBufferSet.memory[i], objIndex * sizeof(SSBOType));549 VulkanUtils::copyDataToMemory(this->device, storageBufferSet.memory[i], objIndex * sizeof(SSBOType), ssbo); 559 550 } 560 551 } -
makefile
r756162f rcb6fabb 74 74 .PHONY: shaders 75 75 shaders: 76 ./compile.sh76 cd shaders && ../compile.sh && cd .. 77 77 78 78 clean: -
sdl-game.cpp
r756162f rcb6fabb 78 78 79 79 void VulkanGame::run(int width, int height, unsigned char guiFlags) { 80 cout << "DEBUGGING IS " << (ENABLE_VALIDATION_LAYERS ? "ON" : "OFF") << endl; 81 80 82 cout << "Vulkan Game" << endl; 81 82 cout << "DEBUGGING IS " << (ENABLE_VALIDATION_LAYERS ? "ON" : "OFF") << endl;83 83 84 84 if (initUI(width, height, guiFlags) == RTWO_ERROR) { … … 103 103 modelPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ModelVertex::objIndex)); 104 104 105 createBufferSet(uniformBuffers_modelPipeline, uniformBuffersMemory_modelPipeline, sizeof(UBO_VP_mats), 106 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 107 uniformBufferInfoList_modelPipeline); 105 createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 106 uniformBuffers_modelPipeline, uniformBuffersMemory_modelPipeline, uniformBufferInfoList_modelPipeline); 108 107 109 108 modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, … … 114 113 115 114 SceneObject<ModelVertex, SSBO_ModelObject>* texturedSquare = nullptr; 116 117 // TODO: Ideally, avoid having to make the squares as modified upon creation118 115 119 116 texturedSquare = &addObject(modelObjects, modelPipeline, … … 449 446 } 450 447 451 VulkanUtils::copyDataToMemory(device, object_VP_mats, uniformBuffersMemory_modelPipeline[imageIndex], 0);448 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_modelPipeline[imageIndex], 0, object_VP_mats); 452 449 } 453 450 … … 1083 1080 } 1084 1081 1085 void VulkanGame::createBufferSet( vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory,1086 VkDeviceSize bufferSize, VkBufferUsageFlags flags, VkMemoryPropertyFlags properties,1082 void VulkanGame::createBufferSet(VkDeviceSize bufferSize, VkBufferUsageFlags flags, 1083 vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory, 1087 1084 vector<VkDescriptorBufferInfo>& bufferInfoList) { 1088 1085 buffers.resize(swapChainImageCount); … … 1091 1088 1092 1089 for (size_t i = 0; i < swapChainImageCount; i++) { 1093 VulkanUtils::createBuffer(device, physicalDevice, bufferSize, flags, properties, buffers[i], buffersMemory[i]); 1090 VulkanUtils::createBuffer(device, physicalDevice, bufferSize, flags, 1091 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 1092 buffers[i], buffersMemory[i]); 1094 1093 1095 1094 bufferInfoList[i].buffer = buffers[i]; … … 1230 1229 // instead of recreated every time 1231 1230 1232 createBufferSet(uniformBuffers_modelPipeline, uniformBuffersMemory_modelPipeline, sizeof(UBO_VP_mats), 1233 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 1234 uniformBufferInfoList_modelPipeline); 1231 createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 1232 uniformBuffers_modelPipeline, uniformBuffersMemory_modelPipeline, uniformBufferInfoList_modelPipeline); 1235 1233 1236 1234 modelPipeline.updateRenderPass(renderPass); -
sdl-game.hpp
r756162f rcb6fabb 276 276 void cleanupImGuiOverlay(); 277 277 278 void createBufferSet( vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory, VkDeviceSize bufferSize,279 VkBufferUsageFlags flags, VkMemoryPropertyFlags properties,280 278 void createBufferSet(VkDeviceSize bufferSize, VkBufferUsageFlags flags, 279 vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory, 280 vector<VkDescriptorBufferInfo>& bufferInfoList); 281 281 282 282 // TODO: Since addObject() returns a reference to the new object now, 283 283 // stop using objects.back() to access the object that was just created 284 284 template<class VertexType, class SSBOType> 285 SceneObject<VertexType, SSBOType>& addObject(vector<SceneObject<VertexType, SSBOType>>& objects, 286 GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline, 287 const vector<VertexType>& vertices, vector<uint16_t> indices, 288 SSBOType ssbo, bool pipelinesCreated); 285 SceneObject<VertexType, SSBOType>& addObject( 286 vector<SceneObject<VertexType, SSBOType>>& objects, 287 GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline, 288 const vector<VertexType>& vertices, vector<uint16_t> indices, SSBOType ssbo, 289 bool pipelinesCreated); 289 290 290 291 template<class VertexType> … … 298 299 299 300 template<class VertexType, class SSBOType> 300 void updateObject(vector<SceneObject<VertexType, SSBOType>>& objects, GraphicsPipeline_Vulkan<VertexType,301 301 void updateObject(vector<SceneObject<VertexType, SSBOType>>& objects, 302 GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline, size_t index); 302 303 303 304 void renderFrame(ImDrawData* draw_data); … … 457 458 // TODO: Just pass in the single object instead of a list of all of them 458 459 template<class VertexType, class SSBOType> 459 void VulkanGame::updateObject(vector<SceneObject<VertexType, SSBOType>>& objects, GraphicsPipeline_Vulkan<VertexType,460 460 void VulkanGame::updateObject(vector<SceneObject<VertexType, SSBOType>>& objects, 461 GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline, size_t index) { 461 462 SceneObject<VertexType, SSBOType>& obj = objects[index]; 462 463 -
vulkan-game.cpp
r756162f rcb6fabb 92 92 seedRandomNums(); 93 93 94 cout << "DEBUGGING IS " << (ENABLE_VALIDATION_LAYERS ? "ON" : "OFF") << endl; 95 94 96 cout << "Vulkan Game" << endl; 95 96 cout << "DEBUGGING IS " << (ENABLE_VALIDATION_LAYERS ? "ON" : "OFF") << endl;97 97 98 98 if (initUI(width, height, guiFlags) == RTWO_ERROR) { … … 1059 1059 explosion_UBO.cur_time = curTime; 1060 1060 1061 VulkanUtils::copyDataToMemory(device, object_VP_mats, uniformBuffersMemory_modelPipeline[imageIndex], 0);1062 1063 VulkanUtils::copyDataToMemory(device, ship_VP_mats, uniformBuffersMemory_shipPipeline[imageIndex], 0);1064 1065 VulkanUtils::copyDataToMemory(device, asteroid_VP_mats, uniformBuffersMemory_asteroidPipeline[imageIndex], 0);1066 1067 VulkanUtils::copyDataToMemory(device, laser_VP_mats, uniformBuffersMemory_laserPipeline[imageIndex], 0);1068 1069 VulkanUtils::copyDataToMemory(device, explosion_UBO, uniformBuffersMemory_explosionPipeline[imageIndex], 0);1061 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_modelPipeline[imageIndex], 0, object_VP_mats); 1062 1063 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_shipPipeline[imageIndex], 0, ship_VP_mats); 1064 1065 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_asteroidPipeline[imageIndex], 0, asteroid_VP_mats); 1066 1067 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_laserPipeline[imageIndex], 0, laser_VP_mats); 1068 1069 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_explosionPipeline[imageIndex], 0, explosion_UBO); 1070 1070 } 1071 1071 -
vulkan-game.hpp
r756162f rcb6fabb 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 modify202 * its params. I should use this where appropriate203 *204 * [return-type] [func-name](params...) const { ... }205 */206 200 207 201 class VulkanGame { -
vulkan-utils.hpp
r756162f rcb6fabb 39 39 40 40 static VkResult createDebugUtilsMessengerEXT(VkInstance instance, 41 42 43 41 const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, 42 const VkAllocationCallbacks* pAllocator, 43 VkDebugUtilsMessengerEXT* pDebugMessenger); 44 44 45 45 static void destroyDebugUtilsMessengerEXT(VkInstance instance, 46 47 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 51 const vector<const char*>& deviceExtensions); 52 52 static VkSurfaceCapabilitiesKHR querySwapChainCapabilities(VkPhysicalDevice physicalDevice, 53 53 VkSurfaceKHR surface); 54 54 static vector<VkSurfaceFormatKHR> querySwapChainFormats(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface); 55 55 static vector<VkPresentModeKHR> querySwapChainPresentModes(VkPhysicalDevice physicalDevice, 56 56 VkSurfaceKHR surface); 57 57 static VkSurfaceFormatKHR chooseSwapSurfaceFormat(const vector<VkSurfaceFormatKHR>& availableFormats, 58 58 const vector<VkFormat>& requestedFormats, VkColorSpaceKHR requestedColorSpace); 59 59 static VkPresentModeKHR chooseSwapPresentMode(const vector<VkPresentModeKHR>& availablePresentModes, 60 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 63 VkImageAspectFlags aspectFlags); 64 64 static VkFormat findSupportedFormat(VkPhysicalDevice physicalDevice, const vector<VkFormat>& candidates, 65 65 VkImageTiling tiling, VkFormatFeatureFlags features); 66 66 static void createBuffer(VkDevice device, VkPhysicalDevice physicalDevice, VkDeviceSize size, 67 68 67 VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer& buffer, 68 VkDeviceMemory& bufferMemory); 69 69 static uint32_t findMemoryType(VkPhysicalDevice physicalDevice, uint32_t typeFilter, 70 70 VkMemoryPropertyFlags properties); 71 71 72 72 static void createVulkanImageFromFile(VkDevice device, VkPhysicalDevice physicalDevice, 73 VkCommandPool commandPool, string filename, VulkanImage& image, 74 VkQueue graphicsQueue); 73 VkCommandPool commandPool, string filename, VulkanImage& image, VkQueue graphicsQueue); 75 74 static void createVulkanImageFromSDLTexture(VkDevice device, VkPhysicalDevice physicalDevice, 76 75 SDL_Texture* texture, VulkanImage& image); 77 76 static void populateVulkanImageFromSDLTexture(VkDevice device, VkPhysicalDevice physicalDevice, 78 VkCommandPool commandPool, SDL_Texture* texture,79 SDL_Renderer* renderer, VulkanImage& image,VkQueue graphicsQueue);77 VkCommandPool commandPool, SDL_Texture* texture, SDL_Renderer* renderer, VulkanImage& image, 78 VkQueue graphicsQueue); 80 79 static void createDepthImage(VkDevice device, VkPhysicalDevice physicalDevice, VkCommandPool commandPool, 81 80 VkFormat depthFormat, VkExtent2D extent, VulkanImage& image, VkQueue graphicsQueue); 82 81 static void createImage(VkDevice device, VkPhysicalDevice physicalDevice, uint32_t width, uint32_t height, 83 VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage,84 VkMemoryPropertyFlags properties,VulkanImage& image);82 VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, 83 VulkanImage& image); 85 84 86 85 static void transitionImageLayout(VkDevice device, VkCommandPool commandPool, VkImage image, 87 VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout, 88 VkQueue graphicsQueue); 86 VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout, VkQueue graphicsQueue); 89 87 static VkCommandBuffer beginSingleTimeCommands(VkDevice device, VkCommandPool commandPool); 90 88 static void endSingleTimeCommands(VkDevice device, VkCommandPool commandPool, 91 89 VkCommandBuffer commandBuffer, VkQueue graphicsQueue); 92 90 static void copyBufferToImage(VkDevice device, VkCommandPool commandPool, VkBuffer buffer, VkImage image, 93 91 uint32_t width, uint32_t height, VkQueue graphicsQueue); 94 92 95 93 template<class DataType> 96 94 static void copyDataToBuffer(VkDevice device, VkPhysicalDevice physicalDevice, VkCommandPool commandPool, 97 const vector<DataType>& srcData, VkBuffer dstBuffer, size_t dstVertexOffset, 98 VkQueue graphicsQueue); 95 const vector<DataType>& srcData, VkBuffer dstBuffer, size_t dstVertexOffset, VkQueue graphicsQueue); 99 96 100 97 static void copyBuffer(VkDevice device, VkCommandPool commandPool, VkBuffer srcBuffer, VkBuffer dstBuffer, 101 VkDeviceSize srcOffset, VkDeviceSize dstOffset, VkDeviceSize size, 102 VkQueue graphicsQueue); 98 VkDeviceSize srcOffset, VkDeviceSize dstOffset, VkDeviceSize size, VkQueue graphicsQueue); 103 99 104 100 template<class DataType> 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); 101 static void copyDataToMemory(VkDevice device, VkDeviceMemory bufferMemory, VkDeviceSize offset, 102 const DataType& srcData); 111 103 112 104 static bool hasStencilComponent(VkFormat format); … … 139 131 140 132 template<class DataType> 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) { 133 void VulkanUtils::copyDataToMemory(VkDevice device, VkDeviceMemory bufferMemory, VkDeviceSize offset, 134 const DataType& srcData) { 149 135 void* data; 150 136 151 vkMapMemory(device, bufferMemory, offset, size , 0, &data);152 memcpy(data, &srcData, size );137 vkMapMemory(device, bufferMemory, offset, sizeof(DataType), 0, &data); 138 memcpy(data, &srcData, sizeof(DataType)); 153 139 vkUnmapMemory(device, bufferMemory); 154 140 } 155 141 156 // TODO: Use this in vulkan-utils itself as well157 142 #define VKUTIL_CHECK_RESULT(f, msg) { \ 158 143 VkResult res = (f); \
Note:
See TracChangeset
for help on using the changeset viewer.