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 constexpr uint32_t INVALID_UINT32 = (~(static_cast<uint32_t>(0u))); 43 44 uint32_t findQueueFamilyIndex(const vk::InstanceInterface &vki, vk::VkPhysicalDevice dev, 45 vk::VkQueueGlobalPriorityKHR priority, vk::VkQueueFlags includeFlags, 46 vk::VkQueueFlags excludeFlags, uint32_t excludeIndex = INVALID_UINT32); 47 48 struct SpecialDevice 49 { 50 SpecialDevice(Context &ctx, vk::VkQueueFlagBits transitionFrom, vk::VkQueueFlagBits transitionTo, 51 vk::VkQueueGlobalPriorityKHR priorityFrom, vk::VkQueueGlobalPriorityKHR priorityTo, 52 bool enableProtected, bool enableSparseBinding); 53 SpecialDevice(const SpecialDevice &) = delete; 54 SpecialDevice &operator=(const SpecialDevice &) = delete; 55 static vk::VkQueueFlags getColissionFlags(vk::VkQueueFlags flags); 56 virtual ~SpecialDevice(); 57 58 public: 59 const uint32_t &queueFamilyIndexFrom; 60 const uint32_t &queueFamilyIndexTo; 61 const vk::VkDevice &handle; 62 const vk::VkQueue &queueFrom; 63 const vk::VkQueue &queueTo; 64 const vk::VkResult &createResult; 65 const char *const &createExpression; 66 const char *const &createFileName; 67 const int32_t &createFileLine; getAllocatorvkt::synchronization::SpecialDevice68 vk::Allocator &getAllocator() const 69 { 70 return *m_allocator; 71 } 72 73 protected: 74 Context &m_context; 75 vk::VkQueueFlagBits m_transitionFrom; 76 vk::VkQueueFlagBits m_transitionTo; 77 uint32_t m_queueFamilyIndexFrom; 78 uint32_t m_queueFamilyIndexTo; 79 vk::VkDevice m_deviceHandle; 80 vk::VkQueue m_queueFrom; 81 vk::VkQueue m_queueTo; 82 de::MovePtr<vk::Allocator> m_allocator; 83 vk::VkResult m_createResult; 84 const char *m_createExpression; 85 const char *m_createFileName; 86 int32_t m_createFileLine; 87 }; 88 89 class BufferWithMemory 90 { 91 public: 92 BufferWithMemory(const vk::InstanceInterface &vki, const vk::DeviceInterface &vkd, const vk::VkPhysicalDevice phys, 93 const vk::VkDevice device, vk::Allocator &allocator, 94 const vk::VkBufferCreateInfo &bufferCreateInfo, const vk::MemoryRequirement memoryRequirement, 95 const vk::VkQueue sparseQueue = vk::VkQueue(0)); 96 get(void) const97 const vk::VkBuffer &get(void) const 98 { 99 return *m_buffer; 100 } getPtr(void) const101 const vk::VkBuffer *getPtr(void) const 102 { 103 return &(*m_buffer); 104 } operator *(void) const105 const vk::VkBuffer &operator*(void) const 106 { 107 return get(); 108 } 109 void *getHostPtr(void) const; getSize() const110 vk::VkDeviceSize getSize() const 111 { 112 return m_size; 113 } 114 void invalidateAlloc(const vk::DeviceInterface &vk, const vk::VkDevice device) const; 115 void flushAlloc(const vk::DeviceInterface &vk, const vk::VkDevice device) const; 116 117 protected: 118 void assertIAmSparse() const; 119 120 const bool m_amISparse; 121 const vk::Unique<vk::VkBuffer> m_buffer; 122 const vk::VkMemoryRequirements m_requirements; 123 std::vector<de::SharedPtr<vk::Allocation>> m_allocations; 124 const vk::VkDeviceSize m_size; 125 126 BufferWithMemory(const BufferWithMemory &); 127 BufferWithMemory operator=(const BufferWithMemory &); 128 }; 129 130 class ImageWithMemory : public image::Image 131 { 132 public: 133 ImageWithMemory(const vk::InstanceInterface &vki, const vk::DeviceInterface &vkd, const vk::VkPhysicalDevice phys, 134 const vk::VkDevice device, vk::Allocator &allocator, const vk::VkImageCreateInfo &imageCreateInfo, 135 const vk::VkQueue sparseQueue = vk::VkQueue(0), 136 const vk::MemoryRequirement memoryRequirement = vk::MemoryRequirement::Any); 137 get(void) const138 const vk::VkImage &get(void) const 139 { 140 return m_image->get(); 141 } operator *(void) const142 const vk::VkImage &operator*(void) const 143 { 144 return m_image->get(); 145 } 146 147 protected: 148 de::MovePtr<image::Image> m_image; 149 150 private: 151 ImageWithMemory &operator=(const ImageWithMemory &); 152 }; 153 154 } // namespace synchronization 155 } // namespace vkt 156 157 #endif // _VKTGLOBALPRIORITYQUEUEUTILS_HPP 158