1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 The Khronos Group Inc.
6 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
7 * Copyright (c) 2015 Google Inc.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and/or associated documentation files (the
11 * "Materials"), to deal in the Materials without restriction, including
12 * without limitation the rights to use, copy, modify, merge, publish,
13 * distribute, sublicense, and/or sell copies of the Materials, and to
14 * permit persons to whom the Materials are furnished to do so, subject to
15 * the following conditions:
17 * The above copyright notice(s) and this permission notice shall be
18 * included in all copies or substantial portions of the Materials.
20 * The Materials are Confidential Information as defined by the
21 * Khronos Membership Agreement until designated non-confidential by
22 * Khronos, at which point this condition clause shall be removed.
24 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
28 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
29 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
30 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
32 *//*--------------------------------------------------------------------*/
35 #include "vktTestCaseUtil.hpp"
36 #include "vkBuilderUtil.hpp"
37 #include "vkPlatform.hpp"
38 #include "vkRefUtil.hpp"
39 #include "vkQueryUtil.hpp"
40 #include "vkMemUtil.hpp"
41 #include "vkDeviceUtil.hpp"
42 #include "vkPrograms.hpp"
43 #include "vkTypeUtil.hpp"
44 #include "vkAllocationCallbackUtil.hpp"
45 #include "vktApiCommandBuffersTests.hpp"
46 #include "vktApiBufferComputeInstance.hpp"
47 #include "vktApiComputeInstanceResultBuffer.hpp"
60 const deUint64 INFINITE_TIMEOUT = ~(deUint64)0u;
63 /********* 19.1. Command Pools (6.1 in VK 1.0 Spec) ***************************/
64 tcu::TestStatus createPoolNullParamsTest(Context& context)
66 const VkDevice vkDevice = context.getDevice();
67 const DeviceInterface& vk = context.getDeviceInterface();
68 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
70 const VkCommandPoolCreateInfo cmdPoolParams =
72 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType;
75 queueFamilyIndex, // queueFamilyIndex;
77 VkCommandPool cmdPool;
79 VK_CHECK(vk.createCommandPool(vkDevice, &cmdPoolParams, DE_NULL, &cmdPool));
81 return tcu::TestStatus::pass("Command Pool allocated correctly.");
84 tcu::TestStatus createPoolNonNullAllocatorTest(Context& context)
86 const VkDevice vkDevice = context.getDevice();
87 const DeviceInterface& vk = context.getDeviceInterface();
88 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
89 const VkAllocationCallbacks* allocationCallbacks = getSystemAllocator();
91 const VkCommandPoolCreateInfo cmdPoolParams =
93 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType;
96 queueFamilyIndex, // queueFamilyIndex;
98 VkCommandPool cmdPool;
100 VK_CHECK(vk.createCommandPool(vkDevice, &cmdPoolParams, allocationCallbacks, &cmdPool));
102 return tcu::TestStatus::pass("Command Pool allocated correctly.");
105 tcu::TestStatus createPoolTransientBitTest(Context& context)
107 const VkDevice vkDevice = context.getDevice();
108 const DeviceInterface& vk = context.getDeviceInterface();
109 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
111 const VkCommandPoolCreateInfo cmdPoolParams =
113 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType;
115 VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, // flags;
116 queueFamilyIndex, // queueFamilyIndex;
118 VkCommandPool cmdPool;
120 VK_CHECK(vk.createCommandPool(vkDevice, &cmdPoolParams, DE_NULL, &cmdPool));
122 return tcu::TestStatus::pass("Command Pool allocated correctly.");
125 tcu::TestStatus createPoolResetBitTest(Context& context)
127 const VkDevice vkDevice = context.getDevice();
128 const DeviceInterface& vk = context.getDeviceInterface();
129 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
131 const VkCommandPoolCreateInfo cmdPoolParams =
133 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType;
135 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags;
136 queueFamilyIndex, // queueFamilyIndex;
138 VkCommandPool cmdPool;
140 VK_CHECK(vk.createCommandPool(vkDevice, &cmdPoolParams, DE_NULL, &cmdPool));
142 return tcu::TestStatus::pass("Command Pool allocated correctly.");
145 tcu::TestStatus resetPoolReleaseResourcesBitTest(Context& context)
147 const VkDevice vkDevice = context.getDevice();
148 const DeviceInterface& vk = context.getDeviceInterface();
149 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
151 const VkCommandPoolCreateInfo cmdPoolParams =
153 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType;
156 queueFamilyIndex, // queueFamilyIndex;
158 VkCommandPool cmdPool;
160 VK_CHECK(vk.createCommandPool(vkDevice, &cmdPoolParams, DE_NULL, &cmdPool));
161 VK_CHECK(vk.resetCommandPool(vkDevice, cmdPool, VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT));
163 return tcu::TestStatus::pass("Command Pool allocated correctly.");
166 tcu::TestStatus resetPoolNoFlagsTest(Context& context)
168 const VkDevice vkDevice = context.getDevice();
169 const DeviceInterface& vk = context.getDeviceInterface();
170 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
172 const VkCommandPoolCreateInfo cmdPoolParams =
174 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType;
177 queueFamilyIndex, // queueFamilyIndex;
179 VkCommandPool cmdPool;
181 VK_CHECK(vk.createCommandPool(vkDevice, &cmdPoolParams, DE_NULL, &cmdPool));
182 VK_CHECK(vk.resetCommandPool(vkDevice, cmdPool, 0u));
184 return tcu::TestStatus::pass("Command Pool allocated correctly.");
187 /******** 19.2. Command Buffer Lifetime (6.2 in VK 1.0 Spec) ******************/
188 tcu::TestStatus allocatePrimaryBufferTest(Context& context)
190 const VkDevice vkDevice = context.getDevice();
191 const DeviceInterface& vk = context.getDeviceInterface();
192 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
194 const VkCommandPoolCreateInfo cmdPoolParams =
196 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType;
198 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags;
199 queueFamilyIndex, // queueFamilyIndex;
201 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
204 const VkCommandBufferAllocateInfo cmdBufParams =
206 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType;
208 *cmdPool, // commandPool;
209 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level;
212 const Unique<VkCommandBuffer> cmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
214 return tcu::TestStatus::pass("Buffer was created correctly.");
217 tcu::TestStatus allocateManyPrimaryBuffersTest(Context& context)
220 const VkDevice vkDevice = context.getDevice();
221 const DeviceInterface& vk = context.getDeviceInterface();
222 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
224 const VkCommandPoolCreateInfo cmdPoolParams =
226 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
227 DE_NULL, // const void* pNext;
228 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags;
229 queueFamilyIndex, // deUint32 queueFamilyIndex;
231 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
233 // create a minimal amount of command buffers - is there any minimal amount in spec?
234 const unsigned minCommandBuffer = 10000;
237 const VkCommandBufferAllocateInfo cmdBufParams =
239 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
240 DE_NULL, // const void* pNext;
241 *cmdPool, // VkCommandPool pool;
242 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
243 minCommandBuffer, // uint32_t bufferCount;
246 // do not keep the handles to buffers, as they will be freed with command pool
248 // allocate the minimum required amount of buffers
249 VkCommandBuffer cmdBuffers[minCommandBuffer];
250 VK_CHECK(vk.allocateCommandBuffers(vkDevice, &cmdBufParams, cmdBuffers));
252 std::ostringstream out;
253 out << "allocateManyPrimaryBuffersTest succeded: created " << minCommandBuffer << " command buffers";
255 return tcu::TestStatus::pass(out.str());
258 tcu::TestStatus allocateZeroPrimaryBuffersTest(Context& context)
260 const VkDevice vkDevice = context.getDevice();
261 const DeviceInterface& vk = context.getDeviceInterface();
262 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
264 const VkCommandPoolCreateInfo cmdPoolParams =
266 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType;
268 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags;
269 queueFamilyIndex, // queueFamilyIndex;
271 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
274 const VkCommandBufferAllocateInfo cmdBufParams =
276 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType;
278 *cmdPool, // commandPool;
279 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level;
283 VkCommandBuffer cmdBuffer;
284 VK_CHECK(vk.allocateCommandBuffers(vkDevice, &cmdBufParams, &cmdBuffer));
286 return tcu::TestStatus::pass("allocateZeroPrimaryBuffersTest passed.");
289 tcu::TestStatus allocateSecondaryBufferTest(Context& context)
291 const VkDevice vkDevice = context.getDevice();
292 const DeviceInterface& vk = context.getDeviceInterface();
293 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
295 const VkCommandPoolCreateInfo cmdPoolParams =
297 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType;
299 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags;
300 queueFamilyIndex, // queueFamilyIndex;
302 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
305 const VkCommandBufferAllocateInfo cmdBufParams =
307 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType;
309 *cmdPool, // commandPool;
310 VK_COMMAND_BUFFER_LEVEL_SECONDARY, // level;
313 const Unique<VkCommandBuffer> cmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
315 return tcu::TestStatus::pass("Buffer was created correctly.");
318 tcu::TestStatus allocateManySecondaryBuffersTest(Context& context)
321 const VkDevice vkDevice = context.getDevice();
322 const DeviceInterface& vk = context.getDeviceInterface();
323 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
325 const VkCommandPoolCreateInfo cmdPoolParams =
327 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
328 DE_NULL, // const void* pNext;
329 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags;
330 queueFamilyIndex, // deUint32 queueFamilyIndex;
332 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
334 // create a minimal amount of command buffers - is there any minimal amount in spec?
335 const unsigned minCommandBuffer = 10000;
338 const VkCommandBufferAllocateInfo cmdBufParams =
340 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
341 DE_NULL, // const void* pNext;
342 *cmdPool, // VkCommandPool pool;
343 VK_COMMAND_BUFFER_LEVEL_SECONDARY, // VkCommandBufferLevel level;
344 minCommandBuffer, // uint32_t bufferCount;
347 // do not keep the handles to buffers, as they will be freed with command pool
349 // allocate the minimum required amount of buffers
350 VkCommandBuffer cmdBuffers[minCommandBuffer];
351 VK_CHECK(vk.allocateCommandBuffers(vkDevice, &cmdBufParams, cmdBuffers));
353 std::ostringstream out;
354 out << "allocateManySecondaryBuffersTest succeded: created " << minCommandBuffer << " command buffers";
356 return tcu::TestStatus::pass(out.str());
359 tcu::TestStatus allocateZeroSecondaryBuffersTest(Context& context)
361 const VkDevice vkDevice = context.getDevice();
362 const DeviceInterface& vk = context.getDeviceInterface();
363 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
365 const VkCommandPoolCreateInfo cmdPoolParams =
367 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType;
369 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags;
370 queueFamilyIndex, // queueFamilyIndex;
372 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
375 const VkCommandBufferAllocateInfo cmdBufParams =
377 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType;
379 *cmdPool, // commandPool;
380 VK_COMMAND_BUFFER_LEVEL_SECONDARY, // level;
384 VkCommandBuffer cmdBuffer;
385 VK_CHECK(vk.allocateCommandBuffers(vkDevice, &cmdBufParams, &cmdBuffer));
387 return tcu::TestStatus::pass("allocateZeroSecondaryBuffersTest passed.");
390 tcu::TestStatus executePrimaryBufferTest(Context& context)
392 const VkDevice vkDevice = context.getDevice();
393 const DeviceInterface& vk = context.getDeviceInterface();
394 const VkQueue queue = context.getUniversalQueue();
395 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
397 const VkCommandPoolCreateInfo cmdPoolParams =
399 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
400 DE_NULL, // const void* pNext;
401 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags;
402 queueFamilyIndex, // deUint32 queueFamilyIndex;
404 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
407 const VkCommandBufferAllocateInfo cmdBufParams =
409 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
410 DE_NULL, // const void* pNext;
411 *cmdPool, // VkCommandPool pool;
412 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
413 1u, // uint32_t bufferCount;
415 const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
416 const VkCommandBufferBeginInfo primCmdBufBeginInfo =
418 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
421 (VkRenderPass)0u, // renderPass
423 (VkFramebuffer)0u, // framebuffer
424 VK_FALSE, // occlusionQueryEnable
425 (VkQueryControlFlags)0u, // queryFlags
426 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
429 // Fill create info struct for event
430 const VkEventCreateInfo eventCreateInfo =
432 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
437 // create event that will be used to check if secondary command buffer has been executed
438 const Unique<VkEvent> event (createEvent(vk, vkDevice, &eventCreateInfo));
441 VK_CHECK(vk.resetEvent(vkDevice, *event));
443 // record primary command buffer
444 VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
446 // allow execution of event during every stage of pipeline
447 VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
449 // record setting event
450 vk.cmdSetEvent(*primCmdBuf, *event,stageMask);
452 VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
454 const VkFenceCreateInfo fenceCreateInfo =
456 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
461 // create fence to wait for execution of queue
462 const Unique<VkFence> fence (createFence(vk, vkDevice, &fenceCreateInfo));
464 const VkSubmitInfo submitInfo =
466 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
468 0u, // waitSemaphoreCount
469 DE_NULL, // pWaitSemaphores
470 // TODO: The following field is in api spec 1.0 37bedec32143807010323f126ad685ab5e9d98de
471 // TODO: but not in the header Loader and Tools 69d4893b673bd552e445ba999ad0e73463d35007
472 // DE_NULL, // pWaitDstStageMask
473 1, // commandBufferCount
474 &primCmdBuf.get(), // pCommandBuffers
475 0u, // signalSemaphoreCount
476 DE_NULL, // pSignalSemaphores
479 // Submit the command buffer to the queue
480 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
482 // wait for end of execution of queue
483 VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
485 // check if buffer has been executed
486 VkResult result = vk.getEventStatus(vkDevice,*event);
487 if (result == VK_EVENT_SET)
488 return tcu::TestStatus::pass("Execute Primary Command Buffer succeeded");
490 return tcu::TestStatus::fail("Execute Primary Command Buffer FAILED");
493 tcu::TestStatus executeLargePrimaryBufferTest(Context& context)
495 const VkDevice vkDevice = context.getDevice();
496 const DeviceInterface& vk = context.getDeviceInterface();
497 const VkQueue queue = context.getUniversalQueue();
498 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
499 const deUint32 LARGE_BUFFER_SIZE = 10000;
501 const VkCommandPoolCreateInfo cmdPoolParams =
503 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
504 DE_NULL, // const void* pNext;
505 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags;
506 queueFamilyIndex, // deUint32 queueFamilyIndex;
508 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
511 const VkCommandBufferAllocateInfo cmdBufParams =
513 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
514 DE_NULL, // const void* pNext;
515 *cmdPool, // VkCommandPool pool;
516 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
517 1u, // uint32_t bufferCount;
519 const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
520 const VkCommandBufferBeginInfo primCmdBufBeginInfo =
522 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
525 (VkRenderPass)0u, // renderPass
527 (VkFramebuffer)0u, // framebuffer
528 VK_FALSE, // occlusionQueryEnable
529 (VkQueryControlFlags)0u, // queryFlags
530 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
533 // Fill create info struct for event
534 const VkEventCreateInfo eventCreateInfo =
536 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
540 VkEvent events[LARGE_BUFFER_SIZE];
541 for (deUint32 ndx = 0; ndx < LARGE_BUFFER_SIZE; ++ndx)
543 VK_CHECK(vk.createEvent(vkDevice, &eventCreateInfo, DE_NULL, &events[ndx]));
546 // record primary command buffer
547 VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
549 // set all the events in the array
550 for (deUint32 ndx = 0; ndx < LARGE_BUFFER_SIZE; ++ndx)
552 vk.cmdSetEvent(*primCmdBuf, events[ndx], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
555 VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
557 const VkFenceCreateInfo fenceCreateInfo =
559 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
564 // create fence to wait for execution of queue
565 const Unique<VkFence> fence (createFence(vk, vkDevice, &fenceCreateInfo));
567 const VkSubmitInfo submitInfo =
569 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
571 0u, // waitSemaphoreCount
572 DE_NULL, // pWaitSemaphores
573 // TODO: The following field is in api spec 1.0 37bedec32143807010323f126ad685ab5e9d98de
574 // TODO: but not in the header Loader and Tools 69d4893b673bd552e445ba999ad0e73463d35007
575 // DE_NULL, // pWaitDstStageMask
576 1, // commandBufferCount
577 &primCmdBuf.get(), // pCommandBuffers
578 0u, // signalSemaphoreCount
579 DE_NULL, // pSignalSemaphores
582 // Submit the command buffer to the queue
583 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
585 // wait for end of execution of queue
586 VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
588 // check if the buffer was executed correctly - all events had their status
590 for (deUint32 ndx = 0; ndx < LARGE_BUFFER_SIZE; ++ndx)
592 if (vk.getEventStatus(vkDevice, events[ndx]) != VK_EVENT_SET)
593 return tcu::TestStatus::fail("An event was not set.");
596 return tcu::TestStatus::pass("All events set correctly.");
599 tcu::TestStatus resetBufferImplicitlyTest(Context& context)
601 const VkDevice vkDevice = context.getDevice();
602 const DeviceInterface& vk = context.getDeviceInterface();
603 const VkQueue queue = context.getUniversalQueue();
604 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
606 const VkCommandPoolCreateInfo cmdPoolParams =
608 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType;
610 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags;
611 queueFamilyIndex, // queueFamilyIndex;
613 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
616 const VkCommandBufferAllocateInfo cmdBufParams =
618 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType;
621 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level;
624 const Unique<VkCommandBuffer> cmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
626 const VkCommandBufferBeginInfo cmdBufBeginInfo =
628 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType
631 DE_NULL, // renderPass
633 DE_NULL, // framebuffer
634 VK_FALSE, // occlusionQueryEnable
635 (VkQueryControlFlags)0u, // queryFlags
636 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
639 const VkEventCreateInfo eventCreateInfo =
641 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO, // sType;
645 const Unique<VkEvent> event (createEvent(vk, vkDevice, &eventCreateInfo));
647 // Put the command buffer in recording state.
648 VK_CHECK(vk.beginCommandBuffer(*cmdBuf, &cmdBufBeginInfo));
651 vk.cmdSetEvent(*cmdBuf, *event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
653 VK_CHECK(vk.endCommandBuffer(*cmdBuf));
655 // We'll use a fence to wait for the execution of the queue
656 const VkFenceCreateInfo fenceCreateInfo =
658 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // sType;
662 const Unique<VkFence> fence (createFence(vk, vkDevice, &fenceCreateInfo));
664 const VkSubmitInfo submitInfo =
666 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
668 0u, // waitSemaphoreCount
669 DE_NULL, // pWaitSemaphores
670 // TODO: The following field is in api spec 1.0 37bedec32143807010323f126ad685ab5e9d98de
671 // TODO: but not in the header Loader and Tools 69d4893b673bd552e445ba999ad0e73463d35007
672 // DE_NULL, // pWaitDstStageMask
673 1u, // commandBufferCount
674 &cmdBuf.get(), // pCommandBuffers
675 0u, // signalSemaphoreCount
676 DE_NULL, // pSignalSemaphores
679 // Submitting the command buffer that sets the event to the queue
680 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, fence.get()));
682 // Waiting for the queue to finish executing
683 VK_CHECK(vk.waitForFences(vkDevice, 1u, &fence.get(), 0u, INFINITE_TIMEOUT));
684 // Reset the fence so that we can reuse it
685 VK_CHECK(vk.resetFences(vkDevice, 1u, &fence.get()));
687 // Check if the buffer was executed
688 if (vk.getEventStatus(vkDevice, *event) != VK_EVENT_SET)
689 return tcu::TestStatus::fail("Failed to set the event.");
692 vk.resetEvent(vkDevice, *event);
693 if(vk.getEventStatus(vkDevice, *event) != VK_EVENT_RESET)
694 return tcu::TestStatus::fail("Failed to reset the event.");
696 // Reset the command buffer by putting it in recording state again. This
697 // should empty the command buffer.
698 VK_CHECK(vk.beginCommandBuffer(*cmdBuf, &cmdBufBeginInfo));
699 VK_CHECK(vk.endCommandBuffer(*cmdBuf));
701 // Submit the command buffer after resetting. It should have no commands
702 // recorded, so the event should remain unsignaled.
703 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, fence.get()));
704 // Waiting for the queue to finish executing
705 VK_CHECK(vk.waitForFences(vkDevice, 1u, &fence.get(), 0u, INFINITE_TIMEOUT));
707 // Check if the event remained unset.
708 if(vk.getEventStatus(vkDevice, *event) == VK_EVENT_RESET)
709 return tcu::TestStatus::pass("Buffer was reset correctly.");
711 return tcu::TestStatus::fail("Buffer was not reset correctly.");
714 /******** 19.3. Command Buffer Recording (6.3 in VK 1.0 Spec) *****************/
715 tcu::TestStatus recordSinglePrimaryBufferTest(Context& context)
717 const VkDevice vkDevice = context.getDevice();
718 const DeviceInterface& vk = context.getDeviceInterface();
719 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
721 const VkCommandPoolCreateInfo cmdPoolParams =
723 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
724 DE_NULL, // const void* pNext;
725 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags;
726 queueFamilyIndex, // deUint32 queueFamilyIndex;
728 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
731 const VkCommandBufferAllocateInfo cmdBufParams =
733 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
734 DE_NULL, // const void* pNext;
735 *cmdPool, // VkCommandPool pool;
736 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
737 1u, // uint32_t bufferCount;
739 const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
741 const VkCommandBufferBeginInfo primCmdBufBeginInfo =
743 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
746 (VkRenderPass)0u, // renderPass
748 (VkFramebuffer)0u, // framebuffer
749 VK_FALSE, // occlusionQueryEnable
750 (VkQueryControlFlags)0u, // queryFlags
751 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
754 // Fill create info struct for event
755 const VkEventCreateInfo eventCreateInfo =
757 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
762 // create event that will be used to check if secondary command buffer has been executed
763 const Unique<VkEvent> event (createEvent(vk, vkDevice, &eventCreateInfo));
765 // record primary command buffer
766 VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
768 // record setting event
769 vk.cmdSetEvent(*primCmdBuf, *event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
771 VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
773 return tcu::TestStatus::pass("Primary buffer recorded successfully.");
776 tcu::TestStatus recordLargePrimaryBufferTest(Context &context)
779 const VkDevice vkDevice = context.getDevice();
780 const DeviceInterface& vk = context.getDeviceInterface();
781 const VkQueue queue = context.getUniversalQueue();
782 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
784 const VkCommandPoolCreateInfo cmdPoolParams =
786 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
787 DE_NULL, // const void* pNext;
788 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags;
789 queueFamilyIndex, // deUint32 queueFamilyIndex;
791 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
794 const VkCommandBufferAllocateInfo cmdBufParams =
796 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
797 DE_NULL, // const void* pNext;
798 *cmdPool, // VkCommandPool pool;
799 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
800 1u, // uint32_t bufferCount;
802 const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
803 const VkCommandBufferBeginInfo primCmdBufBeginInfo =
805 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
808 (VkRenderPass)0u, // renderPass
810 (VkFramebuffer)0u, // framebuffer
811 VK_FALSE, // occlusionQueryEnable
812 (VkQueryControlFlags)0u, // queryFlags
813 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
816 // Fill create info struct for event
817 const VkEventCreateInfo eventCreateInfo =
819 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
824 // create event that will be used to check if secondary command buffer has been executed
825 const Unique<VkEvent> event (createEvent(vk, vkDevice, &eventCreateInfo));
828 VK_CHECK(vk.resetEvent(vkDevice, *event));
830 // record primary command buffer
831 VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
833 // allow execution of event during every stage of pipeline
834 VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
836 // define minimal amount of commands to accept
837 const long long unsigned minNumCommands = 10000llu;
839 for ( long long unsigned currentCommands = 0; currentCommands < minNumCommands / 2; ++currentCommands )
841 // record setting event
842 vk.cmdSetEvent(*primCmdBuf, *event,stageMask);
844 // record resetting event
845 vk.cmdResetEvent(*primCmdBuf, *event,stageMask);
849 VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
851 const VkFenceCreateInfo fenceCreateInfo =
853 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
858 // create fence to wait for execution of queue
859 const Unique<VkFence> fence (createFence(vk, vkDevice, &fenceCreateInfo));
861 const VkSubmitInfo submitInfo =
863 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
865 0u, // waitSemaphoreCount
866 DE_NULL, // pWaitSemaphores
867 // TODO: The following field is in api spec 1.0 37bedec32143807010323f126ad685ab5e9d98de
868 // TODO: but not in the header Loader and Tools 69d4893b673bd552e445ba999ad0e73463d35007
869 // DE_NULL, // pWaitDstStageMask
870 1, // commandBufferCount
871 &primCmdBuf.get(), // pCommandBuffers
872 0u, // signalSemaphoreCount
873 DE_NULL, // pSignalSemaphores
876 // Submit the command buffer to the queue
877 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
879 // wait for end of execution of queue
880 VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
882 return tcu::TestStatus::pass("hugeTest succeeded");
885 tcu::TestStatus recordSingleSecondaryBufferTest(Context& context)
887 const VkDevice vkDevice = context.getDevice();
888 const DeviceInterface& vk = context.getDeviceInterface();
889 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
891 const VkCommandPoolCreateInfo cmdPoolParams =
893 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
894 DE_NULL, // const void* pNext;
895 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags;
896 queueFamilyIndex, // deUint32 queueFamilyIndex;
898 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
901 const VkCommandBufferAllocateInfo cmdBufParams =
903 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
904 DE_NULL, // const void* pNext;
905 *cmdPool, // VkCommandPool pool;
906 VK_COMMAND_BUFFER_LEVEL_SECONDARY, // VkCommandBufferLevel level;
907 1u, // uint32_t bufferCount;
909 const Unique<VkCommandBuffer> secCmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
911 const VkCommandBufferBeginInfo secCmdBufBeginInfo =
913 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
916 (VkRenderPass)0u, // renderPass
918 (VkFramebuffer)0u, // framebuffer
919 VK_FALSE, // occlusionQueryEnable
920 (VkQueryControlFlags)0u, // queryFlags
921 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
924 // Fill create info struct for event
925 const VkEventCreateInfo eventCreateInfo =
927 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
932 // create event that will be used to check if secondary command buffer has been executed
933 const Unique<VkEvent> event (createEvent(vk, vkDevice, &eventCreateInfo));
935 // record primary command buffer
936 VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo));
938 // record setting event
939 vk.cmdSetEvent(*secCmdBuf, *event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
941 VK_CHECK(vk.endCommandBuffer(*secCmdBuf));
943 return tcu::TestStatus::pass("Secondary buffer recorded successfully.");
946 tcu::TestStatus recordLargeSecondaryBufferTest(Context &context)
949 const VkDevice vkDevice = context.getDevice();
950 const DeviceInterface& vk = context.getDeviceInterface();
951 const VkQueue queue = context.getUniversalQueue();
952 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
954 const VkCommandPoolCreateInfo cmdPoolParams =
956 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
957 DE_NULL, // const void* pNext;
958 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags;
959 queueFamilyIndex, // deUint32 queueFamilyIndex;
961 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
964 const VkCommandBufferAllocateInfo cmdBufParams =
966 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
967 DE_NULL, // const void* pNext;
968 *cmdPool, // VkCommandPool pool;
969 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
970 1u, // uint32_t bufferCount;
972 const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
973 const VkCommandBufferBeginInfo primCmdBufBeginInfo =
975 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
978 (VkRenderPass)0u, // renderPass
980 (VkFramebuffer)0u, // framebuffer
981 VK_FALSE, // occlusionQueryEnable
982 (VkQueryControlFlags)0u, // queryFlags
983 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
986 // Fill create info struct for event
987 const VkEventCreateInfo eventCreateInfo =
989 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
994 // create event that will be used to check if secondary command buffer has been executed
995 const Unique<VkEvent> event (createEvent(vk, vkDevice, &eventCreateInfo));
998 VK_CHECK(vk.resetEvent(vkDevice, *event));
1000 // record primary command buffer
1001 VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
1003 // allow execution of event during every stage of pipeline
1004 VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1006 // define minimal amount of commands to accept
1007 const long long unsigned minNumCommands = 10000llu;
1009 for ( long long unsigned currentCommands = 0; currentCommands < minNumCommands / 2; ++currentCommands )
1011 // record setting event
1012 vk.cmdSetEvent(*primCmdBuf, *event,stageMask);
1014 // record resetting event
1015 vk.cmdResetEvent(*primCmdBuf, *event,stageMask);
1020 VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
1022 const VkFenceCreateInfo fenceCreateInfo =
1024 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
1029 // create fence to wait for execution of queue
1030 const Unique<VkFence> fence (createFence(vk, vkDevice, &fenceCreateInfo));
1032 const VkSubmitInfo submitInfo =
1034 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
1036 0u, // waitSemaphoreCount
1037 DE_NULL, // pWaitSemaphores
1038 // TODO: The following field is in api spec 1.0 37bedec32143807010323f126ad685ab5e9d98de
1039 // TODO: but not in the header Loader and Tools 69d4893b673bd552e445ba999ad0e73463d35007
1040 // DE_NULL, // pWaitDstStageMask
1041 1, // commandBufferCount
1042 &primCmdBuf.get(), // pCommandBuffers
1043 0u, // signalSemaphoreCount
1044 DE_NULL, // pSignalSemaphores
1047 // Submit the command buffer to the queue
1048 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
1050 // wait for end of execution of queue
1051 VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
1053 return tcu::TestStatus::pass("hugeTest succeeded");
1056 tcu::TestStatus submitPrimaryBufferTwiceTest(Context& context)
1059 const VkDevice vkDevice = context.getDevice();
1060 const DeviceInterface& vk = context.getDeviceInterface();
1061 const VkQueue queue = context.getUniversalQueue();
1062 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
1064 const VkCommandPoolCreateInfo cmdPoolParams =
1066 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
1067 DE_NULL, // const void* pNext;
1068 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags;
1069 queueFamilyIndex, // deUint32 queueFamilyIndex;
1071 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
1074 const VkCommandBufferAllocateInfo cmdBufParams =
1076 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
1077 DE_NULL, // const void* pNext;
1078 *cmdPool, // VkCommandPool pool;
1079 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
1080 1u, // uint32_t bufferCount;
1082 const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
1083 const VkCommandBufferBeginInfo primCmdBufBeginInfo =
1085 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
1088 (VkRenderPass)0u, // renderPass
1090 (VkFramebuffer)0u, // framebuffer
1091 VK_FALSE, // occlusionQueryEnable
1092 (VkQueryControlFlags)0u, // queryFlags
1093 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
1096 // Fill create info struct for event
1097 const VkEventCreateInfo eventCreateInfo =
1099 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
1104 // create event that will be used to check if secondary command buffer has been executed
1105 const Unique<VkEvent> event (createEvent(vk, vkDevice, &eventCreateInfo));
1108 VK_CHECK(vk.resetEvent(vkDevice, *event));
1110 // record primary command buffer
1111 VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
1113 // allow execution of event during every stage of pipeline
1114 VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1116 // record setting event
1117 vk.cmdSetEvent(*primCmdBuf, *event,stageMask);
1119 VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
1121 const VkFenceCreateInfo fenceCreateInfo =
1123 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
1128 // create fence to wait for execution of queue
1129 const Unique<VkFence> fence (createFence(vk, vkDevice, &fenceCreateInfo));
1131 const VkSubmitInfo submitInfo =
1133 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
1135 0u, // waitSemaphoreCount
1136 DE_NULL, // pWaitSemaphores
1137 // TODO: The following field is in api spec 1.0 37bedec32143807010323f126ad685ab5e9d98de
1138 // TODO: but not in the header Loader and Tools 69d4893b673bd552e445ba999ad0e73463d35007
1139 // DE_NULL, // pWaitDstStageMask
1140 1, // commandBufferCount
1141 &primCmdBuf.get(), // pCommandBuffers
1142 0u, // signalSemaphoreCount
1143 DE_NULL, // pSignalSemaphores
1146 // submit primary buffer
1147 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
1149 // wait for end of execution of queue
1150 VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
1151 VK_CHECK(vk.resetFences(vkDevice, 1u, &fence.get()));
1152 // check if buffer has been executed
1153 VkResult result = vk.getEventStatus(vkDevice,*event);
1154 if (result != VK_EVENT_SET)
1155 return tcu::TestStatus::fail("Submit Twice Test FAILED");
1158 VK_CHECK(vk.resetEvent(vkDevice, *event));
1160 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
1162 // wait for end of execution of queue
1163 VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
1165 // check if buffer has been executed
1166 result = vk.getEventStatus(vkDevice,*event);
1167 if (result != VK_EVENT_SET)
1168 return tcu::TestStatus::fail("Submit Twice Test FAILED");
1170 return tcu::TestStatus::pass("Submit Twice Test succeeded");
1173 tcu::TestStatus submitSecondaryBufferTwiceTest(Context& context)
1176 const VkDevice vkDevice = context.getDevice();
1177 const DeviceInterface& vk = context.getDeviceInterface();
1178 const VkQueue queue = context.getUniversalQueue();
1179 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
1181 const VkCommandPoolCreateInfo cmdPoolParams =
1183 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
1184 DE_NULL, // const void* pNext;
1185 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags;
1186 queueFamilyIndex, // deUint32 queueFamilyIndex;
1189 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
1192 const VkCommandBufferAllocateInfo cmdBufParams =
1194 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
1195 DE_NULL, // const void* pNext;
1196 *cmdPool, // VkCommandPool pool;
1197 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
1198 1u, // uint32_t bufferCount;
1201 const Unique<VkCommandBuffer> primCmdBuf1 (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
1202 const Unique<VkCommandBuffer> primCmdBuf2 (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
1204 // Secondary Command buffer
1205 const VkCommandBufferAllocateInfo secCmdBufParams =
1207 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
1208 DE_NULL, // const void* pNext;
1209 *cmdPool, // VkCommandPool pool;
1210 VK_COMMAND_BUFFER_LEVEL_SECONDARY, // VkCommandBufferLevel level;
1211 1u, // uint32_t bufferCount;
1213 const Unique<VkCommandBuffer> secCmdBuf (allocateCommandBuffer(vk, vkDevice, &secCmdBufParams));
1215 const VkCommandBufferBeginInfo primCmdBufBeginInfo =
1217 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
1220 (VkRenderPass)0u, // renderPass
1222 (VkFramebuffer)0u, // framebuffer
1223 VK_FALSE, // occlusionQueryEnable
1224 (VkQueryControlFlags)0u, // queryFlags
1225 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
1228 const VkCommandBufferBeginInfo secCmdBufBeginInfo =
1230 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
1233 (VkRenderPass)0u, // renderPass
1235 (VkFramebuffer)0u, // framebuffer
1236 VK_FALSE, // occlusionQueryEnable
1237 (VkQueryControlFlags)0u, // queryFlags
1238 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
1241 // Fill create info struct for event
1242 const VkEventCreateInfo eventCreateInfo =
1244 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
1249 // create event that will be used to check if secondary command buffer has been executed
1250 const Unique<VkEvent> event (createEvent(vk, vkDevice, &eventCreateInfo));
1253 VK_CHECK(vk.resetEvent(vkDevice, *event));
1255 // record first primary command buffer
1256 VK_CHECK(vk.beginCommandBuffer(*primCmdBuf1, &primCmdBufBeginInfo));
1258 // record secondary command buffer
1259 VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo));
1261 // allow execution of event during every stage of pipeline
1262 VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1264 // record setting event
1265 vk.cmdSetEvent(*secCmdBuf, *event,stageMask);
1268 // end recording of secondary buffers
1269 VK_CHECK(vk.endCommandBuffer(*secCmdBuf));
1271 // execute secondary buffer
1272 vk.cmdExecuteCommands(*primCmdBuf1, 1, &secCmdBuf.get());
1274 VK_CHECK(vk.endCommandBuffer(*primCmdBuf1));
1276 const VkFenceCreateInfo fenceCreateInfo =
1278 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
1283 // create fence to wait for execution of queue
1284 const Unique<VkFence> fence (createFence(vk, vkDevice, &fenceCreateInfo));
1286 const VkSubmitInfo submitInfo1 =
1288 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
1290 0u, // waitSemaphoreCount
1291 DE_NULL, // pWaitSemaphores
1292 // TODO: The following field is in api spec 1.0 37bedec32143807010323f126ad685ab5e9d98de
1293 // TODO: but not in the header Loader and Tools 69d4893b673bd552e445ba999ad0e73463d35007
1294 // DE_NULL, // pWaitDstStageMask
1295 1, // commandBufferCount
1296 &primCmdBuf1.get(), // pCommandBuffers
1297 0u, // signalSemaphoreCount
1298 DE_NULL, // pSignalSemaphores
1301 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo1, *fence));
1303 // wait for end of execution of queue
1304 VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
1305 VK_CHECK(vk.resetFences(vkDevice, 1u, &fence.get()));
1307 // check if secondary buffer has been executed
1308 VkResult result = vk.getEventStatus(vkDevice,*event);
1309 if (result != VK_EVENT_SET)
1310 return tcu::TestStatus::fail("Submit Twice Secondary Command Buffer FAILED");
1312 // reset first primary buffer
1313 vk.resetCommandBuffer( *primCmdBuf1, 0u);
1315 // reset event to allow receiving it again
1316 VK_CHECK(vk.resetEvent(vkDevice, *event));
1318 // record second primary command buffer
1319 VK_CHECK(vk.beginCommandBuffer(*primCmdBuf2, &primCmdBufBeginInfo));
1321 // execute secondary buffer
1322 vk.cmdExecuteCommands(*primCmdBuf2, 1, &secCmdBuf.get());
1325 VK_CHECK(vk.endCommandBuffer(*primCmdBuf2));
1327 // submit second primary buffer, the secondary should be executed too
1328 const VkSubmitInfo submitInfo2 =
1330 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
1332 0u, // waitSemaphoreCount
1333 DE_NULL, // pWaitSemaphores
1334 // TODO: The following field is in api spec 1.0 37bedec32143807010323f126ad685ab5e9d98de
1335 // TODO: but not in the header Loader and Tools 69d4893b673bd552e445ba999ad0e73463d35007
1336 // DE_NULL, // pWaitDstStageMask
1337 1, // commandBufferCount
1338 &primCmdBuf2.get(), // pCommandBuffers
1339 0u, // signalSemaphoreCount
1340 DE_NULL, // pSignalSemaphores
1342 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo2, *fence));
1344 // wait for end of execution of queue
1345 VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
1347 // check if secondary buffer has been executed
1348 result = vk.getEventStatus(vkDevice,*event);
1349 if (result != VK_EVENT_SET)
1350 return tcu::TestStatus::fail("Submit Twice Secondary Command Buffer FAILED");
1352 return tcu::TestStatus::pass("Submit Twice Secondary Command Buffer succeeded");
1355 tcu::TestStatus oneTimeSubmitFlagPrimaryBufferTest(Context& context)
1358 const VkDevice vkDevice = context.getDevice();
1359 const DeviceInterface& vk = context.getDeviceInterface();
1360 const VkQueue queue = context.getUniversalQueue();
1361 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
1363 const VkCommandPoolCreateInfo cmdPoolParams =
1365 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
1366 DE_NULL, // const void* pNext;
1367 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags;
1368 queueFamilyIndex, // deUint32 queueFamilyIndex;
1370 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
1373 const VkCommandBufferAllocateInfo cmdBufParams =
1375 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
1376 DE_NULL, // const void* pNext;
1377 *cmdPool, // VkCommandPool pool;
1378 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
1379 1u, // uint32_t bufferCount;
1381 const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
1382 const VkCommandBufferBeginInfo primCmdBufBeginInfo =
1384 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
1386 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // flags
1387 (VkRenderPass)0u, // renderPass
1389 (VkFramebuffer)0u, // framebuffer
1390 VK_FALSE, // occlusionQueryEnable
1391 (VkQueryControlFlags)0u, // queryFlags
1392 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
1395 // Fill create info struct for event
1396 const VkEventCreateInfo eventCreateInfo =
1398 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
1403 // create event that will be used to check if secondary command buffer has been executed
1404 const Unique<VkEvent> event (createEvent(vk, vkDevice, &eventCreateInfo));
1407 VK_CHECK(vk.resetEvent(vkDevice, *event));
1409 // record primary command buffer
1410 VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
1412 // allow execution of event during every stage of pipeline
1413 VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1415 // record setting event
1416 vk.cmdSetEvent(*primCmdBuf, *event,stageMask);
1418 VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
1420 const VkFenceCreateInfo fenceCreateInfo =
1422 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
1427 // create fence to wait for execution of queue
1428 const Unique<VkFence> fence (createFence(vk, vkDevice, &fenceCreateInfo));
1430 const VkSubmitInfo submitInfo =
1432 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
1434 0u, // waitSemaphoreCount
1435 DE_NULL, // pWaitSemaphores
1436 // TODO: The following field is in api spec 1.0 37bedec32143807010323f126ad685ab5e9d98de
1437 // TODO: but not in the header Loader and Tools 69d4893b673bd552e445ba999ad0e73463d35007
1438 // DE_NULL, // pWaitDstStageMask
1439 1, // commandBufferCount
1440 &primCmdBuf.get(), // pCommandBuffers
1441 0u, // signalSemaphoreCount
1442 DE_NULL, // pSignalSemaphores
1445 // submit primary buffer
1446 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
1448 // wait for end of execution of queue
1449 VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
1450 VK_CHECK(vk.resetFences(vkDevice, 1u, &fence.get()));
1452 // check if buffer has been executed
1453 VkResult result = vk.getEventStatus(vkDevice,*event);
1454 if (result != VK_EVENT_SET)
1455 return tcu::TestStatus::fail("oneTimeSubmitFlagPrimaryBufferTest FAILED");
1457 // record primary command buffer again - implicit reset because of VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT
1458 VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
1460 // allow execution of event during every stage of pipeline
1461 VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1463 // record setting event
1464 vk.cmdSetEvent(*primCmdBuf, *event,stageMask);
1466 VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
1469 VK_CHECK(vk.resetEvent(vkDevice, *event));
1471 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
1473 // wait for end of execution of queue
1474 VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
1476 // check if buffer has been executed
1477 result = vk.getEventStatus(vkDevice,*event);
1478 if (result != VK_EVENT_SET)
1479 return tcu::TestStatus::fail("oneTimeSubmitFlagPrimaryBufferTest FAILED");
1481 return tcu::TestStatus::pass("oneTimeSubmitFlagPrimaryBufferTest succeeded");
1484 tcu::TestStatus oneTimeSubmitFlagSecondaryBufferTest(Context& context)
1487 const VkDevice vkDevice = context.getDevice();
1488 const DeviceInterface& vk = context.getDeviceInterface();
1489 const VkQueue queue = context.getUniversalQueue();
1490 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
1492 const VkCommandPoolCreateInfo cmdPoolParams =
1494 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
1495 DE_NULL, // const void* pNext;
1496 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags;
1497 queueFamilyIndex, // deUint32 queueFamilyIndex;
1500 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
1503 const VkCommandBufferAllocateInfo cmdBufParams =
1505 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
1506 DE_NULL, // const void* pNext;
1507 *cmdPool, // VkCommandPool pool;
1508 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
1509 1u, // uint32_t bufferCount;
1512 const Unique<VkCommandBuffer> primCmdBuf1 (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
1513 const Unique<VkCommandBuffer> primCmdBuf2 (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
1515 // Secondary Command buffer
1516 const VkCommandBufferAllocateInfo secCmdBufParams =
1518 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
1519 DE_NULL, // const void* pNext;
1520 *cmdPool, // VkCommandPool pool;
1521 VK_COMMAND_BUFFER_LEVEL_SECONDARY, // VkCommandBufferLevel level;
1522 1u, // uint32_t bufferCount;
1524 const Unique<VkCommandBuffer> secCmdBuf (allocateCommandBuffer(vk, vkDevice, &secCmdBufParams));
1526 const VkCommandBufferBeginInfo primCmdBufBeginInfo =
1528 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
1531 (VkRenderPass)0u, // renderPass
1533 (VkFramebuffer)0u, // framebuffer
1534 VK_FALSE, // occlusionQueryEnable
1535 (VkQueryControlFlags)0u, // queryFlags
1536 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
1539 const VkCommandBufferBeginInfo secCmdBufBeginInfo =
1541 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
1543 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // flags
1544 (VkRenderPass)0u, // renderPass
1546 (VkFramebuffer)0u, // framebuffer
1547 VK_FALSE, // occlusionQueryEnable
1548 (VkQueryControlFlags)0u, // queryFlags
1549 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
1552 // Fill create info struct for event
1553 const VkEventCreateInfo eventCreateInfo =
1555 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
1560 // create event that will be used to check if secondary command buffer has been executed
1561 const Unique<VkEvent> event (createEvent(vk, vkDevice, &eventCreateInfo));
1564 VK_CHECK(vk.resetEvent(vkDevice, *event));
1566 // record first primary command buffer
1567 VK_CHECK(vk.beginCommandBuffer(*primCmdBuf1, &primCmdBufBeginInfo));
1569 // record secondary command buffer
1570 VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo));
1572 // allow execution of event during every stage of pipeline
1573 VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1575 // record setting event
1576 vk.cmdSetEvent(*secCmdBuf, *event,stageMask);
1579 // end recording of secondary buffers
1580 VK_CHECK(vk.endCommandBuffer(*secCmdBuf));
1582 // execute secondary buffer
1583 vk.cmdExecuteCommands(*primCmdBuf1, 1, &secCmdBuf.get());
1585 VK_CHECK(vk.endCommandBuffer(*primCmdBuf1));
1587 const VkFenceCreateInfo fenceCreateInfo =
1589 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
1594 // create fence to wait for execution of queue
1595 const Unique<VkFence> fence (createFence(vk, vkDevice, &fenceCreateInfo));
1597 const VkSubmitInfo submitInfo1 =
1599 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
1601 0u, // waitSemaphoreCount
1602 DE_NULL, // pWaitSemaphores
1603 // TODO: The following field is in api spec 1.0 37bedec32143807010323f126ad685ab5e9d98de
1604 // TODO: but not in the header Loader and Tools 69d4893b673bd552e445ba999ad0e73463d35007
1605 // DE_NULL, // pWaitDstStageMask
1606 1, // commandBufferCount
1607 &primCmdBuf1.get(), // pCommandBuffers
1608 0u, // signalSemaphoreCount
1609 DE_NULL, // pSignalSemaphores
1612 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo1, *fence));
1614 // wait for end of execution of queue
1615 VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
1616 VK_CHECK(vk.resetFences(vkDevice, 1u, &fence.get()));
1618 // check if secondary buffer has been executed
1619 VkResult result = vk.getEventStatus(vkDevice,*event);
1620 if (result != VK_EVENT_SET)
1621 return tcu::TestStatus::fail("Submit Twice Secondary Command Buffer FAILED");
1623 // reset first primary buffer
1624 vk.resetCommandBuffer( *primCmdBuf1, 0u);
1626 // reset event to allow receiving it again
1627 VK_CHECK(vk.resetEvent(vkDevice, *event));
1629 // record secondary command buffer again
1630 VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo));
1632 // allow execution of event during every stage of pipeline
1633 VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1635 // record setting event
1636 vk.cmdSetEvent(*secCmdBuf, *event,stageMask);
1638 // end recording of secondary buffers
1639 VK_CHECK(vk.endCommandBuffer(*secCmdBuf));
1641 // record second primary command buffer
1642 VK_CHECK(vk.beginCommandBuffer(*primCmdBuf2, &primCmdBufBeginInfo));
1644 // execute secondary buffer
1645 vk.cmdExecuteCommands(*primCmdBuf2, 1, &secCmdBuf.get());
1648 VK_CHECK(vk.endCommandBuffer(*primCmdBuf2));
1650 // submit second primary buffer, the secondary should be executed too
1651 const VkSubmitInfo submitInfo2 =
1653 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
1655 0u, // waitSemaphoreCount
1656 DE_NULL, // pWaitSemaphores
1657 // TODO: The following field is in api spec 1.0 37bedec32143807010323f126ad685ab5e9d98de
1658 // TODO: but not in the header Loader and Tools 69d4893b673bd552e445ba999ad0e73463d35007
1659 // DE_NULL, // pWaitDstStageMask
1660 1, // commandBufferCount
1661 &primCmdBuf2.get(), // pCommandBuffers
1662 0u, // signalSemaphoreCount
1663 DE_NULL, // pSignalSemaphores
1665 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo2, *fence));
1667 // wait for end of execution of queue
1668 VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
1670 // check if secondary buffer has been executed
1671 result = vk.getEventStatus(vkDevice,*event);
1672 if (result != VK_EVENT_SET)
1673 return tcu::TestStatus::fail("oneTimeSubmitFlagSecondaryBufferTest FAILED");
1675 return tcu::TestStatus::pass("oneTimeSubmitFlagSecondaryBufferTest succeeded");
1678 tcu::TestStatus simultaneousUsePrimaryBufferTest(Context& context)
1681 const VkDevice vkDevice = context.getDevice();
1682 const DeviceInterface& vk = context.getDeviceInterface();
1683 const VkQueue queue = context.getUniversalQueue();
1684 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
1686 const VkCommandPoolCreateInfo cmdPoolParams =
1688 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
1689 DE_NULL, // const void* pNext;
1690 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags;
1691 queueFamilyIndex, // deUint32 queueFamilyIndex;
1693 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
1696 const VkCommandBufferAllocateInfo cmdBufParams =
1698 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
1699 DE_NULL, // const void* pNext;
1700 *cmdPool, // VkCommandPool pool;
1701 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
1702 1u, // uint32_t bufferCount;
1704 const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
1705 const VkCommandBufferBeginInfo primCmdBufBeginInfo =
1707 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
1709 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, // flags
1710 (VkRenderPass)0u, // renderPass
1712 (VkFramebuffer)0u, // framebuffer
1713 VK_FALSE, // occlusionQueryEnable
1714 (VkQueryControlFlags)0u, // queryFlags
1715 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
1718 // Fill create info struct for event
1719 const VkEventCreateInfo eventCreateInfo =
1721 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
1726 // create event that will be used to check if secondary command buffer has been executed
1727 const Unique<VkEvent> eventOne (createEvent(vk, vkDevice, &eventCreateInfo));
1728 const Unique<VkEvent> eventTwo (createEvent(vk, vkDevice, &eventCreateInfo));
1731 VK_CHECK(vk.resetEvent(vkDevice, *eventOne));
1733 // record primary command buffer
1734 VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
1736 // allow execution of event during every stage of pipeline
1737 VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1740 vk.cmdWaitEvents(*primCmdBuf, 1u, &eventOne.get(), stageMask, stageMask, 0u, DE_NULL);
1742 // Set the second event
1743 vk.cmdSetEvent(*primCmdBuf, eventTwo.get(), stageMask);
1745 VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
1747 const VkFenceCreateInfo fenceCreateInfo =
1749 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
1754 // create fence to wait for execution of queue
1755 const Unique<VkFence> fence1 (createFence(vk, vkDevice, &fenceCreateInfo));
1756 const Unique<VkFence> fence2 (createFence(vk, vkDevice, &fenceCreateInfo));
1759 const VkSubmitInfo submitInfo =
1761 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
1763 0u, // waitSemaphoreCount
1764 DE_NULL, // pWaitSemaphores
1765 // TODO: The following field is in api spec 1.0 37bedec32143807010323f126ad685ab5e9d98de
1766 // TODO: but not in the header Loader and Tools 69d4893b673bd552e445ba999ad0e73463d35007
1767 // DE_NULL, // pWaitDstStageMask
1768 1, // commandBufferCount
1769 &primCmdBuf.get(), // pCommandBuffers
1770 0u, // signalSemaphoreCount
1771 DE_NULL, // pSignalSemaphores
1774 // submit first buffer
1775 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence1));
1777 // submit second buffer
1778 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence2));
1780 // wait for both buffer to stop at event for 100 microseconds
1781 vk.waitForFences(vkDevice, 1, &fence1.get(), 0u, 100000);
1782 vk.waitForFences(vkDevice, 1, &fence2.get(), 0u, 100000);
1785 VK_CHECK(vk.setEvent(vkDevice, *eventOne));
1787 // wait for end of execution of the first buffer
1788 VK_CHECK(vk.waitForFences(vkDevice, 1, &fence1.get(), 0u, INFINITE_TIMEOUT));
1789 // wait for end of execution of the second buffer
1790 VK_CHECK(vk.waitForFences(vkDevice, 1, &fence2.get(), 0u, INFINITE_TIMEOUT));
1792 // TODO: this will be true if the command buffer was executed only once
1793 // TODO: add some test that will say if it was executed twice
1795 // check if buffer has been executed
1796 VkResult result = vk.getEventStatus(vkDevice, *eventTwo);
1797 if (result == VK_EVENT_SET)
1798 return tcu::TestStatus::pass("simultaneous use - primary buffers test succeeded");
1800 return tcu::TestStatus::fail("simultaneous use - primary buffers test FAILED");
1803 tcu::TestStatus simultaneousUseSecondaryBufferTest(Context& context)
1805 const VkDevice vkDevice = context.getDevice();
1806 const DeviceInterface& vk = context.getDeviceInterface();
1807 const VkQueue queue = context.getUniversalQueue();
1808 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
1810 const VkCommandPoolCreateInfo cmdPoolParams =
1812 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
1813 DE_NULL, // const void* pNext;
1814 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags;
1815 queueFamilyIndex, // deUint32 queueFamilyIndex;
1817 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
1820 const VkCommandBufferAllocateInfo cmdBufParams =
1822 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
1823 DE_NULL, // const void* pNext;
1824 *cmdPool, // VkCommandPool pool;
1825 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
1826 1u, // uint32_t bufferCount;
1828 const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
1830 // Secondary Command buffer params
1831 const VkCommandBufferAllocateInfo secCmdBufParams =
1833 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
1834 DE_NULL, // const void* pNext;
1835 *cmdPool, // VkCommandPool pool;
1836 VK_COMMAND_BUFFER_LEVEL_SECONDARY, // VkCommandBufferLevel level;
1837 1u, // uint32_t bufferCount;
1839 const Unique<VkCommandBuffer> secCmdBuf (allocateCommandBuffer(vk, vkDevice, &secCmdBufParams));
1841 const VkCommandBufferBeginInfo primCmdBufBeginInfo =
1843 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
1846 (VkRenderPass)0u, // renderPass
1848 (VkFramebuffer)0u, // framebuffer
1849 VK_FALSE, // occlusionQueryEnable
1850 (VkQueryControlFlags)0u, // queryFlags
1851 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
1854 const VkCommandBufferBeginInfo secCmdBufBeginInfo =
1856 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
1858 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, // flags
1859 (VkRenderPass)0u, // renderPass
1861 (VkFramebuffer)0u, // framebuffer
1862 VK_FALSE, // occlusionQueryEnable
1863 (VkQueryControlFlags)0u, // queryFlags
1864 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
1867 // Fill create info struct for event
1868 const VkEventCreateInfo eventCreateInfo =
1870 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
1875 // create event that will be used to check if secondary command buffer has been executed
1876 const Unique<VkEvent> eventOne (createEvent(vk, vkDevice, &eventCreateInfo));
1877 const Unique<VkEvent> eventTwo (createEvent(vk, vkDevice, &eventCreateInfo));
1880 VK_CHECK(vk.resetEvent(vkDevice, *eventOne));
1881 VK_CHECK(vk.resetEvent(vkDevice, *eventTwo));
1883 // record secondary command buffer
1884 VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo));
1886 // allow execution of event during every stage of pipeline
1887 VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1890 vk.cmdWaitEvents(*secCmdBuf, 1, &eventOne.get(), stageMask, stageMask, 0, DE_NULL);
1893 vk.cmdSetEvent(*secCmdBuf, *eventTwo, stageMask);
1895 // end recording of secondary buffers
1896 VK_CHECK(vk.endCommandBuffer(*secCmdBuf));
1898 // record primary command buffer
1899 VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
1901 // execute secondary buffer
1902 vk.cmdExecuteCommands(*primCmdBuf, 1, &secCmdBuf.get());
1904 VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
1906 const VkFenceCreateInfo fenceCreateInfo =
1908 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
1913 // create fence to wait for execution of queue
1914 const Unique<VkFence> fence (createFence(vk, vkDevice, &fenceCreateInfo));
1916 const VkSubmitInfo submitInfo =
1918 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
1920 0u, // waitSemaphoreCount
1921 DE_NULL, // pWaitSemaphores
1922 // TODO: The following field is in api spec 1.0 37bedec32143807010323f126ad685ab5e9d98de
1923 // TODO: but not in the header Loader and Tools 69d4893b673bd552e445ba999ad0e73463d35007
1924 // DE_NULL, // pWaitDstStageMask
1925 1, // commandBufferCount
1926 &primCmdBuf.get(), // pCommandBuffers
1927 0u, // signalSemaphoreCount
1928 DE_NULL, // pSignalSemaphores
1931 // submit primary buffer, the secondary should be executed too
1932 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
1934 // wait for both buffers to stop at event for 100 microseconds
1935 vk.waitForFences(vkDevice, 1, &fence.get(), 0u, 100000);
1938 VK_CHECK(vk.setEvent(vkDevice, *eventOne));
1940 // wait for end of execution of queue
1941 VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
1943 // TODO: this will be true if the command buffer was executed only once
1944 // TODO: add some test that will say if it was executed twice
1946 // check if secondary buffer has been executed
1947 VkResult result = vk.getEventStatus(vkDevice,*eventTwo);
1948 if (result == VK_EVENT_SET)
1949 return tcu::TestStatus::pass("Simulatous Secondary Command Buffer Execution succeeded");
1951 return tcu::TestStatus::fail("Simulatous Secondary Command Buffer Execution FAILED");
1954 tcu::TestStatus recordBufferQueryPreciseWithFlagTest(Context& context)
1956 const VkDevice vkDevice = context.getDevice();
1957 const DeviceInterface& vk = context.getDeviceInterface();
1958 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
1960 const VkCommandPoolCreateInfo cmdPoolParams =
1962 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType;
1964 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags;
1965 queueFamilyIndex, // queueFamilyIndex;
1967 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
1970 const VkCommandBufferAllocateInfo primCmdBufParams =
1972 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType;
1975 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level;
1978 const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &primCmdBufParams));
1980 // Secondary Command buffer params
1981 const VkCommandBufferAllocateInfo secCmdBufParams =
1983 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType;
1986 VK_COMMAND_BUFFER_LEVEL_SECONDARY, // level;
1989 const Unique<VkCommandBuffer> secCmdBuf (allocateCommandBuffer(vk, vkDevice, &secCmdBufParams));
1991 const VkCommandBufferBeginInfo primBufferBeginInfo =
1993 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType
1999 DE_FALSE, // occlusionQueryEnable
2001 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
2004 const VkCommandBufferBeginInfo secBufferBeginInfo =
2006 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType
2012 VK_TRUE, // occlusionQueryEnable
2013 VK_QUERY_CONTROL_PRECISE_BIT, // queryFlags
2014 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
2017 // Create an occlusion query with VK_QUERY_CONTROL_PRECISE_BIT set
2018 const VkQueryPoolCreateInfo queryPoolCreateInfo =
2020 VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO, // sType
2022 VK_QUERY_CONTROL_PRECISE_BIT, // flags
2023 VK_QUERY_TYPE_OCCLUSION, // queryType
2025 0u, // pipelineStatistics
2027 Unique<VkQueryPool> queryPool (createQueryPool(vk, vkDevice, &queryPoolCreateInfo));
2029 VK_CHECK(vk.beginCommandBuffer(secCmdBuf.get(), &secBufferBeginInfo));
2030 VK_CHECK(vk.endCommandBuffer(secCmdBuf.get()));
2032 VK_CHECK(vk.beginCommandBuffer(primCmdBuf.get(), &primBufferBeginInfo));
2034 vk.cmdBeginQuery(primCmdBuf.get(), queryPool.get(), 1u, VK_QUERY_CONTROL_PRECISE_BIT);
2036 vk.cmdExecuteCommands(primCmdBuf.get(), 1u, &secCmdBuf.get());
2038 vk.cmdEndQuery(primCmdBuf.get(), queryPool.get(), 1u);
2040 VK_CHECK(vk.endCommandBuffer(primCmdBuf.get()));
2042 return tcu::TestStatus::pass("Successfully recorded a secondary command buffer allowing a precise occlusion query.");
2045 tcu::TestStatus recordBufferQueryImpreciseWithFlagTest(Context& context)
2047 const VkDevice vkDevice = context.getDevice();
2048 const DeviceInterface& vk = context.getDeviceInterface();
2049 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
2051 const VkCommandPoolCreateInfo cmdPoolParams =
2053 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType;
2055 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags;
2056 queueFamilyIndex, // queueFamilyIndex;
2058 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
2061 const VkCommandBufferAllocateInfo primCmdBufParams =
2063 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType;
2066 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level;
2069 const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &primCmdBufParams));
2071 // Secondary Command buffer params
2072 const VkCommandBufferAllocateInfo secCmdBufParams =
2074 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType;
2077 VK_COMMAND_BUFFER_LEVEL_SECONDARY, // level;
2080 const Unique<VkCommandBuffer> secCmdBuf (allocateCommandBuffer(vk, vkDevice, &secCmdBufParams));
2082 const VkCommandBufferBeginInfo primBufferBeginInfo =
2084 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType
2090 DE_FALSE, // occlusionQueryEnable
2092 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
2095 const VkCommandBufferBeginInfo secBufferBeginInfo =
2097 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType
2103 VK_TRUE, // occlusionQueryEnable
2104 VK_QUERY_CONTROL_PRECISE_BIT, // queryFlags
2105 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
2108 // Create an occlusion query with VK_QUERY_CONTROL_PRECISE_BIT set
2109 const VkQueryPoolCreateInfo queryPoolCreateInfo =
2111 VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO, // sType
2114 VK_QUERY_TYPE_OCCLUSION, // queryType
2116 0u, // pipelineStatistics
2118 Unique<VkQueryPool> queryPool (createQueryPool(vk, vkDevice, &queryPoolCreateInfo));
2120 VK_CHECK(vk.beginCommandBuffer(secCmdBuf.get(), &secBufferBeginInfo));
2121 VK_CHECK(vk.endCommandBuffer(secCmdBuf.get()));
2123 VK_CHECK(vk.beginCommandBuffer(primCmdBuf.get(), &primBufferBeginInfo));
2125 vk.cmdBeginQuery(primCmdBuf.get(), queryPool.get(), 1u, VK_QUERY_CONTROL_PRECISE_BIT);
2127 vk.cmdExecuteCommands(primCmdBuf.get(), 1u, &secCmdBuf.get());
2129 vk.cmdEndQuery(primCmdBuf.get(), queryPool.get(), 1u);
2131 VK_CHECK(vk.endCommandBuffer(primCmdBuf.get()));
2133 return tcu::TestStatus::pass("Successfully recorded a secondary command buffer allowing a precise occlusion query.");
2136 tcu::TestStatus recordBufferQueryImpreciseWithoutFlagTest(Context& context)
2138 const VkDevice vkDevice = context.getDevice();
2139 const DeviceInterface& vk = context.getDeviceInterface();
2140 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
2142 const VkCommandPoolCreateInfo cmdPoolParams =
2144 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType;
2146 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags;
2147 queueFamilyIndex, // queueFamilyIndex;
2149 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
2152 const VkCommandBufferAllocateInfo primCmdBufParams =
2154 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType;
2157 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level;
2160 const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &primCmdBufParams));
2162 // Secondary Command buffer params
2163 const VkCommandBufferAllocateInfo secCmdBufParams =
2165 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType;
2168 VK_COMMAND_BUFFER_LEVEL_SECONDARY, // level;
2171 const Unique<VkCommandBuffer> secCmdBuf (allocateCommandBuffer(vk, vkDevice, &secCmdBufParams));
2173 const VkCommandBufferBeginInfo primBufferBeginInfo =
2175 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType
2181 VK_TRUE, // occlusionQueryEnable
2183 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
2186 const VkCommandBufferBeginInfo secBufferBeginInfo =
2188 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType
2194 VK_TRUE, // occlusionQueryEnable
2196 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
2199 // Create an occlusion query with VK_QUERY_CONTROL_PRECISE_BIT set
2200 const VkQueryPoolCreateInfo queryPoolCreateInfo =
2202 VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO, // sType
2204 (VkQueryPoolCreateFlags)0,
2205 VK_QUERY_TYPE_OCCLUSION,
2209 Unique<VkQueryPool> queryPool (createQueryPool(vk, vkDevice, &queryPoolCreateInfo));
2211 VK_CHECK(vk.beginCommandBuffer(secCmdBuf.get(), &secBufferBeginInfo));
2212 VK_CHECK(vk.endCommandBuffer(secCmdBuf.get()));
2214 VK_CHECK(vk.beginCommandBuffer(primCmdBuf.get(), &primBufferBeginInfo));
2216 vk.cmdBeginQuery(primCmdBuf.get(), queryPool.get(), 1u, VK_QUERY_CONTROL_PRECISE_BIT);
2218 vk.cmdExecuteCommands(primCmdBuf.get(), 1u, &secCmdBuf.get());
2220 vk.cmdEndQuery(primCmdBuf.get(), queryPool.get(), 1u);
2222 VK_CHECK(vk.endCommandBuffer(primCmdBuf.get()));
2224 return tcu::TestStatus::pass("Successfully recorded a secondary command buffer allowing a precise occlusion query.");
2227 /******** 19.4. Command Buffer Submission (6.4 in VK 1.0 Spec) ****************/
2228 tcu::TestStatus submitBufferCountNonZero(Context& context)
2230 const VkDevice vkDevice = context.getDevice();
2231 const DeviceInterface& vk = context.getDeviceInterface();
2232 const VkQueue queue = context.getUniversalQueue();
2233 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
2235 const deUint32 BUFFER_COUNT = 5u;
2237 const VkCommandPoolCreateInfo cmdPoolParams =
2239 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType;
2242 queueFamilyIndex, // queueFamilyIndex;
2244 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
2247 const VkCommandBufferAllocateInfo cmdBufParams =
2249 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType;
2252 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level;
2253 BUFFER_COUNT, // bufferCount;
2255 VkCommandBuffer cmdBuffers[BUFFER_COUNT];
2256 VK_CHECK(vk.allocateCommandBuffers(vkDevice, &cmdBufParams, cmdBuffers));
2258 const VkCommandBufferBeginInfo cmdBufBeginInfo =
2260 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType
2263 DE_NULL, // renderPass
2265 DE_NULL, // framebuffer
2266 VK_FALSE, // occlusionQueryEnable
2267 (VkQueryControlFlags)0u, // queryFlags
2268 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
2271 const VkEventCreateInfo eventCreateInfo =
2273 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO, // sType;
2277 VkEvent events[BUFFER_COUNT];
2278 for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx)
2279 VK_CHECK(vk.createEvent(vkDevice, &eventCreateInfo, DE_NULL, &events[ndx]));
2281 // Record the command buffers
2282 for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx)
2284 VK_CHECK(vk.beginCommandBuffer(cmdBuffers[ndx], &cmdBufBeginInfo));
2286 vk.cmdSetEvent(cmdBuffers[ndx], events[ndx], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
2288 VK_CHECK(vk.endCommandBuffer(cmdBuffers[ndx]));
2291 // We'll use a fence to wait for the execution of the queue
2292 const VkFenceCreateInfo fenceCreateInfo =
2294 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // sType;
2298 const Unique<VkFence> fence (createFence(vk, vkDevice, &fenceCreateInfo));
2300 const VkSubmitInfo submitInfo =
2302 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
2304 0u, // waitSemaphoreCount
2305 DE_NULL, // pWaitSemaphores
2306 // TODO: The following field is in api spec 1.0 37bedec32143807010323f126ad685ab5e9d98de
2307 // TODO: but not in the header Loader and Tools 69d4893b673bd552e445ba999ad0e73463d35007
2308 // DE_NULL, // pWaitDstStageMask
2309 BUFFER_COUNT, // commandBufferCount
2310 cmdBuffers, // pCommandBuffers
2311 0u, // signalSemaphoreCount
2312 DE_NULL, // pSignalSemaphores
2315 // Submit the alpha command buffer to the queue
2316 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, fence.get()));
2317 // Wait for the queue
2318 VK_CHECK(vk.waitForFences(vkDevice, 1u, &fence.get(), VK_TRUE, INFINITE_TIMEOUT));
2320 // Check if the buffers were executed
2321 for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx)
2322 if (vk.getEventStatus(vkDevice, events[ndx]) != VK_EVENT_SET)
2323 return tcu::TestStatus::fail("Failed to set the event.");
2325 return tcu::TestStatus::pass("All buffers were submitted and executed correctly.");
2328 tcu::TestStatus submitBufferCountEqualZero(Context& context)
2330 const VkDevice vkDevice = context.getDevice();
2331 const DeviceInterface& vk = context.getDeviceInterface();
2332 const VkQueue queue = context.getUniversalQueue();
2333 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
2335 const deUint32 BUFFER_COUNT = 2u;
2337 const VkCommandPoolCreateInfo cmdPoolParams =
2339 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType;
2342 queueFamilyIndex, // queueFamilyIndex;
2344 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
2347 const VkCommandBufferAllocateInfo cmdBufParams =
2349 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType;
2352 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level;
2353 BUFFER_COUNT, // bufferCount;
2355 VkCommandBuffer cmdBuffers[BUFFER_COUNT];
2356 VK_CHECK(vk.allocateCommandBuffers(vkDevice, &cmdBufParams, cmdBuffers));
2358 const VkCommandBufferBeginInfo cmdBufBeginInfo =
2360 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType
2363 DE_NULL, // renderPass
2365 DE_NULL, // framebuffer
2366 VK_FALSE, // occlusionQueryEnable
2367 (VkQueryControlFlags)0u, // queryFlags
2368 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
2371 const VkEventCreateInfo eventCreateInfo =
2373 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO, // sType;
2377 VkEvent events[BUFFER_COUNT];
2378 for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx)
2379 VK_CHECK(vk.createEvent(vkDevice, &eventCreateInfo, DE_NULL, &events[ndx]));
2381 // Record the command buffers
2382 for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx)
2384 VK_CHECK(vk.beginCommandBuffer(cmdBuffers[ndx], &cmdBufBeginInfo));
2386 vk.cmdSetEvent(cmdBuffers[ndx], events[ndx], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
2388 VK_CHECK(vk.endCommandBuffer(cmdBuffers[ndx]));
2391 // We'll use a fence to wait for the execution of the queue
2392 const VkFenceCreateInfo fenceCreateInfo =
2394 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // sType;
2398 const Unique<VkFence> fenceZero (createFence(vk, vkDevice, &fenceCreateInfo));
2399 const Unique<VkFence> fenceOne (createFence(vk, vkDevice, &fenceCreateInfo));
2401 const VkSubmitInfo submitInfoCountZero =
2403 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
2405 0u, // waitSemaphoreCount
2406 DE_NULL, // pWaitSemaphores
2407 // TODO: The following field is in api spec 1.0 37bedec32143807010323f126ad685ab5e9d98de
2408 // TODO: but not in the header Loader and Tools 69d4893b673bd552e445ba999ad0e73463d35007
2409 // DE_NULL, // pWaitDstStageMask
2410 1u, // commandBufferCount
2411 &cmdBuffers[0], // pCommandBuffers
2412 0u, // signalSemaphoreCount
2413 DE_NULL, // pSignalSemaphores
2416 const VkSubmitInfo submitInfoCountOne =
2418 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
2420 0u, // waitSemaphoreCount
2421 DE_NULL, // pWaitSemaphores
2422 1u, // commandBufferCount
2423 &cmdBuffers[1], // pCommandBuffers
2424 0u, // signalSemaphoreCount
2425 DE_NULL, // pSignalSemaphores
2428 // Submit the command buffers to the queue
2429 // We're performing two submits to make sure that the first one has
2430 // a chance to be processed before we check the event's status
2431 VK_CHECK(vk.queueSubmit(queue, 0, &submitInfoCountZero, fenceZero.get()));
2432 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfoCountOne, fenceOne.get()));
2434 const VkFence fences[] =
2440 // Wait for the queue
2441 VK_CHECK(vk.waitForFences(vkDevice, (deUint32)DE_LENGTH_OF_ARRAY(fences), fences, VK_TRUE, INFINITE_TIMEOUT));
2443 // Check if the first buffer was executed
2444 if (vk.getEventStatus(vkDevice, events[0]) == VK_EVENT_SET)
2445 return tcu::TestStatus::fail("The first event was signaled.");
2447 return tcu::TestStatus::pass("The first submission was ignored.");
2450 tcu::TestStatus submitBufferNullFence(Context& context)
2452 const VkDevice vkDevice = context.getDevice();
2453 const DeviceInterface& vk = context.getDeviceInterface();
2454 const VkQueue queue = context.getUniversalQueue();
2455 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
2457 const short BUFFER_COUNT = 2;
2459 const VkCommandPoolCreateInfo cmdPoolParams =
2461 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType;
2464 queueFamilyIndex, // queueFamilyIndex;
2466 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
2469 const VkCommandBufferAllocateInfo cmdBufParams =
2471 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType;
2474 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level;
2477 VkCommandBuffer cmdBuffers[BUFFER_COUNT];
2478 for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx)
2479 VK_CHECK(vk.allocateCommandBuffers(vkDevice, &cmdBufParams, &cmdBuffers[ndx]));
2481 const VkCommandBufferBeginInfo cmdBufBeginInfo =
2483 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType
2486 DE_NULL, // renderPass
2488 DE_NULL, // framebuffer
2489 VK_FALSE, // occlusionQueryEnable
2490 (VkQueryControlFlags)0u, // queryFlags
2491 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
2494 const VkEventCreateInfo eventCreateInfo =
2496 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO, // sType;
2500 VkEvent events[BUFFER_COUNT];
2501 for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx)
2502 VK_CHECK(vk.createEvent(vkDevice, &eventCreateInfo, DE_NULL, &events[ndx]));
2504 // Record the command buffers
2505 for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx)
2507 VK_CHECK(vk.beginCommandBuffer(cmdBuffers[ndx], &cmdBufBeginInfo));
2509 vk.cmdSetEvent(cmdBuffers[ndx], events[ndx], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
2511 VK_CHECK(vk.endCommandBuffer(cmdBuffers[ndx]));
2514 // We'll use a fence to wait for the execution of the queue
2515 const VkFenceCreateInfo fenceCreateInfo =
2517 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // sType;
2521 const Unique<VkFence> fence (createFence(vk, vkDevice, &fenceCreateInfo));
2523 const VkSubmitInfo submitInfoNullFence =
2525 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
2527 0u, // waitSemaphoreCount
2528 DE_NULL, // pWaitSemaphores
2529 // TODO: The following field is in api spec 1.0 37bedec32143807010323f126ad685ab5e9d98de
2530 // TODO: but not in the header Loader and Tools 69d4893b673bd552e445ba999ad0e73463d35007
2531 // DE_NULL, // pWaitDstStageMask
2532 1u, // commandBufferCount
2533 &cmdBuffers[0], // pCommandBuffers
2534 0u, // signalSemaphoreCount
2535 DE_NULL, // pSignalSemaphores
2538 const VkSubmitInfo submitInfoNonNullFence =
2540 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
2542 0u, // waitSemaphoreCount
2543 DE_NULL, // pWaitSemaphores
2544 // TODO: The following field is in api spec 1.0 37bedec32143807010323f126ad685ab5e9d98de
2545 // TODO: but not in the header Loader and Tools 69d4893b673bd552e445ba999ad0e73463d35007
2546 // DE_NULL, // pWaitDstStageMask
2547 1u, // commandBufferCount
2548 &cmdBuffers[1], // pCommandBuffers
2549 0u, // signalSemaphoreCount
2550 DE_NULL, // pSignalSemaphores
2553 // Perform two submissions - one with no fence, the other one with a valid
2554 // fence Hoping submitting the other buffer will give the first one time to
2556 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfoNullFence, DE_NULL));
2557 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfoNonNullFence, fence.get()));
2559 // Wait for the queue
2560 VK_CHECK(vk.waitForFences(vkDevice, 1u, &fence.get(), VK_TRUE, INFINITE_TIMEOUT));
2562 if (vk.getEventStatus(vkDevice, events[0]) != VK_EVENT_SET)
2563 return tcu::TestStatus::fail("The first event was not signaled -> the buffer was not executed.");
2565 return tcu::TestStatus::pass("The first event was signaled -> the buffer with null fence submitted and executed correctly.");
2568 /******** 19.5. Secondary Command Buffer Execution (6.6 in VK 1.0 Spec) *******/
2569 tcu::TestStatus executeSecondaryBufferTest(Context& context)
2571 const VkDevice vkDevice = context.getDevice();
2572 const DeviceInterface& vk = context.getDeviceInterface();
2573 const VkQueue queue = context.getUniversalQueue();
2574 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
2576 const VkCommandPoolCreateInfo cmdPoolParams =
2578 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType;
2580 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags;
2581 queueFamilyIndex, // queueFamilyIndex;
2583 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
2586 const VkCommandBufferAllocateInfo cmdBufParams =
2588 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType;
2590 *cmdPool, // commandPool;
2591 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level;
2594 const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
2596 // Secondary Command buffer
2597 const VkCommandBufferAllocateInfo secCmdBufParams =
2599 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType;
2601 *cmdPool, // commandPool;
2602 VK_COMMAND_BUFFER_LEVEL_SECONDARY, // level;
2605 const Unique<VkCommandBuffer> secCmdBuf (allocateCommandBuffer(vk, vkDevice, &secCmdBufParams));
2607 const VkCommandBufferBeginInfo primCmdBufBeginInfo =
2609 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType
2612 DE_NULL, // renderPass
2614 DE_NULL, // framebuffer
2615 VK_FALSE, // occlusionQueryEnable
2616 (VkQueryControlFlags)0u, // queryFlags
2617 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
2620 const VkCommandBufferBeginInfo secCmdBufBeginInfo =
2622 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType
2625 DE_NULL, // renderPass
2627 DE_NULL, // framebuffer
2628 VK_FALSE, // occlusionQueryEnable
2629 (VkQueryControlFlags)0u, // queryFlags
2630 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
2633 // Fill create info struct for event
2634 const VkEventCreateInfo eventCreateInfo =
2636 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
2641 // create event that will be used to check if secondary command buffer has been executed
2642 const Unique<VkEvent> event (createEvent(vk, vkDevice, &eventCreateInfo));
2645 VK_CHECK(vk.resetEvent(vkDevice, *event));
2647 // record secondary command buffer
2648 VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo));
2650 // allow execution of event during every stage of pipeline
2651 VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
2652 // record setting event
2653 vk.cmdSetEvent(*secCmdBuf, *event, stageMask);
2655 // end recording of the secondary buffer
2656 VK_CHECK(vk.endCommandBuffer(*secCmdBuf));
2658 // record primary command buffer
2659 VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
2661 // execute secondary buffer
2662 vk.cmdExecuteCommands(*primCmdBuf, 1u, &secCmdBuf.get());
2664 VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
2666 const VkFenceCreateInfo fenceCreateInfo =
2668 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
2673 // create fence to wait for execution of queue
2674 const Unique<VkFence> fence (createFence(vk, vkDevice, &fenceCreateInfo));
2675 const VkSubmitInfo submitInfo =
2677 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
2679 0u, // waitSemaphoreCount
2680 DE_NULL, // pWaitSemaphores
2681 // TODO: The following field is in api spec 1.0 37bedec32143807010323f126ad685ab5e9d98de
2682 // TODO: but not in the header Loader and Tools 69d4893b673bd552e445ba999ad0e73463d35007
2683 // DE_NULL, // pWaitDstStageMask
2684 1u, // commandBufferCount
2685 &primCmdBuf.get(), // pCommandBuffers
2686 0u, // signalSemaphoreCount
2687 DE_NULL, // pSignalSemaphores
2690 // submit primary buffer, the secondary should be executed too
2691 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, fence.get()));
2693 // wait for end of execution of queue
2694 VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
2696 // check if secondary buffer has been executed
2697 VkResult result = vk.getEventStatus(vkDevice, *event);
2698 if (result == VK_EVENT_SET)
2699 return tcu::TestStatus::pass("executeSecondaryBufferTest succeeded");
2701 return tcu::TestStatus::fail("executeSecondaryBufferTest FAILED");
2704 tcu::TestStatus executeSecondaryBufferTwiceTest(Context& context)
2706 const deUint32 BUFFER_COUNT = 10u;
2707 const VkDevice vkDevice = context.getDevice();
2708 const DeviceInterface& vk = context.getDeviceInterface();
2709 const VkQueue queue = context.getUniversalQueue();
2710 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
2712 const VkCommandPoolCreateInfo cmdPoolParams =
2714 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
2715 DE_NULL, // const void* pNext;
2716 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags;
2717 queueFamilyIndex, // deUint32 queueFamilyIndex;
2719 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
2722 const VkCommandBufferAllocateInfo cmdBufParams =
2724 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
2725 DE_NULL, // const void* pNext;
2726 *cmdPool, // VkCommandPool pool;
2727 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
2728 1u, // uint32_t bufferCount;
2730 const Unique<VkCommandBuffer> primCmdBufOne (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
2731 const Unique<VkCommandBuffer> primCmdBufTwo (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
2733 // Secondary Command buffers params
2734 const VkCommandBufferAllocateInfo secCmdBufParams =
2736 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
2737 DE_NULL, // const void* pNext;
2738 *cmdPool, // VkCommandPool pool;
2739 VK_COMMAND_BUFFER_LEVEL_SECONDARY, // VkCommandBufferLevel level;
2740 BUFFER_COUNT, // uint32_t bufferCount;
2742 VkCommandBuffer cmdBuffers[BUFFER_COUNT];
2743 VK_CHECK(vk.allocateCommandBuffers(vkDevice, &secCmdBufParams, cmdBuffers));
2745 const VkCommandBufferBeginInfo primCmdBufBeginInfo =
2747 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
2750 (VkRenderPass)0u, // renderPass
2752 (VkFramebuffer)0u, // framebuffer
2753 VK_FALSE, // occlusionQueryEnable
2754 (VkQueryControlFlags)0u, // queryFlags
2755 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
2758 const VkCommandBufferBeginInfo secCmdBufBeginInfo =
2760 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
2762 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, // flags
2763 (VkRenderPass)0u, // renderPass
2765 (VkFramebuffer)0u, // framebuffer
2766 VK_FALSE, // occlusionQueryEnable
2767 (VkQueryControlFlags)0u, // queryFlags
2768 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
2771 // Fill create info struct for event
2772 const VkEventCreateInfo eventCreateInfo =
2774 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
2779 // create event that will be used to check if secondary command buffer has been executed
2780 const Unique<VkEvent> eventOne (createEvent(vk, vkDevice, &eventCreateInfo));
2783 VK_CHECK(vk.resetEvent(vkDevice, *eventOne));
2785 for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx)
2787 // record secondary command buffer
2788 VK_CHECK(vk.beginCommandBuffer(cmdBuffers[ndx], &secCmdBufBeginInfo));
2790 // allow execution of event during every stage of pipeline
2791 VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
2794 vk.cmdWaitEvents(cmdBuffers[ndx], 1, &eventOne.get(), stageMask, stageMask, 0, DE_NULL);
2796 // end recording of secondary buffers
2797 VK_CHECK(vk.endCommandBuffer(cmdBuffers[ndx]));
2800 // record primary command buffer one
2801 VK_CHECK(vk.beginCommandBuffer(*primCmdBufOne, &primCmdBufBeginInfo));
2803 // execute one secondary buffer
2804 vk.cmdExecuteCommands(*primCmdBufOne, 1, cmdBuffers );
2806 VK_CHECK(vk.endCommandBuffer(*primCmdBufOne));
2808 // record primary command buffer two
2809 VK_CHECK(vk.beginCommandBuffer(*primCmdBufTwo, &primCmdBufBeginInfo));
2811 // execute one secondary buffer with all buffers
2812 vk.cmdExecuteCommands(*primCmdBufTwo, BUFFER_COUNT, cmdBuffers );
2814 VK_CHECK(vk.endCommandBuffer(*primCmdBufTwo));
2816 const VkFenceCreateInfo fenceCreateInfo =
2818 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
2823 // create fence to wait for execution of queue
2824 const Unique<VkFence> fenceOne (createFence(vk, vkDevice, &fenceCreateInfo));
2825 const Unique<VkFence> fenceTwo (createFence(vk, vkDevice, &fenceCreateInfo));
2827 const VkSubmitInfo submitInfoOne =
2829 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
2831 0u, // waitSemaphoreCount
2832 DE_NULL, // pWaitSemaphores
2833 // TODO: The following field is in api spec 1.0 37bedec32143807010323f126ad685ab5e9d98de
2834 // TODO: but not in the header Loader and Tools 69d4893b673bd552e445ba999ad0e73463d35007
2835 // DE_NULL, // pWaitDstStageMask
2836 1, // commandBufferCount
2837 &primCmdBufOne.get(), // pCommandBuffers
2838 0u, // signalSemaphoreCount
2839 DE_NULL, // pSignalSemaphores
2842 // submit primary buffer, the secondary should be executed too
2843 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfoOne, *fenceOne));
2845 // wait for buffer to stop at event for 100 microseconds
2846 vk.waitForFences(vkDevice, 1, &fenceOne.get(), 0u, 100000);
2848 const VkSubmitInfo submitInfoTwo =
2850 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
2852 0u, // waitSemaphoreCount
2853 DE_NULL, // pWaitSemaphores
2854 // TODO: The following field is in api spec 1.0 37bedec32143807010323f126ad685ab5e9d98de
2855 // TODO: but not in the header Loader and Tools 69d4893b673bd552e445ba999ad0e73463d35007
2856 // DE_NULL, // pWaitDstStageMask
2857 1, // commandBufferCount
2858 &primCmdBufTwo.get(), // pCommandBuffers
2859 0u, // signalSemaphoreCount
2860 DE_NULL, // pSignalSemaphores
2863 // submit second primary buffer, the secondary should be executed too
2864 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfoTwo, *fenceTwo));
2866 // wait for all buffers to stop at event for 100 microseconds
2867 vk.waitForFences(vkDevice, 1, &fenceOne.get(), 0u, 100000);
2869 // now all buffers are waiting at eventOne
2870 // set event eventOne
2871 VK_CHECK(vk.setEvent(vkDevice, *eventOne));
2873 // wait for end of execution of fenceOne
2874 VK_CHECK(vk.waitForFences(vkDevice, 1, &fenceOne.get(), 0u, INFINITE_TIMEOUT));
2876 // wait for end of execution of second queue
2877 VK_CHECK(vk.waitForFences(vkDevice, 1, &fenceTwo.get(), 0u, INFINITE_TIMEOUT));
2879 return tcu::TestStatus::pass("executeSecondaryBufferTwiceTest succeeded");
2882 /******** 19.6. Commands Allowed Inside Command Buffers (6.7 in VK 1.0 Spec) **/
2883 tcu::TestStatus orderBindPipelineTest(Context& context)
2885 const DeviceInterface& vk = context.getDeviceInterface();
2886 const VkDevice device = context.getDevice();
2887 const VkQueue queue = context.getUniversalQueue();
2888 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
2889 Allocator& allocator = context.getDefaultAllocator();
2890 const ComputeInstanceResultBuffer result (vk, device, allocator);
2894 ADDRESSABLE_SIZE = 256, // allocate a lot more than required
2897 const tcu::Vec4 colorA1 = tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f);
2898 const tcu::Vec4 colorA2 = tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f);
2899 const tcu::Vec4 colorB1 = tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f);
2900 const tcu::Vec4 colorB2 = tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f);
2902 const deUint32 dataOffsetA = (0u);
2903 const deUint32 dataOffsetB = (0u);
2904 const deUint32 viewOffsetA = (0u);
2905 const deUint32 viewOffsetB = (0u);
2906 const deUint32 bufferSizeA = dataOffsetA + ADDRESSABLE_SIZE;
2907 const deUint32 bufferSizeB = dataOffsetB + ADDRESSABLE_SIZE;
2909 de::MovePtr<Allocation> bufferMemA;
2910 const Unique<VkBuffer> bufferA (createColorDataBuffer(dataOffsetA, bufferSizeA, colorA1, colorA2, &bufferMemA, context));
2912 de::MovePtr<Allocation> bufferMemB;
2913 const Unique<VkBuffer> bufferB (createColorDataBuffer(dataOffsetB, bufferSizeB, colorB1, colorB2, &bufferMemB, context));
2915 const Unique<VkDescriptorSetLayout> descriptorSetLayout (createDescriptorSetLayout(context));
2916 const Unique<VkDescriptorPool> descriptorPool (createDescriptorPool(context));
2917 const Unique<VkDescriptorSet> descriptorSet (createDescriptorSet(*descriptorPool, *descriptorSetLayout, *bufferA, viewOffsetA, *bufferB, viewOffsetB, result.getBuffer(), context));
2918 const VkDescriptorSet descriptorSets[] = { *descriptorSet };
2919 const int numDescriptorSets = DE_LENGTH_OF_ARRAY(descriptorSets);
2921 const VkPipelineLayoutCreateInfo layoutCreateInfo =
2923 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // sType
2925 (VkPipelineLayoutCreateFlags)0,
2926 numDescriptorSets, // setLayoutCount
2927 &descriptorSetLayout.get(), // pSetLayouts
2928 0u, // pushConstantRangeCount
2929 DE_NULL, // pPushConstantRanges
2931 Unique<VkPipelineLayout> pipelineLayout (createPipelineLayout(vk, device, &layoutCreateInfo));
2933 const Unique<VkShaderModule> computeModuleGood (createShaderModule(vk, device, context.getBinaryCollection().get("compute_good"), (VkShaderModuleCreateFlags)0u));
2934 const Unique<VkShaderModule> computeModuleBad (createShaderModule(vk, device, context.getBinaryCollection().get("compute_bad"), (VkShaderModuleCreateFlags)0u));
2936 const VkPipelineShaderStageCreateInfo shaderCreateInfoGood =
2938 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
2940 (VkPipelineShaderStageCreateFlags)0,
2941 VK_SHADER_STAGE_COMPUTE_BIT, // stage
2942 *computeModuleGood, // shader
2944 DE_NULL, // pSpecializationInfo
2947 const VkPipelineShaderStageCreateInfo shaderCreateInfoBad =
2949 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
2951 (vk::VkPipelineShaderStageCreateFlags)0,
2952 vk::VK_SHADER_STAGE_COMPUTE_BIT, // stage
2953 *computeModuleBad, // shader
2955 DE_NULL, // pSpecializationInfo
2958 const VkComputePipelineCreateInfo createInfoGood =
2960 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
2963 shaderCreateInfoGood, // cs
2964 *pipelineLayout, // layout
2965 (vk::VkPipeline)0, // basePipelineHandle
2966 0u, // basePipelineIndex
2969 const VkComputePipelineCreateInfo createInfoBad =
2971 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
2974 shaderCreateInfoBad, // cs
2975 *pipelineLayout, // descriptorSetLayout.get()
2976 (VkPipeline)0, // basePipelineHandle
2977 0u, // basePipelineIndex
2980 const Unique<VkPipeline> pipelineGood (createComputePipeline(vk, device, (VkPipelineCache)0u, &createInfoGood));
2981 const Unique<VkPipeline> pipelineBad (createComputePipeline(vk, device, (VkPipelineCache)0u, &createInfoBad));
2983 const VkAccessFlags inputBit = (VK_ACCESS_UNIFORM_READ_BIT);
2984 const VkBufferMemoryBarrier bufferBarrierA =
2986 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
2988 VK_ACCESS_HOST_WRITE_BIT, // outputMask
2989 inputBit, // inputMask
2990 VK_QUEUE_FAMILY_IGNORED, // srcQueueFamilyIndex
2991 VK_QUEUE_FAMILY_IGNORED, // destQueueFamilyIndex
2993 (VkDeviceSize)0u, // offset
2994 (VkDeviceSize)bufferSizeA, // size
2997 const VkBufferMemoryBarrier bufferBarrierB =
2999 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
3001 VK_ACCESS_HOST_WRITE_BIT, // outputMask
3002 inputBit, // inputMask
3003 VK_QUEUE_FAMILY_IGNORED, // srcQueueFamilyIndex
3004 VK_QUEUE_FAMILY_IGNORED, // destQueueFamilyIndex
3006 (VkDeviceSize)0u, // offset
3007 (VkDeviceSize)bufferSizeB, // size
3010 const deUint32 numSrcBuffers = 1u;
3012 const deUint32* const dynamicOffsets = (DE_NULL);
3013 const deUint32 numDynamicOffsets = (0);
3014 const void* const preBarriers[] = { &bufferBarrierA, &bufferBarrierB };
3015 const int numPreBarriers = numSrcBuffers;
3016 const void* const postBarriers[] = { result.getResultReadBarrier() };
3017 const int numPostBarriers = DE_LENGTH_OF_ARRAY(postBarriers);
3018 const tcu::Vec4 refQuadrantValue14 = (colorA2);
3019 const tcu::Vec4 refQuadrantValue23 = (colorA1);
3020 const tcu::Vec4 references[4] =
3027 tcu::Vec4 results[4];
3029 // submit and wait begin
3031 const tcu::UVec3 numWorkGroups = tcu::UVec3(4, 1u, 1);
3033 const VkCommandPoolCreateInfo cmdPoolCreateInfo =
3035 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType;
3037 VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, // flags
3038 queueFamilyIndex, // queueFamilyIndex
3040 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, device, &cmdPoolCreateInfo));
3042 const VkFenceCreateInfo fenceCreateInfo =
3044 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
3049 const VkCommandBufferAllocateInfo cmdBufCreateInfo =
3051 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType
3053 *cmdPool, // commandPool
3054 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level
3058 const VkCommandBufferBeginInfo cmdBufBeginInfo =
3060 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType
3063 DE_NULL, // renderPass
3065 DE_NULL, // framebuffer
3066 VK_FALSE, // occlusionQueryEnable
3067 (VkQueryControlFlags)0u, // queryFlags
3068 (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics
3071 const Unique<VkFence> cmdCompleteFence (createFence(vk, device, &fenceCreateInfo));
3072 const Unique<VkCommandBuffer> cmd (allocateCommandBuffer(vk, device, &cmdBufCreateInfo));
3074 VK_CHECK(vk.beginCommandBuffer(*cmd, &cmdBufBeginInfo));
3076 vk.cmdBindPipeline(*cmd, VK_PIPELINE_BIND_POINT_COMPUTE, *pipelineBad);
3077 vk.cmdBindPipeline(*cmd, VK_PIPELINE_BIND_POINT_COMPUTE, *pipelineGood);
3078 vk.cmdBindDescriptorSets(*cmd, VK_PIPELINE_BIND_POINT_COMPUTE, *pipelineLayout, 0, numDescriptorSets, descriptorSets, numDynamicOffsets, dynamicOffsets);
3081 vk.cmdPipelineBarrier(*cmd, 0u, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_FALSE, numPreBarriers, preBarriers);
3083 vk.cmdDispatch(*cmd, numWorkGroups.x(), numWorkGroups.y(), numWorkGroups.z());
3084 vk.cmdPipelineBarrier(*cmd, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_FALSE, numPostBarriers, postBarriers);
3085 VK_CHECK(vk.endCommandBuffer(*cmd));
3088 // submit second primary buffer, the secondary should be executed too
3089 const VkSubmitInfo submitInfo =
3091 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
3093 0u, // waitSemaphoreCount
3094 DE_NULL, // pWaitSemaphores
3095 // TODO: The following field is in api spec 1.0 37bedec32143807010323f126ad685ab5e9d98de
3096 // TODO: but not in the header Loader and Tools 69d4893b673bd552e445ba999ad0e73463d35007
3097 // DE_NULL, // pWaitDstStageMask
3098 1, // commandBufferCount
3099 &cmd.get(), // pCommandBuffers
3100 0u, // signalSemaphoreCount
3101 DE_NULL, // pSignalSemaphores
3103 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *cmdCompleteFence));
3105 VK_CHECK(vk.waitForFences(device, 1u, &cmdCompleteFence.get(), 0u, INFINITE_TIMEOUT)); // \note: timeout is failure
3106 VK_CHECK(vk.resetFences(device, 1u, &cmdCompleteFence.get()));
3108 // submit and wait end
3109 result.readResultContentsTo(&results);
3112 if (results[0] == references[0] &&
3113 results[1] == references[1] &&
3114 results[2] == references[2] &&
3115 results[3] == references[3])
3117 return tcu::TestStatus::pass("Pass");
3119 else if (results[0] == tcu::Vec4(-1.0f) &&
3120 results[1] == tcu::Vec4(-1.0f) &&
3121 results[2] == tcu::Vec4(-1.0f) &&
3122 results[3] == tcu::Vec4(-1.0f))
3124 context.getTestContext().getLog()
3125 << tcu::TestLog::Message
3126 << "Result buffer was not written to."
3127 << tcu::TestLog::EndMessage;
3128 return tcu::TestStatus::fail("Result buffer was not written to");
3132 context.getTestContext().getLog()
3133 << tcu::TestLog::Message
3134 << "Error expected ["
3135 << references[0] << ", "
3136 << references[1] << ", "
3137 << references[2] << ", "
3138 << references[3] << "], got ["
3139 << results[0] << ", "
3140 << results[1] << ", "
3141 << results[2] << ", "
3142 << results[3] << "]"
3143 << tcu::TestLog::EndMessage;
3144 return tcu::TestStatus::fail("Invalid result values");
3149 void genComputeSource (SourceCollections& programCollection)
3151 const char* const versionDecl = glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
3152 std::ostringstream buf_good;
3154 buf_good << versionDecl << "\n"
3156 << "layout(local_size_x = 1u, local_size_y = 1u, local_size_z = 1) in;\n"
3157 << "layout(set = 0, binding = 1u, std140) uniform BufferName\n"
3159 << " highp vec4 colorA;\n"
3160 << " highp vec4 colorB;\n"
3161 << "} b_instance;\n"
3162 << "layout(set = 0, binding = 0, std140) writeonly buffer OutBuf\n"
3164 << " highp vec4 read_colors[4];\n"
3166 << "void main(void)\n"
3168 << " highp int quadrant_id = int(gl_WorkGroupID.x);\n"
3169 << " highp vec4 result_color;\n"
3170 << " if (quadrant_id == 1 || quadrant_id == 2)\n"
3171 << " result_color = b_instance.colorA;\n"
3173 << " result_color = b_instance.colorB;\n"
3174 << " b_out.read_colors[gl_WorkGroupID.x] = result_color;\n"
3177 programCollection.glslSources.add("compute_good") << glu::ComputeSource(buf_good.str());
3179 std::ostringstream buf_bad;
3181 buf_bad << versionDecl << "\n"
3183 << "layout(local_size_x = 1u, local_size_y = 1u, local_size_z = 1) in;\n"
3184 << "layout(set = 0, binding = 1u, std140) uniform BufferName\n"
3186 << " highp vec4 colorA;\n"
3187 << " highp vec4 colorB;\n"
3188 << "} b_instance;\n"
3189 << "layout(set = 0, binding = 0, std140) writeonly buffer OutBuf\n"
3191 << " highp vec4 read_colors[4];\n"
3193 << "void main(void)\n"
3195 << " highp int quadrant_id = int(gl_WorkGroupID.x);\n"
3196 << " highp vec4 result_color;\n"
3197 << " if (quadrant_id == 1 || quadrant_id == 2)\n"
3198 << " result_color = b_instance.colorA;\n"
3200 << " result_color = b_instance.colorB;\n"
3201 << " b_out.read_colors[gl_WorkGroupID.x] = vec4(0.0, 0.0, 0.0, 0.0);\n"
3204 programCollection.glslSources.add("compute_bad") << glu::ComputeSource(buf_bad.str());
3209 tcu::TestCaseGroup* createCommandBuffersTests (tcu::TestContext& testCtx)
3211 de::MovePtr<tcu::TestCaseGroup> commandBuffersTests (new tcu::TestCaseGroup(testCtx, "command_buffers", "Command Buffers Tests"));
3213 /* 19.1. Command Pools (6.1 in VK 1.0 Spec) */
3214 addFunctionCase (commandBuffersTests.get(), "pool_create_null_params", "", createPoolNullParamsTest);
3215 addFunctionCase (commandBuffersTests.get(), "pool_create_non_null_allocator", "", createPoolNonNullAllocatorTest);
3216 addFunctionCase (commandBuffersTests.get(), "pool_create_transient_bit", "", createPoolTransientBitTest);
3217 addFunctionCase (commandBuffersTests.get(), "pool_create_reset_bit", "", createPoolResetBitTest);
3218 addFunctionCase (commandBuffersTests.get(), "pool_reset_release_res", "", resetPoolReleaseResourcesBitTest);
3219 addFunctionCase (commandBuffersTests.get(), "pool_reset_no_flags_res", "", resetPoolNoFlagsTest);
3220 /* 19.2. Command Buffer Lifetime (6.2 in VK 1.0 Spec) */
3221 addFunctionCase (commandBuffersTests.get(), "allocate_single_primary", "", allocatePrimaryBufferTest);
3222 addFunctionCase (commandBuffersTests.get(), "allocate_many_primary", "", allocateManyPrimaryBuffersTest);
3223 addFunctionCase (commandBuffersTests.get(), "allocate_zero_primary", "", allocateZeroPrimaryBuffersTest);
3224 addFunctionCase (commandBuffersTests.get(), "allocate_single_secondary", "", allocateSecondaryBufferTest);
3225 addFunctionCase (commandBuffersTests.get(), "allocate_many_secondary", "", allocateManySecondaryBuffersTest);
3226 addFunctionCase (commandBuffersTests.get(), "allocate_zero_secondary", "", allocateZeroSecondaryBuffersTest);
3227 addFunctionCase (commandBuffersTests.get(), "execute_small_primary", "", executePrimaryBufferTest);
3228 addFunctionCase (commandBuffersTests.get(), "execute_large_primary", "", executeLargePrimaryBufferTest);
3229 addFunctionCase (commandBuffersTests.get(), "reset_implicit", "", resetBufferImplicitlyTest);
3230 /* 19.3. Command Buffer Recording (6.3 in VK 1.0 Spec) */
3231 addFunctionCase (commandBuffersTests.get(), "record_single_primary", "", recordSinglePrimaryBufferTest);
3232 addFunctionCase (commandBuffersTests.get(), "record_many_primary", "", recordLargePrimaryBufferTest);
3233 addFunctionCase (commandBuffersTests.get(), "record_single_secondary", "", recordSingleSecondaryBufferTest);
3234 addFunctionCase (commandBuffersTests.get(), "record_many_secondary", "", recordLargeSecondaryBufferTest);
3235 addFunctionCase (commandBuffersTests.get(), "submit_twice_primary", "", submitPrimaryBufferTwiceTest);
3236 addFunctionCase (commandBuffersTests.get(), "submit_twice_secondary", "", submitSecondaryBufferTwiceTest);
3237 addFunctionCase (commandBuffersTests.get(), "record_one_time_submit_primary", "", oneTimeSubmitFlagPrimaryBufferTest);
3238 addFunctionCase (commandBuffersTests.get(), "record_one_time_submit_secondary", "", oneTimeSubmitFlagSecondaryBufferTest);
3239 addFunctionCase (commandBuffersTests.get(), "record_simul_use_primary", "", simultaneousUsePrimaryBufferTest);
3240 addFunctionCase (commandBuffersTests.get(), "record_simul_use_secondary", "", simultaneousUseSecondaryBufferTest);
3241 addFunctionCase (commandBuffersTests.get(), "record_query_precise_w_flag", "", recordBufferQueryPreciseWithFlagTest);
3242 addFunctionCase (commandBuffersTests.get(), "record_query_imprecise_w_flag", "", recordBufferQueryImpreciseWithFlagTest);
3243 addFunctionCase (commandBuffersTests.get(), "record_query_imprecise_wo_flag", "", recordBufferQueryImpreciseWithoutFlagTest);
3244 /* 19.4. Command Buffer Submission (6.4 in VK 1.0 Spec) */
3245 addFunctionCase (commandBuffersTests.get(), "submit_count_non_zero", "", submitBufferCountNonZero);
3246 addFunctionCase (commandBuffersTests.get(), "submit_count_equal_zero", "", submitBufferCountEqualZero);
3247 addFunctionCase (commandBuffersTests.get(), "submit_null_fence", "", submitBufferNullFence);
3248 /* 19.5. Secondary Command Buffer Execution (6.6 in VK 1.0 Spec) */
3249 addFunctionCase (commandBuffersTests.get(), "secondary_execute", "", executeSecondaryBufferTest);
3250 addFunctionCase (commandBuffersTests.get(), "secondary_execute_twice", "", executeSecondaryBufferTwiceTest);
3251 /* 19.6. Commands Allowed Inside Command Buffers (6.7 in VK 1.0 Spec) */
3252 addFunctionCaseWithPrograms (commandBuffersTests.get(), "order_bind_pipeline", "", genComputeSource, orderBindPipelineTest);
3254 return commandBuffersTests.release();