dEQP-VK.renderpass: Set IMAGE_USAGE_TRANSFER_SRC_BIT when needed
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / api / vktApiCommandBuffersTests.cpp
1 /*-------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2015 The Khronos Group Inc.
6  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
7  * Copyright (c) 2015 Google Inc.
8  *
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:
16  *
17  * The above copyright notice(s) and this permission notice shall be
18  * included in all copies or substantial portions of the Materials.
19  *
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.
23  *
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.
31  *
32  *//*--------------------------------------------------------------------*/
33
34 #include "vkDefs.hpp"
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"
48 #include <sstream>
49
50 namespace vkt
51 {
52 namespace api
53 {
54 namespace
55 {
56
57 using namespace vk;
58
59 // Global variables
60 const deUint64                                                          INFINITE_TIMEOUT                = ~(deUint64)0u;
61
62 // Testcases
63 /********* 19.1. Command Pools (6.1 in VK 1.0 Spec) ***************************/
64 tcu::TestStatus createPoolNullParamsTest(Context& context)
65 {
66         const VkDevice                                                  vkDevice                                = context.getDevice();
67         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
68         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
69
70         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
71         {
72                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // sType;
73                 DE_NULL,                                                                                                        // pNext;
74                 0u,                                                                                                                     // flags;
75                 queueFamilyIndex,                                                                                       // queueFamilyIndex;
76         };
77         VkCommandPool cmdPool;
78
79         VK_CHECK(vk.createCommandPool(vkDevice, &cmdPoolParams, DE_NULL, &cmdPool));
80
81         return tcu::TestStatus::pass("Command Pool allocated correctly.");
82 }
83
84 tcu::TestStatus createPoolNonNullAllocatorTest(Context& context)
85 {
86         const VkDevice                                                  vkDevice                                = context.getDevice();
87         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
88         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
89         const VkAllocationCallbacks*                    allocationCallbacks             = getSystemAllocator();
90
91         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
92         {
93                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // sType;
94                 DE_NULL,                                                                                                        // pNext;
95                 0u,                                                                                                                     // flags;
96                 queueFamilyIndex,                                                                                       // queueFamilyIndex;
97         };
98         VkCommandPool cmdPool;
99
100         VK_CHECK(vk.createCommandPool(vkDevice, &cmdPoolParams, allocationCallbacks, &cmdPool));
101
102         return tcu::TestStatus::pass("Command Pool allocated correctly.");
103 }
104
105 tcu::TestStatus createPoolTransientBitTest(Context& context)
106 {
107         const VkDevice                                                  vkDevice                                = context.getDevice();
108         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
109         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
110
111         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
112         {
113                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // sType;
114                 DE_NULL,                                                                                                        // pNext;
115                 VK_COMMAND_POOL_CREATE_TRANSIENT_BIT,                                           // flags;
116                 queueFamilyIndex,                                                                                       // queueFamilyIndex;
117         };
118         VkCommandPool cmdPool;
119
120         VK_CHECK(vk.createCommandPool(vkDevice, &cmdPoolParams, DE_NULL, &cmdPool));
121
122         return tcu::TestStatus::pass("Command Pool allocated correctly.");
123 }
124
125 tcu::TestStatus createPoolResetBitTest(Context& context)
126 {
127         const VkDevice                                                  vkDevice                                = context.getDevice();
128         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
129         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
130
131         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
132         {
133                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // sType;
134                 DE_NULL,                                                                                                        // pNext;
135                 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,                        // flags;
136                 queueFamilyIndex,                                                                                       // queueFamilyIndex;
137         };
138         VkCommandPool cmdPool;
139
140         VK_CHECK(vk.createCommandPool(vkDevice, &cmdPoolParams, DE_NULL, &cmdPool));
141
142         return tcu::TestStatus::pass("Command Pool allocated correctly.");
143 }
144
145 tcu::TestStatus resetPoolReleaseResourcesBitTest(Context& context)
146 {
147         const VkDevice                                                  vkDevice                                = context.getDevice();
148         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
149         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
150
151         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
152         {
153                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // sType;
154                 DE_NULL,                                                                                                        // pNext;
155                 0u,                                                                                                                     // flags;
156                 queueFamilyIndex,                                                                                       // queueFamilyIndex;
157         };
158         VkCommandPool cmdPool;
159
160         VK_CHECK(vk.createCommandPool(vkDevice, &cmdPoolParams, DE_NULL, &cmdPool));
161         VK_CHECK(vk.resetCommandPool(vkDevice, cmdPool, VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT));
162
163         return tcu::TestStatus::pass("Command Pool allocated correctly.");
164 }
165
166 tcu::TestStatus resetPoolNoFlagsTest(Context& context)
167 {
168         const VkDevice                                                  vkDevice                                = context.getDevice();
169         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
170         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
171
172         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
173         {
174                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // sType;
175                 DE_NULL,                                                                                                        // pNext;
176                 0u,                                                                                                                     // flags;
177                 queueFamilyIndex,                                                                                       // queueFamilyIndex;
178         };
179         VkCommandPool cmdPool;
180
181         VK_CHECK(vk.createCommandPool(vkDevice, &cmdPoolParams, DE_NULL, &cmdPool));
182         VK_CHECK(vk.resetCommandPool(vkDevice, cmdPool, 0u));
183
184         return tcu::TestStatus::pass("Command Pool allocated correctly.");
185 }
186
187 /******** 19.2. Command Buffer Lifetime (6.2 in VK 1.0 Spec) ******************/
188 tcu::TestStatus allocatePrimaryBufferTest(Context& context)
189 {
190         const VkDevice                                                  vkDevice                                = context.getDevice();
191         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
192         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
193
194         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
195         {
196                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // sType;
197                 DE_NULL,                                                                                                        // pNext;
198                 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,                        // flags;
199                 queueFamilyIndex,                                                                                       // queueFamilyIndex;
200         };
201         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
202
203         // Command buffer
204         const VkCommandBufferAllocateInfo               cmdBufParams                    =
205         {
206                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,                         // sType;
207                 DE_NULL,                                                                                                        // pNext;
208                 *cmdPool,                                                                                                       // commandPool;
209                 VK_COMMAND_BUFFER_LEVEL_PRIMARY,                                                        // level;
210                 1u,                                                                                                                     // bufferCount;
211         };
212         const Unique<VkCommandBuffer>                   cmdBuf                                  (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
213
214         return tcu::TestStatus::pass("Buffer was created correctly.");
215 }
216
217 tcu::TestStatus allocateManyPrimaryBuffersTest(Context& context)
218 {
219
220         const VkDevice                                                  vkDevice                                = context.getDevice();
221         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
222         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
223
224         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
225         {
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;
230         };
231         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
232
233         // create a minimal amount of command buffers - is there any minimal amount in spec?
234         const unsigned minCommandBuffer = 10000;
235
236         // Command buffer
237         const VkCommandBufferAllocateInfo               cmdBufParams                    =
238         {
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;
244         };
245
246         // do not keep the handles to buffers, as they will be freed with command pool
247
248         // allocate the minimum required amount of buffers
249         VkCommandBuffer cmdBuffers[minCommandBuffer];
250         VK_CHECK(vk.allocateCommandBuffers(vkDevice, &cmdBufParams, cmdBuffers));
251
252         std::ostringstream out;
253         out << "allocateManyPrimaryBuffersTest succeded: created " << minCommandBuffer << " command buffers";
254
255         return tcu::TestStatus::pass(out.str());
256 }
257
258 tcu::TestStatus allocateZeroPrimaryBuffersTest(Context& context)
259 {
260         const VkDevice                                                  vkDevice                                = context.getDevice();
261         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
262         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
263
264         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
265         {
266                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // sType;
267                 DE_NULL,                                                                                                        // pNext;
268                 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,                        // flags;
269                 queueFamilyIndex,                                                                                       // queueFamilyIndex;
270         };
271         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
272
273         // Command buffer
274         const VkCommandBufferAllocateInfo               cmdBufParams                    =
275         {
276                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,                         // sType;
277                 DE_NULL,                                                                                                        // pNext;
278                 *cmdPool,                                                                                                       // commandPool;
279                 VK_COMMAND_BUFFER_LEVEL_PRIMARY,                                                        // level;
280                 0u,                                                                                                                     // bufferCount;
281         };
282
283         VkCommandBuffer cmdBuffer;
284         VK_CHECK(vk.allocateCommandBuffers(vkDevice, &cmdBufParams, &cmdBuffer));
285
286         return tcu::TestStatus::pass("allocateZeroPrimaryBuffersTest passed.");
287 }
288
289 tcu::TestStatus allocateSecondaryBufferTest(Context& context)
290 {
291         const VkDevice                                                  vkDevice                                = context.getDevice();
292         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
293         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
294
295         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
296         {
297                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // sType;
298                 DE_NULL,                                                                                                        // pNext;
299                 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,                        // flags;
300                 queueFamilyIndex,                                                                                       // queueFamilyIndex;
301         };
302         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
303
304         // Command buffer
305         const VkCommandBufferAllocateInfo               cmdBufParams                    =
306         {
307                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,                         // sType;
308                 DE_NULL,                                                                                                        // pNext;
309                 *cmdPool,                                                                                                       // commandPool;
310                 VK_COMMAND_BUFFER_LEVEL_SECONDARY,                                                      // level;
311                 1u,                                                                                                                     // bufferCount;
312         };
313         const Unique<VkCommandBuffer>                   cmdBuf                                  (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
314
315         return tcu::TestStatus::pass("Buffer was created correctly.");
316 }
317
318 tcu::TestStatus allocateManySecondaryBuffersTest(Context& context)
319 {
320
321         const VkDevice                                                  vkDevice                                = context.getDevice();
322         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
323         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
324
325         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
326         {
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;
331         };
332         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
333
334         // create a minimal amount of command buffers - is there any minimal amount in spec?
335         const unsigned minCommandBuffer = 10000;
336
337         // Command buffer
338         const VkCommandBufferAllocateInfo               cmdBufParams                    =
339         {
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;
345         };
346
347         // do not keep the handles to buffers, as they will be freed with command pool
348
349         // allocate the minimum required amount of buffers
350         VkCommandBuffer cmdBuffers[minCommandBuffer];
351         VK_CHECK(vk.allocateCommandBuffers(vkDevice, &cmdBufParams, cmdBuffers));
352
353         std::ostringstream out;
354         out << "allocateManySecondaryBuffersTest succeded: created " << minCommandBuffer << " command buffers";
355
356         return tcu::TestStatus::pass(out.str());
357 }
358
359 tcu::TestStatus allocateZeroSecondaryBuffersTest(Context& context)
360 {
361         const VkDevice                                                  vkDevice                                = context.getDevice();
362         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
363         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
364
365         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
366         {
367                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // sType;
368                 DE_NULL,                                                                                                        // pNext;
369                 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,                        // flags;
370                 queueFamilyIndex,                                                                                       // queueFamilyIndex;
371         };
372         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
373
374         // Command buffer
375         const VkCommandBufferAllocateInfo               cmdBufParams                    =
376         {
377                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,                         // sType;
378                 DE_NULL,                                                                                                        // pNext;
379                 *cmdPool,                                                                                                       // commandPool;
380                 VK_COMMAND_BUFFER_LEVEL_SECONDARY,                                                      // level;
381                 0u,                                                                                                                     // bufferCount;
382         };
383
384         VkCommandBuffer cmdBuffer;
385         VK_CHECK(vk.allocateCommandBuffers(vkDevice, &cmdBufParams, &cmdBuffer));
386
387         return tcu::TestStatus::pass("allocateZeroSecondaryBuffersTest passed.");
388 }
389
390 tcu::TestStatus executePrimaryBufferTest(Context& context)
391 {
392         const VkDevice                                                  vkDevice                                = context.getDevice();
393         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
394         const VkQueue                                                   queue                                   = context.getUniversalQueue();
395         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
396
397         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
398         {
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;
403         };
404         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
405
406         // Command buffer
407         const VkCommandBufferAllocateInfo               cmdBufParams                    =
408         {
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;
414         };
415         const Unique<VkCommandBuffer>                   primCmdBuf                              (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
416         const VkCommandBufferBeginInfo                  primCmdBufBeginInfo             =
417         {
418                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
419                 DE_NULL,
420                 0,                                                                                                                      // flags
421                 (VkRenderPass)0u,                                                                                       // renderPass
422                 0u,                                                                                                                     // subpass
423                 (VkFramebuffer)0u,                                                                                      // framebuffer
424                 VK_FALSE,                                                                                                       // occlusionQueryEnable
425                 (VkQueryControlFlags)0u,                                                                        // queryFlags
426                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
427         };
428
429         // Fill create info struct for event
430         const VkEventCreateInfo                                 eventCreateInfo                 =
431         {
432                 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
433                 DE_NULL,
434                 0u,
435         };
436
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));
439
440         // reset event
441         VK_CHECK(vk.resetEvent(vkDevice, *event));
442
443         // record primary command buffer
444         VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
445         {
446                 // allow execution of event during every stage of pipeline
447                 VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
448
449                 // record setting event
450                 vk.cmdSetEvent(*primCmdBuf, *event,stageMask);
451         }
452         VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
453
454         const VkFenceCreateInfo                                 fenceCreateInfo                 =
455         {
456                 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
457                 DE_NULL,
458                 0u,                                                                                                                     // flags
459         };
460
461         // create fence to wait for execution of queue
462         const Unique<VkFence>                                   fence                                   (createFence(vk, vkDevice, &fenceCreateInfo));
463
464         const VkSubmitInfo                                              submitInfo                              =
465         {
466                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                          // sType
467                 DE_NULL,                                                                                                        // pNext
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
477         };
478
479         // Submit the command buffer to the queue
480         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
481
482         // wait for end of execution of queue
483         VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
484
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");
489
490         return tcu::TestStatus::fail("Execute Primary Command Buffer FAILED");
491 }
492
493 tcu::TestStatus executeLargePrimaryBufferTest(Context& context)
494 {
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;
500
501         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
502         {
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;
507         };
508         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
509
510         // Command buffer
511         const VkCommandBufferAllocateInfo               cmdBufParams                    =
512         {
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;
518         };
519         const Unique<VkCommandBuffer>                   primCmdBuf                              (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
520         const VkCommandBufferBeginInfo                  primCmdBufBeginInfo             =
521         {
522                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
523                 DE_NULL,
524                 0,                                                                                                                      // flags
525                 (VkRenderPass)0u,                                                                                       // renderPass
526                 0u,                                                                                                                     // subpass
527                 (VkFramebuffer)0u,                                                                                      // framebuffer
528                 VK_FALSE,                                                                                                       // occlusionQueryEnable
529                 (VkQueryControlFlags)0u,                                                                        // queryFlags
530                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
531         };
532
533         // Fill create info struct for event
534         const VkEventCreateInfo                                 eventCreateInfo                 =
535         {
536                 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
537                 DE_NULL,
538                 0u,
539         };
540         VkEvent events[LARGE_BUFFER_SIZE];
541         for (deUint32 ndx = 0; ndx < LARGE_BUFFER_SIZE; ++ndx)
542         {
543                 VK_CHECK(vk.createEvent(vkDevice, &eventCreateInfo, DE_NULL, &events[ndx]));
544         }
545
546         // record primary command buffer
547         VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
548         {
549                 // set all the events in the array
550                 for (deUint32 ndx = 0; ndx < LARGE_BUFFER_SIZE; ++ndx)
551                 {
552                         vk.cmdSetEvent(*primCmdBuf, events[ndx], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
553                 }
554         }
555         VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
556
557         const VkFenceCreateInfo                                 fenceCreateInfo                 =
558         {
559                 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
560                 DE_NULL,
561                 0u,                                                                                                                     // flags
562         };
563
564         // create fence to wait for execution of queue
565         const Unique<VkFence>                                   fence                                   (createFence(vk, vkDevice, &fenceCreateInfo));
566
567         const VkSubmitInfo                                              submitInfo                              =
568         {
569                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                          // sType
570                 DE_NULL,                                                                                                        // pNext
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
580         };
581
582         // Submit the command buffer to the queue
583         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
584
585         // wait for end of execution of queue
586         VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
587
588         // check if the buffer was executed correctly - all events had their status
589         // changed
590         for (deUint32 ndx = 0; ndx < LARGE_BUFFER_SIZE; ++ndx)
591         {
592                 if (vk.getEventStatus(vkDevice, events[ndx]) != VK_EVENT_SET)
593                         return tcu::TestStatus::fail("An event was not set.");
594         }
595
596         return tcu::TestStatus::pass("All events set correctly.");
597 }
598
599 tcu::TestStatus resetBufferImplicitlyTest(Context& context)
600 {
601         const VkDevice                                                  vkDevice                                = context.getDevice();
602         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
603         const VkQueue                                                   queue                                   = context.getUniversalQueue();
604         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
605
606         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
607         {
608                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // sType;
609                 DE_NULL,                                                                                                        // pNext;
610                 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,                        // flags;
611                 queueFamilyIndex,                                                                                       // queueFamilyIndex;
612         };
613         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
614
615         // Command buffer
616         const VkCommandBufferAllocateInfo               cmdBufParams                    =
617         {
618                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,                         // sType;
619                 DE_NULL,                                                                                                        // pNext;
620                 *cmdPool,                                                                                                       // pool;
621                 VK_COMMAND_BUFFER_LEVEL_PRIMARY,                                                        // level;
622                 1u,                                                                                                                     // bufferCount;
623         };
624         const Unique<VkCommandBuffer>                   cmdBuf                                          (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
625
626         const VkCommandBufferBeginInfo                  cmdBufBeginInfo                 =
627         {
628                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                            // sType
629                 DE_NULL,                                                                                                        // pNext
630                 0u,                                                                                                                     // flags
631                 DE_NULL,                                                                                                        // renderPass
632                 0u,                                                                                                                     // subpass
633                 DE_NULL,                                                                                                        // framebuffer
634                 VK_FALSE,                                                                                                       // occlusionQueryEnable
635                 (VkQueryControlFlags)0u,                                                                        // queryFlags
636                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
637         };
638
639         const VkEventCreateInfo                                 eventCreateInfo                 =
640         {
641                 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,                                            // sType;
642                 DE_NULL,                                                                                                        // pNext;
643                 0u,                                                                                                                     // flags;
644         };
645         const Unique<VkEvent>                                   event                                   (createEvent(vk, vkDevice, &eventCreateInfo));
646
647         // Put the command buffer in recording state.
648         VK_CHECK(vk.beginCommandBuffer(*cmdBuf, &cmdBufBeginInfo));
649         {
650                 // Set the event
651                 vk.cmdSetEvent(*cmdBuf, *event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
652         }
653         VK_CHECK(vk.endCommandBuffer(*cmdBuf));
654
655         // We'll use a fence to wait for the execution of the queue
656         const VkFenceCreateInfo                                 fenceCreateInfo                 =
657         {
658                 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,                                            // sType;
659                 DE_NULL,                                                                                                        // pNext;
660                 0u,                                                                                                                     // flags
661         };
662         const Unique<VkFence>                                   fence                                   (createFence(vk, vkDevice, &fenceCreateInfo));
663
664         const VkSubmitInfo                                              submitInfo                              =
665         {
666                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                          // sType
667                 DE_NULL,                                                                                                        // pNext
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
677         };
678
679         // Submitting the command buffer that sets the event to the queue
680         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, fence.get()));
681
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()));
686
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.");
690
691         // Reset 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.");
695
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));
700
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));
706
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.");
710         else
711                 return tcu::TestStatus::fail("Buffer was not reset correctly.");
712 }
713
714 /******** 19.3. Command Buffer Recording (6.3 in VK 1.0 Spec) *****************/
715 tcu::TestStatus recordSinglePrimaryBufferTest(Context& context)
716 {
717         const VkDevice                                                  vkDevice                                = context.getDevice();
718         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
719         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
720
721         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
722         {
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;
727         };
728         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
729
730         // Command buffer
731         const VkCommandBufferAllocateInfo               cmdBufParams                    =
732         {
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;
738         };
739         const Unique<VkCommandBuffer>                   primCmdBuf                              (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
740
741         const VkCommandBufferBeginInfo                  primCmdBufBeginInfo             =
742         {
743                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
744                 DE_NULL,
745                 0,                                                                                                                      // flags
746                 (VkRenderPass)0u,                                                                                       // renderPass
747                 0u,                                                                                                                     // subpass
748                 (VkFramebuffer)0u,                                                                                      // framebuffer
749                 VK_FALSE,                                                                                                       // occlusionQueryEnable
750                 (VkQueryControlFlags)0u,                                                                        // queryFlags
751                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
752         };
753
754         // Fill create info struct for event
755         const VkEventCreateInfo                                 eventCreateInfo                 =
756         {
757                 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
758                 DE_NULL,
759                 0u,
760         };
761
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));
764
765         // record primary command buffer
766         VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
767         {
768                 // record setting event
769                 vk.cmdSetEvent(*primCmdBuf, *event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
770         }
771         VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
772
773         return tcu::TestStatus::pass("Primary buffer recorded successfully.");
774 }
775
776 tcu::TestStatus recordLargePrimaryBufferTest(Context &context)
777 {
778
779         const VkDevice                                                  vkDevice                                = context.getDevice();
780         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
781         const VkQueue                                                   queue                                   = context.getUniversalQueue();
782         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
783
784         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
785         {
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;
790         };
791         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
792
793         // Command buffer
794         const VkCommandBufferAllocateInfo               cmdBufParams                    =
795         {
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;
801         };
802         const Unique<VkCommandBuffer>                   primCmdBuf                              (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
803         const VkCommandBufferBeginInfo                  primCmdBufBeginInfo             =
804         {
805                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
806                 DE_NULL,
807                 0,                                                                                                                      // flags
808                 (VkRenderPass)0u,                                                                                       // renderPass
809                 0u,                                                                                                                     // subpass
810                 (VkFramebuffer)0u,                                                                                      // framebuffer
811                 VK_FALSE,                                                                                                       // occlusionQueryEnable
812                 (VkQueryControlFlags)0u,                                                                        // queryFlags
813                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
814         };
815
816         // Fill create info struct for event
817         const VkEventCreateInfo                                 eventCreateInfo                 =
818         {
819                 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
820                 DE_NULL,
821                 0u,
822         };
823
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));
826
827         // reset event
828         VK_CHECK(vk.resetEvent(vkDevice, *event));
829
830         // record primary command buffer
831         VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
832         {
833                 // allow execution of event during every stage of pipeline
834                 VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
835
836                 // define minimal amount of commands to accept
837                 const long long unsigned minNumCommands = 10000llu;
838
839                 for ( long long unsigned currentCommands = 0; currentCommands < minNumCommands / 2; ++currentCommands )
840                 {
841                         // record setting event
842                         vk.cmdSetEvent(*primCmdBuf, *event,stageMask);
843
844                         // record resetting event
845                         vk.cmdResetEvent(*primCmdBuf, *event,stageMask);
846                 };
847
848         }
849         VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
850
851         const VkFenceCreateInfo                                 fenceCreateInfo                 =
852         {
853                 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
854                 DE_NULL,
855                 0u,                                                                                                                     // flags
856         };
857
858         // create fence to wait for execution of queue
859         const Unique<VkFence>                                   fence                                   (createFence(vk, vkDevice, &fenceCreateInfo));
860
861         const VkSubmitInfo                                              submitInfo                              =
862         {
863                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                          // sType
864                 DE_NULL,                                                                                                        // pNext
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
874         };
875
876         // Submit the command buffer to the queue
877         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
878
879         // wait for end of execution of queue
880         VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
881
882         return tcu::TestStatus::pass("hugeTest succeeded");
883 }
884
885 tcu::TestStatus recordSingleSecondaryBufferTest(Context& context)
886 {
887         const VkDevice                                                  vkDevice                                = context.getDevice();
888         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
889         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
890
891         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
892         {
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;
897         };
898         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
899
900         // Command buffer
901         const VkCommandBufferAllocateInfo               cmdBufParams                    =
902         {
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;
908         };
909         const Unique<VkCommandBuffer>                   secCmdBuf                               (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
910
911         const VkCommandBufferBeginInfo                  secCmdBufBeginInfo              =
912         {
913                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
914                 DE_NULL,
915                 0,                                                                                                                      // flags
916                 (VkRenderPass)0u,                                                                                       // renderPass
917                 0u,                                                                                                                     // subpass
918                 (VkFramebuffer)0u,                                                                                      // framebuffer
919                 VK_FALSE,                                                                                                       // occlusionQueryEnable
920                 (VkQueryControlFlags)0u,                                                                        // queryFlags
921                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
922         };
923
924         // Fill create info struct for event
925         const VkEventCreateInfo                                 eventCreateInfo                 =
926         {
927                 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
928                 DE_NULL,
929                 0u,
930         };
931
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));
934
935         // record primary command buffer
936         VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo));
937         {
938                 // record setting event
939                 vk.cmdSetEvent(*secCmdBuf, *event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
940         }
941         VK_CHECK(vk.endCommandBuffer(*secCmdBuf));
942
943         return tcu::TestStatus::pass("Secondary buffer recorded successfully.");
944 }
945
946 tcu::TestStatus recordLargeSecondaryBufferTest(Context &context)
947 {
948
949         const VkDevice                                                  vkDevice                                = context.getDevice();
950         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
951         const VkQueue                                                   queue                                   = context.getUniversalQueue();
952         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
953
954         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
955         {
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;
960         };
961         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
962
963         // Command buffer
964         const VkCommandBufferAllocateInfo               cmdBufParams                    =
965         {
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;
971         };
972         const Unique<VkCommandBuffer>                   primCmdBuf                              (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
973         const VkCommandBufferBeginInfo                  primCmdBufBeginInfo             =
974         {
975                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
976                 DE_NULL,
977                 0,                                                                                                                      // flags
978                 (VkRenderPass)0u,                                                                                       // renderPass
979                 0u,                                                                                                                     // subpass
980                 (VkFramebuffer)0u,                                                                                      // framebuffer
981                 VK_FALSE,                                                                                                       // occlusionQueryEnable
982                 (VkQueryControlFlags)0u,                                                                        // queryFlags
983                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
984         };
985
986         // Fill create info struct for event
987         const VkEventCreateInfo                                 eventCreateInfo                 =
988         {
989                 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
990                 DE_NULL,
991                 0u,
992         };
993
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));
996
997         // reset event
998         VK_CHECK(vk.resetEvent(vkDevice, *event));
999
1000         // record primary command buffer
1001         VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
1002         {
1003                 // allow execution of event during every stage of pipeline
1004                 VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1005
1006                 // define minimal amount of commands to accept
1007                 const long long unsigned minNumCommands = 10000llu;
1008
1009                 for ( long long unsigned currentCommands = 0; currentCommands < minNumCommands / 2; ++currentCommands )
1010                 {
1011                         // record setting event
1012                         vk.cmdSetEvent(*primCmdBuf, *event,stageMask);
1013
1014                         // record resetting event
1015                         vk.cmdResetEvent(*primCmdBuf, *event,stageMask);
1016                 };
1017
1018
1019         }
1020         VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
1021
1022         const VkFenceCreateInfo                                 fenceCreateInfo                 =
1023         {
1024                 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
1025                 DE_NULL,
1026                 0u,                                                                                                                     // flags
1027         };
1028
1029         // create fence to wait for execution of queue
1030         const Unique<VkFence>                                   fence                                   (createFence(vk, vkDevice, &fenceCreateInfo));
1031
1032         const VkSubmitInfo                                              submitInfo                              =
1033         {
1034                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                          // sType
1035                 DE_NULL,                                                                                                        // pNext
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
1045         };
1046
1047         // Submit the command buffer to the queue
1048         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
1049
1050         // wait for end of execution of queue
1051         VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
1052
1053         return tcu::TestStatus::pass("hugeTest succeeded");
1054 }
1055
1056 tcu::TestStatus submitPrimaryBufferTwiceTest(Context& context)
1057 {
1058
1059         const VkDevice                                                  vkDevice                                = context.getDevice();
1060         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
1061         const VkQueue                                                   queue                                   = context.getUniversalQueue();
1062         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
1063
1064         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
1065         {
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;
1070         };
1071         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
1072
1073         // Command buffer
1074         const VkCommandBufferAllocateInfo               cmdBufParams                    =
1075         {
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;
1081         };
1082         const Unique<VkCommandBuffer>                   primCmdBuf                              (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
1083         const VkCommandBufferBeginInfo                  primCmdBufBeginInfo             =
1084         {
1085                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
1086                 DE_NULL,
1087                 0,                                                                                                                      // flags
1088                 (VkRenderPass)0u,                                                                                       // renderPass
1089                 0u,                                                                                                                     // subpass
1090                 (VkFramebuffer)0u,                                                                                      // framebuffer
1091                 VK_FALSE,                                                                                                       // occlusionQueryEnable
1092                 (VkQueryControlFlags)0u,                                                                        // queryFlags
1093                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
1094         };
1095
1096         // Fill create info struct for event
1097         const VkEventCreateInfo                                 eventCreateInfo                 =
1098         {
1099                 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
1100                 DE_NULL,
1101                 0u,
1102         };
1103
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));
1106
1107         // reset event
1108         VK_CHECK(vk.resetEvent(vkDevice, *event));
1109
1110         // record primary command buffer
1111         VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
1112         {
1113                 // allow execution of event during every stage of pipeline
1114                 VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1115
1116                 // record setting event
1117                 vk.cmdSetEvent(*primCmdBuf, *event,stageMask);
1118         }
1119         VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
1120
1121         const VkFenceCreateInfo                                 fenceCreateInfo                 =
1122         {
1123                 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
1124                 DE_NULL,
1125                 0u,                                                                                                                     // flags
1126         };
1127
1128         // create fence to wait for execution of queue
1129         const Unique<VkFence>                                   fence                                   (createFence(vk, vkDevice, &fenceCreateInfo));
1130
1131         const VkSubmitInfo                                              submitInfo                              =
1132         {
1133                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                          // sType
1134                 DE_NULL,                                                                                                        // pNext
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
1144         };
1145
1146         // submit primary buffer
1147         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
1148
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");
1156
1157         // reset event
1158         VK_CHECK(vk.resetEvent(vkDevice, *event));
1159
1160         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
1161
1162         // wait for end of execution of queue
1163         VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
1164
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");
1169         else
1170                 return tcu::TestStatus::pass("Submit Twice Test succeeded");
1171 }
1172
1173 tcu::TestStatus submitSecondaryBufferTwiceTest(Context& context)
1174 {
1175
1176         const VkDevice                                                  vkDevice                                = context.getDevice();
1177         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
1178         const VkQueue                                                   queue                                   = context.getUniversalQueue();
1179         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
1180
1181         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
1182         {
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;
1187         };
1188
1189         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
1190
1191         // Command buffer
1192         const VkCommandBufferAllocateInfo               cmdBufParams                    =
1193         {
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;
1199         };
1200
1201         const Unique<VkCommandBuffer>                   primCmdBuf1                             (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
1202         const Unique<VkCommandBuffer>                   primCmdBuf2                             (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
1203
1204         // Secondary Command buffer
1205         const VkCommandBufferAllocateInfo               secCmdBufParams                 =
1206         {
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;
1212         };
1213         const Unique<VkCommandBuffer>                   secCmdBuf                               (allocateCommandBuffer(vk, vkDevice, &secCmdBufParams));
1214
1215         const VkCommandBufferBeginInfo                  primCmdBufBeginInfo             =
1216         {
1217                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
1218                 DE_NULL,
1219                 0,                                                                                                                      // flags
1220                 (VkRenderPass)0u,                                                                                       // renderPass
1221                 0u,                                                                                                                     // subpass
1222                 (VkFramebuffer)0u,                                                                                      // framebuffer
1223                 VK_FALSE,                                                                                                       // occlusionQueryEnable
1224                 (VkQueryControlFlags)0u,                                                                        // queryFlags
1225                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
1226         };
1227
1228         const VkCommandBufferBeginInfo                  secCmdBufBeginInfo              =
1229         {
1230                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
1231                 DE_NULL,
1232                 0u,                                                                                                                     // flags
1233                 (VkRenderPass)0u,                                                                                       // renderPass
1234                 0u,                                                                                                                     // subpass
1235                 (VkFramebuffer)0u,                                                                                      // framebuffer
1236                 VK_FALSE,                                                                                                       // occlusionQueryEnable
1237                 (VkQueryControlFlags)0u,                                                                        // queryFlags
1238                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
1239         };
1240
1241         // Fill create info struct for event
1242         const VkEventCreateInfo                                 eventCreateInfo                 =
1243         {
1244                 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
1245                 DE_NULL,
1246                 0u,
1247         };
1248
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));
1251
1252         // reset event
1253         VK_CHECK(vk.resetEvent(vkDevice, *event));
1254
1255         // record first primary command buffer
1256         VK_CHECK(vk.beginCommandBuffer(*primCmdBuf1, &primCmdBufBeginInfo));
1257         {
1258                 // record secondary command buffer
1259                 VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo));
1260                 {
1261                         // allow execution of event during every stage of pipeline
1262                         VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1263
1264                         // record setting event
1265                         vk.cmdSetEvent(*secCmdBuf, *event,stageMask);
1266                 }
1267
1268                 // end recording of secondary buffers
1269                 VK_CHECK(vk.endCommandBuffer(*secCmdBuf));
1270
1271                 // execute secondary buffer
1272                 vk.cmdExecuteCommands(*primCmdBuf1, 1, &secCmdBuf.get());
1273         }
1274         VK_CHECK(vk.endCommandBuffer(*primCmdBuf1));
1275
1276         const VkFenceCreateInfo                                 fenceCreateInfo                 =
1277         {
1278                 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
1279                 DE_NULL,
1280                 0u,                                                                                                                     // flags
1281         };
1282
1283         // create fence to wait for execution of queue
1284         const Unique<VkFence>                                   fence                                   (createFence(vk, vkDevice, &fenceCreateInfo));
1285
1286         const VkSubmitInfo                                              submitInfo1                             =
1287         {
1288                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                          // sType
1289                 DE_NULL,                                                                                                        // pNext
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
1299         };
1300
1301         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo1, *fence));
1302
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()));
1306
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");
1311
1312         // reset first primary buffer
1313         vk.resetCommandBuffer( *primCmdBuf1, 0u);
1314
1315         // reset event to allow receiving it again
1316         VK_CHECK(vk.resetEvent(vkDevice, *event));
1317
1318         // record second primary command buffer
1319         VK_CHECK(vk.beginCommandBuffer(*primCmdBuf2, &primCmdBufBeginInfo));
1320         {
1321                 // execute secondary buffer
1322                 vk.cmdExecuteCommands(*primCmdBuf2, 1, &secCmdBuf.get());
1323         }
1324         // end recording
1325         VK_CHECK(vk.endCommandBuffer(*primCmdBuf2));
1326
1327         // submit second primary buffer, the secondary should be executed too
1328         const VkSubmitInfo                                              submitInfo2                             =
1329         {
1330                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                          // sType
1331                 DE_NULL,                                                                                                        // pNext
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
1341         };
1342         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo2, *fence));
1343
1344         // wait for end of execution of queue
1345         VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
1346
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");
1351         else
1352                 return tcu::TestStatus::pass("Submit Twice Secondary Command Buffer succeeded");
1353 }
1354
1355 tcu::TestStatus oneTimeSubmitFlagPrimaryBufferTest(Context& context)
1356 {
1357
1358         const VkDevice                                                  vkDevice                                = context.getDevice();
1359         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
1360         const VkQueue                                                   queue                                   = context.getUniversalQueue();
1361         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
1362
1363         const VkCommandPoolCreateInfo                           cmdPoolParams                   =
1364         {
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;
1369         };
1370         const Unique<VkCommandPool>                                     cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
1371
1372         // Command buffer
1373         const VkCommandBufferAllocateInfo                               cmdBufParams                    =
1374         {
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;
1380         };
1381         const Unique<VkCommandBuffer>                           primCmdBuf                              (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
1382         const VkCommandBufferBeginInfo                          primCmdBufBeginInfo             =
1383         {
1384                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
1385                 DE_NULL,
1386                 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,                            // flags
1387                 (VkRenderPass)0u,                                                                                       // renderPass
1388                 0u,                                                                                                                     // subpass
1389                 (VkFramebuffer)0u,                                                                                      // framebuffer
1390                 VK_FALSE,                                                                                                       // occlusionQueryEnable
1391                 (VkQueryControlFlags)0u,                                                                        // queryFlags
1392                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
1393         };
1394
1395         // Fill create info struct for event
1396         const VkEventCreateInfo                                 eventCreateInfo                 =
1397         {
1398                 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
1399                 DE_NULL,
1400                 0u,
1401         };
1402
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));
1405
1406         // reset event
1407         VK_CHECK(vk.resetEvent(vkDevice, *event));
1408
1409         // record primary command buffer
1410         VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
1411         {
1412                 // allow execution of event during every stage of pipeline
1413                 VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1414
1415                 // record setting event
1416                 vk.cmdSetEvent(*primCmdBuf, *event,stageMask);
1417         }
1418         VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
1419
1420         const VkFenceCreateInfo                                 fenceCreateInfo                 =
1421         {
1422                 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
1423                 DE_NULL,
1424                 0u,                                                                                                                     // flags
1425         };
1426
1427         // create fence to wait for execution of queue
1428         const Unique<VkFence>                                   fence                                   (createFence(vk, vkDevice, &fenceCreateInfo));
1429
1430         const VkSubmitInfo                                              submitInfo                              =
1431         {
1432                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                          // sType
1433                 DE_NULL,                                                                                                        // pNext
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
1443         };
1444
1445         // submit primary buffer
1446         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
1447
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()));
1451
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");
1456
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));
1459         {
1460                 // allow execution of event during every stage of pipeline
1461                 VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1462
1463                 // record setting event
1464                 vk.cmdSetEvent(*primCmdBuf, *event,stageMask);
1465         }
1466         VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
1467
1468         // reset event
1469         VK_CHECK(vk.resetEvent(vkDevice, *event));
1470
1471         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
1472
1473         // wait for end of execution of queue
1474         VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
1475
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");
1480         else
1481                 return tcu::TestStatus::pass("oneTimeSubmitFlagPrimaryBufferTest succeeded");
1482 }
1483
1484 tcu::TestStatus oneTimeSubmitFlagSecondaryBufferTest(Context& context)
1485 {
1486
1487         const VkDevice                                                  vkDevice                                = context.getDevice();
1488         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
1489         const VkQueue                                                   queue                                   = context.getUniversalQueue();
1490         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
1491
1492         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
1493         {
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;
1498         };
1499
1500         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
1501
1502         // Command buffer
1503         const VkCommandBufferAllocateInfo               cmdBufParams                    =
1504         {
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;
1510         };
1511
1512         const Unique<VkCommandBuffer>                   primCmdBuf1                             (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
1513         const Unique<VkCommandBuffer>                   primCmdBuf2                             (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
1514
1515         // Secondary Command buffer
1516         const VkCommandBufferAllocateInfo               secCmdBufParams                 =
1517         {
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;
1523         };
1524         const Unique<VkCommandBuffer>                   secCmdBuf                               (allocateCommandBuffer(vk, vkDevice, &secCmdBufParams));
1525
1526         const VkCommandBufferBeginInfo                  primCmdBufBeginInfo             =
1527         {
1528                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
1529                 DE_NULL,
1530                 0,                                                                                                                      // flags
1531                 (VkRenderPass)0u,                                                                                       // renderPass
1532                 0u,                                                                                                                     // subpass
1533                 (VkFramebuffer)0u,                                                                                      // framebuffer
1534                 VK_FALSE,                                                                                                       // occlusionQueryEnable
1535                 (VkQueryControlFlags)0u,                                                                        // queryFlags
1536                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
1537         };
1538
1539         const VkCommandBufferBeginInfo                  secCmdBufBeginInfo              =
1540         {
1541                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
1542                 DE_NULL,
1543                 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,                            // flags
1544                 (VkRenderPass)0u,                                                                                       // renderPass
1545                 0u,                                                                                                                     // subpass
1546                 (VkFramebuffer)0u,                                                                                      // framebuffer
1547                 VK_FALSE,                                                                                                       // occlusionQueryEnable
1548                 (VkQueryControlFlags)0u,                                                                        // queryFlags
1549                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
1550         };
1551
1552         // Fill create info struct for event
1553         const VkEventCreateInfo                                 eventCreateInfo                 =
1554         {
1555                 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
1556                 DE_NULL,
1557                 0u,
1558         };
1559
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));
1562
1563         // reset event
1564         VK_CHECK(vk.resetEvent(vkDevice, *event));
1565
1566         // record first primary command buffer
1567         VK_CHECK(vk.beginCommandBuffer(*primCmdBuf1, &primCmdBufBeginInfo));
1568         {
1569                 // record secondary command buffer
1570                 VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo));
1571                 {
1572                         // allow execution of event during every stage of pipeline
1573                         VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1574
1575                         // record setting event
1576                         vk.cmdSetEvent(*secCmdBuf, *event,stageMask);
1577                 }
1578
1579                 // end recording of secondary buffers
1580                 VK_CHECK(vk.endCommandBuffer(*secCmdBuf));
1581
1582                 // execute secondary buffer
1583                 vk.cmdExecuteCommands(*primCmdBuf1, 1, &secCmdBuf.get());
1584         }
1585         VK_CHECK(vk.endCommandBuffer(*primCmdBuf1));
1586
1587         const VkFenceCreateInfo                                 fenceCreateInfo                 =
1588         {
1589                 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
1590                 DE_NULL,
1591                 0u,                                                                                                                     // flags
1592         };
1593
1594         // create fence to wait for execution of queue
1595         const Unique<VkFence>                                   fence                                   (createFence(vk, vkDevice, &fenceCreateInfo));
1596
1597         const VkSubmitInfo                                              submitInfo1                             =
1598         {
1599                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                          // sType
1600                 DE_NULL,                                                                                                        // pNext
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
1610         };
1611
1612         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo1, *fence));
1613
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()));
1617
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");
1622
1623         // reset first primary buffer
1624         vk.resetCommandBuffer( *primCmdBuf1, 0u);
1625
1626         // reset event to allow receiving it again
1627         VK_CHECK(vk.resetEvent(vkDevice, *event));
1628
1629         // record secondary command buffer again
1630         VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo));
1631         {
1632                 // allow execution of event during every stage of pipeline
1633                 VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1634
1635                 // record setting event
1636                 vk.cmdSetEvent(*secCmdBuf, *event,stageMask);
1637         }
1638         // end recording of secondary buffers
1639         VK_CHECK(vk.endCommandBuffer(*secCmdBuf));
1640
1641         // record second primary command buffer
1642         VK_CHECK(vk.beginCommandBuffer(*primCmdBuf2, &primCmdBufBeginInfo));
1643         {
1644                 // execute secondary buffer
1645                 vk.cmdExecuteCommands(*primCmdBuf2, 1, &secCmdBuf.get());
1646         }
1647         // end recording
1648         VK_CHECK(vk.endCommandBuffer(*primCmdBuf2));
1649
1650         // submit second primary buffer, the secondary should be executed too
1651         const VkSubmitInfo                                              submitInfo2                             =
1652         {
1653                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                          // sType
1654                 DE_NULL,                                                                                                        // pNext
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
1664         };
1665         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo2, *fence));
1666
1667         // wait for end of execution of queue
1668         VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
1669
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");
1674         else
1675                 return tcu::TestStatus::pass("oneTimeSubmitFlagSecondaryBufferTest succeeded");
1676 }
1677
1678 tcu::TestStatus simultaneousUsePrimaryBufferTest(Context& context)
1679 {
1680
1681         const VkDevice                                                  vkDevice                                = context.getDevice();
1682         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
1683         const VkQueue                                                   queue                                   = context.getUniversalQueue();
1684         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
1685
1686         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
1687         {
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;
1692         };
1693         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
1694
1695         // Command buffer
1696         const VkCommandBufferAllocateInfo               cmdBufParams                    =
1697         {
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;
1703         };
1704         const Unique<VkCommandBuffer>                   primCmdBuf                              (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
1705         const VkCommandBufferBeginInfo                  primCmdBufBeginInfo             =
1706         {
1707                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
1708                 DE_NULL,
1709                 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT,                           // flags
1710                 (VkRenderPass)0u,                                                                                       // renderPass
1711                 0u,                                                                                                                     // subpass
1712                 (VkFramebuffer)0u,                                                                                      // framebuffer
1713                 VK_FALSE,                                                                                                       // occlusionQueryEnable
1714                 (VkQueryControlFlags)0u,                                                                        // queryFlags
1715                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
1716         };
1717
1718         // Fill create info struct for event
1719         const VkEventCreateInfo                                 eventCreateInfo                 =
1720         {
1721                 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
1722                 DE_NULL,
1723                 0u,
1724         };
1725
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));
1729
1730         // reset event
1731         VK_CHECK(vk.resetEvent(vkDevice, *eventOne));
1732
1733         // record primary command buffer
1734         VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
1735         {
1736                 // allow execution of event during every stage of pipeline
1737                 VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1738
1739                 // wait for event
1740                 vk.cmdWaitEvents(*primCmdBuf, 1u, &eventOne.get(), stageMask, stageMask, 0u, DE_NULL);
1741
1742                 // Set the second event
1743                 vk.cmdSetEvent(*primCmdBuf, eventTwo.get(), stageMask);
1744         }
1745         VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
1746
1747         const VkFenceCreateInfo                                 fenceCreateInfo                 =
1748         {
1749                 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
1750                 DE_NULL,
1751                 0u,                                                                                                                     // flags
1752         };
1753
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));
1757
1758
1759         const VkSubmitInfo                                              submitInfo                              =
1760         {
1761                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                          // sType
1762                 DE_NULL,                                                                                                        // pNext
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
1772         };
1773
1774         // submit first buffer
1775         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence1));
1776
1777         // submit second buffer
1778         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence2));
1779
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);
1783
1784         // set event
1785         VK_CHECK(vk.setEvent(vkDevice, *eventOne));
1786
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));
1791
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
1794
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");
1799         else
1800                 return tcu::TestStatus::fail("simultaneous use - primary buffers test FAILED");
1801 }
1802
1803 tcu::TestStatus simultaneousUseSecondaryBufferTest(Context& context)
1804 {
1805         const VkDevice                                                  vkDevice                                = context.getDevice();
1806         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
1807         const VkQueue                                                   queue                                   = context.getUniversalQueue();
1808         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
1809
1810         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
1811         {
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;
1816         };
1817         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
1818
1819         // Command buffer
1820         const VkCommandBufferAllocateInfo               cmdBufParams                    =
1821         {
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;
1827         };
1828         const Unique<VkCommandBuffer>                   primCmdBuf                              (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
1829
1830         // Secondary Command buffer params
1831         const VkCommandBufferAllocateInfo               secCmdBufParams                 =
1832         {
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;
1838         };
1839         const Unique<VkCommandBuffer>                   secCmdBuf                               (allocateCommandBuffer(vk, vkDevice, &secCmdBufParams));
1840
1841         const VkCommandBufferBeginInfo                  primCmdBufBeginInfo             =
1842         {
1843                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
1844                 DE_NULL,
1845                 0,                                                                                                                      // flags
1846                 (VkRenderPass)0u,                                                                                       // renderPass
1847                 0u,                                                                                                                     // subpass
1848                 (VkFramebuffer)0u,                                                                                      // framebuffer
1849                 VK_FALSE,                                                                                                       // occlusionQueryEnable
1850                 (VkQueryControlFlags)0u,                                                                        // queryFlags
1851                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
1852         };
1853
1854         const VkCommandBufferBeginInfo                  secCmdBufBeginInfo              =
1855         {
1856                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
1857                 DE_NULL,
1858                 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT,                           // flags
1859                 (VkRenderPass)0u,                                                                                       // renderPass
1860                 0u,                                                                                                                     // subpass
1861                 (VkFramebuffer)0u,                                                                                      // framebuffer
1862                 VK_FALSE,                                                                                                       // occlusionQueryEnable
1863                 (VkQueryControlFlags)0u,                                                                        // queryFlags
1864                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
1865         };
1866
1867         // Fill create info struct for event
1868         const VkEventCreateInfo                                 eventCreateInfo                 =
1869         {
1870                 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
1871                 DE_NULL,
1872                 0u,
1873         };
1874
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));
1878
1879         // reset event
1880         VK_CHECK(vk.resetEvent(vkDevice, *eventOne));
1881         VK_CHECK(vk.resetEvent(vkDevice, *eventTwo));
1882
1883         // record secondary command buffer
1884         VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo));
1885         {
1886                 // allow execution of event during every stage of pipeline
1887                 VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1888
1889                 // wait for event
1890                 vk.cmdWaitEvents(*secCmdBuf, 1, &eventOne.get(), stageMask, stageMask, 0, DE_NULL);
1891
1892                 // reset event
1893                 vk.cmdSetEvent(*secCmdBuf, *eventTwo, stageMask);
1894         }
1895         // end recording of secondary buffers
1896         VK_CHECK(vk.endCommandBuffer(*secCmdBuf));
1897
1898         // record primary command buffer
1899         VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
1900         {
1901                 // execute secondary buffer
1902                 vk.cmdExecuteCommands(*primCmdBuf, 1, &secCmdBuf.get());
1903         }
1904         VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
1905
1906         const VkFenceCreateInfo                                 fenceCreateInfo                 =
1907         {
1908                 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
1909                 DE_NULL,
1910                 0u,                                                                                                                     // flags
1911         };
1912
1913         // create fence to wait for execution of queue
1914         const Unique<VkFence>                                   fence                                   (createFence(vk, vkDevice, &fenceCreateInfo));
1915
1916         const VkSubmitInfo                                              submitInfo                              =
1917         {
1918                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                          // sType
1919                 DE_NULL,                                                                                                        // pNext
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
1929         };
1930
1931         // submit primary buffer, the secondary should be executed too
1932         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
1933
1934         // wait for both buffers to stop at event for 100 microseconds
1935         vk.waitForFences(vkDevice, 1, &fence.get(), 0u, 100000);
1936
1937         // set event
1938         VK_CHECK(vk.setEvent(vkDevice, *eventOne));
1939
1940         // wait for end of execution of queue
1941         VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
1942
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
1945
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");
1950         else
1951                 return tcu::TestStatus::fail("Simulatous Secondary Command Buffer Execution FAILED");
1952 }
1953
1954 tcu::TestStatus recordBufferQueryPreciseWithFlagTest(Context& context)
1955 {
1956         const VkDevice                                                  vkDevice                                = context.getDevice();
1957         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
1958         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
1959
1960         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
1961         {
1962                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // sType;
1963                 DE_NULL,                                                                                                        // pNext;
1964                 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,                        // flags;
1965                 queueFamilyIndex,                                                                                       // queueFamilyIndex;
1966         };
1967         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
1968
1969         // Command buffer
1970         const VkCommandBufferAllocateInfo               primCmdBufParams                =
1971         {
1972                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,                         // sType;
1973                 DE_NULL,                                                                                                        // pNext;
1974                 *cmdPool,                                                                                                       // pool;
1975                 VK_COMMAND_BUFFER_LEVEL_PRIMARY,                                                        // level;
1976                 1u,                                                                                                                     // flags;
1977         };
1978         const Unique<VkCommandBuffer>                   primCmdBuf                              (allocateCommandBuffer(vk, vkDevice, &primCmdBufParams));
1979
1980         // Secondary Command buffer params
1981         const VkCommandBufferAllocateInfo               secCmdBufParams                 =
1982         {
1983                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,                         // sType;
1984                 DE_NULL,                                                                                                        // pNext;
1985                 *cmdPool,                                                                                                       // pool;
1986                 VK_COMMAND_BUFFER_LEVEL_SECONDARY,                                                      // level;
1987                 1u,                                                                                                                     // flags;
1988         };
1989         const Unique<VkCommandBuffer>                   secCmdBuf                               (allocateCommandBuffer(vk, vkDevice, &secCmdBufParams));
1990
1991         const VkCommandBufferBeginInfo                  primBufferBeginInfo             =
1992         {
1993                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                            // sType
1994                 DE_NULL,                                                                                                        // pNext
1995                 0u,                                                                                                                     // flags
1996                 0u,                                                                                                                     // renderPass
1997                 0u,                                                                                                                     // subpass
1998                 0u,                                                                                                                     // framebuffer
1999                 DE_FALSE,                                                                                                       // occlusionQueryEnable
2000                 0u,                                                                                                                     // queryFlags
2001                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
2002         };
2003
2004         const VkCommandBufferBeginInfo                  secBufferBeginInfo              =
2005         {
2006                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                            // sType
2007                 DE_NULL,                                                                                                        // pNext
2008                 0u,                                                                                                                     // flags
2009                 0u,                                                                                                                     // renderPass
2010                 0u,                                                                                                                     // subpass
2011                 0u,                                                                                                                     // framebuffer
2012                 VK_TRUE,                                                                                                        // occlusionQueryEnable
2013                 VK_QUERY_CONTROL_PRECISE_BIT,                                                           // queryFlags
2014                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
2015         };
2016
2017         // Create an occlusion query with VK_QUERY_CONTROL_PRECISE_BIT set
2018         const VkQueryPoolCreateInfo                             queryPoolCreateInfo             =
2019         {
2020                 VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO,                                       // sType
2021                 DE_NULL,                                                                                                        // pNext
2022                 VK_QUERY_CONTROL_PRECISE_BIT,                                                           // flags
2023                 VK_QUERY_TYPE_OCCLUSION,                                                                        // queryType
2024                 1u,                                                                                                                     // entryCount
2025                 0u,                                                                                                                     // pipelineStatistics
2026         };
2027         Unique<VkQueryPool>                                             queryPool                               (createQueryPool(vk, vkDevice, &queryPoolCreateInfo));
2028
2029         VK_CHECK(vk.beginCommandBuffer(secCmdBuf.get(), &secBufferBeginInfo));
2030         VK_CHECK(vk.endCommandBuffer(secCmdBuf.get()));
2031
2032         VK_CHECK(vk.beginCommandBuffer(primCmdBuf.get(), &primBufferBeginInfo));
2033         {
2034                 vk.cmdBeginQuery(primCmdBuf.get(), queryPool.get(), 1u, VK_QUERY_CONTROL_PRECISE_BIT);
2035                 {
2036                         vk.cmdExecuteCommands(primCmdBuf.get(), 1u, &secCmdBuf.get());
2037                 }
2038                 vk.cmdEndQuery(primCmdBuf.get(), queryPool.get(), 1u);
2039         }
2040         VK_CHECK(vk.endCommandBuffer(primCmdBuf.get()));
2041
2042         return tcu::TestStatus::pass("Successfully recorded a secondary command buffer allowing a precise occlusion query.");
2043 }
2044
2045 tcu::TestStatus recordBufferQueryImpreciseWithFlagTest(Context& context)
2046 {
2047         const VkDevice                                                  vkDevice                                = context.getDevice();
2048         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
2049         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
2050
2051         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
2052         {
2053                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // sType;
2054                 DE_NULL,                                                                                                        // pNext;
2055                 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,                        // flags;
2056                 queueFamilyIndex,                                                                                       // queueFamilyIndex;
2057         };
2058         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
2059
2060         // Command buffer
2061         const VkCommandBufferAllocateInfo               primCmdBufParams                =
2062         {
2063                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,                         // sType;
2064                 DE_NULL,                                                                                                        // pNext;
2065                 *cmdPool,                                                                                                       // pool;
2066                 VK_COMMAND_BUFFER_LEVEL_PRIMARY,                                                        // level;
2067                 1u,                                                                                                                     // flags;
2068         };
2069         const Unique<VkCommandBuffer>                   primCmdBuf                              (allocateCommandBuffer(vk, vkDevice, &primCmdBufParams));
2070
2071         // Secondary Command buffer params
2072         const VkCommandBufferAllocateInfo               secCmdBufParams                 =
2073         {
2074                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,                         // sType;
2075                 DE_NULL,                                                                                                        // pNext;
2076                 *cmdPool,                                                                                                       // pool;
2077                 VK_COMMAND_BUFFER_LEVEL_SECONDARY,                                                      // level;
2078                 1u,                                                                                                                     // flags;
2079         };
2080         const Unique<VkCommandBuffer>                   secCmdBuf                               (allocateCommandBuffer(vk, vkDevice, &secCmdBufParams));
2081
2082         const VkCommandBufferBeginInfo                  primBufferBeginInfo             =
2083         {
2084                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                            // sType
2085                 DE_NULL,                                                                                                        // pNext
2086                 0u,                                                                                                                     // flags
2087                 0u,                                                                                                                     // renderPass
2088                 0u,                                                                                                                     // subpass
2089                 0u,                                                                                                                     // framebuffer
2090                 DE_FALSE,                                                                                                       // occlusionQueryEnable
2091                 0u,                                                                                                                     // queryFlags
2092                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
2093         };
2094
2095         const VkCommandBufferBeginInfo                  secBufferBeginInfo              =
2096         {
2097                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                            // sType
2098                 DE_NULL,                                                                                                        // pNext
2099                 0u,                                                                                                                     // flags
2100                 0u,                                                                                                                     // renderPass
2101                 0u,                                                                                                                     // subpass
2102                 0u,                                                                                                                     // framebuffer
2103                 VK_TRUE,                                                                                                        // occlusionQueryEnable
2104                 VK_QUERY_CONTROL_PRECISE_BIT,                                                           // queryFlags
2105                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
2106         };
2107
2108         // Create an occlusion query with VK_QUERY_CONTROL_PRECISE_BIT set
2109         const VkQueryPoolCreateInfo                             queryPoolCreateInfo             =
2110         {
2111                 VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO,                                       // sType
2112                 DE_NULL,                                                                                                        // pNext
2113                 0u,                                                                                                                     // flags
2114                 VK_QUERY_TYPE_OCCLUSION,                                                                        // queryType
2115                 1u,                                                                                                                     // entryCount
2116                 0u,                                                                                                                     // pipelineStatistics
2117         };
2118         Unique<VkQueryPool>                                             queryPool                               (createQueryPool(vk, vkDevice, &queryPoolCreateInfo));
2119
2120         VK_CHECK(vk.beginCommandBuffer(secCmdBuf.get(), &secBufferBeginInfo));
2121         VK_CHECK(vk.endCommandBuffer(secCmdBuf.get()));
2122
2123         VK_CHECK(vk.beginCommandBuffer(primCmdBuf.get(), &primBufferBeginInfo));
2124         {
2125                 vk.cmdBeginQuery(primCmdBuf.get(), queryPool.get(), 1u, VK_QUERY_CONTROL_PRECISE_BIT);
2126                 {
2127                         vk.cmdExecuteCommands(primCmdBuf.get(), 1u, &secCmdBuf.get());
2128                 }
2129                 vk.cmdEndQuery(primCmdBuf.get(), queryPool.get(), 1u);
2130         }
2131         VK_CHECK(vk.endCommandBuffer(primCmdBuf.get()));
2132
2133         return tcu::TestStatus::pass("Successfully recorded a secondary command buffer allowing a precise occlusion query.");
2134 }
2135
2136 tcu::TestStatus recordBufferQueryImpreciseWithoutFlagTest(Context& context)
2137 {
2138         const VkDevice                                                  vkDevice                                = context.getDevice();
2139         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
2140         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
2141
2142         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
2143         {
2144                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // sType;
2145                 DE_NULL,                                                                                                        // pNext;
2146                 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,                        // flags;
2147                 queueFamilyIndex,                                                                                       // queueFamilyIndex;
2148         };
2149         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
2150
2151         // Command buffer
2152         const VkCommandBufferAllocateInfo               primCmdBufParams                =
2153         {
2154                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,                         // sType;
2155                 DE_NULL,                                                                                                        // pNext;
2156                 *cmdPool,                                                                                                       // pool;
2157                 VK_COMMAND_BUFFER_LEVEL_PRIMARY,                                                        // level;
2158                 1u,                                                                                                                     // flags;
2159         };
2160         const Unique<VkCommandBuffer>                   primCmdBuf                              (allocateCommandBuffer(vk, vkDevice, &primCmdBufParams));
2161
2162         // Secondary Command buffer params
2163         const VkCommandBufferAllocateInfo               secCmdBufParams                 =
2164         {
2165                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,                         // sType;
2166                 DE_NULL,                                                                                                        // pNext;
2167                 *cmdPool,                                                                                                       // pool;
2168                 VK_COMMAND_BUFFER_LEVEL_SECONDARY,                                                      // level;
2169                 1u,                                                                                                                     // flags;
2170         };
2171         const Unique<VkCommandBuffer>                   secCmdBuf                               (allocateCommandBuffer(vk, vkDevice, &secCmdBufParams));
2172
2173         const VkCommandBufferBeginInfo                  primBufferBeginInfo             =
2174         {
2175                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                            // sType
2176                 DE_NULL,                                                                                                        // pNext
2177                 0u,                                                                                                                     // flags
2178                 0u,                                                                                                                     // renderPass
2179                 0u,                                                                                                                     // subpass
2180                 0u,                                                                                                                     // framebuffer
2181                 VK_TRUE,                                                                                                        // occlusionQueryEnable
2182                 0u,                                                                                                                     // queryFlags
2183                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
2184         };
2185
2186         const VkCommandBufferBeginInfo                  secBufferBeginInfo              =
2187         {
2188                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                            // sType
2189                 DE_NULL,                                                                                                        // pNext
2190                 0u,                                                                                                                     // flags
2191                 0u,                                                                                                                     // renderPass
2192                 0u,                                                                                                                     // subpass
2193                 0u,                                                                                                                     // framebuffer
2194                 VK_TRUE,                                                                                                        // occlusionQueryEnable
2195                 0u,                                                                                                                     // queryFlags
2196                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
2197         };
2198
2199         // Create an occlusion query with VK_QUERY_CONTROL_PRECISE_BIT set
2200         const VkQueryPoolCreateInfo                             queryPoolCreateInfo             =
2201         {
2202                 VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO,                                       // sType
2203                 DE_NULL,                                                                                                        // pNext
2204                 (VkQueryPoolCreateFlags)0,
2205                 VK_QUERY_TYPE_OCCLUSION,
2206                 1u,
2207                 0u,
2208         };
2209         Unique<VkQueryPool>                                             queryPool                               (createQueryPool(vk, vkDevice, &queryPoolCreateInfo));
2210
2211         VK_CHECK(vk.beginCommandBuffer(secCmdBuf.get(), &secBufferBeginInfo));
2212         VK_CHECK(vk.endCommandBuffer(secCmdBuf.get()));
2213
2214         VK_CHECK(vk.beginCommandBuffer(primCmdBuf.get(), &primBufferBeginInfo));
2215         {
2216                 vk.cmdBeginQuery(primCmdBuf.get(), queryPool.get(), 1u, VK_QUERY_CONTROL_PRECISE_BIT);
2217                 {
2218                         vk.cmdExecuteCommands(primCmdBuf.get(), 1u, &secCmdBuf.get());
2219                 }
2220                 vk.cmdEndQuery(primCmdBuf.get(), queryPool.get(), 1u);
2221         }
2222         VK_CHECK(vk.endCommandBuffer(primCmdBuf.get()));
2223
2224         return tcu::TestStatus::pass("Successfully recorded a secondary command buffer allowing a precise occlusion query.");
2225 }
2226
2227 /******** 19.4. Command Buffer Submission (6.4 in VK 1.0 Spec) ****************/
2228 tcu::TestStatus submitBufferCountNonZero(Context& context)
2229 {
2230         const VkDevice                                                  vkDevice                                = context.getDevice();
2231         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
2232         const VkQueue                                                   queue                                   = context.getUniversalQueue();
2233         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
2234
2235         const deUint32                                                  BUFFER_COUNT                    = 5u;
2236
2237         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
2238         {
2239                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // sType;
2240                 DE_NULL,                                                                                                        // pNext;
2241                 0u,                                                                                                                     // flags;
2242                 queueFamilyIndex,                                                                                       // queueFamilyIndex;
2243         };
2244         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
2245
2246         // Command buffer
2247         const VkCommandBufferAllocateInfo               cmdBufParams                    =
2248         {
2249                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,                         // sType;
2250                 DE_NULL,                                                                                                        // pNext;
2251                 *cmdPool,                                                                                                       // pool;
2252                 VK_COMMAND_BUFFER_LEVEL_PRIMARY,                                                        // level;
2253                 BUFFER_COUNT,                                                                                           // bufferCount;
2254         };
2255         VkCommandBuffer cmdBuffers[BUFFER_COUNT];
2256         VK_CHECK(vk.allocateCommandBuffers(vkDevice, &cmdBufParams, cmdBuffers));
2257
2258         const VkCommandBufferBeginInfo                  cmdBufBeginInfo                 =
2259         {
2260                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                            // sType
2261                 DE_NULL,                                                                                                        // pNext
2262                 0u,                                                                                                                     // flags
2263                 DE_NULL,                                                                                                        // renderPass
2264                 0u,                                                                                                                     // subpass
2265                 DE_NULL,                                                                                                        // framebuffer
2266                 VK_FALSE,                                                                                                       // occlusionQueryEnable
2267                 (VkQueryControlFlags)0u,                                                                        // queryFlags
2268                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
2269         };
2270
2271         const VkEventCreateInfo                                 eventCreateInfo                 =
2272         {
2273                 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,                                            // sType;
2274                 DE_NULL,                                                                                                        // pNext;
2275                 0u,                                                                                                                     // flags;
2276         };
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]));
2280
2281         // Record the command buffers
2282         for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx)
2283         {
2284                 VK_CHECK(vk.beginCommandBuffer(cmdBuffers[ndx], &cmdBufBeginInfo));
2285                 {
2286                         vk.cmdSetEvent(cmdBuffers[ndx], events[ndx], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
2287                 }
2288                 VK_CHECK(vk.endCommandBuffer(cmdBuffers[ndx]));
2289         }
2290
2291         // We'll use a fence to wait for the execution of the queue
2292         const VkFenceCreateInfo                                 fenceCreateInfo                 =
2293         {
2294                 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,                                            // sType;
2295                 DE_NULL,                                                                                                        // pNext;
2296                 0u,                                                                                                                     // flags
2297         };
2298         const Unique<VkFence>                                   fence                                   (createFence(vk, vkDevice, &fenceCreateInfo));
2299
2300         const VkSubmitInfo                                              submitInfo                              =
2301         {
2302                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                          // sType
2303                 DE_NULL,                                                                                                        // pNext
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
2313         };
2314
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));
2319
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.");
2324
2325         return tcu::TestStatus::pass("All buffers were submitted and executed correctly.");
2326 }
2327
2328 tcu::TestStatus submitBufferCountEqualZero(Context& context)
2329 {
2330         const VkDevice                                                  vkDevice                                = context.getDevice();
2331         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
2332         const VkQueue                                                   queue                                   = context.getUniversalQueue();
2333         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
2334
2335         const deUint32                                                  BUFFER_COUNT                    = 2u;
2336
2337         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
2338         {
2339                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // sType;
2340                 DE_NULL,                                                                                                        // pNext;
2341                 0u,                                                                                                                     // flags;
2342                 queueFamilyIndex,                                                                                       // queueFamilyIndex;
2343         };
2344         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
2345
2346         // Command buffer
2347         const VkCommandBufferAllocateInfo               cmdBufParams                    =
2348         {
2349                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,                         // sType;
2350                 DE_NULL,                                                                                                        // pNext;
2351                 *cmdPool,                                                                                                       // pool;
2352                 VK_COMMAND_BUFFER_LEVEL_PRIMARY,                                                        // level;
2353                 BUFFER_COUNT,                                                                                           // bufferCount;
2354         };
2355         VkCommandBuffer cmdBuffers[BUFFER_COUNT];
2356         VK_CHECK(vk.allocateCommandBuffers(vkDevice, &cmdBufParams, cmdBuffers));
2357
2358         const VkCommandBufferBeginInfo                  cmdBufBeginInfo                 =
2359         {
2360                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                            // sType
2361                 DE_NULL,                                                                                                        // pNext
2362                 0u,                                                                                                                     // flags
2363                 DE_NULL,                                                                                                        // renderPass
2364                 0u,                                                                                                                     // subpass
2365                 DE_NULL,                                                                                                        // framebuffer
2366                 VK_FALSE,                                                                                                       // occlusionQueryEnable
2367                 (VkQueryControlFlags)0u,                                                                        // queryFlags
2368                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
2369         };
2370
2371         const VkEventCreateInfo                                 eventCreateInfo                 =
2372         {
2373                 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,                                            // sType;
2374                 DE_NULL,                                                                                                        // pNext;
2375                 0u,                                                                                                                     // flags;
2376         };
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]));
2380
2381         // Record the command buffers
2382         for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx)
2383         {
2384                 VK_CHECK(vk.beginCommandBuffer(cmdBuffers[ndx], &cmdBufBeginInfo));
2385                 {
2386                         vk.cmdSetEvent(cmdBuffers[ndx], events[ndx], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
2387                 }
2388                 VK_CHECK(vk.endCommandBuffer(cmdBuffers[ndx]));
2389         }
2390
2391         // We'll use a fence to wait for the execution of the queue
2392         const VkFenceCreateInfo                                 fenceCreateInfo                 =
2393         {
2394                 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,                                            // sType;
2395                 DE_NULL,                                                                                                        // pNext;
2396                 0u,                                                                                                                     // flags
2397         };
2398         const Unique<VkFence>                                   fenceZero                               (createFence(vk, vkDevice, &fenceCreateInfo));
2399         const Unique<VkFence>                                   fenceOne                                (createFence(vk, vkDevice, &fenceCreateInfo));
2400
2401         const VkSubmitInfo                                              submitInfoCountZero             =
2402         {
2403                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                          // sType
2404                 DE_NULL,                                                                                                        // pNext
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
2414         };
2415
2416         const VkSubmitInfo                                              submitInfoCountOne              =
2417         {
2418                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                          // sType
2419                 DE_NULL,                                                                                                        // pNext
2420                 0u,                                                                                                                     // waitSemaphoreCount
2421                 DE_NULL,                                                                                                        // pWaitSemaphores
2422                 1u,                                                                                                                     // commandBufferCount
2423                 &cmdBuffers[1],                                                                                         // pCommandBuffers
2424                 0u,                                                                                                                     // signalSemaphoreCount
2425                 DE_NULL,                                                                                                        // pSignalSemaphores
2426         };
2427
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()));
2433
2434         const VkFence                                                   fences[]                                = 
2435         {
2436                 fenceZero.get(),
2437                 fenceOne.get(),
2438         };
2439
2440         // Wait for the queue
2441         VK_CHECK(vk.waitForFences(vkDevice, (deUint32)DE_LENGTH_OF_ARRAY(fences), fences, VK_TRUE, INFINITE_TIMEOUT));
2442
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.");
2446
2447         return tcu::TestStatus::pass("The first submission was ignored.");
2448 }
2449
2450 tcu::TestStatus submitBufferNullFence(Context& context)
2451 {
2452         const VkDevice                                                  vkDevice                                = context.getDevice();
2453         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
2454         const VkQueue                                                   queue                                   = context.getUniversalQueue();
2455         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
2456
2457         const short                                                             BUFFER_COUNT                    = 2;
2458
2459         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
2460         {
2461                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // sType;
2462                 DE_NULL,                                                                                                        // pNext;
2463                 0u,                                                                                                                     // flags;
2464                 queueFamilyIndex,                                                                                       // queueFamilyIndex;
2465         };
2466         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
2467
2468         // Command buffer
2469         const VkCommandBufferAllocateInfo               cmdBufParams                    =
2470         {
2471                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,                         // sType;
2472                 DE_NULL,                                                                                                        // pNext;
2473                 *cmdPool,                                                                                                       // pool;
2474                 VK_COMMAND_BUFFER_LEVEL_PRIMARY,                                                        // level;
2475                 1u,                                                                                                                     // bufferCount;
2476         };
2477         VkCommandBuffer cmdBuffers[BUFFER_COUNT];
2478         for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx)
2479                 VK_CHECK(vk.allocateCommandBuffers(vkDevice, &cmdBufParams, &cmdBuffers[ndx]));
2480
2481         const VkCommandBufferBeginInfo                  cmdBufBeginInfo                 =
2482         {
2483                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                            // sType
2484                 DE_NULL,                                                                                                        // pNext
2485                 0u,                                                                                                                     // flags
2486                 DE_NULL,                                                                                                        // renderPass
2487                 0u,                                                                                                                     // subpass
2488                 DE_NULL,                                                                                                        // framebuffer
2489                 VK_FALSE,                                                                                                       // occlusionQueryEnable
2490                 (VkQueryControlFlags)0u,                                                                        // queryFlags
2491                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
2492         };
2493
2494         const VkEventCreateInfo                                 eventCreateInfo                 =
2495         {
2496                 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,                                            // sType;
2497                 DE_NULL,                                                                                                        // pNext;
2498                 0u,                                                                                                                     // flags;
2499         };
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]));
2503
2504         // Record the command buffers
2505         for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx)
2506         {
2507                 VK_CHECK(vk.beginCommandBuffer(cmdBuffers[ndx], &cmdBufBeginInfo));
2508                 {
2509                         vk.cmdSetEvent(cmdBuffers[ndx], events[ndx], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
2510                 }
2511                 VK_CHECK(vk.endCommandBuffer(cmdBuffers[ndx]));
2512         }
2513
2514         // We'll use a fence to wait for the execution of the queue
2515         const VkFenceCreateInfo                                 fenceCreateInfo                 =
2516         {
2517                 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,                                            // sType;
2518                 DE_NULL,                                                                                                        // pNext;
2519                 0u,                                                                                                                     // flags
2520         };
2521         const Unique<VkFence>                                   fence                                   (createFence(vk, vkDevice, &fenceCreateInfo));
2522
2523         const VkSubmitInfo                                              submitInfoNullFence             =
2524         {
2525                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                          // sType
2526                 DE_NULL,                                                                                                        // pNext
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
2536         };
2537
2538         const VkSubmitInfo                                              submitInfoNonNullFence  =
2539         {
2540                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                          // sType
2541                 DE_NULL,                                                                                                        // pNext
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
2551         };
2552
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
2555         // execute
2556         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfoNullFence, DE_NULL));
2557         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfoNonNullFence, fence.get()));
2558
2559         // Wait for the queue
2560         VK_CHECK(vk.waitForFences(vkDevice, 1u, &fence.get(), VK_TRUE, INFINITE_TIMEOUT));
2561
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.");
2564
2565         return tcu::TestStatus::pass("The first event was signaled -> the buffer with null fence submitted and executed correctly.");
2566 }
2567
2568 /******** 19.5. Secondary Command Buffer Execution (6.6 in VK 1.0 Spec) *******/
2569 tcu::TestStatus executeSecondaryBufferTest(Context& context)
2570 {
2571         const VkDevice                                                  vkDevice                                = context.getDevice();
2572         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
2573         const VkQueue                                                   queue                                   = context.getUniversalQueue();
2574         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
2575
2576         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
2577         {
2578                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // sType;
2579                 DE_NULL,                                                                                                        // pNext;
2580                 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,                        // flags;
2581                 queueFamilyIndex,                                                                                       // queueFamilyIndex;
2582         };
2583         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
2584
2585         // Command buffer
2586         const VkCommandBufferAllocateInfo               cmdBufParams                    =
2587         {
2588                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,                         // sType;
2589                 DE_NULL,                                                                                                        // pNext;
2590                 *cmdPool,                                                                                                       // commandPool;
2591                 VK_COMMAND_BUFFER_LEVEL_PRIMARY,                                                        // level;
2592                 1u,                                                                                                                     // bufferCount;
2593         };
2594         const Unique<VkCommandBuffer>                   primCmdBuf                              (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
2595
2596         // Secondary Command buffer
2597         const VkCommandBufferAllocateInfo               secCmdBufParams                 =
2598         {
2599                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,                         // sType;
2600                 DE_NULL,                                                                                                        // pNext;
2601                 *cmdPool,                                                                                                       // commandPool;
2602                 VK_COMMAND_BUFFER_LEVEL_SECONDARY,                                                      // level;
2603                 1u,                                                                                                                     // bufferCount;
2604         };
2605         const Unique<VkCommandBuffer>                   secCmdBuf                               (allocateCommandBuffer(vk, vkDevice, &secCmdBufParams));
2606
2607         const VkCommandBufferBeginInfo                  primCmdBufBeginInfo             =
2608         {
2609                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                            // sType
2610                 DE_NULL,                                                                                                        // pNext
2611                 0u,                                                                                                                     // flags
2612                 DE_NULL,                                                                                                        // renderPass
2613                 0u,                                                                                                                     // subpass
2614                 DE_NULL,                                                                                                        // framebuffer
2615                 VK_FALSE,                                                                                                       // occlusionQueryEnable
2616                 (VkQueryControlFlags)0u,                                                                        // queryFlags
2617                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
2618         };
2619
2620         const VkCommandBufferBeginInfo                  secCmdBufBeginInfo              =
2621         {
2622                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                            // sType
2623                 DE_NULL,                                                                                                        // pNext
2624                 0u,                                                                                                                     // flags
2625                 DE_NULL,                                                                                                        // renderPass
2626                 0u,                                                                                                                     // subpass
2627                 DE_NULL,                                                                                                        // framebuffer
2628                 VK_FALSE,                                                                                                       // occlusionQueryEnable
2629                 (VkQueryControlFlags)0u,                                                                        // queryFlags
2630                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
2631         };
2632
2633         // Fill create info struct for event
2634         const VkEventCreateInfo                                 eventCreateInfo                 =
2635         {
2636                 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
2637                 DE_NULL,
2638                 0u,
2639         };
2640
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));
2643
2644         // reset event
2645         VK_CHECK(vk.resetEvent(vkDevice, *event));
2646
2647         // record secondary command buffer
2648         VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo));
2649         {
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);
2654         }
2655         // end recording of the secondary buffer
2656         VK_CHECK(vk.endCommandBuffer(*secCmdBuf));
2657
2658         // record primary command buffer
2659         VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo));
2660         {
2661                 // execute secondary buffer
2662                 vk.cmdExecuteCommands(*primCmdBuf, 1u, &secCmdBuf.get());
2663         }
2664         VK_CHECK(vk.endCommandBuffer(*primCmdBuf));
2665
2666         const VkFenceCreateInfo                                 fenceCreateInfo                 =
2667         {
2668                 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
2669                 DE_NULL,
2670                 0u,                                                                                                                     // flags
2671         };
2672
2673         // create fence to wait for execution of queue
2674         const Unique<VkFence>                                   fence                                   (createFence(vk, vkDevice, &fenceCreateInfo));
2675         const VkSubmitInfo                                              submitInfo                              =
2676         {
2677                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                          // sType
2678                 DE_NULL,                                                                                                        // pNext
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
2688         };
2689
2690         // submit primary buffer, the secondary should be executed too
2691         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, fence.get()));
2692
2693         // wait for end of execution of queue
2694         VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT));
2695
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");
2700
2701         return tcu::TestStatus::fail("executeSecondaryBufferTest FAILED");
2702 }
2703
2704 tcu::TestStatus executeSecondaryBufferTwiceTest(Context& context)
2705 {
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();
2711
2712         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
2713         {
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;
2718         };
2719         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
2720
2721         // Command buffer
2722         const VkCommandBufferAllocateInfo               cmdBufParams                    =
2723         {
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;
2729         };
2730         const Unique<VkCommandBuffer>                   primCmdBufOne                   (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
2731         const Unique<VkCommandBuffer>                   primCmdBufTwo                   (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
2732
2733         // Secondary Command buffers params
2734         const VkCommandBufferAllocateInfo               secCmdBufParams                 =
2735         {
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;
2741         };
2742         VkCommandBuffer cmdBuffers[BUFFER_COUNT];
2743         VK_CHECK(vk.allocateCommandBuffers(vkDevice, &secCmdBufParams, cmdBuffers));
2744
2745         const VkCommandBufferBeginInfo                  primCmdBufBeginInfo             =
2746         {
2747                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
2748                 DE_NULL,
2749                 0,                                                                                                                      // flags
2750                 (VkRenderPass)0u,                                                                                       // renderPass
2751                 0u,                                                                                                                     // subpass
2752                 (VkFramebuffer)0u,                                                                                      // framebuffer
2753                 VK_FALSE,                                                                                                       // occlusionQueryEnable
2754                 (VkQueryControlFlags)0u,                                                                        // queryFlags
2755                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
2756         };
2757
2758         const VkCommandBufferBeginInfo                  secCmdBufBeginInfo              =
2759         {
2760                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
2761                 DE_NULL,
2762                 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT,                           // flags
2763                 (VkRenderPass)0u,                                                                                       // renderPass
2764                 0u,                                                                                                                     // subpass
2765                 (VkFramebuffer)0u,                                                                                      // framebuffer
2766                 VK_FALSE,                                                                                                       // occlusionQueryEnable
2767                 (VkQueryControlFlags)0u,                                                                        // queryFlags
2768                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
2769         };
2770
2771         // Fill create info struct for event
2772         const VkEventCreateInfo                                 eventCreateInfo                 =
2773         {
2774                 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
2775                 DE_NULL,
2776                 0u,
2777         };
2778
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));
2781
2782         // reset event
2783         VK_CHECK(vk.resetEvent(vkDevice, *eventOne));
2784
2785         for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx)
2786         {
2787                 // record secondary command buffer
2788                 VK_CHECK(vk.beginCommandBuffer(cmdBuffers[ndx], &secCmdBufBeginInfo));
2789                 {
2790                         // allow execution of event during every stage of pipeline
2791                         VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
2792
2793                         // wait for event
2794                         vk.cmdWaitEvents(cmdBuffers[ndx], 1, &eventOne.get(), stageMask, stageMask, 0, DE_NULL);
2795                 }
2796                 // end recording of secondary buffers
2797                 VK_CHECK(vk.endCommandBuffer(cmdBuffers[ndx]));
2798         };
2799
2800         // record primary command buffer one
2801         VK_CHECK(vk.beginCommandBuffer(*primCmdBufOne, &primCmdBufBeginInfo));
2802         {
2803                 // execute one secondary buffer
2804                 vk.cmdExecuteCommands(*primCmdBufOne, 1, cmdBuffers );
2805         }
2806         VK_CHECK(vk.endCommandBuffer(*primCmdBufOne));
2807
2808         // record primary command buffer two
2809         VK_CHECK(vk.beginCommandBuffer(*primCmdBufTwo, &primCmdBufBeginInfo));
2810         {
2811                 // execute one secondary buffer with all buffers
2812                 vk.cmdExecuteCommands(*primCmdBufTwo, BUFFER_COUNT, cmdBuffers );
2813         }
2814         VK_CHECK(vk.endCommandBuffer(*primCmdBufTwo));
2815
2816         const VkFenceCreateInfo                                 fenceCreateInfo                 =
2817         {
2818                 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
2819                 DE_NULL,
2820                 0u,                                                                                                                     // flags
2821         };
2822
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));
2826
2827         const VkSubmitInfo                                              submitInfoOne                   =
2828         {
2829                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                          // sType
2830                 DE_NULL,                                                                                                        // pNext
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
2840         };
2841
2842         // submit primary buffer, the secondary should be executed too
2843         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfoOne, *fenceOne));
2844
2845         // wait for buffer to stop at event for 100 microseconds
2846         vk.waitForFences(vkDevice, 1, &fenceOne.get(), 0u, 100000);
2847
2848         const VkSubmitInfo                                              submitInfoTwo                   =
2849         {
2850                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                          // sType
2851                 DE_NULL,                                                                                                        // pNext
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
2861         };
2862
2863         // submit second primary buffer, the secondary should be executed too
2864         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfoTwo, *fenceTwo));
2865
2866         // wait for all buffers to stop at event for 100 microseconds
2867         vk.waitForFences(vkDevice, 1, &fenceOne.get(), 0u, 100000);
2868
2869         // now all buffers are waiting at eventOne
2870         // set event eventOne
2871         VK_CHECK(vk.setEvent(vkDevice, *eventOne));
2872
2873         // wait for end of execution of fenceOne
2874         VK_CHECK(vk.waitForFences(vkDevice, 1, &fenceOne.get(), 0u, INFINITE_TIMEOUT));
2875
2876         // wait for end of execution of second queue
2877         VK_CHECK(vk.waitForFences(vkDevice, 1, &fenceTwo.get(), 0u, INFINITE_TIMEOUT));
2878
2879         return tcu::TestStatus::pass("executeSecondaryBufferTwiceTest succeeded");
2880 }
2881
2882 /******** 19.6. Commands Allowed Inside Command Buffers (6.7 in VK 1.0 Spec) **/
2883 tcu::TestStatus orderBindPipelineTest(Context& context)
2884 {
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);
2891
2892         enum
2893         {
2894                 ADDRESSABLE_SIZE = 256, // allocate a lot more than required
2895         };
2896
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);
2901
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;
2908
2909         de::MovePtr<Allocation>                                 bufferMemA;
2910         const Unique<VkBuffer>                                  bufferA                                 (createColorDataBuffer(dataOffsetA, bufferSizeA, colorA1, colorA2, &bufferMemA, context));
2911
2912         de::MovePtr<Allocation>                                 bufferMemB;
2913         const Unique<VkBuffer>                                  bufferB                                 (createColorDataBuffer(dataOffsetB, bufferSizeB, colorB1, colorB2, &bufferMemB, context));
2914
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);
2920
2921         const VkPipelineLayoutCreateInfo layoutCreateInfo =
2922         {
2923                 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,                          // sType
2924                 DE_NULL,                                                                                                        // pNext
2925                 (VkPipelineLayoutCreateFlags)0,
2926                 numDescriptorSets,                                                                                      // setLayoutCount
2927                 &descriptorSetLayout.get(),                                                                     // pSetLayouts
2928                 0u,                                                                                                                     // pushConstantRangeCount
2929                 DE_NULL,                                                                                                        // pPushConstantRanges
2930         };
2931         Unique<VkPipelineLayout>                                pipelineLayout                  (createPipelineLayout(vk, device, &layoutCreateInfo));
2932
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));
2935
2936         const VkPipelineShaderStageCreateInfo   shaderCreateInfoGood    =
2937         {
2938                 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
2939                 DE_NULL,
2940                 (VkPipelineShaderStageCreateFlags)0,
2941                 VK_SHADER_STAGE_COMPUTE_BIT,                                                            // stage
2942                 *computeModuleGood,                                                                                     // shader
2943                 "main",
2944                 DE_NULL,                                                                                                        // pSpecializationInfo
2945         };
2946
2947         const VkPipelineShaderStageCreateInfo   shaderCreateInfoBad     =
2948         {
2949                 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
2950                 DE_NULL,
2951                 (vk::VkPipelineShaderStageCreateFlags)0,
2952                 vk::VK_SHADER_STAGE_COMPUTE_BIT,                                                        // stage
2953                 *computeModuleBad,                                                                                      // shader
2954                 "main",
2955                 DE_NULL,                                                                                                        // pSpecializationInfo
2956         };
2957
2958         const VkComputePipelineCreateInfo               createInfoGood                  =
2959         {
2960                 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
2961                 DE_NULL,
2962                 0u,                                                                                                                     // flags
2963                 shaderCreateInfoGood,                                                                           // cs
2964                 *pipelineLayout,                                                                                        // layout
2965                 (vk::VkPipeline)0,                                                                                      // basePipelineHandle
2966                 0u,                                                                                                                     // basePipelineIndex
2967         };
2968
2969         const VkComputePipelineCreateInfo               createInfoBad                   =
2970         {
2971                 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
2972                 DE_NULL,
2973                 0u,                                                                                                                     // flags
2974                 shaderCreateInfoBad,                                                                            // cs
2975                 *pipelineLayout,                                                                                        // descriptorSetLayout.get()
2976                 (VkPipeline)0,                                                                                          // basePipelineHandle
2977                 0u,                                                                                                                     // basePipelineIndex
2978         };
2979
2980         const Unique<VkPipeline>                                pipelineGood                    (createComputePipeline(vk, device, (VkPipelineCache)0u, &createInfoGood));
2981         const Unique<VkPipeline>                                pipelineBad                             (createComputePipeline(vk, device, (VkPipelineCache)0u, &createInfoBad));
2982
2983         const VkAccessFlags                                             inputBit                                = (VK_ACCESS_UNIFORM_READ_BIT);
2984         const VkBufferMemoryBarrier                             bufferBarrierA                  =
2985         {
2986                 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
2987                 DE_NULL,
2988                 VK_ACCESS_HOST_WRITE_BIT,                                                                       // outputMask
2989                 inputBit,                                                                                                       // inputMask
2990                 VK_QUEUE_FAMILY_IGNORED,                                                                        // srcQueueFamilyIndex
2991                 VK_QUEUE_FAMILY_IGNORED,                                                                        // destQueueFamilyIndex
2992                 *bufferA,                                                                                                       // buffer
2993                 (VkDeviceSize)0u,                                                                                       // offset
2994                 (VkDeviceSize)bufferSizeA,                                                                      // size
2995         };
2996
2997         const VkBufferMemoryBarrier                             bufferBarrierB                  =
2998         {
2999                 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
3000                 DE_NULL,
3001                 VK_ACCESS_HOST_WRITE_BIT,                                                                       // outputMask
3002                 inputBit,                                                                                                       // inputMask
3003                 VK_QUEUE_FAMILY_IGNORED,                                                                        // srcQueueFamilyIndex
3004                 VK_QUEUE_FAMILY_IGNORED,                                                                        // destQueueFamilyIndex
3005                 *bufferB,                                                                                                       // buffer
3006                 (VkDeviceSize)0u,                                                                                       // offset
3007                 (VkDeviceSize)bufferSizeB,                                                                      // size
3008         };
3009
3010         const deUint32                                                  numSrcBuffers                   = 1u;
3011
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]                   =
3021         {
3022                 refQuadrantValue14,
3023                 refQuadrantValue23,
3024                 refQuadrantValue23,
3025                 refQuadrantValue14,
3026         };
3027         tcu::Vec4                                                               results[4];
3028
3029         // submit and wait begin
3030
3031         const tcu::UVec3 numWorkGroups = tcu::UVec3(4, 1u, 1);
3032
3033         const VkCommandPoolCreateInfo                   cmdPoolCreateInfo               =
3034         {
3035                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // sType;
3036                 DE_NULL,                                                                                                        // pNext
3037                 VK_COMMAND_POOL_CREATE_TRANSIENT_BIT,                                           // flags
3038                 queueFamilyIndex,                                                                                       // queueFamilyIndex
3039         };
3040         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, device, &cmdPoolCreateInfo));
3041
3042         const VkFenceCreateInfo                                 fenceCreateInfo                 =
3043         {
3044                 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
3045                 DE_NULL,
3046                 0u,                     // flags
3047         };
3048
3049         const VkCommandBufferAllocateInfo               cmdBufCreateInfo                =
3050         {
3051                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,                         // sType
3052                 DE_NULL,                                                                                                        // pNext
3053                 *cmdPool,                                                                                                       // commandPool
3054                 VK_COMMAND_BUFFER_LEVEL_PRIMARY,                                                        // level
3055                 1u,                                                                                                                     // bufferCount;
3056         };
3057
3058         const VkCommandBufferBeginInfo                  cmdBufBeginInfo                 =
3059         {
3060                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                            // sType
3061                 DE_NULL,                                                                                                        // pNext
3062                 0u,                                                                                                                     // flags
3063                 DE_NULL,                                                                                                        // renderPass
3064                 0u,                                                                                                                     // subpass
3065                 DE_NULL,                                                                                                        // framebuffer
3066                 VK_FALSE,                                                                                                       // occlusionQueryEnable
3067                 (VkQueryControlFlags)0u,                                                                        // queryFlags
3068                 (VkQueryPipelineStatisticFlags)0u,                                                      // pipelineStatistics
3069         };
3070
3071         const Unique<VkFence>                                   cmdCompleteFence                (createFence(vk, device, &fenceCreateInfo));
3072         const Unique<VkCommandBuffer>                   cmd                                             (allocateCommandBuffer(vk, device, &cmdBufCreateInfo));
3073
3074         VK_CHECK(vk.beginCommandBuffer(*cmd, &cmdBufBeginInfo));
3075
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);
3079
3080         if (numPreBarriers)
3081                 vk.cmdPipelineBarrier(*cmd, 0u, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_FALSE, numPreBarriers, preBarriers);
3082
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));
3086
3087         // run
3088         // submit second primary buffer, the secondary should be executed too
3089         const VkSubmitInfo                                              submitInfo                              =
3090         {
3091                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                          // sType
3092                 DE_NULL,                                                                                                        // pNext
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
3102         };
3103         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *cmdCompleteFence));
3104
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()));
3107
3108         // submit and wait end
3109         result.readResultContentsTo(&results);
3110
3111         // verify
3112         if (results[0] == references[0] &&
3113                 results[1] == references[1] &&
3114                 results[2] == references[2] &&
3115                 results[3] == references[3])
3116         {
3117                 return tcu::TestStatus::pass("Pass");
3118         }
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))
3123         {
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");
3129         }
3130         else
3131         {
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");
3145         }
3146 }
3147
3148 // Shaders
3149 void genComputeSource (SourceCollections& programCollection)
3150 {
3151         const char* const                                               versionDecl                             = glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
3152         std::ostringstream                                              buf_good;
3153
3154         buf_good << versionDecl << "\n"
3155         << ""
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"
3158         << "{\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"
3163         << "{\n"
3164         << "    highp vec4 read_colors[4];\n"
3165         << "} b_out;\n"
3166         << "void main(void)\n"
3167         << "{\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"
3172         << "    else\n"
3173         << "            result_color = b_instance.colorB;\n"
3174         << "    b_out.read_colors[gl_WorkGroupID.x] = result_color;\n"
3175         << "}\n";
3176
3177         programCollection.glslSources.add("compute_good") << glu::ComputeSource(buf_good.str());
3178
3179         std::ostringstream      buf_bad;
3180
3181         buf_bad << versionDecl << "\n"
3182         << ""
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"
3185         << "{\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"
3190         << "{\n"
3191         << "    highp vec4 read_colors[4];\n"
3192         << "} b_out;\n"
3193         << "void main(void)\n"
3194         << "{\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"
3199         << "    else\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"
3202         << "}\n";
3203
3204         programCollection.glslSources.add("compute_bad") << glu::ComputeSource(buf_bad.str());
3205 }
3206
3207 } // anonymous
3208
3209 tcu::TestCaseGroup* createCommandBuffersTests (tcu::TestContext& testCtx)
3210 {
3211         de::MovePtr<tcu::TestCaseGroup> commandBuffersTests     (new tcu::TestCaseGroup(testCtx, "command_buffers", "Command Buffers Tests"));
3212
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);
3253
3254         return commandBuffersTests.release();
3255 }
3256
3257 } // api
3258 } // vkt
3259