• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2016 The Khronos Group Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Synchronization event basic tests
22  *//*--------------------------------------------------------------------*/
23 
24 #include "vktSynchronizationBasicEventTests.hpp"
25 #include "vktTestCaseUtil.hpp"
26 #include "vktSynchronizationUtil.hpp"
27 #include "vktCustomInstancesDevices.hpp"
28 
29 #include "vkDefs.hpp"
30 #include "vkPlatform.hpp"
31 #include "vkRef.hpp"
32 #include "vkCmdUtil.hpp"
33 
34 namespace vkt
35 {
36 namespace synchronization
37 {
38 namespace
39 {
40 
41 using namespace vk;
42 #define SHORT_FENCE_WAIT	1000ull
43 #define LONG_FENCE_WAIT		~0ull
44 
45 using vkt::synchronization::VideoCodecOperationFlags;
46 
47 struct TestConfig
48 {
49 	SynchronizationType			type;
50 	VkEventCreateFlags			flags;
51 	VideoCodecOperationFlags	videoCodecOperationFlags;
52 };
53 
hostResetSetEventCase(Context & context,TestConfig config)54 tcu::TestStatus hostResetSetEventCase (Context& context, TestConfig config)
55 {
56 	de::MovePtr<VideoDevice>	videoDevice	(config.videoCodecOperationFlags != 0 ? new VideoDevice(context, config.videoCodecOperationFlags) : DE_NULL);
57 	const VkDevice				device		= getSyncDevice(videoDevice, context);
58 	const DeviceInterface&		vk			= getSyncDeviceInterface(videoDevice, context);
59 	const VkEventCreateInfo		eventInfo	=
60 											{
61 												VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
62 												DE_NULL,
63 												0
64 											};
65 	VkEvent						event;
66 	Move<VkEvent>				ptrEvent;
67 
68 	DE_UNREF(config);
69 
70 	if (VK_SUCCESS != vk.createEvent(device, &eventInfo, DE_NULL, &event))
71 		return tcu::TestStatus::fail("Couldn't create event");
72 
73 	ptrEvent = Move<VkEvent>(check<VkEvent>(event), Deleter<VkEvent>(vk, device, DE_NULL));
74 
75 	if (VK_EVENT_RESET != vk.getEventStatus(device, event))
76 		return tcu::TestStatus::fail("Created event should be in unsignaled state");
77 
78 	if (VK_SUCCESS != vk.setEvent(device, event))
79 		return tcu::TestStatus::fail("Couldn't set event");
80 
81 	if (VK_EVENT_SET != vk.getEventStatus(device, event))
82 		return tcu::TestStatus::fail("Event should be in signaled state after set");
83 
84 	if (VK_SUCCESS != vk.resetEvent(device, event))
85 		return tcu::TestStatus::fail("Couldn't reset event");
86 
87 	if (VK_EVENT_RESET != vk.getEventStatus(device, event))
88 		return tcu::TestStatus::fail("Event should be in unsignaled state after reset");
89 
90 	return tcu::TestStatus::pass("Tests set and reset event on host pass");
91 }
92 
deviceResetSetEventCase(Context & context,TestConfig config)93 tcu::TestStatus deviceResetSetEventCase (Context& context, TestConfig config)
94 {
95 	de::MovePtr<VideoDevice>			videoDevice				(config.videoCodecOperationFlags != 0 ? new VideoDevice(context, config.videoCodecOperationFlags) : DE_NULL);
96 	const VkDevice						device					= getSyncDevice(videoDevice, context);
97 	const DeviceInterface&				vk						= getSyncDeviceInterface(videoDevice, context);
98 	const VkQueue						queue					= getSyncQueue(videoDevice, context);
99 	const deUint32						queueFamilyIndex		= getSyncQueueFamilyIndex(videoDevice, context);
100 	const Unique<VkCommandPool>			cmdPool					(createCommandPool(vk, device, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, queueFamilyIndex));
101 	const Unique<VkCommandBuffer>		cmdBuffer				(makeCommandBuffer(vk, device, *cmdPool));
102 	const Unique<VkEvent>				event					(createEvent(vk, device));
103 	const VkCommandBufferSubmitInfoKHR	commandBufferSubmitInfo = makeCommonCommandBufferSubmitInfo(cmdBuffer.get());
104 	const VkMemoryBarrier2KHR			memoryBarrier2			=
105 	{
106 		VK_STRUCTURE_TYPE_MEMORY_BARRIER_2_KHR,				// VkStructureType					sType
107 		DE_NULL,											// const void*						pNext
108 		VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT_KHR,			// VkPipelineStageFlags2KHR			srcStageMask
109 		VK_ACCESS_2_NONE_KHR,								// VkAccessFlags2KHR				srcAccessMask
110 		VK_PIPELINE_STAGE_2_HOST_BIT_KHR,					// VkPipelineStageFlags2KHR			dstStageMask
111 		VK_ACCESS_2_HOST_READ_BIT_KHR						// VkAccessFlags2KHR				dstAccessMask
112 	};
113 	VkDependencyInfoKHR					dependencyInfo			= makeCommonDependencyInfo(&memoryBarrier2, DE_NULL, DE_NULL, DE_TRUE);
114 
115 	{
116 		SynchronizationWrapperPtr synchronizationWrapper = getSynchronizationWrapper(config.type, vk, DE_FALSE);
117 
118 		beginCommandBuffer(vk, *cmdBuffer);
119 		synchronizationWrapper->cmdSetEvent(*cmdBuffer, *event, &dependencyInfo);
120 		endCommandBuffer(vk, *cmdBuffer);
121 
122 		synchronizationWrapper->addSubmitInfo(
123 			0u,										// deUint32								waitSemaphoreInfoCount
124 			DE_NULL,								// const VkSemaphoreSubmitInfoKHR*		pWaitSemaphoreInfos
125 			1u,										// deUint32								commandBufferInfoCount
126 			&commandBufferSubmitInfo,				// const VkCommandBufferSubmitInfoKHR*	pCommandBufferInfos
127 			0u,										// deUint32								signalSemaphoreInfoCount
128 			DE_NULL									// const VkSemaphoreSubmitInfoKHR*		pSignalSemaphoreInfos
129 		);
130 
131 		VK_CHECK(synchronizationWrapper->queueSubmit(queue, DE_NULL));
132 	}
133 
134 	VK_CHECK(vk.queueWaitIdle(queue));
135 	context.resetCommandPoolForVKSC(device, *cmdPool);
136 
137 	if (VK_EVENT_SET != vk.getEventStatus(device, *event))
138 		return tcu::TestStatus::fail("Event should be in signaled state after set");
139 
140 	{
141 		SynchronizationWrapperPtr synchronizationWrapper = getSynchronizationWrapper(config.type, vk, DE_FALSE);
142 
143 		beginCommandBuffer(vk, *cmdBuffer);
144 		synchronizationWrapper->cmdResetEvent(*cmdBuffer, *event, VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT_KHR);
145 		endCommandBuffer(vk, *cmdBuffer);
146 
147 		synchronizationWrapper->addSubmitInfo(
148 			0u,										// deUint32								waitSemaphoreInfoCount
149 			DE_NULL,								// const VkSemaphoreSubmitInfoKHR*		pWaitSemaphoreInfos
150 			1u,										// deUint32								commandBufferInfoCount
151 			&commandBufferSubmitInfo,				// const VkCommandBufferSubmitInfoKHR*	pCommandBufferInfos
152 			0u,										// deUint32								signalSemaphoreInfoCount
153 			DE_NULL									// const VkSemaphoreSubmitInfoKHR*		pSignalSemaphoreInfos
154 		);
155 
156 		VK_CHECK(synchronizationWrapper->queueSubmit(queue, DE_NULL));
157 	}
158 
159 	VK_CHECK(vk.queueWaitIdle(queue));
160 
161 	if (VK_EVENT_RESET != vk.getEventStatus(device, *event))
162 		return tcu::TestStatus::fail("Event should be in unsignaled state after set");
163 
164 	return tcu::TestStatus::pass("Device set and reset event tests pass");
165 }
166 
eventSetResetNoneStage(Context & context,TestConfig)167 tcu::TestStatus eventSetResetNoneStage (Context& context, TestConfig)
168 {
169 	const DeviceInterface&							vk								= context.getDeviceInterface();
170 	const VkDevice											device						= context.getDevice();
171 	const VkQueue												queue							= context.getUniversalQueue();
172 	const deUint32											queueFamilyIndex	= context.getUniversalQueueFamilyIndex();
173 	const Unique<VkCommandPool>					cmdPool					(makeCommandPool(vk, device, queueFamilyIndex));
174 	const Unique<VkCommandBuffer>				cmdBuffer				(makeCommandBuffer(vk, device, *cmdPool));
175 	const Unique<VkEvent>								event					(createEvent(vk, device));
176 	const VkCommandBufferSubmitInfoKHR	commandBufferSubmitInfo = makeCommonCommandBufferSubmitInfo(cmdBuffer.get());
177 	const VkMemoryBarrier2KHR			memoryBarrier2			=
178 	{
179 		VK_STRUCTURE_TYPE_MEMORY_BARRIER_2_KHR,	// VkStructureType					sType
180 		DE_NULL,																// const void*							pNext
181 		VK_PIPELINE_STAGE_NONE_KHR,							// VkPipelineStageFlags2KHR	srcStageMask
182 		VK_ACCESS_2_NONE_KHR,										// VkAccessFlags2KHR				srcAccessMask
183 		VK_PIPELINE_STAGE_2_HOST_BIT_KHR,				// VkPipelineStageFlags2KHR	dstStageMask
184 		VK_ACCESS_2_HOST_READ_BIT_KHR						// VkAccessFlags2KHR				dstAccessMask
185 	};
186 	const VkDependencyInfoKHR	dependencyInfo = makeCommonDependencyInfo(&memoryBarrier2, DE_NULL, DE_NULL, DE_TRUE);
187 
188 	SynchronizationWrapperPtr synchronizationWrapper = getSynchronizationWrapper(SynchronizationType::SYNCHRONIZATION2, vk, DE_FALSE);
189 
190 	beginCommandBuffer(vk, *cmdBuffer, VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT);
191 	synchronizationWrapper->cmdSetEvent(*cmdBuffer, *event, &dependencyInfo);
192 	endCommandBuffer(vk, *cmdBuffer);
193 
194 	synchronizationWrapper->addSubmitInfo(
195 		0u,													// deUint32								waitSemaphoreInfoCount
196 		DE_NULL,										// const VkSemaphoreSubmitInfoKHR*		pWaitSemaphoreInfos
197 		1u,													// deUint32								commandBufferInfoCount
198 		&commandBufferSubmitInfo,		// const VkCommandBufferSubmitInfoKHR*	pCommandBufferInfos
199 		0u,													// deUint32								signalSemaphoreInfoCount
200 		DE_NULL											// const VkSemaphoreSubmitInfoKHR*		pSignalSemaphoreInfos
201 	);
202 
203 	VK_CHECK(synchronizationWrapper->queueSubmit(queue, DE_NULL));
204 	VK_CHECK(vk.queueWaitIdle(queue));
205 	context.resetCommandPoolForVKSC(device, *cmdPool);
206 
207 	if (VK_EVENT_SET != vk.getEventStatus(device, *event))
208 		return tcu::TestStatus::fail("Event should be in signaled state after set");
209 	{
210 	//	SynchronizationWrapperPtr synchronizationWrapper = getSynchronizationWrapper(SynchronizationType::SYNCHRONIZATION2, vk, DE_FALSE);
211 		beginCommandBuffer(vk, *cmdBuffer, VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT);
212 		synchronizationWrapper->cmdResetEvent(*cmdBuffer, *event, VK_PIPELINE_STAGE_NONE_KHR);
213 		endCommandBuffer(vk, *cmdBuffer);
214 
215 		synchronizationWrapper->addSubmitInfo(
216 			0u,																		// deUint32								waitSemaphoreInfoCount
217 			DE_NULL,															// const VkSemaphoreSubmitInfoKHR*		pWaitSemaphoreInfos
218 			1u,																		// deUint32								commandBufferInfoCount
219 			&commandBufferSubmitInfo,							// const VkCommandBufferSubmitInfoKHR*	pCommandBufferInfos
220 			0u,																		// deUint32								signalSemaphoreInfoCount
221 			DE_NULL																// const VkSemaphoreSubmitInfoKHR*		pSignalSemaphoreInfos
222 		);
223 
224 		VK_CHECK(synchronizationWrapper->queueSubmit(queue, DE_NULL));
225 	}
226 
227 	VK_CHECK(vk.queueWaitIdle(queue));
228 
229 	if (VK_EVENT_RESET != vk.getEventStatus(device, *event))
230 		return tcu::TestStatus::fail("Event should be in unsignaled state after reset");
231 
232 	return tcu::TestStatus::pass("Pass");
233 }
234 
singleSubmissionCase(Context & context,TestConfig config)235 tcu::TestStatus singleSubmissionCase (Context& context, TestConfig config)
236 {
237 	enum {SET=0, WAIT, COUNT};
238 	de::MovePtr<VideoDevice>		videoDevice					(config.videoCodecOperationFlags != 0 ? new VideoDevice(context, config.videoCodecOperationFlags) : DE_NULL);
239 	const DeviceInterface&			vk							= getSyncDeviceInterface(videoDevice, context);
240 	const VkDevice					device						= getSyncDevice(videoDevice, context);
241 	const VkQueue					queue						= getSyncQueue(videoDevice, context);
242 	const deUint32					queueFamilyIndex			= getSyncQueueFamilyIndex(videoDevice, context);
243 	const Unique<VkFence>			fence						(createFence(vk, device));
244 	const Unique<VkCommandPool>		cmdPool						(createCommandPool(vk, device, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, queueFamilyIndex));
245 	const Move<VkCommandBuffer>		ptrCmdBuffer[COUNT]			= { makeCommandBuffer(vk, device, *cmdPool), makeCommandBuffer(vk, device, *cmdPool) };
246 	VkCommandBuffer					cmdBuffers[COUNT]			= {*ptrCmdBuffer[SET], *ptrCmdBuffer[WAIT]};
247 	const Unique<VkEvent>			event						(createEvent(vk, device, config.flags));
248 	VkCommandBufferSubmitInfoKHR	commandBufferSubmitInfo[]	{
249 																	makeCommonCommandBufferSubmitInfo(cmdBuffers[SET]),
250 																	makeCommonCommandBufferSubmitInfo(cmdBuffers[WAIT])
251 																};
252 	VkDependencyInfoKHR				dependencyInfo				= makeCommonDependencyInfo(DE_NULL, DE_NULL, DE_NULL, DE_TRUE);
253 	SynchronizationWrapperPtr		synchronizationWrapper		= getSynchronizationWrapper(config.type, vk, DE_FALSE);
254 
255 	synchronizationWrapper->addSubmitInfo(
256 		0u,										// deUint32								waitSemaphoreInfoCount
257 		DE_NULL,								// const VkSemaphoreSubmitInfoKHR*		pWaitSemaphoreInfos
258 		2u,										// deUint32								commandBufferInfoCount
259 		commandBufferSubmitInfo,				// const VkCommandBufferSubmitInfoKHR*	pCommandBufferInfos
260 		0u,										// deUint32								signalSemaphoreInfoCount
261 		DE_NULL									// const VkSemaphoreSubmitInfoKHR*		pSignalSemaphoreInfos
262 	);
263 
264 	beginCommandBuffer(vk, cmdBuffers[SET]);
265 	synchronizationWrapper->cmdSetEvent(cmdBuffers[SET], *event, &dependencyInfo);
266 	endCommandBuffer(vk, cmdBuffers[SET]);
267 
268 	beginCommandBuffer(vk, cmdBuffers[WAIT]);
269 	synchronizationWrapper->cmdWaitEvents(cmdBuffers[WAIT], 1u, &event.get(), &dependencyInfo);
270 	endCommandBuffer(vk, cmdBuffers[WAIT]);
271 
272 	VK_CHECK(synchronizationWrapper->queueSubmit(queue, *fence));
273 
274 	if (VK_SUCCESS != vk.waitForFences(device, 1u, &fence.get(), DE_TRUE, LONG_FENCE_WAIT))
275 		return tcu::TestStatus::fail("Queue should end execution");
276 
277 	return tcu::TestStatus::pass("Wait and set even on device single submission tests pass");
278 }
279 
multiSubmissionCase(Context & context,TestConfig config)280 tcu::TestStatus multiSubmissionCase(Context& context, TestConfig config)
281 {
282 	enum { SET = 0, WAIT, COUNT };
283 	de::MovePtr<VideoDevice>		videoDevice			(config.videoCodecOperationFlags != 0 ? new VideoDevice(context, config.videoCodecOperationFlags) : DE_NULL);
284 	const DeviceInterface&			vk					= getSyncDeviceInterface(videoDevice, context);
285 	const VkDevice					device				= getSyncDevice(videoDevice, context);
286 	const VkQueue					queue				= getSyncQueue(videoDevice, context);
287 	const deUint32					queueFamilyIndex	= getSyncQueueFamilyIndex(videoDevice, context);
288 	const Move<VkFence>				ptrFence[COUNT]		= { createFence(vk, device), createFence(vk, device) };
289 	VkFence							fence[COUNT]		= { *ptrFence[SET], *ptrFence[WAIT] };
290 	const Unique<VkCommandPool>		cmdPool				(createCommandPool(vk, device, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, queueFamilyIndex));
291 	const Move<VkCommandBuffer>		ptrCmdBuffer[COUNT] = { makeCommandBuffer(vk, device, *cmdPool), makeCommandBuffer(vk, device, *cmdPool) };
292 	VkCommandBuffer					cmdBuffers[COUNT]	= { *ptrCmdBuffer[SET], *ptrCmdBuffer[WAIT] };
293 	const Unique<VkEvent>			event				(createEvent(vk, device, config.flags));
294 	VkCommandBufferSubmitInfoKHR	commandBufferSubmitInfo[] =
295 	{
296 		makeCommonCommandBufferSubmitInfo(cmdBuffers[SET]),
297 		makeCommonCommandBufferSubmitInfo(cmdBuffers[WAIT])
298 	};
299 	SynchronizationWrapperPtr		synchronizationWrapper[] =
300 	{
301 		getSynchronizationWrapper(config.type, vk, DE_FALSE),
302 		getSynchronizationWrapper(config.type, vk, DE_FALSE)
303 	};
304 	VkDependencyInfoKHR				dependencyInfos[] =
305 	{
306 		makeCommonDependencyInfo(DE_NULL, DE_NULL, DE_NULL, DE_TRUE),
307 		makeCommonDependencyInfo(DE_NULL, DE_NULL, DE_NULL, DE_TRUE)
308 	};
309 
310 	synchronizationWrapper[SET]->addSubmitInfo(
311 		0u,										// deUint32								waitSemaphoreInfoCount
312 		DE_NULL,								// const VkSemaphoreSubmitInfoKHR*		pWaitSemaphoreInfos
313 		1u,										// deUint32								commandBufferInfoCount
314 		&commandBufferSubmitInfo[SET],			// const VkCommandBufferSubmitInfoKHR*	pCommandBufferInfos
315 		0u,										// deUint32								signalSemaphoreInfoCount
316 		DE_NULL									// const VkSemaphoreSubmitInfoKHR*		pSignalSemaphoreInfos
317 	);
318 
319 	synchronizationWrapper[WAIT]->addSubmitInfo(
320 		0u,										// deUint32								waitSemaphoreInfoCount
321 		DE_NULL,								// const VkSemaphoreSubmitInfoKHR*		pWaitSemaphoreInfos
322 		1u,										// deUint32								commandBufferInfoCount
323 		&commandBufferSubmitInfo[WAIT],			// const VkCommandBufferSubmitInfoKHR*	pCommandBufferInfos
324 		0u,										// deUint32								signalSemaphoreInfoCount
325 		DE_NULL									// const VkSemaphoreSubmitInfoKHR*		pSignalSemaphoreInfos
326 	);
327 
328 	beginCommandBuffer(vk, cmdBuffers[SET]);
329 	synchronizationWrapper[SET]->cmdSetEvent(cmdBuffers[SET], *event, &dependencyInfos[SET]);
330 	endCommandBuffer(vk, cmdBuffers[SET]);
331 
332 	beginCommandBuffer(vk, cmdBuffers[WAIT]);
333 	synchronizationWrapper[WAIT]->cmdWaitEvents(cmdBuffers[WAIT], 1u, &event.get(), &dependencyInfos[WAIT]);
334 	endCommandBuffer(vk, cmdBuffers[WAIT]);
335 
336 	VK_CHECK(synchronizationWrapper[SET]->queueSubmit(queue, fence[SET]));
337 	VK_CHECK(synchronizationWrapper[WAIT]->queueSubmit(queue, fence[WAIT]));
338 
339 	if (VK_SUCCESS != vk.waitForFences(device, 2u, fence, DE_TRUE, LONG_FENCE_WAIT))
340 		return tcu::TestStatus::fail("Queue should end execution");
341 
342 	return tcu::TestStatus::pass("Wait and set even on device multi submission tests pass");
343 }
344 
secondaryCommandBufferCase(Context & context,TestConfig config)345 tcu::TestStatus secondaryCommandBufferCase (Context& context, TestConfig config)
346 {
347 	enum {SET=0, WAIT, COUNT};
348 	de::MovePtr<VideoDevice>				videoDevice				(config.videoCodecOperationFlags != 0 ? new VideoDevice(context, config.videoCodecOperationFlags) : DE_NULL);
349 	const DeviceInterface&					vk						= getSyncDeviceInterface(videoDevice, context);
350 	const VkDevice							device					= getSyncDevice(videoDevice, context);
351 	const VkQueue							queue					= getSyncQueue(videoDevice, context);
352 	const deUint32							queueFamilyIndex		= getSyncQueueFamilyIndex(videoDevice, context);
353 	const Unique<VkFence>					fence					(createFence(vk, device));
354 	const Unique<VkCommandPool>				cmdPool					(createCommandPool(vk, device, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, queueFamilyIndex));
355 	const Move<VkCommandBuffer>				primaryCmdBuffer		(makeCommandBuffer(vk, device, *cmdPool));
356 	const VkCommandBufferAllocateInfo		cmdBufferInfo			=
357 																	{
358 																		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,		// VkStructureType		sType;
359 																		DE_NULL,											// const void*			pNext;
360 																		*cmdPool,											// VkCommandPool		commandPool;
361 																		VK_COMMAND_BUFFER_LEVEL_SECONDARY,					// VkCommandBufferLevel	level;
362 																		1u,													// deUint32				commandBufferCount;
363 																	};
364 	const Move<VkCommandBuffer>				prtCmdBuffers[COUNT]	= {allocateCommandBuffer (vk, device, &cmdBufferInfo), allocateCommandBuffer (vk, device, &cmdBufferInfo)};
365 	VkCommandBuffer							secondaryCmdBuffers[]	= {*prtCmdBuffers[SET], *prtCmdBuffers[WAIT]};
366 	const Unique<VkEvent>					event					(createEvent(vk, device, config.flags));
367 
368 	const VkCommandBufferInheritanceInfo	secCmdBufInheritInfo	=
369 																	{
370 																		VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,	//VkStructureType					sType;
371 																		DE_NULL,											//const void*						pNext;
372 																		DE_NULL,											//VkRenderPass					renderPass;
373 																		0u,													//deUint32						subpass;
374 																		DE_NULL,											//VkFramebuffer					framebuffer;
375 																		VK_FALSE,											//VkBool32						occlusionQueryEnable;
376 																		(VkQueryControlFlags)0u,							//VkQueryControlFlags				queryFlags;
377 																		(VkQueryPipelineStatisticFlags)0u,					//VkQueryPipelineStatisticFlags	pipelineStatistics;
378 																	};
379 	const VkCommandBufferBeginInfo			cmdBufferBeginInfo		=
380 																	{
381 																		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,	// VkStructureType                          sType;
382 																		DE_NULL,										// const void*                              pNext;
383 																		VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,	// VkCommandBufferUsageFlags                flags;
384 																		&secCmdBufInheritInfo,							// const VkCommandBufferInheritanceInfo*    pInheritanceInfo;
385 																	};
386 	VkCommandBufferSubmitInfoKHR			commandBufferSubmitInfo	= makeCommonCommandBufferSubmitInfo(*primaryCmdBuffer);
387 	VkDependencyInfoKHR						dependencyInfos[]		=
388 																	{
389 																		makeCommonDependencyInfo(DE_NULL, DE_NULL, DE_NULL, DE_TRUE),
390 																		makeCommonDependencyInfo(DE_NULL, DE_NULL, DE_NULL, DE_TRUE)
391 																	};
392 	SynchronizationWrapperPtr				synchronizationWrapper	= getSynchronizationWrapper(config.type, vk, DE_FALSE);
393 
394 	synchronizationWrapper->addSubmitInfo(
395 		0u,										// deUint32								waitSemaphoreInfoCount
396 		DE_NULL,								// const VkSemaphoreSubmitInfoKHR*		pWaitSemaphoreInfos
397 		1u,										// deUint32								commandBufferInfoCount
398 		&commandBufferSubmitInfo,				// const VkCommandBufferSubmitInfoKHR*	pCommandBufferInfos
399 		0u,										// deUint32								signalSemaphoreInfoCount
400 		DE_NULL									// const VkSemaphoreSubmitInfoKHR*		pSignalSemaphoreInfos
401 	);
402 
403 	VK_CHECK(vk.beginCommandBuffer(secondaryCmdBuffers[SET], &cmdBufferBeginInfo));
404 	synchronizationWrapper->cmdSetEvent(secondaryCmdBuffers[SET], *event, &dependencyInfos[SET]);
405 	endCommandBuffer(vk, secondaryCmdBuffers[SET]);
406 
407 	VK_CHECK(vk.beginCommandBuffer(secondaryCmdBuffers[WAIT], &cmdBufferBeginInfo));
408 	synchronizationWrapper->cmdWaitEvents(secondaryCmdBuffers[WAIT], 1u, &event.get(), &dependencyInfos[WAIT]);
409 	endCommandBuffer(vk, secondaryCmdBuffers[WAIT]);
410 
411 	beginCommandBuffer(vk, *primaryCmdBuffer);
412 	vk.cmdExecuteCommands(*primaryCmdBuffer, 2u, secondaryCmdBuffers);
413 	endCommandBuffer(vk, *primaryCmdBuffer);
414 
415 	VK_CHECK(synchronizationWrapper->queueSubmit(queue, *fence));
416 
417 	if (VK_SUCCESS != vk.waitForFences(device, 1u, &fence.get(), DE_TRUE, LONG_FENCE_WAIT))
418 		return tcu::TestStatus::fail("Queue should end execution");
419 
420 	return tcu::TestStatus::pass("Wait and set even on device using secondary command buffers tests pass");
421 }
422 
checkSupport(Context & context,TestConfig config)423 void checkSupport (Context& context, TestConfig config)
424 {
425 	if (config.videoCodecOperationFlags != 0)
426 		VideoDevice::checkSupport(context, config.videoCodecOperationFlags);
427 
428 	if (config.type == SynchronizationType::SYNCHRONIZATION2)
429 		context.requireDeviceFunctionality("VK_KHR_synchronization2");
430 
431 #ifndef CTS_USES_VULKANSC
432 	if (context.isDeviceFunctionalitySupported("VK_KHR_portability_subset") && !context.getPortabilitySubsetFeatures().events)
433 		TCU_THROW(NotSupportedError, "VK_KHR_portability_subset: Events are not supported by this implementation");
434 #endif // CTS_USES_VULKANSC
435 }
436 
checkSecondaryBufferSupport(Context & context,TestConfig config)437 void checkSecondaryBufferSupport (Context& context, TestConfig config)
438 {
439 	checkSupport(context, config);
440 
441 #ifdef CTS_USES_VULKANSC
442 	if (context.getDeviceVulkanSC10Properties().secondaryCommandBufferNullOrImagelessFramebuffer == VK_FALSE)
443 		TCU_THROW(NotSupportedError, "secondaryCommandBufferNullFramebuffer is not supported");
444 #endif // CTS_USES_VULKANSC
445 }
446 
447 } // anonymous
448 
createBasicEventTests(tcu::TestContext & testCtx,VideoCodecOperationFlags videoCodecOperationFlags)449 tcu::TestCaseGroup* createBasicEventTests (tcu::TestContext& testCtx, VideoCodecOperationFlags videoCodecOperationFlags)
450 {
451 	TestConfig config
452 	{
453 		SynchronizationType::LEGACY,
454 		0U,
455 		videoCodecOperationFlags
456 	};
457 
458 	de::MovePtr<tcu::TestCaseGroup> basicTests (new tcu::TestCaseGroup(testCtx, "event", "Basic event tests"));
459 
460 	addFunctionCase(basicTests.get(), "host_set_reset", "Basic event tests set and reset on host", checkSupport, hostResetSetEventCase, config);
461 	addFunctionCase(basicTests.get(), "device_set_reset", "Basic event tests set and reset on device", checkSupport, deviceResetSetEventCase, config);
462 	addFunctionCase(basicTests.get(), "single_submit_multi_command_buffer", "Wait and set event single submission on device", checkSupport, singleSubmissionCase, config);
463 	addFunctionCase(basicTests.get(), "multi_submit_multi_command_buffer", "Wait and set event mutli submission on device", checkSupport, multiSubmissionCase, config);
464 	// Secondary command buffer does not apply to video queues and should not be a part of test plan
465 	if (!videoCodecOperationFlags)
466 		addFunctionCase(basicTests.get(), "multi_secondary_command_buffer", "Event used on secondary command buffer ", checkSecondaryBufferSupport, secondaryCommandBufferCase, config);
467 
468 	return basicTests.release();
469 }
470 
createSynchronization2BasicEventTests(tcu::TestContext & testCtx,VideoCodecOperationFlags videoCodecOperationFlags)471 tcu::TestCaseGroup* createSynchronization2BasicEventTests (tcu::TestContext& testCtx, VideoCodecOperationFlags videoCodecOperationFlags)
472 {
473 	TestConfig config
474 	{
475 		SynchronizationType::SYNCHRONIZATION2,
476 		0U,
477 		videoCodecOperationFlags
478 	};
479 
480 	de::MovePtr<tcu::TestCaseGroup> basicTests (new tcu::TestCaseGroup(testCtx, "event", "Basic event tests"));
481 
482 	addFunctionCase(basicTests.get(), "device_set_reset", "Basic event tests set and reset on device", checkSupport, deviceResetSetEventCase, config);
483 	addFunctionCase(basicTests.get(), "single_submit_multi_command_buffer", "Wait and set event single submission on device", checkSupport, singleSubmissionCase, config);
484 	addFunctionCase(basicTests.get(), "multi_submit_multi_command_buffer", "Wait and set event mutli submission on device", checkSupport, multiSubmissionCase, config);
485 	addFunctionCase(basicTests.get(), "multi_secondary_command_buffer", "Event used on secondary command buffer ", checkSecondaryBufferSupport, secondaryCommandBufferCase, config);
486 	addFunctionCase(basicTests.get(), "none_set_reset", "Event set and reset using the none pipeline stage ", checkSupport, eventSetResetNoneStage, config);
487 
488 	config.flags = VK_EVENT_CREATE_DEVICE_ONLY_BIT_KHR;
489 	addFunctionCase(basicTests.get(), "single_submit_multi_command_buffer_device_only", "Wait and set GPU-only event single submission", checkSupport, singleSubmissionCase, config);
490 	addFunctionCase(basicTests.get(), "multi_submit_multi_command_buffer_device_only", "Wait and set GPU-only event mutli submission", checkSupport, multiSubmissionCase, config);
491 	addFunctionCase(basicTests.get(), "multi_secondary_command_buffer_device_only", "GPU-only event used on secondary command buffer ", checkSecondaryBufferSupport, secondaryCommandBufferCase, config);
492 
493 	return basicTests.release();
494 
495 }
496 
497 } // synchronization
498 } // vkt
499