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