Changeset c163d81 in opengl-game for vulkan-game.cpp
- Timestamp:
- May 19, 2021, 7:16:37 PM (4 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- 58453c3
- Parents:
- 1abebc1
- git-author:
- Dmitry Portnoy <dportnoy@…> (05/19/21 19:16:33)
- git-committer:
- Dmitry Portnoy <dportnoy@…> (05/19/21 19:16:37)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
r1abebc1 rc163d81 135 135 createBufferSet(sizeof(UBO_VP_mats), 136 136 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 137 uniformBuffers_modelPipeline , uniformBuffersMemory_modelPipeline, uniformBufferInfoList_modelPipeline);137 uniformBuffers_modelPipeline); 138 138 139 139 modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 140 VK_SHADER_STAGE_VERTEX_BIT, &uniformBuffer InfoList_modelPipeline);140 VK_SHADER_STAGE_VERTEX_BIT, &uniformBuffers_modelPipeline.infoSet); 141 141 modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 142 142 VK_SHADER_STAGE_VERTEX_BIT, &storageBuffers_modelPipeline.infoSet); … … 206 206 createBufferSet(sizeof(UBO_VP_mats), 207 207 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 208 uniformBuffers_shipPipeline , uniformBuffersMemory_shipPipeline, uniformBufferInfoList_shipPipeline);208 uniformBuffers_shipPipeline); 209 209 210 210 shipPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 211 VK_SHADER_STAGE_VERTEX_BIT, &uniformBuffer InfoList_shipPipeline);211 VK_SHADER_STAGE_VERTEX_BIT, &uniformBuffers_shipPipeline.infoSet); 212 212 shipPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 213 213 VK_SHADER_STAGE_VERTEX_BIT, &storageBuffers_shipPipeline.infoSet); … … 469 469 createBufferSet(sizeof(UBO_VP_mats), 470 470 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 471 uniformBuffers_asteroidPipeline , uniformBuffersMemory_asteroidPipeline, uniformBufferInfoList_asteroidPipeline);471 uniformBuffers_asteroidPipeline); 472 472 473 473 asteroidPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 474 VK_SHADER_STAGE_VERTEX_BIT, &uniformBuffer InfoList_asteroidPipeline);474 VK_SHADER_STAGE_VERTEX_BIT, &uniformBuffers_asteroidPipeline.infoSet); 475 475 asteroidPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 476 476 VK_SHADER_STAGE_VERTEX_BIT, &storageBuffers_asteroidPipeline.infoSet); … … 487 487 createBufferSet(sizeof(UBO_VP_mats), 488 488 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 489 uniformBuffers_laserPipeline , uniformBuffersMemory_laserPipeline, uniformBufferInfoList_laserPipeline);489 uniformBuffers_laserPipeline); 490 490 491 491 laserPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 492 VK_SHADER_STAGE_VERTEX_BIT, &uniformBuffer InfoList_laserPipeline);492 VK_SHADER_STAGE_VERTEX_BIT, &uniformBuffers_laserPipeline.infoSet); 493 493 laserPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 494 494 VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, &storageBuffers_laserPipeline.infoSet); … … 507 507 createBufferSet(sizeof(UBO_Explosion), 508 508 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 509 uniformBuffers_explosionPipeline , uniformBuffersMemory_explosionPipeline, uniformBufferInfoList_explosionPipeline);509 uniformBuffers_explosionPipeline); 510 510 511 511 explosionPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 512 VK_SHADER_STAGE_VERTEX_BIT, &uniformBuffer InfoList_explosionPipeline);512 VK_SHADER_STAGE_VERTEX_BIT, &uniformBuffers_explosionPipeline.infoSet); 513 513 explosionPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 514 514 VK_SHADER_STAGE_VERTEX_BIT, &storageBuffers_explosionPipeline.infoSet); … … 624 624 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 625 625 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 626 storageBuffers_modelPipeline.buffers, storageBuffers_modelPipeline.memory, 627 storageBuffers_modelPipeline.infoSet); 626 storageBuffers_modelPipeline); 628 627 629 628 shipPipeline = GraphicsPipeline_Vulkan<ModelVertex>( … … 634 633 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 635 634 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 636 storageBuffers_shipPipeline.buffers, storageBuffers_shipPipeline.memory, 637 storageBuffers_shipPipeline.infoSet); 635 storageBuffers_shipPipeline); 638 636 639 637 asteroidPipeline = GraphicsPipeline_Vulkan<ModelVertex>( … … 644 642 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 645 643 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 646 storageBuffers_asteroidPipeline.buffers, storageBuffers_asteroidPipeline.memory, 647 storageBuffers_asteroidPipeline.infoSet); 644 storageBuffers_asteroidPipeline); 648 645 649 646 laserPipeline = GraphicsPipeline_Vulkan<LaserVertex>( … … 654 651 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 655 652 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 656 storageBuffers_laserPipeline.buffers, storageBuffers_laserPipeline.memory, 657 storageBuffers_laserPipeline.infoSet); 653 storageBuffers_laserPipeline); 658 654 659 655 explosionPipeline = GraphicsPipeline_Vulkan<ExplosionVertex>( … … 665 661 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 666 662 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 667 storageBuffers_explosionPipeline.buffers, storageBuffers_explosionPipeline.memory, 668 storageBuffers_explosionPipeline.infoSet); 663 storageBuffers_explosionPipeline); 669 664 } 670 665 … … 1166 1161 explosion_UBO.cur_time = curTime; 1167 1162 1168 VulkanUtils::copyDataToMemory(device, object_VP_mats, uniformBuffers Memory_modelPipeline[imageIndex], 0);1169 1170 VulkanUtils::copyDataToMemory(device, ship_VP_mats, uniformBuffers Memory_shipPipeline[imageIndex], 0);1171 1172 VulkanUtils::copyDataToMemory(device, asteroid_VP_mats, uniformBuffers Memory_asteroidPipeline[imageIndex], 0);1173 1174 VulkanUtils::copyDataToMemory(device, laser_VP_mats, uniformBuffers Memory_laserPipeline[imageIndex], 0);1175 1176 VulkanUtils::copyDataToMemory(device, explosion_UBO, uniformBuffers Memory_explosionPipeline[imageIndex], 0);1163 VulkanUtils::copyDataToMemory(device, object_VP_mats, uniformBuffers_modelPipeline.memory[imageIndex], 0); 1164 1165 VulkanUtils::copyDataToMemory(device, ship_VP_mats, uniformBuffers_shipPipeline.memory[imageIndex], 0); 1166 1167 VulkanUtils::copyDataToMemory(device, asteroid_VP_mats, uniformBuffers_asteroidPipeline.memory[imageIndex], 0); 1168 1169 VulkanUtils::copyDataToMemory(device, laser_VP_mats, uniformBuffers_laserPipeline.memory[imageIndex], 0); 1170 1171 VulkanUtils::copyDataToMemory(device, explosion_UBO, uniformBuffers_explosionPipeline.memory[imageIndex], 0); 1177 1172 } 1178 1173 … … 1943 1938 1944 1939 void VulkanGame::createBufferSet(VkDeviceSize bufferSize, VkBufferUsageFlags flags, VkMemoryPropertyFlags properties, 1945 vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory, 1946 vector<VkDescriptorBufferInfo>& bufferInfoList) { 1947 buffers.resize(swapChainImageCount); 1948 buffersMemory.resize(swapChainImageCount); 1949 bufferInfoList.resize(swapChainImageCount); 1940 BufferSet& set) { 1941 set.buffers.resize(swapChainImageCount); 1942 set.memory.resize(swapChainImageCount); 1943 set.infoSet.resize(swapChainImageCount); 1950 1944 1951 1945 for (size_t i = 0; i < swapChainImageCount; i++) { 1952 VulkanUtils::createBuffer(device, physicalDevice, bufferSize, flags, properties, buffers[i], buffersMemory[i]);1953 1954 bufferInfoList[i].buffer =buffers[i];1955 bufferInfoList[i].offset = 0; // This is the offset from the start of the buffer, so always 0 for now1956 bufferInfoList[i].range = bufferSize; // Size of the update starting from offset, or VK_WHOLE_SIZE1946 VulkanUtils::createBuffer(device, physicalDevice, bufferSize, flags, properties, set.buffers[i], set.memory[i]); 1947 1948 set.infoSet[i].buffer = set.buffers[i]; 1949 set.infoSet[i].offset = 0; // This is the offset from the start of the buffer, so always 0 for now 1950 set.infoSet[i].range = bufferSize; // Size of the update starting from offset, or VK_WHOLE_SIZE 1957 1951 } 1958 1952 } … … 2228 2222 createBufferSet(sizeof(UBO_VP_mats), 2229 2223 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2230 uniformBuffers_modelPipeline , uniformBuffersMemory_modelPipeline, uniformBufferInfoList_modelPipeline);2224 uniformBuffers_modelPipeline); 2231 2225 2232 2226 modelPipeline.updateRenderPass(renderPass); … … 2237 2231 createBufferSet(sizeof(UBO_VP_mats), 2238 2232 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2239 uniformBuffers_shipPipeline , uniformBuffersMemory_shipPipeline, uniformBufferInfoList_shipPipeline);2233 uniformBuffers_shipPipeline); 2240 2234 2241 2235 shipPipeline.updateRenderPass(renderPass); … … 2246 2240 createBufferSet(sizeof(UBO_VP_mats), 2247 2241 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2248 uniformBuffers_asteroidPipeline , uniformBuffersMemory_asteroidPipeline, uniformBufferInfoList_asteroidPipeline);2242 uniformBuffers_asteroidPipeline); 2249 2243 2250 2244 asteroidPipeline.updateRenderPass(renderPass); … … 2255 2249 createBufferSet(sizeof(UBO_VP_mats), 2256 2250 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2257 uniformBuffers_laserPipeline , uniformBuffersMemory_laserPipeline, uniformBufferInfoList_laserPipeline);2251 uniformBuffers_laserPipeline); 2258 2252 2259 2253 laserPipeline.updateRenderPass(renderPass); … … 2264 2258 createBufferSet(sizeof(UBO_Explosion), 2265 2259 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2266 uniformBuffers_explosionPipeline , uniformBuffersMemory_explosionPipeline, uniformBufferInfoList_explosionPipeline);2260 uniformBuffers_explosionPipeline); 2267 2261 2268 2262 explosionPipeline.updateRenderPass(renderPass); … … 2292 2286 explosionPipeline.cleanup(); 2293 2287 2294 for (size_t i = 0; i < uniformBuffers_modelPipeline. size(); i++) {2295 vkDestroyBuffer(device, uniformBuffers_modelPipeline [i], nullptr);2296 vkFreeMemory(device, uniformBuffers Memory_modelPipeline[i], nullptr);2297 } 2298 2299 for (size_t i = 0; i < uniformBuffers_shipPipeline. size(); i++) {2300 vkDestroyBuffer(device, uniformBuffers_shipPipeline [i], nullptr);2301 vkFreeMemory(device, uniformBuffers Memory_shipPipeline[i], nullptr);2302 } 2303 2304 for (size_t i = 0; i < uniformBuffers_asteroidPipeline. size(); i++) {2305 vkDestroyBuffer(device, uniformBuffers_asteroidPipeline [i], nullptr);2306 vkFreeMemory(device, uniformBuffers Memory_asteroidPipeline[i], nullptr);2307 } 2308 2309 for (size_t i = 0; i < uniformBuffers_laserPipeline. size(); i++) {2310 vkDestroyBuffer(device, uniformBuffers_laserPipeline [i], nullptr);2311 vkFreeMemory(device, uniformBuffers Memory_laserPipeline[i], nullptr);2312 } 2313 2314 for (size_t i = 0; i < uniformBuffers_explosionPipeline. size(); i++) {2315 vkDestroyBuffer(device, uniformBuffers_explosionPipeline [i], nullptr);2316 vkFreeMemory(device, uniformBuffers Memory_explosionPipeline[i], nullptr);2288 for (size_t i = 0; i < uniformBuffers_modelPipeline.buffers.size(); i++) { 2289 vkDestroyBuffer(device, uniformBuffers_modelPipeline.buffers[i], nullptr); 2290 vkFreeMemory(device, uniformBuffers_modelPipeline.memory[i], nullptr); 2291 } 2292 2293 for (size_t i = 0; i < uniformBuffers_shipPipeline.buffers.size(); i++) { 2294 vkDestroyBuffer(device, uniformBuffers_shipPipeline.buffers[i], nullptr); 2295 vkFreeMemory(device, uniformBuffers_shipPipeline.memory[i], nullptr); 2296 } 2297 2298 for (size_t i = 0; i < uniformBuffers_asteroidPipeline.buffers.size(); i++) { 2299 vkDestroyBuffer(device, uniformBuffers_asteroidPipeline.buffers[i], nullptr); 2300 vkFreeMemory(device, uniformBuffers_asteroidPipeline.memory[i], nullptr); 2301 } 2302 2303 for (size_t i = 0; i < uniformBuffers_laserPipeline.buffers.size(); i++) { 2304 vkDestroyBuffer(device, uniformBuffers_laserPipeline.buffers[i], nullptr); 2305 vkFreeMemory(device, uniformBuffers_laserPipeline.memory[i], nullptr); 2306 } 2307 2308 for (size_t i = 0; i < uniformBuffers_explosionPipeline.buffers.size(); i++) { 2309 vkDestroyBuffer(device, uniformBuffers_explosionPipeline.buffers[i], nullptr); 2310 vkFreeMemory(device, uniformBuffers_explosionPipeline.memory[i], nullptr); 2317 2311 } 2318 2312
Note:
See TracChangeset
for help on using the changeset viewer.