• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * Vulkan CTS Framework
3  * --------------------
4  *
5  * Copyright (c) 2018 The Khronos Group Inc.
6  * Copyright (c) 2018 Google Inc.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  *//*!
21  * \file
22  * \brief Utility for generating barriers
23  *//*--------------------------------------------------------------------*/
24 
25 #include "vkBarrierUtil.hpp"
26 
27 namespace vk
28 {
29 
makeBufferMemoryBarrier(const VkAccessFlags srcAccessMask,const VkAccessFlags dstAccessMask,const VkBuffer buffer,const VkDeviceSize offset,const VkDeviceSize bufferSizeBytes,const deUint32 srcQueueFamilyIndex,const deUint32 dstQueueFamilyIndex)30 VkBufferMemoryBarrier makeBufferMemoryBarrier (const VkAccessFlags	srcAccessMask,
31 											   const VkAccessFlags	dstAccessMask,
32 											   const VkBuffer		buffer,
33 											   const VkDeviceSize	offset,
34 											   const VkDeviceSize	bufferSizeBytes,
35 											   const deUint32		srcQueueFamilyIndex,
36 											   const deUint32		dstQueueFamilyIndex)
37 {
38 	return
39 	{
40 		VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,		// VkStructureType	sType;
41 		DE_NULL,										// const void*		pNext;
42 		srcAccessMask,									// VkAccessFlags	srcAccessMask;
43 		dstAccessMask,									// VkAccessFlags	dstAccessMask;
44 		srcQueueFamilyIndex,							// deUint32			srcQueueFamilyIndex;
45 		dstQueueFamilyIndex,							// deUint32			destQueueFamilyIndex;
46 		buffer,											// VkBuffer			buffer;
47 		offset,											// VkDeviceSize		offset;
48 		bufferSizeBytes,								// VkDeviceSize		size;
49 	};
50 }
51 
makeBufferMemoryBarrier2(const VkPipelineStageFlags2KHR srcStageMask,const VkAccessFlags2KHR srcAccessMask,const VkPipelineStageFlags2KHR dstStageMask,const VkAccessFlags2KHR dstAccessMask,const VkBuffer buffer,const VkDeviceSize offset,const VkDeviceSize size,const deUint32 srcQueueFamilyIndex,const deUint32 dstQueueFamilyIndex)52 VkBufferMemoryBarrier2KHR makeBufferMemoryBarrier2(const VkPipelineStageFlags2KHR	srcStageMask,
53 												   const VkAccessFlags2KHR			srcAccessMask,
54 												   const VkPipelineStageFlags2KHR	dstStageMask,
55 												   const VkAccessFlags2KHR			dstAccessMask,
56 												   const VkBuffer					buffer,
57 												   const VkDeviceSize				offset,
58 												   const VkDeviceSize				size,
59 												   const deUint32					srcQueueFamilyIndex,
60 												   const deUint32					dstQueueFamilyIndex)
61 {
62 	return
63 	{
64 		VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2_KHR,	// VkStructureType				sType;
65 		DE_NULL,										// const void*					pNext;
66 		srcStageMask,									// VkPipelineStageFlags2KHR		srcStageMask;
67 		srcAccessMask,									// VkAccessFlags2KHR			srcAccessMask;
68 		dstStageMask,									// VkPipelineStageFlags2KHR		dstStageMask;
69 		dstAccessMask,									// VkAccessFlags2KHR			dstAccessMask;
70 		srcQueueFamilyIndex,							// deUint32						srcQueueFamilyIndex;
71 		dstQueueFamilyIndex,							// deUint32						dstQueueFamilyIndex;
72 		buffer,											// VkBuffer						buffer;
73 		offset,											// VkDeviceSize					offset;
74 		size											// VkDeviceSize					size;
75 	};
76 }
77 
makeImageMemoryBarrier(const VkAccessFlags srcAccessMask,const VkAccessFlags dstAccessMask,const VkImageLayout oldLayout,const VkImageLayout newLayout,const VkImage image,const VkImageSubresourceRange subresourceRange,const deUint32 srcQueueFamilyIndex,const deUint32 dstQueueFamilyIndex)78 VkImageMemoryBarrier makeImageMemoryBarrier (const VkAccessFlags			srcAccessMask,
79 											 const VkAccessFlags			dstAccessMask,
80 											 const VkImageLayout			oldLayout,
81 											 const VkImageLayout			newLayout,
82 											 const VkImage					image,
83 											 const VkImageSubresourceRange	subresourceRange,
84 											 const deUint32					srcQueueFamilyIndex,
85 											 const deUint32					dstQueueFamilyIndex)
86 {
87 	return
88 	{
89 		VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,			// VkStructureType			sType;
90 		DE_NULL,										// const void*				pNext;
91 		srcAccessMask,									// VkAccessFlags			outputMask;
92 		dstAccessMask,									// VkAccessFlags			inputMask;
93 		oldLayout,										// VkImageLayout			oldLayout;
94 		newLayout,										// VkImageLayout			newLayout;
95 		srcQueueFamilyIndex,							// deUint32					srcQueueFamilyIndex;
96 		dstQueueFamilyIndex,							// deUint32					destQueueFamilyIndex;
97 		image,											// VkImage					image;
98 		subresourceRange,								// VkImageSubresourceRange	subresourceRange;
99 	};
100 }
101 
makeImageMemoryBarrier2(const VkPipelineStageFlags2KHR srcStageMask,const VkAccessFlags2KHR srcAccessMask,const VkPipelineStageFlags2KHR dstStageMask,const VkAccessFlags2KHR dstAccessMask,const VkImageLayout oldLayout,const VkImageLayout newLayout,const VkImage image,const VkImageSubresourceRange subresourceRange,const deUint32 srcQueueFamilyIndex,const deUint32 dstQueueFamilyIndex)102 VkImageMemoryBarrier2KHR makeImageMemoryBarrier2 (const VkPipelineStageFlags2KHR	srcStageMask,
103 												  const VkAccessFlags2KHR			srcAccessMask,
104 												  const VkPipelineStageFlags2KHR	dstStageMask,
105 												  const VkAccessFlags2KHR			dstAccessMask,
106 												  const VkImageLayout				oldLayout,
107 												  const VkImageLayout				newLayout,
108 												  const VkImage						image,
109 												  const VkImageSubresourceRange		subresourceRange,
110 												  const deUint32					srcQueueFamilyIndex,
111 												  const deUint32					dstQueueFamilyIndex)
112 {
113 	return
114 	{
115 		VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2_KHR,	// VkStructureType				sType;
116 		DE_NULL,										// const void*					pNext;
117 		srcStageMask,									// VkPipelineStageFlags2KHR		srcStageMask;
118 		srcAccessMask,									// VkAccessFlags2KHR			srcAccessMask;
119 		dstStageMask,									// VkPipelineStageFlags2KHR		dstStageMask;
120 		dstAccessMask,									// VkAccessFlags2KHR			dstAccessMask;
121 		oldLayout,										// VkImageLayout				oldLayout;
122 		newLayout,										// VkImageLayout				newLayout;
123 		srcQueueFamilyIndex,							// deUint32						srcQueueFamilyIndex;
124 		dstQueueFamilyIndex,							// deUint32						destQueueFamilyIndex;
125 		image,											// VkImage						image;
126 		subresourceRange,								// VkImageSubresourceRange		subresourceRange;
127 	};
128 }
129 
makeMemoryBarrier(const VkAccessFlags srcAccessMask,const VkAccessFlags dstAccessMask)130 VkMemoryBarrier makeMemoryBarrier (const VkAccessFlags	srcAccessMask,
131 								   const VkAccessFlags	dstAccessMask)
132 {
133 	return
134 	{
135 		VK_STRUCTURE_TYPE_MEMORY_BARRIER,				// VkStructureType				sType;
136 		DE_NULL,										// const void*					pNext;
137 		srcAccessMask,									// VkAccessFlags				srcAccessMask;
138 		dstAccessMask,									// VkAccessFlags				dstAccessMask;
139 	};
140 }
141 
makeMemoryBarrier2(const VkPipelineStageFlags2KHR srcStageMask,const VkAccessFlags2KHR srcAccessMask,const VkPipelineStageFlags2KHR dstStageMask,const VkAccessFlags2KHR dstAccessMask)142 VkMemoryBarrier2KHR makeMemoryBarrier2(const VkPipelineStageFlags2KHR	srcStageMask,
143 									   const VkAccessFlags2KHR			srcAccessMask,
144 									   const VkPipelineStageFlags2KHR	dstStageMask,
145 									   const VkAccessFlags2KHR			dstAccessMask)
146 {
147 	return
148 	{
149 		VK_STRUCTURE_TYPE_MEMORY_BARRIER_2_KHR,			// VkStructureType				sType;
150 		DE_NULL,										// const void*					pNext;
151 		srcStageMask,									// VkPipelineStageFlags2KHR		srcStageMask;
152 		srcAccessMask,									// VkAccessFlags2KHR			srcAccessMask;
153 		dstStageMask,									// VkPipelineStageFlags2KHR		dstStageMask;
154 		dstAccessMask									// VkAccessFlags2KHR			dstAccessMask;
155 	};
156 }
157 
cmdPipelineMemoryBarrier(const DeviceInterface & vk,const VkCommandBuffer commandBuffer,const VkPipelineStageFlags srcStageMask,const VkPipelineStageFlags dstStageMask,const VkMemoryBarrier * pMemoryBarriers,const size_t memoryBarrierCount,const VkDependencyFlags dependencyFlags)158 void cmdPipelineMemoryBarrier		(const DeviceInterface&			vk,
159 									 const VkCommandBuffer			commandBuffer,
160 									 const VkPipelineStageFlags		srcStageMask,
161 									 const VkPipelineStageFlags		dstStageMask,
162 									 const VkMemoryBarrier*			pMemoryBarriers,
163 									 const size_t					memoryBarrierCount,
164 									 const VkDependencyFlags		dependencyFlags)
165 {
166 	const deUint32	memoryBarrierCount32	=static_cast<deUint32>(memoryBarrierCount);
167 
168 	DE_ASSERT(memoryBarrierCount == memoryBarrierCount32);
169 
170 	vk.cmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount32, pMemoryBarriers, 0u, DE_NULL, 0u, DE_NULL);
171 }
172 
cmdPipelineBufferMemoryBarrier(const DeviceInterface & vk,const VkCommandBuffer commandBuffer,const VkPipelineStageFlags srcStageMask,const VkPipelineStageFlags dstStageMask,const VkBufferMemoryBarrier * pBufferMemoryBarriers,const size_t bufferMemoryBarrierCount,const VkDependencyFlags dependencyFlags)173 void cmdPipelineBufferMemoryBarrier	(const DeviceInterface&			vk,
174 									 const VkCommandBuffer			commandBuffer,
175 									 const VkPipelineStageFlags		srcStageMask,
176 									 const VkPipelineStageFlags		dstStageMask,
177 									 const VkBufferMemoryBarrier*	pBufferMemoryBarriers,
178 									 const size_t					bufferMemoryBarrierCount,
179 									 const VkDependencyFlags		dependencyFlags)
180 {
181 	const deUint32	bufferMemoryBarrierCount32	=static_cast<deUint32>(bufferMemoryBarrierCount);
182 
183 	DE_ASSERT(bufferMemoryBarrierCount == bufferMemoryBarrierCount32);
184 
185 	vk.cmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags, 0u, DE_NULL, bufferMemoryBarrierCount32, pBufferMemoryBarriers, 0u, DE_NULL);
186 }
187 
cmdPipelineImageMemoryBarrier(const DeviceInterface & vk,const VkCommandBuffer commandBuffer,const VkPipelineStageFlags srcStageMask,const VkPipelineStageFlags dstStageMask,const VkImageMemoryBarrier * pImageMemoryBarriers,const size_t imageMemoryBarrierCount,const VkDependencyFlags dependencyFlags)188 void cmdPipelineImageMemoryBarrier	(const DeviceInterface&			vk,
189 									 const VkCommandBuffer			commandBuffer,
190 									 const VkPipelineStageFlags		srcStageMask,
191 									 const VkPipelineStageFlags		dstStageMask,
192 									 const VkImageMemoryBarrier*	pImageMemoryBarriers,
193 									 const size_t					imageMemoryBarrierCount,
194 									 const VkDependencyFlags		dependencyFlags)
195 {
196 	const deUint32	imageMemoryBarrierCount32	=static_cast<deUint32>(imageMemoryBarrierCount);
197 
198 	DE_ASSERT(imageMemoryBarrierCount == imageMemoryBarrierCount32);
199 
200 	vk.cmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags, 0u, DE_NULL, 0u, DE_NULL, imageMemoryBarrierCount32, pImageMemoryBarriers);
201 }
202 
203 } // vkt
204