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