blob: cd2ed17a4d94e6eb32199dd08eb560343d034060 [file] [log] [blame]
Karl Schultz7b024b42018-08-30 16:18:18 -06001/* 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-LunarG0e564722019-03-19 16:09:14 -060020#include "vk_mem_alloc.h"
21
Karl Schultz7b024b42018-08-30 16:18:18 -060022#ifndef VULKAN_GPU_VALIDATION_H
23#define VULKAN_GPU_VALIDATION_H
24
Mark Lobodzinski2a3ee4a2019-03-13 13:11:39 -060025struct GpuDeviceMemoryBlock {
26 VkBuffer buffer;
Tony-LunarG0e564722019-03-19 16:09:14 -060027 VmaAllocation allocation;
Tony-LunarG81efe392019-03-07 15:43:27 -070028 std::unordered_map<uint32_t, const cvdescriptorset::Descriptor *> update_at_submit;
Mark Lobodzinski2a3ee4a2019-03-13 13:11:39 -060029};
30
31struct GpuBufferInfo {
Tony-LunarG1b2e0c32019-02-07 17:13:27 -070032 GpuDeviceMemoryBlock output_mem_block;
33 GpuDeviceMemoryBlock input_mem_block;
Mark Lobodzinski2a3ee4a2019-03-13 13:11:39 -060034 VkDescriptorSet desc_set;
35 VkDescriptorPool desc_pool;
Tony-LunarG1b2e0c32019-02-07 17:13:27 -070036 GpuBufferInfo(GpuDeviceMemoryBlock output_mem_block, GpuDeviceMemoryBlock input_mem_block, VkDescriptorSet desc_set,
37 VkDescriptorPool desc_pool)
38 : output_mem_block(output_mem_block), input_mem_block(input_mem_block), desc_set(desc_set), desc_pool(desc_pool){};
Mark Lobodzinski2a3ee4a2019-03-13 13:11:39 -060039};
40
Karl Schultz7b024b42018-08-30 16:18:18 -060041// Class to encapsulate Descriptor Set allocation. This manager creates and destroys Descriptor Pools
42// as needed to satisfy requests for descriptor sets.
43class GpuDescriptorSetManager {
44 public:
Mark Lobodzinski3bf82a52019-03-11 11:49:34 -060045 GpuDescriptorSetManager(CoreChecks *dev_data);
Mark Lobodzinskib56bbb92019-02-18 11:49:59 -070046 ~GpuDescriptorSetManager();
Karl Schultz7b024b42018-08-30 16:18:18 -060047
Karl Schultz7b024b42018-08-30 16:18:18 -060048 VkResult GetDescriptorSets(uint32_t count, VkDescriptorPool *pool, std::vector<VkDescriptorSet> *desc_sets);
49 void PutBackDescriptorSet(VkDescriptorPool desc_pool, VkDescriptorSet desc_set);
50
51 private:
52 static const uint32_t kItemsPerChunk = 512;
53 struct PoolTracker {
54 uint32_t size;
55 uint32_t used;
56 };
57
Mark Lobodzinski3bf82a52019-03-11 11:49:34 -060058 CoreChecks *dev_data_;
Karl Schultz7b024b42018-08-30 16:18:18 -060059 std::unordered_map<VkDescriptorPool, struct PoolTracker> desc_pool_map_;
60};
61
Mark Lobodzinski2a3ee4a2019-03-13 13:11:39 -060062struct GpuValidationState {
63 bool aborted;
64 bool reserve_binding_slot;
65 VkDescriptorSetLayout debug_desc_layout;
66 VkDescriptorSetLayout dummy_desc_layout;
67 uint32_t adjusted_max_desc_sets;
68 uint32_t desc_set_bind_index;
69 uint32_t unique_shader_module_id;
70 std::unordered_map<uint32_t, ShaderTracker> shader_map;
Mark Lobodzinski2a3ee4a2019-03-13 13:11:39 -060071 std::unique_ptr<GpuDescriptorSetManager> desc_set_manager;
72 VkCommandPool barrier_command_pool;
73 VkCommandBuffer barrier_command_buffer;
74 std::unordered_map<VkCommandBuffer, std::vector<GpuBufferInfo>> command_buffer_map; // gpu_buffer_list;
Tony-LunarG0e564722019-03-19 16:09:14 -060075 uint32_t output_buffer_size;
76 VmaAllocator vmaAllocator;
Tony-LunarG2ab9ede2019-05-10 14:34:31 -060077 PFN_vkSetDeviceLoaderData vkSetDeviceLoaderData;
Tony-LunarG76cdcac2019-05-22 16:13:12 -060078 GpuValidationState(bool aborted = false, bool reserve_binding_slot = false, uint32_t unique_shader_module_id = 0,
79 VkCommandPool barrier_command_pool = VK_NULL_HANDLE, VkCommandBuffer barrier_command_buffer = VK_NULL_HANDLE,
80 VmaAllocator vmaAllocator = {})
Tony-LunarG29f48a72019-04-16 11:53:37 -060081 : aborted(aborted),
82 reserve_binding_slot(reserve_binding_slot),
Tony-LunarG76cdcac2019-05-22 16:13:12 -060083 unique_shader_module_id(unique_shader_module_id),
Tony-LunarG29f48a72019-04-16 11:53:37 -060084 barrier_command_pool(barrier_command_pool),
85 barrier_command_buffer(barrier_command_buffer),
86 vmaAllocator(vmaAllocator){};
Mark Lobodzinski2a3ee4a2019-03-13 13:11:39 -060087
88 std::vector<GpuBufferInfo> &GetGpuBufferInfo(const VkCommandBuffer command_buffer) {
89 auto buffer_list = command_buffer_map.find(command_buffer);
90 if (buffer_list == command_buffer_map.end()) {
91 std::vector<GpuBufferInfo> new_list{};
92 command_buffer_map[command_buffer] = new_list;
93 return command_buffer_map[command_buffer];
94 }
95 return buffer_list->second;
96 }
97};
98
Karl Schultz7b024b42018-08-30 16:18:18 -060099using mutex_t = std::mutex;
100using lock_guard_t = std::lock_guard<mutex_t>;
101using unique_lock_t = std::unique_lock<mutex_t>;
102
Karl Schultz7b024b42018-08-30 16:18:18 -0600103#endif // VULKAN_GPU_VALIDATION_H