Karl Schultz | 7b024b4 | 2018-08-30 16:18:18 -0600 | [diff] [blame] | 1 | /* Copyright (c) 2018-2019 The Khronos Group Inc. |
| 2 | * Copyright (c) 2018-2019 Valve Corporation |
| 3 | * Copyright (c) 2018-2019 LunarG, Inc. |
| 4 | * Copyright (C) 2018-2019 Google Inc. |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * |
| 18 | */ |
| 19 | |
Tony-LunarG | 0e56472 | 2019-03-19 16:09:14 -0600 | [diff] [blame^] | 20 | #include "vk_mem_alloc.h" |
| 21 | |
Karl Schultz | 7b024b4 | 2018-08-30 16:18:18 -0600 | [diff] [blame] | 22 | #ifndef VULKAN_GPU_VALIDATION_H |
| 23 | #define VULKAN_GPU_VALIDATION_H |
| 24 | |
Mark Lobodzinski | 2a3ee4a | 2019-03-13 13:11:39 -0600 | [diff] [blame] | 25 | struct GpuDeviceMemoryBlock { |
| 26 | VkBuffer buffer; |
Tony-LunarG | 0e56472 | 2019-03-19 16:09:14 -0600 | [diff] [blame^] | 27 | VmaAllocation allocation; |
Mark Lobodzinski | 2a3ee4a | 2019-03-13 13:11:39 -0600 | [diff] [blame] | 28 | }; |
| 29 | |
| 30 | struct GpuBufferInfo { |
| 31 | GpuDeviceMemoryBlock mem_block; |
| 32 | VkDescriptorSet desc_set; |
| 33 | VkDescriptorPool desc_pool; |
| 34 | GpuBufferInfo(GpuDeviceMemoryBlock mem_block, VkDescriptorSet desc_set, VkDescriptorPool desc_pool) |
| 35 | : mem_block(mem_block), desc_set(desc_set), desc_pool(desc_pool){}; |
| 36 | }; |
| 37 | |
Karl Schultz | 7b024b4 | 2018-08-30 16:18:18 -0600 | [diff] [blame] | 38 | // Class to encapsulate Descriptor Set allocation. This manager creates and destroys Descriptor Pools |
| 39 | // as needed to satisfy requests for descriptor sets. |
| 40 | class GpuDescriptorSetManager { |
| 41 | public: |
Mark Lobodzinski | 3bf82a5 | 2019-03-11 11:49:34 -0600 | [diff] [blame] | 42 | GpuDescriptorSetManager(CoreChecks *dev_data); |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 43 | ~GpuDescriptorSetManager(); |
Karl Schultz | 7b024b4 | 2018-08-30 16:18:18 -0600 | [diff] [blame] | 44 | |
Karl Schultz | 7b024b4 | 2018-08-30 16:18:18 -0600 | [diff] [blame] | 45 | VkResult GetDescriptorSets(uint32_t count, VkDescriptorPool *pool, std::vector<VkDescriptorSet> *desc_sets); |
| 46 | void PutBackDescriptorSet(VkDescriptorPool desc_pool, VkDescriptorSet desc_set); |
Tony-LunarG | d85808d | 2019-02-27 16:12:02 -0700 | [diff] [blame] | 47 | void DestroyDescriptorPools(); |
Karl Schultz | 7b024b4 | 2018-08-30 16:18:18 -0600 | [diff] [blame] | 48 | |
| 49 | private: |
| 50 | static const uint32_t kItemsPerChunk = 512; |
| 51 | struct PoolTracker { |
| 52 | uint32_t size; |
| 53 | uint32_t used; |
| 54 | }; |
| 55 | |
Mark Lobodzinski | 3bf82a5 | 2019-03-11 11:49:34 -0600 | [diff] [blame] | 56 | CoreChecks *dev_data_; |
Karl Schultz | 7b024b4 | 2018-08-30 16:18:18 -0600 | [diff] [blame] | 57 | std::unordered_map<VkDescriptorPool, struct PoolTracker> desc_pool_map_; |
| 58 | }; |
| 59 | |
Mark Lobodzinski | 2a3ee4a | 2019-03-13 13:11:39 -0600 | [diff] [blame] | 60 | struct GpuValidationState { |
| 61 | bool aborted; |
| 62 | bool reserve_binding_slot; |
| 63 | VkDescriptorSetLayout debug_desc_layout; |
| 64 | VkDescriptorSetLayout dummy_desc_layout; |
| 65 | uint32_t adjusted_max_desc_sets; |
| 66 | uint32_t desc_set_bind_index; |
| 67 | uint32_t unique_shader_module_id; |
| 68 | std::unordered_map<uint32_t, ShaderTracker> shader_map; |
Mark Lobodzinski | 2a3ee4a | 2019-03-13 13:11:39 -0600 | [diff] [blame] | 69 | std::unique_ptr<GpuDescriptorSetManager> desc_set_manager; |
| 70 | VkCommandPool barrier_command_pool; |
| 71 | VkCommandBuffer barrier_command_buffer; |
| 72 | std::unordered_map<VkCommandBuffer, std::vector<GpuBufferInfo>> command_buffer_map; // gpu_buffer_list; |
Tony-LunarG | 0e56472 | 2019-03-19 16:09:14 -0600 | [diff] [blame^] | 73 | uint32_t output_buffer_size; |
| 74 | VmaAllocator vmaAllocator; |
Mark Lobodzinski | 2a3ee4a | 2019-03-13 13:11:39 -0600 | [diff] [blame] | 75 | |
| 76 | std::vector<GpuBufferInfo> &GetGpuBufferInfo(const VkCommandBuffer command_buffer) { |
| 77 | auto buffer_list = command_buffer_map.find(command_buffer); |
| 78 | if (buffer_list == command_buffer_map.end()) { |
| 79 | std::vector<GpuBufferInfo> new_list{}; |
| 80 | command_buffer_map[command_buffer] = new_list; |
| 81 | return command_buffer_map[command_buffer]; |
| 82 | } |
| 83 | return buffer_list->second; |
| 84 | } |
| 85 | }; |
| 86 | |
Karl Schultz | 7b024b4 | 2018-08-30 16:18:18 -0600 | [diff] [blame] | 87 | using mutex_t = std::mutex; |
| 88 | using lock_guard_t = std::lock_guard<mutex_t>; |
| 89 | using unique_lock_t = std::unique_lock<mutex_t>; |
| 90 | |
Karl Schultz | 7b024b4 | 2018-08-30 16:18:18 -0600 | [diff] [blame] | 91 | #endif // VULKAN_GPU_VALIDATION_H |