1 #ifndef _VKTGLOBALPRIORITYQUEUEUTILS_HPP 2 #define _VKTGLOBALPRIORITYQUEUEUTILS_HPP 3 /*------------------------------------------------------------------------ 4 * Vulkan Conformance Tests 5 * ------------------------ 6 * 7 * Copyright (c) 2022 The Khronos Group Inc. 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 * 21 *//*! 22 * \file vktGlobalPriorityQueueUtils.hpp 23 * \brief Global Priority Queue Utils 24 *//*--------------------------------------------------------------------*/ 25 26 #include "vkDefs.hpp" 27 #include "vkMemUtil.hpp" 28 #include "vkRefUtil.hpp" 29 #include "deUniquePtr.hpp" 30 #include "../image/vktImageTestsUtil.hpp" 31 32 #include <set> 33 #include <vector> 34 35 namespace vkt 36 { 37 // forward declaration 38 class Context; 39 namespace synchronization 40 { 41 42 struct QueueGlobalPriorities 43 { 44 typedef vk::VkQueueGlobalPriorityKHR Priority; 45 typedef std::set<Priority> Priorities; 46 QueueGlobalPriorities (); 47 QueueGlobalPriorities (const QueueGlobalPriorities& other); 48 QueueGlobalPriorities (const vk::VkQueueFamilyGlobalPriorityPropertiesKHR& source); 49 QueueGlobalPriorities (std::initializer_list<Priority> priorities); 50 static QueueGlobalPriorities full (); 51 auto make (void* pNext = nullptr) const -> vk::VkQueueFamilyGlobalPriorityPropertiesKHR; 52 bool insert (const Priority& prio); 53 bool remove (const Priority& prio); 54 bool any (const Priority& prio) const; 55 bool any (const QueueGlobalPriorities& other) const; 56 bool all (const QueueGlobalPriorities& other) const; 57 protected: 58 Priorities m_priorities; 59 }; 60 61 deUint32 findQueueFamilyIndex (const vk::InstanceInterface& vki, 62 vk::VkPhysicalDevice dev, 63 vk::VkQueueFlags includeFlags, 64 vk::VkQueueFlags excludeFlags = 0, 65 bool priorityQueryEnabled = false, 66 QueueGlobalPriorities priorities = QueueGlobalPriorities::full(), 67 const bool eitherAnyOrAll = true); 68 69 constexpr deUint32 INVALID_UINT32 = (~(static_cast<deUint32>(0u))); 70 71 struct SpecialDevice 72 { 73 SpecialDevice (SpecialDevice&& src); 74 SpecialDevice (Context& ctx, 75 vk::VkQueueFlagBits transitionFrom, 76 vk::VkQueueFlagBits transitionTo, 77 vk::VkQueueGlobalPriorityKHR priorityFrom, 78 vk::VkQueueGlobalPriorityKHR priorityTo, 79 bool enableProtected, 80 bool enableSparseBinding); 81 static vk::VkQueueFlags getColissionFlags (vk::VkQueueFlagBits bits); 82 virtual ~SpecialDevice (); 83 bool isValid (vk::VkResult& creationResult) const; 84 85 public: 86 const deUint32& queueFamilyIndexFrom; 87 const deUint32& queueFamilyIndexTo; 88 const vk::VkDevice& device; 89 const vk::VkQueue& queueFrom; 90 const vk::VkQueue& queueTo; 91 vk::Allocator& getAllocator() const; 92 93 protected: 94 const vk::DeviceInterface& m_vkd; 95 vk::VkQueueFlagBits m_transitionFrom; 96 vk::VkQueueFlagBits m_transitionTo; 97 deUint32 m_queueFamilyIndexFrom; 98 deUint32 m_queueFamilyIndexTo; 99 vk::VkDevice m_device; 100 vk::VkQueue m_queueFrom; 101 vk::VkQueue m_queueTo; 102 de::MovePtr<vk::Allocator> m_allocator; 103 vk::VkResult m_creationResult; 104 }; 105 106 class BufferWithMemory 107 { 108 public: 109 BufferWithMemory (const vk::InstanceInterface& vki, 110 const vk::DeviceInterface& vkd, 111 const vk::VkPhysicalDevice phys, 112 const vk::VkDevice device, 113 vk::Allocator& allocator, 114 const vk::VkBufferCreateInfo& bufferCreateInfo, 115 const vk::MemoryRequirement memoryRequirement, 116 const vk::VkQueue sparseQueue = vk::VkQueue(0)); 117 get(void) const118 const vk::VkBuffer& get (void) const { return *m_buffer; } operator *(void) const119 const vk::VkBuffer& operator* (void) const { return get(); } 120 void* getHostPtr (void) const; getSize() const121 vk::VkDeviceSize getSize () const { return m_requirements.size; } 122 void invalidateAlloc (const vk::DeviceInterface& vk, 123 const vk::VkDevice device) const; 124 void flushAlloc (const vk::DeviceInterface& vk, 125 const vk::VkDevice device) const; 126 127 protected: 128 void assertIAmSparse () const; 129 130 const bool m_amISparse; 131 const vk::Unique<vk::VkBuffer> m_buffer; 132 const vk::VkMemoryRequirements m_requirements; 133 std::vector<de::SharedPtr<vk::Allocation>> m_allocations; 134 135 BufferWithMemory (const BufferWithMemory&); 136 BufferWithMemory operator= (const BufferWithMemory&); 137 }; 138 139 class ImageWithMemory : public image::Image 140 { 141 public: 142 ImageWithMemory (const vk::InstanceInterface& vki, 143 const vk::DeviceInterface& vkd, 144 const vk::VkPhysicalDevice phys, 145 const vk::VkDevice device, 146 vk::Allocator& allocator, 147 const vk::VkImageCreateInfo& imageCreateInfo, 148 const vk::VkQueue sparseQueue = vk::VkQueue(0), 149 const vk::MemoryRequirement memoryRequirement = vk::MemoryRequirement::Any); 150 get(void) const151 const vk::VkImage& get (void) const { return m_image->get(); } operator *(void) const152 const vk::VkImage& operator* (void) const { return m_image->get(); } 153 154 protected: 155 de::MovePtr<image::Image> m_image; 156 157 private: 158 ImageWithMemory& operator= (const ImageWithMemory&); 159 }; 160 161 } // synchronization 162 } // vkt 163 164 #endif // _VKTGLOBALPRIORITYQUEUEUTILS_HPP 165